[bijiben/wip/sadiq/modernize: 10/10] import-dialog: Rewrite logic and port to GtkBuilder



commit 3932042e14ca1a5ef96c38aaadb0de1139277d2a
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Tue Nov 21 10:24:44 2017 +0530

    import-dialog: Rewrite logic and port to GtkBuilder
    
    * Port to GtkBuilder xml ui definitions
    * Create locations list only when asked for one.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790750

 data/bjb.gresource.xml          |    1 +
 data/resources/import-dialog.ui |  260 ++++++++++++++++++++++++
 po/POTFILES.in                  |    2 +-
 src/bjb-app-menu.c              |    2 +-
 src/bjb-import-dialog.c         |  426 +++++++++------------------------------
 5 files changed, 359 insertions(+), 332 deletions(-)
---
diff --git a/data/bjb.gresource.xml b/data/bjb.gresource.xml
index df3f768..950cbb6 100644
--- a/data/bjb.gresource.xml
+++ b/data/bjb.gresource.xml
@@ -17,5 +17,6 @@
   <gresource prefix="/org/gnome/bijiben/ui">
     <file alias="settings-dialog.ui">resources/settings-dialog.ui</file>
     <file alias="empty-results-box.ui">resources/empty-results-box.ui</file>
+    <file alias="import-dialog.ui" preprocess="xml-stripblanks">resources/import-dialog.ui</file>
   </gresource>
 </gresources>
