[shotwell] publishing: Separate UI files and code



commit 98e5f53e1114243e0c6edad7a8c12b382637afb5
Author: Jens Georg <mail jensge org>
Date:   Wed Jan 23 13:59:19 2019 +0100

    publishing: Separate UI files and code

 data/org.gnome.Shotwell.gresource.xml       |   4 +-
 data/ui/login_welcome_pane_widget.ui        |  48 +++++++++++
 data/ui/progress_pane_widget.ui             |  27 ++++++
 data/ui/shotwell.ui                         |  94 --------------------
 data/ui/static_message_pane_widget.ui       |  29 +++++++
 src/AppWindow.vala                          |  13 ---
 src/meson.build                             |  12 ++-
 src/publishing/LoginWelcomePaneWidget.vala  |  45 ++++++++++
 src/publishing/ProgressPaneWidget.vala      |  44 ++++++++++
 src/publishing/PublishingUI.vala            | 128 ----------------------------
 src/publishing/StaticMessagePaneWidget.vala |  55 ++++++++++++
 src/publishing/SuccessPaneWidget.vala       |  39 +++++++++
 src/publishing/meson.build                  |  27 ++++++
 13 files changed, 327 insertions(+), 238 deletions(-)
---
diff --git a/data/org.gnome.Shotwell.gresource.xml b/data/org.gnome.Shotwell.gresource.xml
index cd2d2b68..f17928c4 100644
--- a/data/org.gnome.Shotwell.gresource.xml
+++ b/data/org.gnome.Shotwell.gresource.xml
@@ -24,7 +24,9 @@
       <file preprocess="xml-stripblanks">ui/search_sidebar_context.ui</file>
       <file preprocess="xml-stripblanks">ui/set_background_dialog.ui</file>
       <file preprocess="xml-stripblanks">ui/set_background_slideshow_dialog.ui</file>
-      <file compressed="true">ui/shotwell.ui</file>
+      <file preprocess="xml-stripblanks">ui/login_welcome_pane_widget.ui</file>
+      <file preprocess="xml-stripblanks">ui/progress_pane_widget.ui</file>
+      <file preprocess="xml-stripblanks">ui/static_message_pane_widget.ui</file>
       <file preprocess="xml-stripblanks">ui/sidebar_default_context.ui</file>
       <file preprocess="xml-stripblanks">ui/slideshow_settings.ui</file>
       <file preprocess="xml-stripblanks">ui/saved_search_dialog.ui</file>
diff --git a/data/ui/login_welcome_pane_widget.ui b/data/ui/login_welcome_pane_widget.ui
new file mode 100644
index 00000000..afc724a0
--- /dev/null
+++ b/data/ui/login_welcome_pane_widget.ui
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.0 -->
+<interface domain="shotwell">
+  <requires lib="gtk+" version="3.18"/>
+  <template class="PublishingUILoginWelcomePane" parent="GtkBox">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkLabel" id="not_logged_in_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_start">16</property>
+        <property name="margin_end">16</property>
+        <property name="margin_top">97</property>
+        <property name="margin_bottom">24</property>
+        <property name="label" comments="This is a placeholder string and may be ignored.">This is populated 
from within the code;
+changes made here will not display.</property>
+        <property name="wrap">True</property>
+        <property name="max_width_chars">70</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="login_button">
+        <property name="label" translatable="yes">_Log in</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <property name="margin_start">256</property>
+        <property name="margin_end">240</property>
+        <property name="margin_top">80</property>
+        <property name="margin_bottom">16</property>
+        <property name="use_underline">True</property>
+        <property name="image_position">top</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/data/ui/progress_pane_widget.ui b/data/ui/progress_pane_widget.ui
new file mode 100644
index 00000000..239de609
--- /dev/null
+++ b/data/ui/progress_pane_widget.ui
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.0 -->
+<interface>
+  <requires lib="gtk+" version="3.22"/>
+  <template class="PublishingUIProgressPane" parent="GtkBox">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkProgressBar" id="progress_bar">
+        <property name="height_request">64</property>
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_start">32</property>
+        <property name="margin_end">32</property>
+        <property name="margin_top">108</property>
+        <property name="show_text">True</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="padding">32</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/data/ui/static_message_pane_widget.ui b/data/ui/static_message_pane_widget.ui
new file mode 100644
index 00000000..7a5441af
--- /dev/null
+++ b/data/ui/static_message_pane_widget.ui
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.0 -->
+<interface>
+  <requires lib="gtk+" version="3.22"/>
+  <template class="PublishingUIStaticMessagePane" parent="GtkBox">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkLabel" id="static_msg_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_start">16</property>
+        <property name="margin_end">16</property>
+        <property name="margin_top">97</property>
+        <property name="margin_bottom">24</property>
+        <property name="label" comments="This is a placeholder string and may be ignored.">This is populated 
from within the code;
+changes made here will not display.</property>
+        <property name="wrap">True</property>
+        <property name="max_width_chars">70</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/src/AppWindow.vala b/src/AppWindow.vala
index 892979e4..0374e2ee 100644
--- a/src/AppWindow.vala
+++ b/src/AppWindow.vala
@@ -474,19 +474,6 @@ public abstract class AppWindow : PageWindow {
         return fullscreen_window;
     }
 
