[gnome-builder/wip/exalm/fixes: 17/18] meson-templates: Port to AdwAboutDialog




commit cc08cc8de2212f0ac157ecb1ee1545d06fdb41dd
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Jul 14 04:58:55 2022 +0400

    meson-templates: Port to AdwAboutDialog
    
    Clean up dialogs in process - add app icons and copyright to the GTK
    versions, stop subclassing GtkAboutDialog for Python.

 .../resources/src/application-gtk4.c               | 18 ++++++++++++++++
 .../resources/src/application-gtk4.rs              | 18 ++++++++++++++--
 .../resources/src/application-gtk4.vala            | 19 ++++++++++++++++-
 .../resources/src/main-gtk4.js.tmpl                | 24 +++++++++++++++++++---
 .../meson-templates/resources/src/main-gtk4.py     | 20 ++++++++++++++++--
 .../meson-templates/resources/src/window-gtk4.py   | 13 ------------
 6 files changed, 91 insertions(+), 21 deletions(-)
---
diff --git a/src/plugins/meson-templates/resources/src/application-gtk4.c 
b/src/plugins/meson-templates/resources/src/application-gtk4.c
index 636652a3d..c5f6db426 100644
--- a/src/plugins/meson-templates/resources/src/application-gtk4.c
+++ b/src/plugins/meson-templates/resources/src/application-gtk4.c
@@ -57,7 +57,11 @@ static void
 {{spaces}}                           GVariant      *parameter,
 {{spaces}}                           gpointer       user_data)
 {
+{{if is_adwaita}}
+  static const char *developers[] = {"{{author}}", NULL};
+{{else}}
   static const char *authors[] = {"{{author}}", NULL};
+{{end}}
   {{PreFix}}Application *self = user_data;
   GtkWindow *window = NULL;
 
@@ -65,11 +69,24 @@ static void
 
   window = gtk_application_get_active_window (GTK_APPLICATION (self));
 
+{{if is_adwaita}}
+  adw_show_about_window (window,
+                         "application-name", "{{name}}",
+                         "application-icon", "{{appid}}",
+                         "developer-name", "{{author}}",
+                         "version", "{{project_version}}",
+                         "developers", developers,
+                         "copyright", "© {{year}} {{author}}",
+                         NULL);
+{{else}}
   gtk_show_about_dialog (window,
                          "program-name", "{{name}}",
+                         "logo-icon-name", "{{appid}}",
                          "authors", authors,
                          "version", "{{project_version}}",
+                         "copyright", "© {{year}} {{author}}",
                          NULL);
+{{end}}
 }
 
 static void
@@ -100,3 +117,4 @@ static void
                                          "app.quit",
                                          (const char *[]) { "<primary>q", NULL });
 }
+
diff --git a/src/plugins/meson-templates/resources/src/application-gtk4.rs 
b/src/plugins/meson-templates/resources/src/application-gtk4.rs
index 0314259a8..c6144fe7f 100644
--- a/src/plugins/meson-templates/resources/src/application-gtk4.rs
+++ b/src/plugins/meson-templates/resources/src/application-gtk4.rs
@@ -87,14 +87,28 @@ impl {{PreFix}}Application {
 
     fn show_about(&self) {
         let window = self.active_window().unwrap();
-        let dialog = gtk::AboutDialog::builder()
+{{if is_adwaita}}
+        let about = adw::AboutWindow::builder()
+            .transient_for(&window)
+            .application_name("{{name}}")
+            .application_icon("{{appid}}")
+            .developer_name("{{author}}")
+            .version(VERSION)
+            .developers(vec!["{{author}}".into()])
+            .copyright("© {{year}} {{author}}"),
+            .build();
+{{else}}
+        let about = gtk::AboutDialog::builder()
             .transient_for(&window)
             .modal(true)
             .program_name("{{name}}")
+            .logo_icon_name("{{appid}}")
             .version(VERSION)
             .authors(vec!["{{author}}".into()])
+            .copyright("© {{year}} {{author}}"),
             .build();
+{{end}}
 
-        dialog.present();
+        about.present();
     }
 }
