[bijiben] importDialog: start playing with, bug 698326
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] importDialog: start playing with, bug 698326
- Date: Thu, 16 May 2013 00:35:23 +0000 (UTC)
commit c495d15a6134869553804a3c423b7d99d540e02a
Author: Pierre-Yves Luyten <py luyten fr>
Date: Thu May 16 00:22:17 2013 +0200
importDialog: start playing with, bug 698326
EggListBox
Custom location
Allow selecting several imports at once
po/POTFILES.in | 1 +
src/Makefile.am | 2 +
src/bjb-app-menu.c | 177 ++--------------
src/bjb-bijiben.c | 27 +--
src/bjb-bijiben.h | 2 +-
src/bjb-import-dialog.c | 557 +++++++++++++++++++++++++++++++++++++++++++++++
src/bjb-import-dialog.h | 65 ++++++
7 files changed, 648 insertions(+), 183 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e8c075a..826f7bc 100755
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@ 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-main-toolbar.c
src/bjb-note-tag-dialog.c
src/bjb-note-view.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 8b68f11..17767f8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -58,6 +58,8 @@ bijiben_SOURCES = \
bjb-editor-toolbar.h \
bjb-empty-results-box.c \
bjb-empty-results-box.h \
+ bjb-import-dialog.h \
+ bjb-import-dialog.c \
bjb-main.c \
bjb-main-toolbar.c \
bjb-main-toolbar.h \
diff --git a/src/bjb-app-menu.c b/src/bjb-app-menu.c
index 16ee960..1af8b1b 100644
--- a/src/bjb-app-menu.c
+++ b/src/bjb-app-menu.c
@@ -20,6 +20,7 @@
#include "bjb-app-menu.h"
#include "bjb-bijiben.h"
+#include "bjb-import-dialog.h"
#include "bjb-main-view.h"
#include "bjb-settings.h"
#include "bjb-window-base.h"
@@ -58,178 +59,36 @@ new_activated (GSimpleAction *action,
bjb_window_base_switch_to (win, BJB_WINDOW_BASE_MAIN_VIEW);
}
-/* Import external data - TODO : BJB_TYPE_IMPORT_DIALOG.c */
-
-enum {
- IMPORT_DIALOG_ID,
- IMPORT_DIALOG_ICON,
- IMPORT_DIALOG_LABEL,
- IMPORT_DIALOG_N_COLUMNS
-};
-
-enum {
- TOMBOY_EXT_SRC,
- GNOTE_EXT_SRC
-};
-
-/* First try to find the real icon. FIXME Fallback otherwise
- * in case the user has specific install */
-static GdkPixbuf *
-get_app_icon (gchar *app_name)
-{
- gint i;
- GdkPixbuf *retval= NULL;
- const gchar * const *paths = g_get_system_data_dirs ();
- gchar *app_svg = g_strdup_printf ("%s.svg", app_name);
-
- for (i=0; paths[i] != NULL; i++)
- {
- gchar *path;
- GError *error = NULL;
-
- path = g_build_filename (paths[i], "icons", "hicolor",
- "scalable", "apps", app_svg, NULL);
- retval = gdk_pixbuf_new_from_file (path, &error);
- g_free (path);
-
- if (!error && GDK_IS_PIXBUF (retval))
- break;
-
- else
- retval = NULL;
- }
-
- g_free (app_svg);
- return retval;
-}
static void
-on_import_source_activated_cb (GtkTreeView *t_view,
- GtkTreePath *path,
- GtkTreeViewColumn *column,
- GtkWidget *dialog)
-{
- GtkTreeIter iter;
- GtkTreeModel *model = gtk_tree_view_get_model (t_view);
-
- if (gtk_tree_model_get_iter (model, &iter, path))
- {
- GValue value = G_VALUE_INIT;
- gint retval;
- Bijiben *self = BIJIBEN_APPLICATION (g_application_get_default());
-
- gtk_tree_model_get_value (model, &iter, IMPORT_DIALOG_ID, &value);
- retval = g_value_get_int (&value);
- g_value_unset (&value);
-
- switch (retval)
- {
- case TOMBOY_EXT_SRC:
- import_notes (self, "tomboy");
- gtk_widget_destroy (dialog);
- dialog = NULL;
- break;
-
- case GNOTE_EXT_SRC:
- import_notes (self, "gnote");
- gtk_widget_destroy (dialog);
- dialog = NULL;
- break;
-
- default:
- break;
- }
- }
-}
-
-/* TODO : spinner or any notification */
-static void
external_activated (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- GtkWidget *dialog, *area, *label, *t_view;
- GtkListStore *store;
- GtkTreeModel *model;
- GtkTreeIter iter;
- GList *windows;
- GdkPixbuf *app_icon;
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
-
- windows = gtk_application_get_windows (GTK_APPLICATION(user_data));
+ GtkDialog *dialog;
+ gint result;
- dialog = gtk_dialog_new_with_buttons (_("Import Notes"),
- g_list_nth_data (windows, 0),
- GTK_DIALOG_MODAL|
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- NULL);
- gtk_widget_set_size_request (dialog, 320, 280);
-
- /* User chooses which folder to import */
- area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- gtk_container_set_border_width (GTK_CONTAINER (area), 8);
- gtk_widget_set_hexpand (area, TRUE);
- gtk_widget_set_vexpand (area, TRUE);
-
- label = gtk_label_new (_("Import notes from:"));
- gtk_box_pack_start (GTK_BOX (area), label, TRUE, FALSE, 2);
-
- store = gtk_list_store_new (IMPORT_DIALOG_N_COLUMNS,
- G_TYPE_INT,
- GDK_TYPE_PIXBUF,
- G_TYPE_STRING);
- model = GTK_TREE_MODEL (store);
-
- /* Tomboy */
- app_icon = get_app_icon ("tomboy");
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- IMPORT_DIALOG_ID, TOMBOY_EXT_SRC,
- IMPORT_DIALOG_ICON, app_icon,
- IMPORT_DIALOG_LABEL, "Tomboy", -1);
+ dialog = bjb_import_dialog_new (user_data);
+ result = gtk_dialog_run (dialog);
- /* Gnote */
- app_icon = get_app_icon ("gnote");
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- IMPORT_DIALOG_ID, GNOTE_EXT_SRC,
- IMPORT_DIALOG_ICON, app_icon,
- IMPORT_DIALOG_LABEL, "Gnote", -1);
-
- /* Handle the t_view */
- t_view = gtk_tree_view_new_with_model (model);
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (t_view), FALSE);
- g_signal_connect (t_view, "row-activated",
- G_CALLBACK (on_import_source_activated_cb), dialog);
-
- renderer = gtk_cell_renderer_pixbuf_new ();
- column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
- "pixbuf", IMPORT_DIALOG_ICON,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (t_view), column);
+ if (result == GTK_RESPONSE_OK)
+ {
+ GList *locations, *l;
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
- "text", IMPORT_DIALOG_LABEL,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (t_view), column);
+ locations = bjb_import_dialog_get_paths (BJB_IMPORT_DIALOG (dialog));
+ for (l=locations; l!= NULL; l=l->next)
+ {
+ bijiben_import_notes (user_data, l->data);
+ }
- gtk_box_pack_start (GTK_BOX (area), t_view, TRUE, FALSE, 2);
- gtk_widget_show_all (dialog);
- gtk_dialog_run (GTK_DIALOG (dialog));
+ g_list_free (locations);
+ }
if (dialog)
- {
- gtk_widget_destroy (dialog);
- dialog = NULL;
- }
+ g_clear_pointer (&dialog, gtk_widget_destroy);
}
+
static void
preferences_activated (GSimpleAction *action,
GVariant *parameter,
diff --git a/src/bjb-bijiben.c b/src/bjb-bijiben.c
index aea7f98..599c868 100644
--- a/src/bjb-bijiben.c
+++ b/src/bjb-bijiben.c
@@ -239,10 +239,11 @@ list_notes_to_copy (GObject *src_obj, GAsyncResult *res, Bijiben *self)
}
}
-static void
-import_notes_from_x (gchar *x, Bijiben *self)
+
+void
+bijiben_import_notes (Bijiben *self, gchar *location)
{
- GFile *to_import = g_file_new_for_path (x);
+ GFile *to_import = g_file_new_for_path (location);
g_file_enumerate_children_async (to_import, ATTRIBUTES_FOR_NOTEBOOK,
G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT,
@@ -251,26 +252,6 @@ import_notes_from_x (gchar *x, Bijiben *self)
g_object_unref (to_import);
}
-void
-import_notes (Bijiben *self, gchar *location)
-{
- gchar *path_to_import;
-
- if (g_strcmp0 (location, "tomboy") ==0)
- {
- path_to_import = g_build_filename (g_get_user_data_dir (), "tomboy", NULL);
- import_notes_from_x (path_to_import, self);
- g_free (path_to_import);
- }
-
- else if (g_strcmp0 (location, "gnote") ==0)
- {
- path_to_import = g_build_filename (g_get_user_data_dir (), "gnote", NULL);
- import_notes_from_x (path_to_import, self);
- g_free (path_to_import);
- }
-}
-
static void
bijiben_startup (GApplication *application)
{
diff --git a/src/bjb-bijiben.h b/src/bjb-bijiben.h
index 26bc581..d3db73a 100644
--- a/src/bjb-bijiben.h
+++ b/src/bjb-bijiben.h
@@ -62,7 +62,7 @@ BjbSettings * bjb_app_get_settings(gpointer application);
// Windows
void bijiben_new_window_for_note (GApplication *app, BijiNoteObj *note);
-void import_notes (Bijiben *self, gchar *location);
+void bijiben_import_notes (Bijiben *self, gchar *path);
G_END_DECLS
diff --git a/src/bjb-import-dialog.c b/src/bjb-import-dialog.c
new file mode 100644
index 0000000..d6ca841
--- /dev/null
+++ b/src/bjb-import-dialog.c
@@ -0,0 +1,557 @@
+/*
+ * bjb-import-dialog.c
+ * Copyright (C) Pierre-Yves LUYTEN 2013 <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/>.*/
+
+
+/* TODO
+ *
+ * - 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
+ * - code : move import-notes to libbiji completely
+ */
+
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <egg-list-box.h>
+
+#include "bjb-bijiben.h"
+#include "bjb-import-dialog.h"
+
+
+#define IMPORT_EMBLEM_WIDTH 32
+#define IMPORT_EMBLEM_HEIGHT 32
+
+
+
+
+enum {
+ PROP_0,
+ PROP_APPLICATION,
+ NUM_PROPERTIES
+};
+
+
+static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
+
+typedef struct
+{
+ GtkWidget *overlay;
+ GtkWidget *widget;
+ GtkWidget *toggle;
+
+ gboolean selected;
+ gchar *location;
+
+} ImportDialogChild;
+
+
+struct BjbImportDialogPrivate_
+{
+
+ GtkApplication *bijiben;
+ EggListBox *box;
+
+
+ /* Select spec. foder */
+
+ GtkWidget *cust_box;
+ GtkWidget *browser;
+ ImportDialogChild *custom;
+
+ /* paths and Confirm button */
+
+ GHashTable *locations;
+ GtkWidget *go_go_go;
+};
+
+
+G_DEFINE_TYPE (BjbImportDialog, bjb_import_dialog, GTK_TYPE_DIALOG)
+
+
+
+static ImportDialogChild *
+import_dialog_child_new ()
+{
+ 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);
+}
+
+
+/* First try to find the real icon
+ * might use app_info here */
+
+static GdkPixbuf *
+get_app_icon (gchar *app_name)
+{
+ gint i;
+ GdkPixbuf *retval= NULL;
+ const gchar * const *paths = g_get_system_data_dirs ();
+ gchar *app_svg = g_strdup_printf ("%s.svg", app_name);
+
+ for (i=0; paths[i] != NULL; i++)
+ {
+ gchar *path;
+ GError *error = NULL;
+
+ path = g_build_filename (paths[i], "icons", "hicolor",
+ "scalable", "apps", app_svg, NULL);
+ retval = gdk_pixbuf_new_from_file (path, &error);
+ g_free (path);
+
+ if (!error && GDK_IS_PIXBUF (retval))
+ break;
+
+ else
+ retval = NULL;
+ }
+
+ g_free (app_svg);
+ return retval;
+}
+
+
+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), 38);
+ gtk_widget_show (w);
+ return w;
+}
+
+
+/* toggle_child
+ * 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_child (EggListBox *list_box,
+ GtkWidget *selected,
+ BjbImportDialog *self)
+{
+ BjbImportDialogPrivate *priv = self->priv;
+ ImportDialogChild *child;
+ GtkStyleContext *context;
+ GList *keys;
+
+ child = g_object_get_qdata (G_OBJECT (selected), 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 (priv->locations, child->location);
+ }
+
+ else
+ {
+ if (child->toggle && GTK_IS_WIDGET (child->toggle))
+ gtk_widget_destroy (child->toggle);
+
+ g_hash_table_remove (priv->locations, child->location);
+ }
+
+ context = gtk_widget_get_style_context (priv->go_go_go);
+ keys = g_hash_table_get_keys (priv->locations);
+
+ if (keys)
+ {
+ gtk_style_context_add_class (context, "suggested-action");
+ gtk_widget_set_sensitive (priv->go_go_go, TRUE);
+ g_list_free (keys);
+ }
+
+ else
+ {
+ gtk_style_context_remove_class (context, "suggested-action");
+ }
+
+ gtk_widget_reset_style (priv->go_go_go);
+}
+
+
+static void
+separator_func (GtkWidget** separator,
+ GtkWidget* child,
+ GtkWidget* before,
+ void* user_data)
+{
+ if (*separator == NULL && before != NULL)
+ {
+ *separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+
+ g_object_ref_sink (*separator);
+ gtk_widget_show (*separator);
+ }
+}
+
+
+static void
+on_file_set_cb (GtkWidget *chooser,
+ BjbImportDialog *dialog)
+{
+ gchar *location;
+ g_warning ("on file set");
+
+ /* Remove the former */
+
+ if (dialog->priv->custom->location)
+ {
+ g_warning ("on file set : former was %s ", dialog->priv->custom->location);
+ g_hash_table_remove (dialog->priv->locations,
+ dialog->priv->custom->location);
+ g_clear_pointer (&dialog->priv->custom->location, g_free);
+ }
+
+
+ /* Handle the new : force toggle */
+
+ location = dialog->priv->custom->location =
+ gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
+
+ if (location)
+ {
+ g_warning ("file set a location : %s", location);
+ gtk_widget_set_sensitive (dialog->priv->cust_box, TRUE);
+
+ dialog->priv->custom->selected = FALSE;
+ if (GTK_IS_WIDGET (dialog->priv->custom->toggle))
+ gtk_widget_destroy (dialog->priv->custom->toggle);
+
+ toggle_child (dialog->priv->box, dialog->priv->custom->overlay, dialog);
+ return;
+ }
+
+ gtk_widget_set_sensitive (dialog->priv->cust_box, FALSE);
+}
+
+
+static ImportDialogChild *
+add_custom (BjbImportDialog *self)
+{
+ BjbImportDialogPrivate *priv;
+ GtkWidget *box, *w;
+ ImportDialogChild *child;
+
+ priv = self->priv;
+ child = import_dialog_child_new ();
+ child->widget = box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ child->overlay = gtk_overlay_new ();
+ gtk_container_add (GTK_CONTAINER (child->overlay), child->widget);
+
+ /* Left group */
+ priv->cust_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_box_pack_start (GTK_BOX (box), priv->cust_box, TRUE, FALSE, 0);
+
+ w = gtk_image_new_from_icon_name ("folder-symbolic", GTK_ICON_SIZE_INVALID);
+ gtk_image_set_pixel_size (GTK_IMAGE (w), 38);
+ gtk_widget_set_margin_left (w, 12);
+ gtk_container_add (GTK_CONTAINER (priv->cust_box), w);
+
+
+ w = gtk_label_new (_("Custom Location"));
+ gtk_widget_set_margin_right (w, 180);
+ gtk_container_add (GTK_CONTAINER (priv->cust_box), w);
+ gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
+ gtk_box_pack_start (GTK_BOX (priv->cust_box), w, TRUE, FALSE, 0);
+
+ gtk_widget_set_sensitive (priv->cust_box, FALSE);
+
+ /* Right group */
+
+ priv->browser =
+ gtk_file_chooser_button_new ("", GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->browser),
+ g_get_user_data_dir ());
+ gtk_box_pack_start (GTK_BOX (box), priv->browser, TRUE, FALSE, 0);
+
+ g_signal_connect (priv->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 (gchar *app,
+ gchar *visible_label,
+ gchar *location)
+{
+ GtkWidget *box, *w;
+ GdkPixbuf *pix;
+ ImportDialogChild *child;
+
+ child = import_dialog_child_new ();
+ child->widget = box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ 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);
+
+ /* If the icon is not found, consider the app is not installed
+ * to avoid the dialog showing the feature */
+
+ pix = get_app_icon (app);
+
+ if (pix == NULL)
+ {
+ g_object_ref_sink (box);
+ import_dialog_child_free (child);
+ return NULL;
+ }
+
+ w = gtk_image_new_from_pixbuf (pix);
+ gtk_widget_set_margin_left (w, 12);
+ gtk_container_add (GTK_CONTAINER (box), w);
+
+
+ w = gtk_label_new (visible_label);
+ 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);
+
+ gtk_widget_show_all (box);
+ return child;
+}
+
+
+static void
+bjb_import_dialog_constructed (GObject *obj)
+{
+ G_OBJECT_CLASS(bjb_import_dialog_parent_class)->constructed(obj);
+
+ GtkWidget *area, *label_box, *label;
+ gchar *path;
+ GList *windows;
+ ImportDialogChild *child;
+ BjbImportDialog *self = BJB_IMPORT_DIALOG (obj);
+ GtkDialog *dialog = GTK_DIALOG (obj);
+ GtkWindow *win = GTK_WINDOW (obj);
+ BjbImportDialogPrivate *priv = self->priv;
+
+ /* Don't finalize locations with HashTable
+ * They belong to qdata in gtkwidgets */
+
+ priv->locations = g_hash_table_new (g_str_hash, g_str_equal);
+
+ windows = gtk_application_get_windows (priv->bijiben);
+
+ gtk_window_set_transient_for (win, g_list_nth_data (windows, 0));
+ gtk_window_set_title (win, _("Import Notes"));
+ gtk_window_set_modal (win, TRUE);
+
+ gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+
+ priv->go_go_go = gtk_dialog_add_button (dialog, _("Import"), GTK_RESPONSE_OK);
+ gtk_widget_set_sensitive (priv->go_go_go, FALSE);
+
+ /* Dialog Label */
+ area = gtk_dialog_get_content_area (dialog);
+ gtk_widget_set_margin_left (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 */
+
+ priv->box = egg_list_box_new ();
+ egg_list_box_set_selection_mode (priv->box, GTK_SELECTION_NONE);
+ egg_list_box_set_activate_on_single_click (priv->box, TRUE);
+ egg_list_box_set_separator_funcs (priv->box, separator_func, NULL, NULL);
+ gtk_box_pack_start (GTK_BOX (area), GTK_WIDGET (priv->box) , TRUE, FALSE, 6);
+ g_signal_connect (priv->box, "child-activated",
+ G_CALLBACK (toggle_child), self);
+
+
+ /* Tomboy Gnote ~/.local/share are conditional
+ * these are only packed if app is installed */
+
+ path = g_build_filename (g_get_user_data_dir (), "tomboy", NULL);
+ child = add_application ("tomboy", _("Tomboy application"), path);
+ if (child)
+ gtk_container_add (GTK_CONTAINER (priv->box), child->overlay);
+
+
+ path = g_build_filename (g_get_user_data_dir (), "gnote", NULL);
+ child = add_application ("gnote", _("Gnote application"), path);
+ if (child)
+ gtk_container_add (GTK_CONTAINER (priv->box), child->overlay);
+
+
+ /* User decides path */
+
+ child = priv->custom = add_custom (self);
+ gtk_container_add (GTK_CONTAINER (priv->box), child->overlay);
+
+
+ gtk_widget_show_all (GTK_WIDGET (self));
+}
+
+
+static void
+bjb_import_dialog_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ BjbImportDialog *self = BJB_IMPORT_DIALOG (object);
+
+ switch (property_id)
+ {
+ case PROP_APPLICATION:
+ g_value_set_object (value, self->priv->bijiben);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+static void
+bjb_import_dialog_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ BjbImportDialog *self = BJB_IMPORT_DIALOG (object);
+
+ switch (property_id)
+ {
+ case PROP_APPLICATION:
+ self->priv->bijiben = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+bjb_import_dialog_finalize (GObject *o)
+{
+ BjbImportDialog *self = BJB_IMPORT_DIALOG (o);
+ g_hash_table_destroy (self->priv->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);
+ g_type_class_add_private (klass, sizeof (BjbImportDialogPrivate));
+
+
+ object_class->get_property = bjb_import_dialog_get_property;
+ object_class->set_property = bjb_import_dialog_set_property;
+ object_class->constructed = bjb_import_dialog_constructed;
+ object_class->finalize = bjb_import_dialog_finalize;
+
+ properties[PROP_APPLICATION] =
+ g_param_spec_object ("application",
+ "Application",
+ "Bijiben Application",
+ GTK_TYPE_APPLICATION,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
+}
+
+
+static void
+bjb_import_dialog_init (BjbImportDialog *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BJB_TYPE_IMPORT_DIALOG, BjbImportDialogPrivate);
+}
+
+
+GtkDialog *
+bjb_import_dialog_new (GtkApplication *bijiben)
+{
+ return g_object_new (BJB_TYPE_IMPORT_DIALOG,
+ "application",
+ bijiben,
+ NULL);
+}
+
+
+GList *
+bjb_import_dialog_get_paths (BjbImportDialog *dialog)
+{
+ return g_hash_table_get_values (dialog->priv->locations);
+}
diff --git a/src/bjb-import-dialog.h b/src/bjb-import-dialog.h
new file mode 100644
index 0000000..8900829
--- /dev/null
+++ b/src/bjb-import-dialog.h
@@ -0,0 +1,65 @@
+/*
+ * bjb-import-dialog.h
+ * Copyright (C) Pierre-Yves LUYTEN 2013 <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_IMPORT_DIALOG_H_
+#define BJB_IMPORT_DIALOG_H_ 1
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+
+#define BJB_TYPE_IMPORT_DIALOG (bjb_import_dialog_get_type ())
+#define BJB_IMPORT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BJB_TYPE_IMPORT_DIALOG,
BjbImportDialog))
+#define BJB_IMPORT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BJB_TYPE_IMPORT_DIALOG,
BjbImportDialogClass))
+#define BJB_IS_IMPORT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BJB_TYPE_IMPORT_DIALOG))
+#define BJB_IS_IMPORT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BJB_TYPE_IMPORT_DIALOG))
+#define BJB_IMPORT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BJB_TYPE_IMPORT_DIALOG,
BjbImportDialogClass))
+
+typedef struct BjbImportDialog_ BjbImportDialog;
+typedef struct BjbImportDialogClass_ BjbImportDialogClass;
+typedef struct BjbImportDialogPrivate_ BjbImportDialogPrivate;
+
+
+struct BjbImportDialog_
+{
+ GtkDialog parent;
+ BjbImportDialogPrivate *priv;
+};
+
+
+struct BjbImportDialogClass_
+{
+ GtkDialogClass parent_class;
+};
+
+
+GType bjb_import_dialog_get_type (void);
+
+
+GtkDialog * bjb_import_dialog_new (GtkApplication *bijiben);
+
+
+GList * bjb_import_dialog_get_paths (BjbImportDialog *dialog);
+
+
+G_END_DECLS
+
+#endif /* BJB_IMPORT_DIALOG_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]