#endif
}
+extern const string LIBDIR;
+extern const string MDATADIR;
+extern const string PACKAGE_NAME;
+extern const string SYSCONFDIR;
+
namespace Midori {
public enum RuntimeMode {
UNDEFINED,
}
namespace Paths {
+ static string? exec_path = null;
+ static string[] command_line = null;
static RuntimeMode mode = RuntimeMode.UNDEFINED;
+
static string? config_dir = null;
static string? cache_dir = null;
static string? user_data_dir = null;
public static string get_readonly_config_dir (RuntimeMode new_mode) {
assert (mode == RuntimeMode.UNDEFINED);
if (new_mode == RuntimeMode.PORTABLE) {
- #if HAVE_WIN32
- string profile = win32_get_package_installation_directory_of_module ();
- #else
- string profile = "profile://";
- #endif
return Path.build_path (Path.DIR_SEPARATOR_S,
- profile, "profile", "config");
+ exec_path, "profile", "config");
}
return Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_user_config_dir (), "midori");
+ Environment.get_user_config_dir (), PACKAGE_NAME);
}
public static void init (RuntimeMode new_mode, string? config_base) {
assert (new_mode != RuntimeMode.UNDEFINED);
mode = new_mode;
if (mode == RuntimeMode.PORTABLE) {
- #if HAVE_WIN32
- string profile = win32_get_package_installation_directory_of_module ();
- #else
- string profile = "profile://";
- #endif
config_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- profile, "profile", "config");
+ exec_path, "profile", "config");
cache_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- profile, "profile", "cache");
+ exec_path, "profile", "cache");
user_data_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- profile, "profile", "misc");
+ exec_path, "profile", "misc");
tmp_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- profile, "profile", "tmp");
+ exec_path, "profile", "tmp");
}
else if (mode == RuntimeMode.PRIVATE || mode == RuntimeMode.APP) {
config_dir = "private-or-app://";
config_dir = config_base;
else
config_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_user_config_dir (), "midori");
+ Environment.get_user_config_dir (), PACKAGE_NAME);
cache_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_user_cache_dir (), "midori");
+ Environment.get_user_cache_dir (), PACKAGE_NAME);
user_data_dir = Environment.get_user_data_dir ();
tmp_dir = Path.build_path (Path.DIR_SEPARATOR_S,
Environment.get_tmp_dir (), "midori-" + Environment.get_user_name ());
return mode == RuntimeMode.APP || mode == RuntimeMode.PRIVATE;
}
- public static string get_config_dir () {
+ public static unowned string get_config_dir () {
assert (config_dir != null);
return config_dir;
}
- public static string get_cache_dir () {
+ public static unowned string get_cache_dir () {
assert (cache_dir != null);
return cache_dir;
}
- public static string get_user_data_dir () {
+ public static unowned string get_user_data_dir () {
assert (user_data_dir != null);
return user_data_dir;
}
- public static string get_tmp_dir () {
+ public static unowned string get_tmp_dir () {
assert (tmp_dir != null);
return tmp_dir;
}
+
+ public static void init_exec_path (string[] new_command_line) {
+ assert (command_line == null);
+ command_line = new_command_line;
+ #if HAVE_WIN32
+ exec_path = win32_get_package_installation_directory_of_module ();
+ #else
+ string? executable;
+ try {
+ if (!Path.is_absolute (command_line[0])) {
+ string program = Environment.find_program_in_path (command_line[0]);
+ if (FileUtils.test (program, FileTest.IS_SYMLINK))
+ executable = FileUtils.read_link (program);
+ else
+ executable = program;
+ }
+ else
+ executable = FileUtils.read_link (command_line[0]);
+ }
+ catch (Error error) {
+ executable = command_line[0];
+ }
+
+ exec_path = File.new_for_path (executable).get_parent ().get_parent ().get_path ();
+ #endif
+ if (strcmp (Environment.get_variable ("MIDORI_DEBUG"), "paths") == 0) {
+ stdout.printf ("command_line: %s\nexec_path: %s\nres: %s\nlib: %s\n",
+ "".joinv (" ", command_line), exec_path,
+ get_res_filename (""), get_lib_path (PACKAGE_NAME));
+ }
+ }
+
+ public static unowned string[] get_command_line () {
+ assert (command_line != null);
+ return command_line;
+ }
+
+ public static string get_lib_path (string package) {
+ assert (command_line != null);
+ string path = Path.build_filename (exec_path, "lib", package);
+ if (Posix.access (path, Posix.F_OK) == 0)
+ return path;
+
+ if (package == PACKAGE_NAME) {
+ /* Fallback to build folder */
+ path = Path.build_filename ((File.new_for_path (exec_path).get_path ()), "extensions");
+ if (Posix.access (path, Posix.F_OK) == 0)
+ return path;
+ }
+
+ return Path.build_filename (LIBDIR, PACKAGE_NAME);
+ }
+
+ public static string get_res_filename (string filename) {
+ assert (command_line != null);
+ string path = Path.build_filename (exec_path, "share", PACKAGE_NAME, "res", filename);
+ if (Posix.access (path, Posix.F_OK) == 0)
+ return path;
+
+ /* Fallback to build folder */
+ path = Path.build_filename ((File.new_for_path (exec_path)
+ .get_parent ().get_parent ().get_path ()), "data", filename);
+ if (Posix.access (path, Posix.F_OK) == 0)
+ return path;
+
+ return Path.build_filename (MDATADIR, PACKAGE_NAME, "res", filename);
+ }
+
+ public static string get_data_filename (string filename, bool res) {
+ assert (command_line != null);
+ string res1 = res ? PACKAGE_NAME : "";
+ string res2 = res ? "res" : "";
+
+ #if HAVE_WIN32
+ string path = Path.build_filename (exec_path, "share", res1, res2, filename);
+ if (Posix.access (path, Posix.F_OK) == 0)
+ return path;
+ #else
+ string path = Path.build_filename (get_user_data_dir (), res1, res2, filename);
+ if (Posix.access (path, Posix.F_OK) == 0)
+ return path;
+
+ foreach (string data_dir in Environment.get_system_data_dirs ()) {
+ path = Path.build_filename (data_dir, res1, res2, filename);
+ if (Posix.access (path, Posix.F_OK) == 0)
+ return path;
+ }
+ #endif
+
+ return Path.build_filename (MDATADIR, res1, res2, filename);
+ }
+
+ public static string get_config_filename (string? folder, string filename) {
+ assert (config_dir != null);
+
+ foreach (string config_dir in Environment.get_system_config_dirs ()) {
+ string path = Path.build_filename (config_dir, PACKAGE_NAME, folder ?? "", filename);
+ if (Posix.access (path, Posix.F_OK) == 0)
+ return path;
+ }
+
+ #if HAVE_WIN32
+ string path = Path.build_filename (exec_path, "etc", "xdg", PACKAGE_NAME, folder ?? "", filename);
+ if (Posix.access (path, Posix.F_OK) == 0)
+ return path;
+ #endif
+
+ return Path.build_filename (SYSCONFDIR, "xdg", PACKAGE_NAME, folder ?? "", filename);
+ }
}
}
if (error->code == G_FILE_ERROR_NOENT)
{
GError* inner_error = NULL;
- katze_assign (config_file, sokoke_find_config_filename (NULL, "config"));
+ katze_assign (config_file, midori_paths_get_config_filename (NULL, "config"));
g_key_file_load_from_file (key_file, config_file,
G_KEY_FILE_KEEP_COMMENTS, &inner_error);
if (inner_error != NULL)
/* Load accelerators */
katze_assign (config_file, g_build_filename (config, "accels", NULL));
if (g_access (config_file, F_OK) != 0)
- katze_assign (config_file, sokoke_find_config_filename (NULL, "accels"));
+ katze_assign (config_file, midori_paths_get_config_filename (NULL, "accels"));
gtk_accel_map_load (config_file);
g_free (config_file);
search_engines = search_engines_new_from_file (config_file, NULL);
#else
katze_assign (config_file,
- sokoke_find_config_filename (NULL, "search"));
+ midori_paths_get_config_filename (NULL, "search"));
search_engines = search_engines_new_from_file (config_file, NULL);
#endif
}
return;
array = katze_object_get_object (app, "extensions");
- if ((extension_path = midori_app_get_lib_path (PACKAGE_NAME)))
+ if ((extension_path = midori_paths_get_lib_path (PACKAGE_NAME)))
{
GDir* extension_dir = NULL;
if ((extension_dir = g_dir_open (extension_path, 0, NULL)))
/* We cannot use "ssl-use-system-ca-file" on Windows
* some GTLS backend pieces are missing currently.
* Instead we specify the bundle we ship ourselves */
- gchar* certificate_file = midori_app_find_res_filename ("ca-bundle.crt");
+ gchar* certificate_file = midori_paths_get_res_filename ("ca-bundle.crt");
g_object_set (session,
"ssl-ca-file", certificate_file,
"ssl-strict", FALSE,
if (g_module_supported ())
{
gchar* extension_path;
- if (keys && (extension_path = midori_app_get_lib_path (PACKAGE_NAME)))
+ if (keys && (extension_path = midori_paths_get_lib_path (PACKAGE_NAME)))
{
gint i = 0;
const gchar* filename;
if (app->browser == NULL)
{
gchar* filename;
- if ((filename = midori_app_find_res_filename ("gtk3.css")))
+ if ((filename = midori_paths_get_res_filename ("gtk3.css")))
{
GtkCssProvider* css_provider = gtk_css_provider_new ();
GError* error = NULL;
#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_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_get_lib_path:
- * @package: a filename or relative path
- *
- * Looks for the specified filename in Midori's library path.
- *
- * Return value: a newly allocated full path
- *
- * Since: 0.4.7
- **/
-gchar*
-midori_app_get_lib_path (const gchar* package)
-{
- gchar* path;
-
- path = g_build_filename (exec_path, "lib", package, NULL);
- if (g_access (path, F_OK) == 0)
- return path;
-
- g_free (path);
-
- if (!strcmp (package, PACKAGE_NAME))
- {
- /* Fallback to build folder */
- path = g_build_filename (g_file_get_path (
- g_file_new_for_path (exec_path)),
- "extensions", NULL);
- if (g_access (path, F_OK) == 0)
- return path;
- g_free (path);
- }
-
- return g_build_filename (LIBDIR, PACKAGE_NAME, NULL);
-}
-
/**
* midori_app_setup:
*
GtkIconSet* icon_set;
GtkIconFactory* factory;
gsize i;
- #ifndef G_OS_WIN32
- gchar* executable;
- #endif
gboolean success;
static GtkStockItem items[] =
if (!g_thread_supported ()) g_thread_init (NULL);
#endif
+ /* Midori.Paths uses GFile */
+ g_type_init ();
+ /* Preserve argument vector */
+ midori_paths_init_exec_path (*argument_vector, *argc);
+
#if ENABLE_NLS
setlocale (LC_ALL, "");
if (g_getenv ("MIDORI_NLSPATH"))
else
#ifdef G_OS_WIN32
{
- gchar* path = sokoke_find_data_filename ("locale", FALSE);
+ gchar* path = midori_paths_get_data_filename ("locale", FALSE);
bindtextdomain (GETTEXT_PACKAGE, path);
g_free (path);
}
textdomain (GETTEXT_PACKAGE);
#endif
- /* Preserve argument vector */
- command_line = g_strdupv (*argument_vector);
success = gtk_init_with_args (argc, argument_vector, _("[Addresses]"),
entries, GETTEXT_PACKAGE, error);
gtk_icon_factory_add_default (factory);
g_object_unref (factory);
- #ifdef G_OS_WIN32
- exec_path = g_win32_get_package_installation_directory_of_module (NULL);
- #else
- if (!g_path_is_absolute (command_line[0]))
- {
- gchar* program = g_find_program_in_path (command_line[0]);
-
- if (g_file_test (program, G_FILE_TEST_IS_SYMLINK))
- executable = g_file_read_link (program, NULL);
- else
- executable = g_strdup (program);
-
- g_free (program);
- }
- else
- executable = g_file_read_link (command_line[0], NULL);
-
- exec_path = g_file_get_path (g_file_get_parent (g_file_get_parent (g_file_new_for_path (
- executable ? executable : command_line[0]))));
- g_free (executable);
- #endif
-
/* Print messages to stdout on Win32 console, cf. AbiWord
* http://svn.abisource.com/abiword/trunk/src/wp/main/win/Win32Main.cpp */
#ifdef _WIN32
const GOptionEntry *entries,
GError* *error);
-gchar**
-midori_app_get_command_line (void);
-
-gchar*
-midori_app_find_res_filename (const gchar* filename);
-
-gchar*
-midori_app_get_lib_path (const gchar* package);
-
gboolean
midori_debug (const gchar* token);
if (!view)
return;
- filename = midori_app_find_res_filename ("faq.css");
+ filename = midori_paths_get_res_filename ("faq.css");
stylesheet = NULL;
if (!g_file_get_contents (filename, &stylesheet, NULL, NULL))
{
- katze_assign (filename, sokoke_find_data_filename ("doc/midori/faq.css", FALSE));
+ katze_assign (filename, midori_paths_get_data_filename ("doc/midori/faq.css", FALSE));
g_file_get_contents (filename, &stylesheet, NULL, NULL);
}
if (!(stylesheet && *stylesheet))
midori_browser_get_docs (gboolean error)
{
#ifdef G_OS_WIN32
- gchar* path = sokoke_find_data_filename ("doc/midori/faq.html", FALSE);
+ gchar* path = midori_paths_get_data_filename ("doc/midori/faq.html", FALSE);
if (g_access (path, F_OK) == 0)
return g_filename_to_uri (path, NULL, NULL);
else
folder = g_strconcat ("extensions/", filename, NULL);
g_free (filename);
katze_assign (config_file,
- sokoke_find_config_filename (folder, "config"));
+ midori_paths_get_config_filename (folder, "config"));
g_free (folder);
g_key_file_load_from_file (extension->priv->key_file, config_file,
G_KEY_FILE_KEEP_COMMENTS, NULL);
SPANNED_ADD (button);
/* Disable spell check option if there are no enchant modules */
{
- gchar* enchant_path = midori_app_get_lib_path ("enchant");
+ gchar* enchant_path = midori_paths_get_lib_path ("enchant");
if (enchant_path == NULL)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
if (g_str_has_prefix (uri, "res://"))
{
- gchar* filepath = midori_app_find_res_filename (&uri[6]);
+ gchar* filepath = midori_paths_get_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);
const gchar* try_again,
WebKitWebFrame* web_frame)
{
- gchar* path = midori_app_find_res_filename ("error.html");
+ gchar* path = midori_paths_get_res_filename ("error.html");
gchar* template;
if (g_file_get_contents (path, &template, NULL, NULL))
gchar** groups;
g_object_get (browser, "speed-dial", &key_file, NULL);
- file_path = midori_app_find_res_filename ("speeddial-head.html");
+ file_path = midori_paths_get_res_filename ("speeddial-head.html");
if (key_file != NULL
&& g_access (file_path, F_OK) == 0
}
else if (!strcmp (uri, "about:paths"))
{
- gchar* res_dir = midori_app_find_res_filename ("");
- gchar* lib_dir = midori_app_get_lib_path (PACKAGE_NAME);
+ gchar* res_dir = midori_paths_get_res_filename ("");
+ gchar* lib_dir = midori_paths_get_lib_path (PACKAGE_NAME);
data = g_strdup_printf ("<body><h1>%s</h1>"
"<p>config: %s</p>"
"<p>res: %s</p>"
}
else if (!strcmp (uri, "about:") || !strcmp (uri, "about:version"))
{
- gchar* arguments = g_strjoinv (" ", midori_app_get_command_line ());
+ gchar* arguments = g_strjoinv (" ", midori_paths_get_command_line (NULL));
gchar* command_line = sokoke_replace_variables (
arguments, g_get_home_dir (), "~", NULL);
gchar* architecture, *platform;
GtkSettings* settings = gtk_settings_get_for_screen (screen);
gchar* theme = katze_object_get_string (settings, "gtk-theme-name");
gchar* theme_file = g_build_filename ("themes", theme, "index.theme", NULL);
- gchar* filename = sokoke_find_data_filename (theme_file, FALSE);
+ gchar* filename = midori_paths_get_data_filename (theme_file, FALSE);
g_free (theme_file);
web_settings->close_buttons_left = 1;
if (g_access (filename, F_OK) != 0)
sokoke_spawn_app (const gchar* uri,
gboolean private)
{
- const gchar* executable = midori_app_get_command_line ()[0];
+ const gchar* executable = midori_paths_get_command_line (NULL)[0];
gchar* uri_quoted = g_shell_quote (uri);
gchar* argument;
if (private)
return TRUE;
}
-/**
- * sokoke_find_config_filename:
- * @folder: a subfolder
- * @filename: a filename or relative path
- *
- * Looks for the specified filename in the system config
- * directories, depending on the platform.
- *
- * Return value: a full path
- **/
-gchar*
-sokoke_find_config_filename (const gchar* folder,
- const gchar* filename)
-{
- const gchar* const* config_dirs = g_get_system_config_dirs ();
- guint i = 0;
- const gchar* config_dir;
- gchar* path;
-
- if (!folder)
- folder = "";
-
- while ((config_dir = config_dirs[i++]))
- {
- path = g_build_filename (config_dir, PACKAGE_NAME, folder, filename, NULL);
- if (g_access (path, F_OK) == 0)
- return path;
- g_free (path);
- }
-
- #ifdef G_OS_WIN32
- config_dir = g_win32_get_package_installation_directory_of_module (NULL);
- path = g_build_filename (config_dir, "etc", "xdg", PACKAGE_NAME, folder, filename, NULL);
- if (g_access (path, F_OK) == 0)
- return path;
- g_free (path);
- #endif
-
- return g_build_filename (SYSCONFDIR, "xdg", PACKAGE_NAME, folder, filename, NULL);
-}
-
-/**
- * sokoke_find_data_filename:
- * @filename: a filename or relative path
- *
- * Looks for the specified filename in the system data
- * directories, depending on the platform.
- *
- * Return value: a newly allocated full path
- **/
-gchar*
-sokoke_find_data_filename (const gchar* filename,
- gboolean res)
-{
- const gchar* res1 = res ? PACKAGE_NAME : "";
- const gchar* res2 = res ? "res" : "";
- const gchar* const* data_dirs = g_get_system_data_dirs ();
- guint i = 0;
- const gchar* data_dir;
- gchar* path;
-
- #ifdef G_OS_WIN32
- gchar* install_path = g_win32_get_package_installation_directory_of_module (NULL);
- path = g_build_filename (install_path, "share", res1, res2, filename, NULL);
- g_free (install_path);
- if (g_access (path, F_OK) == 0)
- return path;
-
- g_free (path);
- #endif
-
- path = g_build_filename (midori_paths_get_user_data_dir (), res1, res2, filename, NULL);
- if (g_access (path, F_OK) == 0)
- return path;
- g_free (path);
-
- while ((data_dir = data_dirs[i++]))
- {
- path = g_build_filename (data_dir, res1, res2, filename, NULL);
- if (g_access (path, F_OK) == 0)
- return path;
- g_free (path);
- }
- return g_build_filename (MDATADIR, res1, res2, filename, NULL);
-}
-
gchar*
sokoke_replace_variables (const gchar* template,
const gchar* variable_first, ...)
sokoke_remove_path (const gchar* path,
gboolean ignore_errors);
-gchar*
-sokoke_find_config_filename (const gchar* folder,
- const gchar* filename);
-
-gchar*
-sokoke_find_data_filename (const gchar* filename,
- gboolean res);
-
-gchar**
-sokoke_get_argv (gchar** argument_vector);
-
gchar*
sokoke_replace_variables (const gchar* template,
const gchar* variable_first, ...);
obj.add_marshal_file ('marshal.list', 'midori_cclosure_marshal')
obj.install_path = None
obj.vapi_dirs = '../midori ../katze'
- obj.packages = 'glib-2.0 gio-2.0 libsoup-2.4'
+ obj.packages = 'glib-2.0 gio-2.0 libsoup-2.4 posix'
if bld.env['HAVE_GTK3']:
obj.packages += ' gtk+-3.0 webkitgtk-3.0'
else: