* 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 "pidginaccountchooser.h" /****************************************************************************** *****************************************************************************/ /****************************************************************************** *****************************************************************************/ struct _PidginAccountChooser { PurpleFilterAccountFunc filter_func; /****************************************************************************** *****************************************************************************/ G_DEFINE_TYPE(PidginAccountChooser, pidgin_account_chooser, GTK_TYPE_COMBO_BOX) account_chooser_get_selected(PidginAccountChooser *chooser) if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(chooser), &iter)) { gtk_combo_box_get_model(GTK_COMBO_BOX(chooser)), &iter, AOP_DATA_COLUMN, &data, -1); account_chooser_select_by_data(GtkWidget *chooser, gpointer data) model = gtk_combo_box_get_model(GTK_COMBO_BOX(chooser)); if (gtk_tree_model_get_iter_first(model, &iter)) { gtk_tree_model_get(model, &iter, AOP_DATA_COLUMN, gtk_combo_box_set_active_iter( GTK_COMBO_BOX(chooser), &iter); } while (gtk_tree_model_iter_next(model, &iter)); set_account_menu(PidginAccountChooser *chooser, PurpleAccount *default_account) GdkPixbuf *pixbuf = NULL; list = purple_accounts_get_all(); list = purple_connections_get_all(); gtk_list_store_clear(chooser->model); for (p = list, i = 0; p != NULL; p = p->next, i++) { account = (PurpleAccount *)p->data; PurpleConnection *gc = (PurpleConnection *)p->data; account = purple_connection_get_account(gc); if (chooser->filter_func && !chooser->filter_func(account)) { pixbuf = pidgin_create_protocol_icon( account, PIDGIN_PROTOCOL_ICON_SMALL); if (purple_account_is_disconnected(account) && chooser->show_all && purple_connections_get_all()) { gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, if (purple_account_get_private_alias(account)) { g_snprintf(buf, sizeof(buf), "%s (%s) (%s)", purple_account_get_username(account), purple_account_get_private_alias(account), purple_account_get_protocol_name(account)); g_snprintf(buf, sizeof(buf), "%s (%s)", purple_account_get_username(account), purple_account_get_protocol_name(account)); gtk_list_store_append(chooser->model, &iter); gtk_list_store_set(chooser->model, &iter, AOP_ICON_COLUMN, pixbuf, AOP_NAME_COLUMN, buf, AOP_DATA_COLUMN, account, -1); if (default_account && account == default_account) { gtk_combo_box_set_active(GTK_COMBO_BOX(chooser), default_item); regenerate_account_menu(PidginAccountChooser *chooser) account = (PurpleAccount *)account_chooser_get_selected(chooser); set_account_menu(chooser, account); account_menu_sign_on_off_cb(PurpleConnection *gc, PidginAccountChooser *chooser) regenerate_account_menu(chooser); account_menu_added_removed_cb(PurpleAccount *account, PidginAccountChooser *chooser) regenerate_account_menu(chooser); account_menu_destroyed_cb(GtkWidget *chooser, GdkEvent *event, void *user_data) purple_signals_disconnect_by_handle(chooser); /****************************************************************************** *****************************************************************************/ pidgin_account_chooser_class_init(PidginAccountChooserClass *klass) GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); gtk_widget_class_set_template_from_resource( widget_class, "/im/pidgin/Pidgin/Accounts/chooser.ui"); gtk_widget_class_bind_template_child(widget_class, PidginAccountChooser, gtk_widget_class_bind_template_callback(widget_class, account_menu_destroyed_cb); pidgin_account_chooser_init(PidginAccountChooser *chooser) gtk_widget_init_template(GTK_WIDGET(chooser)); /* Register the purple sign on/off event callbacks. */ purple_connections_get_handle(), "signed-on", chooser, PURPLE_CALLBACK(account_menu_sign_on_off_cb), chooser); purple_connections_get_handle(), "signed-off", chooser, PURPLE_CALLBACK(account_menu_sign_on_off_cb), chooser); purple_accounts_get_handle(), "account-added", chooser, PURPLE_CALLBACK(account_menu_added_removed_cb), chooser); purple_accounts_get_handle(), "account-removed", chooser, PURPLE_CALLBACK(account_menu_added_removed_cb), chooser); /****************************************************************************** *****************************************************************************/ pidgin_account_chooser_new(PurpleAccount *default_account, gboolean show_all) PidginAccountChooser *chooser = NULL; chooser = g_object_new(PIDGIN_TYPE_ACCOUNT_CHOOSER, NULL); chooser->show_all = show_all; set_account_menu(PIDGIN_ACCOUNT_CHOOSER(chooser), default_account); return GTK_WIDGET(chooser); pidgin_account_chooser_set_filter_func(PidginAccountChooser *chooser, PurpleFilterAccountFunc filter_func) g_return_if_fail(PIDGIN_IS_ACCOUNT_CHOOSER(chooser)); chooser->filter_func = filter_func; regenerate_account_menu(chooser); pidgin_account_chooser_get_selected(GtkWidget *chooser) g_return_val_if_fail(PIDGIN_IS_ACCOUNT_CHOOSER(chooser), NULL); return (PurpleAccount *)account_chooser_get_selected( PIDGIN_ACCOUNT_CHOOSER(chooser)); pidgin_account_chooser_set_selected(GtkWidget *chooser, PurpleAccount *account) g_return_if_fail(PIDGIN_IS_ACCOUNT_CHOOSER(chooser)); account_chooser_select_by_data(chooser, account);