[gnome-todo/wip/lists] storage-dialog: initial working impl



commit b7343d031565f2b17948e38f35a88709a453985f
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Jun 20 23:32:41 2015 -0300

    storage-dialog: initial working impl

 data/todo.gresource.xml   |    1 +
 data/ui/storage-dialog.ui |   45 +++++++++
 src/Makefile.am           |    2 +
 src/gtd-storage-dialog.c  |  227 +++++++++++++++++++++++++++++++++++++++++++++
 src/gtd-storage-dialog.h  |   41 ++++++++
 5 files changed, 316 insertions(+), 0 deletions(-)
---
diff --git a/data/todo.gresource.xml b/data/todo.gresource.xml
index 703aa8a..0c87a55 100644
--- a/data/todo.gresource.xml
+++ b/data/todo.gresource.xml
@@ -6,6 +6,7 @@
     <file compressed="true" preprocess="xml-stripblanks">ui/initial-setup.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/list-view.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/source-dialog.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/storage-dialog.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/storage-popover.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/storage-row.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/storage-selector.ui</file>
diff --git a/data/ui/storage-dialog.ui b/data/ui/storage-dialog.ui
new file mode 100644
index 0000000..2fc5a12
--- /dev/null
+++ b/data/ui/storage-dialog.ui
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GtdStorageDialog" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="type_hint">dialog</property>
+    <property name="width_request">450</property>
+    <property name="height_request">450</property>
+    <signal name="close" handler="gtk_widget_hide" object="GtdStorageDialog" swapped="no" />
+    <signal name="response" handler="gtk_widget_hide" object="GtdStorageDialog" swapped="no" />
+    <child internal-child="vbox">
+      <object class="GtkBox" id="main_box">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <property name="border_width">18</property>
+        <child>
+          <object class="GtkLabel" id="title_label">
+            <property name="visible">True</property>
+            <property name="wrap_mode">word</property>
+            <property name="hexpand">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Select the default storage location to create task 
lists:</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtdStorageSelector" id="storage_selector">
+            <property name="visible">True</property>
+            <property name="select_default">True</property>
+            <property name="show_local">True</property>
+            <signal name="storage-selected" handler="gtd_storage_dialog__storage_selected" 
object="GtdStorageDialog" swapped="yes" />
+          </object>
+        </child>
+      </object>
+    </child>
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="headerbar">
+        <property name="visible">True</property>
+        <property name="has_subtitle">True</property>
+        <property name="show_close_button">True</property>
+        <property name="title">Default storage location</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 7917916..b80614d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,6 +31,8 @@ gnome_todo_SOURCES = \
        gtd-object.h \
        gtd-storage.c \
        gtd-storage.h \
+       gtd-storage-dialog.c \
+       gtd-storage-dialog.h \
        gtd-storage-popover.c \
        gtd-storage-popover.h \
        gtd-storage-row.c \
