* Pidgin is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA #include "pidgincontactcompletion.h" struct _PidginContactCompletion { GtkEntryCompletion parent; PIDGIN_CONTACT_COMPLETION_COLUMN_CONTACT, PIDGIN_CONTACT_COMPLETION_COLUMN_ACCOUNT, PIDGIN_CONTACT_COMPLETION_N_COLUMNS, static GParamSpec *properties[N_PROPERTIES] = {0, }; G_DEFINE_TYPE(PidginContactCompletion, pidgin_contact_completion, GTK_TYPE_ENTRY_COMPLETION); /****************************************************************************** *****************************************************************************/ pidgin_contact_completion_walk_contact_func(PurpleBlistNode *node, gpointer data) { PurpleBuddy *buddy = PURPLE_BUDDY(node); PurpleAccount *account = purple_buddy_get_account(buddy); GtkListStore *store = GTK_LIST_STORE(data); name = purple_buddy_get_name(buddy); gtk_list_store_append(store, &iter); PIDGIN_CONTACT_COMPLETION_COLUMN_CONTACT, name, PIDGIN_CONTACT_COMPLETION_COLUMN_ACCOUNT, account, pidgin_contact_completion_create_model(void) { GtkListStore *store = NULL; store = gtk_list_store_new( PIDGIN_CONTACT_COMPLETION_N_COLUMNS, pidgin_contact_completion_walk_contact_func, return GTK_TREE_MODEL(store); pidgin_contact_completion_match_func(GtkEntryCompletion *completion, GtkTreeModel *model = NULL; PidginContactCompletion *comp = PIDGIN_CONTACT_COMPLETION(completion); model = gtk_entry_completion_get_model(completion); PIDGIN_CONTACT_COMPLETION_COLUMN_CONTACT, &name, if(!purple_str_has_prefix(name, key)) { if(PURPLE_IS_ACCOUNT(comp->account)) { PurpleAccount *account = NULL; PIDGIN_CONTACT_COMPLETION_COLUMN_ACCOUNT, &account, if(account != comp->account) { /****************************************************************************** *****************************************************************************/ pidgin_contact_completion_init(PidginContactCompletion *comp) { pidgin_contact_completion_constructed(GObject *obj) { GtkTreeModel *model = NULL; G_OBJECT_CLASS(pidgin_contact_completion_parent_class)->constructed(obj); model = pidgin_contact_completion_create_model(); gtk_entry_completion_set_model( GTK_ENTRY_COMPLETION(obj), gtk_entry_completion_set_match_func( GTK_ENTRY_COMPLETION(obj), pidgin_contact_completion_match_func, gtk_entry_completion_set_text_column( GTK_ENTRY_COMPLETION(obj), PIDGIN_CONTACT_COMPLETION_COLUMN_CONTACT pidgin_contact_completion_get_property(GObject *obj, PidginContactCompletion *comp = PIDGIN_CONTACT_COMPLETION(obj); g_value_set_object(value, pidgin_contact_completion_get_account(comp)); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); pidgin_contact_completion_set_property(GObject *obj, PidginContactCompletion *comp = PIDGIN_CONTACT_COMPLETION(obj); pidgin_contact_completion_set_account(comp, g_value_get_object(value)); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); pidgin_contact_completion_finalize(GObject *obj) { PidginContactCompletion *comp = PIDGIN_CONTACT_COMPLETION(obj); g_object_unref(comp->account); G_OBJECT_CLASS(pidgin_contact_completion_parent_class)->finalize(obj); pidgin_contact_completion_class_init(PidginContactCompletionClass *klass) { GObjectClass *obj_class = G_OBJECT_CLASS(klass); /* The only solution I could find to make this work was to implement the * constructed handler and chain up to the parent. If you find another, * better way, please implement it :) obj_class->constructed = pidgin_contact_completion_constructed; obj_class->get_property = pidgin_contact_completion_get_property; obj_class->set_property = pidgin_contact_completion_set_property; obj_class->finalize = pidgin_contact_completion_finalize; properties[PROP_ACCOUNT] = g_param_spec_object( "The account to filter by or NULL for no filtering", G_PARAM_READWRITE | G_PARAM_CONSTRUCT g_object_class_install_properties(obj_class, N_PROPERTIES, properties); /****************************************************************************** *****************************************************************************/ pidgin_contact_completion_new(void) { return GTK_ENTRY_COMPLETION(g_object_new(PIDGIN_TYPE_CONTACT_COMPLETION, NULL)); pidgin_contact_completion_get_account(PidginContactCompletion *completion) { g_return_val_if_fail(PIDGIN_IS_CONTACT_COMPLETION(completion), NULL); return g_object_ref(completion->account); pidgin_contact_completion_set_account(PidginContactCompletion *completion, g_return_if_fail(PIDGIN_IS_CONTACT_COMPLETION(completion)); if(g_set_object(&completion->account, account)) { g_object_notify_by_pspec(G_OBJECT(completion), properties[PROP_ACCOUNT]);