diff --git a/src/plugins/meson-templates/resources/src/application-gtk4.vala 
b/src/plugins/meson-templates/resources/src/application-gtk4.vala
index 03415657b..54149824e 100644
--- a/src/plugins/meson-templates/resources/src/application-gtk4.vala
+++ b/src/plugins/meson-templates/resources/src/application-gtk4.vala
@@ -26,11 +26,28 @@ namespace {{PreFix}} {
         }
 
         private void on_about_action () {
+{{if is_adwaita}}
+            string[] developers = { "{{author}}" };
+            var about = new Adw.AboutWindow () {
+                transient_for = this.active_window,
+                application_name = "{{name}}",
+                application_icon = "{{appid}}",
+                developer_name = "{{author}}",
+                version = "{{project_version}}",
+                developers = developers,
+                copyright = "© {{year}} {{author}}",
+            };
+
+            about.present ();
+{{else}}
             string[] authors = { "{{author}}" };
             Gtk.show_about_dialog (this.active_window,
                                    "program-name", "{{name}}",
+                                   "logo-icon-name", "{{appid}}",
                                    "authors", authors,
-                                   "version", "{{project_version}}");
+                                   "version", "{{project_version}}",
+                                   "copyright", "© {{year}} {{author}}");
+{{end}}
         }
 
         private void on_preferences_action () {
diff --git a/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl 
b/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
index 13ad322e8..2bef656b7 100644
--- a/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
+++ b/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
@@ -26,17 +26,35 @@ export const {{PreFix}}Application = GObject.registerClass(
 
             const show_about_action = new Gio.SimpleAction({name: 'about'});
             show_about_action.connect('activate', action => {
+{{if is_adwaita}}
                 let aboutParams = {
-                    authors: [
+                    transient_for: this.active_window,
+                    application_name: '{{name}}',
+                    application_icon: '{{appid}}',
+                    developer_name: '{{author}}',
+                    version: '{{project_version}}',
+                    developers: [
                         '{{author}}'
                     ],
-                    version: '{{project_version}}',
-                    program_name: '{{name}}',
+                    copyright: '© {{year}} {{author}}'
+                };
+                const aboutWindow = new Adw.AboutWindow(aboutParams);
+                aboutWindow.present();
+{{else}}
+                let aboutParams = {
                     transient_for: this.active_window,
                     modal: true,
+                    program_name: '{{name}}',
+                    logo_icon_name: '{{appid}}',
+                    version: '{{project_version}}',
+                    authors: [
+                        '{{author}}'
+                    ],
+                    copyright: '© {{year}} {{author}}'
                 };
                 const aboutDialog = new Gtk.AboutDialog(aboutParams);
                 aboutDialog.present();
+{{end}}
             });
             this.add_action(show_about_action);
         }
diff --git a/src/plugins/meson-templates/resources/src/main-gtk4.py 
b/src/plugins/meson-templates/resources/src/main-gtk4.py
index 0184493ce..7c3b908a3 100644
--- a/src/plugins/meson-templates/resources/src/main-gtk4.py
+++ b/src/plugins/meson-templates/resources/src/main-gtk4.py
@@ -10,7 +10,7 @@ gi.require_version('Adw', '1')
 
 from gi.repository import Gtk, Gio{{if is_adwaita}}, Adw{{end}}
 
-from .window import {{PreFix}}Window, AboutDialog
+from .window import {{PreFix}}Window
 
 
 class {{Prefix}}Application({{if is_adwaita}}Adw{{else}}Gtk{{end}}.Application):
@@ -36,7 +36,23 @@ class {{Prefix}}Application({{if is_adwaita}}Adw{{else}}Gtk{{end}}.Application):
 
     def on_about_action(self, widget, _):
         """Callback for the app.about action."""
-        about = AboutDialog(self.props.active_window)
+{{if is_adwaita}}
+        about = Adw.AboutWindow(transient_for=self.props.active_window,
+                                application_name='{{name}}',
+                                application_icon='{{appid}}',
+                                developer_name='{{author}}',
+                                version='{{project_version}}',
+                                developers=['{{author}}'],
+                                copyright='© {{year}} {{author}}')
+{{else}}
+        about = Gtk.AboutDialog(transient_for=self.props.active_window,
+                                modal=True,
+                                program_name='{{name}}',
+                                logo_icon_name='{{appid}}',
+                                version='{{project_version}}',
+                                authors=['{{author}}'],
+                                copyright='© {{year}} {{author}}')
+{{end}}
         about.present()
 
     def on_preferences_action(self, widget, _):
diff --git a/src/plugins/meson-templates/resources/src/window-gtk4.py 
b/src/plugins/meson-templates/resources/src/window-gtk4.py
index a41beaa94..84431ad33 100644
--- a/src/plugins/meson-templates/resources/src/window-gtk4.py
+++ b/src/plugins/meson-templates/resources/src/window-gtk4.py
@@ -13,16 +13,3 @@ class {{PreFix}}Window({{if is_adwaita}}Adw{{else}}Gtk{{end}}.ApplicationWindow)
 
     def __init__(self, **kwargs):
         super().__init__(**kwargs)
-
-
-class AboutDialog(Gtk.AboutDialog):
-
-    def __init__(self, parent):
-        Gtk.AboutDialog.__init__(self)
-        self.props.program_name = '{{name}}'
-        self.props.version = "0.1.0"
-        self.props.authors = ['{{author}}']
-        self.props.copyright = '{{year}} {{author}}'
-        self.props.logo_icon_name = '{{appid}}'
-        self.props.modal = True
-        self.set_transient_for(parent)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]