[gnome-calendar/calendar-management] source-manager: finish sources.local action implementation



commit e610e362fea0ebd002f9430068354a10107cade1
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Feb 5 16:10:19 2015 -0200

    source-manager: finish sources.local action implementation
    
    It now really creates sources from local files. Yay!

 src/gcal-source-manager-dialog.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/src/gcal-source-manager-dialog.c b/src/gcal-source-manager-dialog.c
index 4c64531..e50e76c 100644
--- a/src/gcal-source-manager-dialog.c
+++ b/src/gcal-source-manager-dialog.c
@@ -18,6 +18,7 @@
 
 #include "gcal-source-manager-dialog.h"
 
+#include "e-source-local.h"
 #include "gcal-manager.h"
 #include "gcal-utils.h"
 
@@ -311,10 +312,13 @@ file_action_activated (GSimpleAction *menu_item,
                        GVariant      *value,
                        gpointer       user_data)
 {
+  GcalSourceManagerDialogPrivate *priv;
   GtkWidget *dialog;
   GtkFileFilter *filter;
   gint response;
 
+  priv = gcal_source_manager_dialog_get_instance_private (GCAL_SOURCE_MANAGER_DIALOG (user_data));
+
   // file chooser dialog
   dialog = gtk_file_chooser_dialog_new (_("Open File"), GTK_WINDOW (user_data), GTK_FILE_CHOOSER_ACTION_OPEN,
                                         _("_Cancel"), GTK_RESPONSE_CANCEL, _("_Open"), GTK_RESPONSE_ACCEPT, 
NULL);
@@ -340,6 +344,8 @@ file_action_activated (GSimpleAction *menu_item,
    */
   if (response == GTK_RESPONSE_ACCEPT)
     {
+      ESourceExtension *ext;
+      ESource *new_source;
       GFile *file;
       gchar *filename;
 
@@ -350,7 +356,26 @@ file_action_activated (GSimpleAction *menu_item,
 
       filename = g_file_get_basename (file);
 
-      /* TODO: create the source */
+      /* new source */
+      new_source = e_source_new (NULL, NULL, NULL);
+
+      e_source_set_display_name (new_source, filename);
+      e_source_set_parent (new_source, "local-stub");
+
+      /**
+       * Getting a extension that does not exists creates it
+       * in to the source.
+       */
+      ext = e_source_get_extension (new_source, E_SOURCE_EXTENSION_CALENDAR);
+      e_source_backend_set_backend_name (E_SOURCE_BACKEND (ext), "local");
+
+      g_type_ensure (E_TYPE_SOURCE_LOCAL);
+
+      ext = e_source_get_extension (new_source, E_SOURCE_EXTENSION_LOCAL_BACKEND);
+      e_source_local_set_custom_file (E_SOURCE_LOCAL (ext), file);
+
+      /* Create the source */
+      gcal_manager_save_source (priv->manager, new_source);
 
       g_free (filename);
       g_object_unref (file);


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