[evince/wip/gpoo/gtk4-rebase-port: 72/72] previewer: Port EvPreviewerWindow to gtk4 with composite template
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/gpoo/gtk4-rebase-port: 72/72] previewer: Port EvPreviewerWindow to gtk4 with composite template
- Date: Mon, 21 Mar 2022 05:37:34 +0000 (UTC)
commit 2701ae7584d5d7dafb86f7b1988f138a724c191f
Author: Qiu Wenbo <qiuwenbo kylinos com cn>
Date: Mon Aug 30 17:12:09 2021 +0800
previewer: Port EvPreviewerWindow to gtk4 with composite template
previewer/ev-previewer-toolbar.c | 198 --------------------------------------
previewer/ev-previewer-toolbar.h | 51 ----------
previewer/ev-previewer-window.c | 105 ++++++--------------
previewer/ev-previewer.c | 10 +-
previewer/meson.build | 6 +-
previewer/previewer-window.ui | 82 ++++++++++++++++
previewer/previewer.gresource.xml | 5 +-
previewer/previewer.ui | 79 ---------------
8 files changed, 118 insertions(+), 418 deletions(-)
---
diff --git a/previewer/ev-previewer-window.c b/previewer/ev-previewer-window.c
index c0f330174..c3403a654 100644
--- a/previewer/ev-previewer-window.c
+++ b/previewer/ev-previewer-window.c
@@ -1,4 +1,4 @@
-/* ev-previewer-window.c:
+/* ev-previewer-window.c:
* this file is part of evince, a gnome document viewer
*
* Copyright (C) 2009 Carlos Garcia Campos <carlosgc gnome org>
@@ -28,21 +28,21 @@
#include <gtk/gtkunixprint.h>
#endif
#include <glib/gi18n.h>
+#include <adwaita.h>
#include <evince-view.h>
#include "ev-page-action-widget.h"
#include "ev-previewer-window.h"
-#include "ev-previewer-toolbar.h"
struct _EvPreviewerWindow {
- GtkApplicationWindow base_instance;
+ AdwApplicationWindow base_instance;
EvJob *job;
EvDocumentModel *model;
EvDocument *document;
EvView *view;
- GtkWidget *toolbar;
+ GtkWidget *page_selector;
/* Printing */
GtkPrintSettings *print_settings;
@@ -56,13 +56,13 @@ struct _EvPreviewerWindow {
};
struct _EvPreviewerWindowClass {
- GtkApplicationWindowClass base_class;
+ AdwApplicationWindowClass base_class;
};
#define MIN_SCALE 0.05409
#define MAX_SCALE 4.0
-G_DEFINE_TYPE (EvPreviewerWindow, ev_previewer_window, GTK_TYPE_APPLICATION_WINDOW)
+G_DEFINE_TYPE (EvPreviewerWindow, ev_previewer_window, ADW_TYPE_APPLICATION_WINDOW)
static void
ev_previewer_window_error_dialog_run (EvPreviewerWindow *window,
@@ -78,8 +78,8 @@ ev_previewer_window_error_dialog_run (EvPreviewerWindow *window,
"%s", _("Failed to print document"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", error->message);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
+
+ gtk_widget_show (dialog);
}
static void
@@ -87,9 +87,7 @@ ev_previewer_window_close (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (user_data);
-
- gtk_widget_destroy (GTK_WIDGET (window));
+ gtk_window_destroy (GTK_WINDOW (user_data));
}
static void
@@ -146,7 +144,7 @@ ev_previewer_window_zoom_default (GSimpleAction *action,
}
static void
-ev_previewer_window_action_page_activated (GtkAction *action,
+ev_previewer_window_action_page_activated (GObject *object,
EvLink *link,
EvPreviewerWindow *window)
{
@@ -160,10 +158,8 @@ ev_previewer_window_focus_page_selector (GSimpleAction *action,
gpointer user_data)
{
EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (user_data);
- GtkWidget *page_selector;
- page_selector = ev_previewer_toolbar_get_page_selector (EV_PREVIEWER_TOOLBAR (window->toolbar));
- ev_page_action_widget_grab_focus (EV_PAGE_ACTION_WIDGET (page_selector));
+ ev_page_action_widget_grab_focus (EV_PAGE_ACTION_WIDGET (window->page_selector));
}
#if GTKUNIXPRINT_ENABLED
@@ -178,7 +174,7 @@ ev_previewer_window_print_finished (GtkPrintJob *print_job,
}
g_object_unref (print_job);
- gtk_widget_destroy (GTK_WIDGET (window));
+ gtk_window_destroy (GTK_WINDOW (window));
}
static void
@@ -410,99 +406,44 @@ ev_previewer_window_init (EvPreviewerWindow *window)
{
window->source_fd = -1;
- gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
+ gtk_widget_init_template (GTK_WIDGET (window));
g_action_map_add_action_entries (G_ACTION_MAP (window),
actions, G_N_ELEMENTS (actions),
window);
-
- gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
-}
-
-static gboolean
-_gtk_css_provider_load_from_resource (GtkCssProvider *provider,
- const char *resource_path,
- GError **error)
-{
- GBytes *data;
- gboolean retval;
-
- data = g_resources_lookup_data (resource_path, 0, error);
- if (!data)
- return FALSE;
-
- retval = gtk_css_provider_load_from_data (provider,
- g_bytes_get_data (data, NULL),
- g_bytes_get_size (data),
- error);
- g_bytes_unref (data);
-
- return retval;
}
static void
ev_previewer_window_constructed (GObject *object)
{
EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (object);
- GtkWidget *vbox;
- GtkWidget *swindow;
- GError *error = NULL;
gdouble dpi;
- GtkCssProvider *css_provider;
G_OBJECT_CLASS (ev_previewer_window_parent_class)->constructed (object);
window->model = ev_document_model_new ();
+ ev_document_model_set_continuous (window->model, FALSE);
+
+ ev_view_set_model (window->view, window->model);
+ ev_page_action_widget_set_model (EV_PAGE_ACTION_WIDGET (window->page_selector),
+ window->model);
dpi = ev_document_misc_get_widget_dpi (GTK_WIDGET (window));
ev_document_model_set_min_scale (window->model, MIN_SCALE * dpi / 72.0);
ev_document_model_set_max_scale (window->model, MAX_SCALE * dpi / 72.0);
ev_document_model_set_sizing_mode (window->model, EV_SIZING_AUTOMATIC);
- css_provider = gtk_css_provider_new ();
- _gtk_css_provider_load_from_resource (css_provider,
- "/org/gnome/evince/previewer/ui/evince-previewer.css",
- &error);
- g_assert_no_error (error);
- gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)),
- GTK_STYLE_PROVIDER (css_provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- g_object_unref (css_provider);
-
view_sizing_mode_changed (window->model, NULL, window);
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-
- window->toolbar = ev_previewer_toolbar_new (window);
- gtk_widget_set_no_show_all (window->toolbar, TRUE);
- gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (window->toolbar),
- TRUE);
- gtk_window_set_titlebar (GTK_WINDOW (window), window->toolbar);
- gtk_widget_show (window->toolbar);
-
- g_signal_connect (ev_previewer_toolbar_get_page_selector (EV_PREVIEWER_TOOLBAR (window->toolbar)),
+ g_signal_connect (window->page_selector,
"activate-link",
G_CALLBACK (ev_previewer_window_action_page_activated),
window);
- swindow = gtk_scrolled_window_new (NULL, NULL);
-
- window->view = EV_VIEW (ev_view_new ());
- ev_view_set_model (window->view, window->model);
- ev_document_model_set_continuous (window->model, FALSE);
g_signal_connect_object (window->model, "page-changed",
G_CALLBACK (model_page_changed),
window, 0);
-
- gtk_container_add (GTK_CONTAINER (swindow), GTK_WIDGET (window->view));
- gtk_widget_show (GTK_WIDGET (window->view));
-
- gtk_box_pack_start (GTK_BOX (vbox), swindow, TRUE, TRUE, 0);
- gtk_widget_show (swindow);
-
- gtk_container_add (GTK_CONTAINER (window), vbox);
- gtk_widget_show (vbox);
}
@@ -510,9 +451,17 @@ static void
ev_previewer_window_class_init (EvPreviewerWindowClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gobject_class->constructed = ev_previewer_window_constructed;
gobject_class->dispose = ev_previewer_window_dispose;
+
+ g_type_ensure (EV_TYPE_PAGE_ACTION_WIDGET);
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/evince/previewer/ui/previewer-window.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, EvPreviewerWindow, view);
+ gtk_widget_class_bind_template_child (widget_class, EvPreviewerWindow, page_selector);
}
/* Public methods */
diff --git a/previewer/ev-previewer.c b/previewer/ev-previewer.c
index 4754adc5b..b42557bfe 100644
--- a/previewer/ev-previewer.c
+++ b/previewer/ev-previewer.c
@@ -29,7 +29,7 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
-#include <handy.h>
+#include <adwaita.h>
#include <evince-document.h>
#include <evince-view.h>
@@ -244,7 +244,7 @@ check_arguments (int argc,
gint
main (gint argc, gchar **argv)
{
- GtkApplication *application;
+ AdwApplication *application;
GOptionContext *context;
GError *error = NULL;
int status = 1;
@@ -298,8 +298,6 @@ main (gint argc, gchar **argv)
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE);
- g_option_context_add_group (context, gtk_get_option_group (TRUE));
-
if (!g_option_context_parse (context, &argc, &argv, &error) ||
!check_arguments (argc, argv, &error)) {
g_printerr ("Error parsing command line arguments: %s\n", error->message);
@@ -317,7 +315,9 @@ main (gint argc, gchar **argv)
g_set_application_name (_("GNOME Document Previewer"));
gtk_window_set_default_icon_name (PACKAGE_ICON_NAME);
- application = gtk_application_new (NULL, G_APPLICATION_NON_UNIQUE);
+ application = adw_application_new (NULL, G_APPLICATION_NON_UNIQUE);
+ g_application_set_resource_base_path (G_APPLICATION (application),
+ "/org/gnome/evince/previewer");
g_signal_connect (application, "startup", G_CALLBACK (startup_cb), NULL);
g_signal_connect (application, "activate", G_CALLBACK (activate_cb), NULL);
diff --git a/previewer/meson.build b/previewer/meson.build
index 389c75c50..30b2077bd 100644
--- a/previewer/meson.build
+++ b/previewer/meson.build
@@ -1,6 +1,5 @@
previewer_sources = files(
- 'ev-previewer-toolbar.c',
- 'ev-previewer-toolbar.h',
+ 'ev-previewer.c',
'ev-previewer-window.c',
'ev-previewer-window.h',
'ev-previewer.c',
@@ -9,7 +8,6 @@ previewer_sources = files(
resource_data = files(
'../data/thumbnail-frame.png',
'evince-previewer.css',
- 'previewer.ui',
)
previewer_sources += gnome.compile_resources(
@@ -24,7 +22,7 @@ previewer_deps = [
libevdocument_dep,
libevmisc_dep,
libevview_dep,
- hdy_dep
+ libaw_dep,
]
if enable_gtk_unix_print
diff --git a/previewer/previewer-window.ui b/previewer/previewer-window.ui
new file mode 100644
index 000000000..fcfa88a25
--- /dev/null
+++ b/previewer/previewer-window.ui
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk" version="4.0" />
+ <requires lib="libadwaita" version="1.0" />
+ <template class="EvPreviewerWindow" parent="AdwApplicationWindow">
+ <property name="default-width">600</property>
+ <property name="default-height">600</property>
+ <property name="title"></property>
+
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="AdwHeaderBar">
+ <child>
+ <object class="GtkButton" id="go-previous-page">
+ <property name="tooltip-text" translatable="yes">Previous Page</property>
+ <property name="action-name">win.go-previous-page</property>
+ <property name="icon-name">go-up-symbolic</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="go-next-page">
+ <property name="tooltip-text" translatable="yes">Next Page</property>
+ <property name="action-name">win.go-next-page</property>
+ <property name="icon-name">go-down-symbolic</property>
+ </object>
+ </child>
+ <child>
+ <object class="EvPageActionWidget" id="page_selector">
+ <property name="tooltip-text" translatable="yes">Select Page or Search in the
Index</property>
+ </object>
+ </child>
+
+ <child type="end">
+ <object class="GtkButton" id="print">
+ <property name="label" translatable="yes">_Print</property>
+ <property name="tooltip-text" translatable="yes">Print this Document</property>
+ <property name="action-name">win.print</property>
+ <property name="use-underline">True</property>
+ <style>
+ <class name="suggested-action" />
+ </style>
+ </object>
+ </child>
+ <child type="end">
+ <object class="GtkButton" id="zoom-out">
+ <property name="tooltip-text" translatable="yes">Shrink the Document</property>
+ <property name="action-name">win.zoom-out</property>
+ <property name="icon-name">zoom-out-symbolic</property>
+ </object>
+ </child>
+ <child type="end">
+ <object class="GtkButton" id="zoom-default">
+ <property name="tooltip-text" translatable="yes">Reset Zoom and Make the Page Fit in the
Window</property>
+ <property name="action-name">win.zoom-default</property>
+ <property name="icon-name">zoom-fit-best-symbolic</property>
+ </object>
+ </child>
+ <child type="end">
+ <object class="GtkButton" id="zoom-in">
+ <property name="tooltip-text" translatable="yes">Enlarge the Document</property>
+ <property name="action-name">win.zoom-in</property>
+ <property name="icon-name">zoom-in-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <child>
+ <object class="EvView" id="view" />
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/previewer/previewer.gresource.xml b/previewer/previewer.gresource.xml
index 26872ad28..34c142585 100644
--- a/previewer/previewer.gresource.xml
+++ b/previewer/previewer.gresource.xml
@@ -17,8 +17,7 @@
-->
<gresources>
<gresource prefix="/org/gnome/evince/previewer">
- <file alias="ui/previewer.ui" compressed="true" preprocess="xml-stripblanks">previewer.ui</file>
- <file alias="ui/evince-previewer.css" compressed="true">evince-previewer.css</file>
- <file alias="ui/thumbnail-frame.png" compressed="true">thumbnail-frame.png</file>
+ <file alias="ui/previewer-window.ui" compressed="true"
preprocess="xml-stripblanks">previewer-window.ui</file>
+ <file alias="style.css" compressed="true">evince-previewer.css</file>
</gresource>
</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]