nemiver r814 - in trunk: . src src/common src/workbench tests



Author: dodji
Date: Sat May 17 14:44:02 2008
New Revision: 814
URL: http://svn.gnome.org/viewvc/nemiver?rev=814&view=rev

Log:
[workbench] don't use libgnome anymore

Libgnome was used to display the nemiver help. So basically the called used
was gnome_help_display(). That call was replaced by building the path to
the nemiver help file and directly spawning yelp with that path.


Added:
   trunk/tests/test-env.cc
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/src/common/nmv-env.cc
   trunk/src/common/nmv-env.h
   trunk/src/main.cc
   trunk/src/workbench/nmv-workbench.cc
   trunk/tests/Makefile.am

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Sat May 17 14:44:02 2008
@@ -28,8 +28,6 @@
 AC_SUBST([LIBGTHREAD_VERSION])
 LIBGLIBMM_VERSION=2.14
 AC_SUBST([LIBGLIBMM_VERSION])
-LIBGNOME_VERSION=2.0
-AC_SUBST([LIBGNOME_VERSION])
 LIBGNOMEVFS_VERSION=2.14
 AC_SUBST([LIBGNOMEVFS_VERSION])
 LIBXML2_VERSION=2.6.22
@@ -237,7 +235,6 @@
 PKG_CHECK_MODULES(LIBXML2, [libxml-2.0 >= $LIBXML2_VERSION])
 PKG_CHECK_MODULES(LIBGMODULE, [gmodule-2.0 >= $LIBGMODULE_VERSION])
 PKG_CHECK_MODULES(LIBGTHREAD, [gthread-2.0 >= $LIBGTHREAD_VERSION])
-PKG_CHECK_MODULES(LIBGNOME, [libgnome-2.0 >= $LIBGNOME_VERSION])
 PKG_CHECK_MODULES(LIBVFS, [$VFS_PKG >= $VFS_VERSION])
 PKG_CHECK_MODULES(LIBGTOP, [libgtop-2.0 >= $LIBGTOP_VERSION])
 PKG_CHECK_MODULES(GCONF,[gconf-2.0 >= $GCONF_VERSION])
@@ -302,11 +299,9 @@
 
 dnl library dependencies for the nemiver workbench module
 NEMIVERWORKBENCH_LIBS="$NEMIVERCOMMON_LIBS $LIBGTKMM_LIBS $LIBGLADEMM_LIBS"
-NEMIVERWORKBENCH_LIBS="$NEMIVERWORKBENCH_LIBS $LIBGNOME_LIBS"
 NEMIVERWORKBENCH_LIBS="$NEMIVERWORKBENCH_LIBS $LIBVFS_LIBS"
 NEMIVERWORKBENCH_CFLAGS="$NEMIVERCOMMON_CFLAGS $LIBGTKMM_CFLAGS "
 NEMIVERWORKBENCH_CFLAGS="$NEMIVERWORKBENCH_CFLAGS $LIBGLADEMM_CFLAGS"
-NEMIVERWORKBENCH_CFLAGS="$NEMIVERWORKBENCH_CFLAGS $LIBGNOME_CFLAGS"
 NEMIVERWORKBENCH_CFLAGS="$NEMIVERWORKBENCH_CFLAGS $LIBVFS_CFLAGS"
 
 AC_SUBST(NEMIVERWORKBENCH_LIBS)
@@ -325,8 +320,8 @@
 AC_SUBST(NEMIVERDBGPERSP_LIBS)
 AC_SUBST(NEMIVERDBGPERSP_CFLAGS)
 
-NEMIVER_LIBS="$NEMIVERUICOMMON_LIBS $LIBGNOME_LIBS"
-NEMIVER_CFLAGS="$NEMIVERUICOMMON_CFLAGS $LIBGNOME_CFLAGS"
+NEMIVER_LIBS="$NEMIVERUICOMMON_LIBS"
+NEMIVER_CFLAGS="$NEMIVERUICOMMON_CFLAGS"
 
 AC_SUBST(NEMIVER_LIBS)
 AC_SUBST(NEMIVER_CFLAGS)

Modified: trunk/src/common/nmv-env.cc
==============================================================================
--- trunk/src/common/nmv-env.cc	(original)
+++ trunk/src/common/nmv-env.cc	Sat May 17 14:44:02 2008
@@ -39,9 +39,9 @@
 
 using namespace std ;
 
-namespace nemiver {
-namespace common {
-namespace env {
+NEMIVER_BEGIN_NAMESPACE (nemiver)
+NEMIVER_BEGIN_NAMESPACE (common)
+NEMIVER_BEGIN_NAMESPACE (env)
 
 class Initializer
 {
@@ -279,6 +279,86 @@
     return result ;
 }
 
-}//end namespace env
-}//end namespace common
-}//end namespace nemiver
+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.
+    UString result;
+    UString prefix (get_install_prefix ());
+    vector<string> path_elems;
+    path_elems.push_back (prefix.c_str ());
+    path_elems.push_back ("share");
+    path_elems.push_back ("gnome");
+    path_elems.push_back ("help");
+    path_elems.push_back ("nemiver");
+
+    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);
+    string lang_dir = Glib::build_filename (help_dir, loc_name.c_str ());
+    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.c_str ());
+        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.c_str ());
+            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.c_str ());
+                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 result;
+                }
+            }
+        }
+    }
+    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 result;
+}
+
+NEMIVER_END_NAMESPACE (env)
+NEMIVER_END_NAMESPACE (common)
+NEMIVER_END_NAMESPACE (nemiver)
+

