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 #include <libheraia.h>
00026
00027 static void verify_preference_file_path_presence(gchar *pathname);
00028 static void verify_preference_file_name_presence(gchar *filename);
00029 static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop);
00030 static void save_mp_file_preferences_options(heraia_window_t *main_window);
00031
00036 static void verify_preference_file_path_presence(gchar *pathname)
00037 {
00038 struct stat *buf = NULL;
00039 gint result = 0;
00040
00041 buf = (struct stat *) g_malloc0(sizeof(struct stat));
00042 result = g_stat(pathname, buf);
00043
00044 if (result != 0)
00045 {
00046 g_mkdir_with_parents(pathname, 488);
00047 }
00048 }
00049
00053 static void verify_preference_file_name_presence(gchar *filename)
00054 {
00055 FILE *fp = NULL;
00056
00057 fp = g_fopen(filename, "r");
00058
00059 if (fp == NULL)
00060 {
00061 fp = g_fopen(filename, "w");
00062 if (fp == NULL)
00063 {
00064 fprintf(stderr, "Unable to open and create the main preference file %s\n", filename);
00065 }
00066 else
00067 {
00068 fprintf(stderr, "Main preference file %s created successfully\n", filename);
00069 fclose(fp);
00070 }
00071 }
00072 else
00073 {
00074 fclose(fp);
00075 }
00076 }
00077
00082 void verify_preference_file(gchar *pathname, gchar *filename)
00083 {
00084
00085 verify_preference_file_path_presence(pathname);
00086 verify_preference_file_name_presence(filename);
00087
00088 }
00089
00093 static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
00094 {
00095 gchar *keyname = NULL;
00096
00097 keyname = g_strconcat(name, " Displayed", NULL);
00098 g_key_file_set_boolean(file, GN_GLOBAL_PREFS, keyname, window_prop->displayed);
00099 g_free(keyname);
00100
00101 keyname = g_strconcat(name, " X_pos", NULL);
00102 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->x);
00103 g_free(keyname);
00104
00105 keyname = g_strconcat(name, " Y_pos", NULL);
00106 g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->y);
00107 g_free(keyname);
00108 }
00109
00113 static void save_mp_file_preferences_options(heraia_window_t *main_window)
00114 {
00115 prefs_t *prefs = NULL;
00116 GtkWidget *save_window_position_bt = NULL;
00117 gboolean activated = FALSE;
00118
00119 if (main_window != NULL)
00120 {
00121 prefs = main_window->prefs;
00122
00123 if (prefs->file == NULL)
00124 {
00125 prefs->file = g_key_file_new();
00126 }
00127
00128 if (prefs != NULL && prefs->file != NULL)
00129 {
00130
00131 save_window_position_bt = heraia_get_widget(main_window->xmls->main, "save_window_position_bt");
00132 activated = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(save_window_position_bt));
00133 g_key_file_set_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, activated);
00134
00135
00136 if (activated == TRUE)
00137 {
00138 save_window_preferences(prefs->file, KN_ABOUT_BOX, main_window->win_prop->about_box);
00139 save_window_preferences(prefs->file, KN_DATA_INTERPRETOR, main_window->win_prop->data_interpretor);
00140 save_window_preferences(prefs->file, KN_LOG_BOX, main_window->win_prop->log_box);
00141 save_window_preferences(prefs->file, KN_MAIN_DIALOG, main_window->win_prop->main_dialog);
00142 save_window_preferences(prefs->file, KN_PLUGIN_LIST, main_window->win_prop->plugin_list);
00143 save_window_preferences(prefs->file, KN_LDT, main_window->win_prop->ldt);
00144 save_window_preferences(prefs->file, KN_MAIN_PREFS, main_window->win_prop->main_pref_window);
00145 }
00146 }
00147 }
00148 }
00149
00153 void save_main_preferences(heraia_window_t *main_window)
00154 {
00155 if (main_window != NULL)
00156 {
00157
00158 save_mp_file_preferences_options(main_window);
00159
00160 if (main_window->prefs != NULL)
00161 {
00162
00163 save_preferences_to_file(main_window->prefs);
00164 }
00165 }
00166 }
00167
00168
00172 static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
00173 {
00174 gchar *keyname = NULL;
00175
00176 keyname = g_strconcat(name, " Displayed", NULL);
00177 window_prop->displayed = g_key_file_get_boolean(file, GN_GLOBAL_PREFS, keyname, NULL);
00178 g_free(keyname);
00179
00180 keyname = g_strconcat(name, " X_pos", NULL);
00181 window_prop->x = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00182 g_free(keyname);
00183
00184 keyname = g_strconcat(name, " Y_pos", NULL);
00185 window_prop->y = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00186 g_free(keyname);
00187 }
00188
00189
00193 static void load_mp_file_preferences_options(heraia_window_t *main_window)
00194 {
00195 prefs_t *prefs = NULL;
00196 GtkWidget *save_window_position_bt = NULL;
00197 gboolean activated = FALSE;
00198
00199 if (main_window != NULL)
00200 {
00201 prefs = main_window->prefs;
00202
00203 if (prefs != NULL && prefs->file != NULL)
00204 {
00205
00206 activated = g_key_file_get_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, NULL);
00207 save_window_position_bt = heraia_get_widget(main_window->xmls->main, "save_window_position_bt");
00208 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_window_position_bt), activated);
00209
00210 if (activated == TRUE)
00211 {
00212
00213 load_window_preferences(prefs->file, KN_ABOUT_BOX, main_window->win_prop->about_box);
00214 load_window_preferences(prefs->file, KN_DATA_INTERPRETOR, main_window->win_prop->data_interpretor);
00215 load_window_preferences(prefs->file, KN_LOG_BOX, main_window->win_prop->log_box);
00216 load_window_preferences(prefs->file, KN_MAIN_DIALOG, main_window->win_prop->main_dialog);
00217 load_window_preferences(prefs->file, KN_PLUGIN_LIST, main_window->win_prop->plugin_list);
00218 load_window_preferences(prefs->file, KN_LDT, main_window->win_prop->ldt);
00219 load_window_preferences(prefs->file, KN_MAIN_PREFS, main_window->win_prop->main_pref_window);
00220 }
00221 }
00222 }
00223 }
00224
00228 void setup_preferences(heraia_window_t *main_window)
00229 {
00230 if (main_window != NULL)
00231 {
00232
00233 load_mp_file_preferences_options(main_window);
00234 }
00235 }
00236