[frogr] Use the proper icons and data paths depending on the platform



commit 14a8f997ab19cea42ca840097a61da30b61b0d74
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Thu May 19 02:06:11 2011 +0200

    Use the proper icons and data paths depending on the platform

 Makefile.am                |    4 +-
 configure.ac               |    3 +-
 src/Makefile.am            |    4 +--
 src/frogr-about-dialog.c   |   12 +++++++--
 src/frogr-details-dialog.c |   14 +++++++---
 src/frogr-main-view.c      |   57 +++++++++++++++++++++++++++-----------------
 src/frogr-util.c           |   36 +++++++++++++++++++++++++++
 src/frogr-util.h           |    4 +++
 8 files changed, 98 insertions(+), 36 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 7bb1ffe..38b7346 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -60,10 +60,10 @@ icon128_DATA = data/icons/hicolor/128x128/apps/frogr.png
 iconscalabledir = $(datadir)/icons/hicolor/scalable/apps
 iconscalable_DATA = data/icons/hicolor/scalable/apps/frogr.svg
 
-imagesdir = $(appdatadir)/images
+imagesdir = $(datadir)/frogr/images
 images_DATA = data/images/mpictures.png
 
-gtkbuilderdir = $(appdatadir)/gtkbuilder
+gtkbuilderdir = $(datadir)/frogr/gtkbuilder
 gtkbuilder_DATA = data/gtkbuilder/frogr-main-view.xml
 
 desktopentrydir = $(datadir)/applications
diff --git a/configure.ac b/configure.ac
index 3c44f63..f1ebeab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -145,8 +145,7 @@ fi
 
 # Substitute
 
-AC_SUBST(appdatadir, "\${datadir}/frogr")
-AC_SUBST(iconsdir, "\${datadir}/icons")
+AC_SUBST(DATA_DIR, "\${datadir}")
 AC_SUBST(FROGR_CFLAGS)
 AC_SUBST(FROGR_LIBS)
 
diff --git a/src/Makefile.am b/src/Makefile.am
index e1f5efe..307e248 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,9 +27,7 @@ frogr_LDADD = 				\
 	$(FROGR_LIBS)
 
 frogr_CFLAGS = $(FROGR_CFLAGS) \
-	-DAPP_DATA_DIR=\"$(appdatadir)\" \
-	-DICONS_DIR=\"$(iconsdir)\"
-
+	-DDATA_DIR=\"$(DATA_DIR)\"
 
 if GTK_API_VERSION_2
 frogr_CFLAGS += \
diff --git a/src/frogr-about-dialog.c b/src/frogr-about-dialog.c
index df4c691..e5a479f 100644
--- a/src/frogr-about-dialog.c
+++ b/src/frogr-about-dialog.c
@@ -22,12 +22,14 @@
 
 #include "frogr-about-dialog.h"
 
+#include "frogr-global-defs.h"
 #include "frogr-util.h"
 
 #include <config.h>
 #include <glib/gi18n.h>
 
