r22377 - gnucash/trunk/src - Eliminate gnome dependency in file location functions

Geert Janssens gjanssens at code.gnucash.org
Mon Sep 10 15:21:39 EDT 2012


Author: gjanssens
Date: 2012-09-10 15:21:38 -0400 (Mon, 10 Sep 2012)
New Revision: 22377
Trac: http://svn.gnucash.org/trac/changeset/22377

Modified:
   gnucash/trunk/src/core-utils/gnc-filepath-utils.c
   gnucash/trunk/src/core-utils/gnc-filepath-utils.h
   gnucash/trunk/src/core-utils/gnc-path.c
   gnucash/trunk/src/core-utils/gnc-path.h
   gnucash/trunk/src/gnome-utils/dialog-totd.c
   gnucash/trunk/src/gnome-utils/gnc-embedded-window.c
   gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
   gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h
   gnucash/trunk/src/gnome-utils/gnc-icons.c
   gnucash/trunk/src/gnome-utils/gnc-main-window.c
   gnucash/trunk/src/gnome-utils/gnc-plugin.c
   gnucash/trunk/src/gnome/window-reconcile.c
Log:
Eliminate gnome dependency in file location functions

As a side effect, they can now be grouped together with
our other file location functions in core-utils. They
no longer depend on any gui library.

Modified: gnucash/trunk/src/core-utils/gnc-filepath-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-filepath-utils.c	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/core-utils/gnc-filepath-utils.c	2012-09-10 19:21:38 UTC (rev 22377)
@@ -418,5 +418,67 @@
     return result;
 }
 
+static gchar *
+gnc_filepath_locate_file (const gchar *default_path, const gchar *name)
+{
+    gchar *fullname;
 
+    g_return_val_if_fail (name != NULL, NULL);
+
+    if (g_path_is_absolute (name))
+        fullname = g_strdup (name);
+    else if (default_path)
+        fullname = g_build_filename (default_path, name, NULL);
+    else
+        fullname = gnc_resolve_file_path (name);
+
+    if (!g_file_test (fullname, G_FILE_TEST_IS_REGULAR))
+    {
+        g_error ("Could not locate file %s", name);
+        g_free (fullname);
+        return NULL;
+    }
+
+    return fullname;
+}
+
+gchar *
+gnc_filepath_locate_data_file (const gchar *name)
+{
+    return gnc_filepath_locate_file (gnc_path_get_pkgdatadir(), name);
+}
+
+gchar *
+gnc_filepath_locate_pixmap (const gchar *name)
+{
+    gchar *default_path;
+    gchar *fullname;
+
+    default_path = g_build_filename (gnc_path_get_pkgdatadir (), "pixmaps", NULL);
+    fullname = gnc_filepath_locate_file (default_path, name);
+    g_free(default_path);
+
+    return fullname;
+}
+
+gchar *
+gnc_filepath_locate_ui_file (const gchar *name)
+{
+    gchar *default_path;
+    gchar *fullname;
+
+    default_path = g_build_filename (gnc_path_get_pkgdatadir (), "ui", NULL);
+    fullname = gnc_filepath_locate_file (default_path, name);
+    g_free(default_path);
+
+    return fullname;
+}
+
+gchar *
+gnc_filepath_locate_doc_file (const gchar *name)
+{
+    return gnc_filepath_locate_file (gnc_path_get_pkgdocdir(), name);
+}
+
+
 /* =============================== END OF FILE ========================== */

Modified: gnucash/trunk/src/core-utils/gnc-filepath-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-filepath-utils.h	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/core-utils/gnc-filepath-utils.h	2012-09-10 19:21:38 UTC (rev 22377)
@@ -49,4 +49,59 @@
 gchar *gnc_build_report_path (const gchar *filename);
 gchar *gnc_build_stdreports_path (const gchar *filename);
 
