[epiphany] Allow sorting by date, title or url in the history dialog.
- From: Yosef Or Boczko <yoseforb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Allow sorting by date, title or url in the history dialog.
- Date: Wed, 7 May 2014 15:15:11 +0000 (UTC)
commit c3c38edbf82a4697078e658c3cda442ff5ac7229
Author: Robert Roth <robert roth off gmail com>
Date: Wed Feb 19 15:34:38 2014 +0200
Allow sorting by date, title or url in the history dialog.
https://bugzilla.gnome.org/show_bug.cgi?id=699519
Implemented by:
* adding the proper sorting enum values in the history service
* using the order by in query statements based on the enum values
* overriding the column header clicked event to change the sorting
order and/or direction
* reloading the data from the history service on column header clicks
lib/history/ephy-history-service-urls-table.c | 12 ++++
lib/history/ephy-history-types.h | 6 ++-
src/ephy-history-window.c | 68 ++++++++++++++++++++++++-
src/resources/history-dialog.ui | 10 +++-
4 files changed, 91 insertions(+), 5 deletions(-)
---
diff --git a/lib/history/ephy-history-service-urls-table.c b/lib/history/ephy-history-service-urls-table.c
index f9d577b..026a116 100644
--- a/lib/history/ephy-history-service-urls-table.c
+++ b/lib/history/ephy-history-service-urls-table.c
@@ -288,6 +288,18 @@ ephy_history_service_find_url_rows (EphyHistoryService *self, EphyHistoryQuery *
case EPHY_HISTORY_SORT_LEAST_RECENTLY_VISITED:
statement_str = g_string_append (statement_str, "ORDER BY urls.last_visit_time ");
break;
+ case EPHY_HISTORY_SORT_TITLE_ASCENDING:
+ statement_str = g_string_append (statement_str, "ORDER BY LOWER(urls.title) ");
+ break;
+ case EPHY_HISTORY_SORT_TITLE_DESCENDING:
+ statement_str = g_string_append (statement_str, "ORDER BY LOWER(urls.title) DESC ");
+ break;
+ case EPHY_HISTORY_SORT_URL_ASCENDING:
+ statement_str = g_string_append (statement_str, "ORDER BY LOWER(urls.url) ");
+ break;
+ case EPHY_HISTORY_SORT_URL_DESCENDING:
+ statement_str = g_string_append (statement_str, "ORDER BY LOWER(urls.url) DESC ");
+ break;
default:
g_warning ("We don't support this sorting method yet.");
}
diff --git a/lib/history/ephy-history-types.h b/lib/history/ephy-history-types.h
index ecfd821..5f5f5fe 100644
--- a/lib/history/ephy-history-types.h
+++ b/lib/history/ephy-history-types.h
@@ -51,7 +51,11 @@ typedef enum {
EPHY_HISTORY_SORT_MOST_RECENTLY_VISITED,
EPHY_HISTORY_SORT_LEAST_RECENTLY_VISITED,
EPHY_HISTORY_SORT_MOST_VISITED,
- EPHY_HISTORY_SORT_LEAST_VISITED
+ EPHY_HISTORY_SORT_LEAST_VISITED,
+ EPHY_HISTORY_SORT_TITLE_ASCENDING,
+ EPHY_HISTORY_SORT_TITLE_DESCENDING,
+ EPHY_HISTORY_SORT_URL_ASCENDING,
+ EPHY_HISTORY_SORT_URL_DESCENDING
} EphyHistorySortType;
typedef struct
diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c
index 03af3c7..9091d5d 100644
--- a/src/ephy-history-window.c
+++ b/src/ephy-history-window.c
@@ -46,7 +46,9 @@ struct _EphyHistoryWindowPrivate
GtkWidget *treeview;
GtkWidget *liststore;
- GtkWidget *date_column;
+ GtkTreeViewColumn *date_column;
+ GtkTreeViewColumn *name_column;
+ GtkTreeViewColumn *location_column;
GtkWidget *date_renderer;
GtkWidget *remove_button;
GtkWidget *open_button;
@@ -58,6 +60,10 @@ struct _EphyHistoryWindowPrivate
GtkWidget *treeview_popup_menu;
char *search_text;
+
+ gboolean sort_ascending;
+ gint sort_column;
+
GtkWidget *window;
GtkWidget *confirmation_dialog;
@@ -138,15 +144,29 @@ filter_now (EphyHistoryWindow *self)
{
gint64 from, to;
GList *substrings;
+ EphyHistorySortType type = EPHY_HISTORY_SORT_MOST_RECENTLY_VISITED;
substrings = substrings_filter (self);
from = to = -1; /* all */
+
+ switch (self->priv->sort_column)
+ {
+ case COLUMN_DATE:
+ type = self->priv->sort_ascending ? EPHY_HISTORY_SORT_LEAST_RECENTLY_VISITED :
EPHY_HISTORY_SORT_MOST_RECENTLY_VISITED;
+ break;
+ case COLUMN_NAME:
+ type = self->priv->sort_ascending ? EPHY_HISTORY_SORT_TITLE_ASCENDING :
EPHY_HISTORY_SORT_TITLE_DESCENDING;
+ break;
+ case COLUMN_LOCATION:
+ type = self->priv->sort_ascending ? EPHY_HISTORY_SORT_URL_ASCENDING :
EPHY_HISTORY_SORT_URL_DESCENDING;
+ break;
+ }
ephy_history_service_find_urls (self->priv->history_service,
from, to,
NUM_RESULTS_LIMIT, 0,
substrings,
- EPHY_HISTORY_SORT_MOST_RECENTLY_VISITED,
+ type,
self->priv->cancellable,
(EphyHistoryJobCallback)on_find_urls_cb, self);
}
@@ -462,6 +482,44 @@ on_treeview_selection_changed (GtkTreeSelection *selection,
}
static void
+on_treeview_column_clicked_event (GtkTreeViewColumn *column,
+ EphyHistoryWindow *self)
+{
+ gint new_sort_column = COLUMN_DATE;
+ GtkTreeViewColumn *previous_sortby;
+
+ if (column == self->priv->date_column)
+ {
+ new_sort_column = COLUMN_DATE;
+ }
+ else if (column == self->priv->name_column)
+ {
+ new_sort_column = COLUMN_NAME;
+ }
+ else if (column == self->priv->location_column)
+ {
+ new_sort_column = COLUMN_LOCATION;
+ }
+
+ if (new_sort_column == self->priv->sort_column)
+ {
+ self->priv->sort_ascending = !(self->priv->sort_ascending);
+ }
+ else
+ {
+ previous_sortby = gtk_tree_view_get_column (GTK_TREE_VIEW (self->priv->treeview),
self->priv->sort_column);
+ gtk_tree_view_column_set_sort_indicator (previous_sortby, FALSE);
+
+ self->priv->sort_column = new_sort_column;
+ self->priv->sort_ascending = self->priv->sort_column == COLUMN_DATE ? FALSE : TRUE;
+ }
+
+ gtk_tree_view_column_set_sort_order (column, self->priv->sort_ascending ? GTK_SORT_ASCENDING :
GTK_SORT_DESCENDING);
+ gtk_tree_view_column_set_sort_indicator (column, TRUE);
+ filter_now (self);
+}
+
+static void
on_remove_button_clicked (GtkButton *button,
EphyHistoryWindow *self)
{
@@ -616,6 +674,8 @@ ephy_history_window_class_init (EphyHistoryWindowClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, EphyHistoryWindow, remove_button);
gtk_widget_class_bind_template_child_private (widget_class, EphyHistoryWindow, open_button);
gtk_widget_class_bind_template_child_private (widget_class, EphyHistoryWindow, date_column);
+ gtk_widget_class_bind_template_child_private (widget_class, EphyHistoryWindow, name_column);
+ gtk_widget_class_bind_template_child_private (widget_class, EphyHistoryWindow, location_column);
gtk_widget_class_bind_template_child_private (widget_class, EphyHistoryWindow, date_renderer);
gtk_widget_class_bind_template_child_private (widget_class, EphyHistoryWindow, open_menuitem);
gtk_widget_class_bind_template_child_private (widget_class, EphyHistoryWindow,
copy_location_menuitem);
@@ -627,6 +687,7 @@ ephy_history_window_class_init (EphyHistoryWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, on_treeview_key_press_event);
gtk_widget_class_bind_template_callback (widget_class, on_treeview_button_press_event);
gtk_widget_class_bind_template_callback (widget_class, on_treeview_selection_changed);
+ gtk_widget_class_bind_template_callback (widget_class, on_treeview_column_clicked_event);
gtk_widget_class_bind_template_callback (widget_class, on_remove_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_open_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_search_entry_changed);
@@ -718,6 +779,9 @@ ephy_history_window_init (EphyHistoryWindow *self)
self->priv->cancellable = g_cancellable_new ();
+ self->priv->sort_ascending = FALSE;
+ self->priv->sort_column = COLUMN_DATE;
+
ephy_gui_ensure_window_group (GTK_WINDOW (self));
gtk_tree_view_column_set_cell_data_func (GTK_TREE_VIEW_COLUMN (self->priv->date_column),
diff --git a/src/resources/history-dialog.ui b/src/resources/history-dialog.ui
index bbf3cd9..e793425 100644
--- a/src/resources/history-dialog.ui
+++ b/src/resources/history-dialog.ui
@@ -127,8 +127,10 @@
<property name="sizing">fixed</property>
<property name="fixed-width">150</property>
<property name="title" translatable="yes">Date</property>
+ <property name="clickable">True</property>
<property name="sort_indicator">True</property>
<property name="sort_order">descending</property>
+ <signal name="clicked" handler="on_treeview_column_clicked_event"
object="EphyHistoryWindow" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="date_renderer"/>
<attributes>
@@ -138,10 +140,12 @@
</object>
</child>
<child>
- <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+ <object class="GtkTreeViewColumn" id="name_column">
<property name="sizing">fixed</property>
<property name="fixed-width">500</property>
<property name="title" translatable="yes">Name</property>
+ <property name="clickable">True</property>
+ <signal name="clicked" handler="on_treeview_column_clicked_event"
object="EphyHistoryWindow" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2">
<property name="ellipsize">end</property>
@@ -154,9 +158,11 @@
</child>
<child>
<object class="GtkTreeViewColumn" id="location_column">
- <property name="sizing">fixed</property>
+ <property name="sizing">fixed</property>
<property name="fixed-width">200</property>
<property name="title" translatable="yes">Location</property>
+ <property name="clickable">True</property>
+ <signal name="clicked" handler="on_treeview_column_clicked_event"
object="EphyHistoryWindow" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="location_renderer">
<property name="ellipsize">end</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]