[Telepathy-commits] [telepathy-mission-control/master] Keep track of active connections in a tmp file
Alberto Mardegan
alberto.mardegan at nokia.com
Mon Feb 16 00:13:58 PST 2009
---
src/mcd-account-manager.c | 51 +++++++++++++++++++++++++++++++++++++++++++++
src/mcd-account-manager.h | 3 ++
src/mcd-account.c | 3 ++
3 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c
index a35117b..64250c0 100644
--- a/src/mcd-account-manager.c
+++ b/src/mcd-account-manager.c
@@ -80,6 +80,8 @@ struct _McdAccountManagerPrivate
GKeyFile *keyfile; /* configuration file */
GHashTable *accounts;
+
+ gchar *account_connections_file; /* temporary file */
};
typedef struct
@@ -619,6 +621,9 @@ _mcd_account_manager_finalize (GObject *object)
write_conf (priv->keyfile);
g_key_file_free (priv->keyfile);
+ remove (priv->account_connections_file);
+ g_free (priv->account_connections_file);
+
g_hash_table_destroy (priv->accounts);
G_OBJECT_CLASS (mcd_account_manager_parent_class)->finalize (object);
@@ -672,6 +677,9 @@ mcd_account_manager_init (McdAccountManager *account_manager)
priv->accounts = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, unref_account);
+ priv->account_connections_file =
+ g_build_filename (g_get_tmp_dir (), ".mc_connections", NULL);
+
priv->keyfile = g_key_file_new ();
conf_filename = get_account_conf_filename ();
g_debug ("Loading accounts from %s", conf_filename);
@@ -787,3 +795,46 @@ mcd_account_manager_get_config (McdAccountManager *account_manager)
return account_manager->priv->keyfile;
}
+/*
+ * _mcd_account_manager_store_account_connections:
+ * @account_manager: the #McdAccountManager.
+ *
+ * This function is used to remember what connection an account was bound to.
+ * The data is stored in a temporary file, and can be read when MC restarts
+ * after a crash.
+ */
+void
+_mcd_account_manager_store_account_connections (McdAccountManager *manager)
+{
+ McdAccountManagerPrivate *priv;
+ GHashTableIter iter;
+ const gchar *account_name, *connection_path, *connection_name;
+ McdAccount *account;
+ FILE *file;
+
+ g_return_if_fail (MCD_IS_ACCOUNT_MANAGER (manager));
+ g_return_if_fail (account != NULL);
+ priv = manager->priv;
+
+ file = fopen (priv->account_connections_file, "w");
+ if (G_UNLIKELY (!file)) return;
+
+ g_hash_table_iter_init (&iter, priv->accounts);
+ while (g_hash_table_iter_next (&iter, (gpointer)&account_name,
+ (gpointer)&account))
+ {
+ McdConnection *connection;
+
+ connection = mcd_account_get_connection (account);
+ if (connection)
+ {
+ connection_path = mcd_connection_get_object_path (connection);
+ connection_name = mcd_connection_get_name (connection);
+ if (connection_path && connection_name)
+ fprintf (file, "%s\t%s\t%s\n",
+ connection_path, connection_name, account_name);
+ }
+ }
+ fclose (file);
+}
+
diff --git a/src/mcd-account-manager.h b/src/mcd-account-manager.h
index 4b4273d..b63430b 100644
--- a/src/mcd-account-manager.h
+++ b/src/mcd-account-manager.h
@@ -103,5 +103,8 @@ void mcd_account_manager_create_account (McdAccountManager *account_manager,
McdGetAccountCb callback,
gpointer user_data,
GDestroyNotify destroy);
+G_GNUC_INTERNAL
+void _mcd_account_manager_store_account_connections
+ (McdAccountManager *manager);
#endif
diff --git a/src/mcd-account.c b/src/mcd-account.c
index 777e993..baee4cc 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -2247,6 +2247,9 @@ _mcd_account_tp_connection_changed (McdAccount *account)
get_connection ((TpSvcDBusProperties *)account, "Connection", &value);
mcd_account_changed_property (account, "Connection", &value);
g_value_unset (&value);
+
+ _mcd_account_manager_store_account_connections
+ (account->priv->account_manager);
}
McdConnection *
--
1.5.6.5
More information about the telepathy-commits
mailing list