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_struct_t *main_struct);
00036 static void save_mp_display_preferences_options(heraia_struct_t *main_struct);
00037
00038 static void save_di_preferences(heraia_struct_t *main_struct);
00039
00040 static void save_mpwp_preferences(heraia_struct_t *main_struct);
00041
00042
00043 static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop);
00044
00045 static void load_mp_file_preferences_options(heraia_struct_t *main_struct);
00046 static void load_mp_display_preferences_options(heraia_struct_t *main_struct);
00047
00048 static void load_di_preferences(heraia_struct_t *main_struct);
00049
00050
00051
00052
00053
00054
00055
00056 static void verify_preference_file_path_presence(gchar *pathname)
00057 {
00058 struct stat *buf = NULL;
00059 gint result = 0;
00060
00061 buf = (struct stat *) g_malloc0(sizeof(struct stat));
00062 result = g_stat(pathname, buf);
00063
00064 if (result != 0)
00065 {
00066 g_mkdir_with_parents(pathname, 488);
00067 }
00068 }
00069
00070
00071
00072
00073
00074
00075
00076 static void verify_preference_file_name_presence(gchar *filename)
00077 {
00078 FILE *fp = NULL;
00079
00080 fp = g_fopen(filename, "r");
00081
00082 if (fp == NULL)
00083 {
00084 fp = g_fopen(filename, "w");
00085 if (fp == NULL)
00086 {
00087 fprintf(stderr, Q_("Unable to open and create the main preference file %s\n"), filename);
00088 }
00089 else
00090 {
00091 fprintf(stderr, Q_("Main preference file %s created successfully\n"), filename);
00092 fclose(fp);
00093 }
00094 }
00095 else
00096 {
00097 fclose(fp);
00098 }
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108 void verify_preference_file(gchar *pathname, gchar *filename)
00109 {
00110 verify_preference_file_path_presence(pathname);
00111 verify_preference_file_name_presence(filename);
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121 void init_preference_struct(heraia_struct_t *main_struct)
00122 {
00123 prefs_t *prefs = NULL;
00124
00125 if (main_struct->prefs == NULL)
00126 {
00127 main_struct->prefs = (prefs_t *) g_malloc0(sizeof(prefs_t));
00128 main_struct->prefs->file = g_key_file_new();
00129 main_struct->prefs->pathname = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), "heraia", NULL);
00130 main_struct->prefs->filename = g_build_filename(main_struct->prefs->pathname, "main_preferences", NULL);
00131 }
00132 else
00133 {
00134 prefs = main_struct->prefs;
00135
00136 if (prefs->file == NULL)
00137 {
00138 prefs->file = g_key_file_new();
00139 }
00140 }
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150 static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
00151 {
00152 gchar *keyname = NULL;
00153
00154 keyname = g_strconcat(name, " Displayed", NULL);
00155 g_key_file_set_boolean(file, GN_GLOBAL_PREFS, keyname, window_prop->displayed);
00156 g_free(keyname);
00157
00158 keyname = g_strconcat(name, " X_pos", NULL);
00159 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->x);
00160 g_free(keyname);
00161
00162 keyname = g_strconcat(name, " Y_pos", NULL);
00163 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->y);
00164 g_free(keyname);
00165
00166 keyname = g_strconcat(name, " Height", NULL);
00167 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->height);
00168 g_free(keyname);
00169
00170 keyname = g_strconcat(name, " Width", NULL);
00171 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->width);
00172 g_free(keyname);
00173 }
00174
00175
00176
00177
00178
00179
00180 static void save_mp_file_preferences_options(heraia_struct_t *main_struct)
00181 {
00182 prefs_t *prefs = NULL;
00183 gboolean activated = FALSE;
00184
00185 if (main_struct != NULL)
00186 {
00187 prefs = main_struct->prefs;
00188
00189
00190 activated = is_toggle_button_activated(main_struct->xmls->main, "save_window_position_bt");
00191 g_key_file_set_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, activated);
00192
00193
00194 if (activated == TRUE)
00195 {
00196 save_window_preferences(prefs->file, KN_ABOUT_BOX, main_struct->win_prop->about_box);
00197 save_window_preferences(prefs->file, KN_DATA_INTERPRETOR, main_struct->win_prop->data_interpretor);
00198 save_window_preferences(prefs->file, KN_LOG_BOX, main_struct->win_prop->log_box);
00199 save_window_preferences(prefs->file, KN_MAIN_DIALOG, main_struct->win_prop->main_dialog);
00200 save_window_preferences(prefs->file, KN_PLUGIN_LIST, main_struct->win_prop->plugin_list);
00201 save_window_preferences(prefs->file, KN_LDT, main_struct->win_prop->ldt);
00202 save_window_preferences(prefs->file, KN_MAIN_PREFS, main_struct->win_prop->main_pref_window);
00203 save_window_preferences(prefs->file, KN_GOTO_DIALOG, main_struct->win_prop->goto_window);
00204 save_window_preferences(prefs->file, KN_RESULT_WINDOW, main_struct->win_prop->result_window);
00205 save_window_preferences(prefs->file, KN_FIND_WINDOW, main_struct->win_prop->find_window);
00206 save_window_preferences(prefs->file, KN_FR_WINDOW, main_struct->win_prop->fr_window);
00207 }
00208 }
00209 }
00210
00211
00212
00213
00214
00215
00216 static void save_mp_display_preferences_options(heraia_struct_t *main_struct)
00217 {
00218 prefs_t *prefs = NULL;
00219 gboolean activated = FALSE;
00220
00221 if (main_struct != NULL)
00222 {
00223 prefs = main_struct->prefs;
00224
00225
00226 activated = is_toggle_button_activated(main_struct->xmls->main, "mp_thousand_bt");
00227 g_key_file_set_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_THOUSAND, activated);
00228
00229
00230 activated = is_toggle_button_activated(main_struct->xmls->main, "mp_display_offset_bt");
00231 g_key_file_set_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_OFFSETS, activated);
00232 }
00233 }
00234
00235
00236
00237
00238
00239
00240 static void save_di_preferences(heraia_struct_t *main_struct)
00241 {
00242 gint selected_tab = -1;
00243 gint stream_size = -1;
00244 gint endianness = -1;
00245 prefs_t *prefs = NULL;
00246
00247 if (main_struct != NULL && main_struct->current_DW != NULL)
00248 {
00249 prefs = main_struct->prefs;
00250
00251 selected_tab = di_get_selected_tab(main_struct);
00252 if (selected_tab >= 0)
00253 {
00254 g_key_file_set_integer(prefs->file, GN_DI_PREFS, KN_DI_SELECTED_TAB, selected_tab);
00255 }
00256
00257 stream_size = di_get_stream_size(main_struct);
00258 if (stream_size >= 0)
00259 {
00260 g_key_file_set_integer(prefs->file, GN_DI_PREFS, KN_DI_STREAM_SIZE, stream_size);
00261 }
00262
00263 endianness = di_get_endianness(main_struct);
00264 if (endianness >= 0)
00265 {
00266 g_key_file_set_integer(prefs->file, GN_DI_PREFS, KN_DI_ENDIANNESS, endianness);
00267 }
00268 }
00269 }
00270
00271
00272
00273
00274
00275
00276 static void save_mpwp_preferences(heraia_struct_t *main_struct)
00277 {
00278 GtkNotebook *notebook = NULL;
00279 gint selected_tab = -1;
00280 prefs_t *prefs = NULL;
00281
00282 if (main_struct != NULL && main_struct->current_DW != NULL)
00283 {
00284 prefs = main_struct->prefs;
00285
00286 notebook = GTK_NOTEBOOK(heraia_get_widget(main_struct->xmls->main, "mp_first_notebook"));
00287
00288 if (notebook != NULL)
00289 {
00290 selected_tab = gtk_notebook_get_current_page(notebook);
00291
00292 if (selected_tab >= 0)
00293 {
00294 g_key_file_set_integer(prefs->file, GN_MPWP_PREFS, KN_MPWP_SELECTED_TAB, selected_tab);
00295 }
00296 }
00297 }
00298 }
00299
00300
00301
00302
00303
00304
00305 void save_preferences(heraia_struct_t *main_struct)
00306 {
00307 if (main_struct != NULL)
00308 {
00309
00310 save_mp_file_preferences_options(main_struct);
00311
00312
00313 save_mp_display_preferences_options(main_struct);
00314
00315
00316 save_di_preferences(main_struct);
00317
00318
00319 save_mpwp_preferences(main_struct);
00320
00321 if (main_struct->prefs != NULL)
00322 {
00323
00324 save_preferences_to_file(main_struct->prefs);
00325 }
00326 }
00327 }
00328
00329
00330
00331
00332
00333
00334
00335
00336 static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
00337 {
00338 gchar *keyname = NULL;
00339
00340 keyname = g_strconcat(name, " Displayed", NULL);
00341 window_prop->displayed = g_key_file_get_boolean(file, GN_GLOBAL_PREFS, keyname, NULL);
00342 g_free(keyname);
00343
00344 keyname = g_strconcat(name, " X_pos", NULL);
00345 window_prop->x = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00346 g_free(keyname);
00347
00348 keyname = g_strconcat(name, " Y_pos", NULL);
00349 window_prop->y = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00350 g_free(keyname);
00351
00352 keyname = g_strconcat(name, " Height", NULL);
00353 window_prop->height = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00354 g_free(keyname);
00355
00356 keyname = g_strconcat(name, " Width", NULL);
00357 window_prop->width = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00358 g_free(keyname);
00359
00360 }
00361
00362
00363
00364
00365
00366
00367 static void load_mp_file_preferences_options(heraia_struct_t *main_struct)
00368 {
00369 prefs_t *prefs = NULL;
00370 GtkWidget *save_window_position_bt = NULL;
00371 gboolean activated = FALSE;
00372
00373 if (main_struct != NULL)
00374 {
00375 prefs = main_struct->prefs;
00376
00377
00378 activated = g_key_file_get_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, NULL);
00379 save_window_position_bt = heraia_get_widget(main_struct->xmls->main, "save_window_position_bt");
00380 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_window_position_bt), activated);
00381
00382 if (activated == TRUE)
00383 {
00384
00385 load_window_preferences(prefs->file, KN_ABOUT_BOX, main_struct->win_prop->about_box);
00386 load_window_preferences(prefs->file, KN_DATA_INTERPRETOR, main_struct->win_prop->data_interpretor);
00387 load_window_preferences(prefs->file, KN_LOG_BOX, main_struct->win_prop->log_box);
00388 load_window_preferences(prefs->file, KN_MAIN_DIALOG, main_struct->win_prop->main_dialog);
00389 load_window_preferences(prefs->file, KN_PLUGIN_LIST, main_struct->win_prop->plugin_list);
00390 load_window_preferences(prefs->file, KN_LDT, main_struct->win_prop->ldt);
00391 load_window_preferences(prefs->file, KN_MAIN_PREFS, main_struct->win_prop->main_pref_window);
00392 load_window_preferences(prefs->file, KN_GOTO_DIALOG, main_struct->win_prop->goto_window);
00393 load_window_preferences(prefs->file, KN_RESULT_WINDOW, main_struct->win_prop->result_window);
00394 load_window_preferences(prefs->file, KN_FIND_WINDOW, main_struct->win_prop->find_window);
00395 load_window_preferences(prefs->file, KN_FR_WINDOW, main_struct->win_prop->fr_window);
00396 }
00397 }
00398 }
00399
00400
00401
00402
00403
00404
00405 static void load_mp_display_preferences_options(heraia_struct_t *main_struct)
00406 {
00407 prefs_t *prefs = NULL;
00408 GtkWidget *toggle_button = NULL;
00409 gboolean activated = FALSE;
00410
00411 if (main_struct != NULL)
00412 {
00413 prefs = main_struct->prefs;
00414
00415
00416 activated = g_key_file_get_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_THOUSAND, NULL);
00417 toggle_button = heraia_get_widget(main_struct->xmls->main, "mp_thousand_bt");
00418 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), activated);
00419
00420
00421 activated = g_key_file_get_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_OFFSETS, NULL);
00422 toggle_button = heraia_get_widget(main_struct->xmls->main, "mp_display_offset_bt");
00423 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), activated);
00424 }
00425 }
00426
00427
00428
00429
00430
00431
00432 static void load_di_preferences(heraia_struct_t *main_struct)
00433 {
00434 gint selected_tab = -1;
00435 gint stream_size = -1;
00436 gint endianness = -1;
00437 prefs_t *prefs = NULL;
00438
00439 if (main_struct != NULL && main_struct->current_DW != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL)
00440 {
00441
00442 prefs = main_struct->prefs;
00443
00444 selected_tab = g_key_file_get_integer(prefs->file, GN_DI_PREFS, KN_DI_SELECTED_TAB, NULL);
00445 stream_size = g_key_file_get_integer(prefs->file, GN_DI_PREFS, KN_DI_STREAM_SIZE, NULL);
00446 endianness = g_key_file_get_integer(prefs->file, GN_DI_PREFS, KN_DI_ENDIANNESS, NULL);
00447
00448 di_set_selected_tab(main_struct, selected_tab);
00449 di_set_stream_size(main_struct, stream_size);
00450 di_set_endianness(main_struct, endianness);
00451 }
00452 }
00453
00454
00455
00456
00457
00458
00459 static void load_mpwp_preferences(heraia_struct_t *main_struct)
00460 {
00461 GtkNotebook *notebook = NULL;
00462 GtkWidget *button = NULL;
00463 gint selected_tab;
00464 prefs_t *prefs = NULL;
00465
00466 if (main_struct != NULL && main_struct->current_DW != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL)
00467 {
00468 notebook = GTK_NOTEBOOK(heraia_get_widget(main_struct->xmls->main, "mp_first_notebook"));
00469 prefs = main_struct->prefs;
00470
00471 if (notebook != NULL)
00472 {
00473 selected_tab = g_key_file_get_integer(prefs->file, GN_MPWP_PREFS, KN_MPWP_SELECTED_TAB, NULL);
00474
00475 switch (selected_tab)
00476 {
00477 case 0:
00478 gtk_notebook_set_current_page(notebook, selected_tab);
00479 button = heraia_get_widget(main_struct->xmls->main, "mp_tb_fp_bt");
00480 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(button), TRUE);
00481 break;
00482
00483 case 1:
00484 gtk_notebook_set_current_page(notebook, selected_tab);
00485 button = heraia_get_widget(main_struct->xmls->main, "mp_tb_display_bt");
00486 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(button), TRUE);
00487 break;
00488
00489 default:
00490 break;
00491 }
00492 }
00493 }
00494 }
00495
00496
00497
00498
00499
00500
00501 void load_preferences(heraia_struct_t *main_struct)
00502 {
00503 if (main_struct != NULL)
00504 {
00505
00506 load_mp_file_preferences_options(main_struct);
00507
00508
00509 load_mp_display_preferences_options(main_struct);
00510
00511
00512 load_di_preferences(main_struct);
00513
00514
00515 load_mpwp_preferences(main_struct);
00516 }
00517 }