show.c

Go to the documentation of this file.
00001 /*
00002  * File Name: show.c
00003  */
00004 
00005 /*
00006  * This file is part of erconftool.
00007  *
00008  * erconftool 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  * erconftool 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 #include <glib.h>
00033 #include <stdio.h>
00034 #include <string.h>
00035 #include <stdlib.h>
00036 
00037 #include <gconf/gconf-client.h>
00038 
00039 // ereader include files, between < >
00040 
00041 // local include files, between " "
00042 #include "log.h"
00043 #include "erconftool.h"
00044 
00045 #define UNUSED(x) (void)(x)
00046 
00047 
00048 //----------------------------------------------------------------------------
00049 // Type Declarations
00050 //----------------------------------------------------------------------------
00051 
00052 
00053 //----------------------------------------------------------------------------
00054 // Global Constants
00055 //----------------------------------------------------------------------------
00056 
00057 
00058 //----------------------------------------------------------------------------
00059 // Static Variables
00060 //----------------------------------------------------------------------------
00061 
00062 
00063 //============================================================================
00064 // Local Function Definitions
00065 //============================================================================
00066 
00067 static void dump_dir    (GConfClient *client, const char *path);
00068 void dump_entries       (GConfClient *client, const char *path);
00069 void show_key           (GConfClient *client, const char *key);
00070 
00071 
00072 //============================================================================
00073 // Functions Implementation
00074 //============================================================================
00075 
00076 void show_registry(GConfClient *client, const char **paths)
00077 {
00078     gint i;
00079     for (i = 0; paths[i]; i++)
00080         dump_dir(client, paths[i]);
00081 }
00082 
00083 
00084 void show_entry(GConfClient *client, GConfEntry *entry)
00085 {
00086     UNUSED(client);
00087     GConfValue *value = gconf_entry_get_value(entry);
00088     gboolean is_default = gconf_entry_get_is_default(entry);
00089     gboolean is_writable = gconf_entry_get_is_writable(entry);
00090 
00091     g_print("Key %s\t", entry->key);
00092 
00093     if (value) 
00094     {
00095         g_print("%s%s", (is_default ? " DEFAULT" : ""), (is_writable ? " WRITABLE" : ""));
00096 
00097         switch (value->type) 
00098         {
00099         case GCONF_VALUE_STRING: 
00100             g_print(" STRING\t`%s`", gconf_value_get_string(value));
00101             break;
00102         
00103         case GCONF_VALUE_INT:
00104             g_print(" INT\t %d", gconf_value_get_int(value));
00105             break;      
00106         
00107         case GCONF_VALUE_FLOAT:
00108             g_print(" FLOAT\t %f", gconf_value_get_float(value));
00109             break;            
00110         
00111         case GCONF_VALUE_BOOL:
00112             g_print(" BOOL\t %s", (gconf_value_get_bool(value) ? "true" : "false"));
00113             break;            
00114         
00115         case GCONF_VALUE_SCHEMA:
00116             g_print(" SCHEMA (data not shown for this type)");
00117             break;            
00118         
00119         case GCONF_VALUE_LIST:
00120             {
00121                 g_print(" LIST of ");
00122                 GSList *valuelist = gconf_value_get_list(value);
00123                 gsize len = g_slist_length(valuelist);
00124                 
00125                 switch (gconf_value_get_list_type(value))
00126                 {
00127                 case GCONF_VALUE_STRING:
00128                     g_print("%d STRINGS\t", len);
00129                     while (valuelist!=NULL) 
00130                     {
00131                         g_print("%s;", gconf_value_get_string(valuelist->data));
00132                         valuelist=valuelist->next; 
00133                     }
00134                     break;
00135                             
00136                 case GCONF_VALUE_INT:
00137                     g_print("%d INTS\t", len);
00138                     while (valuelist!=NULL) 
00139                     {
00140                         g_print("%d;", gconf_value_get_int(valuelist->data));
00141                         valuelist=valuelist->next; 
00142                     }
00143                     break;
00144                             
00145                 case GCONF_VALUE_FLOAT:
00146                     g_print("%d FLOATS\t", len);
00147                     while (valuelist!=NULL) 
00148                     {
00149                         g_print("%f;", gconf_value_get_float(valuelist->data));
00150                         valuelist=valuelist->next; 
00151                     }
00152                     break;
00153                             
00154                 case GCONF_VALUE_BOOL:
00155                     g_print("%d BOOLS\t", len);
00156                     while (valuelist!=NULL) 
00157                     {
00158                         g_print("%s;", (gconf_value_get_bool(valuelist->data) ? "true" : "false"));
00159                         valuelist=valuelist->next; 
00160                     }
00161                     break;
00162                             
00163                 default:
00164                     g_print("Unsupported data type %d\n", value->type);
00165                     break;
00166                 }
00167                 
00168                 g_slist_free(valuelist);
00169             }
00170             break;   
00171         
00172         case GCONF_VALUE_PAIR:
00173             g_print(" PAIR (data not shown for this type)");
00174             break;            
00175         
00176         case GCONF_VALUE_INVALID:
00177         default:
00178             g_print(" has invalid type");
00179             break;
00180         }
00181     }
00182     else
00183     {
00184       g_print(" has invalid type");
00185     } 
00186 
00187     g_print("\n");
00188 }
00189 
00190 
00191 void show_key(GConfClient *client, const char *key)
00192 { 
00193     show_entry(client, gconf_client_get_entry(client, key, NULL, TRUE, NULL));   
00194 }
00195 
00196 
00197 void dump_entries(GConfClient *client, const char *path)
00198 {
00199     GSList *entries = gconf_client_all_entries(client, (char*) path, NULL);
00200     while (entries!=NULL)
00201     {
00202         show_entry(client, (GConfEntry*) entries->data);
00203         entries=entries->next;
00204     }   
00205 }    
00206 
00207 
00208 static void dump_dir(GConfClient *client, const char *path)
00209 {
00210     GSList *tmp = gconf_client_all_dirs(client, path, NULL);
00211 
00212     dump_entries(client,path);
00213 
00214     // resursively dump all directories below
00215     while (tmp!=NULL) 
00216     {
00217         dump_dir(client, (char*) tmp->data);
00218         tmp=tmp->next; 
00219     }
00220 }
Generated by  doxygen 1.6.2-20100208