[Xfce4-commits] <midori:master> Find res in executable or build folder
Christian Dywan
noreply at xfce.org
Fri Jun 1 00:58:01 CEST 2012
Updating branch refs/heads/master
to 4a4887b5112236ed089fcfc5a9b46bb3a0bef69a (commit)
from af315513a8d26b91d99d61f65f6466fc4caf798a (commit)
commit 4a4887b5112236ed089fcfc5a9b46bb3a0bef69a
Author: Christian Dywan <christian at twotoasts.de>
Date: Fri Jun 1 00:05:11 2012 +0200
Find res in executable or build folder
We can drop the versioned filename.
extensions/formhistory/formhistory-js-frontend.c | 4 +-
midori/midori-app.c | 63 ++++++++++++++++++++-
midori/midori-app.h | 6 ++
midori/midori-view.c | 8 ++--
midori/sokoke.c | 22 +-------
wscript | 5 +--
6 files changed, 75 insertions(+), 33 deletions(-)
diff --git a/extensions/formhistory/formhistory-js-frontend.c b/extensions/formhistory/formhistory-js-frontend.c
index c1c85ea..ec64d7a 100644
--- a/extensions/formhistory/formhistory-js-frontend.c
+++ b/extensions/formhistory/formhistory-js-frontend.c
@@ -27,7 +27,7 @@ formhistory_construct_popup_gui (FormHistoryPriv* priv)
guint i;
gchar* file;
- file = sokoke_find_data_filename ("autosuggestcontrol.js", TRUE);
+ file = midori_app_find_res_filename ("autosuggestcontrol.js");
if (!g_file_get_contents (file, &autosuggest, NULL, NULL))
{
g_free (file);
@@ -35,7 +35,7 @@ formhistory_construct_popup_gui (FormHistoryPriv* priv)
}
g_strchomp (autosuggest);
- katze_assign (file, sokoke_find_data_filename ("autosuggestcontrol.css", TRUE));
+ katze_assign (file, midori_app_find_res_filename ("autosuggestcontrol.css"));
if (!g_file_get_contents (file, &style, NULL, NULL))
{
g_free (file);
diff --git a/midori/midori-app.c b/midori/midori-app.c
index 8c361f9..8fdcac6 100644
--- a/midori/midori-app.c
+++ b/midori/midori-app.c
@@ -1302,6 +1302,57 @@ midori_app_send_notification (MidoriApp* app,
#endif
}
+static gchar** command_line = NULL;
+static gchar* exec_path = NULL;
+
+/**
+ * midori_app_get_command_line:
+ *
+ * Retrieves the argument vector passed at program startup.
+ *
+ * Return value: the argument vector
+ *
+ * Since: 0.4.7
+ **/
+gchar**
+midori_app_get_command_line (void)
+{
+ return command_line;
+}
+
+/**
+ * midori_app_find_res_filename:
+ * @filename: a filename or relative path
+ *
+ * Looks for the specified filename in Midori's resources.
+ *
+ * Return value: a newly allocated full path
+ *
+ * Since: 0.4.7
+ **/
+gchar*
+midori_app_find_res_filename (const gchar* filename)
+{
+ gchar* path;
+
+ path = g_build_filename (exec_path, "share", PACKAGE_NAME, "res", filename, NULL);
+ if (g_access (path, F_OK) == 0)
+ return path;
+
+ g_free (path);
+
+ /* Fallback to build folder */
+ path = g_build_filename (g_file_get_path (g_file_get_parent (
+ g_file_get_parent (g_file_get_parent (g_file_new_for_path (exec_path))))),
+ "data", filename, NULL);
+ if (g_access (path, F_OK) == 0)
+ return path;
+ g_free (path);
+
+ return g_build_filename (MDATADIR, PACKAGE_NAME, "res", filename, NULL);
+}
+
+
/**
* midori_app_setup:
*
@@ -1352,9 +1403,6 @@ midori_app_setup (gchar** argument_vector)
{ GTK_STOCK_DIRECTORY, N_("New _Folder"), 0, 0, NULL },
};
- /* Preserve argument vector */
- sokoke_get_argv (argument_vector);
-
/* libSoup uses threads, therefore if WebKit is built with libSoup
* or Midori is using it, we need to initialize threads. */
#if !GLIB_CHECK_VERSION (2, 32, 0)
@@ -1450,6 +1498,15 @@ midori_app_setup (gchar** argument_vector)
g_object_unref (factory);
#endif
+ /* Preserve argument vector */
+ command_line = g_strdupv (argument_vector);
+ #ifdef G_OS_WIN32
+ exec_path = g_win32_get_package_installation_directory_of_module (NULL);
+ #else
+ exec_path = g_file_get_path (g_file_get_parent (g_file_get_parent (g_file_new_for_path (
+ g_find_program_in_path (command_line[0])))));
+ #endif
+
/* Print messages to stdout on Win32 console, cf. AbiWord
* http://svn.abisource.com/abiword/trunk/src/wp/main/win/Win32Main.cpp */
#ifdef _WIN32
diff --git a/midori/midori-app.h b/midori/midori-app.h
index c918a19..ffb03bc 100644
--- a/midori/midori-app.h
+++ b/midori/midori-app.h
@@ -85,6 +85,12 @@ midori_app_send_notification (MidoriApp* app,
void
midori_app_setup (gchar** argument_vector);
+gchar**
+midori_app_get_command_line (void);
+
+gchar*
+midori_app_find_res_filename (const gchar* filename);
+
G_END_DECLS
#endif /* __MIDORI_APP_H__ */
diff --git a/midori/midori-view.c b/midori/midori-view.c
index b6fe7ff..e839743 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -1128,7 +1128,7 @@ midori_view_web_view_resource_request_cb (WebKitWebView* web_view,
if (g_str_has_prefix (uri, "res://"))
{
- gchar* filepath = sokoke_find_data_filename (&uri[6], TRUE);
+ gchar* filepath = midori_app_find_res_filename (&uri[6]);
gchar* file_uri = g_filename_to_uri (filepath, NULL, NULL);
g_free (filepath);
webkit_network_request_set_uri (request, file_uri);
@@ -1441,7 +1441,7 @@ midori_view_display_error (MidoriView* view,
const gchar* try_again,
WebKitWebFrame* web_frame)
{
- gchar* path = sokoke_find_data_filename ("error.html", TRUE);
+ gchar* path = midori_app_find_res_filename ("error.html");
gchar* template;
if (g_file_get_contents (path, &template, NULL, NULL))
@@ -3977,7 +3977,7 @@ prepare_speed_dial_html (MidoriView* view,
gchar** groups;
g_object_get (browser, "speed-dial", &key_file, NULL);
- file_path = sokoke_find_data_filename ("speeddial-head-" MIDORI_VERSION ".html", TRUE);
+ file_path = midori_app_find_res_filename ("speeddial-head.html");
if (key_file != NULL
&& g_access (file_path, F_OK) == 0
@@ -4245,7 +4245,7 @@ midori_view_set_uri (MidoriView* view,
}
else if (!strcmp (uri, "about:") || !strcmp (uri, "about:version"))
{
- gchar* arguments = g_strjoinv (" ", sokoke_get_argv (NULL));
+ gchar* arguments = g_strjoinv (" ", midori_app_get_command_line ());
gchar* command_line = sokoke_replace_variables (
arguments, g_get_home_dir (), "~", NULL);
gchar* architecture, *platform;
diff --git a/midori/sokoke.c b/midori/sokoke.c
index e4a0a44..1428924 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -15,6 +15,7 @@
#include "midori-core.h"
#include "midori-platform.h"
+#include "midori-app.h"
#include <config.h>
#if HAVE_UNISTD_H
@@ -496,7 +497,7 @@ void
sokoke_spawn_app (const gchar* uri,
gboolean private)
{
- const gchar* executable = sokoke_get_argv (NULL)[0];
+ const gchar* executable = midori_app_get_command_line ()[0];
/* "midori"
"/usr/bin/midori"
"c:/Program Files/Midori/bin/midori.exe" */
@@ -1178,25 +1179,6 @@ sokoke_find_data_filename (const gchar* filename,
return g_build_filename (MDATADIR, res1, res2, filename, NULL);
}
-/**
- * sokoke_get_argv:
- * @argument_vector: %NULL
- *
- * Retrieves the argument vector passed at program startup.
- *
- * Return value: the argument vector
- **/
-gchar**
-sokoke_get_argv (gchar** argument_vector)
-{
- static gchar** stored_argv = NULL;
-
- if (!stored_argv)
- stored_argv = g_strdupv (argument_vector);
-
- return stored_argv;
-}
-
gchar*
sokoke_replace_variables (const gchar* template,
const gchar* variable_first, ...)
diff --git a/wscript b/wscript
index f0c42eb..43963e6 100644
--- a/wscript
+++ b/wscript
@@ -518,11 +518,8 @@ def build (bld):
else:
Utils.pprint ('BLUE', "logo-shade could not be rasterized.")
- for res_file in ['about.css', 'error.html', 'close.png']:
+ for res_file in ['about.css', 'error.html', 'close.png', 'speeddial-head.html']:
bld.install_files ('${MDATADIR}/' + APPNAME + '/res', 'data/' + res_file)
- bld.install_as ( \
- '${MDATADIR}/' + APPNAME + '/res/speeddial-head-%s.html' % VERSION, \
- 'data/speeddial-head.html')
if bld.env['addons']:
bld.install_files ('${MDATADIR}/' + APPNAME + '/res', 'data/autosuggestcontrol.js')
More information about the Xfce4-commits
mailing list