[gnome-todo] todo.txt plugin: move to GFile API



commit 388c8e4e97890f2de7b349c12cb27cd5e901c491
Author: Rohit Kaushik <kaushikrohit325 gmail com>
Date:   Fri Feb 17 20:54:53 2017 +0530

    todo.txt plugin: move to GFile API
    
    Currently gtd-plugin-todo-txt has a source element in the struct
    which stores the todo.txt path. This is not needed and the code
    should make use of GFile API only.
    so the source variable has been removed from the structure in both
    provider and plugin and now we only use source_file.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=778583

 plugins/todo-txt/gtd-plugin-todo-txt.c   |   46 +++++++++++++++++------------
 plugins/todo-txt/gtd-provider-todo-txt.c |   15 ++++------
 plugins/todo-txt/gtd-provider-todo-txt.h |    2 +-
 3 files changed, 34 insertions(+), 29 deletions(-)
---
diff --git a/plugins/todo-txt/gtd-plugin-todo-txt.c b/plugins/todo-txt/gtd-plugin-todo-txt.c
index aac8446..c48bc22 100644
--- a/plugins/todo-txt/gtd-plugin-todo-txt.c
+++ b/plugins/todo-txt/gtd-plugin-todo-txt.c
@@ -33,8 +33,6 @@ struct _GtdPluginTodoTxt
 {
   PeasExtensionBase   parent;
 
-  gchar              *source;
-
   GFile              *source_file;
   GFileMonitor       *monitor;
 
@@ -80,8 +78,7 @@ gtd_plugin_todo_txt_monitor_source (GFileMonitor      *monitor,
 
   g_signal_emit_by_name (self, "provider-removed", provider);
 
-  provider = gtd_provider_todo_txt_new (self->source);
-  self->source_file = g_file_new_for_uri (self->source);
+  provider = gtd_provider_todo_txt_new (self->source_file);
 
   self->providers = g_list_append (self->providers, provider);
   g_signal_emit_by_name (self, "provider-added", provider);
@@ -117,11 +114,10 @@ gtd_plugin_todo_txt_set_default_source (GtdPluginTodoTxt *self)
   gchar *default_file;
   GError *error;
 
-  default_file = g_strconcat (g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS), "todo.txt", NULL);
+  default_file = g_build_filename (g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS), "todo.txt", NULL);
   error = NULL;
 
-  self->source = g_filename_to_uri (default_file, NULL, &error);
-  self->source_file = g_file_new_for_uri (default_file);
+  default_file = g_filename_to_uri (default_file, NULL, &error);
 
   if (error)
     {
@@ -132,6 +128,10 @@ gtd_plugin_todo_txt_set_default_source (GtdPluginTodoTxt *self)
       g_clear_error (&error);
       return FALSE;
     }
