[gnome-todo] gtd-manager: allow pass an action to emit-error-message



commit 9320437b8bd79854f0c7ebeefc293204beb3f69a
Author: Kevin Lopez <kevin kevlopez com>
Date:   Fri Apr 28 04:30:38 2017 +0200

    gtd-manager: allow pass an action to emit-error-message
    
    gtd-manager-emit-error-message function only allows pass a primary and a
    secondary text to the notification.
    
    This patch allows pass an action to the above function as well as change
    the text of the notification's button.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=778960

 plugins/eds/gtd-plugin-eds.c             |    4 +-
 plugins/eds/gtd-provider-eds.c           |   32 +++++++++++----
 plugins/eds/gtd-provider-local.c         |    4 +-
 plugins/todo-txt/gtd-plugin-todo-txt.c   |   20 +++++++--
 plugins/todo-txt/gtd-provider-todo-txt.c |   32 +++++++++++----
 plugins/todo-txt/gtd-todo-txt-parser.c   |   12 ++++-
 src/engine/gtd-manager.c                 |   34 ++++++++++-----
 src/engine/gtd-manager.h                 |   65 ++++++++++++++++-------------
 src/gtd-window.c                         |   26 ++++++++----
 9 files changed, 155 insertions(+), 74 deletions(-)
---
diff --git a/plugins/eds/gtd-plugin-eds.c b/plugins/eds/gtd-plugin-eds.c
index 534c4eb..824fbca 100644
--- a/plugins/eds/gtd-plugin-eds.c
+++ b/plugins/eds/gtd-plugin-eds.c
@@ -245,7 +245,9 @@ gtd_plugin_eds_goa_client_finish_cb (GObject      *client,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error loading GNOME Online Accounts"),
-                                      error->message);
+                                      error->message,
+                                      NULL,
+                                      NULL);
       g_clear_error (&error);
     }
 }
diff --git a/plugins/eds/gtd-provider-eds.c b/plugins/eds/gtd-provider-eds.c
index 1be1fcb..97214d5 100644
--- a/plugins/eds/gtd-provider-eds.c
+++ b/plugins/eds/gtd-provider-eds.c
@@ -134,7 +134,9 @@ gtd_provider_eds_fill_task_list (GObject      *client,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error fetching tasks from list"),
-                                      error->message);
+                                      error->message,
+                                      NULL,
+                                      NULL);
       g_error_free (error);
       return;
     }
@@ -171,7 +173,9 @@ gtd_provider_eds_on_client_connected (GObject      *source_object,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Failed to connect to task list"),
-                                      error->message);
+                                      error->message,
+                                      NULL,
+                                      NULL);
 
       g_error_free (error);
       return;
@@ -589,7 +593,9 @@ gtd_provider_eds_create_task_finished (GObject      *client,
       /* Display a notification */
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error creating task"),
-                                      error->message);
+                                      error->message,
+                                      NULL,
+                                      NULL);
 
       g_error_free (error);
     }
@@ -633,7 +639,9 @@ gtd_provider_eds_update_task_finished (GObject      *client,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error updating task"),
-                                      error->message);
+                                      error->message,
+                                      NULL,
+                                      NULL);
 
       g_error_free (error);
     }
@@ -669,7 +677,9 @@ gtd_provider_eds_remove_task_finished (GObject      *client,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error removing task"),
-                                      error->message);
+                                      error->message,
+                                      NULL,
+                                      NULL);
       g_error_free (error);
       return;
     }
@@ -697,7 +707,9 @@ gtd_provider_eds_remote_create_source_finished (GObject      *source,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error creating task list"),
-                                      error->message);
+                                      error->message,
+                                      NULL,
+                                      NULL);
       g_clear_error (&error);
     }
 }
@@ -720,7 +732,9 @@ task_list_removal_finished (GtdProvider *provider,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error removing task list"),
-                                      (*error)->message);
+                                      (*error)->message,
+                                      NULL,
+                                      NULL);
       g_clear_error (error);
     }
 }
@@ -781,7 +795,9 @@ gtd_provider_eds_commit_source_finished (GObject      *registry,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error saving task list"),
-                                      error->message);
+                                      error->message,
+                                      NULL,
+                                      NULL);
       g_error_free (error);
       return;
     }
