diff options
Diffstat (limited to 'plugins/common')
| -rw-r--r-- | plugins/common/RESTSupport.vala | 12 | ||||
| -rw-r--r-- | plugins/common/Resources.vala | 24 | ||||
| -rw-r--r-- | plugins/common/WebAuthenticationPane.vala | 129 |
3 files changed, 41 insertions, 124 deletions
diff --git a/plugins/common/RESTSupport.vala b/plugins/common/RESTSupport.vala index cc810fe..13286de 100644 --- a/plugins/common/RESTSupport.vala +++ b/plugins/common/RESTSupport.vala @@ -4,6 +4,8 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ +extern const string _VERSION; + namespace Publishing.RESTSupport { // Ported from librest @@ -34,9 +36,11 @@ public abstract class Session { public signal void authenticated(); public signal void authentication_failed(Spit.Publishing.PublishingError err); - protected Session(string? endpoint_url = null) { + protected Session(string? endpoint_url = null, Soup.SessionFeature[] features = {}) { this.endpoint_url = endpoint_url; soup_session = new Soup.Session (); + // The trailing space is intentional to make libsoup append its version info + soup_session.set_user_agent("Shotwell/%s ".printf(_VERSION)); if (Environment.get_variable("SHOTWELL_SOUP_LOG") != null) { var logger = new Soup.Logger(Soup.LoggerLogLevel.BODY); logger.set_request_filter((logger, msg) => { @@ -49,6 +53,10 @@ public abstract class Session { }); soup_session.add_feature (logger); } + + foreach (var feature in features) { + soup_session.add_feature(feature); + } } protected void notify_wire_message_unqueued(Soup.Message message) { @@ -361,7 +369,7 @@ public class Transaction { protected virtual void add_header(string key, string value) { message.request_headers.append(key, value); } - + // set custom_payload to null to have this transaction send the default payload of // key-value pairs appended through add_argument(...) (this is how most REST requests work). // To send a payload other than traditional key-value pairs (such as an XML document or a JPEG diff --git a/plugins/common/Resources.vala b/plugins/common/Resources.vala index 16306f2..d8c3fd3 100644 --- a/plugins/common/Resources.vala +++ b/plugins/common/Resources.vala @@ -30,30 +30,6 @@ along with Shotwell; if not, write to the Free Software Foundation, Inc., public const string TRANSLATORS = _("translator-credits"); -// TODO: modify to load multiple icons -// -// provided all the icons in the set follow a known naming convention (such as iconName_nn.png, -// where 'nn' is a size value in pixels, for example plugins_16.png -- this convention seems -// pretty common in the GNOME world), then this function can be modified to load an entire icon -// set without its interface needing to change, since given one icon filename, we can -// determine the others. -public Gdk.Pixbuf[]? load_icon_set(GLib.File? icon_file) { - Gdk.Pixbuf? icon = null; - try { - icon = new Gdk.Pixbuf.from_file(icon_file.get_path()); - } catch (Error err) { - warning("couldn't load icon set from %s: %s", icon_file.get_path(), err.message); - } - - if (icon != null) { - Gdk.Pixbuf[] icon_pixbuf_set = new Gdk.Pixbuf[0]; - icon_pixbuf_set += icon; - return icon_pixbuf_set; - } - - return null; -} - public Gdk.Pixbuf[]? load_from_resource (string resource_path) { Gdk.Pixbuf? icon = null; try { diff --git a/plugins/common/WebAuthenticationPane.vala b/plugins/common/WebAuthenticationPane.vala index b9f7280..f745252 100644 --- a/plugins/common/WebAuthenticationPane.vala +++ b/plugins/common/WebAuthenticationPane.vala @@ -6,109 +6,44 @@ using Spit.Publishing; namespace Shotwell.Plugins.Common { - public abstract class WebAuthenticationPane : Spit.Publishing.DialogPane, Object { + public class ExternalWebPane : Spit.Publishing.DialogPane, Object { public DialogPane.GeometryOptions preferred_geometry { get; construct; default = DialogPane.GeometryOptions.COLOSSAL_SIZE; } - public string login_uri { owned get; construct; } - public Error load_error { get; private set; default = null; } - - private WebKit.WebView webview; - private Gtk.Widget widget; - private Gtk.Entry entry; + public Gtk.Widget widget; - public void clear() { - debug("Clearing the data of WebKit..."); - this.webview.get_website_data_manager().clear.begin(WebKit.WebsiteDataTypes.ALL, (GLib.TimeSpan)0); + public ExternalWebPane(string uri) { + Object(login_uri: uri); } + public signal void browser_toggled(); + public override void constructed () { base.constructed (); - var ctx = WebKit.WebContext.get_default(); - if (!ctx.get_sandbox_enabled()) { - ctx.set_sandbox_enabled(true); - } - - var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 4); - this.widget = box; - this.entry = new Gtk.Entry(); - this.entry.editable = false; - this.entry.get_style_context().add_class("flat"); - this.entry.get_style_context().add_class("read-only"); - box.pack_start (entry, false, false, 6); - - this.webview = new WebKit.WebView (); - - this.webview.load_changed.connect (this.on_page_load_changed); - this.webview.load_failed.connect (this.on_page_load_failed); - this.webview.context_menu.connect ( () => { return false; }); - this.webview.decide_policy.connect (this.on_decide_policy); - this.webview.bind_property("uri", this.entry, "text", GLib.BindingFlags.DEFAULT); - box.pack_end (this.webview); - } - - private bool on_decide_policy(WebKit.PolicyDecision decision, WebKit.PolicyDecisionType type) { - switch (type) { - case WebKit.PolicyDecisionType.NEW_WINDOW_ACTION: { - var navigation = (WebKit.NavigationPolicyDecision) decision; - var action = navigation.get_navigation_action(); - var uri = action.get_request().uri; - decision.ignore(); - AppInfo.launch_default_for_uri_async.begin(uri, null); - return true; - } - default: - break; - } - - return false; - } - - public abstract void on_page_load (); - - protected void set_cursor (Gdk.CursorType type) { - var window = webview.get_window (); - if (window == null) - return; - - var display = window.get_display (); - if (display == null) - return; - - var cursor = new Gdk.Cursor.for_display (display, type); - window.set_cursor (cursor); - } - - private bool on_page_load_failed (WebKit.LoadEvent load_event, string uri, Error error) { - // OAuth call-back scheme. Produces a load error because it is not HTTP(S) - // Do not set the load_error, but continue the error handling - if (uri.has_prefix ("shotwell-auth://")) - return false; - - critical ("Failed to load uri %s: %s", uri, error.message); - this.load_error = error; - - return false; - } - - private void on_page_load_changed (WebKit.LoadEvent load_event) { - switch (load_event) { - case WebKit.LoadEvent.STARTED: - case WebKit.LoadEvent.REDIRECTED: - this.set_cursor (Gdk.CursorType.WATCH); - break; - case WebKit.LoadEvent.FINISHED: - this.set_cursor (Gdk.CursorType.LEFT_PTR); - this.on_page_load (); - break; - default: - break; - } - } - - public WebKit.WebView get_view () { - return this.webview; + var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 18); + box.set_halign(Gtk.Align.CENTER); + box.hexpand = true; + box.set_valign(Gtk.Align.CENTER); + box.vexpand = true; + var image = new Gtk.Image.from_icon_name ("web-browser-symbolic", Gtk.IconSize.DIALOG); + image.get_style_context().add_class("dim-label"); + image.set_pixel_size(128); + box.add(image); + + var label = new Gtk.Label(_("Sign in with your browser to setup an account")); + label.get_style_context().add_class("heading"); + box.add(label); + var button = new Gtk.Button.with_label (_("Continue")); + button.set_halign(Gtk.Align.CENTER); + button.get_style_context().add_class ("suggested-action"); + button.clicked.connect(() => { + AppInfo.launch_default_for_uri_async.begin(login_uri, null); + browser_toggled(); + }); + box.pack_end(button); + + widget = box; } public DialogPane.GeometryOptions get_preferred_geometry() { @@ -120,11 +55,9 @@ namespace Shotwell.Plugins.Common { } public void on_pane_installed () { - this.get_view ().load_uri (this.login_uri); } public void on_pane_uninstalled() { - this.clear(); - } - } + } + } } |
