2 * connectnow home widget for the maemo desktop.
3 * Copyright (C) 2010 Nicolai Hess
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "connectnow-load-and-store.h"
21 #define CONNECTNOW_HOME_PLUGIN_SETTINGS_FILE "/.connectnow_home_widget"
25 read_settings(ConnectNowHomePlugin *desktop_plugin)
31 keyFile = g_key_file_new();
32 fileName = g_strconcat(g_get_home_dir(), CONNECTNOW_HOME_PLUGIN_SETTINGS_FILE, NULL);
33 fileExists = g_key_file_load_from_file (keyFile, fileName, G_KEY_FILE_KEEP_COMMENTS, NULL);
37 if(g_key_file_has_key(keyFile, desktop_plugin->iD, "widget_size", NULL))
39 desktop_plugin->widget_size = g_key_file_get_integer(keyFile, desktop_plugin->iD, "widget_size", NULL);
41 if(g_key_file_has_key(keyFile, desktop_plugin->iD, "hide_connection_name", NULL))
43 desktop_plugin->hide_connection_name = g_key_file_get_boolean(keyFile, desktop_plugin->iD, "hide_connection_name", NULL);
45 if(g_key_file_has_key(keyFile, desktop_plugin->iD, "connectedIcon", NULL))
47 desktop_plugin->connectedImageName = g_key_file_get_string(keyFile, desktop_plugin->iD, "connectedIcon", NULL);
51 desktop_plugin->connectedImageName = g_strdup(GENERAL_CONNECTED);
53 if(g_key_file_has_key(keyFile, desktop_plugin->iD, "disconnectedIcon", NULL))
55 desktop_plugin->disconnectedImageName = g_key_file_get_string(keyFile, desktop_plugin->iD, "disconnectedIcon", NULL);
59 desktop_plugin->disconnectedImageName = g_strdup(GENERAL_DISCONNECTED);
61 desktop_plugin->connectedImage = load_image(desktop_plugin->connectedImageName);
62 desktop_plugin->disconnectedImage = load_image(desktop_plugin->disconnectedImageName);
63 desktop_plugin->connection_name = g_key_file_get_string(keyFile, desktop_plugin->iD, "connection_name", &error);
66 desktop_plugin->connection_id = g_key_file_get_string(keyFile, desktop_plugin->iD, "connection_id", &error);
70 g_key_file_free(keyFile);
78 desktop_plugin->connection_name = NULL;
79 desktop_plugin->connection_id = NULL;
80 g_key_file_free(keyFile);
85 connect_now_save_settings(ConnectNowHomePlugin* desktop_plugin)
93 keyFile = g_key_file_new();
94 filename = g_strconcat (g_get_home_dir(), CONNECTNOW_HOME_PLUGIN_SETTINGS_FILE, NULL);
95 g_key_file_load_from_file (keyFile, filename, G_KEY_FILE_KEEP_COMMENTS, NULL);
96 if(desktop_plugin->connection_id)
97 g_key_file_set_string(keyFile, desktop_plugin->iD, "connection_id", desktop_plugin->connection_id);
98 if(desktop_plugin->connection_name)
99 g_key_file_set_string(keyFile, desktop_plugin->iD, "connection_name", desktop_plugin->connection_name);
101 g_key_file_set_integer(keyFile, desktop_plugin->iD, "widget_size", desktop_plugin->widget_size);
102 g_key_file_set_boolean(keyFile, desktop_plugin->iD, "hide_connection_name", desktop_plugin->hide_connection_name);
103 if(desktop_plugin->connectedImageName)
105 g_key_file_set_string(keyFile, desktop_plugin->iD, "connectedIcon", desktop_plugin->connectedImageName);
109 g_key_file_remove_key(keyFile, desktop_plugin->iD, "connectedIcon", NULL);
111 if(desktop_plugin->disconnectedImageName)
113 g_key_file_set_string(keyFile, desktop_plugin->iD, "disconnectedIcon", desktop_plugin->disconnectedImageName);
117 g_key_file_remove_key(keyFile, desktop_plugin->iD, "disconnectedIcon", NULL);
119 fileData = g_key_file_to_data (keyFile, &size, NULL);
120 g_file_set_contents(filename, fileData, size, NULL);
122 g_key_file_free (keyFile);
128 load_image(const gchar* image_name)
130 GdkPixbuf* image = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
132 CONNECTNOW_DEFAULT_WIDGET_WIDTH,
137 image = gdk_pixbuf_new_from_file_at_size(image_name,
138 CONNECTNOW_DEFAULT_WIDGET_WIDTH,
139 CONNECTNOW_DEFAULT_WIDGET_WIDTH,