[PATCH] Fix help browser launching



Hello,

The way we are launching the help browser from Nemiver is convoluted
for historical reasons.  In these Yelp 3 times, it turned out this
could be greatly improved.

Fixed thus, applied to master.

	* src/common/nmv-env.cc (build_path_to_help_file): Remove definition.
	* src/common/nmv-env.h (build_path_to_help_file): Remove
	declaration.
	* src/workbench/nmv-workbench.cc
	(Workbench::on_contents_menu_item_action): Use gtk_show_uri
	instead of the previously convoluted env::build_path_to_help_file.
	* tests/Makefile.am: Don't run untestenv that was testing
	env:build_path_to_help_file.
	* tests/test-env.cc (test_build_path_to_help_file): Remove.
	(init_unit_test_suite): Comment the juice out of this, waiting for
	more env tests to come.
---
 src/common/nmv-env.cc          | 80 ------------------------------------------
 src/common/nmv-env.h           |  2 --
 src/workbench/nmv-workbench.cc | 16 ++-------
 tests/Makefile.am              | 11 +++---
 tests/test-env.cc              | 19 +++-------
 5 files changed, 13 insertions(+), 115 deletions(-)

diff --git a/src/common/nmv-env.cc b/src/common/nmv-env.cc
index 6804cd2..42cfdd9 100644
--- a/src/common/nmv-env.cc
+++ b/src/common/nmv-env.cc
@@ -282,86 +282,6 @@ build_path_to_image_file (const UString &a_image_file_name)
     return result;
 }
 
-UString
-build_path_to_help_file (const UString &a_file_name)
-{
-    //So, before all, don't forget that a locale name has the general form:
-    //language[_territory][.codeset][@modifier]
-    //
-    //Once that is said, let's not forget either that
-    //the help file is located under the directory:
-    //$prefix/share/gnome/help/nemiver/language[_territory]
-    //So the goal of this function is to go look in that directory
-    //to see if a_file_name exists there. If so, return the path to it.
-    //Otherwise, return an empty string.
-    std::string result;
-    UString prefix (get_install_prefix ());
-    vector<std::string> path_elems;
-    path_elems.push_back (Glib::filename_from_utf8 (prefix));
-    path_elems.push_back ("share");
-    path_elems.push_back ("gnome");
-    path_elems.push_back ("help");
-    path_elems.push_back ("nemiver");
-
-    std::string help_dir = Glib::build_filename (path_elems);
-
-    if (!Glib::file_test (help_dir, Glib::FILE_TEST_IS_DIR)) {
-        LOG_ERROR ("help dir " << help_dir << " does not exist");
-        return "";
-    }
-
-    locale loc ("");
-    UString loc_name (loc.name ());
-    LOG_DD ("locale name: " << loc_name);
-    std::string lang_dir = Glib::build_filename (help_dir, loc_name.raw ());
-    if (!Glib::file_test (lang_dir, Glib::FILE_TEST_IS_DIR)) {
-        LOG_DD ("lang dir '" << lang_dir << "' does not exist");
-        //let's try now to extract the <language>_<territory> part of the
-        //locale, that can be of the more general form:
-        //language[_territory][.codeset][@modifier]
-        vector<UString> tmp;
-        tmp = loc_name.split (".");
-        if (tmp.empty ()) {
-            goto locale_language;
-        }
-        loc_name = tmp[0];
-        lang_dir = Glib::build_filename (help_dir, loc_name.raw ());
-        LOG_DD ("trying locale name: " << lang_dir);
-        if (!Glib::file_test (lang_dir, Glib::FILE_TEST_IS_DIR)) {
-            LOG_DD ("lang dir '" << lang_dir << "' does not exist");
-            //let's try to extract the <language> part of the locale now.
-locale_language:
-            tmp.clear ();
-            tmp = loc_name.split ("_");
-            if (tmp.empty ()) {
-                goto c_locale;
-            }
-            loc_name = tmp[0];
-            lang_dir = Glib::build_filename (help_dir, loc_name.raw ());
-            LOG_DD ("trying locale name: " << lang_dir);
-            if (!Glib::file_test (lang_dir, Glib::FILE_TEST_IS_DIR)) {
-                LOG_DD ("lang dir '" << lang_dir << "' does not exist");
-                //okay so let's fall back to the C locale then.
-c_locale:
-                loc_name = "C";
-                lang_dir = Glib::build_filename (help_dir, loc_name.raw ());
-                LOG_DD ("trying locale name: " << lang_dir);
-                if (!Glib::file_test (lang_dir, Glib::FILE_TEST_IS_DIR)) {
-                    LOG_ERROR ("could not find a proper help dir");
-                    return UString ();
-                }
-            }
-        }
-    }
-    result = Glib::build_filename (lang_dir, a_file_name);
-    if (!Glib::file_test (result, Glib::FILE_TEST_IS_REGULAR)) {
-        LOG_ERROR ("file " << result << " does not exist!");
-        result.clear ();
-    }
-    return Glib::filename_to_utf8 (result);
-}
-
-
 bool
 build_path_to_executable (const UString &a_exe_name,
                           UString &a_path_to_exe)
