fixed time to change image, added icons to slideshow and flash, added change image...
[livewp] / applet / src / livewp-config.c
index 2275a10..f5ca024 100644 (file)
@@ -1,21 +1,21 @@
 /* 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 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
  * 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
@@ -24,7 +24,7 @@
 /*******************************************************************************/
 #include "livewp-config.h"
 /*******************************************************************************/
-gint 
+gint
 current_active_view(void){
     GConfClient *gconf_client = NULL;
     gint result = -1;
@@ -41,7 +41,7 @@ current_active_view(void){
 
 /*******************************************************************************/
 #ifdef APPLICATION
-void 
+void
 fill_priv(Animation_WallpaperPrivate *priv)
 {
     /* Reset data */
@@ -59,7 +59,9 @@ fill_priv(Animation_WallpaperPrivate *priv)
         priv->scene_func = (gpointer)&init_scene_Matrix;
     if (!strcmp(priv->theme, "Video"))
         priv->scene_func = (gpointer)&init_scene_Video;
-    
+    if (!strcmp(priv->theme, "Slideshow"))
+       priv->scene_func = (gpointer)&init_scene_Slideshow;
+
     priv->extheme_list = get_list_exthemes();
     GSList *store = priv->extheme_list;
     while (store){
@@ -69,6 +71,8 @@ fill_priv(Animation_WallpaperPrivate *priv)
                 priv->scene_func = (gpointer)&init_scene_External;
             if (!strcmp(priv->theme, "Conky"))
                 priv->scene_func = (gpointer)&init_scene_Conky;
+            if (!strcmp(priv->theme, "Flash"))
+                priv->scene_func = (gpointer)&init_scene_Flash;
             priv->hash_theme = store->data;
             break;
         }
@@ -78,7 +82,7 @@ fill_priv(Animation_WallpaperPrivate *priv)
 }
 #endif
 /*******************************************************************************/
-gint 
+gint
 read_config(Animation_WallpaperPrivate *priv) {
 
     GConfClient *gconf_client = NULL;
@@ -96,10 +100,10 @@ read_config(Animation_WallpaperPrivate *priv) {
     str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
     tmp = gconf_client_get_string(gconf_client,
                                   str, NULL);
-    if (str){ 
+    if (str){
         g_free(str);
         str = NULL;
-    }    
+    }
     if (tmp){
         priv->theme = tmp;
     }else
@@ -107,10 +111,10 @@ read_config(Animation_WallpaperPrivate *priv) {
     /* get Rich animation default TRUE */
     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
     value = gconf_client_get(gconf_client, str, NULL);
-    if (str){ 
+    if (str){
         g_free(str);
         str = NULL;
-    } 
+    }
     if (value) {
         priv->rich_animation = gconf_value_get_bool(value);
         gconf_value_free(value);
@@ -119,10 +123,10 @@ read_config(Animation_WallpaperPrivate *priv) {
     /* get theme additional bool aparametr 1 default  TRUE */
     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_BOOL_1, id);
     value = gconf_client_get(gconf_client, str, NULL);
-    if (str){ 
+    if (str){
         g_free(str);
         str = NULL;
-    } 
+    }
     if (value) {
         priv->theme_bool_parametr1 = gconf_value_get_bool(value);
         gconf_value_free(value);
@@ -132,14 +136,26 @@ read_config(Animation_WallpaperPrivate *priv) {
     /* get theme additional parameter 1  */
     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_STRING_1 , id);
     value = gconf_client_get(gconf_client, str, NULL);
-    if (str){ 
+    if (str){
         g_free(str);
         str = NULL;
-    } 
+    }
     if (value) {
         priv->theme_string_parametr1 = g_strdup(gconf_value_get_string(value));
         gconf_value_free(value);
-    } 
+    }
+    /* get theme additional int parameter 1  */
+    str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_INT_1 , id);
+    value = gconf_client_get(gconf_client, str, NULL);
+    if (str){
+        g_free(str);
+        str = NULL;
+    }
+    if (value) {
+        priv->theme_int_parametr1 = gconf_value_get_int(value);
+        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;
@@ -197,7 +213,7 @@ save_config(Animation_WallpaperPrivate *priv) {
         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
         return;
     }
-    
+
     if (priv->theme){
         str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
         gconf_client_set_string(gconf_client,
@@ -232,14 +248,57 @@ save_config(Animation_WallpaperPrivate *priv) {
         str = NULL;
     }
 
+    str = g_strdup_printf("%s%i",GCONF_KEY_ADDITIONAL_STRING_1, id);
     if (priv->theme_string_parametr1){
-        str = g_strdup_printf("%s%i",GCONF_KEY_ADDITIONAL_STRING_1, id);
         gconf_client_set_string(gconf_client,
                   str,
                   priv->theme_string_parametr1, NULL);
+    }else
+        gconf_client_unset(gconf_client, str, NULL);
+    if (str){
+            g_free(str);
+            str = NULL;
+    }
+    str = g_strdup_printf("%s%i",GCONF_KEY_ADDITIONAL_INT_1, id);
+    if (priv->theme_int_parametr1){
+        gconf_client_set_int(gconf_client,
+                  str,
+                  priv->theme_int_parametr1, NULL);
+    }else
+        gconf_client_unset(gconf_client, str, NULL);
+    if (str){
+            g_free(str);
+            str = 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;
 }
+