conf.c

Go to the documentation of this file.
00001 /*
00002  * File Name: conf.c
00003  */
00004 
00005 /*
00006  * This file is part of sysd.
00007  *
00008  * sysd is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * sysd is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 //----------------------------------------------------------------------------
00028 // Include Files
00029 //----------------------------------------------------------------------------
00030 
00031 #include "config.h"
00032 
00033 // system include files, between < >
00034 #include <glib.h>
00035 #include <gconf/gconf-client.h>
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039 
00040 // ereader include files, between < >
00041 #include <liberipc/eripc.h>
00042 
00043 // local include files, between " "
00044 #include "log.h"
00045 #include "conf.h"
00046 #include "connections.h"
00047 #include "locales.h"
00048 #include "i18n.h"
00049 #include "ipc.h"
00050 #include "wacom.h"
00051 
00052 #define UNUSED(x) (void)(x)
00053 
00054 
00055 //----------------------------------------------------------------------------
00056 // Type Declarations
00057 //----------------------------------------------------------------------------
00058 
00059 
00060 //----------------------------------------------------------------------------
00061 // Global Constants
00062 //----------------------------------------------------------------------------
00063 
00064 #define KEYS_SYSTEM                    KEYS_EREADER "/sys"
00065 #define KEY_GLOBAL_LOCALE              KEYS_SYSTEM "/global/locale"
00066 #define KEY_GLOBAL_TZ_OFFSET           KEYS_SYSTEM "/global/timezone_offset"
00067 #define KEY_GLOBAL_LIST_LOCALES        KEYS_SYSTEM "/global/list_locales"
00068 #define KEY_GLOBAL_LIST_LANGUAGES      KEYS_SYSTEM "/global/list_languages"
00069 #define KEY_GLOBAL_FIRST_BOOT          KEYS_SYSTEM "/global/is_first_boot"
00070 #define KEY_DISPLAY_ROTATION           KEYS_SYSTEM "/display/rotation"
00071 #define KEY_SENSOR_USE_SOUND           KEYS_SYSTEM "/sensor/use_sound"
00072 #define KEY_SENSOR_USE_LIGHT           KEYS_SYSTEM "/sensor/use_light"
00073 #define KEY_SENSOR_USE_LOCK_LEFT       KEYS_SYSTEM "/sensor/use_lock_left"
00074 #define KEY_SENSOR_USE_LOCK_RIGHT      KEYS_SYSTEM "/sensor/use_lock_right"
00075 #define KEY_SENSOR_USE_LOCK_MIDDLE     KEYS_SYSTEM "/sensor/use_lock_middle"
00076 #define KEY_POWER_IDLE_MODE             KEYS_SYSTEM "/power/idle_mode"
00077 #define KEY_POWER_MIN_STANDBY          KEYS_SYSTEM "/power/min_standby"
00078 #define KEY_POWER_USE_STYLUS           KEYS_SYSTEM "/power/use_stylus"
00079 #define KEY_POWER_STANDBY_IF_PLUGGED    KEYS_SYSTEM "/power/standby_if_plugged"
00080 #define KEY_FLIGHTMODE_MODE             KEYS_SYSTEM "/flightmode/flightmode_mode"
00081 #define KEY_PAGETURN_INVERTED           KEYS_SYSTEM "/flipbar/pageturn_inverted"
00082 #define KEY_INDEX_WITH_METADATA         KEYS_SYSTEM "/index/add_with_metadata"
00083  
00084 #define KEY_UP_DOWN_FOCUS_BEHAVIOR      "/desktop/poky/interface/gtk-up-down-focus-behavior"
00085 
00086 #define MINIMUM_STANDBY_MIN         1
00087  
00088  
00089 //----------------------------------------------------------------------------
00090 // Static Variables
00091 //----------------------------------------------------------------------------
00092 
00093 static GConfClient                  *g_gconfclient  = NULL;
00094 static gboolean                      g_number_of_langages = FALSE;
00095 
00096 
00097 //============================================================================
00098 // Local Function Definition
00099 //============================================================================
00100 
00101 static void event_gconf_value_changed(GConfClient *client,
00102                                       guint cnxn_id,
00103                                       GConfEntry *entry,
00104                                       gpointer user_data);
00105 static void set_startup_defaults(void);
00106 static void update_installed_locales(void);
00107 
00108 //============================================================================
00109 // Functions Implementation
00110 //============================================================================
00111 
00112 void conf_set_services(void)
00113 {
00114     LOGPRINTF("entry");
00115 
00116     g_type_init();
00117     g_gconfclient = gconf_client_get_default();
00118     if (g_gconfclient==NULL) 
00119     {
00120         ERRORPRINTF("Failed to connect to GConf");
00121         exit(1);
00122     }   
00123     
00124     gconf_client_add_dir(g_gconfclient,
00125                          KEYS_SYSTEM,
00126                          GCONF_CLIENT_PRELOAD_NONE,
00127                          NULL);
00128 
00129     gconf_client_notify_add(g_gconfclient,
00130                             KEYS_SYSTEM,
00131                             event_gconf_value_changed,
00132                             NULL,
00133                             NULL,
00134                             NULL);
00135     
00136     // check locales/languages available on system
00137     update_installed_locales();
00138     
00139     // initialize system settings from startup configuration
00140     set_startup_defaults();
00141 }
00142 
00143 
00144 gboolean conf_get_first_boot(void)
00145 {
00146     LOGPRINTF("entry");
00147 
00148     gboolean     first_boot = FALSE;
00149     GError       *error     = NULL;
00150     
00151     first_boot = gconf_client_get_bool(g_gconfclient, KEY_GLOBAL_FIRST_BOOT, &error);
00152     if (error)
00153     {
00154         WARNPRINTF("error fetching GConf key %s: %s", KEY_GLOBAL_FIRST_BOOT, error->message);
00155         g_error_free(error);
00156     }   
00157     LOGPRINTF("return: %d", first_boot);
00158     
00159     return first_boot;
00160 }
00161 
00162 
00163 void conf_set_first_boot(gboolean first_boot)
00164 {
00165     LOGPRINTF("entry");
00166 
00167     GError       *error     = NULL;
00168     
00169     gconf_client_set_bool(g_gconfclient, KEY_GLOBAL_FIRST_BOOT, first_boot, &error);
00170     if (error)
00171     {
00172         WARNPRINTF("error writing GConf key %s: %s", KEY_GLOBAL_FIRST_BOOT, error->message);
00173         g_error_free(error);
00174     }   
00175 }
00176 
00177 
00178 void conf_disabled_sensor_lock(void)
00179 {
00180     LOGPRINTF("entry");
00181     
00182     gboolean locked;
00183     GError   *error = NULL;
00184 
00185     locked = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_LEFT, &error);
00186     if (!error && !locked)
00187     {
00188         locked = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_RIGHT, &error);
00189         if (!error && !locked)
00190         {
00191             locked = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_MIDDLE, &error);
00192         }
00193     }
00194     
00195     if (error) 
00196     {
00197         g_error_free(error);
00198     }
00199     else if (locked)
00200     {
00201         ipc_menu_set_item_state("lock", "general", "normal");
00202     }
00203     else
00204     {
00205         ipc_menu_set_item_state("lock", "general", "disabled");
00206     }
00207 }
00208 
00209 
00210 gboolean conf_set_flightmode(gboolean is_enabled)
00211 {
00212     gboolean ret = TRUE;  // return value, TRUE = ok
00213     GError   *error = NULL;
00214 
00215     LOGPRINTF("entry");
00216 
00217     ret = gconf_client_set_bool(g_gconfclient, KEY_FLIGHTMODE_MODE, is_enabled, &error);
00218     if (error)
00219     {
00220         WARNPRINTF("error saving GConf key %s: %s", KEY_FLIGHTMODE_MODE, error->message);
00221         g_error_free(error);
00222     }
00223 
00224     return ret;
00225 }
00226 
00227 
00228 gboolean conf_is_multi_language()
00229 {
00230     return (g_number_of_langages > 1);
00231 }
00232 
00233 
00234 //============================================================================
00235 // Local Functions Implementation
00236 //============================================================================
00237 
00238 static gboolean set_locale(const gchar *locale)
00239 {
00240     gboolean retval = FALSE;
00241     GSList *locale_list;
00242     GSList *code_list;
00243     GSList *found;
00244     locale_list = locales_list_create();
00245     code_list = locales_list_codes(locale_list);
00246     
00247     found = g_slist_find_custom(code_list, locale, (GCompareFunc)strcmp);
00248     if (!found) 
00249     {
00250         WARNPRINTF("Locale [%s] not found, try en_US", locale);
00251         found = g_slist_find_custom(code_list, "en_US", (GCompareFunc)strcmp);
00252     }
00253     if (!found) 
00254     {
00255         WARNPRINTF("Locale en_US not found, try en_GB");
00256         found = g_slist_find_custom(code_list, "en_GB", (GCompareFunc)strcmp);
00257     }
00258     
00259     if (found)
00260     {
00261         LOGPRINTF("Found and set locale [%s]", (gchar *) found->data);
00262         
00263         // set locale in environment 
00264         g_setenv("LANG", found->data, TRUE);
00265         setlocale(LC_ALL, "");
00266         
00267         // report to applications
00268         ipc_send_changed_locale(found->data);
00269         
00270         retval = TRUE;
00271     }
00272     
00273     // free memory
00274     locales_list_free(locale_list);
00275     g_slist_free(code_list);
00276     
00277     return retval;
00278 }
00279 
00280 
00281 static void event_gconf_value_changed(GConfClient *client,
00282                                       guint cnxn_id,
00283                                       GConfEntry *entry,
00284                                       gpointer user_data)
00285 {
00286     UNUSED(cnxn_id);
00287     UNUSED(user_data);
00288 
00289     LOGPRINTF("entry");
00290 
00291     const gchar* key = gconf_entry_get_key(entry);
00292     if (key == NULL)
00293     {
00294         WARNPRINTF("Failed to get key name");
00295         return;
00296     }
00297     
00298     const GConfValue* value = gconf_entry_get_value(entry);
00299     if (value == NULL)
00300     {
00301         // value not set, possibly empty folder
00302         return;
00303     }
00304 
00305     LOGPRINTF("key [%s] type [%d] value [%s]", key, value->type, gconf_value_to_string(value));
00306     
00307     if (strcmp(key, KEY_GLOBAL_LOCALE) == 0)
00308     {
00309         if (value->type == GCONF_VALUE_STRING)
00310         {   
00311             const char *locale = gconf_value_get_string(value);
00312             if (locale != NULL)
00313             {
00314                 if (!set_locale(locale))
00315                 {
00316                     WARNPRINTF("Locale not found");
00317                 }
00318             }
00319         }
00320         else
00321         {
00322             WARNPRINTF("Cannot parse value of key %s", key);
00323         }
00324     }
00325     else if (strcmp(key, KEY_INDEX_WITH_METADATA) == 0)
00326     {
00327         if (value->type == GCONF_VALUE_BOOL)
00328         {
00329             sys_set_index_with_metadata(gconf_value_get_bool(value));
00330         }
00331         else
00332         {
00333             WARNPRINTF("Cannot parse value of key %s", key);
00334         }
00335     }
00336     else if (strcmp(key, KEY_PAGETURN_INVERTED) == 0)
00337     {
00338         if (value->type == GCONF_VALUE_BOOL)
00339         {
00340             sys_set_pageturn_inverted(gconf_value_get_bool(value));
00341         }
00342         else
00343         {
00344             WARNPRINTF("Cannot parse value of key %s", key);
00345         }
00346     }
00347     else if (strcmp(key, KEY_DISPLAY_ROTATION) == 0)
00348     {
00349         if (value->type == GCONF_VALUE_STRING)
00350         {   
00351             const char *rotation = gconf_value_get_string(value);
00352             if (rotation != NULL)
00353             {
00354                 sys_set_rotate_direction(rotation);
00355             }
00356         }
00357         else
00358         {
00359             WARNPRINTF("Cannot parse value of key %s", key);
00360         }
00361     }
00362     else if (strcmp(key, KEY_SENSOR_USE_SOUND) == 0)
00363     {
00364         if (value->type == GCONF_VALUE_BOOL)
00365         {   
00366             gboolean use_light     = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LIGHT, NULL);
00367             gboolean use_sound     = gconf_value_get_bool(value);
00368 
00369             sys_set_sensor_feedback(use_light, use_sound);
00370         }
00371         else
00372         {
00373             WARNPRINTF("Cannot parse value of key %s", key);
00374         }
00375     }
00376     else if (strcmp(key, KEY_SENSOR_USE_LIGHT) == 0)
00377     {
00378         if (value->type == GCONF_VALUE_BOOL)
00379         {   
00380             gboolean use_sound     = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_SOUND, NULL);
00381             gboolean use_light     = gconf_value_get_bool(value);
00382             
00383             sys_set_sensor_feedback(use_light, use_sound);
00384         }
00385         else
00386         {
00387             WARNPRINTF("Cannot parse value of key %s", key);
00388         }
00389     }
00390     else if (strcmp(key, KEY_SENSOR_USE_LOCK_LEFT) == 0)
00391     {
00392         if (value->type == GCONF_VALUE_BOOL)
00393         {   
00394             gboolean use_lock_left = gconf_value_get_bool(value);
00395             gboolean use_lock_right = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_RIGHT, NULL);
00396             gboolean use_lock_middle = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_MIDDLE, NULL);
00397             
00398             conf_disabled_sensor_lock();
00399             
00400             sys_set_sensor_lock_config(use_lock_left, use_lock_right, use_lock_middle);
00401         }
00402         else
00403         {
00404             WARNPRINTF("Cannot parse value of key %s", key);
00405         }
00406     }
00407     else if (strcmp(key, KEY_SENSOR_USE_LOCK_RIGHT) == 0)
00408     {
00409         if (value->type == GCONF_VALUE_BOOL)
00410         {   
00411             gboolean use_lock_left = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_LEFT, NULL);
00412             gboolean use_lock_right = gconf_value_get_bool(value);
00413             gboolean use_lock_middle = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_MIDDLE, NULL);
00414             
00415             conf_disabled_sensor_lock();
00416             
00417             sys_set_sensor_lock_config(use_lock_left, use_lock_right, use_lock_middle);
00418         }
00419         else
00420         {
00421             WARNPRINTF("Cannot parse value of key %s", key);
00422         }
00423     }
00424     else if (strcmp(key, KEY_SENSOR_USE_LOCK_MIDDLE) == 0)
00425     {
00426         if (value->type == GCONF_VALUE_BOOL)
00427         {   
00428             gboolean use_lock_left = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_LEFT, NULL);
00429             gboolean use_lock_right = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_RIGHT, NULL);
00430             gboolean use_lock_middle = gconf_value_get_bool(value);
00431             
00432             conf_disabled_sensor_lock();
00433             
00434             sys_set_sensor_lock_config(use_lock_left, use_lock_right, use_lock_middle);
00435         }
00436         else
00437         {
00438             WARNPRINTF("Cannot parse value of key %s", key);
00439         }
00440     }
00441 /*    
00442     else if (strcmp(key, KEY_GLOBAL_TZ_OFFSET) == 0)
00443     {
00444         if (value->type == GCONF_VALUE_INT)
00445         {   
00446             sys_set_timezone_offset(gconf_value_get_int(value));
00447         }
00448         else
00449         {
00450             WARNPRINTF("Cannot parse value of key %s", key);
00451         }
00452     }
00453 */
00454     else if (strcmp(key, KEY_POWER_USE_STYLUS) == 0)
00455     {
00456         if (value->type == GCONF_VALUE_BOOL)
00457         {   
00458             if (gconf_value_get_bool(value))
00459             {
00460                 wacom_enable();
00461             }
00462             else
00463             {
00464                 wacom_disable();
00465             }
00466         }
00467         else
00468         {
00469             WARNPRINTF("Cannot parse value of key %s", key);
00470         }
00471     }
00472     else if (strcmp(key, KEY_POWER_IDLE_MODE) == 0)
00473     {
00474         if (value->type == GCONF_VALUE_BOOL)
00475         {   
00476             sys_set_idle_mode(gconf_value_get_bool(value));
00477         }
00478         else
00479         {
00480             WARNPRINTF("Cannot parse value of key %s", key);
00481         }
00482     }
00483     else if (strcmp(key, KEY_POWER_MIN_STANDBY) == 0)
00484     {
00485         if (value->type == GCONF_VALUE_INT)
00486         {   
00487             gint standby = gconf_value_get_int(value);
00488             if (standby > 0)
00489             {
00490                 if (standby < MINIMUM_STANDBY_MIN)
00491                 {
00492                     standby = MINIMUM_STANDBY_MIN;
00493                 }
00494                 sys_set_standby_time(standby * 60);
00495             }
00496             else if (standby == -1)
00497             {
00498                 sys_set_standby_time(0);
00499             }
00500         }
00501         else
00502         {
00503             WARNPRINTF("Cannot parse value of key %s", key);
00504         }
00505     }
00506     else if (strcmp(key, KEY_POWER_STANDBY_IF_PLUGGED) == 0)
00507     {
00508         if (value->type == GCONF_VALUE_BOOL)
00509         {   
00510             sys_set_standby_mode(gconf_value_get_bool(value));
00511         }
00512         else
00513         {
00514             WARNPRINTF("Cannot parse value of key %s", key);
00515         }
00516     }
00517     else if (strcmp(key, KEY_FLIGHTMODE_MODE) == 0)
00518     {
00519         if (value->type == GCONF_VALUE_BOOL)
00520         {   
00521             conn_set_flightmode(gconf_value_get_bool(value));
00522         }
00523         else
00524         {
00525             WARNPRINTF("Cannot parse value of key %s", key);
00526         }
00527     }
00528     else if (strcmp(key, KEY_GLOBAL_FIRST_BOOT) == 0)
00529     {
00530         if (value->type == GCONF_VALUE_BOOL)
00531         {   
00532             if (gconf_value_get_bool(value))
00533             {
00534                 // device is reset to factory defaults;
00535                 // check locales/languages available on system
00536                 update_installed_locales();
00537             }
00538         }
00539     }    
00540     
00541 /*
00542     LOGPRINTF("GConf key changed");
00543     g_print("Key: %s\t", key);
00544 
00545     if (value) 
00546     {
00547         switch (value->type) 
00548         {
00549         case GCONF_VALUE_STRING: 
00550             g_print(" STRING\t`%s`", gconf_value_get_string(value));
00551             break;
00552         
00553         case GCONF_VALUE_INT:
00554             g_print(" INT\t %d", gconf_value_get_int(value));
00555             break;      
00556         
00557         case GCONF_VALUE_FLOAT:
00558             g_print(" FLOAT\t %f", gconf_value_get_float(value));
00559             break;            
00560         
00561         case GCONF_VALUE_BOOL:
00562             g_print(" BOOL\t %s", (gconf_value_get_bool(value) ? "true" : "false"));
00563             break;            
00564         
00565         case GCONF_VALUE_SCHEMA:
00566             g_print(" SCHEMA");
00567             break;            
00568         
00569         case GCONF_VALUE_LIST:
00570             g_print(" LIST");
00571             break;            
00572         
00573         case GCONF_VALUE_PAIR:
00574             g_print(" PAIR");
00575             break;            
00576         
00577         case GCONF_VALUE_INVALID:
00578         default:
00579             g_print(" has invalid type");
00580             break;
00581         }
00582     }
00583     else
00584     {
00585       g_print(" has invalid type");
00586     } 
00587     g_print("\n");
00588 */
00589 }
00590 
00591 
00592 static void set_startup_defaults(void)
00593 {
00594     LOGPRINTF("entry");
00595 
00596     GError *error = NULL;
00597     
00598     // set alternate navigation of GTK+ for DR800 with up/down buttons only
00599 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800S || MACHINE_IS_DR800SW
00600     gconf_client_set_int(g_gconfclient, KEY_UP_DOWN_FOCUS_BEHAVIOR, 1, &error);
00601 #elif MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00602     gconf_client_set_int(g_gconfclient, KEY_UP_DOWN_FOCUS_BEHAVIOR, 0, &error);
00603 #endif    
00604     if (error)
00605     {
00606         WARNPRINTF("error writing GConf key %s: %s", KEY_UP_DOWN_FOCUS_BEHAVIOR, error->message);
00607         g_error_free(error);
00608         error = NULL;
00609     }
00610     
00611     char *locale = gconf_client_get_string(g_gconfclient, KEY_GLOBAL_LOCALE, &error);
00612     if (error)
00613     {
00614         WARNPRINTF("error fetching GConf key %s: %s", KEY_GLOBAL_LOCALE, error->message);
00615         g_error_free(error);
00616         error = NULL;
00617     }
00618     else
00619     {
00620         if (!set_locale(locale))
00621         {
00622             WARNPRINTF("Locale not found");
00623         }
00624     }
00625   
00626 /*    
00627     gint tz_offset = gconf_client_get_int(g_gconfclient, KEY_GLOBAL_TZ_OFFSET, &error);
00628     if (error)
00629     {
00630         WARNPRINTF("error fetching GConf key %s: %s", KEY_GLOBAL_TZ_OFFSET, error->message);
00631         g_error_free(error);
00632         error = NULL;
00633     }
00634     else
00635     {
00636         sys_set_timezone_offset(tz_offset);
00637     }
00638 */
00639 
00640     gboolean index_with_metadata = gconf_client_get_bool(g_gconfclient, KEY_INDEX_WITH_METADATA, &error);
00641     if (error)
00642     {
00643         WARNPRINTF("error fetching GConf key %s: %s", KEY_INDEX_WITH_METADATA, error->message);
00644         g_error_free(error);
00645         error = NULL;
00646     }
00647     else
00648     {
00649         sys_set_index_with_metadata(index_with_metadata);
00650     }
00651 
00652     char *rotation = gconf_client_get_string(g_gconfclient, KEY_DISPLAY_ROTATION, &error);
00653     if (error)
00654     {
00655         WARNPRINTF("error fetching GConf key %s: %s", KEY_DISPLAY_ROTATION, error->message);
00656         g_error_free(error);
00657         error = NULL;
00658     }
00659     if (rotation != NULL )
00660     {
00661         sys_set_rotate_direction(rotation);
00662     }
00663     
00664     gboolean is_pageturn_inverted = gconf_client_get_bool(g_gconfclient, KEY_PAGETURN_INVERTED, &error);
00665     if (error)
00666     {
00667         WARNPRINTF("error fetching GConf key %s: %s", KEY_PAGETURN_INVERTED, error->message);
00668         g_error_free(error);
00669         error = NULL;
00670     }
00671     else
00672     {
00673         sys_set_pageturn_inverted(is_pageturn_inverted);
00674     }
00675 
00676     gboolean use_light = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LIGHT, &error);
00677     if (error)
00678     {
00679         WARNPRINTF("error fetching GConf key %s: %s", KEY_SENSOR_USE_LIGHT, error->message);
00680         g_error_free(error);
00681         error = NULL;
00682     }
00683     else
00684     {
00685         gboolean use_sound = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_SOUND, &error);
00686         if (error)
00687         {
00688             WARNPRINTF("error fetching GConf key %s: %s", KEY_SENSOR_USE_SOUND, error->message);
00689             g_error_free(error);
00690             error = NULL;
00691         }
00692         else
00693         {
00694             sys_set_sensor_feedback(use_light, use_sound);    
00695         }
00696     }
00697     
00698     gboolean use_lock_left = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_LEFT, &error);
00699     if (error)
00700     {
00701         WARNPRINTF("error fetching GConf key %s: %s", KEY_SENSOR_USE_LOCK_LEFT, error->message);
00702         g_error_free(error);
00703         error = NULL;
00704     }
00705     else
00706     {
00707         gboolean use_lock_right  = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_RIGHT, &error);
00708         if (error)
00709         {
00710             WARNPRINTF("error fetching GConf key %s: %s", KEY_SENSOR_USE_LOCK_RIGHT, error->message);
00711             g_error_free(error);
00712             error = NULL;
00713         }
00714         else
00715         {
00716             gboolean use_lock_middle = gconf_client_get_bool(g_gconfclient, KEY_SENSOR_USE_LOCK_MIDDLE, &error);
00717             if (error)
00718             {
00719                 WARNPRINTF("error fetching GConf key %s: %s", KEY_SENSOR_USE_LOCK_MIDDLE, error->message);
00720                 g_error_free(error);
00721                 error = NULL;
00722             }
00723             else
00724             {
00725                 sys_set_sensor_lock_config(use_lock_left, use_lock_right, use_lock_middle);    
00726             }
00727         }
00728     }
00729 
00730     gboolean use_stylus = gconf_client_get_bool(g_gconfclient, KEY_POWER_USE_STYLUS, &error);
00731     if (error)
00732     {
00733         WARNPRINTF("error fetching GConf key %s: %s", KEY_POWER_USE_STYLUS, error->message);
00734         g_error_free(error);
00735         error = NULL;
00736     }
00737     else
00738     {
00739         if (use_stylus)
00740         {
00741             wacom_enable();
00742         }
00743         else
00744         {
00745             wacom_disable();
00746         }
00747     }
00748  
00749     gboolean idle_mode = gconf_client_get_bool(g_gconfclient, KEY_POWER_IDLE_MODE, &error);
00750     if (error)
00751     {
00752         WARNPRINTF("error fetching GConf key %s: %s", KEY_POWER_IDLE_MODE, error->message);
00753         g_error_free(error);
00754         error = NULL;
00755     }
00756     else
00757     {
00758         sys_set_idle_mode(idle_mode);
00759     }
00760 
00761     gint standby = gconf_client_get_int(g_gconfclient, KEY_POWER_MIN_STANDBY, &error);
00762     if (error)
00763     {
00764         WARNPRINTF("error fetching GConf key %s: %s", KEY_POWER_MIN_STANDBY, error->message);
00765         g_error_free(error);
00766         error = NULL;
00767     }
00768     else
00769     {
00770         if (standby > 0)
00771         {
00772             if (standby < MINIMUM_STANDBY_MIN)
00773             {
00774                 standby = MINIMUM_STANDBY_MIN;
00775             }
00776             sys_set_standby_time(standby * 60);
00777         }
00778         else if (standby == -1)
00779         {
00780             sys_set_standby_time(0);
00781         }
00782     }
00783     
00784     gboolean standby_if_plugged = gconf_client_get_bool(g_gconfclient, KEY_POWER_STANDBY_IF_PLUGGED, &error);
00785     if (error)
00786     {
00787         WARNPRINTF("error fetching GConf key %s: %s", KEY_POWER_STANDBY_IF_PLUGGED, error->message);
00788         g_error_free(error);
00789         error = NULL;
00790     }
00791     else
00792     {
00793         sys_set_standby_mode(standby_if_plugged);
00794     }
00795     
00796     gboolean is_flightmode_enabled = gconf_client_get_bool(g_gconfclient, KEY_FLIGHTMODE_MODE, &error);
00797     if (error)
00798     {
00799         WARNPRINTF("error fetching GConf key %s: %s", KEY_FLIGHTMODE_MODE, error->message);
00800         g_error_free(error);
00801         error = NULL;
00802     }
00803     else
00804     {
00805         conn_set_flightmode(is_flightmode_enabled);
00806     }
00807 }
00808 
00809 
00810 static void update_installed_locales()
00811 {
00812     GSList *locale_list;
00813     GSList *code_list;
00814     GSList *lang_list;
00815     
00816     // get list of installed locales on system
00817     locale_list = locales_list_create();
00818 
00819     // create lists of only codes and languages
00820     code_list = locales_list_codes(locale_list);
00821     lang_list = locales_list_languages(locale_list);
00822 
00823     // update gconf entries
00824     gconf_client_set_list(g_gconfclient, KEY_GLOBAL_LIST_LOCALES, GCONF_VALUE_STRING, code_list, NULL);
00825     gconf_client_set_list(g_gconfclient, KEY_GLOBAL_LIST_LANGUAGES, GCONF_VALUE_STRING, lang_list, NULL);
00826 
00827     if (g_slist_length(code_list) != g_slist_length(lang_list))
00828     {
00829         WARNPRINTF("Locale code and language lists are not of equal length");
00830     }
00831     
00832     g_number_of_langages = g_slist_length(code_list);
00833         
00834     if (g_number_of_langages == 1)
00835     {
00836         // auto set locale to the only available langage
00837         //
00838         char *new_locale = code_list->data;
00839         char *old_locale = gconf_client_get_string(g_gconfclient, KEY_GLOBAL_LOCALE, NULL);
00840         if ( ((old_locale == NULL) || (strcmp(old_locale, new_locale) != 0)) )
00841         {
00842             LOGPRINTF("Auto set locale to %s (was: %s)", new_locale, old_locale);
00843             gconf_client_set_string(g_gconfclient, KEY_GLOBAL_LOCALE, new_locale, NULL);
00844         }
00845         else
00846         {
00847             LOGPRINTF("Locale already set to %s", new_locale);
00848         }
00849     }
00850 
00851     // free memory
00852     locales_list_free(locale_list);
00853     g_slist_free(code_list);
00854     g_slist_free(lang_list);
00855 }
00856 
00857 
00858 /*
00859 static void print_environment(void)
00860 {
00861     char **envp;
00862     int i;
00863     envp = g_listenv();
00864     for (i = 0; envp[i]; i++) 
00865     {
00866         char *name = envp[i];
00867         LOGPRINTF("%s=%s", name, g_getenv(name));
00868         g_free name);
00869     }                
00870 }
00871 */                
Generated by  doxygen 1.6.2-20100208