[gnome-clocks] Sort locations by timezone
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Sort locations by timezone
- Date: Sun, 27 Jul 2014 08:49:12 +0000 (UTC)
commit 29ceb12dd50d6e17bd9cee6f713617979eea00d1
Author: Mike Gorse <mgorse suse com>
Date: Wed Jul 23 12:22:51 2014 -0500
Sort locations by timezone
https://bugzilla.gnome.org/show_bug.cgi?id=701169
src/widgets.vala | 16 ++++++++++++++++
src/world.vala | 9 +++++++++
2 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/src/widgets.vala b/src/widgets.vala
index 9ff2820..dba08d2 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -647,6 +647,22 @@ public class ContentView : Gtk.Bin {
break;
}
}
+
+ public delegate int SortFunc(ContentItem item1, ContentItem item2);
+
+ public void set_sorting(Gtk.SortType sort_type, SortFunc sort_func) {
+ var sortable = icon_view.get_model () as Gtk.TreeSortable;
+ sortable.set_sort_column_id (1, sort_type);
+ sortable.set_sort_func (1, (model, iter1, iter2) => {
+ ContentItem item1;
+ ContentItem item2;
+
+ model.get (iter1, IconView.Column.ITEM, out item1);
+ model.get (iter2, IconView.Column.ITEM, out item2);
+
+ return sort_func (item1, item2);
+ });
+ }
}
public class AmPmToggleButton : Gtk.Button {
diff --git a/src/world.vala b/src/world.vala
index d73daa1..0fb9ce0 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -294,6 +294,15 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
var builder = Utils.load_ui ("world.ui");
var empty_view = builder.get_object ("empty_panel") as Gtk.Widget;
content_view = new ContentView (empty_view, header_bar);
+ content_view.set_sorting(Gtk.SortType.ASCENDING, (item1, item2) => {
+ var offset1 = ((Item) item1).location.get_timezone().get_offset();
+ var offset2 = ((Item) item2).location.get_timezone().get_offset();
+ if (offset1 < offset2)
+ return -1;
+ if (offset1 > offset2)
+ return 1;
+ return 0;
+ });
add (content_view);
content_view.item_activated.connect ((item) => {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]