-#define ABOUT_DIALOG_ICON ICONS_DIR "/hicolor/48x48/apps/frogr.png"
+/* Path relative to the icons dir */
+#define ABOUT_DIALOG_ICON "/hicolor/48x48/apps/frogr.png"
 
 static const gchar *authors[] = {
   "Mario Sanchez Prada <msanchez igalia com>",
@@ -78,9 +80,13 @@ void
 frogr_about_dialog_show (GtkWindow *parent)
 {
   GdkPixbuf *logo = NULL;
-  char *version = NULL;
+  gchar *version = NULL;
+  gchar *icon_full_path = NULL;
 
-  logo = gdk_pixbuf_new_from_file (ABOUT_DIALOG_ICON, NULL);
+  icon_full_path = g_strdup_printf ("%s/" ABOUT_DIALOG_ICON,
+				    frogr_util_get_icons_dir ());
+  logo = gdk_pixbuf_new_from_file (icon_full_path, NULL);
+  g_free (icon_full_path);
 
 #if !GTK_CHECK_VERSION (2,23,0)
   /* Install about dialog hooks */
diff --git a/src/frogr-details-dialog.c b/src/frogr-details-dialog.c
index a9581c4..4d25bcf 100644
--- a/src/frogr-details-dialog.c
+++ b/src/frogr-details-dialog.c
@@ -24,6 +24,7 @@
 
 #include "frogr-config.h"
 #include "frogr-controller.h"
+#include "frogr-global-defs.h"
 #include "frogr-picture.h"
 #include "frogr-util.h"
 
@@ -31,7 +32,8 @@
 #include <glib/gi18n.h>
 #include <flicksoup/flicksoup.h>
 
-#define MPICTURES_IMAGE APP_DATA_DIR "/images/mpictures.png"
+/* Path relative to the application data dir */
+#define MPICTURES_IMAGE "/images/mpictures.png"
 
 #define DIALOG_MIN_WIDTH 640
 #define DIALOG_MIN_HEIGHT 420
@@ -742,13 +744,17 @@ _fill_dialog_with_data (FrogrDetailsDialog *self)
   n_pictures = g_slist_length (priv->pictures);
   if (n_pictures > 1)
     {
-      GdkPixbuf *pixbuf;
-      gchar *mpictures_str;
+      GdkPixbuf *pixbuf = NULL;
+      gchar *mpictures_str = NULL;
+      gchar *mpictures_full_path = NULL;
 
       /* Set the image for editing multiple pictures */
-      pixbuf = gdk_pixbuf_new_from_file (MPICTURES_IMAGE, NULL);
+      mpictures_full_path = g_strdup_printf ("%s/" MPICTURES_IMAGE,
+					     frogr_util_get_app_data_dir ());
+      pixbuf = gdk_pixbuf_new_from_file (mpictures_full_path, NULL);
       gtk_image_set_from_pixbuf (GTK_IMAGE (priv->picture_img), pixbuf);
       g_object_unref (pixbuf);
+      g_free (mpictures_full_path);
 
       /* Visually indicate how many pictures are being edited */
       mpictures_str = g_strdup_printf (ngettext ("(%d Picture)", "(%d Pictures)", n_pictures), n_pictures);
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index dee4e51..5068c57 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -46,15 +46,16 @@
 
 #include <glib/gi18n.h>
 
-
-#define MAIN_VIEW_ICON(_s) ICONS_DIR "/hicolor/" _s "/apps/frogr.png"
+/* Paths relative to the icons dir */
+#define MAIN_VIEW_ICON(_s) "/hicolor/" _s "/apps/frogr.png"
 
 #define MINIMUM_WINDOW_WIDTH 800
 #define MINIMUM_WINDOW_HEIGHT 600
 
 #define ITEM_WIDTH 120
 
-#define GTKBUILDER_FILE APP_DATA_DIR "/gtkbuilder/frogr-main-view.xml"
+/* Path relative to the application data dir */
+#define GTKBUILDER_FILE "/gtkbuilder/frogr-main-view.xml"
 
 #define FROGR_MAIN_VIEW_GET_PRIVATE(object)             \
   (G_TYPE_INSTANCE_GET_PRIVATE ((object),               \
@@ -1757,6 +1758,8 @@ frogr_main_view_init (FrogrMainView *self)
   GtkWidget *progress_vbox;
   GtkWidget *progress_bar;
   GtkWidget *progress_label;
+  const gchar *icons_path;
+  gchar *full_path;
   GList *icons;
 
 #ifdef MAC_INTEGRATION
@@ -1774,31 +1777,41 @@ frogr_main_view_init (FrogrMainView *self)
   _update_state_description (self);
 
   /* Provide a default icon list in several sizes */
-  icons = g_list_prepend (NULL,
-                          gdk_pixbuf_new_from_file (MAIN_VIEW_ICON("128x128"),
-                                                    NULL));
-  icons = g_list_prepend (icons,
-                          gdk_pixbuf_new_from_file (MAIN_VIEW_ICON("64x64"),
-                                                    NULL));
-  icons = g_list_prepend (icons,
-                          gdk_pixbuf_new_from_file (MAIN_VIEW_ICON("48x48"),
-                                                    NULL));
-  icons = g_list_prepend (icons,
-                          gdk_pixbuf_new_from_file (MAIN_VIEW_ICON("32x32"),
-                                                    NULL));
-  icons = g_list_prepend (icons,
-                          gdk_pixbuf_new_from_file (MAIN_VIEW_ICON("24x24"),
-                                                    NULL));
-  icons = g_list_prepend (icons,
-                          gdk_pixbuf_new_from_file (MAIN_VIEW_ICON("16x16"),
-                                                    NULL));
+  icons_path = frogr_util_get_icons_dir ();
+  full_path = g_strdup_printf ("%s/" MAIN_VIEW_ICON("128x128"), icons_path);
+  icons = g_list_prepend (NULL, gdk_pixbuf_new_from_file (full_path, NULL));
+  g_free (full_path);
+
+  full_path = g_strdup_printf ("%s/" MAIN_VIEW_ICON("64x64"), icons_path);
+  icons = g_list_prepend (NULL, gdk_pixbuf_new_from_file (full_path, NULL));
+  g_free (full_path);
+
+  full_path = g_strdup_printf ("%s/" MAIN_VIEW_ICON("48x48"), icons_path);
+  icons = g_list_prepend (NULL, gdk_pixbuf_new_from_file (full_path, NULL));
+  g_free (full_path);
+
+  full_path = g_strdup_printf ("%s/" MAIN_VIEW_ICON("32x32"), icons_path);
+  icons = g_list_prepend (NULL, gdk_pixbuf_new_from_file (full_path, NULL));
+  g_free (full_path);
+
+  full_path = g_strdup_printf ("%s/" MAIN_VIEW_ICON("24x24"), icons_path);
+  icons = g_list_prepend (NULL, gdk_pixbuf_new_from_file (full_path, NULL));
+  g_free (full_path);
+
+  full_path = g_strdup_printf ("%s/" MAIN_VIEW_ICON("16x16"), icons_path);
+  icons = g_list_prepend (NULL, gdk_pixbuf_new_from_file (full_path, NULL));
+  g_free (full_path);
+
   gtk_window_set_default_icon_list (icons);
   g_list_foreach (icons, (GFunc) g_object_unref, NULL);
   g_list_free (icons);
 
   /* Get widgets from GtkBuilder */
   builder = gtk_builder_new ();
-  gtk_builder_add_from_file (builder, GTKBUILDER_FILE, NULL);
+
+  full_path = g_strdup_printf ("%s/" GTKBUILDER_FILE, frogr_util_get_app_data_dir ());
+  gtk_builder_add_from_file (builder, full_path, NULL);
+  g_free (full_path);
 
   window = GTK_WINDOW(gtk_builder_get_object (builder, "main_window"));
   gtk_window_set_title (GTK_WINDOW (window), _(APP_NAME));
diff --git a/src/frogr-util.c b/src/frogr-util.c
index 522d007..d45e5ab 100644
--- a/src/frogr-util.c
+++ b/src/frogr-util.c
@@ -46,6 +46,42 @@ _spawn_command (const gchar* cmd)
 }
 #endif
 
+const gchar *
+_get_data_dir (void)
+{
+#ifdef MAC_INTEGRATION
+  /* For MacOSX, we return the value of the environment value set by
+     the wrapper script running the application */
+  static gchar *xdg_data_dir = NULL;
+  if (!xdg_data_dir)
+    xdg_data_dir = g_strdup (g_getenv("XDG_DATA_DIRS"));
+  return (const gchar *) xdg_data_dir;
+#else
+  /* For GNOME, we just return DATA_DIR */
+  return DATA_DIR;
+#endif
+}
+
+const gchar *
+frogr_util_get_app_data_dir (void)
+{
+  static gchar *app_data_dir = NULL;
+  if (!app_data_dir)
+    app_data_dir = g_strdup_printf ("%s/frogr", _get_data_dir ());
+
+  return (const gchar *) app_data_dir;
+}
+
+const gchar *
+frogr_util_get_icons_dir (void)
+{
+  static gchar *icons_dir = NULL;
+  if (!icons_dir)
+    icons_dir = g_strdup_printf ("%s/icons", _get_data_dir ());
+
+  return (const gchar *) icons_dir;
+}
+
 void
 frogr_util_open_url_in_browser (const gchar *url)
 {
diff --git a/src/frogr-util.h b/src/frogr-util.h
index d90dfef..9430d04 100644
--- a/src/frogr-util.h
+++ b/src/frogr-util.h
@@ -25,6 +25,10 @@
 
 G_BEGIN_DECLS
 
+const gchar *frogr_util_get_app_data_dir (void);
+
+const gchar *frogr_util_get_icons_dir (void);
+
 void frogr_util_open_url_in_browser (const gchar *url);
 
 void frogr_util_show_info_dialog (GtkWindow *parent, const gchar *message);



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