g_object_class_install_property (gobject_class,
PROP_ADDED,
- g_param_spec_string (
+ g_param_spec_int64 (
"added",
"Added",
"When the item was added",
- NULL,
+ G_MININT64,
+ G_MAXINT64,
+ 0,
flags));
g_object_class_install_property (gobject_class,
g_free (item->uri);
g_free (item->icon);
g_free (item->token);
- g_free (item->added);
G_OBJECT_CLASS (katze_item_parent_class)->finalize (object);
}
katze_assign (item->token, g_value_dup_string (value));
break;
case PROP_ADDED:
- katze_assign (item->added, g_value_dup_string (value));
+ item->added = g_value_get_int64 (value);
break;
case PROP_VISITS:
item->visits = g_value_get_int (value);
g_value_set_string (value, item->token);
break;
case PROP_ADDED:
- g_value_set_string (value, item->added);
+ g_value_set_int64 (value, item->added);
break;
case PROP_VISITS:
g_value_set_int (value, item->visits);
*
* Return value: a timestamp
**/
-const gchar*
+gint64
katze_item_get_added (KatzeItem* item)
{
- g_return_val_if_fail (KATZE_IS_ITEM (item), NULL);
+ g_return_val_if_fail (KATZE_IS_ITEM (item), 0);
return item->added;
}
* Sets when @item was added.
**/
void
-katze_item_set_added (KatzeItem* item,
- const gchar* added)
+katze_item_set_added (KatzeItem* item,
+ gint64 added)
{
g_return_if_fail (KATZE_IS_ITEM (item));
- katze_assign (item->added, g_strdup (added));
+ item->added = added;
g_object_notify (G_OBJECT (item), "added");
}
g_return_val_if_fail (argc == 1, 1);
- katze_item_set_added (item, argv[0]);
+ katze_item_set_added (item, g_ascii_strtoull (argv[0], NULL, 10));
return 0;
}
g_return_if_fail (KATZE_IS_ITEM (item));
sqlcmd = g_strdup_printf ("DELETE FROM history WHERE uri = '%s' AND"
- " title = '%s' AND date = '%s' AND visits = %d",
+ " title = '%s' AND date = %ld AND visits = %d",
katze_item_get_uri (item),
katze_item_get_name (item),
katze_item_get_added (item),
/* New item, set added to the current date/ time */
if (!katze_item_get_added (item))
{
- if (!db_exec_callback (db, "SELECT datetime('now')",
+ if (!db_exec_callback (db, "SELECT date('now')",
gettimestr, item, &error))
{
g_printerr (_("Failed to add history item. %s\n"), error->message);
}
}
sqlcmd = g_strdup_printf ("INSERT INTO history VALUES"
- "('%s', '%s', '%s', %d)",
+ "('%s', '%s', %" G_GUINT64_FORMAT ", %d)",
katze_item_get_uri (item),
katze_item_get_name (item),
katze_item_get_added (item),
KatzeItem* item;
KatzeArray* parent = NULL;
KatzeArray* array = KATZE_ARRAY (data);
- gchar* newdate;
+ gint64 date;
+ time_t newdate;
gint i, j, n;
gint ncols = 4;
- gsize len;
g_return_val_if_fail (KATZE_IS_ARRAY (array), 1);
item = katze_item_new ();
katze_item_set_uri (item, argv[i]);
katze_item_set_name (item, argv[i + 1]);
- katze_item_set_added (item, argv[i + 2]);
+ date = g_ascii_strtoull (argv[i + 2], NULL, 10);
+ katze_item_set_added (item, date);
katze_item_set_visits (item, atoi (argv[i + 3]));
- len = (g_strrstr (argv[i + 2], " ") - argv[i + 2]);
- newdate = g_strndup (argv[i + 2], len);
-
n = katze_array_get_length (array);
for (j = 0; j < n; j++)
{
parent = katze_array_get_nth_item (array, j);
- if (newdate && g_ascii_strcasecmp
- (katze_item_get_added (KATZE_ITEM (parent)), newdate) == 0)
+ newdate = katze_item_get_added (KATZE_ITEM (parent));
+ if (sokoke_same_day (&date, &newdate))
break;
}
if (j == n)
{
parent = katze_array_new (KATZE_TYPE_ARRAY);
- katze_item_set_added (KATZE_ITEM (parent), newdate);
+ katze_item_set_added (KATZE_ITEM (parent), date);
katze_array_add_item (array, parent);
}
- g_free (newdate);
-
katze_array_add_item (parent, item);
}
}
if (!db_exec (db,
"CREATE TABLE IF NOT EXISTS "
- "history(uri text, title text, date text, visits integer)",
+ "history(uri text, title text, date integer, visits integer)",
error))
return NULL;
if (!db_exec_callback (db,
"SELECT uri, title, date, visits FROM history "
- "ORDER BY strftime('%s', date) ASC",
+ "ORDER BY date ASC",
midori_history_add_items,
array,
error))
}
return db;
}
+
+static void
+midori_history_terminate (sqlite3* db,
+ gint max_history_age)
+{
+ gchar* sqlcmd;
+ gboolean success = TRUE;
+ GError* error = NULL;
+
+ sqlcmd = g_strdup_printf (
+ "DELETE FROM history WHERE "
+ "(julianday(date('now')) - julianday(date(date,'unixepoch')))"
+ " >= %d", max_history_age);
+ db_exec (db, sqlcmd, &error);
+ if (!success)
+ {
+ g_printerr (_("Failed to remove old history items. %s\n"), error->message);
+ g_error_free (error);
+ return ;
+ }
+ g_free (sqlcmd);
+ db_close (db);
+}
#endif
static gchar*
gchar* uri_ready;
#ifdef HAVE_SQLITE
sqlite3* db;
+ gint max_history_age;
#endif
#if ENABLE_NLS
g_mkdir_with_parents (config_path, 0755);
g_object_unref (history);
#ifdef HAVE_SQLITE
- db_close (db);
+ g_object_get (settings, "maximum-history-age", &max_history_age, NULL);
+ midori_history_terminate (db, max_history_age);
#endif
config_file = g_build_filename (config_path, "search", NULL);
error = NULL;
GtkWidget* treeview)
{
KatzeItem* item;
+ time_t date;
+ char sdate[50];
gtk_tree_model_get (model, iter, 0, &item, -1);
}
if (KATZE_IS_ARRAY (item))
- g_object_set (renderer, "text", katze_item_get_added (item), NULL);
+ {
+ date = (time_t)katze_item_get_added (item);
+ strftime (sdate, sizeof (sdate), "%Y-%m-%d", localtime (&date));
+ g_object_set (renderer, "text", sdate, NULL);
+ }
else
g_object_set (renderer, "text", katze_item_get_name (item), NULL);
gint i;
gboolean found;
time_t now;
- gchar newdate [70];
- gchar *today;
- gsize len;
+ gint64 date;
if (!sokoke_object_get_boolean (browser->settings, "remember-last-visited-pages"))
return;
treemodel = gtk_tree_view_get_model (treeview);
now = time (NULL);
- strftime (newdate, sizeof (newdate), "%Y-%m-%d %H:%M:%S", localtime (&now));
- katze_item_set_added (item, newdate);
-
- len = (g_strrstr (newdate, " ") - newdate);
- today = g_strndup (newdate, len);
+ katze_item_set_added (item, now);
found = FALSE;
i = 0;
while (gtk_tree_model_iter_nth_child (treemodel, &iter, NULL, i++))
{
gtk_tree_model_get (treemodel, &iter, 0, &parent, -1);
- if (g_ascii_strcasecmp (today,
- katze_item_get_added (KATZE_ITEM (parent))) == 0)
+ date = katze_item_get_added (KATZE_ITEM (parent));
+ if (sokoke_same_day (&now, &date))
{
found = TRUE;
break;
if (!found)
{
parent = katze_array_new (KATZE_TYPE_ARRAY);
- katze_item_set_added (KATZE_ITEM (parent), today);
+ katze_item_set_added (KATZE_ITEM (parent), now);
katze_array_add_item (browser->history, parent);
katze_array_add_item (parent, item);
_tree_store_insert_history_item (GTK_TREE_STORE (treemodel), NULL,
katze_array_add_item (parent, item);
g_object_unref (parent);
}
- g_free (today);
}