A więc tak, mam taki plik konfiguracyjny:
[main window position]
remember=true
x=349
y=333
taka funkcje odczytujaca dane z pliku knfiguracyjnego:
----------------------------------------START
gboolean load_settings_file (void) {
gchar settings_file_path[1024];
g_sprintf (settings_file_path, "%s/.gbiblioteka/%s", g_get_home_dir(), "gbiblioteka.conf");
if( g_file_test (settings_file_path, G_FILE_TEST_EXISTS)) {
GError *error_handler;
GKeyFile *settings_file;
error_handler = NULL;
settings_file = g_key_file_new ();
g_key_file_load_from_file (settings_file,
settings_file_path,
G_KEY_FILE_NONE,
&error_handler);
settings.remember = g_key_file_get_boolean (settings_file,
"main window position",
"remember",
&error_handler);
settings.x = g_key_file_get_integer (settings_file,
"main window position",
"x",
&error_handler);
settings.y = g_key_file_get_integer (settings_file,
"main window position",
"y",
&error_handler);
g_key_file_free (settings_file);
g_clear_error (&error_handler);
return TRUE;
}
else {
g_printf (_("(ERROR) Can't open config file!n"));
return FALSE;
}
}
-----------------------------------------KONIEC
a to funkcja zapisywania:
----------------------------------------START
gchar settings_file_path[1024];
g_sprintf (settings_file_path, "%s/.gbiblioteka/%s", g_get_home_dir(), "gbiblioteka.conf");
g_printf (_("Saving settings...n"));
set_statusbar_text (_("Saving settings..."));
if( g_file_test (settings_file_path, G_FILE_TEST_EXISTS)) {
GError *error_handler;
GKeyFile *settings_file;
error_handler = NULL;
settings_file = g_key_file_new ();
g_key_file_load_from_file (settings_file,
settings_file_path,
G_KEY_FILE_NONE,
&error_handler);
g_key_file_set_boolean (settings_file,
"main window position",
"remember",
settings.remember);
get_main_win_position ();
printf ("%d %dn", settings.x, settings.y);
g_key_file_set_integer (settings_file,
"main window position",
"x",
settings.x);
g_key_file_set_integer (settings_file,
"main window position",
"xg",
settings.x);
g_key_file_set_integer (settings_file,
"main window position",
"y",
settings.y);
g_key_file_remove_key (settings_file,
"main window position",
"x",
&error_handler);
g_key_file_free (settings_file);
g_clear_error (&error_handler);
set_statusbar_text (_("Settings saved!"));
g_printf (_("tSettings saved!n"));
}
else {
set_statusbar_text (_("Error while saving settings!"));
g_printf (_("t(ERROR) Can't save config file!n"));
}
}
-----------------------------------------KONIEC
i kłopot w ty,m, ze funkcja zapisywania niec nie zapisuje :-(
dane trzymam w strukturze i dane sa na 100% poprawne, po prpstu funkcja nie zapisuje nowych ustawien! A samo GLib nie zglasza ZADNYCH bledow?!
Pomocy!