00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "config.h"
00032
00033
00034 #include <glib.h>
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <unistd.h>
00038 #include <gconf/gconf-client.h>
00039
00040
00041
00042
00043 #include "log.h"
00044 #include "export.h"
00045 #include "import.h"
00046 #include "show.h"
00047
00048 #define UNUSED(x) (void)(x)
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #define INI_FILE_DEFAULT "/media/mmcblk0p1/System/dr.ini"
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 void key_changed_callback(GConfClient *client,
00078 guint cnxn_id,
00079 GConfEntry *entry,
00080 gpointer user_data)
00081 {
00082 UNUSED(cnxn_id);
00083 UNUSED(user_data);
00084 show_entry(client, entry);
00085 }
00086
00087
00088 int main (int argc, char *argv[])
00089 {
00090 GMainLoop *mainloop = NULL;
00091 GError *error = NULL;
00092 GConfClient *gconf_client = NULL;
00093 gboolean force_defaults = FALSE;
00094 gboolean start_monitor = FALSE;
00095 gchar *ini_file = NULL;
00096 gchar **delete_paths = NULL;
00097 gchar **show_paths = NULL;
00098 gchar **import_paths = NULL;
00099 gchar **export_paths = NULL;
00100 GOptionContext *context = NULL;
00101 gint i = 0;
00102
00103 GOptionEntry entries[] =
00104 {
00105 { "config", 'c', 0, G_OPTION_ARG_STRING, &ini_file, "Fully qualified name of config file", "<filename>" },
00106 { "import", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &import_paths, "Force export of schema defaults", "<paths>" },
00107 { "delete", 'd', 0, G_OPTION_ARG_STRING_ARRAY, &delete_paths, "Delete GConf preferences (revert to defaults)", "<paths>" },
00108 { "export", 'e', 0, G_OPTION_ARG_STRING_ARRAY, &export_paths, "Export settings to the config file", "<paths>" },
00109 { "show", 's', 0, G_OPTION_ARG_STRING_ARRAY, &show_paths, "Show GConf preferences", "<paths>" },
00110 { "monitor", 'm', 0, G_OPTION_ARG_NONE, &start_monitor, "Monitor updated GConf preferences", NULL },
00111 { "force", 'f', 0, G_OPTION_ARG_NONE, &force_defaults, "Force export of schema defaults", NULL },
00112 { NULL, 0, 0, 0, NULL, NULL, NULL }
00113 };
00114
00115 if (argc <= 1)
00116 {
00117 g_print("Run with '--help' to see a full list of available command line options.\n");
00118 exit(0);
00119 }
00120
00121
00122 g_type_init();
00123 mainloop = g_main_loop_new(NULL, FALSE);
00124
00125
00126 context = g_option_context_new("- Tool to manipulate ereader configuration");
00127 g_option_context_add_main_entries(context, entries, NULL);
00128 if (!g_option_context_parse(context, &argc, &argv, &error))
00129 {
00130 g_print("Error parsing arguments: %s\n", error->message);
00131 g_error_free(error);
00132 error = NULL;
00133 }
00134 g_option_context_free(context);
00135
00136
00137 gconf_client = gconf_client_get_default();
00138 if (gconf_client==NULL)
00139 {
00140 g_error("Failed to connect GConf");
00141 return 1;
00142 }
00143
00144 gconf_client_add_dir(gconf_client,
00145 "/",
00146 GCONF_CLIENT_PRELOAD_NONE,
00147 NULL);
00148
00149 if (!ini_file)
00150 {
00151 ini_file = g_strdup(INI_FILE_DEFAULT);
00152 }
00153
00154 if (import_paths)
00155 {
00156 import_registry(gconf_client, ini_file, (const char**) import_paths);
00157 }
00158
00159 if (delete_paths)
00160 {
00161 for (i = 0; delete_paths[i]; i++)
00162 {
00163 gconf_client_recursive_unset(gconf_client, delete_paths[i], 0, &error);
00164 if (error != NULL)
00165 {
00166 g_print("Error deleting keys for %s\n", error->message);
00167 g_error_free(error);
00168 error = NULL;
00169 }
00170 }
00171 }
00172
00173 if (export_paths)
00174 {
00175 export_registry(gconf_client, ini_file, (const char**) export_paths, force_defaults);
00176 }
00177
00178 if (show_paths)
00179 {
00180 show_registry(gconf_client, (const char**) show_paths);
00181 }
00182
00183 if (start_monitor)
00184 {
00185 gconf_client_notify_add(gconf_client, "/",
00186 key_changed_callback,
00187 NULL,
00188 NULL, &error);
00189 if (error != NULL)
00190 {
00191 g_print("Error installing monitor for %s\n", error->message);
00192 g_error_free(error);
00193 error = NULL;
00194 }
00195 else
00196 {
00197 g_main_loop_run(mainloop);
00198 }
00199 }
00200
00201 return 0;
00202 }