diff --git a/plugins/eds/gtd-provider-local.c b/plugins/eds/gtd-provider-local.c
index 168877a..245bc0d 100644
--- a/plugins/eds/gtd-provider-local.c
+++ b/plugins/eds/gtd-provider-local.c
@@ -136,7 +136,9 @@ gtd_provider_local_create_task_list (GtdProvider *provider,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error creating new task list"),
-                                      error->message);
+                                      error->message,
+                                      NULL,
+                                      NULL);
 
       g_clear_error (&error);
       return;
diff --git a/plugins/todo-txt/gtd-plugin-todo-txt.c b/plugins/todo-txt/gtd-plugin-todo-txt.c
index fd95eb0..14f2ed8 100644
--- a/plugins/todo-txt/gtd-plugin-todo-txt.c
+++ b/plugins/todo-txt/gtd-plugin-todo-txt.c
@@ -90,7 +90,9 @@ gtd_plugin_todo_txt_monitor_source (GFileMonitor      *monitor,
         {
           gtd_manager_emit_error_message (gtd_manager_get_default (),
                                           _("Cannot create Todo.txt file"),
-                                          error->message);
+                                          error->message,
+                                          NULL,
+                                          NULL);
 
           g_clear_error (&error);
           return;
@@ -117,7 +119,9 @@ gtd_plugin_todo_txt_load_source_monitor (GtdPluginTodoTxt *self)
     {
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error while opening the file monitor. Todo.txt will not be 
monitored"),
-                                      file_monitor->message);
+                                      file_monitor->message,
+                                      NULL,
+                                      NULL);
       g_clear_error (&file_monitor);
     }
   else
@@ -151,7 +155,9 @@ gtd_plugin_todo_txt_set_default_source (GtdPluginTodoTxt *self)
     {
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Cannot create Todo.txt file"),
-                                      error->message);
+                                      error->message,
+                                      NULL,
+                                      NULL);
 
       g_clear_error (&error);
       return FALSE;
@@ -195,7 +201,9 @@ gtd_plugin_todo_txt_activate (GtdActivatable *activatable)
         {
           gtd_manager_emit_error_message (gtd_manager_get_default (),
                                           _("Cannot create Todo.txt file"),
-                                          error->message);
+                                          error->message,
+                                          NULL,
+                                          NULL);
 
           g_clear_error (&error);
           return;
@@ -296,7 +304,9 @@ gtd_plugin_todo_txt_source_changed_finished_cb (GtdPluginTodoTxt *self)
         {
           gtd_manager_emit_error_message (gtd_manager_get_default (),
                                           _("Cannot create Todo.txt file"),
-                                          error->message);
+                                          error->message,
+                                          NULL,
+                                          NULL);
 
           g_clear_error (&error);
           return;
diff --git a/plugins/todo-txt/gtd-provider-todo-txt.c b/plugins/todo-txt/gtd-provider-todo-txt.c
index 293f050..d7db273 100644
--- a/plugins/todo-txt/gtd-provider-todo-txt.c
+++ b/plugins/todo-txt/gtd-provider-todo-txt.c
@@ -132,7 +132,9 @@ emit_generic_error (GError *error)
 
   gtd_manager_emit_error_message (gtd_manager_get_default (),
                                   _("Error while opening Todo.txt"),
-                                  error->message);
+                                  error->message,
+                                  NULL,
+                                  NULL);
 }
 
 static void
@@ -318,7 +320,9 @@ gtd_provider_todo_txt_load_source (GtdProviderTodoTxt *self)
 
           gtd_manager_emit_error_message (gtd_manager_get_default (),
                                           _("Error while reading a line from Todo.txt"),
-                                          line_read_error->message);
+                                          line_read_error->message,
+                                          NULL,
+                                          NULL);
           g_error_free (line_read_error);
 
           return;
@@ -404,7 +408,9 @@ gtd_provider_todo_txt_create_task (GtdProvider *provider,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error while adding a task to Todo.txt"),
-                                      write_error->message);
+                                      write_error->message,
+                                      NULL,
+                                      NULL);
       g_error_free (write_error);
 
       goto out;
