summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2022-02-09 23:02:11 +0100
committerBastien Nocera <hadess@hadess.net>2022-02-10 12:08:55 +0100
commitc3326d1b31b3b1e69a14053f173bef2593f02eba (patch)
treeeaafb1c4779f52a17fe3909f921b5d8723fa8790
parentd640ea6b62bd8de95f80fd5eedfc827edb4311c5 (diff)
downloadtotem-c3326d1b31b3b1e69a14053f173bef2593f02eba.tar.gz
main: Use template to create TotemOpenLocation
-rw-r--r--data/meson.build1
-rw-r--r--data/totem.gresource.xml1
-rw-r--r--data/uri.ui100
-rw-r--r--src/totem-open-location.c66
4 files changed, 83 insertions, 85 deletions
diff --git a/data/meson.build b/data/meson.build
index ce9790ed2..669621981 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -39,7 +39,6 @@ endif
ui_files = files(
'shortcuts.ui',
'totem.ui',
- 'uri.ui'
)
install_data(
diff --git a/data/totem.gresource.xml b/data/totem.gresource.xml
index 897ff8189..97e6f60ec 100644
--- a/data/totem.gresource.xml
+++ b/data/totem.gresource.xml
@@ -3,5 +3,6 @@
<gresource prefix="/org/gnome/totem/ui">
<file compressed="true">totem-preferences-dialog.ui</file>
<file compressed="true">playlist.ui</file>
+ <file compressed="true">uri.ui</file>
</gresource>
</gresources>
diff --git a/data/uri.ui b/data/uri.ui
index 3f86cfb24..71b61f07c 100644
--- a/data/uri.ui
+++ b/data/uri.ui
@@ -1,35 +1,69 @@
<?xml version="1.0" ?>
-<!DOCTYPE glade-interface
- SYSTEM 'glade-2.0.dtd'>
-<!--*- mode: xml -*--><interface>
-<object class="GtkVBox" id="open_uri_dialog_content">
- <property name="visible">True</property>
- <property name="border_width">5</property>
- <property name="spacing">6</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Enter the _address of the file you would like to open:</property>
- <property name="use_underline">True</property>
- <property name="wrap">True</property>
- <property name="mnemonic_widget">uri</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="uri">
- <property name="visible">True</property>
- <property name="activates_default">True</property>
- <signal name="changed" handler="uri_entry_changed_cb"/>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
-</object>
+<interface>
+<requires lib="gtk+" version="3.24"/>
+ <template class="TotemOpenLocation" parent="GtkDialog">
+ <property name="title" translatable="yes">Add Web Video</property>
+ <property name="type_hint">dialog</property>
+ <property name="modal">1</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="open_uri_dialog_content">
+ <property name="visible">True</property>
+ <property name="border_width">5</property>
+ <property name="spacing">6</property>
+ <property name="orientation">vertical</property>
+ <property name="expand">True</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Enter the _address of the file you would like to open:</property>
+ <property name="use_underline">True</property>
+ <property name="wrap">True</property>
+ <property name="mnemonic_widget">uri_entry</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="uri_entry">
+ <property name="visible">True</property>
+ <property name="activates_default">True</property>
+ <property name="width-chars">50</property>
+ <signal name="changed" handler="uri_entry_changed_cb"/>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child type="action">
+ <object class="GtkButton" id="cancel_button">
+ <property name="label" translatable="yes">_Cancel</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="use_underline">True</property>
+ <property name="receives-default">True</property>
+ </object>
+ </child>
+ <child type="action">
+ <object class="GtkButton" id="add_button">
+ <property name="label" translatable="yes">_Add</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="can-default">True</property>
+ <property name="has-default">True</property>
+ <property name="receives-default">True</property>
+ <property name="use_underline">True</property>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-6">cancel_button</action-widget>
+ <action-widget response="-5" default="True">add_button</action-widget>
+ </action-widgets>
+ <initial-focus name="uri_entry"/>
+ </template>
</interface>
diff --git a/src/totem-open-location.c b/src/totem-open-location.c
index 9a676db2d..40d225c30 100644
--- a/src/totem-open-location.c
+++ b/src/totem-open-location.c
@@ -40,9 +40,8 @@
#include "totem-open-location.h"
#include "totem-interface.h"
-struct _TotemOpenLocation
-{
- GtkWidget *uri_container;
+struct _TotemOpenLocation {
+ GtkDialog parent;
GtkEntry *uri_entry;
};
@@ -54,27 +53,10 @@ G_MODULE_EXPORT void uri_entry_changed_cb (GtkEditable *entry, GtkDialog *dialog
static void
totem_open_location_class_init (TotemOpenLocationClass *klass)
{
-}
-
-static void
-totem_open_location_init (TotemOpenLocation *self)
-{
- GtkBuilder *builder;
-
- builder = totem_interface_load ("uri.ui", FALSE, NULL, self);
+ GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
- if (builder == NULL)
- return;
-
- self->uri_container = GTK_WIDGET (gtk_builder_get_object (builder, "open_uri_dialog_content"));
- g_object_ref (self->uri_container);
-
- self->uri_entry = GTK_ENTRY (gtk_builder_get_object (builder, "uri"));
- gtk_entry_set_width_chars (self->uri_entry, 50);
-
- gtk_window_set_modal (GTK_WINDOW (self), TRUE);
-
- g_object_unref (builder);
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/totem/ui/uri.ui");
+ gtk_widget_class_bind_template_child (widget_class, TotemOpenLocation, uri_entry);
}
static gboolean
@@ -162,28 +144,21 @@ uri_entry_changed_cb (GtkEditable *entry, GtkDialog *dialog)
GtkWidget *
totem_open_location_new (void)
{
- TotemOpenLocation *open_location;
+ return GTK_WIDGET (g_object_new (TOTEM_TYPE_OPEN_LOCATION,
+ "use-header-bar", 1,
+ NULL));
+}
+
+static void
+totem_open_location_init (TotemOpenLocation *open_location)
+{
char *clipboard_location;
GtkEntryCompletion *completion;
GtkTreeModel *model;
GList *recent_items, *streams_recent_items = NULL;
- open_location = TOTEM_OPEN_LOCATION (g_object_new (TOTEM_TYPE_OPEN_LOCATION,
- "use-header-bar", 1, NULL));
-
- if (open_location->uri_container == NULL) {
- g_object_unref (open_location);
- return NULL;
- }
-
- gtk_window_set_title (GTK_WINDOW (open_location), _("Add Web Video"));
- gtk_dialog_add_buttons (GTK_DIALOG (open_location),
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("_Add"), GTK_RESPONSE_OK,
- NULL);
+ gtk_widget_init_template (GTK_WIDGET (open_location));
gtk_dialog_set_response_sensitive (GTK_DIALOG (open_location), GTK_RESPONSE_OK, FALSE);
- gtk_container_set_border_width (GTK_CONTAINER (open_location), 5);
- gtk_dialog_set_default_response (GTK_DIALOG (open_location), GTK_RESPONSE_OK);
/* Get item from clipboard to fill GtkEntry */
clipboard_location = totem_open_location_set_from_clipboard (open_location);
@@ -198,8 +173,7 @@ totem_open_location_new (void)
recent_items = gtk_recent_manager_get_items (gtk_recent_manager_get_default ());
- if (recent_items != NULL)
- {
+ if (recent_items != NULL) {
GList *p;
GtkTreeIter iter;
@@ -233,14 +207,4 @@ totem_open_location_new (void)
gtk_entry_completion_set_model (completion, model);
gtk_entry_completion_set_text_column (completion, 0);
gtk_entry_completion_set_match_func (completion, (GtkEntryCompletionMatchFunc) totem_open_location_match, model, NULL);
-
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (open_location))),
- open_location->uri_container,
- TRUE, /* expand */
- TRUE, /* fill */
- 0); /* padding */
-
- gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (open_location)));
-
- return GTK_WIDGET (open_location);
}