Skip to content

Commit

Permalink
Sui(impl): Add chat list order configuration (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
Exagone313 authored Aug 26, 2024
1 parent 4a5efc9 commit 8258011
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/builtin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ auto-connect = [] # String array; Servers that are auto connected
# after startup
server-visibility = true # Bool; Whether the server buffer is visible
scroll-on-new-message = false # Auto scroll when a new message is recieved
chat-list-order = "recent" # String; Set to "alphabet" for alphabetical order sort

# If you want to report/fix a bug, terminal log will be helpful.
log =
Expand Down
2 changes: 2 additions & 0 deletions src/config/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ static SrnRet read_application_config_from_cfg(config_t *cfg,
&app_cfg->ui->window.server_visibility);
config_lookup_bool_ex(cfg, "scroll-on-new-message",
&app_cfg->ui->window.scroll_on_new_message);
config_lookup_string_ex(cfg, "chat-list-order",
&app_cfg->ui->window.chat_list_order);

/* Read auto connect server list */
config_setting_t *auto_connect;
Expand Down
5 changes: 5 additions & 0 deletions src/core/app_config.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "core/core.h"
#include "i18n.h"

SrnApplicationConfig *srn_application_config_new(void){
SrnApplicationConfig *cfg;
Expand All @@ -16,5 +17,9 @@ void srn_application_config_free(SrnApplicationConfig *cfg){
}

SrnRet srn_application_config_check(SrnApplicationConfig *cfg){
if (g_strcmp0(cfg->ui->window.chat_list_order, CHAT_LIST_ORDER_RECENT) != 0
&& g_strcmp0(cfg->ui->window.chat_list_order, CHAT_LIST_ORDER_ALPHABET) != 0){
return RET_ERR(_("Invalid chat-list-order configuration"));
}
return SRN_OK;
}
4 changes: 4 additions & 0 deletions src/inc/sui/sui_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ struct _SuiWindowConfig {
bool exit_on_close;
bool server_visibility;
bool scroll_on_new_message;
char *chat_list_order;
};

#define CHAT_LIST_ORDER_RECENT "recent"
#define CHAT_LIST_ORDER_ALPHABET "alphabet"

struct _SuiApplicationConfig {
char *theme;

Expand Down
1 change: 1 addition & 0 deletions src/sui/sui_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ SrnRet sui_window_config_check(SuiWindowConfig *cfg){
void sui_window_config_free(SuiWindowConfig *cfg){
g_return_if_fail(cfg);

g_free(cfg->chat_list_order);
g_free(cfg);
}

Expand Down
9 changes: 9 additions & 0 deletions src/sui/sui_side_bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static gint list_sort_func(GtkListBoxRow *row1, GtkListBoxRow *row2,
SuiSideBarItem *item1;
SuiSideBarItem *item2;
GtkWidget *event_box;
SuiWindowConfig* cfg;

event_box = gtk_bin_get_child(GTK_BIN(row1));
g_return_val_if_fail(GTK_IS_EVENT_BOX(event_box), 0);
Expand All @@ -105,6 +106,14 @@ static gint list_sort_func(GtkListBoxRow *row1, GtkListBoxRow *row2,
g_return_val_if_fail(GTK_IS_EVENT_BOX(event_box), 0);
item2 = SUI_SIDE_BAR_ITEM(gtk_bin_get_child(GTK_BIN(event_box)));

cfg = sui_window_get_config(sui_common_get_cur_window());
if (g_strcmp0(cfg->chat_list_order, CHAT_LIST_ORDER_ALPHABET) == 0){
return g_strcmp0(
sui_side_bar_item_get_title(item1),
sui_side_bar_item_get_title(item2)
);
}

time1 = sui_side_bar_item_get_update_time(item1);
time2 = sui_side_bar_item_get_update_time(item2);

Expand Down
4 changes: 4 additions & 0 deletions src/sui/sui_side_bar_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ unsigned long sui_side_bar_item_get_update_time(SuiSideBarItem *self){
return self->update_time;
}

const gchar *sui_side_bar_item_get_title(SuiSideBarItem *self){
return gtk_label_get_text(self->title_label);
}

/*****************************************************************************
* Static functions
*****************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/sui/sui_side_bar_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void sui_side_bar_item_inc_count(SuiSideBarItem *self);
void sui_side_bar_item_clear_count(SuiSideBarItem *self);

unsigned long sui_side_bar_item_get_update_time(SuiSideBarItem *self);
const gchar *sui_side_bar_item_get_title(SuiSideBarItem *self);

#endif /* __SUI_SIDE_BAR_ITEM_H */

0 comments on commit 8258011

Please sign in to comment.