[gnome-calendar/wip/gbsneto/edit-dialog-cleanup] edit-dialog: add ::writable and ::manager properties



commit 13c4145507bee8226ed2ed4cf143c6c91d64a4c1
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Dec 30 16:03:48 2015 -0200

    edit-dialog: add ::writable and ::manager properties
    
    By using these properties, we gain the possibility to
    bind them to the widgets and save some needless code.
    
    This commit adds GcalEditDialog::writable and ::manager
    properties. Other needed properties will be eventually
    added in the subsequent commits.

 data/ui/edit-dialog.ui |    8 +++
 src/gcal-edit-dialog.c |  126 ++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 108 insertions(+), 26 deletions(-)
---
diff --git a/data/ui/edit-dialog.ui b/data/ui/edit-dialog.ui
index 322ac08..d281189 100644
--- a/data/ui/edit-dialog.ui
+++ b/data/ui/edit-dialog.ui
@@ -26,6 +26,7 @@
         </child>
         <child>
           <object class="GtkImage" id="lock">
+            <property name="visible" bind-source="GcalEditDialog" bind-property="writable" 
bind-flags="default|invert-boolean" />
             <property name="icon_name">changes-prevent-symbolic</property>
             <property name="icon_size">1</property>
           </object>
@@ -135,6 +136,7 @@
                 <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
                 <property name="activates_default">True</property>
+                <property name="editable" bind-source="GcalEditDialog" bind-property="writable" 
bind-flags="default" />
                 <signal name="notify::text" handler="update_summary" object="GcalEditDialog" swapped="no"/>
               </object>
               <packing>
@@ -167,6 +169,7 @@
                 <property name="can_focus">True</property>
                 <property name="draw_indicator">True</property>
                 <property name="label" translatable="yes">All day</property>
+                <property name="sensitive" bind-source="GcalEditDialog" bind-property="writable" 
bind-flags="default" />
                 <signal name="toggled" handler="gcal_edit_dialog_all_day_changed" object="GcalEditDialog" 
swapped="no"/>
               </object>
               <packing>
@@ -180,6 +183,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="secondary_icon_name">find-location-symbolic</property>
+                <property name="editable" bind-source="GcalEditDialog" bind-property="writable" 
bind-flags="default" />
                 <signal name="notify::text" handler="update_location" object="GcalEditDialog" swapped="no"/>
               </object>
               <packing>
@@ -202,6 +206,7 @@
                     <property name="hexpand">True</property>
                     <property name="left_margin">6</property>
                     <property name="right_margin">6</property>
+                    <property name="editable" bind-source="GcalEditDialog" bind-property="writable" 
bind-flags="default" />
                     <property name="wrap_mode">GTK_WRAP_WORD_CHAR</property>
                   </object>
                 </child>
@@ -223,6 +228,7 @@
                   <object class="GcalDateSelector" id="start_date_selector">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
+                    <property name="sensitive" bind-source="GcalEditDialog" bind-property="writable" 
bind-flags="default" />
                     <signal name="modified" handler="update_date" object="GcalEditDialog" swapped="no"/>
                   </object>
                   <packing>
@@ -258,6 +264,7 @@
                   <object class="GcalDateSelector" id="end_date_selector">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
+                    <property name="sensitive" bind-source="GcalEditDialog" bind-property="writable" 
bind-flags="default" />
                     <signal name="modified" handler="update_date" object="GcalEditDialog" swapped="no"/>
                   </object>
                   <packing>
@@ -286,6 +293,7 @@
               <object class="GtkButton" id="delete_button">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="sensitive" bind-source="GcalEditDialog" bind-property="writable" 
bind-flags="default" />
                 <signal name="clicked" handler="gcal_edit_dialog_action_button_clicked" 
object="GcalEditDialog" swapped="no"/>
                 <child>
                   <object class="GtkLabel" id="delete_label">
diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c
index 651e0e6..54f47a6 100644
--- a/src/gcal-edit-dialog.c
+++ b/src/gcal-edit-dialog.c
@@ -112,6 +112,14 @@ static void        gcal_edit_dialog_all_day_changed       (GtkWidget         *wi
 
 G_DEFINE_TYPE (GcalEditDialog, gcal_edit_dialog, GTK_TYPE_DIALOG)
 
+enum
+{
+  PROP_0,
+  PROP_MANAGER,
+  PROP_WRITABLE,
+  LAST_PROP
+};
+
 static void
 fill_sources_menu (GcalEditDialog *dialog)
 {
@@ -469,18 +477,92 @@ update_time (GtkEntry   *entry,
 }
 
 static void
+gcal_edit_dialog_get_property (GObject    *object,
+                               guint       prop_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  GcalEditDialog *self = GCAL_EDIT_DIALOG (object);
+
+  switch (prop_id)
+    {
+    case PROP_MANAGER:
+      g_value_set_object (value, self->manager);
+      break;
+
+    case PROP_WRITABLE:
+      g_value_set_boolean (value, self->writable);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gcal_edit_dialog_set_property (GObject      *object,
+                               guint         prop_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  GcalEditDialog *self = GCAL_EDIT_DIALOG (object);
+
+  switch (prop_id)
+    {
+    case PROP_MANAGER:
+      gcal_edit_dialog_set_manager (self, g_value_get_object (value));
+      break;
+
+    case PROP_WRITABLE:
+      gcal_edit_dialog_set_writable (self, g_value_get_boolean (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
 gcal_edit_dialog_class_init (GcalEditDialogClass *klass)
 {
   GObjectClass *object_class;
   GtkWidgetClass *widget_class;
 
   object_class = G_OBJECT_CLASS (klass);
+  object_class->get_property = gcal_edit_dialog_get_property;
+  object_class->set_property = gcal_edit_dialog_set_property;
   object_class->constructed = gcal_edit_dialog_constructed;
   object_class->finalize = gcal_edit_dialog_finalize;
 
   widget_class = GTK_WIDGET_CLASS (klass);
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/edit-dialog.ui");
 
+  /**
+   * GcalEditDialog::manager:
+   *
+   * The #GcalManager of the dialog.
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_MANAGER,
+                                   g_param_spec_object ("manager",
+                                                        "Manager of the dialog",
+                                                        "The manager of the dialog",
+                                                        GCAL_TYPE_MANAGER,
+                                                        G_PARAM_READWRITE));
+
+  /**
+   * GcalEditDialog::writable:
+   *
+   * Whether the current event can be edited or not.
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_WRITABLE,
+                                   g_param_spec_boolean ("writable",
+                                                         "Whether the current event can be edited",
+                                                         "Whether the current event can be edited or not",
+                                                         TRUE,
+                                                         G_PARAM_READWRITE));
+
   /* Buttons */
   gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, done_button);
   gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, cancel_button);
@@ -574,6 +656,7 @@ gcal_edit_dialog_finalize (GObject *object)
   g_clear_object (&dialog->action_group);
   g_clear_object (&dialog->action);
   g_clear_object (&dialog->component);
+  g_clear_object (&dialog->manager);
   g_clear_object (&dialog->source);
 
   G_OBJECT_CLASS (gcal_edit_dialog_parent_class)->finalize (object);
@@ -583,35 +666,25 @@ static void
 gcal_edit_dialog_set_writable (GcalEditDialog *dialog,
                                gboolean        writable)
 {
-  dialog->writable = writable;
-
-  gtk_widget_set_visible (dialog->lock, !writable);
-
-  gtk_editable_set_editable (GTK_EDITABLE (dialog->summary_entry), writable);
-  gtk_editable_set_editable (GTK_EDITABLE (dialog->location_entry), writable);
+  if (dialog->writable != writable)
+    {
+      dialog->writable = writable;
 
-  gtk_text_view_set_editable (GTK_TEXT_VIEW (dialog->notes_text), writable);
+      gtk_button_set_label (GTK_BUTTON (dialog->done_button), writable ? _("Save") : _("Done"));
 
-  gtk_widget_set_sensitive (dialog->all_day_check, writable);
-  gtk_widget_set_sensitive (dialog->end_date_selector, writable);
-  gtk_widget_set_sensitive (dialog->start_date_selector, writable);
+      if (!writable || (writable && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON 
(dialog->all_day_check))))
+        {
+          gtk_widget_set_sensitive (dialog->start_time_selector, FALSE);
+          gtk_widget_set_sensitive (dialog->end_time_selector, FALSE);
+        }
+      else
+        {
+          gtk_widget_set_sensitive (dialog->start_time_selector, TRUE);
+          gtk_widget_set_sensitive (dialog->end_time_selector, TRUE);
+        }
 
-  if (!writable || (writable && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check))))
-    {
-      gtk_widget_set_sensitive (dialog->start_time_selector, FALSE);
-      gtk_widget_set_sensitive (dialog->end_time_selector, FALSE);
+      g_object_notify (G_OBJECT (dialog), "writable");
     }
-  else
-    {
-      gtk_widget_set_sensitive (dialog->start_time_selector, TRUE);
-      gtk_widget_set_sensitive (dialog->end_time_selector, TRUE);
-    }
-
-  gtk_button_set_label (GTK_BUTTON (dialog->done_button),
-                        writable ? _("Save") : _("Done"));
-
-  /* add delete_button here */
-  gtk_widget_set_sensitive (dialog->delete_button, writable);
 }
 
 static void
@@ -879,7 +952,8 @@ gcal_edit_dialog_set_manager (GcalEditDialog *dialog,
   g_return_if_fail (GCAL_IS_EDIT_DIALOG (dialog));
   g_return_if_fail (GCAL_IS_MANAGER (manager));
 
-  dialog->manager = manager;
+  if (g_set_object (&dialog->manager, manager))
+    g_object_notify (G_OBJECT (dialog), "manager");
 }
 
 ECalComponent*


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