@@ -492,7 +498,9 @@ gtd_provider_todo_txt_update_task (GtdProvider *provider,
 
           gtd_manager_emit_error_message (gtd_manager_get_default (),
                                           _("Error while reading tasks from Todo.txt"),
-                                          line_read_error->message);
+                                          line_read_error->message,
+                                          NULL,
+                                          NULL);
           g_error_free (line_read_error);
         }
 
@@ -626,7 +634,9 @@ gtd_provider_todo_txt_remove_task (GtdProvider *provider,
 
           gtd_manager_emit_error_message (gtd_manager_get_default (),
                                           _("Error while reading tasks from Todo.txt"),
-                                          line_read_error->message);
+                                          line_read_error->message,
+                                          NULL,
+                                          NULL);
           g_error_free (line_read_error);
           return;
         }
@@ -722,7 +732,9 @@ gtd_provider_todo_txt_create_task_list (GtdProvider *provider,
 
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("Error while creating a Todo.txt list"),
-                                      write_error->message);
+                                      write_error->message,
+                                      NULL,
+                                      NULL);
       g_error_free (write_error);
       goto out;
     }
@@ -807,7 +819,9 @@ gtd_provider_todo_txt_update_task_list (GtdProvider *provider,
 
           gtd_manager_emit_error_message (gtd_manager_get_default (),
                                          _("Error while reading tasks from Todo.txt"),
-                                           line_read_error->message);
+                                           line_read_error->message,
+                                           NULL,
+                                           NULL);
           g_error_free (line_read_error);
           continue;
         }
@@ -943,7 +957,9 @@ gtd_provider_todo_txt_remove_task_list (GtdProvider *provider,
 
           gtd_manager_emit_error_message (gtd_manager_get_default (),
                                           _("Error while reading task lists from Todo.txt"),
-                                          line_read_error->message);
+                                          line_read_error->message,
+                                          NULL,
+                                          NULL);
           g_error_free (line_read_error);
         }
 
diff --git a/plugins/todo-txt/gtd-todo-txt-parser.c b/plugins/todo-txt/gtd-todo-txt-parser.c
index a1f96cb..24ecd81 100644
--- a/plugins/todo-txt/gtd-todo-txt-parser.c
+++ b/plugins/todo-txt/gtd-todo-txt-parser.c
@@ -343,7 +343,9 @@ gtd_todo_txt_parser_validate_token_format (GList *tokens)
             {
               gtd_manager_emit_error_message (gtd_manager_get_default (),
                                              _("Incorrect date"),
-                                             _("Please make sure the date in Todo.txt is valid."));
+                                             _("Please make sure the date in Todo.txt is valid."),
+                                             NULL,
+                                             NULL);
               return FALSE;
             }
 
