1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-09 21:30:42 +00:00
profanity/src/config/theme.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1071 lines
38 KiB
C
Raw Normal View History

/*
* theme.c
2019-11-13 11:11:05 +00:00
* vim: expandtab:ts=4:sts=4:sw=4
*
2019-01-22 10:31:45 +00:00
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
2023-01-10 09:37:25 +00:00
* Copyright (C) 2019 - 2023 Michael Vetter <jubalh@iodoru.org>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2016-07-24 00:14:49 +00:00
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
*/
2016-03-31 20:05:02 +00:00
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
2016-07-24 14:43:51 +00:00
2016-03-31 20:05:02 +00:00
#ifdef HAVE_NCURSESW_NCURSES_H
2013-01-02 20:27:37 +00:00
#include <ncursesw/ncurses.h>
2016-03-31 20:05:02 +00:00
#elif HAVE_NCURSES_H
#include <ncurses.h>
#elif HAVE_CURSES_H
#include <curses.h>
#endif
#include "common.h"
#include "log.h"
2016-07-24 15:22:15 +00:00
#include "config/files.h"
#include "config/theme.h"
#include "config/preferences.h"
#include "config/color.h"
2020-07-07 12:18:57 +00:00
static GString* theme_loc;
static GKeyFile* theme;
static GHashTable* bold_items;
static GHashTable* defaults;
2014-11-19 23:58:55 +00:00
static void _load_preferences(void);
2020-07-07 12:18:57 +00:00
static void _theme_list_dir(const gchar* const dir, GSList** result);
static GString* _theme_find(const char* const theme_name);
static gboolean _theme_load_file(const char* const theme_name);
void
2020-07-07 12:18:57 +00:00
theme_init(const char* const theme_name)
{
if (!_theme_load_file(theme_name)) {
log_error("Loading theme %s failed.", theme_name);
if (!_theme_load_file("default")) {
log_error("Theme initialisation failed.");
}
2012-12-09 00:21:33 +00:00
}
2016-01-10 03:11:05 +00:00
2016-02-14 01:37:13 +00:00
defaults = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
2016-01-21 23:59:45 +00:00
// Set default colors
2020-07-07 12:18:57 +00:00
g_hash_table_insert(defaults, strdup("main.text"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.text.history"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.text.me"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.text.them"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.splash"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("main.help.header"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.trackbar"), strdup("default"));
2020-07-07 12:18:57 +00:00
g_hash_table_insert(defaults, strdup("error"), strdup("red"));
g_hash_table_insert(defaults, strdup("incoming"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("mention"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("trigger"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("input.text"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.time"), strdup("default"));
g_hash_table_insert(defaults, strdup("titlebar.text"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.brackets"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("titlebar.unencrypted"), strdup("red"));
g_hash_table_insert(defaults, strdup("titlebar.encrypted"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.untrusted"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("titlebar.trusted"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.online"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.offline"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.away"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.chat"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.dnd"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.xa"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.scrolled"), strdup("default"));
g_hash_table_insert(defaults, strdup("statusbar.text"), strdup("white"));
g_hash_table_insert(defaults, strdup("statusbar.brackets"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("statusbar.active"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("statusbar.current"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("statusbar.new"), strdup("white"));
g_hash_table_insert(defaults, strdup("statusbar.time"), strdup("white"));
g_hash_table_insert(defaults, strdup("me"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("them"), strdup("green"));
g_hash_table_insert(defaults, strdup("receipt.sent"), strdup("red"));
g_hash_table_insert(defaults, strdup("roominfo"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roommention"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roommention.term"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roomtrigger"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roomtrigger.term"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("online"), strdup("green"));
g_hash_table_insert(defaults, strdup("offline"), strdup("red"));
g_hash_table_insert(defaults, strdup("away"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("chat"), strdup("green"));
g_hash_table_insert(defaults, strdup("dnd"), strdup("red"));
g_hash_table_insert(defaults, strdup("xa"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("typing"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("gone"), strdup("red"));
g_hash_table_insert(defaults, strdup("subscribed"), strdup("green"));
g_hash_table_insert(defaults, strdup("unsubscribed"), strdup("red"));
g_hash_table_insert(defaults, strdup("otr.started.trusted"), strdup("green"));
g_hash_table_insert(defaults, strdup("otr.started.untrusted"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("otr.ended"), strdup("red"));
g_hash_table_insert(defaults, strdup("otr.trusted"), strdup("green"));
g_hash_table_insert(defaults, strdup("otr.untrusted"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roster.header"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roster.online"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.offline"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.chat"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.away"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.dnd"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.xa"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.online.active"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.offline.active"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.chat.active"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.away.active"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.dnd.active"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.xa.active"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.online.unread"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.offline.unread"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.chat.unread"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.away.unread"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.dnd.unread"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.xa.unread"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.room"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.room.unread"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.room.trigger"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.room.mention"), strdup("green"));
g_hash_table_insert(defaults, strdup("occupants.header"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("untrusted"), strdup("red"));
g_hash_table_insert(defaults, strdup("cmd.wins.unread"), strdup("default"));
//_load_preferences();
2012-12-09 00:21:33 +00:00
}
2016-01-22 01:06:28 +00:00
gboolean
2020-07-07 12:18:57 +00:00
theme_exists(const char* const theme_name)
2016-01-22 01:06:28 +00:00
{
if (g_strcmp0(theme_name, "default") == 0) {
return TRUE;
}
2020-07-07 12:18:57 +00:00
GString* new_theme_file = _theme_find(theme_name);
2016-01-22 01:06:28 +00:00
if (new_theme_file == NULL) {
return FALSE;
}
g_string_free(new_theme_file, TRUE);
return TRUE;
}
gboolean
2020-07-07 12:18:57 +00:00
theme_load(const char* const theme_name, gboolean load_theme_prefs)
{
if (!theme_exists(theme_name))
return FALSE;
color_pair_cache_reset();
if (_theme_load_file(theme_name)) {
if (load_theme_prefs) {
_load_preferences();
}
return TRUE;
} else {
return FALSE;
}
}
static gboolean
2020-07-07 12:18:57 +00:00
_theme_load_file(const char* const theme_name)
{
// use default theme
if (theme_name == NULL || strcmp(theme_name, "default") == 0) {
2015-05-04 21:33:55 +00:00
if (theme) {
g_key_file_free(theme);
}
theme = g_key_file_new();
2020-07-07 12:18:57 +00:00
// load theme from file
} else {
2020-07-07 12:18:57 +00:00
GString* new_theme_file = _theme_find(theme_name);
if (new_theme_file == NULL) {
log_info("Theme does not exist \"%s\"", theme_name);
return FALSE;
}
2015-05-04 21:33:55 +00:00
if (theme_loc) {
g_string_free(theme_loc, TRUE);
}
theme_loc = new_theme_file;
log_info("Loading theme \"%s\"", theme_name);
2015-05-04 21:33:55 +00:00
if (theme) {
g_key_file_free(theme);
}
theme = g_key_file_new();
g_key_file_load_from_file(theme, theme_loc->str, G_KEY_FILE_KEEP_COMMENTS,
2020-07-07 12:18:57 +00:00
NULL);
}
return TRUE;
}
2015-10-25 22:23:38 +00:00
GSList*
theme_list(void)
{
2020-07-07 12:18:57 +00:00
GSList* result = NULL;
auto_gchar gchar* themes_dir = files_get_config_path(DIR_THEMES);
2015-02-09 21:21:22 +00:00
_theme_list_dir(themes_dir, &result);
#ifdef THEMES_PATH
_theme_list_dir(THEMES_PATH, &result);
#endif
return result;
}
void
theme_close(void)
{
2015-05-04 21:33:55 +00:00
if (theme) {
g_key_file_free(theme);
2015-05-17 21:05:43 +00:00
theme = NULL;
}
2015-05-04 21:33:55 +00:00
if (theme_loc) {
g_string_free(theme_loc, TRUE);
2015-05-17 21:05:43 +00:00
theme_loc = NULL;
}
2014-11-16 21:56:19 +00:00
if (bold_items) {
g_hash_table_destroy(bold_items);
2015-05-17 21:05:43 +00:00
bold_items = NULL;
2014-11-16 21:56:19 +00:00
}
2016-01-21 23:59:45 +00:00
if (defaults) {
g_hash_table_destroy(defaults);
defaults = NULL;
}
}
2016-01-10 03:11:05 +00:00
void
theme_init_colours(void)
{
2016-01-10 03:11:05 +00:00
assume_default_colors(-1, -1);
color_pair_cache_reset();
}
2014-11-19 23:58:55 +00:00
static void
2020-07-07 12:18:57 +00:00
_set_string_preference(char* prefstr, preference_t pref)
2014-11-19 23:58:55 +00:00
{
if (g_key_file_has_key(theme, "ui", prefstr, NULL)) {
auto_gchar gchar* val = g_key_file_get_string(theme, "ui", prefstr, NULL);
2014-11-19 23:58:55 +00:00
prefs_set_string(pref, val);
}
}
static void
2020-07-07 12:18:57 +00:00
_set_boolean_preference(char* prefstr, preference_t pref)
2014-11-19 23:58:55 +00:00
{
if (g_key_file_has_key(theme, "ui", prefstr, NULL)) {
gboolean val = g_key_file_get_boolean(theme, "ui", prefstr, NULL);
prefs_set_boolean(pref, val);
}
}
static void
_load_preferences(void)
{
// load booleans from theme and set them to prefs
2014-11-19 23:58:55 +00:00
_set_boolean_preference("beep", PREF_BEEP);
_set_boolean_preference("flash", PREF_FLASH);
_set_boolean_preference("splash", PREF_SPLASH);
2014-11-19 23:58:55 +00:00
_set_boolean_preference("wrap", PREF_WRAP);
_set_boolean_preference("resource.title", PREF_RESOURCE_TITLE);
_set_boolean_preference("resource.message", PREF_RESOURCE_MESSAGE);
2014-11-19 23:58:55 +00:00
_set_boolean_preference("occupants", PREF_OCCUPANTS);
_set_boolean_preference("occupants.jid", PREF_OCCUPANTS_JID);
2021-03-05 12:29:36 +00:00
_set_boolean_preference("occupants.offline", PREF_OCCUPANTS_OFFLINE);
_set_boolean_preference("occupants.wrap", PREF_OCCUPANTS_WRAP);
2014-11-19 23:58:55 +00:00
_set_boolean_preference("roster", PREF_ROSTER);
_set_boolean_preference("roster.offline", PREF_ROSTER_OFFLINE);
_set_boolean_preference("roster.resource", PREF_ROSTER_RESOURCE);
2015-11-22 17:45:38 +00:00
_set_boolean_preference("roster.resource.join", PREF_ROSTER_RESOURCE_JOIN);
_set_boolean_preference("roster.presence", PREF_ROSTER_PRESENCE);
_set_boolean_preference("roster.status", PREF_ROSTER_STATUS);
_set_boolean_preference("roster.empty", PREF_ROSTER_EMPTY);
2015-11-22 01:39:20 +00:00
_set_boolean_preference("roster.wrap", PREF_ROSTER_WRAP);
2016-01-27 23:02:28 +00:00
_set_boolean_preference("roster.count.zero", PREF_ROSTER_COUNT_ZERO);
_set_boolean_preference("roster.priority", PREF_ROSTER_PRIORITY);
2016-01-20 01:48:41 +00:00
_set_boolean_preference("roster.contacts", PREF_ROSTER_CONTACTS);
2016-02-07 00:49:48 +00:00
_set_boolean_preference("roster.unsubscribed", PREF_ROSTER_UNSUBSCRIBED);
2016-01-02 01:29:12 +00:00
_set_boolean_preference("roster.rooms", PREF_ROSTER_ROOMS);
2016-01-24 02:28:22 +00:00
_set_boolean_preference("privileges", PREF_MUC_PRIVILEGES);
_set_boolean_preference("presence", PREF_PRESENCE);
_set_boolean_preference("intype", PREF_INTYPE);
_set_boolean_preference("enc.warn", PREF_ENC_WARN);
_set_boolean_preference("tls.show", PREF_TLS_SHOW);
2018-03-10 23:22:58 +00:00
_set_boolean_preference("statusbar.show.name", PREF_STATUSBAR_SHOW_NAME);
_set_boolean_preference("statusbar.show.number", PREF_STATUSBAR_SHOW_NUMBER);
2016-01-24 02:28:22 +00:00
// load strings from theme and set them to prefs
2016-01-24 02:28:22 +00:00
_set_string_preference("time.console", PREF_TIME_CONSOLE);
_set_string_preference("time.chat", PREF_TIME_CHAT);
_set_string_preference("time.muc", PREF_TIME_MUC);
_set_string_preference("time.config", PREF_TIME_CONFIG);
2016-01-24 02:28:22 +00:00
_set_string_preference("time.private", PREF_TIME_PRIVATE);
_set_string_preference("time.xmlconsole", PREF_TIME_XMLCONSOLE);
_set_string_preference("time.statusbar", PREF_TIME_STATUSBAR);
_set_string_preference("time.lastactivity", PREF_TIME_LASTACTIVITY);
_set_string_preference("statuses.console", PREF_STATUSES_CONSOLE);
_set_string_preference("statuses.chat", PREF_STATUSES_CHAT);
_set_string_preference("statuses.muc", PREF_STATUSES_MUC);
_set_string_preference("console.muc", PREF_CONSOLE_MUC);
2016-02-03 23:39:20 +00:00
_set_string_preference("console.private", PREF_CONSOLE_PRIVATE);
2016-02-03 23:02:52 +00:00
_set_string_preference("console.chat", PREF_CONSOLE_CHAT);
2016-01-24 02:28:22 +00:00
_set_string_preference("roster.by", PREF_ROSTER_BY);
_set_string_preference("roster.order", PREF_ROSTER_ORDER);
_set_string_preference("roster.unread", PREF_ROSTER_UNREAD);
2016-01-09 22:21:09 +00:00
_set_string_preference("roster.rooms.order", PREF_ROSTER_ROOMS_ORDER);
_set_string_preference("roster.rooms.unread", PREF_ROSTER_ROOMS_UNREAD);
_set_string_preference("roster.rooms.pos", PREF_ROSTER_ROOMS_POS);
_set_string_preference("roster.rooms.by", PREF_ROSTER_ROOMS_BY);
2016-01-24 01:04:21 +00:00
_set_string_preference("roster.private", PREF_ROSTER_PRIVATE);
2016-01-27 23:02:28 +00:00
_set_string_preference("roster.count", PREF_ROSTER_COUNT);
Improve MUC title behaviour for roster, statusbar, and titlebar ## Abstract Continuation of https://github.com/profanity-im/profanity/pull/1881 Give all MUC title commands a consistent command structure and appearance. - `/roster room use name|jid` and `/roster room show|hide server` are now `/roster room title bookmark|jid|localpart|name` - `/statusbar room room|jid` is now `/statusbar room title bookmark|jid|localpart|name` - `/statusbar show|hide jid` and `/statusbar show|hide name` are now `/titlebar room title bookmark|jid|localpart|name` Fix both bugs mentioned in https://github.com/profanity-im/profanity/pull/1881 ### src/ui/mucwin.c:mucwin_generate_title Called by each command to generate a properly formatted title. It checks for "name" first because "name" is the default preference for each command. The last if-statement sets the title to "localpart" for special cases when the title should be "localpart" instead of the user-defined preference. ## Testing ### Preparation Remove preferences that will interfere with testing. ``` sed -i "/roster.rooms.title=/d" profrc sed -i "/statusbar.room.title=/d" profrc sed -i "/titlebar.muc.title=/d" profrc sed -i "/roster.rooms.use.name=/d" profrc sed -i "/roster.rooms.server=/d" profrc sed -i "/statusbar.room=/d" profrc sed -i "/titlebar.muc.title.jid=/d" profrc sed -i "/titlebar.muc.title.name=/d" profrc sed -i "/roster.rooms.by=/d" profrc ``` ### Command Definitions | Test | Window | | :--- | :--- | | `/help roster` | - /roster room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the roster title for MUCs.<br>- *No /roster show\|hide server*<br>- *No /roster room use jid\|name* | | `/help statusbar` | - /statusbar room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the title for MUC tabs.<br>- *No /statusbar room jid\|room* | | `/help titlebar` | - /titlebar room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the MUC window title.<br>- *No /titlebar show\|hide jid\|name* | ### Autocomplete | Test | Command line | | :--- | :--- | | `/roster room <TAB>` | Autocompletes `title` | | `/roster room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` | | `/statusbar room <TAB>` | Autocompletes `title` | | `/statusbar room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` | | `/titlebar room <TAB>` | Autocompletes `title` | | `/titlebar room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` | | `/roster room <TAB>` | Does not autocomplete `use`, `show`, or `hide` | | `/roster room use <TAB>` | Does not autocomplete `name` | | `/roster room show <TAB>` | Does not autocomplete `server` | | `/roster room hide <TAB>` | Does not autocomplete `server` | | `/statusbar room <TAB>` | Does not autocomplete `jid` or `room` | | `/titlebar show <TAB>` | Does not autocomplete `jid` or `name` | | `/titlebar hide <TAB>` | Does not autocomplete `jid` or `name` | ### Set Preferences | Test | Window | profrc | | :--- | :--- | :--- | | `/roster room title bookmark` | Roster MUCs will display 'bookmark' as their title. | roster.rooms.title=bookmark | | `/roster room title jid` | Roster MUCs will display 'jid' as their title. | roster.rooms.title=jid | | `/roster room title localpart` | Roster MUCs will display 'localpart' as their title. | roster.rooms.title=localpart | | `/roster room title name` | Roster MUCs will display 'name' as their title. | roster.rooms.title=name | | `/roster room title invalid` | Invalid usage, see '/help roster' for details. | | | `/statusbar room title bookmark` | Displaying 'bookmark' as the title for MUC tabs. | statusbar.room.title=bookmark | | `/statusbar room title jid` | Displaying 'jid' as the title for MUC tabs. | statusbar.room.title=jid | | `/statusbar room title localpart` | Displaying 'localpart' as the title for MUC tabs. | statusbar.room.title=localpart | | `/statusbar room title name` | Displaying 'name' as the title for MUC tabs. | statusbar.room.title=name | | `/statusbar room title invalid` | Invalid usage, see '/help statusbar' for details. | | | `/titlebar room title bookmark` | MUC windows will display 'bookmark' as the window title. | titlebar.muc.title=bookmark | | `/titlebar room title jid` | MUC windows will display 'jid' as the window title. | titlebar.muc.title=jid | | `/titlebar room title localpart` | MUC windows will display 'localpart' as the window title. | titlebar.muc.title=localpart | | `/titlebar room title name` | MUC windows will display 'name' as the window title. | titlebar.muc.title=name | | `/titlebar room title invalid` | Invalid usage, see '/help titlebar' for details. | | | `/roster room use jid` | Invalid usage, see '/help roster' for details. | | | `/roster room use name` | Invalid usage, see '/help roster' for details. | | | `/roster room show server` | Invalid usage, see '/help roster' for details. | | | `/roster room hide server` | Invalid usage, see '/help roster' for details. | | | `/statusbar room jid` | Invalid usage, see '/help statusbar' for details. | | | `/statusbar room room` | Invalid usage, see '/help statusbar' for details. | | | `/titlebar show jid` | Invalid usage, see '/help titlebar' for details. | | | `/titlebar hide jid` | Invalid usage, see '/help titlebar' for details. | | | `/titlebar show name` | Invalid usage, see '/help titlebar' for details. | | | `/titlebar hide name` | Invalid usage, see '/help titlebar' for details. | | ### Display Set Preferences | Test | Window | | :--- | :--- | | /prefs ui | - Roster rooms title (/roster) : name<br>- Room tab display (/statusbar) : name<br>- MUC window title (/titlebar) : name | ### Test MUC Window #### Test: without *name* preference, without *room name* field ``` /join muc@dmn.im /room config /field1 "" /form submit /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | #### Test: with *name* preference, without *room name* field ``` /roster room title name /statusbar room title name /titlebar room title name /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | #### Test: without *name* preference, with *room name* field ``` sed -i "/roster.rooms.title=/d" profrc sed -i "/statusbar.room.title=/d" profrc sed -i "/titlebar.muc.title=/d" profrc /join muc@dmn.im /room config /field1 "my_room" /form submit /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | my_room | my_room | my_room | | `/room config` | | my_room conf | my_room config | | `/field2 edit` | | | my_room config * | | `/msg tst` | tst | my_room/tst | my_room/tst | | `/roster room by service` | my_room | | | #### Test: with *name* preference, with *room name* field ``` /quit /roster room title name /statusbar room title name /titlebar room title name /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | my_room | my_room | my_room | | `/room config` | | my_room conf | my_room config | | `/field2 edit` | | | my_room config * | | `/msg tst` | tst | my_room/tst | my_room/tst | | `/roster room by service` | my_room | | | #### Test: with *localpart* preference ``` /quit /roster room title localpart /statusbar room title localpart /titlebar room title localpart /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc | muc | muc | | `/room config` | | muc conf | muc config | | `/field2 edit` | | | muc config * | | `/msg tst` | tst | muc/tst | muc/tst | | `/roster room by service` | muc | | | #### Test: with *bookmark* preference, without *bookmark name* ``` /quit /roster room title bookmark /statusbar room title bookmark /titlebar room title bookmark /save /quit /bookmark add muc@dmn.im ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/bookmark join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | #### Test: with *bookmark* preference, with *bookmark name* ``` /quit /bookmark remove muc@dmn.im /bookmark add muc@dmn.im name "my_bookmark" ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/bookmark join muc@dmn.im` | my_bookmark | my_bookmark | my_bookmark | | `/room config` | | my_bookmark conf | my_bookmark config | | `/field2 edit` | | | my_bookmark config * | | `/msg tst` | tst | my_bookmark/tst | my_bookmark/tst | | `/roster room by service` | my_bookmark | | | #### Test: with *jid* preference ``` /quit /roster room title jid /statusbar room title jid /titlebar room title jid /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | ### Test Contact Chat Window Title #### Test: without contact nick ``` /roster add tst@dmn.im ``` | Test | Titlebar | | :--- | :--- | | `/msg tst@dmn.im` | tst<span/>@dmn.im | #### Test: with contact nick ``` /roster add tst@dmn.im my_tst ``` | Test | Titlebar | | :--- | :--- | | `/msg my_tst` | my_tst <tst<span/>@ike.snikket.chat> | ### Test Preference Upgrade #### Test /roster | Test | profrc | | :--- | :--- | | `sed -i '/\[ui\]/a\roster.rooms.use.name=name' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\roster.rooms.use.name=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\roster.rooms.server=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc` | Original key removed.<br>roster.rooms.title=jid | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=false' profrc` | Original keys removed.<br>roster.rooms.title=localpart | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=true' profrc` | Original keys removed.<br>roster.rooms.title=jid | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=' profrc` | Original keys removed.<br>roster.rooms.title=jid | | `sed -i '/\[ui\]/a\statusbar.room=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\statusbar.room=room' profrc` | Original key removed.<br>statusbar.room.title=localpart | | `sed -i '/\[ui\]/a\statusbar.room=jid' profrc` | Original key removed.<br>statusbar.room.title=jid | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.name=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=false' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.name=false' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=false' profrc` | Original key removed.<br>titlebar.muc.title=jid | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=false' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original keys removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original keys removed. | ### Test Valgrind No memory leaks detected relating to these changes.
2023-10-06 00:16:04 +00:00
_set_string_preference("roster.rooms.title", PREF_ROSTER_ROOMS_TITLE);
2018-03-10 23:22:58 +00:00
_set_string_preference("statusbar.self", PREF_STATUSBAR_SELF);
_set_string_preference("statusbar.chat", PREF_STATUSBAR_CHAT);
Improve MUC title behaviour for roster, statusbar, and titlebar ## Abstract Continuation of https://github.com/profanity-im/profanity/pull/1881 Give all MUC title commands a consistent command structure and appearance. - `/roster room use name|jid` and `/roster room show|hide server` are now `/roster room title bookmark|jid|localpart|name` - `/statusbar room room|jid` is now `/statusbar room title bookmark|jid|localpart|name` - `/statusbar show|hide jid` and `/statusbar show|hide name` are now `/titlebar room title bookmark|jid|localpart|name` Fix both bugs mentioned in https://github.com/profanity-im/profanity/pull/1881 ### src/ui/mucwin.c:mucwin_generate_title Called by each command to generate a properly formatted title. It checks for "name" first because "name" is the default preference for each command. The last if-statement sets the title to "localpart" for special cases when the title should be "localpart" instead of the user-defined preference. ## Testing ### Preparation Remove preferences that will interfere with testing. ``` sed -i "/roster.rooms.title=/d" profrc sed -i "/statusbar.room.title=/d" profrc sed -i "/titlebar.muc.title=/d" profrc sed -i "/roster.rooms.use.name=/d" profrc sed -i "/roster.rooms.server=/d" profrc sed -i "/statusbar.room=/d" profrc sed -i "/titlebar.muc.title.jid=/d" profrc sed -i "/titlebar.muc.title.name=/d" profrc sed -i "/roster.rooms.by=/d" profrc ``` ### Command Definitions | Test | Window | | :--- | :--- | | `/help roster` | - /roster room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the roster title for MUCs.<br>- *No /roster show\|hide server*<br>- *No /roster room use jid\|name* | | `/help statusbar` | - /statusbar room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the title for MUC tabs.<br>- *No /statusbar room jid\|room* | | `/help titlebar` | - /titlebar room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the MUC window title.<br>- *No /titlebar show\|hide jid\|name* | ### Autocomplete | Test | Command line | | :--- | :--- | | `/roster room <TAB>` | Autocompletes `title` | | `/roster room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` | | `/statusbar room <TAB>` | Autocompletes `title` | | `/statusbar room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` | | `/titlebar room <TAB>` | Autocompletes `title` | | `/titlebar room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` | | `/roster room <TAB>` | Does not autocomplete `use`, `show`, or `hide` | | `/roster room use <TAB>` | Does not autocomplete `name` | | `/roster room show <TAB>` | Does not autocomplete `server` | | `/roster room hide <TAB>` | Does not autocomplete `server` | | `/statusbar room <TAB>` | Does not autocomplete `jid` or `room` | | `/titlebar show <TAB>` | Does not autocomplete `jid` or `name` | | `/titlebar hide <TAB>` | Does not autocomplete `jid` or `name` | ### Set Preferences | Test | Window | profrc | | :--- | :--- | :--- | | `/roster room title bookmark` | Roster MUCs will display 'bookmark' as their title. | roster.rooms.title=bookmark | | `/roster room title jid` | Roster MUCs will display 'jid' as their title. | roster.rooms.title=jid | | `/roster room title localpart` | Roster MUCs will display 'localpart' as their title. | roster.rooms.title=localpart | | `/roster room title name` | Roster MUCs will display 'name' as their title. | roster.rooms.title=name | | `/roster room title invalid` | Invalid usage, see '/help roster' for details. | | | `/statusbar room title bookmark` | Displaying 'bookmark' as the title for MUC tabs. | statusbar.room.title=bookmark | | `/statusbar room title jid` | Displaying 'jid' as the title for MUC tabs. | statusbar.room.title=jid | | `/statusbar room title localpart` | Displaying 'localpart' as the title for MUC tabs. | statusbar.room.title=localpart | | `/statusbar room title name` | Displaying 'name' as the title for MUC tabs. | statusbar.room.title=name | | `/statusbar room title invalid` | Invalid usage, see '/help statusbar' for details. | | | `/titlebar room title bookmark` | MUC windows will display 'bookmark' as the window title. | titlebar.muc.title=bookmark | | `/titlebar room title jid` | MUC windows will display 'jid' as the window title. | titlebar.muc.title=jid | | `/titlebar room title localpart` | MUC windows will display 'localpart' as the window title. | titlebar.muc.title=localpart | | `/titlebar room title name` | MUC windows will display 'name' as the window title. | titlebar.muc.title=name | | `/titlebar room title invalid` | Invalid usage, see '/help titlebar' for details. | | | `/roster room use jid` | Invalid usage, see '/help roster' for details. | | | `/roster room use name` | Invalid usage, see '/help roster' for details. | | | `/roster room show server` | Invalid usage, see '/help roster' for details. | | | `/roster room hide server` | Invalid usage, see '/help roster' for details. | | | `/statusbar room jid` | Invalid usage, see '/help statusbar' for details. | | | `/statusbar room room` | Invalid usage, see '/help statusbar' for details. | | | `/titlebar show jid` | Invalid usage, see '/help titlebar' for details. | | | `/titlebar hide jid` | Invalid usage, see '/help titlebar' for details. | | | `/titlebar show name` | Invalid usage, see '/help titlebar' for details. | | | `/titlebar hide name` | Invalid usage, see '/help titlebar' for details. | | ### Display Set Preferences | Test | Window | | :--- | :--- | | /prefs ui | - Roster rooms title (/roster) : name<br>- Room tab display (/statusbar) : name<br>- MUC window title (/titlebar) : name | ### Test MUC Window #### Test: without *name* preference, without *room name* field ``` /join muc@dmn.im /room config /field1 "" /form submit /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | #### Test: with *name* preference, without *room name* field ``` /roster room title name /statusbar room title name /titlebar room title name /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | #### Test: without *name* preference, with *room name* field ``` sed -i "/roster.rooms.title=/d" profrc sed -i "/statusbar.room.title=/d" profrc sed -i "/titlebar.muc.title=/d" profrc /join muc@dmn.im /room config /field1 "my_room" /form submit /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | my_room | my_room | my_room | | `/room config` | | my_room conf | my_room config | | `/field2 edit` | | | my_room config * | | `/msg tst` | tst | my_room/tst | my_room/tst | | `/roster room by service` | my_room | | | #### Test: with *name* preference, with *room name* field ``` /quit /roster room title name /statusbar room title name /titlebar room title name /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | my_room | my_room | my_room | | `/room config` | | my_room conf | my_room config | | `/field2 edit` | | | my_room config * | | `/msg tst` | tst | my_room/tst | my_room/tst | | `/roster room by service` | my_room | | | #### Test: with *localpart* preference ``` /quit /roster room title localpart /statusbar room title localpart /titlebar room title localpart /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc | muc | muc | | `/room config` | | muc conf | muc config | | `/field2 edit` | | | muc config * | | `/msg tst` | tst | muc/tst | muc/tst | | `/roster room by service` | muc | | | #### Test: with *bookmark* preference, without *bookmark name* ``` /quit /roster room title bookmark /statusbar room title bookmark /titlebar room title bookmark /save /quit /bookmark add muc@dmn.im ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/bookmark join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | #### Test: with *bookmark* preference, with *bookmark name* ``` /quit /bookmark remove muc@dmn.im /bookmark add muc@dmn.im name "my_bookmark" ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/bookmark join muc@dmn.im` | my_bookmark | my_bookmark | my_bookmark | | `/room config` | | my_bookmark conf | my_bookmark config | | `/field2 edit` | | | my_bookmark config * | | `/msg tst` | tst | my_bookmark/tst | my_bookmark/tst | | `/roster room by service` | my_bookmark | | | #### Test: with *jid* preference ``` /quit /roster room title jid /statusbar room title jid /titlebar room title jid /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | ### Test Contact Chat Window Title #### Test: without contact nick ``` /roster add tst@dmn.im ``` | Test | Titlebar | | :--- | :--- | | `/msg tst@dmn.im` | tst<span/>@dmn.im | #### Test: with contact nick ``` /roster add tst@dmn.im my_tst ``` | Test | Titlebar | | :--- | :--- | | `/msg my_tst` | my_tst <tst<span/>@ike.snikket.chat> | ### Test Preference Upgrade #### Test /roster | Test | profrc | | :--- | :--- | | `sed -i '/\[ui\]/a\roster.rooms.use.name=name' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\roster.rooms.use.name=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\roster.rooms.server=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc` | Original key removed.<br>roster.rooms.title=jid | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=false' profrc` | Original keys removed.<br>roster.rooms.title=localpart | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=true' profrc` | Original keys removed.<br>roster.rooms.title=jid | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=' profrc` | Original keys removed.<br>roster.rooms.title=jid | | `sed -i '/\[ui\]/a\statusbar.room=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\statusbar.room=room' profrc` | Original key removed.<br>statusbar.room.title=localpart | | `sed -i '/\[ui\]/a\statusbar.room=jid' profrc` | Original key removed.<br>statusbar.room.title=jid | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.name=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=false' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.name=false' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=false' profrc` | Original key removed.<br>titlebar.muc.title=jid | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=false' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original keys removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original keys removed. | ### Test Valgrind No memory leaks detected relating to these changes.
2023-10-06 00:16:04 +00:00
_set_string_preference("statusbar.room.title", PREF_STATUSBAR_ROOM_TITLE);
_set_string_preference("titlebar.muc.title", PREF_TITLEBAR_MUC_TITLE);
2018-03-10 23:22:58 +00:00
// load ints from theme and set them to prefs
// with custom set functions
2018-03-10 23:22:58 +00:00
if (g_key_file_has_key(theme, "ui", "statusbar.tabs", NULL)) {
gint tabs_size = g_key_file_get_integer(theme, "ui", "statusbar.tabs", NULL);
prefs_set_statusbartabs(tabs_size);
}
2016-01-24 02:28:22 +00:00
2018-03-11 01:18:46 +00:00
if (g_key_file_has_key(theme, "ui", "statusbar.tablen", NULL)) {
gint tab_len = g_key_file_get_integer(theme, "ui", "statusbar.tablen", NULL);
2018-03-11 01:21:36 +00:00
prefs_set_statusbartablen(tab_len);
2018-03-11 01:18:46 +00:00
}
2016-01-24 02:28:22 +00:00
if (g_key_file_has_key(theme, "ui", "occupants.size", NULL)) {
gint occupants_size = g_key_file_get_integer(theme, "ui", "occupants.size", NULL);
prefs_set_occupants_size(occupants_size);
}
if (g_key_file_has_key(theme, "ui", "occupants.indent", NULL)) {
gint occupants_indent = g_key_file_get_integer(theme, "ui", "occupants.indent", NULL);
prefs_set_occupants_indent(occupants_indent);
}
if (g_key_file_has_key(theme, "ui", "roster.size", NULL)) {
gint roster_size = g_key_file_get_integer(theme, "ui", "roster.size", NULL);
prefs_set_roster_size(roster_size);
}
if (g_key_file_has_key(theme, "ui", "roster.contact.indent", NULL)) {
gint contact_indent = g_key_file_get_integer(theme, "ui", "roster.contact.indent", NULL);
prefs_set_roster_contact_indent(contact_indent);
}
if (g_key_file_has_key(theme, "ui", "roster.resource.indent", NULL)) {
gint resource_indent = g_key_file_get_integer(theme, "ui", "roster.resource.indent", NULL);
prefs_set_roster_resource_indent(resource_indent);
}
if (g_key_file_has_key(theme, "ui", "roster.presence.indent", NULL)) {
gint presence_indent = g_key_file_get_integer(theme, "ui", "roster.presence.indent", NULL);
prefs_set_roster_presence_indent(presence_indent);
}
// load chars from theme and set them to prefs
// with custom set functions
if (g_key_file_has_key(theme, "ui", "occupants.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "occupants.char", NULL);
2021-10-22 14:47:15 +00:00
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_occupants_char(ch);
}
}
if (g_key_file_has_key(theme, "ui", "occupants.header.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "occupants.header.char", NULL);
2021-10-22 14:51:15 +00:00
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_occupants_header_char(ch);
}
}
2015-11-19 23:21:51 +00:00
if (g_key_file_has_key(theme, "ui", "roster.header.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.header.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_header_char(ch);
2015-11-19 23:21:51 +00:00
}
}
2016-01-24 02:28:22 +00:00
2015-11-20 00:06:46 +00:00
if (g_key_file_has_key(theme, "ui", "roster.contact.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.contact.char", NULL);
2021-10-22 14:23:18 +00:00
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_contact_char(ch);
2015-11-22 02:04:59 +00:00
}
}
2016-01-24 02:28:22 +00:00
2015-11-22 02:04:59 +00:00
if (g_key_file_has_key(theme, "ui", "roster.resource.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.resource.char", NULL);
2021-10-22 14:29:08 +00:00
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_resource_char(ch);
2015-11-20 00:06:46 +00:00
}
2015-11-22 17:45:38 +00:00
} else {
prefs_clear_roster_resource_char();
2015-11-20 00:06:46 +00:00
}
2016-01-24 02:28:22 +00:00
if (g_key_file_has_key(theme, "ui", "roster.rooms.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.char", NULL);
2021-10-22 14:39:54 +00:00
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_room_char(ch);
2016-01-24 02:28:22 +00:00
}
}
if (g_key_file_has_key(theme, "ui", "roster.rooms.private.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.private.char", NULL);
2021-10-22 14:42:57 +00:00
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_room_private_char(ch);
}
}
2016-01-24 02:28:22 +00:00
if (g_key_file_has_key(theme, "ui", "roster.private.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.private.char", NULL);
2021-10-22 14:33:10 +00:00
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_private_char(ch);
2016-01-24 02:28:22 +00:00
}
}
2015-08-26 00:36:41 +00:00
if (g_key_file_has_key(theme, "ui", "otr.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "otr.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_otr_char(ch);
2015-08-26 00:36:41 +00:00
}
}
2016-01-24 02:28:22 +00:00
2015-08-26 00:36:41 +00:00
if (g_key_file_has_key(theme, "ui", "pgp.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "pgp.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_pgp_char(ch);
2015-08-26 00:36:41 +00:00
}
}
if (g_key_file_has_key(theme, "ui", "omemo.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "omemo.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_omemo_char(ch);
}
}
if (g_key_file_has_key(theme, "ui", "correction.char", NULL)) {
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "correction.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_correction_char(ch[0]);
}
}
// load window positions
2020-07-07 12:18:57 +00:00
if (g_key_file_has_key(theme, "ui", "titlebar.position", NULL) && g_key_file_has_key(theme, "ui", "mainwin.position", NULL) && g_key_file_has_key(theme, "ui", "statusbar.position", NULL) && g_key_file_has_key(theme, "ui", "inputwin.position", NULL)) {
2016-09-25 20:47:00 +00:00
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);
2020-07-07 12:18:57 +00:00
ProfWinPlacement* placement = prefs_create_profwin_placement(titlebar_pos, mainwin_pos, statusbar_pos, inputwin_pos);
2016-09-25 20:47:00 +00:00
prefs_save_win_placement(placement);
prefs_free_win_placement(placement);
}
2014-11-19 23:58:55 +00:00
}
static void
2020-07-07 12:18:57 +00:00
_theme_list_dir(const gchar* const dir, GSList** result)
{
2020-07-07 12:18:57 +00:00
GDir* themes = g_dir_open(dir, 0, NULL);
2015-05-04 21:33:55 +00:00
if (themes) {
2020-07-07 12:18:57 +00:00
const gchar* theme = g_dir_read_name(themes);
2015-05-04 21:33:55 +00:00
while (theme) {
*result = g_slist_append(*result, strdup(theme));
theme = g_dir_read_name(themes);
}
g_dir_close(themes);
}
}
2015-10-25 22:23:38 +00:00
static GString*
2020-07-07 12:18:57 +00:00
_theme_find(const char* const theme_name)
{
2020-07-07 12:18:57 +00:00
GString* path = NULL;
auto_gchar gchar* themes_dir = files_get_config_path(DIR_THEMES);
2015-05-04 21:33:55 +00:00
if (themes_dir) {
path = g_string_new(themes_dir);
g_string_append(path, "/");
g_string_append(path, theme_name);
if (!g_file_test(path->str, G_FILE_TEST_EXISTS)) {
g_string_free(path, true);
path = NULL;
}
}
#ifdef THEMES_PATH
if (path == NULL) {
path = g_string_new(THEMES_PATH);
g_string_append(path, "/");
g_string_append(path, theme_name);
if (!g_file_test(path->str, G_FILE_TEST_EXISTS)) {
g_string_free(path, true);
path = NULL;
}
}
#endif /* THEMES_PATH */
return path;
}
2014-11-16 20:40:19 +00:00
2016-01-14 22:54:50 +00:00
theme_item_t
2020-07-07 12:18:57 +00:00
theme_roster_unread_presence_attrs(const char* const presence)
2016-01-14 22:54:50 +00:00
{
if (g_strcmp0(presence, "online") == 0) {
return THEME_ROSTER_ONLINE_UNREAD;
} else if (g_strcmp0(presence, "away") == 0) {
return THEME_ROSTER_AWAY_UNREAD;
} else if (g_strcmp0(presence, "chat") == 0) {
return THEME_ROSTER_CHAT_UNREAD;
} else if (g_strcmp0(presence, "dnd") == 0) {
return THEME_ROSTER_DND_UNREAD;
} else if (g_strcmp0(presence, "xa") == 0) {
return THEME_ROSTER_XA_UNREAD;
} else {
return THEME_ROSTER_OFFLINE_UNREAD;
}
}
theme_item_t
2020-07-07 12:18:57 +00:00
theme_roster_active_presence_attrs(const char* const presence)
2016-01-14 22:54:50 +00:00
{
if (g_strcmp0(presence, "online") == 0) {
return THEME_ROSTER_ONLINE_ACTIVE;
} else if (g_strcmp0(presence, "away") == 0) {
return THEME_ROSTER_AWAY_ACTIVE;
} else if (g_strcmp0(presence, "chat") == 0) {
return THEME_ROSTER_CHAT_ACTIVE;
} else if (g_strcmp0(presence, "dnd") == 0) {
return THEME_ROSTER_DND_ACTIVE;
} else if (g_strcmp0(presence, "xa") == 0) {
return THEME_ROSTER_XA_ACTIVE;
} else {
return THEME_ROSTER_OFFLINE_ACTIVE;
}
}
theme_item_t
2020-07-07 12:18:57 +00:00
theme_roster_presence_attrs(const char* const presence)
2016-01-14 22:54:50 +00:00
{
if (g_strcmp0(presence, "online") == 0) {
return THEME_ROSTER_ONLINE;
} else if (g_strcmp0(presence, "away") == 0) {
return THEME_ROSTER_AWAY;
} else if (g_strcmp0(presence, "chat") == 0) {
return THEME_ROSTER_CHAT;
} else if (g_strcmp0(presence, "dnd") == 0) {
return THEME_ROSTER_DND;
} else if (g_strcmp0(presence, "xa") == 0) {
return THEME_ROSTER_XA;
} else {
return THEME_ROSTER_OFFLINE;
}
}
theme_item_t
2020-07-07 12:18:57 +00:00
theme_main_presence_attrs(const char* const presence)
{
if (g_strcmp0(presence, "online") == 0) {
return THEME_ONLINE;
} else if (g_strcmp0(presence, "away") == 0) {
return THEME_AWAY;
} else if (g_strcmp0(presence, "chat") == 0) {
return THEME_CHAT;
} else if (g_strcmp0(presence, "dnd") == 0) {
return THEME_DND;
} else if (g_strcmp0(presence, "xa") == 0) {
return THEME_XA;
} else {
return THEME_OFFLINE;
}
}
2016-01-10 03:11:05 +00:00
static void
2020-07-07 12:18:57 +00:00
_theme_prep_bgnd(char* setting, char* def, GString* lookup_str)
2016-01-10 03:11:05 +00:00
{
auto_gchar gchar* val = g_key_file_get_string(theme, "colours", setting, NULL);
2016-01-10 03:11:05 +00:00
if (!val) {
g_string_append(lookup_str, def);
} else {
if (g_str_has_prefix(val, "bold_")) {
g_string_append(lookup_str, &val[5]);
} else {
g_string_append(lookup_str, val);
}
}
}
/* return value needs to be freed */
char*
theme_get_bkgnd(void)
{
2020-07-07 12:18:57 +00:00
char* val = g_key_file_get_string(theme, "colours", "bkgnd", NULL);
return val;
}
/* gets the foreground color from the theme. or uses the one defined in 'defaults' */
2016-01-10 03:11:05 +00:00
static void
2020-07-07 12:18:57 +00:00
_theme_prep_fgnd(char* setting, GString* lookup_str, gboolean* bold)
2016-01-10 03:11:05 +00:00
{
auto_gchar gchar* conf_str = g_key_file_get_string(theme, "colours", setting, NULL);
2022-04-01 14:00:13 +00:00
gchar* val = conf_str;
if (!val)
val = g_hash_table_lookup(defaults, setting);
if (g_str_has_prefix(val, "bold_")) {
g_string_append(lookup_str, &val[5]);
*bold = TRUE;
2016-01-10 03:11:05 +00:00
} else {
2022-04-01 14:00:13 +00:00
g_string_append(lookup_str, val);
*bold = FALSE;
2016-01-10 03:11:05 +00:00
}
}
2016-01-21 02:00:12 +00:00
char*
2020-07-07 12:18:57 +00:00
theme_get_string(char* str)
2016-01-21 02:00:12 +00:00
{
gchar* res = g_key_file_get_string(theme, "colours", str, NULL);
2016-01-21 23:59:45 +00:00
if (!res) {
return strdup(g_hash_table_lookup(defaults, str));
} else {
return res;
}
2016-01-21 02:00:12 +00:00
}
void
2020-07-07 12:18:57 +00:00
theme_free_string(char* str)
2016-01-21 02:00:12 +00:00
{
if (str) {
g_free(str);
}
}
int
2020-07-07 12:18:57 +00:00
theme_hash_attrs(const char* str)
{
color_profile profile = COLOR_PROFILE_DEFAULT;
auto_gchar gchar* color_pref = prefs_get_string(PREF_COLOR_NICK);
if (strcmp(color_pref, "redgreen") == 0) {
profile = COLOR_PROFILE_REDGREEN_BLINDNESS;
} else if (strcmp(color_pref, "blue") == 0) {
profile = COLOR_PROFILE_BLUE_BLINDNESS;
}
return COLOR_PAIR(color_pair_cache_hash_str(str, profile));
}
/* returns the colours (fgnd and bknd) for a certain attribute ie main.text */
2014-11-16 20:40:19 +00:00
int
theme_attrs(theme_item_t attrs)
{
int result = 0;
2020-07-07 12:18:57 +00:00
GString* lookup_str = g_string_new("");
2016-01-10 03:11:05 +00:00
gboolean bold = FALSE;
2020-12-10 08:24:32 +00:00
// get foreground colour
2014-11-16 20:40:19 +00:00
switch (attrs) {
2020-07-07 12:18:57 +00:00
case THEME_TEXT:
_theme_prep_fgnd("main.text", lookup_str, &bold);
break;
case THEME_TEXT_HISTORY:
_theme_prep_fgnd("main.text.history", lookup_str, &bold);
break;
case THEME_TEXT_ME:
_theme_prep_fgnd("main.text.me", lookup_str, &bold);
break;
case THEME_TEXT_THEM:
_theme_prep_fgnd("main.text.them", lookup_str, &bold);
break;
case THEME_SPLASH:
_theme_prep_fgnd("main.splash", lookup_str, &bold);
break;
case THEME_TRACKBAR:
_theme_prep_fgnd("main.trackbar", lookup_str, &bold);
break;
case THEME_HELP_HEADER:
_theme_prep_fgnd("main.help.header", lookup_str, &bold);
break;
case THEME_ERROR:
_theme_prep_fgnd("error", lookup_str, &bold);
break;
case THEME_INCOMING:
_theme_prep_fgnd("incoming", lookup_str, &bold);
break;
case THEME_MENTION:
_theme_prep_fgnd("mention", lookup_str, &bold);
break;
case THEME_TRIGGER:
_theme_prep_fgnd("trigger", lookup_str, &bold);
break;
case THEME_INPUT_TEXT:
_theme_prep_fgnd("input.text", lookup_str, &bold);
break;
case THEME_TIME:
_theme_prep_fgnd("main.time", lookup_str, &bold);
break;
case THEME_TITLE_TEXT:
_theme_prep_fgnd("titlebar.text", lookup_str, &bold);
break;
case THEME_TITLE_BRACKET:
_theme_prep_fgnd("titlebar.brackets", lookup_str, &bold);
break;
case THEME_TITLE_SCROLLED:
_theme_prep_fgnd("titlebar.scrolled", lookup_str, &bold);
break;
case THEME_TITLE_UNENCRYPTED:
_theme_prep_fgnd("titlebar.unencrypted", lookup_str, &bold);
break;
case THEME_TITLE_ENCRYPTED:
_theme_prep_fgnd("titlebar.encrypted", lookup_str, &bold);
break;
case THEME_TITLE_UNTRUSTED:
_theme_prep_fgnd("titlebar.untrusted", lookup_str, &bold);
break;
case THEME_TITLE_TRUSTED:
_theme_prep_fgnd("titlebar.trusted", lookup_str, &bold);
break;
case THEME_TITLE_ONLINE:
_theme_prep_fgnd("titlebar.online", lookup_str, &bold);
break;
case THEME_TITLE_OFFLINE:
_theme_prep_fgnd("titlebar.offline", lookup_str, &bold);
break;
case THEME_TITLE_AWAY:
_theme_prep_fgnd("titlebar.away", lookup_str, &bold);
break;
case THEME_TITLE_CHAT:
_theme_prep_fgnd("titlebar.chat", lookup_str, &bold);
break;
case THEME_TITLE_DND:
_theme_prep_fgnd("titlebar.dnd", lookup_str, &bold);
break;
case THEME_TITLE_XA:
_theme_prep_fgnd("titlebar.xa", lookup_str, &bold);
break;
case THEME_STATUS_TEXT:
_theme_prep_fgnd("statusbar.text", lookup_str, &bold);
break;
case THEME_STATUS_BRACKET:
_theme_prep_fgnd("statusbar.brackets", lookup_str, &bold);
break;
case THEME_STATUS_ACTIVE:
_theme_prep_fgnd("statusbar.active", lookup_str, &bold);
break;
case THEME_STATUS_CURRENT:
_theme_prep_fgnd("statusbar.current", lookup_str, &bold);
break;
case THEME_STATUS_NEW:
_theme_prep_fgnd("statusbar.new", lookup_str, &bold);
break;
case THEME_STATUS_TIME:
_theme_prep_fgnd("statusbar.time", lookup_str, &bold);
break;
case THEME_ME:
_theme_prep_fgnd("me", lookup_str, &bold);
break;
case THEME_THEM:
_theme_prep_fgnd("them", lookup_str, &bold);
break;
case THEME_RECEIPT_SENT:
_theme_prep_fgnd("receipt.sent", lookup_str, &bold);
break;
case THEME_ROOMINFO:
_theme_prep_fgnd("roominfo", lookup_str, &bold);
break;
case THEME_ROOMMENTION:
_theme_prep_fgnd("roommention", lookup_str, &bold);
break;
case THEME_ROOMMENTION_TERM:
_theme_prep_fgnd("roommention.term", lookup_str, &bold);
break;
case THEME_ROOMTRIGGER:
_theme_prep_fgnd("roomtrigger", lookup_str, &bold);
break;
case THEME_ROOMTRIGGER_TERM:
_theme_prep_fgnd("roomtrigger.term", lookup_str, &bold);
break;
case THEME_ONLINE:
_theme_prep_fgnd("online", lookup_str, &bold);
break;
case THEME_OFFLINE:
_theme_prep_fgnd("offline", lookup_str, &bold);
break;
case THEME_AWAY:
_theme_prep_fgnd("away", lookup_str, &bold);
break;
case THEME_CHAT:
_theme_prep_fgnd("chat", lookup_str, &bold);
break;
case THEME_DND:
_theme_prep_fgnd("dnd", lookup_str, &bold);
break;
case THEME_XA:
_theme_prep_fgnd("xa", lookup_str, &bold);
break;
case THEME_TYPING:
_theme_prep_fgnd("typing", lookup_str, &bold);
break;
case THEME_GONE:
_theme_prep_fgnd("gone", lookup_str, &bold);
break;
case THEME_SUBSCRIBED:
_theme_prep_fgnd("subscribed", lookup_str, &bold);
break;
case THEME_UNSUBSCRIBED:
_theme_prep_fgnd("unsubscribed", lookup_str, &bold);
break;
case THEME_OTR_STARTED_TRUSTED:
_theme_prep_fgnd("otr.started.trusted", lookup_str, &bold);
break;
case THEME_OTR_STARTED_UNTRUSTED:
_theme_prep_fgnd("otr.started.untrusted", lookup_str, &bold);
break;
case THEME_OTR_ENDED:
_theme_prep_fgnd("otr.ended", lookup_str, &bold);
break;
case THEME_OTR_TRUSTED:
_theme_prep_fgnd("otr.trusted", lookup_str, &bold);
break;
case THEME_OTR_UNTRUSTED:
_theme_prep_fgnd("otr.untrusted", lookup_str, &bold);
break;
case THEME_ROSTER_HEADER:
_theme_prep_fgnd("roster.header", lookup_str, &bold);
break;
case THEME_ROSTER_ONLINE:
_theme_prep_fgnd("roster.online", lookup_str, &bold);
break;
case THEME_ROSTER_OFFLINE:
_theme_prep_fgnd("roster.offline", lookup_str, &bold);
break;
case THEME_ROSTER_CHAT:
_theme_prep_fgnd("roster.chat", lookup_str, &bold);
break;
case THEME_ROSTER_AWAY:
_theme_prep_fgnd("roster.away", lookup_str, &bold);
break;
case THEME_ROSTER_DND:
_theme_prep_fgnd("roster.dnd", lookup_str, &bold);
break;
case THEME_ROSTER_XA:
_theme_prep_fgnd("roster.xa", lookup_str, &bold);
break;
case THEME_ROSTER_ONLINE_ACTIVE:
_theme_prep_fgnd("roster.online.active", lookup_str, &bold);
break;
case THEME_ROSTER_OFFLINE_ACTIVE:
_theme_prep_fgnd("roster.offline.active", lookup_str, &bold);
break;
case THEME_ROSTER_CHAT_ACTIVE:
_theme_prep_fgnd("roster.chat.active", lookup_str, &bold);
break;
case THEME_ROSTER_AWAY_ACTIVE:
_theme_prep_fgnd("roster.away.active", lookup_str, &bold);
break;
case THEME_ROSTER_DND_ACTIVE:
_theme_prep_fgnd("roster.dnd.active", lookup_str, &bold);
break;
case THEME_ROSTER_XA_ACTIVE:
_theme_prep_fgnd("roster.xa.active", lookup_str, &bold);
break;
case THEME_ROSTER_ONLINE_UNREAD:
_theme_prep_fgnd("roster.online.unread", lookup_str, &bold);
break;
case THEME_ROSTER_OFFLINE_UNREAD:
_theme_prep_fgnd("roster.offline.unread", lookup_str, &bold);
break;
case THEME_ROSTER_CHAT_UNREAD:
_theme_prep_fgnd("roster.chat.unread", lookup_str, &bold);
break;
case THEME_ROSTER_AWAY_UNREAD:
_theme_prep_fgnd("roster.away.unread", lookup_str, &bold);
break;
case THEME_ROSTER_DND_UNREAD:
_theme_prep_fgnd("roster.dnd.unread", lookup_str, &bold);
break;
case THEME_ROSTER_XA_UNREAD:
_theme_prep_fgnd("roster.xa.unread", lookup_str, &bold);
break;
case THEME_ROSTER_ROOM:
_theme_prep_fgnd("roster.room", lookup_str, &bold);
break;
case THEME_ROSTER_ROOM_UNREAD:
_theme_prep_fgnd("roster.room.unread", lookup_str, &bold);
break;
case THEME_ROSTER_ROOM_TRIGGER:
_theme_prep_fgnd("roster.room.trigger", lookup_str, &bold);
break;
case THEME_ROSTER_ROOM_MENTION:
_theme_prep_fgnd("roster.room.mention", lookup_str, &bold);
break;
case THEME_OCCUPANTS_HEADER:
_theme_prep_fgnd("occupants.header", lookup_str, &bold);
break;
case THEME_UNTRUSTED:
_theme_prep_fgnd("untrusted", lookup_str, &bold);
break;
case THEME_CMD_WINS_UNREAD:
_theme_prep_fgnd("cmd.wins.unread", lookup_str, &bold);
break;
case THEME_WHITE:
g_string_append(lookup_str, "white");
bold = FALSE;
break;
case THEME_WHITE_BOLD:
g_string_append(lookup_str, "white");
bold = TRUE;
break;
case THEME_GREEN:
g_string_append(lookup_str, "green");
bold = FALSE;
break;
case THEME_GREEN_BOLD:
g_string_append(lookup_str, "green");
bold = TRUE;
break;
case THEME_RED:
g_string_append(lookup_str, "red");
bold = FALSE;
break;
case THEME_RED_BOLD:
g_string_append(lookup_str, "red");
bold = TRUE;
break;
case THEME_YELLOW:
g_string_append(lookup_str, "yellow");
bold = FALSE;
break;
case THEME_YELLOW_BOLD:
g_string_append(lookup_str, "yellow");
bold = TRUE;
break;
case THEME_BLUE:
g_string_append(lookup_str, "blue");
bold = FALSE;
break;
case THEME_BLUE_BOLD:
g_string_append(lookup_str, "blue");
bold = TRUE;
break;
case THEME_CYAN:
g_string_append(lookup_str, "cyan");
bold = FALSE;
break;
case THEME_CYAN_BOLD:
g_string_append(lookup_str, "cyan");
bold = TRUE;
break;
case THEME_BLACK:
g_string_append(lookup_str, "black");
bold = FALSE;
break;
case THEME_BLACK_BOLD:
g_string_append(lookup_str, "black");
bold = TRUE;
break;
case THEME_MAGENTA:
g_string_append(lookup_str, "magenta");
bold = FALSE;
break;
case THEME_MAGENTA_BOLD:
g_string_append(lookup_str, "magenta");
bold = TRUE;
break;
default:
g_string_append(lookup_str, "default");
bold = FALSE;
break;
2014-11-16 20:40:19 +00:00
}
2016-01-10 03:11:05 +00:00
g_string_append(lookup_str, "_");
2014-11-16 21:56:19 +00:00
2016-01-10 03:11:05 +00:00
// append background str
switch (attrs) {
case THEME_TITLE_TEXT:
case THEME_TITLE_BRACKET:
2020-05-21 07:13:42 +00:00
case THEME_TITLE_SCROLLED:
2016-01-10 03:11:05 +00:00
case THEME_TITLE_UNENCRYPTED:
case THEME_TITLE_ENCRYPTED:
case THEME_TITLE_UNTRUSTED:
case THEME_TITLE_TRUSTED:
case THEME_TITLE_ONLINE:
case THEME_TITLE_OFFLINE:
case THEME_TITLE_AWAY:
case THEME_TITLE_CHAT:
case THEME_TITLE_DND:
case THEME_TITLE_XA:
_theme_prep_bgnd("titlebar", "blue", lookup_str);
break;
case THEME_STATUS_TEXT:
case THEME_STATUS_BRACKET:
case THEME_STATUS_ACTIVE:
case THEME_STATUS_CURRENT:
2016-01-10 03:11:05 +00:00
case THEME_STATUS_NEW:
case THEME_STATUS_TIME:
2016-01-10 03:11:05 +00:00
_theme_prep_bgnd("statusbar", "blue", lookup_str);
break;
default:
_theme_prep_bgnd("bkgnd", "default", lookup_str);
break;
}
// lookup colour pair
result = color_pair_cache_get(lookup_str->str);
if (result < 0) {
log_error("Unable to load colour theme");
2019-08-23 11:46:14 +00:00
result = 0;
}
2016-01-10 03:11:05 +00:00
g_string_free(lookup_str, TRUE);
2016-01-10 03:11:05 +00:00
if (bold) {
return COLOR_PAIR(result) | A_BOLD;
} else {
return COLOR_PAIR(result);
2014-11-16 21:56:19 +00:00
}
2015-05-17 21:05:43 +00:00
}