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 static void verify_preference_file_path_presence(gchar *pathname)
00050 {
00051 struct stat *buf = NULL;
00052 gint result = 0;
00053
00054 buf = (struct stat *) g_malloc0(sizeof(struct stat));
00055 result = g_stat(pathname, buf);
00056
00057 if (result != 0)
00058 {
00059 g_mkdir_with_parents(pathname, 488);
00060 }
00061 }
00062
00063
00064
00065
00066
00067
00068
00069 static void verify_preference_file_name_presence(gchar *filename)
00070 {
00071 FILE *fp = NULL;
00072
00073 fp = g_fopen(filename, "r");
00074
00075 if (fp == NULL)
00076 {
00077 fp = g_fopen(filename, "w");
00078 if (fp == NULL)
00079 {
00080 fprintf(stderr, "Unable to open and create the main preference file %s\n", filename);
00081 }
00082 else
00083 {
00084 fprintf(stderr, "Main preference file %s created successfully\n", filename);
00085 fclose(fp);
00086 }
00087 }
00088 else
00089 {
00090 fclose(fp);
00091 }
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101 void verify_preference_file(gchar *pathname, gchar *filename)
00102 {
00103
00104 verify_preference_file_path_presence(pathname);
00105 verify_preference_file_name_presence(filename);
00106
00107 }
00108
00109
00110
00111
00112
00113
00114 void init_preference_struct(heraia_window_t *main_window)
00115 {
00116 prefs_t *prefs = NULL;
00117
00118 if (main_window->prefs == NULL)
00119 {
00120 main_window->prefs = (prefs_t *) g_malloc0(sizeof(prefs_t));
00121 main_window->prefs->file = g_key_file_new();
00122 main_window->prefs->pathname = g_strdup_printf("%s%c.%s", g_get_home_dir(), G_DIR_SEPARATOR, "heraia");
00123 main_window->prefs->filename = g_strdup_printf("%s%c%s", main_window->prefs->pathname, G_DIR_SEPARATOR, "main_preferences");
00124 }
00125 else
00126 {
00127 prefs = main_window->prefs;
00128
00129 if (prefs->file == NULL)
00130 {
00131 prefs->file = g_key_file_new();
00132 }
00133 }
00134 }
00135
00136
00137
00138
00139
00140
00141
00142 static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
00143 {
00144 gchar *keyname = NULL;
00145
00146 keyname = g_strconcat(name, " Displayed", NULL);
00147 g_key_file_set_boolean(file, GN_GLOBAL_PREFS, keyname, window_prop->displayed);
00148 g_free(keyname);
00149
00150 keyname = g_strconcat(name, " X_pos", NULL);
00151 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->x);
00152 g_free(keyname);
00153
00154 keyname = g_strconcat(name, " Y_pos", NULL);
00155 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->y);
00156 g_free(keyname);
00157
00158 keyname = g_strconcat(name, " Height", NULL);
00159 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->height);
00160 g_free(keyname);
00161
00162 keyname = g_strconcat(name, " Width", NULL);
00163 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->width);
00164 g_free(keyname);
00165 }
00166
00167
00168
00169
00170
00171 static void save_mp_file_preferences_options(heraia_window_t *main_window)
00172 {
00173 prefs_t *prefs = NULL;
00174 gboolean activated = FALSE;
00175
00176 if (main_window != NULL)
00177 {
00178 prefs = main_window->prefs;
00179
00180
00181 activated = is_toggle_button_activated(main_window->xmls->main, "save_window_position_bt");
00182 g_key_file_set_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, activated);
00183
00184
00185 if (activated == TRUE)
00186 {
00187 save_window_preferences(prefs->file, KN_ABOUT_BOX, main_window->win_prop->about_box);
00188 save_window_preferences(prefs->file, KN_DATA_INTERPRETOR, main_window->win_prop->data_interpretor);
00189 save_window_preferences(prefs->file, KN_LOG_BOX, main_window->win_prop->log_box);
00190 save_window_preferences(prefs->file, KN_MAIN_DIALOG, main_window->win_prop->main_dialog);
00191 save_window_preferences(prefs->file, KN_PLUGIN_LIST, main_window->win_prop->plugin_list);
00192 save_window_preferences(prefs->file, KN_LDT, main_window->win_prop->ldt);
00193 save_window_preferences(prefs->file, KN_MAIN_PREFS, main_window->win_prop->main_pref_window);
00194 }
00195 }
00196 }
00197
00198
00199
00200
00201
00202
00203 static void save_mp_display_preferences_options(heraia_window_t *main_window)
00204 {
00205 prefs_t *prefs = NULL;
00206 gboolean activated = FALSE;
00207
00208 if (main_window != NULL)
00209 {
00210 prefs = main_window->prefs;
00211
00212
00213 activated = is_toggle_button_activated(main_window->xmls->main, "mp_thousand_bt");
00214 g_key_file_set_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_THOUSAND, activated);
00215 }
00216 }
00217
00218
00219
00220
00221
00222
00223 static void save_di_preferences(heraia_window_t *main_window)
00224 {
00225 GtkNotebook *notebook = NULL;
00226 gint selected_tab;
00227 prefs_t *prefs = NULL;
00228
00229 if (main_window != NULL && main_window->current_DW != NULL)
00230 {
00231 prefs = main_window->prefs;
00232
00233 notebook = GTK_NOTEBOOK(heraia_get_widget(main_window->xmls->main, "diw_notebook"));
00234
00235 if (notebook != NULL)
00236 {
00237 selected_tab = gtk_notebook_get_current_page(notebook);
00238
00239 if (selected_tab >= 0)
00240 {
00241 g_key_file_set_integer(prefs->file, GN_DI_PREFS, KN_DI_SELECTED_TAB, selected_tab);
00242 }
00243 }
00244 }
00245 }
00246
00247
00248
00249
00250
00251
00252 void save_preferences(heraia_window_t *main_window)
00253 {
00254 if (main_window != NULL)
00255 {
00256
00257
00258
00259
00260 save_mp_file_preferences_options(main_window);
00261
00262
00263 save_mp_display_preferences_options(main_window);
00264
00265
00266 save_di_preferences(main_window);
00267
00268 if (main_window->prefs != NULL)
00269 {
00270
00271 save_preferences_to_file(main_window->prefs);
00272 }
00273 }
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283 static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
00284 {
00285 gchar *keyname = NULL;
00286
00287 keyname = g_strconcat(name, " Displayed", NULL);
00288 window_prop->displayed = g_key_file_get_boolean(file, GN_GLOBAL_PREFS, keyname, NULL);
00289 g_free(keyname);
00290
00291 keyname = g_strconcat(name, " X_pos", NULL);
00292 window_prop->x = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00293 g_free(keyname);
00294
00295 keyname = g_strconcat(name, " Y_pos", NULL);
00296 window_prop->y = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00297 g_free(keyname);
00298
00299 keyname = g_strconcat(name, " Height", NULL);
00300 window_prop->height = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00301 g_free(keyname);
00302
00303 keyname = g_strconcat(name, " Width", NULL);
00304 window_prop->width = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00305 g_free(keyname);
00306
00307 }
00308
00309
00310
00311
00312
00313
00314 static void load_mp_file_preferences_options(heraia_window_t *main_window)
00315 {
00316 prefs_t *prefs = NULL;
00317 GtkWidget *save_window_position_bt = NULL;
00318 gboolean activated = FALSE;
00319
00320 if (main_window != NULL)
00321 {
00322 prefs = main_window->prefs;
00323
00324
00325 activated = g_key_file_get_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, NULL);
00326 save_window_position_bt = heraia_get_widget(main_window->xmls->main, "save_window_position_bt");
00327 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_window_position_bt), activated);
00328
00329 if (activated == TRUE)
00330 {
00331
00332 load_window_preferences(prefs->file, KN_ABOUT_BOX, main_window->win_prop->about_box);
00333 load_window_preferences(prefs->file, KN_DATA_INTERPRETOR, main_window->win_prop->data_interpretor);
00334 load_window_preferences(prefs->file, KN_LOG_BOX, main_window->win_prop->log_box);
00335 load_window_preferences(prefs->file, KN_MAIN_DIALOG, main_window->win_prop->main_dialog);
00336 load_window_preferences(prefs->file, KN_PLUGIN_LIST, main_window->win_prop->plugin_list);
00337 load_window_preferences(prefs->file, KN_LDT, main_window->win_prop->ldt);
00338 load_window_preferences(prefs->file, KN_MAIN_PREFS, main_window->win_prop->main_pref_window);
00339 }
00340 }
00341 }
00342
00343
00344
00345
00346
00347
00348 static void load_mp_display_preferences_options(heraia_window_t *main_window)
00349 {
00350 prefs_t *prefs = NULL;
00351 GtkWidget *display_thousand_bt = NULL;
00352 gboolean activated = FALSE;
00353
00354 if (main_window != NULL)
00355 {
00356 prefs = main_window->prefs;
00357
00358
00359 activated = g_key_file_get_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_THOUSAND, NULL);
00360 display_thousand_bt = heraia_get_widget(main_window->xmls->main, "mp_thousand_bt");
00361 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(display_thousand_bt), activated);
00362 }
00363 }
00364
00365
00366
00367
00368
00369
00370 static void load_di_preferences(heraia_window_t *main_window)
00371 {
00372 GtkNotebook *notebook = NULL;
00373 gint selected_tab;
00374 prefs_t *prefs = NULL;
00375
00376 if (main_window != NULL && main_window->current_DW != NULL && main_window->xmls != NULL && main_window->xmls->main != NULL)
00377 {
00378 notebook = GTK_NOTEBOOK(heraia_get_widget(main_window->xmls->main, "diw_notebook"));
00379 prefs = main_window->prefs;
00380
00381 if (notebook != NULL)
00382 {
00383 selected_tab = g_key_file_get_integer(prefs->file, GN_DI_PREFS, KN_DI_SELECTED_TAB, NULL);
00384
00385 if (selected_tab >= 0)
00386 {
00387 gtk_notebook_set_current_page(notebook, selected_tab);
00388 main_window->current_DW->tab_displayed = selected_tab;
00389 }
00390 }
00391 }
00392 }
00393
00394
00395
00396
00397
00398
00399 void load_preferences(heraia_window_t *main_window)
00400 {
00401 if (main_window != NULL)
00402 {
00403
00404
00405
00406
00407 load_mp_file_preferences_options(main_window);
00408
00409
00410 load_mp_display_preferences_options(main_window);
00411
00412
00413 load_di_preferences(main_window);
00414 }
00415 }