added possibility to load and to save config of application
authorVlad Vasiliev <vlad@toshiba2.oblgaz>
Sun, 4 Apr 2010 15:52:14 +0000 (18:52 +0300)
committerVlad Vasiliev <vlad@toshiba2.oblgaz>
Sun, 4 Apr 2010 15:52:14 +0000 (18:52 +0300)
applet/src/Makefile.am
applet/src/livewp-common.h
applet/src/livewp-config.c [new file with mode: 0644]
applet/src/livewp-config.h [new file with mode: 0644]
applet/src/livewp-home-widget.c
applet/src/livewp-home-widget.h

index 23c9dec..a4b7464 100644 (file)
@@ -7,8 +7,8 @@ liblivewp_home_widget_la_SOURCES = livewp-home-widget.c livewp-home-widget.h \
                                   livewp-astro.c livewp-astro.h \
                                   livewp-rules.c livewp-rules.h \
                                   livewp-settings.c livewp-settings.h livewp-common.h \
-                                  livewp-multiactor.c livewp-multiactor.h
-
+                                  livewp-multiactor.c livewp-multiactor.h \
+                                  livewp-config.c livewp-config.h
 liblivewp_home_widget_la_LIBADD = $(EXAMPLE_LIBS) 
 
 AM_CFLAGS = -Wall $(EXAMPLE_CFLAGS) 
index dafabaa..4e74a2e 100644 (file)
@@ -41,3 +41,10 @@ typedef struct {
 
 } MultiActor;
 
+typedef struct _Animation_WallpaperPrivate Animation_WallpaperPrivate;
+struct _Animation_WallpaperPrivate
+{
+      gint timer;
+      gchar *theme;
+};
+
diff --git a/applet/src/livewp-config.c b/applet/src/livewp-config.c
new file mode 100644 (file)
index 0000000..9b15b75
--- /dev/null
@@ -0,0 +1,67 @@
+/* vim: set sw=4 ts=4 et: */
+/*
+ * This file is part of Live Wallpaper (livewp)
+ * 
+ * Copyright (C) 2010 Vlad Vasiliev
+ * Copyright (C) 2010 Tanya Makova
+ *       for the code
+ * 
+ * This software 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 software 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 software; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+*/
+/*******************************************************************************/
+#include "livewp-config.h"
+/*******************************************************************************/
+gint 
+read_config(Animation_WallpaperPrivate *priv) {
+
+    GConfValue *value = NULL;
+    GConfClient *gconf_client = NULL;
+    GSList *stlist = NULL;
+    GError *gerror = NULL;
+    gchar *tmp = NULL;
+
+    gconf_client = gconf_client_get_default();
+    if (!gconf_client) {
+        fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
+        return -1;
+    }
+    /* get Theme default Modern */
+    tmp = gconf_client_get_string(gconf_client,
+                                  GCONF_KEY_THEME, NULL);
+    if (tmp){
+        priv->theme = tmp;
+    }else
+        priv->theme = g_strdup("Modern");
+
+    return 0;
+}
+
+/*******************************************************************************/
+void
+save_config(Animation_WallpaperPrivate *priv) {
+
+    GConfClient *gconf_client;
+    gconf_client = gconf_client_get_default();
+    if (!gconf_client) {
+        fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
+        return -1;
+    }
+    /* Save Weather source name. */
+    if (priv->theme)
+        gconf_client_set_string(gconf_client,
+                  GCONF_KEY_THEME,
+                  priv->theme, NULL);
+}
diff --git a/applet/src/livewp-config.h b/applet/src/livewp-config.h
new file mode 100644 (file)
index 0000000..f6dc5f3
--- /dev/null
@@ -0,0 +1,32 @@
+/* vim: set sw=4 ts=4 et: */
+/*
+ * This file is part of Live Wallpaper (livewp)
+ * 
+ * Copyright (C) 2010 Vlad Vasiliev
+ * Copyright (C) 2010 Tanya Makova
+ *       for the code
+ * 
+ * This software 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 software 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 software; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+*/
+/*******************************************************************************/
+#include "livewp-common.h"
+#include <gconf/gconf-client.h>
+
+#define GCONF_KEY_PREFIX                            "/apps/maemo/livewp"
+#define GCONF_KEY_THEME                             GCONF_KEY_PREFIX"/theme"
+gint read_config(Animation_WallpaperPrivate *priv); 
+void save_config(Animation_WallpaperPrivate *priv); 
+
index fb9f070..e3e0ff3 100644 (file)
@@ -558,23 +558,25 @@ desktop_plugin_visible_notify (GObject    *object,
 static void
 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
 {
-  GtkWidget *label;
-  Animation_WallpaperPrivate *priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
-  desktop_plugin->priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
-  label = gtk_label_new (""); 
-  //desktop_plugin->priv->main_widget = label;
-  gtk_widget_set_size_request(label, 95, 30);
-  gtk_widget_show (label);
-  hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
-  g_signal_connect (desktop_plugin, "show-settings",
+    GtkWidget *label;
+
+    Animation_WallpaperPrivate *priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
+    desktop_plugin->priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
+    /* Load config */
+    read_config(priv);
+    label = gtk_label_new (""); 
+    gtk_widget_set_size_request(label, 95, 30);
+    gtk_widget_show (label);
+    hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
+    g_signal_connect (desktop_plugin, "show-settings",
                             G_CALLBACK (lw_settings), NULL);
-  g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
+    g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
                      G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
 
-  gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
-  init_applet_position();
-  init_scene(desktop_plugin);
-  priv->timer = g_timeout_add(50, plugin_on_timeout, desktop_plugin);
+    gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
+    init_applet_position();
+    init_scene(desktop_plugin);
+    priv->timer = g_timeout_add(50, plugin_on_timeout, desktop_plugin);
 }
 
 static void
@@ -587,6 +589,8 @@ lw_applet_finalize (GObject *object)
         g_source_remove(priv->timer);
         priv->timer = NULL;
      }
+     /* Save config */
+     save_config(priv);
 }
 
 static void
index 8952ed1..58e8293 100644 (file)
@@ -50,7 +50,6 @@ typedef struct _AWallpaperPluginClass AWallpaperPluginClass;
 #define Animation_Wallpaper_HOME_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
                         Animation_Wallpaper_TYPE_HOME_PLUGIN, AWallpaperPluginClass))
 
-typedef struct _Animation_WallpaperPrivate Animation_WallpaperPrivate;
 
 struct _AWallpaperPlugin
 {
@@ -88,17 +87,13 @@ GType animation_wallpaper_plugin_get_type(void);
 
 G_END_DECLS
 
-struct _Animation_WallpaperPrivate
-{
-      gint timer;
-      gchar *theme;
-};
 void lw_settings(GtkWidget *widget, gpointer user_data);
 MultiActor *multiactor_init(gchar * name, GSList * child, gint x, gint y, gint z, double scale, gboolean visible);
 void multiactor_set_visible(MultiActor *ma, gboolean visible);
 void multiactor_set_scale(MultiActor *ma, double scale);
 void multiactor_set_position(MultiActor *ma, gint dx, gint dy, gint dz);
 void actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z);
-
+gint read_config(Animation_WallpaperPrivate *priv);
+void save_config(Animation_WallpaperPrivate *priv);
 
 #endif