+/** Given a pixmap/pixbuf file name, find the file in the pixmap
+ *  directory associated with this application.  This routine will
+ *  display an error message if it can't find the file.
+ *
+ *  @param name The name of the file to be found.
+ *
+ *  @return the full path name of the file, or NULL of the file can't
+ *  be found.
+ *
+ *  @note It is the caller's responsibility to free the returned string.
+ */
+gchar *gnc_filepath_locate_pixmap (const gchar *name);
+
+
+/** Given a file name, find the file in the directories associated
+ *  with this application.  This routine will display an error message
+ *  if it can't find the file.
+ *
+ *  @param name The name of the file to be found.
+ *
+ *  @return the full path name of the file, or NULL of the file can't
+ *  be found.
+ *
+ *  @note It is the caller's responsibility to free the returned string.
+ */
+gchar *gnc_filepath_locate_data_file (const gchar *name);
+
+
+/** Given a ui file name, find the file in the ui directory associated
+ *  with this application.  This routine will display an error message
+ *  if it can't find the file.
+ *
+ *  @param name The name of the file to be found.
+ *
+ *  @return the full path name of the file, or NULL of the file can't
+ *  be found.
+ *
+ *  @note It is the caller's responsibility to free the returned string.
+ */
+gchar *gnc_filepath_locate_ui_file (const gchar *name);
+
+
+/** Given a documentation file name, find the file in the doc directory
+ *  associated with this application.  This routine will display an error
+ *  message if it can't find the file.
+ *
+ *  @param name The name of the file to be found.
+ *
+ *  @return the full path name of the file, or NULL of the file can't
+ *  be found.
+ *
+ *  @note It is the caller's responsibility to free the returned string.
+ */
+gchar *gnc_filepath_locate_doc_file (const gchar *name);
+
 #endif /* GNC_FILEPATH_UTILS_H */

Modified: gnucash/trunk/src/core-utils/gnc-path.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-path.c	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/core-utils/gnc-path.c	2012-09-10 19:21:38 UTC (rev 22377)
@@ -64,6 +64,19 @@
     return result;
 }
 
+/** Returns the docdir path, usually
+ * "$prefix/share/doc/gnucash".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_pkgdocdir()
+{
+    gchar *docdir = gnc_gbr_find_data_dir (DATADIR);
+    gchar *result = g_build_filename (docdir, "doc", "gnucash", (char*)NULL);
+    g_free (docdir);
+    //printf("Returning pkgdocdir %s\n", result);
+    return result;
+}
+
 /** Returns the sysconfdir path, usually
  * "$prefix/etc/gnucash". Needed for gnome_program_init().
  *

Modified: gnucash/trunk/src/core-utils/gnc-path.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-path.h	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/core-utils/gnc-path.h	2012-09-10 19:21:38 UTC (rev 22377)
@@ -49,6 +49,12 @@
  * @returns A newly allocated string. */
 gchar *gnc_path_get_pkgdatadir(void);
 
+/** Returns the pkgdocdir path, usually
+ * "$prefix/share/doc/gnucash".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_pkgdocdir(void);
+
 /** Returns the pkgsysconfdir path, usually
  * "$prefix/etc/gnucash". Needed for gnome_program_init(void).
  *

Modified: gnucash/trunk/src/gnome/window-reconcile.c
===================================================================
--- gnucash/trunk/src/gnome/window-reconcile.c	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/gnome/window-reconcile.c	2012-09-10 19:21:38 UTC (rev 22377)
@@ -46,6 +46,7 @@
 #include "gnc-component-manager.h"
 #include "gnc-date-edit.h"
 #include "gnc-event.h"
+#include "gnc-filepath-utils.h"
 #include "gnc-gconf-utils.h"
 #include "gnc-gnome-utils.h"
 #include "gnc-main-window.h"
@@ -1744,7 +1745,7 @@
 
         gtk_ui_manager_insert_action_group (recnData->ui_merge, action_group, 0);
 
-        filename = gnc_gnome_locate_ui_file("gnc-reconcile-window-ui.xml");
+        filename = gnc_filepath_locate_ui_file("gnc-reconcile-window-ui.xml");
         /* Can't do much without a ui. */
         g_assert (filename);
 

Modified: gnucash/trunk/src/gnome-utils/dialog-totd.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-totd.c	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/gnome-utils/dialog-totd.c	2012-09-10 19:21:38 UTC (rev 22377)
@@ -30,6 +30,7 @@
 #include "dialog-totd.h"
 #include "dialog-utils.h"
 #include "gnc-component-manager.h"
+#include "gnc-filepath-utils.h"
 #include "gnc-gconf-utils.h"
 #include "gnc-gnome-utils.h"
 #include "gnc-engine.h"
@@ -178,7 +179,7 @@
     GError *error;
 
     /* Find the file */
-    filename = gnc_gnome_locate_data_file("tip_of_the_day.list");
+    filename = gnc_filepath_locate_data_file("tip_of_the_day.list");
     if (!filename)
         return FALSE;
 

Modified: gnucash/trunk/src/gnome-utils/gnc-embedded-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-embedded-window.c	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/gnome-utils/gnc-embedded-window.c	2012-09-10 19:21:38 UTC (rev 22377)
@@ -30,6 +30,7 @@
 #include "gnc-embedded-window.h"
 
 #include "gnc-engine.h"
+#include "gnc-filepath-utils.h"
 #include "gnc-gnome-utils.h"
 #include "gnc-gobject-utils.h"
 #include "gnc-gui-query.h"
