[gnome-builder/wip/project-selector: 56/56] git: add IdeGitRemoteCallbacks



commit 366509cf46178c2c0b6e6ed61b3575ede70a9dc7
Author: Christian Hergert <christian hergert me>
Date:   Mon Apr 6 14:22:58 2015 -0700

    git: add IdeGitRemoteCallbacks
    
    This is where we'll put various git clone/operation integration helpers
    such as password dialogs and progress.
    
    More to come.

 libide/Makefile.am                    |    2 +
 libide/git/ide-git-remote-callbacks.c |  144 +++++++++++++++++++++++++++++++++
 libide/git/ide-git-remote-callbacks.h |   45 ++++++++++
 3 files changed, 191 insertions(+), 0 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index d0cba48..823927a 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -36,6 +36,8 @@ libide_1_0_la_public_sources = \
        libide/directory/ide-directory-vcs.h \
        libide/editorconfig/ide-editorconfig-file-settings.c \
        libide/editorconfig/ide-editorconfig-file-settings.h \
+       libide/git/ide-git-remote-callbacks.c \
+       libide/git/ide-git-remote-callbacks.h \
        libide/git/ide-git-search-provider.c \
        libide/git/ide-git-search-provider.h \
        libide/git/ide-git-search-result.c \
diff --git a/libide/git/ide-git-remote-callbacks.c b/libide/git/ide-git-remote-callbacks.c
new file mode 100644
index 0000000..6112f88
--- /dev/null
+++ b/libide/git/ide-git-remote-callbacks.c
@@ -0,0 +1,144 @@
+/* ide-git-remote-callbacks.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "ide-git-remote-callbacks.h"
+
+struct _IdeGitRemoteCallbacks
+{
+  GgitRemoteCallbacks  parent_instance;
+
+  gdouble              fraction;
+};
+
+struct _IdeGitRemoteCallbacksClass
+{
+  GgitRemoteCallbacksClass parent_class;
+};
+
+G_DEFINE_TYPE (IdeGitRemoteCallbacks, ide_git_remote_callbacks, GGIT_TYPE_REMOTE_CALLBACKS)
+
+enum {
+  PROP_0,
+  PROP_FRACTION,
+  LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+GgitRemoteCallbacks *
+ide_git_remote_callbacks_new (void)
+{
+  return g_object_new (IDE_TYPE_GIT_REMOTE_CALLBACKS, NULL);
+}
+
+/**
+ * ide_git_remote_callbacks_get_fraction:
+ *
+ * Gets the fraction of the current operation. This should typically be bound using
+ * g_object_bind_property() to GtkProgressBar:fraction or similar progress widget.
+ *
+ * Returns: The operation completion percentage, as a fraction between 0 and 1.
+ */
+gdouble
+ide_git_remote_callbacks_get_fraction (IdeGitRemoteCallbacks *self)
+{
+  g_return_val_if_fail (IDE_IS_GIT_REMOTE_CALLBACKS (self), 0.0);
+
+  return self->fraction;
+}
+
+static gboolean
+ide_git_remote_callbacks__notify_fraction_cb (gpointer data)
+{
+  g_autoptr(IdeGitRemoteCallbacks) self = data;
+
+  g_assert (IDE_IS_GIT_REMOTE_CALLBACKS (self));
+
+  g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_FRACTION]);
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+ide_git_remote_callbacks_real_transfer_progress (GgitRemoteCallbacks  *callbacks,
+                                                 GgitTransferProgress *stats)
+{
+  IdeGitRemoteCallbacks *self = (IdeGitRemoteCallbacks *)callbacks;
+  guint total;
+  guint received;
+
+  g_assert (IDE_IS_GIT_REMOTE_CALLBACKS (self));
+  g_assert (stats != NULL);
+
+  total = ggit_transfer_progress_get_total_objects (stats);
+  received = ggit_transfer_progress_get_received_objects (stats);
+  if (total == 0)
+    return;
+
+  self->fraction = (gdouble)received / (gdouble)total;
+
+  /* Emit notify::fraction from the gtk+ main loop */
+  g_timeout_add (0, ide_git_remote_callbacks__notify_fraction_cb, g_object_ref (self));
+}
+
+static void
+ide_git_remote_callbacks_get_property (GObject    *object,
+                                       guint       prop_id,
+                                       GValue     *value,
+                                       GParamSpec *pspec)
+{
+  IdeGitRemoteCallbacks *self = IDE_GIT_REMOTE_CALLBACKS (object);
+
+  switch (prop_id)
+    {
+    case PROP_FRACTION:
+      g_value_set_double (value, ide_git_remote_callbacks_get_fraction (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_git_remote_callbacks_class_init (IdeGitRemoteCallbacksClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GgitRemoteCallbacksClass *callbacks_class = GGIT_REMOTE_CALLBACKS_CLASS (klass);
+
+  object_class->get_property = ide_git_remote_callbacks_get_property;
+
+  callbacks_class->transfer_progress = ide_git_remote_callbacks_real_transfer_progress;
+
+  gParamSpecs [PROP_FRACTION] =
+    g_param_spec_double ("fraction",
+                         _("Fraction"),
+                         _("A fraction containing the operatoin progress."),
+                         0,
+                         1.0,
+                         0.0,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (object_class, PROP_FRACTION, gParamSpecs [PROP_FRACTION]);
+}
+
+static void
+ide_git_remote_callbacks_init (IdeGitRemoteCallbacks *self)
+{
+}
diff --git a/libide/git/ide-git-remote-callbacks.h b/libide/git/ide-git-remote-callbacks.h
new file mode 100644
index 0000000..94e7fbc
--- /dev/null
+++ b/libide/git/ide-git-remote-callbacks.h
@@ -0,0 +1,45 @@
+/* ide-git-remote-callbacks.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_GIT_REMOTE_CALLBACKS_H
+#define IDE_GIT_REMOTE_CALLBACKS_H
+
+#include <libgit2-glib/ggit.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_GIT_REMOTE_CALLBACKS            (ide_git_remote_callbacks_get_type())
+#define IDE_GIT_REMOTE_CALLBACKS(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
IDE_TYPE_GIT_REMOTE_CALLBACKS, IdeGitRemoteCallbacks))
+#define IDE_GIT_REMOTE_CALLBACKS_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
IDE_TYPE_GIT_REMOTE_CALLBACKS, IdeGitRemoteCallbacks const))
+#define IDE_GIT_REMOTE_CALLBACKS_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
IDE_TYPE_GIT_REMOTE_CALLBACKS, IdeGitRemoteCallbacksClass))
+#define IDE_IS_GIT_REMOTE_CALLBACKS(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
IDE_TYPE_GIT_REMOTE_CALLBACKS))
+#define IDE_IS_GIT_REMOTE_CALLBACKS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
IDE_TYPE_GIT_REMOTE_CALLBACKS))
+#define IDE_GIT_REMOTE_CALLBACKS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
IDE_TYPE_GIT_REMOTE_CALLBACKS, IdeGitRemoteCallbacksClass))
+
+typedef struct _IdeGitRemoteCallbacks      IdeGitRemoteCallbacks;
+typedef struct _IdeGitRemoteCallbacksClass IdeGitRemoteCallbacksClass;
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeGitRemoteCallbacks, g_object_unref)
+
+GType                ide_git_remote_callbacks_get_type     (void);
+GgitRemoteCallbacks *ide_git_remote_callbacks_new          (void);
+gdouble              ide_git_remote_callbacks_get_fraction (IdeGitRemoteCallbacks *self);
+
+G_END_DECLS
+
+#endif /* IDE_GIT_REMOTE_CALLBACKS_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]