[tracker/tracker-needle-improved-tagging: 6/6] WIP
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-needle-improved-tagging: 6/6] WIP
- Date: Mon, 19 Sep 2011 14:37:08 +0000 (UTC)
commit 026353dd11b7c1fdf74e36fa2fe2588985541a40
Author: Martyn Russell <martyn lanedo com>
Date: Mon Sep 19 15:35:15 2011 +0100
WIP
src/tracker-needle/Makefile.am | 1 +
src/tracker-needle/tracker-taglist.vala | 2 +-
src/tracker-needle/tracker-tagmenu.vala | 178 +++++++++++++++++++++++++++++++
src/tracker-needle/tracker-view.vala | 11 +-
4 files changed, 186 insertions(+), 6 deletions(-)
---
diff --git a/src/tracker-needle/Makefile.am b/src/tracker-needle/Makefile.am
index 5dbc7eb..01bfe28 100644
--- a/src/tracker-needle/Makefile.am
+++ b/src/tracker-needle/Makefile.am
@@ -30,6 +30,7 @@ tracker_needle_SOURCES = \
tracker-result-store.vala \
tracker-stats.vala \
tracker-taglist.vala \
+ tracker-tagmenu.vala \
tracker-utils.vala \
tracker-needle.vala \
tracker-view.vala
diff --git a/src/tracker-needle/tracker-taglist.vala b/src/tracker-needle/tracker-taglist.vala
index c5c9796..6f8c328 100644
--- a/src/tracker-needle/tracker-taglist.vala
+++ b/src/tracker-needle/tracker-taglist.vala
@@ -20,7 +20,7 @@
using Gtk;
public class Tracker.TagList : ScrolledWindow {
- static Sparql.Connection connection;
+ private static Sparql.Connection connection;
private TreeView treeview;
private ListStore store;
private int offset;
diff --git a/src/tracker-needle/tracker-tagmenu.vala b/src/tracker-needle/tracker-tagmenu.vala
new file mode 100644
index 0000000..b247ce7
--- /dev/null
+++ b/src/tracker-needle/tracker-tagmenu.vala
@@ -0,0 +1,178 @@
+//
+// Copyright 2010, Martyn Russell <martyn lanedo com>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301, USA.
+//
+
+using Gtk;
+
+public class Tracker.TagMenu : Menu {
+ private static Sparql.Connection connection;
+ private int offset;
+ private int limit;
+
+ public enum Type {
+ NONE,
+ ADD,
+ REMOVE
+ }
+
+ public Type menu_type { get; set; }
+ public GenericArray<string> tags { get; private set; }
+
+ public signal void selection_changed (GenericArray<string> new_tags);
+
+ public TagMenu (Type type) {
+ menu_type = type;
+ limit = 100;
+
+ tags = new GenericArray<string> ();
+
+ // Add data
+ try {
+ connection = Sparql.Connection.get ();
+ } catch (GLib.Error e) {
+ warning ("Could not get Sparql connection: %s", e.message);
+ return;
+ }
+
+ query_get_tags.begin ();
+ }
+
+ private async void query_get_tags () {
+ string query = null;
+
+ switch (menu_type) {
+ case Type.NONE:
+ query = @"
+ SELECT
+ ?tag
+ ?label
+ nao:description(?tag)
+ COUNT(?urns) AS urns
+ WHERE {
+ ?tag a nao:Tag ;
+ nao:prefLabel ?label .
+ OPTIONAL {
+ ?urns nao:hasTag ?tag
+ }
+ }
+ GROUP BY ?tag
+ ORDER BY ASC(?label)
+ OFFSET $offset
+ LIMIT $limit
+ ";
+ break;
+ case Type.Add:
+ query = @"
+ SELECT
+ ?tag
+ ?label
+ nao:description(?tag)
+ COUNT(?urns) AS urns
+ WHERE {
+ ?tag a nao:Tag ;
+ nao:prefLabel ?label .
+ OPTIONAL {
+ ?urns nao:hasTag ?tag
+ }
+ }
+ GROUP BY ?tag
+ ORDER BY ASC(?label)
+ OFFSET $offset
+ LIMIT $limit
+ ";
+ break;
+ case Type.Remove:
+ break;
+ }
+
+ debug ("Getting tags");
+
+ Sparql.Cursor cursor = null;
+
+ // First clear all existing menu items
+ ((Container) base).forall (w => {
+ base.remove (w);
+ });
+
+ int count = 0;
+
+ try {
+ cursor = yield connection.query_async (query, null);
+
+ while (yield cursor.next_async ()) {
+ for (int i = 0; i < cursor.n_columns; i++) {
+ if (i == 0) {
+ debug ("--> %s", cursor.get_string (i));
+ } else {
+ debug (" --> %s", cursor.get_string (i));
+ }
+ }
+
+ var item = new MenuItem.with_label (cursor.get_string (1));
+ item.activate.connect (menu_tag_clicked);
+ base.append (item);
+
+ count++;
+ }
+ } catch (GLib.Error e) {
+ warning ("Could not run Sparql query: %s", e.message);
+ }
+
+ debug (" Done");
+
+ if (count > 1) {
+ switch (menu_type) {
+ case Type.NONE:
+ break;
+ case Type.ADD:
+ case Type.REMOVE:
+ var separator = new SeparatorMenuItem ();
+ base.append (separator);
+
+ MenuItem last_item;
+
+ if (menu_type == Type.ADD) {
+ last_item = new MenuItem.with_mnemonic (_("_Add New..."));
+ last_item.activate.connect (menu_tag_add_new_clicked);
+ } else {
+ last_item = new MenuItem.with_mnemonic (_("_Remove All"));
+ last_item.activate.connect (menu_tag_remove_all_clicked);
+ }
+
+ base.append (last_item);
+ break;
+ }
+
+ base.show_all ();
+ }
+ }
+
+ private void menu_tag_clicked () {
+ warning ("Not yet implemented");
+ }
+
+ private void menu_tag_add_new_clicked () {
+ warning ("Not yet implemented");
+ }
+
+ private void menu_tag_remove_all_clicked () {
+ warning ("Not yet implemented");
+ }
+
+}
+
diff --git a/src/tracker-needle/tracker-view.vala b/src/tracker-needle/tracker-view.vala
index 0c51af3..fb4b40c 100644
--- a/src/tracker-needle/tracker-view.vala
+++ b/src/tracker-needle/tracker-view.vala
@@ -453,13 +453,15 @@ public class Tracker.View : ScrolledWindow {
context_menu.append (separator);
item = new MenuItem.with_mnemonic (_("_Add Tag..."));
- item.activate.connect (context_menu_tag_add_clicked);
- item.sensitive = false;
+ //item.activate.connect (context_menu_tag_add_clicked);
+ //tem.sensitive = false;
+ item.set_submenu (new TagMenu (TagMenu.Type.ADD));
context_menu.append (item);
item = new MenuItem.with_mnemonic (_("_Remove Tag..."));
- item.activate.connect (context_menu_tag_remove_clicked);
- item.sensitive = false;
+ //item.activate.connect (context_menu_tag_remove_clicked);
+ //item.sensitive = false;
+ item.set_submenu (new TagMenu (TagMenu.Type.REMOVE));
context_menu.append (item);
context_menu.show_all ();
@@ -529,5 +531,4 @@ public class Tracker.View : ScrolledWindow {
private void context_menu_tag_remove_clicked () {
warning ("Not yet implemented");
}
-
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]