/*
- * Copyright (C) 2008 Collabora Ltd.
+ * Copyright (C) 2009 Collabora Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
#include <glib.h>
#include <glib/gi18n.h>
#include <gconf/gconf-client.h>
+#include <telepathy-glib/account-manager.h>
#include <telepathy-glib/util.h>
+#include <telepathy-glib/defs.h>
#include <dbus/dbus-protocol.h>
#include <gnome-keyring.h>
-#include <libempathy/empathy-account-manager.h>
#include <libempathy/empathy-account-settings.h>
#include <libempathy/empathy-connection-managers.h>
{ "sofiasip", "sip" },
};
+typedef struct {
+ gchar *account_name;
+ gboolean enable;
+} Misc;
+
static gchar *
_account_name_from_key (const gchar *key)
{
{
const gchar *base, *slash;
gchar *account_name;
+ gchar *ret;
account_name = _account_name_from_key (key);
base = strstr (key, account_name);
slash = strchr (base, '/');
+
+ ret = g_strdup (slash+1);
g_free (account_name);
- return g_strdup (slash+1);
+ return ret;
}
static gchar *
if (!tp_strdiff (protocol, "local-xmpp"))
return g_strdup (_("People Nearby"));
- return g_strdup_printf ("%s account", protocol);
+ return g_strdup_printf (_("%s account"), protocol);
}
static const gchar *
{
TpConnectionManager *tp_cm = l->data;
- /* Only use haze if no other cm provides this account */
+ /* Only use haze if no other cm provides this protocol */
if (!tp_strdiff (tp_connection_manager_get_name (tp_cm), "haze"))
{
haze = tp_cm;
return cm != NULL ? tp_connection_manager_get_name (cm) : NULL;
}
+static void
+_move_contents (const gchar *old, const gchar *new)
+{
+ GDir *source;
+ const gchar *f;
+ int ret;
+
+ ret = g_mkdir_with_parents (new, 0777);
+ if (ret == -1)
+ return;
+
+ source = g_dir_open (old, 0, NULL);
+ if (source == NULL)
+ return;
+
+ while ((f = g_dir_read_name (source)) != NULL)
+ {
+ gchar *old_path;
+ gchar *new_path;
+
+ old_path = g_build_path (G_DIR_SEPARATOR_S, old, f, NULL);
+ new_path = g_build_path (G_DIR_SEPARATOR_S, new, f, NULL);
+
+ if (g_file_test (old_path, G_FILE_TEST_IS_DIR))
+ {
+ _move_contents (old_path, new_path);
+ }
+ else
+ {
+ GFile *f_old, *f_new;
+
+ f_old = g_file_new_for_path (old_path);
+ f_new = g_file_new_for_path (new_path);
+
+ g_file_move (f_old, f_new, G_FILE_COPY_NONE,
+ NULL, NULL, NULL, NULL);
+
+ g_object_unref (f_old);
+ g_object_unref (f_new);
+ }
+
+ g_free (old_path);
+ g_free (new_path);
+ }
+
+ g_dir_close (source);
+}
+
+static void
+_move_logs (TpAccount *account, const gchar *account_name)
+{
+ gchar *old_path, *new_path, *escaped;
+ const gchar *name;
+
+ name = tp_proxy_get_object_path (account);
+ if (g_str_has_prefix (name, TP_ACCOUNT_OBJECT_PATH_BASE))
+ name += strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
+
+ escaped = g_strdelimit (g_strdup (name), "/", '_');
+ new_path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
+ PACKAGE_NAME, "logs", escaped, NULL);
+ g_free (escaped);
+
+ old_path = g_build_path (G_DIR_SEPARATOR_S,
+ g_get_home_dir (),
+ ".gnome2", PACKAGE_NAME, "logs", account_name, NULL);
+
+ _move_contents (old_path, new_path);
+}
+
static void
_create_account_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
- EmpathyAccount *account;
+ TpAccount *account;
GError *error = NULL;
+ Misc *misc = (Misc *) user_data;
if (!empathy_account_settings_apply_finish (
EMPATHY_ACCOUNT_SETTINGS (source), result, &error))
{
- DEBUG ("Failed to create account: %s",
- error ? error->message : "No error given");
+ DEBUG ("Failed to create account: %s", error->message);
g_error_free (error);
goto out;
}
- DEBUG ("account created\n");
+ DEBUG ("account created");
account = empathy_account_settings_get_account (
EMPATHY_ACCOUNT_SETTINGS (source));
- empathy_account_set_enabled_async (account,
- GPOINTER_TO_INT (user_data), NULL, NULL);
+
+ _move_logs (account, misc->account_name);
+
+ tp_account_set_enabled_async (account,
+ misc->enable, NULL, NULL);
+
+ g_free (misc->account_name);
+ g_slice_free (Misc, misc);
out:
g_object_unref (source);
static gchar *
_get_protocol_from_profile (const gchar *profile)
{
- gint i;
+ guint i;
- DEBUG ("profile: %s\n", profile);
+ DEBUG ("profile: %s", profile);
for (i = 0; i < G_N_ELEMENTS (profile_protocol_map); i++)
if (!tp_strdiff (profile, profile_protocol_map[i].profile))
GConfEntry *entry;
gchar *param;
- entry = (GConfEntry*) tmp->data;
+ entry = (GConfEntry *) tmp->data;
param = _param_name_from_key (gconf_entry_get_key (entry));
if (g_str_has_prefix (param, "param-"))
GConfClient *client)
{
gchar *account_name = _account_name_from_key (path);
- EmpathyAccountSettings *settings;
+ EmpathyAccountSettings *settings = NULL;
GError *error = NULL;
GSList *entries = NULL;
gchar *profile = NULL;
gchar *key;
gboolean enabled = FALSE;
gboolean ret = FALSE;
+ Misc *misc;
DEBUG ("Starting import of %s (%s)", path, account_name);
if (profile == NULL)
{
- DEBUG ("Account is missing a profile entry\n");
+ DEBUG ("Account is missing a profile entry");
goto failed;
}
if (entries == NULL)
{
-
- DEBUG ("Failed to get all entries: %s\n", error->message);
+ DEBUG ("Failed to get all entries: %s", error->message);
g_error_free (error);
goto failed;
}
key = g_strdup_printf ("%s/enabled", path);
enabled = gconf_client_get_bool (client, key, NULL);
g_free (key);
+
+ misc = g_slice_new (Misc);
+ misc->account_name = account_name;
+ misc->enable = enabled;
+
empathy_account_settings_apply_async (settings,
- _create_account_cb, GINT_TO_POINTER (enabled));
+ _create_account_cb, misc);
ret = TRUE;
out:
g_free (protocol);
g_free (profile);
g_slist_free (entries);
- g_free (account_name);
return ret;
failed:
DEBUG ("Failed to import %s", path);
+ g_free (account_name);
if (settings != NULL)
g_object_unref (settings);
goto out;
if (error != NULL)
{
- DEBUG ("Failed to get import_mc4_accounts key: %s\n", error->message);
+ DEBUG ("Failed to get import_mc4_accounts key: %s", error->message);
g_error_free (error);
goto out;
}
goto out;
}
- DEBUG ("MC 4 accounts are going to be imported\n");
+ DEBUG ("MC 4 accounts are going to be imported");
dirs = gconf_client_all_dirs (client, MC_ACCOUNTS_GCONF_BASE, &error);
if (error != NULL)
{
- DEBUG ("Failed to get MC4 account dirs: %s\n",
+ DEBUG ("Failed to get MC4 account dirs: %s",
error->message);
g_clear_error (&error);
g_object_unref (client);
for (dir = dirs; NULL != dir; dir = dir->next)
{
- if (import_one_account ((gchar *)dir->data, managers, client))
+ if (import_one_account ((gchar *) dir->data, managers, client))
imported = TRUE;
g_free (dir->data);
}