Introduce Midori.Paths and Midori.RuntimeMode

Also introduce initial "portable" mode on Win32.
This commit is contained in:
Christian Dywan 2012-08-27 21:49:36 +02:00
parent 49dae87d36
commit 7f37162fe0
21 changed files with 192 additions and 135 deletions

View file

@ -10,6 +10,7 @@
See the file COPYING for the full license text. See the file COPYING for the full license text.
*/ */
#include <midori/midori.h> #include <midori/midori.h>
#include "midori-core.h"
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include "config.h" #include "config.h"
@ -179,8 +180,7 @@ adblock_get_filename_for_uri (const gchar* uri)
if (!strncmp (uri, "file", 4)) if (!strncmp (uri, "file", 4))
return g_strndup (uri + 7, strlen (uri) - 7); return g_strndup (uri + 7, strlen (uri) - 7);
folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME, folder = g_build_filename (midori_paths_get_cache_dir (), "adblock", NULL);
"adblock", NULL);
katze_mkdir_with_parents (folder, 0700); katze_mkdir_with_parents (folder, 0700);
filename = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1); filename = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);

View file

@ -14,6 +14,7 @@
/* This extensions add support for user addons: userscripts and userstyles */ /* This extensions add support for user addons: userscripts and userstyles */
#include <midori/midori.h> #include <midori/midori.h>
#include "midori-core.h"
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include "config.h" #include "config.h"
@ -182,8 +183,8 @@ addons_install_response (GtkWidget* infobar,
if (!filename) if (!filename)
filename = g_path_get_basename (uri); filename = g_path_get_basename (uri);
folder_path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), folder_path = g_build_path (G_DIR_SEPARATOR_S,
PACKAGE_NAME, folder, NULL); midori_paths_get_user_data_dir (), PACKAGE_NAME, folder, NULL);
if (!g_file_test (folder_path, G_FILE_TEST_EXISTS)) if (!g_file_test (folder_path, G_FILE_TEST_EXISTS))
katze_mkdir_with_parents (folder_path, 0700); katze_mkdir_with_parents (folder_path, 0700);
@ -293,13 +294,13 @@ addons_button_add_clicked_cb (GtkToolItem* toolitem,
if (addons->kind == ADDONS_USER_SCRIPTS) if (addons->kind == ADDONS_USER_SCRIPTS)
{ {
addons_type = g_strdup ("userscripts"); addons_type = g_strdup ("userscripts");
path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), path = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_user_data_dir (),
PACKAGE_NAME, "scripts", NULL); PACKAGE_NAME, "scripts", NULL);
} }
else if (addons->kind == ADDONS_USER_STYLES) else if (addons->kind == ADDONS_USER_STYLES)
{ {
addons_type = g_strdup ("userstyles"); addons_type = g_strdup ("userstyles");
path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), path = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_user_data_dir (),
PACKAGE_NAME, "styles", NULL); PACKAGE_NAME, "styles", NULL);
} }
else else
@ -513,13 +514,10 @@ addons_open_target_folder_clicked_cb (GtkWidget* toolitem,
} }
else else
{ {
folder = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), folder = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_user_data_dir (),
PACKAGE_NAME, PACKAGE_NAME, addons->kind == ADDONS_USER_SCRIPTS
addons->kind == ADDONS_USER_SCRIPTS ? "scripts" : "styles", NULL);
? "scripts" : "styles", NULL); katze_mkdir_with_parents (folder, 0700);
if (!g_file_test (folder, G_FILE_TEST_EXISTS))
katze_mkdir_with_parents (folder, 0700);
} }
folder_uri = g_filename_to_uri (folder, NULL, NULL); folder_uri = g_filename_to_uri (folder, NULL, NULL);
@ -827,7 +825,7 @@ addons_get_directories (AddonsKind kind)
else else
g_assert_not_reached (); g_assert_not_reached ();
path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), path = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_user_data_dir (),
PACKAGE_NAME, folder_name, NULL); PACKAGE_NAME, folder_name, NULL);
directories = g_slist_prepend (directories, path); directories = g_slist_prepend (directories, path);

View file

@ -28,7 +28,7 @@ web_cache_get_cache_dir (void)
{ {
static gchar* cache_dir = NULL; static gchar* cache_dir = NULL;
if (!cache_dir) if (!cache_dir)
cache_dir = g_build_filename (g_get_user_cache_dir (), cache_dir = g_build_filename (sokoke_get_user_cache_dir (),
PACKAGE_NAME, "web", NULL); PACKAGE_NAME, "web", NULL);
return cache_dir; return cache_dir;
} }

View file

