mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-17 19:20:20 +00:00
Persist GTK userlist column widths
This commit is contained in:
@@ -407,6 +407,9 @@ const struct prefs vars[] =
|
||||
{"gui_autoopen_send", P_OFFINT (hex_gui_autoopen_send), TYPE_BOOL},
|
||||
{"gui_chanlist_maxusers", P_OFFINT (hex_gui_chanlist_maxusers), TYPE_INT},
|
||||
{"gui_chanlist_minusers", P_OFFINT (hex_gui_chanlist_minusers), TYPE_INT},
|
||||
{"gui_chanlist_width_channel", P_OFFINT (hex_gui_chanlist_width_channel), TYPE_INT},
|
||||
{"gui_chanlist_width_topic", P_OFFINT (hex_gui_chanlist_width_topic), TYPE_INT},
|
||||
{"gui_chanlist_width_users", P_OFFINT (hex_gui_chanlist_width_users), TYPE_INT},
|
||||
{"gui_compact", P_OFFINT (hex_gui_compact), TYPE_BOOL},
|
||||
{"gui_dialog_height", P_OFFINT (hex_gui_dialog_height), TYPE_INT},
|
||||
{"gui_dialog_left", P_OFFINT (hex_gui_dialog_left), TYPE_INT},
|
||||
@@ -466,6 +469,8 @@ const struct prefs vars[] =
|
||||
{"gui_ulist_hide", P_OFFINT (hex_gui_ulist_hide), TYPE_BOOL},
|
||||
{"gui_ulist_icons", P_OFFINT (hex_gui_ulist_icons), TYPE_BOOL},
|
||||
{"gui_ulist_pos", P_OFFINT (hex_gui_ulist_pos), TYPE_INT},
|
||||
{"gui_ulist_nick_width", P_OFFINT (hex_gui_ulist_nick_width), TYPE_INT},
|
||||
{"gui_ulist_host_width", P_OFFINT (hex_gui_ulist_host_width), TYPE_INT},
|
||||
{"gui_ulist_show_hosts", P_OFFINT(hex_gui_ulist_show_hosts), TYPE_BOOL},
|
||||
{"gui_ulist_sort", P_OFFINT (hex_gui_ulist_sort), TYPE_INT},
|
||||
{"gui_ulist_style", P_OFFINT (hex_gui_ulist_style), TYPE_BOOL},
|
||||
@@ -824,6 +829,9 @@ load_default_config(void)
|
||||
prefs.hex_flood_msg_time = 30;
|
||||
prefs.hex_gui_chanlist_maxusers = 9999;
|
||||
prefs.hex_gui_chanlist_minusers = 5;
|
||||
prefs.hex_gui_chanlist_width_channel = 0;
|
||||
prefs.hex_gui_chanlist_width_topic = 0;
|
||||
prefs.hex_gui_chanlist_width_users = 0;
|
||||
prefs.hex_gui_dialog_height = 256;
|
||||
prefs.hex_gui_dialog_width = 500;
|
||||
prefs.hex_gui_lagometer = 1;
|
||||
@@ -837,6 +845,8 @@ load_default_config(void)
|
||||
prefs.hex_gui_tab_trunc = 20;
|
||||
prefs.hex_gui_throttlemeter = 1;
|
||||
prefs.hex_gui_ulist_pos = 3;
|
||||
prefs.hex_gui_ulist_nick_width = 0;
|
||||
prefs.hex_gui_ulist_host_width = 0;
|
||||
prefs.hex_gui_win_height = 400;
|
||||
prefs.hex_gui_win_width = 640;
|
||||
prefs.hex_irc_ban_type = 1;
|
||||
|
||||
@@ -248,6 +248,9 @@ struct zoitechatprefs
|
||||
int hex_flood_msg_time;
|
||||
int hex_gui_chanlist_maxusers;
|
||||
int hex_gui_chanlist_minusers;
|
||||
int hex_gui_chanlist_width_channel;
|
||||
int hex_gui_chanlist_width_topic;
|
||||
int hex_gui_chanlist_width_users;
|
||||
int hex_gui_dialog_height;
|
||||
int hex_gui_dialog_left;
|
||||
int hex_gui_dialog_top;
|
||||
@@ -269,6 +272,8 @@ struct zoitechatprefs
|
||||
int hex_gui_transparency;
|
||||
int hex_gui_throttlemeter;
|
||||
int hex_gui_ulist_pos;
|
||||
int hex_gui_ulist_nick_width;
|
||||
int hex_gui_ulist_host_width;
|
||||
int hex_gui_ulist_sort;
|
||||
int hex_gui_url_mod;
|
||||
int hex_gui_win_height;
|
||||
|
||||
@@ -74,6 +74,19 @@ chanlistrow;
|
||||
|
||||
#define GET_MODEL(xserv) (gtk_tree_view_get_model(GTK_TREE_VIEW(xserv->gui->chanlist_list)))
|
||||
|
||||
#define CHANLIST_COL_WIDTH_MIN_CHANNEL 60
|
||||
#define CHANLIST_COL_WIDTH_MIN_USERS 40
|
||||
#define CHANLIST_COL_WIDTH_MIN_TOPIC 60
|
||||
|
||||
static int
|
||||
chanlist_clamp_width (int width, int min_width)
|
||||
{
|
||||
if (width < min_width)
|
||||
return min_width;
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
static void
|
||||
chanlist_set_label_alignment (GtkWidget *widget)
|
||||
{
|
||||
@@ -805,6 +818,26 @@ chanlist_button_cb (GtkTreeView *tree, GdkEventButton *event, server *serv)
|
||||
static void
|
||||
chanlist_destroy_widget (GtkWidget *wid, server *serv)
|
||||
{
|
||||
GtkTreeViewColumn *column;
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (serv->gui->chanlist_list), COL_CHANNEL);
|
||||
if (column)
|
||||
prefs.hex_gui_chanlist_width_channel =
|
||||
chanlist_clamp_width (gtk_tree_view_column_get_width (column), CHANLIST_COL_WIDTH_MIN_CHANNEL);
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (serv->gui->chanlist_list), COL_USERS);
|
||||
if (column)
|
||||
prefs.hex_gui_chanlist_width_users =
|
||||
chanlist_clamp_width (gtk_tree_view_column_get_width (column), CHANLIST_COL_WIDTH_MIN_USERS);
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (serv->gui->chanlist_list), COL_TOPIC);
|
||||
if (column)
|
||||
prefs.hex_gui_chanlist_width_topic =
|
||||
chanlist_clamp_width (gtk_tree_view_column_get_width (column), CHANLIST_COL_WIDTH_MIN_TOPIC);
|
||||
|
||||
if (!save_config ())
|
||||
fe_message (_("Could not save zoitechat.conf."), FE_MSG_WARN);
|
||||
|
||||
custom_list_clear ((CustomList *)GET_MODEL (serv));
|
||||
chanlist_data_free (serv);
|
||||
|
||||
@@ -944,6 +977,37 @@ chanlist_opengui (server *serv, int do_refresh)
|
||||
chanlist_add_column (view, COL_CHANNEL, 96, _("Channel"), FALSE);
|
||||
chanlist_add_column (view, COL_USERS, 50, _("Users"), TRUE);
|
||||
chanlist_add_column (view, COL_TOPIC, 50, _("Topic"), FALSE);
|
||||
|
||||
if (prefs.hex_gui_chanlist_width_channel > 0)
|
||||
{
|
||||
GtkTreeViewColumn *column = gtk_tree_view_get_column (GTK_TREE_VIEW (view), COL_CHANNEL);
|
||||
if (column)
|
||||
gtk_tree_view_column_set_fixed_width (column,
|
||||
chanlist_clamp_width (prefs.hex_gui_chanlist_width_channel, CHANLIST_COL_WIDTH_MIN_CHANNEL));
|
||||
}
|
||||
|
||||
if (prefs.hex_gui_chanlist_width_users > 0)
|
||||
{
|
||||
GtkTreeViewColumn *column = gtk_tree_view_get_column (GTK_TREE_VIEW (view), COL_USERS);
|
||||
if (column)
|
||||
{
|
||||
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_fixed_width (column,
|
||||
chanlist_clamp_width (prefs.hex_gui_chanlist_width_users, CHANLIST_COL_WIDTH_MIN_USERS));
|
||||
gtk_tree_view_column_set_resizable (column, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
if (prefs.hex_gui_chanlist_width_topic > 0)
|
||||
{
|
||||
GtkTreeViewColumn *column = gtk_tree_view_get_column (GTK_TREE_VIEW (view), COL_TOPIC);
|
||||
if (column)
|
||||
{
|
||||
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_fixed_width (column,
|
||||
chanlist_clamp_width (prefs.hex_gui_chanlist_width_topic, CHANLIST_COL_WIDTH_MIN_TOPIC));
|
||||
}
|
||||
}
|
||||
gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_HORIZONTAL);
|
||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), GTK_SELECTION_MULTIPLE);
|
||||
/* this is a speed up, but no horizontal scrollbar :( */
|
||||
|
||||
@@ -52,6 +52,29 @@ enum
|
||||
|
||||
static void userlist_store_color (GtkListStore *store, GtkTreeIter *iter, ThemeSemanticToken token, gboolean has_token);
|
||||
|
||||
static void
|
||||
userlist_column_width_notify_cb (GtkTreeViewColumn *column, GParamSpec *pspec, gpointer userdata)
|
||||
{
|
||||
(void)pspec;
|
||||
|
||||
int width = gtk_tree_view_column_get_width (column);
|
||||
int *target = (int *)userdata;
|
||||
|
||||
if (!target || width < 1 || *target == width)
|
||||
return;
|
||||
|
||||
*target = width;
|
||||
}
|
||||
|
||||
static void
|
||||
userlist_apply_saved_column_width (GtkTreeViewColumn *column, int width)
|
||||
{
|
||||
if (!column || width < 1)
|
||||
return;
|
||||
|
||||
gtk_tree_view_column_set_fixed_width (column, width);
|
||||
}
|
||||
|
||||
static void
|
||||
userlist_update_min_width (session *sess)
|
||||
{
|
||||
@@ -71,7 +94,6 @@ userlist_update_min_width (session *sess)
|
||||
scrolled_window = gtk_widget_get_parent (sess->gui->user_tree);
|
||||
if (GTK_IS_SCROLLED_WINDOW (scrolled_window))
|
||||
gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW (scrolled_window), width);
|
||||
gtk_widget_set_size_request (sess->gui->user_tree, width, -1);
|
||||
gtk_widget_set_size_request (sess->gui->user_box, width, -1);
|
||||
}
|
||||
|
||||
@@ -712,6 +734,11 @@ userlist_add_columns (GtkTreeView * treeview)
|
||||
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_expand (column, TRUE);
|
||||
gtk_tree_view_column_set_min_width (column, 1);
|
||||
gtk_tree_view_column_set_resizable (column, TRUE);
|
||||
userlist_apply_saved_column_width (column, prefs.hex_gui_ulist_nick_width);
|
||||
g_signal_connect (G_OBJECT (column), "notify::width",
|
||||
G_CALLBACK (userlist_column_width_notify_cb),
|
||||
&prefs.hex_gui_ulist_nick_width);
|
||||
|
||||
if (prefs.hex_gui_ulist_show_hosts)
|
||||
{
|
||||
@@ -728,6 +755,11 @@ userlist_add_columns (GtkTreeView * treeview)
|
||||
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_expand (column, TRUE);
|
||||
gtk_tree_view_column_set_min_width (column, 1);
|
||||
gtk_tree_view_column_set_resizable (column, TRUE);
|
||||
userlist_apply_saved_column_width (column, prefs.hex_gui_ulist_host_width);
|
||||
g_signal_connect (G_OBJECT (column), "notify::width",
|
||||
G_CALLBACK (userlist_column_width_notify_cb),
|
||||
&prefs.hex_gui_ulist_host_width);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -854,7 +886,7 @@ userlist_create (GtkWidget *box)
|
||||
treeview = gtk_tree_view_new ();
|
||||
gtk_widget_set_name (treeview, "zoitechat-userlist");
|
||||
gtk_widget_set_can_focus (treeview, TRUE);
|
||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
|
||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
|
||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection
|
||||
(GTK_TREE_VIEW (treeview)),
|
||||
GTK_SELECTION_MULTIPLE);
|
||||
|
||||
Reference in New Issue
Block a user