* Pidgin - Internet Messenger
* Copyright (C) Pidgin Developers <devel@pidgin.im>
* 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 "pidgin/pidginprotocolstore.h"
struct _PidginProtocolStore {
/******************************************************************************
*****************************************************************************/
pidgin_protocol_store_add_protocol(PidginProtocolStore *store,
PurpleProtocol *protocol)
GdkPixbuf *pixbuf = NULL;
pixbuf = pidgin_create_icon_from_protocol(protocol,
PIDGIN_PROTOCOL_ICON_SMALL, NULL);
gtk_list_store_append(GTK_LIST_STORE(store), &iter);
PIDGIN_PROTOCOL_STORE_COLUMN_PROTOCOL, protocol,
PIDGIN_PROTOCOL_STORE_COLUMN_NAME, purple_protocol_get_name(protocol),
PIDGIN_PROTOCOL_STORE_COLUMN_ICON, pixbuf,
pidgin_protocol_store_add_protocol_helper(gpointer data, gpointer user_data) {
if(PURPLE_IS_PROTOCOL(data)) {
pidgin_protocol_store_add_protocol(PIDGIN_PROTOCOL_STORE(user_data),
pidgin_protocol_store_add_protocols(PidginProtocolStore *store) {
g_list_foreach(purple_protocols_get_all(),
pidgin_protocol_store_add_protocol_helper, store);
pidgin_protocol_store_remove_protocol(PidginProtocolStore *store,
PurpleProtocol *protocol)
if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter) == FALSE) {
purple_debug_warning("protocol-store",
"protocol %s was removed but not in the store",
purple_protocol_get_name(protocol));
/* walk through the store and look for the protocol to remove */
PurpleProtocol *prpl = NULL;
PIDGIN_PROTOCOL_STORE_COLUMN_PROTOCOL, &prpl,
g_object_unref(G_OBJECT(prpl));
gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
} while(gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
/******************************************************************************
*****************************************************************************/
pidgin_protocol_store_protocol_added_cb(PurpleProtocol *protocol,
pidgin_protocol_store_add_protocol(PIDGIN_PROTOCOL_STORE(data), protocol);
pidgin_protocol_store_protocol_removed_cb(PurpleProtocol *protocol,
pidgin_protocol_store_remove_protocol(PIDGIN_PROTOCOL_STORE(data), protocol);
/******************************************************************************
*****************************************************************************/
G_DEFINE_TYPE(PidginProtocolStore, pidgin_protocol_store, GTK_TYPE_LIST_STORE)
pidgin_protocol_store_init(PidginProtocolStore *store) {
gpointer protocols_handle = NULL;
GType types[PIDGIN_PROTOCOL_STORE_N_COLUMNS] = {
gtk_list_store_set_column_types(
PIDGIN_PROTOCOL_STORE_N_COLUMNS,
/* add the known protocols */
pidgin_protocol_store_add_protocols(store);
/* add the signal handlers to dynamically add/remove protocols */
protocols_handle = purple_protocols_get_handle();
purple_signal_connect(protocols_handle, "protocol-added", store,
G_CALLBACK(pidgin_protocol_store_protocol_added_cb),
purple_signal_connect(protocols_handle, "protocol-removed", store,
G_CALLBACK(pidgin_protocol_store_protocol_removed_cb),
pidgin_protocol_store_finalize(GObject *obj) {
purple_signals_disconnect_by_handle(obj);
G_OBJECT_CLASS(pidgin_protocol_store_parent_class)->finalize(obj);
pidgin_protocol_store_class_init(PidginProtocolStoreClass *klass) {
GObjectClass *obj_class = G_OBJECT_CLASS(klass);
obj_class->finalize = pidgin_protocol_store_finalize;
/******************************************************************************
*****************************************************************************/
pidgin_protocol_store_new(void) {
return GTK_LIST_STORE(g_object_new(PIDGIN_TYPE_PROTOCOL_STORE, NULL));