[glom] show_help(): Use gtk_show_uri() with a help: URI.



commit caed2762b45d939996be288ab2a92347018800da
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Mar 7 20:32:54 2016 +0100

    show_help(): Use gtk_show_uri() with a help: URI.
    
    This seems to actually work. I don't think it worked for a while
    after something changed about how GNOME does help files or IDs.
    
    This fixes bug #763250 (m.rick.mac)

 glom/appwindow.cc |    2 +-
 glom/utils_ui.cc  |   84 +++++++++++++---------------------------------------
 glom/utils_ui.h   |    2 +-
 3 files changed, 23 insertions(+), 65 deletions(-)
---
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index 639e849..186dcb3 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -1476,7 +1476,7 @@ void AppWindow::set_mode_find()
 
 void AppWindow::on_menu_help_contents()
 {
-  Glom::UiUtils::show_help();
+  Glom::UiUtils::show_help(this);
 }
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index 141a152..b307867 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -90,37 +90,6 @@ static Glib::RefPtr<Gtk::CssProvider> create_css_provider(Gtk::Widget& widget)
   return css_provider;
 }
 
-// Basically copied from libgnome (gnome-help.c, Copyright (C) 2001 Sid Vicious
-// Copyright (C) 2001 Jonathan Blandford <jrb alum mit edu>), but C++ified
-std::string locate_help_file(const std::string& path, const std::string& doc_name)
-{
-  // g_get_language_names seems not to be wrapped by glibmm
-  const char* const* lang_list = g_get_language_names ();
-
-  for(unsigned int j = 0; lang_list[j] != 0; ++j)
-  {
-    const char* lang = lang_list[j];
-
-    /* This must be a valid language AND a language with
-     * no encoding postfix.  The language will come up without
-     * encoding next. */
-    if(lang == 0 || strchr(lang, '.') != 0)
-      continue;
-
-    const char* exts[] = { "", ".xml", ".docbook", ".sgml", ".html", 0 };
-    for(unsigned i = 0; exts[i] != 0; ++i)
-    {
-      std::string name = doc_name + exts[i];
-      std::string full = Glib::build_filename(path, Glib::build_filename(lang, name));
-
-      if(Glib::file_test(full, Glib::FILE_TEST_EXISTS))
-        return full;
-    }
-  }
-
-  return std::string();
-}
-
 } //anonymous namespace
 
 namespace Glom
@@ -133,7 +102,7 @@ int UiUtils::dialog_run_with_help(Gtk::Dialog* dialog, const Glib::ustring& id)
   
   while (result == Gtk::RESPONSE_HELP)
   {
-    show_help(id);
+    show_help(dialog, id);
     result = dialog->run();
   }
 
@@ -147,41 +116,30 @@ int UiUtils::dialog_run_with_help(Gtk::Dialog* dialog, const Glib::ustring& id)
  * Launch a help browser with the glom help and load the given id if given
  * If the help cannot be found an error dialog will be shown
  */
-void UiUtils::show_help(const Glib::ustring& id)
+void UiUtils::show_help(Gtk::Window* parent_window, const Glib::ustring& id)
 {
-  GError* err = nullptr;
-  const gchar* pId;
-  if(id.length())
-  {
-    pId = id.c_str();
-  }
-  else
-  {
-    pId = nullptr;
-  }
-
+  //TODO: Check that this actually works for any dialog that has an ID in the help files.
+  Glib::ustring uri = "help:glom";
+  if (!id.empty())
+    uri + "/" + id;
+    
   try
   {
-    const char path[] = GLOM_DATADIR G_DIR_SEPARATOR_S "gnome"
-                                     G_DIR_SEPARATOR_S "help"
-                                     G_DIR_SEPARATOR_S "glom";
-    std::string help_file = locate_help_file(path, "glom.xml");
-    if(help_file.empty())
-    {
-      throw std::runtime_error(_("No help file available"));
-    }
-    else
+    //Use the GNOME help browser:
+    GError* gerror = nullptr;
+    Glib::RefPtr<Gdk::Screen> screen;
+    if(parent_window)
+      screen = parent_window->get_screen();
+
+    std::cout << "debug: opening URI:" << uri << std::endl;
+    if(!gtk_show_uri(screen ? screen->gobj() : nullptr,
+      uri.c_str(), GDK_CURRENT_TIME, &gerror))
     {
-      std::string uri = "ghelp:" + help_file;
-      if(pId) { uri += '?'; uri += pId; }
+      std::cerr << G_STRFUNC << ": " << gerror->message << std::endl;
 
-      // g_app_info_launch_default_for_uri seems not to be wrapped by giomm
-      if(!g_app_info_launch_default_for_uri(uri.c_str(), 0, &err))
-      {
-        std::string message(err->message);
-        g_error_free(err);
-        throw std::runtime_error(message);
-      }
+      const Glib::ustring message(gerror->message);
+      g_error_free(gerror);
+      throw std::runtime_error(message);
     }
   }
   catch(const std::exception& ex)
diff --git a/glom/utils_ui.h b/glom/utils_ui.h
index bc52d30..cd514b4 100644
--- a/glom/utils_ui.h
+++ b/glom/utils_ui.h
@@ -66,7 +66,7 @@ int dialog_run_with_help(T_Dialog* dialog)
  * to avoid the libgnome dependency.
  * TODO: GTK+ should have a function for this soon.
  */
-void show_help(const Glib::ustring& id = Glib::ustring());
+void show_help(Gtk::Window* parent_window, const Glib::ustring& id = Glib::ustring());
 
 void show_ok_dialog(const Glib::ustring& title, const Glib::ustring& message, Gtk::Window& parent, 
Gtk::MessageType message_type);
 void show_ok_dialog(const Glib::ustring& title, const Glib::ustring& message, Gtk::Window* parent, 
Gtk::MessageType message_type);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]