[gparted] port-to-gtk3: Use Gdk::AppLaunchContext to launch yelp (#7)
- From: Mike Fleetwood <mfleetwo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] port-to-gtk3: Use Gdk::AppLaunchContext to launch yelp (#7)
- Date: Mon, 11 Feb 2019 09:19:55 +0000 (UTC)
commit 2953778a4c0e61d8fe49c7a6d707add8a9eb0634
Author: Luca Bacci <luca bacci982 gmail com>
Date: Thu Aug 9 10:26:44 2018 +0200
port-to-gtk3: Use Gdk::AppLaunchContext to launch yelp (#7)
gdk_spawn_command_line_on_screen() is not present in Gtk3. The
documentation from Gtkmm 2.24 states [1]:
gdk_spawn_command_line_on_screen has been deprecated since version
2.24 and should not be used in newly-written code. This function is
being removed in 3.0. Use either g_spawn_command_line_sync(),
g_spawn_command_line_async() or GdkAppLaunchContext instead.
g_spawn_command_line_sync() and g_spawn_command_line_async() are screen
/ display agnostic, as such we would loose functionality. There is a
workaround, which involves setting the DISPLAY environment variable [2],
but it's a weak solution (and I don't know if it works on backends
other than X11).
GdkAppLaunchContext is an implementation of GIO's GAppLaunchContext that
handles launching an application in a graphical context [3]. Therefore
use GdkAppLaunchContext and GIO's GAppInfo.
GdkAppLaunchContext was introduced in Gtk2 version 2.14. The C++
wrapper Gdk::AppLaunchContext was introduced only in Gtkmm3 version 3.4
[4]. Bump the minimum required version of Gtkmm to 3.4.0 for this
requirement.
GAppInfo was introduced in GLib version 2.16. The C++ wrapper
Gio::AppInfo was introduced in Giomm version 2.16. Note that the
minimum required version for glibmm is already 2.32.
[1] GDK 2 Reference Manual, GdkScreen, gdk_spawn_on_screen()
https://developer.gnome.org/gdk2/2.24/GdkScreen.html#gdk-spawn-on-screen
[2] Migrating from GTK+ 2.x to GTK+ 3 - "Use GIO for launching applications"
https://developer.gnome.org/gtk3/stable/gtk-migrating-2-to-3.html#id-1.6.3.3.7
[3] GDK 3 Reference Manual - "Application launching"
https://developer.gnome.org/gdk3/stable/gdk3-Application-launching.html
[4] Gtkmm 3.4 Gdk::AppLaunchContext Class Reference, Detailed Description
https://developer.gnome.org/gtkmm/3.4/classGdk_1_1AppLaunchContext.html#details
Closes #7 - Port to Gtk3
configure.ac | 2 +-
src/Win_GParted.cc | 50 +++++++++++++++++++++++++++++++++-----------------
2 files changed, 34 insertions(+), 18 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9c11ab79..8cad5e8e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -199,7 +199,7 @@ AC_SUBST([GTHREAD_LIBS])
AC_SUBST([GTHREAD_CFLAGS])
dnl GTKMM
-PKG_CHECK_MODULES([GTKMM], [gtkmm-3.0 >= 3.0.0])
+PKG_CHECK_MODULES([GTKMM], [gtkmm-3.0 >= 3.4.0])
AC_SUBST([GTKMM_LIBS])
AC_SUBST([GTKMM_CFLAGS])
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index a30329ba..ea29baa7 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -1748,28 +1748,44 @@ void Win_GParted::show_help_dialog( const Glib::ustring & filename /* E.g., gpar
uri = uri + "?" + link_id ;
}
- gscreen = gdk_screen_get_default() ;
-
+ gscreen = get_window()->get_screen()->gobj();
gtk_show_uri( gscreen, uri .c_str(), gtk_get_current_event_time(), &error ) ;
if ( error != NULL )
{
//Try opening yelp application directly
- g_clear_error( &error ); // Clear error from trying to open gparted help manual above
(gtk_show_uri).
- Glib::ustring command = "yelp " + uri ;
- gdk_spawn_command_line_on_screen( gscreen, command .c_str(), &error ) ;
- }
- if ( error != NULL )
- {
- Gtk::MessageDialog dialog( *this
- , _( "Unable to open GParted Manual help file" )
- , false
- , Gtk::MESSAGE_ERROR
- , Gtk::BUTTONS_OK
- , true
- ) ;
- dialog .set_secondary_text( error ->message ) ;
- dialog .run() ;
+ Glib::RefPtr<Gio::AppInfo> yelp
+ = Gio::AppInfo::create_from_commandline("yelp", "",
Gio::APP_INFO_CREATE_SUPPORTS_URIS);
+
+ Glib::RefPtr<Gdk::AppLaunchContext> context
+ = get_window()->get_display()->get_app_launch_context();
+
+ context->set_timestamp(gtk_get_current_event_time());
+
+ bool launched;
+ try
+ {
+ launched = yelp->launch_uris(std::vector<std::string>(1, uri), context);
+ }
+ catch (Glib::Error& e)
+ {
+ std::cerr << e.what() << std::endl;
+ launched = false;
+ }
+
+ if (!launched)
+ {
+ Gtk::MessageDialog dialog(*this,
+ _( "Unable to open GParted Manual help file" ),
+ false,
+ Gtk::MESSAGE_ERROR,
+ Gtk::BUTTONS_OK,
+ true);
+ dialog.set_secondary_text(error->message);
+ dialog.run();
+ }
+
+ g_clear_error(&error);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]