diff --git a/data/resources/import-dialog.ui b/data/resources/import-dialog.ui
new file mode 100644
index 0000000..9656cc2
--- /dev/null
+++ b/data/resources/import-dialog.ui
@@ -0,0 +1,260 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="BjbImportDialog" parent="GtkDialog">
+    <property name="modal">1</property>
+    <property name="title" translatable="yes">Import Notes</property>
+    <property name="width-request">500</property>
+    <property name="resizable">0</property>
+
+    <child type="action">
+      <object class="GtkButton" id="cancel_button">
+        <property name="visible">1</property>
+        <property name="label" translatable="yes">_Cancel</property>
+        <property name="use-underline">1</property>
+      </object>
+    </child>
+
+    <child type="action">
+      <object class="GtkButton" id="import_button">
+        <property name="visible">1</property>
+        <property name="sensitive">0</property>
+        <property name="can-default">1</property>
+        <property name="label" translatable="yes">_Import</property>
+        <property name="use-underline">1</property>
+      </object>
+    </child>
+
+    <child internal-child="vbox">
+      <object class="GtkBox" id="action_area">
+        <property name="visible">1</property>
+        <property name="orientation">vertical</property>
+        <property name="hexpand">1</property>
+        <property name="vexpand">1</property>
+        <property name="border-width">2</property>
+        <property name="margin-start">12</property>
+        <property name="margin-top">12</property>
+
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">1</property>
+            <property name="halign">start</property>
+            <property name="label" translatable="yes">Select import location</property>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkFrame" id="frame">
+            <property name="visible">1</property>
+            <child>
+              <object class="GtkListBox" id="box">
+                <property name="visible">1</property>
+                <property name="selection-mode">none</property>
+                <signal name="row-activated" handler="on_row_activated_cb" object="BjbImportDialog" 
swapped="no"/>
+
+                <!-- Gnote Application -->
+                <child>
+                  <object class="GtkListBoxRow" id="gnote_import">
+                    <property name="visible">0</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="visible">1</property>
+                        <property name="name">gnote</property>
+                        <property name="margin-top">6</property>
+                        <property name="margin-bottom">6</property>
+                        <property name="margin-start">12</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <object class="GtkImage">
+                            <property name="visible">1</property>
+                            <property name="icon-name">folder-documents-symbolic</property>
+                            <property name="pixel-size">24</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="gnote_label">
+                            <property name="visible">1</property>
+                            <property name="xalign">0</property>
+                            <property name="halign">start</property>
+                            <property name="label" translatable="yes">Gnote application</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkStack" id="gnote_stack">
+                            <property name="visible">1</property>
+                            <property name="halign">start</property>
+                            <property name="expand">1</property>
+                            <child>
+                              <object class="GtkImage">
+                                <property name="visible">1</property>
+                                <property name="opacity">0</property>
+                              </object>
+                              <packing>
+                                <property name="name">empty</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkImage" id="image1">
+                                <property name="visible">1</property>
+                                <property name="icon-name">object-select-symbolic</property>
+                                <property name="pixel-size">32</property>
+                              </object>
+                              <packing>
+                                <property name="name">tick</property>
+                              </packing>
+                            </child>
+                          </object>
+                        </child> <!-- ./GtkStack gnote_stack -->
+                      </object>
+                    </child>
+                  </object>
+                </child>
+
+                <!-- Tomboy Application -->
+                <child>
+                  <object class="GtkListBoxRow" id="tomboy_import">
+                    <property name="visible">0</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="visible">1</property>
+                        <property name="name">tomboy</property>
+                        <property name="margin-top">6</property>
+                        <property name="margin-bottom">6</property>
+                        <property name="margin-start">12</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <object class="GtkImage">
+                            <property name="visible">1</property>
+                            <property name="icon-name">folder-documents-symbolic</property>
+                            <property name="pixel-size">24</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="tomboy_label">
+                            <property name="visible">1</property>
+                            <property name="halign">start</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">Tomboy application</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkStack" id="tomboy_stack">
+                            <property name="visible">1</property>
+                            <property name="halign">start</property>
+                            <property name="expand">1</property>
+                            <child>
+                              <object class="GtkImage">
+                                <property name="visible">1</property>
+                                <property name="opacity">0</property>
+                              </object>
+                              <packing>
+                                <property name="name">empty</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkImage" id="image2">
+                                <property name="visible">1</property>
+                                <property name="icon-name">object-select-symbolic</property>
+                                <property name="pixel-size">32</property>
+                              </object>
+                              <packing>
+                                <property name="name">tick</property>
+                              </packing>
+                            </child>
+                          </object>
+                        </child>  <!-- ./GtkStack tomboy_stack -->
+                      </object>
+                    </child>
+                  </object>
+                </child>
+
+                <!-- Custom Directory -->
+                <child>
+                  <object class="GtkBox" id="custom_import">
+                    <property name="visible">1</property>
+                    <property name="margin-top">6</property>
+                    <property name="margin-bottom">6</property>
+                    <property name="margin-start">12</property>
+                    <property name="spacing">12</property>
+                    <property name="name">custom</property>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="visible">1</property>
+                        <property name="icon-name">folder-visiting-symbolic</property>
+                        <property name="pixel-size">24</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="custom_label">
+                        <property name="visible">1</property>
+                        <property name="sensitive">0</property>
+                        <property name="halign">start</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Custom Location</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkStack" id="custom_stack">
+                        <property name="visible">1</property>
+                        <property name="halign">start</property>
+                        <property name="expand">1</property>
+                        <child>
+                          <object class="GtkImage">
+                            <property name="visible">1</property>
+                            <property name="opacity">0</property>
+                          </object>
+                          <packing>
+                            <property name="name">empty</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkImage">
+                            <property name="visible">1</property>
+                            <property name="icon-name">object-select-symbolic</property>
+                            <property name="pixel-size">32</property>
+                          </object>
+                          <packing>
+                            <property name="name">tick</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child> <!-- ./GtkStack custom_stack -->
+                    <child>
+                      <object class="GtkFileChooserButton">
+                        <property name="visible">1</property>
+                        <property name="title" translatable="yes">Select a Folder</property>
+                        <property name="action">select-folder</property>
+                        <signal name="current-folder-changed" handler="on_file_set_cb" 
object="BjbImportDialog" swapped="no"/>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">1</property>
+            <property name="fill">0</property>
+            <property name="padding">6</property>
+          </packing>
+        </child>
+
+      </object>
+    </child>
+
+    <action-widgets>
+      <action-widget response="cancel">cancel_button</action-widget>
+      <action-widget response="ok" default="true">import_button</action-widget>
+    </action-widgets>
+  </template>
+
+  <object class="GtkSizeGroup">
+    <property name="mode">horizontal</property>
+    <widgets>
+      <widget name="gnote_label"/>
+      <widget name="tomboy_label"/>
+      <widget name="custom_label"/>
+    </widgets>
+  </object>
+
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d0e80ee..e350b89 100755
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ data/org.gnome.bijiben.xml.in
 data/resources/app-menu.ui
 data/resources/editor-toolbar.ui
 data/resources/empty-results-box.ui
+data/resources/import-dialog.ui
 data/resources/settings-dialog.ui
 src/bijiben-shell-search-provider.c
 src/bjb-application.c
@@ -13,7 +14,6 @@ src/bjb-app-menu.c
 src/bjb-color-button.c
 src/bjb-editor-toolbar.c
 src/bjb-empty-results-box.c
-src/bjb-import-dialog.c
 src/bjb-load-more-button.c
 src/bjb-main-toolbar.c
 src/bjb-main-view.c
diff --git a/src/bjb-app-menu.c b/src/bjb-app-menu.c
index dff6324..17f99c0 100644
--- a/src/bjb-app-menu.c
+++ b/src/bjb-app-menu.c
@@ -79,7 +79,7 @@ external_activated (GSimpleAction *action,
       g_free (uri);
     }
 
-    g_list_free (locations);
+    g_list_free_full (locations, g_free);
   }
 
   if (dialog)
diff --git a/src/bjb-import-dialog.c b/src/bjb-import-dialog.c
index cf5adde..74f4d41 100644
--- a/src/bjb-import-dialog.c
+++ b/src/bjb-import-dialog.c
@@ -21,7 +21,6 @@
  *
  * - better label for dialog (pango for head label)
  * - maybe align diffrently
- * - we check if apps are installed. rather check for notes...
  * - we might also trigger spinner view when import runs
  */
 
@@ -36,409 +35,163 @@
 #define IMPORT_EMBLEM_WIDTH 32
 #define IMPORT_EMBLEM_HEIGHT 32
 
-
-typedef struct
+typedef enum
 {
-  GtkWidget     *overlay;
-  GtkWidget     *widget;
-  GtkWidget     *toggle;
-
-  gboolean       selected;
-  gchar         *location;
-
-} ImportDialogChild;
+  IMPORT_DIALOG_ITEM_TOMBOY = 1 << 0,
+  IMPORT_DIALOG_ITEM_GNOTE  = 1 << 1,
+  IMPORT_DIALOG_ITEM_CUSTOM = 1 << 2,
+} ImportDialogItem;
 
 
 struct _BjbImportDialog
 {
-  GtkDialog             parent_instance;
-
-  GtkListBox           *box;
+  GtkDialog parent_instance;
 
+  GtkWidget *import_button;
 
-  /* Select spec. foder */
+  GtkWidget *gnote_label;
+  GtkWidget *gnote_stack;
+  GtkWidget *gnote_import;
 
-  GtkWidget            *cust_box;
-  GtkWidget            *browser;
-  ImportDialogChild    *custom;
+  GtkWidget *tomboy_label;
+  GtkWidget *tomboy_stack;
+  GtkWidget *tomboy_import;
 
-  /* paths and Confirm button */
+  GtkWidget *custom_label;
+  GtkWidget *custom_stack;
+  GtkWidget *custom_import;
 
-  GHashTable           *locations;
-  GtkWidget            *go_go_go;
+  gchar *custom_location;
+  ImportDialogItem items;
 };
 
 
 G_DEFINE_TYPE (BjbImportDialog, bjb_import_dialog, GTK_TYPE_DIALOG)
 
 
-
-static ImportDialogChild *
-import_dialog_child_new (void)
-{
-  ImportDialogChild *retval = g_slice_new (ImportDialogChild);
-
-  retval->overlay = NULL;
-  retval->widget = NULL;
-  retval->toggle = NULL;
-
-  retval->selected = FALSE;
-  retval->location = NULL;
-
-  return retval;
-}
-
-
 static void
