[gnome-builder] transfers: use EggProgressButton as IdeTransferButton base
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] transfers: use EggProgressButton as IdeTransferButton base
- Date: Sat, 11 Mar 2017 02:57:34 +0000 (UTC)
commit 082edc06bb6d9e3f5d7ed4d805f2381936500758
Author: Christian Hergert <chergert redhat com>
Date: Fri Mar 10 18:56:30 2017 -0800
transfers: use EggProgressButton as IdeTransferButton base
libide/transfers/ide-transfer-button.c | 64 ++++++++++++++++++++++++++++++--
libide/transfers/ide-transfer-button.h | 6 ++-
2 files changed, 64 insertions(+), 6 deletions(-)
---
diff --git a/libide/transfers/ide-transfer-button.c b/libide/transfers/ide-transfer-button.c
index 270ac0a..003cbdb 100644
--- a/libide/transfers/ide-transfer-button.c
+++ b/libide/transfers/ide-transfer-button.c
@@ -38,11 +38,38 @@ enum {
N_PROPS
};
-G_DEFINE_TYPE_WITH_PRIVATE (IdeTransferButton, ide_transfer_button, GTK_TYPE_BUTTON)
+G_DEFINE_TYPE_WITH_PRIVATE (IdeTransferButton, ide_transfer_button, EGG_TYPE_PROGRESS_BUTTON)
static GParamSpec *properties [N_PROPS];
static void
+notify_progress_cb (IdeTransferButton *self,
+ GParamSpec *pspec,
+ IdeTransfer *transfer)
+{
+ gdouble progress;
+
+ g_assert (IDE_IS_TRANSFER_BUTTON (self));
+ g_assert (pspec != NULL);
+ g_assert (IDE_IS_TRANSFER (transfer));
+
+ progress = ide_transfer_get_progress (transfer);
+
+ egg_progress_button_set_progress (EGG_PROGRESS_BUTTON (self), progress * 100.0);
+}
+
+static void
+notify_active_cb (IdeTransferButton *self,
+ GParamSpec *pspec,
+ IdeTransfer *transfer)
+{
+ g_assert (IDE_IS_TRANSFER_BUTTON (self));
+ g_assert (IDE_IS_TRANSFER (transfer));
+
+ gtk_widget_set_sensitive (GTK_WIDGET (self), !ide_transfer_get_active (transfer));
+}
+
+static void
ide_transfer_button_set_transfer (IdeTransferButton *self,
IdeTransfer *transfer)
{
@@ -53,8 +80,35 @@ ide_transfer_button_set_transfer (IdeTransferButton *self,
g_assert (IDE_IS_TRANSFER_BUTTON (self));
g_assert (!transfer || IDE_IS_TRANSFER (transfer));
- if (g_set_object (&priv->transfer, transfer))
- gtk_widget_set_sensitive (GTK_WIDGET (self), transfer != NULL);
+ if (transfer != priv->transfer)
+ {
+ if (priv->transfer != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (priv->transfer, notify_progress_cb, self);
+ g_signal_handlers_disconnect_by_func (priv->transfer, notify_active_cb, self);
+ g_clear_object (&priv->transfer);
+ gtk_widget_hide (GTK_WIDGET (self));
+ }
+
+ if (transfer != NULL)
+ {
+ priv->transfer = g_object_ref (transfer);
+ g_signal_connect_object (priv->transfer,
+ "notify::active",
+ G_CALLBACK (notify_active_cb),
+ self,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (priv->transfer,
+ "notify::progress",
+ G_CALLBACK (notify_progress_cb),
+ self,
+ G_CONNECT_SWAPPED);
+ notify_active_cb (self, NULL, priv->transfer);
+ gtk_widget_show (GTK_WIDGET (self));
+ }
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TRANSFER]);
+ }
IDE_EXIT;
}
@@ -76,6 +130,7 @@ ide_transfer_button_execute_cb (GObject *object,
ide_transfer_manager_execute_finish (transfer_manager, result, NULL);
gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
+ egg_progress_button_set_show_progress (EGG_PROGRESS_BUTTON (self), FALSE);
IDE_EXIT;
}
@@ -100,6 +155,7 @@ ide_transfer_button_clicked (GtkButton *button)
if (context == NULL)
return;
+ egg_progress_button_set_show_progress (EGG_PROGRESS_BUTTON (self), TRUE);
gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
transfer_manager = ide_context_get_transfer_manager (context);
@@ -186,7 +242,7 @@ ide_transfer_button_class_init (IdeTransferButtonClass *klass)
"Transfer",
IDE_TYPE_TRANSFER,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
-
+
g_object_class_install_properties (object_class, N_PROPS, properties);
}
diff --git a/libide/transfers/ide-transfer-button.h b/libide/transfers/ide-transfer-button.h
index cd224e6..a013f37 100644
--- a/libide/transfers/ide-transfer-button.h
+++ b/libide/transfers/ide-transfer-button.h
@@ -21,17 +21,19 @@
#include <gtk/gtk.h>
+#include "egg-progress-button.h"
+
#include "transfers/ide-transfer.h"
G_BEGIN_DECLS
#define IDE_TYPE_TRANSFER_BUTTON (ide_transfer_button_get_type())
-G_DECLARE_DERIVABLE_TYPE (IdeTransferButton, ide_transfer_button, IDE, TRANSFER_BUTTON, GtkButton)
+G_DECLARE_DERIVABLE_TYPE (IdeTransferButton, ide_transfer_button, IDE, TRANSFER_BUTTON, EggProgressButton)
struct _IdeTransferButtonClass
{
- GtkButtonClass parent_class;
+ EggProgressButtonClass parent_class;
gpointer _reserved1;
gpointer _reserved2;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]