[gparted] Replace deprecated gtk_show_uri() method for help window (!82)
- From: Mike Fleetwood <mfleetwo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Replace deprecated gtk_show_uri() method for help window (!82)
- Date: Mon, 17 May 2021 20:51:16 +0000 (UTC)
commit 26f4dc504ab6837d717b1f047edc3853b1c67a5f
Author: Curtis Gedak <gedakc gmail com>
Date: Sat May 15 11:52:50 2021 -0600
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
configure.ac | 12 ++++++++
src/Win_GParted.cc | 81 ++++++++++++++++++++++++++++--------------------------
2 files changed, 54 insertions(+), 39 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4cd0c85e..22e2c93a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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 gthread package check.
GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index f15d29f4..f2d1975a 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -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" */,
const Glib::ustring & link_id /* For context sensitive help */)
{
- GError *error1 = NULL;
- GdkScreen *gscreen = NULL ;
-
+ // Build uri string
Glib::ustring uri = "help:" + filename;
if (link_id.size() > 0)
uri = uri + "/" + link_id;
- gscreen = get_window()->get_screen()->gobj();
- gtk_show_uri(gscreen, uri.c_str(), gtk_get_current_event_time(), &error1);
- if (error1 != NULL)
- {
- //Try opening yelp application directly
-
- 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 = 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();
- }
+ // Check if yelp is available to provide a useful error message.
+ // Missing yelp is the most common cause of failure to display help.
+ //
+ // 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())
+ {
+ Gtk::MessageDialog errorDialog(*this,
+ _("Unable to open GParted Manual help file"),
+ false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
+ Glib::ustring sec_text(_("Command yelp not found."));
+ sec_text.append("\n");
+ sec_text.append("\n");
+ sec_text.append(_("Install yelp and try again."));
+ errorDialog.set_secondary_text(sec_text, true);
+ errorDialog.run();
+ return;
+ }
- 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(error2_msg);
- dialog.run();
- }
+ GError *error = NULL;
- g_clear_error(&error1);
+ // 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 errorDialog(*this,
+ _("Failed to open GParted Manual help file"),
+ false,
+ Gtk::MESSAGE_ERROR,
+ Gtk::BUTTONS_OK,
+ true);
+ errorDialog.set_secondary_text(error->message);
+ errorDialog.run();
}
+
+ g_clear_error(&error);
}
void Win_GParted::menu_help_contents()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]