[gnome-calendar] app: implemented sync action
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] app: implemented sync action
- Date: Thu, 4 Dec 2014 22:44:00 +0000 (UTC)
commit 2e8b677d6ae853e979c6c074315df334c607a57e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Nov 21 19:17:02 2014 -0200
app: implemented sync action
Useful when the local calendar differs from the remote calendar (i.e. you added an event at Google
Calendar).
data/ui/menus.ui | 5 ++++
src/gcal-application.c | 17 +++++++++++++++
src/gcal-manager.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
src/gcal-manager.h | 2 +
4 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/menus.ui b/data/ui/menus.ui
index f85deee..8beb1b5 100644
--- a/data/ui/menus.ui
+++ b/data/ui/menus.ui
@@ -32,6 +32,11 @@
<attribute name="label" translatable="yes">_New Event</attribute>
<attribute name="action">app.new</attribute>
</item>
+ <item>
+ <attribute name="label" translatable="yes">_Synchronize</attribute>
+ <attribute name="action">app.sync</attribute>
+ <attribute name="accel">F5</attribute>
+ </item>
</section>
</menu>
</interface>
diff --git a/src/gcal-application.c b/src/gcal-application.c
index a0d2d49..4d388f9 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -64,6 +64,10 @@ static void gcal_application_show_about (GSimpleAction *
GVariant *parameter,
gpointer user_data);
+static void gcal_application_sync (GSimpleAction *sync,
+ GVariant *parameter,
+ gpointer app);
+
static void gcal_application_quit (GSimpleAction *simple,
GVariant *parameter,
gpointer user_data);
@@ -83,6 +87,7 @@ static GOptionEntry gcal_application_goptions[] = {
static const GActionEntry gcal_app_entries[] = {
{ "new", gcal_application_create_new_event },
+ { "sync", gcal_application_sync },
{ "search", gcal_application_launch_search },
{ "about", gcal_application_show_about },
{ "quit", gcal_application_quit },
@@ -265,6 +270,18 @@ gcal_application_create_new_event (GSimpleAction *new_event,
}
static void
+gcal_application_sync (GSimpleAction *sync,
+ GVariant *parameter,
+ gpointer app)
+{
+ GcalApplicationPrivate *priv;
+
+ priv = gcal_application_get_instance_private (GCAL_APPLICATION (app));
+
+ gcal_manager_refresh (priv->manager);
+}
+
+static void
gcal_application_launch_search (GSimpleAction *search,
GVariant *parameter,
gpointer app)
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index 13ecbd6..2795e40 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -90,6 +90,10 @@ static void on_client_connected (GObject *sour
GAsyncResult *result,
gpointer user_data);
+static void on_client_refreshed (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data);
+
static void on_event_updated (GObject *source_object,
GAsyncResult *result,
gpointer user_data);
@@ -282,6 +286,27 @@ on_client_connected (GObject *source_object,
}
}
+
+static void
+on_client_refreshed (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GError *error;
+
+ error = NULL;
+ if (e_client_refresh_finish (E_CLIENT (source_object), result, &error))
+ {
+ /* FIXME: add notification to UI */
+ ;
+ }
+ else
+ {
+ /* FIXME: do something when there was some error */
+ g_warning ("Error synchronizing client");
+ }
+}
+
/**
* on_component_updated:
* @source_object: { link ECalClient} source
@@ -600,6 +625,35 @@ gcal_manager_get_default_source (GcalManager *manager)
return source_uid;
}
+void
+gcal_manager_refresh (GcalManager *manager)
+{
+ GcalManagerPrivate *priv;
+ GList *clients;
+ GList *l;
+
+ priv = gcal_manager_get_instance_private (manager);
+ clients = g_hash_table_get_values (priv->clients);
+
+ /* refresh clients */
+ for (l = clients; l != NULL; l = l->next)
+ {
+ GcalManagerUnit *unit;
+
+ unit = (GcalManagerUnit*) l->data;
+
+ if (! e_client_check_refresh_supported (E_CLIENT (unit->client)))
+ continue;
+
+ e_client_refresh (E_CLIENT (unit->client),
+ NULL,
+ on_client_refreshed,
+ manager);
+ }
+
+ g_list_free (clients);
+}
+
gboolean
gcal_manager_is_client_writable (GcalManager *manager,
ESource *source)
diff --git a/src/gcal-manager.h b/src/gcal-manager.h
index 5137513..030755c 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -81,6 +81,8 @@ gchar* gcal_manager_add_source (GcalManager *manager
gchar* gcal_manager_get_default_source (GcalManager *manager);
+void gcal_manager_refresh (GcalManager *manager);
+
gboolean gcal_manager_is_client_writable (GcalManager *manager,
ESource *source);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]