[tracker/needle: 37/43] tracker-needle: Added a spinner to indicate when searching
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/needle: 37/43] tracker-needle: Added a spinner to indicate when searching
- Date: Tue, 28 Sep 2010 20:27:18 +0000 (UTC)
commit 43d324e858fb1d562e7eb229136742001cb199e2
Author: Martyn Russell <martyn lanedo com>
Date: Fri Sep 10 00:17:18 2010 +0100
tracker-needle: Added a spinner to indicate when searching
Using while(yield cursor.next()) {} seems to cause a crash here
so currently operations are not totally async so the spinner isn't
seen unless left running and shown
src/tracker-needle/tracker-needle.ui | 31 ++++++++++----
src/tracker-needle/tracker-needle.vala | 72 +++++++++++++++++++------------
src/tracker-needle/tracker-query.vala | 4 +-
3 files changed, 69 insertions(+), 38 deletions(-)
---
diff --git a/src/tracker-needle/tracker-needle.ui b/src/tracker-needle/tracker-needle.ui
index afce65b..3cf7ca4 100644
--- a/src/tracker-needle/tracker-needle.ui
+++ b/src/tracker-needle/tracker-needle.ui
@@ -2,7 +2,6 @@
<interface>
<!-- interface-requires gtk+ 2.12 -->
<!-- interface-naming-policy project-wide -->
- <object class="GtkListStore" id="liststore_results"/>
<object class="GtkWindow" id="window_needle">
<property name="title" translatable="yes">Needle</property>
<property name="default_width">640</property>
@@ -110,10 +109,8 @@
<child>
<object class="GtkLabel" id="label_search">
<property name="visible">True</property>
- <property name="xpad">4</property>
<property name="label" translatable="yes">_Search:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">entry_search</property>
</object>
</child>
</object>
@@ -127,12 +124,18 @@
<property name="visible">True</property>
<property name="is_important">True</property>
<child>
- <object class="GtkEntry" id="entry_search">
+ <object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="has_focus">True</property>
- <property name="invisible_char">●</property>
- <property name="activates_default">True</property>
+ <property name="left_padding">4</property>
+ <property name="right_padding">4</property>
+ <child>
+ <object class="GtkEntry" id="entry_search">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property name="activates_default">True</property>
+ </object>
+ </child>
</object>
</child>
</object>
@@ -142,6 +145,18 @@
</packing>
</child>
<child>
+ <object class="GtkToolItem" id="toolcustom_spinner">
+ <property name="border_width">8</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkSeparatorToolItem" id="<separator>1">
<property name="visible">True</property>
</object>
diff --git a/src/tracker-needle/tracker-needle.vala b/src/tracker-needle/tracker-needle.vala
index 2795714..e17ac93 100644
--- a/src/tracker-needle/tracker-needle.vala
+++ b/src/tracker-needle/tracker-needle.vala
@@ -37,6 +37,8 @@ public class TrackerNeedle {
private ToggleToolButton find_in_contents;
private ToggleToolButton find_in_titles;
private Entry search;
+ private Spinner spinner;
+ private ToolItem spinner_shell;
private ToolButton show_stats;
private HBox view;
private Tracker.View sw_noresults;
@@ -107,26 +109,28 @@ public class TrackerNeedle {
search = builder.get_object ("entry_search") as Entry;
search.changed.connect (search_changed);
+ spinner = new Spinner ();
+ spinner_shell = builder.get_object ("toolcustom_spinner") as ToolItem;
+ spinner_shell.add (spinner);
+
show_stats = builder.get_object ("toolbutton_show_stats") as ToolButton;
show_stats.clicked.connect (show_stats_clicked);
view = builder.get_object ("hbox_view") as HBox;
+ // Set up views
sw_noresults = new Tracker.View (Tracker.View.Display.NO_RESULTS);
view.pack_start (sw_noresults, true, true, 0);
sw_treeview = new Tracker.View (Tracker.View.Display.CATEGORIES);
treeview = (TreeView) sw_treeview.get_child ();
view.pack_start (sw_treeview, true, true, 0);
- //sw_treeview = builder.get_object ("scrolledwindow_treeview") as ScrolledWindow;
- //treeview = builder.get_object ("treeview_results") as TreeView;
sw_iconview = new Tracker.View (Tracker.View.Display.FILE_ICONS);
iconview = (IconView) sw_iconview.get_child ();
view.pack_start (sw_iconview, true, true, 0);
- //sw_iconview = builder.get_object ("scrolledwindow_iconview") as ScrolledWindow;
- //iconview = builder.get_object ("iconview_results") as IconView;
-
+
+ // Set up view models
setup_ui_results (treeview, iconview);
view_details.set_active (true);
@@ -248,31 +252,31 @@ public class TrackerNeedle {
last_search_id = Timeout.add_seconds (1, search_run);
}
- private void search_simple () {
+ private async void search_simple () {
Tracker.Query query = new Tracker.Query ();
Tracker.Sparql.Cursor cursor = null;
query.limit = 100;
query.criteria = search.get_text ();
- if (find_in_contents.active) {
- cursor = query.perform (query.Type.ALL);
- } else {
- cursor = query.perform (query.Type.ALL_ONLY_IN_TITLES);
- }
+ try {
+ if (find_in_contents.active) {
+ cursor = yield query.perform_async (query.Type.ALL);
+ } else {
+ cursor = yield query.perform_async (query.Type.ALL_ONLY_IN_TITLES);
+ }
- if (cursor == null) {
- // FIXME: Print "no results" some where
- return;
- }
+ if (cursor == null) {
+ // FIXME: Print "no results" some where
+ return;
+ }
- store.clear ();
+ store.clear ();
- var screen = window.get_screen ();
- var theme = IconTheme.get_for_screen (screen);
+ var screen = window.get_screen ();
+ var theme = IconTheme.get_for_screen (screen);
- try {
- while (cursor.next()) {
+ while (cursor.next ()) {
int i;
for (i = 0; i < cursor.n_columns; i++) {
@@ -318,7 +322,7 @@ public class TrackerNeedle {
}
}
- private void search_detailed () {
+ private async void search_detailed () {
Tracker.Query.Type[] categories = {
Tracker.Query.Type.APPLICATIONS,
Tracker.Query.Type.MUSIC,
@@ -342,15 +346,15 @@ public class TrackerNeedle {
query.limit = 100;
query.criteria = search.get_text ();
- cursor = query.perform (type);
+ try {
+ cursor = yield query.perform_async (type);
- if (cursor == null) {
- // FIXME: Print "no results" some where
- return;
- }
+ if (cursor == null) {
+ // FIXME: Print "no results" some where
+ return;
+ }
- try {
- while (cursor.next()) {
+ while (cursor.next ()) {
int i;
for (i = 0; i < cursor.n_columns; i++) {
@@ -453,6 +457,10 @@ public class TrackerNeedle {
sw_iconview.hide ();
sw_treeview.hide ();
+ // Hide spinner
+ spinner.stop ();
+ spinner_shell.hide ();
+
return false;
}
@@ -469,12 +477,20 @@ public class TrackerNeedle {
sw_treeview.hide ();
}
+ // Show spinner
+ spinner_shell.show_all ();
+ spinner.start ();
+
if (view_details.active) {
search_detailed ();
} else {
search_simple ();
}
+ // Hide spinner
+ spinner.stop ();
+ spinner_shell.hide ();
+
return false;
}
diff --git a/src/tracker-needle/tracker-query.vala b/src/tracker-needle/tracker-query.vala
index 00421aa..6bc3419 100644
--- a/src/tracker-needle/tracker-query.vala
+++ b/src/tracker-needle/tracker-query.vala
@@ -48,7 +48,7 @@ public class Tracker.Query {
}
}
- public Sparql.Cursor? perform (Type query_type)
+ public async Sparql.Cursor? perform_async (Type query_type, Cancellable? cancellable = null) throws IOError
requires (connection != null) {
Sparql.Cursor cursor = null;
@@ -186,7 +186,7 @@ public class Tracker.Query {
debug ("Running query: '%s'", query);
try {
- cursor = connection.query (query, null);
+ cursor = yield connection.query_async (query, null);
} catch (Sparql.Error ea) {
warning ("Could not run Sparql query: %s", ea.message);
} catch (GLib.IOError eb) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]