@ -19,6 +19,7 @@
#include "katze-net.h" #include "katze-net.h"
#include "midori-core.h" #include "midori-core.h"
#include "sokoke.h"
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <libsoup/soup.h> #include <libsoup/soup.h>
@ -28,7 +29,6 @@ struct _KatzeNet
{ {
GObject parent_instance; GObject parent_instance;
gchar* cache_path;
guint cache_size; guint cache_size;
}; };
@ -54,17 +54,11 @@ katze_net_class_init (KatzeNetClass* class)
static void static void
katze_net_init (KatzeNet* net) katze_net_init (KatzeNet* net)
{ {
net->cache_path = g_build_filename (g_get_user_cache_dir (),
PACKAGE_NAME, NULL);
} }
static void static void
katze_net_finalize (GObject* object) katze_net_finalize (GObject* object)
{ {
KatzeNet* net = KATZE_NET (object);
katze_assign (net->cache_path, NULL);
G_OBJECT_CLASS (katze_net_parent_class)->finalize (object); G_OBJECT_CLASS (katze_net_parent_class)->finalize (object);
} }
@ -118,9 +112,9 @@ katze_net_get_cached_path (KatzeNet* net,
net = katze_net_new (); net = katze_net_new ();
if (subfolder) if (subfolder)
cache_path = g_build_filename (net->cache_path, subfolder, NULL); cache_path = g_build_filename (midori_paths_get_cache_dir (), subfolder, NULL);
else else
cache_path = net->cache_path; cache_path = midori_paths_get_cache_dir ();
katze_mkdir_with_parents (cache_path, 0700); katze_mkdir_with_parents (cache_path, 0700);
checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1); checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);

View file

