[bijiben] Import Notes: move to an initial UI (external data app menu item)



commit 818d5b614302f1a2695e2db8d5d8221b924027f2
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Mon Nov 19 22:30:41 2012 +0100

    Import Notes: move to an initial UI (external data app menu item)

 src/bjb-app-menu.c          |   57 ++++++++++++++++++++++++++++++++++++
 src/bjb-bijiben.c           |   67 ++++++++++++++++++++++++++++++++++--------
 src/bjb-bijiben.h           |    5 ++-
 src/bjb-settings.c          |    6 +--
 src/libbiji/biji-note-obj.c |    2 +-
 src/resources/app-menu.ui   |    4 ++
 6 files changed, 121 insertions(+), 20 deletions(-)
---
diff --git a/src/bjb-app-menu.c b/src/bjb-app-menu.c
index effed0f..cff0cad 100644
--- a/src/bjb-app-menu.c
+++ b/src/bjb-app-menu.c
@@ -42,6 +42,62 @@ new_activated (GSimpleAction *action,
 }
 
 static void
+import_gnote_notes (Bijiben *self)
+{
+  import_notes (self, "gnote");
+}
+
+static void
+import_tomboy_notes (Bijiben *self)
+{
+  import_notes (self, "tomboy");
+}
+
+static void
+external_activated (GSimpleAction *action,
+                    GVariant      *parameter,
+                    gpointer       user_data)
+{
+  GtkWidget *dialog, *area, *hbox, *button;
+  GList *windows;
+  Bijiben *app = BIJIBEN_APPLICATION (user_data);
+
+  windows = gtk_application_get_windows (GTK_APPLICATION(user_data));
+  
+  dialog = gtk_dialog_new_with_buttons ("External data",
+                                        g_list_nth_data (windows, 0),
+                                        GTK_DIALOG_MODAL| 
+                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                        GTK_STOCK_OK,
+                                        GTK_RESPONSE_OK,
+                                        NULL);
+
+  /* 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);
+
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 20);
+  gtk_box_pack_start (GTK_BOX (area), hbox, TRUE, FALSE, 2);
+  button = gtk_button_new_with_label ("Import Tomboy Notes");
+  g_signal_connect_swapped (button, "clicked",
+                            G_CALLBACK (import_tomboy_notes), app);
+  gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, FALSE, 2);
+
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 20);
+  gtk_box_pack_start (GTK_BOX (area), hbox, TRUE, FALSE, 2);
+  button = gtk_button_new_with_label ("Import GNote Notes");
+  g_signal_connect_swapped (button, "clicked",
+                            G_CALLBACK (import_gnote_notes), app);
+  gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, FALSE, 2);
+
+  gtk_widget_show_all (dialog);
+  gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_destroy (dialog);
+}
+
+static void
 preferences_activated (GSimpleAction *action,
                        GVariant      *parameter,
                        gpointer       user_data)
@@ -87,6 +143,7 @@ quit_activated (GSimpleAction *action,
 
 static GActionEntry app_entries[] = {
            { "new", new_activated, NULL, NULL, NULL },
+           { "external", external_activated, NULL, NULL, NULL },
            { "preferences", preferences_activated, NULL, NULL, NULL },
            { "about", about_activated, NULL, NULL, NULL },
            { "help", help_activated, NULL, NULL, NULL },
diff --git a/src/bjb-bijiben.c b/src/bjb-bijiben.c
index d3004c1..69f7919 100644
--- a/src/bjb-bijiben.c
+++ b/src/bjb-bijiben.c
@@ -112,10 +112,14 @@ copy_note_file (GFileInfo *info,
                 GFile *dir,
                 GFile *dest)
 {
+  Bijiben *self;
+  BijiNoteObj *note_obj;
   GFile *note, *result;
   const gchar *name;
-  gchar *path;
+  gchar *path, *default_color;
   GError *error = NULL;
+  BjbSettings *settings;
+  GdkRGBA color;
 
   name = g_file_info_get_name (info);
   if (!g_str_has_suffix (name, ".note"))
@@ -127,7 +131,6 @@ copy_note_file (GFileInfo *info,
 
   path = g_build_filename (g_file_get_path(dest), name, NULL);
   result = g_file_new_for_path (path);
-  g_free (path);
 
   g_file_copy (note, result, G_FILE_COPY_NOFOLLOW_SYMLINKS,
                NULL,NULL, NULL, &error);
@@ -138,6 +141,22 @@ copy_note_file (GFileInfo *info,
      g_error_free (error);
   }
 
+  self = BIJIBEN_APPLICATION (g_application_get_default ());
+  note_obj = biji_note_get_new_from_file (path);
+
+  /* Sanitize color
+   * This is done here in Bijiben because
+   * default color is app choice */
+  settings = bjb_app_get_settings (self);
+  g_object_get (G_OBJECT(settings),"color", &default_color, NULL);
+  gdk_rgba_parse (&color, default_color);
+  g_free (default_color);
+  biji_note_obj_set_rgba (note_obj, &color);
+
+  /* Append the note refreshes main view */
+  note_book_append_new_note (self->priv->book, note_obj);
+
+  g_free (path);
   g_object_unref (note);
   g_object_unref (result);
 }
