src/manager/src/ws_mng_gconf_utils.c

Go to the documentation of this file.
00001 /*******************************************************************************
00002 This file is part of mdictionary.
00003 
00004 mdictionary is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 mdictionary is distributed in the hope that it will be useful, 
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License 
00015 along with mdictionary; if not, write to the Free Software
00016 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00017 
00018 Copyright 2006-2008 ComArch S.A.
00019 *******************************************************************************/
00026 #include <ws_mng_gconf_utils.h>
00027 
00028 
00036 GArray* ws_mng_read_gconf()
00037 {
00038         g_debug("--%s", __FUNCTION__);
00039         GConfClient* client = NULL;
00040         client = gconf_client_get_default();
00041         GArray* path_to_dir = g_array_new(TRUE, TRUE, sizeof(gchar *));
00042         gchar* path = NULL;
00043         gboolean key_active = FALSE;
00044         gint i = 0;
00045 
00046         /* get location of every dictionary */
00047         GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
00048         for (i = 0; i < g_slist_length(list); ++i)
00049         {
00050                 path = (gchar* ) g_slist_nth_data(list, i);
00051                 gchar* new_path = g_strconcat(path, "/path", NULL);
00052                 gchar* new_active = g_strconcat(path, "/active", NULL);
00053                 key_active = gconf_client_get_bool(client, new_active, NULL);
00054                 if (key_active == TRUE)
00055                 {
00056                         gchar* key_value = gconf_client_get_string( client,
00057                                                                     new_path,
00058                                                                     NULL );
00059                         if (key_value != NULL){
00060                                 g_array_append_val(path_to_dir, key_value);
00061                         }
00062                 }
00063                 g_free(new_path);
00064                 g_free(new_active);
00065         }
00066 
00067         /* free memmory */
00068         for (i=0; i<g_slist_length(list); i++)
00069         {
00070                 g_free(g_slist_nth_data(list, i));
00071         }
00072         g_slist_free(list);
00073         g_object_unref (client);
00074         return path_to_dir;
00075 }
00076 
00077 
00081 GArray* ws_mng_get_engines_location()
00082 {
00083         g_debug("->%s", __FUNCTION__);
00084         GConfClient* client = NULL;
00085         GArray* path_to_dir = g_array_new(TRUE, TRUE, sizeof(gchar *));
00086         gchar* path = NULL;
00087         gint i = 0;
00088         client = gconf_client_get_default();
00089 
00090         GSList* list = gconf_client_all_dirs(client, GCONF_LIB_PATH, NULL);
00091         for (i=0; i<g_slist_length(list); i++)
00092         {
00093                 path = (gchar* ) g_slist_nth_data(list, i);
00094                 gchar* new_path = g_strconcat(path, "/path",NULL);
00095                 gchar* key_value = gconf_client_get_string( client,
00096                                                             new_path,
00097                                                             NULL);
00098                 gchar** tmp = g_strsplit(key_value, "/", -1);
00099                 guint i = 0;
00100                 gboolean bookmark_engine = FALSE;
00101                 while(NULL != tmp[i])
00102                 {
00103                         g_debug("Comapred string %s", tmp[i]);
00104                         if (g_ascii_strcasecmp(tmp[i], "ws_bookmark.so") == 0)
00105                         {
00106                                 bookmark_engine = TRUE;
00107                                 break;
00108                         }
00109                         i++;
00110                 }
00111                 g_strfreev(tmp);
00112                 
00113                 if (key_value != NULL)
00114                 {
00115                         g_debug("Added library path %s", key_value);
00116                         g_array_append_val(path_to_dir, key_value);
00117                 }
00118                 g_free(new_path);
00119         }
00120 
00121         for (i=0; i<g_slist_length(list); i++)
00122         {
00123                 g_free(g_slist_nth_data(list, i));
00124         }
00125         g_slist_free(list);
00126         g_object_unref (client);
00127         return path_to_dir;
00128 }
00129 
00130 
00134 gchar* ws_mng_get_boomark_location()
00135 {
00136         g_debug("->%s", __FUNCTION__);
00137         GConfClient* client = NULL;
00138         gchar* path = NULL;
00139         guint i = 0;
00140         client = gconf_client_get_default();
00141 
00142         GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
00143         for (i=0; i<g_slist_length(list); i++)
00144         {
00145                 path = (gchar* ) g_slist_nth_data(list, i);
00146                 gchar* name = g_strconcat(path, "/name",NULL);
00147                 gchar* new_path = g_strconcat(path, "/path",NULL);
00148                 gchar* key_value = gconf_client_get_string( client,
00149                                                             name,
00150                                                             NULL );
00151 
00152                 if (key_value != NULL)
00153                 {
00154                         if (g_ascii_strcasecmp(key_value, "Bookmarks") == 0)
00155                         {
00156                                 gchar* key_value_path = 
00157                                         gconf_client_get_string( client,
00158                                                                  new_path,
00159                                                                  NULL );
00160 
00161                                 if (key_value_path != NULL)
00162                                 {
00163                                         g_free(key_value);
00164                                         key_value = NULL;
00165                                         g_free(new_path);
00166                                         new_path = NULL;
00167                                         g_free(name); name = NULL;      
00168                                         for (i=0; i<g_slist_length(list); i++)
00169                                         {
00170                                                 g_free(
00171                                                 g_slist_nth_data(list, i));
00172                                         }
00173                                         g_slist_free(list);
00174                                         g_object_unref(client);
00175                                         return key_value_path;
00176                                 }
00177                         }
00178                 }
00179                 g_free(name); name = NULL;
00180                 g_free(key_value);
00181                 key_value = NULL;
00182                 g_free(new_path);
00183                 new_path = NULL;
00184         }
00185 
00186         g_debug("<-%s", __FUNCTION__);
00187         return NULL;
00188 }
00189 
00194 gboolean ws_mng_if_optimized(gchar* dict)
00195 {
00196         g_debug("->%s", __FUNCTION__);
00197 
00198         GConfClient* client;
00199         gchar* path = NULL;
00200         gboolean key_optimized = FALSE;
00201         gboolean key_found = FALSE;
00202         gint i = 0;
00203 
00204         client = gconf_client_get_default();
00205         GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
00206         for (i=0; i<g_slist_length(list); i++)
00207         {
00208                 path = (gchar *) g_slist_nth_data(list, i);
00209                 gchar* new_path = g_strconcat(path, "/path",NULL);
00210                 gchar* new_optimized = g_strconcat(path, "/optimized",NULL);
00211                 gchar* key_value = gconf_client_get_string( client,
00212                                                             new_path,
00213                                                             NULL );
00214 
00215                 if (g_ascii_strcasecmp(key_value, dict) == 0)
00216                 {
00217                         key_optimized = gconf_client_get_bool( client,
00218                                                                new_optimized,
00219                                                                NULL );
00220                         key_found = TRUE;
00221                 }
00222                 g_free(new_path);
00223                 g_free(new_optimized);
00224                 g_free(key_value);
00225 
00226                 if ( TRUE == key_found )
00227                 {
00228                         break;
00229                 }
00230         }
00231 
00232         for (i=0; i<g_slist_length(list); i++)
00233         {
00234                 g_free(g_slist_nth_data(list, i));
00235         }
00236         g_slist_free(list);
00237         g_object_unref (client);
00238 
00239         g_debug("<-%s", __FUNCTION__);
00240         return key_optimized;
00241 }
00242 

Generated on Fri Jan 11 14:30:17 2008 for mDictionary Project by  doxygen 1.5.1