settings_utils.c

Go to the documentation of this file.
00001 /*
00002  * File Name: settings_utils.c
00003  */
00004 
00005 /*
00006  * This file is part of settings.
00007  *
00008  * settings 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  * settings 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 // system include files, between < >
00032 #ifndef WIN32
00033 #include <sys/time.h>
00034 #endif
00035 #include <time.h>
00036 #include <string.h>
00037 #include <stdlib.h>
00038 #include <gconf/gconf-client.h>
00039 
00040 // ereader include files, between < >
00041 
00042 // local include files, between " "
00043 #include "log.h"
00044 #include "ipc.h"
00045 #include "settings.h"
00046 #include "settings_utils.h"
00047 
00048 
00049 //----------------------------------------------------------------------------
00050 // Type Declarations
00051 //----------------------------------------------------------------------------
00052 
00053 
00054 //----------------------------------------------------------------------------
00055 // Global Constants
00056 //----------------------------------------------------------------------------
00057 
00058 
00059 //----------------------------------------------------------------------------
00060 // Static Variables
00061 //----------------------------------------------------------------------------
00062 
00063 static GConfClient* client = NULL;
00064 
00065 
00066 //============================================================================
00067 // Local Function Definitions
00068 //============================================================================
00069 
00070 
00071 //============================================================================
00072 // Functions Implementation
00073 //============================================================================
00074 
00075 GtkWidget* create_separator_widgets()
00076 {
00077     GtkWidget* separator = gtk_event_box_new();
00078     gtk_widget_set_name(separator, "irex-settings-separator");
00079     gtk_widget_set_size_request(separator, -1, SETTINGS_SEPARATOR_HEIGHT);
00080     return separator;
00081 }
00082 
00083 
00084 void set_popup_window_style(GtkWindow* window)
00085 {
00086     gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_DIALOG);
00087     gtk_window_set_decorated(window, FALSE);
00088     gtk_widget_realize(GTK_WIDGET(window));
00089     gdk_window_set_decorations(GTK_WIDGET(window)->window, GDK_DECOR_BORDER);
00090 
00091     // Put the window in the center of its parent.
00092     gtk_window_set_position(window, GTK_WIN_POS_CENTER_ON_PARENT);
00093 }
00094 
00095 
00096 gboolean set_date_time(time_t t)
00097 {
00098     LOGPRINTF("entry");
00099     gboolean ret = TRUE;
00100 #ifndef WIN32
00101     // set system clock 
00102     struct timeval tv;
00103     memset(&tv, 0, sizeof(struct timeval));
00104     tv.tv_sec = t;
00105     ret = (0 == settimeofday(&tv, NULL));
00106     LOGPRINTF("returned %d", ret);
00107 
00108     // synchronise hardware clock
00109     system("/sbin/hwclock -w -u");
00110 #endif
00111     return ret;
00112 }
00113 
00114 
00115 void gconf_initialize()
00116 {
00117     if (client == NULL)
00118     {
00119         client = gconf_client_get_default();
00120     }
00121 }
00122 
00123 void gconf_finalize()
00124 {
00125     if (client)
00126     {
00127         g_object_unref(client);
00128         client = NULL;
00129     }
00130 }
00131 
00132 
00133 int get_value_int(const char* key)
00134 {
00135     return gconf_client_get_int(client, key, NULL);
00136 }
00137 
00138 
00139 gboolean set_value_int(const char* key, int new_value)
00140 {
00141     return gconf_client_set_int(client, key, new_value, NULL);
00142 }
00143 
00144 
00145 gboolean get_value_bool(const char* key)
00146 {
00147     return gconf_client_get_bool(client, key, NULL);
00148 }
00149 
00150 
00151 gboolean set_value_bool(const char* key, gboolean new_value)
00152 {
00153     return gconf_client_set_bool(client, key, new_value, NULL);
00154 }
00155 
00156 
00157 const char* get_value_string(const char* key)
00158 {
00159     return gconf_client_get_string(client, key, NULL);
00160 }
00161 
00162 
00163 gboolean set_value_string(const char* key, const char* new_value)
00164 {
00165     return gconf_client_set_string(client, key, new_value, NULL);
00166 }
00167 
00168 
00169 GSList* get_value_string_list(const char* key)
00170 {
00171     return gconf_client_get_list(client, key, GCONF_VALUE_STRING, NULL);
00172 }
00173 
00174 GArray* get_int_array(const gchar* key)
00175 {
00176     GConfValue *gc_value = NULL;
00177     GArray *ret = NULL;
00178 
00179     g_assert(client);
00180     g_assert(key && *key);
00181 
00182     gc_value = gconf_client_get (client, key, NULL);
00183     if (gc_value == NULL)
00184     {
00185         return NULL;
00186     }
00187 
00188     if (gc_value->type == GCONF_VALUE_LIST
00189         && gconf_value_get_list_type (gc_value) == GCONF_VALUE_INT)
00190     {
00191         GSList *elt;
00192 
00193         ret = g_array_new (FALSE, FALSE, sizeof (gint));
00194         for (elt = gconf_value_get_list (gc_value); 
00195              elt != NULL; 
00196              elt = g_slist_next (elt))
00197         {
00198             int i = gconf_value_get_int ((GConfValue *) elt->data);
00199             g_array_append_val (ret, i);
00200         }
00201     }
00202 
00203     if (gc_value != NULL)
00204     {
00205         gconf_value_free (gc_value);
00206     }
00207     return ret;
00208 }
00209 
00210 gboolean set_int_array(const gchar* key, const GArray* new_value)
00211 {
00212     gboolean ret = FALSE;
00213     GSList *list = NULL;
00214 
00215     g_assert(client);
00216     g_assert(key && *key);
00217     g_return_val_if_fail(new_value != NULL, FALSE);
00218 
00219     unsigned int i;
00220     for (i = 0; i < new_value->len; i++)
00221     {
00222         gint val = g_array_index (new_value, gint, i);
00223         list = g_slist_append (list, GINT_TO_POINTER(val));
00224     }
00225 
00226     ret = gconf_client_set_list (client, key, GCONF_VALUE_INT, list, NULL);
00227 
00228     g_slist_free (list);
00229 
00230     return ret;
00231 }
00232 
Generated by  doxygen 1.6.2-20100208