fixed start only one copy of some themes
[livewp] / applet / src / livewp-config.c
index 4c7a06c..b84c644 100644 (file)
@@ -7,8 +7,8 @@
  *       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
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of
  * the License, or (at your option) any later version.
  * 
  * This software is distributed in the hope that it will be useful, but
@@ -44,6 +44,8 @@ current_active_view(void){
 void 
 fill_priv(Animation_WallpaperPrivate *priv)
 {
+    /* Reset data */
+    priv->hash_theme = NULL;
     /* Load config */
     read_config(priv);
     /* Set function */
@@ -139,16 +141,49 @@ read_config(Animation_WallpaperPrivate *priv) {
         gconf_value_free(value);
     } 
     /* get parameter one theme in all view */
+    priv->one_in_all_view = get_one_in_all_views_from_config();
+    return 0;
+}
+/*******************************************************************************/
+gboolean
+get_one_in_all_views_from_config(void){
+    GConfClient *gconf_client;
+    GConfValue *value = NULL;
+    gboolean result;
+
+    gconf_client = gconf_client_get_default();
+    if (!gconf_client) {
+        fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
+        return FALSE;
+    }
+    /* get parameter one theme in all view */
     value = gconf_client_get(gconf_client, GCONF_KEY_ONE_IN_ALL_VIEW, NULL);
     if (value) {
-        priv->one_in_all_view = gconf_value_get_bool(value);
+        result = gconf_value_get_bool(value);
         gconf_value_free(value);
     } else
-       priv->one_in_all_view = FALSE;
-
-    return 0;
+        result = FALSE;
+    return result;
 }
+/*******************************************************************************/
+void
+save_one_in_all_views_to_config(gboolean one_in_all_views){
+    GConfClient *gconf_client;
+
+    gconf_client = gconf_client_get_default();
+    if (!gconf_client) {
+        fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
+        return;
+    }
 
+    if (one_in_all_views)
+        gconf_client_set_bool(gconf_client,
+                              GCONF_KEY_ONE_IN_ALL_VIEW, TRUE, NULL);
+    else
+        gconf_client_set_bool(gconf_client,
+                              GCONF_KEY_ONE_IN_ALL_VIEW, FALSE, NULL);
+
+}
 /*******************************************************************************/
 void
 save_config(Animation_WallpaperPrivate *priv) {
@@ -207,12 +242,34 @@ save_config(Animation_WallpaperPrivate *priv) {
             str = NULL;
         }
     }
-    if (priv->one_in_all_view)
-        gconf_client_set_bool(gconf_client,
-                              GCONF_KEY_ONE_IN_ALL_VIEW, TRUE, NULL);
-    else
-        gconf_client_set_bool(gconf_client,
-                              GCONF_KEY_ONE_IN_ALL_VIEW, FALSE, NULL);
+}
+/*******************************************************************************/
+gint
+get_count_themes_from_config(gchar *theme_name){
+    GConfClient *gconf_client;
+    gint i, count;
+    gchar *str, *value;
 
-    
+    gconf_client = gconf_client_get_default();
+    if (!gconf_client) {
+        fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
+        return FALSE;
+    }
+    /* get count such themes */
+    count = 0;
+    for (i=1; i<=9; i++){
+        str = g_strdup_printf("%s%i", GCONF_KEY_THEME, i);
+        value = gconf_client_get_string(gconf_client, str, NULL);
+        if (str){ 
+            g_free(str);
+            str = NULL;
+        }    
+        if (value && !strcmp(value, theme_name)){
+            count++;
+        }
+
+    }
+    //fprintf(stderr, "get count_theme from config = %d\n", count);
+    return count;
 }
+