@@ -373,7 +375,9 @@ gtd_todo_txt_parser_validate_token_format (GList *tokens)
         default:
           gtd_manager_emit_error_message (gtd_manager_get_default (),
                                           _("Unrecognized token in a Todo.txt line"),
-                                          _("To Do cannot recognize some tags in your Todo.txt file. Some 
tasks may not be loaded"));
+                                          _("To Do cannot recognize some tags in your Todo.txt file. Some 
tasks may not be loaded"),
+                                          NULL,
+                                          NULL);
           return FALSE;
           break;
         }
@@ -383,7 +387,9 @@ gtd_todo_txt_parser_validate_token_format (GList *tokens)
     {
       gtd_manager_emit_error_message (gtd_manager_get_default (),
                                       _("No task list found for some tasks"),
-                                      _("Some of the tasks in your Todo.txt file do not have a task list. To 
Do supports tasks with a task list. Please add a list to all your tasks"));
+                                      _("Some of the tasks in your Todo.txt file do not have a task list. To 
Do supports tasks with a task list. Please add a list to all your tasks"),
+                                      NULL,
+                                      NULL);
       return FALSE;
     }
 
diff --git a/src/engine/gtd-manager.c b/src/engine/gtd-manager.c
index fe0dca1..79b5f51 100644
--- a/src/engine/gtd-manager.c
+++ b/src/engine/gtd-manager.c
@@ -109,15 +109,19 @@ check_provider_is_default (GtdManager  *manager,
 }
 
 static void
-emit_show_error_message (GtdManager  *manager,
-                         const gchar *primary_text,
-                         const gchar *secondary_text)
+emit_show_error_message (GtdManager                *manager,
+                         const gchar               *primary_text,
+                         const gchar               *secondary_text,
+                         GtdNotificationActionFunc  action,
+                         gpointer                   user_data)
 {
   g_signal_emit (manager,
                  signals[SHOW_ERROR_MESSAGE],
                  0,
                  primary_text,
-                 secondary_text);
+                 secondary_text,
+                 action,
+                 user_data);
 }
 
 static void
@@ -317,7 +321,9 @@ gtd_manager_class_init (GtdManagerClass *klass)
    * GtdManager::show-error-message:
    * @manager: a #GtdManager
    * @primary_text: the primary message
-   * @secondary_text: the detailed explanation of the error
+   * @secondary_text: the detailed explanation of the error or the text to the notification button.
+   * @action : optionally action of type GtdNotificationActionFunc ignored if it's null.
+   * @user_data : user data passed to the action.
    *
    * Notifies about errors, and sends the error message for widgets
    * to display.
@@ -330,9 +336,11 @@ gtd_manager_class_init (GtdManagerClass *klass)
                                               NULL,
                                               NULL,
                                               G_TYPE_NONE,
-                                              2,
+                                              4,
                                               G_TYPE_STRING,
-                                              G_TYPE_STRING);
+                                              G_TYPE_STRING,
+                                              G_TYPE_POINTER,
+                                              G_TYPE_POINTER);
 
   /**
    * GtdManager::panel-added:
@@ -955,15 +963,19 @@ gtd_manager_set_is_first_run (GtdManager *manager,
 }
 
 void
-gtd_manager_emit_error_message (GtdManager  *manager,
-                                const gchar *primary_message,
-                                const gchar *secondary_message)
+gtd_manager_emit_error_message (GtdManager                *manager,
+                                const gchar               *primary_message,
+                                const gchar               *secondary_message,
+                                GtdNotificationActionFunc  function,
+                                gpointer                   user_data)
 {
   g_return_if_fail (GTD_IS_MANAGER (manager));
 
   emit_show_error_message (manager,
                            primary_message,
-                           secondary_message);
+                           secondary_message,
+                           function,
+                           user_data);
 }
 
 /**
diff --git a/src/engine/gtd-manager.h b/src/engine/gtd-manager.h
index d9f5bb2..77cb7ad 100644
--- a/src/engine/gtd-manager.h
+++ b/src/engine/gtd-manager.h
@@ -30,59 +30,66 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GtdManager, gtd_manager, GTD, MANAGER, GtdObject)
 
+
+typedef void (*GtdNotificationActionFunc) (GtdNotification *notification,
+                                           gpointer         user_data);
+
+
 GtdManager*             gtd_manager_new                   (void);
 
 GtdManager*             gtd_manager_get_default           (void);
 
-GList*                  gtd_manager_get_task_lists        (GtdManager           *manager);
+GList*                  gtd_manager_get_task_lists        (GtdManager                *manager);
 
-GList*                  gtd_manager_get_providers         (GtdManager           *manager);
+GList*                  gtd_manager_get_providers         (GtdManager                *manager);
 
-GList*                  gtd_manager_get_panels            (GtdManager           *manager);
+GList*                  gtd_manager_get_panels            (GtdManager                *manager);
 
 /* Task lists */
-void                    gtd_manager_create_task_list      (GtdManager           *manager,
-                                                           GtdTaskList          *list);
+void                    gtd_manager_create_task_list      (GtdManager                *manager,
+                                                           GtdTaskList               *list);
 
-void                    gtd_manager_remove_task_list      (GtdManager           *manager,
-                                                           GtdTaskList          *list);
+void                    gtd_manager_remove_task_list      (GtdManager                *manager,
+                                                           GtdTaskList               *list);
 
-void                    gtd_manager_save_task_list        (GtdManager           *manager,
-                                                           GtdTaskList          *list);
+void                    gtd_manager_save_task_list        (GtdManager                *manager,
+                                                           GtdTaskList               *list);
 
 /* Tasks */
