| 46 pidgin_account_filter_protocol_set_protocol_id(PidginAccountFilterProtocol *filter, |
44 pidgin_account_filter_protocol_set_protocol_id(PidginAccountFilterProtocol *filter, |
| 47 const gchar *protocol_id) |
45 const gchar *protocol_id) |
| 48 { |
46 { |
| 49 g_free(filter->protocol_id); |
47 g_free(filter->protocol_id); |
| 50 filter->protocol_id = g_strdup(protocol_id); |
48 filter->protocol_id = g_strdup(protocol_id); |
| |
49 |
| |
50 gtk_filter_changed(GTK_FILTER(filter), GTK_FILTER_CHANGE_DIFFERENT); |
| |
51 } |
| |
52 |
| |
53 /****************************************************************************** |
| |
54 * GtkFilter Implementation |
| |
55 *****************************************************************************/ |
| |
56 static GtkFilterMatch |
| |
57 pidgin_account_filter_protocol_get_strictness(G_GNUC_UNUSED GtkFilter *self) { |
| |
58 return GTK_FILTER_MATCH_SOME; |
| 51 } |
59 } |
| 52 |
60 |
| 53 static gboolean |
61 static gboolean |
| 54 pidgin_account_filter_protocol_func(GtkTreeModel *model, GtkTreeIter *iter, |
62 pidgin_account_filter_protocol_match(G_GNUC_UNUSED GtkFilter *self, |
| 55 gpointer data) |
63 gpointer item) |
| 56 { |
64 { |
| 57 PidginAccountFilterProtocol *filter = NULL; |
|
| 58 PurpleAccount *account = NULL; |
|
| 59 gboolean ret = FALSE; |
65 gboolean ret = FALSE; |
| 60 |
66 |
| 61 g_return_val_if_fail(PIDGIN_IS_ACCOUNT_FILTER_PROTOCOL(data), FALSE); |
67 g_return_val_if_fail(PIDGIN_IS_ACCOUNT_FILTER_PROTOCOL(self), FALSE); |
| 62 g_return_val_if_fail(GTK_IS_TREE_MODEL(model), FALSE); |
|
| 63 g_return_val_if_fail(iter != NULL, FALSE); |
|
| 64 |
68 |
| 65 filter = PIDGIN_ACCOUNT_FILTER_PROTOCOL(data); |
69 if(PURPLE_IS_ACCOUNT(item)) { |
| |
70 PidginAccountFilterProtocol *filter = NULL; |
| |
71 PurpleAccount *account = NULL; |
| 66 |
72 |
| 67 gtk_tree_model_get(model, iter, PIDGIN_ACCOUNT_STORE_COLUMN_ACCOUNT, |
73 filter = PIDGIN_ACCOUNT_FILTER_PROTOCOL(self); |
| 68 &account, -1); |
74 account = PURPLE_ACCOUNT(item); |
| 69 |
75 ret = purple_strequal(purple_account_get_protocol_id(account), |
| 70 if(!PURPLE_IS_ACCOUNT(account)) { |
76 filter->protocol_id); |
| 71 return FALSE; |
|
| 72 } |
77 } |
| 73 |
|
| 74 ret = purple_strequal(purple_account_get_protocol_id(account), |
|
| 75 filter->protocol_id); |
|
| 76 |
|
| 77 g_object_unref(G_OBJECT(account)); |
|
| 78 |
78 |
| 79 return ret; |
79 return ret; |
| 80 } |
80 } |
| 81 |
81 |
| 82 /****************************************************************************** |
82 /****************************************************************************** |
| 83 * GObject Implementation |
83 * GObject Implementation |
| 84 *****************************************************************************/ |
84 *****************************************************************************/ |
| 85 G_DEFINE_TYPE(PidginAccountFilterProtocol, pidgin_account_filter_protocol, |
85 G_DEFINE_TYPE(PidginAccountFilterProtocol, pidgin_account_filter_protocol, |
| 86 GTK_TYPE_TREE_MODEL_FILTER) |
86 GTK_TYPE_FILTER) |
| 87 |
87 |
| 88 static void |
88 static void |
| 89 pidgin_account_filter_protocol_get_property(GObject *obj, guint param_id, |
89 pidgin_account_filter_protocol_get_property(GObject *obj, guint param_id, |
| 90 GValue *value, GParamSpec *pspec) |
90 GValue *value, GParamSpec *pspec) |
| 91 { |
91 { |
| 128 |
128 |
| 129 G_OBJECT_CLASS(pidgin_account_filter_protocol_parent_class)->finalize(obj); |
129 G_OBJECT_CLASS(pidgin_account_filter_protocol_parent_class)->finalize(obj); |
| 130 } |
130 } |
| 131 |
131 |
| 132 static void |
132 static void |
| 133 pidgin_account_filter_protocol_init(PidginAccountFilterProtocol *filter) { |
133 pidgin_account_filter_protocol_init(G_GNUC_UNUSED PidginAccountFilterProtocol *filter) |
| 134 gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(filter), |
134 { |
| 135 pidgin_account_filter_protocol_func, |
|
| 136 filter, NULL); |
|
| 137 } |
135 } |
| 138 |
136 |
| 139 static void |
137 static void |
| 140 pidgin_account_filter_protocol_class_init(PidginAccountFilterProtocolClass *klass) { |
138 pidgin_account_filter_protocol_class_init(PidginAccountFilterProtocolClass *klass) { |
| 141 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
139 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
| |
140 GtkFilterClass *filter_class = GTK_FILTER_CLASS(klass); |
| 142 |
141 |
| 143 obj_class->get_property = pidgin_account_filter_protocol_get_property; |
142 obj_class->get_property = pidgin_account_filter_protocol_get_property; |
| 144 obj_class->set_property = pidgin_account_filter_protocol_set_property; |
143 obj_class->set_property = pidgin_account_filter_protocol_set_property; |
| 145 obj_class->finalize = pidgin_account_filter_protocol_finalize; |
144 obj_class->finalize = pidgin_account_filter_protocol_finalize; |
| |
145 |
| |
146 filter_class->get_strictness = pidgin_account_filter_protocol_get_strictness; |
| |
147 filter_class->match = pidgin_account_filter_protocol_match; |
| 146 |
148 |
| 147 /** |
149 /** |
| 148 * PidginAccountFilterProtocol:protocol-id: |
150 * PidginAccountFilterProtocol:protocol-id: |
| 149 * |
151 * |
| 150 * The protocol id that will be filtered for. |
152 * The protocol id that will be filtered for. |
| 158 } |
160 } |
| 159 |
161 |
| 160 /****************************************************************************** |
162 /****************************************************************************** |
| 161 * API |
163 * API |
| 162 *****************************************************************************/ |
164 *****************************************************************************/ |
| 163 GtkTreeModel * |
165 GtkFilter * |
| 164 pidgin_account_filter_protocol_new(const gchar *protocol_id, |
166 pidgin_account_filter_protocol_new(const gchar *protocol_id) { |
| 165 GtkTreeModel *child_model, |
|
| 166 GtkTreePath *root) |
|
| 167 { |
|
| 168 g_return_val_if_fail(GTK_IS_TREE_MODEL(child_model), NULL); |
|
| 169 |
|
| 170 return g_object_new( |
167 return g_object_new( |
| 171 PIDGIN_TYPE_ACCOUNT_FILTER_PROTOCOL, |
168 PIDGIN_TYPE_ACCOUNT_FILTER_PROTOCOL, |
| 172 "protocol-id", protocol_id, |
169 "protocol-id", protocol_id, |
| 173 "child-model", child_model, |
|
| 174 "virtual-root", root, |
|
| 175 NULL); |
170 NULL); |
| 176 } |
171 } |
| 177 |
172 |
| 178 const gchar * |
173 const gchar * |
| 179 pidgin_account_filter_protocol_get_protocol_id(PidginAccountFilterProtocol *filter) { |
174 pidgin_account_filter_protocol_get_protocol_id(PidginAccountFilterProtocol *filter) { |