diff options
| author | Neil Jagdish Patel <neil.patel@canonical.com> | 2010-08-24 14:31:11 +0100 |
|---|---|---|
| committer | Neil Jagdish Patel <neil.patel@canonical.com> | 2010-08-24 14:31:11 +0100 |
| commit | d2c37dbd51928997535f4d859685e69b025e96d0 (patch) | |
| tree | 9aef53b2de987b75c638b43609d950a87b4260ef /unity-private | |
| parent | cb4aea0864d818bcccc1f59738d2a822293bf78c (diff) | |
| parent | 0f37f74e1dffecaa86333b24efce01a1e4640f50 (diff) | |
[merge] Async PlaceEntries and Browsing
(bzr r454)
Diffstat (limited to 'unity-private')
| -rw-r--r-- | unity-private/places/places-place-entry.vala | 33 | ||||
| -rw-r--r-- | unity-private/places/places-place-search-navigation.vala | 77 | ||||
| -rw-r--r-- | unity-private/places/places-place.vala | 86 |
3 files changed, 127 insertions, 69 deletions
diff --git a/unity-private/places/places-place-entry.vala b/unity-private/places/places-place-entry.vala index 14c588437..b11657fe7 100644 --- a/unity-private/places/places-place-entry.vala +++ b/unity-private/places/places-place-entry.vala @@ -68,6 +68,15 @@ namespace Unity.Places HashTable<string, string> hints); } + [DBus (name = "com.canonical.Unity.PlaceEntry")] + public interface PlaceEntryRemote : Object + { + public abstract async void set_global_search (string search_string, + HashTable<string, string>hints) throws DBus.Error; + public abstract async void set_active_section (uint32 section) throws DBus.Error; + public abstract async void set_search (string search, HashTable<string, string>hints) throws DBus.Error; + public abstract async void set_active (bool is_active) throws DBus.Error; + } /** * Represents a PlaceEntry through a .place file ("offline") and then through @@ -139,7 +148,7 @@ namespace Unity.Places if (_active != value) { _active = value; - service.set_active (_active); + remote.set_active.begin (_active); } } } @@ -258,6 +267,7 @@ namespace Unity.Places /* Our connection to the place-entry over dbus */ private DBus.Connection? connection; private dynamic DBus.Object? service; + private PlaceEntryRemote remote; /* * Signals @@ -387,9 +397,24 @@ namespace Unity.Places /* Grab the entry off DBus */ try { connection = DBus.Bus.get (DBus.BusType.SESSION); + remote = (PlaceEntryRemote) connection.get_object (dbus_name, + dbus_path, + "com.canonical.Unity.PlaceEntry"); + + /* FIXME: Kill vala. + * The reason we need both objects is because the former cannot + * marshall the struct within a struct of PlaceEntryInfoChanged signal + * but it can to async methods. + * The dynamic 'service' object can do the signals (though it returns + * a ValueArray, but not the async stuff. + * + * So basically we need both right now and every new place kills a + * thousand kittens. + */ service = connection.get_object (dbus_name, dbus_path, "com.canonical.Unity.PlaceEntry"); + } catch (Error e) { warning (@"Unable to connect to $dbus_path on $dbus_name: %s", e.message); @@ -404,18 +429,18 @@ namespace Unity.Places public void set_search (string search, HashTable<string, string> hints) { - service.set_search (search, hints); + remote.set_search.begin (search, hints); } public void set_active_section (uint section_id) { - service.set_active_section (section_id); + remote.set_active_section.begin (section_id); } public void set_global_search (string search, HashTable<string, string> hints) { - service.set_global_search (search, hints); + remote.set_global_search.begin (search, hints); } /* diff --git a/unity-private/places/places-place-search-navigation.vala b/unity-private/places/places-place-search-navigation.vala index fc951349c..adab1d125 100644 --- a/unity-private/places/places-place-search-navigation.vala +++ b/unity-private/places/places-place-search-navigation.vala @@ -21,6 +21,20 @@ using Unity; namespace Unity.Places { + [DBus (name = "com.canonical.Unity.PlaceBrowser")] + public interface PlaceBrowserRemote : Object + { + public struct State + { + bool sensitive; + string tooltip; + } + + public abstract async State[] get_state () throws DBus.Error; + public abstract async State[] go_back () throws DBus.Error; + public abstract async State[] go_forward () throws DBus.Error; + } + public class PlaceSearchNavigation : Ctk.Box { static const int SPACING = 1; @@ -36,7 +50,7 @@ namespace Unity.Places private Ctk.EffectGlow glow; - private dynamic DBus.Object service; + private PlaceBrowserRemote remote; public PlaceSearchNavigation () { @@ -47,21 +61,12 @@ namespace Unity.Places construct { - /* - padding = { - SPACING * 2.0f, - SPACING * 1.0f, - SPACING * 1.0f, - SPACING * 1.0f - };*/ - back = new CairoCanvas (draw_back_arrow); back.reactive = true; back.button_release_event.connect (() => { - if (service != null && back_sensitive) + if (remote != null && back_sensitive) { - ValueArray[] a = service.go_back (); - refresh_state (a); + go_back.begin (); } return true; @@ -71,10 +76,9 @@ namespace Unity.Places forward = new CairoCanvas (draw_forward_arrow); forward.button_release_event.connect (() => { - if (service != null && forward_sensitive) + if (remote != null && forward_sensitive) { - ValueArray[] a = service.go_back (); - refresh_state (a); + go_forward.begin (); } return true; }); @@ -91,7 +95,7 @@ namespace Unity.Places public void set_active_entry (PlaceEntry entry) { active_entry = null; - service = null; + remote = null; if (entry.hints == null) { @@ -107,11 +111,10 @@ namespace Unity.Places { try { var connection = DBus.Bus.get (DBus.BusType.SESSION); - service = connection.get_object (entry.parent.dbus_name, + remote = (PlaceBrowserRemote)connection.get_object (entry.parent.dbus_name, path, "com.canonical.Unity.PlaceBrowser"); - ValueArray[] entries = service.get_state (); - refresh_state (entries); + refresh_states.begin (); } catch (Error e) { warning (@"Unable to connect to $path: %s", @@ -133,15 +136,37 @@ namespace Unity.Places glow.set_invalidate_effect_cache (true); } - private void refresh_state (ValueArray[] entries) + private async void refresh_states () { - unowned ValueArray array; - - array = entries[0]; - back_sensitive = array.get_nth (0).get_boolean (); + try { + var states = yield remote.get_state (); + back_sensitive = states[0].sensitive; + forward_sensitive = states[1].sensitive; + } catch (DBus.Error e) { + warning (@"Unable to refresh browser navigation state: $(e.message)"); + } + } + + private async void go_forward () + { + try { + var states = yield remote.go_forward (); + back_sensitive = states[0].sensitive; + forward_sensitive = states[1].sensitive; + } catch (DBus.Error e) { + warning (@"Unable to go forward in browser view: $(e.message)"); + } + } - array = entries[1]; - forward_sensitive = array.get_nth (0).get_boolean (); + private async void go_back () + { + try { + var states = yield remote.go_back (); + back_sensitive = states[0].sensitive; + forward_sensitive = states[1].sensitive; + } catch (DBus.Error e) { + warning (@"Unable to go back in browser view: $(e.message)"); + } } private override void get_preferred_width (float for_height, diff --git a/unity-private/places/places-place.vala b/unity-private/places/places-place.vala index 599d74b40..a1c696093 100644 --- a/unity-private/places/places-place.vala +++ b/unity-private/places/places-place.vala @@ -159,46 +159,54 @@ namespace Unity.Places service.EntryRemoved.connect (on_service_entry_removed); /* Make sure our entries are up-to-date */ - ValueArray[] entries = service.get_entries (); - for (int i = 0; i < entries.length; i++) - { - unowned ValueArray array = entries[i]; - var path = array.get_nth (0).get_string (); - bool existing = false; - - foreach (PlaceEntry e in entries_array) - { - var entry = e as PlaceEntryDbus; - if (entry.dbus_path == path) - { - entry.update_info (array); - entry.connect (); - entry.parent = this; - existing = true; - } - } - - if (existing == false) - { - on_service_entry_added (service, array); - } - } - - /* Now remove those that couldn't connect or did not exist in the live - * place + /* FIXME: In a world without Vala this would be async, however due to + * it's troubles with marshalling complex types (which I concede cannot + * be easy), we need to do a poor-mans async and call it in an idle + * instead. */ - /* FIXME: Make this cleaner */ - ArrayList<PlaceEntry> old = new ArrayList<PlaceEntry> (); - foreach (PlaceEntry entry in entries_array) - { - if (entry.online == false) - old.add (entry); - } - foreach (PlaceEntry entry in old) - { - entry_removed (entry); - entries_array.remove (entry); - } + Idle.add (() => { + ValueArray[] entries = service.get_entries (); + for (int i = 0; i < entries.length; i++) + { + unowned ValueArray array = entries[i]; + var path = array.get_nth (0).get_string (); + bool existing = false; + + foreach (PlaceEntry e in entries_array) + { + var entry = e as PlaceEntryDbus; + if (entry.dbus_path == path) + { + entry.update_info (array); + entry.connect (); + entry.parent = this; + existing = true; + } + } + + if (existing == false) + { + on_service_entry_added (service, array); + } + } + + /* Now remove those that couldn't connect or did not exist in the live + * place + */ + /* FIXME: Make this cleaner */ + ArrayList<PlaceEntry> old = new ArrayList<PlaceEntry> (); + foreach (PlaceEntry entry in entries_array) + { + if (entry.online == false) + old.add (entry); + } + foreach (PlaceEntry entry in old) + { + entry_removed (entry); + entries_array.remove (entry); + } + return false; + }); online = true; } |
