KatzeArray* trash;
KatzeArray* search_engines;
KatzeArray* history;
- GKeyFile* speeddial;
+ MidoriSpeedDial* dial;
gboolean show_tabs;
gboolean show_navigationbar;
{
GdkPixbuf* img;
GtkWidget* view = midori_browser_get_current_tab (browser);
- gchar* slot_id = midori_speed_dial_get_next_free_slot_fk (browser->speeddial);
- gchar* uri;
- gchar* title;
-
- if (slot_id == NULL)
- return;
- uri = g_strdup (midori_view_get_display_uri (MIDORI_VIEW (view)));
- title = g_strdup (midori_view_get_display_title (MIDORI_VIEW (view)));
if ((img = midori_view_get_snapshot (MIDORI_VIEW (view), 240, 160)))
{
+ gchar* slot_id = midori_speed_dial_get_next_free_slot (browser->dial);
gchar* dial_id = g_strdup_printf ("Dial %s", slot_id + 1);
- midori_speed_dial_add_fk (dial_id, uri, title, img, browser->speeddial);
+ midori_speed_dial_add (browser->dial, dial_id,
+ midori_view_get_display_uri (MIDORI_VIEW (view)),
+ midori_view_get_display_title (MIDORI_VIEW (view)), img);
g_free (dial_id);
- midori_view_save_speed_dial_config (MIDORI_VIEW (view), browser->speeddial);
+ midori_view_save_speed_dial_config (MIDORI_VIEW (view));
g_object_unref (img);
+ g_free (slot_id);
}
- g_free (uri);
- g_free (title);
- g_free (slot_id);
}
* The speed dial configuration file.
*
* Since: 0.3.4
+ * Since 0.4.7 this is a Midori.SpeedDial instance.
*/
g_object_class_install_property (gobject_class,
PROP_SPEED_DIAL,
g_param_spec_pointer (
"speed-dial",
"Speeddial",
- "Pointer to key-value object with speed dial items",
+ "Speed dial",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
/**
* MidoriBrowser:show-tabs:
*
browser->bookmarks = NULL;
browser->trash = NULL;
browser->search_engines = NULL;
- browser->speeddial = NULL;
+ browser->dial = NULL;
/* Setup the window metrics */
g_signal_connect (browser, "realize",
katze_object_assign (browser->trash, NULL);
katze_object_assign (browser->search_engines, NULL);
katze_object_assign (browser->history, NULL);
- browser->speeddial = NULL;
+ browser->dial = NULL;
katze_assign (browser->news_aggregator, NULL);
midori_browser_set_history (browser, g_value_get_object (value));
break;
case PROP_SPEED_DIAL:
- browser->speeddial = g_value_get_pointer (value);
+ browser->dial = g_value_get_pointer (value);
break;
case PROP_SHOW_TABS:
browser->show_tabs = g_value_get_boolean (value);
g_value_set_object (value, browser->history);
break;
case PROP_SPEED_DIAL:
- g_value_set_pointer (value, browser->speeddial);
+ g_value_set_pointer (value, browser->dial);
break;
case PROP_SHOW_TABS:
g_value_set_boolean (value, browser->show_tabs);
namespace Midori {
public class SpeedDial : GLib.Object {
+ string filename;
public GLib.KeyFile keyfile;
+ string? html = null;
- public SpeedDial (string filename, string? fallback = null) {
+ public SpeedDial (string new_filename, string? fallback = null) {
+ filename = new_filename;
keyfile = new GLib.KeyFile ();
try {
keyfile.load_from_file (filename, GLib.KeyFileFlags.NONE);
}
}
- public static string get_next_free_slot_fk (KeyFile keyfile) {
+ public string get_next_free_slot () {
uint slot_count = 0;
foreach (string tile in keyfile.get_groups ()) {
try {
return "s%u".printf (slot_count + 1);
}
- public static void add_fk (string id, string uri, string title, Gdk.Pixbuf img, KeyFile keyfile) {
+ public void add (string id, string uri, string title, Gdk.Pixbuf img) {
keyfile.set_string (id, "uri", uri);
keyfile.set_string (id, "title", title);
}
}
- public static string? get_html_fk (KeyFile? keyfile,
- bool close_buttons_left, GLib.Object view, bool load_missing) throws Error {
+ public unowned string get_html (bool close_buttons_left, GLib.Object view) throws Error {
+ bool load_missing = true;
+
+ if (html != null)
+ return html;
string? head = null;
string filename = Paths.get_res_filename ("speeddial-head.html");
""",
slot_count + 1, slot_count + 1, _("Click to add a shortcut"));
markup.append_printf ("</div>\n</body>\n</html>\n");
- return markup.str;
+ html = markup.str;
+ }
+ else
+ html = "";
+
+ return html;
+ }
+
+ public void save_message (string message) throws Error {
+ string msg = message.substring (16, -1);
+ string[] parts = msg.split (" ", 4);
+ string action = parts[0];
+
+ if (action == "add" || action == "rename"
+ || action == "delete" || action == "swap") {
+ uint slot_id = parts[1].to_int () + 1;
+ string dial_id = "Dial %u".printf (slot_id);
+
+ if (action == "delete") {
+ string uri = keyfile.get_string (dial_id, "uri");
+ string file_path = Sokoke.build_thumbnail_path (uri);
+ keyfile.remove_group (dial_id);
+ FileUtils.unlink (file_path);
+ }
+ else if (action == "add") {
+ keyfile.set_string (dial_id, "uri", parts[2]);
+ /* FIXME midori_view_speed_dial_get_thumb (view, dial_id, parts[2]); */
+ }
+ else if (action == "rename") {
+ uint offset = parts[0].length + parts[1].length + 2;
+ string title = msg.substring (offset, -1);
+ keyfile.set_string (dial_id, "title", title);
+ }
+ else if (action == "swap") {
+ uint slot2_id = parts[2].to_int () + 1;
+ string dial2_id = "Dial %u".printf (slot2_id);
+
+ string uri = keyfile.get_string (dial_id, "uri");
+ string title = keyfile.get_string (dial_id, "title");
+ string uri2 = keyfile.get_string (dial2_id, "uri");
+ string title2 = keyfile.get_string (dial2_id, "title");
+
+ keyfile.set_string (dial_id, "uri", uri2);
+ keyfile.set_string (dial2_id, "uri", uri);
+ keyfile.set_string (dial_id, "title", title2);
+ keyfile.set_string (dial2_id, "title", title);
+ }
}
- return null;
+ }
+
+ public void save () throws Error {
+ html = null;
+
+ FileUtils.set_contents (filename, keyfile.to_data ());
}
}
}
static guint signals[LAST_SIGNAL];
-static gchar* speeddial_markup = NULL;
static GtkWidget* thumb_view = NULL;
static GList* thumb_queue = NULL;
GParamSpec* pspec,
MidoriView* view);
-static void
-midori_view_speed_dial_save (MidoriView* view,
- const gchar* message);
-
static void
midori_view_class_init (MidoriViewClass* class)
{
return FALSE;
if (!strncmp (message, "speed_dial-save", 13))
- midori_view_speed_dial_save (view, message);
+ {
+ MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
+ MidoriSpeedDial* dial = katze_object_get_object (browser, "speed-dial");
+
+ midori_speed_dial_save_message (dial, message, NULL);
+ midori_view_save_speed_dial_config (view);
+ }
else
g_signal_emit (view, signals[CONSOLE_MESSAGE], 0, message, line, source_id);
return TRUE;
valid_about_uris[i], valid_about_uris[i]);
}
-static gchar*
-prepare_speed_dial_html (MidoriView* view,
- gboolean load_missing)
-{
- MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
- GKeyFile* key_file = katze_object_get_object (browser, "speed-dial");
- return midori_speed_dial_get_html_fk (key_file,
- katze_object_get_boolean (view->settings, "close-buttons-left"),
- G_OBJECT (view), load_missing, NULL);
-}
-
/**
* midori_view_set_uri:
{
if (!uri || !strcmp (uri, "") || !strcmp (uri, "about:blank"))
{
+ MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
+ MidoriSpeedDial* dial = katze_object_get_object (browser, "speed-dial");
+ const gchar* html;
#ifdef G_ENABLE_DEBUG
GTimer* timer = NULL;
katze_item_set_meta_string (view->item, "mime-type", NULL);
katze_item_set_meta_integer (view->item, "delay", -1);
- if (speeddial_markup == NULL)
- speeddial_markup = prepare_speed_dial_html (view, TRUE);
-
- midori_view_load_alternate_string (view,
- speeddial_markup ? speeddial_markup : "", "about:blank", NULL);
+ html = midori_speed_dial_get_html (dial,
+ katze_object_get_boolean (view->settings, "close-buttons-left"),
+ G_OBJECT (view), NULL);
+ midori_view_load_alternate_string (view, html, "about:blank", NULL);
#ifdef G_ENABLE_DEBUG
if (midori_debug ("startup"))
#if HAVE_OFFSCREEN
GdkPixbuf* pixbuf_scaled;
#endif
- gchar* file_path;
- gchar* thumb_dir;
gchar* spec;
gchar* url;
gchar* dial_id;
MidoriBrowser* browser;
- GKeyFile* key_file;
+ MidoriSpeedDial* dial;
const gchar* title;
if (webkit_web_view_get_load_status (thumb_view_) != WEBKIT_LOAD_FINISHED)
return;
+ browser = midori_browser_get_for_widget (GTK_WIDGET (view));
+ dial = katze_object_get_object (browser, "speed-dial");
+
spec = g_object_get_data (G_OBJECT (thumb_view), "spec");
url = strstr (spec, "|") + 1;
dial_id = g_strndup (spec, url - spec - 1);
gtk_widget_realize (thumb_view);
img = midori_view_web_view_get_snapshot (thumb_view, 240, 160);
#endif
- file_path = sokoke_build_thumbnail_path (url);
- thumb_dir = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_cache_dir (), "thumbnails", NULL);
-
- if (!g_file_test (thumb_dir, G_FILE_TEST_EXISTS))
- katze_mkdir_with_parents (thumb_dir, 0700);
- gdk_pixbuf_save (img, file_path, "png", NULL, "compression", "7", NULL);
-
- g_object_unref (img);
-
- g_free (file_path);
- g_free (thumb_dir);
-
- browser = midori_browser_get_for_widget (GTK_WIDGET (view));
- g_object_get (browser, "speed-dial", &key_file, NULL);
title = webkit_web_view_get_title (WEBKIT_WEB_VIEW (thumb_view));
- g_key_file_set_string (key_file, dial_id, "title", title ? title : url);
- midori_view_save_speed_dial_config (view, key_file);
+ midori_speed_dial_add (dial, dial_id, url, title ? title : url, img);
+ g_object_unref (img);
+ midori_view_save_speed_dial_config (view);
thumb_queue = g_list_remove (thumb_queue, spec);
if (thumb_queue != NULL)
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (thumb_view), url);
}
-/**
- * midori_view_speed_dial_save
- * @view: a #MidoriView
- * @message: message from JavaScript
- *
- * Save speed_dial settings
- *
- **/
-static void
-midori_view_speed_dial_save (MidoriView* view,
- const gchar* message)
-{
- gchar* action;
- GKeyFile* key_file;
- MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
- gchar* msg = g_strdup (message + 16);
- gchar** parts = g_strsplit (msg, " ", 4);
-
- g_object_get (browser, "speed-dial", &key_file, NULL);
- action = parts[0];
-
- if (g_str_equal (action, "add") || g_str_equal (action, "rename")
- || g_str_equal (action, "delete") || g_str_equal (action, "swap"))
- {
- gchar* tmp = g_strdup (parts[1] + 1);
- guint slot_id = atoi (tmp);
- gchar* dial_id = g_strdup_printf ("Dial %d", slot_id);
- g_free (tmp);
-
-
- if (g_str_equal (action, "delete"))
- {
- gchar* uri = g_key_file_get_string (key_file, dial_id, "uri", NULL);
- gchar* file_path = sokoke_build_thumbnail_path (uri);
-
- g_key_file_remove_group (key_file, dial_id, NULL);
- g_unlink (file_path);
-
- g_free (uri);
- g_free (file_path);
- }
- else if (g_str_equal (action, "add"))
- {
- g_key_file_set_string (key_file, dial_id, "uri", parts[2]);
- midori_view_speed_dial_get_thumb (view, dial_id, parts[2]);
- }
- else if (g_str_equal (action, "rename"))
- {
- guint offset = strlen (parts[0]) + strlen (parts[1]) + 2;
- gchar* title = g_strdup (msg + offset);
- g_key_file_set_string (key_file, dial_id, "title", title);
- g_free (title);
- }
- else if (g_str_equal (action, "swap"))
- {
- gchar* tmp1 = g_strdup (parts[2] + 1);
- guint slot2_id = atoi (tmp1);
- gchar* dial2_id = g_strdup_printf ("Dial %d", slot2_id);
- gchar* uri, *uri2, *title, *title2;
- g_free (tmp1);
-
- uri = g_key_file_get_string (key_file, dial_id, "uri", NULL);
- title = g_key_file_get_string (key_file, dial_id, "title", NULL);
- uri2 = g_key_file_get_string (key_file, dial2_id, "uri", NULL);
- title2 = g_key_file_get_string (key_file, dial2_id, "title", NULL);
-
- g_key_file_set_string (key_file, dial_id, "uri", uri2);
- g_key_file_set_string (key_file, dial2_id, "uri", uri);
- g_key_file_set_string (key_file, dial_id, "title", title2);
- g_key_file_set_string (key_file, dial2_id, "title", title);
-
- g_free (uri);
- g_free (uri2);
- g_free (title);
- g_free (title2);
- g_free (dial2_id);
- }
-
- g_free (dial_id);
- }
-
- midori_view_save_speed_dial_config (view, key_file);
-
- g_free (msg);
- g_free (action);
-}
-
void
-midori_view_save_speed_dial_config (MidoriView* view,
- GKeyFile* key_file)
+midori_view_save_speed_dial_config (MidoriView* view)
{
- gchar* config_file;
guint i = 0;
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
+ MidoriSpeedDial* dial = katze_object_get_object (browser, "speed-dial");
GtkWidget* tab;
- config_file = g_build_filename (midori_paths_get_config_dir (), "speeddial", NULL);
- sokoke_key_file_save_to_file (key_file, config_file, NULL);
- g_free (config_file);
-
- katze_assign (speeddial_markup, prepare_speed_dial_html (view, FALSE));
-
+ midori_speed_dial_save (dial, NULL);
while ((tab = midori_browser_get_nth_tab (browser, i++)))
if (midori_view_is_blank (MIDORI_VIEW (tab)))
midori_view_reload (MIDORI_VIEW (tab), FALSE);
-
}