From 9c48997a26d84a7063613b31baa16a15d33810dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Forysiuk?= Date: Mon, 14 Mar 2011 20:07:18 +0100 Subject: [PATCH] Use speeddial property to store GKeyFile with speeddial entries --- midori/main.c | 43 +++++++++++++++++++---------------------- midori/midori-app.c | 29 +++++++++++++++++++++++++++ midori/midori-browser.c | 26 +++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 23 deletions(-) diff --git a/midori/main.c b/midori/main.c index d2241926..7d168746 100644 --- a/midori/main.c +++ b/midori/main.c @@ -1467,19 +1467,28 @@ signal_handler (int signal_id) } #endif -#if 0 -static void -midori_speeddial_import_from_json (const gchar* json_file, - const gchar* speeddial_file) +static GKeyFile* +speeddial_new_from_file (const gchar* config, + GError** error) { + + GKeyFile* key_file = g_key_file_new (); + gchar* config_file = g_build_filename (config, "speeddial", NULL); guint i = 0; guint columns = 3; guint slot_count = 0; gchar* json_content; gchar** parts; - GKeyFile* key_file = g_key_file_new (); - g_file_get_contents (json_file, &json_content, NULL, NULL); + if (g_key_file_load_from_file (key_file, config_file, G_KEY_FILE_NONE, error)) + { + g_free (config_file); + return key_file; + } + + katze_assign (config_file, g_build_filename (config, "speeddial.json", NULL)); + g_file_get_contents (config_file, &json_content, NULL, NULL); + g_free (config_file); parts = g_strsplit (json_content ? json_content : "", ",", -1); while (parts && parts[i] != NULL) { @@ -1588,13 +1597,10 @@ midori_speeddial_import_from_json (const gchar* json_file, g_key_file_set_integer (key_file, "settings", "columns", columns); g_key_file_set_integer (key_file, "settings", "rows", slot_count / columns); - sokoke_key_file_save_to_file (key_file, speeddial_file, NULL); - g_strfreev (parts); g_free (json_content); - g_key_file_free (key_file); + return key_file; } -#endif static void midori_soup_session_block_uris_cb (SoupSession* session, @@ -1812,9 +1818,7 @@ main (int argc, MidoriWebSettings* settings; gchar* config_file; gchar* bookmarks_file; -#if 0 - gchar* speeddial_file; -#endif + GKeyFile* speeddial; gboolean bookmarks_exist; MidoriStartup load_on_startup; KatzeArray* search_engines; @@ -2231,16 +2235,7 @@ main (int argc, g_free (bookmarks_file); midori_startup_timer ("History read: \t%f"); - #if 0 - speeddial_file = g_build_filename (config, "speeddial", NULL); - if (g_access (speeddial_file, F_OK) != 0) - { - gchar* json_file = g_build_filename (config, "speeddial.json", NULL); - midori_speeddial_import_from_json (json_file, speeddial_file); - g_free (json_file); - } - g_free (speeddial_file); - #endif + speeddial = speeddial_new_from_file (config, &error); /* In case of errors */ if (error_messages->len) @@ -2359,6 +2354,7 @@ main (int argc, "trash", trash, "search-engines", search_engines, "history", history, + "speed-dial", speeddial, NULL); g_object_unref (history); g_object_unref (search_engines); @@ -2419,6 +2415,7 @@ main (int argc, } g_object_unref (settings); + g_key_file_free (speeddial); g_object_unref (app); g_free (config_file); return 0; diff --git a/midori/midori-app.c b/midori/midori-app.c index 4440de70..f88741e2 100644 --- a/midori/midori-app.c +++ b/midori/midori-app.c @@ -60,6 +60,7 @@ struct _MidoriApp KatzeArray* trash; KatzeArray* search_engines; KatzeArray* history; + GKeyFile* speeddial; KatzeArray* extensions; KatzeArray* browsers; @@ -97,6 +98,7 @@ enum PROP_TRASH, PROP_SEARCH_ENGINES, PROP_HISTORY, + PROP_SPEED_DIAL, PROP_EXTENSIONS, PROP_BROWSERS, PROP_BROWSER @@ -149,6 +151,7 @@ midori_browser_new_window_cb (MidoriBrowser* browser, "trash", app->trash, "search-engines", app->search_engines, "history", app->history, + "speed-dial", app->speeddial, NULL); else new_browser = midori_app_create_browser (app); @@ -365,6 +368,23 @@ midori_app_class_init (MidoriAppClass* class) KATZE_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + + /** + * MidoriApp:speed-dial: + * + * The speed dial configuration file. + * + * Since: 0.3.4 + */ + 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", + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + /** * MidoriApp:browsers: * @@ -717,6 +737,7 @@ midori_app_init (MidoriApp* app) app->trash = NULL; app->search_engines = NULL; app->history = NULL; + app->speeddial = NULL; app->extensions = NULL; app->browsers = katze_array_new (MIDORI_TYPE_BROWSER); @@ -743,6 +764,7 @@ midori_app_finalize (GObject* object) katze_object_assign (app->trash, NULL); katze_object_assign (app->search_engines, NULL); katze_object_assign (app->history, NULL); + app->speeddial = NULL; katze_object_assign (app->extensions, NULL); katze_object_assign (app->browsers, NULL); @@ -793,6 +815,9 @@ midori_app_set_property (GObject* object, case PROP_HISTORY: katze_object_assign (app->history, g_value_dup_object (value)); break; + case PROP_SPEED_DIAL: + app->speeddial = g_value_get_pointer (value); + break; case PROP_EXTENSIONS: katze_object_assign (app->extensions, g_value_dup_object (value)); break; @@ -830,6 +855,9 @@ midori_app_get_property (GObject* object, case PROP_HISTORY: g_value_set_object (value, app->history); break; + case PROP_SPEED_DIAL: + g_value_set_pointer (value, app->speeddial); + break; case PROP_EXTENSIONS: g_value_set_object (value, app->extensions); break; @@ -1122,6 +1150,7 @@ midori_app_create_browser (MidoriApp* app) "trash", app->trash, "search-engines", app->search_engines, "history", app->history, + "speed-dial", app->speeddial, NULL); } diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 10c12b12..d552281e 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -94,6 +94,7 @@ struct _MidoriBrowser KatzeArray* trash; KatzeArray* search_engines; KatzeArray* history; + GKeyFile* speeddial; gboolean show_tabs; gboolean show_navigationbar; @@ -128,6 +129,7 @@ enum PROP_TRASH, PROP_SEARCH_ENGINES, PROP_HISTORY, + PROP_SPEED_DIAL, PROP_SHOW_TABS, }; @@ -2085,6 +2087,22 @@ midori_browser_class_init (MidoriBrowserClass* class) KATZE_TYPE_ARRAY, flags)); + /** + * MidoriBrowser:speed-dial: + * + * The speed dial configuration file. + * + * Since: 0.3.4 + */ + 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", + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + /** * MidoriBrowser:show-tabs: * @@ -5651,6 +5669,7 @@ midori_browser_init (MidoriBrowser* browser) browser->bookmarks = NULL; browser->trash = NULL; browser->search_engines = NULL; + browser->speeddial = NULL; /* Setup the window metrics */ g_signal_connect (browser, "realize", @@ -6097,6 +6116,7 @@ midori_browser_finalize (GObject* object) katze_object_assign (browser->trash, NULL); katze_object_assign (browser->search_engines, NULL); katze_object_assign (browser->history, NULL); + browser->speeddial = NULL; katze_assign (browser->news_aggregator, NULL); @@ -6663,6 +6683,9 @@ midori_browser_set_property (GObject* object, case PROP_HISTORY: midori_browser_set_history (browser, g_value_get_object (value)); break; + case PROP_SPEED_DIAL: + browser->speeddial = g_value_get_pointer (value); + break; case PROP_SHOW_TABS: browser->show_tabs = g_value_get_boolean (value); if (browser->show_tabs) @@ -6738,6 +6761,9 @@ midori_browser_get_property (GObject* object, case PROP_HISTORY: g_value_set_object (value, browser->history); break; + case PROP_SPEED_DIAL: + g_value_set_pointer (value, browser->speeddial); + break; case PROP_SHOW_TABS: g_value_set_boolean (value, browser->show_tabs); break; -- 2.39.5