Sun, 15 May 2022 02:33:17 -0500
Rename PidginCredentialsPage to PidginCredentialPrefs
| pidgin/meson.build | file | annotate | diff | comparison | revisions | |
| pidgin/prefs/pidgincredentialprefs.c | file | annotate | diff | comparison | revisions | |
| pidgin/prefs/pidgincredentialprefs.h | file | annotate | diff | comparison | revisions | |
| pidgin/prefs/pidgincredentialspage.c | file | annotate | diff | comparison | revisions | |
| pidgin/prefs/pidgincredentialspage.h | file | annotate | diff | comparison | revisions | |
| pidgin/resources/Prefs/credentials.ui | file | annotate | diff | comparison | revisions | |
| pidgin/resources/Prefs/prefs.ui | file | annotate | diff | comparison | revisions |
--- a/pidgin/meson.build Sun May 15 02:33:16 2022 -0500 +++ b/pidgin/meson.build Sun May 15 02:33:17 2022 -0500 @@ -63,7 +63,7 @@ 'prefs/pidginawayprefs.c', 'prefs/pidginconversationprefs.c', 'prefs/pidgincredentialproviderrow.c', - 'prefs/pidgincredentialspage.c', + 'prefs/pidgincredentialprefs.c', 'prefs/pidginnetworkpage.c', 'prefs/pidginproxyprefs.c', ] @@ -135,7 +135,7 @@ 'prefs/pidginawayprefs.h', 'prefs/pidginconversationprefs.h', 'prefs/pidgincredentialproviderrow.h', - 'prefs/pidgincredentialspage.h', + 'prefs/pidgincredentialprefs.h', 'prefs/pidginnetworkpage.h', 'prefs/pidginproxyprefs.h', ]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/prefs/pidgincredentialprefs.c Sun May 15 02:33:17 2022 -0500 @@ -0,0 +1,204 @@ +/* + * 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 + * source distribution. + * + * 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, see <https://www.gnu.org/licenses/>. + */ + +#include <purple.h> + +#include <handy.h> + +#include "pidgincredentialprefs.h" + +#include "pidgincredentialproviderrow.h" + +struct _PidginCredentialPrefs { + HdyPreferencesPage parent; + + GtkWidget *credential_list; +}; + +G_DEFINE_TYPE(PidginCredentialPrefs, pidgin_credential_prefs, + HDY_TYPE_PREFERENCES_PAGE) + +/****************************************************************************** + * Helpers + *****************************************************************************/ +static void +pidgin_credential_prefs_create_row(PurpleCredentialProvider *provider, + gpointer data) +{ + GtkListBox *box = GTK_LIST_BOX(data); + GtkWidget *row = NULL; + + row = pidgin_credential_provider_row_new(provider); + gtk_list_box_prepend(box, row); +} + +static gint +pidgin_credential_prefs_sort_rows(GtkListBoxRow *row1, GtkListBoxRow *row2, + G_GNUC_UNUSED gpointer user_data) +{ + PidginCredentialProviderRow *pcprow = NULL; + PurpleCredentialProvider *provider = NULL; + const gchar *id1 = NULL; + gboolean is_noop1 = FALSE; + const gchar *id2 = NULL; + gboolean is_noop2 = FALSE; + + pcprow = PIDGIN_CREDENTIAL_PROVIDER_ROW(row1); + provider = pidgin_credential_provider_row_get_provider(pcprow); + id1 = purple_credential_provider_get_id(provider); + is_noop1 = purple_strequal(id1, "noop-provider"); + + pcprow = PIDGIN_CREDENTIAL_PROVIDER_ROW(row2); + provider = pidgin_credential_provider_row_get_provider(pcprow); + id2 = purple_credential_provider_get_id(provider); + is_noop2 = purple_strequal(id2, "noop-provider"); + + /* Sort None provider after everything else. */ + if (is_noop1 && is_noop2) { + return 0; + } else if (is_noop1 && !is_noop2) { + return 1; + } else if (!is_noop1 && is_noop2) { + return -1; + } + /* Sort normally by ID. */ + return g_strcmp0(id1, id2); +} + +static void +pidgin_credential_prefs_list_row_activated_cb(GtkListBox *box, + GtkListBoxRow *row, + G_GNUC_UNUSED gpointer data) +{ + PurpleCredentialManager *manager = NULL; + PurpleCredentialProvider *provider = NULL; + const gchar *id = NULL; + GError *error = NULL; + + provider = pidgin_credential_provider_row_get_provider( + PIDGIN_CREDENTIAL_PROVIDER_ROW(row)); + id = purple_credential_provider_get_id(provider); + + manager = purple_credential_manager_get_default(); + if(purple_credential_manager_set_active(manager, id, &error)) { + return; + } + + purple_debug_warning("credential-prefs", "failed to set the active " + "credential provider to '%s': %s", + id, error ? error->message : "unknown error"); + + g_clear_error(&error); +} + +static void +pidgin_credential_prefs_set_active_provider(PidginCredentialPrefs *prefs, + const gchar *new_id) +{ + GList *rows = NULL; + + rows = gtk_container_get_children(GTK_CONTAINER(prefs->credential_list)); + for (; rows; rows = g_list_delete_link(rows, rows)) { + PidginCredentialProviderRow *row = NULL; + PurpleCredentialProvider *provider = NULL; + const gchar *id = NULL; + + row = PIDGIN_CREDENTIAL_PROVIDER_ROW(rows->data); + provider = pidgin_credential_provider_row_get_provider(row); + id = purple_credential_provider_get_id(provider); + + pidgin_credential_provider_row_set_active(row, + purple_strequal(new_id, id)); + } +} + +static void +pidgin_credential_prefs_active_provider_changed_cb(const gchar *name, + PurplePrefType type, + gconstpointer value, + gpointer data) +{ + PidginCredentialPrefs *prefs = PIDGIN_CREDENTIAL_PREFS(data); + + pidgin_credential_prefs_set_active_provider(prefs, (const gchar *)value); +} + +/****************************************************************************** + * GObject Implementation + *****************************************************************************/ +static void +pidgin_credential_prefs_finalize(GObject *obj) { + purple_prefs_disconnect_by_handle(obj); + + G_OBJECT_CLASS(pidgin_credential_prefs_parent_class)->finalize(obj); +} + +static void +pidgin_credential_prefs_init(PidginCredentialPrefs *prefs) { + PurpleCredentialManager *manager = NULL; + const gchar *active = NULL; + + gtk_widget_init_template(GTK_WIDGET(prefs)); + + manager = purple_credential_manager_get_default(); + purple_credential_manager_foreach( + manager, + pidgin_credential_prefs_create_row, + prefs->credential_list); + gtk_list_box_set_sort_func(GTK_LIST_BOX(prefs->credential_list), + pidgin_credential_prefs_sort_rows, NULL, NULL); + + purple_prefs_connect_callback(prefs, "/purple/credentials/active-provider", + pidgin_credential_prefs_active_provider_changed_cb, + prefs); + + active = purple_prefs_get_string("/purple/credentials/active-provider"); + if(active != NULL) { + pidgin_credential_prefs_set_active_provider(prefs, active); + } +} + +static void +pidgin_credential_prefs_class_init(PidginCredentialPrefsClass *klass) { + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + + obj_class->finalize = pidgin_credential_prefs_finalize; + + gtk_widget_class_set_template_from_resource( + widget_class, + "/im/pidgin/Pidgin3/Prefs/credentials.ui" + ); + + gtk_widget_class_bind_template_child(widget_class, PidginCredentialPrefs, + credential_list); + gtk_widget_class_bind_template_callback(widget_class, + pidgin_credential_prefs_list_row_activated_cb); +} + +/****************************************************************************** + * API + *****************************************************************************/ +GtkWidget * +pidgin_credential_prefs_new(void) { + return GTK_WIDGET(g_object_new(PIDGIN_TYPE_CREDENTIAL_PREFS, NULL)); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/prefs/pidgincredentialprefs.h Sun May 15 02:33:17 2022 -0500 @@ -0,0 +1,70 @@ +/* + * 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 + * source distribution. + * + * 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, see <https://www.gnu.org/licenses/>. + */ + +#if !defined(PIDGIN_GLOBAL_HEADER_INSIDE) && !defined(PIDGIN_COMPILATION) +# error "only <pidgin.h> may be included directly" +#endif + +#ifndef PIDGIN_CREDENTIAL_PREFS_H +#define PIDGIN_CREDENTIAL_PREFS_H + +#include <glib.h> + +#include <gtk/gtk.h> +#include <handy.h> + +G_BEGIN_DECLS + +/** + * PIDGIN_TYPE_CREDENTIAL_PREFS: + * + * The standard _get_type macro for #PidginCredentialPrefs. + * + * Since: 3.0.0 + */ +#define PIDGIN_TYPE_CREDENTIAL_PREFS (pidgin_credential_prefs_get_type()) +G_DECLARE_FINAL_TYPE(PidginCredentialPrefs, pidgin_credential_prefs, + PIDGIN, CREDENTIAL_PREFS, HdyPreferencesPage) + +/** + * PidginCredentialPrefs: + * + * #PidginCredentialPrefs is a widget for the preferences window to let users + * choose and configure their credential provider. + * + * Since: 3.0.0 + */ + +/** + * pidgin_credential_prefs_new: + * + * Creates a new #PidginCredentialPrefs instance. + * + * Returns: (transfer full): The new #PidginCredentialPrefs instance. + * + * Since: 3.0.0 + */ +GtkWidget *pidgin_credential_prefs_new(void); + +G_END_DECLS + +#endif /* PIDGIN_CREDENTIAL_PREFS_H */
--- a/pidgin/prefs/pidgincredentialspage.c Sun May 15 02:33:16 2022 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,204 +0,0 @@ -/* - * 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 - * source distribution. - * - * 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, see <https://www.gnu.org/licenses/>. - */ - -#include <purple.h> - -#include <handy.h> - -#include "pidgincredentialspage.h" - -#include "pidgincredentialproviderrow.h" - -struct _PidginCredentialsPage { - HdyPreferencesPage parent; - - GtkWidget *credential_list; -}; - -G_DEFINE_TYPE(PidginCredentialsPage, pidgin_credentials_page, - HDY_TYPE_PREFERENCES_PAGE) - -/****************************************************************************** - * Helpers - *****************************************************************************/ -static void -pidgin_credentials_page_create_row(PurpleCredentialProvider *provider, - gpointer data) -{ - GtkListBox *box = GTK_LIST_BOX(data); - GtkWidget *row = NULL; - - row = pidgin_credential_provider_row_new(provider); - gtk_list_box_prepend(box, row); -} - -static gint -pidgin_credentials_page_sort_rows(GtkListBoxRow *row1, GtkListBoxRow *row2, - G_GNUC_UNUSED gpointer user_data) -{ - PidginCredentialProviderRow *pcprow = NULL; - PurpleCredentialProvider *provider = NULL; - const gchar *id1 = NULL; - gboolean is_noop1 = FALSE; - const gchar *id2 = NULL; - gboolean is_noop2 = FALSE; - - pcprow = PIDGIN_CREDENTIAL_PROVIDER_ROW(row1); - provider = pidgin_credential_provider_row_get_provider(pcprow); - id1 = purple_credential_provider_get_id(provider); - is_noop1 = purple_strequal(id1, "noop-provider"); - - pcprow = PIDGIN_CREDENTIAL_PROVIDER_ROW(row2); - provider = pidgin_credential_provider_row_get_provider(pcprow); - id2 = purple_credential_provider_get_id(provider); - is_noop2 = purple_strequal(id2, "noop-provider"); - - /* Sort None provider after everything else. */ - if (is_noop1 && is_noop2) { - return 0; - } else if (is_noop1 && !is_noop2) { - return 1; - } else if (!is_noop1 && is_noop2) { - return -1; - } - /* Sort normally by ID. */ - return g_strcmp0(id1, id2); -} - -static void -pidgin_credential_page_list_row_activated_cb(GtkListBox *box, - GtkListBoxRow *row, - G_GNUC_UNUSED gpointer data) -{ - PurpleCredentialManager *manager = NULL; - PurpleCredentialProvider *provider = NULL; - const gchar *id = NULL; - GError *error = NULL; - - provider = pidgin_credential_provider_row_get_provider( - PIDGIN_CREDENTIAL_PROVIDER_ROW(row)); - id = purple_credential_provider_get_id(provider); - - manager = purple_credential_manager_get_default(); - if(purple_credential_manager_set_active(manager, id, &error)) { - return; - } - - purple_debug_warning("credentials-page", "failed to set the active " - "credential provider to '%s': %s", - id, error ? error->message : "unknown error"); - - g_clear_error(&error); -} - -static void -pidgin_credentials_page_set_active_provider(PidginCredentialsPage *page, - const gchar *new_id) -{ - GList *rows = NULL; - - rows = gtk_container_get_children(GTK_CONTAINER(page->credential_list)); - for (; rows; rows = g_list_delete_link(rows, rows)) { - PidginCredentialProviderRow *row = NULL; - PurpleCredentialProvider *provider = NULL; - const gchar *id = NULL; - - row = PIDGIN_CREDENTIAL_PROVIDER_ROW(rows->data); - provider = pidgin_credential_provider_row_get_provider(row); - id = purple_credential_provider_get_id(provider); - - pidgin_credential_provider_row_set_active(row, - purple_strequal(new_id, id)); - } -} - -static void -pidgin_credentials_page_active_provider_changed_cb(const gchar *name, - PurplePrefType type, - gconstpointer value, - gpointer data) -{ - PidginCredentialsPage *page = PIDGIN_CREDENTIALS_PAGE(data); - - pidgin_credentials_page_set_active_provider(page, (const gchar *)value); -} - -/****************************************************************************** - * GObject Implementation - *****************************************************************************/ -static void -pidgin_credentials_page_finalize(GObject *obj) { - purple_prefs_disconnect_by_handle(obj); - - G_OBJECT_CLASS(pidgin_credentials_page_parent_class)->finalize(obj); -} - -static void -pidgin_credentials_page_init(PidginCredentialsPage *page) { - PurpleCredentialManager *manager = NULL; - const gchar *active = NULL; - - gtk_widget_init_template(GTK_WIDGET(page)); - - manager = purple_credential_manager_get_default(); - purple_credential_manager_foreach( - manager, - pidgin_credentials_page_create_row, - page->credential_list); - gtk_list_box_set_sort_func(GTK_LIST_BOX(page->credential_list), - pidgin_credentials_page_sort_rows, NULL, NULL); - - purple_prefs_connect_callback(page, "/purple/credentials/active-provider", - pidgin_credentials_page_active_provider_changed_cb, - page); - - active = purple_prefs_get_string("/purple/credentials/active-provider"); - if(active != NULL) { - pidgin_credentials_page_set_active_provider(page, active); - } -} - -static void -pidgin_credentials_page_class_init(PidginCredentialsPageClass *klass) { - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); - - obj_class->finalize = pidgin_credentials_page_finalize; - - gtk_widget_class_set_template_from_resource( - widget_class, - "/im/pidgin/Pidgin3/Prefs/credentials.ui" - ); - - gtk_widget_class_bind_template_child(widget_class, PidginCredentialsPage, - credential_list); - gtk_widget_class_bind_template_callback(widget_class, - pidgin_credential_page_list_row_activated_cb); -} - -/****************************************************************************** - * API - *****************************************************************************/ -GtkWidget * -pidgin_credentials_page_new(void) { - return GTK_WIDGET(g_object_new(PIDGIN_TYPE_CREDENTIALS_PAGE, NULL)); -}
--- a/pidgin/prefs/pidgincredentialspage.h Sun May 15 02:33:16 2022 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * 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 - * source distribution. - * - * 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, see <https://www.gnu.org/licenses/>. - */ - -#if !defined(PIDGIN_GLOBAL_HEADER_INSIDE) && !defined(PIDGIN_COMPILATION) -# error "only <pidgin.h> may be included directly" -#endif - -#ifndef PIDGIN_CREDENTIALS_PAGE_H -#define PIDGIN_CREDENTIALS_PAGE_H - -#include <glib.h> - -#include <gtk/gtk.h> -#include <handy.h> - -G_BEGIN_DECLS - -/** - * PIDGIN_TYPE_CREDENTIALS_PAGE: - * - * The standard _get_type macro for #PidginCredentialsPage. - * - * Since: 3.0.0 - */ -#define PIDGIN_TYPE_CREDENTIALS_PAGE (pidgin_credentials_page_get_type()) -G_DECLARE_FINAL_TYPE(PidginCredentialsPage, pidgin_credentials_page, - PIDGIN, CREDENTIALS_PAGE, HdyPreferencesPage) - -/** - * PidginCredentialsPage: - * - * #PidginCredentialsPage is a widget for the preferences window to let users - * choose and configure their credential provider. - * - * Since: 3.0.0 - */ - -/** - * pidgin_credentials_page_new: - * - * Creates a new #PidginCredentialsPage instance. - * - * Returns: (transfer full): The new #PidginCredentialsPage instance. - * - * Since: 3.0.0 - */ -GtkWidget *pidgin_credentials_page_new(void); - -G_END_DECLS - -#endif /* PIDGIN_CREDENTIALS_PAGE_H */
--- a/pidgin/resources/Prefs/credentials.ui Sun May 15 02:33:16 2022 -0500 +++ b/pidgin/resources/Prefs/credentials.ui Sun May 15 02:33:17 2022 -0500 @@ -26,7 +26,7 @@ <!-- interface-name Pidgin --> <!-- interface-description Internet Messenger --> <!-- interface-copyright Pidgin Developers <devel@pidgin.im> --> - <template class="PidginCredentialsPage" parent="HdyPreferencesPage"> + <template class="PidginCredentialPrefs" parent="HdyPreferencesPage"> <property name="visible">True</property> <property name="can-focus">False</property> <property name="title" translatable="yes">Credentials</property> @@ -41,7 +41,7 @@ <property name="visible">True</property> <property name="can-focus">False</property> <property name="selection-mode">none</property> - <signal name="row-activated" handler="pidgin_credential_page_list_row_activated_cb" after="yes" swapped="no"/> + <signal name="row-activated" handler="pidgin_credential_prefs_list_row_activated_cb" after="yes" swapped="no"/> <style> <class name="content"/> </style>
--- a/pidgin/resources/Prefs/prefs.ui Sun May 15 02:33:16 2022 -0500 +++ b/pidgin/resources/Prefs/prefs.ui Sun May 15 02:33:17 2022 -0500 @@ -127,7 +127,7 @@ </packing> </child> <child> - <object class="PidginCredentialsPage"> + <object class="PidginCredentialPrefs"> <property name="visible">True</property> <property name="can-focus">False</property> </object>