@@ -160,21 +179,46 @@ list_notes_to_copy (GFileEnumerator *enumerator,
 }
 
 static void
-import_notes_from_x (GFile *bijiben_dir, gchar *app)
+import_notes_from_x (GFile *bijiben_dir, gchar *path)
 {
-  gchar *from;
   GFile *to_import;
   GFileEnumerator *enumerator;
 
-  from = g_build_filename (g_get_user_data_dir (), app, NULL);
-  to_import = g_file_new_for_path (from);
-  g_free (from);
-
-  enumerator = g_file_enumerate_children (to_import,ATTRIBUTES_FOR_NOTEBOOK,
-                                                G_PRIORITY_DEFAULT, NULL,NULL);
+  to_import = g_file_new_for_path (path);
+  enumerator = g_file_enumerate_children (to_import,
+                                          ATTRIBUTES_FOR_NOTEBOOK,
+                                          G_PRIORITY_DEFAULT, NULL,NULL);
 
   list_notes_to_copy (enumerator, bijiben_dir);
   g_object_unref (enumerator);
+  g_object_unref (to_import);
+}
+
+void
+import_notes (Bijiben *self, gchar *location)
+{
+  gchar *storage_path, *path_to_import;
+  GFile *bjb_dir;
+
+  storage_path = g_build_filename (g_get_user_data_dir (), "bijiben", NULL);
+  bjb_dir = g_file_new_for_path (storage_path);
+  g_free (storage_path);
+
+  if (g_strcmp0 (location, "tomboy") ==0)
+  {
+    path_to_import = g_build_filename (g_get_user_data_dir (), "tomboy", NULL);
+    import_notes_from_x (bjb_dir, path_to_import);
+    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 (bjb_dir, path_to_import);
+    g_free (path_to_import);
+  }
+
+  g_object_unref (bjb_dir);
 }
 
 static void
@@ -215,12 +259,9 @@ bijiben_startup (GApplication *application)
     g_error_free (error);
   }
 
-  /* First run, import tomboy gnote for testing */
   else
   {
     self->priv->first_run = TRUE;
-    import_notes_from_x (storage, "tomboy");
-    import_notes_from_x (storage, "gnote");
   }
 
   self->priv->book = biji_note_book_new (storage);
diff --git a/src/bjb-bijiben.h b/src/bjb-bijiben.h
index ac43436..26bc581 100644
--- a/src/bjb-bijiben.h
+++ b/src/bjb-bijiben.h
@@ -60,8 +60,9 @@ BijiNoteBook * bijiben_get_book(Bijiben *self);
 BjbSettings * bjb_app_get_settings(gpointer application);
 
 // Windows
-void bijiben_new_window_for_note (GApplication *app,
-								  BijiNoteObj *note);
+void bijiben_new_window_for_note (GApplication *app, BijiNoteObj *note);
+
+void import_notes (Bijiben *self, gchar *location);
 
 G_END_DECLS
 
diff --git a/src/bjb-settings.c b/src/bjb-settings.c
index cf9db38..635d379 100644
--- a/src/bjb-settings.c
+++ b/src/bjb-settings.c
@@ -170,7 +170,8 @@ show_bijiben_settings_window (GtkWidget *parent_window)
   GdkRGBA color;
   gint width, height;
 
-  BjbSettings *settings = bjb_app_get_settings(g_application_get_default());
+  GApplication *app = g_application_get_default();
+  BjbSettings *settings = bjb_app_get_settings(app);
 
   /* create dialog */
   dialog = gtk_dialog_new_with_buttons("Notes tag",
@@ -219,9 +220,6 @@ show_bijiben_settings_window (GtkWidget *parent_window)
   gtk_notebook_append_page(GTK_NOTEBOOK(notebook),page,
                            gtk_label_new("Note Editor"));
 
-  /* External data Page */
-  // TODO
-
   /* pack, show, run, kill */
   gtk_box_pack_start (GTK_BOX (area), notebook, TRUE, TRUE,2);
   gtk_widget_show_all(dialog);
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 43229dc..dd3b5c3 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -344,7 +344,7 @@ biji_note_obj_trash (BijiNoteObj *note_to_kill)
   g_free (backup_path);
   result = g_file_move (to_trash,
                         backup_file,
-                        G_FILE_COPY_NONE,
+                        G_FILE_COPY_OVERWRITE,
                         NULL, // cancellable
                         NULL, // progress callback
                         NULL, // progress_callback_data,
diff --git a/src/resources/app-menu.ui b/src/resources/app-menu.ui
index 5de8ff6..6605428 100644
--- a/src/resources/app-menu.ui
+++ b/src/resources/app-menu.ui
@@ -6,6 +6,10 @@
         <attribute name="action">app.new</attribute>
         <attribute name="accel">&lt;Primary&gt;n</attribute>
       </item>
+      <item>
+        <attribute name="label" translatable="yes">_External data</attribute>
+        <attribute name="action">app.external</attribute>
+      </item>
     </section>
     <section>
       <item>



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