[gnome-todo] todoist-plugin: stub out



commit cf778f83d82fe510697fc43df8997c954e654ef3
Author: Rohit Kaushik <kaushikrohit325 gmail com>
Date:   Fri Jun 2 16:52:44 2017 +0530

    todoist-plugin: stub out
    
    This patch includes the basic skeleton along with certain signal
    and functions that will be required for todoist integration.
    Many function are not implemented since we don't have a Todoist
    Goa Account.
    Classes added:
        1) TodoistPreferencesPanel
        2) TodoistProvider
        3) TodoistPlugin
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772278

 configure.ac                                    |    2 +
 configure_meson                                 |    2 +
 data/todo.gresource.xml                         |    6 +
 meson_options.txt                               |    1 +
 plugins/Makefile.am                             |    4 +
 plugins/meson.build                             |    4 +
 plugins/todoist/Makefile.am                     |   20 ++
 plugins/todoist/gtd-plugin-todoist.c            |  267 ++++++++++++++++++++
 plugins/todoist/gtd-plugin-todoist.h            |   35 +++
 plugins/todoist/gtd-provider-todoist.c          |  298 +++++++++++++++++++++++
 plugins/todoist/gtd-provider-todoist.h          |   40 +++
 plugins/todoist/gtd-todoist-preferences-panel.c |  271 +++++++++++++++++++++
 plugins/todoist/gtd-todoist-preferences-panel.h |   40 +++
 plugins/todoist/meson.build                     |   26 ++
 plugins/todoist/todoist.plugin.in               |   13 +
 plugins/todoist/ui/preferences.ui               |  103 ++++++++
 src/Makefile.am                                 |    6 +
 src/meson.build                                 |    5 +
 18 files changed, 1143 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index bce125e..129d8f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -96,6 +96,7 @@ GNOME_TODO_ADD_PLUGIN([score], [Score], [yes])
 GNOME_TODO_ADD_PLUGIN([today-panel], [Today Panel], [yes])
 GNOME_TODO_ADD_PLUGIN([unscheduled-panel], [Unscheduled Tasks Panel], [yes])
 GNOME_TODO_ADD_PLUGIN([todo-txt], [Todo.Txt], [yes])
+GNOME_TODO_ADD_PLUGIN([todoist], [Todoist], [yes])
 
 
 dnl ***********************************************************************
@@ -146,6 +147,7 @@ echo "
         Today panel ............. ${enable_today_panel_plugin}
         Unscheduled panel ....... ${enable_unscheduled_panel_plugin}
         Todo.txt ................ ${enable_todo_txt_plugin}
+        Todoist ................. ${enable_todoist_plugin}
 
         Now type 'make' to build $PACKAGE
 "
diff --git a/configure_meson b/configure_meson
index dc0b488..acd02aa 100755
--- a/configure_meson
+++ b/configure_meson
@@ -91,6 +91,7 @@ declare -A default_options=(
     ['today-panel-plugin']=true
     ['unscheduled-panel-plugin']=true
     ['todo-txt-plugin']=true
+    ['todoist-plugin']=true
     ['introspection']=true
 )
 
@@ -176,6 +177,7 @@ echo "
         Today panel ............. $(echooption today-panel-plugin)
         Unscheduled panel ....... $(echooption unscheduled-panel-plugin)
         Todo.txt ................ $(echooption todo-txt-plugin)
+        Todoist ................. $(echooption todoist-plugin)
 
         Now type '${NINJA} -C ${builddir}' to build
 "
diff --git a/data/todo.gresource.xml b/data/todo.gresource.xml
index a48571e..94b18eb 100644
--- a/data/todo.gresource.xml
+++ b/data/todo.gresource.xml
@@ -53,4 +53,10 @@
   <gresource prefix="/org/gnome/todo">
     <file alias="plugins/todo-txt/todo-txt.plugin">../plugins/todo-txt/todo-txt.plugin</file>
   </gresource>
+
+  <!--Todoist-->
+  <gresource prefix="/org/gnome/todo">
+    <file alias="plugins/todoist/todoist.plugin">../plugins/todoist/todoist.plugin</file>
+    <file compressed="true" alias="ui/todoist/preferences.ui">../plugins/todoist/ui/preferences.ui</file>
+  </gresource>
 </gresources>
