diff options
Diffstat (limited to 'src/fe-gtk')
-rw-r--r-- | src/fe-gtk/maingui.c | 4 | ||||
-rw-r--r-- | src/fe-gtk/setup.c | 2 | ||||
-rw-r--r-- | src/fe-gtk/userlistgui.c | 74 | ||||
-rw-r--r-- | src/fe-gtk/userlistgui.h | 2 |
4 files changed, 67 insertions, 15 deletions
diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c index b1764a0a..2eabe8b7 100644 --- a/src/fe-gtk/maingui.c +++ b/src/fe-gtk/maingui.c @@ -1715,7 +1715,7 @@ mg_add_chan (session *sess) { sess->res->buffer = gtk_xtext_buffer_new (GTK_XTEXT (sess->gui->xtext)); gtk_xtext_set_time_stamp (sess->res->buffer, prefs.hex_stamp_text); - sess->res->user_model = userlist_create_model (); + sess->res->user_model = userlist_create_model (sess); } } @@ -3164,7 +3164,7 @@ mg_create_topwindow (session *sess) sess->res->buffer = gtk_xtext_buffer_new (GTK_XTEXT (sess->gui->xtext)); gtk_xtext_buffer_show (GTK_XTEXT (sess->gui->xtext), sess->res->buffer, TRUE); gtk_xtext_set_time_stamp (sess->res->buffer, prefs.hex_stamp_text); - sess->res->user_model = userlist_create_model (); + sess->res->user_model = userlist_create_model (sess); } userlist_show (sess); diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c index cc5d25bf..e3969ff3 100644 --- a/src/fe-gtk/setup.c +++ b/src/fe-gtk/setup.c @@ -2114,6 +2114,8 @@ setup_apply (struct hexchatprefs *pr) noapply = TRUE; if (DIFF (hex_gui_ulist_style)) noapply = TRUE; + if (DIFF (hex_gui_ulist_sort)) + noapply = TRUE; if (DIFF (hex_gui_tab_dots)) do_layout = TRUE; diff --git a/src/fe-gtk/userlistgui.c b/src/fe-gtk/userlistgui.c index b95eb522..943bd17b 100644 --- a/src/fe-gtk/userlistgui.c +++ b/src/fe-gtk/userlistgui.c @@ -332,9 +332,9 @@ fe_userlist_rehash (session *sess, struct User *user) } void -fe_userlist_insert (session *sess, struct User *newuser, int row, int sel) +fe_userlist_insert (session *sess, struct User *newuser, gboolean sel) { - GtkTreeModel *model = sess->res->user_model; + GtkTreeModel *model = GTK_TREE_MODEL(sess->res->user_model); GdkPixbuf *pix = get_user_icon (sess->server, newuser); GtkTreeIter iter; char *nick; @@ -357,7 +357,7 @@ fe_userlist_insert (session *sess, struct User *newuser, int row, int sel) pix = NULL; } - gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, row, + gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, 0, COL_PIX, pix, COL_NICK, nick, COL_HOST, newuser->hostname, @@ -396,12 +396,6 @@ fe_userlist_insert (session *sess, struct User *newuser, int row, int sel) } void -fe_userlist_move (session *sess, struct User *user, int new_row) -{ - fe_userlist_insert (sess, user, new_row, fe_userlist_remove (sess, user)); -} - -void fe_userlist_clear (session *sess) { gtk_list_store_clear (sess->res->user_model); @@ -459,11 +453,67 @@ userlist_dnd_leave (GtkTreeView *widget, GdkDragContext *context, guint ttime) return TRUE; } -void * -userlist_create_model (void) +static int +userlist_alpha_cmp (GtkTreeModel *model, GtkTreeIter *iter_a, GtkTreeIter *iter_b, gpointer userdata) +{ + struct User *user_a, *user_b; + + gtk_tree_model_get (model, iter_a, COL_USER, &user_a, -1); + gtk_tree_model_get (model, iter_b, COL_USER, &user_b, -1); + + return nick_cmp_alpha (user_a, user_b, ((session*)userdata)->server); +} + +static int +userlist_ops_cmp (GtkTreeModel *model, GtkTreeIter *iter_a, GtkTreeIter *iter_b, gpointer userdata) +{ + struct User *user_a, *user_b; + + gtk_tree_model_get (model, iter_a, COL_USER, &user_a, -1); + gtk_tree_model_get (model, iter_b, COL_USER, &user_b, -1); + + return nick_cmp_az_ops (((session*)userdata)->server, user_a, user_b); +} + +GtkListStore * +userlist_create_model (session *sess) { - return gtk_list_store_new (5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, + GtkListStore *store; + GtkTreeIterCompareFunc cmp_func; + GtkSortType sort_type; + + store = gtk_list_store_new (5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, GDK_TYPE_COLOR); + + switch (prefs.hex_gui_ulist_sort) + { + case 0: + cmp_func = userlist_ops_cmp; + sort_type = GTK_SORT_ASCENDING; + break; + case 1: + cmp_func = userlist_alpha_cmp; + sort_type = GTK_SORT_ASCENDING; + break; + case 2: + cmp_func = userlist_ops_cmp; + sort_type = GTK_SORT_DESCENDING; + break; + case 3: + cmp_func = userlist_alpha_cmp; + sort_type = GTK_SORT_DESCENDING; + break; + default: + /* No sorting */ + gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE(store), NULL, NULL, NULL); + return store; + } + + gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE(store), cmp_func, sess, NULL); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(store), + GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, sort_type); + + return store; } static void diff --git a/src/fe-gtk/userlistgui.h b/src/fe-gtk/userlistgui.h index 993fe8f0..7633246a 100644 --- a/src/fe-gtk/userlistgui.h +++ b/src/fe-gtk/userlistgui.h @@ -23,7 +23,7 @@ void userlist_set_value (GtkWidget *treeview, gfloat val); gfloat userlist_get_value (GtkWidget *treeview); GtkWidget *userlist_create (GtkWidget *box); -void *userlist_create_model (void); +void *userlist_create_model (session *sess); void userlist_show (session *sess); void userlist_select (session *sess, char *name); char **userlist_selection_list (GtkWidget *widget, int *num_ret); |