diff options
Diffstat (limited to 'src/config/preferences.c')
-rw-r--r-- | src/config/preferences.c | 471 |
1 files changed, 464 insertions, 7 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; } |