[shotwell/wip/dedeprecate: 21/26] piwigo: Port SSL pane to BuilderPane



commit 0435fc3883ec941967138900c23dc215d7a56a00
Author: Jens Georg <mail jensge org>
Date:   Sat Oct 29 03:11:24 2016 +0200

    piwigo: Port SSL pane to BuilderPane
    
    Signed-off-by: Jens Georg <mail jensge org>

 plugins/shotwell-publishing/PiwigoPublishing.vala |  101 ++++++++++-----------
 1 files changed, 48 insertions(+), 53 deletions(-)
---
diff --git a/plugins/shotwell-publishing/PiwigoPublishing.vala 
b/plugins/shotwell-publishing/PiwigoPublishing.vala
index 71b3e99..a7afe25 100644
--- a/plugins/shotwell-publishing/PiwigoPublishing.vala
+++ b/plugins/shotwell-publishing/PiwigoPublishing.vala
@@ -999,71 +999,66 @@ internal class Uploader : Publishing.RESTSupport.BatchUploader {
 
 // UI elements
 
-internal class SSLErrorPane : Spit.Publishing.DialogPane, Object {
-    private Gtk.Builder builder;
-    private Gtk.Widget content;
+internal class SSLErrorPane : Shotwell.Plugins.Common.BuilderPane {
 
     public signal void proceed ();
+    public string host { owned get; construct; }
+    public TlsCertificate cert { private get; construct; }
+    public string error_text { owned get; construct; }
 
     public SSLErrorPane (SessionLoginTransaction transaction,
                          string host) {
-        try {
-            TlsCertificate cert;
-            this.builder = new Gtk.Builder ();
-            this.builder.add_from_resource (Resources.RESOURCE_PATH +
-                                            "/piwigo_ssl_failure_pane.ui");
-            this.content = this.builder.get_object ("content") as Gtk.Widget;
-            var label = this.builder.get_object ("main_text") as Gtk.Label;
-            // %s is the host name that we tried to connect to
-            label.set_text (_("This does not look like the real <b>%s</b>. Attackers might be trying to 
steal or alter information going to or from this site (for example, private messages, credit card 
information, or passwords).").printf (host));
-            label.use_markup = true;
-
-            label = this.builder.get_object ("ssl_errors") as Gtk.Label;
-            var text = transaction.detailed_error_from_tls_flags (out cert);
-            label.set_text (text);
-
-            var info = this.builder.get_object ("default") as Gtk.Button;
-            info.clicked.connect (() => {
-                var simple_cert = new Gcr.SimpleCertificate (cert.certificate.data);
-                var widget = new Gcr.CertificateWidget (simple_cert);
-
-                var dialog = new Gtk.Dialog ();
-                dialog.get_content_area ().add (widget);
-                dialog.add_button ("_OK", Gtk.ResponseType.OK);
-                dialog.set_default_response (Gtk.ResponseType.OK);
-                dialog.set_default_size (640, -1);
-                dialog.show_all ();
-                dialog.run ();
-                dialog.destroy ();
-            });
-
-            var proceed = this.builder.get_object ("proceed_button") as Gtk.Button;
-            proceed.clicked.connect (() => { this.proceed (); });
-
-            if (this.content.parent != null) {
-                this.content.parent.remove (this.content);
-            }
-        } catch (Error error) {
-            warning ("Failed to create ui file: %s", error.message);
-            assert_not_reached ();
-        }
+        TlsCertificate cert;
+        var text = transaction.detailed_error_from_tls_flags (out cert);
+        Object (resource_path : Resources.RESOURCE_PATH +
+                                "/piwigo_ssl_failure_pane.ui",
+                cert : cert,
+                error_text : text,
+                host : host);
     }
 
-    public Spit.Publishing.DialogPane.GeometryOptions get_preferred_geometry () {
-        return Spit.Publishing.DialogPane.GeometryOptions.NONE;
-    }
+    public override void constructed () {
+        base.constructed ();
+
+        var label = this.get_builder ().get_object ("main_text") as Gtk.Label;
+        // %s is the host name that we tried to connect to
+        label.set_text (_("This does not look like the real <b>%s</b>. Attackers might be trying to steal or 
alter information going to or from this site (for example, private messages, credit card information, or 
passwords).").printf (host));
+        label.use_markup = true;
+
+        label = this.get_builder ().get_object ("ssl_errors") as Gtk.Label;
+        label.set_text (error_text);
+
+        var info = this.get_builder ().get_object ("default") as Gtk.Button;
+        info.clicked.connect (() => {
+            var simple_cert = new Gcr.SimpleCertificate (cert.certificate.data);
+            var widget = new Gcr.CertificateWidget (simple_cert);
+            bool use_header = true;
+            Gtk.Settings.get_default ().get ("gtk-dialogs-use-header", out use_header);
+            var flags = (Gtk.DialogFlags) 0;
+            if (use_header) {
+                flags |= Gtk.DialogFlags.USE_HEADER_BAR;
+            }
 
-    public Gtk.Widget get_widget () {
-        return this.content;
+            var dialog = new Gtk.Dialog.with_buttons (
+                            _("Certificate of %s").printf (host),
+                            null,
+                            flags,
+                            _("_OK"), Gtk.ResponseType.OK);
+            dialog.get_content_area ().add (widget);
+            dialog.set_default_response (Gtk.ResponseType.OK);
+            dialog.set_default_size (640, -1);
+            dialog.show_all ();
+            dialog.run ();
+            dialog.destroy ();
+        });
+
+        var proceed = this.get_builder ().get_object ("proceed_button") as Gtk.Button;
+        proceed.clicked.connect (() => { this.proceed (); });
     }
 
     public Gtk.Widget get_default_widget () {
-        return this.builder.get_object ("default") as Gtk.Widget;
+        return this.get_builder ().get_object ("default") as Gtk.Widget;
     }
-
-    public void on_pane_installed () { }
-
-    public void on_pane_uninstalled () { }
 }
 
 /**


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