[gtranslator] Using fuctions instead of macros to resolve paths
- From: Pablo Sanxiao Roca <psanxiao src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtranslator] Using fuctions instead of macros to resolve paths
- Date: Thu, 30 Jul 2009 21:18:51 +0000 (UTC)
commit 2b664390e847675c57ff09e2faa4c713782d6816
Author: Francisco Puga <francisco puga ghandalf org>
Date: Fri Jul 17 19:31:13 2009 +0200
Using fuctions instead of macros to resolve paths
src/application.c | 17 ++----
src/dialogs/comment-dialog.c | 5 ++-
src/dialogs/header-dialog.c | 6 ++-
src/dialogs/jump-dialog.c | 5 ++-
src/dialogs/preferences-dialog.c | 5 ++-
src/dialogs/profile-dialog.c | 5 ++-
src/dialogs/search-dialog.c | 5 ++-
src/main.c | 11 +++-
src/utils.c | 102 +++++++++++++++++++++++++++++++++++++-
src/utils.h | 6 ++
src/view.c | 5 ++-
src/window.c | 20 +++++---
12 files changed, 162 insertions(+), 30 deletions(-)
---
diff --git a/src/application.c b/src/application.c
index 5e209d3..83d0ec5 100644
--- a/src/application.c
+++ b/src/application.c
@@ -133,7 +133,7 @@ static void
gtranslator_application_init (GtranslatorApplication *application)
{
gchar *gtranslator_folder;
- gchar *filename;
+ gchar *path_default_gtr_toolbar;
gchar *profiles_file;
GtranslatorApplicationPrivate * priv;
@@ -199,24 +199,21 @@ gtranslator_application_init (GtranslatorApplication *application)
priv->toolbars_file = g_build_filename (gtranslator_folder,
"gtr-toolbar.xml",
NULL);
-
- filename = g_build_filename (PKGDATADIR,
- "gtr-toolbar.xml",
- NULL);
+ path_default_gtr_toolbar = gtranslator_utils_get_file_from_pkgdatadir ("gtr-toolbar.xml");
g_free (gtranslator_folder);
egg_toolbars_model_load_names (priv->toolbars_model,
- filename);
+ path_default_gtr_toolbar);
if (!egg_toolbars_model_load_toolbars (priv->toolbars_model,
priv->toolbars_file))
{
egg_toolbars_model_load_toolbars (priv->toolbars_model,
- filename);
+ path_default_gtr_toolbar);
}
- g_free (filename);
+ g_free (path_default_gtr_toolbar);
egg_toolbars_model_set_flags (priv->toolbars_model, 0,
EGG_TB_MODEL_NOT_REMOVABLE);
@@ -514,9 +511,7 @@ gtranslator_application_register_icon (GtranslatorApplication *app,
GtkIconSource * icon_source = gtk_icon_source_new ();
gchar *path;
- path = g_build_filename (PIXMAPSDIR,
- icon,
- NULL);
+ path = gtranslator_utils_get_file_from_pixmapsdir (icon);
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file (path, NULL);
if (pixbuf)
diff --git a/src/dialogs/comment-dialog.c b/src/dialogs/comment-dialog.c
index a11f75d..acfca2d 100644
--- a/src/dialogs/comment-dialog.c
+++ b/src/dialogs/comment-dialog.c
@@ -87,6 +87,7 @@ gtranslator_comment_dialog_init (GtranslatorCommentDialog *dlg)
"main_box",
NULL
};
+ gchar *path;
dlg->priv = GTR_COMMENT_DIALOG_GET_PRIVATE (dlg);
@@ -113,7 +114,8 @@ gtranslator_comment_dialog_init (GtranslatorCommentDialog *dlg)
NULL);
/*Glade*/
- ret = gtranslator_utils_get_ui_objects (PKGDATADIR "/comment-dialog.ui",
+ path = gtranslator_utils_get_file_from_pkgdatadir("comment-dialog.ui");
+ ret = gtranslator_utils_get_ui_objects (path,
root_objects,
&error_widget,
@@ -121,6 +123,7 @@ gtranslator_comment_dialog_init (GtranslatorCommentDialog *dlg)
"comment", &dlg->priv->comment,
NULL);
+ g_free(path);
if(!ret)
{
diff --git a/src/dialogs/header-dialog.c b/src/dialogs/header-dialog.c
index 869aa1a..fd66965 100644
--- a/src/dialogs/header-dialog.c
+++ b/src/dialogs/header-dialog.c
@@ -248,6 +248,7 @@ static void gtranslator_header_dialog_init (GtranslatorHeaderDialog *dlg)
"main_box",
NULL
};
+ gchar *path;
dlg->priv = GTR_HEADER_DIALOG_GET_PRIVATE (dlg);
@@ -270,8 +271,10 @@ static void gtranslator_header_dialog_init (GtranslatorHeaderDialog *dlg)
"response",
G_CALLBACK (gtk_widget_destroy),
NULL);
+
+ path = gtranslator_utils_get_file_from_pkgdatadir("header-dialog.ui");
- ret = gtranslator_utils_get_ui_objects (PKGDATADIR"/header-dialog.ui",
+ ret = gtranslator_utils_get_ui_objects (path,
root_objects,
&error_widget,
"main_box", &dlg->priv->main_box,
@@ -290,6 +293,7 @@ static void gtranslator_header_dialog_init (GtranslatorHeaderDialog *dlg)
"charset_entry", &dlg->priv->charset,
"encoding_entry", &dlg->priv->encoding,
NULL);
+ g_free(path);
if(!ret)
{
diff --git a/src/dialogs/jump-dialog.c b/src/dialogs/jump-dialog.c
index 4e0527a..8afcd33 100644
--- a/src/dialogs/jump-dialog.c
+++ b/src/dialogs/jump-dialog.c
@@ -79,6 +79,7 @@ gtranslator_jump_dialog_init (GtranslatorJumpDialog *dlg)
"main_box",
NULL
};
+ gchar *path;
dlg->priv = GTR_JUMP_DIALOG_GET_PRIVATE (dlg);
@@ -109,7 +110,8 @@ gtranslator_jump_dialog_init (GtranslatorJumpDialog *dlg)
NULL);
/*Glade*/
- ret = gtranslator_utils_get_ui_objects (PKGDATADIR "/jump-dialog.ui",
+ path = gtranslator_utils_get_file_from_pkgdatadir("jump-dialog.ui");
+ ret = gtranslator_utils_get_ui_objects (path,
root_objects,
&error_widget,
@@ -117,6 +119,7 @@ gtranslator_jump_dialog_init (GtranslatorJumpDialog *dlg)
"jump", &dlg->priv->jump,
NULL);
+ g_free(path);
if(!ret)
{
diff --git a/src/dialogs/preferences-dialog.c b/src/dialogs/preferences-dialog.c
index 647c757..812d2fc 100644
--- a/src/dialogs/preferences-dialog.c
+++ b/src/dialogs/preferences-dialog.c
@@ -1104,6 +1104,7 @@ gtranslator_preferences_dialog_init (GtranslatorPreferencesDialog *dlg)
"model1",
NULL
};
+ gchar *path;
dlg->priv = GTR_PREFERENCES_DIALOG_GET_PRIVATE (dlg);
@@ -1132,7 +1133,8 @@ gtranslator_preferences_dialog_init (GtranslatorPreferencesDialog *dlg)
/*Glade*/
- ret = gtranslator_utils_get_ui_objects (PKGDATADIR "/preferences-dialog.ui",
+ path = gtranslator_utils_get_file_from_pkgdatadir("preferences-dialog.ui");
+ ret = gtranslator_utils_get_ui_objects (path,
root_objects,
&error_widget,
@@ -1174,6 +1176,7 @@ gtranslator_preferences_dialog_init (GtranslatorPreferencesDialog *dlg)
"plugins_box", &dlg->priv->plugins_box,
NULL);
+ g_free(path);
if(!ret)
{
diff --git a/src/dialogs/profile-dialog.c b/src/dialogs/profile-dialog.c
index 3a3c6ac..42aaed7 100644
--- a/src/dialogs/profile-dialog.c
+++ b/src/dialogs/profile-dialog.c
@@ -339,6 +339,7 @@ static void gtranslator_profile_dialog_init (GtranslatorProfileDialog *dlg)
"profiles_dialog",
NULL
};
+ gchar *path;
dlg->priv = GTR_PROFILE_DIALOG_GET_PRIVATE (dlg);
@@ -350,7 +351,8 @@ static void gtranslator_profile_dialog_init (GtranslatorProfileDialog *dlg)
gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dlg)->vbox), 2);
- ret = gtranslator_utils_get_ui_objects (PKGDATADIR"/profile-dialog.ui",
+ path = gtranslator_utils_get_file_from_pkgdatadir("profile-dialog.ui");
+ ret = gtranslator_utils_get_ui_objects (path,
root_objects,
&error_widget,
"profiles_dialog", &dlg->priv->main_box,
@@ -364,6 +366,7 @@ static void gtranslator_profile_dialog_init (GtranslatorProfileDialog *dlg)
"team_email_entry", &dlg->priv->language_email_entry,
"plurals_entry", &dlg->priv->plurals_forms_entry,
NULL);
+ g_free(path);
if(!ret)
{
diff --git a/src/dialogs/search-dialog.c b/src/dialogs/search-dialog.c
index 10e86a0..d5178bc 100644
--- a/src/dialogs/search-dialog.c
+++ b/src/dialogs/search-dialog.c
@@ -356,6 +356,7 @@ gtranslator_search_dialog_init (GtranslatorSearchDialog *dlg)
"search_dialog_content",
NULL
};
+ gchar *path;
dlg->priv = GTR_SEARCH_DIALOG_GET_PRIVATE (dlg);
@@ -373,7 +374,8 @@ gtranslator_search_dialog_init (GtranslatorSearchDialog *dlg)
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dlg)->action_area), 5);
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dlg)->action_area), 6);
- ret = gtranslator_utils_get_ui_objects (PKGDATADIR"/search-dialog.ui",
+ path = gtranslator_utils_get_file_from_pkgdatadir("search-dialog.ui");
+ ret = gtranslator_utils_get_ui_objects (path,
root_objects,
&error_widget,
"search_dialog_content", &content,
@@ -388,6 +390,7 @@ gtranslator_search_dialog_init (GtranslatorSearchDialog *dlg)
"search_backwards_checkbutton", &dlg->priv->backwards_checkbutton,
"wrap_around_checkbutton", &dlg->priv->wrap_around_checkbutton,
NULL);
+ g_free(path);
if (!ret)
{
diff --git a/src/main.c b/src/main.c
index c4a7e90..c6a5d0f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -95,6 +95,8 @@ main (gint argc,
gchar *config_folder;
GList *profiles_list = NULL;
GFile *file;
+ gchar *pixmapsdir;
+ gchar *window_icon;
/*
* Initialize gettext.
@@ -133,7 +135,9 @@ main (gint argc,
/*
* Show the application window with icon.
*/
- gtk_window_set_default_icon_from_file(WINDOW_ICON, &error);
+ window_icon = gtranslator_utils_get_file_from_pixmapsdir("gtranslator.png");
+ gtk_window_set_default_icon_from_file(window_icon, &error);
+ g_free (window_icon);
if(error)
{
g_warning(_("Error setting the default window icon: %s"),
@@ -144,8 +148,11 @@ main (gint argc,
/*
* We set the default icon dir
*/
+
+ pixmapsdir = gtranslator_utils_get_file_from_pixmapsdir(NULL);
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
- PIXMAPSDIR);
+ pixmapsdir);
+ g_free(pixmapsdir);
/*
* Init preferences manager
diff --git a/src/utils.c b/src/utils.c
index b937826..35a7fa7 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -777,6 +777,7 @@ gtranslator_utils_help_display (GtkWindow *parent,
const gchar *lang;
const gchar * const *langs;
gchar *uri = NULL;
+ gchar *path;
gint i;
g_return_if_fail (file_name != NULL);
@@ -788,9 +789,11 @@ gtranslator_utils_help_display (GtkWindow *parent,
if (strchr (lang, '.'))
continue;
- uri = g_build_filename (DATADIR, "/gnome/help/", doc_id,
+ path = gtranslator_utils_get_datadir ();
+ uri = g_build_filename (path, "/gnome/help/", doc_id,
lang, file_name, NULL);
-
+ g_free(path);
+
if (g_file_test (uri, G_FILE_TEST_EXISTS)) {
break;
}
@@ -966,3 +969,98 @@ gtranslator_utils_reduce_path (const gchar *path)
}
return new_str;
}
+
+
+/**
+ * gtranslator_utils_get_file_from_pixmapsdir:
+ * @filename: name of the file
+ *
+ * Returns the absolute path of a file that is located on the folder that contains
+ * the pixmaps. If filename is NULL returns the path to the folder PIXMAPSDIR
+ */
+gchar *
+gtranslator_utils_get_file_from_pixmapsdir (gchar *filename)
+{
+ gchar *path;
+
+#ifndef G_OS_WIN32
+ path = g_build_filename(PIXMAPSDIR,
+ filename,
+ NULL);
+#else
+ gchar *win32_dir;
+
+ win32_dir = g_win32_get_package_installation_directory_of_module (NULL);
+ path = g_build_filename (win32_dir,
+ "share",
+ "pixmaps",
+ filename,
+ NULL);
+ g_free (win32_dir);
+#endif
+
+ return path;
+}
+
+
+/**
+ * gtranslator_utils_get_file_from_pkgdatadir:
+ * @filename: name of the file
+ *
+ * Returns the absolute path of a file that is located on the folder that contains
+ * the data of the package. If filename is NULL returns the path to the folder
+ * that contains the data of the package.
+ */
+gchar *
+gtranslator_utils_get_file_from_pkgdatadir (gchar *filename)
+{
+ gchar *path;
+
+#ifndef G_OS_WIN32
+ path = g_build_filename(PKGDATADIR,
+ filename,
+ NULL);
+#else
+ gchar *win32_dir;
+
+ win32_dir = g_win32_get_package_installation_directory_of_module (NULL);
+ path = g_build_filename (win32_dir,
+ "share",
+ "gtranslator",
+ filename,
+ NULL);
+ g_free (win32_dir);
+#endif
+
+ return path;
+}
+
+
+/**
+ * gtranslator_utils_get_datadir:
+ *
+ * Returns the path to the DATADIR folder
+ */
+
+gchar *
+gtranslator_utils_get_datadir (void)
+{
+ gchar *path;
+
+#ifndef G_OS_WIN32
+ path = g_build_filename (DATADIR,
+ NULL);
+#else
+ gchar *win32_dir;
+
+ win32_dir = g_win32_get_package_installation_directory_of_module (NULL);
+
+ path = g_build_filename (win32_dir,
+ "share",
+ NULL);
+
+ g_free (win32_dir);
+#endif
+
+ return path;
+}
diff --git a/src/utils.h b/src/utils.h
index a3db99f..1a87635 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -92,4 +92,10 @@ void gtranslator_utils_scan_dir (GFile *dir,
gchar * gtranslator_utils_reduce_path (const gchar *path);
+gchar *gtranslator_utils_get_file_from_pixmapsdir (gchar *filename);
+
+gchar *gtranslator_utils_get_file_from_pkgdatadir (gchar *filename);
+
+gchar *gtranslator_utils_get_datadir (void);
+
#endif
diff --git a/src/view.c b/src/view.c
index b2832ee..435e5af 100644
--- a/src/view.c
+++ b/src/view.c
@@ -98,6 +98,7 @@ gtranslator_view_init (GtranslatorView *view)
gchar **langs;
const gchar * const *temp;
gint i;
+ gchar *pkgdatadir;
view->priv = GTR_VIEW_GET_PRIVATE (view);
@@ -111,7 +112,9 @@ gtranslator_view_init (GtranslatorView *view)
++temp)
g_ptr_array_add(dirs, g_strdup(*temp));
- g_ptr_array_add(dirs, g_strdup(PKGDATADIR));
+ pkgdatadir = gtranslator_utils_get_file_from_pkgdatadir(NULL);
+ /* FIXME: Where pkgdatadir must be free */
+ g_ptr_array_add(dirs, pkgdatadir);
g_ptr_array_add(dirs, NULL);
langs = (gchar **)g_ptr_array_free(dirs, FALSE);
diff --git a/src/window.c b/src/window.c
index c63f5c8..1e5af35 100644
--- a/src/window.c
+++ b/src/window.c
@@ -365,14 +365,15 @@ gtranslator_window_layout_load (GtranslatorWindow *window,
!gdl_dock_layout_load_from_file (window->priv->layout_manager,
layout_filename))
{
- gchar *filename;
+ gchar *path;
- filename = g_build_filename (PKGDATADIR"/layout.xml", NULL);
- //DEBUG_PRINT ("Layout = %s", filename);
+
+ path = gtranslator_utils_get_file_from_pkgdatadir("layout.xml");
+ //DEBUG_PRINT ("Layout = %s", path);
if (!gdl_dock_layout_load_from_file (window->priv->layout_manager,
- filename))
- g_warning ("Loading layout from '%s' failed!!", filename);
- g_free (filename);
+ path))
+ g_warning ("Loading layout from '%s' failed!!", path);
+ g_free (path);
}
if (!gdl_dock_layout_load_layout (window->priv->layout_manager, name))
@@ -1329,6 +1330,7 @@ gtranslator_window_draw (GtranslatorWindow *window)
GtkWidget *dockbar;
GtkWidget *hbox_dock;
GtkWidget *tm_widget;
+ gchar *path;
GtranslatorWindowPrivate *priv = window->priv;
@@ -1366,13 +1368,15 @@ gtranslator_window_draw (GtranslatorWindow *window)
priv->action_group, 0);
+ path=gtranslator_utils_get_file_from_pkgdatadir("gtranslator-ui.xml");
if (!gtk_ui_manager_add_ui_from_file (priv->ui_manager,
- PKGDATADIR"/gtranslator-ui.xml",
+ path,
&error)) {
g_warning ("building menus failed: %s", error->message);
g_error_free (error);
}
-
+ g_free(path);
+
/* show tooltips in the statusbar */
g_signal_connect (priv->ui_manager,
"connect_proxy",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]