[bijiben] settings: Add the primary book choice



commit fe8f65ae5e30119d040f662139debb10622df817
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Thu Aug 8 21:16:41 2013 +0200

    settings: Add the primary book choice
    
    User can now select any provider as the default one for new notes.

 po/POTFILES.in            |    2 +
 src/Makefile.am           |    2 +
 src/bjb-bijiben.c         |   13 +-
 src/bjb-editor-toolbar.c  |    6 +-
 src/bjb-main-toolbar.c    |   10 +-
 src/bjb-main-view.c       |    8 +-
 src/bjb-settings-dialog.c |  535 +++++++++++++++++++++++++++++++++++++++++++++
 src/bjb-settings-dialog.h |   61 +++++
 src/bjb-settings.c        |  190 +++++++---------
 src/bjb-settings.h        |   30 ++-
 10 files changed, 733 insertions(+), 124 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4fcff8c..dafc1ff 100755
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -13,6 +13,8 @@ src/bjb-note-view.c
 src/bjb-rename-note.c
 src/bjb-selection-toolbar.c
 src/bjb-settings.c
+src/bjb-settings-dialog.c
 src/bjb-window-base.c
 src/libbiji/biji-date-time.c
+src/libbiji/provider/biji-local-provider.c
 [type: gettext/glade]src/resources/app-menu.ui
diff --git a/src/Makefile.am b/src/Makefile.am
index c88a31a..d34ecf3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -79,6 +79,8 @@ bijiben_SOURCES = \
        bjb-selection-toolbar.h \
        bjb-settings.c \
        bjb-settings.h \
+       bjb-settings-dialog.c \
+       bjb-settings-dialog.h \
        bjb-share.c \
        bjb-share.h \
        bjb-window-base.c \
diff --git a/src/bjb-bijiben.c b/src/bjb-bijiben.c
index 14671fe..080696a 100644
--- a/src/bjb-bijiben.c
+++ b/src/bjb-bijiben.c
@@ -31,7 +31,7 @@
 struct _BijibenPriv
 {
   BijiNoteBook *book;
-  BjbSettings *settings ;
+  BjbSettings *settings;
 
   /* First run is not used yet,
    * could ask tracker for notes / memo to import */
@@ -118,7 +118,7 @@ bijiben_init (Bijiben *object)
   object->priv =
     G_TYPE_INSTANCE_GET_PRIVATE(object,BIJIBEN_TYPE_APPLICATION,BijibenPriv);
 
-  object->priv->settings = initialize_settings();
+  object->priv->settings = bjb_settings_new ();
 }
 
 /* Import. TODO : move to libbiji */
@@ -319,11 +319,20 @@ on_client_got (GObject *source_object,
     {
       type = goa_account_get_provider_type (account);
 
+
+      /* We do not need to store any object here.
+       * account_get_id can be used to talk with libbji */
+
       if (g_strcmp0 (type, "owncloud") ==0)
+      {
+        g_warning ("%s", goa_account_get_id (account));
         biji_note_book_add_goa_object (self->priv->book, object);
+      }
 
       else
+      {
         g_object_unref (object);
+      }
     } 
   }
 