-import_dialog_child_free (ImportDialogChild *child)
-{
-  g_free (child->location);
-  g_slice_free (ImportDialogChild, 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 (void)
-{
-  GtkWidget *w;
-
-  w = gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_INVALID);
-  gtk_image_set_pixel_size (GTK_IMAGE (w), 38);
-  gtk_widget_show (w);
-  return w;
-}
-
-
-/* row_activated
- * When an item is activated
- * Check for the location
- * Show or delete the visible toggle
- * Add or remove location from import paths */
-
-static void
-toggle_widget (BjbImportDialog *self,
-               GObject         *widget)
-{
-  ImportDialogChild *child;
-  GtkStyleContext *context;
-  GList *keys;
-
-  child = g_object_get_qdata (widget, application_quark ());
-
-  if (!child->selected && child->location == NULL)
-    return;
-
-  child->selected = !child->selected;
-
-
-  if (child->selected)
-  {
-    child->toggle = child_toggle_new ();
-    gtk_overlay_add_overlay (GTK_OVERLAY (child->overlay), child->toggle);
-
-    g_hash_table_add (self->locations, child->location);
-  }
-
+toggle_selection (BjbImportDialog  *self,
+                  GtkWidget        *widget,
+                  ImportDialogItem  item)
+{
+  /* If custom import clicked,  check if location is set */
+  if (item != IMPORT_DIALOG_ITEM_CUSTOM || self->custom_location)
+    self->items ^= item;
+  else /* ie, custom import with no location set */
+    self->items &= self->items ^ IMPORT_DIALOG_ITEM_CUSTOM;
+
+  if (self->items & item)
+    gtk_stack_set_visible_child_name (GTK_STACK (widget), "tick");
   else
-  {
-    if (child->toggle && GTK_IS_WIDGET (child->toggle))
-      gtk_widget_destroy (child->toggle);
-
-    g_hash_table_remove (self->locations, child->location);
-  }
-
-  context = gtk_widget_get_style_context (self->go_go_go);
-  keys = g_hash_table_get_keys (self->locations);
-
-  if (keys)
-  {
-    gtk_style_context_add_class (context, "suggested-action");
-    gtk_widget_set_sensitive (self->go_go_go, TRUE);
-    g_list_free (keys);
-  }
+    gtk_stack_set_visible_child_name (GTK_STACK (widget), "empty");
 
+  if (self->items)
+    gtk_widget_set_sensitive (self->import_button, TRUE);
   else
-  {
-    gtk_widget_set_sensitive (self->go_go_go, FALSE);
-  }
-
-  gtk_widget_reset_style (self->go_go_go);
+    gtk_widget_set_sensitive (self->import_button, FALSE);
 }
 
-
 static void
 on_row_activated_cb    (GtkListBox    *list_box,
                         GtkListBoxRow *row,
                         gpointer       user_data)
 {
-  toggle_widget (user_data, G_OBJECT (gtk_bin_get_child (GTK_BIN (row))));
-}
+  const gchar *widget_name;
+  BjbImportDialog *self = user_data;
 
+  widget_name = gtk_widget_get_name (gtk_bin_get_child (GTK_BIN (row)));
 
-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);
+  if (g_strcmp0 (widget_name, "custom") == 0)
+    toggle_selection (self, self->custom_stack, IMPORT_DIALOG_ITEM_CUSTOM);
+  else if (g_strcmp0 (widget_name, "gnote") == 0)
+    toggle_selection (self, self->gnote_stack, IMPORT_DIALOG_ITEM_GNOTE);
+  else if (g_strcmp0 (widget_name, "tomboy") == 0)
+    toggle_selection (self, self->tomboy_stack, IMPORT_DIALOG_ITEM_TOMBOY);
 }
 
-
 static void
