diff options
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/preferences.c | 471 | ||||
-rw-r--r-- | src/config/preferences.h | 22 | ||||
-rw-r--r-- | src/config/theme.c | 9 |
3 files changed, 493 insertions, 9 deletions
diff --git a/src/config/preferences.c b/src/config/preferences.c index 68a132e5..defc582e 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -143,7 +143,7 @@ prefs_load(void) prefs_free_string(value); } - // move pre 0.5.0 titlebar settings to wintitle + // move pre 0.6.0 titlebar settings to wintitle if (g_key_file_has_key(prefs, PREF_GROUP_UI, "titlebar.show", NULL)) { gboolean show = g_key_file_get_boolean(prefs, PREF_GROUP_UI, "titlebar.show", NULL); g_key_file_set_boolean(prefs, PREF_GROUP_UI, "wintitle.show", show); @@ -155,7 +155,6 @@ prefs_load(void) g_key_file_remove_key(prefs, PREF_GROUP_UI, "titlebar.goodbye", NULL); } - _save_prefs(); boolean_choice_ac = autocomplete_new(); @@ -1062,6 +1061,469 @@ prefs_get_room_notify_triggers(void) return result; } +ProfWinPlacement* +prefs_create_profwin_placement(int titlebar, int mainwin, int statusbar, int inputwin) +{ + ProfWinPlacement *placement = malloc(sizeof(ProfWinPlacement)); + placement->titlebar_pos = titlebar; + placement->mainwin_pos = mainwin; + placement->statusbar_pos = statusbar; + placement->inputwin_pos = inputwin; + + return placement; +} + +void +prefs_free_win_placement(ProfWinPlacement *placement) +{ + free(placement); +} + +ProfWinPlacement* +prefs_get_win_placement(void) +{ + // read from settings file + int titlebar_pos = g_key_file_get_integer(prefs, PREF_GROUP_UI, "titlebar.position", NULL); + int mainwin_pos = g_key_file_get_integer(prefs, PREF_GROUP_UI, "mainwin.position", NULL); + int statusbar_pos = g_key_file_get_integer(prefs, PREF_GROUP_UI, "statusbar.position", NULL); + int inputwin_pos = g_key_file_get_integer(prefs, PREF_GROUP_UI, "inputwin.position", NULL); + + // default if setting invalid, or not present + if (titlebar_pos < 1 || titlebar_pos > 4) { + titlebar_pos = 1; + } + if (mainwin_pos < 1 || mainwin_pos > 4) { + mainwin_pos = 2; + } + if (statusbar_pos < 1 || statusbar_pos > 4) { + statusbar_pos = 3; + } + if (inputwin_pos < 1 || inputwin_pos > 4) { + inputwin_pos = 4; + } + + // return default if duplicates found + if (titlebar_pos == mainwin_pos) { + return prefs_create_profwin_placement(1, 2, 3, 5); + } + if (titlebar_pos == statusbar_pos) { + return prefs_create_profwin_placement(1, 2, 3, 5); + } + if (titlebar_pos == inputwin_pos) { + return prefs_create_profwin_placement(1, 2, 3, 5); + } + + if (mainwin_pos == statusbar_pos) { + return prefs_create_profwin_placement(1, 2, 3, 5); + } + if (mainwin_pos == inputwin_pos) { + return prefs_create_profwin_placement(1, 2, 3, 5); + } + + if (statusbar_pos == inputwin_pos) { + return prefs_create_profwin_placement(1, 2, 3, 5); + } + + // return settings + return prefs_create_profwin_placement(titlebar_pos, mainwin_pos, statusbar_pos, inputwin_pos); +} + +void +prefs_save_win_placement(ProfWinPlacement *placement) +{ + g_key_file_set_integer(prefs, PREF_GROUP_UI, "titlebar.position", placement->titlebar_pos); + g_key_file_set_integer(prefs, PREF_GROUP_UI, "mainwin.position", placement->mainwin_pos); + g_key_file_set_integer(prefs, PREF_GROUP_UI, "statusbar.position", placement->statusbar_pos); + g_key_file_set_integer(prefs, PREF_GROUP_UI, "inputwin.position", placement->inputwin_pos); + _save_prefs(); +} + +gboolean +prefs_titlebar_pos_up(void) +{ + ProfWinPlacement *placement = prefs_get_win_placement(); + if (placement->titlebar_pos == 2) { + placement->titlebar_pos = 1; + if (placement->mainwin_pos == 1) { + placement->mainwin_pos = 2; + } else if (placement->statusbar_pos == 1) { + placement->statusbar_pos = 2; + } else if (placement->inputwin_pos == 1) { + placement->inputwin_pos = 2; + } + + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->titlebar_pos == 3) { + placement->titlebar_pos = 2; + if (placement->mainwin_pos == 2) { + placement->mainwin_pos = 3; + } else if (placement->statusbar_pos == 2) { + placement->statusbar_pos = 3; + } else if (placement->inputwin_pos == 2) { + placement->inputwin_pos = 3; + } + + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->titlebar_pos == 4) { + placement->titlebar_pos = 3; + if (placement->mainwin_pos == 3) { + placement->mainwin_pos = 4; + } else if (placement->statusbar_pos == 3) { + placement->statusbar_pos = 4; + } else if (placement->inputwin_pos == 3) { + placement->inputwin_pos = 4; + } + + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + + prefs_free_win_placement(placement); + return FALSE; +} + +gboolean +prefs_mainwin_pos_up(void) +{ + ProfWinPlacement *placement = prefs_get_win_placement(); + if (placement->mainwin_pos == 2) { + placement->mainwin_pos = 1; + if (placement->titlebar_pos == 1) { + placement->titlebar_pos = 2; + } else if (placement->statusbar_pos == 1) { + placement->statusbar_pos = 2; + } else if (placement->inputwin_pos == 1) { + placement->inputwin_pos = 2; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->mainwin_pos == 3) { + placement->mainwin_pos = 2; + if (placement->titlebar_pos == 2) { + placement->titlebar_pos = 3; + } else if (placement->statusbar_pos == 2) { + placement->statusbar_pos = 3; + } else if (placement->inputwin_pos == 2) { + placement->inputwin_pos = 3; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->mainwin_pos == 4) { + placement->mainwin_pos = 3; + if (placement->titlebar_pos == 3) { + placement->titlebar_pos = 4; + } else if (placement->statusbar_pos == 3) { + placement->statusbar_pos = 4; + } else if (placement->inputwin_pos == 3) { + placement->inputwin_pos = 4; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + + prefs_free_win_placement(placement); + return FALSE; +} + +gboolean +prefs_statusbar_pos_up(void) +{ + ProfWinPlacement *placement = prefs_get_win_placement(); + if (placement->statusbar_pos == 2) { + placement->statusbar_pos = 1; + if (placement->titlebar_pos == 1) { + placement->titlebar_pos = 2; + } else if (placement->mainwin_pos == 1) { + placement->mainwin_pos = 2; + } else if (placement->inputwin_pos == 1) { + placement->inputwin_pos = 2; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->statusbar_pos == 3) { + placement->statusbar_pos = 2; + if (placement->titlebar_pos == 2) { + placement->titlebar_pos = 3; + } else if (placement->mainwin_pos == 2) { + placement->mainwin_pos = 3; + } else if (placement->inputwin_pos == 2) { + placement->inputwin_pos = 3; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->statusbar_pos == 4) { + placement->statusbar_pos = 3; + if (placement->titlebar_pos == 3) { + placement->titlebar_pos = 4; + } else if (placement->mainwin_pos == 3) { + placement->mainwin_pos = 4; + } else if (placement->inputwin_pos == 3) { + placement->inputwin_pos = 4; + } + return TRUE; + } + + prefs_free_win_placement(placement); + return FALSE; +} + +gboolean +prefs_inputwin_pos_up(void) +{ + ProfWinPlacement *placement = prefs_get_win_placement(); + if (placement->inputwin_pos == 2) { + placement->inputwin_pos = 1; + if (placement->titlebar_pos == 1) { + placement->titlebar_pos = 2; + } else if (placement->mainwin_pos == 1) { + placement->mainwin_pos = 2; + } else if (placement->inputwin_pos == 1) { + placement->inputwin_pos = 2; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->inputwin_pos == 3) { + placement->inputwin_pos = 2; + if (placement->titlebar_pos == 2) { + placement->titlebar_pos = 3; + } else if (placement->mainwin_pos == 2) { + placement->mainwin_pos = 3; + } else if (placement->statusbar_pos == 2) { + placement->statusbar_pos = 3; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->inputwin_pos == 4) { + placement->inputwin_pos = 3; + if (placement->titlebar_pos == 3) { + placement->titlebar_pos = 4; + } else if (placement->mainwin_pos == 3) { + placement->mainwin_pos = 4; + } else if (placement->statusbar_pos == 3) { + placement->statusbar_pos = 4; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + + prefs_free_win_placement(placement); + return FALSE; +} + +gboolean +prefs_titlebar_pos_down(void) +{ + ProfWinPlacement *placement = prefs_get_win_placement(); + if (placement->titlebar_pos == 1) { + placement->titlebar_pos = 2; + if (placement->mainwin_pos == 2) { + placement->mainwin_pos = 1; + } else if (placement->statusbar_pos == 2) { + placement->statusbar_pos = 1; + } else if (placement->inputwin_pos == 2) { + placement->inputwin_pos = 1; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->titlebar_pos == 2) { + placement->titlebar_pos = 3; + if (placement->mainwin_pos == 3) { + placement->mainwin_pos = 2; + } else if (placement->statusbar_pos == 3) { + placement->statusbar_pos = 2; + } else if (placement->inputwin_pos == 3) { + placement->inputwin_pos = 2; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->titlebar_pos == 3) { + placement->titlebar_pos = 4; + if (placement->mainwin_pos == 4) { + placement->mainwin_pos = 3; + } else if (placement->statusbar_pos == 4) { + placement->statusbar_pos = 3; + } else if (placement->inputwin_pos == 4) { + placement->inputwin_pos = 3; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + + prefs_free_win_placement(placement); + return FALSE; +} + +gboolean +prefs_mainwin_pos_down(void) +{ + ProfWinPlacement *placement = prefs_get_win_placement(); + if (placement->mainwin_pos == 1) { + placement->mainwin_pos = 2; + if (placement->titlebar_pos == 2) { + placement->titlebar_pos = 1; + } else if (placement->statusbar_pos == 2) { + placement->statusbar_pos = 1; + } else if (placement->inputwin_pos == 2) { + placement->inputwin_pos = 1; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->mainwin_pos == 2) { + placement->mainwin_pos = 3; + if (placement->titlebar_pos == 3) { + placement->titlebar_pos = 2; + } else if (placement->statusbar_pos == 3) { + placement->statusbar_pos = 2; + } else if (placement->inputwin_pos == 3) { + placement->inputwin_pos = 2; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->mainwin_pos == 3) { + placement->mainwin_pos = 4; + if (placement->titlebar_pos == 4) { + placement->titlebar_pos = 3; + } else if (placement->statusbar_pos == 4) { + placement->statusbar_pos = 3; + } else if (placement->inputwin_pos == 4) { + placement->inputwin_pos = 3; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + + prefs_free_win_placement(placement); + return FALSE; +} + +gboolean +prefs_statusbar_pos_down(void) +{ + ProfWinPlacement *placement = prefs_get_win_placement(); + if (placement->statusbar_pos == 1) { + placement->statusbar_pos = 2; + if (placement->titlebar_pos == 2) { + placement->titlebar_pos = 1; + } else if (placement->mainwin_pos == 2) { + placement->mainwin_pos = 1; + } else if (placement->inputwin_pos == 2) { + placement->inputwin_pos = 1; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->statusbar_pos == 2) { + placement->statusbar_pos = 3; + if (placement->titlebar_pos == 3) { + placement->titlebar_pos = 2; + } else if (placement->mainwin_pos == 3) { + placement->mainwin_pos = 2; + } else if (placement->inputwin_pos == 3) { + placement->inputwin_pos = 2; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->statusbar_pos == 3) { + placement->statusbar_pos = 4; + if (placement->titlebar_pos == 4) { + placement->titlebar_pos = 3; + } else if (placement->mainwin_pos == 4) { + placement->mainwin_pos = 3; + } else if (placement->inputwin_pos == 4) { + placement->inputwin_pos = 3; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + + prefs_free_win_placement(placement); + return FALSE; +} + + +gboolean +prefs_inputwin_pos_down(void) +{ + ProfWinPlacement *placement = prefs_get_win_placement(); + if (placement->inputwin_pos == 1) { + placement->inputwin_pos = 2; + if (placement->titlebar_pos == 2) { + placement->titlebar_pos = 1; + } else if (placement->mainwin_pos == 2) { + placement->mainwin_pos = 1; + } else if (placement->inputwin_pos == 2) { + placement->inputwin_pos = 1; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->inputwin_pos == 2) { + placement->inputwin_pos = 3; + if (placement->titlebar_pos == 3) { + placement->titlebar_pos = 2; + } else if (placement->mainwin_pos == 3) { + placement->mainwin_pos = 2; + } else if (placement->statusbar_pos == 3) { + placement->statusbar_pos = 2; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + if (placement->inputwin_pos == 3) { + placement->inputwin_pos = 4; + if (placement->titlebar_pos == 4) { + placement->titlebar_pos = 3; + } else if (placement->mainwin_pos == 4) { + placement->mainwin_pos = 3; + } else if (placement->statusbar_pos == 4) { + placement->statusbar_pos = 3; + } + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); + return TRUE; + } + + prefs_free_win_placement(placement); + return FALSE; +} + gboolean prefs_add_alias(const char *const name, const char *const value) { @@ -1224,7 +1686,6 @@ _get_group(preference_t pref) case PREF_RESOURCE_MESSAGE: case PREF_ENC_WARN: case PREF_INPBLOCK_DYNAMIC: - case PREF_INPUTWIN: case PREF_TLS_SHOW: case PREF_CONSOLE_MUC: case PREF_CONSOLE_PRIVATE: @@ -1457,8 +1918,6 @@ _get_key(preference_t pref) return "resource.message"; case PREF_INPBLOCK_DYNAMIC: return "inpblock.dynamic"; - case PREF_INPUTWIN: - return "inputwin.position"; case PREF_ENC_WARN: return "enc.warn"; case PREF_PGP_LOG: @@ -1587,8 +2046,6 @@ _get_default_string(preference_t pref) case PREF_CONSOLE_PRIVATE: case PREF_CONSOLE_CHAT: return "all"; - case PREF_INPUTWIN: - return "bottom"; default: return NULL; } diff --git a/src/config/preferences.h b/src/config/preferences.h index ee89bd90..e0ac7442 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -132,7 +132,6 @@ typedef enum { PREF_RESOURCE_TITLE, PREF_RESOURCE_MESSAGE, PREF_INPBLOCK_DYNAMIC, - PREF_INPUTWIN, PREF_ENC_WARN, PREF_PGP_LOG, PREF_TLS_CERTPATH, @@ -149,6 +148,13 @@ typedef struct prof_alias_t { gchar *value; } ProfAlias; +typedef struct prof_winplacement_t { + int titlebar_pos; + int mainwin_pos; + int statusbar_pos; + int inputwin_pos; +} ProfWinPlacement; + void prefs_load(void); void prefs_close(void); @@ -240,6 +246,20 @@ gboolean prefs_add_room_notify_trigger(const char * const text); gboolean prefs_remove_room_notify_trigger(const char * const text); GList* prefs_get_room_notify_triggers(void); +ProfWinPlacement* prefs_get_win_placement(void); +void prefs_free_win_placement(ProfWinPlacement *placement); + +gboolean prefs_titlebar_pos_up(void); +gboolean prefs_titlebar_pos_down(void); +gboolean prefs_mainwin_pos_up(void); +gboolean prefs_mainwin_pos_down(void); +gboolean prefs_statusbar_pos_up(void); +gboolean prefs_statusbar_pos_down(void); +gboolean prefs_inputwin_pos_up(void); +gboolean prefs_inputwin_pos_down(void); +ProfWinPlacement* prefs_create_profwin_placement(int titlebar, int mainwin, int statusbar, int inputwin); +void prefs_save_win_placement(ProfWinPlacement *placement); + gboolean prefs_get_boolean(preference_t pref); void prefs_set_boolean(preference_t pref, gboolean value); char* prefs_get_string(preference_t pref); diff --git a/src/config/theme.c b/src/config/theme.c index d4494e58..cee95883 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -429,7 +429,6 @@ _load_preferences(void) _set_string_preference("roster.rooms.by", PREF_ROSTER_ROOMS_BY); _set_string_preference("roster.private", PREF_ROSTER_PRIVATE); _set_string_preference("roster.count", PREF_ROSTER_COUNT); - _set_string_preference("inputwin.position", PREF_INPUTWIN); if (g_key_file_has_key(theme, "ui", "occupants.size", NULL)) { gint occupants_size = g_key_file_get_integer(theme, "ui", "occupants.size", NULL); @@ -531,6 +530,14 @@ _load_preferences(void) g_free(ch); } } + + int titlebar_pos = g_key_file_get_integer(theme, "ui", "titlebar.position", NULL); + int mainwin_pos = g_key_file_get_integer(theme, "ui", "mainwin.position", NULL); + int statusbar_pos = g_key_file_get_integer(theme, "ui", "statusbar.position", NULL); + int inputwin_pos = g_key_file_get_integer(theme, "ui", "inputwin.position", NULL); + ProfWinPlacement *placement = prefs_create_profwin_placement(titlebar_pos, mainwin_pos, statusbar_pos, inputwin_pos); + prefs_save_win_placement(placement); + prefs_free_win_placement(placement); } void |