[gnome-calendar/calendar-management] sources-dialog: add rows when source is connected



commit ee37cf5d4c0ce23ab2191ac99f84c00fd6c96fcf
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Jan 15 06:46:15 2015 -0200

    sources-dialog: add rows when source is connected

 src/gcal-source-manager-dialog.c |  102 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 102 insertions(+), 0 deletions(-)
---
diff --git a/src/gcal-source-manager-dialog.c b/src/gcal-source-manager-dialog.c
index 7a4fdcc..94d57ae 100644
--- a/src/gcal-source-manager-dialog.c
+++ b/src/gcal-source-manager-dialog.c
@@ -41,6 +41,21 @@ enum {
   PROP_MANAGER
 };
 
+/* callbacks */
+static void     source_added_cb                            (GcalManager         *manager,
+                                                            ESource             *source,
+                                                            gboolean             enabled,
+                                                            gpointer             user_data);
+
+static void     source_removed_cb                          (GcalManager         *manager,
+                                                            ESource             *source,
+                                                            gpointer             user_data);
+
+/* private */
+static GtkWidget* make_row_for_source                      (GcalSourceManagerDialog *dialog,
+                                                            ESource                 *source);
+
+/* prototypes */
 static void     gcal_source_manager_dialog_constructed     (GObject             *object);
 
 static void     gcal_source_manager_dialog_get_property    (GObject           *object,
@@ -55,6 +70,91 @@ static void     gcal_source_manager_dialog_set_property    (GObject           *o
 
 G_DEFINE_TYPE_WITH_PRIVATE (GcalSourceManagerDialog, gcal_source_manager_dialog, GTK_TYPE_DIALOG)
 
+/**
+ * source_added_cb:
+ *
+ * Callback for when an #ESource is added
+ * to the #GcalManager.
+ *
+ * Returns:
+ */
+static void
+source_added_cb (GcalManager *manager,
+                 ESource     *source,
+                 gboolean     enabled,
+                 gpointer     user_data)
+{
+  GcalSourceManagerDialogPrivate *priv;
+  GtkWidget *row;
+
+  priv = gcal_source_manager_dialog_get_instance_private (GCAL_SOURCE_MANAGER_DIALOG (user_data));
+  row = make_row_for_source (GCAL_SOURCE_MANAGER_DIALOG (user_data), source);
+
+  gtk_container_add (GTK_CONTAINER (priv->sources_listbox), row);
+}
+
+/**
+ * source_removed_cb:
+ *
+ * Callback for when an #ESource is removed
+ * from the #GcalManager.
+ *
+ * Returns:
+ */
+static void
+source_removed_cb (GcalManager *manager,
+                   ESource     *source,
+                   gpointer     user_data)
+{
+  g_message ("Source removed CB");
+}
+
+/**
+ * make_row_for_source:
+ *
+ * Creates a row for the given source.
+ *
+ * Returns: (transfer full) a new #GtkListBoxRow with source data.
+ */
+static GtkWidget*
+make_row_for_source (GcalSourceManagerDialog *dialog,
+                     ESource                 *source)
+{
+  GcalSourceManagerDialogPrivate *priv;
+  GtkWidget *row;
+  GtkWidget *grid;
+  GtkWidget *label;
+
+  priv = gcal_source_manager_dialog_get_instance_private (dialog);
+
+  /* grid */
+  grid = gtk_grid_new ();
+  g_object_set (grid, "column-spacing", 12, "border-width", 6, NULL);
+
+  /* label */
+  label = gtk_label_new (e_source_get_display_name (source));
+  gtk_widget_set_hexpand (label, TRUE);
+  gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+  gtk_container_add (GTK_CONTAINER (grid), label);
+
+  /* default source icon */
+  if (source == gcal_manager_get_default_source (priv->manager))
+    {
+      GtkWidget *default_icon;
+
+      default_icon = gtk_image_new_from_icon_name ("starred-symbolic", GTK_ICON_SIZE_MENU);
+      gtk_container_add (GTK_CONTAINER (grid), default_icon);
+    }
+
+  /* row */
+  row = gtk_list_box_row_new ();
+  gtk_container_add (GTK_CONTAINER (row), grid);
+
+  gtk_widget_show_all (row);
+
+  return row;
+}
+
 GtkWidget *
 gcal_source_manager_dialog_new (GcalManager *manager)
 {
@@ -96,6 +196,8 @@ gcal_source_manager_dialog_set_property (GObject      *object,
     {
       case PROP_MANAGER:
         priv->manager = g_value_get_pointer (value);
+        g_signal_connect (priv->manager, "source-added", G_CALLBACK (source_added_cb), object);
+        g_signal_connect (priv->manager, "source-removed", G_CALLBACK (source_removed_cb), object);
         break;
 
       default:


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