From: Christian Dywan Date: Mon, 26 Jan 2009 02:43:59 +0000 (+0100) Subject: Instead of adding multiple same history items, update the original item X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b2d8df6afd9d84c1cbe1c083f2d6476b8d25ac7;p=midori Instead of adding multiple same history items, update the original item --- diff --git a/midori/main.c b/midori/main.c index 4be09b13..d6c29e81 100644 --- a/midori/main.c +++ b/midori/main.c @@ -682,6 +682,30 @@ midori_history_clear_cb (KatzeArray* history, } } +static void +midori_history_notify_item_cb (KatzeItem* item, + GParamSpec* pspec, + sqlite3* db) +{ + gchar* sqlcmd; + gboolean success = TRUE; + GError* error = NULL; + + sqlcmd = sqlite3_mprintf ("UPDATE history SET title='%q' WHERE " + "uri='%q' AND date=%" G_GUINT64_FORMAT, + katze_item_get_name (item), + katze_item_get_uri (item), + katze_item_get_added (item)); + success = db_exec (db, sqlcmd, &error); + sqlite3_free (sqlcmd); + if (!success) + { + g_printerr (_("Failed to add history item: %s\n"), error->message); + g_error_free (error); + return ; + } +} + static void midori_history_add_item_cb (KatzeArray* array, KatzeItem* item, @@ -716,7 +740,8 @@ midori_history_add_item_cb (KatzeArray* array, } } sqlcmd = sqlite3_mprintf ("INSERT INTO history VALUES" - "('%q', '%q', %" G_GUINT64_FORMAT ", %" G_GUINT64_FORMAT ")", + "('%q', '%q', %" G_GUINT64_FORMAT "," + " %" G_GUINT64_FORMAT ")", katze_item_get_uri (item), katze_item_get_name (item), katze_item_get_added (item), @@ -729,6 +754,10 @@ midori_history_add_item_cb (KatzeArray* array, g_error_free (error); return ; } + + /* The title is set after the item is added */ + g_signal_connect_after (item, "notify::name", + G_CALLBACK (midori_history_notify_item_cb), db); } static int diff --git a/midori/midori-browser.c b/midori/midori-browser.c index f7d096b7..df41a9e4 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -437,7 +437,6 @@ midori_view_notify_title_cb (GtkWidget* view, const gchar* title; GtkAction* action; gchar* window_title; - KatzeItem* item; uri = midori_view_get_display_uri (MIDORI_VIEW (view)); title = midori_view_get_display_title (MIDORI_VIEW (view)); @@ -447,13 +446,23 @@ midori_view_notify_title_cb (GtkWidget* view, MIDORI_LOCATION_ACTION (action), title, uri); if (midori_view_get_load_status (MIDORI_VIEW (view)) == MIDORI_LOAD_COMMITTED) { + KatzeItem* item; + KatzeItem* proxy; + if (!browser->history) return; - item = katze_item_new (); - katze_item_set_uri (item, uri); - katze_item_set_name (item, title); - midori_browser_new_history_item (browser, item); + item = g_object_get_data (G_OBJECT (view), "history-item-added"); + proxy = midori_view_get_proxy_item (MIDORI_VIEW (view)); + if (item && katze_item_get_added (item) == katze_item_get_added (proxy)) + katze_item_set_name (item, katze_item_get_name (proxy)); + else + { + katze_object_assign (item, katze_item_copy (proxy)); + midori_browser_new_history_item (browser, g_object_ref (item)); + g_object_set_data_full (G_OBJECT (view), "history-item-added", + item, (GDestroyNotify)g_object_unref); + } } if (view == midori_browser_get_current_tab (browser)) diff --git a/midori/midori-view.c b/midori/midori-view.c index 5bfe9007..7d15e412 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -546,7 +546,10 @@ webkit_web_view_load_committed_cb (WebKitWebView* web_view, g_return_if_fail (uri != NULL); katze_assign (view->uri, g_strdup (uri)); if (view->item) + { katze_item_set_uri (view->item, uri); + katze_item_set_added (view->item, time (NULL)); + } g_object_notify (G_OBJECT (view), "uri"); g_object_set (view, "title", NULL, NULL);