diff --git a/src/gtd-storage-dialog.c b/src/gtd-storage-dialog.c
new file mode 100644
index 0000000..2d91c30
--- /dev/null
+++ b/src/gtd-storage-dialog.c
@@ -0,0 +1,227 @@
+/* gtd-storage-dialog.c
+ *
+ * Copyright (C) 2015 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * 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 "gtd-manager.h"
+#include "gtd-storage.h"
+#include "gtd-storage-dialog.h"
+#include "gtd-storage-selector.h"
+
+#include <glib/gi18n.h>
+
+typedef struct
+{
+  GtkWidget       *headerbar;
+  GtkWidget       *storage_selector;
+
+  GtdManager      *manager;
+} GtdStorageDialogPrivate;
+
+struct _GtdStorageDialog
+{
+  GtkDialog                parent;
+
+  /*<private>*/
+  GtdStorageDialogPrivate *priv;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtdStorageDialog, gtd_storage_dialog, GTK_TYPE_DIALOG)
+
+enum {
+  PROP_0,
+  PROP_MANAGER,
+  LAST_PROP
+};
+
+static void
+gtd_storage_dialog__storage_selected (GtdStorageDialog *dialog,
+                                      GtdStorage       *storage)
+{
+  GtdStorageDialogPrivate *priv;
+
+  g_return_if_fail (GTD_IS_STORAGE_DIALOG (dialog));
+  g_return_if_fail (GTD_IS_MANAGER (dialog->priv->manager));
+  g_return_if_fail (GTD_IS_STORAGE (storage));
+
+  priv = dialog->priv;
+
+  if (storage)
+    gtd_manager_set_default_storage (priv->manager, storage);
+}
+
+static void
+gtd_storage_dialog_finalize (GObject *object)
+{
+  GtdStorageDialog *self = (GtdStorageDialog *)object;
+  GtdStorageDialogPrivate *priv = gtd_storage_dialog_get_instance_private (self);
+
+  G_OBJECT_CLASS (gtd_storage_dialog_parent_class)->finalize (object);
+}
+
+static void
+gtd_storage_dialog_constructed (GObject *object)
+{
+  GtdStorageDialogPrivate *priv;
+
+  /* Chain up */
+  G_OBJECT_CLASS (gtd_storage_dialog_parent_class)->constructed (object);
+
+  priv = GTD_STORAGE_DIALOG (object)->priv;
+
+  gtk_window_set_titlebar (GTK_WINDOW (object), priv->headerbar);
+
+  g_object_bind_property (object,
+                          "manager",
+                          priv->storage_selector,
+                          "manager",
+                          G_BINDING_DEFAULT);
+}
+
+static void
+gtd_storage_dialog_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  GtdStorageDialog *self = GTD_STORAGE_DIALOG (object);
+
+  switch (prop_id)
+    {
+    case PROP_MANAGER:
+      g_value_set_object (value, self->priv->manager);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gtd_storage_dialog_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  GtdStorageDialog *self = GTD_STORAGE_DIALOG (object);
+
+  switch (prop_id)
+    {
+    case PROP_MANAGER:
+      gtd_storage_dialog_set_manager (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gtd_storage_dialog_class_init (GtdStorageDialogClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = gtd_storage_dialog_finalize;
+  object_class->constructed = gtd_storage_dialog_constructed;
+  object_class->get_property = gtd_storage_dialog_get_property;
+  object_class->set_property = gtd_storage_dialog_set_property;
+
+
+  /**
+   * GtdStorageDialog::manager:
+   *
+   * A weak reference to the application's #GtdManager instance.
+   */
+  g_object_class_install_property (
+        object_class,
+        PROP_MANAGER,
+        g_param_spec_object ("manager",
+                             _("Manager of this window's application"),
+                             _("The manager of the window's application"),
+                             GTD_TYPE_MANAGER,
+                             G_PARAM_READWRITE));
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/todo/ui/storage-dialog.ui");
+
+  gtk_widget_class_bind_template_child_private (widget_class, GtdStorageDialog, headerbar);
+  gtk_widget_class_bind_template_child_private (widget_class, GtdStorageDialog, storage_selector);
+
+  gtk_widget_class_bind_template_callback (widget_class, gtd_storage_dialog__storage_selected);
+}
+
+static void
+gtd_storage_dialog_init (GtdStorageDialog *self)
+{
+  self->priv = gtd_storage_dialog_get_instance_private (self);
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+/**
+ * gtd_storage_dialog_new:
+ *
+ * Creates a new #GtdStorageDialog.
+ *
+ * Returns: (transfer full): the newly allocated #GtdStorageDialog
+ */
+GtkWidget*
+gtd_storage_dialog_new (void)
+{
+  return g_object_new (GTD_TYPE_STORAGE_DIALOG, NULL);
+}
+
+/**
+ * gtd_storage_dialog_get_manager:
+ * @dialog: a #GtdStorageDialog
+ *
+ * Retrieves @dialog's internal #GtdManager.
+ *
+ * Returns: (transfer none): the @dialog's #GtdManager
+ */
+GtdManager*
+gtd_storage_dialog_get_manager (GtdStorageDialog *dialog)
+{
+  g_return_val_if_fail (GTD_IS_STORAGE_DIALOG (dialog), NULL);
+
+  return dialog->priv->manager;
+}
+
+/**
+ * gtd_storage_dialog_set_manager:
+ * @dialog: a #GtdStorageDialog
+ * @manager: a #GtdManager
+ *
+ * Sets the @dialog's #GtdManager.
+ *
+ * Returns:
+ */
+void
+gtd_storage_dialog_set_manager (GtdStorageDialog *dialog,
+                                GtdManager       *manager)
+{
+  GtdStorageDialogPrivate *priv;
+
+  g_return_if_fail (GTD_IS_STORAGE_DIALOG (dialog));
+
+  priv = dialog->priv;
+
+  if (priv->manager != manager)
+    {
+      priv->manager = manager;
+      g_object_notify (G_OBJECT (dialog), "manager");
+    }
+}
diff --git a/src/gtd-storage-dialog.h b/src/gtd-storage-dialog.h
new file mode 100644
index 0000000..30d43b5
--- /dev/null
+++ b/src/gtd-storage-dialog.h
@@ -0,0 +1,41 @@
+/* gtd-storage-dialog.h
+ *
+ * Copyright (C) 2015 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * 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 GTD_STORAGE_DIALOG_H
+#define GTD_STORAGE_DIALOG_H
+
+#include "gtd-types.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTD_TYPE_STORAGE_DIALOG (gtd_storage_dialog_get_type())
+
+G_DECLARE_FINAL_TYPE (GtdStorageDialog, gtd_storage_dialog, GTD, STORAGE_DIALOG, GtkDialog)
+
+GtkWidget*         gtd_storage_dialog_new                        (void);
+
+GtdManager*        gtd_storage_dialog_get_manager                (GtdStorageDialog   *dialog);
+
+void               gtd_storage_dialog_set_manager                (GtdStorageDialog   *dialog,
+                                                                  GtdManager         *manager);
+
+G_END_DECLS
+
+#endif /* GTD_STORAGE_DIALOG_H */


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