Don't do any saving on configuration files which are not writable

If you have a restricted setup where user configuration is not
meant to be saved, Midori will not even monitor changes if the
files are not writable.

This does *not* prevent any changes at runtime, but nothing will
be saved to disk.
This commit is contained in:
Christian Dywan 2009-02-12 23:52:14 +01:00
parent d810faf933
commit f1f27c9322

View file

@ -30,6 +30,12 @@
#include "sokoke.h" #include "sokoke.h"
#if HAVE_UNISTD_H
#include <unistd.h>
#define is_writable(_cfg_filename) !g_access (_cfg_filename, W_OK)
#else
#define is_writable(_cfg_filename) 1
#endif
#include <string.h> #include <string.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
@ -1911,6 +1917,7 @@ midori_load_session (gpointer data)
KatzeArray* _session = KATZE_ARRAY (data); KatzeArray* _session = KATZE_ARRAY (data);
MidoriBrowser* browser; MidoriBrowser* browser;
MidoriApp* app = katze_item_get_parent (KATZE_ITEM (_session)); MidoriApp* app = katze_item_get_parent (KATZE_ITEM (_session));
gchar* config_file;
KatzeArray* session; KatzeArray* session;
KatzeItem* item; KatzeItem* item;
guint n, i; guint n, i;
@ -1919,8 +1926,10 @@ midori_load_session (gpointer data)
midori_app_add_browser (app, browser); midori_app_add_browser (app, browser);
gtk_widget_show (GTK_WIDGET (browser)); gtk_widget_show (GTK_WIDGET (browser));
g_signal_connect_after (gtk_accel_map_get (), "changed", config_file = build_config_filename ("accels");
G_CALLBACK (accel_map_changed_cb), NULL); if (is_writable (config_file))
g_signal_connect_after (gtk_accel_map_get (), "changed",
G_CALLBACK (accel_map_changed_cb), NULL);
if (katze_array_is_empty (_session)) if (katze_array_is_empty (_session))
{ {
@ -1954,14 +1963,18 @@ midori_load_session (gpointer data)
midori_browser_activate_action (browser, "Location"); midori_browser_activate_action (browser, "Location");
g_object_unref (_session); g_object_unref (_session);
g_signal_connect_after (browser, "notify::uri", katze_assign (config_file, build_config_filename ("session.xbel"));
G_CALLBACK (midori_browser_session_cb), session); if (is_writable (config_file))
g_signal_connect_after (browser, "add-tab", {
G_CALLBACK (midori_browser_session_cb), session); g_signal_connect_after (browser, "notify::uri",
g_signal_connect_after (browser, "remove-tab", G_CALLBACK (midori_browser_session_cb), session);
G_CALLBACK (midori_browser_session_cb), session); g_signal_connect_after (browser, "add-tab",
g_object_weak_ref (G_OBJECT (session), G_CALLBACK (midori_browser_session_cb), session);
(GWeakNotify)(midori_browser_weak_notify_cb), browser); g_signal_connect_after (browser, "remove-tab",
G_CALLBACK (midori_browser_session_cb), session);
g_object_weak_ref (G_OBJECT (session),
(GWeakNotify)(midori_browser_weak_notify_cb), browser);
}
return FALSE; return FALSE;
} }
@ -2347,52 +2360,71 @@ main (int argc,
i++; i++;
} }
g_signal_connect_after (settings, "notify", katze_assign (config_file, build_config_filename ("config"));
G_CALLBACK (settings_notify_cb), NULL); if (is_writable (config_file))
g_signal_connect_after (search_engines, "add-item", g_signal_connect_after (settings, "notify",
G_CALLBACK (midori_search_engines_modify_cb), search_engines); G_CALLBACK (settings_notify_cb), NULL);
g_signal_connect_after (search_engines, "remove-item",
G_CALLBACK (midori_search_engines_modify_cb), search_engines); katze_assign (config_file, build_config_filename ("search"));
if (!katze_array_is_empty (search_engines)) if (is_writable (config_file))
{ {
guint n = katze_array_get_length (search_engines); g_signal_connect_after (search_engines, "add-item",
for (i = 0; i < n; i++) G_CALLBACK (midori_search_engines_modify_cb), search_engines);
g_signal_connect_after (search_engines, "remove-item",
G_CALLBACK (midori_search_engines_modify_cb), search_engines);
if (!katze_array_is_empty (search_engines))
{ {
item = katze_array_get_nth_item (search_engines, i); guint n = katze_array_get_length (search_engines);
g_signal_connect_after (item, "notify", for (i = 0; i < n; i++)
G_CALLBACK (midori_search_engines_modify_cb), search_engines);
}
}
g_signal_connect_after (bookmarks, "add-item",
G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
g_signal_connect_after (bookmarks, "remove-item",
G_CALLBACK (midori_bookmarks_remove_item_cb), NULL);
if (!katze_array_is_empty (bookmarks))
{
guint n = katze_array_get_length (bookmarks);
for (i = 0; i < n; i++)
{
item = katze_array_get_nth_item (bookmarks, i);
if (KATZE_IS_ARRAY (item))
{ {
g_signal_connect_after (item, "add-item", item = katze_array_get_nth_item (search_engines, i);
G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks); g_signal_connect_after (item, "notify",
g_signal_connect_after (item, "remove-item", G_CALLBACK (midori_search_engines_modify_cb), search_engines);
G_CALLBACK (midori_bookmarks_remove_item_cb), NULL);
} }
g_signal_connect_after (item, "notify",
G_CALLBACK (midori_bookmarks_notify_item_cb), bookmarks);
} }
} }
g_signal_connect_after (trash, "add-item", katze_assign (config_file, build_config_filename ("bookmarks.xbel"));
G_CALLBACK (midori_trash_add_item_cb), NULL); if (is_writable (config_file))
g_signal_connect_after (trash, "remove-item", {
G_CALLBACK (midori_trash_remove_item_cb), NULL); g_signal_connect_after (bookmarks, "add-item",
G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
g_signal_connect_after (bookmarks, "remove-item",
G_CALLBACK (midori_bookmarks_remove_item_cb), NULL);
if (!katze_array_is_empty (bookmarks))
{
guint n = katze_array_get_length (bookmarks);
for (i = 0; i < n; i++)
{
item = katze_array_get_nth_item (bookmarks, i);
if (KATZE_IS_ARRAY (item))
{
g_signal_connect_after (item, "add-item",
G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
g_signal_connect_after (item, "remove-item",
G_CALLBACK (midori_bookmarks_remove_item_cb), NULL);
}
g_signal_connect_after (item, "notify",
G_CALLBACK (midori_bookmarks_notify_item_cb), bookmarks);
}
}
}
katze_assign (config_file, build_config_filename ("tabtrash.xbel"));
if (is_writable (config_file))
{
g_signal_connect_after (trash, "add-item",
G_CALLBACK (midori_trash_add_item_cb), NULL);
g_signal_connect_after (trash, "remove-item",
G_CALLBACK (midori_trash_remove_item_cb), NULL);
}
#ifdef HAVE_SQLITE #ifdef HAVE_SQLITE
g_signal_connect_after (history, "add-item", katze_assign (config_file, build_config_filename ("history.db"));
G_CALLBACK (midori_history_add_item_cb), db); if (is_writable (config_file))
g_signal_connect_after (history, "clear", {
G_CALLBACK (midori_history_clear_cb), db); g_signal_connect_after (history, "add-item",
G_CALLBACK (midori_history_add_item_cb), db);
g_signal_connect_after (history, "clear",
G_CALLBACK (midori_history_clear_cb), db);
}
#endif #endif
/* We test for the presence of a dummy file which is created once /* We test for the presence of a dummy file which is created once