From 608cbc28af20a6775aff5256827bb5b3ea6f6e41 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 28 Jun 2020 08:33:17 -0400 Subject: [PATCH 1/3] printeditor: Cosmetics Bring this up to our standards for an installable demo, by touching up the about dialog and menus. --- demos/print-editor/print-editor.c | 90 +++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 27 deletions(-) diff --git a/demos/print-editor/print-editor.c b/demos/print-editor/print-editor.c index 79e9b0d807..158ea873b1 100644 --- a/demos/print-editor/print-editor.c +++ b/demos/print-editor/print-editor.c @@ -23,7 +23,7 @@ update_title (GtkWindow *window) else basename = g_file_get_basename (filename); - title = g_strdup_printf ("Simple Editor with printing - %s", basename); + title = g_strdup_printf ("GTK Print Editor — %s", basename); g_free (basename); gtk_window_set_title (window, title); @@ -592,18 +592,54 @@ activate_about (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - const gchar *authors[] = { - "Alexander Larsson", - NULL - }; + char *version; + GString *sysinfo; + char *setting; + char **backends; + int i; + + sysinfo = g_string_new ("System libraries\n"); + g_string_append_printf (sysinfo, "\tGLib\t%d.%d.%d\n", + glib_major_version, + glib_minor_version, + glib_micro_version); + g_string_append_printf (sysinfo, "\tPango\t%s\n", + pango_version_string ()); + g_string_append_printf (sysinfo, "\tGTK\t%d.%d.%d\n", + gtk_get_major_version (), + gtk_get_minor_version (), + gtk_get_micro_version ()); + + g_string_append (sysinfo, "\nPrint backends\n"); + + g_object_get (gtk_settings_get_default (), "gtk-print-backends", &setting, NULL); + backends = g_strsplit (setting, ",", -1); + for (i = 0; backends[i]; i++) + g_string_append_printf (sysinfo, "\t%s\n", backends[i]); + g_strfreev (backends); + g_free (setting); + + version = g_strdup_printf ("%s\nRunning against GTK %d.%d.%d", + PACKAGE_VERSION, + gtk_get_major_version (), + gtk_get_minor_version (), + gtk_get_micro_version ()); + gtk_show_about_dialog (GTK_WINDOW (main_window), - "name", "Print Test Editor", - "logo-icon-name", "text-editor-symbolic", - "version", PACKAGE_VERSION, + "program-name", "GTK Print Editor", + "version", version, "copyright", "© 2006-2020 Red Hat, Inc", - "comments", "Program to demonstrate GTK printing.", - "authors", authors, + "license-type", GTK_LICENSE_LGPL_2_1, + "website", "http://www.gtk.org", + "comments", "Program to demonstrate GTK printing", + "authors", (const char *[]){ "Alexander Larsson", NULL }, + "logo-icon-name", "text-editor-symbolic", + "title", "About GTK Print Editor", + "system-information", sysinfo->str, NULL); + + g_string_free (sysinfo, TRUE); + g_free (version); } static void @@ -643,23 +679,6 @@ static const gchar ui_info[] = "" " " " " - " _Application" - "
" - " " - " _About" - " app.about" - " <Primary>a" - " " - "
" - "
" - " " - " _Quit" - " app.quit" - " <Primary>q" - " " - "
" - "
" - " " " _File" "
" " " @@ -696,6 +715,23 @@ static const gchar ui_info[] = " app.print" " " "
" + "
" + " " + " _Quit" + " app.quit" + " <Primary>q" + " " + "
" + "
" + " " + " _Help" + "
" + " " + " _About Print Editor" + " app.about" + " <Primary>a" + " " + "
" "
" "
" "
"; From 6774f3663643dd052641f1bd90ce64b13a31c92e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 28 Jun 2020 10:26:19 -0400 Subject: [PATCH 2/3] print-editor: Allow opening files Since it calls itself an editor, it should really support opening files on the commandline. --- demos/print-editor/print-editor.c | 37 +++++++++++++------------------ 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/demos/print-editor/print-editor.c b/demos/print-editor/print-editor.c index 158ea873b1..f8fa0b4ef1 100644 --- a/demos/print-editor/print-editor.c +++ b/demos/print-editor/print-editor.c @@ -752,25 +752,6 @@ mark_set_callback (GtkTextBuffer *text_buffer, update_statusbar (); } -static gint -command_line (GApplication *application, - GApplicationCommandLine *command_line) -{ - int argc; - char **argv; - - argv = g_application_command_line_get_arguments (command_line, &argc); - - if (argc == 2) - { - GFile *file = g_file_new_for_commandline_arg (argv[1]); - load_file (file); - g_object_unref (file); - } - - return 0; -} - static void startup (GApplication *app) { @@ -845,6 +826,20 @@ activate (GApplication *app) gtk_widget_show (main_window); } +static void +open (GApplication *application, + GFile **files, + int n_files, + const char *hint) +{ + if (n_files > 1) + g_warning ("Can only open a single file"); + + activate (application); + + load_file (files[0]); +} + int main (int argc, char **argv) { @@ -868,7 +863,7 @@ main (int argc, char **argv) g_clear_error (&error); } - app = gtk_application_new ("org.gtk.PrintEditor", 0); + app = gtk_application_new ("org.gtk.PrintEditor4", G_APPLICATION_HANDLES_OPEN); g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), @@ -876,7 +871,7 @@ main (int argc, char **argv) g_signal_connect (app, "startup", G_CALLBACK (startup), NULL); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); - g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL); + g_signal_connect (app, "open", G_CALLBACK (open), NULL); g_application_run (G_APPLICATION (app), argc, argv); From 59fe4a3a090cdc76f44bc3928a43a9b9c9a3f142 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 28 Jun 2020 10:12:45 -0400 Subject: [PATCH 3/3] printeditor: Add desktop file and appdata All our installed demos have this. --- demos/print-editor/meson.build | 11 ++++-- .../org.gtk.PrintEditor4.appdata.xml | 34 +++++++++++++++++++ .../print-editor/org.gtk.PrintEditor4.desktop | 10 ++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 demos/print-editor/org.gtk.PrintEditor4.appdata.xml create mode 100644 demos/print-editor/org.gtk.PrintEditor4.desktop diff --git a/demos/print-editor/meson.build b/demos/print-editor/meson.build index baa86aed12..9b3e7910c5 100644 --- a/demos/print-editor/meson.build +++ b/demos/print-editor/meson.build @@ -1,7 +1,14 @@ -executable('print-editor', +executable('gtk4-print-editor', ['print-editor.c'], c_args: common_cflags, dependencies: libgtk_dep, include_directories: confinc, gui_app: true, - link_args: extra_demo_ldflags) + link_args: extra_demo_ldflags, + install: true) + +# desktop file +install_data('org.gtk.PrintEditor4.desktop', install_dir: gtk_applicationsdir) + +# appdata +install_data('org.gtk.PrintEditor4.appdata.xml', install_dir: gtk_appdatadir) diff --git a/demos/print-editor/org.gtk.PrintEditor4.appdata.xml b/demos/print-editor/org.gtk.PrintEditor4.appdata.xml new file mode 100644 index 0000000000..2d60e80666 --- /dev/null +++ b/demos/print-editor/org.gtk.PrintEditor4.appdata.xml @@ -0,0 +1,34 @@ + + + org.gtk.PrintEditor4.desktop + CC0-1.0 + LGPL-2.0+ + GTK Print Editor + Program to demonstrate GTK printing + +

+ GTK Print Editor is a simple editor to demonstrate GTK printing. +

+
+ + + https://static.gnome.org/appdata/gtk4-print-editor/gtk-print-editor1.png + Print Editor + + + + HiDpiIcon + ModernToolkit + + https://www.gtk.org + gtk-4.0 + matthias.clasen_at_gmail.com + Matthias Clasen and others + + + +

A new developers snapshot towards GTK 4.0.

+
+
+
+
diff --git a/demos/print-editor/org.gtk.PrintEditor4.desktop b/demos/print-editor/org.gtk.PrintEditor4.desktop new file mode 100644 index 0000000000..7c663365d3 --- /dev/null +++ b/demos/print-editor/org.gtk.PrintEditor4.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Print Editor +Comment=A simple editor demonstrating GTK printing +Exec=gtk4-print-editor %f +Icon=text-editor-symbolic +Terminal=false +Type=Application +StartupNotify=true +Categories=Development;GTK; +NoDisplay=true