pidgin/pidgin

The start of the new account editor.

22 months ago, Gary Kramlich
e3bd18c1769d
Parents c51a28d28a2d
Children abadfc227738
The start of the new account editor.

Right now this just modifies proxy info, and uses some "secret" buttons so that
we don't have to break the existing account editor until this one is finished.

Testing Done:
Created a new account using the tau button.
Modified an account using the pi button and verified it's settings matched the old editor.
Modified an account using the old editor and verified that the new editor showed the changes.

Reviewed at https://reviews.imfreedom.org/r/1569/
--- a/pidgin/glade/pidgin3.xml.in Mon Aug 08 22:03:04 2022 -0500
+++ b/pidgin/glade/pidgin3.xml.in Mon Aug 08 22:14:37 2022 -0500
@@ -17,6 +17,7 @@
<glade-widget-class name="PidginPresenceIcon" generic-name="presence_icon" title="PresenceIcon"/>
<glade-widget-class name="PidginProtocolChooser" generic-name="protocol_chooser" title="ProtocolChooser"/>
<glade-widget-class name="PidginProtocolStore" generic-name="protocol_store" title="ProtocolStore"/>
+ <glade-widget-class name="PidginProxyOptions" generic-name="proxy_options" title="ProxyOptions"/>
<glade-widget-class name="PidginScrollBook" generic-name="scroll_book" title="ScrollBook"/>
<glade-widget-class name="PidginStatusBox" generic-name="status_box" title="StatusBox"/>
<glade-widget-class name="PidginStatusPrimitiveChooser" generic-name="status_primitive_chooser" title="StatusPrimitiveChooser"/>
@@ -39,6 +40,7 @@
<glade-widget-class-ref name="PidginPresenceIcon"/>
<glade-widget-class-ref name="PidginProtocolChooser"/>
<glade-widget-class-ref name="PidginProtocolStore"/>
+ <glade-widget-class-ref name="PidginProxyOptions"/>
<glade-widget-class-ref name="PidginScrollBook"/>
<glade-widget-class-ref name="PidginStatusBox"/>
<glade-widget-class-ref name="PidginStatusPrimitiveChooser"/>
--- a/pidgin/meson.build Mon Aug 08 22:03:04 2022 -0500
+++ b/pidgin/meson.build Mon Aug 08 22:14:37 2022 -0500
@@ -19,6 +19,7 @@
'minidialog.c',
'pidginabout.c',
'pidginaccountchooser.c',
+ 'pidginaccounteditor.c',
'pidginaccountfilterconnected.c',
'pidginaccountfilterprotocol.c',
'pidginaccountmanager.c',
@@ -93,6 +94,7 @@
'minidialog.h',
'pidginabout.h',
'pidginaccountchooser.h',
+ 'pidginaccounteditor.h',
'pidginaccountfilterconnected.h',
'pidginaccountfilterprotocol.h',
'pidginaccountmanager.h',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidginaccounteditor.c Mon Aug 08 22:14:37 2022 -0500
@@ -0,0 +1,217 @@
+/*
+ * 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 <glib/gi18n-lib.h>
+
+#include "pidginaccounteditor.h"
+
+#include "pidginproxyoptions.h"
+
+struct _PidginAccountEditor {
+ GtkDialog parent;
+
+ PurpleAccount *account;
+
+ GtkWidget *notebook;
+ GtkWidget *proxy_options;
+};
+
+enum {
+ PROP_0,
+ PROP_ACCOUNT,
+ N_PROPERTIES,
+};
+static GParamSpec *properties[N_PROPERTIES] = {NULL, };
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+pidgin_account_editor_set_account(PidginAccountEditor *editor,
+ PurpleAccount *account)
+{
+ if(g_set_object(&editor->account, account)) {
+ PurpleProxyInfo *proxy_info = NULL;
+
+ if(PURPLE_IS_ACCOUNT(account)) {
+ proxy_info = purple_account_get_proxy_info(account);
+ }
+
+ pidgin_proxy_options_set_info(PIDGIN_PROXY_OPTIONS(editor->proxy_options),
+ proxy_info);
+
+ g_object_notify_by_pspec(G_OBJECT(editor), properties[PROP_ACCOUNT]);
+ }
+}
+
+static void
+pidgin_account_editor_save_account(PidginAccountEditor *editor) {
+ PurpleAccountManager *manager = NULL;
+ PurpleProxyInfo *info = NULL;
+ gboolean new_account = FALSE;
+
+ manager = purple_account_manager_get_default();
+
+ if(!PURPLE_IS_ACCOUNT(editor->account)) {
+ editor->account = purple_account_new("undefined", "undefined");
+ new_account = TRUE;
+ }
+
+ info = pidgin_proxy_options_get_info(PIDGIN_PROXY_OPTIONS(editor->proxy_options));
+ purple_account_set_proxy_info(editor->account, info);
+
+ /* If this is a new account, add it to the account manager and bring it
+ * online.
+ */
+ if(new_account) {
+ const PurpleSavedStatus *saved_status;
+
+ purple_account_manager_add(manager, editor->account);
+
+ saved_status = purple_savedstatus_get_current();
+ if (saved_status != NULL) {
+ purple_savedstatus_activate_for_account(saved_status,
+ editor->account);
+ purple_account_set_enabled(editor->account, TRUE);
+ }
+ }
+}
+
+/******************************************************************************
+ * Callbacks
+ *****************************************************************************/
+static void
+pidgin_account_editor_response_cb(GtkDialog *dialog, gint response_id,
+ G_GNUC_UNUSED gpointer data)
+{
+ if(response_id == GTK_RESPONSE_APPLY) {
+ pidgin_account_editor_save_account(PIDGIN_ACCOUNT_EDITOR(dialog));
+ }
+
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+}
+
+/******************************************************************************
+ * GObject Implementation
+ *****************************************************************************/
+G_DEFINE_TYPE(PidginAccountEditor, pidgin_account_editor, GTK_TYPE_DIALOG)
+
+static void
+pidgin_account_editor_get_property(GObject *obj, guint param_id, GValue *value,
+ GParamSpec *pspec)
+{
+ PidginAccountEditor *editor = PIDGIN_ACCOUNT_EDITOR(obj);
+
+ switch(param_id) {
+ case PROP_ACCOUNT:
+ g_value_set_object(value,
+ pidgin_account_editor_get_account(editor));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+ break;
+ }
+}
+
+static void
+pidgin_account_editor_set_property(GObject *obj, guint param_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ PidginAccountEditor *editor = PIDGIN_ACCOUNT_EDITOR(obj);
+
+ switch(param_id) {
+ case PROP_ACCOUNT:
+ pidgin_account_editor_set_account(editor,
+ g_value_get_object(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+ break;
+ }
+}
+
+static void
+pidgin_account_editor_dispose(GObject *obj) {
+ PidginAccountEditor *editor = PIDGIN_ACCOUNT_EDITOR(obj);
+
+ g_clear_object(&editor->account);
+
+ G_OBJECT_CLASS(pidgin_account_editor_parent_class)->dispose(obj);
+}
+
+static void
+pidgin_account_editor_init(PidginAccountEditor *account_editor) {
+ GtkWidget *widget = GTK_WIDGET(account_editor);
+
+ gtk_widget_init_template(widget);
+}
+
+static void
+pidgin_account_editor_class_init(PidginAccountEditorClass *klass) {
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+
+ obj_class->get_property = pidgin_account_editor_get_property;
+ obj_class->set_property = pidgin_account_editor_set_property;
+ obj_class->dispose = pidgin_account_editor_dispose;
+
+ /**
+ * PidginAccountEditor::account:
+ *
+ * The account that this editor is modifying.
+ *
+ * Since: 3.0.0
+ */
+ properties[PROP_ACCOUNT] = g_param_spec_object(
+ "account", "account",
+ "The account to modify",
+ PURPLE_TYPE_ACCOUNT,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
+
+ gtk_widget_class_set_template_from_resource(widget_class,
+ "/im/pidgin/Pidgin3/Accounts/editor.ui");
+
+ gtk_widget_class_bind_template_child(widget_class, PidginAccountEditor,
+ notebook);
+ gtk_widget_class_bind_template_child(widget_class, PidginAccountEditor,
+ proxy_options);
+
+ gtk_widget_class_bind_template_callback(widget_class,
+ pidgin_account_editor_response_cb);
+}
+
+/******************************************************************************
+ * API
+ *****************************************************************************/
+GtkWidget *
+pidgin_account_editor_new(PurpleAccount *account) {
+ return g_object_new(PIDGIN_TYPE_ACCOUNT_EDITOR, "account", account, NULL);
+}
+
+PurpleAccount *
+pidgin_account_editor_get_account(PidginAccountEditor *editor) {
+ g_return_val_if_fail(PIDGIN_IS_ACCOUNT_EDITOR(editor), NULL);
+
+ return editor->account;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidginaccounteditor.h Mon Aug 08 22:14:37 2022 -0500
@@ -0,0 +1,75 @@
+/*
+ * 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_ACCOUNT_EDITOR_H
+#define PIDGIN_ACCOUNT_EDITOR_H
+
+#include <gtk/gtk.h>
+
+#include <purple.h>
+
+/**
+ * PidginAccountEditor:
+ *
+ * #PidginAccountEditor is a dialog that allows you to edit an account.
+ *
+ * Since: 3.0.0
+ */
+
+G_BEGIN_DECLS
+
+#define PIDGIN_TYPE_ACCOUNT_EDITOR pidgin_account_editor_get_type()
+G_DECLARE_FINAL_TYPE(PidginAccountEditor, pidgin_account_editor, PIDGIN,
+ ACCOUNT_EDITOR, GtkDialog)
+
+/**
+ * pidgin_account_editor_new:
+ * @account: (nullable): The [class@Purple.Account] to edit.
+ *
+ * Creates a new #PidginAccountEditor for @account. If @account is %NULL, the
+ * editor will create a new account.
+ *
+ * Returns: (transfer full): The new instance.
+ *
+ * Since: 3.0.0
+ */
+GtkWidget *pidgin_account_editor_new(PurpleAccount *account);
+
+/**
+ * pidgin_account_editor_get_account:
+ * @editor: The instance.
+ *
+ * Gets the [class@Purple.Account] that @editor is modifying.
+ *
+ * Returns: (transfer none): The [class@Purple.Account] or %NULL.
+ *
+ * Since: 3.0.0
+ */
+PurpleAccount *pidgin_account_editor_get_account(PidginAccountEditor *editor);
+
+G_END_DECLS
+
+#endif /* PIDGIN_ACCOUNT_EDITOR_H */
--- a/pidgin/pidginaccountmanager.c Mon Aug 08 22:03:04 2022 -0500
+++ b/pidgin/pidginaccountmanager.c Mon Aug 08 22:14:37 2022 -0500
@@ -28,6 +28,7 @@
#include "gtkaccount.h"
#include "pidgincore.h"
+#include "pidginaccounteditor.h"
struct _PidginAccountManager {
GtkDialog parent;
@@ -42,7 +43,9 @@
enum {
RESPONSE_ADD,
RESPONSE_MODIFY,
- RESPONSE_REMOVE
+ RESPONSE_REMOVE,
+ RESPONSE_ADD_OLD,
+ RESPONSE_MODIFY_OLD
};
enum {
@@ -209,14 +212,27 @@
{
PidginAccountManager *manager = PIDGIN_ACCOUNT_MANAGER(dialog);
PurpleAccount *account = NULL;
+ GtkWidget *editor = NULL;
switch(response_id) {
case RESPONSE_ADD:
+ editor = pidgin_account_editor_new(NULL);
+ gtk_widget_show_all(editor);
+ break;
+ case RESPONSE_ADD_OLD:
pidgin_account_dialog_show(PIDGIN_ADD_ACCOUNT_DIALOG, NULL);
break;
case RESPONSE_MODIFY:
account = pidgin_account_manager_get_selected_account(manager);
+ editor = pidgin_account_editor_new(account);
+ gtk_widget_show_all(editor);
+
+ g_clear_object(&account);
+ break;
+ case RESPONSE_MODIFY_OLD:
+ account = pidgin_account_manager_get_selected_account(manager);
+
pidgin_account_dialog_show(PIDGIN_MODIFY_ACCOUNT_DIALOG, account);
g_clear_object(&account);
--- a/pidgin/pidginproxyoptions.h Mon Aug 08 22:03:04 2022 -0500
+++ b/pidgin/pidginproxyoptions.h Mon Aug 08 22:14:37 2022 -0500
@@ -95,7 +95,7 @@
/**
* pidgin_proxy_options_set_info:
* @options: The instance.
- * @info: The [class@Purple.ProxyInfo] to set.
+ * @info: (nullable): The [class@Purple.ProxyInfo] to set.
*
* The proxy info that will be configured.
*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/resources/Accounts/editor.ui Mon Aug 08 22:14:37 2022 -0500
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2
+
+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, see <https://www.gnu.org/licenses/>.
+
+-->
+<interface>
+ <requires lib="gtk+" version="3.24"/>
+ <requires lib="pidgin" version="3.0"/>
+ <!-- interface-license-type gplv2 -->
+ <!-- interface-name Pidgin -->
+ <!-- interface-description Internet Messenger -->
+ <!-- interface-copyright Pidgin Developers <devel@pidgin.im> -->
+ <template class="PidginAccountEditor" parent="GtkDialog">
+ <property name="can-focus">False</property>
+ <property name="type-hint">dialog</property>
+ <signal name="response" handler="pidgin_account_editor_response_cb" swapped="no"/>
+ <child internal-child="vbox">
+ <object class="GtkBox">
+ <property name="can-focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox">
+ <property name="can-focus">False</property>
+ <property name="layout-style">end</property>
+ <child>
+ <object class="GtkButton" id="button1">
+ <property name="label" translatable="yes">_Cancel</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ <property name="use-underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button2">
+ <property name="label" translatable="yes">_Save</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ <property name="use-underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkNotebook" id="notebook">
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <child>
+ <object class="PidginProxyOptions" id="proxy_options">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="margin-left">12</property>
+ <property name="margin-right">12</property>
+ <property name="margin-start">12</property>
+ <property name="margin-end">12</property>
+ <property name="margin-top">12</property>
+ <property name="margin-bottom">12</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="label" translatable="yes">_Proxy</property>
+ <property name="use-underline">True</property>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ <property name="tab-fill">False</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-6">button1</action-widget>
+ <action-widget response="-10">button2</action-widget>
+ </action-widgets>
+ </template>
+</interface>
--- a/pidgin/resources/Accounts/manager.ui Mon Aug 08 22:03:04 2022 -0500
+++ b/pidgin/resources/Accounts/manager.ui Mon Aug 08 22:14:37 2022 -0500
@@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses/>.
+
-->
<interface>
<requires lib="gtk+" version="3.24"/>
@@ -56,6 +57,42 @@
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
+ <object class="GtkButton" id="button1">
+ <property name="label" translatable="yes">τ</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ <style>
+ <class name="circular"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ <property name="non-homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="praetorians">
+ <property name="label" translatable="yes">π</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="focus-on-click">False</property>
+ <property name="receives-default">True</property>
+ <property name="relief">none</property>
+ <style>
+ <class name="circular"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ <property name="non-homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkButton" id="button3">
<property name="label" translatable="yes">_Add...</property>
<property name="visible">True</property>
@@ -66,7 +103,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">0</property>
+ <property name="position">2</property>
</packing>
</child>
<child>
@@ -81,7 +118,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="position">3</property>
</packing>
</child>
<child>
@@ -96,7 +133,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">4</property>
</packing>
</child>
<child>
@@ -110,7 +147,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">3</property>
+ <property name="position">5</property>
</packing>
</child>
</object>
@@ -197,8 +234,10 @@
</object>
</child>
<action-widgets>
- <action-widget response="0">button3</action-widget>
- <action-widget response="1">modify_button</action-widget>
+ <action-widget response="0">button1</action-widget>
+ <action-widget response="1">praetorians</action-widget>
+ <action-widget response="3">button3</action-widget>
+ <action-widget response="4">modify_button</action-widget>
<action-widget response="2">remove_button</action-widget>
<action-widget response="-7">button2</action-widget>
</action-widgets>
--- a/pidgin/resources/pidgin.gresource.xml Mon Aug 08 22:03:04 2022 -0500
+++ b/pidgin/resources/pidgin.gresource.xml Mon Aug 08 22:14:37 2022 -0500
@@ -6,6 +6,7 @@
<file compressed="true">About/about.md</file>
<file compressed="true">About/credits.json</file>
<file compressed="true">Accounts/chooser.ui</file>
+ <file compressed="true">Accounts/editor.ui</file>
<file compressed="true">Accounts/entry.css</file>
<file compressed="true">Accounts/manager.ui</file>
<file compressed="true">Avatar/avatar.ui</file>
--- a/po/POTFILES.in Mon Aug 08 22:03:04 2022 -0500
+++ b/po/POTFILES.in Mon Aug 08 22:14:37 2022 -0500
@@ -335,6 +335,7 @@
pidgin/minidialog.c
pidgin/pidginabout.c
pidgin/pidginaccountchooser.c
+pidgin/pidginaccounteditor.c
pidgin/pidginaccountfilterconnected.c
pidgin/pidginaccountfilterprotocol.c
pidgin/pidginaccountmanager.c
@@ -397,6 +398,7 @@
pidgin/prefs/pidginvvprefs.c
pidgin/resources/About/about.ui
pidgin/resources/Accounts/chooser.ui
+pidgin/resources/Accounts/editor.ui
pidgin/resources/Accounts/manager.ui
pidgin/resources/Avatar/avatar.ui
pidgin/resources/Avatar/menu.ui