@ -14,6 +14,7 @@
#include "katze-utils.h" #include "katze-utils.h"
#include "katze-array.h" #include "katze-array.h"
#include "midori-core.h" #include "midori-core.h"
#include "sokoke.h"
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
@ -1509,8 +1510,7 @@ katze_load_cached_icon (const gchar* uri,
filename = g_strdup_printf ("%s%s", checksum, ext ? ext : ""); filename = g_strdup_printf ("%s%s", checksum, ext ? ext : "");
g_free (icon_uri); g_free (icon_uri);
g_free (checksum); g_free (checksum);
path = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME, path = g_build_filename (midori_paths_get_cache_dir (), "icons", filename, NULL);
"icons", filename, NULL);
g_free (filename); g_free (filename);
if ((icon = gdk_pixbuf_new_from_file_at_size (path, 16, 16, NULL))) if ((icon = gdk_pixbuf_new_from_file_at_size (path, 16, 16, NULL)))
{ {

117
katze/midori-paths.vala Normal file
View file

@ -0,0 +1,117 @@
/*
Copyright (C) 2012 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
namespace GLib {
#if HAVE_WIN32
extern static string win32_get_package_installation_directory_of_module (void* hmodule = null);
#endif
}
namespace Midori {
public enum RuntimeMode {
UNDEFINED,
NORMAL,
APP,
PRIVATE,
PORTABLE
}
namespace Paths {
static RuntimeMode mode = RuntimeMode.UNDEFINED;
static string? config_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) {
#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");
}
return Path.build_path (Path.DIR_SEPARATOR_S,
Environment.get_user_config_dir (), "midori");
}
public static void init (RuntimeMode new_mode, string? config_base) {
assert (mode == RuntimeMode.UNDEFINED);
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");
cache_dir = Path.build_path (Path.DIR_SEPARATOR_S,
profile, "profile", "cache");
user_data_dir = Path.build_path (Path.DIR_SEPARATOR_S,
profile, "profile", "misc");
tmp_dir = Path.build_path (Path.DIR_SEPARATOR_S,
profile, "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://";
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 (), "midori");
cache_dir = Path.build_path (Path.DIR_SEPARATOR_S,
Environment.get_user_cache_dir (), "midori");
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 ());
}
if (strcmp (Environment.get_variable ("MIDORI_DEBUG"), "paths") == 0) {
stdout.printf ("config: %s\ncache: %s\nuser_data: %s\ntmp: %s\n",
config_dir, cache_dir, user_data_dir, tmp_dir);
}
}
public bool is_readonly () {
return mode == RuntimeMode.APP || mode == RuntimeMode.PRIVATE;
}
public static string get_config_dir () {
assert (config_dir != null);
return config_dir;
}
public static string get_cache_dir () {
assert (cache_dir != null);
return cache_dir;
}
public static string get_user_data_dir () {
assert (user_data_dir != null);
return user_data_dir;
}
public static string get_tmp_dir () {
assert (tmp_dir != null);
return tmp_dir;
}
}
}

View file

@ -55,7 +55,7 @@
static gchar* static gchar*
build_config_filename (const gchar* filename) build_config_filename (const gchar* filename)
{ {
return g_build_filename (sokoke_set_config_dir (NULL), filename, NULL); return g_build_filename (midori_paths_get_config_dir (), filename, NULL);
} }
static MidoriWebSettings* static MidoriWebSettings*
@ -1018,7 +1018,7 @@ midori_load_soup_session (gpointer settings)
#endif #endif
#if WEBKIT_CHECK_VERSION (1, 8, 0) #if WEBKIT_CHECK_VERSION (1, 8, 0)
gchar* cache = g_build_filename (g_get_user_data_dir (), gchar* cache = g_build_filename (midori_paths_get_user_data_dir (),
"webkit", "icondatabase", NULL); "webkit", "icondatabase", NULL);
webkit_favicon_database_set_path (webkit_get_favicon_database (), cache); webkit_favicon_database_set_path (webkit_get_favicon_database (), cache);
g_free (cache); g_free (cache);
@ -1194,8 +1194,7 @@ midori_load_soup_session_full (gpointer settings)
} }
#if WEBKIT_CHECK_VERSION (1, 3, 11) #if WEBKIT_CHECK_VERSION (1, 3, 11)
katze_assign (config_file, g_build_filename (g_get_user_cache_dir (), katze_assign (config_file, g_build_filename (midori_paths_get_cache_dir (), "web", NULL));
PACKAGE_NAME, "web", NULL));
feature = SOUP_SESSION_FEATURE (soup_cache_new (config_file, 0)); feature = SOUP_SESSION_FEATURE (soup_cache_new (config_file, 0));
soup_session_add_feature (session, feature); soup_session_add_feature (session, feature);
soup_cache_set_max_size (SOUP_CACHE (feature), soup_cache_set_max_size (SOUP_CACHE (feature),
@ -1615,8 +1614,7 @@ speeddial_new_from_file (const gchar* config,
g_key_file_load_from_data (key_file, keyfile, -1, 0, NULL); g_key_file_load_from_data (key_file, keyfile, -1, 0, NULL);
g_free (keyfile); g_free (keyfile);
tiles = g_key_file_get_groups (key_file, NULL); tiles = g_key_file_get_groups (key_file, NULL);
thumb_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_cache_dir (), thumb_dir = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_cache_dir (), "thumbnails", NULL);
PACKAGE_NAME, "thumbnails", NULL);
if (!g_file_test (thumb_dir, G_FILE_TEST_EXISTS)) if (!g_file_test (thumb_dir, G_FILE_TEST_EXISTS))
katze_mkdir_with_parents (thumb_dir, 0700); katze_mkdir_with_parents (thumb_dir, 0700);
g_free (thumb_dir); g_free (thumb_dir);
@ -1804,10 +1802,10 @@ static void
midori_clear_saved_logins_cb (void) midori_clear_saved_logins_cb (void)
{ {
sqlite3* db; sqlite3* db;
gchar* path = g_build_filename (sokoke_set_config_dir (NULL), "logins", NULL); gchar* path = g_build_filename (midori_paths_get_config_dir (), "logins", NULL);
g_unlink (path); g_unlink (path);
/* Form History database, written by the extension */ /* Form History database, written by the extension */
katze_assign (path, g_build_filename (sokoke_set_config_dir (NULL), katze_assign (path, g_build_filename (midori_paths_get_config_dir (),
"extensions", MIDORI_MODULE_PREFIX "formhistory." G_MODULE_SUFFIX, "forms.db", NULL)); "extensions", MIDORI_MODULE_PREFIX "formhistory." G_MODULE_SUFFIX, "forms.db", NULL));
if (sqlite3_open (path, &db) == SQLITE_OK) if (sqlite3_open (path, &db) == SQLITE_OK)
{ {
@ -1823,7 +1821,7 @@ midori_clear_web_cache_cb (void)
{ {
SoupSession* session = webkit_get_default_session (); SoupSession* session = webkit_get_default_session ();
SoupSessionFeature* feature = soup_session_get_feature (session, SOUP_TYPE_CACHE); SoupSessionFeature* feature = soup_session_get_feature (session, SOUP_TYPE_CACHE);
gchar* cache = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME, "web", NULL); gchar* cache = g_build_filename (midori_paths_get_cache_dir (), "web", NULL);
soup_cache_clear (SOUP_CACHE (feature)); soup_cache_clear (SOUP_CACHE (feature));
soup_cache_flush (SOUP_CACHE (feature)); soup_cache_flush (SOUP_CACHE (feature));
sokoke_remove_path (cache, TRUE); sokoke_remove_path (cache, TRUE);
@ -1834,13 +1832,11 @@ midori_clear_web_cache_cb (void)
static void static void
midori_clear_page_icons_cb (void) midori_clear_page_icons_cb (void)
{ {
gchar* cache = g_build_filename (g_get_user_cache_dir (), gchar* cache = g_build_filename (midori_paths_get_cache_dir (), "icons", NULL);
PACKAGE_NAME, "icons", NULL);
/* FIXME: Exclude search engine icons */ /* FIXME: Exclude search engine icons */
sokoke_remove_path (cache, TRUE); sokoke_remove_path (cache, TRUE);
g_free (cache); g_free (cache);
cache = g_build_filename (g_get_user_data_dir (), cache = g_build_filename (midori_paths_get_user_data_dir (), "webkit", "icondatabase", NULL);
"webkit", "icondatabase", NULL);
sokoke_remove_path (cache, TRUE); sokoke_remove_path (cache, TRUE);
g_free (cache); g_free (cache);
#if WEBKIT_CHECK_VERSION (1, 8, 0) #if WEBKIT_CHECK_VERSION (1, 8, 0)
@ -1897,6 +1893,7 @@ main (int argc,
gchar* webapp; gchar* webapp;
gchar* config; gchar* config;
gboolean private; gboolean private;
gboolean portable;
gboolean diagnostic_dialog; gboolean diagnostic_dialog;
gboolean back_from_crash; gboolean back_from_crash;
gboolean run; gboolean run;
@ -1921,6 +1918,10 @@ main (int argc,
#endif #endif
{ "private", 'p', 0, G_OPTION_ARG_NONE, &private, { "private", 'p', 0, G_OPTION_ARG_NONE, &private,
N_("Private browsing, no changes are saved"), NULL }, N_("Private browsing, no changes are saved"), NULL },
#ifdef G_OS_WIN32
{ "portable", 't', 0, G_OPTION_ARG_NONE, &portable,
N_("Portable mode, all runtime files are stored in one place"), NULL },
#endif
{ "diagnostic-dialog", 'd', 0, G_OPTION_ARG_NONE, &diagnostic_dialog, { "diagnostic-dialog", 'd', 0, G_OPTION_ARG_NONE, &diagnostic_dialog,
N_("Show a diagnostic dialog"), NULL }, N_("Show a diagnostic dialog"), NULL },
{ "run", 'r', 0, G_OPTION_ARG_NONE, &run, { "run", 'r', 0, G_OPTION_ARG_NONE, &run,
@ -1992,6 +1993,7 @@ main (int argc,
webapp = NULL; webapp = NULL;
config = NULL; config = NULL;
private = FALSE; private = FALSE;
portable = FALSE;
back_from_crash = FALSE; back_from_crash = FALSE;
diagnostic_dialog = FALSE; diagnostic_dialog = FALSE;
run = FALSE; run = FALSE;
@ -2025,7 +2027,7 @@ main (int argc,
if (private) if (private)
{ {
if (!config && !webapp) if (!config && !webapp)
config = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL); config = midori_paths_get_readonly_config_dir (MIDORI_RUNTIME_MODE_PRIVATE);
/* Mask the timezone, which can be read by Javascript */ /* Mask the timezone, which can be read by Javascript */
g_setenv ("TZ", "UTC", TRUE); g_setenv ("TZ", "UTC", TRUE);
} }
@ -2207,13 +2209,13 @@ main (int argc,
"gtk-application-prefer-dark-theme", TRUE, "gtk-application-prefer-dark-theme", TRUE,
NULL); NULL);
#endif #endif
}
if (private || !config) midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, "private://");
{
/* Disable saving by setting an unwritable folder */
sokoke_set_config_dir ("/");
} }
else if (webapp)
midori_paths_init (MIDORI_RUNTIME_MODE_APP, config ? config : "app://");
else if (portable)
midori_paths_init (MIDORI_RUNTIME_MODE_PORTABLE, "portable://");
midori_load_soup_session (settings); midori_load_soup_session (settings);
if (block_uris) if (block_uris)
@ -2326,9 +2328,9 @@ main (int argc,
if (inactivity_reset > 0) if (inactivity_reset > 0)
g_error ("--inactivity-reset is currently only supported with --app."); g_error ("--inactivity-reset is currently only supported with --app.");
sokoke_set_config_dir (config); midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, config);
app = midori_app_new (); app = midori_app_new ();
katze_assign (config, (gchar*)sokoke_set_config_dir (NULL)); katze_assign (config, g_strdup (midori_paths_get_config_dir ()));
midori_startup_timer ("App created: \t%f"); midori_startup_timer ("App created: \t%f");
/* FIXME: The app might be 'running' but actually showing a dialog /* FIXME: The app might be 'running' but actually showing a dialog

View file

@ -21,6 +21,7 @@
#include "midori-app.h" #include "midori-app.h"
#include "midori-platform.h" #include "midori-platform.h"
#include "midori-core.h"
#include <string.h> #include <string.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -750,7 +751,7 @@ midori_app_create_instance (MidoriApp* app)
{ {
#if HAVE_UNIQUE #if HAVE_UNIQUE
const gchar* config = sokoke_set_config_dir (NULL); const gchar* config = midori_paths_get_config_dir ();
gchar* name_hash; gchar* name_hash;
name_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, config, -1); name_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, config, -1);
katze_assign (app_name, g_strconcat ("midori", "_", name_hash, NULL)); katze_assign (app_name, g_strconcat ("midori", "_", name_hash, NULL));
@ -781,7 +782,7 @@ midori_app_create_instance (MidoriApp* app)
g_signal_connect (instance, "message-received", g_signal_connect (instance, "message-received",
G_CALLBACK (midori_browser_message_received_cb), app); G_CALLBACK (midori_browser_message_received_cb), app);
#else #else
instance = socket_init (instance_name, sokoke_set_config_dir (NULL), &exists); instance = socket_init (instance_name, midori_paths_get_config_dir (), &exists);
g_object_set_data (G_OBJECT (app), "sock-exists", g_object_set_data (G_OBJECT (app), "sock-exists",
exists ? (gpointer)0xdeadbeef : NULL); exists ? (gpointer)0xdeadbeef : NULL);
if (instance != MidoriAppInstanceNull) if (instance != MidoriAppInstanceNull)
@ -1567,7 +1568,7 @@ midori_debug (const gchar* token)
{ {
static const gchar* debug_token = NULL; static const gchar* debug_token = NULL;
const gchar* debug = g_getenv ("MIDORI_DEBUG"); const gchar* debug = g_getenv ("MIDORI_DEBUG");
const gchar* debug_tokens = "soup soup:1 soup:2 soup:3 cookies "; const gchar* debug_tokens = "soup soup:1 soup:2 soup:3 cookies paths ";
const gchar* full_debug_tokens = "adblock:1 adblock:2 startup bookmarks "; const gchar* full_debug_tokens = "adblock:1 adblock:2 startup bookmarks ";
if (debug_token == NULL) if (debug_token == NULL)
{ {

View file

@ -14,6 +14,7 @@
#include "panels/midori-bookmarks.h" #include "panels/midori-bookmarks.h"
#include "midori-array.h" #include "midori-array.h"
#include "sokoke.h" #include "sokoke.h"
#include "midori-core.h"
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
@ -142,9 +143,9 @@ midori_bookmarks_initialize (KatzeArray* array,
g_return_val_if_fail (errmsg != NULL, NULL); g_return_val_if_fail (errmsg != NULL, NULL);
oldfile = g_build_filename (sokoke_set_config_dir (NULL), "bookmarks.db", NULL); oldfile = g_build_filename (midori_paths_get_config_dir (), "bookmarks.db", NULL);
oldfile_exists = g_access (oldfile, F_OK) == 0; oldfile_exists = g_access (oldfile, F_OK) == 0;
newfile = g_build_filename (sokoke_set_config_dir (NULL), "bookmarks_v2.db", NULL); newfile = g_build_filename (midori_paths_get_config_dir (), "bookmarks_v2.db", NULL);
newfile_did_exist = g_access (newfile, F_OK) == 0; newfile_did_exist = g_access (newfile, F_OK) == 0;
/* sqlite3_open will create the file if it did not exists already */ /* sqlite3_open will create the file if it did not exists already */

View file

@ -565,7 +565,7 @@ midori_view_notify_icon_cb (MidoriView* view,
if (midori_browser_get_current_tab (browser) != (GtkWidget*)view) if (midori_browser_get_current_tab (browser) != (GtkWidget*)view)
return; return;
if (sokoke_is_app_or_private ()) if (midori_paths_is_readonly () /* APP, PRIVATE */)
gtk_window_set_icon (GTK_WINDOW (browser), midori_view_get_icon (view)); gtk_window_set_icon (GTK_WINDOW (browser), midori_view_get_icon (view));
} }
@ -1286,8 +1286,7 @@ midori_browser_add_speed_dial (MidoriBrowser* browser)
GKeyFile* key_file; GKeyFile* key_file;
gchar* dial_id = g_strdup_printf ("Dial %s", slot_id + 1); gchar* dial_id = g_strdup_printf ("Dial %s", slot_id + 1);
gchar* file_path = sokoke_build_thumbnail_path (uri); gchar* file_path = sokoke_build_thumbnail_path (uri);
gchar* thumb_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_cache_dir (), gchar* thumb_dir = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_cache_dir (), "thumbnails", NULL);
PACKAGE_NAME, "thumbnails", NULL);
g_object_get (browser, "speed-dial", &key_file, NULL); g_object_get (browser, "speed-dial", &key_file, NULL);
g_key_file_set_string (key_file, dial_id, "uri", uri); g_key_file_set_string (key_file, dial_id, "uri", uri);
@ -1560,7 +1559,7 @@ midori_browser_download_prepare_destination_uri (WebKitDownload* download,
gchar* suggested_filename; gchar* suggested_filename;
GFile* file_source; GFile* file_source;
gchar* file_basename; gchar* file_basename;
gchar* download_dir = NULL; const gchar* download_dir = NULL;
gchar* destination_uri; gchar* destination_uri;
gchar* destination_filename; gchar* destination_filename;
@ -1569,16 +1568,14 @@ midori_browser_download_prepare_destination_uri (WebKitDownload* download,
g_free (suggested_filename); g_free (suggested_filename);
file_basename = g_file_get_basename (file_source); file_basename = g_file_get_basename (file_source);
if (folder == NULL) if (folder == NULL)
download_dir = midori_view_get_tmp_dir (); download_dir = midori_paths_get_tmp_dir ();
else else
download_dir = (gchar*)folder; download_dir = folder;
destination_filename = g_build_filename (download_dir, file_basename, NULL); destination_filename = g_build_filename (download_dir, file_basename, NULL);
destination_filename = midori_browser_download_prepare_filename (destination_filename); destination_filename = midori_browser_download_prepare_filename (destination_filename);
destination_uri = g_filename_to_uri (destination_filename, NULL, NULL); destination_uri = g_filename_to_uri (destination_filename, NULL, NULL);
g_free (file_basename); g_free (file_basename);
if (folder == NULL)
g_free (download_dir);
g_free (destination_filename); g_free (destination_filename);
g_object_unref (file_source); g_object_unref (file_source);
@ -2749,7 +2746,7 @@ _action_tab_close_activate (GtkAction* action,
GtkWidget* widget = midori_browser_get_current_tab (browser); GtkWidget* widget = midori_browser_get_current_tab (browser);
MidoriView* view = MIDORI_VIEW (widget); MidoriView* view = MIDORI_VIEW (widget);
gboolean last_tab = midori_browser_get_n_pages (browser) == 1; gboolean last_tab = midori_browser_get_n_pages (browser) == 1;
if (last_tab && sokoke_is_app_or_private ()) if (last_tab && midori_paths_is_readonly () /* APP, PRIVATE */)
{ {
gtk_widget_destroy (GTK_WIDGET (browser)); gtk_widget_destroy (GTK_WIDGET (browser));
return; return;
@ -5345,7 +5342,7 @@ midori_browser_switched_tab (MidoriBrowser* browser,
midori_browser_set_title (browser, midori_view_get_display_title (new_view)); midori_browser_set_title (browser, midori_view_get_display_title (new_view));
action = _action_by_name (browser, "Location"); action = _action_by_name (browser, "Location");
midori_location_action_set_text (MIDORI_LOCATION_ACTION (action), uri); midori_location_action_set_text (MIDORI_LOCATION_ACTION (action), uri);
if (sokoke_is_app_or_private ()) if (midori_paths_is_readonly () /* APP, PRIVATE */)
gtk_window_set_icon (GTK_WINDOW (browser), midori_view_get_icon (new_view)); gtk_window_set_icon (GTK_WINDOW (browser), midori_view_get_icon (new_view));
if (browser->proxy_array) if (browser->proxy_array)

View file

@ -14,6 +14,7 @@
#include <katze/katze.h> #include <katze/katze.h>
#include "midori-platform.h" #include "midori-platform.h"
#include "midori-core.h"
#include <glib/gi18n.h> #include <glib/gi18n.h>
G_DEFINE_TYPE (MidoriExtension, midori_extension, G_TYPE_OBJECT); G_DEFINE_TYPE (MidoriExtension, midori_extension, G_TYPE_OBJECT);
@ -648,7 +649,7 @@ midori_extension_get_config_dir (MidoriExtension* extension)
if (!filename) if (!filename)
return "/"; return "/";
extension->priv->config_dir = g_build_filename ( extension->priv->config_dir = g_build_filename (
sokoke_set_config_dir (NULL), "extensions", filename, NULL); midori_paths_get_config_dir (), "extensions", filename, NULL);
} }
return extension->priv->config_dir; return extension->priv->config_dir;

View file

@ -12,6 +12,7 @@
#include "midori-preferences.h" #include "midori-preferences.h"
#include "midori-app.h" #include "midori-app.h"
#include "midori-core.h"
#include "midori-platform.h" #include "midori-platform.h"
#include <string.h> #include <string.h>
@ -293,7 +294,7 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
#define SPANNED_ADD(__widget) \ #define SPANNED_ADD(__widget) \
katze_preferences_add_widget (_preferences, __widget, "spanned") katze_preferences_add_widget (_preferences, __widget, "spanned")
/* Page "General" */ /* Page "General" */
if (!sokoke_is_app_or_private ()) if (!midori_paths_is_readonly ())
{ {
PAGE_NEW (GTK_STOCK_HOME, _("Startup")); PAGE_NEW (GTK_STOCK_HOME, _("Startup"));
FRAME_NEW (NULL); FRAME_NEW (NULL);

View file

@ -3002,7 +3002,7 @@ midori_view_populate_popup (MidoriView* view,
gtk_action_group_get_action (actions, "BookmarkAdd")); gtk_action_group_get_action (actions, "BookmarkAdd"));
gtk_menu_shell_append (menu_shell, menuitem); gtk_menu_shell_append (menu_shell, menuitem);
if (!midori_view_is_blank (view) && !sokoke_is_app_or_private ()) if (!midori_view_is_blank (view) && !midori_paths_is_readonly ())
{ {
menuitem = sokoke_action_create_popup_menu_item ( menuitem = sokoke_action_create_popup_menu_item (
gtk_action_group_get_action (actions, "AddSpeedDial")); gtk_action_group_get_action (actions, "AddSpeedDial"));
@ -4286,8 +4286,8 @@ prepare_speed_dial_html (MidoriView* view,
g_string_append_printf (markup, g_string_append_printf (markup,
"%s<style>.cross { display:none }</style>%s" "%s<style>.cross { display:none }</style>%s"
"<style> div.shortcut { height: %d%%; width: %d%%; }</style>\n", "<style> div.shortcut { height: %d%%; width: %d%%; }</style>\n",
sokoke_is_app_or_private () ? "" : "<noscript>", midori_paths_is_readonly () ? "" : "<noscript>",
sokoke_is_app_or_private () ? "" : "</noscript>", midori_paths_is_readonly () ? "" : "</noscript>",
slot_size + 1, slot_size - 4); slot_size + 1, slot_size - 4);
/* Combined width of slots should always be less than 100%. /* Combined width of slots should always be less than 100%.
@ -4525,7 +4525,6 @@ midori_view_set_uri (MidoriView* view,
{ {
gchar* res_dir = midori_app_find_res_filename (""); gchar* res_dir = midori_app_find_res_filename ("");
gchar* lib_dir = midori_app_get_lib_path (PACKAGE_NAME); gchar* lib_dir = midori_app_get_lib_path (PACKAGE_NAME);
gchar* tmp_dir = midori_view_get_tmp_dir ();
data = g_strdup_printf ("<body><h1>%s</h1>" data = g_strdup_printf ("<body><h1>%s</h1>"
"<p>config: %s</p>" "<p>config: %s</p>"
"<p>res: %s</p>" "<p>res: %s</p>"
@ -4533,10 +4532,10 @@ midori_view_set_uri (MidoriView* view,
"<p>cache: %s</p>" "<p>cache: %s</p>"
"<p>tmp: %s</p>" "<p>tmp: %s</p>"
"</body>", "</body>",
uri, sokoke_set_config_dir (NULL), res_dir, lib_dir, g_get_user_cache_dir (), tmp_dir); uri, midori_paths_get_config_dir (), res_dir,
lib_dir, midori_paths_get_cache_dir (), midori_paths_get_tmp_dir ());
g_free (res_dir); g_free (res_dir);
g_free (lib_dir); g_free (lib_dir);
g_free (tmp_dir);
katze_assign (view->uri, g_strdup (uri)); katze_assign (view->uri, g_strdup (uri));
} }
else if (!strcmp (uri, "about:") || !strcmp (uri, "about:version")) else if (!strcmp (uri, "about:") || !strcmp (uri, "about:version"))
@ -5643,15 +5642,6 @@ midori_view_fallback_extension (MidoriView* view,
return ""; return "";
} }
gchar*
midori_view_get_tmp_dir (void)
{
gchar* tmpdir = g_strdup_printf ("%s/midori-%s",
g_get_tmp_dir (), g_get_user_name ());
g_mkdir (tmpdir, 0700);
return tmpdir;
}
/** /**
* midori_view_save_source: * midori_view_save_source:
* @view: a #MidoriView * @view: a #MidoriView
@ -5687,10 +5677,8 @@ midori_view_save_source (MidoriView* view,
if (!outfile) if (!outfile)
{ {
gchar* extension = midori_view_get_uri_extension (uri); gchar* extension = midori_view_get_uri_extension (uri);
gchar* tmpdir = midori_view_get_tmp_dir (); unique_filename = g_strdup_printf ("%s/%uXXXXXX%s", midori_paths_get_tmp_dir (),
unique_filename = g_strdup_printf ("%s/%uXXXXXX%s", tmpdir,
g_str_hash (uri), midori_view_fallback_extension (view, extension)); g_str_hash (uri), midori_view_fallback_extension (view, extension));
g_free (tmpdir);
g_free (extension); g_free (extension);
fd = g_mkstemp (unique_filename); fd = g_mkstemp (unique_filename);
} }
@ -6348,8 +6336,7 @@ thumb_view_load_status_cb (WebKitWebView* thumb_view_,
img = midori_view_web_view_get_snapshot (thumb_view, 240, 160); img = midori_view_web_view_get_snapshot (thumb_view, 240, 160);
#endif #endif
file_path = sokoke_build_thumbnail_path (url); file_path = sokoke_build_thumbnail_path (url);
thumb_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_cache_dir (), thumb_dir = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_cache_dir (), "thumbnails", NULL);
PACKAGE_NAME, "thumbnails", NULL);
if (!g_file_test (thumb_dir, G_FILE_TEST_EXISTS)) if (!g_file_test (thumb_dir, G_FILE_TEST_EXISTS))
katze_mkdir_with_parents (thumb_dir, 0700); katze_mkdir_with_parents (thumb_dir, 0700);
@ -6549,7 +6536,7 @@ midori_view_save_speed_dial_config (MidoriView* view,
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view)); MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
GtkWidget* tab; GtkWidget* tab;
config_file = g_build_filename (sokoke_set_config_dir (NULL), "speeddial", NULL); config_file = g_build_filename (midori_paths_get_config_dir (), "speeddial", NULL);
sokoke_key_file_save_to_file (key_file, config_file, NULL); sokoke_key_file_save_to_file (key_file, config_file, NULL);
g_free (config_file); g_free (config_file);

View file

@ -298,9 +298,6 @@ const gchar*
midori_view_fallback_extension (MidoriView* view, midori_view_fallback_extension (MidoriView* view,
const gchar* extension); const gchar* extension);
gchar*
midori_view_get_tmp_dir (void);
G_END_DECLS G_END_DECLS
#endif /* __MIDORI_VIEW_H__ */ #endif /* __MIDORI_VIEW_H__ */

View file

@ -497,7 +497,7 @@ sokoke_spawn_app (const gchar* uri,
gchar* argument; gchar* argument;
if (private) if (private)
{ {
gchar* config_quoted = g_shell_quote (sokoke_set_config_dir (NULL)); gchar* config_quoted = g_shell_quote (midori_paths_get_config_dir ());
argument = g_strconcat ("-c ", config_quoted, argument = g_strconcat ("-c ", config_quoted,
" -p ", uri_quoted, NULL); " -p ", uri_quoted, NULL);
} }
@ -970,42 +970,6 @@ sokoke_time_t_to_julian (const time_t* timestamp)
return julian; return julian;
} }
/**
* sokoke_set_config_dir:
* @new_config_dir: an absolute path, or %NULL
*
* Retrieves and/ or sets the base configuration folder.
*
* "/" means no configuration is saved.
*
* Return value: the configuration folder, or %NULL
**/
const gchar*
sokoke_set_config_dir (const gchar* new_config_dir)
{
static gchar* config_dir = NULL;
if (config_dir)
return config_dir;
if (!new_config_dir)
config_dir = g_build_filename (g_get_user_config_dir (),
PACKAGE_NAME, NULL);
else
{
g_return_val_if_fail (g_path_is_absolute (new_config_dir), NULL);
katze_assign (config_dir, g_strdup (new_config_dir));
}
return config_dir;
}
gboolean
sokoke_is_app_or_private (void)
{
return !strcmp ("/", sokoke_set_config_dir (NULL));
}
/** /**
* sokoke_remove_path: * sokoke_remove_path:
* @path: an absolute path * @path: an absolute path
@ -1116,7 +1080,7 @@ sokoke_find_data_filename (const gchar* filename,
g_free (path); g_free (path);
#endif #endif
path = g_build_filename (g_get_user_data_dir (), res1, res2, filename, NULL); path = g_build_filename (midori_paths_get_user_data_dir (), res1, res2, filename, NULL);
if (g_access (path, F_OK) == 0) if (g_access (path, F_OK) == 0)
return path; return path;
g_free (path); g_free (path);
@ -1409,8 +1373,7 @@ sokoke_build_thumbnail_path (const gchar* name)
gchar* checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, name, -1); gchar* checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, name, -1);
gchar* filename = g_strdup_printf ("%s.png", checksum); gchar* filename = g_strdup_printf ("%s.png", checksum);
path = g_build_filename (g_get_user_cache_dir (), "midori", "thumbnails", path = g_build_filename (midori_paths_get_cache_dir (), "thumbnails", filename, NULL);
filename, NULL);
g_free (filename); g_free (filename);
g_free (checksum); g_free (checksum);

View file

@ -130,12 +130,6 @@ sokoke_action_create_popup_menu_item (GtkAction* action);
gint64 gint64
sokoke_time_t_to_julian (const time_t* timestamp); sokoke_time_t_to_julian (const time_t* timestamp);
const gchar*
sokoke_set_config_dir (const gchar* new_config_dir);
gboolean
sokoke_is_app_or_private (void);
gboolean gboolean
sokoke_remove_path (const gchar* path, sokoke_remove_path (const gchar* path,
gboolean ignore_errors); gboolean ignore_errors);

View file

@ -132,6 +132,7 @@ main (int argc,
{ {
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
midori_app_setup (&argc, &argv, NULL, NULL); midori_app_setup (&argc, &argv, NULL, NULL);
midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, NULL);
g_object_set_data (G_OBJECT (webkit_get_default_session ()), g_object_set_data (G_OBJECT (webkit_get_default_session ()),
"midori-session-initialized", (void*)1); "midori-session-initialized", (void*)1);

View file

@ -247,6 +247,7 @@ main (int argc,
{ {
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
midori_app_setup (&argc, &argv, NULL, NULL); midori_app_setup (&argc, &argv, NULL, NULL);
midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, NULL);
soup_session_add_feature_by_type (webkit_get_default_session (), soup_session_add_feature_by_type (webkit_get_default_session (),
SOUP_TYPE_COOKIE_JAR); SOUP_TYPE_COOKIE_JAR);

View file

@ -189,6 +189,7 @@ main (int argc,
{ {
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
midori_app_setup (&argc, &argv, NULL, NULL); midori_app_setup (&argc, &argv, NULL, NULL);
midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, NULL);
g_object_set_data (G_OBJECT (webkit_get_default_session ()), g_object_set_data (G_OBJECT (webkit_get_default_session ()),
"midori-session-initialized", (void*)1); "midori-session-initialized", (void*)1);

View file

@ -159,7 +159,7 @@ midori_transferbar_download_notify_status_cb (WebKitDownload* download,
g_free (fingerprint); g_free (fingerprint);
if (verified) if (verified)
{ {
if (!sokoke_is_app_or_private ()) if (!midori_paths_is_readonly ())
gtk_recent_manager_add_item (gtk_recent_manager_get_default (), gtk_recent_manager_add_item (gtk_recent_manager_get_default (),
webkit_download_get_destination_uri (download)); webkit_download_get_destination_uri (download));
} }

View file

@ -245,6 +245,7 @@ def configure (conf):
args = '' args = ''
if Options.platform == 'win32': if Options.platform == 'win32':
args = '--define-variable=target=win32' args = '--define-variable=target=win32'
conf.env.append_value ('VALAFLAGS', '-D HAVE_WIN32')
elif sys.platform != 'darwin': elif sys.platform != 'darwin':
check_pkg ('x11') check_pkg ('x11')
# Pass /usr/X11R6/include for OpenBSD # Pass /usr/X11R6/include for OpenBSD