diff options
Diffstat (limited to 'src/plugins/todo-txt/gtd-provider-todo-txt.c')
-rw-r--r-- | src/plugins/todo-txt/gtd-provider-todo-txt.c | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/src/plugins/todo-txt/gtd-provider-todo-txt.c b/src/plugins/todo-txt/gtd-provider-todo-txt.c new file mode 100644 index 00000000..ab923f42 --- /dev/null +++ b/src/plugins/todo-txt/gtd-provider-todo-txt.c @@ -0,0 +1,184 @@ +/* gtd-provider-todo-txt.c + * + * Copyright (C) 2022 Jamie Murphy <hello@itsjamie.dev> + * + * 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 "GtdImportExportProviderTodoTxt" + +#include "gtd-provider-todo-txt.h" + +#include <glib/gi18n.h> + +struct _GtdProviderTodoTxt +{ + GtdObject parent; + + GIcon *icon; +}; + +static void gtd_import_export_provider_iface_init (GtdImportExportProviderInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtdProviderTodoTxt, gtd_provider_todo_txt, GTD_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (GTD_TYPE_IMPORT_EXPORT_PROVIDER, gtd_import_export_provider_iface_init)) + +enum +{ + PROP_0, + PROP_ENABLED, + PROP_DESCRIPTION, + PROP_ICON, + PROP_ID, + PROP_NAME, + PROP_PROVIDER_TYPE, + N_PROPS +}; + + +/* + * GtdImportExportProvider overrides + */ + +static const gchar* +gtd_provider_todo_txt_get_id (GtdImportExportProvider *provider) +{ + return "todo-txt"; +} + +static const gchar* +gtd_provider_todo_txt_get_name (GtdImportExportProvider *provider) +{ + return "Todo.txt"; +} + +static const gchar* +gtd_provider_todo_txt_get_provider_type (GtdImportExportProvider *provider) +{ + return "todo-txt"; +} + +static const gchar* +gtd_provider_todo_txt_get_description (GtdImportExportProvider *provider) +{ + return "Todo.txt"; +} + +static gboolean +gtd_provider_todo_txt_get_enabled (GtdImportExportProvider *provider) +{ + return TRUE; +} + +static GIcon* +gtd_provider_todo_txt_get_icon (GtdImportExportProvider *provider) +{ + GtdProviderTodoTxt *self = GTD_PROVIDER_TODO_TXT (provider); + + return self->icon; +} + +static void +gtd_import_export_provider_iface_init (GtdImportExportProviderInterface *iface) +{ + iface->get_id = gtd_provider_todo_txt_get_id; + iface->get_name = gtd_provider_todo_txt_get_name; + iface->get_provider_type = gtd_provider_todo_txt_get_provider_type; + iface->get_description = gtd_provider_todo_txt_get_description; + iface->get_enabled = gtd_provider_todo_txt_get_enabled; + // iface->refresh = gtd_provider_todo_txt_refresh; + iface->get_icon = gtd_provider_todo_txt_get_icon; +} + +/* + * GObject overrides + */ + +static void +gtd_provider_todo_txt_finalize (GObject *object) +{ + GtdProviderTodoTxt *self = (GtdProviderTodoTxt *)object; + + g_clear_object (&self->icon); + + G_OBJECT_CLASS (gtd_provider_todo_txt_parent_class)->finalize (object); +} + +static void +gtd_provider_todo_txt_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtdImportExportProvider *provider = GTD_IMPORT_EXPORT_PROVIDER (object); + + switch (prop_id) + { + case PROP_DESCRIPTION: + g_value_set_string (value, gtd_provider_todo_txt_get_description (provider)); + break; + + case PROP_ENABLED: + g_value_set_boolean (value, gtd_provider_todo_txt_get_enabled (provider)); + break; + + case PROP_ICON: + g_value_set_object (value, gtd_provider_todo_txt_get_icon (provider)); + break; + + case PROP_ID: + g_value_set_string (value, gtd_provider_todo_txt_get_id (provider)); + break; + + case PROP_NAME: + g_value_set_string (value, gtd_provider_todo_txt_get_name (provider)); + break; + + case PROP_PROVIDER_TYPE: + g_value_set_string (value, gtd_provider_todo_txt_get_provider_type (provider)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +gtd_provider_todo_txt_class_init (GtdProviderTodoTxtClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = gtd_provider_todo_txt_finalize; + object_class->get_property = gtd_provider_todo_txt_get_property; + + 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"); + g_object_class_override_property (object_class, PROP_PROVIDER_TYPE, "provider-type"); +} + +static void +gtd_provider_todo_txt_init (GtdProviderTodoTxt *self) +{ + self->icon = G_ICON (g_themed_icon_new_with_default_fallbacks ("accessories-text-editor-symbolic")); +} + +GtdProviderTodoTxt* +gtd_provider_todo_txt_new () +{ + return g_object_new (GTD_TYPE_PROVIDER_TODO_TXT, + NULL); +} |