[gnome-calendar/calendar-management] source-manager: stub implementation of ::file action



commit 2cc1019e12c4ee597e5549467ffb85f01c302d44
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Feb 3 11:35:40 2015 -0200

    source-manager: stub implementation of ::file action

 src/gcal-source-manager-dialog.c |   74 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/src/gcal-source-manager-dialog.c b/src/gcal-source-manager-dialog.c
index 0bc5cd5..6979529 100644
--- a/src/gcal-source-manager-dialog.c
+++ b/src/gcal-source-manager-dialog.c
@@ -21,6 +21,8 @@
 #include "gcal-manager.h"
 #include "gcal-utils.h"
 
+#include <glib/gi18n.h>
+
 struct _GcalSourceManagerDialogPrivate
 {
   GtkWidget               *add_button;
@@ -52,6 +54,10 @@ enum {
 };
 
 /* callbacks */
+static void     file_action_activated                      (GSimpleAction       *menu_item,
+                                                            GVariant            *value,
+                                                            gpointer             user_data);
+
 static void     display_header_func                        (GtkListBoxRow       *row,
                                                             GtkListBoxRow       *before,
                                                             gpointer             user_data);
@@ -73,6 +79,10 @@ static void     source_removed_cb                          (GcalManager
                                                             ESource             *source,
                                                             gpointer             user_data);
 
+static void     url_action_activated                       (GSimpleAction       *menu_item,
+                                                            GVariant            *value,
+                                                            gpointer             user_data);
+
 /* private */
 static void       fill_sources_list                        (GcalSourceManagerDialog *dialog);
 
@@ -95,6 +105,69 @@ static void     gcal_source_manager_dialog_set_property    (GObject           *o
 G_DEFINE_TYPE_WITH_PRIVATE (GcalSourceManagerDialog, gcal_source_manager_dialog, GTK_TYPE_DIALOG)
 
 /**
+ * file_action_activated:
+ *
+ * Spawns a file chooser dialog with proper
+ * filtering for the user to select a calendar
+ * file.
+ *
+ * Returns:
+ */
+static void
+file_action_activated (GSimpleAction *menu_item,
+                       GVariant      *value,
+                       gpointer       user_data)
+{
+  GtkWidget *dialog;
+  GtkFileFilter *filter;
+  gint response;
+
+  // 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);
+
+  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (user_data));
+
+  // filter non-calendar files
+  filter = gtk_file_filter_new ();
+  gtk_file_filter_set_name (filter, _("Calendars"));
+  gtk_file_filter_add_mime_type (filter, "text/calendar");
+  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+  // wait for the response
+  response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+  /**
+   * Create a source with the selected file.
+   * This source will have the filename as
+   * it's name, and a default color will be
+   * used. Users then will be able to change
+   * these values at their will.
+   */
+  if (response == GTK_RESPONSE_ACCEPT)
+    {
+      GFile *file;
+      gchar *filename;
+
+      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+
+      if (file == NULL)
+        goto out;
+
+      filename = g_file_get_basename (file);
+
+      /* TODO: create the source */
+
+      g_free (filename);
+      g_object_unref (file);
+    }
+
+out:
+  gtk_widget_destroy (dialog);
+}
+
+/**
  * display_header_func:
  *
  * Shows a separator before each row.
@@ -457,6 +530,7 @@ gcal_source_manager_dialog_constructed (GObject *object)
 
   /* sources.file action */
   file_action = g_simple_action_new ("file", NULL);
+  g_signal_connect (file_action, "activate", G_CALLBACK (file_action_activated), object);
   g_action_map_add_action (G_ACTION_MAP (priv->action_group), G_ACTION (file_action));
 
   /* sources.file action */


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