1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Authors: Alejandro J. Cura <alecu@canonical.com>
5
* Copyright (C) 2010 Canonical Ltd.
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License version 3,
9
* as published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
#include <glib/gi18n-lib.h>
27
#include <gconf/gconf-client.h>
29
#include "gnome-settings-daemon/gnome-settings-plugin.h"
30
#include "gsd-ubuntuone.h"
32
GNOME_SETTINGS_PLUGIN_REGISTER (GsdUbuntuOne, gsd_ubuntuone)
34
#define CHECKED_BOOKMARK_FILE_KEY "/apps/gnome_settings_daemon/plugins/ubuntuone/checked_bookmark_file"
38
bookmark_file_loaded (GObject *source, GAsyncResult *res, gpointer user_data)
40
gchar *contents = NULL;
43
g_file_load_contents_finish (G_FILE (source), res, &contents, NULL, NULL, &error);
45
gchar **lines, *u1_location;
47
gboolean add_it = TRUE;
49
u1_location = g_build_filename ("file://", g_get_home_dir (), "Ubuntu%20One", NULL);
51
lines = g_strsplit (contents, "\n", -1);
52
for (i = 0; lines[i] != NULL; i++) {
53
/* Ignore empty lines */
54
if (lines[i][0] != '\0' && lines[i][0] != ' ') {
55
if (g_str_has_prefix (lines[i], u1_location)) {
63
gchar *new_contents = g_strdup_printf ("%s\n%s Ubuntu One\n", contents, u1_location);
65
if (g_file_replace_contents (G_FILE (source),
66
(const gchar *) new_contents,
67
strlen (new_contents),
70
0, NULL, NULL, &error)) {
71
GConfClient *conf_client;
73
conf_client = gconf_client_get_default ();
74
gconf_client_set_bool (conf_client, CHECKED_BOOKMARK_FILE_KEY, TRUE, NULL);
76
g_warning ("Could not save bookmarks file: %s\n", error->message);
85
g_warning ("Could not load bookmark file: %s\n", error->message);
91
check_bookmark_file (void)
94
GConfClient *conf_client;
97
/* We only check the bookmark file if we haven't already done so */
98
conf_client = gconf_client_get_default ();
99
if (!gconf_client_get_bool (conf_client, CHECKED_BOOKMARK_FILE_KEY, &error)) {
103
u1_folder = g_build_filename (g_get_home_dir (), "Ubuntu One", NULL);
104
if (g_file_test ((const gchar *) u1_folder, G_FILE_TEST_IS_DIR)) {
105
/* Load the bookmark file */
106
filename = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
107
if (filename != NULL) {
110
file = g_file_new_for_path (filename);
111
g_file_load_contents_async (file, NULL, bookmark_file_loaded, NULL);
113
g_object_unref (G_OBJECT (file));
120
g_warning ("Error getting settings: %s\n", error->message);
121
g_error_free (error);
125
g_object_unref (conf_client);
129
credentials_found_cb (SyncdaemonAuthentication *auth, SyncdaemonCredentials *credentials, gpointer user_data)
131
check_bookmark_file ();
135
delayed_syncdaemon_start (gpointer data)
137
GsdUbuntuOne *plugin;
138
SyncdaemonAuthentication *auth;
140
plugin = GSD_UBUNTUONE (data);
142
plugin->syncdaemon = syncdaemon_daemon_new ();
144
/* Check for authentication */
145
auth = syncdaemon_daemon_get_authentication (plugin->syncdaemon);
146
g_signal_connect (auth, "credentials_found",
147
G_CALLBACK (credentials_found_cb), NULL);
153
gsd_ubuntuone_init (GsdUbuntuOne *plugin)
158
gsd_ubuntuone_activate (GnomeSettingsPlugin *gsp_object)
160
GsdUbuntuOne *plugin = GSD_UBUNTUONE (gsp_object);
162
g_timeout_add (DELAYED_START_TIMEOUT, delayed_syncdaemon_start, plugin);
166
gsd_ubuntuone_dispose (GObject *object)
168
GsdUbuntuOne *plugin = GSD_UBUNTUONE (object);
170
if (plugin->syncdaemon != NULL)
171
g_object_unref (plugin->syncdaemon);
173
G_OBJECT_CLASS (gsd_ubuntuone_parent_class)->dispose (object);
178
gsd_ubuntuone_class_finalize (GsdUbuntuOneClass *klass)
184
gsd_ubuntuone_class_init (GsdUbuntuOneClass *klass)
186
GObjectClass *g_class = G_OBJECT_CLASS (klass);
187
GnomeSettingsPluginClass *gsp_class = (GnomeSettingsPluginClass *) klass;
189
g_class->dispose = gsd_ubuntuone_dispose;
190
gsp_class->activate = gsd_ubuntuone_activate;