-on_file_set_cb (GtkWidget *chooser,
-                BjbImportDialog *dialog)
+on_file_set_cb (GtkWidget       *chooser,
+                BjbImportDialog *self)
 {
-  gchar *location;
-
-  /* Remove the former */
-
-  if (dialog->custom->location)
-  {
-    g_hash_table_remove (dialog->locations,
-                         dialog->custom->location);
-    g_clear_pointer (&dialog->custom->location, g_free);
-  }
-
-
-  /* Handle the new : force toggle */
-
-  location = dialog->custom->location =
-    gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
-
-  if (location)
-  {
-    gtk_widget_set_sensitive (dialog->cust_box, TRUE);
+  g_clear_pointer (&self->custom_location, g_free);
+  self->custom_location = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
 
-    dialog->custom->selected = FALSE;
-    if (GTK_IS_WIDGET (dialog->custom->toggle))
-      gtk_widget_destroy (dialog->custom->toggle);
+  toggle_selection (self, self->custom_stack, IMPORT_DIALOG_ITEM_CUSTOM);
 
-    toggle_widget (dialog, G_OBJECT (dialog->custom->overlay));
-    return;
-  }
-
-  gtk_widget_set_sensitive (dialog->cust_box, FALSE);
-}
-
-
-static ImportDialogChild *
-add_custom (BjbImportDialog *self)
-{
-  GtkWidget *box, *w;
-  ImportDialogChild *child;
-
-  child = import_dialog_child_new ();
-  child->widget = box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-  gtk_widget_set_margin_top (child->widget, 6);
-  gtk_widget_set_margin_bottom (child->widget, 6);
-  child->overlay = gtk_overlay_new ();
-  gtk_container_add (GTK_CONTAINER (child->overlay), child->widget);
-
-  /* Left group */
-  self->cust_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  gtk_box_pack_start (GTK_BOX (box), self->cust_box, TRUE, FALSE, 0);
-
-  w = gtk_image_new_from_icon_name ("folder-visiting-symbolic", GTK_ICON_SIZE_INVALID);
-  gtk_image_set_pixel_size (GTK_IMAGE (w), 24);
-  gtk_widget_set_margin_start (w, 12);
-  gtk_widget_set_margin_end (w, 12);
-  gtk_container_add (GTK_CONTAINER (self->cust_box), w);
-
-
-  w = gtk_label_new (_("Custom Location"));
-  gtk_widget_set_margin_end (w, 180);
-  gtk_container_add (GTK_CONTAINER (self->cust_box), w);
-  gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
-  gtk_box_pack_start (GTK_BOX (self->cust_box), w, TRUE, FALSE, 0);
-
-  gtk_widget_set_sensitive (self->cust_box, FALSE);
-
-  /* Right group */
-
-  self->browser =
-    gtk_file_chooser_button_new ("", GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
-  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (self->browser),
-                                       g_get_user_data_dir ());
-  gtk_box_pack_start (GTK_BOX (box), self->browser, TRUE, FALSE, 0);
-
-  g_signal_connect (self->browser, "current-folder-changed",
-                    G_CALLBACK (on_file_set_cb), self);
-
-  g_object_set_qdata_full (G_OBJECT (child->overlay), application_quark (),
-                           child, (GDestroyNotify) import_dialog_child_free);
-
-  return child;
-}
-
-
-static ImportDialogChild *
-add_application (const gchar *app,
-                 const gchar *visible_label,
-                 gchar *location)
-{
-  GtkWidget *box, *w;
-  ImportDialogChild *child;
-
-  child = import_dialog_child_new ();
-  child->widget = box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-  gtk_widget_set_margin_top (child->widget, 6);
-  gtk_widget_set_margin_bottom (child->widget, 6);
-  child->overlay = gtk_overlay_new ();
-  child->location = location;
-  gtk_container_add (GTK_CONTAINER (child->overlay), child->widget);
-
-  if (location)
-    g_object_set_qdata_full (G_OBJECT (child->overlay), application_quark (),
-                             child, (GDestroyNotify) import_dialog_child_free);
-
-  w = gtk_image_new_from_icon_name ("folder-documents-symbolic", GTK_ICON_SIZE_INVALID);
-  gtk_image_set_pixel_size (GTK_IMAGE (w), 24);
-  gtk_widget_set_margin_start (w, 12);
-  gtk_container_add (GTK_CONTAINER (box), w);
-
-  w = gtk_label_new (visible_label);
-  gtk_widget_set_margin_end (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);
-
-  gtk_widget_show_all (box);
-  return child;
+  if (self->custom_location)
+    gtk_widget_set_sensitive (self->custom_label, TRUE);
+  else
+    gtk_widget_set_sensitive (self->custom_label, FALSE);
 }
 
