From 2403af8101a00532124246578afb88c1c8e34c14 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Tue, 11 Jun 2013 22:40:58 +0200 Subject: [PATCH] Allow showing offline contacts in the GTK UI --- data/gtk/roster.ui | 27 +++++++++++++++++++++++++-- src/gui/gtk/JubGtkRosterUI.h | 2 ++ src/gui/gtk/JubGtkRosterUI.m | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/data/gtk/roster.ui b/data/gtk/roster.ui index a2dc350..4223a85 100644 --- a/data/gtk/roster.ui +++ b/data/gtk/roster.ui @@ -188,6 +188,21 @@ False _Ansicht True + + + True + False + + + True + False + Show _Offline Contacts + True + + + + + @@ -197,7 +212,7 @@ _Hilfe True - + True False @@ -230,6 +245,7 @@ True True RosterTreeModelFilter + False 0 3 @@ -238,6 +254,7 @@ Status + True @@ -249,6 +266,7 @@ Name + True @@ -259,9 +277,14 @@ + fixed + 32 Avatar - + + 32 + 32 + 4 diff --git a/src/gui/gtk/JubGtkRosterUI.h b/src/gui/gtk/JubGtkRosterUI.h index 0fc8e2d..461a11a 100644 --- a/src/gui/gtk/JubGtkRosterUI.h +++ b/src/gui/gtk/JubGtkRosterUI.h @@ -19,7 +19,9 @@ OFMapTable *_subDialogMap; OFMutableDictionary *_contactMap; JubChatClient *_client; + bool _showOffline; } +@property (assign) bool showOffline; - initWithClient: (JubChatClient*)client; - (void)client: (JubChatClient*)client diff --git a/src/gui/gtk/JubGtkRosterUI.m b/src/gui/gtk/JubGtkRosterUI.m index e7e36f7..5711ee6 100644 --- a/src/gui/gtk/JubGtkRosterUI.m +++ b/src/gui/gtk/JubGtkRosterUI.m @@ -50,6 +50,7 @@ static void presence_changed(GtkComboBox *combo_box, gpointer data) static gboolean filter_roster_by_presence(GtkTreeModel *model, GtkTreeIter *iter, gpointer data) { + bool *showOffline = data; char *status; gtk_tree_model_get(model, iter, 2, &status, -1); @@ -57,12 +58,18 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model, if (!status) return TRUE; - if (!strcmp(status, "unavailable")) + if (!*showOffline && !strcmp(status, "unavailable")) return FALSE; return TRUE; } +static void menu_show_offline(GtkCheckMenuItem *checkmenuitem, gpointer data) +{ + JubGtkRosterUI *ui = data; + ui.showOffline = gtk_check_menu_item_get_active(checkmenuitem); +} + static void dialog_response_callback(GtkDialog *dialog, gint response_id, gpointer user_data) { @@ -77,6 +84,7 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id, self = [super init]; @try { + GtkCheckMenuItem *show_offline_menu_item; GtkTreeView *roster_view; GtkBuilder *builder; @@ -108,7 +116,7 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id, gtk_builder_get_object(builder, "RosterTreeModelFilter")); gtk_tree_model_filter_set_visible_func(_roster_filter, - filter_roster_by_presence, NULL, NULL); + filter_roster_by_presence, &_showOffline, NULL); roster_view = GTK_TREE_VIEW(gtk_builder_get_object(builder, "RosterTreeView")); @@ -123,6 +131,13 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id, g_signal_connect(_presence_combo, "changed", G_CALLBACK(presence_changed), client); + show_offline_menu_item = + GTK_CHECK_MENU_ITEM(gtk_builder_get_object(builder, + "showOfflineCheckMenuItem")); + + g_signal_connect(show_offline_menu_item, "toggled", + G_CALLBACK(menu_show_offline), self); + g_object_unref(G_OBJECT(builder)); } @catch (id e) { [self release]; @@ -450,7 +465,8 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id, OFArray *groups = contact.rosterItem.groups;; GdkPixbuf *avatar = - gdk_pixbuf_new_from_file([avatarFile UTF8String], NULL); + gdk_pixbuf_new_from_file_at_size([avatarFile UTF8String], + 32, 32, NULL); if (groups == nil) groups = @[ @"General" ]; @@ -507,4 +523,17 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id, [tooltip UTF8String]); }); } + +- (bool)showOffline +{ + OF_GETTER(_showOffline, YES); +} + +- (void)setShowOffline: (bool)showOffline +{ + _showOffline = showOffline; + g_idle_add_block(^{ + gtk_tree_model_filter_refilter(_roster_filter); + }); +} @end -- 2.39.5