pidgin/pidgin

09b500dd62e7
Parents a050107a1268
Children c51a28d28a2d
Very simple approach to converting PidginMedia to GtkBuilder

Testing Done:
Verified that the window at looked like the pre gtk builder version.

Reviewed at https://reviews.imfreedom.org/r/1572/
--- a/pidgin/gtkmedia.c Thu Aug 04 16:11:11 2022 -0500
+++ b/pidgin/gtkmedia.c Mon Aug 08 20:23:17 2022 -0500
@@ -126,12 +126,21 @@
PROP_SCREENNAME
};
+static gboolean
+pidgin_media_delete_event_cb(GtkWidget *widget,
+ GdkEvent *event, PidginMedia *media)
+{
+ if (media->priv->media)
+ g_action_group_activate_action(G_ACTION_GROUP(media),
+ "Hangup", NULL);
+ return FALSE;
+}
static void
pidgin_media_class_init (PidginMediaClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-/* GtkContainerClass *container_class = (GtkContainerClass*)klass; */
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
gobject_class->dispose = pidgin_media_dispose;
gobject_class->finalize = pidgin_media_finalize;
@@ -150,6 +159,20 @@
"The screenname of the user this session is with.",
NULL,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ gtk_widget_class_set_template_from_resource(
+ widget_class,
+ "/im/pidgin/Pidgin3/Media/window.ui"
+ );
+
+ gtk_widget_class_bind_template_child_private(widget_class, PidginMedia,
+ display);
+ gtk_widget_class_bind_template_child_private(widget_class, PidginMedia,
+ statusbar);
+
+ gtk_widget_class_bind_template_callback(widget_class,
+ pidgin_media_delete_event_cb);
+
}
static void
@@ -204,16 +227,6 @@
g_simple_action_set_state(action, value);
}
-static gboolean
-pidgin_media_delete_event_cb(GtkWidget *widget,
- GdkEvent *event, PidginMedia *media)
-{
- if (media->priv->media)
- g_action_group_activate_action(G_ACTION_GROUP(media),
- "Hangup", NULL);
- return FALSE;
-}
-
static const GActionEntry media_action_entries[] = {
{ "Hangup", pidgin_media_hangup_activate_cb },
{ "Hold", NULL, NULL, "false", pidgin_media_hold_change_state_cb },
@@ -221,76 +234,19 @@
{ "Pause", NULL, NULL, "false", pidgin_media_pause_change_state_cb },
};
-static const gchar *media_menu =
-"<interface>"
- "<menu id='MediaMenu'>"
- "<submenu>"
- "<attribute name='label' translatable='yes'>_Media</attribute>"
- "<section>"
- "<item>"
- "<attribute name='label' translatable='yes'>_Hangup</attribute>"
- "<attribute name='action'>win.Hangup</attribute>"
- "</item>"
- "</section>"
- "</submenu>"
- "</menu>"
-"</interface>";
-
-static GtkWidget *
-setup_menubar(PidginMedia *window)
-{
- GError *error = NULL;
- GtkWidget *menu;
-
- window->priv->ui = gtk_builder_new();
- gtk_builder_set_translation_domain(window->priv->ui, PACKAGE);
-
- if (!gtk_builder_add_from_string(window->priv->ui, media_menu, -1, &error))
- {
- g_message("building menus failed: %s", error->message);
- g_error_free(error);
- exit(EXIT_FAILURE);
- }
-
- menu = gtk_menu_bar_new_from_model(G_MENU_MODEL(
- gtk_builder_get_object(window->priv->ui,
- "MediaMenu")));
-
- gtk_widget_show(menu);
- return menu;
-}
-
static void
pidgin_media_init (PidginMedia *media)
{
- GtkWidget *vbox;
media->priv = pidgin_media_get_instance_private(media);
+ gtk_widget_init_template(GTK_WIDGET(media));
+
g_action_map_add_action_entries(G_ACTION_MAP(media),
media_action_entries,
G_N_ELEMENTS(media_action_entries), media);
- vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_add(GTK_CONTAINER(media), vbox);
-
- media->priv->statusbar = gtk_statusbar_new();
- gtk_box_pack_end(GTK_BOX(vbox), media->priv->statusbar,
- FALSE, FALSE, 0);
gtk_statusbar_push(GTK_STATUSBAR(media->priv->statusbar),
0, _("Calling..."));
- gtk_widget_show(media->priv->statusbar);
-
- media->priv->menubar = setup_menubar(media);
- gtk_box_pack_start(GTK_BOX(vbox), media->priv->menubar,
- FALSE, TRUE, 0);
-
- media->priv->display = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_container_set_border_width(GTK_CONTAINER(media->priv->display), 6);
- gtk_box_pack_start(GTK_BOX(vbox), media->priv->display, TRUE, TRUE, 6);
- gtk_widget_show(vbox);
-
- g_signal_connect(G_OBJECT(media), "delete-event",
- G_CALLBACK(pidgin_media_delete_event_cb), media);
media->priv->recv_progressbars =
g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
@@ -1048,4 +1004,3 @@
purple_media_manager_set_active_element(manager, audio_sink);
#endif
}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/resources/Media/window.ui Mon Aug 08 20:23:17 2022 -0500
@@ -0,0 +1,101 @@
+<?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, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+-->
+<interface>
+ <requires lib="gtk+" version="3.24"/>
+ <!-- interface-license-type gplv2 -->
+ <!-- interface-name Pidgin -->
+ <!-- interface-description Internet Messenger -->
+ <!-- interface-copyright Pidgin Developers <devel@pidgin.im> -->
+ <template class="PidginMedia" parent="GtkApplicationWindow">
+ <property name="can-focus">False</property>
+ <signal name="delete-event" handler="pidgin_media_delete_event_cb" swapped="no"/>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkToolbar">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="toolbar-style">both</property>
+ <child>
+ <object class="GtkToolButton">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="tooltip-text" translatable="yes">Hangup</property>
+ <property name="action-name">win.Hangup</property>
+ <property name="label" translatable="yes">Hangup</property>
+ <property name="use-underline">True</property>
+ <property name="icon-name">media-playback-stop</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="display">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkStatusbar" id="statusbar">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="margin-left">10</property>
+ <property name="margin-right">10</property>
+ <property name="margin-start">10</property>
+ <property name="margin-end">10</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
--- a/pidgin/resources/pidgin.gresource.xml Thu Aug 04 16:11:11 2022 -0500
+++ b/pidgin/resources/pidgin.gresource.xml Mon Aug 08 20:23:17 2022 -0500
@@ -20,6 +20,7 @@
<file compressed="true">Debug/plugininfo.ui</file>
<file compressed="true">Keypad/keypad.ui</file>
<file compressed="true">Log/log-viewer.ui</file>
+ <file compressed="true">Media/window.ui</file>
<file compressed="true">Notifications/connectionerror.ui</file>
<file compressed="true">Notifications/list.ui</file>
<file compressed="true">Plugins/dialog.ui</file>
--- a/po/POTFILES.in Thu Aug 04 16:11:11 2022 -0500
+++ b/po/POTFILES.in Mon Aug 08 20:23:17 2022 -0500
@@ -408,6 +408,7 @@
pidgin/resources/Debug/plugininfo.ui
pidgin/resources/Keypad/keypad.ui
pidgin/resources/Log/log-viewer.ui
+pidgin/resources/Media/window.ui
pidgin/resources/Plugins/dialog.ui
pidgin/resources/Plugins/menu.ui
pidgin/resources/Prefs/away.ui