[empathy] Add magic to automatically run tasks when empathy-auth-client is started
- From: Guillaume Desmottes <gdesmott src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy] Add magic to automatically run tasks when empathy-auth-client is started
- Date: Tue, 6 Mar 2012 15:15:27 +0000 (UTC)
commit c69625323288a119356bb6627c00f21a74f32f24
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date: Tue Mar 6 15:08:03 2012 +0100
Add magic to automatically run tasks when empathy-auth-client is started
empathy-auth-client is the best place to do such tasks as it will be run even
if using only the Shell without Empathy's UI.
https://bugzilla.gnome.org/show_bug.cgi?id=671452
data/org.gnome.Empathy.gschema.xml.in | 5 ++
libempathy/empathy-gsettings.h | 1 +
src/Makefile.am | 1 +
src/empathy-auth-client.c | 3 +
src/empathy-sanity-cleaning.c | 89 +++++++++++++++++++++++++++++++++
src/empathy-sanity-cleaning.h | 27 ++++++++++
6 files changed, 126 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.Empathy.gschema.xml.in b/data/org.gnome.Empathy.gschema.xml.in
index 8e7d9fd..8901d21 100644
--- a/data/org.gnome.Empathy.gschema.xml.in
+++ b/data/org.gnome.Empathy.gschema.xml.in
@@ -28,6 +28,11 @@
<_summary>Empathy default download folder</_summary>
<_description>The default folder to save file transfers in.</_description>
</key>
+ <key name="sanity-cleaning-number" type="u">
+ <default>0</default>
+ <_summary>Magic number used to check if sanity cleaning tasks should be run</_summary>
+ <_description>empathy-sanity-cleaning.c uses this number to check if the cleaning tasks should be executed or not. Users should not change this key manually.</_description>
+ </key>
<child name="ui" schema="org.gnome.Empathy.ui"/>
<child name="contacts" schema="org.gnome.Empathy.contacts"/>
<child name="sounds" schema="org.gnome.Empathy.sounds"/>
diff --git a/libempathy/empathy-gsettings.h b/libempathy/empathy-gsettings.h
index fd05141..2863cf9 100644
--- a/libempathy/empathy-gsettings.h
+++ b/libempathy/empathy-gsettings.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
#define EMPATHY_PREFS_AUTOCONNECT "autoconnect"
#define EMPATHY_PREFS_AUTOAWAY "autoaway"
#define EMPATHY_PREFS_FILE_TRANSFER_DEFAULT_FOLDER "file-transfer-default-folder"
+#define EMPATHY_PREFS_SANITY_CLEANING_NUMBER "sanity-cleaning-number"
#define EMPATHY_PREFS_NOTIFICATIONS_SCHEMA EMPATHY_PREFS_SCHEMA ".notifications"
#define EMPATHY_PREFS_NOTIFICATIONS_ENABLED "notifications-enabled"
diff --git a/src/Makefile.am b/src/Makefile.am
index 8ffdedc..dfde205 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -102,6 +102,7 @@ libexec_PROGRAMS += empathy-av
endif
empathy_auth_client_SOURCES = \
+ empathy-sanity-cleaning.c empathy-sanity-cleaning.h \
empathy-auth-client.c \
$(NULL)
diff --git a/src/empathy-auth-client.c b/src/empathy-auth-client.c
index 22a6252..ecf1ad1 100644
--- a/src/empathy-auth-client.c
+++ b/src/empathy-auth-client.c
@@ -41,6 +41,8 @@
#include <libempathy-gtk/empathy-tls-dialog.h>
#include <libempathy-gtk/empathy-ui-utils.h>
+#include "empathy-sanity-cleaning.h"
+
#include <gnutls/gnutls.h>
#include <extensions/extensions.h>
@@ -351,6 +353,7 @@ main (int argc,
}
start_timer ();
+ empathy_sanity_checking_run_if_needed ();
gtk_main ();
diff --git a/src/empathy-sanity-cleaning.c b/src/empathy-sanity-cleaning.c
new file mode 100644
index 0000000..95353eb
--- /dev/null
+++ b/src/empathy-sanity-cleaning.c
@@ -0,0 +1,89 @@
+/*
+ * empathy-sanity-cleaning.c
+ * Code automatically called when starting a specific version of Empathy for
+ * the first time doing misc cleaning.
+ *
+ * Copyright (C) 2012 Collabora Ltd.
+ * @author Guillaume Desmottes <guillaume desmottes collabora co uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+
+#include "empathy-sanity-cleaning.h"
+
+#include <telepathy-glib/telepathy-glib.h>
+
+#include <libempathy/empathy-gsettings.h>
+
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include <libempathy/empathy-debug.h>
+
+/*
+ * This number has to be increased each time a new task is added or modified.
+ *
+ * If the number stored in gsettings is lower than it, all the tasks will
+ * be executed.
+ */
+#define SANITY_CLEANING_NUMBER 0
+
+static void
+run_sanity_cleaning_tasks (TpAccountManager *am)
+{
+ DEBUG ("Starting sanity cleaning tasks");
+}
+
+static void
+am_prepare_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GError *error = NULL;
+ TpAccountManager *am = TP_ACCOUNT_MANAGER (source);
+
+ if (!tp_proxy_prepare_finish (am, result, &error))
+ {
+ DEBUG ("Failed to prepare account manager: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ run_sanity_cleaning_tasks (am);
+}
+
+void empathy_sanity_checking_run_if_needed (void)
+{
+ GSettings *settings;
+ guint number;
+ TpAccountManager *am;
+
+ settings = g_settings_new (EMPATHY_PREFS_SCHEMA);
+ number = g_settings_get_uint (settings, EMPATHY_PREFS_SANITY_CLEANING_NUMBER);
+
+ if (number == SANITY_CLEANING_NUMBER)
+ goto out;
+
+ am = tp_account_manager_dup ();
+
+ tp_proxy_prepare_async (am, NULL, am_prepare_cb, NULL);
+
+ g_settings_set_uint (settings, EMPATHY_PREFS_SANITY_CLEANING_NUMBER,
+ SANITY_CLEANING_NUMBER);
+
+ g_object_unref (am);
+out:
+ g_object_unref (settings);
+}
diff --git a/src/empathy-sanity-cleaning.h b/src/empathy-sanity-cleaning.h
new file mode 100644
index 0000000..593f9ad
--- /dev/null
+++ b/src/empathy-sanity-cleaning.h
@@ -0,0 +1,27 @@
+/*
+ * empathy-sanity-cleaning.h
+ *
+ * Copyright (C) 2012 Collabora Ltd.
+ * @author Guillaume Desmottes <guillaume desmottes collabora co uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __EMPATHY_SANITY_CLEANING_H__
+#define __EMPATHY_SANITY_CLEANING_H__
+
+void empathy_sanity_checking_run_if_needed (void);
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]