Skip to content

Commit

Permalink
Prefs(fix): Fix reading chat-specific config.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowRZ authored and SilverRainZ committed Jun 11, 2020
1 parent 58317ad commit a421532
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
13 changes: 10 additions & 3 deletions data/builtin.ini
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ kick-message = "Kick."
away-message = "Away from keyboard."
quit-message = "El Psy Congroo."

# List of chats that contains specified chat configuration.
chat-list = ["#srain"]

# Chat configuration.
[Chat]
# Bool; Persistent chat log to storage
Expand All @@ -82,6 +79,8 @@ preview-url = true
auto-preview-url = false
# String array; Commands that are auto run after chat is created
auto-run = []
# List of chats that contains specified chat configuration.
chat-list = ["#srain"]

# A example of specified chat configuration.
[Chat/#srain]
Expand Down Expand Up @@ -161,3 +160,11 @@ encoding = "utf-8"
name = "localhost"
addresses = ["localhost:6667", "127.0.0.1:6667"]
tls = false

# Example server-specific configs.
#[Server/freenode/Chat]
#preview-url = true
#chat-list = ['#archlinux-cn']
#
#[Server/freenode/Chat/#archlinux-cn]
#preview-url = false
26 changes: 15 additions & 11 deletions src/config/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,14 @@ static SrnRet read_server_config_from_cfg(SrnSettingsStruct *cfg, SrnServerConfi
}

static SrnRet read_chat_config_from_chat(GSettings *chat, SrnChatConfig *cfg){
settings_get_boolean_ex(chat, "notify", &cfg->ui->notify);
settings_get_boolean_ex(chat, "show-topic", &cfg->ui->show_topic);
settings_get_boolean_ex(chat, "show-avatar", &cfg->ui->show_avatar);
settings_get_boolean_ex(chat, "show-user-list", &cfg->ui->show_user_list);
settings_get_boolean_ex(chat, "render-mirc-color", &cfg->render_mirc_color);
settings_get_boolean_ex(chat, "preview-url", &cfg->ui->preview_url);
settings_get_boolean_ex(chat, "auto-preview-url", &cfg->ui->auto_preview_url);
settings_get_string_ex(chat, "nick-completion-suffix", &cfg->ui->nick_completion_suffix);
settings_get_boolean_ex(chat, "notify", &cfg->ui->notify);
settings_get_boolean_ex(chat, "show-topic", &cfg->ui->show_topic);
settings_get_boolean_ex(chat, "show-avatar", &cfg->ui->show_avatar);
settings_get_boolean_ex(chat, "show-user-list", &cfg->ui->show_user_list);
settings_get_boolean_ex(chat, "render-mirc-color", &cfg->render_mirc_color);
settings_get_boolean_ex(chat, "preview-url", &cfg->ui->preview_url);
settings_get_boolean_ex(chat, "auto-preview-url", &cfg->ui->auto_preview_url);
settings_get_string_ex(chat, "nick-completion-suffix", &cfg->ui->nick_completion_suffix);

/* Read autorun command list */
gchar **cmds = NULL;
Expand All @@ -531,11 +531,13 @@ static SrnRet read_chat_config_from_chat_list(SrnSettingsStruct *gs,

for (int i = 0, count = g_strv_length(chat_list); i < count; i++){
const char *name = NULL;
name = chat_list[i];
if (g_strcmp0(chat_name, name) != 0) continue;
GSettings *chat;

gchar *chat_path = g_strdup_printf("%s%s/",
PACKAGE_GSCHEMA_CHAT_PATH,
chat_list[i]);
name);
chat = g_settings_new_with_backend_and_path(PACKAGE_GSCHEMA_CHAT_ID,
gs->gs_backend,
chat_path);
Expand All @@ -544,7 +546,6 @@ static SrnRet read_chat_config_from_chat_list(SrnSettingsStruct *gs,
g_free(chat_path);
break;
};
name = chat_list[i];

DBG_FR("Read: chat-list.%s, chat_name: %s", name, chat_name);
ret = read_chat_config_from_chat(chat, cfg);
Expand All @@ -560,6 +561,8 @@ static SrnRet read_chat_config_from_server_chat_list(SrnSettingsStruct *gs,

for (int i = 0, count = g_strv_length(chat_list); i < count; i++){
const char *name = NULL;
name = chat_list[i];
if (g_strcmp0(chat_name, name) != 0) continue;
GSettings *chat;

gchar *chat_path = g_strdup_printf("%s%s/Chat/%s/",
Expand All @@ -574,7 +577,6 @@ static SrnRet read_chat_config_from_server_chat_list(SrnSettingsStruct *gs,
g_free(chat_path);
break;
};
name = chat_list[i];

DBG_FR("Read: server.%s.chat-list.%s, chat_name: %s", srv_name, name, chat_name);
ret = read_chat_config_from_chat(chat, cfg);
Expand Down Expand Up @@ -644,6 +646,8 @@ static SrnRet read_chat_config_from_cfg(SrnSettingsStruct *cfg, SrnChatConfig *c
gchar **chat_list = NULL;
settings_get_strv_ex(chat, "chat-list", &chat_list);
if (chat_list){
DBG_FR("Read server-list.[name = %s].chat-list.[name = %s], srv_name: %s, chat_name: %s",
name, chat_name, srv_name, chat_name);
ret = read_chat_config_from_server_chat_list(cfg, name, chat_list, chat_cfg, chat_name);
g_strfreev(chat_list);
if (!RET_IS_OK(ret)) return ret;
Expand Down

0 comments on commit a421532

Please sign in to comment.