-    public static Gtk.Builder create_builder(string glade_filename = "shotwell.ui", void *user = null) {
-        Gtk.Builder builder = new Gtk.Builder();
-        try {
-            builder.add_from_resource(Resources.get_ui(glade_filename));
-        } catch(GLib.Error error) {
-            warning("Unable to create Gtk.Builder: %s\n", error.message);
-        }
-        
-        builder.connect_signals(user);
-        
-        return builder;
-    }
-    
     public static void error_message(string message, Gtk.Window? parent = null) {
         error_message_with_title(Resources.APP_TITLE, message, parent);
     }
diff --git a/src/meson.build b/src/meson.build
index 20308e49..65197196 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -36,6 +36,9 @@ shotwell_deps = [gio, gee, sqlite, gtk, sqlite, posix, gphoto2,
 if unity_available
     shotwell_deps += [unity]
 endif
+
+subdir('publishing')
+
 executable('shotwell',
            ['unit/Unit.vala',
             'util/Util.vala',
@@ -241,7 +244,10 @@ executable('shotwell',
             '.unitize/_Library_unitize_entry.vala',
             '.unitize/_Direct_unitize_entry.vala'] + shotwell_resources + face_sources,
            include_directories : vapi_incdir,
-           dependencies : shotwell_deps,
+           dependencies : [
+               shotwell_deps,
+               sw_publishing_gui
+           ],
            vala_args : ['--pkg', 'libgphoto2',
                         '--pkg', 'libraw',
                         '--pkg', 'libexif',
@@ -251,5 +257,7 @@ executable('shotwell',
                         join_paths(meson.source_root(), 'data',
                           'org.gnome.Shotwell.gresource.xml')
                        ],
-           link_with: [sw_graphics_processor],
+           link_with: [
+               sw_graphics_processor
+           ],
            install : true)
diff --git a/src/publishing/LoginWelcomePaneWidget.vala b/src/publishing/LoginWelcomePaneWidget.vala
new file mode 100644
index 00000000..ba480525
--- /dev/null
+++ b/src/publishing/LoginWelcomePaneWidget.vala
@@ -0,0 +1,45 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2019 Jens Georg <mail jensge org>
+ *
+ * This software is licensed under the GNU LGPL (version 2.1 or later).
+ * See the COPYING file in this distribution.
+ */
+
+namespace PublishingUI {
+
+[GtkTemplate (ui = "/org/gnome/Shotwell/ui/login_welcome_pane_widget.ui")]
+public class LoginWelcomePane : Spit.Publishing.DialogPane, Gtk.Box {
+    [GtkChild]
+    private Gtk.Button login_button;
+    [GtkChild]
+    private Gtk.Label not_logged_in_label;
+
+    public Gtk.Widget get_widget() {
+        return this;
+    }
+
+    public Spit.Publishing.DialogPane.GeometryOptions get_preferred_geometry() {
+        return Spit.Publishing.DialogPane.GeometryOptions.NONE;
+    }
+
+    public void on_pane_installed() {
+    }
+
+    public void on_pane_uninstalled() {
+    }
+
+    public signal void login_requested();
+
+    public LoginWelcomePane(string service_welcome_message) {
+        Object();
+
+        login_button.clicked.connect(on_login_clicked);
+        not_logged_in_label.set_use_markup(true);
+        not_logged_in_label.set_markup(service_welcome_message);
+    }
+
+    private void on_login_clicked() {
+        login_requested();
+    }
+}
+} // namespace PublishingUI
diff --git a/src/publishing/ProgressPaneWidget.vala b/src/publishing/ProgressPaneWidget.vala
new file mode 100644
index 00000000..bf8af1da
--- /dev/null
+++ b/src/publishing/ProgressPaneWidget.vala
@@ -0,0 +1,44 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2019 Jens Georg <mail jensge org>
+ *
+ * This software is licensed under the GNU LGPL (version 2.1 or later).
+ * See the COPYING file in this distribution.
+ */
+
+namespace PublishingUI {
+
+[GtkTemplate (ui = "/org/gnome/Shotwell/ui/progress_pane_widget.ui")]
+public class ProgressPane : Spit.Publishing.DialogPane, Gtk.Box {
+    [GtkChild]
+    private Gtk.ProgressBar progress_bar;
+
+    public Gtk.Widget get_widget() {
+        return this;
+    }
+
+    public Spit.Publishing.DialogPane.GeometryOptions get_preferred_geometry() {
+        return Spit.Publishing.DialogPane.GeometryOptions.NONE;
+    }
+
+    public void on_pane_installed() {
+    }
+
+    public void on_pane_uninstalled() {
+    }
+
+    public void set_text(string text) {
+        progress_bar.set_text(text);
+    }
+
+    public void set_progress(double progress) {
+        progress_bar.set_fraction(progress);
+    }
+
+    public void set_status(string status_text, double progress) {
+        if (status_text != progress_bar.get_text())
+            progress_bar.set_text(status_text);
+
+        set_progress(progress);
+    }
+}
+} // namespace PublishingUI
diff --git a/src/publishing/PublishingUI.vala b/src/publishing/PublishingUI.vala
index 2b967dd3..911adc1d 100644
--- a/src/publishing/PublishingUI.vala
+++ b/src/publishing/PublishingUI.vala
@@ -6,134 +6,6 @@
 
 namespace PublishingUI {
 
-public class ConcreteDialogPane : Spit.Publishing.DialogPane, GLib.Object {
-    protected Gtk.Box pane_widget = null;
-    protected Gtk.Builder builder = null;
-
-    public ConcreteDialogPane() {
-        builder = AppWindow.create_builder();
-    }
-
-    public Gtk.Widget get_widget() {
-        return pane_widget;
-    }
-
-    public Spit.Publishing.DialogPane.GeometryOptions get_preferred_geometry() {
-        return Spit.Publishing.DialogPane.GeometryOptions.NONE;
-    }
-
-    public void on_pane_installed() {
-    }
-
-    public void on_pane_uninstalled() {
-    }
-}
-
-public class StaticMessagePane : ConcreteDialogPane {
-    private Gtk.Label msg_label = null;
-
-    public StaticMessagePane(string message_string, bool enable_markup = false) {
-        base();
-        msg_label = builder.get_object("static_msg_label") as Gtk.Label;
-        pane_widget = builder.get_object("static_msg_pane_widget") as Gtk.Box;
-
-        if (enable_markup) {
-            msg_label.set_markup(message_string);
-            msg_label.set_line_wrap(true);
-            msg_label.set_use_markup(true);
-        } else {
-            msg_label.set_label(message_string);
-        }
-    }
-}
-
-public class LoginWelcomePane : ConcreteDialogPane {
-    private Gtk.Button login_button = null;
-    private Gtk.Label not_logged_in_label = null;
-
-    public signal void login_requested();
-
-    public LoginWelcomePane(string service_welcome_message) {
-        base();
-        pane_widget = builder.get_object("welcome_pane_widget") as Gtk.Box;
-        login_button = builder.get_object("login_button") as Gtk.Button;
-        not_logged_in_label = builder.get_object("not_logged_in_label") as Gtk.Label;
-
-        login_button.clicked.connect(on_login_clicked);
-        not_logged_in_label.set_use_markup(true);
-        not_logged_in_label.set_markup(service_welcome_message);
-    }
-
-    private void on_login_clicked() {
-        login_requested();
-    }
-}
-
-public class ProgressPane : ConcreteDialogPane {
-    private Gtk.ProgressBar progress_bar = null;
-
-    public ProgressPane() {
-        base();
-        pane_widget = (Gtk.Box) builder.get_object("progress_pane_widget");
-        progress_bar = (Gtk.ProgressBar) builder.get_object("publishing_progress_bar");
-    }
-
-    public void set_text(string text) {
-        progress_bar.set_text(text);
-    }
-
-    public void set_progress(double progress) {
-        progress_bar.set_fraction(progress);
-    }
-
-    public void set_status(string status_text, double progress) {
-        if (status_text != progress_bar.get_text())
-            progress_bar.set_text(status_text);
-
-        set_progress(progress);
-    }
-}
-
-public class SuccessPane : StaticMessagePane {
-    public SuccessPane(Spit.Publishing.Publisher.MediaType published_media, int num_uploaded = 1) {
-        string? message_string = null;
-
-        // Here, we check whether more than one item is being uploaded, and if so, display
-        // an alternate message.
-        if (published_media == Spit.Publishing.Publisher.MediaType.VIDEO) {
-            message_string = ngettext ("The selected video was successfully published.",
-                                       "The selected videos were successfully published.",
-                                       num_uploaded);
-        }
-        else if (published_media == Spit.Publishing.Publisher.MediaType.PHOTO) {
-            message_string = ngettext ("The selected photo was successfully published.",
-                                       "The selected photos were successfully published.",
-                                       num_uploaded);
-        }
-        else if (published_media == (Spit.Publishing.Publisher.MediaType.PHOTO
-                                     | Spit.Publishing.Publisher.MediaType.VIDEO)) {
-            message_string = _("The selected photos/videos were successfully published.");
-        }
-        else {
-            assert_not_reached ();
-        }
-
-        base(message_string);
-    }
-}
-
-public class AccountFetchWaitPane : StaticMessagePane {
-    public AccountFetchWaitPane() {
-        base(_("Fetching account information…"));
-    }
-}
-
-public class LoginWaitPane : StaticMessagePane {
-    public LoginWaitPane() {
-        base(_("Logging in…"));
-    }
-}
-
 public class PublishingDialog : Gtk.Dialog {
     private const int LARGE_WINDOW_WIDTH = 860;
     private const int LARGE_WINDOW_HEIGHT = 688;
diff --git a/src/publishing/StaticMessagePaneWidget.vala b/src/publishing/StaticMessagePaneWidget.vala
new file mode 100644
index 00000000..1ed6b0a7
--- /dev/null
+++ b/src/publishing/StaticMessagePaneWidget.vala
@@ -0,0 +1,55 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2019 Jens Georg <mail jensge org>
+ *
+ * This software is licensed under the GNU LGPL (version 2.1 or later).
+ * See the COPYING file in this distribution.
+ */
+
+namespace PublishingUI {
+
+[GtkTemplate (ui = "/org/gnome/Shotwell/ui/static_message_pane_widget.ui")]
+public class StaticMessagePane : Spit.Publishing.DialogPane, Gtk.Box {
+    [GtkChild]
+    private Gtk.Label static_msg_label;
+
+    public Gtk.Widget get_widget() {
+        return this;
+    }
+
+    public Spit.Publishing.DialogPane.GeometryOptions get_preferred_geometry() {
+        return Spit.Publishing.DialogPane.GeometryOptions.NONE;
+    }
+
+    public void on_pane_installed() {
+    }
+
+    public void on_pane_uninstalled() {
+    }
+
+    public StaticMessagePane(string message_string, bool enable_markup = false) {
+        Object();
+
+        if (enable_markup) {
+            static_msg_label.set_markup(message_string);
+            static_msg_label.set_line_wrap(true);
+            static_msg_label.set_use_markup(true);
+        } else {
+            static_msg_label.set_label(message_string);
+        }
+    }
+}
+
+public class AccountFetchWaitPane : StaticMessagePane {
+    public AccountFetchWaitPane() {
+        base(_("Fetching account information…"));
+    }
+}
+
+public class LoginWaitPane : StaticMessagePane {
+    public LoginWaitPane() {
+        base(_("Logging in…"));
+    }
+}
+
+
+} // namespace PublishingUI
diff --git a/src/publishing/SuccessPaneWidget.vala b/src/publishing/SuccessPaneWidget.vala
new file mode 100644
index 00000000..05b0c160
--- /dev/null
+++ b/src/publishing/SuccessPaneWidget.vala
@@ -0,0 +1,39 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2019 Jens Georg <mail jensge org>
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later).  See the COPYING file in this distribution.
+ */
+
+namespace PublishingUI {
+
+public class SuccessPane : StaticMessagePane {
+    public SuccessPane(Spit.Publishing.Publisher.MediaType published_media, int num_uploaded = 1) {
+        string? message_string = null;
+
+        // Here, we check whether more than one item is being uploaded, and if so, display
+        // an alternate message.
+        if (published_media == Spit.Publishing.Publisher.MediaType.VIDEO) {
+            message_string = ngettext ("The selected video was successfully published.",
+                                       "The selected videos were successfully published.",
+                                       num_uploaded);
+        }
+        else if (published_media == Spit.Publishing.Publisher.MediaType.PHOTO) {
+            message_string = ngettext ("The selected photo was successfully published.",
+                                       "The selected photos were successfully published.",
+                                       num_uploaded);
+        }
+        else if (published_media == (Spit.Publishing.Publisher.MediaType.PHOTO
+                                     | Spit.Publishing.Publisher.MediaType.VIDEO)) {
+            message_string = _("The selected photos/videos were successfully published.");
+        }
+        else {
+            assert_not_reached ();
+        }
+
+        base(message_string);
+    }
+}
+}
+
+
diff --git a/src/publishing/meson.build b/src/publishing/meson.build
new file mode 100644
index 00000000..39b471bc
--- /dev/null
+++ b/src/publishing/meson.build
@@ -0,0 +1,27 @@
+libsw_publishing_gui = static_library(
+    'publishing_gui',
+    [
+        'StaticMessagePaneWidget.vala',
+        'ProgressPaneWidget.vala',
+        'SuccessPaneWidget.vala',
+        'LoginWelcomePaneWidget.vala',
+    ],
+    vala_header : 'shotwell-internal-publishing-gui.h',
+    vala_vapi : 'shotwell-internal-publishing-gui.vapi',
+    include_directories : config_incdir,
+    dependencies: [
+        gtk,
+        gee,
+        sw_plugin
+    ],
+    vala_args : [
+        '--gresources',
+        join_paths(meson.source_root(), 'data',
+        'org.gnome.Shotwell.gresource.xml')
+    ]
+)
+
+sw_publishing_gui = declare_dependency(
+    include_directories : include_directories('.'),
+    link_with : libsw_publishing_gui
+)


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