2009-02-21 22:59:02 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2008-2009 Christian Dywan <christian@twotoasts.de>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
See the file COPYING for the full license text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "midori-history.h"
|
|
|
|
|
|
|
|
#include "midori-app.h"
|
2010-07-02 15:47:55 +00:00
|
|
|
#include "midori-array.h"
|
2009-02-21 22:59:02 +00:00
|
|
|
#include "midori-browser.h"
|
2011-10-31 21:10:39 +00:00
|
|
|
#include "midori-platform.h"
|
2009-02-21 22:59:02 +00:00
|
|
|
#include "midori-view.h"
|
|
|
|
#include "midori-viewable.h"
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
2010-07-21 14:34:52 +00:00
|
|
|
#define COMPLETION_DELAY 200
|
|
|
|
|
2009-02-21 22:59:02 +00:00
|
|
|
void
|
|
|
|
midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
|
|
|
|
KatzeItem* bookmark,
|
2009-02-22 02:11:40 +00:00
|
|
|
gboolean new_bookmark,
|
|
|
|
gboolean is_folder);
|
2009-02-21 22:59:02 +00:00
|
|
|
|
2010-02-07 23:57:45 +00:00
|
|
|
|
2009-02-21 22:59:02 +00:00
|
|
|
struct _MidoriHistory
|
|
|
|
{
|
|
|
|
GtkVBox parent_instance;
|
|
|
|
|
|
|
|
GtkWidget* toolbar;
|
|
|
|
GtkWidget* bookmark;
|
|
|
|
GtkWidget* delete;
|
|
|
|
GtkWidget* clear;
|
|
|
|
GtkWidget* treeview;
|
|
|
|
MidoriApp* app;
|
|
|
|
KatzeArray* array;
|
2010-02-07 23:57:45 +00:00
|
|
|
|
|
|
|
gint filter_timeout;
|
|
|
|
gchar* filter;
|
2009-02-21 22:59:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MidoriHistoryClass
|
|
|
|
{
|
|
|
|
GtkVBoxClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_viewable_iface_init (MidoriViewableIface* iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (MidoriHistory, midori_history, GTK_TYPE_VBOX,
|
|
|
|
G_IMPLEMENT_INTERFACE (MIDORI_TYPE_VIEWABLE,
|
|
|
|
midori_history_viewable_iface_init));
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_APP
|
|
|
|
};
|
|
|
|
|
2009-04-05 21:46:15 +00:00
|
|
|
static void
|
|
|
|
midori_history_finalize (GObject* object);
|
|
|
|
|
2009-02-21 22:59:02 +00:00
|
|
|
static void
|
|
|
|
midori_history_set_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue* value,
|
|
|
|
GParamSpec* pspec);
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_get_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue* value,
|
|
|
|
GParamSpec* pspec);
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_class_init (MidoriHistoryClass* class)
|
|
|
|
{
|
|
|
|
GObjectClass* gobject_class;
|
|
|
|
GParamFlags flags;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (class);
|
2009-04-05 21:46:15 +00:00
|
|
|
gobject_class->finalize = midori_history_finalize;
|
2009-02-21 22:59:02 +00:00
|
|
|
gobject_class->set_property = midori_history_set_property;
|
|
|
|
gobject_class->get_property = midori_history_get_property;
|
|
|
|
|
|
|
|
flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_APP,
|
|
|
|
g_param_spec_object (
|
|
|
|
"app",
|
|
|
|
"App",
|
|
|
|
"The app",
|
|
|
|
MIDORI_TYPE_APP,
|
|
|
|
flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar*
|
|
|
|
midori_history_get_label (MidoriViewable* viewable)
|
|
|
|
{
|
|
|
|
return _("History");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar*
|
|
|
|
midori_history_get_stock_id (MidoriViewable* viewable)
|
|
|
|
{
|
|
|
|
return STOCK_HISTORY;
|
|
|
|
}
|
|
|
|
|
2010-07-21 14:34:52 +00:00
|
|
|
static gchar*
|
|
|
|
midori_history_format_date (KatzeItem *item)
|
|
|
|
{
|
|
|
|
gint age;
|
|
|
|
gint64 day;
|
|
|
|
gchar token[50];
|
|
|
|
gchar* sdate;
|
|
|
|
time_t current_time;
|
|
|
|
|
|
|
|
current_time = time (NULL);
|
|
|
|
day = katze_item_get_added (item);
|
|
|
|
|
|
|
|
age = sokoke_days_between ((time_t*)&day, ¤t_time);
|
|
|
|
|
|
|
|
/* A negative age is a date in the future, the clock is probably off */
|
|
|
|
if (age < -1)
|
2010-09-05 20:33:01 +00:00
|
|
|
sdate = g_strdup ("");
|
2010-07-21 14:34:52 +00:00
|
|
|
else if (age > 7 || age < 0)
|
|
|
|
{
|
|
|
|
strftime (token, sizeof (token), "%x", localtime ((time_t*)&day));
|
2010-07-23 13:50:10 +00:00
|
|
|
sdate = g_strdup (token);
|
2010-07-21 14:34:52 +00:00
|
|
|
}
|
|
|
|
else if (age > 6)
|
2010-09-05 20:33:01 +00:00
|
|
|
sdate = g_strdup (_("A week ago"));
|
2010-07-21 14:34:52 +00:00
|
|
|
else if (age > 1)
|
|
|
|
sdate = g_strdup_printf (ngettext ("%d day ago",
|
|
|
|
"%d days ago", (gint)age), (gint)age);
|
|
|
|
else if (age == 0)
|
2010-09-05 20:33:01 +00:00
|
|
|
sdate = g_strdup (_("Today"));
|
2010-07-21 14:34:52 +00:00
|
|
|
else
|
2010-09-05 20:33:01 +00:00
|
|
|
sdate = g_strdup (_("Yesterday"));
|
2010-07-21 14:34:52 +00:00
|
|
|
return sdate;
|
|
|
|
}
|
|
|
|
|
2011-04-17 20:56:30 +00:00
|
|
|
static void
|
|
|
|
midori_history_toolbar_update (MidoriHistory *history)
|
|
|
|
{
|
|
|
|
gboolean selected;
|
|
|
|
|
|
|
|
selected = katze_tree_view_get_selected_iter (
|
|
|
|
GTK_TREE_VIEW (history->treeview), NULL, NULL);
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (history->delete), selected);
|
|
|
|
}
|
|
|
|
|
2010-02-02 20:10:03 +00:00
|
|
|
static void
|
|
|
|
midori_history_remove_item_from_db (MidoriHistory* history,
|
2010-02-02 22:51:49 +00:00
|
|
|
KatzeItem* item)
|
2010-02-02 20:10:03 +00:00
|
|
|
{
|
|
|
|
gchar* sqlcmd;
|
|
|
|
sqlite3* db;
|
|
|
|
char* errmsg = NULL;
|
|
|
|
|
|
|
|
db = g_object_get_data (G_OBJECT (history->array), "db");
|
|
|
|
|
2011-07-30 18:11:45 +00:00
|
|
|
if (!db)
|
|
|
|
return;
|
|
|
|
|
2010-07-21 14:34:52 +00:00
|
|
|
if (KATZE_ITEM_IS_BOOKMARK (item))
|
2010-02-02 20:10:03 +00:00
|
|
|
sqlcmd = sqlite3_mprintf (
|
|
|
|
"DELETE FROM history WHERE uri = '%q' AND"
|
|
|
|
" title = '%q' AND date = %llu",
|
|
|
|
katze_item_get_uri (item),
|
|
|
|
katze_item_get_name (item),
|
|
|
|
katze_item_get_added (item));
|
|
|
|
else
|
2010-07-21 14:34:52 +00:00
|
|
|
sqlcmd = sqlite3_mprintf ("DELETE FROM history WHERE day = %d",
|
|
|
|
katze_item_get_meta_integer (item, "day"));
|
2010-02-02 20:10:03 +00:00
|
|
|
|
|
|
|
if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
|
|
|
|
{
|
|
|
|
g_printerr (_("Failed to remove history item: %s\n"), errmsg);
|
|
|
|
sqlite3_free (errmsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
sqlite3_free (sqlcmd);
|
|
|
|
}
|
|
|
|
|
2010-02-07 23:57:45 +00:00
|
|
|
/**
|
|
|
|
* midori_history_read_from_db:
|
|
|
|
* @history: a #MidoriHistory
|
|
|
|
* @req_day: the timestamp of one day, or 0
|
|
|
|
* @filter: a filter string to search for
|
|
|
|
*
|
|
|
|
* Populates the model according to parameters:
|
|
|
|
* 1. If @req_day is 0, all dates are added as folders.
|
|
|
|
* 2. If @req_day is given, all pages for that day are added.
|
|
|
|
* 3. If @filter is given, all pages matching the filter are added.
|
|
|
|
**/
|
2010-07-21 14:34:52 +00:00
|
|
|
static KatzeArray*
|
2010-02-02 20:10:03 +00:00
|
|
|
midori_history_read_from_db (MidoriHistory* history,
|
2010-02-07 23:57:45 +00:00
|
|
|
int req_day,
|
|
|
|
const gchar* filter)
|
2010-02-02 20:10:03 +00:00
|
|
|
{
|
|
|
|
sqlite3* db;
|
|
|
|
sqlite3_stmt* statement;
|
|
|
|
gint result;
|
2010-02-07 23:57:45 +00:00
|
|
|
const gchar* sqlcmd;
|
2010-02-02 20:10:03 +00:00
|
|
|
|
|
|
|
db = g_object_get_data (G_OBJECT (history->array), "db");
|
|
|
|
|
2011-07-30 18:11:45 +00:00
|
|
|
if (!db)
|
|
|
|
return katze_array_new (KATZE_TYPE_ITEM);
|
|
|
|
|
2010-02-07 23:57:45 +00:00
|
|
|
if (filter && *filter)
|
|
|
|
{
|
|
|
|
gchar* filterstr;
|
|
|
|
|
2010-07-20 19:25:34 +00:00
|
|
|
sqlcmd = "SELECT * FROM ("
|
2010-11-23 23:37:01 +00:00
|
|
|
" SELECT uri, title, day, date FROM history"
|
2010-07-20 19:25:34 +00:00
|
|
|
" WHERE uri LIKE ?1 OR title LIKE ?1 GROUP BY uri "
|
2010-02-25 22:09:31 +00:00
|
|
|
"UNION ALL "
|
2010-07-20 19:25:34 +00:00
|
|
|
" SELECT replace (uri, '%s', keywords) AS uri, "
|
2010-11-23 23:37:01 +00:00
|
|
|
" keywords AS title, day, 0 AS date FROM search "
|
2010-07-20 19:25:34 +00:00
|
|
|
" WHERE uri LIKE ?1 OR keywords LIKE ?1 GROUP BY uri "
|
|
|
|
") ORDER BY day ASC";
|
2010-02-07 23:57:45 +00:00
|
|
|
result = sqlite3_prepare_v2 (db, sqlcmd, -1, &statement, NULL);
|
|
|
|
filterstr = g_strdup_printf ("%%%s%%", filter);
|
|
|
|
sqlite3_bind_text (statement, 1, filterstr, -1, g_free);
|
|
|
|
req_day = -1;
|
|
|
|
}
|
|
|
|
else if (req_day == 0)
|
|
|
|
{
|
|
|
|
sqlcmd = "SELECT day, date FROM history GROUP BY day ORDER BY day ASC";
|
|
|
|
result = sqlite3_prepare_v2 (db, sqlcmd, -1, &statement, NULL);
|
|
|
|
}
|
2010-02-02 20:10:03 +00:00
|
|
|
else
|
|
|
|
{
|
2010-02-07 23:57:45 +00:00
|
|
|
sqlcmd = "SELECT uri, title, date, day "
|
|
|
|
"FROM history WHERE day = ? "
|
|
|
|
"GROUP BY uri ORDER BY date ASC";
|
|
|
|
result = sqlite3_prepare_v2 (db, sqlcmd, -1, &statement, NULL);
|
|
|
|
sqlite3_bind_int64 (statement, 1, req_day);
|
2010-02-02 20:10:03 +00:00
|
|
|
}
|
2010-02-07 23:57:45 +00:00
|
|
|
|
|
|
|
if (result != SQLITE_OK)
|
2011-07-30 18:11:45 +00:00
|
|
|
return katze_array_new (KATZE_TYPE_ITEM);
|
2010-02-02 20:10:03 +00:00
|
|
|
|
2010-07-21 14:34:52 +00:00
|
|
|
return katze_array_from_statement (statement);
|
|
|
|
}
|
2010-02-02 20:10:03 +00:00
|
|
|
|
2010-07-21 14:34:52 +00:00
|
|
|
static void
|
|
|
|
midori_history_read_from_db_to_model (MidoriHistory* history,
|
|
|
|
GtkTreeStore* model,
|
|
|
|
GtkTreeIter* parent,
|
|
|
|
int req_day,
|
|
|
|
const gchar* filter)
|
|
|
|
{
|
|
|
|
KatzeArray* array;
|
|
|
|
gint last;
|
|
|
|
KatzeItem* item;
|
|
|
|
GtkTreeIter child;
|
2010-02-02 22:51:49 +00:00
|
|
|
|
2010-07-21 14:34:52 +00:00
|
|
|
array = midori_history_read_from_db (history, req_day, filter);
|
|
|
|
katze_bookmark_populate_tree_view (array, model, parent);
|
2010-02-02 22:51:49 +00:00
|
|
|
|
2010-07-21 14:34:52 +00:00
|
|
|
/* Remove invisible dummy row */
|
|
|
|
last = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), parent);
|
|
|
|
if (!last)
|
|
|
|
return;
|
|
|
|
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (model), &child, parent, last - 1);
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (model), &child, 0, &item, -1);
|
|
|
|
if (KATZE_ITEM_IS_SEPARATOR (item))
|
2010-02-07 23:12:15 +00:00
|
|
|
gtk_tree_store_remove (model, &child);
|
2010-07-21 14:34:52 +00:00
|
|
|
else
|
|
|
|
g_object_unref (item);
|
2010-02-02 20:10:03 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 22:59:02 +00:00
|
|
|
static void
|
|
|
|
midori_history_delete_clicked_cb (GtkWidget* toolitem,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (history->treeview),
|
|
|
|
&model, &iter))
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
|
2010-02-02 22:51:49 +00:00
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
|
|
|
midori_history_remove_item_from_db (history, item);
|
2010-02-02 20:10:03 +00:00
|
|
|
gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
|
2009-02-21 22:59:02 +00:00
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_clear_clicked_cb (GtkWidget* toolitem,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
2009-04-23 02:14:32 +00:00
|
|
|
MidoriBrowser* browser;
|
2009-02-21 22:59:02 +00:00
|
|
|
GtkWidget* dialog;
|
|
|
|
gint result;
|
|
|
|
|
2009-04-23 02:14:32 +00:00
|
|
|
browser = midori_browser_get_for_widget (GTK_WIDGET (history));
|
2009-02-21 22:59:02 +00:00
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (browser),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
|
|
|
|
_("Are you sure you want to remove all history items?"));
|
|
|
|
result = gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
if (result != GTK_RESPONSE_YES)
|
|
|
|
return;
|
|
|
|
|
2010-11-21 15:14:30 +00:00
|
|
|
katze_array_clear (history->array);
|
2009-02-21 22:59:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-25 04:11:36 +00:00
|
|
|
static void
|
|
|
|
midori_history_bookmark_add_cb (GtkWidget* menuitem,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
2010-07-21 14:34:52 +00:00
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
2011-07-30 18:11:45 +00:00
|
|
|
KatzeItem* item = NULL;
|
2010-06-25 04:11:36 +00:00
|
|
|
|
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (history));
|
2010-07-21 14:34:52 +00:00
|
|
|
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (history->treeview),
|
|
|
|
&model, &iter))
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
2010-06-25 04:11:36 +00:00
|
|
|
|
|
|
|
if (KATZE_IS_ITEM (item) && katze_item_get_uri (item))
|
2011-07-30 18:11:45 +00:00
|
|
|
{
|
2010-06-25 04:11:36 +00:00
|
|
|
midori_browser_edit_bookmark_dialog_new (browser, item, TRUE, FALSE);
|
2011-07-30 18:11:45 +00:00
|
|
|
g_object_unref (item);
|
|
|
|
}
|
2010-06-25 04:11:36 +00:00
|
|
|
else
|
|
|
|
midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, FALSE);
|
|
|
|
}
|
|
|
|
|
2009-02-21 22:59:02 +00:00
|
|
|
static GtkWidget*
|
|
|
|
midori_history_get_toolbar (MidoriViewable* viewable)
|
|
|
|
{
|
|
|
|
MidoriHistory* history = MIDORI_HISTORY (viewable);
|
|
|
|
|
|
|
|
if (!history->toolbar)
|
|
|
|
{
|
|
|
|
GtkWidget* toolbar;
|
|
|
|
GtkToolItem* toolitem;
|
|
|
|
|
|
|
|
toolbar = gtk_toolbar_new ();
|
|
|
|
gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_BUTTON);
|
|
|
|
history->toolbar = toolbar;
|
|
|
|
toolitem = gtk_tool_button_new_from_stock (STOCK_BOOKMARK_ADD);
|
|
|
|
gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem),
|
|
|
|
_("Bookmark the selected history item"));
|
|
|
|
gtk_tool_item_set_is_important (toolitem, TRUE);
|
|
|
|
g_signal_connect (toolitem, "clicked",
|
2010-06-25 04:11:36 +00:00
|
|
|
G_CALLBACK (midori_history_bookmark_add_cb), history);
|
2009-02-21 22:59:02 +00:00
|
|
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
|
|
|
|
gtk_widget_show (GTK_WIDGET (toolitem));
|
|
|
|
history->bookmark = GTK_WIDGET (toolitem);
|
|
|
|
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_DELETE);
|
|
|
|
gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem),
|
|
|
|
_("Delete the selected history item"));
|
|
|
|
g_signal_connect (toolitem, "clicked",
|
|
|
|
G_CALLBACK (midori_history_delete_clicked_cb), history);
|
|
|
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
|
|
|
|
gtk_widget_show (GTK_WIDGET (toolitem));
|
|
|
|
history->delete = GTK_WIDGET (toolitem);
|
|
|
|
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
|
|
|
|
gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem),
|
|
|
|
_("Clear the entire history"));
|
|
|
|
g_signal_connect (toolitem, "clicked",
|
|
|
|
G_CALLBACK (midori_history_clear_clicked_cb), history);
|
|
|
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
|
|
|
|
gtk_widget_show (GTK_WIDGET (toolitem));
|
|
|
|
history->clear = GTK_WIDGET (toolitem);
|
2011-04-17 20:56:30 +00:00
|
|
|
midori_history_toolbar_update (history);
|
2009-02-21 22:59:02 +00:00
|
|
|
g_signal_connect (history->bookmark, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &history->bookmark);
|
|
|
|
g_signal_connect (history->delete, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &history->delete);
|
|
|
|
g_signal_connect (history->clear, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &history->clear);
|
|
|
|
}
|
|
|
|
|
|
|
|
return history->toolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_viewable_iface_init (MidoriViewableIface* iface)
|
|
|
|
{
|
|
|
|
iface->get_stock_id = midori_history_get_stock_id;
|
|
|
|
iface->get_label = midori_history_get_label;
|
|
|
|
iface->get_toolbar = midori_history_get_toolbar;
|
|
|
|
}
|
|
|
|
|
2010-07-30 23:42:14 +00:00
|
|
|
static void
|
|
|
|
midori_history_add_item_cb (KatzeArray* array,
|
|
|
|
KatzeItem* item,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
GtkTreeView* treeview = GTK_TREE_VIEW (history->treeview);
|
|
|
|
GtkTreeModel* model = gtk_tree_view_get_model (treeview);
|
|
|
|
GtkTreeIter iter;
|
|
|
|
KatzeItem* today;
|
|
|
|
time_t current_time;
|
|
|
|
|
|
|
|
current_time = time (NULL);
|
|
|
|
if (gtk_tree_model_iter_children (model, &iter, NULL))
|
|
|
|
{
|
|
|
|
gint64 day;
|
|
|
|
gboolean has_today;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &today, -1);
|
|
|
|
|
|
|
|
day = katze_item_get_added (today);
|
|
|
|
has_today = sokoke_days_between ((time_t*)&day, ¤t_time) == 0;
|
|
|
|
g_object_unref (today);
|
|
|
|
if (has_today)
|
|
|
|
{
|
|
|
|
gchar* tooltip = g_markup_escape_text (katze_item_get_uri (item), -1);
|
|
|
|
KatzeItem* copy = katze_item_copy (item);
|
|
|
|
gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), NULL, &iter,
|
|
|
|
0, 0, copy, 1, tooltip, -1);
|
|
|
|
g_object_unref (copy);
|
|
|
|
g_free (tooltip);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
today = (KatzeItem*)katze_array_new (KATZE_TYPE_ITEM);
|
|
|
|
katze_item_set_added (today, current_time);
|
|
|
|
katze_item_set_meta_integer (today, "day",
|
|
|
|
sokoke_time_t_to_julian (¤t_time));
|
|
|
|
gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), &iter, NULL,
|
|
|
|
0, 0, today, -1);
|
|
|
|
/* That's an invisible dummy, so we always have an expander */
|
|
|
|
gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), NULL, &iter,
|
|
|
|
0, 0, NULL, -1);
|
|
|
|
}
|
|
|
|
|
2010-11-21 15:14:30 +00:00
|
|
|
static void
|
|
|
|
midori_history_clear_cb (KatzeArray* array,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
GtkTreeView* treeview = GTK_TREE_VIEW (history->treeview);
|
|
|
|
GtkTreeModel* model = gtk_tree_view_get_model (treeview);
|
|
|
|
gtk_tree_store_clear (GTK_TREE_STORE (model));
|
|
|
|
}
|
2009-02-21 22:59:02 +00:00
|
|
|
static void
|
|
|
|
midori_history_set_app (MidoriHistory* history,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
|
|
|
|
if (history->array)
|
|
|
|
{
|
2010-07-30 23:42:14 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (history->array,
|
|
|
|
midori_history_add_item_cb, history);
|
2010-11-21 15:14:30 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (history->array,
|
|
|
|
midori_history_clear_cb, history);
|
2010-07-30 23:42:14 +00:00
|
|
|
katze_object_assign (history->array, NULL);
|
2009-02-21 22:59:02 +00:00
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (history->treeview));
|
|
|
|
gtk_tree_store_clear (GTK_TREE_STORE (model));
|
|
|
|
}
|
2010-02-02 20:10:03 +00:00
|
|
|
|
2011-01-16 13:04:11 +00:00
|
|
|
katze_object_assign (history->app, app);
|
2009-02-21 22:59:02 +00:00
|
|
|
if (!app)
|
|
|
|
return;
|
|
|
|
g_object_ref (app);
|
|
|
|
|
2010-02-02 20:10:03 +00:00
|
|
|
history->array = katze_object_get_object (app, "history");
|
2010-07-30 23:42:14 +00:00
|
|
|
g_signal_connect (history->array, "add-item",
|
|
|
|
G_CALLBACK (midori_history_add_item_cb), history);
|
2010-11-21 15:14:30 +00:00
|
|
|
g_signal_connect (history->array, "clear",
|
|
|
|
G_CALLBACK (midori_history_clear_cb), history);
|
2010-02-02 20:10:03 +00:00
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (history->treeview));
|
2010-02-08 22:13:35 +00:00
|
|
|
if (history->array)
|
2010-07-21 14:34:52 +00:00
|
|
|
midori_history_read_from_db_to_model (history, GTK_TREE_STORE (model), NULL, 0, NULL);
|
2009-02-21 22:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_set_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue* value,
|
|
|
|
GParamSpec* pspec)
|
|
|
|
{
|
|
|
|
MidoriHistory* history = MIDORI_HISTORY (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_APP:
|
|
|
|
midori_history_set_app (history, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_get_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue* value,
|
|
|
|
GParamSpec* pspec)
|
|
|
|
{
|
|
|
|
MidoriHistory* history = MIDORI_HISTORY (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_APP:
|
|
|
|
g_value_set_object (value, history->app);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_treeview_render_icon_cb (GtkTreeViewColumn* column,
|
|
|
|
GtkCellRenderer* renderer,
|
|
|
|
GtkTreeModel* model,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
GtkWidget* treeview)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
2010-02-03 22:48:07 +00:00
|
|
|
GdkPixbuf* pixbuf;
|
2009-02-21 22:59:02 +00:00
|
|
|
|
2010-02-02 22:51:49 +00:00
|
|
|
gtk_tree_model_get (model, iter, 0, &item, -1);
|
2009-02-21 22:59:02 +00:00
|
|
|
|
2010-02-03 22:48:07 +00:00
|
|
|
if (!item)
|
|
|
|
pixbuf = NULL;
|
|
|
|
else if (katze_item_get_uri (item))
|
2010-02-02 20:10:03 +00:00
|
|
|
pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
|
|
|
|
else
|
2009-02-21 22:59:02 +00:00
|
|
|
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
|
|
|
|
GTK_ICON_SIZE_MENU, NULL);
|
|
|
|
|
|
|
|
g_object_set (renderer, "pixbuf", pixbuf, NULL);
|
|
|
|
|
|
|
|
if (pixbuf)
|
2010-02-03 22:48:07 +00:00
|
|
|
{
|
2009-02-21 22:59:02 +00:00
|
|
|
g_object_unref (pixbuf);
|
2010-02-03 22:48:07 +00:00
|
|
|
g_object_unref (item);
|
|
|
|
}
|
2009-02-21 22:59:02 +00:00
|
|
|
}
|
|
|
|
|
2010-07-21 14:34:52 +00:00
|
|
|
static void
|
|
|
|
midori_history_treeview_render_text_cb (GtkTreeViewColumn* column,
|
|
|
|
GtkCellRenderer* renderer,
|
|
|
|
GtkTreeModel* model,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
GtkWidget* treeview)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, 0, &item, -1);
|
|
|
|
|
|
|
|
if (KATZE_ITEM_IS_BOOKMARK (item))
|
|
|
|
g_object_set (renderer, "markup", NULL,
|
|
|
|
"text", katze_item_get_name (item), NULL);
|
|
|
|
else if (KATZE_ITEM_IS_FOLDER (item))
|
2010-09-05 20:33:01 +00:00
|
|
|
{
|
|
|
|
gchar* formatted = midori_history_format_date (item);
|
|
|
|
g_object_set (renderer, "markup", NULL, "text", formatted, NULL);
|
|
|
|
g_free (formatted);
|
|
|
|
}
|
2010-07-21 14:34:52 +00:00
|
|
|
else
|
|
|
|
g_object_set (renderer, "markup", _("<i>Separator</i>"), NULL);
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
2009-02-21 22:59:02 +00:00
|
|
|
static void
|
|
|
|
midori_history_row_activated_cb (GtkTreeView* treeview,
|
2010-07-02 04:23:25 +00:00
|
|
|
GtkTreePath* path,
|
|
|
|
GtkTreeViewColumn* column,
|
|
|
|
MidoriHistory* history)
|
2009-02-21 22:59:02 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (treeview);
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter (model, &iter, path))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
2010-07-02 04:23:25 +00:00
|
|
|
if (KATZE_ITEM_IS_BOOKMARK (item))
|
2009-02-21 22:59:02 +00:00
|
|
|
{
|
2009-04-23 02:14:32 +00:00
|
|
|
MidoriBrowser* browser;
|
2010-07-02 04:23:25 +00:00
|
|
|
const gchar* uri;
|
2009-02-21 22:59:02 +00:00
|
|
|
|
2010-07-02 04:23:25 +00:00
|
|
|
uri = katze_item_get_uri (item);
|
2009-04-23 02:14:32 +00:00
|
|
|
browser = midori_browser_get_for_widget (GTK_WIDGET (history));
|
|
|
|
midori_browser_set_current_uri (browser, uri);
|
2010-07-02 04:23:25 +00:00
|
|
|
g_object_unref (item);
|
|
|
|
return;
|
2009-02-21 22:59:02 +00:00
|
|
|
}
|
2010-07-02 04:23:25 +00:00
|
|
|
if (gtk_tree_view_row_expanded (treeview, path))
|
|
|
|
gtk_tree_view_collapse_row (treeview, path);
|
|
|
|
else
|
|
|
|
gtk_tree_view_expand_row (treeview, path, FALSE);
|
2009-02-21 22:59:02 +00:00
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_popup_item (GtkWidget* menu,
|
|
|
|
const gchar* stock_id,
|
|
|
|
const gchar* label,
|
|
|
|
KatzeItem* item,
|
|
|
|
gpointer callback,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
const gchar* uri;
|
|
|
|
GtkWidget* menuitem;
|
|
|
|
|
|
|
|
uri = katze_item_get_uri (item);
|
|
|
|
|
|
|
|
menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
|
|
|
|
if (label)
|
|
|
|
gtk_label_set_text_with_mnemonic (GTK_LABEL (gtk_bin_get_child (
|
|
|
|
GTK_BIN (menuitem))), label);
|
|
|
|
if (!strcmp (stock_id, GTK_STOCK_EDIT))
|
2010-07-01 01:24:43 +00:00
|
|
|
gtk_widget_set_sensitive (menuitem, uri != NULL);
|
|
|
|
else if (katze_item_get_uri (item) && strcmp (stock_id, GTK_STOCK_DELETE))
|
2009-02-21 22:59:02 +00:00
|
|
|
gtk_widget_set_sensitive (menuitem, uri != NULL);
|
|
|
|
g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);
|
|
|
|
g_signal_connect (menuitem, "activate", G_CALLBACK (callback), history);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_open_activate_cb (GtkWidget* menuitem,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
const gchar* uri;
|
|
|
|
|
|
|
|
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
|
|
|
|
uri = katze_item_get_uri (item);
|
|
|
|
|
|
|
|
if (uri && *uri)
|
|
|
|
{
|
2009-04-23 02:14:32 +00:00
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (history));
|
|
|
|
midori_browser_set_current_uri (browser, uri);
|
2009-02-21 22:59:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_open_in_tab_activate_cb (GtkWidget* menuitem,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
const gchar* uri;
|
|
|
|
guint n;
|
|
|
|
|
|
|
|
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
|
2010-07-02 15:47:55 +00:00
|
|
|
if (KATZE_ITEM_IS_FOLDER (item))
|
2009-02-27 20:52:51 +00:00
|
|
|
{
|
2010-07-02 15:47:55 +00:00
|
|
|
sqlite3* db;
|
|
|
|
gchar* sqlcmd;
|
2009-02-27 20:52:51 +00:00
|
|
|
KatzeItem* child;
|
2010-07-02 15:47:55 +00:00
|
|
|
KatzeArray* array;
|
2009-02-21 22:59:02 +00:00
|
|
|
|
2010-07-02 15:47:55 +00:00
|
|
|
db = g_object_get_data (G_OBJECT (history->array), "db");
|
2011-07-30 18:11:45 +00:00
|
|
|
|
|
|
|
if (!db)
|
|
|
|
return;
|
|
|
|
|
2010-07-02 15:47:55 +00:00
|
|
|
sqlcmd = g_strdup_printf ("SELECT uri, title, date, day "
|
|
|
|
"FROM history WHERE day = %d "
|
|
|
|
"GROUP BY uri ORDER BY date ASC",
|
|
|
|
(int)katze_item_get_added (item));
|
|
|
|
array = katze_array_from_sqlite (db, sqlcmd);
|
|
|
|
g_free (sqlcmd);
|
2010-09-11 21:39:51 +00:00
|
|
|
KATZE_ARRAY_FOREACH_ITEM (child, KATZE_ARRAY (array))
|
2009-02-27 20:52:51 +00:00
|
|
|
{
|
|
|
|
if ((uri = katze_item_get_uri (child)) && *uri)
|
|
|
|
{
|
2009-04-23 02:14:32 +00:00
|
|
|
MidoriBrowser* browser;
|
2009-02-27 20:52:51 +00:00
|
|
|
|
2009-04-23 02:14:32 +00:00
|
|
|
browser = midori_browser_get_for_widget (GTK_WIDGET (history));
|
|
|
|
n = midori_browser_add_item (browser, child);
|
2010-07-03 07:28:03 +00:00
|
|
|
midori_browser_set_current_page_smartly (browser, n);
|
2009-02-27 20:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-02-21 22:59:02 +00:00
|
|
|
{
|
2009-02-27 20:52:51 +00:00
|
|
|
if ((uri = katze_item_get_uri (item)) && *uri)
|
|
|
|
{
|
2009-04-23 02:14:32 +00:00
|
|
|
MidoriBrowser* browser;
|
2009-02-27 20:52:51 +00:00
|
|
|
|
2009-04-23 02:14:32 +00:00
|
|
|
browser = midori_browser_get_for_widget (GTK_WIDGET (history));
|
|
|
|
n = midori_browser_add_item (browser, item);
|
2010-07-03 07:28:03 +00:00
|
|
|
midori_browser_set_current_page_smartly (browser, n);
|
2009-02-27 20:52:51 +00:00
|
|
|
}
|
2009-02-21 22:59:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_open_in_window_activate_cb (GtkWidget* menuitem,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
const gchar* uri;
|
|
|
|
|
|
|
|
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
|
|
|
|
uri = katze_item_get_uri (item);
|
|
|
|
|
|
|
|
if (uri && *uri)
|
|
|
|
{
|
2009-05-31 01:34:13 +00:00
|
|
|
MidoriBrowser* new_browser = midori_app_create_browser (history->app);
|
|
|
|
midori_app_add_browser (history->app, new_browser);
|
|
|
|
gtk_widget_show (GTK_WIDGET (new_browser));
|
|
|
|
midori_browser_add_uri (new_browser, uri);
|
2009-02-21 22:59:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_popup (GtkWidget* widget,
|
|
|
|
GdkEventButton* event,
|
|
|
|
KatzeItem* item,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
GtkWidget* menu;
|
|
|
|
GtkWidget* menuitem;
|
|
|
|
|
|
|
|
menu = gtk_menu_new ();
|
2010-07-01 01:24:43 +00:00
|
|
|
if (!katze_item_get_uri (item))
|
2009-02-27 20:52:51 +00:00
|
|
|
midori_history_popup_item (menu,
|
|
|
|
STOCK_TAB_NEW, _("Open all in _Tabs"),
|
|
|
|
item, midori_history_open_in_tab_activate_cb, history);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
midori_history_popup_item (menu, GTK_STOCK_OPEN, NULL,
|
|
|
|
item, midori_history_open_activate_cb, history);
|
|
|
|
midori_history_popup_item (menu, STOCK_TAB_NEW, _("Open in New _Tab"),
|
|
|
|
item, midori_history_open_in_tab_activate_cb, history);
|
|
|
|
midori_history_popup_item (menu, STOCK_WINDOW_NEW, _("Open in New _Window"),
|
|
|
|
item, midori_history_open_in_window_activate_cb, history);
|
2009-02-21 22:59:02 +00:00
|
|
|
midori_history_popup_item (menu, STOCK_BOOKMARK_ADD, NULL,
|
2010-06-25 04:11:36 +00:00
|
|
|
item, midori_history_bookmark_add_cb, history);
|
2009-02-27 20:52:51 +00:00
|
|
|
}
|
2009-02-21 22:59:02 +00:00
|
|
|
menuitem = gtk_separator_menu_item_new ();
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
midori_history_popup_item (menu, GTK_STOCK_DELETE, NULL,
|
2010-02-02 20:10:03 +00:00
|
|
|
item, midori_history_delete_clicked_cb, history);
|
2009-02-21 22:59:02 +00:00
|
|
|
|
2009-11-15 17:00:33 +00:00
|
|
|
katze_widget_popup (widget, GTK_MENU (menu), event, KATZE_MENU_POSITION_CURSOR);
|
2009-02-21 22:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
midori_history_button_release_event_cb (GtkWidget* widget,
|
|
|
|
GdkEventButton* event,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (event->button != 2 && event->button != 3)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
|
|
|
|
2010-02-03 22:48:07 +00:00
|
|
|
if (!item)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-02-21 22:59:02 +00:00
|
|
|
if (event->button == 2)
|
|
|
|
{
|
|
|
|
const gchar* uri = katze_item_get_uri (item);
|
|
|
|
|
|
|
|
if (uri && *uri)
|
|
|
|
{
|
2009-04-23 02:14:32 +00:00
|
|
|
MidoriBrowser* browser;
|
2009-02-21 22:59:02 +00:00
|
|
|
gint n;
|
|
|
|
|
2009-04-23 02:14:32 +00:00
|
|
|
browser = midori_browser_get_for_widget (widget);
|
|
|
|
n = midori_browser_add_uri (browser, uri);
|
|
|
|
midori_browser_set_current_page (browser, n);
|
2009-02-21 22:59:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
midori_history_popup (widget, event, item, history);
|
|
|
|
|
|
|
|
g_object_unref (item);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
midori_history_key_release_event_cb (GtkWidget* widget,
|
|
|
|
GdkEventKey* event,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2011-10-01 13:12:04 +00:00
|
|
|
if (event->keyval != GDK_KEY_Delete)
|
2009-02-21 22:59:02 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
2010-02-03 21:15:49 +00:00
|
|
|
midori_history_remove_item_from_db (history, item);
|
|
|
|
gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
|
2009-02-21 22:59:02 +00:00
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_popup_menu_cb (GtkWidget* widget,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
|
|
|
midori_history_popup (widget, NULL, item, history);
|
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-02 20:10:03 +00:00
|
|
|
static void
|
|
|
|
midori_history_row_expanded_cb (GtkTreeView* treeview,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
GtkTreePath* path,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
|
|
|
|
gtk_tree_model_get (model, iter, 0, &item, -1);
|
2010-07-21 14:34:52 +00:00
|
|
|
midori_history_read_from_db_to_model (history, GTK_TREE_STORE (model),
|
|
|
|
iter, katze_item_get_meta_integer (item, "day"), NULL);
|
2010-02-02 20:10:03 +00:00
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_row_collapsed_cb (GtkTreeView *treeview,
|
2010-02-03 21:13:00 +00:00
|
|
|
GtkTreeIter *parent,
|
2010-02-02 20:10:03 +00:00
|
|
|
GtkTreePath *path,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2010-02-03 21:13:00 +00:00
|
|
|
GtkTreeModel* model;
|
2010-02-07 23:12:15 +00:00
|
|
|
GtkTreeStore* treestore;
|
2010-02-03 21:13:00 +00:00
|
|
|
GtkTreeIter child;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
|
2010-02-07 23:12:15 +00:00
|
|
|
treestore = GTK_TREE_STORE (model);
|
|
|
|
while (gtk_tree_model_iter_nth_child (model, &child, parent, 0))
|
|
|
|
gtk_tree_store_remove (treestore, &child);
|
|
|
|
/* That's an invisible dummy, so we always have an expander */
|
|
|
|
gtk_tree_store_insert_with_values (treestore, &child, parent,
|
2010-07-21 14:34:52 +00:00
|
|
|
0, 0, NULL, -1);
|
2010-02-02 20:10:03 +00:00
|
|
|
}
|
2010-02-07 23:57:45 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
midori_history_filter_timeout_cb (gpointer data)
|
|
|
|
{
|
|
|
|
MidoriHistory* history = data;
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeStore* treestore;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (history->treeview));
|
|
|
|
treestore = GTK_TREE_STORE (model);
|
|
|
|
|
|
|
|
gtk_tree_store_clear (treestore);
|
2010-07-21 14:34:52 +00:00
|
|
|
midori_history_read_from_db_to_model (history, treestore, NULL, 0, history->filter);
|
2010-02-07 23:57:45 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_filter_entry_changed_cb (GtkEntry* entry,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
if (history->filter_timeout)
|
|
|
|
g_source_remove (history->filter_timeout);
|
|
|
|
history->filter_timeout = g_timeout_add (COMPLETION_DELAY,
|
|
|
|
midori_history_filter_timeout_cb, history);
|
|
|
|
katze_assign (history->filter, g_strdup (gtk_entry_get_text (entry)));
|
|
|
|
}
|
2010-07-17 19:31:29 +00:00
|
|
|
|
2010-02-07 23:57:45 +00:00
|
|
|
static void
|
|
|
|
midori_history_filter_entry_clear_cb (GtkEntry* entry,
|
|
|
|
gint icon_pos,
|
|
|
|
gint button,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
|
|
|
|
gtk_entry_set_text (entry, "");
|
|
|
|
}
|
|
|
|
|
2011-04-17 20:56:30 +00:00
|
|
|
static void
|
|
|
|
midori_history_selection_changed_cb (GtkTreeView* treeview,
|
|
|
|
MidoriHistory* history)
|
|
|
|
{
|
|
|
|
midori_history_toolbar_update (history);
|
|
|
|
}
|
2010-02-02 20:10:03 +00:00
|
|
|
|
2009-02-21 22:59:02 +00:00
|
|
|
static void
|
|
|
|
midori_history_init (MidoriHistory* history)
|
|
|
|
{
|
2010-02-07 23:57:45 +00:00
|
|
|
GtkWidget* entry;
|
|
|
|
GtkWidget* box;
|
2009-02-21 22:59:02 +00:00
|
|
|
GtkTreeStore* model;
|
|
|
|
GtkWidget* treeview;
|
|
|
|
GtkTreeViewColumn* column;
|
|
|
|
GtkCellRenderer* renderer_pixbuf;
|
|
|
|
GtkCellRenderer* renderer_text;
|
2011-04-17 20:56:30 +00:00
|
|
|
GtkTreeSelection* selection;
|
2009-02-21 22:59:02 +00:00
|
|
|
|
2010-02-07 23:57:45 +00:00
|
|
|
/* Create the filter entry */
|
|
|
|
entry = gtk_icon_entry_new ();
|
|
|
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
|
2010-07-03 05:49:29 +00:00
|
|
|
GTK_ICON_ENTRY_PRIMARY,
|
|
|
|
GTK_STOCK_FIND);
|
2012-01-13 23:45:01 +00:00
|
|
|
sokoke_entry_set_clear_button_visible (GTK_ENTRY (entry), TRUE);
|
2010-02-07 23:57:45 +00:00
|
|
|
g_signal_connect (entry, "icon-release",
|
|
|
|
G_CALLBACK (midori_history_filter_entry_clear_cb), history);
|
|
|
|
g_signal_connect (entry, "changed",
|
|
|
|
G_CALLBACK (midori_history_filter_entry_changed_cb), history);
|
|
|
|
box = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), entry, TRUE, TRUE, 3);
|
|
|
|
gtk_widget_show_all (box);
|
|
|
|
gtk_box_pack_start (GTK_BOX (history), box, FALSE, FALSE, 5);
|
|
|
|
|
2009-02-21 22:59:02 +00:00
|
|
|
/* Create the treeview */
|
2010-07-30 23:21:50 +00:00
|
|
|
model = gtk_tree_store_new (2, KATZE_TYPE_ITEM, G_TYPE_STRING);
|
2009-02-21 22:59:02 +00:00
|
|
|
treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
|
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
|
2010-07-30 23:21:50 +00:00
|
|
|
gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (treeview), 1);
|
2009-02-21 22:59:02 +00:00
|
|
|
column = gtk_tree_view_column_new ();
|
2010-11-24 18:06:12 +00:00
|
|
|
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
2009-02-21 22:59:02 +00:00
|
|
|
renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE);
|
|
|
|
gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf,
|
|
|
|
(GtkTreeCellDataFunc)midori_history_treeview_render_icon_cb,
|
|
|
|
treeview, NULL);
|
|
|
|
renderer_text = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_tree_view_column_pack_start (column, renderer_text, FALSE);
|
2010-07-21 14:34:52 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func (column, renderer_text,
|
|
|
|
(GtkTreeCellDataFunc)midori_history_treeview_render_text_cb,
|
|
|
|
treeview, NULL);
|
2009-02-21 22:59:02 +00:00
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
|
|
|
|
g_object_unref (model);
|
|
|
|
g_object_connect (treeview,
|
|
|
|
"signal::row-activated",
|
|
|
|
midori_history_row_activated_cb, history,
|
|
|
|
"signal::button-release-event",
|
|
|
|
midori_history_button_release_event_cb, history,
|
|
|
|
"signal::key-release-event",
|
|
|
|
midori_history_key_release_event_cb, history,
|
2010-02-02 20:10:03 +00:00
|
|
|
"signal::row-expanded",
|
|
|
|
midori_history_row_expanded_cb, history,
|
|
|
|
"signal::row-collapsed",
|
|
|
|
midori_history_row_collapsed_cb, history,
|
2009-02-21 22:59:02 +00:00
|
|
|
"signal::popup-menu",
|
|
|
|
midori_history_popup_menu_cb, history,
|
|
|
|
NULL);
|
2011-04-17 20:56:30 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
|
|
|
|
g_signal_connect_after (selection, "changed",
|
|
|
|
G_CALLBACK (midori_history_selection_changed_cb),
|
|
|
|
history);
|
2009-02-21 22:59:02 +00:00
|
|
|
gtk_widget_show (treeview);
|
|
|
|
gtk_box_pack_start (GTK_BOX (history), treeview, TRUE, TRUE, 0);
|
|
|
|
history->treeview = treeview;
|
2010-02-02 20:10:03 +00:00
|
|
|
/* FIXME: We need to connect a signal here, to add new pages into history */
|
2010-02-07 23:57:45 +00:00
|
|
|
|
|
|
|
history->filter = NULL;
|
2009-02-21 22:59:02 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 21:46:15 +00:00
|
|
|
static void
|
|
|
|
midori_history_finalize (GObject* object)
|
|
|
|
{
|
|
|
|
MidoriHistory* history = MIDORI_HISTORY (object);
|
|
|
|
|
|
|
|
if (history->app)
|
|
|
|
g_object_unref (history->app);
|
2009-05-15 18:08:06 +00:00
|
|
|
|
2010-08-10 20:58:11 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (history->array,
|
|
|
|
midori_history_add_item_cb, history);
|
2010-11-21 15:14:30 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (history->array,
|
|
|
|
midori_history_clear_cb, history);
|
2009-04-05 21:46:15 +00:00
|
|
|
g_object_unref (history->array);
|
2010-02-07 23:57:45 +00:00
|
|
|
katze_assign (history->filter, NULL);
|
2009-04-05 21:46:15 +00:00
|
|
|
}
|
|
|
|
|