-
 static void
 bjb_import_dialog_constructed (GObject *obj)
 {
-  GtkWidget *area, *label_box, *label, *frame;
   gchar *path;
-  GtkApplication *app;
-  ImportDialogChild *child;
-  BjbImportDialog        *self    = BJB_IMPORT_DIALOG (obj);
-  GtkDialog              *dialog  = GTK_DIALOG (obj);
-  GtkWindow              *win     = GTK_WINDOW (obj);
+  BjbImportDialog *self = BJB_IMPORT_DIALOG (obj);
 
   G_OBJECT_CLASS(bjb_import_dialog_parent_class)->constructed(obj);
 
-  /* Don't finalize locations with HashTable
-   * They belong to qdata in gtkwidgets */
-
-  self->locations = g_hash_table_new (g_str_hash, g_str_equal);
-
-  app = GTK_APPLICATION (g_application_get_default ());
-
-  gtk_window_set_transient_for (win, gtk_application_get_active_window (app));
-  gtk_window_set_title (win, _("Import Notes"));
-  gtk_window_set_modal (win, TRUE);
-
-  gtk_header_bar_set_show_close_button (GTK_HEADER_BAR
-    (gtk_dialog_get_header_bar (GTK_DIALOG (self))), TRUE);
-
-
-  self->go_go_go = gtk_dialog_add_button (dialog, _("Import"), GTK_RESPONSE_OK);
-  gtk_widget_set_sensitive (self->go_go_go, FALSE);
-
-  /* Dialog Label */
-  area = gtk_dialog_get_content_area (dialog);
-  gtk_widget_set_margin_start (area, 12);
-  gtk_container_set_border_width (GTK_CONTAINER (area), 2);
-  gtk_widget_set_hexpand (area, TRUE);
-  gtk_widget_set_vexpand (area, TRUE);
-
-  label_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  label = gtk_label_new (_("Select import location"));
-  gtk_widget_set_halign (label, GTK_ALIGN_START);
-  gtk_box_pack_start (GTK_BOX (label_box), label, TRUE, TRUE, 0);
-  gtk_box_pack_start (GTK_BOX (area), label_box, TRUE, FALSE, 12);
-
-  /* Dialog locations to import */
-
-  frame = gtk_frame_new (NULL);
-  self->box = GTK_LIST_BOX (gtk_list_box_new ());
-  gtk_list_box_set_selection_mode (self->box, GTK_SELECTION_NONE);
-  gtk_list_box_set_activate_on_single_click (self->box, TRUE);
-  gtk_list_box_set_header_func (self->box, (GtkListBoxUpdateHeaderFunc) header_func, NULL, NULL);
-  g_signal_connect (self->box, "row-activated", G_CALLBACK (on_row_activated_cb), self);
-  gtk_box_pack_start (GTK_BOX (area), GTK_WIDGET (frame) , TRUE, FALSE, 6);
-
-  gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (self->box));
-
   /*
    * Tomboy and Gnote ~/.local/share are conditional.
-   * These are only packed if their data directories are present.
+   * These are shown only if their data directories are present.
    */
 
   path = g_build_filename (g_get_user_data_dir (), "tomboy", NULL);
-  if (g_file_test (path, G_FILE_TEST_EXISTS))
-    {
-      child = add_application ("tomboy", _("Tomboy application"), path);
-      gtk_container_add (GTK_CONTAINER (self->box), child->overlay);
-    }
-
 
-  path = g_build_filename (g_get_user_data_dir (), "gnote", NULL);
   if (g_file_test (path, G_FILE_TEST_EXISTS))
