[gnome-todo/wip/gbsneto/plugins] manager: bring back ::default-provider
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo/wip/gbsneto/plugins] manager: bring back ::default-provider
- Date: Fri, 15 Jan 2016 00:24:23 +0000 (UTC)
commit 0410dbd759e44d9dc5e93820ff52eed8c8b2ca9e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Jan 10 21:13:34 2016 -0200
manager: bring back ::default-provider
This was removed during the transition period
to the new plugin system. Now that things are
more or less settled, I'm bringing this feature
back.
data/org.gnome.todo.gschema.xml | 6 +-
src/gtd-manager.c | 91 +++++++++++++---------------------
src/provider/gtd-provider-selector.c | 14 ++---
3 files changed, 43 insertions(+), 68 deletions(-)
---
diff --git a/data/org.gnome.todo.gschema.xml b/data/org.gnome.todo.gschema.xml
index 5300b4e..a7bfccf 100644
--- a/data/org.gnome.todo.gschema.xml
+++ b/data/org.gnome.todo.gschema.xml
@@ -21,10 +21,10 @@
<summary>First run of GNOME To Do</summary>
<description>Whether it's the first run of GNOME To Do (to run the initial setup) or
not</description>
</key>
- <key name="storage-location" type="s">
+ <key name="default-provider" type="s">
<default>"local"</default>
- <summary>Default location to add new lists to</summary>
- <description>The identifier of the default location to add new lists to</description>
+ <summary>Default provider to add new lists to</summary>
+ <description>The identifier of the default provider to add new lists to</description>
</key>
</schema>
</schemalist>
diff --git a/src/gtd-manager.c b/src/gtd-manager.c
index 49fabeb..3bee5bd 100644
--- a/src/gtd-manager.c
+++ b/src/gtd-manager.c
@@ -52,7 +52,6 @@ GtdManager *gtd_manager_instance = NULL;
enum
{
- DEFAULT_PROVIDER_CHANGED,
LIST_ADDED,
LIST_CHANGED,
LIST_REMOVED,
@@ -74,6 +73,26 @@ enum
static guint signals[NUM_SIGNALS] = { 0, };
static void
+check_provider_is_default (GtdManager *manager,
+ GtdProvider *provider)
+{
+ GtdManagerPrivate *priv;
+ gchar *default_provider;
+
+ priv = manager->priv;
+ default_provider = g_settings_get_string (priv->settings, "default-provider");
+
+ if (g_strcmp0 (default_provider, gtd_provider_get_id (provider)) == 0)
+ {
+ g_set_object (&priv->default_provider, provider);
+
+ g_object_notify (G_OBJECT (manager), "default-provider");
+ }
+
+ g_free (default_provider);
+}
+
+static void
emit_show_error_message (GtdManager *manager,
const gchar *primary_text,
const gchar *secondary_text)
@@ -123,19 +142,6 @@ gtd_manager_set_property (GObject *object,
}
static void
-gtd_manager_constructed (GObject *object)
-{
- GtdManagerPrivate *priv = GTD_MANAGER (object)->priv;
- gchar *default_location;
-
- G_OBJECT_CLASS (gtd_manager_parent_class)->constructed (object);
-
- default_location = g_settings_get_string (priv->settings, "storage-location");
-
- g_free (default_location);
-}
-
-static void
gtd_manager_class_init (GtdManagerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -143,7 +149,6 @@ gtd_manager_class_init (GtdManagerClass *klass)
object_class->finalize = gtd_manager_finalize;
object_class->get_property = gtd_manager_get_property;
object_class->set_property = gtd_manager_set_property;
- object_class->constructed = gtd_manager_constructed;
/**
* GtdManager::goa-client:
@@ -160,25 +165,6 @@ gtd_manager_class_init (GtdManagerClass *klass)
G_PARAM_READWRITE));
/**
- * GtdManager::default-provider-changed:
- *
- * The ::default-provider-changed signal is emmited when a new #GtdStorage
- * is set as default.
- */
- signals[DEFAULT_PROVIDER_CHANGED] =
- g_signal_new ("default-provider-changed",
- GTD_TYPE_MANAGER,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- NULL,
- G_TYPE_NONE,
- 2,
- GTD_TYPE_PROVIDER,
- GTD_TYPE_PROVIDER);
-
- /**
* GtdManager::list-added:
*
* The ::list-added signal is emmited after a #GtdTaskList
@@ -432,6 +418,9 @@ gtd_manager__provider_added (GtdPluginManager *plugin_manager,
G_CALLBACK (gtd_manager__list_removed),
self);
+ /* If we just added the default provider, update the property */
+ check_provider_is_default (self, provider);
+
g_signal_emit (self, signals[PROVIDER_ADDED], 0, provider);
}
@@ -709,32 +698,20 @@ void
gtd_manager_set_default_provider (GtdManager *manager,
GtdProvider *provider)
{
+ GtdManagerPrivate *priv;
+
g_return_if_fail (GTD_IS_MANAGER (manager));
-/*
- if (!gtd_storage_get_is_default (default_storage))
+
+ priv = manager->priv;
+
+ if (g_set_object (&priv->default_provider, provider))
{
- GtdStorage *previus_default = NULL;
- GList *l;
-
- g_settings_set_string (manager->priv->settings,
- "storage-location",
- gtd_storage_get_id (default_storage));
-
- for (l = manager->priv->storage_locations; l != NULL; l = l->next)
- {
- if (gtd_storage_get_is_default (l->data))
- previus_default = l->data;
-
- gtd_storage_set_is_default (l->data, l->data == default_storage);
- }
-
- g_signal_emit (manager,
- signals[DEFAULT_PROVIDER_CHANGED],
- 0,
- default_storage,
- previus_default);
+ g_settings_set_string (priv->settings,
+ "default-provider",
+ provider ? gtd_provider_get_id (provider) : "local");
+
+ g_object_notify (G_OBJECT (manager), "default-provider");
}
- */
}
/**
diff --git a/src/provider/gtd-provider-selector.c b/src/provider/gtd-provider-selector.c
index 89f8705..3398062 100644
--- a/src/provider/gtd-provider-selector.c
+++ b/src/provider/gtd-provider-selector.c
@@ -89,20 +89,18 @@ display_header_func (GtkListBoxRow *row,
}
static void
-gtd_provider_selector__default_provider_changed (GtdProviderSelector *selector,
- GtdProvider *current,
- GtdProvider *previous)
+gtd_provider_selector__default_provider_changed (GtdProviderSelector *selector)
{
+ GtdProvider *current;
+ GtdManager *manager;
GList *children;
GList *l;
- g_return_if_fail (GTD_IS_PROVIDER_SELECTOR (selector));
- g_return_if_fail (GTD_IS_PROVIDER (previous));
- g_return_if_fail (GTD_IS_PROVIDER (current));
-
if (!selector->select_default)
return;
+ manager = gtd_manager_get_default ();
+ current = gtd_manager_get_default_provider (manager);
children = gtk_container_get_children (GTK_CONTAINER (selector->listbox));
for (l = children; l != NULL; l = l->next)
@@ -515,7 +513,7 @@ gtd_provider_selector_init (GtdProviderSelector *self)
gtd_provider_selector__fill_accounts (self);
g_signal_connect_swapped (manager,
- "default-provider-changed",
+ "notify::default-provider",
G_CALLBACK (gtd_provider_selector__default_provider_changed),
self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]