Store visited pages in the history again

This commit is contained in:
Alexander Butenko 2010-02-03 22:12:19 +01:00 committed by Christian Dywan
parent c550d36649
commit 42a29682e6

View file

@ -50,6 +50,10 @@
#include <X11/Xatom.h> #include <X11/Xatom.h>
#endif #endif
#if HAVE_SQLITE
#include <sqlite3.h>
#endif
struct _MidoriBrowser struct _MidoriBrowser
{ {
#if HAVE_HILDON #if HAVE_HILDON
@ -455,6 +459,31 @@ _midori_browser_update_progress (MidoriBrowser* browser,
} }
} }
static void
midori_browser_update_history_title (MidoriBrowser* browser,
KatzeItem* item)
{
#if HAVE_SQLITE
sqlite3* db;
gchar* sqlcmd;
char* errmsg = NULL;
db = g_object_get_data (G_OBJECT (browser->history), "db");
sqlcmd = sqlite3_mprintf ("UPDATE history SET title='%q' WHERE"
" uri = '%q' and date=%d",
katze_item_get_name (item),
katze_item_get_uri (item),
katze_item_get_added (item));
if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
{
g_printerr (_("Failed to insert new history item: %s\n"), errmsg);
sqlite3_free (errmsg);
}
sqlite3_free (sqlcmd);
#endif
}
static void static void
_midori_browser_activate_action (MidoriBrowser* browser, _midori_browser_activate_action (MidoriBrowser* browser,
const gchar* name) const gchar* name)
@ -582,7 +611,10 @@ midori_view_notify_title_cb (GtkWidget* widget,
item = g_object_get_data (G_OBJECT (view), "history-item-added"); item = g_object_get_data (G_OBJECT (view), "history-item-added");
proxy = midori_view_get_proxy_item (view); proxy = midori_view_get_proxy_item (view);
if (item && katze_item_get_added (item) == katze_item_get_added (proxy)) if (item && katze_item_get_added (item) == katze_item_get_added (proxy))
{
katze_item_set_name (item, katze_item_get_name (proxy)); katze_item_set_name (item, katze_item_get_name (proxy));
midori_browser_update_history_title (browser, item);
}
else else
{ {
katze_object_assign (item, katze_item_copy (proxy)); katze_object_assign (item, katze_item_copy (proxy));
@ -5561,42 +5593,34 @@ static void
midori_browser_new_history_item (MidoriBrowser* browser, midori_browser_new_history_item (MidoriBrowser* browser,
KatzeItem** item) KatzeItem** item)
{ {
KatzeArray* parent;
gint i;
gboolean found;
time_t now; time_t now;
gint64 day; gint64 day;
gchar token[50]; #if HAVE_SQLITE
sqlite3* db;
gchar* sqlcmd;
char* errmsg = NULL;
#endif
now = time (NULL); now = time (NULL);
katze_item_set_added (*item, now); katze_item_set_added (*item, now);
day = sokoke_time_t_to_julian (&now); day = sokoke_time_t_to_julian (&now);
found = FALSE; #if HAVE_SQLITE
i = 0; db = g_object_get_data (G_OBJECT (browser->history), "db");
while ((parent = katze_array_get_nth_item (browser->history, i++))) sqlcmd = sqlite3_mprintf ("INSERT INTO history (uri, title, date, day) VALUES "
{ "('%q', '%q', %d, %d)",
gint64 pday = katze_item_get_added (KATZE_ITEM (parent)); katze_item_get_uri (*item),
if (day - pday == 0) katze_item_get_name (*item),
{ katze_item_get_added (*item),
KatzeItem* _item; day);
found = TRUE; if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
if ((_item = katze_array_find_uri (parent, katze_item_get_uri (*item))))
*item = g_object_ref (_item);
else
katze_array_add_item (parent, *item);
}
}
if (!found)
{ {
strftime (token, sizeof (token), "%x", localtime (&now)); g_printerr (_("Failed to insert new history item: %s\n"), errmsg);
parent = katze_array_new (KATZE_TYPE_ARRAY); sqlite3_free (errmsg);
katze_item_set_added (KATZE_ITEM (parent), day);
katze_item_set_name (KATZE_ITEM (parent), token);
katze_array_add_item (browser->history, parent);
katze_array_add_item (parent, *item);
} }
sqlite3_free (sqlcmd);
#endif
} }
static void static void