* 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;
/******************************************************************************
*****************************************************************************/
static GParamSpec *properties[PROP_LAST] = {NULL};
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_changed_cb(GtkComboBox *widget, gpointer user_data)
g_object_notify_by_pspec(G_OBJECT(widget), properties[PROP_ACCOUNT]);
/******************************************************************************
*****************************************************************************/
pidgin_account_chooser_get_property(GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
PidginAccountChooser *chooser = PIDGIN_ACCOUNT_CHOOSER(object);
g_value_set_object(value, account_chooser_get_selected(chooser));
g_value_set_boolean(value, chooser->show_all);
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
pidgin_account_chooser_set_property(GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
PidginAccountChooser *chooser = PIDGIN_ACCOUNT_CHOOSER(object);
account_chooser_select_by_data(GTK_WIDGET(chooser),
g_value_get_object(value));
chooser->show_all = g_value_get_boolean(value);
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
pidgin_account_chooser_class_init(PidginAccountChooserClass *klass)
GObjectClass *obj_class = G_OBJECT_CLASS(klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
obj_class->get_property = pidgin_account_chooser_get_property;
obj_class->set_property = pidgin_account_chooser_set_property;
properties[PROP_ACCOUNT] = g_param_spec_object(
"account", "Account", "The account that is currently selected.",
PURPLE_TYPE_ACCOUNT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
properties[PROP_SHOW_ALL] = g_param_spec_boolean(
"Whether to show all accounts, or just online ones.", FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
g_object_class_install_properties(obj_class, PROP_LAST, properties);
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));
set_account_menu(chooser, NULL);
g_signal_connect(chooser, "changed",
G_CALLBACK(pidgin_account_chooser_changed_cb), NULL);
/* 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, "account",
default_account, "show-all", show_all, NULL);
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);
/* NOTE: Property notification occurs in 'changed' signal callback. */
pidgin_account_chooser_get_show_all(GtkWidget *chooser)
g_return_val_if_fail(PIDGIN_IS_ACCOUNT_CHOOSER(chooser), FALSE);
return PIDGIN_ACCOUNT_CHOOSER(chooser)->show_all;