@@ -364,7 +365,7 @@
     priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
 
     /* Determine the full pathname of the ui file */
-    ui_fullname = gnc_gnome_locate_ui_file(ui_filename);
+    ui_fullname = gnc_filepath_locate_ui_file (ui_filename);
 
     priv->parent_window = enclosing_win;
 

Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2012-09-10 19:21:38 UTC (rev 22377)
@@ -170,60 +170,6 @@
     }
 }
 
-char *
-gnc_gnome_locate_pixmap (const char *name)
-{
-    char *fullname;
-
-    g_return_val_if_fail (name != NULL, NULL);
-
-    fullname = gnome_program_locate_file (gnucash_program,
-                                          GNOME_FILE_DOMAIN_APP_PIXMAP,
-                                          name, TRUE, NULL);
-    if (fullname == NULL)
-    {
-        PERR ("Could not locate pixmap/pixbuf file %s", name);
-        return NULL;
-    }
-
-    return fullname;
-}
-
-char *
-gnc_gnome_locate_data_file (const char *name)
-{
-    char *fullname;
-
-    g_return_val_if_fail (name != NULL, NULL);
-
-    fullname = gnome_program_locate_file (gnucash_program,
-                                          GNOME_FILE_DOMAIN_APP_DATADIR,
-                                          name, TRUE, NULL);
-
-    if (fullname == NULL)
-    {
-        PERR ("Could not locate file %s", name);
-        return NULL;
-    }
-
-    return fullname;
-}
-
-char *
-gnc_gnome_locate_ui_file (const char *name)
-{
-    char *partial;
-    char *fullname;
-
-    g_return_val_if_fail (name != NULL, NULL);
-
-    partial = g_strdup_printf("ui/%s", name);
-    fullname = gnc_gnome_locate_data_file(partial);
-    g_free(partial);
-
-    return fullname;
-}
-
 static void
 gnc_gtk_add_rc_file (void)
 {
@@ -321,7 +267,7 @@
         {
             GdkPixbuf *buf = NULL;
 
-            fullname = gnc_gnome_locate_pixmap(icon_filenames[idx]);
+            fullname = gnc_filepath_locate_pixmap(icon_filenames[idx]);
             if (fullname == NULL)
             {
                 g_warning("couldn't find icon file [%s]", icon_filenames[idx]);
@@ -570,7 +516,7 @@
 
     g_return_val_if_fail (name != NULL, NULL);
 
-    fullname = gnc_gnome_locate_pixmap (name);
+    fullname = gnc_filepath_locate_pixmap (name);
     if (fullname == NULL)
         return NULL;
 
@@ -602,7 +548,7 @@
 
     g_return_val_if_fail (name != NULL, NULL);
 
-    fullname = gnc_gnome_locate_pixmap (name);
+    fullname = gnc_filepath_locate_pixmap (name);
     if (fullname == NULL)
         return NULL;
 

Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h	2012-09-10 19:21:38 UTC (rev 22377)
@@ -40,47 +40,6 @@
 /** Initialize the Gnome libraries. */
 void gnc_gnome_init (int argc, char **argv, const char * version);
 
-/** Given a pixmap/pixbuf file name, find the file in the pixmap
- *  directory associated with this application.  This routine will
- *  display an error message if it can't find the file.
- *
- *  @param name The name of the file to be found.
- *
- *  @return the full path name of the file, or NULL of the file can't
- *  be found.
- *
- *  @note It is the caller's responsibility to free the returned string.
- */
-char *gnc_gnome_locate_pixmap (const char *name);
-
-
-/** Given a file name, find the file in the directories associated
- *  with this application.  This routine will display an error message
- *  if it can't find the file.
- *
- *  @param name The name of the file to be found.
- *
- *  @return the full path name of the file, or NULL of the file can't
- *  be found.
- *
- *  @note It is the caller's responsibility to free the returned string.
- */
-char *gnc_gnome_locate_data_file (const char *name);
-
-
-/** Given a file name, find the file in the directories associated
- *  with this application.  This routine will display an error message
- *  if it can't find the file.
- *
- *  @param name The name of the file to be found.
- *
- *  @return the full path name of the file, or NULL of the file can't
- *  be found.
- *
- *  @note It is the caller's responsibility to free the returned string.
- */
-char *gnc_gnome_locate_ui_file (const char *name);
-
 /** Launch the default gnome help browser and open to a given link
  *  within a given file.  This routine will display an error message
  *  if it can't find the help file or can't open the help browser.

Modified: gnucash/trunk/src/gnome-utils/gnc-icons.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-icons.c	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/gnome-utils/gnc-icons.c	2012-09-10 19:21:38 UTC (rev 22377)
@@ -10,6 +10,7 @@
 #include <glib/gi18n.h>
 
 #include "gnc-icons.h"
+#include "gnc-filepath-utils.h"
 #include "gnc-gnome-utils.h"
 
 static GtkStockItem items[] =
@@ -65,8 +66,8 @@
     char *fullname1, *fullname2;
 
     /* Find the complete path names for these files */
-    fullname1 = gnc_gnome_locate_pixmap (filename1);
-    fullname2 = gnc_gnome_locate_pixmap (filename2);
+    fullname1 = gnc_filepath_locate_pixmap (filename1);
+    fullname2 = gnc_filepath_locate_pixmap (filename2);
     g_assert (fullname1 && fullname2);
 
     /* Load the pixbufs */

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c	2012-09-10 19:21:38 UTC (rev 22377)
@@ -51,6 +51,7 @@
 #include "gnc-component-manager.h"
 #include "gnc-engine.h"
 #include "gnc-file.h"
+#include "gnc-filepath-utils.h"
 #include "gnc-gkeyfile-utils.h"
 #include "gnc-gnome-utils.h"
 #include "gnc-gobject-utils.h"
@@ -2894,7 +2895,7 @@
     g_return_if_fail (n_actions > 0);
     g_return_if_fail (filename != NULL);
 
-    pathname = gnc_gnome_locate_ui_file (filename);
+    pathname = gnc_filepath_locate_ui_file (filename);
     if (pathname == NULL)
         return;
 
@@ -3304,9 +3305,9 @@
 {
     guint merge_id;
 #ifdef MAC_INTEGRATION
-    gchar *filename = gnc_gnome_locate_ui_file("gnc-windows-menu-ui-quartz.xml");
+    gchar *filename = gnc_filepath_locate_ui_file("gnc-windows-menu-ui-quartz.xml");
 #else
-    gchar *filename = gnc_gnome_locate_ui_file("gnc-windows-menu-ui.xml");
+    gchar *filename = gnc_filepath_locate_ui_file("gnc-windows-menu-ui.xml");
     GncMainWindowPrivate *priv;
 #endif
     GError *error = NULL;
@@ -3410,7 +3411,7 @@
     g_signal_connect (G_OBJECT (window->ui_merge), "connect-proxy",
                       G_CALLBACK (connect_proxy), priv->statusbar);
 
-    filename = gnc_gnome_locate_ui_file("gnc-main-window-ui.xml");
+    filename = gnc_filepath_locate_ui_file("gnc-main-window-ui.xml");
 
     /* Can't do much without a ui. */
     g_assert (filename);
@@ -4062,7 +4063,7 @@
 {
     gchar *filename, *text = NULL;
 
-    filename = gnc_gnome_locate_data_file(partial);
+    filename = gnc_filepath_locate_doc_file(partial);
     g_file_get_contents(filename, &text, NULL, NULL);
     g_free(filename);
 
@@ -4118,9 +4119,9 @@
 
     logo = gnc_gnome_get_gdkpixbuf ("gnucash-icon-48x48.png");
 
-    authors = get_file_strsplit("doc/AUTHORS");
-    documenters = get_file_strsplit("doc/DOCUMENTERS");
-    license = get_file("doc/LICENSE");
+    authors = get_file_strsplit("AUTHORS");
+    documenters = get_file_strsplit("DOCUMENTERS");
+    license = get_file("LICENSE");
 #ifdef GNUCASH_SVN
     /* Development version */
     message = g_strdup_printf(_("%s  This copy was built from svn r%s on %s."),

Modified: gnucash/trunk/src/gnome-utils/gnc-plugin.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-plugin.c	2012-09-09 20:26:58 UTC (rev 22376)
+++ gnucash/trunk/src/gnome-utils/gnc-plugin.c	2012-09-10 19:21:38 UTC (rev 22377)
@@ -39,6 +39,7 @@
 
 #include "gnc-plugin.h"
 #include "gnc-engine.h"
+#include "gnc-filepath-utils.h"
 #include "gnc-gconf-utils.h"
 #include "gnc-gnome-utils.h"
 #include "gnc-gobject-utils.h"
@@ -381,7 +382,7 @@
           ui_merge, action_group, filename);
     gtk_ui_manager_insert_action_group (ui_merge, action_group, 0);
 
-    pathname = gnc_gnome_locate_ui_file (filename);
+    pathname = gnc_filepath_locate_ui_file (filename);
     if (pathname == NULL)
     {
         LEAVE("fail");



More information about the gnucash-changes mailing list