extern const string MDATADIR;
extern const string PACKAGE_NAME;
extern const string SYSCONFDIR;
+extern const string MIDORI_VERSION_SUFFIX;
namespace Midori {
public enum RuntimeMode {
static RuntimeMode mode = RuntimeMode.UNDEFINED;
static string? config_dir = null;
+ static string? readonly_dir = null;
static string? cache_dir = null;
static string? user_data_dir = null;
static string? tmp_dir = null;
- public static string get_readonly_config_dir (RuntimeMode new_mode) {
- assert (mode == RuntimeMode.UNDEFINED);
- if (new_mode == RuntimeMode.PORTABLE) {
- return Path.build_path (Path.DIR_SEPARATOR_S,
- exec_path, "profile", "config");
- }
+ public static string get_readonly_config_dir () {
+ assert (mode != RuntimeMode.UNDEFINED);
+ return readonly_dir ?? config_dir;
+ }
+
+ public static string get_readonly_config_filename (string filename) {
+ assert (mode != RuntimeMode.UNDEFINED);
return Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_user_config_dir (), PACKAGE_NAME);
+ readonly_dir ?? config_dir, filename);
+ }
+
+ public bool is_readonly () {
+ assert (mode != RuntimeMode.UNDEFINED);
+ return readonly_dir != null;
}
public static void init (RuntimeMode new_mode, string? config_base) {
exec_path, "profile", "tmp");
}
else if (mode == RuntimeMode.PRIVATE || mode == RuntimeMode.APP) {
- config_dir = "private-or-app://";
- cache_dir = "private-or-app://";
- user_data_dir = "private-or-app://";
+ /* Use mock folders in development builds */
+ if ("." in MIDORI_VERSION_SUFFIX)
+ config_dir = cache_dir = user_data_dir = config_base;
+ else
+ config_dir = cache_dir = user_data_dir = "/";
+ readonly_dir = config_base ?? Path.build_path (Path.DIR_SEPARATOR_S,
+ Environment.get_user_config_dir (), PACKAGE_NAME);
tmp_dir = Path.build_path (Path.DIR_SEPARATOR_S,
Environment.get_tmp_dir (), "midori-" + Environment.get_user_name ());
}
else {
- if (config_base != null)
- config_dir = config_base;
- else
- config_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_user_config_dir (), PACKAGE_NAME);
+ config_dir = config_base ?? Path.build_path (Path.DIR_SEPARATOR_S,
+ Environment.get_user_config_dir (), PACKAGE_NAME);
cache_dir = Path.build_path (Path.DIR_SEPARATOR_S,
Environment.get_user_cache_dir (), PACKAGE_NAME);
user_data_dir = Environment.get_user_data_dir ();
}
}
- public bool is_readonly () {
- return mode == RuntimeMode.APP || mode == RuntimeMode.PRIVATE;
- }
-
public static unowned string get_config_dir () {
assert (config_dir != null);
return config_dir;
}
+ public static string get_config_filename (string filename) {
+ assert (mode != RuntimeMode.UNDEFINED);
+ assert (config_dir != null);
+ return Path.build_path (Path.DIR_SEPARATOR_S, config_dir, filename);
+ }
+
public static unowned string get_cache_dir () {
assert (cache_dir != null);
return cache_dir;
#endif
}
- public static string get_config_filename (string? folder, string filename) {
+ public static string get_preset_filename (string? folder, string filename) {
assert (config_dir != null);
#if HAVE_WIN32
#include <gdk/gdkx.h>
#endif
-static gchar*
-build_config_filename (const gchar* filename)
-{
- return g_build_filename (midori_paths_get_config_dir (), filename, NULL);
-}
-
static MidoriWebSettings*
-settings_and_accels_new (const gchar* config,
- gchar*** extensions)
+settings_and_accels_new (gchar*** extensions)
{
MidoriWebSettings* settings = midori_web_settings_new ();
- gchar* config_file = g_build_filename (config, "config", NULL);
+ gchar* config_file = midori_paths_get_readonly_config_filename ("config");
GKeyFile* key_file = g_key_file_new ();
GError* error = NULL;
GObjectClass* class;
if (error->code == G_FILE_ERROR_NOENT)
{
GError* inner_error = NULL;
- katze_assign (config_file, midori_paths_get_config_filename (NULL, "config"));
+ katze_assign (config_file, midori_paths_get_preset_filename (NULL, "config"));
g_key_file_load_from_file (key_file, config_file,
G_KEY_FILE_KEEP_COMMENTS, &inner_error);
if (inner_error != NULL)
g_key_file_free (key_file);
/* Load accelerators */
- katze_assign (config_file, g_build_filename (config, "accels", NULL));
+ katze_assign (config_file, midori_paths_get_config_filename ("accels"));
if (g_access (config_file, F_OK) != 0)
- katze_assign (config_file, midori_paths_get_config_filename (NULL, "accels"));
+ katze_assign (config_file, midori_paths_get_preset_filename (NULL, "accels"));
gtk_accel_map_load (config_file);
g_free (config_file);
}
static KatzeArray*
-search_engines_new_from_folder (const gchar* config,
- GString* error_messages)
+search_engines_new_from_folder (GString* error_messages)
{
- gchar* config_file = g_build_filename (config, "search", NULL);
+ gchar* config_file = midori_paths_get_config_filename ("search");
GError* error = NULL;
KatzeArray* search_engines;
if (!error && katze_array_is_empty (search_engines))
{
katze_assign (config_file,
- midori_paths_get_config_filename (NULL, "search"));
+ midori_paths_get_preset_filename (NULL, "search"));
katze_object_assign (search_engines,
search_engines_new_from_file (config_file, NULL));
}
"COMMIT;",
NULL, NULL, errmsg);
- bookmarks_filename = build_config_filename ("bookmarks_v2.db");
+ bookmarks_filename = midori_paths_get_config_filename ("bookmarks_v2.db");
sql = g_strdup_printf ("ATTACH DATABASE '%s' AS bookmarks", bookmarks_filename);
g_free (bookmarks_filename);
sqlite3_exec (db, sql, NULL, NULL, errmsg);
if (pspec && midori_settings_delay_saving (MIDORI_SETTINGS (settings), pspec->name))
return;
- config_file = build_config_filename ("config");
+ config_file = midori_paths_get_config_filename ("config");
if (!settings_save_to_file (settings, app, config_file, &error))
{
g_warning (_("The configuration couldn't be saved. %s"), error->message);
guint accel_key,
GdkModifierType accel_mods)
{
- gchar* config_file = build_config_filename ("accels");
+ gchar* config_file = midori_paths_get_config_filename ("accels");
gtk_accel_map_save (config_file);
g_free (config_file);
}
gpointer item,
KatzeArray* search_engines)
{
- gchar* config_file = build_config_filename ("search");
+ gchar* config_file = midori_paths_get_config_filename ("search");
GError* error = NULL;
if (!search_engines_save_to_file (search_engines, config_file, &error))
{
midori_trash_remove_item_cb (KatzeArray* trash,
GObject* item)
{
- gchar* config_file = build_config_filename ("tabtrash.xbel");
+ gchar* config_file = midori_paths_get_config_filename ("tabtrash.xbel");
GError* error = NULL;
midori_trash_add_item_no_save_cb (trash, item);
if (!midori_array_to_file (trash, config_file, "xbel", &error))
static gboolean
midori_session_save_timeout_cb (KatzeArray* session)
{
- gchar* config_file = build_config_filename ("session.xbel");
+ gchar* config_file = midori_paths_get_config_filename ("session.xbel");
GError* error = NULL;
if (!midori_array_to_file (session, config_file, "xbel", &error))
{
midori_app_quit_cb (MidoriBrowser* browser,
KatzeArray* session)
{
- gchar* config_file = build_config_filename ("running");
+ gchar* config_file = midori_paths_get_config_filename ("running");
g_unlink (config_file);
g_free (config_file);
g_signal_connect (session, "request-queued",
G_CALLBACK (midori_soup_session_settings_accept_language_cb), settings);
- soup_session_add_feature (session,
- SOUP_SESSION_FEATURE (midori_hsts_new (build_config_filename ("hsts"))));
+ soup_session_add_feature (session, SOUP_SESSION_FEATURE (
+ midori_hsts_new (midori_paths_get_readonly_config_filename ("hsts"))));
midori_soup_session_debug (session);
midori_load_soup_session (settings);
- config_file = build_config_filename ("logins");
+ config_file = midori_paths_get_config_filename ("logins");
feature = g_object_new (KATZE_TYPE_HTTP_AUTH, "filename", config_file, NULL);
soup_session_add_feature (session, feature);
g_object_unref (feature);
soup_session_add_feature (session, SOUP_SESSION_FEATURE (jar));
g_object_unref (jar);
- katze_assign (config_file, build_config_filename ("cookies.db"));
+ katze_assign (config_file, midori_paths_get_config_filename ("cookies.db"));
have_new_cookies = g_access (config_file, F_OK) == 0;
feature = g_object_new (KATZE_TYPE_HTTP_COOKIES_SQLITE, NULL);
g_object_set_data_full (G_OBJECT (feature), "filename",
if (!have_new_cookies)
{
- katze_assign (config_file, build_config_filename ("cookies.txt"));
+ katze_assign (config_file, midori_paths_get_config_filename ("cookies.txt"));
if (g_access (config_file, F_OK) == 0)
{
g_message ("Importing cookies from txt to sqlite3");
MidoriBrowser* browser)
{
KatzeArray* old_session = katze_array_new (KATZE_TYPE_ITEM);
- gchar* config_file = build_config_filename ("session.old.xbel");
+ gchar* config_file = midori_paths_get_readonly_config_filename ("session.old.xbel");
GError* error = NULL;
if (midori_array_from_file (old_session, config_file, "xbel", &error))
{
g_signal_connect_after (katze_object_get_object (app, "settings"), "notify",
G_CALLBACK (settings_notify_cb), app);
- config_file = build_config_filename ("session.old.xbel");
+ config_file = midori_paths_get_readonly_config_filename ("session.old.xbel");
if (g_access (config_file, F_OK) == 0)
{
GtkActionGroup* action_group = midori_browser_get_action_group (browser);
midori_app_add_browser (app, browser);
gtk_widget_show (GTK_WIDGET (browser));
- katze_assign (config_file, build_config_filename ("accels"));
+ katze_assign (config_file, midori_paths_get_readonly_config_filename ("accels"));
g_signal_connect_after (gtk_accel_map_get (), "changed",
G_CALLBACK (accel_map_changed_cb), NULL);
g_object_unref (settings);
g_object_unref (_session);
- katze_assign (config_file, build_config_filename ("session.xbel"));
+ katze_assign (config_file, midori_paths_get_readonly_config_filename ("session.xbel"));
g_signal_connect_after (browser, "add-tab",
G_CALLBACK (midori_browser_session_cb), session);
g_signal_connect_after (browser, "remove-tab",
{
if ((clear_prefs & flag) == flag)
{
- gchar* config_file = build_config_filename (filename);
+ gchar* config_file = midori_paths_get_config_filename (filename);
g_unlink (config_file);
g_free (config_file);
}
g_free (old_config);
}
- /* Private browsing, window title, default config folder */
- if (private)
- {
- if (!config && !webapp)
- config = midori_paths_get_readonly_config_dir (MIDORI_RUNTIME_MODE_PRIVATE);
- /* Mask the timezone, which can be read by Javascript */
- g_setenv ("TZ", "UTC", TRUE);
- }
- else
- g_set_application_name (_("Midori"));
-
+ g_set_application_name (_("Midori"));
/* Versioned prgname to override menuproxy blacklist */
g_set_prgname (PACKAGE_NAME "4");
midori_startup_timer ("Browser: \t%f");
- if (config)
+ if (private)
+ midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, config);
+ else if (webapp)
+ midori_paths_init (MIDORI_RUNTIME_MODE_APP, config);
+ else
+ midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, config);
+
+ if (private || !webapp)
{
- settings = settings_and_accels_new (config, &extensions);
+ settings = settings_and_accels_new (&extensions);
g_strfreev (extensions);
- search_engines = search_engines_new_from_folder (config, NULL);
+ search_engines = search_engines_new_from_folder (NULL);
g_object_set (browser, "search-engines", search_engines, NULL);
g_object_unref (search_engines);
}
if (private)
{
+ /* Mask the timezone, which can be read by Javascript */
+ g_setenv ("TZ", "UTC", TRUE);
/* In-memory trash for re-opening closed tabs */
trash = katze_array_new (KATZE_TYPE_ITEM);
g_signal_connect_after (trash, "add-item",
g_object_set (gtk_settings_get_default (),
"gtk-recent-files-max-age", 0, NULL);
- midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, "private://");
}
- else if (webapp)
- midori_paths_init (MIDORI_RUNTIME_MODE_APP, config ? config : "app://");
midori_load_soup_session (settings);
if (block_uris)
{
g_object_set (gtk_settings_get_default (),
"gtk-recent-files-max-age", 0, NULL);
- midori_paths_init (MIDORI_RUNTIME_MODE_PORTABLE, "portable://");
+ midori_paths_init (MIDORI_RUNTIME_MODE_PORTABLE, config);
}
else
midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, config);
/* Load configuration file */
error_messages = g_string_new (NULL);
error = NULL;
- settings = settings_and_accels_new (config, &extensions);
+ settings = settings_and_accels_new (&extensions);
g_object_set (settings, "enable-developer-extras", TRUE, NULL);
g_object_set (settings, "enable-html5-database", TRUE, NULL);
midori_startup_timer ("Config and accels read: \t%f");
/* Load search engines */
- search_engines = search_engines_new_from_folder (config, error_messages);
+ search_engines = search_engines_new_from_folder (error_messages);
/* Pick first search engine as default if not set */
g_object_get (settings, "location-entry-search", &uri, NULL);
if (!(uri && *uri) && !katze_array_is_empty (search_engines))
#if HAVE_LIBXML
if (load_on_startup >= MIDORI_STARTUP_LAST_OPEN_PAGES)
{
- katze_assign (config_file, build_config_filename ("session.xbel"));
+ katze_assign (config_file, midori_paths_get_readonly_config_filename ("session.xbel"));
error = NULL;
if (!midori_array_from_file (_session, config_file, "xbel", &error))
{
load_on_startup = katze_object_get_int (settings, "load-on-startup");
if (load_on_startup < MIDORI_STARTUP_LAST_OPEN_PAGES)
{
- katze_assign (config_file, g_build_filename (config, "session.xbel", NULL));
+ katze_assign (config_file, midori_paths_get_config_filename ("session.xbel"));
g_unlink (config_file);
}