Replace deprecated gtk_show_uri() method for help window (!82)

The gtk_show_uri() [1] method was deprecated as of gtk3 version 3.22 and
has been replaced with gtk_show_uri_on_window [2].

[1] https://developer.gnome.org/gtk3/stable/gtk3-Filesystem-utilities.html#gtk-show-uri
[2] https://developer.gnome.org/gtk3/stable/gtk-migrating-2-to-3.html#id-1.6.3.3.7

Note that AppInfo::launch_uris() has been removed because with
glib/glibmm >= 2.58 AppInfo::launch_uris() always reports success even
when yelp is not launched and in such cases prevents the dialog
reporting the error from being displayed.

Closes !82 - Replace deprecated gtk_show_uri() method for help window
This commit is contained in:
Curtis Gedak 2021-05-15 11:52:50 -06:00 committed by Mike Fleetwood
parent f5b17f40fe
commit 26f4dc504a
2 changed files with 55 additions and 40 deletions

View File

@ -266,6 +266,18 @@ PKG_CHECK_EXISTS(
) )
dnl Check for gtk+-3.0 >= 3.22 to determine availability of gtk_show_uri_on_window() function.
AC_MSG_CHECKING([for gtk_show_uri_on_window() function])
PKG_CHECK_EXISTS(
[gtk+-3.0 >= 3.22.0],
[AC_DEFINE([HAVE_GTK_SHOW_URI_ON_WINDOW], 1,
[Define to 1 if gtk provides gtk_show_uri_on_window function.])
AC_MSG_RESULT([yes])
],
[AC_MSG_RESULT([no])]
)
dnl Definitions for building of and with gtest. Gets flags for pthread via earlier dnl Definitions for building of and with gtest. Gets flags for pthread via earlier
dnl gthread package check. dnl gthread package check.
GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1" GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"

View File

@ -1778,52 +1778,55 @@ void Win_GParted::show_resize_readonly( const Glib::ustring & path )
void Win_GParted::show_help(const Glib::ustring & filename /* E.g., "gparted" */, void Win_GParted::show_help(const Glib::ustring & filename /* E.g., "gparted" */,
const Glib::ustring & link_id /* For context sensitive help */) const Glib::ustring & link_id /* For context sensitive help */)
{ {
GError *error1 = NULL; // Build uri string
GdkScreen *gscreen = NULL ;
Glib::ustring uri = "help:" + filename; Glib::ustring uri = "help:" + filename;
if (link_id.size() > 0) if (link_id.size() > 0)
uri = uri + "/" + link_id; uri = uri + "/" + link_id;
gscreen = get_window()->get_screen()->gobj(); // Check if yelp is available to provide a useful error message.
gtk_show_uri(gscreen, uri.c_str(), gtk_get_current_event_time(), &error1); // Missing yelp is the most common cause of failure to display help.
if (error1 != NULL) //
// This early check is performed because failure of gtk_show_uri*()
// method only provides a generic "Operation not permitted" message.
if (Glib::find_program_in_path("yelp").empty())
{ {
//Try opening yelp application directly Gtk::MessageDialog errorDialog(*this,
_("Unable to open GParted Manual help file"),
Glib::RefPtr<Gio::AppInfo> yelp false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
= Gio::AppInfo::create_from_commandline("yelp", "", Gio::APP_INFO_CREATE_SUPPORTS_URIS); Glib::ustring sec_text(_("Command yelp not found."));
sec_text.append("\n");
Glib::RefPtr<Gdk::AppLaunchContext> context sec_text.append("\n");
= get_window()->get_display()->get_app_launch_context(); sec_text.append(_("Install yelp and try again."));
errorDialog.set_secondary_text(sec_text, true);
context->set_timestamp(gtk_get_current_event_time()); errorDialog.run();
return;
bool launched = false;
Glib::ustring error2_msg;
try
{
launched = yelp->launch_uris(std::vector<std::string>(1, uri), context);
}
catch (Glib::Error& e)
{
error2_msg = e.what();
} }
if (!launched) GError *error = NULL;
// Display help window
#if HAVE_GTK_SHOW_URI_ON_WINDOW
// NULL is provided for the gtk_show_uri_on_window() parent window
// so that failures to launch yelp are reported.
// https://gitlab.gnome.org/GNOME/gparted/-/merge_requests/82#note_1106114
gtk_show_uri_on_window(NULL, uri.c_str(), gtk_get_current_event_time(), &error);
#else
GdkScreen *gscreen = gscreen = gdk_screen_get_default();
gtk_show_uri(gscreen, uri.c_str(), gtk_get_current_event_time(), &error);
#endif
if (error != NULL)
{ {
Gtk::MessageDialog dialog(*this, Gtk::MessageDialog errorDialog(*this,
_( "Unable to open GParted Manual help file" ), _("Failed to open GParted Manual help file"),
false, false,
Gtk::MESSAGE_ERROR, Gtk::MESSAGE_ERROR,
Gtk::BUTTONS_OK, Gtk::BUTTONS_OK,
true); true);
dialog.set_secondary_text(error2_msg); errorDialog.set_secondary_text(error->message);
dialog.run(); errorDialog.run();
} }
g_clear_error(&error1); g_clear_error(&error);
}
} }
void Win_GParted::menu_help_contents() void Win_GParted::menu_help_contents()