pidgin/prefs/pidginawayprefs.c

Mon, 29 Aug 2022 22:06:07 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Mon, 29 Aug 2022 22:06:07 -0500
changeset 41623
78cf94d0f8c8
parent 41622
4e81efb6f325
child 41640
d8636f8db50a
permissions
-rw-r--r--

Move network preferences to Adwaita preference widgets

This does make the TURN server settings longer vertically, but that seems more consistent with everything.

Also fix the `leave` event on the TURN server setting.

Testing Done:
Toggled all the options and checked that stuff happened in the Debug Window.

Also, I'm not sure why the `GtkSpinButton` and `GtkEntry` expand to different sizes; they both have `hexpand=1`, and the spin button is next to text that's _shorter_ than the entry, but somehow ends up farther right. Seems like a bug in GTK.

PS, be careful of this page; it tries to get your public IP address and displays it when it succeeds.

Reviewed at https://reviews.imfreedom.org/r/1680/

/*
 * 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 <adwaita.h>

#include "pidginawayprefs.h"
#include "gtksavedstatuses.h"
#include "gtkutils.h"
#include "pidginprefsinternal.h"

struct _PidginAwayPrefs {
	AdwPreferencesPage parent;

	PidginPrefCombo idle_reporting;
	GtkWidget *mins_before_away;
	GtkWidget *idle_row;
	GtkWidget *away_when_idle;
	PidginPrefCombo auto_reply;
	GtkWidget *startup_current_status;
	GtkWidget *startup_row;
};

G_DEFINE_TYPE(PidginAwayPrefs, pidgin_away_prefs, ADW_TYPE_PREFERENCES_PAGE)

/******************************************************************************
 * Helpers
 *****************************************************************************/
static void
set_idle_away(PurpleSavedStatus *status)
{
	purple_prefs_set_int("/purple/savedstatus/idleaway",
	                     purple_savedstatus_get_creation_time(status));
}

static void
set_startupstatus(PurpleSavedStatus *status)
{
	purple_prefs_set_int("/purple/savedstatus/startup",
	                     purple_savedstatus_get_creation_time(status));
}

/******************************************************************************
 * GObject Implementation
 *****************************************************************************/
static void
pidgin_away_prefs_class_init(PidginAwayPrefsClass *klass)
{
	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);

	gtk_widget_class_set_template_from_resource(
	    widget_class,
	    "/im/pidgin/Pidgin3/Prefs/away.ui"
	);

	gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs,
	                                     idle_reporting.combo);
	gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs,
	                                     mins_before_away);
	gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs,
	                                     away_when_idle);
	gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs,
	                                     idle_row);
	gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs,
	                                     auto_reply.combo);
	gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs,
	                                     startup_current_status);
	gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs,
	                                     startup_row);
}

static void
pidgin_away_prefs_init(PidginAwayPrefs *prefs)
{
	GtkWidget *menu;

	gtk_widget_init_template(GTK_WIDGET(prefs));

	prefs->idle_reporting.type = PURPLE_PREF_STRING;
	prefs->idle_reporting.key = "/purple/away/idle_reporting";
	pidgin_prefs_bind_dropdown(&prefs->idle_reporting);

	pidgin_prefs_bind_spin_button("/purple/away/mins_before_away",
			prefs->mins_before_away);

	pidgin_prefs_bind_switch("/purple/away/away_when_idle",
	                         prefs->away_when_idle);

	/* TODO: Show something useful if we don't have any saved statuses. */
	menu = pidgin_status_menu(purple_savedstatus_get_idleaway(),
	                          G_CALLBACK(set_idle_away));
	gtk_widget_set_valign(menu, GTK_ALIGN_CENTER);
	adw_action_row_add_suffix(ADW_ACTION_ROW(prefs->idle_row), menu);
	adw_action_row_set_activatable_widget(ADW_ACTION_ROW(prefs->idle_row),
	                                      menu);

	g_object_bind_property(prefs->away_when_idle, "active",
			menu, "sensitive",
			G_BINDING_SYNC_CREATE);

	/* Away stuff */
	prefs->auto_reply.type = PURPLE_PREF_STRING;
	prefs->auto_reply.key = "/purple/away/auto_reply";
	pidgin_prefs_bind_dropdown(&prefs->auto_reply);

	/* Signon status stuff */
	pidgin_prefs_bind_switch("/purple/savedstatus/startup_current_status",
	                         prefs->startup_current_status);

	/* TODO: Show something useful if we don't have any saved statuses. */
	menu = pidgin_status_menu(purple_savedstatus_get_startup(),
	                          G_CALLBACK(set_startupstatus));
	gtk_widget_set_valign(menu, GTK_ALIGN_CENTER);
	adw_action_row_add_suffix(ADW_ACTION_ROW(prefs->startup_row), menu);
	adw_action_row_set_activatable_widget(ADW_ACTION_ROW(prefs->startup_row),
	                                      menu);
	g_object_bind_property(prefs->startup_current_status, "active",
	                       prefs->startup_row, "sensitive",
	                       G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
}

/******************************************************************************
 * API
 *****************************************************************************/
GtkWidget *
pidgin_away_prefs_new(void) {
	return GTK_WIDGET(g_object_new(PIDGIN_TYPE_AWAY_PREFS, NULL));
}

mercurial