-void                    gtd_manager_create_task           (GtdManager           *manager,
-                                                           GtdTask              *task);
+void                    gtd_manager_create_task           (GtdManager                *manager,
+                                                           GtdTask                   *task);
 
-void                    gtd_manager_remove_task           (GtdManager           *manager,
-                                                           GtdTask              *task);
+void                    gtd_manager_remove_task           (GtdManager                *manager,
+                                                           GtdTask                   *task);
 
-void                    gtd_manager_update_task           (GtdManager           *manager,
-                                                           GtdTask              *task);
+void                    gtd_manager_update_task           (GtdManager                *manager,
+                                                           GtdTask                   *task);
 
 /* Settings */
-GtdProvider*            gtd_manager_get_default_provider  (GtdManager           *manager);
+GtdProvider*            gtd_manager_get_default_provider  (GtdManager                *manager);
 
-void                    gtd_manager_set_default_provider  (GtdManager           *manager,
-                                                           GtdProvider          *provider);
+void                    gtd_manager_set_default_provider  (GtdManager                *manager,
+                                                           GtdProvider               *provider);
 
-GtdTaskList*            gtd_manager_get_default_task_list (GtdManager           *self);
+GtdTaskList*            gtd_manager_get_default_task_list (GtdManager                *self);
 
-void                    gtd_manager_set_default_task_list (GtdManager           *self,
-                                                           GtdTaskList          *list);
+void                    gtd_manager_set_default_task_list (GtdManager                *self,
+                                                           GtdTaskList               *list);
 
-GSettings*              gtd_manager_get_settings          (GtdManager           *manager);
+GSettings*              gtd_manager_get_settings          (GtdManager                *manager);
 
-gboolean                gtd_manager_get_is_first_run      (GtdManager           *manager);
+gboolean                gtd_manager_get_is_first_run      (GtdManager                *manager);
 
-void                    gtd_manager_set_is_first_run      (GtdManager           *manager,
-                                                           gboolean              is_first_run);
+void                    gtd_manager_set_is_first_run      (GtdManager                *manager,
+                                                           gboolean                   is_first_run);
 
-void                    gtd_manager_emit_error_message    (GtdManager           *manager,
-                                                           const gchar          *primary_message,
-                                                           const gchar          *secondary_message);
+void                    gtd_manager_emit_error_message    (GtdManager                *manager,
+                                                           const gchar               *primary_message,
+                                                           const gchar               *secondary_message,
+                                                           GtdNotificationActionFunc  function,
+                                                           gpointer                   user_data);
 
-GtdTimer*               gtd_manager_get_timer             (GtdManager           *self);
+GtdTimer*               gtd_manager_get_timer             (GtdManager                *self);
 
 G_END_DECLS
 
diff --git a/src/gtd-window.c b/src/gtd-window.c
index baf7fbd..3bdbba9 100644
--- a/src/gtd-window.c
+++ b/src/gtd-window.c
@@ -520,10 +520,12 @@ gtd_window__manager_ready_changed (GObject    *source,
 }
 
 static void
-gtd_window__show_error_message (GtdManager  *manager,
-                                const gchar *primary_text,
-                                const gchar *secondary_text,
-                                GtdWindow   *window)
+gtd_window__show_error_message (GtdManager                *manager,
+                                const gchar               *primary_text,
+                                const gchar               *secondary_text,
+                                GtdNotificationActionFunc  function,
+                                gpointer                   user_data,
+                                GtdWindow                 *window)
 {
   GtdNotification *notification;
   ErrorData *error_data;
@@ -538,10 +540,18 @@ gtd_window__show_error_message (GtdManager  *manager,
   gtd_notification_set_primary_action (notification,
                                        error_message_notification_primary_action,
                                        error_data);
-  gtd_notification_set_secondary_action (notification,
-                                         _("Details"),
-                                         error_message_notification_secondary_action,
-                                         error_data);
+
+  if (function == NULL)
+    gtd_notification_set_secondary_action (notification,
+                                           _("Details"),
+                                           error_message_notification_secondary_action,
+                                           error_data);
+  else
+    gtd_notification_set_secondary_action (notification,
+                                           secondary_text,
+                                           function,
+                                           user_data);
+
 
   gtd_window_notify (window, notification);
 }


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