Add the new PidginProtocolChooser and implement it in account dialog
--- a/pidgin/gtkaccount.c Wed Oct 09 05:42:34 2019 -0500
+++ b/pidgin/gtkaccount.c Fri Feb 14 00:50:39 2020 -0600
@@ -42,6 +42,7 @@
#include "gtkstatusbox.h"
+#include "pidginprotocolchooser.h" @@ -224,12 +225,15 @@
-set_account_protocol_cb(GtkWidget *widget, const char *id,
- AccountPrefsDialog *dialog)
+set_account_protocol_cb(GtkWidget *widget, AccountPrefsDialog *dialog) + PidginProtocolChooser *chooser = PIDGIN_PROTOCOL_CHOOSER(widget); PurpleProtocol *new_protocol;
+ id = pidgin_protocol_chooser_get_selected(chooser); new_protocol = purple_protocols_find(id);
dialog->protocol = new_protocol;
@@ -478,10 +482,12 @@
- if (dialog->protocol_menu == NULL)
- dialog->protocol_menu = pidgin_protocol_option_menu_new(
- dialog->protocol_id, G_CALLBACK(set_account_protocol_cb), dialog);
+ if(dialog->protocol_menu == NULL) { + dialog->protocol_menu = pidgin_protocol_chooser_new(); + gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->protocol_menu), 0); + g_signal_connect(G_OBJECT(dialog->protocol_menu), "changed", + G_CALLBACK(set_account_protocol_cb), dialog); + gtk_widget_show(dialog->protocol_menu); g_object_ref(G_OBJECT(dialog->protocol_menu));
--- a/pidgin/gtkutils.c Wed Oct 09 05:42:34 2019 -0500
+++ b/pidgin/gtkutils.c Fri Feb 14 00:50:39 2020 -0600
@@ -458,7 +458,7 @@
pidgin_create_icon_from_protocol(PurpleProtocol *protocol, PidginProtocolIconSize size, PurpleAccount *account)
const char *protoname = NULL;
--- a/pidgin/gtkutils.h Wed Oct 09 05:42:34 2019 -0500
+++ b/pidgin/gtkutils.h Fri Feb 14 00:50:39 2020 -0600
@@ -457,6 +457,27 @@
GdkPixbuf *pidgin_create_protocol_icon(PurpleAccount *account, PidginProtocolIconSize size);
+ * pidgin_create_icon_from_protocol: + * @protocol: The #PurpleProtocolInstance + * @size: The size of the icon to return. + * @account: (nullable): An optional #PurpleAccount to use. + * Returns the base image to represent @protocol based on the currently + * selected theme. If @account is not %NULL then the returned icon will + * represent the account. + * Returns: (transfer full): A newly-created pixbuf with a reference count of 1, + * or NULL if any of several error conditions occurred: + * the file could not be opened, there was no loader + * for the file's format, there was not enough memory + * to allocate the image buffer, or the image file + * contained invalid data. +GdkPixbuf *pidgin_create_icon_from_protocol(PurpleProtocol *protocol, PidginProtocolIconSize size, PurpleAccount *account); * pidgin_create_status_icon:
* @primitive: The status primitive
* @w: The widget to render this
--- a/pidgin/meson.build Wed Oct 09 05:42:34 2019 -0500
+++ b/pidgin/meson.build Fri Feb 14 00:50:39 2020 -0600
@@ -44,6 +44,7 @@
+ 'pidginprotocolchooser.c', @@ -97,6 +98,7 @@
+ 'pidginprotocolchooser.h', --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidginprotocolchooser.c Fri Feb 14 00:50:39 2020 -0600
@@ -0,0 +1,113 @@
+ * 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 "pidginprotocolchooser.h" +#include "pidginprotocolstore.h" +/****************************************************************************** + *****************************************************************************/ +struct _PidginProtocolChooser { +/****************************************************************************** + * GObject Implementation + *****************************************************************************/ +G_DEFINE_TYPE(PidginProtocolChooser, pidgin_protocol_chooser, +pidgin_protocol_chooser_class_init(PidginProtocolChooserClass *klass) + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + gtk_widget_class_set_template_from_resource(widget_class, + "/im/pidgin/Pidgin/Protocols/chooser.ui"); + gtk_widget_class_bind_template_child(widget_class, PidginProtocolChooser, +pidgin_protocol_chooser_init(PidginProtocolChooser *chooser) { + gtk_widget_init_template(GTK_WIDGET(chooser)); +/****************************************************************************** + *****************************************************************************/ +pidgin_protocol_chooser_new(void) { + return GTK_WIDGET(g_object_new(PIDGIN_TYPE_PROTOCOL_CHOOSER, NULL)); +pidgin_protocol_chooser_get_selected(PidginProtocolChooser *chooser) + g_return_val_if_fail(PIDGIN_IS_PROTOCOL_CHOOSER(chooser), NULL); + if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(chooser), &iter)) { + gtk_tree_model_get(GTK_TREE_MODEL(chooser->model), &iter, + PIDGIN_PROTOCOL_STORE_COLUMN_NAME, &name, +pidgin_protocol_chooser_set_selected(PidginProtocolChooser *chooser, + gchar *iter_name = NULL; + g_return_if_fail(PIDGIN_IS_PROTOCOL_CHOOSER(chooser)); + if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(chooser->model), &iter)) { + gtk_tree_model_get(GTK_TREE_MODEL(chooser->model), &iter, + PIDGIN_PROTOCOL_STORE_COLUMN_NAME, &iter_name, + if(purple_strequal(iter_name, name)) { + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(chooser), &iter); + } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(chooser->model), --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidginprotocolchooser.h Fri Feb 14 00:50:39 2020 -0600
@@ -0,0 +1,80 @@
+ * 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 +#ifndef PIDGIN_PROTOCOL_CHOOSER_H +#define PIDGIN_PROTOCOL_CHOOSER_H + * SECTION:pidginaccountchooser + * @section_id: pidgin-protocol-chooser + * @short_description: A #GtkComboBox for choosing protocols + * @title: Pidgin Protocol Chooser Combo Box Widget +#define PIDGIN_TYPE_PROTOCOL_CHOOSER (pidgin_protocol_chooser_get_type()) +G_DECLARE_FINAL_TYPE(PidginProtocolChooser, pidgin_protocol_chooser, PIDGIN, + PROTOCOL_CHOOSER, GtkComboBox) + * pidgin_protocol_chooser_new: + * Creates a combo box for a user to select a protocol from. + * Returns: (transfer full): The protocol chooser combo box. +GtkWidget *pidgin_protocol_chooser_new(void); + * pidgin_protocol_chooser_get_selected: + * @chooser: The #PidginProtocolChooser instance. + * Gets the name of the currently selected protocol from @chooser. + * Returns: (transfer full): Returns the name of the currently selected +gchar *pidgin_protocol_chooser_get_selected(PidginProtocolChooser *chooser); + * pidgin_protocol_chooser_set_selected: + * @chooser: The #PidginProtocolChooser instance. + * @protocol: The name of the protocol to select. + * Sets the currently selected protocol of @chooser to @protocol. +void pidgin_protocol_chooser_set_selected(PidginProtocolChooser *chooser, const gchar *protocol); +#endif /* PIDGIN_PROTOCOL_CHOOSER_H */ --- a/pidgin/pidginprotocolstore.c Wed Oct 09 05:42:34 2019 -0500
+++ b/pidgin/pidginprotocolstore.c Fri Feb 14 00:50:39 2020 -0600
@@ -1,4 +1,6 @@
+ * 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
@@ -21,6 +23,8 @@
#include "pidgin/pidginprotocolstore.h"
struct _PidginProtocolStore {
@@ -33,6 +37,10 @@
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);
@@ -40,19 +48,25 @@
PIDGIN_PROTOCOL_STORE_COLUMN_PROTOCOL, protocol,
PIDGIN_PROTOCOL_STORE_COLUMN_NAME, purple_protocol_get_name(protocol),
+ PIDGIN_PROTOCOL_STORE_COLUMN_ICON, pixbuf, + g_clear_object(&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), + PURPLE_PROTOCOL(data)); pidgin_protocol_store_add_protocols(PidginProtocolStore *store) {
- GList *protocols = purple_protocols_get_all(), *l;
- for(l = protocols; l != NULL; l = l->data) {
- if(PURPLE_IS_PROTOCOL(l->data)) {
- pidgin_protocol_store_add_protocol(store, PURPLE_PROTOCOL(l->data));
+ g_list_foreach(purple_protocols_get_all(), + pidgin_protocol_store_add_protocol_helper, store); @@ -117,6 +131,7 @@
GType types[PIDGIN_PROTOCOL_STORE_N_COLUMNS] = {
gtk_list_store_set_column_types(
--- a/pidgin/pidginprotocolstore.h Wed Oct 09 05:42:34 2019 -0500
+++ b/pidgin/pidginprotocolstore.h Fri Feb 14 00:50:39 2020 -0600
@@ -40,6 +40,7 @@
PIDGIN_PROTOCOL_STORE_COLUMN_PROTOCOL,
PIDGIN_PROTOCOL_STORE_COLUMN_NAME,
+ PIDGIN_PROTOCOL_STORE_COLUMN_ICON, PIDGIN_PROTOCOL_STORE_N_COLUMNS,
} PidginProtocolStoreColumn;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/resources/Protocols/chooser.ui Fri Feb 14 00:50:39 2020 -0600
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 +Pidgin - Internet Messenger +Copyright (C) Pidgin Developers <devel@pidgin.im> +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 02110-1301, USA. +<interface domain="pidgin"> + <requires lib="gtk+" version="3.20"/> + <!-- interface-license-type gplv2 --> + <!-- interface-name Pidgin --> + <!-- interface-description Internet Messenger --> + <!-- interface-copyright Pidgin Developers <devel@pidgin.im> --> + <template class="PidginProtocolChooser" parent="GtkComboBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="model">model</property> + <object class="GtkCellRendererPixbuf" id="icon"/> + <attribute name="pixbuf">2</attribute> + <object class="GtkCellRendererText" id="name"/> + <attribute name="text">1</attribute> + <object class="PidginProtocolStore" id="model"/> --- a/pidgin/resources/pidgin.gresource.xml Wed Oct 09 05:42:34 2019 -0500
+++ b/pidgin/resources/pidgin.gresource.xml Fri Feb 14 00:50:39 2020 -0600
@@ -14,6 +14,7 @@
<file compressed="true">Prefs/prefs.ui</file>
<file compressed="true">Prefs/vv.ui</file>
<file compressed="true">Privacy/dialog.ui</file>
+ <file compressed="true">Protocols/chooser.ui</file> <file compressed="true">Roomlist/roomlist.ui</file>
<file compressed="true">Whiteboard/whiteboard.ui</file>
<file compressed="true">Xfer/xfer.ui</file>