[geary] Use Gtk.show_uri_on_window when available. Bug 770884.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Use Gtk.show_uri_on_window when available. Bug 770884.
- Date: Mon, 27 Feb 2017 13:25:02 +0000 (UTC)
commit 2349ea6892e07d09445f1a6b95af5c3f924a631d
Author: Michael James Gratton <mike vee net>
Date: Mon Feb 27 11:36:17 2017 +1100
Use Gtk.show_uri_on_window when available. Bug 770884.
* src/CMakeLists.txt: Define a macro when Gtk+ 3.22 is available.
* src/client/application/geary-application.vala (GearyApplication): Add
show_uri method that uses the app's currently active window/screen to
show the URI on, add a compile-time test to use Gtk.show_uri or
Gtk.show_uri_on_window as appropriate, make the API nicer to use by
not having two different error reporting methods. Rework existing uses
of Gtk.show_uri to use this method.
src/CMakeLists.txt | 7 +++++++
src/client/application/geary-application.vala | 21 ++++++++++++++++++++-
src/client/application/geary-controller.vala | 17 +++++++++--------
3 files changed, 36 insertions(+), 9 deletions(-)
---
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4b39a8f..64c541e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -593,6 +593,13 @@ if (NOT DEPS_gtk+-3.0_VERSION VERSION_LESS 3.20)
)
endif()
+if (NOT DEPS_gtk+-3.0_VERSION VERSION_LESS 3.22)
+ set(EXTRA_VALA_OPTIONS
+ ${EXTRA_VALA_OPTIONS}
+ -D GTK_3_22
+ )
+endif()
+
if (DISABLE_POODLE)
message(STATUS "POODLE SSLv3 fix: OFF")
set(EXTRA_VALA_OPTIONS
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index 324cebf..563fd3e 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -372,6 +372,25 @@ public class GearyApplication : Gtk.Application {
}
}
+ /**
+ * Displays a URI on the current active window, if any.
+ */
+ public void show_uri(string uri) throws Error {
+ Gtk.Window? window = get_active_window();
+#if !GTK_3_22
+ bool success = Gtk.show_uri(
+ window != null ? window.get_screen() : null, uri, Gdk.CURRENT_TIME
+ );
+ if (!success) {
+ throw new IOError.FAILED("gtk_show_uri() returned false");
+ }
+#else
+ if (!Gtk.show_uri_on_window(window, uri, Gdk.CURRENT_TIME)) {
+ throw new IOError.FAILED("gtk_show_uri_on_window() returned false");
+ }
+#endif
+ }
+
// This call will fire "exiting" only if it's not already been fired.
public void exit(int exitcode = 0) {
if (exiting_fired)
@@ -481,7 +500,7 @@ public class GearyApplication : Gtk.Application {
private void on_activate_help() {
try {
if (is_installed()) {
- Gtk.show_uri(null, "ghelp:geary", Gdk.CURRENT_TIME);
+ show_uri("ghelp:geary");
} else {
Pid pid;
File exec_dir = get_exec_dir();
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 51638d2..a7dd147 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -2184,19 +2184,20 @@ public class GearyController : Geary.BaseObject {
// Opens a link in an external browser.
private bool open_uri(string _link) {
string link = _link;
-
+
// Support web URLs that ommit the protocol.
if (!link.contains(":"))
link = "http://" + link;
-
- bool ret = false;
+
+ bool success = true;
try {
- ret = Gtk.show_uri(main_window.get_screen(), link, Gdk.CURRENT_TIME);
+ this.application.show_uri(link);
} catch (Error err) {
- debug("Unable to open URL. %s", err.message);
+ success = false;
+ debug("Unable to open URL: \"%s\" %s", link, err.message);
}
-
- return ret;
+
+ return success;
}
internal bool close_composition_windows(bool main_window_only = false) {
@@ -2798,7 +2799,7 @@ public class GearyController : Geary.BaseObject {
FileUtils.chmod(temporary_filename, (int) (Posix.S_IRUSR | Posix.S_IWUSR));
string temporary_uri = Filename.to_uri(temporary_filename, null);
- Gtk.show_uri(main_window.get_screen(), temporary_uri, Gdk.CURRENT_TIME);
+ this.application.show_uri(temporary_uri);
} catch (Error error) {
ErrorDialog dialog = new ErrorDialog(
main_window,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]