diff --git a/src/bjb-editor-toolbar.c b/src/bjb-editor-toolbar.c
index dc168b4..1bb4f62 100644
--- a/src/bjb-editor-toolbar.c
+++ b/src/bjb-editor-toolbar.c
@@ -289,6 +289,7 @@ strike_button_callback (GtkWidget *button, BijiNoteObj *note)
 static void
 link_callback (GtkWidget *button, BjbEditorToolbar *self)
 {
+  BjbSettings             *settings;
   gchar                   *link;
   GtkWidget               *window;
   BijiNoteObj             *result;
@@ -304,7 +305,10 @@ link_callback (GtkWidget *button, BjbEditorToolbar *self)
   window = bjb_note_view_get_base_window (priv->view);
   book = bjb_window_base_get_book(window);
 
-  result = biji_note_book_note_new (book, link);
+  settings = bjb_app_get_settings (g_application_get_default ());
+  result = biji_note_book_note_new (book,
+                                    link,
+                                    bjb_settings_get_default_location (settings));
 
   /* Change result color. */
   if (biji_note_obj_get_rgba (priv->note, &color))
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index fe4fa15..fbdc482 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -111,12 +111,16 @@ bjb_main_toolbar_clear (BjbMainToolbar *self)
 static void
 on_new_note_clicked (GtkWidget *but, BjbMainView *view)
 {
-  BijiNoteObj *result ;
-  BijiNoteBook *book ;
+  BijiNoteObj *result;
+  BijiNoteBook *book;
+  BjbSettings  *settings;
 
   /* append note to collection */
   book = bjb_window_base_get_book (bjb_main_view_get_window (view));
-  result = biji_note_book_note_new (book, NULL);
+  settings = bjb_app_get_settings (g_application_get_default ());
+  result = biji_note_book_note_new (book,
+                                    NULL,
+                                    bjb_settings_get_default_location (settings));
 
   /* Go to that note */
   switch_to_note_view(view,result);
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 77894d6..bc296b5 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -382,10 +382,14 @@ on_drag_data_received (GtkWidget        *widget,
       BijiNoteBook *book;
       BijiNoteObj *ret;
       BjbMainView *self = BJB_MAIN_VIEW (user_data);
+      BjbSettings *settings;
 
       /* FIXME Text is guchar utf 8, conversion to perform */
-      book =  bjb_window_base_get_book (self->priv->window); 
-      ret = biji_note_book_note_new (book, (gchar*) text);
+      book =  bjb_window_base_get_book (self->priv->window);
+      settings = bjb_app_get_settings (g_application_get_default ());
+      ret = biji_note_book_note_new (book,
+                                     (gchar*) text,
+                                     bjb_settings_get_default_location (settings));
       switch_to_note_view (self, ret); // maybe AFTER drag finish?
 
       g_free (text);
diff --git a/src/bjb-settings-dialog.c b/src/bjb-settings-dialog.c
new file mode 100644
index 0000000..053fb71
--- /dev/null
+++ b/src/bjb-settings-dialog.c
@@ -0,0 +1,535 @@
+/*
+ * bjb_settings_dialog.c
+ * 
+ * Copyright © 2013 Pierre-Yves LUYTEN <py luyten fr>
+ *
+ * bijiben 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.
+ *
+ * bijiben 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 "config.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "bjb-bijiben.h"
+#include "bjb-color-button.h"
+#include "bjb-settings.h"
+#include "bjb-settings-dialog.h"
+
+
+enum
+{
+  PROP_0,
+  PROP_PARENT,
+  N_PROPERTIES
+};
+
+
+struct BjbSettingsDialogPrivate_
+{
+  GtkWidget        *parent;
+  BjbSettings      *settings;
+  BijiNoteBook     *book;
+
+  GtkStack         *stack;
+  GtkStackSwitcher *switcher;
+
+  /* Primary NoteBook page */
+
+  GtkListBox       *box;
+  GList            *children;
+};
+
+
+
+
+G_DEFINE_TYPE (BjbSettingsDialog, bjb_settings_dialog, GTK_TYPE_DIALOG)
+
+/* Callbacks */
+
+static void
+on_font_selected (GtkFontButton     *widget,
+                  BjbSettings       *settings)
+{
+  g_settings_set_string (G_SETTINGS (settings),
+                         "font",
+                         gtk_font_button_get_font_name (widget));
+  
+}
+
+
+
+static void
+on_color_set (GtkColorButton *button,
+              BjbSettings    *settings)
+{
+  GdkRGBA color;
+  gchar *color_str;
+
+  gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &color);
+  color_str = gdk_rgba_to_string (&color);
+
+  g_settings_set_string (G_SETTINGS (settings),
+                         "color",
+                         color_str);
+
+  g_free (color_str);
+}
+
+
+
+
+
+
+/* Primary Provider page */
+
+typedef struct
+{
+  GtkWidget      *overlay;
+  GtkWidget      *widget;
+  GtkWidget      *toggle;
+
+  const gchar    *id;
+  const char     *name;
+  GtkWidget      *icon;
+
+  gboolean       selected;
+
+} ProviderChild;
+
+
+static ProviderChild *
+provider_child_new ()
+{
+  ProviderChild *retval;
+
+  retval = g_slice_new (ProviderChild);
+  retval->overlay = NULL;
+  retval->widget = NULL;
+  retval->toggle = NULL;
+  retval->selected = FALSE;
+  retval->id = NULL;
+  retval->icon = NULL;
+
+  return retval;
+}
+
+
+static void
+provider_child_free (gpointer child)
+{
+  g_slice_free (ProviderChild, child);
+}
+
+
+static inline GQuark
+application_quark (void)
+{
+  static GQuark quark;
+
+  if (G_UNLIKELY (quark == 0))
+    quark = g_quark_from_static_string ("bjb-application");
+
+  return quark;
+}
+
+
+static GtkWidget *
+child_toggle_new ()
+{
+  GtkWidget *w;
+
+  w = gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_INVALID);
+  gtk_image_set_pixel_size (GTK_IMAGE (w), 48);
+  gtk_widget_show (w);
+  return w;
+}
+
+
+static void
+toggle_child (gpointer iter,
+              gpointer user_data)
+{
+  ProviderChild *child;
+
+
+  child = (ProviderChild*) iter;
+
+
+  if (child->selected)
+  {
+    child->toggle = child_toggle_new ();
+    gtk_overlay_add_overlay (GTK_OVERLAY (child->overlay), child->toggle);
+  }
+
+
+  else
+  {
+    if (child->toggle && GTK_IS_WIDGET (child->toggle))
+      gtk_widget_destroy (child->toggle);
+  }
+}
+
+
+
+static void
+update_providers (BjbSettingsDialog *self)
+{
+  g_list_foreach (self->priv->children, toggle_child, self);
+}
+
+
+static void
+unselect_child (gpointer data, gpointer user_data)
+{
+  ProviderChild *child;
+
+  child = (ProviderChild*) data;
+  child->selected = FALSE;
+}
+
+
+static void
+on_row_activated_cb    (GtkListBox    *list_box,
+                        GtkListBoxRow *row,
+                        gpointer       user_data)
+{
+  BjbSettingsDialog *self;
+  GtkWidget     *widget;
+  ProviderChild *child;
+
+
+  self = BJB_SETTINGS_DIALOG (user_data);
+
+  /* Write GSettings if the provider was not the primary one */
+  widget = gtk_bin_get_child (GTK_BIN (row));
+  child = g_object_get_qdata (G_OBJECT (widget), application_quark ());
+
+  if (child->selected == TRUE)
+    return;
+
+  g_object_set (bjb_app_get_settings (g_application_get_default ()),
+                "default-location", child->id, NULL);
+
+
+  /* Toggle everything : unselect all but this one */
+  g_list_foreach (self->priv->children, unselect_child, NULL);
+  child->selected = TRUE;
+  update_providers (self);
+}
+
+
+static void
+header_func (GtkListBoxRow *row,
+             GtkListBoxRow *before_row,
+             gpointer user_data)
+{
+  if (before_row != NULL && gtk_list_box_row_get_header (row) != NULL)
+    gtk_list_box_row_set_header (row, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
+
+  else
+    gtk_list_box_row_set_header (row, NULL);
+}
+
+
+static void
+add_child (gpointer provider_info, gpointer user_data)
+{
+  BjbSettingsDialog           *self;
+  BjbSettingsDialogPrivate    *priv;
+  const BijiProviderInfo      *info;
+  ProviderChild               *child;
+  GtkWidget                   *box, *w;
+
+  self = BJB_SETTINGS_DIALOG (user_data);
+  priv = self->priv;
+  info = (const BijiProviderInfo*) provider_info;
+
+
+  child = provider_child_new ();
+  child->id = info->unique_id;
+  child->icon = info->icon;
+  child->name = info->name;
+
+
+  // what if (child->id != NULL && g_strcmp0 (child->id, "") != 0)
+
+
+  /* Is the provider the primary ? */
+  if (g_strcmp0 (child->id, bjb_settings_get_default_location (priv->settings)) ==0)
+    child->selected = TRUE;
+
+  /* Create the widget */
+
+  child->widget = box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+  child->overlay = gtk_overlay_new ();
+  gtk_container_add (GTK_CONTAINER (priv->box), child->overlay);
+  gtk_container_add (GTK_CONTAINER (child->overlay), box);
+
+
+  g_object_set_qdata_full (G_OBJECT (child->overlay), application_quark (),
+                           child, provider_child_free);
+
+  w = child->icon;
+  gtk_widget_set_margin_left (w, 12);
+  gtk_container_add (GTK_CONTAINER (box), w);
+
+
+  w = gtk_label_new (child->name);
+  gtk_widget_set_margin_right (w, 180);
+  gtk_container_add (GTK_CONTAINER (box), w);
+  gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
+  gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0);
+
+  self->priv->children = g_list_prepend (priv->children, child);
+  gtk_widget_show_all (box);
+}
+
+
+GtkWidget *
+create_page_primary (BjbSettingsDialog *self)
+{
+  BjbSettingsDialogPrivate *priv;
+  GList *providers_info;
+
+  priv = self->priv;
+  priv->box = GTK_LIST_BOX (gtk_list_box_new ());
+
+  /* Create the list */
+
+  gtk_list_box_set_selection_mode (priv->box, GTK_SELECTION_NONE);
+  gtk_list_box_set_header_func (priv->box, header_func, NULL, NULL);
+
+  g_signal_connect (priv->box, "row-activated",
+                    G_CALLBACK (on_row_activated_cb), self);
+
+
+  /* Add providers */
+
+  providers_info = biji_note_book_get_providers (priv->book);
+  g_list_foreach (providers_info, add_child, self);
+  g_list_free (providers_info);
+
+
+  /* Check GSettings : toggle the actual default provider */
+  update_providers (self);
+
+  return GTK_WIDGET (priv->box);
+}
+
+
+
+
+/* Edition page (font, color) */
+
+
+GtkWidget *
+create_page_edition (BjbSettings *settings)
+{
+  GtkWidget                  *grid, *label, *picker;
+  GdkRGBA                    color;
+
+  grid = gtk_grid_new ();
+  gtk_grid_set_column_spacing (GTK_GRID (grid), 36);
+  gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
+  gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
+
+
+  /* Default font */
+  label = gtk_label_new (_("Note Font"));
+  gtk_widget_set_halign (label, GTK_ALIGN_END);
+  gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1);
+  picker = gtk_font_button_new_with_font (bjb_settings_get_default_font (settings));
+  g_signal_connect (picker, "font-set",
+                    G_CALLBACK (on_font_selected), settings);
+  gtk_grid_attach (GTK_GRID (grid), picker, 2, 1, 1, 1);
+
+
+
+  /* Default color */
+  label = gtk_label_new (_("Default Color"));
+  gtk_widget_set_halign (label, GTK_ALIGN_END);
+  gtk_grid_attach (GTK_GRID (grid), label, 1, 2, 1, 1);
+
+  picker = bjb_color_button_new ();
+  gdk_rgba_parse (&color, bjb_settings_get_default_color (settings));
+  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (picker), &color);
+  g_signal_connect (picker, "color-set",
+                    G_CALLBACK (on_color_set), settings); 
+  gtk_grid_attach (GTK_GRID (grid), picker, 2, 2, 1, 1);
+
+  return grid;
+}
+
+
+
+/* Packaging */
+
+static void
+bjb_settings_dialog_constructed (GObject *object)
+{
+  BjbSettingsDialog          *self;
+  GtkDialog                  *dialog; //also self
+  BjbSettingsDialogPrivate   *priv;
+  GtkWidget                  *area, *grid, *hbox, *page;
+  GtkWindow                  *window;
+  GApplication               *app;
+
+
+  G_OBJECT_CLASS (bjb_settings_dialog_parent_class)->constructed (object);
+
+  self = BJB_SETTINGS_DIALOG (object);
+  dialog = GTK_DIALOG (self);
+  window = GTK_WINDOW (self);
+  priv = self->priv;
+
+
+  app = g_application_get_default ();
+  priv->book = bijiben_get_book (BIJIBEN_APPLICATION (app));
+  priv->settings = bjb_app_get_settings (app);
+
+
+  gtk_window_set_default_size (window, 500, 300);
+  gtk_window_set_modal (window, TRUE);
+  gtk_dialog_add_button (dialog, _("_Close"), GTK_RESPONSE_CLOSE);
+
+
+  /* Dialog Area */
+  area = gtk_dialog_get_content_area (dialog);
+  gtk_container_set_border_width (GTK_CONTAINER (area), 38);
+
+  priv->stack = GTK_STACK (gtk_stack_new ());
+  gtk_widget_set_hexpand (GTK_WIDGET (priv->stack), TRUE);
+  gtk_widget_set_vexpand (GTK_WIDGET (priv->stack), TRUE);
+
+  priv->switcher = GTK_STACK_SWITCHER (gtk_stack_switcher_new ());
+  hbox = gtk_grid_new ();
+  gtk_widget_set_vexpand (hbox, TRUE);
+  gtk_grid_attach (GTK_GRID (hbox), GTK_WIDGET (priv->switcher), 1, 1, 1, 1);
+  gtk_widget_set_valign (GTK_WIDGET (priv->switcher), GTK_ALIGN_CENTER);
+  gtk_stack_switcher_set_stack (priv->switcher, priv->stack);
+
+  grid = gtk_grid_new ();
+  gtk_container_add (GTK_CONTAINER (area),grid);
+  gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
+  gtk_widget_set_valign (GTK_WIDGET (priv->switcher), GTK_ALIGN_START);
+  gtk_grid_attach (GTK_GRID (grid), GTK_WIDGET (priv->stack), 1, 2, 1, 1);
+  gtk_widget_set_valign (GTK_WIDGET (priv->stack), GTK_ALIGN_CENTER);
+
+
+  /* Dialog Pages */
+  page = create_page_edition (priv->settings);
+  gtk_widget_set_vexpand (page, TRUE);
+  gtk_stack_add_titled (priv->stack, page, "edition", _("Note Edition"));
+
+  page = create_page_primary (self);
+  gtk_stack_add_titled (priv->stack, page, "provider", _("Primary Book"));
+
+  gtk_widget_show_all (area);
+} 
+
+
+
+static void
+bjb_settings_dialog_finalize (GObject *object)
+{
+  BjbSettingsDialog *self;
+
+  g_return_if_fail (BJB_IS_SETTINGS_DIALOG (object));
+
+  self = BJB_SETTINGS_DIALOG (object);
+  //g_list_free_full (self->priv->children, provider_child_free); uh?
+  g_list_free (self->priv->children);
+
+  G_OBJECT_CLASS (bjb_settings_dialog_parent_class)->finalize (object);
+}
+
+
+static void
+bjb_settings_dialog_get_property (GObject    *object,
+                                  guint       prop_id,
+                                  GValue     *value,
+                                  GParamSpec *pspec)
+{
+  BjbSettingsDialog *self = BJB_SETTINGS_DIALOG (object);
+
+  switch (prop_id)
+  {            
+    case PROP_PARENT:
+      g_value_set_object (value, self->priv->parent);
+      break;
+                                
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+bjb_settings_dialog_set_property (GObject      *object,
+                                  guint         prop_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+  BjbSettingsDialog *self = BJB_SETTINGS_DIALOG (object);
+
+  switch (prop_id)
+  {
+    case PROP_PARENT:
+      self->priv->parent = g_value_get_object (value);
+      break;
+            
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+bjb_settings_dialog_init (BjbSettingsDialog *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BJB_TYPE_SETTINGS_DIALOG, BjbSettingsDialogPrivate);
+}
+
+
+
+static void
+bjb_settings_dialog_class_init (BjbSettingsDialogClass *klass)
+{
+  GObjectClass *g_object_class;
+
+  g_object_class = G_OBJECT_CLASS (klass);
+
+  g_object_class->set_property = bjb_settings_dialog_set_property;
+  g_object_class->get_property = bjb_settings_dialog_get_property;
+  g_object_class->finalize = bjb_settings_dialog_finalize;
+  g_object_class->constructed = bjb_settings_dialog_constructed;
+
+  g_type_class_add_private ((gpointer)klass, sizeof (BjbSettingsDialogPrivate));
+
+  g_object_class_install_property (g_object_class,PROP_PARENT,
+                                   g_param_spec_object ("parent",
+                                                        "Parent Window",
+                                                        "Parent Window Transient For",
+                                                        GTK_TYPE_WINDOW,
+                                                        G_PARAM_READWRITE | 
+                                                        G_PARAM_STATIC_STRINGS));
+}
+
+
+GtkDialog *
+bjb_settings_dialog_new (GtkWidget *parent_window)
+{
+  return g_object_new (BJB_TYPE_SETTINGS_DIALOG, "parent", parent_window, NULL);
+}
diff --git a/src/bjb-settings-dialog.h b/src/bjb-settings-dialog.h
new file mode 100644
index 0000000..ae75d80
--- /dev/null
+++ b/src/bjb-settings-dialog.h
@@ -0,0 +1,61 @@
+/*
+ * bjb_settings_dialog.h
+ * 
+ * Copyright © 2013 Pierre-Yves LUYTEN <py luyten fr>
+ *
+ * bijiben 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.
+ *
+ * bijiben 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 BJB_SETTINGS_DIALOG_H_
+#define BJB_SETTINGS_DIALOG_H_ 1
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+
+#define BJB_TYPE_SETTINGS_DIALOG             (bjb_settings_dialog_get_type ())
+#define BJB_SETTINGS_DIALOG(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), BJB_TYPE_SETTINGS_DIALOG, 
BjbSettingsDialog))
+#define BJB_SETTINGS_DIALOG_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), BJB_TYPE_SETTINGS_DIALOG, 
BjbSettingsDialogClass))
+#define BJB_IS_SETTINGS_DIALOG(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BJB_TYPE_SETTINGS_DIALOG))
+#define BJB_IS_SETTINGS_DIALOG_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), BJB_TYPE_SETTINGS_DIALOG))
+#define BJB_SETTINGS_DIALOG_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), BJB_TYPE_SETTINGS_DIALOG, 
BjbSettingsDialogClass))
+
+typedef struct BjbSettingsDialog_         BjbSettingsDialog;
+typedef struct BjbSettingsDialogClass_    BjbSettingsDialogClass;
+typedef struct BjbSettingsDialogPrivate_  BjbSettingsDialogPrivate;
+
+struct BjbSettingsDialog_
+{
+  GtkDialog parent;
+  BjbSettingsDialogPrivate *priv;
+};
+
+
+struct BjbSettingsDialogClass_
+{
+  GtkDialogClass parent_class;
+};
+
+
+GType                  bjb_settings_dialog_get_type            (void);
+
+
+GtkDialog             *bjb_settings_dialog_new                 (GtkWidget *window);
+
+
+G_END_DECLS
+
+#endif /* BJB_SETTINGS_DIALOG_H_ */
diff --git a/src/bjb-settings.c b/src/bjb-settings.c
index cca2d90..137477a 100644
--- a/src/bjb-settings.c
+++ b/src/bjb-settings.c
@@ -14,33 +14,39 @@
  * 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 "config.h"
+
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
 #include "bjb-bijiben.h"
-#include "bjb-color-button.h"
 #include "bjb-settings.h"
+#include "bjb-settings-dialog.h"
+
 
 struct _BjbSettingsPrivate
 {
-  GSettings *settings ;
+  /* Note edition settings */
+  gchar *font;
+  gchar *color;
+
+  /* Default Provider */
+  gchar *primary;
 };
 
-// Properties binded to gsettings.
+
 enum
 {
   PROP_0,
-
-  // Note Editor.
   PROP_FONT,
   PROP_COLOR,
-
+  PROP_PRIMARY,
   N_PROPERTIES
 };
 
 #define BJB_SETTINGS_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BJB_TYPE_SETTINGS, BjbSettingsPrivate))
 
-G_DEFINE_TYPE (BjbSettings, bjb_settings, G_TYPE_OBJECT);
+G_DEFINE_TYPE (BjbSettings, bjb_settings, G_TYPE_SETTINGS);
 
 static void
 bjb_settings_init (BjbSettings *object)
@@ -66,11 +72,15 @@ bjb_settings_get_property (GObject    *object,
   switch (prop_id)
   {            
     case PROP_FONT:
-      g_value_set_string (value,settings->font);
+      g_value_set_string (value, settings->priv->font);
       break;
 
     case PROP_COLOR:
-      g_value_set_string (value,settings->color);
+      g_value_set_string (value, settings->priv->color);
+      break;
+
+    case PROP_PRIMARY:
+      g_value_set_string (value, settings->priv->primary);
       break;
                                 
     default:
@@ -90,11 +100,15 @@ bjb_settings_set_property (GObject      *object,
   switch (prop_id)
   {
     case PROP_FONT:
-      settings->font = g_value_dup_string(value) ; 
+      settings->priv->font = g_value_dup_string(value) ; 
       break;
 
     case PROP_COLOR:
-      settings->color = g_value_dup_string(value);
+      settings->priv->color = g_value_dup_string(value);
+      break;
+
+    case PROP_PRIMARY:
+      settings->priv->primary = g_value_dup_string (value);
       break;
             
     default:
@@ -103,6 +117,33 @@ bjb_settings_set_property (GObject      *object,
   }
 }
 
+
+static void
+bjb_settings_constructed (GObject *object)
+{
+  BjbSettings *self;
+  GSettings   *settings;
+
+  G_OBJECT_CLASS (bjb_settings_parent_class)->constructed (object);
+
+  self = BJB_SETTINGS (object);
+  settings = G_SETTINGS (object);
+
+
+  g_settings_bind  (settings, "font",
+                    self,     "font",
+                    G_SETTINGS_BIND_DEFAULT);
+
+  g_settings_bind  (settings, "color",
+                    self,     "color",
+                    G_SETTINGS_BIND_DEFAULT);
+
+  g_settings_bind  (settings,  "default-location",
+                    self,      "default-location",
+                    G_SETTINGS_BIND_DEFAULT);
+}
+
+
 static void
 bjb_settings_class_init (BjbSettingsClass *klass)
 {
@@ -110,6 +151,7 @@ bjb_settings_class_init (BjbSettingsClass *klass)
 
   g_type_class_add_private (klass, sizeof (BjbSettingsPrivate));
 
+  object_class->constructed = bjb_settings_constructed;
   object_class->finalize = bjb_settings_finalize;
   object_class->get_property = bjb_settings_get_property;
   object_class->set_property = bjb_settings_set_property;
@@ -129,118 +171,54 @@ bjb_settings_class_init (BjbSettingsClass *klass)
                                                        NULL,
                                                        G_PARAM_READWRITE | 
                                                        G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (object_class,PROP_PRIMARY,
+                                   g_param_spec_string("default-location",
+                                                       "Primary Location",
+                                                       "Default Provider for New Notes",
+                                                       NULL,
+                                                       G_PARAM_READWRITE | 
+                                                       G_PARAM_STATIC_STRINGS));
 }
 
-// only init from bijiben
+
+
 
 BjbSettings *
-initialize_settings (void)
+bjb_settings_new (void)
 {
-  BjbSettings *result = g_object_new (BJB_TYPE_SETTINGS,NULL) ;
-  result->priv->settings= g_settings_new ("org.gnome.bijiben");
-
-  // Note editor settings
-  g_settings_bind  (result->priv->settings, "font",
-                    result,"font",
-                    G_SETTINGS_BIND_DEFAULT);
+  return g_object_new (BJB_TYPE_SETTINGS, "schema-id", "org.gnome.bijiben", NULL);
+}
 
-  g_settings_bind  (result->priv->settings, "color",
-                    result,"color",
-                    G_SETTINGS_BIND_DEFAULT);
 
-  return result ;
-}
 
-static void
-on_font_selected (GtkFontButton *widget,
-                  BjbSettings *settings)
+gchar *
+bjb_settings_get_default_font           (BjbSettings *settings)
 {
-  g_settings_set_string (settings->priv->settings,
-                         "font",
-                         gtk_font_button_get_font_name (widget));
+  return settings->priv->font;
 }
 
-static void
-on_color_set (GtkColorButton *button,
-              BjbSettings *settings)
-{
-  GdkRGBA color;
-  gchar *color_str;
 
-  gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &color);
-  color_str = gdk_rgba_to_string (&color);
+gchar *
+bjb_settings_get_default_color          (BjbSettings *settings)
+{
+  return settings->priv->color;
+}
 
-  g_settings_set_string (settings->priv->settings,
-                         "color",
-                         color_str);
 
-  g_free (color_str);
+gchar *
+bjb_settings_get_default_location       (BjbSettings *settings)
+{
+  return settings->priv->primary;
 }
 
+
 void
 show_bijiben_settings_window (GtkWidget *parent_window)
 {
-  GtkWidget *dialog,*area, *vbox, *hbox, *grid, *label, *picker;
-  GdkRGBA color;
-  gint width, height;
-
-  GApplication *app = g_application_get_default();
-  BjbSettings *settings = bjb_app_get_settings(app);
-
-  /* create dialog */
-  dialog = gtk_dialog_new_with_buttons (_("Preferences"),
-                                        GTK_WINDOW(parent_window),
-                                        GTK_DIALOG_MODAL| 
-                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                        _("_Close"),
-                                        GTK_RESPONSE_OK,
-                                        NULL);
-
-  gtk_window_get_size (GTK_WINDOW (parent_window), &width, &height);
-  gtk_window_set_default_size (GTK_WINDOW (dialog),
-                               width /2,
-                               height /2);
-
-  area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-  gtk_container_set_border_width (GTK_CONTAINER (area), 0);
-  gtk_widget_set_hexpand (area, TRUE);
-  gtk_widget_set_vexpand (area, TRUE);
-
-  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-  gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER);
-
-  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
-  gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
-
-  grid = gtk_grid_new ();
-  gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
-  gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
-  gtk_box_pack_start (GTK_BOX (hbox), grid, TRUE, FALSE, 0);
-
-  /* Note Font */
-  label = gtk_label_new (_("Note Font"));
-  gtk_widget_set_halign (label, GTK_ALIGN_END);
-  gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1);
-  picker = gtk_font_button_new_with_font (settings->font);
-  g_signal_connect(picker,"font-set",
-                   G_CALLBACK(on_font_selected),settings);
-  gtk_grid_attach (GTK_GRID (grid), picker, 2, 1, 1, 1);
-
-  /* Default Color */
-  label = gtk_label_new (_("Default Color"));
-  gtk_widget_set_halign (label, GTK_ALIGN_END);
-  gtk_grid_attach (GTK_GRID (grid), label, 1, 2, 1, 1);
-  picker = bjb_color_button_new ();
-  gtk_grid_attach (GTK_GRID (grid), picker, 2, 2, 1, 1);
-  gdk_rgba_parse (&color, settings->color );
-  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (picker), &color);
-  g_signal_connect (picker, "color-set",
-                    G_CALLBACK(on_color_set), settings);
-
-  /* pack, show, run, kill */
-  gtk_box_pack_start (GTK_BOX (area), vbox, TRUE, TRUE, 0);
-  gtk_widget_show_all (dialog);
-  gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_destroy (dialog);
+  GtkDialog *dialog;
+
+  dialog = bjb_settings_dialog_new (parent_window);
+  /* result = */ gtk_dialog_run (dialog);
+  gtk_widget_destroy (GTK_WIDGET (dialog));
 }
diff --git a/src/bjb-settings.h b/src/bjb-settings.h
index 087f04a..e83d931 100644
--- a/src/bjb-settings.h
+++ b/src/bjb-settings.h
@@ -20,6 +20,8 @@
 
 #include <glib-object.h>
 
+
+
 G_BEGIN_DECLS
 
 #define BJB_TYPE_SETTINGS             (bjb_settings_get_type ())
@@ -36,24 +38,32 @@ typedef struct _BjbSettingsPrivate BjbSettingsPrivate;
 
 struct _BjbSettingsClass
 {
-  GObjectClass parent_class;
+  GSettingsClass parent_class;
 };
 
 struct _BjbSettings
 {
-  GObject parent_instance;
-  BjbSettingsPrivate *priv ;
-
-  /* Note edition settings */
-  gchar *font ;
-  gchar *color ;
+  GSettings parent_instance;
+  BjbSettingsPrivate *priv;
 };
 
-GType bjb_settings_get_type (void) G_GNUC_CONST;
 
-BjbSettings * initialize_settings(void);
+GType             bjb_settings_get_type                   (void) G_GNUC_CONST;
+
+
+BjbSettings      *bjb_settings_new                        (void);
+
+
+gchar            *bjb_settings_get_default_font           (BjbSettings *settings);
+
+
+gchar            *bjb_settings_get_default_color          (BjbSettings *settings);
+
+
+gchar            *bjb_settings_get_default_location       (BjbSettings *settings);
+
 
-void show_bijiben_settings_window (GtkWidget *parent_window);
+void              show_bijiben_settings_window            (GtkWidget *parent_window);
 
 G_END_DECLS
 


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