[gnome-todo/gnome-3-24] todo-txt: rework on plugin
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo/gnome-3-24] todo-txt: rework on plugin
- Date: Thu, 1 Jun 2017 20:01:41 +0000 (UTC)
commit 92fb227eb4d587b305dfd13a31e0b241f9f20c66
Author: Rohit Kaushik <kaushikrohit325 gmail com>
Date: Thu May 25 21:10:56 2017 +0530
todo-txt: rework on plugin
plugins/todo-txt/gtd-plugin-todo-txt.c | 158 +++++++++++++-------------------
1 files changed, 65 insertions(+), 93 deletions(-)
---
diff --git a/plugins/todo-txt/gtd-plugin-todo-txt.c b/plugins/todo-txt/gtd-plugin-todo-txt.c
index 4132249..c524d26 100644
--- a/plugins/todo-txt/gtd-plugin-todo-txt.c
+++ b/plugins/todo-txt/gtd-plugin-todo-txt.c
@@ -58,88 +58,13 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (GtdPluginTodoTxt, gtd_plugin_todo_txt, PEAS_TYPE
G_IMPLEMENT_INTERFACE_DYNAMIC (GTD_TYPE_ACTIVATABLE,
gtd_activatable_iface_init))
-static gboolean
-gtd_plugin_todo_txt_set_default_source (GtdPluginTodoTxt *self)
-{
- g_autofree gchar *default_file;
- GError *error;
-
- error = NULL;
- default_file = g_build_filename (g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
- "todo.txt",
- NULL);
- self->source_file = g_file_new_for_path (default_file);
-
- if (g_file_query_exists (self->source_file, NULL))
- return TRUE;
-
- g_file_create (self->source_file,
- G_FILE_CREATE_NONE,
- NULL,
- &error);
-
- if (error)
- {
- gtd_manager_emit_error_message (gtd_manager_get_default (),
- _("Cannot create Todo.txt file"),
- error->message);
-
- g_clear_error (&error);
- return FALSE;
- }
-
- return TRUE;
-}
-
/*
* GtdActivatable interface implementation
*/
static void
gtd_plugin_todo_txt_activate (GtdActivatable *activatable)
{
- GtdPluginTodoTxt *self;
- GtdProviderTodoTxt *provider;
- gchar *source;
- GError *error = NULL;
-
- self = GTD_PLUGIN_TODO_TXT (activatable);
- source = g_settings_get_string (self->settings, "file");
-
- if (!source || source[0] == '\0')
- {
- if (!gtd_plugin_todo_txt_set_default_source (self))
- return;
- }
- else
- {
- self->source_file = g_file_new_for_uri (source);
- }
-
- if (!g_file_query_exists (self->source_file, NULL))
- {
- g_file_create (self->source_file,
- G_FILE_CREATE_NONE,
- NULL,
- &error);
-
- if (error)
- {
- gtd_manager_emit_error_message (gtd_manager_get_default (),
- _("Cannot create Todo.txt file"),
- error->message);
-
- g_clear_error (&error);
- return;
- }
- }
-
- 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);
-
- g_free (source);
- g_clear_error (&error);
+ ;
}
static void
@@ -173,7 +98,6 @@ static GList*
gtd_plugin_todo_txt_get_providers (GtdActivatable *activatable)
{
GtdPluginTodoTxt *plugin = GTD_PLUGIN_TODO_TXT (activatable);
-
return plugin->providers;
}
@@ -192,22 +116,52 @@ gtd_activatable_iface_init (GtdActivatableInterface *iface)
* Init
*/
-static void
-gtd_plugin_todo_txt_source_changed_finished_cb (GtdPluginTodoTxt *self)
+static gboolean
+gtd_plugin_todo_txt_set_default_source (GtdPluginTodoTxt *self)
{
- GtdProviderTodoTxt *provider;
- gchar *source;
- GError *error = NULL;
+ g_autofree gchar *default_file;
+ GError *error;
+
+ error = NULL;
+ default_file = g_build_filename (g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
+ "todo.txt",
+ NULL);
+ self->source_file = g_file_new_for_path (default_file);
+
+ if (g_file_query_exists (self->source_file, NULL))
+ return TRUE;
+
+ g_file_create (self->source_file,
+ G_FILE_CREATE_NONE,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ gtd_manager_emit_error_message (gtd_manager_get_default (),
+ _("Cannot create Todo.txt file"),
+ error->message);
+
+ g_clear_error (&error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+static gboolean
+gtd_plugin_todo_txt_set_source (GtdPluginTodoTxt *self)
+{
+ GError *error;
+ gchar *source;
+
+ error = NULL;
source = g_settings_get_string (self->settings, "file");
if (!source || source[0] == '\0')
{
- gboolean set;
- set = gtd_plugin_todo_txt_set_default_source (self);
-
- if(!set)
- return;
+ if (!gtd_plugin_todo_txt_set_default_source (self))
+ return FALSE;
}
else
{
@@ -228,17 +182,28 @@ gtd_plugin_todo_txt_source_changed_finished_cb (GtdPluginTodoTxt *self)
error->message);
g_clear_error (&error);
- return;
+ return FALSE;
}
}
+ return TRUE;
+}
+
+static void
+gtd_plugin_todo_txt_source_changed_finished_cb (GtdPluginTodoTxt *self)
+{
+ GtdProviderTodoTxt *provider;
+ gboolean set;
+
+ set = gtd_plugin_todo_txt_set_source (self);
+
+ if (!set)
+ return;
+
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);
-
- g_free (source);
- g_clear_error (&error);
}
static void
@@ -269,13 +234,11 @@ gtd_plugin_todo_txt_source_changed_cb (GtkWidget *preference_panel,
gtd_plugin_todo_txt_source_changed_finished_cb (self);
}
-
static void
gtd_plugin_todo_txt_finalize (GObject *object)
{
GtdPluginTodoTxt *self = (GtdPluginTodoTxt *) object;
- g_clear_object (&self->source_file);
g_list_free_full (self->providers, g_object_unref);
self->providers = NULL;
@@ -316,11 +279,20 @@ gtd_plugin_todo_txt_class_init (GtdPluginTodoTxtClass *klass)
static void
gtd_plugin_todo_txt_init (GtdPluginTodoTxt *self)
{
+ GtdProviderTodoTxt *provider;
GtkWidget *label;
+ gboolean set;
self->settings = g_settings_new ("org.gnome.todo.plugins.todo-txt");
+ set = gtd_plugin_todo_txt_set_source (self);
self->providers = NULL;
+ if (set)
+ {
+ provider = gtd_provider_todo_txt_new (self->source_file);
+ self->providers = g_list_append (self->providers, provider);
+ }
+
/* Preferences */
self->preferences_box = g_object_new (GTK_TYPE_BOX,
"margin", 18,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]