+  else
+    {
+      self->source_file = g_file_new_for_uri (default_file);
+    }
 
   if (!g_file_query_exists (self->source_file, NULL))
     {
@@ -161,10 +161,12 @@ gtd_plugin_todo_txt_activate (GtdActivatable *activatable)
 {
   GtdPluginTodoTxt *self;
   GtdProviderTodoTxt *provider;
+  gchar *source;
 
   self = GTD_PLUGIN_TODO_TXT (activatable);
+  source = g_settings_get_string (self->settings, "file");
 
-  if (!self->source || self->source[0] == '\0')
+  if (!source || source[0] == '\0')
     {
       gboolean set;
       set = gtd_plugin_todo_txt_set_default_source (self);
@@ -172,15 +174,19 @@ gtd_plugin_todo_txt_activate (GtdActivatable *activatable)
       if (!set)
         return;
     }
+  else
+    {
+      self->source_file = g_file_new_for_uri (source);
+    }
 
-
-  provider = gtd_provider_todo_txt_new (self->source);
-  self->source_file = g_file_new_for_uri (self->source);
+  provider = gtd_provider_todo_txt_new (self->source_file);
 
   self->providers = g_list_append (self->providers, provider);
   g_signal_emit_by_name (self, "provider-added", provider);
 
   gtd_plugin_todo_txt_load_source_monitor (self);
+
+  g_free (source);
 }
 
 static void
@@ -237,10 +243,11 @@ static void
 gtd_plugin_todo_txt_source_changed_finished_cb (GtdPluginTodoTxt *self)
 {
   GtdProviderTodoTxt *provider;
+  gchar *source;
 
-  self->source = g_settings_get_string (self->settings, "file");
+  source = g_settings_get_string (self->settings, "file");
 
-  if (!self->source || self->source[0] == '\0')
+  if (!source || source[0] == '\0')
     {
       gboolean set;
       set = gtd_plugin_todo_txt_set_default_source (self);
@@ -248,15 +255,19 @@ gtd_plugin_todo_txt_source_changed_finished_cb (GtdPluginTodoTxt *self)
       if(!set)
         return;
     }
+  else
+    {
+      self->source_file = g_file_new_for_uri (source);
+    }
 
-  self->source_file = g_file_new_for_uri (self->source);
-
-  provider = gtd_provider_todo_txt_new (self->source);
+  provider = gtd_provider_todo_txt_new (self->source_file);
   self->providers = g_list_append (self->providers, provider);
 
   gtd_plugin_todo_txt_load_source_monitor (self);
 
   g_signal_emit_by_name (self, "provider-added", provider);
+
+  g_free (source);
 }
 
 static void
@@ -269,7 +280,6 @@ gtd_plugin_todo_txt_source_changed_cb (GtkWidget *preference_panel,
   self = GTD_PLUGIN_TODO_TXT (user_data);
 
   g_clear_object (&self->monitor);
-  g_free (self->source);
   g_clear_object (&self->source_file);
 
   g_settings_set_string (self->settings,
@@ -296,7 +306,6 @@ gtd_plugin_todo_txt_finalize (GObject *object)
   GtdPluginTodoTxt *self = (GtdPluginTodoTxt *) object;
 
   g_clear_object (&self->monitor);
-  g_free (self->source);
   g_clear_object (&self->source_file);
   g_list_free_full (self->providers, g_object_unref);
   self->providers = NULL;
@@ -341,7 +350,6 @@ gtd_plugin_todo_txt_init (GtdPluginTodoTxt *self)
   GtkWidget *label, *frame;
 
   self->settings = g_settings_new ("org.gnome.todo.plugins.todo-txt");
-  self->source = g_settings_get_string (self->settings, "file");
   self->providers = NULL;
 
   /* Preferences */
diff --git a/plugins/todo-txt/gtd-provider-todo-txt.c b/plugins/todo-txt/gtd-provider-todo-txt.c
index 12b6cbe..5fdb320 100644
--- a/plugins/todo-txt/gtd-provider-todo-txt.c
+++ b/plugins/todo-txt/gtd-provider-todo-txt.c
@@ -39,7 +39,6 @@ struct _GtdProviderTodoTxt
   GFileMonitor       *monitor;
   GFile              *source_file;
 
-  gchar              *source;
   GList              *tasklists;
 
   gint                no_of_lines;
@@ -1029,11 +1028,11 @@ gtd_provider_iface_init (GtdProviderInterface *iface)
 }
 
 GtdProviderTodoTxt*
-gtd_provider_todo_txt_new (gchar *source)
+gtd_provider_todo_txt_new (GFile *source_file)
 {
 
   return g_object_new (GTD_TYPE_PROVIDER_TODO_TXT,
-                       "source", source,
+                       "source", source_file,
                        NULL);
 }
 
@@ -1047,7 +1046,6 @@ gtd_provider_todo_txt_finalize (GObject *object)
   g_clear_pointer (&self->tasklists, g_clear_object);
   g_clear_pointer (&self->source_file, g_free);
   g_clear_object (&self->icon);
-  g_clear_pointer (&self->source, g_free);
 
   G_OBJECT_CLASS (gtd_provider_todo_txt_parent_class)->finalize (object);
 }
@@ -1083,7 +1081,7 @@ gtd_provider_todo_txt_get_property (GObject    *object,
       break;
 
     case PROP_SOURCE:
-      g_value_set_string (value, GTD_PROVIDER_TODO_TXT (provider)->source);
+      g_value_set_object (value, GTD_PROVIDER_TODO_TXT (provider)->source_file);
       break;
 
     default:
@@ -1101,8 +1099,7 @@ gtd_provider_todo_txt_set_property (GObject      *object,
   switch (prop_id)
     {
     case PROP_SOURCE:
-      self->source = g_value_dup_string (value);
-      self->source_file = g_file_new_for_uri (self->source);
+      self->source_file = g_value_dup_object (value);
       gtd_provider_todo_txt_load_source (self);
       break;
 
@@ -1122,10 +1119,10 @@ gtd_provider_todo_txt_class_init (GtdProviderTodoTxtClass *klass)
 
   g_object_class_install_property (object_class,
                                    PROP_SOURCE,
-                                   g_param_spec_string ("source",
+                                   g_param_spec_object ("source",
                                                         "Source file",
                                                         "The Todo.txt source file",
-                                                         NULL,
+                                                         G_TYPE_OBJECT,
                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
   g_object_class_override_property (object_class, PROP_DESCRIPTION, "description");
diff --git a/plugins/todo-txt/gtd-provider-todo-txt.h b/plugins/todo-txt/gtd-provider-todo-txt.h
index fe09857..c97d7ac 100644
--- a/plugins/todo-txt/gtd-provider-todo-txt.h
+++ b/plugins/todo-txt/gtd-provider-todo-txt.h
@@ -29,7 +29,7 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GtdProviderTodoTxt, gtd_provider_todo_txt, GTD, PROVIDER_TODO_TXT, GtdObject)
 
-GtdProviderTodoTxt*    gtd_provider_todo_txt_new                     (gchar          *source);
+GtdProviderTodoTxt*    gtd_provider_todo_txt_new                     (GFile         *source_file);
 
 void                   gtd_provider_todo_txt_set_monitor             (GtdProviderTodoTxt *self,
                                                                       GFileMonitor       *monitor);


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