diff --git a/meson_options.txt b/meson_options.txt
index 38cc32d..98856f9 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -7,5 +7,6 @@ option('enable-score-plugin', type: 'boolean', value: true, description: 'enable
 option('enable-today-panel-plugin', type: 'boolean', value: true, description: 'enable Today Panel plugin')
 option('enable-unscheduled-panel-plugin', type: 'boolean', value: true, description: 'enable Unscheduled 
Tasks Panel plugin')
 option('enable-todo-txt-plugin', type: 'boolean', value: true, description: 'enable Todo.Txt plugin')
+option('enable-todoist-plugin', type: 'boolean', value: true, description: 'enable Todoist plugin')
 option('enable-gtk-doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation')
 option('enable-introspection', type: 'boolean', value: true, description: 'Enable GObject Introspection 
(depends on GObject)')
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 67184f5..8735ee4 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -28,4 +28,8 @@ if BUILD_TODO_TXT_PLUGIN
 SUBDIRS += todo-txt
 endif
 
+if BUILD_TODOIST_PLUGIN
+SUBDIRS += todoist
+endif
+
 MAINTAINERCLEANFILES = Makefile.in
diff --git a/plugins/meson.build b/plugins/meson.build
index 09a75b9..9302fd4 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -34,3 +34,7 @@ endif
 if get_option('enable-todo-txt-plugin')
   subdir('todo-txt')
 endif
+
+if get_option('enable-todoist-plugin')
+  subdir('todoist')
+endif
diff --git a/plugins/todoist/Makefile.am b/plugins/todoist/Makefile.am
new file mode 100644
index 0000000..75b0434
--- /dev/null
+++ b/plugins/todoist/Makefile.am
@@ -0,0 +1,20 @@
+include $(top_srcdir)/common.am
+
+noinst_LTLIBRARIES = libtodoist.la
+
+libtodoist_la_SOURCES = \
+       gtd-plugin-todoist.c \
+       gtd-plugin-todoist.h \
+       gtd-provider-todoist.c \
+       gtd-provider-todoist.h \
+       gtd-todoist-preferences-panel.c \
+       gtd-todoist_preferences_panel.h
+
+libtodoist_la_CFLAGS = \
+       $(GNOME_TODO_PLUGIN_CFLAGS) \
+       $(GNOME_TODO_PLUGIN_WARN_CFLAGS)
+       -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\"
+
+EXTRA_DIST = \
+       todoist.plugin.in
+
diff --git a/plugins/todoist/gtd-plugin-todoist.c b/plugins/todoist/gtd-plugin-todoist.c
new file mode 100644
index 0000000..7f90a4d
--- /dev/null
+++ b/plugins/todoist/gtd-plugin-todoist.c
@@ -0,0 +1,267 @@
+/* gtd-plugin-todoist.c
+ *
+ * Copyright (C) 2017 Rohit Kaushik <kaushikrohit325 gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "Todoist"
+
+#include "gtd-plugin-todoist.h"
+#include "gtd-provider-todoist.h"
+#include "gtd-todoist-preferences-panel.h"
+
+#include <glib/gi18n.h>
+#include <glib-object.h>
+
+/**
+ * The #GtdPluginTodoist is a class that loads Todoist
+ * provider of GNOME To Do.
+ */
+
+struct _GtdPluginTodoist
+{
+  PeasExtensionBase   parent;
+
+  GtkWidget          *preferences;
+
+  /* Providers */
+  GList              *providers;
+};
+
+enum
+{
+  PROP_0,
+  PROP_PREFERENCES_PANEL,
+  LAST_PROP
+};
+
+static void          gtd_activatable_iface_init                  (GtdActivatableInterface  *iface);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (GtdPluginTodoist, gtd_plugin_todoist, PEAS_TYPE_EXTENSION_BASE,
+                                0,
+                                G_IMPLEMENT_INTERFACE_DYNAMIC (GTD_TYPE_ACTIVATABLE,
+                                                               gtd_activatable_iface_init))
+
+/*
+ * GtdActivatable interface implementation
+ */
+static void
+gtd_plugin_todoist_activate (GtdActivatable *activatable)
+{
+  ;
+}
+
+static void
+gtd_plugin_todoist_deactivate (GtdActivatable *activatable)
+{
+  ;
+}
+
+static GList*
+gtd_plugin_todoist_get_header_widgets (GtdActivatable *activatable)
+{
+  return NULL;
+}
+
+static GtkWidget*
+gtd_plugin_todoist_get_preferences_panel (GtdActivatable *activatable)
+{
+  GtdPluginTodoist *self = GTD_PLUGIN_TODOIST (activatable);
+
+  return self->preferences;
+
+}
+
+static GList*
+gtd_plugin_todoist_get_panels (GtdActivatable *activatable)
+{
+  return NULL;
+}
+
+static GList*
+gtd_plugin_todoist_get_providers (GtdActivatable *activatable)
+{
+  GtdPluginTodoist *plugin = GTD_PLUGIN_TODOIST (activatable);
+
+  return plugin->providers;
+}
+
+static void
+gtd_plugin_todoist_account_added (GtdTodoistPreferencesPanel *panel,
+                                  GoaObject                  *account_object,
+                                  GtdPluginTodoist           *self)
+{
+  GtdProviderTodoist *provider;
+  GoaAccount *goa_account;
+  const gchar *provider_name;
+
+  goa_account = goa_object_get_account (account_object);
+  provider_name = goa_account_get_provider_name (goa_account);
+
+  if (g_strcmp0 (provider_name, "Todoist") != 0)
+    return;
+
+  provider = gtd_provider_todoist_new (account_object);
+
+  self->providers = g_list_append (self->providers, provider);
+
+  g_signal_emit_by_name (self, "provider-added", provider);
+}
+
+static void
+gtd_plugin_todoist_account_removed (GtdTodoistPreferencesPanel *panel,
+                                    GoaObject                  *account_object,
+                                    GtdPluginTodoist           *self)
+{
+  GoaAccount *goa_account;
+  const gchar *provider_name;
+  GList *l;
+
+  goa_account = goa_object_get_account (account_object);
+  provider_name = goa_account_get_provider_name (goa_account);
+  l = NULL;
+
+  if (g_strcmp0 (provider_name, "Todoist") != 0)
+    return;
+
+  for (l = self->providers; l != NULL; l = l->next)
+    {
+      GoaObject *object;
+
+      object = gtd_provider_todoist_get_goa_object (l->data);
+
+      if (object == account_object)
+        {
+          self->providers = g_list_remove (self->providers, l->data);
+
+          g_signal_emit_by_name (self, "provider-removed", l->data);
+
+          break;
+        }
+    }
+}
+
+static void
+gtd_plugin_todoist_account_changed (GtdTodoistPreferencesPanel *panel,
+                                    GoaObject                  *account_object,
+                                    GtdPluginTodoist           *self)
+{
+  GoaAccount *goa_account;
+  const gchar *provider_name;
+
+  goa_account = goa_object_get_account (account_object);
+  provider_name = goa_account_get_provider_name (goa_account);
+
+  if (g_strcmp0 (provider_name, "Todoist") != 0)
+    return;
+}
+
+static void
+goa_client_ready (GObject           *source,
+                  GAsyncResult      *res,
+                  GtdPluginTodoist  *self)
+{
+  GoaClient *client;
+
+  client = goa_client_new_finish (res, NULL);
+
+  /* Connect signals */
+  g_signal_connect (client, "account-added", G_CALLBACK (gtd_plugin_todoist_account_added), self);
+  g_signal_connect (client, "account-removed", G_CALLBACK (gtd_plugin_todoist_account_removed), self);
+  g_signal_connect (client, "account-changed", G_CALLBACK (gtd_plugin_todoist_account_changed), self);
+
+  gtd_todoist_preferences_panel_set_client (GTD_TODOIST_PREFERENCES_PANEL (self->preferences), client);
+}
+
+static void
+gtd_activatable_iface_init (GtdActivatableInterface *iface)
+{
+  iface->activate = gtd_plugin_todoist_activate;
+  iface->deactivate = gtd_plugin_todoist_deactivate;
+  iface->get_header_widgets = gtd_plugin_todoist_get_header_widgets;
+  iface->get_preferences_panel = gtd_plugin_todoist_get_preferences_panel;
+  iface->get_panels = gtd_plugin_todoist_get_panels;
+  iface->get_providers = gtd_plugin_todoist_get_providers;
+}
+
+/*
+ * Init
+ */
+
+static void
+gtd_plugin_todoist_finalize (GObject *object)
+{
+  GtdPluginTodoist *self = (GtdPluginTodoist *) object;
+
+  g_list_free_full (self->providers, g_object_unref);
+  self->providers = NULL;
+
+  G_OBJECT_CLASS (gtd_plugin_todoist_parent_class)->finalize (object);
+}
+
+static void
+gtd_plugin_todoist_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  GtdPluginTodoist *self = GTD_PLUGIN_TODOIST (object);
+  switch (prop_id)
+    {
+    case PROP_PREFERENCES_PANEL:
+      g_value_set_object (value, self->preferences);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gtd_plugin_todoist_class_init (GtdPluginTodoistClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize     = gtd_plugin_todoist_finalize;
+  object_class->get_property = gtd_plugin_todoist_get_property;
+
+  g_object_class_override_property (object_class,
+                                    PROP_PREFERENCES_PANEL,
+                                    "preferences-panel");
+}
+
+static void
+gtd_plugin_todoist_init (GtdPluginTodoist *self)
+{
+  self->preferences = GTK_WIDGET (gtd_todoist_preferences_panel_new ());
+
+  goa_client_new (NULL, (GAsyncReadyCallback) goa_client_ready, self);
+}
+
+/* Empty class_finalize method */
+static void
+gtd_plugin_todoist_class_finalize (GtdPluginTodoistClass *klass)
+{
+}
+
+G_MODULE_EXPORT void
+gtd_plugin_todoist_register_types (PeasObjectModule *module)
+{
+  gtd_plugin_todoist_register_type (G_TYPE_MODULE (module));
+
+  peas_object_module_register_extension_type (module,
+                                              GTD_TYPE_ACTIVATABLE,
+                                              GTD_TYPE_PLUGIN_TODOIST);
+}
diff --git a/plugins/todoist/gtd-plugin-todoist.h b/plugins/todoist/gtd-plugin-todoist.h
new file mode 100644
index 0000000..e2eac39
--- /dev/null
+++ b/plugins/todoist/gtd-plugin-todoist.h
@@ -0,0 +1,35 @@
+/* gtd-plugin-todoist.h
+ *
+ * Copyright (C) 2017 Rohit Kaushik <kaushikrohit325 gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTD_TODOIST_PLUGIN_H
+#define GTD_TODOIST_PLUGIN_H
+
+#include <glib.h>
+#include <gnome-todo.h>
+
+G_BEGIN_DECLS
+
+#define GTD_TYPE_PLUGIN_TODOIST (gtd_plugin_todoist_get_type())
+
+G_DECLARE_FINAL_TYPE (GtdPluginTodoist, gtd_plugin_todoist, GTD, PLUGIN_TODOIST, PeasExtensionBase)
+
+G_MODULE_EXPORT void  gtd_plugin_todoist_register_types         (PeasObjectModule   *module);
+
+G_END_DECLS
+
+#endif /* GTD_TODOIST_PLUGIN_H */
diff --git a/plugins/todoist/gtd-provider-todoist.c b/plugins/todoist/gtd-provider-todoist.c
new file mode 100644
index 0000000..341542a
--- /dev/null
+++ b/plugins/todoist/gtd-provider-todoist.c
@@ -0,0 +1,298 @@
+/* gtd-provider-todoist.c
+ *
+ * Copyright (C) 2017 Rohit Kaushik <kaushikrohit325 gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gtd-provider-todoist.h"
+#include "gtd-plugin-todoist.h"
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib/gi18n.h>
+
+
+struct _GtdProviderTodoist
+{
+  GtdObject          parent;
+
+  GoaObject          *account_object;
+
+  GIcon              *icon;
+  GList              *task_lists;
+};
+
+static void          gtd_provider_iface_init                     (GtdProviderInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtdProviderTodoist, gtd_provider_todoist, GTD_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (GTD_TYPE_PROVIDER,
+                                                gtd_provider_iface_init))
+
+enum {
+  PROP_0,
+  PROP_DEFAULT_TASKLIST,
+  PROP_DESCRIPTION,
+  PROP_ENABLED,
+  PROP_ICON,
+  PROP_ID,
+  PROP_NAME,
+  PROP_GOA_OBJECT,
+  LAST_PROP
+};
+
+/*
+ * GtdProviderInterface implementation
+ */
+static const gchar*
+gtd_provider_todoist_get_id (GtdProvider *provider)
+{
+  return "todoist";
+}
+
+static const gchar*
+gtd_provider_todoist_get_name (GtdProvider *provider)
+{
+  return _("Todoist");
+}
+
+static const gchar*
+gtd_provider_todoist_get_description (GtdProvider *provider)
+{
+  return _("Todoist Plugin for GNOME To Do");
+}
+
+
+static gboolean
+gtd_provider_todoist_get_enabled (GtdProvider *provider)
+{
+  return TRUE;
+}
+
+static GIcon*
+gtd_provider_todoist_get_icon (GtdProvider *provider)
+{
+  GtdProviderTodoist *self;
+
+  self = GTD_PROVIDER_TODOIST (provider);
+
+  return self->icon;
+}
+
+static const GtkWidget*
+gtd_provider_todoist_get_edit_panel (GtdProvider *provider)
+{
+  return NULL;
+}
+
+GoaObject*
+gtd_provider_todoist_get_goa_object (GtdProviderTodoist  *self)
+{
+  return self->account_object;
+}
+static void
+gtd_provider_todoist_create_task (GtdProvider *provider,
+                                   GtdTask     *task)
+{
+
+}
+
+static void
+gtd_provider_todoist_update_task (GtdProvider *provider,
+                                   GtdTask     *task)
+{
+
+}
+
+static void
+gtd_provider_todoist_remove_task (GtdProvider *provider,
+                                   GtdTask     *task)
+{
+
+}
+
+static void
+gtd_provider_todoist_create_task_list (GtdProvider *provider,
+                                        GtdTaskList *list)
+{
+
+}
+
+static void
+gtd_provider_todoist_update_task_list (GtdProvider *provider,
+                                        GtdTaskList *list)
+{
+
+}
+
+static void
+gtd_provider_todoist_remove_task_list (GtdProvider *provider,
+                                        GtdTaskList *list)
+{
+
+}
+
+static GList*
+gtd_provider_todoist_get_task_lists (GtdProvider *provider)
+{
+  GtdProviderTodoist *self;
+
+  self = GTD_PROVIDER_TODOIST (provider);
+
+  return self->task_lists;
+}
+
+static GtdTaskList*
+gtd_provider_todoist_get_default_task_list (GtdProvider *provider)
+{
+  return NULL;
+}
+
+static void
+gtd_provider_todoist_set_default_task_list (GtdProvider *provider,
+                                            GtdTaskList *list)
+{
+
+}
+
+static void
+gtd_provider_iface_init (GtdProviderInterface *iface)
+{
+  iface->get_id = gtd_provider_todoist_get_id;
+  iface->get_name = gtd_provider_todoist_get_name;
+  iface->get_description = gtd_provider_todoist_get_description;
+  iface->get_enabled = gtd_provider_todoist_get_enabled;
+  iface->get_icon = gtd_provider_todoist_get_icon;
+  iface->get_edit_panel = gtd_provider_todoist_get_edit_panel;
+  iface->create_task = gtd_provider_todoist_create_task;
+  iface->update_task = gtd_provider_todoist_update_task;
+  iface->remove_task = gtd_provider_todoist_remove_task;
+  iface->create_task_list = gtd_provider_todoist_create_task_list;
+  iface->update_task_list = gtd_provider_todoist_update_task_list;
+  iface->remove_task_list = gtd_provider_todoist_remove_task_list;
+  iface->get_task_lists = gtd_provider_todoist_get_task_lists;
+  iface->get_default_task_list = gtd_provider_todoist_get_default_task_list;
+  iface->set_default_task_list = gtd_provider_todoist_set_default_task_list;
+}
+
+GtdProviderTodoist*
+gtd_provider_todoist_new (GoaObject *account_object)
+{
+
+  return g_object_new (GTD_TYPE_PROVIDER_TODOIST,
+                       "goa object",account_object,
+                       NULL);
+}
+
+static void
+gtd_provider_todoist_finalize (GObject *object)
+{
+  GtdProviderTodoist *self = (GtdProviderTodoist *)object;
+
+  g_clear_pointer (&self->task_lists, g_clear_object);
+  g_clear_object (&self->icon);
+
+  G_OBJECT_CLASS (gtd_provider_todoist_parent_class)->finalize (object);
+}
+
+static void
+gtd_provider_todoist_get_property (GObject    *object,
+                                   guint       prop_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
+{
+  GtdProvider *provider = GTD_PROVIDER (object);
+
+  switch (prop_id)
+    {
+    case PROP_DESCRIPTION:
+      g_value_set_string (value, gtd_provider_todoist_get_description (provider));
+      break;
+
+    case PROP_ENABLED:
+      g_value_set_boolean (value, gtd_provider_todoist_get_enabled (provider));
+      break;
+
+    case PROP_ICON:
+      g_value_set_object (value, gtd_provider_todoist_get_icon (provider));
+      break;
+
+    case PROP_ID:
+      g_value_set_string (value, gtd_provider_todoist_get_id (provider));
+      break;
+
+    case PROP_NAME:
+      g_value_set_string (value, gtd_provider_todoist_get_name (provider));
+      break;
+
+    case PROP_GOA_OBJECT:
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gtd_provider_todoist_set_property (GObject      *object,
+                                   guint         prop_id,
+                                   const GValue *value,
+                                   GParamSpec   *pspec)
+{
+  GtdProviderTodoist *self = GTD_PROVIDER_TODOIST (object);
+
+  switch (prop_id)
+    {
+    case PROP_GOA_OBJECT:
+      self->account_object = GOA_OBJECT (g_value_dup_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gtd_provider_todoist_class_init (GtdProviderTodoistClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = gtd_provider_todoist_finalize;
+  object_class->get_property = gtd_provider_todoist_get_property;
+  object_class->set_property = gtd_provider_todoist_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_GOA_OBJECT,
+                                   g_param_spec_object ("goa object",
+                                                        "Goa Object",
+                                                        "GOA Object around a Todoist Goa Account",
+                                                        GOA_TYPE_OBJECT,
+                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+  g_object_class_override_property (object_class, PROP_DEFAULT_TASKLIST, "default-task-list");
+  g_object_class_override_property (object_class, PROP_DESCRIPTION, "description");
+  g_object_class_override_property (object_class, PROP_ENABLED, "enabled");
+  g_object_class_override_property (object_class, PROP_ICON, "icon");
+  g_object_class_override_property (object_class, PROP_ID, "id");
+  g_object_class_override_property (object_class, PROP_NAME, "name");
+}
+
+static void
+gtd_provider_todoist_init (GtdProviderTodoist *self)
+{
+  gtd_object_set_ready (GTD_OBJECT (self), TRUE);
+
+  /* icon */
+  self->icon = G_ICON (g_themed_icon_new_with_default_fallbacks ("computer-symbolic"));
+}
diff --git a/plugins/todoist/gtd-provider-todoist.h b/plugins/todoist/gtd-provider-todoist.h
new file mode 100644
index 0000000..266db40
--- /dev/null
+++ b/plugins/todoist/gtd-provider-todoist.h
@@ -0,0 +1,40 @@
+/* gtd-provider-todoist.h
+ *
+ * Copyright (C) 2017 Rohit Kaushik <kaushikrohit325 gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTD_PROVIDER_TODOIST_H
+#define GTD_PROVIDER_TODOIST_H
+
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+
+#include <glib.h>
+#include <gnome-todo.h>
+#include <goa/goa.h>
+
+G_BEGIN_DECLS
+
+#define GTD_TYPE_PROVIDER_TODOIST (gtd_provider_todoist_get_type())
+
+G_DECLARE_FINAL_TYPE (GtdProviderTodoist, gtd_provider_todoist, GTD, PROVIDER_TODOIST, GtdObject)
+
+GtdProviderTodoist*    gtd_provider_todoist_new                     (GoaObject *account_object);
+
+GoaObject*             gtd_provider_todoist_get_goa_object          (GtdProviderTodoist  *self);
+
+G_END_DECLS
+
+#endif /* GTD_PROVIDER_TODOIST_H */
diff --git a/plugins/todoist/gtd-todoist-preferences-panel.c b/plugins/todoist/gtd-todoist-preferences-panel.c
new file mode 100644
index 0000000..ae72f61
--- /dev/null
+++ b/plugins/todoist/gtd-todoist-preferences-panel.c
@@ -0,0 +1,271 @@
+/* gtd-todoist-preferences-panel.c
+ *
+ * Copyright (C) 2017 Rohit Kaushik <kaushikrohit325 gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gtd-todoist-preferences-panel.h"
+#include <glib/gi18n.h>
+
+struct _GtdTodoistPreferencesPanel
+{
+  GtkStack            parent;
+
+  GoaClient          *client;
+  GtkWidget          *accounts_listbox;
+  GtkWidget          *add_button;
+  GtkWidget          *accounts_page;
+  GtkWidget          *empty_page;
+};
+
+G_DEFINE_TYPE (GtdTodoistPreferencesPanel, gtd_todoist_preferences_panel, GTK_TYPE_STACK)
+
+GtdTodoistPreferencesPanel*
+gtd_todoist_preferences_panel_new (void)
+{
+
+  return g_object_new (GTD_TYPE_TODOIST_PREFERENCES_PANEL,
+                       NULL);
+}
+
+static GVariant*
+build_dbus_parameters (const gchar *action,
+                       const gchar *arg)
+{
+  GVariantBuilder builder;
+  GVariant *array[1], *params2[3];
+
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
+
+  if (!action && !arg)
+    {
+      g_variant_builder_add (&builder, "v", g_variant_new_string (""));
+    }
+  else
+    {
+      if (action)
+        g_variant_builder_add (&builder, "v", g_variant_new_string (action));
+
+      if (arg)
+        g_variant_builder_add (&builder, "v", g_variant_new_string (arg));
+    }
+
+  array[0] = g_variant_new ("v", g_variant_new ("(sav)", "online-accounts", &builder));
+
+  params2[0] = g_variant_new_string ("launch-panel");
+  params2[1] = g_variant_new_array (G_VARIANT_TYPE ("v"), array, 1);
+  params2[2] = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
+
+  return g_variant_new_tuple (params2, 3);
+}
+
+static void
+spawn_goa_with_args (const gchar *action,
+                     const gchar *arg)
+{
+  GDBusProxy *proxy;
+
+  proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+                                         G_DBUS_PROXY_FLAGS_NONE,
+                                         NULL,
+                                         "org.gnome.ControlCenter",
+                                         "/org/gnome/ControlCenter",
+                                         "org.gtk.Actions",
+                                         NULL,
+                                         NULL);
+
+  if (!proxy)
+    {
+      g_warning ("Couldn't open Online Accounts panel");
+      return;
+    }
+
+  g_dbus_proxy_call_sync (proxy,
+                          "Activate",
+                          build_dbus_parameters (action, arg),
+                          G_DBUS_CALL_FLAGS_NONE,
+                          -1,
+                          NULL,
+                          NULL);
+
+  g_clear_object (&proxy);
+}
+
+static void
+add_account_button_clicked (GtdTodoistPreferencesPanel *self)
+{
+  spawn_goa_with_args (NULL, NULL);
+}
+
+static void
+account_row_clicked_cb (GtkListBox                 *box,
+                        GtkListBoxRow              *row,
+                        GtdTodoistPreferencesPanel *self)
+{
+  spawn_goa_with_args (NULL, NULL);
+}
+
+static void
+on_goa_account_added (GoaClient                   *client,
+                      GoaObject                   *object,
+                      GtdTodoistPreferencesPanel  *self)
+{
+  GoaAccount *goa_account;
+  GtkWidget *row;
+  GtkWidget *box;
+  GtkWidget *logo;
+  GtkWidget *desc;
+  const gchar *provider_name;
+  const gchar *identity;
+  goa_account = goa_object_get_account (object);
+
+  provider_name = goa_account_get_provider_name (goa_account);
+
+  if (g_strcmp0 (provider_name, "Todoist") != 0)
+    return;
+
+  identity = goa_account_get_presentation_identity (goa_account);
+  row = gtk_list_box_row_new ();
+
+  g_object_set_data_full (G_OBJECT (row), "goa-object", g_object_ref (object), g_object_unref);
+
+  logo = gtk_image_new_from_icon_name ("org.gnome.Todo", GTK_ICON_SIZE_LARGE_TOOLBAR);
+  desc = gtk_label_new (identity);
+  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+
+  gtk_container_set_border_width (GTK_CONTAINER (box), 6);
+  gtk_container_add (GTK_CONTAINER (box), logo);
+  gtk_container_add (GTK_CONTAINER (box), desc);
+  gtk_container_add (GTK_CONTAINER (row), box);
+
+  gtk_widget_show_all (row);
+  gtk_list_box_insert (GTK_LIST_BOX (self->accounts_listbox), GTK_WIDGET (row), -1);
+}
+
+static void
+on_goa_account_removed (GoaClient                   *client,
+                        GoaObject                   *object,
+                        GtdTodoistPreferencesPanel  *self)
+{
+  GoaAccount *goa_account;
+  GList *child;
+  GList *l;
+  gchar *provider;
+
+  goa_account = goa_object_get_account (object);
+  provider = goa_account_get_provider_name (goa_account);
+  child = NULL;
+  l = NULL;
+
+  if (g_strcmp0 (provider, "Todoist") != 0)
+    return;
+
+  child = gtk_container_get_children (GTK_CONTAINER (self->accounts_listbox));
+
+  for (l = child; l != NULL; l = l->next)
+    {
+      GoaObject *row_account;
+
+      row_account = GOA_OBJECT (g_object_get_data (G_OBJECT (l->data), "account"));
+
+      if (row_account == object)
+        {
+          gtk_container_remove (GTK_CONTAINER (self->accounts_listbox),l->data);
+
+          break;
+        }
+    }
+}
+
+void
+gtd_todoist_preferences_panel_set_client (GtdTodoistPreferencesPanel *self,
+                                          GoaClient                  *client)
+{
+  self->client = client;
+
+  g_signal_connect (self->client,
+                    "account-added",
+                    G_CALLBACK (on_goa_account_added),
+                    self);
+
+  g_signal_connect (self->client,
+                    "account-removed",
+                    G_CALLBACK (on_goa_account_removed),
+                    self);
+}
+
+static void
+gtd_todoist_preferences_panel_finalize (GObject *object)
+{
+  GtdTodoistPreferencesPanel *self = (GtdTodoistPreferencesPanel *)object;
+
+  g_object_unref (self->client);
+
+  G_OBJECT_CLASS (gtd_todoist_preferences_panel_parent_class)->finalize (object);
+}
+
+static void
+gtd_todoist_preferences_panel_get_property (GObject    *object,
+                                            guint       prop_id,
+                                            GValue     *value,
+                                            GParamSpec *pspec)
+{
+  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+}
+
+static void
+gtd_todoist_preferences_panel_set_property (GObject      *object,
+                                            guint         prop_id,
+                                            const GValue *value,
+                                            GParamSpec   *pspec)
+{
+  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+}
+
+static void
+gtd_todoist_preferences_panel_class_init (GtdTodoistPreferencesPanelClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = gtd_todoist_preferences_panel_finalize;
+  object_class->get_property = gtd_todoist_preferences_panel_get_property;
+  object_class->set_property = gtd_todoist_preferences_panel_set_property;
+
+    /* template class */
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/todo/ui/todoist/preferences.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, GtdTodoistPreferencesPanel, accounts_listbox);
+  gtk_widget_class_bind_template_child (widget_class, GtdTodoistPreferencesPanel, add_button);
+  gtk_widget_class_bind_template_child (widget_class, GtdTodoistPreferencesPanel, accounts_page);
+  gtk_widget_class_bind_template_child (widget_class, GtdTodoistPreferencesPanel, empty_page);
+
+  gtk_widget_class_bind_template_callback (widget_class, account_row_clicked_cb);
+}
+
+static void
+gtd_todoist_preferences_panel_init (GtdTodoistPreferencesPanel *self)
+{
+  GtkWidget *label;
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  gtk_stack_set_visible_child (GTK_STACK (self), self->empty_page);
+  label = gtk_label_new ("No Todoist account configured");
+  gtk_widget_show (label);
+  gtk_list_box_set_placeholder (GTK_LIST_BOX (self->accounts_listbox), GTK_WIDGET (label));
+
+  g_signal_connect (self->add_button, "clicked", G_CALLBACK (add_account_button_clicked), self);
+}
diff --git a/plugins/todoist/gtd-todoist-preferences-panel.h b/plugins/todoist/gtd-todoist-preferences-panel.h
new file mode 100644
index 0000000..9b14f9a
--- /dev/null
+++ b/plugins/todoist/gtd-todoist-preferences-panel.h
@@ -0,0 +1,40 @@
+/* gtd-todoist-preferences-panel.h
+ *
+ * Copyright (C) 2017 Rohit Kaushik <kaushikrohit325 gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+
+#ifndef GTD_TODOIST_PREFERENCES_PANEL_H
+#define GTD_TODOIST_PREFERENCES_PANEL_H
+
+#include <glib.h>
+#include <gnome-todo.h>
+#include <goa/goa.h>
+
+G_BEGIN_DECLS
+
+#define GTD_TYPE_TODOIST_PREFERENCES_PANEL (gtd_todoist_preferences_panel_get_type())
+
+G_DECLARE_FINAL_TYPE (GtdTodoistPreferencesPanel, gtd_todoist_preferences_panel, GTD, 
TODOIST_PREFERENCES_PANEL, GtkStack)
+
+GtdTodoistPreferencesPanel*   gtd_todoist_preferences_panel_new           (void);
+
+void                          gtd_todoist_preferences_panel_set_client    (GtdTodoistPreferencesPanel *self,
+                                                                           GoaClient                  
*client);
+G_END_DECLS
+
+#endif /* GTD_TODOIST_PREFERENCES_PANEL_H */
diff --git a/plugins/todoist/meson.build b/plugins/todoist/meson.build
new file mode 100644
index 0000000..e7dde5d
--- /dev/null
+++ b/plugins/todoist/meson.build
@@ -0,0 +1,26 @@
+plugin_name = 'todoist'
+
+sources = [
+  'gtd-plugin-todoist.c',
+  'gtd-plugin-todoist.h',
+  'gtd-provider-todoist.c',
+  'gtd-provider-todoist.h',
+  'gtd-todoist-preferences-panel.c',
+  'gtd-todoist-preferences-panel.h'
+]
+
+libtodoist_lib = static_library(
+  'todoist',
+  sources: sources,
+  include_directories: plugins_inc,
+  dependencies: gnome_todo_dep,
+  c_args: common_flags + [
+    '-DPACKAGE_DATA_DIR="@0@"'.format(gnome_todo_pkgdatadir)
+  ]
+)
+
+plugins_files += configure_file(
+  input: '@0  plugin in'.format(plugin_name),
+  output: '@0@.plugin'.format(plugin_name),
+  configuration: plugins_conf
+)
diff --git a/plugins/todoist/todoist.plugin.in b/plugins/todoist/todoist.plugin.in
new file mode 100644
index 0000000..89dfc82
--- /dev/null
+++ b/plugins/todoist/todoist.plugin.in
@@ -0,0 +1,13 @@
+[Plugin]
+Name = Todoist
+Module = todoist
+Description = Todoist integration for GNOME To Do
+Version = @VERSION@
+Authors = Rohit Kaushik <kaushikrohit325 gmail com>
+Copyright = Copyleft © The To Do maintainers
+Website = https://wiki.gnome.org/Apps/Todo
+Builtin = true
+License = GPL
+Loader = C
+Embedded = gtd_plugin_todoist_register_types
+Depends =
diff --git a/plugins/todoist/ui/preferences.ui b/plugins/todoist/ui/preferences.ui
new file mode 100644
index 0000000..dd6a6c3
--- /dev/null
+++ b/plugins/todoist/ui/preferences.ui
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GtdTodoistPreferencesPanel" parent="GtkStack">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="transition_type">crossfade</property>
+    <child>
+      <object class="GtkBox" id="accounts_page">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_start">80</property>
+        <property name="margin_end">80</property>
+        <property name="margin_top">24</property>
+        <property name="margin_bottom">24</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child>
+          <object class="GtkImage" id="logo">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="pixel_size">64</property>
+            <property name="icon_name">org.gnome.Todo</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolled_window">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="shadow_type">in</property>
+            <property name="min_content_height">200</property>
+            <property name="max_content_height">300</property>
+            <child>
+              <object class="GtkViewport" id="viewport">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkListBox" id="accounts_listbox">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <signal name="row-activated" handler="account_row_clicked_cb"/>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="name">accounts</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkBox" id="empty_page">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_start">24</property>
+        <property name="margin_end">24</property>
+        <property name="margin_top">80</property>
+        <property name="margin_bottom">80</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child>
+          <object class="GtkImage">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="pixel_size">96</property>
+            <property name="icon_name">edit-find-symbolic</property>
+            <style>
+              <class name="dim-label" />
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">No Todoist accounts found</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+              <attribute name="scale" value="1.44" />
+            </attributes>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton" id="add_button">
+            <property name="label" translatable="yes">Add a Todoist account</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="halign">center</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="name">empty</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 99dc43b..4aaebdf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -129,6 +129,12 @@ gnome_todo_LDADD += $(top_builddir)/plugins/todo-txt/libtodotxt.la
 gnome_todo_DEPENDENCIES += $(top_builddir)/plugins/todo-txt/libtodotxt.la
 endif
 
+if BUILD_TODOIST_PLUGIN
+gnome_todo_LDFLAGS += -Wl,--undefined=gtd_plugin_todoist_register_types
+gnome_todo_LDADD += $(top_builddir)/plugins/todoist/libtodoist.la
+gnome_todo_DEPENDENCIES += $(top_builddir)/plugins/todoist/libtodoist.la
+endif
+
 #
 # Export headers to [PREFIX]/include/gnome-todo
 #
diff --git a/src/meson.build b/src/meson.build
index b0dc444..b5bfc68 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -165,6 +165,11 @@ if get_option('enable-todo-txt-plugin')
   gnome_todo_libs += [libtodotxt_lib]
 endif
 
+if get_option('enable-todoist-plugin')
+  ldflags += ['-Wl,--undefined=gtd_plugin_todoist_register_types']
+  gnome_todo_libs += [libtodoist_lib]
+endif
+
 gnome_todo_ldflags = []
 
 if host_machine.system().contains('linux')



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