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.
This commit is contained in:
Michael James Gratton 2017-02-27 11:36:17 +11:00
parent 4cab543e1b
commit 2349ea6892
3 changed files with 36 additions and 9 deletions

View file

@ -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

View file

@ -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();

View file

@ -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,