Store history dates in 'token' to avoid locatime() and revamp deleting
Loading history items used to involve frequent calls to localtime() and g_memdup(). We avoid this by storing the date strings in parent items now, which can even be used to display items in the treeview. Deleting of treeview items was also reworked so it should work from menu items and the panel.
This commit is contained in:
parent
d55b6ddd00
commit
6753a9ade3
5 changed files with 82 additions and 100 deletions
|
@ -597,7 +597,7 @@ db_exec_callback (sqlite3* db,
|
|||
{
|
||||
*error = g_error_new (MIDORI_HISTORY_ERROR,
|
||||
MIDORI_HISTORY_ERROR_EXEC_SQL,
|
||||
_("Failed to open database: %s\n"),
|
||||
_("Failed to execute SQL statement: %s\n"),
|
||||
errmsg);
|
||||
}
|
||||
sqlite3_free (errmsg);
|
||||
|
@ -642,9 +642,9 @@ midori_history_remove_item_cb (KatzeArray* history,
|
|||
|
||||
g_return_if_fail (KATZE_IS_ITEM (item));
|
||||
|
||||
sqlcmd = g_strdup_printf (
|
||||
"DELETE FROM history WHERE uri = '%s' AND"
|
||||
" title = '%s' AND date = %" G_GINT64_FORMAT,
|
||||
sqlcmd = sqlite3_mprintf (
|
||||
"DELETE FROM history WHERE uri = '%q' AND"
|
||||
" title = '%q' AND date = %" G_GINT64_FORMAT,
|
||||
katze_item_get_uri (item),
|
||||
katze_item_get_name (item),
|
||||
katze_item_get_added (item));
|
||||
|
@ -655,7 +655,7 @@ midori_history_remove_item_cb (KatzeArray* history,
|
|||
g_error_free (error);
|
||||
return ;
|
||||
}
|
||||
g_free (sqlcmd);
|
||||
sqlite3_free (sqlcmd);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -738,9 +738,9 @@ midori_history_add_items (void* data,
|
|||
KatzeArray* parent = NULL;
|
||||
KatzeArray* array = KATZE_ARRAY (data);
|
||||
gint64 date;
|
||||
time_t newdate;
|
||||
gint i, j, n;
|
||||
gint i;
|
||||
gint ncols = 3;
|
||||
gchar token[50];
|
||||
|
||||
g_return_val_if_fail (KATZE_IS_ARRAY (array), 1);
|
||||
|
||||
|
@ -761,18 +761,15 @@ midori_history_add_items (void* data,
|
|||
date = g_ascii_strtoull (argv[i + 2], NULL, 10);
|
||||
katze_item_set_added (item, date);
|
||||
|
||||
n = katze_array_get_length (array);
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
parent = katze_array_get_nth_item (array, j);
|
||||
newdate = katze_item_get_added (KATZE_ITEM (parent));
|
||||
if (sokoke_same_day ((time_t *)&date, (time_t *)&newdate))
|
||||
break;
|
||||
}
|
||||
if (j == n)
|
||||
strftime (token, sizeof (token), "%Y-%m-%d",
|
||||
localtime ((time_t *)&date));
|
||||
parent = katze_array_find_token (array, token);
|
||||
|
||||
if (!parent)
|
||||
{
|
||||
parent = katze_array_new (KATZE_TYPE_ARRAY);
|
||||
katze_item_set_added (KATZE_ITEM (parent), date);
|
||||
katze_item_set_token (KATZE_ITEM (parent), token);
|
||||
katze_array_add_item (array, parent);
|
||||
}
|
||||
katze_array_add_item (parent, item);
|
||||
|
|
|
@ -2332,6 +2332,62 @@ midori_browser_bookmark_edit_activate_cb (GtkWidget* menuitem,
|
|||
midori_browser_edit_bookmark_dialog_new (browser, item, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
midori_browser_model_remove_item (GtkTreeModel* model,
|
||||
KatzeItem* item,
|
||||
GtkTreeIter* iter)
|
||||
{
|
||||
GtkTreeIter child_iter;
|
||||
KatzeItem* child;
|
||||
KatzeArray* parent;
|
||||
gint i, n;
|
||||
|
||||
if (KATZE_IS_ARRAY (item))
|
||||
{
|
||||
n = katze_array_get_length (KATZE_ARRAY (item));
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
child = katze_array_get_nth_item (KATZE_ARRAY (item), 0);
|
||||
katze_array_remove_item (KATZE_ARRAY (item), child);
|
||||
}
|
||||
while (gtk_tree_model_iter_nth_child (model, &child_iter, iter, 0))
|
||||
gtk_tree_store_remove (GTK_TREE_STORE (model), &child_iter);
|
||||
}
|
||||
|
||||
gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
|
||||
g_object_unref (item);
|
||||
|
||||
parent = katze_item_get_parent (item);
|
||||
katze_array_remove_item (parent, item);
|
||||
}
|
||||
|
||||
static void
|
||||
midori_browser_history_delete (MidoriBrowser* browser)
|
||||
{
|
||||
GtkTreeView* treeview;
|
||||
GtkTreeModel* model;
|
||||
GtkTreeIter iter;
|
||||
KatzeItem* item;
|
||||
GtkAction* location_action;
|
||||
|
||||
treeview = GTK_TREE_VIEW (browser->panel_history);
|
||||
if (sokoke_tree_view_get_selected_iter (treeview, &model, &iter))
|
||||
{
|
||||
location_action = _action_by_name (browser, "Location");
|
||||
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
||||
midori_browser_model_remove_item (model, item, &iter);
|
||||
midori_location_action_delete_item_from_uri (
|
||||
MIDORI_LOCATION_ACTION (location_action), katze_item_get_uri (item));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
midori_browser_history_delete_activate_cb (GtkWidget* menuitem,
|
||||
MidoriBrowser* browser)
|
||||
{
|
||||
midori_browser_history_delete (browser);
|
||||
}
|
||||
|
||||
static void
|
||||
midori_browser_bookmark_delete_activate_cb (GtkWidget* menuitem,
|
||||
MidoriBrowser* browser)
|
||||
|
@ -2377,10 +2433,15 @@ midori_browser_bookmark_popup (GtkWidget* widget,
|
|||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
||||
gtk_widget_show (menuitem);
|
||||
if (!history_item)
|
||||
{
|
||||
midori_browser_bookmark_popup_item (menu, GTK_STOCK_EDIT, NULL,
|
||||
item, midori_browser_bookmark_edit_activate_cb, browser);
|
||||
midori_browser_bookmark_popup_item (menu, GTK_STOCK_DELETE, NULL,
|
||||
item, midori_browser_bookmark_delete_activate_cb, browser);
|
||||
}
|
||||
else
|
||||
midori_browser_bookmark_popup_item (menu, GTK_STOCK_DELETE, NULL,
|
||||
item, midori_browser_history_delete_activate_cb, browser);
|
||||
|
||||
sokoke_widget_popup (widget, GTK_MENU (menu),
|
||||
event, SOKOKE_MENU_POSITION_CURSOR);
|
||||
|
@ -2525,35 +2586,6 @@ midori_panel_history_button_release_event_cb (GtkWidget* widget,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
midori_browser_model_remove_item (GtkTreeModel* model,
|
||||
KatzeItem* item,
|
||||
GtkTreeIter* iter)
|
||||
{
|
||||
GtkTreeIter child_iter;
|
||||
KatzeItem* child;
|
||||
KatzeArray* parent;
|
||||
gint i, n;
|
||||
|
||||
if (KATZE_IS_ARRAY (item))
|
||||
{
|
||||
n = katze_array_get_length (KATZE_ARRAY (item));
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
child = katze_array_get_nth_item (KATZE_ARRAY (item), 0);
|
||||
katze_array_remove_item (KATZE_ARRAY (item), child);
|
||||
}
|
||||
while (gtk_tree_model_iter_nth_child (model, &child_iter, iter, 0))
|
||||
gtk_tree_store_remove (GTK_TREE_STORE (model), &child_iter);
|
||||
}
|
||||
|
||||
gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
|
||||
g_object_unref (item);
|
||||
|
||||
parent = katze_item_get_parent (item);
|
||||
katze_array_remove_item (parent, item);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
midori_panel_history_key_release_event_cb (GtkWidget* widget,
|
||||
GdkEventKey* event,
|
||||
|
@ -2733,8 +2765,6 @@ midori_browser_history_render_text_cb (GtkTreeViewColumn* column,
|
|||
GtkWidget* treeview)
|
||||
{
|
||||
KatzeItem* item;
|
||||
time_t date;
|
||||
gchar datebuf[50];
|
||||
char* sdate;
|
||||
gint age;
|
||||
|
||||
|
@ -2748,9 +2778,7 @@ midori_browser_history_render_text_cb (GtkTreeViewColumn* column,
|
|||
|
||||
if (age > 7)
|
||||
{
|
||||
date = (time_t)katze_item_get_added (item);
|
||||
strftime (datebuf, sizeof (datebuf), "%Y-%m-%d", localtime (&date));
|
||||
g_object_set (renderer, "text", datebuf, NULL);
|
||||
g_object_set (renderer, "text", katze_item_get_token (item), NULL);
|
||||
}
|
||||
else if (age > 6)
|
||||
{
|
||||
|
@ -2965,21 +2993,7 @@ static void
|
|||
_action_history_delete_activate (GtkAction* action,
|
||||
MidoriBrowser* browser)
|
||||
{
|
||||
GtkTreeView* treeview;
|
||||
GtkTreeModel* model;
|
||||
GtkTreeIter iter;
|
||||
KatzeItem* item;
|
||||
GtkAction* location_action;
|
||||
|
||||
treeview = GTK_TREE_VIEW (browser->panel_history);
|
||||
if (sokoke_tree_view_get_selected_iter (treeview, &model, &iter))
|
||||
{
|
||||
location_action = _action_by_name (browser, "Location");
|
||||
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
||||
midori_location_action_delete_item_from_uri (
|
||||
MIDORI_LOCATION_ACTION (location_action), katze_item_get_uri (item));
|
||||
midori_browser_model_remove_item (model, item, &iter);
|
||||
}
|
||||
midori_browser_history_delete (browser);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -3518,6 +3532,7 @@ midori_browser_new_history_item (MidoriBrowser* browser,
|
|||
time_t date_;
|
||||
gint age;
|
||||
gint newage;
|
||||
gchar token[50];
|
||||
|
||||
if (!katze_object_get_boolean (browser->settings, "remember-last-visited-pages"))
|
||||
return;
|
||||
|
@ -3550,8 +3565,10 @@ midori_browser_new_history_item (MidoriBrowser* browser,
|
|||
}
|
||||
if (!found)
|
||||
{
|
||||
strftime (token, sizeof (token), "%Y-%m-%d", localtime (&now));
|
||||
parent = katze_array_new (KATZE_TYPE_ARRAY);
|
||||
katze_item_set_added (KATZE_ITEM (parent), now);
|
||||
katze_item_set_token (KATZE_ITEM (parent), token);
|
||||
katze_array_add_item (browser->history, parent);
|
||||
katze_array_add_item (parent, item);
|
||||
_tree_store_insert_history_item (GTK_TREE_STORE (treemodel), NULL,
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "marshal.h"
|
||||
#include "sokoke.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
|
|
|
@ -663,35 +663,6 @@ sokoke_tree_view_get_selected_iter (GtkTreeView* tree_view,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* sokoke_same_day:
|
||||
* @day1: a time_t timestamp value
|
||||
* @day2: a time_t timestamp value
|
||||
*
|
||||
* Compares two timestamps to see if their values are on the
|
||||
* same day.
|
||||
*
|
||||
* Return value: %TRUE if the day of the timestamps match.
|
||||
**/
|
||||
gboolean
|
||||
sokoke_same_day (const time_t* day1,
|
||||
const time_t* day2)
|
||||
{
|
||||
struct tm* tm1;
|
||||
struct tm* tm2;
|
||||
gboolean same;
|
||||
|
||||
tm2 = localtime (day1);
|
||||
tm1 = (struct tm*) g_memdup (tm2, sizeof (struct tm));
|
||||
tm2 = localtime (day2);
|
||||
|
||||
same = (tm1->tm_year == tm2->tm_year &&
|
||||
tm1->tm_mon == tm2->tm_mon &&
|
||||
tm1->tm_mday == tm2->tm_mday) ? TRUE : FALSE;
|
||||
g_free (tm1);
|
||||
return same;
|
||||
}
|
||||
|
||||
/**
|
||||
* sokoke_days_between:
|
||||
* @day1: a time_t timestamp value
|
||||
|
|
|
@ -126,10 +126,6 @@ sokoke_tree_view_get_selected_iter (GtkTreeView* tree_view,
|
|||
GtkTreeModel** model,
|
||||
GtkTreeIter* iter);
|
||||
|
||||
gboolean
|
||||
sokoke_same_day (const time_t* day1,
|
||||
const time_t* day2);
|
||||
|
||||
gint
|
||||
sokoke_days_between (const time_t* day1,
|
||||
const time_t* day2);
|
||||
|
|
Loading…
Reference in a new issue