-    {
-      child = add_application ("gnote", _("Gnote application"), path);
-      gtk_container_add (GTK_CONTAINER (self->box), child->overlay);
-    }
-
-
-  /* User decides path */
+    gtk_widget_show (self->tomboy_import);
 
-  child = self->custom = add_custom (self);
-  gtk_container_add (GTK_CONTAINER (self->box), child->overlay);
+  g_free (path);
+  path = g_build_filename (g_get_user_data_dir (), "gnote", NULL);
 
+  if (g_file_test (path, G_FILE_TEST_EXISTS))
+    gtk_widget_show (self->gnote_import);
 
-  gtk_widget_show_all (GTK_WIDGET (self));
+  g_free (path);
 }
 
 static void
-bjb_import_dialog_finalize (GObject *o)
-{
-  BjbImportDialog *self = BJB_IMPORT_DIALOG (o);
-  g_hash_table_destroy (self->locations);
-
-  G_OBJECT_CLASS (bjb_import_dialog_parent_class)->finalize (o);
-}
-
-
-static void
 bjb_import_dialog_class_init (BjbImportDialogClass *klass)
 {
   GObjectClass* object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   object_class->constructed = bjb_import_dialog_constructed;
-  object_class->finalize = bjb_import_dialog_finalize;
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/bijiben/ui/import-dialog.ui");
+  gtk_widget_class_bind_template_child (widget_class, BjbImportDialog, import_button);
+  gtk_widget_class_bind_template_child (widget_class, BjbImportDialog, gnote_label);
+  gtk_widget_class_bind_template_child (widget_class, BjbImportDialog, gnote_stack);
+  gtk_widget_class_bind_template_child (widget_class, BjbImportDialog, gnote_import);
+  gtk_widget_class_bind_template_child (widget_class, BjbImportDialog, tomboy_label);
+  gtk_widget_class_bind_template_child (widget_class, BjbImportDialog, tomboy_stack);
+  gtk_widget_class_bind_template_child (widget_class, BjbImportDialog, tomboy_import);
+  gtk_widget_class_bind_template_child (widget_class, BjbImportDialog, custom_label);
+  gtk_widget_class_bind_template_child (widget_class, BjbImportDialog, custom_stack);
+  gtk_widget_class_bind_template_child (widget_class, BjbImportDialog, custom_import);
+
+  gtk_widget_class_bind_template_callback (widget_class, on_row_activated_cb);
+  gtk_widget_class_bind_template_callback (widget_class, on_file_set_cb);
 }
 
 
 static void
 bjb_import_dialog_init (BjbImportDialog *self)
 {
+  gtk_widget_init_template (GTK_WIDGET (self));
 }
 
 
 GtkDialog *
 bjb_import_dialog_new (GtkApplication *bijiben)
 {
+  GtkWindow *window;
+
+  window = gtk_application_get_active_window (bijiben);
   return g_object_new (BJB_TYPE_IMPORT_DIALOG,
-                      "use-header-bar", TRUE,
+                       "use-header-bar", TRUE,
+                       "transient-for", window,
                        NULL);
 }
 
@@ -446,5 +199,18 @@ bjb_import_dialog_new (GtkApplication *bijiben)
 GList *
 bjb_import_dialog_get_paths (BjbImportDialog *self)
 {
-  return g_hash_table_get_values (self->locations);
+  GList *list = NULL;
+
+  if (self->items & IMPORT_DIALOG_ITEM_GNOTE)
+    list = g_list_prepend (list, g_build_filename (g_get_user_data_dir (),
+                                                   "gnote", NULL));
+  if (self->items & IMPORT_DIALOG_ITEM_TOMBOY)
+    list = g_list_prepend (list, g_build_filename (g_get_user_data_dir (),
+                                                   "tomboy", NULL));
+  if (self->items & IMPORT_DIALOG_ITEM_CUSTOM &&
+      self->custom_location &&
+      g_list_find_custom (list, self->custom_location, g_str_equal) == NULL)
+    list = g_list_prepend (list, self->custom_location);
+
+  return list;
 }


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