summaryrefslogtreecommitdiff
path: root/src/preferences.c
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2012-11-05 14:08:40 -0800
committerStefano Karapetsas <[email protected]>2012-11-05 14:08:40 -0800
commit0d97b91e417fda108955b155cc287db086850c81 (patch)
tree5fd33bf86621b0de3aa2cb30b7b940f74c979749 /src/preferences.c
parent8f8784ba4ebcd8eb099c4e119a9a8d5a349efd61 (diff)
parent61fe44bd16be34d89b127f403b3e07d63aa67e89 (diff)
downloadengrampa-0d97b91e417fda108955b155cc287db086850c81.tar.bz2
engrampa-0d97b91e417fda108955b155cc287db086850c81.tar.xz
Merge pull request #7 from NiceandGently/master
port to gsettings
Diffstat (limited to 'src/preferences.c')
-rw-r--r--src/preferences.c244
1 files changed, 24 insertions, 220 deletions
diff --git a/src/preferences.c b/src/preferences.c
index 3c877cd..7fbdf8f 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -21,248 +21,52 @@
*/
#include <string.h>
-#include <mateconf/mateconf-client.h>
#include "typedefs.h"
#include "preferences.h"
#include "main.h"
#include "file-utils.h"
-#include "mateconf-utils.h"
#include "fr-window.h"
-#define DIALOG_PREFIX "/apps/engrampa/dialogs/"
-
-
-typedef struct {
- int i_value;
- char *s_value;
-} EnumStringTable;
-
-
-static int
-get_enum_from_string (EnumStringTable *table,
- const char *s_value)
-{
- int i;
-
- /* return the first value if s_value is invalid */
-
- if (s_value == NULL)
- return table[0].i_value;
-
- for (i = 0; table[i].s_value != NULL; i++)
- if (strcmp (s_value, table[i].s_value) == 0)
- return table[i].i_value;
-
- return table[0].i_value;
-}
-
-
-static char *
-get_string_from_enum (EnumStringTable *table,
- int i_value)
-{
- int i;
-
- for (i = 0; table[i].s_value != NULL; i++)
- if (i_value == table[i].i_value)
- return table[i].s_value;
-
- /* return the first value if i_value is invalid */
-
- return table[0].s_value;
-}
-
-
-/* --------------- */
-
-
-static EnumStringTable sort_method_table [] = {
- { FR_WINDOW_SORT_BY_NAME, "name" },
- { FR_WINDOW_SORT_BY_SIZE, "size" },
- { FR_WINDOW_SORT_BY_TYPE, "type" },
- { FR_WINDOW_SORT_BY_TIME, "time" },
- { FR_WINDOW_SORT_BY_PATH, "path" },
- { 0, NULL }
-};
-
-static EnumStringTable sort_type_table [] = {
- { GTK_SORT_ASCENDING, "ascending" },
- { GTK_SORT_DESCENDING, "descending" },
- { 0, NULL }
-};
-
-static EnumStringTable list_mode_table [] = {
- { FR_WINDOW_LIST_MODE_FLAT, "all_files" },
- { FR_WINDOW_LIST_MODE_AS_DIR, "as_folder" },
- { 0, NULL }
-};
-
-static EnumStringTable compression_level_table [] = {
- { FR_COMPRESSION_VERY_FAST, "very_fast" },
- { FR_COMPRESSION_FAST, "fast" },
- { FR_COMPRESSION_NORMAL, "normal" },
- { FR_COMPRESSION_MAXIMUM, "maximum" },
- { 0, NULL }
-};
-
-
-/* --------------- */
-
-
-FrWindowSortMethod
-preferences_get_sort_method (void)
-{
- char *s_value;
- int i_value;
-
- s_value = eel_mateconf_get_string (PREF_LIST_SORT_METHOD, "name");
- i_value = get_enum_from_string (sort_method_table, s_value);
- g_free (s_value);
-
- return (FrWindowSortMethod) i_value;
-}
-
-
-void
-preferences_set_sort_method (FrWindowSortMethod i_value)
-{
- char *s_value;
-
- s_value = get_string_from_enum (sort_method_table, i_value);
- eel_mateconf_set_string (PREF_LIST_SORT_METHOD, s_value);
-}
-
-
-GtkSortType
-preferences_get_sort_type (void)
-{
- char *s_value;
- int i_value;
-
- s_value = eel_mateconf_get_string (PREF_LIST_SORT_TYPE, "ascending");
- i_value = get_enum_from_string (sort_type_table, s_value);
- g_free (s_value);
-
- return (GtkSortType) i_value;
-}
-
-
-void
-preferences_set_sort_type (GtkSortType i_value)
-{
- char *s_value;
-
- s_value = get_string_from_enum (sort_type_table, i_value);
- eel_mateconf_set_string (PREF_LIST_SORT_TYPE, s_value);
-}
-
-
-FrWindowListMode
-preferences_get_list_mode (void)
-{
- char *s_value;
- int i_value;
-
- s_value = eel_mateconf_get_string (PREF_LIST_MODE, "as_folder");
- i_value = get_enum_from_string (list_mode_table, s_value);
- g_free (s_value);
-
- return (FrWindowListMode) i_value;
-}
-
-
-void
-preferences_set_list_mode (FrWindowListMode i_value)
-{
- char *s_value;
-
- s_value = get_string_from_enum (list_mode_table, i_value);
- eel_mateconf_set_string (PREF_LIST_MODE, s_value);
-}
-
-
-FrCompression
-preferences_get_compression_level (void)
-{
- char *s_value;
- int i_value;
-
- s_value = eel_mateconf_get_string (PREF_ADD_COMPRESSION_LEVEL, "normal");
- i_value = get_enum_from_string (compression_level_table, s_value);
- g_free (s_value);
-
- return (FrCompression) i_value;
-}
-
-
-void
-preferences_set_compression_level (FrCompression i_value)
-{
- char *s_value;
-
- s_value = get_string_from_enum (compression_level_table, i_value);
- eel_mateconf_set_string (PREF_ADD_COMPRESSION_LEVEL, s_value);
-}
-
-
-static void
-set_dialog_property_int (const char *dialog,
- const char *property,
- int value)
-{
- char *key;
-
- key = g_strconcat (DIALOG_PREFIX, dialog, "/", property, NULL);
- eel_mateconf_set_integer (key, value);
- g_free (key);
-}
-
-
void
pref_util_save_window_geometry (GtkWindow *window,
- const char *dialog)
+ const char *dialog_id)
{
- int x, y, width, height;
+ char *schema;
+ GSettings *settings;
+ int width;
+ int height;
- gtk_window_get_position (window, &x, &y);
- set_dialog_property_int (dialog, "x", x);
- set_dialog_property_int (dialog, "y", y);
+ schema = g_strconcat (ENGRAMPA_SCHEMA_DIALOGS, ".", dialog_id, NULL);
+ settings = g_settings_new (schema);
gtk_window_get_size (window, &width, &height);
- set_dialog_property_int (dialog, "width", width);
- set_dialog_property_int (dialog, "height", height);
-}
-
-
-static int
-get_dialog_property_int (const char *dialog,
- const char *property)
-{
- char *key;
- int value;
-
- key = g_strconcat (DIALOG_PREFIX, dialog, "/", property, NULL);
- value = eel_mateconf_get_integer (key, -1);
- g_free (key);
-
- return value;
+ g_settings_set_int (settings, "width", width);
+ g_settings_set_int (settings, "height", height);
+ g_object_unref (settings);
+ g_free (schema);
}
void
pref_util_restore_window_geometry (GtkWindow *window,
- const char *dialog)
+ const char *dialog_id)
{
- int x, y, width, height;
+ char *schema;
+ GSettings *settings;
+ int width;
+ int height;
- x = get_dialog_property_int (dialog, "x");
- y = get_dialog_property_int (dialog, "y");
- width = get_dialog_property_int (dialog, "width");
- height = get_dialog_property_int (dialog, "height");
+ schema = g_strconcat (ENGRAMPA_SCHEMA_DIALOGS, ".", dialog_id, NULL);
+ settings = g_settings_new (schema);
- if (width != -1 && height != 1)
+ width = g_settings_get_int (settings, "width");
+ height = g_settings_get_int (settings, "height");
+ if ((width != -1) && (height != 1))
gtk_window_set_default_size (window, width, height);
gtk_window_present (window);
+
+ g_object_unref (settings);
+ g_free (schema);
}