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 #include <libheraia.h>
00029
00030 static void verify_preference_file_path_presence(gchar *pathname);
00031 static void verify_preference_file_name_presence(gchar *filename);
00032
00033 static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop);
00034
00035 static void save_mp_file_preferences_options(heraia_window_t *main_window);
00036 static void save_mp_display_preferences_options(heraia_window_t *main_window);
00037
00038 static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop);
00039
00040 static void load_mp_file_preferences_options(heraia_window_t *main_window);
00041 static void load_mp_display_preferences_options(heraia_window_t *main_window);
00042
00043
00044
00045
00046
00047
00048
00049
00050 static void verify_preference_file_path_presence(gchar *pathname)
00051 {
00052 struct stat *buf = NULL;
00053 gint result = 0;
00054
00055 buf = (struct stat *) g_malloc0(sizeof(struct stat));
00056 result = g_stat(pathname, buf);
00057
00058 if (result != 0)
00059 {
00060 g_mkdir_with_parents(pathname, 488);
00061 }
00062 }
00063
00064
00065
00066
00067
00068
00069
00070 static void verify_preference_file_name_presence(gchar *filename)
00071 {
00072 FILE *fp = NULL;
00073
00074 fp = g_fopen(filename, "r");
00075
00076 if (fp == NULL)
00077 {
00078 fp = g_fopen(filename, "w");
00079 if (fp == NULL)
00080 {
00081 fprintf(stderr, "Unable to open and create the main preference file %s\n", filename);
00082 }
00083 else
00084 {
00085 fprintf(stderr, "Main preference file %s created successfully\n", filename);
00086 fclose(fp);
00087 }
00088 }
00089 else
00090 {
00091 fclose(fp);
00092 }
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102 void verify_preference_file(gchar *pathname, gchar *filename)
00103 {
00104
00105 verify_preference_file_path_presence(pathname);
00106 verify_preference_file_name_presence(filename);
00107
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117 static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
00118 {
00119 gchar *keyname = NULL;
00120
00121 keyname = g_strconcat(name, " Displayed", NULL);
00122 g_key_file_set_boolean(file, GN_GLOBAL_PREFS, keyname, window_prop->displayed);
00123 g_free(keyname);
00124
00125 keyname = g_strconcat(name, " X_pos", NULL);
00126 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->x);
00127 g_free(keyname);
00128
00129 keyname = g_strconcat(name, " Y_pos", NULL);
00130 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->y);
00131 g_free(keyname);
00132 }
00133
00134
00135
00136
00137
00138
00139 static void save_mp_file_preferences_options(heraia_window_t *main_window)
00140 {
00141 prefs_t *prefs = NULL;
00142 gboolean activated = FALSE;
00143
00144 if (main_window != NULL)
00145 {
00146 prefs = main_window->prefs;
00147
00148 if (prefs->file == NULL)
00149 {
00150 prefs->file = g_key_file_new();
00151 }
00152
00153 if (prefs != NULL && prefs->file != NULL)
00154 {
00155
00156 activated = is_toggle_button_activated(main_window->xmls->main, "save_window_position_bt");
00157 g_key_file_set_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, activated);
00158
00159
00160 if (activated == TRUE)
00161 {
00162 save_window_preferences(prefs->file, KN_ABOUT_BOX, main_window->win_prop->about_box);
00163 save_window_preferences(prefs->file, KN_DATA_INTERPRETOR, main_window->win_prop->data_interpretor);
00164 save_window_preferences(prefs->file, KN_LOG_BOX, main_window->win_prop->log_box);
00165 save_window_preferences(prefs->file, KN_MAIN_DIALOG, main_window->win_prop->main_dialog);
00166 save_window_preferences(prefs->file, KN_PLUGIN_LIST, main_window->win_prop->plugin_list);
00167 save_window_preferences(prefs->file, KN_LDT, main_window->win_prop->ldt);
00168 save_window_preferences(prefs->file, KN_MAIN_PREFS, main_window->win_prop->main_pref_window);
00169 }
00170 }
00171 }
00172 }
00173
00174
00175
00176
00177
00178
00179 static void save_mp_display_preferences_options(heraia_window_t *main_window)
00180 {
00181 prefs_t *prefs = NULL;
00182 gboolean activated = FALSE;
00183
00184 if (main_window != NULL)
00185 {
00186 prefs = main_window->prefs;
00187
00188 if (prefs->file == NULL)
00189 {
00190 prefs->file = g_key_file_new();
00191 }
00192
00193 if (prefs != NULL && prefs->file != NULL)
00194 {
00195
00196 activated = is_toggle_button_activated(main_window->xmls->main, "mp_thousand_bt");
00197 g_key_file_set_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_THOUSAND, activated);
00198 }
00199 }
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209 void save_main_preferences(heraia_window_t *main_window)
00210 {
00211 if (main_window != NULL)
00212 {
00213
00214 save_mp_file_preferences_options(main_window);
00215
00216
00217 save_mp_display_preferences_options(main_window);
00218
00219 if (main_window->prefs != NULL)
00220 {
00221
00222 save_preferences_to_file(main_window->prefs);
00223 }
00224 }
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
00236 {
00237 gchar *keyname = NULL;
00238
00239 keyname = g_strconcat(name, " Displayed", NULL);
00240 window_prop->displayed = g_key_file_get_boolean(file, GN_GLOBAL_PREFS, keyname, NULL);
00241 g_free(keyname);
00242
00243 keyname = g_strconcat(name, " X_pos", NULL);
00244 window_prop->x = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00245 g_free(keyname);
00246
00247 keyname = g_strconcat(name, " Y_pos", NULL);
00248 window_prop->y = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00249 g_free(keyname);
00250 }
00251
00252
00253
00254
00255
00256
00257
00258 static void load_mp_file_preferences_options(heraia_window_t *main_window)
00259 {
00260 prefs_t *prefs = NULL;
00261 GtkWidget *save_window_position_bt = NULL;
00262 gboolean activated = FALSE;
00263
00264 if (main_window != NULL)
00265 {
00266 prefs = main_window->prefs;
00267
00268 if (prefs != NULL && prefs->file != NULL)
00269 {
00270
00271 activated = g_key_file_get_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, NULL);
00272 save_window_position_bt = heraia_get_widget(main_window->xmls->main, "save_window_position_bt");
00273 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_window_position_bt), activated);
00274
00275 if (activated == TRUE)
00276 {
00277
00278 load_window_preferences(prefs->file, KN_ABOUT_BOX, main_window->win_prop->about_box);
00279 load_window_preferences(prefs->file, KN_DATA_INTERPRETOR, main_window->win_prop->data_interpretor);
00280 load_window_preferences(prefs->file, KN_LOG_BOX, main_window->win_prop->log_box);
00281 load_window_preferences(prefs->file, KN_MAIN_DIALOG, main_window->win_prop->main_dialog);
00282 load_window_preferences(prefs->file, KN_PLUGIN_LIST, main_window->win_prop->plugin_list);
00283 load_window_preferences(prefs->file, KN_LDT, main_window->win_prop->ldt);
00284 load_window_preferences(prefs->file, KN_MAIN_PREFS, main_window->win_prop->main_pref_window);
00285 }
00286 }
00287 }
00288 }
00289
00290
00291
00292
00293
00294
00295
00296 static void load_mp_display_preferences_options(heraia_window_t *main_window)
00297 {
00298 prefs_t *prefs = NULL;
00299 GtkWidget *display_thousand_bt = NULL;
00300 gboolean activated = FALSE;
00301
00302 if (main_window != NULL)
00303 {
00304 prefs = main_window->prefs;
00305
00306 if (prefs != NULL && prefs->file != NULL)
00307 {
00308
00309 activated = g_key_file_get_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_THOUSAND, NULL);
00310 display_thousand_bt = heraia_get_widget(main_window->xmls->main, "mp_thousand_bt");
00311 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(display_thousand_bt), activated);
00312 }
00313 }
00314 }
00315
00316
00317
00318
00319
00320
00321
00322 void setup_preferences(heraia_window_t *main_window)
00323 {
00324 if (main_window != NULL)
00325 {
00326
00327 load_mp_file_preferences_options(main_window);
00328
00329
00330 load_mp_display_preferences_options(main_window);
00331 }
00332 }