diff --git a/src/common/nmv-env.h b/src/common/nmv-env.h
index 2d15bfd..ee76963 100644
--- a/src/common/nmv-env.h
+++ b/src/common/nmv-env.h
@@ -78,8 +78,6 @@ NEMIVER_API UString build_path_to_menu_file (const UString &a_ui_file_name);
 
 NEMIVER_API UString build_path_to_image_file (const UString &a_image_file_name);
 
-NEMIVER_API UString build_path_to_help_file (const UString &a_file_name);
-
 NEMIVER_API bool build_path_to_executable (const UString &a_exe_name,
                                            UString &a_exe_path);
 
diff --git a/src/workbench/nmv-workbench.cc b/src/workbench/nmv-workbench.cc
index e82c13d..fadda00 100644
--- a/src/workbench/nmv-workbench.cc
+++ b/src/workbench/nmv-workbench.cc
@@ -233,21 +233,9 @@ Workbench::on_quit_menu_item_action ()
 void
 Workbench::on_contents_menu_item_action ()
 {
-    NEMIVER_TRY
-
-    UString help_url = "ghelp:nemiver";
+    UString help_url = "help:" PACKAGE_TARNAME;
     LOG_DD ("launching help url: " << help_url);
-    UString path_to_help =
-        nemiver::common::env::build_path_to_help_file ("nemiver.xml");
-    THROW_IF_FAIL (!path_to_help.empty ());
-    UString cmd_line ("yelp " + path_to_help);
-    LOG_DD ("going to spawn: " << cmd_line);
-    bool is_ok = g_spawn_command_line_async (Glib::locale_from_utf8
-                                             (cmd_line).c_str (), 0);
-    if (!is_ok) {
-        LOG_ERROR ("failed to spawn " << is_ok);
-    }
-    NEMIVER_CATCH
+    gtk_show_uri (NULL, help_url.c_str (), 0, NULL);
 }
 
 void
diff --git a/tests/Makefile.am b/tests/Makefile.am
index afbe7fd..c9bb30e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,6 +6,7 @@ if AUTOTESTS
 
 #runtestoverloads
 #runtestglobalvariables
+#runtestenv
 
 TESTS=\
 runtestgdbmi runtestunicode \
@@ -15,7 +16,7 @@ runtestwatchpoint runtestderef \
 runtestlocalvarslist runtestcpplexer \
 runtestcppparser runtestvarpathexpr \
 runtestlibtoolwrapperdetection \
-runtestenv runtesttypes runtestdisassemble \
+runtesttypes runtestdisassemble \
 runtestvariableformat runtestprettyprint
 
 else
@@ -155,10 +156,10 @@ runtestlibtoolwrapperdetection_LDADD=@NEMIVERCOMMON_LIBS@ \
 $(top_builddir)/src/langs/libnemivercparser.la \
 $(top_builddir)/src/common/libnemivercommon.la
 
-runtestenv_SOURCES=$(h)/test-env.cc
-runtestenv_LDADD=@NEMIVERCOMMON_LIBS@ \
-@BOOST_UNIT_TEST_FRAMEWORK_STATIC_LIB@ \
-$(top_builddir)/src/common/libnemivercommon.la
+#runtestenv_SOURCES=$(h)/test-env.cc
+#runtestenv_LDADD=@NEMIVERCOMMON_LIBS@ \
+#@BOOST_UNIT_TEST_FRAMEWORK_STATIC_LIB@ \
+#$(top_builddir)/src/common/libnemivercommon.la
 
 runtesttypes_SOURCES=$(h)/test-types.cc
 runtesttypes_LDADD=@NEMIVERCOMMON_LIBS@ \
diff --git a/tests/test-env.cc b/tests/test-env.cc
index 5027650..c116c2e 100644
--- a/tests/test-env.cc
+++ b/tests/test-env.cc
@@ -13,27 +13,18 @@ using nemiver::common::UString;
 using nemiver::common::Initializer;
 using boost::unit_test::test_suite;
 namespace env=nemiver::common::env;
-void
-test_build_path_to_help_file ()
-{
-    string nemiver_file ("nemiver.xml");
-    UString path (env::build_path_to_help_file ("nemiver.xml"));
-    BOOST_REQUIRE_MESSAGE (!path.empty (),
-                           "failed build path to " + nemiver_file);
-}
+
 
 test_suite*
-init_unit_test_suite (int argc, char** argv)
+init_unit_test_suite (int, char**)
 {
-    if (argc || argv) {/*keep compiler happy*/}
-
     NEMIVER_TRY
 
     Initializer::do_init ();
 
-    test_suite *suite = BOOST_TEST_SUITE ("nemiver env tests");
-    suite->add (BOOST_TEST_CASE (&test_build_path_to_help_file));
-    return suite;
+    // test_suite *suite = BOOST_TEST_SUITE ("nemiver env tests");
+    // suite->add (BOOST_TEST_CASE (&test_function_to_be_defined));
+    // return suite;
 
     NEMIVER_CATCH_NOX
 
-- 
		Dodji


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