Modified: trunk/src/common/nmv-env.h
==============================================================================
--- trunk/src/common/nmv-env.h	(original)
+++ trunk/src/common/nmv-env.h	Sat May 17 14:44:02 2008
@@ -34,9 +34,9 @@
 #include "nmv-ustring.h"
 #include "nmv-exception.h"
 
-namespace nemiver {
-namespace common {
-namespace env {
+NEMIVER_BEGIN_NAMESPACE (nemiver)
+NEMIVER_BEGIN_NAMESPACE (common)
+NEMIVER_BEGIN_NAMESPACE (env)
 
 void do_init () ;
 
@@ -76,10 +76,11 @@
 
 NEMIVER_API UString build_path_to_image_file (const UString &a_image_file_name) ;
 
-}//end namespace env
-}//end namespace common
-}//end namespace nemiver
+NEMIVER_API UString build_path_to_help_file (const UString &a_file_name);
 
+NEMIVER_END_NAMESPACE (env)
+NEMIVER_END_NAMESPACE (common)
+NEMIVER_END_NAMESPACE (nemiver)
 
 #endif //__NEMIVER_ENV_H__
 

Modified: trunk/src/main.cc
==============================================================================
--- trunk/src/main.cc	(original)
+++ trunk/src/main.cc	Sat May 17 14:44:02 2008
@@ -27,7 +27,6 @@
 #include <gtkmm/window.h>
 #include <libglademm.h>
 #include <glib/gi18n.h>
-#include <libgnome/gnome-init.h>
 #include "nmv-exception.h"
 #include "nmv-initializer.h"
 #include "nmv-i-workbench.h"
@@ -439,11 +438,6 @@
 
     parse_command_line (a_argc, a_argv);
 
-    //intialize gnome libraries
-    gnome_program_init (PACKAGE, PACKAGE_VERSION,
-                        LIBGNOME_MODULE, a_argc, a_argv,
-                        GNOME_PROGRAM_STANDARD_PROPERTIES, NULL);
-
 
     //**********************************
     //load the workbench dynamic module

Modified: trunk/src/workbench/nmv-workbench.cc
==============================================================================
--- trunk/src/workbench/nmv-workbench.cc	(original)
+++ trunk/src/workbench/nmv-workbench.cc	Sat May 17 14:44:02 2008
@@ -27,7 +27,6 @@
 #include <vector>
 #include <iostream>
 #include <glib/gi18n.h>
-#include <libgnome/gnome-help.h>
 #ifdef WITH_GIO
 #include <giomm/init.h>
 #else
@@ -227,9 +226,20 @@
 void
 Workbench::on_contents_menu_item_action ()
 {
-    gnome_help_display("nemiver.xml",
-                       NULL, /*link id*/
-                       NULL /*GError*/);
+    NEMIVER_TRY
+
+    UString help_url = "ghelp:nemiver";
+    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 (cmd_line.c_str (), NULL);
+    if (!is_ok) {
+        LOG_ERROR ("failed to spawn " << is_ok);
+    }
+    NEMIVER_CATCH
 }
 
 void

Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am	(original)
+++ trunk/tests/Makefile.am	Sat May 17 14:44:02 2008
@@ -11,7 +11,8 @@
 runtestderef \
 runtestlocalvarslist runtestcpplexer \
 runtestcppparser  \
-runtestlibtoolwrapperdetection
+runtestlibtoolwrapperdetection \
+runtestenv
 
 
 else
@@ -104,6 +105,11 @@
 $(top_builddir)/src/langs/libnemivercparser.la \
 $(top_builddir)/src/common/libnemivercommon.la
 
+runtestenv_SOURCES=test-env.cc
+runtestenv_LDADD= NEMIVERCOMMON_LIBS@ \
+ BOOST_UNIT_TEST_FRAMEWORK_STATIC_LIB@ \
+$(top_builddir)/src/common/libnemivercommon.la
+
 docore_SOURCES=do-core.cc
 docore_LDADD= NEMIVERCOMMON_LIBS@ \
 $(top_builddir)/src/common/libnemivercommon.la

Added: trunk/tests/test-env.cc
==============================================================================
--- (empty file)
+++ trunk/tests/test-env.cc	Sat May 17 14:44:02 2008
@@ -0,0 +1,40 @@
+#include <iostream>
+#include <string>
+#include <boost/test/unit_test.hpp>
+#include <glibmm.h>
+#include "common/nmv-ustring.h"
+#include "common/nmv-initializer.h"
+#include "common/nmv-exception.h"
+#include "common/nmv-env.h"
+
+using namespace std;
+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)
+{
+    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;
+
+    NEMIVER_CATCH_NOX
+
+    return 0;
+}



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