3 * Pidgin is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #include "pidgincontactcompletion.h"
26 struct _PidginContactCompletion
{
27 GtkEntryCompletion parent
;
28 PurpleAccount
*account
;
32 PIDGIN_CONTACT_COMPLETION_COLUMN_CONTACT
,
33 PIDGIN_CONTACT_COMPLETION_COLUMN_ACCOUNT
,
34 PIDGIN_CONTACT_COMPLETION_N_COLUMNS
,
43 static GParamSpec
*properties
[N_PROPERTIES
] = {0, };
45 G_DEFINE_TYPE(PidginContactCompletion
, pidgin_contact_completion
, GTK_TYPE_ENTRY_COMPLETION
);
47 /******************************************************************************
49 *****************************************************************************/
51 pidgin_contact_completion_walk_contact_func(PurpleBlistNode
*node
, gpointer data
) {
52 PurpleBuddy
*buddy
= PURPLE_BUDDY(node
);
53 PurpleAccount
*account
= purple_buddy_get_account(buddy
);
54 GtkListStore
*store
= GTK_LIST_STORE(data
);
58 name
= purple_buddy_get_name(buddy
);
63 gtk_list_store_append(store
, &iter
);
67 PIDGIN_CONTACT_COMPLETION_COLUMN_CONTACT
, name
,
68 PIDGIN_CONTACT_COMPLETION_COLUMN_ACCOUNT
, account
,
74 pidgin_contact_completion_create_model(void) {
75 GtkListStore
*store
= NULL
;
77 store
= gtk_list_store_new(
78 PIDGIN_CONTACT_COMPLETION_N_COLUMNS
,
83 purple_blist_walk(NULL
,
86 pidgin_contact_completion_walk_contact_func
,
90 return GTK_TREE_MODEL(store
);
94 pidgin_contact_completion_match_func(GtkEntryCompletion
*completion
,
99 GtkTreeModel
*model
= NULL
;
100 PidginContactCompletion
*comp
= PIDGIN_CONTACT_COMPLETION(completion
);
103 model
= gtk_entry_completion_get_model(completion
);
108 PIDGIN_CONTACT_COMPLETION_COLUMN_CONTACT
, &name
,
116 if(!purple_str_has_prefix(name
, key
)) {
121 if(PURPLE_IS_ACCOUNT(comp
->account
)) {
122 PurpleAccount
*account
= NULL
;
127 PIDGIN_CONTACT_COMPLETION_COLUMN_ACCOUNT
, &account
,
131 if(account
!= comp
->account
) {
132 g_object_unref(account
);
136 g_object_unref(account
);
142 /******************************************************************************
143 * GObject Implemention
144 *****************************************************************************/
146 pidgin_contact_completion_init(PidginContactCompletion
*comp
) {
150 pidgin_contact_completion_constructed(GObject
*obj
) {
151 GtkTreeModel
*model
= NULL
;
153 G_OBJECT_CLASS(pidgin_contact_completion_parent_class
)->constructed(obj
);
155 model
= pidgin_contact_completion_create_model();
157 gtk_entry_completion_set_model(
158 GTK_ENTRY_COMPLETION(obj
),
162 gtk_entry_completion_set_match_func(
163 GTK_ENTRY_COMPLETION(obj
),
164 pidgin_contact_completion_match_func
,
169 gtk_entry_completion_set_text_column(
170 GTK_ENTRY_COMPLETION(obj
),
171 PIDGIN_CONTACT_COMPLETION_COLUMN_CONTACT
176 pidgin_contact_completion_get_property(GObject
*obj
,
181 PidginContactCompletion
*comp
= PIDGIN_CONTACT_COMPLETION(obj
);
185 g_value_set_object(value
, pidgin_contact_completion_get_account(comp
));
188 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
194 pidgin_contact_completion_set_property(GObject
*obj
,
199 PidginContactCompletion
*comp
= PIDGIN_CONTACT_COMPLETION(obj
);
203 pidgin_contact_completion_set_account(comp
,
204 g_value_get_object(value
));
207 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
213 pidgin_contact_completion_finalize(GObject
*obj
) {
214 PidginContactCompletion
*comp
= PIDGIN_CONTACT_COMPLETION(obj
);
216 g_object_unref(comp
->account
);
218 G_OBJECT_CLASS(pidgin_contact_completion_parent_class
)->finalize(obj
);
222 pidgin_contact_completion_class_init(PidginContactCompletionClass
*klass
) {
223 GObjectClass
*obj_class
= G_OBJECT_CLASS(klass
);
225 /* The only solution I could find to make this work was to implement the
226 * constructed handler and chain up to the parent. If you find another,
227 * better way, please implement it :)
229 obj_class
->constructed
= pidgin_contact_completion_constructed
;
231 obj_class
->get_property
= pidgin_contact_completion_get_property
;
232 obj_class
->set_property
= pidgin_contact_completion_set_property
;
233 obj_class
->finalize
= pidgin_contact_completion_finalize
;
235 properties
[PROP_ACCOUNT
] = g_param_spec_object(
238 "The account to filter by or NULL for no filtering",
240 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
243 g_object_class_install_properties(obj_class
, N_PROPERTIES
, properties
);
246 /******************************************************************************
248 *****************************************************************************/
250 pidgin_contact_completion_new(void) {
251 return GTK_ENTRY_COMPLETION(g_object_new(PIDGIN_TYPE_CONTACT_COMPLETION
, NULL
));
255 pidgin_contact_completion_get_account(PidginContactCompletion
*completion
) {
256 g_return_val_if_fail(PIDGIN_IS_CONTACT_COMPLETION(completion
), NULL
);
258 return g_object_ref(completion
->account
);
262 pidgin_contact_completion_set_account(PidginContactCompletion
*completion
,
263 PurpleAccount
*account
)
265 g_return_if_fail(PIDGIN_IS_CONTACT_COMPLETION(completion
));
267 if(g_set_object(&completion
->account
, account
)) {
268 g_object_notify_by_pspec(G_OBJECT(completion
),
269 properties
[PROP_ACCOUNT
]);