pidgin/pidginaccountfilterconnected.c

changeset 41864
6f490dec468f
parent 40539
2941deda6d8d
child 42575
580339aa47cc
equal deleted inserted replaced
41863:0067a0ff5b74 41864:6f490dec468f
20 * along with this program; if not, see <https://www.gnu.org/licenses/>. 20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
21 */ 21 */
22 22
23 #include "pidgin/pidginaccountfilterconnected.h" 23 #include "pidgin/pidginaccountfilterconnected.h"
24 24
25 #include "pidgin/pidginaccountstore.h"
26
27 #include <purple.h> 25 #include <purple.h>
28 26
29 struct _PidginAccountFilterConnected { 27 struct _PidginAccountFilterConnected {
30 GtkTreeModelFilter parent; 28 GtkFilter parent;
31 }; 29 };
32 30
33 /****************************************************************************** 31 /******************************************************************************
34 * Callbacks 32 * Callbacks
35 *****************************************************************************/ 33 *****************************************************************************/
36 static void 34 static void
37 pidgin_account_filter_connected_changed(PurpleConnection *connection, 35 pidgin_account_filter_connected_changed(PurpleConnection *connection,
38 gpointer data) 36 gpointer data)
39 { 37 {
40 PidginAccountFilterConnected *filter = NULL; 38 PidginAccountFilterConnected *filter = NULL;
39 PurpleConnectionState state;
41 40
42 filter = PIDGIN_ACCOUNT_FILTER_CONNECTED(data); 41 filter = PIDGIN_ACCOUNT_FILTER_CONNECTED(data);
43 42
44 gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(filter)); 43 state = purple_connection_get_state(connection);
44 gtk_filter_changed(GTK_FILTER(filter),
45 (state == PURPLE_CONNECTION_STATE_CONNECTED) ?
46 GTK_FILTER_CHANGE_LESS_STRICT :
47 GTK_FILTER_CHANGE_MORE_STRICT);
45 } 48 }
46 49
47 /****************************************************************************** 50 /******************************************************************************
48 * GObject Implementation 51 * GtkFilter Implementation
49 *****************************************************************************/ 52 *****************************************************************************/
53 static GtkFilterMatch
54 pidgin_account_filter_connected_get_strictness(G_GNUC_UNUSED GtkFilter *self) {
55 return GTK_FILTER_MATCH_SOME;
56 }
57
50 static gboolean 58 static gboolean
51 pidgin_account_filter_connected_func(GtkTreeModel *model, GtkTreeIter *iter, 59 pidgin_account_filter_connected_match(G_GNUC_UNUSED GtkFilter *self,
52 gpointer data) 60 gpointer item)
53 { 61 {
54 PurpleAccount *account = NULL;
55 gboolean ret = FALSE; 62 gboolean ret = FALSE;
56 63
57 g_return_val_if_fail(GTK_IS_TREE_MODEL(model), FALSE); 64 if(PURPLE_IS_ACCOUNT(item)) {
58 g_return_val_if_fail(iter != NULL, FALSE); 65 ret = purple_account_is_connected(PURPLE_ACCOUNT(item));
59
60 gtk_tree_model_get(model, iter, PIDGIN_ACCOUNT_STORE_COLUMN_ACCOUNT,
61 &account, -1);
62
63 if(!PURPLE_IS_ACCOUNT(account)) {
64 return FALSE;
65 } 66 }
66
67 ret = purple_account_is_connected(account);
68
69 g_object_unref(G_OBJECT(account));
70 67
71 return ret; 68 return ret;
72 } 69 }
73 70
74 /****************************************************************************** 71 /******************************************************************************
75 * GObject Implementation 72 * GObject Implementation
76 *****************************************************************************/ 73 *****************************************************************************/
77 G_DEFINE_TYPE(PidginAccountFilterConnected, pidgin_account_filter_connected, 74 G_DEFINE_TYPE(PidginAccountFilterConnected, pidgin_account_filter_connected,
78 GTK_TYPE_TREE_MODEL_FILTER) 75 GTK_TYPE_FILTER)
79 76
80 static void 77 static void
81 pidgin_account_filter_connected_init(PidginAccountFilterConnected *filter) { 78 pidgin_account_filter_connected_init(PidginAccountFilterConnected *filter) {
82 gpointer connections_handle = NULL; 79 gpointer connections_handle = NULL;
83
84 gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(filter),
85 pidgin_account_filter_connected_func,
86 NULL, NULL);
87 80
88 /* we connect to the connections signals to force a refresh of the filter */ 81 /* we connect to the connections signals to force a refresh of the filter */
89 connections_handle = purple_connections_get_handle(); 82 connections_handle = purple_connections_get_handle();
90 purple_signal_connect(connections_handle, "signed-on", filter, 83 purple_signal_connect(connections_handle, "signed-on", filter,
91 G_CALLBACK(pidgin_account_filter_connected_changed), 84 G_CALLBACK(pidgin_account_filter_connected_changed),
103 } 96 }
104 97
105 static void 98 static void
106 pidgin_account_filter_connected_class_init(PidginAccountFilterConnectedClass *klass) { 99 pidgin_account_filter_connected_class_init(PidginAccountFilterConnectedClass *klass) {
107 GObjectClass *obj_class = G_OBJECT_CLASS(klass); 100 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
101 GtkFilterClass *filter_class = GTK_FILTER_CLASS(klass);
108 102
109 obj_class->finalize = pidgin_account_filter_connected_finalize; 103 obj_class->finalize = pidgin_account_filter_connected_finalize;
104
105 filter_class->get_strictness = pidgin_account_filter_connected_get_strictness;
106 filter_class->match = pidgin_account_filter_connected_match;
110 } 107 }
111 108
112 /****************************************************************************** 109 /******************************************************************************
113 * API 110 * API
114 *****************************************************************************/ 111 *****************************************************************************/
115 GtkTreeModel * 112 GtkFilter *
116 pidgin_account_filter_connected_new(GtkTreeModel *child_model, 113 pidgin_account_filter_connected_new(void)
117 GtkTreePath *root)
118 { 114 {
119 g_return_val_if_fail(GTK_IS_TREE_MODEL(child_model), NULL); 115 return g_object_new(PIDGIN_TYPE_ACCOUNT_FILTER_CONNECTED, NULL);
120
121 return g_object_new(PIDGIN_TYPE_ACCOUNT_FILTER_CONNECTED, "child-model",
122 child_model, "virtual-root", root, NULL);
123 } 116 }

mercurial