Merge lp:~unity-team/unity/unity-lens.to.scope into lp:unity
- unity-lens.to.scope
- Merge into trunk
Status: | Work in progress |
---|---|
Proposed branch: | lp:~unity-team/unity/unity-lens.to.scope |
Merge into: | lp:unity |
Diff against target: |
8181 lines (+4339/-860) 99 files modified
UnityCore/CMakeLists.txt (+12/-7) UnityCore/Categories.cpp (+1/-0) UnityCore/Category.cpp (+13/-3) UnityCore/Category.h (+2/-1) UnityCore/FilesystemLenses.cpp (+4/-5) UnityCore/Filter.cpp (+21/-0) UnityCore/Filter.h (+2/-0) UnityCore/Filters.cpp (+6/-1) UnityCore/GLibWrapper.cpp (+1/-5) UnityCore/GLibWrapper.h (+9/-0) UnityCore/GSettingsScopes.cpp (+171/-0) UnityCore/GSettingsScopes.h (+56/-0) UnityCore/MiscUtils.h (+118/-0) UnityCore/Model-inl.h (+55/-23) UnityCore/Model.h (+12/-5) UnityCore/MusicPreview.cpp (+14/-2) UnityCore/Preview.cpp (+26/-21) UnityCore/Preview.h (+8/-8) UnityCore/Result.cpp (+25/-7) UnityCore/Result.h (+4/-2) UnityCore/Results.cpp (+1/-0) UnityCore/Scope.cpp (+211/-0) UnityCore/Scope.h (+105/-0) UnityCore/ScopeData.cpp (+89/-0) UnityCore/ScopeData.h (+68/-0) UnityCore/ScopeProxy.cpp (+804/-0) UnityCore/ScopeProxy.h (+57/-0) UnityCore/ScopeProxyInterface.h (+96/-0) UnityCore/Scopes.cpp (+271/-0) UnityCore/Scopes.h (+94/-0) UnityCore/SeriesPreview.cpp (+11/-11) UnityCore/Tracks.cpp (+2/-1) UnityCore/Variant.cpp (+41/-1) UnityCore/Variant.h (+2/-0) com.canonical.Unity.gschema.xml (+10/-0) dash/DashController.cpp (+3/-3) dash/DashView.cpp (+162/-207) dash/DashView.h (+20/-22) dash/DashViewPrivate.cpp (+2/-2) dash/DashViewPrivate.h (+3/-1) dash/FilterBar.cpp (+12/-5) dash/FilterBar.h (+1/-0) dash/FilterRatingsButton.cpp (+1/-1) dash/LensBar.cpp (+41/-55) dash/LensBar.h (+12/-11) dash/LensBarIcon.cpp (+9/-9) dash/LensBarIcon.h (+4/-4) dash/LensView.cpp (+207/-173) dash/LensView.h (+27/-16) dash/PlacesGroup.h (+1/-1) dash/PreviewStateMachine.cpp (+1/-1) dash/PreviewStateMachine.h (+1/-1) dash/ResultRenderer.cpp (+2/-2) dash/ResultRenderer.h (+2/-2) dash/ResultRendererTile.cpp (+13/-8) dash/ResultRendererTile.h (+5/-5) dash/ResultView.cpp (+19/-38) dash/ResultView.h (+6/-7) dash/ResultViewGrid.cpp (+2/-2) dash/ResultViewGrid.h (+0/-1) dash/previews/DBusTestRunner.h (+0/-1) dash/previews/LensDBusTestRunner.h (+10/-9) dash/previews/StandaloneMusicPreview.cpp (+2/-2) launcher/BFBLauncherIcon.cpp (+11/-11) launcher/BFBLauncherIcon.h (+3/-3) launcher/LauncherController.cpp (+1/-1) plugins/unityshell/src/unityshell.cpp (+1/-1) tests/CMakeLists.txt (+17/-7) tests/autopilot/unity/emulators/dash.py (+15/-15) tests/autopilot/unity/tests/test_command_lens.py (+2/-2) tests/autopilot/unity/tests/test_dash.py (+9/-15) tests/data/unity/scopes/testscope1.scope (+13/-0) tests/data/unity/scopes/testscope2.scope (+13/-0) tests/data/unity/scopes/testscope3.scope (+13/-0) tests/data/unity/scopes/testscope4.scope (+13/-0) tests/test_categories.cpp (+11/-6) tests/test_dashview.cpp (+55/-0) tests/test_dashview_impl.cpp (+6/-6) tests/test_gsettings_scopes.cpp (+191/-0) tests/test_hud_view.cpp (+1/-0) tests/test_lensview.cpp (+17/-17) tests/test_main.cpp (+6/-2) tests/test_main_dbus.cpp (+4/-0) tests/test_main_xless.cpp (+6/-0) tests/test_mock_scope.h (+142/-0) tests/test_model_iterator.cpp (+8/-3) tests/test_result_renderer.cpp (+1/-1) tests/test_results.cpp (+0/-1) tests/test_resultviewgrid.cpp (+1/-1) tests/test_scope.cpp (+120/-0) tests/test_scope_bar.cpp (+138/-0) tests/test_scope_proxy.cpp (+197/-0) tests/test_searchbar.cpp (+0/-63) tests/test_service_main.c (+4/-4) tests/test_service_model.c (+17/-7) tests/test_service_scope.c (+245/-0) tests/test_service_scope.h (+66/-0) unity-shared/DashStyle.cpp (+1/-1) unity-shared/DashStyle.h (+1/-1) |
To merge this branch: | bzr merge lp:~unity-team/unity/unity-lens.to.scope |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity Team | Pending | ||
Review via email: mp+143922@code.launchpad.net |
Commit message
Description of the change
.
- 3010. By Nick Dedekind
-
more cleanup
- 3011. By Nick Dedekind
-
Reverted ModelIterator to ResultIterator
- 3012. By Nick Dedekind
-
Reverted more unnecessary changes.
- 3013. By Nick Dedekind
-
removed filter_update for changes in libunity
- 3014. By Nick Dedekind
-
Merged with trunk
- 3015. By Nick Dedekind
-
Fixed 64bit size_t->unsigned int conversion.
- 3016. By Nick Dedekind
-
Connected up client filter updates to scope backend.
- 3017. By Nick Dedekind
-
more 64bit fixes
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
320 +// wrapper for raw const gchar*. non-deleteable.
321 +class StringRef : boost::noncopyable
I also wanted to do this before, but I always been suggested to instead just add a function into the glib namespace that takes a gchar* returning a std::string with just a null-check on it...
Michal Hruby (mhr3) wrote : | # |
+++ UnityCore/
@@ -70,7 +71,12 @@
+ else
+ g_assert(false);
Nasty, LOG_ERROR() pls.
@@ -81,7 +87,12 @@
+ else
+ g_assert(false);
Same as above
+++ UnityCore/
@@ -229,7 +229,12 @@
+ else
+ g_assert(false);
Same
+++ UnityCore/
+ if (error)
+ {
+ data->id = scope_id;
+ LOG_DEBUG(logger) << "Error fetching metadata for scope: " << scope_id << " : " << error.Message();
+ }
This is pretty serious error, perhaps propagate it to the caller? If a .scope file can't be found proxy can't be created and therefore it doesn't even make sense to try to display an icon for the .scope file. Bottom line - invalid scope ids should be completely ignored (and LOG_WARNed)
+void ScopeProxy:
+{
+ scope_proxy_
+ if (cancel_scope_)
+ {
+ g_cancellable_
+ cancel_scope_ = g_cancellable_
+ }
+ cancel_scope_ = g_cancellable_
Why the double creation?
+void ScopeProxy:
+{
+ LOG_WARNING(logger) << "Channels for scope '" << scope_data_
+ DestroyProxy();
+ CreateProxy();
+}
Shouldn't be needed, UnityProtocolSc
+GHashTable* hashtable_
+{
+ if (!hash_table)
+ return nullptr;
+
+ for (glib::
+ {
+ gchar* key = g_strdup(
+ GVariant* ptr = g_variant_
+
+ g_hash_
+ }
+ return hash_table;
+}
Too easy to get wrong, the passed hashtable needs to have key_destroy_func set to g_free and value_destroy_func to g_variant_unref. Perhaps just return a hash table without making it an in param?
+++ UnityCore/
+ GHashTable* hints_table = glib::hashtable
The poor hashtable is leaking, the proxy doesn't steal it.
- 3018. By Nick Dedekind
-
Added cancellable to scope calls
- 3019. By Nick Dedekind
-
Removed StringRef. removed always-search
- 3020. By Nick Dedekind
-
reverted changes to function declarations.
- 3021. By Nick Dedekind
-
Review fixes. Scopes now initialized with ScopeData structure.
- 3022. By Nick Dedekind
-
Fixed connections in scope.
- 3023. By Nick Dedekind
-
Merge with trunk.
- 3024. By Nick Dedekind
-
Fixed filter variant serialization.
- 3025. By Nick Dedekind
-
Added category order change connections.
- 3026. By Nick Dedekind
-
removed visibility fetching from proxy
- 3027. By Nick Dedekind
-
renaming .lens files to .scope
- 3028. By Nick Dedekind
-
Implemented re-opening of channel on reconnection.
- 3029. By Nick Dedekind
-
Fixed connected property validation.
- 3030. By Michal Hruby
-
Fix reconnection
- 3031. By Nick Dedekind
-
Merged with trunk
- 3032. By Nick Dedekind
-
merge with trunk
Unmerged revisions
- 3032. By Nick Dedekind
-
merge with trunk
- 3031. By Nick Dedekind
-
Merged with trunk
- 3030. By Michal Hruby
-
Fix reconnection
Preview Diff
1 | === modified file 'UnityCore/CMakeLists.txt' | |||
2 | --- UnityCore/CMakeLists.txt 2012-12-19 20:53:12 +0000 | |||
3 | +++ UnityCore/CMakeLists.txt 2013-02-21 10:37:29 +0000 | |||
4 | @@ -21,7 +21,6 @@ | |||
5 | 21 | CheckOptionFilter.h | 21 | CheckOptionFilter.h |
6 | 22 | DBusIndicators.h | 22 | DBusIndicators.h |
7 | 23 | DesktopUtilities.h | 23 | DesktopUtilities.h |
8 | 24 | FilesystemLenses.h | ||
9 | 25 | Filter.h | 24 | Filter.h |
10 | 26 | Filters.h | 25 | Filters.h |
11 | 27 | GenericPreview.h | 26 | GenericPreview.h |
12 | @@ -31,13 +30,12 @@ | |||
13 | 31 | GLibSource.h | 30 | GLibSource.h |
14 | 32 | GLibWrapper.h | 31 | GLibWrapper.h |
15 | 33 | GLibWrapper-inl.h | 32 | GLibWrapper-inl.h |
16 | 33 | GSettingsScopes.h | ||
17 | 34 | Hud.h | 34 | Hud.h |
18 | 35 | HomeLens.h | ||
19 | 36 | IndicatorEntry.h | 35 | IndicatorEntry.h |
20 | 37 | Indicator.h | 36 | Indicator.h |
21 | 38 | Indicators.h | 37 | Indicators.h |
24 | 39 | Lens.h | 38 | MiscUtils.h |
23 | 40 | Lenses.h | ||
25 | 41 | MoviePreview.h | 39 | MoviePreview.h |
26 | 42 | MultiRangeFilter.h | 40 | MultiRangeFilter.h |
27 | 43 | MusicPreview.h | 41 | MusicPreview.h |
28 | @@ -51,6 +49,11 @@ | |||
29 | 51 | Result.h | 49 | Result.h |
30 | 52 | ResultIterator.h | 50 | ResultIterator.h |
31 | 53 | Results.h | 51 | Results.h |
32 | 52 | Scope.h | ||
33 | 53 | ScopeData.h | ||
34 | 54 | Scopes.h | ||
35 | 55 | ScopeProxy.h | ||
36 | 56 | ScopeProxyInterface.h | ||
37 | 54 | SeriesPreview.h | 57 | SeriesPreview.h |
38 | 55 | SocialPreview.h | 58 | SocialPreview.h |
39 | 56 | Track.h | 59 | Track.h |
40 | @@ -66,7 +69,6 @@ | |||
41 | 66 | CheckOptionFilter.cpp | 69 | CheckOptionFilter.cpp |
42 | 67 | DBusIndicators.cpp | 70 | DBusIndicators.cpp |
43 | 68 | DesktopUtilities.cpp | 71 | DesktopUtilities.cpp |
44 | 69 | FilesystemLenses.cpp | ||
45 | 70 | Filter.cpp | 72 | Filter.cpp |
46 | 71 | Filters.cpp | 73 | Filters.cpp |
47 | 72 | GenericPreview.cpp | 74 | GenericPreview.cpp |
48 | @@ -74,12 +76,11 @@ | |||
49 | 74 | GLibSignal.cpp | 76 | GLibSignal.cpp |
50 | 75 | GLibSource.cpp | 77 | GLibSource.cpp |
51 | 76 | GLibWrapper.cpp | 78 | GLibWrapper.cpp |
52 | 79 | GSettingsScopes.cpp | ||
53 | 77 | Hud.cpp | 80 | Hud.cpp |
54 | 78 | HomeLens.cpp | ||
55 | 79 | Indicator.cpp | 81 | Indicator.cpp |
56 | 80 | IndicatorEntry.cpp | 82 | IndicatorEntry.cpp |
57 | 81 | Indicators.cpp | 83 | Indicators.cpp |
58 | 82 | Lens.cpp | ||
59 | 83 | MoviePreview.cpp | 84 | MoviePreview.cpp |
60 | 84 | MultiRangeFilter.cpp | 85 | MultiRangeFilter.cpp |
61 | 85 | MusicPreview.cpp | 86 | MusicPreview.cpp |
62 | @@ -90,6 +91,10 @@ | |||
63 | 90 | Result.cpp | 91 | Result.cpp |
64 | 91 | ResultIterator.cpp | 92 | ResultIterator.cpp |
65 | 92 | Results.cpp | 93 | Results.cpp |
66 | 94 | Scope.cpp | ||
67 | 95 | ScopeData.cpp | ||
68 | 96 | Scopes.cpp | ||
69 | 97 | ScopeProxy.cpp | ||
70 | 93 | SeriesPreview.cpp | 98 | SeriesPreview.cpp |
71 | 94 | SocialPreview.cpp | 99 | SocialPreview.cpp |
72 | 95 | Track.cpp | 100 | Track.cpp |
73 | 96 | 101 | ||
74 | === modified file 'UnityCore/Categories.cpp' | |||
75 | --- UnityCore/Categories.cpp 2012-03-14 06:24:18 +0000 | |||
76 | +++ UnityCore/Categories.cpp 2013-02-21 10:37:29 +0000 | |||
77 | @@ -25,6 +25,7 @@ | |||
78 | 25 | { | 25 | { |
79 | 26 | 26 | ||
80 | 27 | Categories::Categories() | 27 | Categories::Categories() |
81 | 28 | : Model<Category>::Model(REMOTE) | ||
82 | 28 | { | 29 | { |
83 | 29 | row_added.connect(sigc::mem_fun(this, &Categories::OnRowAdded)); | 30 | row_added.connect(sigc::mem_fun(this, &Categories::OnRowAdded)); |
84 | 30 | row_changed.connect(sigc::mem_fun(this, &Categories::OnRowChanged)); | 31 | row_changed.connect(sigc::mem_fun(this, &Categories::OnRowChanged)); |
85 | 31 | 32 | ||
86 | === modified file 'UnityCore/Category.cpp' | |||
87 | --- UnityCore/Category.cpp 2012-11-29 13:28:27 +0000 | |||
88 | +++ UnityCore/Category.cpp 2013-02-21 10:37:29 +0000 | |||
89 | @@ -26,6 +26,15 @@ | |||
90 | 26 | namespace dash | 26 | namespace dash |
91 | 27 | { | 27 | { |
92 | 28 | 28 | ||
93 | 29 | enum CategoryColumn | ||
94 | 30 | { | ||
95 | 31 | ID = 0, | ||
96 | 32 | DISPLAY_NAME, | ||
97 | 33 | ICON_HINT, | ||
98 | 34 | RENDERER_NAME, | ||
99 | 35 | HINTS | ||
100 | 36 | }; | ||
101 | 37 | |||
102 | 29 | Category::Category(DeeModel* model, | 38 | Category::Category(DeeModel* model, |
103 | 30 | DeeModelIter* iter, | 39 | DeeModelIter* iter, |
104 | 31 | DeeModelTag* renderer_name_tag) | 40 | DeeModelTag* renderer_name_tag) |
105 | @@ -49,10 +58,11 @@ | |||
106 | 49 | 58 | ||
107 | 50 | void Category::SetupGetters() | 59 | void Category::SetupGetters() |
108 | 51 | { | 60 | { |
111 | 52 | name.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 0)); | 61 | id.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), CategoryColumn::ID)); |
112 | 53 | icon_hint.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 1)); | 62 | name.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), CategoryColumn::DISPLAY_NAME)); |
113 | 63 | icon_hint.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), CategoryColumn::ICON_HINT)); | ||
114 | 64 | renderer_name.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), CategoryColumn::RENDERER_NAME)); | ||
115 | 54 | index.SetGetterFunction(sigc::mem_fun(this, &Category::get_index)); | 65 | index.SetGetterFunction(sigc::mem_fun(this, &Category::get_index)); |
116 | 55 | renderer_name.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 2)); | ||
117 | 56 | } | 66 | } |
118 | 57 | 67 | ||
119 | 58 | std::size_t Category::get_index() const | 68 | std::size_t Category::get_index() const |
120 | 59 | 69 | ||
121 | === modified file 'UnityCore/Category.h' | |||
122 | --- UnityCore/Category.h 2011-07-31 08:39:48 +0000 | |||
123 | +++ UnityCore/Category.h 2013-02-21 10:37:29 +0000 | |||
124 | @@ -38,10 +38,11 @@ | |||
125 | 38 | Category(Category const& other); | 38 | Category(Category const& other); |
126 | 39 | Category& operator=(Category const& other); | 39 | Category& operator=(Category const& other); |
127 | 40 | 40 | ||
128 | 41 | nux::ROProperty<std::string> id; | ||
129 | 41 | nux::ROProperty<std::string> name; | 42 | nux::ROProperty<std::string> name; |
130 | 42 | nux::ROProperty<std::string> icon_hint; | 43 | nux::ROProperty<std::string> icon_hint; |
131 | 44 | nux::ROProperty<std::string> renderer_name; | ||
132 | 43 | nux::ROProperty<std::size_t> index; | 45 | nux::ROProperty<std::size_t> index; |
133 | 44 | nux::ROProperty<std::string> renderer_name; | ||
134 | 45 | 46 | ||
135 | 46 | private: | 47 | private: |
136 | 47 | void SetupGetters(); | 48 | void SetupGetters(); |
137 | 48 | 49 | ||
138 | === modified file 'UnityCore/FilesystemLenses.cpp' | |||
139 | --- UnityCore/FilesystemLenses.cpp 2012-10-29 09:34:54 +0000 | |||
140 | +++ UnityCore/FilesystemLenses.cpp 2013-02-21 10:37:29 +0000 | |||
141 | @@ -81,12 +81,11 @@ | |||
142 | 81 | * /usr/share/unity/lenses | 81 | * /usr/share/unity/lenses |
143 | 82 | * /applications | 82 | * /applications |
144 | 83 | * /applications.lens | 83 | * /applications.lens |
147 | 84 | * /applications.scope | 84 | * /chromium-webapps.lens |
146 | 85 | * /chromium-webapps.scope | ||
148 | 86 | * /files | 85 | * /files |
149 | 87 | * /files.lens | 86 | * /files.lens |
152 | 88 | * /zeitgiest.scope | 87 | * /zeitgiest.lens |
153 | 89 | * /ubuntuone.scope | 88 | * /ubuntuone.lens |
154 | 90 | * | 89 | * |
155 | 91 | * Etc, etc. We therefore need to enumerate these directories and find our | 90 | * Etc, etc. We therefore need to enumerate these directories and find our |
156 | 92 | * .lens files in them. | 91 | * .lens files in them. |
157 | @@ -401,7 +400,7 @@ | |||
158 | 401 | } | 400 | } |
159 | 402 | 401 | ||
160 | 403 | for (Lens::Ptr& lens: lenses_) | 402 | for (Lens::Ptr& lens: lenses_) |
162 | 404 | owner_->lens_added.emit(lens); | 403 | owner_->lenses_added.emit(lens); |
163 | 405 | 404 | ||
164 | 406 | owner_->lenses_loaded.emit(); | 405 | owner_->lenses_loaded.emit(); |
165 | 407 | } | 406 | } |
166 | 408 | 407 | ||
167 | === modified file 'UnityCore/Filter.cpp' | |||
168 | --- UnityCore/Filter.cpp 2012-10-29 09:34:54 +0000 | |||
169 | +++ UnityCore/Filter.cpp 2013-02-21 10:37:29 +0000 | |||
170 | @@ -25,6 +25,7 @@ | |||
171 | 25 | #include "MultiRangeFilter.h" | 25 | #include "MultiRangeFilter.h" |
172 | 26 | #include "RadioOptionFilter.h" | 26 | #include "RadioOptionFilter.h" |
173 | 27 | #include "RatingsFilter.h" | 27 | #include "RatingsFilter.h" |
174 | 28 | #include "GLibWrapper.h" | ||
175 | 28 | 29 | ||
176 | 29 | namespace unity | 30 | namespace unity |
177 | 30 | { | 31 | { |
178 | @@ -154,6 +155,26 @@ | |||
179 | 154 | g_variant_unref(row_value); | 155 | g_variant_unref(row_value); |
180 | 155 | } | 156 | } |
181 | 156 | 157 | ||
182 | 158 | glib::Variant Filter::VariantValue() const | ||
183 | 159 | { | ||
184 | 160 | if (!IsValid()) | ||
185 | 161 | return glib::Variant(); | ||
186 | 162 | |||
187 | 163 | GVariantBuilder hints; | ||
188 | 164 | g_variant_builder_init (&hints, G_VARIANT_TYPE("(ssssa{sv}bbb)")); | ||
189 | 165 | |||
190 | 166 | g_variant_builder_add(&hints, "s", id().c_str(), NULL); | ||
191 | 167 | g_variant_builder_add(&hints, "s", name().c_str(), NULL); | ||
192 | 168 | g_variant_builder_add(&hints, "s", icon_hint().c_str(), NULL); | ||
193 | 169 | g_variant_builder_add(&hints, "s", renderer_name().c_str(), NULL); | ||
194 | 170 | g_variant_builder_add(&hints, "@a{sv}", dee_model_get_value(model_, iter_, FilterColumn::RENDERER_STATE), NULL); | ||
195 | 171 | g_variant_builder_add(&hints, "b", visible(), NULL); | ||
196 | 172 | g_variant_builder_add(&hints, "b", collapsed(), NULL); | ||
197 | 173 | g_variant_builder_add(&hints, "b", filtering(), NULL); | ||
198 | 174 | |||
199 | 175 | return glib::Variant(g_variant_builder_end(&hints)); | ||
200 | 176 | } | ||
201 | 177 | |||
202 | 157 | std::string Filter::get_id() const | 178 | std::string Filter::get_id() const |
203 | 158 | { | 179 | { |
204 | 159 | if (IsValid()) | 180 | if (IsValid()) |
205 | 160 | 181 | ||
206 | === modified file 'UnityCore/Filter.h' | |||
207 | --- UnityCore/Filter.h 2012-07-16 11:03:32 +0000 | |||
208 | +++ UnityCore/Filter.h 2013-02-21 10:37:29 +0000 | |||
209 | @@ -77,6 +77,8 @@ | |||
210 | 77 | virtual void Clear() = 0; | 77 | virtual void Clear() = 0; |
211 | 78 | bool IsValid() const; | 78 | bool IsValid() const; |
212 | 79 | 79 | ||
213 | 80 | glib::Variant VariantValue() const; | ||
214 | 81 | |||
215 | 80 | nux::ROProperty<std::string> id; | 82 | nux::ROProperty<std::string> id; |
216 | 81 | nux::ROProperty<std::string> name; | 83 | nux::ROProperty<std::string> name; |
217 | 82 | nux::ROProperty<std::string> icon_hint; | 84 | nux::ROProperty<std::string> icon_hint; |
218 | 83 | 85 | ||
219 | === modified file 'UnityCore/Filters.cpp' | |||
220 | --- UnityCore/Filters.cpp 2012-03-14 06:24:18 +0000 | |||
221 | +++ UnityCore/Filters.cpp 2013-02-21 10:37:29 +0000 | |||
222 | @@ -50,6 +50,7 @@ | |||
223 | 50 | 50 | ||
224 | 51 | 51 | ||
225 | 52 | Filters::Filters() | 52 | Filters::Filters() |
226 | 53 | : Model<FilterAdaptor>::Model(ModelType::REMOTE) | ||
227 | 53 | { | 54 | { |
228 | 54 | row_added.connect(sigc::mem_fun(this, &Filters::OnRowAdded)); | 55 | row_added.connect(sigc::mem_fun(this, &Filters::OnRowAdded)); |
229 | 55 | row_changed.connect(sigc::mem_fun(this, &Filters::OnRowChanged)); | 56 | row_changed.connect(sigc::mem_fun(this, &Filters::OnRowChanged)); |
230 | @@ -57,7 +58,7 @@ | |||
231 | 57 | } | 58 | } |
232 | 58 | 59 | ||
233 | 59 | Filters::Filters(ModelType model_type) | 60 | Filters::Filters(ModelType model_type) |
235 | 60 | : Model<FilterAdaptor>::Model(model_type) | 61 | : Model<FilterAdaptor>::Model(model_type) |
236 | 61 | { | 62 | { |
237 | 62 | row_added.connect(sigc::mem_fun(this, &Filters::OnRowAdded)); | 63 | row_added.connect(sigc::mem_fun(this, &Filters::OnRowAdded)); |
238 | 63 | row_changed.connect(sigc::mem_fun(this, &Filters::OnRowChanged)); | 64 | row_changed.connect(sigc::mem_fun(this, &Filters::OnRowChanged)); |
239 | @@ -70,6 +71,10 @@ | |||
240 | 70 | Filter::Ptr Filters::FilterAtIndex(std::size_t index) | 71 | Filter::Ptr Filters::FilterAtIndex(std::size_t index) |
241 | 71 | { | 72 | { |
242 | 72 | FilterAdaptor adaptor = RowAtIndex(index); | 73 | FilterAdaptor adaptor = RowAtIndex(index); |
243 | 74 | if (filter_map_.find(adaptor.iter()) == filter_map_.end()) | ||
244 | 75 | { | ||
245 | 76 | OnRowAdded(adaptor); | ||
246 | 77 | } | ||
247 | 73 | return filter_map_[adaptor.iter()]; | 78 | return filter_map_[adaptor.iter()]; |
248 | 74 | } | 79 | } |
249 | 75 | 80 | ||
250 | 76 | 81 | ||
251 | === modified file 'UnityCore/GLibWrapper.cpp' | |||
252 | --- UnityCore/GLibWrapper.cpp 2012-03-14 06:24:18 +0000 | |||
253 | +++ UnityCore/GLibWrapper.cpp 2013-02-21 10:37:29 +0000 | |||
254 | @@ -69,7 +69,6 @@ | |||
255 | 69 | return o; | 69 | return o; |
256 | 70 | } | 70 | } |
257 | 71 | 71 | ||
258 | 72 | |||
259 | 73 | String::String() | 72 | String::String() |
260 | 74 | : string_(0) | 73 | : string_(0) |
261 | 75 | {} | 74 | {} |
262 | @@ -116,10 +115,7 @@ | |||
263 | 116 | 115 | ||
264 | 117 | std::string String::Str() const | 116 | std::string String::Str() const |
265 | 118 | { | 117 | { |
270 | 119 | if (string_) | 118 | return glib::gchar_to_string(string_); |
267 | 120 | return std::string(string_); | ||
268 | 121 | else | ||
269 | 122 | return std::string(""); | ||
271 | 123 | } | 119 | } |
272 | 124 | 120 | ||
273 | 125 | std::ostream& operator<<(std::ostream& o, String const& s) | 121 | std::ostream& operator<<(std::ostream& o, String const& s) |
274 | 126 | 122 | ||
275 | === modified file 'UnityCore/GLibWrapper.h' | |||
276 | --- UnityCore/GLibWrapper.h 2012-07-04 20:16:06 +0000 | |||
277 | +++ UnityCore/GLibWrapper.h 2013-02-21 10:37:29 +0000 | |||
278 | @@ -105,6 +105,7 @@ | |||
279 | 105 | GError* error_; | 105 | GError* error_; |
280 | 106 | }; | 106 | }; |
281 | 107 | 107 | ||
282 | 108 | // wrapper for raw gcha*. auto-deleted. | ||
283 | 108 | class String : boost::noncopyable | 109 | class String : boost::noncopyable |
284 | 109 | { | 110 | { |
285 | 110 | public: | 111 | public: |
286 | @@ -125,6 +126,14 @@ | |||
287 | 125 | gchar* string_; | 126 | gchar* string_; |
288 | 126 | }; | 127 | }; |
289 | 127 | 128 | ||
290 | 129 | inline std::string gchar_to_string(const char* str) | ||
291 | 130 | { | ||
292 | 131 | if (!str) | ||
293 | 132 | return std::string(""); | ||
294 | 133 | else | ||
295 | 134 | return std::string(str); | ||
296 | 135 | } | ||
297 | 136 | |||
298 | 128 | std::ostream& operator<<(std::ostream& o, Error const& e); | 137 | std::ostream& operator<<(std::ostream& o, Error const& e); |
299 | 129 | std::ostream& operator<<(std::ostream& o, String const& s); | 138 | std::ostream& operator<<(std::ostream& o, String const& s); |
300 | 130 | 139 | ||
301 | 131 | 140 | ||
302 | === added file 'UnityCore/GSettingsScopes.cpp' | |||
303 | --- UnityCore/GSettingsScopes.cpp 1970-01-01 00:00:00 +0000 | |||
304 | +++ UnityCore/GSettingsScopes.cpp 2013-02-21 10:37:29 +0000 | |||
305 | @@ -0,0 +1,171 @@ | |||
306 | 1 | /* | ||
307 | 2 | * Copyright (C) 2013 Canonical Ltd | ||
308 | 3 | * | ||
309 | 4 | * This program is free software: you can redistribute it and/or modify | ||
310 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
311 | 6 | * published by the Free Software Foundation. | ||
312 | 7 | * | ||
313 | 8 | * This program is distributed in the hope that it will be useful, | ||
314 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
315 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
316 | 11 | * GNU General Public License for more details. | ||
317 | 12 | * | ||
318 | 13 | * You should have received a copy of the GNU General Public License | ||
319 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
320 | 15 | * | ||
321 | 16 | * Authored by: Nick Dedekind <nick.dedekind@canonical.com> | ||
322 | 17 | */ | ||
323 | 18 | |||
324 | 19 | |||
325 | 20 | #include "GSettingsScopes.h" | ||
326 | 21 | |||
327 | 22 | #include "Scope.h" | ||
328 | 23 | |||
329 | 24 | namespace unity | ||
330 | 25 | { | ||
331 | 26 | namespace dash | ||
332 | 27 | { | ||
333 | 28 | DECLARE_LOGGER(logger, "unity.dash.gsettingsscopereader"); | ||
334 | 29 | |||
335 | 30 | namespace | ||
336 | 31 | { | ||
337 | 32 | const std::string SETTINGS_NAME = "com.canonical.Unity.Dash"; | ||
338 | 33 | const std::string SCOPE_SETTINGS_KEY = "scopes"; | ||
339 | 34 | } | ||
340 | 35 | |||
341 | 36 | class GSettingsScopesReader::Impl | ||
342 | 37 | { | ||
343 | 38 | public: | ||
344 | 39 | Impl(GSettingsScopesReader* owner); | ||
345 | 40 | ~Impl() {} | ||
346 | 41 | |||
347 | 42 | void LoadScopes(); | ||
348 | 43 | |||
349 | 44 | GSettingsScopesReader* owner_; | ||
350 | 45 | bool loaded_; | ||
351 | 46 | |||
352 | 47 | glib::Object<GSettings> settings_; | ||
353 | 48 | glib::Signal<void, GSettings*, gchar*> scopes_changed; | ||
354 | 49 | |||
355 | 50 | std::vector<std::string> get_string_vector(std::string const& setting) | ||
356 | 51 | { | ||
357 | 52 | std::vector<std::string> vector; | ||
358 | 53 | |||
359 | 54 | std::unique_ptr<gchar*[], void(*)(gchar**)> strings(g_settings_get_strv(settings_, setting.c_str()), g_strfreev); | ||
360 | 55 | |||
361 | 56 | for (int i = 0; strings[i]; ++i) | ||
362 | 57 | { | ||
363 | 58 | std::string value = strings[i]; | ||
364 | 59 | |||
365 | 60 | if (!value.empty()) | ||
366 | 61 | vector.push_back(value); | ||
367 | 62 | } | ||
368 | 63 | return vector; | ||
369 | 64 | } | ||
370 | 65 | |||
371 | 66 | ScopeDataList scopes_order_; | ||
372 | 67 | }; | ||
373 | 68 | |||
374 | 69 | |||
375 | 70 | GSettingsScopesReader::Impl::Impl(GSettingsScopesReader* owner) | ||
376 | 71 | : owner_(owner) | ||
377 | 72 | , loaded_(false) | ||
378 | 73 | , settings_(g_settings_new(SETTINGS_NAME.c_str())) | ||
379 | 74 | { | ||
380 | 75 | auto change_func = [&] (GSettings*, gchar*) | ||
381 | 76 | { | ||
382 | 77 | if (loaded_) | ||
383 | 78 | { | ||
384 | 79 | LoadScopes(); | ||
385 | 80 | owner_->scopes_changed.emit(scopes_order_); | ||
386 | 81 | } | ||
387 | 82 | }; | ||
388 | 83 | |||
389 | 84 | scopes_changed.Connect(settings_, "changed::"+SCOPE_SETTINGS_KEY, change_func); | ||
390 | 85 | } | ||
391 | 86 | |||
392 | 87 | |||
393 | 88 | void GSettingsScopesReader::Impl::LoadScopes() | ||
394 | 89 | { | ||
395 | 90 | std::vector<std::string> tmp_scope_ids = get_string_vector(SCOPE_SETTINGS_KEY); | ||
396 | 91 | |||
397 | 92 | ScopeDataList old_scopes_order = scopes_order_; | ||
398 | 93 | scopes_order_.clear(); | ||
399 | 94 | |||
400 | 95 | // insert new | ||
401 | 96 | for (std::string const& scope_id : tmp_scope_ids) | ||
402 | 97 | { | ||
403 | 98 | auto match_scope_data_to_id = [scope_id](ScopeData::Ptr const& scope_data) { return scope_data->id() == scope_id; }; | ||
404 | 99 | |||
405 | 100 | ScopeData::Ptr scope; | ||
406 | 101 | auto scope_position = std::find_if(old_scopes_order.begin(), old_scopes_order.end(), match_scope_data_to_id); | ||
407 | 102 | if (scope_position == old_scopes_order.end()) | ||
408 | 103 | { | ||
409 | 104 | glib::Error error; | ||
410 | 105 | scope = ScopeData::ReadProtocolDataForId(scope_id, error); | ||
411 | 106 | if (error) | ||
412 | 107 | { | ||
413 | 108 | LOG_WARN(logger) << "Error fetching protocol metadata for scope: " << scope_id << " : " << error.Message(); | ||
414 | 109 | continue; | ||
415 | 110 | } | ||
416 | 111 | } | ||
417 | 112 | else | ||
418 | 113 | { | ||
419 | 114 | scope = *scope_position; | ||
420 | 115 | } | ||
421 | 116 | |||
422 | 117 | if (scope) | ||
423 | 118 | { | ||
424 | 119 | scopes_order_.push_back(scope); | ||
425 | 120 | } | ||
426 | 121 | } | ||
427 | 122 | loaded_ = true; | ||
428 | 123 | } | ||
429 | 124 | |||
430 | 125 | |||
431 | 126 | GSettingsScopesReader::GSettingsScopesReader() | ||
432 | 127 | : pimpl(new Impl(this)) | ||
433 | 128 | { | ||
434 | 129 | } | ||
435 | 130 | |||
436 | 131 | void GSettingsScopesReader::LoadScopes() | ||
437 | 132 | { | ||
438 | 133 | pimpl->LoadScopes(); | ||
439 | 134 | } | ||
440 | 135 | |||
441 | 136 | ScopeDataList const& GSettingsScopesReader::GetScopesData() const | ||
442 | 137 | { | ||
443 | 138 | if (!pimpl->loaded_) | ||
444 | 139 | pimpl->LoadScopes(); | ||
445 | 140 | return pimpl->scopes_order_; | ||
446 | 141 | } | ||
447 | 142 | |||
448 | 143 | ScopeData::Ptr GSettingsScopesReader::GetScopeDataById(std::string const& scope_id) const | ||
449 | 144 | { | ||
450 | 145 | if (!pimpl->loaded_) | ||
451 | 146 | pimpl->LoadScopes(); | ||
452 | 147 | |||
453 | 148 | auto match_scope_data_to_id = [scope_id](ScopeData::Ptr const& scope_data) { return scope_data->id() == scope_id; }; | ||
454 | 149 | auto scope_position = std::find_if(pimpl->scopes_order_.begin(), pimpl->scopes_order_.end(), match_scope_data_to_id); | ||
455 | 150 | |||
456 | 151 | if (scope_position == pimpl->scopes_order_.end()) | ||
457 | 152 | return ScopeData::Ptr(); | ||
458 | 153 | |||
459 | 154 | return *scope_position; | ||
460 | 155 | } | ||
461 | 156 | |||
462 | 157 | GSettingsScopesReader::Ptr GSettingsScopesReader::GetDefault() | ||
463 | 158 | { | ||
464 | 159 | static GSettingsScopesReader::Ptr main_reader(new GSettingsScopesReader()); | ||
465 | 160 | |||
466 | 161 | return main_reader; | ||
467 | 162 | } | ||
468 | 163 | |||
469 | 164 | GSettingsScopes::GSettingsScopes() | ||
470 | 165 | : Scopes(GSettingsScopesReader::GetDefault()) | ||
471 | 166 | { | ||
472 | 167 | |||
473 | 168 | } | ||
474 | 169 | |||
475 | 170 | } // namespace dash | ||
476 | 171 | } // namespace unity | ||
477 | 0 | \ No newline at end of file | 172 | \ No newline at end of file |
478 | 1 | 173 | ||
479 | === added file 'UnityCore/GSettingsScopes.h' | |||
480 | --- UnityCore/GSettingsScopes.h 1970-01-01 00:00:00 +0000 | |||
481 | +++ UnityCore/GSettingsScopes.h 2013-02-21 10:37:29 +0000 | |||
482 | @@ -0,0 +1,56 @@ | |||
483 | 1 | /* | ||
484 | 2 | * Copyright (C) 2013 Canonical Ltd | ||
485 | 3 | * | ||
486 | 4 | * This program is free software: you can redistribute it and/or modify | ||
487 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
488 | 6 | * published by the Free Software Foundation. | ||
489 | 7 | * | ||
490 | 8 | * This program is distributed in the hope that it will be useful, | ||
491 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
492 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
493 | 11 | * GNU General Public License for more details. | ||
494 | 12 | * | ||
495 | 13 | * You should have received a copy of the GNU General Public License | ||
496 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
497 | 15 | * | ||
498 | 16 | * Authored by: Nick Dedekind <nick.dedekind@canonical.com> | ||
499 | 17 | */ | ||
500 | 18 | |||
501 | 19 | #ifndef UNITY_GSETTINGS_SCOPES_H | ||
502 | 20 | #define UNITY_GSETTINGS_SCOPES_H | ||
503 | 21 | |||
504 | 22 | #include "Scopes.h" | ||
505 | 23 | |||
506 | 24 | namespace unity | ||
507 | 25 | { | ||
508 | 26 | namespace dash | ||
509 | 27 | { | ||
510 | 28 | |||
511 | 29 | class GSettingsScopesReader : public ScopesReader | ||
512 | 30 | { | ||
513 | 31 | public: | ||
514 | 32 | typedef std::shared_ptr<GSettingsScopesReader> Ptr; | ||
515 | 33 | GSettingsScopesReader(); | ||
516 | 34 | |||
517 | 35 | virtual void LoadScopes(); | ||
518 | 36 | virtual ScopeDataList const& GetScopesData() const; | ||
519 | 37 | virtual ScopeData::Ptr GetScopeDataById(std::string const& scope_id) const; | ||
520 | 38 | |||
521 | 39 | static GSettingsScopesReader::Ptr GetDefault(); | ||
522 | 40 | |||
523 | 41 | private: | ||
524 | 42 | class Impl; | ||
525 | 43 | std::unique_ptr<Impl> pimpl; | ||
526 | 44 | }; | ||
527 | 45 | |||
528 | 46 | |||
529 | 47 | class GSettingsScopes : public Scopes | ||
530 | 48 | { | ||
531 | 49 | public: | ||
532 | 50 | GSettingsScopes(); | ||
533 | 51 | }; | ||
534 | 52 | |||
535 | 53 | } // namespace dash | ||
536 | 54 | } // namespace unity | ||
537 | 55 | |||
538 | 56 | #endif // UNITY_GSETTINGS_SCOPES_H | ||
539 | 0 | \ No newline at end of file | 57 | \ No newline at end of file |
540 | 1 | 58 | ||
541 | === added file 'UnityCore/MiscUtils.h' | |||
542 | --- UnityCore/MiscUtils.h 1970-01-01 00:00:00 +0000 | |||
543 | +++ UnityCore/MiscUtils.h 2013-02-21 10:37:29 +0000 | |||
544 | @@ -0,0 +1,118 @@ | |||
545 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
546 | 2 | /* | ||
547 | 3 | * Copyright (C) 2011 Canonical Ltd | ||
548 | 4 | * | ||
549 | 5 | * This program is free software: you can redistribute it and/or modify | ||
550 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
551 | 7 | * published by the Free Software Foundation. | ||
552 | 8 | * | ||
553 | 9 | * This program is distributed in the hope that it will be useful, | ||
554 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
555 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
556 | 12 | * GNU General Public License for more details. | ||
557 | 13 | * | ||
558 | 14 | * You should have received a copy of the GNU General Public License | ||
559 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
560 | 16 | * | ||
561 | 17 | * Authored by: Nick Dedekind <nick.dedekind@canonical.com> | ||
562 | 18 | */ | ||
563 | 19 | |||
564 | 20 | #ifndef UNITY_MISC_UTILS_H | ||
565 | 21 | #define UNITY_MISC_UTILS_H | ||
566 | 22 | |||
567 | 23 | #include <NuxCore/Property.h> | ||
568 | 24 | |||
569 | 25 | namespace unity | ||
570 | 26 | { | ||
571 | 27 | namespace utils | ||
572 | 28 | { | ||
573 | 29 | |||
574 | 30 | template <typename TYPE> | ||
575 | 31 | std::shared_ptr<sigc::connection> ConnectProperties(nux::ROProperty<TYPE>& local_property, nux::Property<TYPE>& remote_property) | ||
576 | 32 | { | ||
577 | 33 | auto change_connection = std::make_shared<sigc::connection>(); | ||
578 | 34 | local_property.SetGetterFunction([&remote_property]() { return remote_property.Get(); }); | ||
579 | 35 | *change_connection = remote_property.changed.connect([&local_property, &remote_property](TYPE const& value) { local_property.EmitChanged(value); }); | ||
580 | 36 | return change_connection; | ||
581 | 37 | } | ||
582 | 38 | |||
583 | 39 | template <typename TYPE> | ||
584 | 40 | std::shared_ptr<sigc::connection> ConnectProperties(nux::ROProperty<TYPE>& local_property, nux::ROProperty<TYPE>& remote_property) | ||
585 | 41 | { | ||
586 | 42 | auto change_connection = std::make_shared<sigc::connection>(); | ||
587 | 43 | local_property.SetGetterFunction([&remote_property]() { return remote_property.Get(); }); | ||
588 | 44 | *change_connection = remote_property.changed.connect([&local_property, &remote_property](TYPE const& value) { local_property.EmitChanged(value); }); | ||
589 | 45 | return change_connection; | ||
590 | 46 | } | ||
591 | 47 | |||
592 | 48 | template <typename TYPE> | ||
593 | 49 | std::shared_ptr<sigc::connection> ConnectProperties(nux::RWProperty<TYPE>& local_property, nux::Property<TYPE>& remote_property) | ||
594 | 50 | { | ||
595 | 51 | auto change_connection = std::make_shared<sigc::connection>(); | ||
596 | 52 | *change_connection = remote_property.changed.connect([&local_property, &remote_property](TYPE const& value) | ||
597 | 53 | { | ||
598 | 54 | local_property.EmitChanged(value); | ||
599 | 55 | }); | ||
600 | 56 | |||
601 | 57 | local_property.SetGetterFunction([&remote_property]() { return remote_property.Get(); }); | ||
602 | 58 | local_property.SetSetterFunction([&remote_property, &local_property, change_connection](TYPE const& value) | ||
603 | 59 | { | ||
604 | 60 | TYPE old_value = remote_property.Get(); | ||
605 | 61 | |||
606 | 62 | // block so we doing get a loop. | ||
607 | 63 | bool blocked = change_connection->block(true); | ||
608 | 64 | bool ret = remote_property.Set(value) != old_value; | ||
609 | 65 | change_connection->block(blocked); | ||
610 | 66 | return ret; | ||
611 | 67 | }); | ||
612 | 68 | return change_connection; | ||
613 | 69 | } | ||
614 | 70 | |||
615 | 71 | template <typename TYPE> | ||
616 | 72 | std::shared_ptr<sigc::connection> ConnectProperties(nux::RWProperty<TYPE>& local_property, nux::RWProperty<TYPE>& remote_property) | ||
617 | 73 | { | ||
618 | 74 | auto change_connection = std::make_shared<sigc::connection>(); | ||
619 | 75 | *change_connection = remote_property.changed.connect([&local_property, &remote_property](TYPE const& value) | ||
620 | 76 | { | ||
621 | 77 | local_property.EmitChanged(value); | ||
622 | 78 | }); | ||
623 | 79 | |||
624 | 80 | local_property.SetGetterFunction([&remote_property]() { return remote_property.Get(); }); | ||
625 | 81 | local_property.SetSetterFunction([&remote_property, &local_property, change_connection](TYPE const& value) | ||
626 | 82 | { | ||
627 | 83 | TYPE old_value = remote_property.Get(); | ||
628 | 84 | |||
629 | 85 | // block so we doing get a loop. | ||
630 | 86 | bool blocked = change_connection->block(true); | ||
631 | 87 | bool ret = remote_property.Set(value) != old_value; | ||
632 | 88 | change_connection->block(blocked); | ||
633 | 89 | return ret; | ||
634 | 90 | }); | ||
635 | 91 | return change_connection; | ||
636 | 92 | } | ||
637 | 93 | |||
638 | 94 | template <class TYPE> | ||
639 | 95 | class AutoResettingVariable | ||
640 | 96 | { | ||
641 | 97 | public: | ||
642 | 98 | AutoResettingVariable(TYPE*const variable, TYPE const& new_value) | ||
643 | 99 | : variable_(variable) | ||
644 | 100 | , original_value_(*variable) | ||
645 | 101 | { | ||
646 | 102 | *variable_ = new_value; | ||
647 | 103 | } | ||
648 | 104 | |||
649 | 105 | ~AutoResettingVariable() | ||
650 | 106 | { | ||
651 | 107 | *variable_ = original_value_; | ||
652 | 108 | } | ||
653 | 109 | |||
654 | 110 | private: | ||
655 | 111 | TYPE*const variable_; | ||
656 | 112 | TYPE original_value_; | ||
657 | 113 | }; | ||
658 | 114 | |||
659 | 115 | } | ||
660 | 116 | } | ||
661 | 117 | |||
662 | 118 | #endif // UNITY_MISC_UTILS_H | ||
663 | 0 | \ No newline at end of file | 119 | \ No newline at end of file |
664 | 1 | 120 | ||
665 | === modified file 'UnityCore/Model-inl.h' | |||
666 | --- UnityCore/Model-inl.h 2012-10-29 09:34:54 +0000 | |||
667 | +++ UnityCore/Model-inl.h 2013-02-21 10:37:29 +0000 | |||
668 | @@ -28,16 +28,6 @@ | |||
669 | 28 | { | 28 | { |
670 | 29 | 29 | ||
671 | 30 | template<class RowAdaptor> | 30 | template<class RowAdaptor> |
672 | 31 | Model<RowAdaptor>::Model() | ||
673 | 32 | : model_type_(ModelType::REMOTE) | ||
674 | 33 | , cached_adaptor1_(nullptr, nullptr, nullptr) | ||
675 | 34 | , cached_adaptor2_(nullptr, nullptr, nullptr) | ||
676 | 35 | , cached_adaptor3_(nullptr, nullptr, nullptr) | ||
677 | 36 | { | ||
678 | 37 | Init(); | ||
679 | 38 | } | ||
680 | 39 | |||
681 | 40 | template<class RowAdaptor> | ||
682 | 41 | Model<RowAdaptor>::Model (ModelType model_type) | 31 | Model<RowAdaptor>::Model (ModelType model_type) |
683 | 42 | : model_type_(model_type) | 32 | : model_type_(model_type) |
684 | 43 | , cached_adaptor1_(nullptr, nullptr, nullptr) | 33 | , cached_adaptor1_(nullptr, nullptr, nullptr) |
685 | @@ -63,26 +53,66 @@ | |||
686 | 63 | void Model<RowAdaptor>::OnSwarmNameChanged(std::string const& swarm_name) | 53 | void Model<RowAdaptor>::OnSwarmNameChanged(std::string const& swarm_name) |
687 | 64 | { | 54 | { |
688 | 65 | static nux::logging::Logger local_logger("unity.dash.model"); | 55 | static nux::logging::Logger local_logger("unity.dash.model"); |
690 | 66 | 56 | LOG_DEBUG(local_logger) << "New swarm name: " << swarm_name; | |
691 | 57 | |||
692 | 58 | glib::Object<DeeModel> new_model; | ||
693 | 59 | |||
694 | 60 | switch(model_type_) | ||
695 | 61 | { | ||
696 | 62 | case ModelType::LOCAL: | ||
697 | 63 | new_model = dee_sequence_model_new(); | ||
698 | 64 | break; | ||
699 | 65 | |||
700 | 66 | case ModelType::REMOTE: | ||
701 | 67 | case ModelType::REMOTE_SHARED: | ||
702 | 68 | new_model = dee_shared_model_new(swarm_name.c_str()); | ||
703 | 69 | break; | ||
704 | 70 | |||
705 | 71 | case ModelType::UNATTACHED: | ||
706 | 72 | break; | ||
707 | 73 | |||
708 | 74 | default: | ||
709 | 75 | LOG_ERROR(local_logger) << "Unexpected ModelType " << model_type_; | ||
710 | 76 | break; | ||
711 | 77 | } | ||
712 | 78 | |||
713 | 79 | SetModel(new_model); | ||
714 | 80 | } | ||
715 | 81 | |||
716 | 82 | template<class RowAdaptor> | ||
717 | 83 | void Model<RowAdaptor>::SetModel(glib::Object<DeeModel> const& new_model) | ||
718 | 84 | { | ||
719 | 85 | GetDeeTagFunc func = [](glib::Object<DeeModel> const& model) { | ||
720 | 86 | return dee_model_register_tag(model, NULL); | ||
721 | 87 | }; | ||
722 | 88 | SetModel(new_model, func); | ||
723 | 89 | } | ||
724 | 90 | |||
725 | 91 | template<class RowAdaptor> | ||
726 | 92 | void Model<RowAdaptor>::SetModel(glib::Object<DeeModel> const& new_model, GetDeeTagFunc const& get_dee_tag_func) | ||
727 | 93 | { | ||
728 | 94 | typedef glib::Signal<void, DeeModel*, guint64, guint64> TransactionSignalType; | ||
729 | 67 | typedef glib::Signal<void, DeeModel*, DeeModelIter*> RowSignalType; | 95 | typedef glib::Signal<void, DeeModel*, DeeModelIter*> RowSignalType; |
730 | 68 | typedef glib::Signal<void, DeeModel*, guint64, guint64> TransactionSignalType; | ||
731 | 69 | 96 | ||
733 | 70 | LOG_DEBUG(local_logger) << "New swarm name: " << swarm_name; | 97 | // Check if it's the same as the current model. |
734 | 98 | if (new_model == model_) | ||
735 | 99 | return; | ||
736 | 71 | 100 | ||
737 | 72 | // Let the views clean up properly | 101 | // Let the views clean up properly |
738 | 73 | if (model_) | 102 | if (model_) |
739 | 74 | { | 103 | { |
740 | 75 | dee_model_clear(model_); | 104 | dee_model_clear(model_); |
741 | 76 | sig_manager_.Disconnect(model_); | 105 | sig_manager_.Disconnect(model_); |
742 | 106 | model_.Release(); | ||
743 | 77 | } | 107 | } |
744 | 108 | model_ = new_model; | ||
745 | 109 | |||
746 | 110 | if (!model_) | ||
747 | 111 | return; | ||
748 | 78 | 112 | ||
749 | 79 | switch(model_type_) | 113 | switch(model_type_) |
750 | 80 | { | 114 | { |
756 | 81 | case ModelType::LOCAL: | 115 | case ModelType::REMOTE_SHARED: |
752 | 82 | model_ = dee_sequence_model_new(); | ||
753 | 83 | break; | ||
754 | 84 | case ModelType::REMOTE: | ||
755 | 85 | model_ = dee_shared_model_new(swarm_name.c_str()); | ||
757 | 86 | sig_manager_.Add(new TransactionSignalType(model_, | 116 | sig_manager_.Add(new TransactionSignalType(model_, |
758 | 87 | "begin-transaction", | 117 | "begin-transaction", |
759 | 88 | sigc::mem_fun(this, &Model<RowAdaptor>::OnTransactionBegin))); | 118 | sigc::mem_fun(this, &Model<RowAdaptor>::OnTransactionBegin))); |
760 | @@ -91,15 +121,15 @@ | |||
761 | 91 | "end-transaction", | 121 | "end-transaction", |
762 | 92 | sigc::mem_fun(this, &Model<RowAdaptor>::OnTransactionEnd))); | 122 | sigc::mem_fun(this, &Model<RowAdaptor>::OnTransactionEnd))); |
763 | 93 | break; | 123 | break; |
764 | 124 | |||
765 | 125 | case ModelType::REMOTE: | ||
766 | 126 | case ModelType::LOCAL: | ||
767 | 127 | case ModelType::UNATTACHED: | ||
768 | 94 | default: | 128 | default: |
769 | 95 | LOG_ERROR(local_logger) << "Unexpected ModelType " << model_type_; | ||
770 | 96 | break; | 129 | break; |
771 | 97 | } | 130 | } |
772 | 98 | 131 | ||
777 | 99 | model.EmitChanged(model_); | 132 | renderer_tag_ = get_dee_tag_func(model_); |
774 | 100 | |||
775 | 101 | |||
776 | 102 | renderer_tag_ = dee_model_register_tag(model_, NULL); | ||
778 | 103 | 133 | ||
779 | 104 | sig_manager_.Add(new RowSignalType(model_, | 134 | sig_manager_.Add(new RowSignalType(model_, |
780 | 105 | "row-added", | 135 | "row-added", |
781 | @@ -112,6 +142,8 @@ | |||
782 | 112 | sig_manager_.Add(new RowSignalType(model_, | 142 | sig_manager_.Add(new RowSignalType(model_, |
783 | 113 | "row-removed", | 143 | "row-removed", |
784 | 114 | sigc::mem_fun(this, &Model<RowAdaptor>::OnRowRemoved))); | 144 | sigc::mem_fun(this, &Model<RowAdaptor>::OnRowRemoved))); |
785 | 145 | |||
786 | 146 | model.EmitChanged(model_); | ||
787 | 115 | } | 147 | } |
788 | 116 | 148 | ||
789 | 117 | template<class RowAdaptor> | 149 | template<class RowAdaptor> |
790 | 118 | 150 | ||
791 | === modified file 'UnityCore/Model.h' | |||
792 | --- UnityCore/Model.h 2012-09-02 20:34:37 +0000 | |||
793 | +++ UnityCore/Model.h 2013-02-21 10:37:29 +0000 | |||
794 | @@ -38,7 +38,9 @@ | |||
795 | 38 | enum ModelType | 38 | enum ModelType |
796 | 39 | { | 39 | { |
797 | 40 | REMOTE, | 40 | REMOTE, |
799 | 41 | LOCAL | 41 | REMOTE_SHARED, |
800 | 42 | LOCAL, | ||
801 | 43 | UNATTACHED | ||
802 | 42 | }; | 44 | }; |
803 | 43 | 45 | ||
804 | 44 | /* This template class encapsulates the basics of talking to a DeeSharedModel, | 46 | /* This template class encapsulates the basics of talking to a DeeSharedModel, |
805 | @@ -52,14 +54,14 @@ | |||
806 | 52 | public: | 54 | public: |
807 | 53 | typedef std::shared_ptr<Model> Ptr; | 55 | typedef std::shared_ptr<Model> Ptr; |
808 | 54 | 56 | ||
811 | 55 | Model(); | 57 | Model (ModelType model_type = ModelType::REMOTE_SHARED); |
810 | 56 | Model (ModelType model_type); | ||
812 | 57 | virtual ~Model(); | 58 | virtual ~Model(); |
813 | 58 | 59 | ||
814 | 59 | const RowAdaptor RowAtIndex(std::size_t index); | 60 | const RowAdaptor RowAtIndex(std::size_t index); |
815 | 60 | DeeModelTag* GetTag(); | 61 | DeeModelTag* GetTag(); |
816 | 61 | 62 | ||
817 | 62 | nux::Property<std::string> swarm_name; | 63 | nux::Property<std::string> swarm_name; |
818 | 64 | |||
819 | 63 | nux::ROProperty<std::size_t> count; | 65 | nux::ROProperty<std::size_t> count; |
820 | 64 | nux::ROProperty<unsigned long long> seqnum; | 66 | nux::ROProperty<unsigned long long> seqnum; |
821 | 65 | nux::ROProperty<glib::Object<DeeModel>> model; | 67 | nux::ROProperty<glib::Object<DeeModel>> model; |
822 | @@ -71,6 +73,11 @@ | |||
823 | 71 | sigc::signal<void, unsigned long long, unsigned long long> begin_transaction; | 73 | sigc::signal<void, unsigned long long, unsigned long long> begin_transaction; |
824 | 72 | sigc::signal<void, unsigned long long, unsigned long long> end_transaction; | 74 | sigc::signal<void, unsigned long long, unsigned long long> end_transaction; |
825 | 73 | 75 | ||
826 | 76 | typedef std::function<DeeModelTag*(glib::Object<DeeModel> const& model)> GetDeeTagFunc; | ||
827 | 77 | |||
828 | 78 | void SetModel(glib::Object<DeeModel> const& model); | ||
829 | 79 | void SetModel(glib::Object<DeeModel> const& model, GetDeeTagFunc const& func); | ||
830 | 80 | |||
831 | 74 | private: | 81 | private: |
832 | 75 | void Init(); | 82 | void Init(); |
833 | 76 | void OnRowAdded(DeeModel* model, DeeModelIter* iter); | 83 | void OnRowAdded(DeeModel* model, DeeModelIter* iter); |
834 | @@ -94,8 +101,8 @@ | |||
835 | 94 | RowAdaptor cached_adaptor3_; | 101 | RowAdaptor cached_adaptor3_; |
836 | 95 | }; | 102 | }; |
837 | 96 | 103 | ||
840 | 97 | } | 104 | } // namespace dash |
841 | 98 | } | 105 | } // namespace unity |
842 | 99 | 106 | ||
843 | 100 | #include "Model-inl.h" | 107 | #include "Model-inl.h" |
844 | 101 | 108 | ||
845 | 102 | 109 | ||
846 | === modified file 'UnityCore/MusicPreview.cpp' | |||
847 | --- UnityCore/MusicPreview.cpp 2012-07-12 16:36:54 +0000 | |||
848 | +++ UnityCore/MusicPreview.cpp 2013-02-21 10:37:29 +0000 | |||
849 | @@ -22,11 +22,13 @@ | |||
850 | 22 | 22 | ||
851 | 23 | #include "MusicPreview.h" | 23 | #include "MusicPreview.h" |
852 | 24 | #include "Tracks.h" | 24 | #include "Tracks.h" |
853 | 25 | #include "Scope.h" | ||
854 | 25 | 26 | ||
855 | 26 | namespace unity | 27 | namespace unity |
856 | 27 | { | 28 | { |
857 | 28 | namespace dash | 29 | namespace dash |
858 | 29 | { | 30 | { |
859 | 31 | DECLARE_LOGGER(logger, "unity.dash.musicpreview"); | ||
860 | 30 | 32 | ||
861 | 31 | class MusicPreview::Impl | 33 | class MusicPreview::Impl |
862 | 32 | { | 34 | { |
863 | @@ -70,7 +72,12 @@ | |||
864 | 70 | unity_protocol_music_preview_play_uri(raw_preview_, uri.c_str()); | 72 | unity_protocol_music_preview_play_uri(raw_preview_, uri.c_str()); |
865 | 71 | glib::Variant properties(unity_protocol_preview_end_updates(preview), | 73 | glib::Variant properties(unity_protocol_preview_end_updates(preview), |
866 | 72 | glib::StealRef()); | 74 | glib::StealRef()); |
868 | 73 | owner_->Update(properties); | 75 | |
869 | 76 | glib::HintsMap property_hints; | ||
870 | 77 | if (properties.ASVToHints(property_hints)) | ||
871 | 78 | owner_->Update(property_hints); | ||
872 | 79 | else | ||
873 | 80 | LOG_ERROR(logger) << "PlayUri could not convert property hints to variant for " << uri; | ||
874 | 74 | } | 81 | } |
875 | 75 | 82 | ||
876 | 76 | void MusicPreview::Impl::PauseUri(std::string const& uri) const | 83 | void MusicPreview::Impl::PauseUri(std::string const& uri) const |
877 | @@ -81,7 +88,12 @@ | |||
878 | 81 | unity_protocol_music_preview_pause_uri(raw_preview_, uri.c_str()); | 88 | unity_protocol_music_preview_pause_uri(raw_preview_, uri.c_str()); |
879 | 82 | glib::Variant properties(unity_protocol_preview_end_updates(preview), | 89 | glib::Variant properties(unity_protocol_preview_end_updates(preview), |
880 | 83 | glib::StealRef()); | 90 | glib::StealRef()); |
882 | 84 | owner_->Update(properties); | 91 | |
883 | 92 | glib::HintsMap property_hints; | ||
884 | 93 | if (properties.ASVToHints(property_hints)) | ||
885 | 94 | owner_->Update(property_hints); | ||
886 | 95 | else | ||
887 | 96 | LOG_ERROR(logger) << "PauseUri could not convert property hints to variant for " << uri; | ||
888 | 85 | } | 97 | } |
889 | 86 | 98 | ||
890 | 87 | MusicPreview::MusicPreview(unity::glib::Object<GObject> const& proto_obj) | 99 | MusicPreview::MusicPreview(unity::glib::Object<GObject> const& proto_obj) |
891 | 88 | 100 | ||
892 | === modified file 'UnityCore/Preview.cpp' | |||
893 | --- UnityCore/Preview.cpp 2012-10-29 09:34:54 +0000 | |||
894 | +++ UnityCore/Preview.cpp 2013-02-21 10:37:29 +0000 | |||
895 | @@ -21,8 +21,8 @@ | |||
896 | 21 | #include <NuxCore/Logger.h> | 21 | #include <NuxCore/Logger.h> |
897 | 22 | #include <unity-protocol.h> | 22 | #include <unity-protocol.h> |
898 | 23 | 23 | ||
899 | 24 | #include "Lens.h" | ||
900 | 25 | #include "Preview.h" | 24 | #include "Preview.h" |
901 | 25 | #include "Scope.h" | ||
902 | 26 | 26 | ||
903 | 27 | #include "ApplicationPreview.h" | 27 | #include "ApplicationPreview.h" |
904 | 28 | #include "GenericPreview.h" | 28 | #include "GenericPreview.h" |
905 | @@ -81,7 +81,7 @@ | |||
906 | 81 | return nullptr; | 81 | return nullptr; |
907 | 82 | } | 82 | } |
908 | 83 | 83 | ||
910 | 84 | Preview::Ptr Preview::PreviewForVariant(glib::Variant &properties) | 84 | Preview::Ptr Preview::PreviewForVariant(glib::Variant const& properties) |
911 | 85 | { | 85 | { |
912 | 86 | glib::Object<UnityProtocolPreview> preview(unity_protocol_preview_parse(properties)); | 86 | glib::Object<UnityProtocolPreview> preview(unity_protocol_preview_parse(properties)); |
913 | 87 | if (!preview) | 87 | if (!preview) |
914 | @@ -123,10 +123,10 @@ | |||
915 | 123 | InfoHintPtrList get_info_hints() const { return info_hint_list_; }; | 123 | InfoHintPtrList get_info_hints() const { return info_hint_list_; }; |
916 | 124 | void EmitClosed() const; | 124 | void EmitClosed() const; |
917 | 125 | 125 | ||
920 | 126 | Lens* get_parent_lens() const { return parent_lens_; }; | 126 | Scope* get_parent_scope() const { return parent_scope_; }; |
921 | 127 | bool set_parent_lens(Lens* lens) | 127 | bool set_parent_scope(Scope* scope) |
922 | 128 | { | 128 | { |
924 | 129 | parent_lens_ = lens; | 129 | parent_scope_ = scope; |
925 | 130 | return false; // TODO: do we need the notifications here? | 130 | return false; // TODO: do we need the notifications here? |
926 | 131 | }; | 131 | }; |
927 | 132 | 132 | ||
928 | @@ -141,12 +141,12 @@ | |||
929 | 141 | std::string image_source_uri_; | 141 | std::string image_source_uri_; |
930 | 142 | ActionPtrList actions_list_; | 142 | ActionPtrList actions_list_; |
931 | 143 | InfoHintPtrList info_hint_list_; | 143 | InfoHintPtrList info_hint_list_; |
933 | 144 | Lens* parent_lens_; | 144 | Scope* parent_scope_; |
934 | 145 | }; | 145 | }; |
935 | 146 | 146 | ||
936 | 147 | Preview::Impl::Impl(Preview* owner, glib::Object<GObject> const& proto_obj) | 147 | Preview::Impl::Impl(Preview* owner, glib::Object<GObject> const& proto_obj) |
937 | 148 | : owner_(owner) | 148 | : owner_(owner) |
939 | 149 | , parent_lens_(nullptr) | 149 | , parent_scope_(nullptr) |
940 | 150 | { | 150 | { |
941 | 151 | if (!proto_obj) | 151 | if (!proto_obj) |
942 | 152 | { | 152 | { |
943 | @@ -215,10 +215,10 @@ | |||
944 | 215 | owner_->image_source_uri.SetGetterFunction( | 215 | owner_->image_source_uri.SetGetterFunction( |
945 | 216 | sigc::mem_fun(this, &Preview::Impl::get_image_source_uri)); | 216 | sigc::mem_fun(this, &Preview::Impl::get_image_source_uri)); |
946 | 217 | 217 | ||
951 | 218 | owner_->parent_lens.SetGetterFunction( | 218 | owner_->parent_scope.SetGetterFunction( |
952 | 219 | sigc::mem_fun(this, &Preview::Impl::get_parent_lens)); | 219 | sigc::mem_fun(this, &Preview::Impl::get_parent_scope)); |
953 | 220 | owner_->parent_lens.SetSetterFunction( | 220 | owner_->parent_scope.SetSetterFunction( |
954 | 221 | sigc::mem_fun(this, &Preview::Impl::set_parent_lens)); | 221 | sigc::mem_fun(this, &Preview::Impl::set_parent_scope)); |
955 | 222 | } | 222 | } |
956 | 223 | 223 | ||
957 | 224 | void Preview::Impl::EmitClosed() const | 224 | void Preview::Impl::EmitClosed() const |
958 | @@ -229,7 +229,12 @@ | |||
959 | 229 | unity_protocol_preview_preview_closed(raw_preview_); | 229 | unity_protocol_preview_preview_closed(raw_preview_); |
960 | 230 | glib::Variant properties(unity_protocol_preview_end_updates(preview), | 230 | glib::Variant properties(unity_protocol_preview_end_updates(preview), |
961 | 231 | glib::StealRef()); | 231 | glib::StealRef()); |
963 | 232 | owner_->Update(properties); | 232 | |
964 | 233 | glib::HintsMap property_hints; | ||
965 | 234 | if (properties.ASVToHints(property_hints)) | ||
966 | 235 | owner_->Update(property_hints); | ||
967 | 236 | else | ||
968 | 237 | LOG_ERROR(logger) << "EmitClosed could not convert property hints to variant for " << owner_->preview_uri.Get(); | ||
969 | 233 | } | 238 | } |
970 | 234 | 239 | ||
971 | 235 | Preview::Preview(glib::Object<GObject> const& proto_obj) | 240 | Preview::Preview(glib::Object<GObject> const& proto_obj) |
972 | @@ -251,28 +256,28 @@ | |||
973 | 251 | return pimpl->get_info_hints(); | 256 | return pimpl->get_info_hints(); |
974 | 252 | } | 257 | } |
975 | 253 | 258 | ||
978 | 254 | void Preview::Update(glib::Variant const& properties, | 259 | void Preview::Update(glib::HintsMap const& property_hints, |
979 | 255 | glib::DBusProxy::ReplyCallback reply_callback) const | 260 | std::function<void(glib::HintsMap const&, glib::Error const&)> const& reply_callback) const |
980 | 256 | { | 261 | { |
982 | 257 | if (pimpl->parent_lens_) | 262 | if (pimpl->parent_scope_) |
983 | 258 | { | 263 | { |
985 | 259 | pimpl->parent_lens_->SignalPreview(preview_uri, properties, reply_callback); | 264 | pimpl->parent_scope_->UpdatePreviewProperty(preview_uri, property_hints, reply_callback); |
986 | 260 | } | 265 | } |
987 | 261 | else | 266 | else |
988 | 262 | { | 267 | { |
990 | 263 | LOG_WARN(logger) << "Unable to update Preview, parent_lens wasn't set!"; | 268 | LOG_WARN(logger) << "Unable to update Preview, parent_scope_ wasn't set!"; |
991 | 264 | } | 269 | } |
992 | 265 | } | 270 | } |
993 | 266 | 271 | ||
995 | 267 | void Preview::PerformAction(std::string const& id, Lens::Hints const& hints) const | 272 | void Preview::PerformAction(std::string const& id, glib::HintsMap const& hints) const |
996 | 268 | { | 273 | { |
998 | 269 | if (pimpl->parent_lens_) | 274 | if (pimpl->parent_scope_) |
999 | 270 | { | 275 | { |
1001 | 271 | pimpl->parent_lens_->ActivatePreviewAction(id, preview_uri, hints); | 276 | pimpl->parent_scope_->ActivatePreviewAction(id, preview_uri, hints); |
1002 | 272 | } | 277 | } |
1003 | 273 | else | 278 | else |
1004 | 274 | { | 279 | { |
1006 | 275 | LOG_WARN(logger) << "Unable to perform action '" << id << "', parent_lens wasn't set!"; | 280 | LOG_WARN(logger) << "Unable to perform action '" << id << "', parent_scope_ wasn't set!"; |
1007 | 276 | } | 281 | } |
1008 | 277 | } | 282 | } |
1009 | 278 | 283 | ||
1010 | 279 | 284 | ||
1011 | === modified file 'UnityCore/Preview.h' | |||
1012 | --- UnityCore/Preview.h 2012-09-13 10:56:42 +0000 | |||
1013 | +++ UnityCore/Preview.h 2013-02-21 10:37:29 +0000 | |||
1014 | @@ -40,7 +40,7 @@ | |||
1015 | 40 | namespace dash | 40 | namespace dash |
1016 | 41 | { | 41 | { |
1017 | 42 | 42 | ||
1019 | 43 | class Lens; | 43 | class Scope; |
1020 | 44 | 44 | ||
1021 | 45 | enum LayoutHint | 45 | enum LayoutHint |
1022 | 46 | { | 46 | { |
1023 | @@ -110,7 +110,7 @@ | |||
1024 | 110 | 110 | ||
1025 | 111 | virtual ~Preview(); | 111 | virtual ~Preview(); |
1026 | 112 | 112 | ||
1028 | 113 | static Preview::Ptr PreviewForVariant(glib::Variant& properties); | 113 | static Preview::Ptr PreviewForVariant(glib::Variant const& properties); |
1029 | 114 | static Preview::Ptr PreviewForProtocolObject(glib::Object<GObject> const& proto_obj); | 114 | static Preview::Ptr PreviewForProtocolObject(glib::Object<GObject> const& proto_obj); |
1030 | 115 | 115 | ||
1031 | 116 | nux::ROProperty<std::string> renderer_name; | 116 | nux::ROProperty<std::string> renderer_name; |
1032 | @@ -120,24 +120,24 @@ | |||
1033 | 120 | nux::ROProperty<unity::glib::Object<GIcon>> image; | 120 | nux::ROProperty<unity::glib::Object<GIcon>> image; |
1034 | 121 | nux::ROProperty<std::string> image_source_uri; | 121 | nux::ROProperty<std::string> image_source_uri; |
1035 | 122 | 122 | ||
1038 | 123 | // can't use Lens::Ptr to avoid circular dependency | 123 | // can't use Scope::Ptr to avoid circular dependency |
1039 | 124 | nux::RWProperty<Lens*> parent_lens; | 124 | nux::RWProperty<Scope*> parent_scope; |
1040 | 125 | nux::Property<std::string> preview_uri; | 125 | nux::Property<std::string> preview_uri; |
1041 | 126 | 126 | ||
1042 | 127 | ActionPtrList GetActions() const; | 127 | ActionPtrList GetActions() const; |
1043 | 128 | InfoHintPtrList GetInfoHints() const; | 128 | InfoHintPtrList GetInfoHints() const; |
1044 | 129 | 129 | ||
1045 | 130 | void PerformAction(std::string const& id, | 130 | void PerformAction(std::string const& id, |
1048 | 131 | std::map<std::string, glib::Variant> const& hints = | 131 | glib::HintsMap const& hints = |
1049 | 132 | std::map<std::string, glib::Variant>()) const; | 132 | glib::HintsMap()) const; |
1050 | 133 | void EmitClosed() const; | 133 | void EmitClosed() const; |
1051 | 134 | 134 | ||
1052 | 135 | protected: | 135 | protected: |
1053 | 136 | // this should be UnityProtocolPreview, but we want to keep the usage | 136 | // this should be UnityProtocolPreview, but we want to keep the usage |
1054 | 137 | // of libunity-protocol-private private to unity-core | 137 | // of libunity-protocol-private private to unity-core |
1055 | 138 | Preview(glib::Object<GObject> const& proto_obj); | 138 | Preview(glib::Object<GObject> const& proto_obj); |
1058 | 139 | void Update(glib::Variant const& properties, | 139 | void Update(glib::HintsMap const& property_hints, |
1059 | 140 | glib::DBusProxy::ReplyCallback reply_callback = nullptr) const; | 140 | std::function<void(glib::HintsMap const&, glib::Error const&)> const& reply_callback = nullptr) const; |
1060 | 141 | static glib::Object<GIcon> IconForString(std::string const& icon_hint); | 141 | static glib::Object<GIcon> IconForString(std::string const& icon_hint); |
1061 | 142 | 142 | ||
1062 | 143 | private: | 143 | private: |
1063 | 144 | 144 | ||
1064 | === modified file 'UnityCore/Result.cpp' | |||
1065 | --- UnityCore/Result.cpp 2012-12-06 17:41:07 +0000 | |||
1066 | +++ UnityCore/Result.cpp 2013-02-21 10:37:29 +0000 | |||
1067 | @@ -25,6 +25,22 @@ | |||
1068 | 25 | namespace dash | 25 | namespace dash |
1069 | 26 | { | 26 | { |
1070 | 27 | 27 | ||
1071 | 28 | namespace | ||
1072 | 29 | { | ||
1073 | 30 | enum ResultColumn | ||
1074 | 31 | { | ||
1075 | 32 | URI, | ||
1076 | 33 | ICON_HINT, | ||
1077 | 34 | CATEGORY, | ||
1078 | 35 | RESULT_TYPE, | ||
1079 | 36 | MIMETYPE, | ||
1080 | 37 | TITLE, | ||
1081 | 38 | COMMENT, | ||
1082 | 39 | DND_URI, | ||
1083 | 40 | METADATA | ||
1084 | 41 | }; | ||
1085 | 42 | } | ||
1086 | 43 | |||
1087 | 28 | Result::Result(DeeModel* model, | 44 | Result::Result(DeeModel* model, |
1088 | 29 | DeeModelIter* iter, | 45 | DeeModelIter* iter, |
1089 | 30 | DeeModelTag* renderer_tag) | 46 | DeeModelTag* renderer_tag) |
1090 | @@ -51,19 +67,21 @@ | |||
1091 | 51 | uri.SetGetterFunction(sigc::mem_fun(this, &Result::GetURI)); | 67 | uri.SetGetterFunction(sigc::mem_fun(this, &Result::GetURI)); |
1092 | 52 | icon_hint.SetGetterFunction(sigc::mem_fun(this, &Result::GetIconHint)); | 68 | icon_hint.SetGetterFunction(sigc::mem_fun(this, &Result::GetIconHint)); |
1093 | 53 | category_index.SetGetterFunction(sigc::mem_fun(this, &Result::GetCategoryIndex)); | 69 | category_index.SetGetterFunction(sigc::mem_fun(this, &Result::GetCategoryIndex)); |
1094 | 70 | result_type.SetGetterFunction(sigc::mem_fun(this, &Result::GetResultType)); | ||
1095 | 54 | mimetype.SetGetterFunction(sigc::mem_fun(this, &Result::GetMimeType)); | 71 | mimetype.SetGetterFunction(sigc::mem_fun(this, &Result::GetMimeType)); |
1096 | 55 | name.SetGetterFunction(sigc::mem_fun(this, &Result::GetName)); | 72 | name.SetGetterFunction(sigc::mem_fun(this, &Result::GetName)); |
1097 | 56 | comment.SetGetterFunction(sigc::mem_fun(this, &Result::GetComment)); | 73 | comment.SetGetterFunction(sigc::mem_fun(this, &Result::GetComment)); |
1098 | 57 | dnd_uri.SetGetterFunction(sigc::mem_fun(this, &Result::GetDndURI)); | 74 | dnd_uri.SetGetterFunction(sigc::mem_fun(this, &Result::GetDndURI)); |
1099 | 58 | } | 75 | } |
1100 | 59 | 76 | ||
1108 | 60 | std::string Result::GetURI() const { return GetStringAt(0); } | 77 | std::string Result::GetURI() const { return GetStringAt(ResultColumn::URI); } |
1109 | 61 | std::string Result::GetIconHint() const { return GetStringAt(1); } | 78 | std::string Result::GetIconHint() const { return GetStringAt(ResultColumn::ICON_HINT); } |
1110 | 62 | std::size_t Result::GetCategoryIndex() const { return GetUIntAt(2); } | 79 | unsigned Result::GetCategoryIndex() const { return GetUIntAt(ResultColumn::CATEGORY); } |
1111 | 63 | std::string Result::GetMimeType() const { return GetStringAt(3); } | 80 | unsigned Result::GetResultType() const { return GetUIntAt(ResultColumn::RESULT_TYPE); } |
1112 | 64 | std::string Result::GetName() const { return GetStringAt(4); } | 81 | std::string Result::GetMimeType() const { return GetStringAt(ResultColumn::MIMETYPE); } |
1113 | 65 | std::string Result::GetComment() const { return GetStringAt(5); } | 82 | std::string Result::GetName() const { return GetStringAt(ResultColumn::TITLE); } |
1114 | 66 | std::string Result::GetDndURI() const { return GetStringAt(6); } | 83 | std::string Result::GetComment() const { return GetStringAt(ResultColumn::COMMENT); } |
1115 | 84 | std::string Result::GetDndURI() const { return GetStringAt(ResultColumn::DND_URI); } | ||
1116 | 67 | 85 | ||
1117 | 68 | } | 86 | } |
1118 | 69 | } | 87 | } |
1119 | 70 | 88 | ||
1120 | === modified file 'UnityCore/Result.h' | |||
1121 | --- UnityCore/Result.h 2012-12-06 17:41:07 +0000 | |||
1122 | +++ UnityCore/Result.h 2013-02-21 10:37:29 +0000 | |||
1123 | @@ -45,7 +45,8 @@ | |||
1124 | 45 | 45 | ||
1125 | 46 | nux::ROProperty<std::string> uri; | 46 | nux::ROProperty<std::string> uri; |
1126 | 47 | nux::ROProperty<std::string> icon_hint; | 47 | nux::ROProperty<std::string> icon_hint; |
1128 | 48 | nux::ROProperty<std::size_t> category_index; | 48 | nux::ROProperty<unsigned> category_index; |
1129 | 49 | nux::ROProperty<unsigned> result_type; | ||
1130 | 49 | nux::ROProperty<std::string> mimetype; | 50 | nux::ROProperty<std::string> mimetype; |
1131 | 50 | nux::ROProperty<std::string> name; | 51 | nux::ROProperty<std::string> name; |
1132 | 51 | nux::ROProperty<std::string> comment; | 52 | nux::ROProperty<std::string> comment; |
1133 | @@ -54,7 +55,8 @@ | |||
1134 | 54 | protected: | 55 | protected: |
1135 | 55 | virtual std::string GetURI() const; | 56 | virtual std::string GetURI() const; |
1136 | 56 | virtual std::string GetIconHint() const; | 57 | virtual std::string GetIconHint() const; |
1138 | 57 | virtual std::size_t GetCategoryIndex() const; | 58 | virtual unsigned GetCategoryIndex() const; |
1139 | 59 | virtual unsigned GetResultType() const; | ||
1140 | 58 | virtual std::string GetMimeType() const; | 60 | virtual std::string GetMimeType() const; |
1141 | 59 | virtual std::string GetName() const; | 61 | virtual std::string GetName() const; |
1142 | 60 | virtual std::string GetComment() const; | 62 | virtual std::string GetComment() const; |
1143 | 61 | 63 | ||
1144 | === modified file 'UnityCore/Results.cpp' | |||
1145 | --- UnityCore/Results.cpp 2012-04-23 12:29:20 +0000 | |||
1146 | +++ UnityCore/Results.cpp 2013-02-21 10:37:29 +0000 | |||
1147 | @@ -25,6 +25,7 @@ | |||
1148 | 25 | { | 25 | { |
1149 | 26 | 26 | ||
1150 | 27 | Results::Results() | 27 | Results::Results() |
1151 | 28 | : Model<Result>::Model(ModelType::REMOTE_SHARED) | ||
1152 | 28 | { | 29 | { |
1153 | 29 | row_added.connect(sigc::mem_fun(this, &Results::OnRowAdded)); | 30 | row_added.connect(sigc::mem_fun(this, &Results::OnRowAdded)); |
1154 | 30 | row_changed.connect(sigc::mem_fun(this, &Results::OnRowChanged)); | 31 | row_changed.connect(sigc::mem_fun(this, &Results::OnRowChanged)); |
1155 | 31 | 32 | ||
1156 | === added file 'UnityCore/Scope.cpp' | |||
1157 | --- UnityCore/Scope.cpp 1970-01-01 00:00:00 +0000 | |||
1158 | +++ UnityCore/Scope.cpp 2013-02-21 10:37:29 +0000 | |||
1159 | @@ -0,0 +1,211 @@ | |||
1160 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
1161 | 2 | /* | ||
1162 | 3 | * Copyright (C) 2013 Canonical Ltd | ||
1163 | 4 | * | ||
1164 | 5 | * This program is free software: you can redistribute it and/or modify | ||
1165 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
1166 | 7 | * published by the Free Software Foundation. | ||
1167 | 8 | * | ||
1168 | 9 | * This program is distributed in the hope that it will be useful, | ||
1169 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1170 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1171 | 12 | * GNU General Public License for more details. | ||
1172 | 13 | * | ||
1173 | 14 | * You should have received a copy of the GNU General Public License | ||
1174 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1175 | 16 | * | ||
1176 | 17 | * Authored by: Nick Dedekind <nick.dedekind@canonical.com> | ||
1177 | 18 | * | ||
1178 | 19 | */ | ||
1179 | 20 | |||
1180 | 21 | #include "Scope.h" | ||
1181 | 22 | #include "MiscUtils.h" | ||
1182 | 23 | #include "ScopeProxy.h" | ||
1183 | 24 | #include <unity-protocol.h> | ||
1184 | 25 | |||
1185 | 26 | |||
1186 | 27 | namespace unity | ||
1187 | 28 | { | ||
1188 | 29 | namespace dash | ||
1189 | 30 | { | ||
1190 | 31 | DECLARE_LOGGER(logger, "unity.dash.scope"); | ||
1191 | 32 | |||
1192 | 33 | class Scope::Impl | ||
1193 | 34 | { | ||
1194 | 35 | public: | ||
1195 | 36 | Impl(Scope* owner, ScopeData::Ptr const& scope_data); | ||
1196 | 37 | ~Impl(); | ||
1197 | 38 | |||
1198 | 39 | void Init(); | ||
1199 | 40 | |||
1200 | 41 | void Activate(std::string const& uri, guint action_type, glib::HintsMap const& hints, ActivateCallback const& callback, GCancellable* cancellable); | ||
1201 | 42 | void OnActivateReply(std::string const& uri, ScopeHandledType handled_type, glib::HintsMap const& hints, glib::Error const& error); | ||
1202 | 43 | |||
1203 | 44 | DeeFilter* GetFilterForCategory(unsigned category, DeeFilter* filter) const; | ||
1204 | 45 | |||
1205 | 46 | Scope* owner_; | ||
1206 | 47 | ScopeData::Ptr scope_data_; | ||
1207 | 48 | ScopeProxyInterface::Ptr proxy_; | ||
1208 | 49 | |||
1209 | 50 | typedef std::shared_ptr<sigc::connection> ConnectionPtr; | ||
1210 | 51 | std::vector<ConnectionPtr> property_connections; | ||
1211 | 52 | }; | ||
1212 | 53 | |||
1213 | 54 | Scope::Impl::Impl(Scope* owner, ScopeData::Ptr const& scope_data) | ||
1214 | 55 | : owner_(owner) | ||
1215 | 56 | , scope_data_(scope_data) | ||
1216 | 57 | { | ||
1217 | 58 | property_connections.push_back(utils::ConnectProperties(owner_->id, scope_data_->id)); | ||
1218 | 59 | } | ||
1219 | 60 | |||
1220 | 61 | Scope::Impl::~Impl() | ||
1221 | 62 | { | ||
1222 | 63 | for_each(property_connections.begin(), property_connections.end(), [](ConnectionPtr const& con) { con->disconnect(); }); | ||
1223 | 64 | property_connections.clear(); | ||
1224 | 65 | } | ||
1225 | 66 | |||
1226 | 67 | void Scope::Impl::Init() | ||
1227 | 68 | { | ||
1228 | 69 | proxy_ = owner_->CreateProxyInterface(); | ||
1229 | 70 | |||
1230 | 71 | if (proxy_) | ||
1231 | 72 | { | ||
1232 | 73 | property_connections.push_back(utils::ConnectProperties(owner_->connected, proxy_->connected)); | ||
1233 | 74 | property_connections.push_back(utils::ConnectProperties(owner_->is_master, proxy_->is_master)); | ||
1234 | 75 | property_connections.push_back(utils::ConnectProperties(owner_->search_in_global, proxy_->search_in_global)); | ||
1235 | 76 | property_connections.push_back(utils::ConnectProperties(owner_->search_hint, proxy_->search_hint)); | ||
1236 | 77 | property_connections.push_back(utils::ConnectProperties(owner_->view_type, proxy_->view_type)); | ||
1237 | 78 | property_connections.push_back(utils::ConnectProperties(owner_->results, proxy_->results)); | ||
1238 | 79 | property_connections.push_back(utils::ConnectProperties(owner_->filters, proxy_->filters)); | ||
1239 | 80 | property_connections.push_back(utils::ConnectProperties(owner_->categories, proxy_->categories)); | ||
1240 | 81 | property_connections.push_back(utils::ConnectProperties(owner_->category_order, proxy_->category_order)); | ||
1241 | 82 | |||
1242 | 83 | property_connections.push_back(utils::ConnectProperties(owner_->name, proxy_->name)); | ||
1243 | 84 | property_connections.push_back(utils::ConnectProperties(owner_->description, proxy_->description)); | ||
1244 | 85 | property_connections.push_back(utils::ConnectProperties(owner_->icon_hint, proxy_->icon_hint)); | ||
1245 | 86 | property_connections.push_back(utils::ConnectProperties(owner_->category_icon_hint, proxy_->category_icon_hint)); | ||
1246 | 87 | property_connections.push_back(utils::ConnectProperties(owner_->keywords, proxy_->keywords)); | ||
1247 | 88 | property_connections.push_back(utils::ConnectProperties(owner_->type, proxy_->type)); | ||
1248 | 89 | property_connections.push_back(utils::ConnectProperties(owner_->query_pattern, proxy_->query_pattern)); | ||
1249 | 90 | property_connections.push_back(utils::ConnectProperties(owner_->shortcut, proxy_->shortcut)); | ||
1250 | 91 | property_connections.push_back(utils::ConnectProperties(owner_->visible, proxy_->visible)); | ||
1251 | 92 | |||
1252 | 93 | property_connections.push_back(utils::ConnectProperties(owner_->results, proxy_->results)); | ||
1253 | 94 | property_connections.push_back(utils::ConnectProperties(owner_->filters, proxy_->filters)); | ||
1254 | 95 | property_connections.push_back(utils::ConnectProperties(owner_->categories, proxy_->categories)); | ||
1255 | 96 | } | ||
1256 | 97 | } | ||
1257 | 98 | |||
1258 | 99 | void Scope::Impl::Activate(std::string const& uri, guint action_type, glib::HintsMap const& hints, ActivateCallback const& callback, GCancellable* cancellable) | ||
1259 | 100 | { | ||
1260 | 101 | proxy_->Activate(uri, | ||
1261 | 102 | action_type, | ||
1262 | 103 | hints, | ||
1263 | 104 | [this, callback] (std::string const& uri, ScopeHandledType handled_type, glib::HintsMap const& hints, glib::Error const& error) { | ||
1264 | 105 | if (callback) | ||
1265 | 106 | callback(uri, handled_type, error); | ||
1266 | 107 | OnActivateReply(uri, handled_type, hints, error); | ||
1267 | 108 | }, | ||
1268 | 109 | cancellable); | ||
1269 | 110 | } | ||
1270 | 111 | |||
1271 | 112 | |||
1272 | 113 | void Scope::Impl::OnActivateReply(std::string const& uri, ScopeHandledType handled, glib::HintsMap const& hints, glib::Error const& error) | ||
1273 | 114 | { | ||
1274 | 115 | LOG_DEBUG(logger) << "Activation reply (handled:" << handled << ", error: " << (error ? "true" : "false") << ") for " << uri; | ||
1275 | 116 | |||
1276 | 117 | if (static_cast<UnityProtocolHandledType>(handled) == UNITY_PROTOCOL_HANDLED_TYPE_SHOW_PREVIEW) | ||
1277 | 118 | { | ||
1278 | 119 | auto iter = hints.find("preview"); | ||
1279 | 120 | if (iter != hints.end()) | ||
1280 | 121 | { | ||
1281 | 122 | glib::Variant v = iter->second; | ||
1282 | 123 | |||
1283 | 124 | Preview::Ptr preview(Preview::PreviewForVariant(v)); | ||
1284 | 125 | if (preview) | ||
1285 | 126 | { | ||
1286 | 127 | // would be nice to make parent_scope_ a shared_ptr, | ||
1287 | 128 | // but that's not really doable from here | ||
1288 | 129 | preview->parent_scope = owner_; | ||
1289 | 130 | preview->preview_uri = uri; | ||
1290 | 131 | owner_->preview_ready.emit(uri, preview); | ||
1291 | 132 | return; | ||
1292 | 133 | } | ||
1293 | 134 | } | ||
1294 | 135 | |||
1295 | 136 | LOG_WARNING(logger) << "Unable to deserialize Preview"; | ||
1296 | 137 | } | ||
1297 | 138 | else | ||
1298 | 139 | { | ||
1299 | 140 | owner_->activated.emit(uri, handled, hints); | ||
1300 | 141 | } | ||
1301 | 142 | } | ||
1302 | 143 | |||
1303 | 144 | Scope::Scope(ScopeData::Ptr const& scope_data) | ||
1304 | 145 | : pimpl(new Impl(this, scope_data)) | ||
1305 | 146 | { | ||
1306 | 147 | } | ||
1307 | 148 | |||
1308 | 149 | Scope::~Scope() | ||
1309 | 150 | { | ||
1310 | 151 | } | ||
1311 | 152 | |||
1312 | 153 | void Scope::Init() | ||
1313 | 154 | { | ||
1314 | 155 | pimpl->Init(); | ||
1315 | 156 | } | ||
1316 | 157 | |||
1317 | 158 | void Scope::Connect() | ||
1318 | 159 | { | ||
1319 | 160 | if (pimpl->proxy_->connected()) | ||
1320 | 161 | return; | ||
1321 | 162 | |||
1322 | 163 | pimpl->proxy_->CreateProxy(); | ||
1323 | 164 | } | ||
1324 | 165 | |||
1325 | 166 | void Scope::Search(std::string const& search_hint, SearchCallback const& callback, GCancellable* cancellable) | ||
1326 | 167 | { | ||
1327 | 168 | return pimpl->proxy_->Search(search_hint, callback, cancellable); | ||
1328 | 169 | } | ||
1329 | 170 | |||
1330 | 171 | void Scope::Activate(std::string const& uri, ActivateCallback const& callback, GCancellable* cancellable) | ||
1331 | 172 | { | ||
1332 | 173 | pimpl->Activate(uri, UNITY_PROTOCOL_ACTION_TYPE_ACTIVATE_RESULT, glib::HintsMap(), callback, cancellable); | ||
1333 | 174 | } | ||
1334 | 175 | |||
1335 | 176 | void Scope::Preview(std::string const& uri, ActivateCallback const& callback, GCancellable* cancellable) | ||
1336 | 177 | { | ||
1337 | 178 | pimpl->Activate(uri, UNITY_PROTOCOL_ACTION_TYPE_PREVIEW_RESULT, glib::HintsMap(), callback, cancellable); | ||
1338 | 179 | } | ||
1339 | 180 | |||
1340 | 181 | void Scope::ActivatePreviewAction(std::string const& action_id, | ||
1341 | 182 | std::string const& uri, | ||
1342 | 183 | glib::HintsMap const& hints, | ||
1343 | 184 | ActivateCallback const& callback, | ||
1344 | 185 | GCancellable* cancellable) | ||
1345 | 186 | { | ||
1346 | 187 | std::string activation_uri(action_id); | ||
1347 | 188 | activation_uri += ":"; | ||
1348 | 189 | activation_uri += uri; | ||
1349 | 190 | |||
1350 | 191 | pimpl->Activate(activation_uri, UNITY_PROTOCOL_ACTION_TYPE_PREVIEW_ACTION, hints, callback, cancellable); | ||
1351 | 192 | } | ||
1352 | 193 | |||
1353 | 194 | void Scope::UpdatePreviewProperty(std::string const& uri, glib::HintsMap const& hints, UpdatePreviewPropertyCallback const& callback, GCancellable* cancellable) | ||
1354 | 195 | { | ||
1355 | 196 | pimpl->proxy_->UpdatePreviewProperty(uri, glib::HintsMap(), callback, cancellable); | ||
1356 | 197 | } | ||
1357 | 198 | |||
1358 | 199 | Results::Ptr Scope::GetResultsForCategory(unsigned category) const | ||
1359 | 200 | { | ||
1360 | 201 | return pimpl->proxy_->GetResultsForCategory(category); | ||
1361 | 202 | } | ||
1362 | 203 | |||
1363 | 204 | ScopeProxyInterface::Ptr Scope::CreateProxyInterface() const | ||
1364 | 205 | { | ||
1365 | 206 | return ScopeProxyInterface::Ptr(new ScopeProxy(pimpl->scope_data_)); | ||
1366 | 207 | } | ||
1367 | 208 | |||
1368 | 209 | |||
1369 | 210 | } // namespace dash | ||
1370 | 211 | } // namespace unity | ||
1371 | 0 | 212 | ||
1372 | === added file 'UnityCore/Scope.h' | |||
1373 | --- UnityCore/Scope.h 1970-01-01 00:00:00 +0000 | |||
1374 | +++ UnityCore/Scope.h 2013-02-21 10:37:29 +0000 | |||
1375 | @@ -0,0 +1,105 @@ | |||
1376 | 1 | /* | ||
1377 | 2 | * Copyright (C) 2013 Canonical Ltd | ||
1378 | 3 | * | ||
1379 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1380 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
1381 | 6 | * published by the Free Software Foundation. | ||
1382 | 7 | * | ||
1383 | 8 | * This program is distributed in the hope that it will be useful, | ||
1384 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1385 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1386 | 11 | * GNU General Public License for more details. | ||
1387 | 12 | * | ||
1388 | 13 | * You should have received a copy of the GNU General Public License | ||
1389 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1390 | 15 | * | ||
1391 | 16 | * Authored by: Nick Dedekind <nick.dedekind@canonical.com> | ||
1392 | 17 | */ | ||
1393 | 18 | |||
1394 | 19 | #ifndef UNITY_SCOPE_H | ||
1395 | 20 | #define UNITY_SCOPE_H | ||
1396 | 21 | |||
1397 | 22 | #include <boost/noncopyable.hpp> | ||
1398 | 23 | #include <sigc++/trackable.h> | ||
1399 | 24 | |||
1400 | 25 | #include "ScopeProxyInterface.h" | ||
1401 | 26 | #include "Preview.h" | ||
1402 | 27 | #include "Result.h" | ||
1403 | 28 | |||
1404 | 29 | namespace unity | ||
1405 | 30 | { | ||
1406 | 31 | namespace dash | ||
1407 | 32 | { | ||
1408 | 33 | |||
1409 | 34 | class Scope : public sigc::trackable, boost::noncopyable | ||
1410 | 35 | { | ||
1411 | 36 | public: | ||
1412 | 37 | typedef std::shared_ptr<Scope> Ptr; | ||
1413 | 38 | |||
1414 | 39 | Scope(ScopeData::Ptr const& scope_data); | ||
1415 | 40 | virtual ~Scope(); | ||
1416 | 41 | |||
1417 | 42 | // Must call this function after construction. | ||
1418 | 43 | virtual void Init(); | ||
1419 | 44 | |||
1420 | 45 | void Connect(); | ||
1421 | 46 | |||
1422 | 47 | nux::ROProperty<std::string> id; | ||
1423 | 48 | nux::ROProperty<bool> connected; | ||
1424 | 49 | |||
1425 | 50 | nux::ROProperty<bool> visible; | ||
1426 | 51 | nux::ROProperty<bool> is_master; | ||
1427 | 52 | nux::ROProperty<bool> search_in_global; | ||
1428 | 53 | nux::ROProperty<std::string> search_hint; | ||
1429 | 54 | nux::RWProperty<ScopeViewType> view_type; | ||
1430 | 55 | |||
1431 | 56 | nux::ROProperty<Results::Ptr> results; | ||
1432 | 57 | nux::ROProperty<Filters::Ptr> filters; | ||
1433 | 58 | nux::ROProperty<Categories::Ptr> categories; | ||
1434 | 59 | nux::ROProperty<std::vector<int>> category_order; | ||
1435 | 60 | |||
1436 | 61 | nux::ROProperty<std::string> name; | ||
1437 | 62 | nux::ROProperty<std::string> description; | ||
1438 | 63 | nux::ROProperty<std::string> icon_hint; | ||
1439 | 64 | nux::ROProperty<std::string> category_icon_hint; | ||
1440 | 65 | nux::ROProperty<std::vector<std::string>> keywords; | ||
1441 | 66 | nux::ROProperty<std::string> type; | ||
1442 | 67 | nux::ROProperty<std::string> query_pattern; | ||
1443 | 68 | nux::ROProperty<std::string> shortcut; | ||
1444 | 69 | |||
1445 | 70 | typedef std::function<void(glib::HintsMap const&, glib::Error const&)> SearchCallback; | ||
1446 | 71 | virtual void Search(std::string const& search_hint, SearchCallback const& callback = nullptr, GCancellable* cancellable = nullptr); | ||
1447 | 72 | |||
1448 | 73 | typedef std::function<void(std::string const&, ScopeHandledType, glib::Error const&)> ActivateCallback; | ||
1449 | 74 | |||
1450 | 75 | virtual void Activate(std::string const& uri, ActivateCallback const& callback = nullptr, GCancellable* cancellable = nullptr); | ||
1451 | 76 | |||
1452 | 77 | virtual void Preview(std::string const& uri, ActivateCallback const& callback = nullptr, GCancellable* cancellable = nullptr); | ||
1453 | 78 | |||
1454 | 79 | virtual void ActivatePreviewAction(std::string const& action_id, | ||
1455 | 80 | std::string const& uri, | ||
1456 | 81 | glib::HintsMap const& hints, | ||
1457 | 82 | ActivateCallback const& callback = nullptr, | ||
1458 | 83 | GCancellable* cancellable = nullptr); | ||
1459 | 84 | |||
1460 | 85 | typedef std::function<void(glib::HintsMap const&, glib::Error const&)> UpdatePreviewPropertyCallback; | ||
1461 | 86 | virtual void UpdatePreviewProperty(std::string const& uri, glib::HintsMap const& hints, UpdatePreviewPropertyCallback const& callback = nullptr, GCancellable* cancellable = nullptr); | ||
1462 | 87 | |||
1463 | 88 | virtual Results::Ptr GetResultsForCategory(unsigned category) const; | ||
1464 | 89 | |||
1465 | 90 | |||
1466 | 91 | sigc::signal<void, std::string const&, ScopeHandledType, glib::HintsMap const&> activated; | ||
1467 | 92 | sigc::signal<void, std::string const&, Preview::Ptr const&> preview_ready; | ||
1468 | 93 | |||
1469 | 94 | protected: | ||
1470 | 95 | virtual ScopeProxyInterface::Ptr CreateProxyInterface() const; | ||
1471 | 96 | |||
1472 | 97 | private: | ||
1473 | 98 | class Impl; | ||
1474 | 99 | std::unique_ptr<Impl> pimpl; | ||
1475 | 100 | }; | ||
1476 | 101 | |||
1477 | 102 | } // namespace dash | ||
1478 | 103 | } // namespace unity | ||
1479 | 104 | |||
1480 | 105 | #endif // UNITY_SCOPE_H | ||
1481 | 0 | \ No newline at end of file | 106 | \ No newline at end of file |
1482 | 1 | 107 | ||
1483 | === added file 'UnityCore/ScopeData.cpp' | |||
1484 | --- UnityCore/ScopeData.cpp 1970-01-01 00:00:00 +0000 | |||
1485 | +++ UnityCore/ScopeData.cpp 2013-02-21 10:37:29 +0000 | |||
1486 | @@ -0,0 +1,89 @@ | |||
1487 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
1488 | 2 | /* | ||
1489 | 3 | * Copyright (C) 2013 Canonical Ltd | ||
1490 | 4 | * | ||
1491 | 5 | * This program is free software: you can redistribute it and/or modify | ||
1492 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
1493 | 7 | * published by the Free Software Foundation. | ||
1494 | 8 | * | ||
1495 | 9 | * This program is distributed in the hope that it will be useful, | ||
1496 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1497 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1498 | 12 | * GNU General Public License for more details. | ||
1499 | 13 | * | ||
1500 | 14 | * You should have received a copy of the GNU General Public License | ||
1501 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1502 | 16 | * | ||
1503 | 17 | * Authored by: Nick Dedekind <nick.dedekind@canonical.com> | ||
1504 | 18 | */ | ||
1505 | 19 | |||
1506 | 20 | |||
1507 | 21 | #include "ScopeData.h" | ||
1508 | 22 | #include <unity-protocol.h> | ||
1509 | 23 | #include <NuxCore/Logger.h> | ||
1510 | 24 | |||
1511 | 25 | #include "GLibWrapper.h" | ||
1512 | 26 | |||
1513 | 27 | namespace unity | ||
1514 | 28 | { | ||
1515 | 29 | namespace dash | ||
1516 | 30 | { | ||
1517 | 31 | |||
1518 | 32 | namespace | ||
1519 | 33 | { | ||
1520 | 34 | static void safe_delete_scope_metadata(UnityProtocolScopeRegistryScopeMetadata* data) | ||
1521 | 35 | { | ||
1522 | 36 | if (!data) return; | ||
1523 | 37 | unity_protocol_scope_registry_scope_metadata_unref(data); | ||
1524 | 38 | } | ||
1525 | 39 | } | ||
1526 | 40 | |||
1527 | 41 | ScopeData::ScopeData() | ||
1528 | 42 | : visible(true) | ||
1529 | 43 | { | ||
1530 | 44 | } | ||
1531 | 45 | |||
1532 | 46 | ScopeData::Ptr ScopeData::ReadProtocolDataForId(std::string const& scope_id, glib::Error& error) | ||
1533 | 47 | { | ||
1534 | 48 | ScopeData::Ptr data(new ScopeData()); | ||
1535 | 49 | |||
1536 | 50 | std::shared_ptr<UnityProtocolScopeRegistryScopeMetadata> meta_data(unity_protocol_scope_registry_scope_metadata_for_id(scope_id.c_str(), &error), | ||
1537 | 51 | safe_delete_scope_metadata); | ||
1538 | 52 | |||
1539 | 53 | if (error) | ||
1540 | 54 | { | ||
1541 | 55 | data->id = scope_id; | ||
1542 | 56 | } | ||
1543 | 57 | else if (meta_data) | ||
1544 | 58 | { | ||
1545 | 59 | data->dbus_name = glib::gchar_to_string(meta_data->dbus_name); | ||
1546 | 60 | data->dbus_path = glib::gchar_to_string(meta_data->dbus_path); | ||
1547 | 61 | |||
1548 | 62 | data->id = glib::gchar_to_string(meta_data->id); | ||
1549 | 63 | data->full_path = glib::gchar_to_string(meta_data->full_path); | ||
1550 | 64 | data->name = glib::gchar_to_string(meta_data->name); | ||
1551 | 65 | data->icon_hint = glib::gchar_to_string(meta_data->icon); | ||
1552 | 66 | data->category_icon_hint = glib::gchar_to_string(meta_data->category_icon); | ||
1553 | 67 | data->type = meta_data->type; | ||
1554 | 68 | data->description = glib::gchar_to_string(meta_data->description); | ||
1555 | 69 | data->shortcut = glib::gchar_to_string(meta_data->shortcut); | ||
1556 | 70 | data->search_hint = glib::gchar_to_string(meta_data->search_hint); | ||
1557 | 71 | data->is_master = meta_data->is_master; | ||
1558 | 72 | data->query_pattern = glib::gchar_to_string(meta_data->query_pattern); | ||
1559 | 73 | |||
1560 | 74 | std::vector<std::string> keywords; | ||
1561 | 75 | for (GSList* v = meta_data->keywords; v; v = g_slist_next(v)) | ||
1562 | 76 | { | ||
1563 | 77 | std::string value(static_cast<gchar*>(v->data)); | ||
1564 | 78 | if (value.empty()) | ||
1565 | 79 | continue; | ||
1566 | 80 | |||
1567 | 81 | keywords.push_back(value); | ||
1568 | 82 | } | ||
1569 | 83 | data->keywords = keywords; | ||
1570 | 84 | } | ||
1571 | 85 | return data; | ||
1572 | 86 | } | ||
1573 | 87 | |||
1574 | 88 | } | ||
1575 | 89 | } | ||
1576 | 0 | \ No newline at end of file | 90 | \ No newline at end of file |
1577 | 1 | 91 | ||
1578 | === added file 'UnityCore/ScopeData.h' | |||
1579 | --- UnityCore/ScopeData.h 1970-01-01 00:00:00 +0000 | |||
1580 | +++ UnityCore/ScopeData.h 2013-02-21 10:37:29 +0000 | |||
1581 | @@ -0,0 +1,68 @@ | |||
1582 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
1583 | 2 | /* | ||
1584 | 3 | * Copyright (C) 2013 Canonical Ltd | ||
1585 | 4 | * | ||
1586 | 5 | * This program is free software: you can redistribute it and/or modify | ||
1587 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
1588 | 7 | * published by the Free Software Foundation. | ||
1589 | 8 | * | ||
1590 | 9 | * This program is distributed in the hope that it will be useful, | ||
1591 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1592 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1593 | 12 | * GNU General Public License for more details. | ||
1594 | 13 | * | ||
1595 | 14 | * You should have received a copy of the GNU General Public License | ||
1596 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1597 | 16 | * | ||
1598 | 17 | * Authored by: Nick Dedekind <nick.dedekind@canonical.com> | ||
1599 | 18 | */ | ||
1600 | 19 | |||
1601 | 20 | |||
1602 | 21 | #ifndef UNITY_SCOPE_DATA_H | ||
1603 | 22 | #define UNITY_SCOPE_DATA_H | ||
1604 | 23 | |||
1605 | 24 | #include <NuxCore/Property.h> | ||
1606 | 25 | #include "GLibWrapper.h" | ||
1607 | 26 | |||
1608 | 27 | namespace unity | ||
1609 | 28 | { | ||
1610 | 29 | namespace dash | ||
1611 | 30 | { | ||
1612 | 31 | |||
1613 | 32 | enum ScopeViewType | ||
1614 | 33 | { | ||
1615 | 34 | HIDDEN=0, | ||
1616 | 35 | HOME_VIEW, | ||
1617 | 36 | SCOPE_VIEW | ||
1618 | 37 | }; | ||
1619 | 38 | |||
1620 | 39 | class ScopeData | ||
1621 | 40 | { | ||
1622 | 41 | public: | ||
1623 | 42 | typedef std::shared_ptr<ScopeData> Ptr; | ||
1624 | 43 | ScopeData(); | ||
1625 | 44 | |||
1626 | 45 | nux::Property<std::string> id; | ||
1627 | 46 | nux::Property<std::string> full_path; | ||
1628 | 47 | nux::Property<std::string> dbus_name; | ||
1629 | 48 | nux::Property<std::string> dbus_path; | ||
1630 | 49 | nux::Property<bool> is_master; | ||
1631 | 50 | nux::Property<std::string> icon_hint; | ||
1632 | 51 | nux::Property<std::string> category_icon_hint; | ||
1633 | 52 | nux::Property<std::vector<std::string>> keywords; | ||
1634 | 53 | nux::Property<std::string> type; | ||
1635 | 54 | nux::Property<std::string> query_pattern; | ||
1636 | 55 | nux::Property<std::string> name; | ||
1637 | 56 | nux::Property<std::string> description; | ||
1638 | 57 | nux::Property<std::string> shortcut; | ||
1639 | 58 | nux::Property<std::string> search_hint; | ||
1640 | 59 | |||
1641 | 60 | nux::Property<bool> visible; // FIXME! | ||
1642 | 61 | |||
1643 | 62 | static ScopeData::Ptr ReadProtocolDataForId(std::string const& scope_id, glib::Error& error); | ||
1644 | 63 | }; | ||
1645 | 64 | |||
1646 | 65 | } | ||
1647 | 66 | } | ||
1648 | 67 | |||
1649 | 68 | #endif | ||
1650 | 0 | \ No newline at end of file | 69 | \ No newline at end of file |
1651 | 1 | 70 | ||
1652 | === added file 'UnityCore/ScopeProxy.cpp' | |||
1653 | --- UnityCore/ScopeProxy.cpp 1970-01-01 00:00:00 +0000 | |||
1654 | +++ UnityCore/ScopeProxy.cpp 2013-02-21 10:37:29 +0000 | |||
1655 | @@ -0,0 +1,804 @@ | |||
1656 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
1657 | 2 | /* | ||
1658 | 3 | * Copyright (C) 2012 Canonical Ltd | ||
1659 | 4 | * | ||
1660 | 5 | * This program is free software: you can redistribute it and/or modify | ||
1661 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
1662 | 7 | * published by the Free Software Foundation. | ||
1663 | 8 | * | ||
1664 | 9 | * This program is distributed in the hope that it will be useful, | ||
1665 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1666 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1667 | 12 | * GNU General Public License for more details. | ||
1668 | 13 | * | ||
1669 | 14 | * You should have received a copy of the GNU General Public License | ||
1670 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1671 | 16 | * | ||
1672 | 17 | * Authored by: Nick Dedekind <nick.dedekind@canonical.com> | ||
1673 | 18 | */ | ||
1674 | 19 | |||
1675 | 20 | #include "ScopeProxy.h" | ||
1676 | 21 | #include "GLibSignal.h" | ||
1677 | 22 | #include "MiscUtils.h" | ||
1678 | 23 | |||
1679 | 24 | #include <unity-protocol.h> | ||
1680 | 25 | #include <NuxCore/Logger.h> | ||
1681 | 26 | #include "GLibSource.h" | ||
1682 | 27 | |||
1683 | 28 | namespace unity | ||
1684 | 29 | { | ||
1685 | 30 | namespace dash | ||
1686 | 31 | { | ||
1687 | 32 | |||
1688 | 33 | namespace | ||
1689 | 34 | { | ||
1690 | 35 | const int PROXY_CONNECT_TIMEOUT = 2000; | ||
1691 | 36 | |||
1692 | 37 | const unsigned CATEGORY_COLUMN = 2; | ||
1693 | 38 | } | ||
1694 | 39 | |||
1695 | 40 | |||
1696 | 41 | DECLARE_LOGGER(logger, "unity.dash.scopeproxy"); | ||
1697 | 42 | |||
1698 | 43 | class ScopeProxy::Impl | ||
1699 | 44 | { | ||
1700 | 45 | public: | ||
1701 | 46 | Impl(ScopeProxy*const owner, ScopeData::Ptr const& scope_data); | ||
1702 | 47 | ~Impl(); | ||
1703 | 48 | |||
1704 | 49 | static ScopeData::Ptr CreateData(std::string const& dbus_name, std::string const& dbus_path); | ||
1705 | 50 | |||
1706 | 51 | void CreateProxy(); | ||
1707 | 52 | void OnNewScope(GObject *source_object, GAsyncResult *res); | ||
1708 | 53 | void DestroyProxy(); | ||
1709 | 54 | |||
1710 | 55 | void OpenChannel(); | ||
1711 | 56 | void OnChannelOpened(GObject *source_object, GAsyncResult *res); | ||
1712 | 57 | |||
1713 | 58 | void CloseChannel(); | ||
1714 | 59 | static void OnCloseChannel(GObject *source_object, GAsyncResult *res, gpointer user_data); | ||
1715 | 60 | |||
1716 | 61 | void Search(std::string const& search_string, glib::HintsMap const& hints, SearchCallback const& callback, GCancellable* cancel); | ||
1717 | 62 | void Activate(std::string const& uri, uint activate_type, glib::HintsMap const& hints, ScopeProxy::ActivateCallback const& callback, GCancellable* cancellable); | ||
1718 | 63 | void UpdatePreviewProperty(std::string const& uri, glib::HintsMap const& hints, UpdatePreviewPropertyCallback const& callback, GCancellable* cancellable); | ||
1719 | 64 | |||
1720 | 65 | bool set_view_type(ScopeViewType const& view_type) | ||
1721 | 66 | { | ||
1722 | 67 | if (scope_proxy_ && unity_protocol_scope_proxy_get_view_type(scope_proxy_) != static_cast<UnityProtocolViewType>(view_type)) | ||
1723 | 68 | { | ||
1724 | 69 | unity_protocol_scope_proxy_set_view_type(scope_proxy_, static_cast<UnityProtocolViewType>(view_type)); | ||
1725 | 70 | return true; | ||
1726 | 71 | } | ||
1727 | 72 | return false; | ||
1728 | 73 | } | ||
1729 | 74 | |||
1730 | 75 | Results::Ptr results() { return results_; } | ||
1731 | 76 | Filters::Ptr filters() { return filters_; } | ||
1732 | 77 | Categories::Ptr categories() { return categories_; } | ||
1733 | 78 | |||
1734 | 79 | DeeFilter* GetFilterForCategory(unsigned category, DeeFilter* filter) const; | ||
1735 | 80 | |||
1736 | 81 | ScopeProxy*const owner_; | ||
1737 | 82 | ScopeData::Ptr scope_data_; | ||
1738 | 83 | |||
1739 | 84 | // scope proxy properties | ||
1740 | 85 | nux::Property<bool> search_in_global; | ||
1741 | 86 | nux::Property<ScopeViewType> view_type; | ||
1742 | 87 | |||
1743 | 88 | nux::Property<bool> connected; | ||
1744 | 89 | nux::Property<std::string> channel; | ||
1745 | 90 | nux::Property<std::vector<int>> category_order; | ||
1746 | 91 | std::string last_search_; | ||
1747 | 92 | |||
1748 | 93 | glib::Object<UnityProtocolScopeProxy> scope_proxy_; | ||
1749 | 94 | glib::Object<GCancellable> cancel_scope_; | ||
1750 | 95 | bool proxy_created_; | ||
1751 | 96 | bool scope_proxy_connected_; | ||
1752 | 97 | bool searching_; | ||
1753 | 98 | |||
1754 | 99 | Results::Ptr results_; | ||
1755 | 100 | Filters::Ptr filters_; | ||
1756 | 101 | Categories::Ptr categories_; | ||
1757 | 102 | |||
1758 | 103 | typedef std::shared_ptr<sigc::connection> ConnectionPtr; | ||
1759 | 104 | std::vector<ConnectionPtr> property_connections; | ||
1760 | 105 | sigc::connection filters_change_connection; | ||
1761 | 106 | |||
1762 | 107 | ///////////////////////////////////////////////// | ||
1763 | 108 | // DBus property signals. | ||
1764 | 109 | glib::Signal<void, UnityProtocolScopeProxy*, GParamSpec*> connected_signal_; | ||
1765 | 110 | glib::Signal<void, UnityProtocolScopeProxy*, GParamSpec*> search_in_global_signal_; | ||
1766 | 111 | glib::Signal<void, UnityProtocolScopeProxy*, GParamSpec*> is_master_signal_; | ||
1767 | 112 | glib::Signal<void, UnityProtocolScopeProxy*, GParamSpec*> search_hint_signal_; | ||
1768 | 113 | glib::Signal<void, UnityProtocolScopeProxy*, GParamSpec*> view_type_signal_; | ||
1769 | 114 | glib::Signal<void, UnityProtocolScopeProxy*, GParamSpec*> filters_signal_; | ||
1770 | 115 | glib::Signal<void, UnityProtocolScopeProxy*, GParamSpec*> categories_signal_; | ||
1771 | 116 | glib::Signal<void, UnityProtocolScopeProxy*, GParamSpec*> metadata_signal_; | ||
1772 | 117 | glib::Signal<void, UnityProtocolScopeProxy*, GParamSpec*> optional_metadata_signal_; | ||
1773 | 118 | glib::Signal<void, UnityProtocolScopeProxy*, const gchar*, guint32*, int> category_order_signal_; | ||
1774 | 119 | ///////////////////////////////////////////////// | ||
1775 | 120 | |||
1776 | 121 | private: | ||
1777 | 122 | ///////////////////////////////////////////////// | ||
1778 | 123 | // Signal Connections | ||
1779 | 124 | void OnScopeConnectedChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param); | ||
1780 | 125 | void OnScopeIsMasterChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param); | ||
1781 | 126 | void OnScopeSearchInGlobalChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param); | ||
1782 | 127 | void OnScopeSearchHintChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param); | ||
1783 | 128 | void OnScopeViewTypeChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param); | ||
1784 | 129 | void OnScopeFiltersChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param); | ||
1785 | 130 | void OnScopeCategoriesChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param); | ||
1786 | 131 | void OnScopeMetadataChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param); | ||
1787 | 132 | void OnScopeOptionalMetadataChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param); | ||
1788 | 133 | void OnScopeCategoryOrderChanged(UnityProtocolScopeProxy* sender, const gchar* channel_id, guint32* new_order, int new_order_length1); | ||
1789 | 134 | ///////////////////////////////////////////////// | ||
1790 | 135 | |||
1791 | 136 | void WaitForProxyConnection(GCancellable* cancellable, | ||
1792 | 137 | int timeout_msec, | ||
1793 | 138 | std::function<void(glib::Error const&)> const& callback); | ||
1794 | 139 | |||
1795 | 140 | ///////////////////////////////////// | ||
1796 | 141 | // Search Callback | ||
1797 | 142 | struct SearchData | ||
1798 | 143 | { | ||
1799 | 144 | SearchCallback callback; | ||
1800 | 145 | }; | ||
1801 | 146 | |||
1802 | 147 | static void OnScopeSearchCallback(GObject *source_object, GAsyncResult *res, gpointer user_data) | ||
1803 | 148 | { | ||
1804 | 149 | std::unique_ptr<SearchData> data(static_cast<SearchData*>(user_data)); | ||
1805 | 150 | glib::Error error; | ||
1806 | 151 | GHashTable* hint_ret = unity_protocol_scope_proxy_search_finish(UNITY_PROTOCOL_SCOPE_PROXY(source_object), res, &error); | ||
1807 | 152 | |||
1808 | 153 | glib::HintsMap hints; | ||
1809 | 154 | glib::hintsmap_from_hashtable(hint_ret, hints); | ||
1810 | 155 | |||
1811 | 156 | if (data->callback) | ||
1812 | 157 | data->callback(hints, error); | ||
1813 | 158 | if (hint_ret) { g_hash_table_destroy(hint_ret); } | ||
1814 | 159 | } | ||
1815 | 160 | ///////////////////////////////////// | ||
1816 | 161 | |||
1817 | 162 | ///////////////////////////////////// | ||
1818 | 163 | // Search Callback | ||
1819 | 164 | struct UpdatePreviewPropertyData | ||
1820 | 165 | { | ||
1821 | 166 | UpdatePreviewPropertyCallback callback; | ||
1822 | 167 | }; | ||
1823 | 168 | |||
1824 | 169 | static void OnScopeUpdatePreviewPropertyCallback(GObject *source_object, GAsyncResult *res, gpointer user_data) | ||
1825 | 170 | { | ||
1826 | 171 | std::unique_ptr<UpdatePreviewPropertyData> data(static_cast<UpdatePreviewPropertyData*>(user_data)); | ||
1827 | 172 | glib::Error error; | ||
1828 | 173 | GHashTable* hint_ret = unity_protocol_scope_proxy_update_preview_property_finish(UNITY_PROTOCOL_SCOPE_PROXY(source_object), res, &error); | ||
1829 | 174 | |||
1830 | 175 | glib::HintsMap hints; | ||
1831 | 176 | glib::hintsmap_from_hashtable(hint_ret, hints); | ||
1832 | 177 | |||
1833 | 178 | if (data->callback) | ||
1834 | 179 | data->callback(hints, error); | ||
1835 | 180 | |||
1836 | 181 | if (hint_ret) { g_hash_table_destroy(hint_ret); } | ||
1837 | 182 | } | ||
1838 | 183 | ///////////////////////////////////// | ||
1839 | 184 | |||
1840 | 185 | ///////////////////////////////////// | ||
1841 | 186 | // Activation Callback | ||
1842 | 187 | struct ActivateData | ||
1843 | 188 | { | ||
1844 | 189 | ScopeProxy::ActivateCallback callback; | ||
1845 | 190 | }; | ||
1846 | 191 | static void OnScopeActivateCallback(GObject *source_object, GAsyncResult *res, gpointer user_data) | ||
1847 | 192 | { | ||
1848 | 193 | std::unique_ptr<ActivateData> data(static_cast<ActivateData*>(user_data)); | ||
1849 | 194 | UnityProtocolActivationReplyRaw result; | ||
1850 | 195 | glib::Error error; | ||
1851 | 196 | unity_protocol_scope_proxy_activate_finish(UNITY_PROTOCOL_SCOPE_PROXY(source_object), res, &result, &error); | ||
1852 | 197 | |||
1853 | 198 | if (data->callback) | ||
1854 | 199 | { | ||
1855 | 200 | std::string uri; | ||
1856 | 201 | ScopeHandledType handled = ScopeHandledType::NOT_HANDLED; | ||
1857 | 202 | |||
1858 | 203 | uri = result.uri; | ||
1859 | 204 | handled = static_cast<ScopeHandledType>(result.handled); | ||
1860 | 205 | |||
1861 | 206 | glib::HintsMap hints; | ||
1862 | 207 | glib::hintsmap_from_hashtable(result.hints, hints); | ||
1863 | 208 | |||
1864 | 209 | data->callback(uri, handled, hints, error); | ||
1865 | 210 | } | ||
1866 | 211 | } | ||
1867 | 212 | ///////////////////////////////////// | ||
1868 | 213 | |||
1869 | 214 | ///////////////////////////////////// | ||
1870 | 215 | // Async Calls | ||
1871 | 216 | struct ScopeAyncReplyData | ||
1872 | 217 | { | ||
1873 | 218 | typedef std::function<void(GObject *source_object, GAsyncResult *res)> ScopeAsyncReplyCallback; | ||
1874 | 219 | ScopeAyncReplyData(ScopeAsyncReplyCallback const& callback): callback(callback) {} | ||
1875 | 220 | |||
1876 | 221 | ScopeAsyncReplyCallback callback; | ||
1877 | 222 | }; | ||
1878 | 223 | static void OnScopeAsyncCallback(GObject *source_object, GAsyncResult *res, gpointer user_data) | ||
1879 | 224 | { | ||
1880 | 225 | std::unique_ptr<ScopeAyncReplyData> data(static_cast<ScopeAyncReplyData*>(user_data)); | ||
1881 | 226 | if (data->callback) | ||
1882 | 227 | data->callback(source_object, res); | ||
1883 | 228 | } | ||
1884 | 229 | ///////////////////////////////////// | ||
1885 | 230 | }; | ||
1886 | 231 | |||
1887 | 232 | |||
1888 | 233 | ScopeProxy::Impl::Impl(ScopeProxy*const owner, ScopeData::Ptr const& scope_data) | ||
1889 | 234 | : owner_(owner) | ||
1890 | 235 | , scope_data_(scope_data) | ||
1891 | 236 | , search_in_global(false) | ||
1892 | 237 | , view_type(ScopeViewType::HIDDEN) | ||
1893 | 238 | , connected(false) | ||
1894 | 239 | , cancel_scope_(g_cancellable_new()) | ||
1895 | 240 | , proxy_created_(false) | ||
1896 | 241 | , scope_proxy_connected_(false) | ||
1897 | 242 | , searching_(false) | ||
1898 | 243 | , results_(new Results()) | ||
1899 | 244 | , filters_(new Filters()) | ||
1900 | 245 | , categories_(new Categories()) | ||
1901 | 246 | { | ||
1902 | 247 | // remote properties | ||
1903 | 248 | property_connections.push_back(utils::ConnectProperties(owner_->connected, connected)); | ||
1904 | 249 | property_connections.push_back(utils::ConnectProperties(owner_->channel, channel)); | ||
1905 | 250 | property_connections.push_back(utils::ConnectProperties(owner_->search_in_global, search_in_global)); | ||
1906 | 251 | property_connections.push_back(utils::ConnectProperties(owner_->view_type, view_type)); | ||
1907 | 252 | property_connections.push_back(utils::ConnectProperties(owner_->category_order, category_order)); | ||
1908 | 253 | |||
1909 | 254 | // shared properties | ||
1910 | 255 | property_connections.push_back(utils::ConnectProperties(owner_->is_master, scope_data_->is_master)); | ||
1911 | 256 | property_connections.push_back(utils::ConnectProperties(owner_->search_hint, scope_data_->search_hint)); | ||
1912 | 257 | // local properties | ||
1913 | 258 | property_connections.push_back(utils::ConnectProperties(owner_->dbus_name, scope_data_->dbus_name)); | ||
1914 | 259 | property_connections.push_back(utils::ConnectProperties(owner_->dbus_path, scope_data_->dbus_path)); | ||
1915 | 260 | property_connections.push_back(utils::ConnectProperties(owner_->name, scope_data_->name)); | ||
1916 | 261 | property_connections.push_back(utils::ConnectProperties(owner_->description, scope_data_->description)); | ||
1917 | 262 | property_connections.push_back(utils::ConnectProperties(owner_->shortcut, scope_data_->shortcut)); | ||
1918 | 263 | property_connections.push_back(utils::ConnectProperties(owner_->icon_hint, scope_data_->icon_hint)); | ||
1919 | 264 | property_connections.push_back(utils::ConnectProperties(owner_->category_icon_hint, scope_data_->category_icon_hint)); | ||
1920 | 265 | property_connections.push_back(utils::ConnectProperties(owner_->keywords, scope_data_->keywords)); | ||
1921 | 266 | property_connections.push_back(utils::ConnectProperties(owner_->type, scope_data_->type)); | ||
1922 | 267 | property_connections.push_back(utils::ConnectProperties(owner_->query_pattern, scope_data_->query_pattern)); | ||
1923 | 268 | property_connections.push_back(utils::ConnectProperties(owner_->visible, scope_data_->visible)); | ||
1924 | 269 | |||
1925 | 270 | owner_->filters.SetGetterFunction(sigc::mem_fun(this, &Impl::filters)); | ||
1926 | 271 | owner_->categories.SetGetterFunction(sigc::mem_fun(this, &Impl::categories)); | ||
1927 | 272 | owner_->results.SetGetterFunction(sigc::mem_fun(this, &Impl::results)); | ||
1928 | 273 | } | ||
1929 | 274 | |||
1930 | 275 | ScopeProxy::Impl::~Impl() | ||
1931 | 276 | { | ||
1932 | 277 | filters_change_connection.disconnect(); | ||
1933 | 278 | for_each(property_connections.begin(), property_connections.end(), [](ConnectionPtr const& con) { con->disconnect(); }); | ||
1934 | 279 | property_connections.clear(); | ||
1935 | 280 | |||
1936 | 281 | g_cancellable_cancel(cancel_scope_); | ||
1937 | 282 | |||
1938 | 283 | if (scope_proxy_ && connected) | ||
1939 | 284 | unity_protocol_scope_proxy_close_channel(scope_proxy_, channel().c_str(), nullptr, Impl::OnCloseChannel, nullptr); | ||
1940 | 285 | } | ||
1941 | 286 | |||
1942 | 287 | ScopeData::Ptr ScopeProxy::Impl::CreateData(std::string const& dbus_name, std::string const& dbus_path) | ||
1943 | 288 | { | ||
1944 | 289 | ScopeData::Ptr data(new ScopeData); | ||
1945 | 290 | data->dbus_path = dbus_path; | ||
1946 | 291 | data->dbus_name = dbus_name; | ||
1947 | 292 | |||
1948 | 293 | return data; | ||
1949 | 294 | } | ||
1950 | 295 | |||
1951 | 296 | void ScopeProxy::Impl::DestroyProxy() | ||
1952 | 297 | { | ||
1953 | 298 | scope_proxy_.Release(); | ||
1954 | 299 | if (cancel_scope_) | ||
1955 | 300 | g_cancellable_cancel(cancel_scope_); | ||
1956 | 301 | |||
1957 | 302 | cancel_scope_ = g_cancellable_new(); | ||
1958 | 303 | connected = false; | ||
1959 | 304 | proxy_created_ = false; | ||
1960 | 305 | } | ||
1961 | 306 | |||
1962 | 307 | void ScopeProxy::Impl::CreateProxy() | ||
1963 | 308 | { | ||
1964 | 309 | if (proxy_created_) | ||
1965 | 310 | return; | ||
1966 | 311 | |||
1967 | 312 | proxy_created_ = true; | ||
1968 | 313 | unity_protocol_scope_proxy_new_from_dbus(scope_data_->dbus_name().c_str(), | ||
1969 | 314 | scope_data_->dbus_path().c_str(), | ||
1970 | 315 | cancel_scope_, | ||
1971 | 316 | Impl::OnScopeAsyncCallback, | ||
1972 | 317 | new ScopeAyncReplyData(sigc::mem_fun(this, &Impl::OnNewScope))); | ||
1973 | 318 | } | ||
1974 | 319 | |||
1975 | 320 | void ScopeProxy::Impl::OnNewScope(GObject *source_object, GAsyncResult *res) | ||
1976 | 321 | { | ||
1977 | 322 | glib::Object<UnityProtocolScopeProxy> scope_proxy; | ||
1978 | 323 | glib::Error error; | ||
1979 | 324 | scope_proxy = unity_protocol_scope_proxy_new_from_dbus_finish(res, &error); | ||
1980 | 325 | |||
1981 | 326 | search_in_global_signal_.Disconnect(); | ||
1982 | 327 | is_master_signal_.Disconnect(); | ||
1983 | 328 | search_hint_signal_.Disconnect(); | ||
1984 | 329 | view_type_signal_.Disconnect(); | ||
1985 | 330 | filters_signal_.Disconnect(); | ||
1986 | 331 | categories_signal_.Disconnect(); | ||
1987 | 332 | metadata_signal_.Disconnect(); | ||
1988 | 333 | optional_metadata_signal_.Disconnect(); | ||
1989 | 334 | |||
1990 | 335 | |||
1991 | 336 | if (error || !scope_proxy) | ||
1992 | 337 | { | ||
1993 | 338 | scope_proxy_.Release(); | ||
1994 | 339 | LOG_ERROR(logger) << "Failed to create scope proxy for " << scope_data_->id(); | ||
1995 | 340 | return; | ||
1996 | 341 | } | ||
1997 | 342 | |||
1998 | 343 | LOG_DEBUG(logger) << "Created scope proxy for " << scope_data_->id(); | ||
1999 | 344 | |||
2000 | 345 | scope_proxy_ = scope_proxy; | ||
2001 | 346 | |||
2002 | 347 | // shared properties | ||
2003 | 348 | scope_data_->is_master = unity_protocol_scope_proxy_get_is_master(scope_proxy_); | ||
2004 | 349 | scope_data_->search_hint = glib::gchar_to_string(unity_protocol_scope_proxy_get_search_hint(scope_proxy_)); | ||
2005 | 350 | // remote properties | ||
2006 | 351 | search_in_global = unity_protocol_scope_proxy_get_search_in_global(scope_proxy_); | ||
2007 | 352 | view_type = static_cast<ScopeViewType>(unity_protocol_scope_proxy_get_view_type(scope_proxy_)); | ||
2008 | 353 | |||
2009 | 354 | connected_signal_.Connect(scope_proxy_, "notify::connected", sigc::mem_fun(this, &Impl::OnScopeConnectedChanged)); | ||
2010 | 355 | search_in_global_signal_.Connect(scope_proxy_, "notify::search-in-global", sigc::mem_fun(this, &Impl::OnScopeSearchInGlobalChanged)); | ||
2011 | 356 | is_master_signal_.Connect(scope_proxy_, "notify::is-master", sigc::mem_fun(this, &Impl::OnScopeIsMasterChanged)); | ||
2012 | 357 | search_hint_signal_.Connect(scope_proxy_, "notify::search-hint", sigc::mem_fun(this, &Impl::OnScopeSearchHintChanged)); | ||
2013 | 358 | view_type_signal_.Connect(scope_proxy_, "notify::view-type", sigc::mem_fun(this, &Impl::OnScopeViewTypeChanged)); | ||
2014 | 359 | filters_signal_.Connect(scope_proxy_, "notify::filters-model", sigc::mem_fun(this, &Impl::OnScopeFiltersChanged)); | ||
2015 | 360 | categories_signal_.Connect(scope_proxy_, "notify::categories-model", sigc::mem_fun(this, &Impl::OnScopeCategoriesChanged)); | ||
2016 | 361 | metadata_signal_.Connect(scope_proxy_, "notify::metadata", sigc::mem_fun(this, &Impl::OnScopeMetadataChanged)); | ||
2017 | 362 | optional_metadata_signal_.Connect(scope_proxy_, "notify::optional-metadata", sigc::mem_fun(this, &Impl::OnScopeOptionalMetadataChanged)); | ||
2018 | 363 | category_order_signal_.Connect(scope_proxy_, "category-order-changed", sigc::mem_fun(this, &Impl::OnScopeCategoryOrderChanged)); | ||
2019 | 364 | |||
2020 | 365 | scope_proxy_connected_ = unity_protocol_scope_proxy_get_connected(scope_proxy_); | ||
2021 | 366 | |||
2022 | 367 | if (scope_proxy_connected_) | ||
2023 | 368 | OpenChannel(); | ||
2024 | 369 | else | ||
2025 | 370 | LOG_WARN(logger) << "Proxy scope not connected for " << scope_data_->id(); | ||
2026 | 371 | } | ||
2027 | 372 | |||
2028 | 373 | void ScopeProxy::Impl::OpenChannel() | ||
2029 | 374 | { | ||
2030 | 375 | if (channel != "") | ||
2031 | 376 | return; | ||
2032 | 377 | |||
2033 | 378 | unity_protocol_scope_proxy_open_channel(scope_proxy_, | ||
2034 | 379 | UNITY_PROTOCOL_CHANNEL_TYPE_DEFAULT, | ||
2035 | 380 | UNITY_PROTOCOL_CHANNEL_FLAGS_NONE, | ||
2036 | 381 | cancel_scope_, | ||
2037 | 382 | OnScopeAsyncCallback, | ||
2038 | 383 | new ScopeAyncReplyData(sigc::mem_fun(this, &Impl::OnChannelOpened))); | ||
2039 | 384 | } | ||
2040 | 385 | |||
2041 | 386 | void ScopeProxy::Impl::OnChannelOpened(GObject *source_object, GAsyncResult *res) | ||
2042 | 387 | { | ||
2043 | 388 | if (!UNITY_PROTOCOL_IS_SCOPE_PROXY(source_object)) | ||
2044 | 389 | return; | ||
2045 | 390 | |||
2046 | 391 | glib::Object<UnityProtocolScopeProxy> scope_proxy; | ||
2047 | 392 | glib::Error error; | ||
2048 | 393 | DeeSerializableModel* serialisable_model = nullptr; | ||
2049 | 394 | glib::String tmp_channel(unity_protocol_scope_proxy_open_channel_finish(UNITY_PROTOCOL_SCOPE_PROXY(source_object), res, &serialisable_model, &error)); | ||
2050 | 395 | |||
2051 | 396 | glib::Object<DeeModel> results_dee_model(DEE_MODEL(serialisable_model)); | ||
2052 | 397 | results_->SetModel(results_dee_model); | ||
2053 | 398 | |||
2054 | 399 | glib::Object<DeeModel> filters_dee_model(DEE_MODEL(unity_protocol_scope_proxy_get_filters_model(scope_proxy_)), glib::AddRef()); | ||
2055 | 400 | filters_->SetModel(filters_dee_model); | ||
2056 | 401 | filters_change_connection.disconnect(); | ||
2057 | 402 | filters_change_connection = filters_->filter_changed.connect([this](Filter::Ptr const& filter) | ||
2058 | 403 | { | ||
2059 | 404 | glib::HintsMap hints; | ||
2060 | 405 | hints["changed-filter-row"] = filter->VariantValue(); | ||
2061 | 406 | Search(last_search_, hints, nullptr, cancel_scope_); | ||
2062 | 407 | }); | ||
2063 | 408 | |||
2064 | 409 | glib::Object<DeeModel> categories_dee_model(DEE_MODEL(unity_protocol_scope_proxy_get_categories_model(scope_proxy_)), glib::AddRef()); | ||
2065 | 410 | categories_->SetModel(categories_dee_model); | ||
2066 | 411 | |||
2067 | 412 | if (tmp_channel.Str().empty() || error) | ||
2068 | 413 | { | ||
2069 | 414 | channel = ""; | ||
2070 | 415 | connected = false; | ||
2071 | 416 | |||
2072 | 417 | LOG_ERROR(logger) << "Failed to open channel for " << scope_data_->id(); | ||
2073 | 418 | return; | ||
2074 | 419 | } | ||
2075 | 420 | |||
2076 | 421 | channel = tmp_channel.Str(); | ||
2077 | 422 | LOG_DEBUG(logger) << "Opened channel:" << channel() << " for " << scope_data_->id(); | ||
2078 | 423 | connected = true; | ||
2079 | 424 | |||
2080 | 425 | if (!searching_) | ||
2081 | 426 | { | ||
2082 | 427 | // If a search hasn't initiated this channel opening, perform the search to get the results. | ||
2083 | 428 | Search(last_search_, glib::HintsMap(), nullptr, cancel_scope_); | ||
2084 | 429 | } | ||
2085 | 430 | } | ||
2086 | 431 | |||
2087 | 432 | void ScopeProxy::Impl::CloseChannel() | ||
2088 | 433 | { | ||
2089 | 434 | if (channel != "") | ||
2090 | 435 | { | ||
2091 | 436 | unity_protocol_scope_proxy_close_channel(scope_proxy_, | ||
2092 | 437 | channel.Get().c_str(), | ||
2093 | 438 | nullptr, | ||
2094 | 439 | OnCloseChannel, | ||
2095 | 440 | nullptr); | ||
2096 | 441 | channel = ""; | ||
2097 | 442 | } | ||
2098 | 443 | } | ||
2099 | 444 | |||
2100 | 445 | void ScopeProxy::Impl::OnCloseChannel(GObject *source_object, GAsyncResult *res, gpointer user_data) | ||
2101 | 446 | { | ||
2102 | 447 | glib::Error err; | ||
2103 | 448 | unity_protocol_scope_proxy_close_channel_finish(UNITY_PROTOCOL_SCOPE_PROXY(source_object), res, &err); | ||
2104 | 449 | } | ||
2105 | 450 | |||
2106 | 451 | void ScopeProxy::Impl::WaitForProxyConnection(GCancellable* cancellable, | ||
2107 | 452 | int timeout_msec, | ||
2108 | 453 | std::function<void(glib::Error const&)> const& callback) | ||
2109 | 454 | { | ||
2110 | 455 | if (!connected) | ||
2111 | 456 | { | ||
2112 | 457 | auto con = std::make_shared<sigc::connection>(); | ||
2113 | 458 | auto canc = glib::Object<GCancellable>(cancellable, glib::AddRef()); | ||
2114 | 459 | |||
2115 | 460 | // add a timeout | ||
2116 | 461 | auto timeout = std::make_shared<glib::Timeout>(timeout_msec < 0 ? 30000 : timeout_msec, [con, canc, callback] () | ||
2117 | 462 | { | ||
2118 | 463 | if (!g_cancellable_is_cancelled(canc)) | ||
2119 | 464 | { | ||
2120 | 465 | glib::Error err; | ||
2121 | 466 | GError** real_err = &err; | ||
2122 | 467 | *real_err = g_error_new_literal(G_DBUS_ERROR, G_DBUS_ERROR_TIMED_OUT, | ||
2123 | 468 | "Timed out waiting for scope proxy connection"); | ||
2124 | 469 | callback(err); | ||
2125 | 470 | } | ||
2126 | 471 | con->disconnect(); | ||
2127 | 472 | return false; | ||
2128 | 473 | }); | ||
2129 | 474 | // wait for the signal | ||
2130 | 475 | *con = connected.changed.connect([con, canc, timeout, callback] (bool connected) | ||
2131 | 476 | { | ||
2132 | 477 | if (!connected) | ||
2133 | 478 | return; | ||
2134 | 479 | |||
2135 | 480 | if (!g_cancellable_is_cancelled(canc)) callback(glib::Error()); | ||
2136 | 481 | timeout->Remove(); | ||
2137 | 482 | con->disconnect(); | ||
2138 | 483 | }); | ||
2139 | 484 | } | ||
2140 | 485 | else | ||
2141 | 486 | { | ||
2142 | 487 | callback(glib::Error()); | ||
2143 | 488 | } | ||
2144 | 489 | } | ||
2145 | 490 | |||
2146 | 491 | void ScopeProxy::Impl::Search(std::string const& search_string, glib::HintsMap const& hints, SearchCallback const& callback, GCancellable* cancellable) | ||
2147 | 492 | { | ||
2148 | 493 | // Activate a guard against performing a "on channel open search" if we're not connected. | ||
2149 | 494 | utils::AutoResettingVariable<bool> searching(&searching_, true); | ||
2150 | 495 | |||
2151 | 496 | GCancellable* target_canc = cancellable != NULL ? cancellable : cancel_scope_; | ||
2152 | 497 | |||
2153 | 498 | if (!scope_proxy_) | ||
2154 | 499 | { | ||
2155 | 500 | if (!proxy_created_) | ||
2156 | 501 | CreateProxy(); | ||
2157 | 502 | |||
2158 | 503 | glib::Object<GCancellable> canc(target_canc, glib::AddRef()); | ||
2159 | 504 | WaitForProxyConnection(canc, PROXY_CONNECT_TIMEOUT, [this, search_string, hints, callback, canc] (glib::Error const& err) | ||
2160 | 505 | { | ||
2161 | 506 | if (err) | ||
2162 | 507 | { | ||
2163 | 508 | callback(glib::HintsMap(), err); | ||
2164 | 509 | LOG_WARNING(logger) << "Could not search '" << search_string | ||
2165 | 510 | << "' on " << scope_data_->id() << " => " << err; | ||
2166 | 511 | } | ||
2167 | 512 | else | ||
2168 | 513 | { | ||
2169 | 514 | Search(search_string, hints, callback, canc); | ||
2170 | 515 | } | ||
2171 | 516 | }); | ||
2172 | 517 | return; | ||
2173 | 518 | } | ||
2174 | 519 | |||
2175 | 520 | SearchData* data = new SearchData(); | ||
2176 | 521 | data->callback = callback; | ||
2177 | 522 | |||
2178 | 523 | GHashTable* hints_table = glib::hashtable_from_hintsmap(hints); | ||
2179 | 524 | |||
2180 | 525 | last_search_ = search_string.c_str(); | ||
2181 | 526 | unity_protocol_scope_proxy_search(scope_proxy_, | ||
2182 | 527 | channel().c_str(), | ||
2183 | 528 | search_string.c_str(), | ||
2184 | 529 | hints_table, | ||
2185 | 530 | target_canc, | ||
2186 | 531 | Impl::OnScopeSearchCallback, | ||
2187 | 532 | data); | ||
2188 | 533 | |||
2189 | 534 | g_hash_table_unref(hints_table); | ||
2190 | 535 | } | ||
2191 | 536 | |||
2192 | 537 | void ScopeProxy::Impl::Activate(std::string const& uri, uint activate_type, glib::HintsMap const& hints, ScopeProxy::ActivateCallback const& callback, GCancellable* cancellable) | ||
2193 | 538 | { | ||
2194 | 539 | GCancellable* target_canc = cancellable != NULL ? cancellable : cancel_scope_; | ||
2195 | 540 | |||
2196 | 541 | if (!scope_proxy_) | ||
2197 | 542 | { | ||
2198 | 543 | if (!proxy_created_) | ||
2199 | 544 | CreateProxy(); | ||
2200 | 545 | |||
2201 | 546 | glib::Object<GCancellable> canc(target_canc, glib::AddRef()); | ||
2202 | 547 | WaitForProxyConnection(canc, PROXY_CONNECT_TIMEOUT, [this, uri, activate_type, hints, callback, canc] (glib::Error const& err) | ||
2203 | 548 | { | ||
2204 | 549 | if (err) | ||
2205 | 550 | { | ||
2206 | 551 | callback(uri, ScopeHandledType::NOT_HANDLED, glib::HintsMap(), err); | ||
2207 | 552 | LOG_WARNING(logger) << "Could not activate '" << uri | ||
2208 | 553 | << "' on " << scope_data_->id() << " => " << err; | ||
2209 | 554 | } | ||
2210 | 555 | else | ||
2211 | 556 | { | ||
2212 | 557 | Activate(uri, activate_type, hints, callback, canc); | ||
2213 | 558 | } | ||
2214 | 559 | }); | ||
2215 | 560 | return; | ||
2216 | 561 | } | ||
2217 | 562 | |||
2218 | 563 | ActivateData* data = new ActivateData(); | ||
2219 | 564 | data->callback = callback; | ||
2220 | 565 | |||
2221 | 566 | GHashTable* hints_table = glib::hashtable_from_hintsmap(hints); | ||
2222 | 567 | |||
2223 | 568 | unity_protocol_scope_proxy_activate(scope_proxy_, | ||
2224 | 569 | channel().c_str(), | ||
2225 | 570 | uri.c_str(), | ||
2226 | 571 | (UnityProtocolActionType)activate_type, | ||
2227 | 572 | hints_table, | ||
2228 | 573 | target_canc, | ||
2229 | 574 | Impl::OnScopeActivateCallback, | ||
2230 | 575 | data); | ||
2231 | 576 | g_hash_table_unref(hints_table); | ||
2232 | 577 | } | ||
2233 | 578 | |||
2234 | 579 | void ScopeProxy::Impl::UpdatePreviewProperty(std::string const& uri, glib::HintsMap const& hints, ScopeProxy::UpdatePreviewPropertyCallback const& callback, GCancellable* cancellable) | ||
2235 | 580 | { | ||
2236 | 581 | GCancellable* target_canc = cancellable != NULL ? cancellable : cancel_scope_; | ||
2237 | 582 | |||
2238 | 583 | if (!scope_proxy_) | ||
2239 | 584 | { | ||
2240 | 585 | if (!proxy_created_) | ||
2241 | 586 | CreateProxy(); | ||
2242 | 587 | |||
2243 | 588 | glib::Object<GCancellable> canc(target_canc, glib::AddRef()); | ||
2244 | 589 | WaitForProxyConnection(canc, PROXY_CONNECT_TIMEOUT, [this, uri, hints, callback, canc] (glib::Error const& err) | ||
2245 | 590 | { | ||
2246 | 591 | if (err) | ||
2247 | 592 | { | ||
2248 | 593 | callback(glib::HintsMap(), err); | ||
2249 | 594 | LOG_WARNING(logger) << "Could not update preview property '" << uri | ||
2250 | 595 | << "' on " << scope_data_->id() << " => " << err; | ||
2251 | 596 | } | ||
2252 | 597 | else | ||
2253 | 598 | { | ||
2254 | 599 | UpdatePreviewProperty(uri, hints, callback, canc); | ||
2255 | 600 | } | ||
2256 | 601 | }); | ||
2257 | 602 | return; | ||
2258 | 603 | } | ||
2259 | 604 | |||
2260 | 605 | UpdatePreviewPropertyData* data = new UpdatePreviewPropertyData(); | ||
2261 | 606 | data->callback = callback; | ||
2262 | 607 | |||
2263 | 608 | GHashTable* hints_table = glib::hashtable_from_hintsmap(hints); | ||
2264 | 609 | |||
2265 | 610 | unity_protocol_scope_proxy_update_preview_property(scope_proxy_, | ||
2266 | 611 | channel().c_str(), | ||
2267 | 612 | uri.c_str(), | ||
2268 | 613 | hints_table, | ||
2269 | 614 | target_canc, | ||
2270 | 615 | Impl::OnScopeUpdatePreviewPropertyCallback, | ||
2271 | 616 | data); | ||
2272 | 617 | |||
2273 | 618 | g_hash_table_unref(hints_table); | ||
2274 | 619 | } | ||
2275 | 620 | |||
2276 | 621 | void ScopeProxy::Impl::OnScopeConnectedChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param) | ||
2277 | 622 | { | ||
2278 | 623 | bool tmp_scope_proxy_connected = unity_protocol_scope_proxy_get_connected(scope_proxy_); | ||
2279 | 624 | if (tmp_scope_proxy_connected != scope_proxy_connected_) | ||
2280 | 625 | { | ||
2281 | 626 | scope_proxy_connected_ = tmp_scope_proxy_connected; | ||
2282 | 627 | |||
2283 | 628 | LOG_WARN(logger) << "Connection state changed for " << scope_data_->id() << " => " << (scope_proxy_connected_ ? "connected" : "disconnected"); | ||
2284 | 629 | |||
2285 | 630 | CloseChannel(); | ||
2286 | 631 | if (tmp_scope_proxy_connected) | ||
2287 | 632 | { | ||
2288 | 633 | OpenChannel(); | ||
2289 | 634 | } | ||
2290 | 635 | } | ||
2291 | 636 | } | ||
2292 | 637 | |||
2293 | 638 | void ScopeProxy::Impl::OnScopeIsMasterChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param) | ||
2294 | 639 | { | ||
2295 | 640 | scope_data_->is_master = unity_protocol_scope_proxy_get_is_master(proxy); | ||
2296 | 641 | } | ||
2297 | 642 | |||
2298 | 643 | void ScopeProxy::Impl::OnScopeSearchInGlobalChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param) | ||
2299 | 644 | { | ||
2300 | 645 | search_in_global = unity_protocol_scope_proxy_get_search_in_global(proxy); | ||
2301 | 646 | } | ||
2302 | 647 | |||
2303 | 648 | void ScopeProxy::Impl::OnScopeSearchHintChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param) | ||
2304 | 649 | { | ||
2305 | 650 | scope_data_->search_hint = unity_protocol_scope_proxy_get_search_hint(proxy); | ||
2306 | 651 | } | ||
2307 | 652 | |||
2308 | 653 | void ScopeProxy::Impl::OnScopeViewTypeChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param) | ||
2309 | 654 | { | ||
2310 | 655 | view_type = static_cast<ScopeViewType>(unity_protocol_scope_proxy_get_view_type(proxy)); | ||
2311 | 656 | } | ||
2312 | 657 | |||
2313 | 658 | void ScopeProxy::Impl::OnScopeFiltersChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param) | ||
2314 | 659 | { | ||
2315 | 660 | LOG_DEBUG(logger) << scope_data_->id() << " - Filter changed by server"; | ||
2316 | 661 | bool blocked = filters_change_connection.block(true); | ||
2317 | 662 | |||
2318 | 663 | glib::Object<DeeModel> filters_dee_model(DEE_MODEL(unity_protocol_scope_proxy_get_filters_model(scope_proxy_)), glib::AddRef()); | ||
2319 | 664 | categories_->SetModel(filters_dee_model); | ||
2320 | 665 | |||
2321 | 666 | filters_change_connection.block(blocked); | ||
2322 | 667 | |||
2323 | 668 | owner_->filters.EmitChanged(filters()); | ||
2324 | 669 | } | ||
2325 | 670 | |||
2326 | 671 | void ScopeProxy::Impl::OnScopeCategoriesChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param) | ||
2327 | 672 | { | ||
2328 | 673 | glib::Object<DeeModel> categories_dee_model(DEE_MODEL(unity_protocol_scope_proxy_get_categories_model(scope_proxy_)), glib::AddRef()); | ||
2329 | 674 | categories_->SetModel(categories_dee_model); | ||
2330 | 675 | |||
2331 | 676 | owner_->categories.EmitChanged(categories()); | ||
2332 | 677 | } | ||
2333 | 678 | |||
2334 | 679 | void ScopeProxy::Impl::OnScopeMetadataChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param) | ||
2335 | 680 | { | ||
2336 | 681 | } | ||
2337 | 682 | |||
2338 | 683 | void ScopeProxy::Impl::OnScopeOptionalMetadataChanged(UnityProtocolScopeProxy* proxy, GParamSpec* param) | ||
2339 | 684 | { | ||
2340 | 685 | } | ||
2341 | 686 | |||
2342 | 687 | void ScopeProxy::Impl::OnScopeCategoryOrderChanged(UnityProtocolScopeProxy* sender, const gchar* channel_id, guint32* new_order, int new_order_length1) | ||
2343 | 688 | { | ||
2344 | 689 | if (channel() != glib::gchar_to_string(channel_id)) | ||
2345 | 690 | return; | ||
2346 | 691 | |||
2347 | 692 | std::vector<int> order; | ||
2348 | 693 | for (int i = 0; i < new_order_length1; i++) | ||
2349 | 694 | { | ||
2350 | 695 | order.push_back(new_order[i]); | ||
2351 | 696 | } | ||
2352 | 697 | |||
2353 | 698 | category_order = order; | ||
2354 | 699 | } | ||
2355 | 700 | |||
2356 | 701 | static void category_filter_map_func (DeeModel* orig_model, | ||
2357 | 702 | DeeFilterModel* filter_model, | ||
2358 | 703 | gpointer user_data) | ||
2359 | 704 | { | ||
2360 | 705 | DeeModelIter* iter; | ||
2361 | 706 | DeeModelIter* end; | ||
2362 | 707 | unsigned index = GPOINTER_TO_UINT(user_data); | ||
2363 | 708 | |||
2364 | 709 | iter = dee_model_get_first_iter(orig_model); | ||
2365 | 710 | end = dee_model_get_last_iter(orig_model); | ||
2366 | 711 | while (iter != end) | ||
2367 | 712 | { | ||
2368 | 713 | unsigned category_index = dee_model_get_uint32(orig_model, iter, | ||
2369 | 714 | CATEGORY_COLUMN); | ||
2370 | 715 | if (index == category_index) | ||
2371 | 716 | { | ||
2372 | 717 | dee_filter_model_append_iter(filter_model, iter); | ||
2373 | 718 | } | ||
2374 | 719 | iter = dee_model_next(orig_model, iter); | ||
2375 | 720 | } | ||
2376 | 721 | } | ||
2377 | 722 | |||
2378 | 723 | static gboolean category_filter_notify_func (DeeModel* orig_model, | ||
2379 | 724 | DeeModelIter* orig_iter, | ||
2380 | 725 | DeeFilterModel* filter_model, | ||
2381 | 726 | gpointer user_data) | ||
2382 | 727 | { | ||
2383 | 728 | unsigned index = GPOINTER_TO_UINT(user_data); | ||
2384 | 729 | unsigned category_index = dee_model_get_uint32(orig_model, orig_iter, | ||
2385 | 730 | CATEGORY_COLUMN); | ||
2386 | 731 | |||
2387 | 732 | if (index != category_index) | ||
2388 | 733 | return FALSE; | ||
2389 | 734 | |||
2390 | 735 | dee_filter_model_insert_iter_with_original_order(filter_model, orig_iter); | ||
2391 | 736 | return TRUE; | ||
2392 | 737 | } | ||
2393 | 738 | |||
2394 | 739 | DeeFilter* ScopeProxy::Impl::GetFilterForCategory(unsigned category, DeeFilter* filter) const | ||
2395 | 740 | { | ||
2396 | 741 | filter->map_func = category_filter_map_func; | ||
2397 | 742 | filter->map_notify = category_filter_notify_func; | ||
2398 | 743 | filter->destroy = nullptr; | ||
2399 | 744 | filter->userdata = GUINT_TO_POINTER(category); | ||
2400 | 745 | |||
2401 | 746 | return filter; | ||
2402 | 747 | } | ||
2403 | 748 | |||
2404 | 749 | ScopeProxy::ScopeProxy(ScopeData::Ptr const& scope_data) | ||
2405 | 750 | : pimpl(new Impl(this, scope_data)) | ||
2406 | 751 | { | ||
2407 | 752 | } | ||
2408 | 753 | |||
2409 | 754 | |||
2410 | 755 | ScopeProxy::ScopeProxy(std::string const& dbus_name, std::string const& dbus_path) | ||
2411 | 756 | : pimpl(new Impl(this, Impl::CreateData(dbus_name, dbus_path))) | ||
2412 | 757 | { | ||
2413 | 758 | } | ||
2414 | 759 | |||
2415 | 760 | ScopeProxy::~ScopeProxy() | ||
2416 | 761 | { | ||
2417 | 762 | } | ||
2418 | 763 | |||
2419 | 764 | void ScopeProxy::CreateProxy() | ||
2420 | 765 | { | ||
2421 | 766 | pimpl->CreateProxy(); | ||
2422 | 767 | } | ||
2423 | 768 | |||
2424 | 769 | void ScopeProxy::Search(std::string const& search_string, SearchCallback const& callback, GCancellable* cancellable) | ||
2425 | 770 | { | ||
2426 | 771 | pimpl->Search(search_string, glib::HintsMap(), callback, cancellable); | ||
2427 | 772 | } | ||
2428 | 773 | |||
2429 | 774 | void ScopeProxy::Activate(std::string const& uri, uint activate_type, glib::HintsMap const& hints, ScopeProxy::ActivateCallback const& callback, GCancellable* cancellable) | ||
2430 | 775 | { | ||
2431 | 776 | pimpl->Activate(uri, activate_type, hints, callback, cancellable); | ||
2432 | 777 | } | ||
2433 | 778 | |||
2434 | 779 | void ScopeProxy::UpdatePreviewProperty(std::string const& uri, glib::HintsMap const& hints, ScopeProxy::UpdatePreviewPropertyCallback const& callback, GCancellable* cancellable) | ||
2435 | 780 | { | ||
2436 | 781 | pimpl->UpdatePreviewProperty(uri, hints, callback, cancellable); | ||
2437 | 782 | } | ||
2438 | 783 | |||
2439 | 784 | Results::Ptr ScopeProxy::GetResultsForCategory(unsigned category) const | ||
2440 | 785 | { | ||
2441 | 786 | Results::Ptr all_results = results; | ||
2442 | 787 | |||
2443 | 788 | if (!all_results || !all_results->model()) | ||
2444 | 789 | return Results::Ptr(); | ||
2445 | 790 | |||
2446 | 791 | DeeFilter filter; | ||
2447 | 792 | pimpl->GetFilterForCategory(category, &filter); | ||
2448 | 793 | glib::Object<DeeModel> filter_model(dee_filter_model_new(all_results->model(), &filter)); | ||
2449 | 794 | |||
2450 | 795 | auto func = [all_results](glib::Object<DeeModel> const& model) { return all_results->GetTag(); }; | ||
2451 | 796 | |||
2452 | 797 | Results::Ptr results_category_model(new Results(ModelType::UNATTACHED)); | ||
2453 | 798 | results_category_model->SetModel(filter_model, func); | ||
2454 | 799 | return results_category_model; | ||
2455 | 800 | } | ||
2456 | 801 | |||
2457 | 802 | |||
2458 | 803 | } // namespace dash | ||
2459 | 804 | } // namespace unity | ||
2460 | 0 | 805 | ||
2461 | === added file 'UnityCore/ScopeProxy.h' | |||
2462 | --- UnityCore/ScopeProxy.h 1970-01-01 00:00:00 +0000 | |||
2463 | +++ UnityCore/ScopeProxy.h 2013-02-21 10:37:29 +0000 | |||
2464 | @@ -0,0 +1,57 @@ | |||
2465 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
2466 | 2 | /* | ||
2467 | 3 | * Copyright (C) 2013 Canonical Ltd | ||
2468 | 4 | * | ||
2469 | 5 | * This program is free software: you can redistribute it and/or modify | ||
2470 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
2471 | 7 | * published by the Free Software Foundation. | ||
2472 | 8 | * | ||
2473 | 9 | * This program is distributed in the hope that it will be useful, | ||
2474 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2475 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2476 | 12 | * GNU General Public License for more details. | ||
2477 | 13 | * | ||
2478 | 14 | * You should have received a copy of the GNU General Public License | ||
2479 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2480 | 16 | * | ||
2481 | 17 | * Authored by: Nick Dedekind <nick.dedekind@canonical.com> | ||
2482 | 18 | */ | ||
2483 | 19 | |||
2484 | 20 | #ifndef UNITY_SCOPE_PROXY_H | ||
2485 | 21 | #define UNITY_SCOPE_PROXY_H | ||
2486 | 22 | |||
2487 | 23 | #include "ScopeProxyInterface.h" | ||
2488 | 24 | |||
2489 | 25 | namespace unity | ||
2490 | 26 | { | ||
2491 | 27 | namespace dash | ||
2492 | 28 | { | ||
2493 | 29 | |||
2494 | 30 | class ScopeProxy : public ScopeProxyInterface | ||
2495 | 31 | { | ||
2496 | 32 | public: | ||
2497 | 33 | ScopeProxy(ScopeData::Ptr const& scope_data); | ||
2498 | 34 | ~ScopeProxy(); | ||
2499 | 35 | |||
2500 | 36 | virtual void CreateProxy(); | ||
2501 | 37 | |||
2502 | 38 | virtual void Search(std::string const& search_hint, SearchCallback const& callback, GCancellable* cancellable); | ||
2503 | 39 | |||
2504 | 40 | virtual void Activate(std::string const& uri, uint activate_type, glib::HintsMap const& hints, ActivateCallback const& callback, GCancellable* cancellable); | ||
2505 | 41 | |||
2506 | 42 | virtual void UpdatePreviewProperty(std::string const& uri, glib::HintsMap const& hints, UpdatePreviewPropertyCallback const& callback, GCancellable* cancellable); | ||
2507 | 43 | |||
2508 | 44 | Results::Ptr GetResultsForCategory(unsigned category) const; | ||
2509 | 45 | |||
2510 | 46 | protected: | ||
2511 | 47 | ScopeProxy(std::string const& dbus_name, std::string const& dbus_path); | ||
2512 | 48 | |||
2513 | 49 | private: | ||
2514 | 50 | class Impl; | ||
2515 | 51 | std::unique_ptr<Impl> pimpl; | ||
2516 | 52 | }; | ||
2517 | 53 | |||
2518 | 54 | } // namespace dash | ||
2519 | 55 | } // namespace unity | ||
2520 | 56 | |||
2521 | 57 | #endif // UNITY_SCOPE_PROXY_H | ||
2522 | 0 | 58 | ||
2523 | === added file 'UnityCore/ScopeProxyInterface.h' | |||
2524 | --- UnityCore/ScopeProxyInterface.h 1970-01-01 00:00:00 +0000 | |||
2525 | +++ UnityCore/ScopeProxyInterface.h 2013-02-21 10:37:29 +0000 | |||
2526 | @@ -0,0 +1,96 @@ | |||
2527 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
2528 | 2 | /* | ||
2529 | 3 | * Copyright (C) 2013 Canonical Ltd | ||
2530 | 4 | * | ||
2531 | 5 | * This program is free software: you can redistribute it and/or modify | ||
2532 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
2533 | 7 | * published by the Free Software Foundation. | ||
2534 | 8 | * | ||
2535 | 9 | * This program is distributed in the hope that it will be useful, | ||
2536 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2537 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2538 | 12 | * GNU General Public License for more details. | ||
2539 | 13 | * | ||
2540 | 14 | * You should have received a copy of the GNU General Public License | ||
2541 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2542 | 16 | * | ||
2543 | 17 | * Authored by: Nick Dedekind <nick.dedekind@canonical.com> | ||
2544 | 18 | */ | ||
2545 | 19 | |||
2546 | 20 | #ifndef UNITY_SCOPE_PROXY_INTERFACE_H | ||
2547 | 21 | #define UNITY_SCOPE_PROXY_INTERFACE_H | ||
2548 | 22 | |||
2549 | 23 | #include "GLibWrapper.h" | ||
2550 | 24 | #include <NuxCore/Property.h> | ||
2551 | 25 | #include <dee.h> | ||
2552 | 26 | |||
2553 | 27 | #include "Results.h" | ||
2554 | 28 | #include "Filters.h" | ||
2555 | 29 | #include "Categories.h" | ||
2556 | 30 | #include "GLibWrapper.h" | ||
2557 | 31 | #include "ScopeData.h" | ||
2558 | 32 | |||
2559 | 33 | namespace unity | ||
2560 | 34 | { | ||
2561 | 35 | namespace dash | ||
2562 | 36 | { | ||
2563 | 37 | |||
2564 | 38 | enum ScopeHandledType | ||
2565 | 39 | { | ||
2566 | 40 | NOT_HANDLED=0, | ||
2567 | 41 | SHOW_DASH, | ||
2568 | 42 | HIDE_DASH, | ||
2569 | 43 | GOTO_DASH_URI, | ||
2570 | 44 | SHOW_PREVIEW | ||
2571 | 45 | }; | ||
2572 | 46 | |||
2573 | 47 | class ScopeProxyInterface : public sigc::trackable, boost::noncopyable | ||
2574 | 48 | { | ||
2575 | 49 | public: | ||
2576 | 50 | typedef std::shared_ptr<ScopeProxyInterface> Ptr; | ||
2577 | 51 | |||
2578 | 52 | virtual ~ScopeProxyInterface() {} | ||
2579 | 53 | |||
2580 | 54 | nux::ROProperty<std::string> dbus_name; | ||
2581 | 55 | nux::ROProperty<std::string> dbus_path; | ||
2582 | 56 | nux::ROProperty<bool> connected; | ||
2583 | 57 | nux::ROProperty<std::string> channel; | ||
2584 | 58 | |||
2585 | 59 | nux::ROProperty<bool> visible; | ||
2586 | 60 | nux::ROProperty<bool> is_master; | ||
2587 | 61 | nux::ROProperty<bool> search_in_global; | ||
2588 | 62 | nux::ROProperty<std::string> search_hint; | ||
2589 | 63 | nux::RWProperty<ScopeViewType> view_type; | ||
2590 | 64 | |||
2591 | 65 | nux::ROProperty<Results::Ptr> results; | ||
2592 | 66 | nux::ROProperty<Filters::Ptr> filters; | ||
2593 | 67 | nux::ROProperty<Categories::Ptr> categories; | ||
2594 | 68 | nux::ROProperty<std::vector<int>> category_order; | ||
2595 | 69 | |||
2596 | 70 | nux::ROProperty<std::string> name; | ||
2597 | 71 | nux::ROProperty<std::string> description; | ||
2598 | 72 | nux::ROProperty<std::string> icon_hint; | ||
2599 | 73 | nux::ROProperty<std::string> category_icon_hint; | ||
2600 | 74 | nux::ROProperty<std::vector<std::string>> keywords; | ||
2601 | 75 | nux::ROProperty<std::string> type; | ||
2602 | 76 | nux::ROProperty<std::string> query_pattern; | ||
2603 | 77 | nux::ROProperty<std::string> shortcut; | ||
2604 | 78 | |||
2605 | 79 | virtual void CreateProxy() {} | ||
2606 | 80 | |||
2607 | 81 | typedef std::function<void(glib::HintsMap const&, glib::Error const&)> SearchCallback; | ||
2608 | 82 | virtual void Search(std::string const& search_hint, SearchCallback const& callback, GCancellable* cancellable) = 0; | ||
2609 | 83 | |||
2610 | 84 | typedef std::function<void(std::string const&, ScopeHandledType, glib::HintsMap const&, glib::Error const&)> ActivateCallback; | ||
2611 | 85 | virtual void Activate(std::string const& uri, uint activate_type, glib::HintsMap const& hints, ActivateCallback const& callback, GCancellable* cancellable) = 0; | ||
2612 | 86 | |||
2613 | 87 | typedef std::function<void(glib::HintsMap const&, glib::Error const&)> UpdatePreviewPropertyCallback; | ||
2614 | 88 | virtual void UpdatePreviewProperty(std::string const& uri, glib::HintsMap const& hints, UpdatePreviewPropertyCallback const& callback, GCancellable* cancellable) = 0; | ||
2615 | 89 | |||
2616 | 90 | virtual Results::Ptr GetResultsForCategory(unsigned category) const = 0; | ||
2617 | 91 | }; | ||
2618 | 92 | |||
2619 | 93 | } // namespace dash | ||
2620 | 94 | } // namespace unity | ||
2621 | 95 | |||
2622 | 96 | #endif // UNITY_SCOPE_PROXY_INTERFACE_H | ||
2623 | 0 | \ No newline at end of file | 97 | \ No newline at end of file |
2624 | 1 | 98 | ||
2625 | === added file 'UnityCore/Scopes.cpp' | |||
2626 | --- UnityCore/Scopes.cpp 1970-01-01 00:00:00 +0000 | |||
2627 | +++ UnityCore/Scopes.cpp 2013-02-21 10:37:29 +0000 | |||
2628 | @@ -0,0 +1,271 @@ | |||
2629 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
2630 | 2 | /* | ||
2631 | 3 | * Copyright (C) 2011 Canonical Ltd | ||
2632 | 4 | * | ||
2633 | 5 | * This program is free software: you can redistribute it and/or modify | ||
2634 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
2635 | 7 | * published by the Free Software Foundation. | ||
2636 | 8 | * | ||
2637 | 9 | * This program is distributed in the hope that it will be useful, | ||
2638 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2639 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2640 | 12 | * GNU General Public License for more details. | ||
2641 | 13 | * | ||
2642 | 14 | * You should have received a copy of the GNU General Public License | ||
2643 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2644 | 16 | * | ||
2645 | 17 | * Authored by: Nick Dedekind <nick.dedeknd@canoncial.com> | ||
2646 | 18 | */ | ||
2647 | 19 | |||
2648 | 20 | #include "Scopes.h" | ||
2649 | 21 | #include <stdexcept> | ||
2650 | 22 | |||
2651 | 23 | namespace unity | ||
2652 | 24 | { | ||
2653 | 25 | namespace dash | ||
2654 | 26 | { | ||
2655 | 27 | DECLARE_LOGGER(logger, "unity.dash.scopes"); | ||
2656 | 28 | |||
2657 | 29 | class Scopes::Impl | ||
2658 | 30 | { | ||
2659 | 31 | public: | ||
2660 | 32 | Impl(Scopes* owner, ScopesReader::Ptr scopes_reader); | ||
2661 | 33 | ~Impl(); | ||
2662 | 34 | |||
2663 | 35 | void LoadScopes(); | ||
2664 | 36 | void InsertScope(ScopeData::Ptr const& data, unsigned index); | ||
2665 | 37 | void RemoveScope(std::string const& scope); | ||
2666 | 38 | |||
2667 | 39 | ScopeList const& GetScopes() const; | ||
2668 | 40 | Scope::Ptr GetScope(std::string const& scope_id, int* index = nullptr) const; | ||
2669 | 41 | Scope::Ptr GetScopeAtIndex(std::size_t index) const; | ||
2670 | 42 | Scope::Ptr GetScopeForShortcut(std::string const& scope_shortcut) const; | ||
2671 | 43 | |||
2672 | 44 | Scopes* owner_; | ||
2673 | 45 | ScopesReader::Ptr scopes_reader_; | ||
2674 | 46 | ScopeList scopes_; | ||
2675 | 47 | sigc::connection scope_changed_signal; | ||
2676 | 48 | |||
2677 | 49 | std::size_t get_count() const { return scopes_.size(); } | ||
2678 | 50 | |||
2679 | 51 | void UpdateScopes(ScopeDataList const& scopes_list); | ||
2680 | 52 | }; | ||
2681 | 53 | |||
2682 | 54 | Scopes::Impl::Impl(Scopes* owner, ScopesReader::Ptr scopes_reader) | ||
2683 | 55 | : owner_(owner) | ||
2684 | 56 | , scopes_reader_(scopes_reader) | ||
2685 | 57 | { | ||
2686 | 58 | } | ||
2687 | 59 | |||
2688 | 60 | Scopes::Impl::~Impl() | ||
2689 | 61 | { | ||
2690 | 62 | scope_changed_signal.disconnect(); | ||
2691 | 63 | } | ||
2692 | 64 | |||
2693 | 65 | void Scopes::Impl::UpdateScopes(ScopeDataList const& scopes_list) | ||
2694 | 66 | { | ||
2695 | 67 | // insert new. | ||
2696 | 68 | int index = 0; | ||
2697 | 69 | for (ScopeData::Ptr const& scope_data: scopes_list) | ||
2698 | 70 | { | ||
2699 | 71 | InsertScope(scope_data, index++); | ||
2700 | 72 | } | ||
2701 | 73 | |||
2702 | 74 | // remove old. | ||
2703 | 75 | std::vector<std::string> remove_scopes; | ||
2704 | 76 | for (Scope::Ptr const& scope: scopes_) | ||
2705 | 77 | { | ||
2706 | 78 | auto scope_data_position = std::find_if(scopes_list.begin(), | ||
2707 | 79 | scopes_list.end(), | ||
2708 | 80 | [scope](ScopeData::Ptr const& data) { return data->id() == scope->id(); }); | ||
2709 | 81 | if (scope_data_position == scopes_list.end()) | ||
2710 | 82 | { | ||
2711 | 83 | remove_scopes.push_back(scope->id()); | ||
2712 | 84 | } | ||
2713 | 85 | } | ||
2714 | 86 | for (std::string const& scope: remove_scopes) | ||
2715 | 87 | { | ||
2716 | 88 | RemoveScope(scope); | ||
2717 | 89 | } | ||
2718 | 90 | } | ||
2719 | 91 | |||
2720 | 92 | void Scopes::Impl::LoadScopes() | ||
2721 | 93 | { | ||
2722 | 94 | if (!scopes_reader_) | ||
2723 | 95 | return; | ||
2724 | 96 | |||
2725 | 97 | scope_changed_signal.disconnect(); | ||
2726 | 98 | scope_changed_signal = scopes_reader_->scopes_changed.connect(sigc::mem_fun(this, &Impl::UpdateScopes)); | ||
2727 | 99 | UpdateScopes(scopes_reader_->GetScopesData()); | ||
2728 | 100 | } | ||
2729 | 101 | |||
2730 | 102 | void Scopes::Impl::InsertScope(ScopeData::Ptr const& scope_data, unsigned index) | ||
2731 | 103 | { | ||
2732 | 104 | if (!scope_data) | ||
2733 | 105 | return; | ||
2734 | 106 | |||
2735 | 107 | index = std::min(index, static_cast<unsigned>(scopes_.size())); | ||
2736 | 108 | |||
2737 | 109 | auto start = scopes_.begin(); | ||
2738 | 110 | auto scope_position = std::find_if(scopes_.begin(), | ||
2739 | 111 | scopes_.end(), | ||
2740 | 112 | [scope_data](Scope::Ptr const& value) { return value->id() == scope_data->id(); }); | ||
2741 | 113 | if (scope_position == scopes_.end()) | ||
2742 | 114 | { | ||
2743 | 115 | Scope::Ptr scope(owner_->CreateScope(scope_data)); | ||
2744 | 116 | if (scope) | ||
2745 | 117 | { | ||
2746 | 118 | scopes_.insert(start+index, scope); | ||
2747 | 119 | |||
2748 | 120 | owner_->scope_added.emit(scope, index); | ||
2749 | 121 | } | ||
2750 | 122 | } | ||
2751 | 123 | else | ||
2752 | 124 | { | ||
2753 | 125 | Scope::Ptr scope = *scope_position; | ||
2754 | 126 | if (scope_position > (start + index)) | ||
2755 | 127 | { | ||
2756 | 128 | scopes_.erase(scope_position); | ||
2757 | 129 | scopes_.insert(start + index, scope); | ||
2758 | 130 | |||
2759 | 131 | owner_->scopes_reordered.emit(GetScopes()); | ||
2760 | 132 | } | ||
2761 | 133 | else if (index > 0 && scope_position < (start + index - 1)) | ||
2762 | 134 | { | ||
2763 | 135 | scopes_.erase(scope_position); | ||
2764 | 136 | |||
2765 | 137 | scopes_.insert(start + index - 1, scope); | ||
2766 | 138 | |||
2767 | 139 | owner_->scopes_reordered.emit(GetScopes()); | ||
2768 | 140 | } | ||
2769 | 141 | } | ||
2770 | 142 | } | ||
2771 | 143 | |||
2772 | 144 | void Scopes::Impl::RemoveScope(std::string const& scope_id) | ||
2773 | 145 | { | ||
2774 | 146 | auto scope_position = std::find_if(scopes_.begin(), | ||
2775 | 147 | scopes_.end(), | ||
2776 | 148 | [scope_id](Scope::Ptr const& value) { return value->id() == scope_id; }); | ||
2777 | 149 | |||
2778 | 150 | if (scope_position != scopes_.end()) | ||
2779 | 151 | { | ||
2780 | 152 | Scope::Ptr scope = *scope_position; | ||
2781 | 153 | scopes_.erase(scope_position); | ||
2782 | 154 | |||
2783 | 155 | owner_->scope_removed.emit(scope); | ||
2784 | 156 | } | ||
2785 | 157 | } | ||
2786 | 158 | |||
2787 | 159 | Scopes::ScopeList const& Scopes::Impl::GetScopes() const | ||
2788 | 160 | { | ||
2789 | 161 | return scopes_; | ||
2790 | 162 | } | ||
2791 | 163 | |||
2792 | 164 | Scope::Ptr Scopes::Impl::GetScope(std::string const& scope_id, int* index) const | ||
2793 | 165 | { | ||
2794 | 166 | int tmp_index = 0; | ||
2795 | 167 | for (auto scope: scopes_) | ||
2796 | 168 | { | ||
2797 | 169 | if (scope->id == scope_id) | ||
2798 | 170 | { | ||
2799 | 171 | if (index) | ||
2800 | 172 | *index = tmp_index; | ||
2801 | 173 | return scope; | ||
2802 | 174 | } | ||
2803 | 175 | tmp_index++; | ||
2804 | 176 | } | ||
2805 | 177 | if (index) | ||
2806 | 178 | *index = -1; | ||
2807 | 179 | return Scope::Ptr(); | ||
2808 | 180 | } | ||
2809 | 181 | |||
2810 | 182 | Scope::Ptr Scopes::Impl::GetScopeAtIndex(std::size_t index) const | ||
2811 | 183 | { | ||
2812 | 184 | try | ||
2813 | 185 | { | ||
2814 | 186 | return scopes_.at(index); | ||
2815 | 187 | } | ||
2816 | 188 | catch (std::out_of_range& error) | ||
2817 | 189 | { | ||
2818 | 190 | LOG_WARN(logger) << error.what(); | ||
2819 | 191 | } | ||
2820 | 192 | return Scope::Ptr(); | ||
2821 | 193 | } | ||
2822 | 194 | |||
2823 | 195 | Scope::Ptr Scopes::Impl::GetScopeForShortcut(std::string const& scope_shortcut) const | ||
2824 | 196 | { | ||
2825 | 197 | for (auto scope: scopes_) | ||
2826 | 198 | { | ||
2827 | 199 | if (scope->shortcut == scope_shortcut) | ||
2828 | 200 | { | ||
2829 | 201 | return scope; | ||
2830 | 202 | } | ||
2831 | 203 | } | ||
2832 | 204 | |||
2833 | 205 | return Scope::Ptr(); | ||
2834 | 206 | } | ||
2835 | 207 | |||
2836 | 208 | Scopes::Scopes(ScopesReader::Ptr scopes_reader) | ||
2837 | 209 | : pimpl(new Impl(this, scopes_reader)) | ||
2838 | 210 | { | ||
2839 | 211 | count.SetGetterFunction(sigc::mem_fun(pimpl.get(), &Impl::get_count)); | ||
2840 | 212 | } | ||
2841 | 213 | |||
2842 | 214 | Scopes::~Scopes() | ||
2843 | 215 | { | ||
2844 | 216 | } | ||
2845 | 217 | |||
2846 | 218 | void Scopes::LoadScopes() | ||
2847 | 219 | { | ||
2848 | 220 | pimpl->LoadScopes(); | ||
2849 | 221 | } | ||
2850 | 222 | |||
2851 | 223 | Scopes::ScopeList const& Scopes::GetScopes() const | ||
2852 | 224 | { | ||
2853 | 225 | return pimpl->GetScopes(); | ||
2854 | 226 | } | ||
2855 | 227 | |||
2856 | 228 | Scope::Ptr Scopes::GetScope(std::string const& scope_id, int* position) const | ||
2857 | 229 | { | ||
2858 | 230 | return pimpl->GetScope(scope_id, position); | ||
2859 | 231 | } | ||
2860 | 232 | |||
2861 | 233 | Scope::Ptr Scopes::GetScopeAtIndex(std::size_t index) const | ||
2862 | 234 | { | ||
2863 | 235 | return pimpl->GetScopeAtIndex(index); | ||
2864 | 236 | } | ||
2865 | 237 | |||
2866 | 238 | Scope::Ptr Scopes::GetScopeForShortcut(std::string const& scope_shortcut) const | ||
2867 | 239 | { | ||
2868 | 240 | return pimpl->GetScopeForShortcut(scope_shortcut); | ||
2869 | 241 | } | ||
2870 | 242 | |||
2871 | 243 | void Scopes::InsertScope(std::string const& scope_id, unsigned index) | ||
2872 | 244 | { | ||
2873 | 245 | if (!pimpl->scopes_reader_) | ||
2874 | 246 | return; | ||
2875 | 247 | |||
2876 | 248 | ScopeData::Ptr scope_data(pimpl->scopes_reader_->GetScopeDataById(scope_id)); | ||
2877 | 249 | if (scope_data) | ||
2878 | 250 | pimpl->InsertScope(scope_data, index); | ||
2879 | 251 | } | ||
2880 | 252 | |||
2881 | 253 | void Scopes::RemoveScope(std::string const& scope_id) | ||
2882 | 254 | { | ||
2883 | 255 | pimpl->RemoveScope(scope_id); | ||
2884 | 256 | } | ||
2885 | 257 | |||
2886 | 258 | Scope::Ptr Scopes::CreateScope(ScopeData::Ptr const& scope_data) | ||
2887 | 259 | { | ||
2888 | 260 | if (!scope_data) | ||
2889 | 261 | return Scope::Ptr(); | ||
2890 | 262 | |||
2891 | 263 | LOG_DEBUG(logger) << "Creating scope: " << scope_data->id() << " (" << scope_data->dbus_path() << " @ " << scope_data->dbus_name() << ")"; | ||
2892 | 264 | Scope::Ptr scope(new Scope(scope_data)); | ||
2893 | 265 | scope->Init(); | ||
2894 | 266 | return scope; | ||
2895 | 267 | } | ||
2896 | 268 | |||
2897 | 269 | |||
2898 | 270 | } // namespace dash | ||
2899 | 271 | } // namespace unity | ||
2900 | 0 | 272 | ||
2901 | === added file 'UnityCore/Scopes.h' | |||
2902 | --- UnityCore/Scopes.h 1970-01-01 00:00:00 +0000 | |||
2903 | +++ UnityCore/Scopes.h 2013-02-21 10:37:29 +0000 | |||
2904 | @@ -0,0 +1,94 @@ | |||
2905 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
2906 | 2 | /* | ||
2907 | 3 | * Copyright (C) 2011 Canonical Ltd | ||
2908 | 4 | * | ||
2909 | 5 | * This program is free software: you can redistribute it and/or modify | ||
2910 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
2911 | 7 | * published by the Free Software Foundation. | ||
2912 | 8 | * | ||
2913 | 9 | * This program is distributed in the hope that it will be useful, | ||
2914 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2915 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2916 | 12 | * GNU General Public License for more details. | ||
2917 | 13 | * | ||
2918 | 14 | * You should have received a copy of the GNU General Public License | ||
2919 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2920 | 16 | * | ||
2921 | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | ||
2922 | 18 | Nick Dedekind <nick.dedeknd@canoncial.com> | ||
2923 | 19 | */ | ||
2924 | 20 | |||
2925 | 21 | #ifndef UNITY_SCOPES_H | ||
2926 | 22 | #define UNITY_SCOPES_H | ||
2927 | 23 | |||
2928 | 24 | #include <sigc++/trackable.h> | ||
2929 | 25 | #include <sigc++/signal.h> | ||
2930 | 26 | |||
2931 | 27 | #include "Scope.h" | ||
2932 | 28 | |||
2933 | 29 | namespace unity | ||
2934 | 30 | { | ||
2935 | 31 | namespace dash | ||
2936 | 32 | { | ||
2937 | 33 | |||
2938 | 34 | typedef std::vector<ScopeData::Ptr> ScopeDataList; | ||
2939 | 35 | |||
2940 | 36 | class ScopesReader : public sigc::trackable, boost::noncopyable | ||
2941 | 37 | { | ||
2942 | 38 | public: | ||
2943 | 39 | typedef std::shared_ptr<ScopesReader> Ptr; | ||
2944 | 40 | virtual ~ScopesReader() {} | ||
2945 | 41 | |||
2946 | 42 | virtual void LoadScopes() = 0; | ||
2947 | 43 | virtual ScopeDataList const& GetScopesData() const = 0; | ||
2948 | 44 | |||
2949 | 45 | virtual ScopeData::Ptr GetScopeDataById(std::string const& scope_id) const = 0; | ||
2950 | 46 | |||
2951 | 47 | sigc::signal<void, ScopeDataList const&> scopes_changed; | ||
2952 | 48 | }; | ||
2953 | 49 | |||
2954 | 50 | class Scopes : public sigc::trackable, boost::noncopyable | ||
2955 | 51 | { | ||
2956 | 52 | public: | ||
2957 | 53 | typedef std::shared_ptr<Scopes> Ptr; | ||
2958 | 54 | typedef std::vector<Scope::Ptr> ScopeList; | ||
2959 | 55 | |||
2960 | 56 | Scopes(ScopesReader::Ptr scope_reader); | ||
2961 | 57 | virtual ~Scopes(); | ||
2962 | 58 | |||
2963 | 59 | virtual void LoadScopes(); | ||
2964 | 60 | |||
2965 | 61 | /** | ||
2966 | 62 | * Get the currently loaded Scopess. This is necessary as some of the consumers | ||
2967 | 63 | * of this object employ a lazy-loading technique to reduce the overhead of | ||
2968 | 64 | * starting Unity. Therefore, the Scopes may already have been loaded by the time | ||
2969 | 65 | * the objects have been initiated (and so just connecting to the signals is not | ||
2970 | 66 | * enough) | ||
2971 | 67 | */ | ||
2972 | 68 | virtual ScopeList const& GetScopes() const; | ||
2973 | 69 | virtual Scope::Ptr GetScope(std::string const& scope_id, int* position = nullptr) const; | ||
2974 | 70 | virtual Scope::Ptr GetScopeAtIndex(std::size_t index) const; | ||
2975 | 71 | virtual Scope::Ptr GetScopeForShortcut(std::string const& scope_shortcut) const; | ||
2976 | 72 | |||
2977 | 73 | nux::ROProperty<std::size_t> count; | ||
2978 | 74 | |||
2979 | 75 | sigc::signal<void, Scope::Ptr const&, int> scope_added; | ||
2980 | 76 | sigc::signal<void, Scope::Ptr const&> scope_removed; | ||
2981 | 77 | |||
2982 | 78 | sigc::signal<void, ScopeList const&> scopes_reordered; | ||
2983 | 79 | |||
2984 | 80 | protected: | ||
2985 | 81 | virtual void InsertScope(std::string const& scope_id, unsigned index); | ||
2986 | 82 | virtual void RemoveScope(std::string const& scope_id); | ||
2987 | 83 | |||
2988 | 84 | virtual Scope::Ptr CreateScope(ScopeData::Ptr const& scope_data); | ||
2989 | 85 | |||
2990 | 86 | private: | ||
2991 | 87 | class Impl; | ||
2992 | 88 | std::unique_ptr<Impl> pimpl; | ||
2993 | 89 | }; | ||
2994 | 90 | |||
2995 | 91 | } // namespace dash | ||
2996 | 92 | } // namespace unity | ||
2997 | 93 | |||
2998 | 94 | #endif // UNITY_SCOPES_H | ||
2999 | 0 | 95 | ||
3000 | === modified file 'UnityCore/SeriesPreview.cpp' | |||
3001 | --- UnityCore/SeriesPreview.cpp 2012-07-12 16:36:54 +0000 | |||
3002 | +++ UnityCore/SeriesPreview.cpp 2013-02-21 10:37:29 +0000 | |||
3003 | @@ -33,14 +33,14 @@ | |||
3004 | 33 | Impl(SeriesPreview* owner, glib::Object<GObject> const& proto_obj); | 33 | Impl(SeriesPreview* owner, glib::Object<GObject> const& proto_obj); |
3005 | 34 | 34 | ||
3006 | 35 | void SetupGetters(); | 35 | void SetupGetters(); |
3008 | 36 | void selected_item_reply(GVariant* reply); | 36 | void selected_item_reply(glib::HintsMap const&, glib::Error const&); |
3009 | 37 | int get_selected_item_index() const { return selected_item_index_; }; | 37 | int get_selected_item_index() const { return selected_item_index_; }; |
3010 | 38 | bool set_selected_item_index(int index); | 38 | bool set_selected_item_index(int index); |
3011 | 39 | SeriesItemPtrList get_items() const { return items_list_; }; | 39 | SeriesItemPtrList get_items() const { return items_list_; }; |
3012 | 40 | Preview::Ptr get_child_preview() const | 40 | Preview::Ptr get_child_preview() const |
3013 | 41 | { | 41 | { |
3016 | 42 | if (!child_preview_->parent_lens) | 42 | if (!child_preview_->parent_scope) |
3017 | 43 | child_preview_->parent_lens = owner_->parent_lens(); | 43 | child_preview_->parent_scope = owner_->parent_scope(); |
3018 | 44 | if (child_preview_->preview_uri().empty()) | 44 | if (child_preview_->preview_uri().empty()) |
3019 | 45 | child_preview_->preview_uri = owner_->preview_uri(); | 45 | child_preview_->preview_uri = owner_->preview_uri(); |
3020 | 46 | return child_preview_; | 46 | return child_preview_; |
3021 | @@ -101,24 +101,24 @@ | |||
3022 | 101 | unity_protocol_series_preview_set_selected_item(raw_preview_, index); | 101 | unity_protocol_series_preview_set_selected_item(raw_preview_, index); |
3023 | 102 | glib::Variant properties(unity_protocol_preview_end_updates(preview), | 102 | glib::Variant properties(unity_protocol_preview_end_updates(preview), |
3024 | 103 | glib::StealRef()); | 103 | glib::StealRef()); |
3027 | 104 | owner_->Update(properties, sigc::mem_fun(this, &SeriesPreview::Impl::selected_item_reply)); | 104 | |
3028 | 105 | return true; | 105 | glib::HintsMap property_hints; |
3029 | 106 | if (properties.ASVToHints(property_hints)) | ||
3030 | 107 | owner_->Update(property_hints, sigc::mem_fun(this, &SeriesPreview::Impl::selected_item_reply)); | ||
3031 | 108 | else | ||
3032 | 109 | g_assert(false); | ||
3033 | 106 | } | 110 | } |
3034 | 107 | 111 | ||
3035 | 108 | return false; | 112 | return false; |
3036 | 109 | } | 113 | } |
3037 | 110 | 114 | ||
3039 | 111 | void SeriesPreview::Impl::selected_item_reply(GVariant *reply) | 115 | void SeriesPreview::Impl::selected_item_reply(glib::HintsMap const& hints, glib::Error const&) |
3040 | 112 | { | 116 | { |
3041 | 113 | glib::Variant dict(reply); | ||
3042 | 114 | glib::HintsMap hints; | ||
3043 | 115 | dict.ASVToHints(hints); | ||
3044 | 116 | |||
3045 | 117 | auto iter = hints.find("preview"); | 117 | auto iter = hints.find("preview"); |
3046 | 118 | if (iter != hints.end()) | 118 | if (iter != hints.end()) |
3047 | 119 | { | 119 | { |
3048 | 120 | Preview::Ptr new_child = Preview::PreviewForVariant(iter->second); | 120 | Preview::Ptr new_child = Preview::PreviewForVariant(iter->second); |
3050 | 121 | new_child->parent_lens = owner_->parent_lens(); | 121 | new_child->parent_scope = owner_->parent_scope(); |
3051 | 122 | new_child->preview_uri = owner_->preview_uri(); // FIXME: really? | 122 | new_child->preview_uri = owner_->preview_uri(); // FIXME: really? |
3052 | 123 | child_preview_ = new_child; | 123 | child_preview_ = new_child; |
3053 | 124 | owner_->child_preview_changed.emit(new_child); | 124 | owner_->child_preview_changed.emit(new_child); |
3054 | 125 | 125 | ||
3055 | === modified file 'UnityCore/Tracks.cpp' | |||
3056 | --- UnityCore/Tracks.cpp 2012-06-19 16:47:56 +0000 | |||
3057 | +++ UnityCore/Tracks.cpp 2013-02-21 10:37:29 +0000 | |||
3058 | @@ -25,6 +25,7 @@ | |||
3059 | 25 | { | 25 | { |
3060 | 26 | 26 | ||
3061 | 27 | Tracks::Tracks() | 27 | Tracks::Tracks() |
3062 | 28 | : Model<Track>::Model(ModelType::REMOTE_SHARED) | ||
3063 | 28 | { | 29 | { |
3064 | 29 | row_added.connect(sigc::mem_fun(this, &Tracks::OnRowAdded)); | 30 | row_added.connect(sigc::mem_fun(this, &Tracks::OnRowAdded)); |
3065 | 30 | row_changed.connect(sigc::mem_fun(this, &Tracks::OnRowChanged)); | 31 | row_changed.connect(sigc::mem_fun(this, &Tracks::OnRowChanged)); |
3066 | @@ -32,7 +33,7 @@ | |||
3067 | 32 | } | 33 | } |
3068 | 33 | 34 | ||
3069 | 34 | Tracks::Tracks(ModelType model_type) | 35 | Tracks::Tracks(ModelType model_type) |
3071 | 35 | : Model<Track>::Model(model_type) | 36 | : Model<Track>::Model(model_type) |
3072 | 36 | { | 37 | { |
3073 | 37 | row_added.connect(sigc::mem_fun(this, &Tracks::OnRowAdded)); | 38 | row_added.connect(sigc::mem_fun(this, &Tracks::OnRowAdded)); |
3074 | 38 | row_changed.connect(sigc::mem_fun(this, &Tracks::OnRowChanged)); | 39 | row_changed.connect(sigc::mem_fun(this, &Tracks::OnRowChanged)); |
3075 | 39 | 40 | ||
3076 | === modified file 'UnityCore/Variant.cpp' | |||
3077 | --- UnityCore/Variant.cpp 2012-11-06 18:19:09 +0000 | |||
3078 | +++ UnityCore/Variant.cpp 2013-02-21 10:37:29 +0000 | |||
3079 | @@ -125,6 +125,47 @@ | |||
3080 | 125 | return bool(variant_); | 125 | return bool(variant_); |
3081 | 126 | } | 126 | } |
3082 | 127 | 127 | ||
3083 | 128 | static void g_variant_unref0 (gpointer var) | ||
3084 | 129 | { | ||
3085 | 130 | if (var) | ||
3086 | 131 | g_variant_unref((GVariant*)var); | ||
3087 | 132 | } | ||
3088 | 133 | |||
3089 | 134 | GHashTable* hashtable_from_hintsmap(glib::HintsMap const& hints) | ||
3090 | 135 | { | ||
3091 | 136 | GHashTable* hash_table = g_hash_table_new_full(g_str_hash, g_direct_equal, g_free, g_variant_unref0); | ||
3092 | 137 | |||
3093 | 138 | if (!hash_table) | ||
3094 | 139 | return nullptr; | ||
3095 | 140 | |||
3096 | 141 | for (glib::HintsMap::const_iterator it = hints.begin(); it != hints.end(); ++it) | ||
3097 | 142 | { | ||
3098 | 143 | gchar* key = g_strdup(it->first.c_str()); | ||
3099 | 144 | GVariant* ptr = g_variant_ref(it->second); | ||
3100 | 145 | |||
3101 | 146 | g_hash_table_insert(hash_table, key, ptr); | ||
3102 | 147 | } | ||
3103 | 148 | return hash_table; | ||
3104 | 149 | } | ||
3105 | 150 | |||
3106 | 151 | HintsMap const& hintsmap_from_hashtable(GHashTable* hashtable, HintsMap& hints) | ||
3107 | 152 | { | ||
3108 | 153 | if (!hashtable) | ||
3109 | 154 | return hints; | ||
3110 | 155 | |||
3111 | 156 | GHashTableIter hints_iter; | ||
3112 | 157 | gpointer key, value; | ||
3113 | 158 | g_hash_table_iter_init (&hints_iter, hashtable); | ||
3114 | 159 | while (g_hash_table_iter_next (&hints_iter, &key, &value)) | ||
3115 | 160 | { | ||
3116 | 161 | std::string hint_key(static_cast<gchar*>(key)); | ||
3117 | 162 | glib::Variant hint_value(static_cast<GVariant*>(value)); | ||
3118 | 163 | |||
3119 | 164 | hints[hint_key] = hint_value; | ||
3120 | 165 | } | ||
3121 | 166 | return hints; | ||
3122 | 167 | } | ||
3123 | 168 | |||
3124 | 128 | } // namespace glib | 169 | } // namespace glib |
3125 | 129 | 170 | ||
3126 | 130 | namespace variant | 171 | namespace variant |
3127 | @@ -220,6 +261,5 @@ | |||
3128 | 220 | return *this; | 261 | return *this; |
3129 | 221 | } | 262 | } |
3130 | 222 | 263 | ||
3131 | 223 | |||
3132 | 224 | } | 264 | } |
3133 | 225 | } | 265 | } |
3134 | 226 | 266 | ||
3135 | === modified file 'UnityCore/Variant.h' | |||
3136 | --- UnityCore/Variant.h 2012-11-06 18:19:09 +0000 | |||
3137 | +++ UnityCore/Variant.h 2013-02-21 10:37:29 +0000 | |||
3138 | @@ -33,6 +33,8 @@ | |||
3139 | 33 | 33 | ||
3140 | 34 | class Variant; | 34 | class Variant; |
3141 | 35 | typedef std::map<std::string, Variant> HintsMap; | 35 | typedef std::map<std::string, Variant> HintsMap; |
3142 | 36 | GHashTable* hashtable_from_hintsmap(HintsMap const& hints); | ||
3143 | 37 | HintsMap const& hintsmap_from_hashtable(GHashTable* hashtable, HintsMap& hints); | ||
3144 | 36 | 38 | ||
3145 | 37 | struct StealRef {}; | 39 | struct StealRef {}; |
3146 | 38 | 40 | ||
3147 | 39 | 41 | ||
3148 | === modified file 'com.canonical.Unity.gschema.xml' | |||
3149 | --- com.canonical.Unity.gschema.xml 2013-02-06 11:07:00 +0000 | |||
3150 | +++ com.canonical.Unity.gschema.xml 2013-02-21 10:37:29 +0000 | |||
3151 | @@ -67,5 +67,15 @@ | |||
3152 | 67 | <summary>List of lens ids specifying how lenses should be ordered in the Dash home screen.</summary> | 67 | <summary>List of lens ids specifying how lenses should be ordered in the Dash home screen.</summary> |
3153 | 68 | <description>The categories listed on the Dash home screen will be ordered according to this list. Lenses not appearing in this list will not have any particular ordering and will always sort after lenses specified in this list.</description> | 68 | <description>The categories listed on the Dash home screen will be ordered according to this list. Lenses not appearing in this list will not have any particular ordering and will always sort after lenses specified in this list.</description> |
3154 | 69 | </key> | 69 | </key> |
3155 | 70 | <key type="as" name="scopes"> | ||
3156 | 71 | <default>[ 'home.scope' , 'applications.scope' ]</default> | ||
3157 | 72 | <summary>List of scope ids specifying which scopes should be created and the order to display them in.</summary> | ||
3158 | 73 | <description>The scopes listed in the scope bar will be ordered according to this list.</description> | ||
3159 | 74 | </key> | ||
3160 | 75 | <key type="as" name="always-search"> | ||
3161 | 76 | <default>[ 'applications.lens' ]</default> | ||
3162 | 77 | <summary>List of scope ids which are always searched when the search string changes.</summary> | ||
3163 | 78 | <description></description> | ||
3164 | 79 | </key> | ||
3165 | 70 | </schema> | 80 | </schema> |
3166 | 71 | </schemalist> | 81 | </schemalist> |
3167 | 72 | 82 | ||
3168 | === modified file 'dash/DashController.cpp' | |||
3169 | --- dash/DashController.cpp 2013-01-30 02:11:19 +0000 | |||
3170 | +++ dash/DashController.cpp 2013-02-21 10:37:29 +0000 | |||
3171 | @@ -403,14 +403,14 @@ | |||
3172 | 403 | gboolean Controller::CheckShortcutActivation(const char* key_string) | 403 | gboolean Controller::CheckShortcutActivation(const char* key_string) |
3173 | 404 | { | 404 | { |
3174 | 405 | EnsureDash(); | 405 | EnsureDash(); |
3177 | 406 | std::string lens_id = view_->GetIdForShortcutActivation(std::string(key_string)); | 406 | std::string scope_id = view_->GetIdForShortcutActivation(std::string(key_string)); |
3178 | 407 | if (lens_id != "") | 407 | if (scope_id != "") |
3179 | 408 | { | 408 | { |
3180 | 409 | WindowManager& wm = WindowManager::Default(); | 409 | WindowManager& wm = WindowManager::Default(); |
3181 | 410 | if (wm.IsScaleActive()) | 410 | if (wm.IsScaleActive()) |
3182 | 411 | wm.TerminateScale(); | 411 | wm.TerminateScale(); |
3183 | 412 | 412 | ||
3185 | 413 | GVariant* args = g_variant_new("(sus)", lens_id.c_str(), dash::GOTO_DASH_URI, ""); | 413 | GVariant* args = g_variant_new("(sus)", scope_id.c_str(), dash::GOTO_DASH_URI, ""); |
3186 | 414 | OnActivateRequest(args); | 414 | OnActivateRequest(args); |
3187 | 415 | g_variant_unref(args); | 415 | g_variant_unref(args); |
3188 | 416 | return true; | 416 | return true; |
3189 | 417 | 417 | ||
3190 | === modified file 'dash/DashView.cpp' | |||
3191 | --- dash/DashView.cpp 2013-02-14 22:12:50 +0000 | |||
3192 | +++ dash/DashView.cpp 2013-02-21 10:37:29 +0000 | |||
3193 | @@ -31,6 +31,7 @@ | |||
3194 | 31 | #include <NuxCore/Logger.h> | 31 | #include <NuxCore/Logger.h> |
3195 | 32 | #include <UnityCore/GLibWrapper.h> | 32 | #include <UnityCore/GLibWrapper.h> |
3196 | 33 | #include <UnityCore/RadioOptionFilter.h> | 33 | #include <UnityCore/RadioOptionFilter.h> |
3197 | 34 | #include <UnityCore/GSettingsScopes.h> | ||
3198 | 34 | 35 | ||
3199 | 35 | #include "unity-shared/DashStyle.h" | 36 | #include "unity-shared/DashStyle.h" |
3200 | 36 | #include "unity-shared/KeyboardUtil.h" | 37 | #include "unity-shared/KeyboardUtil.h" |
3201 | @@ -110,9 +111,8 @@ | |||
3202 | 110 | 111 | ||
3203 | 111 | NUX_IMPLEMENT_OBJECT_TYPE(DashView); | 112 | NUX_IMPLEMENT_OBJECT_TYPE(DashView); |
3204 | 112 | 113 | ||
3206 | 113 | DashView::DashView() | 114 | DashView::DashView(ScopesCreator scopes_creator) |
3207 | 114 | : nux::View(NUX_TRACKER_LOCATION) | 115 | : nux::View(NUX_TRACKER_LOCATION) |
3208 | 115 | , home_lens_(new HomeLens(_("Home"), _("Home screen"), _("Search your computer and online sources"))) | ||
3209 | 116 | , preview_container_(nullptr) | 116 | , preview_container_(nullptr) |
3210 | 117 | , preview_displaying_(false) | 117 | , preview_displaying_(false) |
3211 | 118 | , preview_navigation_mode_(previews::Navigation::NONE) | 118 | , preview_navigation_mode_(previews::Navigation::NONE) |
3212 | @@ -137,32 +137,34 @@ | |||
3213 | 137 | SetupViews(); | 137 | SetupViews(); |
3214 | 138 | SetupUBusConnections(); | 138 | SetupUBusConnections(); |
3215 | 139 | 139 | ||
3216 | 140 | lenses_.lens_added.connect(sigc::mem_fun(this, &DashView::OnLensAdded)); | ||
3217 | 141 | mouse_down.connect(sigc::mem_fun(this, &DashView::OnMouseButtonDown)); | 140 | mouse_down.connect(sigc::mem_fun(this, &DashView::OnMouseButtonDown)); |
3218 | 142 | preview_state_machine_.PreviewActivated.connect(sigc::mem_fun(this, &DashView::BuildPreview)); | 141 | preview_state_machine_.PreviewActivated.connect(sigc::mem_fun(this, &DashView::BuildPreview)); |
3219 | 143 | Relayout(); | 142 | Relayout(); |
3220 | 144 | 143 | ||
3221 | 145 | home_lens_->AddLenses(lenses_); | ||
3222 | 146 | lens_bar_->Activate("home.lens"); | ||
3223 | 147 | |||
3224 | 148 | // we will special case when applications lens finishes global search | ||
3225 | 149 | // because we want to be able to launch applications immediately | ||
3226 | 150 | // without waiting for the search finished signal which will | ||
3227 | 151 | // be delayed by all the lenses we're searching | ||
3228 | 152 | home_lens_->lens_search_finished.connect(sigc::mem_fun(this, &DashView::OnAppsGlobalSearchFinished)); | ||
3229 | 153 | |||
3230 | 154 | // We are interested in the color of the desktop background. | 144 | // We are interested in the color of the desktop background. |
3231 | 155 | ubus_manager_.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED, sigc::mem_fun(this, &DashView::OnBGColorChanged)); | 145 | ubus_manager_.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED, sigc::mem_fun(this, &DashView::OnBGColorChanged)); |
3232 | 156 | 146 | ||
3233 | 157 | // request the latest colour from bghash | 147 | // request the latest colour from bghash |
3234 | 158 | ubus_manager_.SendMessage(UBUS_BACKGROUND_REQUEST_COLOUR_EMIT); | 148 | ubus_manager_.SendMessage(UBUS_BACKGROUND_REQUEST_COLOUR_EMIT); |
3235 | 159 | 149 | ||
3236 | 150 | if (scopes_creator == nullptr) | ||
3237 | 151 | { | ||
3238 | 152 | scopes_creator = [this]() { scopes_.reset(new GSettingsScopes()); }; | ||
3239 | 153 | } | ||
3240 | 154 | |||
3241 | 155 | scopes_creator(); | ||
3242 | 156 | if (scopes_) | ||
3243 | 157 | { | ||
3244 | 158 | scopes_->scope_added.connect(sigc::mem_fun(this, &DashView::OnScopeAdded)); | ||
3245 | 159 | scopes_->LoadScopes(); | ||
3246 | 160 | } | ||
3247 | 160 | } | 161 | } |
3248 | 161 | 162 | ||
3249 | 162 | DashView::~DashView() | 163 | DashView::~DashView() |
3250 | 163 | { | 164 | { |
3251 | 165 | scope_can_refine_connection_.disconnect(); | ||
3252 | 164 | // Do this explicitely, otherwise dee will complain about invalid access | 166 | // Do this explicitely, otherwise dee will complain about invalid access |
3254 | 165 | // to the lens models | 167 | // to the scope models |
3255 | 166 | RemoveLayout(); | 168 | RemoveLayout(); |
3256 | 167 | } | 169 | } |
3257 | 168 | 170 | ||
3258 | @@ -220,12 +222,12 @@ | |||
3259 | 220 | StartPreviewAnimation(); | 222 | StartPreviewAnimation(); |
3260 | 221 | 223 | ||
3261 | 222 | content_view_->SetPresentRedirectedView(false); | 224 | content_view_->SetPresentRedirectedView(false); |
3264 | 223 | preview_lens_view_ = active_lens_view_; | 225 | preview_scope_view_ = active_scope_view_; |
3265 | 224 | if (preview_lens_view_) | 226 | if (preview_scope_view_) |
3266 | 225 | { | 227 | { |
3270 | 226 | preview_lens_view_->ForceCategoryExpansion(stored_activated_unique_id_, true); | 228 | preview_scope_view_->ForceCategoryExpansion(stored_activated_unique_id_, true); |
3271 | 227 | preview_lens_view_->EnableResultTextures(true); | 229 | preview_scope_view_->EnableResultTextures(true); |
3272 | 228 | preview_lens_view_->PushFilterExpansion(false); | 230 | preview_scope_view_->PushFilterExpansion(false); |
3273 | 229 | } | 231 | } |
3274 | 230 | 232 | ||
3275 | 231 | if (!preview_container_) | 233 | if (!preview_container_) |
3276 | @@ -237,7 +239,7 @@ | |||
3277 | 237 | } | 239 | } |
3278 | 238 | preview_container_->Preview(model, previews::Navigation::NONE); // no swipe left or right | 240 | preview_container_->Preview(model, previews::Navigation::NONE); // no swipe left or right |
3279 | 239 | 241 | ||
3281 | 240 | preview_container_->SetGeometry(lenses_layout_->GetGeometry()); | 242 | preview_container_->SetGeometry(scopes_layout_->GetGeometry()); |
3282 | 241 | preview_displaying_ = true; | 243 | preview_displaying_ = true; |
3283 | 242 | 244 | ||
3284 | 243 | // connect to nav left/right signals to request nav left/right movement. | 245 | // connect to nav left/right signals to request nav left/right movement. |
3285 | @@ -354,8 +356,8 @@ | |||
3286 | 354 | preview_container_animation_->Start(); | 356 | preview_container_animation_->Start(); |
3287 | 355 | } | 357 | } |
3288 | 356 | 358 | ||
3291 | 357 | if (preview_lens_view_) | 359 | if (preview_scope_view_) |
3292 | 358 | preview_lens_view_->SetResultsPreviewAnimationValue(animate_split_value_); | 360 | preview_scope_view_->SetResultsPreviewAnimationValue(animate_split_value_); |
3293 | 359 | }); | 361 | }); |
3294 | 360 | 362 | ||
3295 | 361 | split_animation_->finished.connect(sigc::mem_fun(this, &DashView::OnPreviewAnimationFinished)); | 363 | split_animation_->finished.connect(sigc::mem_fun(this, &DashView::OnPreviewAnimationFinished)); |
3296 | @@ -415,8 +417,8 @@ | |||
3297 | 415 | split_animation_->finished.connect(sigc::mem_fun(this, &DashView::OnPreviewAnimationFinished)); | 417 | split_animation_->finished.connect(sigc::mem_fun(this, &DashView::OnPreviewAnimationFinished)); |
3298 | 416 | split_animation_->Start(); | 418 | split_animation_->Start(); |
3299 | 417 | 419 | ||
3302 | 418 | // if (preview_lens_view_) | 420 | // if (preview_scope_view_) |
3303 | 419 | // preview_lens_view_->PopFilterExpansion(); | 421 | // preview_scope_view_->PopFilterExpansion(); |
3304 | 420 | } | 422 | } |
3305 | 421 | }); | 423 | }); |
3306 | 422 | 424 | ||
3307 | @@ -445,14 +447,14 @@ | |||
3308 | 445 | } | 447 | } |
3309 | 446 | 448 | ||
3310 | 447 | // reset the saturation. | 449 | // reset the saturation. |
3312 | 448 | if (preview_lens_view_.IsValid()) | 450 | if (preview_scope_view_.IsValid()) |
3313 | 449 | { | 451 | { |
3318 | 450 | preview_lens_view_->SetResultsPreviewAnimationValue(0.0); | 452 | preview_scope_view_->SetResultsPreviewAnimationValue(0.0); |
3319 | 451 | preview_lens_view_->ForceCategoryExpansion(stored_activated_unique_id_, false); | 453 | preview_scope_view_->ForceCategoryExpansion(stored_activated_unique_id_, false); |
3320 | 452 | preview_lens_view_->EnableResultTextures(false); | 454 | preview_scope_view_->EnableResultTextures(false); |
3321 | 453 | preview_lens_view_->PopFilterExpansion(); | 455 | preview_scope_view_->PopFilterExpansion(); |
3322 | 454 | } | 456 | } |
3324 | 455 | preview_lens_view_.Release(); | 457 | preview_scope_view_.Release(); |
3325 | 456 | content_view_->SetPresentRedirectedView(true); | 458 | content_view_->SetPresentRedirectedView(true); |
3326 | 457 | } | 459 | } |
3327 | 458 | 460 | ||
3328 | @@ -462,31 +464,13 @@ | |||
3329 | 462 | visible_ = true; | 464 | visible_ = true; |
3330 | 463 | search_bar_->text_entry()->SelectAll(); | 465 | search_bar_->text_entry()->SelectAll(); |
3331 | 464 | 466 | ||
3357 | 465 | /* Give the lenses a chance to prep data before we map them */ | 467 | /* Give the scopes a chance to prep data before we map them */ |
3358 | 466 | lens_bar_->Activate(active_lens_view_->lens()->id()); | 468 | if (active_scope_view_) |
3359 | 467 | if (active_lens_view_) | 469 | { |
3360 | 468 | { | 470 | scope_bar_->Activate(active_scope_view_->scope()->id()); |
3361 | 469 | active_lens_view_->SetVisible(true); | 471 | |
3362 | 470 | 472 | active_scope_view_->SetVisible(true); | |
3363 | 471 | if (active_lens_view_->lens()->id() == "home.lens") | 473 | active_scope_view_->scope()->view_type = ScopeViewType::SCOPE_VIEW; |
3339 | 472 | { | ||
3340 | 473 | for (auto lens : lenses_.GetLenses()) | ||
3341 | 474 | { | ||
3342 | 475 | lens->view_type = ViewType::HOME_VIEW; | ||
3343 | 476 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HOME_VIEW | ||
3344 | 477 | << " on '" << lens->id() << "'"; | ||
3345 | 478 | } | ||
3346 | 479 | |||
3347 | 480 | home_lens_->view_type = ViewType::LENS_VIEW; | ||
3348 | 481 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::LENS_VIEW | ||
3349 | 482 | << " on '" << home_lens_->id() << "'"; | ||
3350 | 483 | } | ||
3351 | 484 | else | ||
3352 | 485 | { | ||
3353 | 486 | // careful here, the lens_view's view_type doesn't get reset when the dash | ||
3354 | 487 | // hides, but lens' view_type does, so we need to update the lens directly | ||
3355 | 488 | active_lens_view_->lens()->view_type = ViewType::LENS_VIEW; | ||
3356 | 489 | } | ||
3364 | 490 | } | 474 | } |
3365 | 491 | 475 | ||
3366 | 492 | // this will make sure the spinner animates if the search takes a while | 476 | // this will make sure the spinner animates if the search takes a while |
3367 | @@ -508,19 +492,18 @@ | |||
3368 | 508 | visible_ = false; | 492 | visible_ = false; |
3369 | 509 | renderer_.AboutToHide(); | 493 | renderer_.AboutToHide(); |
3370 | 510 | 494 | ||
3372 | 511 | for (auto lens : lenses_.GetLenses()) | 495 | if (scopes_) |
3373 | 512 | { | 496 | { |
3377 | 513 | lens->view_type = ViewType::HIDDEN; | 497 | for (auto scope : scopes_->GetScopes()) |
3378 | 514 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HIDDEN | 498 | { |
3379 | 515 | << " on '" << lens->id() << "'"; | 499 | scope->view_type = ScopeViewType::HIDDEN; |
3380 | 500 | LOG_DEBUG(logger) << "Setting ViewType " << ScopeViewType::HIDDEN | ||
3381 | 501 | << " on '" << scope->id() << "'"; | ||
3382 | 502 | } | ||
3383 | 516 | } | 503 | } |
3384 | 517 | 504 | ||
3391 | 518 | home_lens_->view_type = ViewType::HIDDEN; | 505 | if (active_scope_view_.IsValid()) |
3392 | 519 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HIDDEN | 506 | active_scope_view_->SetVisible(false); |
3387 | 520 | << " on '" << home_lens_->id() << "'"; | ||
3388 | 521 | |||
3389 | 522 | if (active_lens_view_.IsValid()) | ||
3390 | 523 | active_lens_view_->SetVisible(false); | ||
3393 | 524 | 507 | ||
3394 | 525 | // if a preview is open, close it | 508 | // if a preview is open, close it |
3395 | 526 | if (preview_displaying_) | 509 | if (preview_displaying_) |
3396 | @@ -562,30 +545,22 @@ | |||
3397 | 562 | search_bar_->live_search_reached.connect(sigc::mem_fun(this, &DashView::OnLiveSearchReached)); | 545 | search_bar_->live_search_reached.connect(sigc::mem_fun(this, &DashView::OnLiveSearchReached)); |
3398 | 563 | search_bar_->showing_filters.changed.connect([&] (bool showing) | 546 | search_bar_->showing_filters.changed.connect([&] (bool showing) |
3399 | 564 | { | 547 | { |
3401 | 565 | if (active_lens_view_) | 548 | if (active_scope_view_) |
3402 | 566 | { | 549 | { |
3404 | 567 | active_lens_view_->filters_expanded = showing; | 550 | active_scope_view_->filters_expanded = showing; |
3405 | 568 | QueueDraw(); | 551 | QueueDraw(); |
3406 | 569 | } | 552 | } |
3407 | 570 | }); | 553 | }); |
3408 | 571 | search_bar_layout_->AddView(search_bar_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); | 554 | search_bar_layout_->AddView(search_bar_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); |
3409 | 572 | content_layout_->SetSpecialArea(search_bar_->show_filters()); | 555 | content_layout_->SetSpecialArea(search_bar_->show_filters()); |
3410 | 573 | 556 | ||
3426 | 574 | lenses_layout_ = new nux::VLayout(); | 557 | scopes_layout_ = new nux::VLayout(); |
3427 | 575 | content_layout_->AddLayout(lenses_layout_, 1, nux::MINOR_POSITION_START); | 558 | content_layout_->AddLayout(scopes_layout_, 1, nux::MINOR_POSITION_START); |
3428 | 576 | 559 | ||
3429 | 577 | home_view_ = new LensView(home_lens_, nullptr); | 560 | scope_bar_ = new ScopeBar(); |
3430 | 578 | home_view_->uri_activated.connect(sigc::mem_fun(this, &DashView::OnUriActivated)); | 561 | AddChild(scope_bar_); |
3431 | 579 | 562 | scope_bar_->scope_activated.connect(sigc::mem_fun(this, &DashView::OnScopeBarActivated)); | |
3432 | 580 | AddChild(home_view_.GetPointer()); | 563 | content_layout_->AddView(scope_bar_, 0, nux::MINOR_POSITION_CENTER); |
3418 | 581 | active_lens_view_ = home_view_; | ||
3419 | 582 | lens_views_[home_lens_->id] = home_view_; | ||
3420 | 583 | lenses_layout_->AddView(home_view_.GetPointer()); | ||
3421 | 584 | |||
3422 | 585 | lens_bar_ = new LensBar(); | ||
3423 | 586 | AddChild(lens_bar_); | ||
3424 | 587 | lens_bar_->lens_activated.connect(sigc::mem_fun(this, &DashView::OnLensBarActivated)); | ||
3425 | 588 | content_layout_->AddView(lens_bar_, 0, nux::MINOR_POSITION_CENTER); | ||
3433 | 589 | } | 564 | } |
3434 | 590 | 565 | ||
3435 | 591 | void DashView::SetupUBusConnections() | 566 | void DashView::SetupUBusConnections() |
3436 | @@ -609,8 +584,8 @@ | |||
3437 | 609 | // kinda hacky, but it makes sure the content isn't so big that it throws | 584 | // kinda hacky, but it makes sure the content isn't so big that it throws |
3438 | 610 | // the bottom of the dash off the screen | 585 | // the bottom of the dash off the screen |
3439 | 611 | // not hugely happy with this, so FIXME | 586 | // not hugely happy with this, so FIXME |
3442 | 612 | lenses_layout_->SetMaximumHeight (std::max(0, content_geo_.height - search_bar_->GetGeometry().height - lens_bar_->GetGeometry().height - style.GetDashViewTopPadding())); | 587 | scopes_layout_->SetMaximumHeight (std::max(0, content_geo_.height - search_bar_->GetGeometry().height - scope_bar_->GetGeometry().height - style.GetDashViewTopPadding())); |
3443 | 613 | lenses_layout_->SetMinimumHeight (std::max(0, content_geo_.height - search_bar_->GetGeometry().height - lens_bar_->GetGeometry().height - style.GetDashViewTopPadding())); | 588 | scopes_layout_->SetMinimumHeight (std::max(0, content_geo_.height - search_bar_->GetGeometry().height - scope_bar_->GetGeometry().height - style.GetDashViewTopPadding())); |
3444 | 614 | 589 | ||
3445 | 615 | layout_->SetMinMaxSize(content_geo_.width, content_geo_.y + content_geo_.height); | 590 | layout_->SetMinMaxSize(content_geo_.width, content_geo_.y + content_geo_.height); |
3446 | 616 | 591 | ||
3447 | @@ -653,7 +628,7 @@ | |||
3448 | 653 | height += style.GetDashViewTopPadding(); | 628 | height += style.GetDashViewTopPadding(); |
3449 | 654 | height += search_bar_->GetGeometry().height; | 629 | height += search_bar_->GetGeometry().height; |
3450 | 655 | height += category_height * DASH_DEFAULT_CATEGORY_COUNT; // adding three categories | 630 | height += category_height * DASH_DEFAULT_CATEGORY_COUNT; // adding three categories |
3452 | 656 | height += lens_bar_->GetGeometry().height; | 631 | height += scope_bar_->GetGeometry().height; |
3453 | 657 | 632 | ||
3454 | 658 | // width/height shouldn't be bigger than the geo available. | 633 | // width/height shouldn't be bigger than the geo available. |
3455 | 659 | width = std::min(width, for_geo.width); // launcher width is taken into account in for_geo. | 634 | width = std::min(width, for_geo.width); // launcher width is taken into account in for_geo. |
3456 | @@ -715,7 +690,7 @@ | |||
3457 | 715 | 690 | ||
3458 | 716 | graphics_engine.PushClippingRectangle(geo_split_clip); | 691 | graphics_engine.PushClippingRectangle(geo_split_clip); |
3459 | 717 | 692 | ||
3461 | 718 | if (preview_lens_view_.IsValid()) | 693 | if (preview_scope_view_.IsValid()) |
3462 | 719 | { | 694 | { |
3463 | 720 | DrawPreviewResultTextures(graphics_engine, force_draw); | 695 | DrawPreviewResultTextures(graphics_engine, force_draw); |
3464 | 721 | } | 696 | } |
3465 | @@ -762,29 +737,29 @@ | |||
3466 | 762 | texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); | 737 | texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); |
3467 | 763 | texxform.FlipVCoord(true); | 738 | texxform.FlipVCoord(true); |
3468 | 764 | 739 | ||
3472 | 765 | // Lens Bar | 740 | // Scope Bar |
3473 | 766 | texxform.uoffset = (lens_bar_->GetX() - content_view_->GetX())/(float)content_view_->GetWidth(); | 741 | texxform.uoffset = (scope_bar_->GetX() - content_view_->GetX())/(float)content_view_->GetWidth(); |
3474 | 767 | texxform.voffset = (lens_bar_->GetY() - content_view_->GetY())/(float)content_view_->GetHeight(); | 742 | texxform.voffset = (scope_bar_->GetY() - content_view_->GetY())/(float)content_view_->GetHeight(); |
3475 | 768 | 743 | ||
3477 | 769 | int start_y = lens_bar_->GetY(); | 744 | int start_y = scope_bar_->GetY(); |
3478 | 770 | int final_y = geo_layout.y + geo_layout.height + PREVIEW_ICON_SPLIT_OFFSCREEN_OFFSET; | 745 | int final_y = geo_layout.y + geo_layout.height + PREVIEW_ICON_SPLIT_OFFSCREEN_OFFSET; |
3479 | 771 | 746 | ||
3481 | 772 | int lens_y = (1.0f - animate_split_value_) * start_y + (animate_split_value_ * final_y); | 747 | int scope_y = (1.0f - animate_split_value_) * start_y + (animate_split_value_ * final_y); |
3482 | 773 | 748 | ||
3483 | 774 | graphics_engine.QRP_1Tex | 749 | graphics_engine.QRP_1Tex |
3484 | 775 | ( | 750 | ( |
3489 | 776 | lens_bar_->GetX(), | 751 | scope_bar_->GetX(), |
3490 | 777 | lens_y, | 752 | scope_y, |
3491 | 778 | lens_bar_->GetWidth(), | 753 | scope_bar_->GetWidth(), |
3492 | 779 | lens_bar_->GetHeight(), | 754 | scope_bar_->GetHeight(), |
3493 | 780 | content_view_->BackupTexture(), | 755 | content_view_->BackupTexture(), |
3494 | 781 | texxform, | 756 | texxform, |
3495 | 782 | nux::Color((1.0-animate_split_value_), (1.0-animate_split_value_), (1.0-animate_split_value_), (1.0-animate_split_value_)) | 757 | nux::Color((1.0-animate_split_value_), (1.0-animate_split_value_), (1.0-animate_split_value_), (1.0-animate_split_value_)) |
3496 | 783 | ); | 758 | ); |
3497 | 784 | 759 | ||
3499 | 785 | split_clip.height = std::min(lens_y, geo_layout.height); | 760 | split_clip.height = std::min(scope_y, geo_layout.height); |
3500 | 786 | 761 | ||
3502 | 787 | if (active_lens_view_ && active_lens_view_->GetPushedFilterExpansion()) | 762 | if (active_scope_view_ && active_scope_view_->GetPushedFilterExpansion()) |
3503 | 788 | { | 763 | { |
3504 | 789 | // Search Bar | 764 | // Search Bar |
3505 | 790 | texxform.uoffset = (search_bar_->GetX() - content_view_->GetX())/(float)content_view_->GetWidth(); | 765 | texxform.uoffset = (search_bar_->GetX() - content_view_->GetX())/(float)content_view_->GetWidth(); |
3506 | @@ -797,7 +772,7 @@ | |||
3507 | 797 | ( | 772 | ( |
3508 | 798 | search_bar_->GetX(), | 773 | search_bar_->GetX(), |
3509 | 799 | (1.0f - animate_split_value_) * start_y + (animate_split_value_ * final_y), | 774 | (1.0f - animate_split_value_) * start_y + (animate_split_value_ * final_y), |
3511 | 800 | search_bar_->GetWidth() - active_lens_view_->filter_bar()->GetWidth(), | 775 | search_bar_->GetWidth() - active_scope_view_->filter_bar()->GetWidth(), |
3512 | 801 | search_bar_->GetHeight(), | 776 | search_bar_->GetHeight(), |
3513 | 802 | content_view_->BackupTexture(), | 777 | content_view_->BackupTexture(), |
3514 | 803 | texxform, | 778 | texxform, |
3515 | @@ -805,10 +780,10 @@ | |||
3516 | 805 | ); | 780 | ); |
3517 | 806 | 781 | ||
3518 | 807 | // Filter Bar | 782 | // Filter Bar |
3520 | 808 | texxform.uoffset = (active_lens_view_->filter_bar()->GetX() -content_view_->GetX())/(float)content_view_->GetWidth(); | 783 | texxform.uoffset = (active_scope_view_->filter_bar()->GetX() -content_view_->GetX())/(float)content_view_->GetWidth(); |
3521 | 809 | texxform.voffset = (search_bar_->GetY() - content_view_->GetY())/(float)content_view_->GetHeight(); | 784 | texxform.voffset = (search_bar_->GetY() - content_view_->GetY())/(float)content_view_->GetHeight(); |
3522 | 810 | 785 | ||
3524 | 811 | int start_x = active_lens_view_->filter_bar()->GetX(); | 786 | int start_x = active_scope_view_->filter_bar()->GetX(); |
3525 | 812 | int final_x = content_view_->GetX() + content_view_->GetWidth() + PREVIEW_ICON_SPLIT_OFFSCREEN_OFFSET; | 787 | int final_x = content_view_->GetX() + content_view_->GetWidth() + PREVIEW_ICON_SPLIT_OFFSCREEN_OFFSET; |
3526 | 813 | 788 | ||
3527 | 814 | int filter_x = (1.0f - animate_split_value_) * start_x + (animate_split_value_ * final_x); | 789 | int filter_x = (1.0f - animate_split_value_) * start_x + (animate_split_value_ * final_x); |
3528 | @@ -817,8 +792,8 @@ | |||
3529 | 817 | ( | 792 | ( |
3530 | 818 | filter_x, | 793 | filter_x, |
3531 | 819 | search_bar_->GetY(), | 794 | search_bar_->GetY(), |
3534 | 820 | active_lens_view_->filter_bar()->GetWidth(), | 795 | active_scope_view_->filter_bar()->GetWidth(), |
3535 | 821 | active_lens_view_->filter_bar()->GetY() + active_lens_view_->filter_bar()->GetHeight(), | 796 | active_scope_view_->filter_bar()->GetY() + active_scope_view_->filter_bar()->GetHeight(), |
3536 | 822 | content_view_->BackupTexture(), | 797 | content_view_->BackupTexture(), |
3537 | 823 | texxform, | 798 | texxform, |
3538 | 824 | nux::Color((1.0-animate_split_value_), (1.0-animate_split_value_), (1.0-animate_split_value_), (1.0-animate_split_value_)) | 799 | nux::Color((1.0-animate_split_value_), (1.0-animate_split_value_), (1.0-animate_split_value_), (1.0-animate_split_value_)) |
3539 | @@ -935,7 +910,7 @@ | |||
3540 | 935 | texxform.voffset = 0.0f; | 910 | texxform.voffset = 0.0f; |
3541 | 936 | texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); | 911 | texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); |
3542 | 937 | 912 | ||
3544 | 938 | std::vector<ResultViewTexture::Ptr> result_textures = preview_lens_view_->GetResultTextureContainers(); | 913 | std::vector<ResultViewTexture::Ptr> result_textures = preview_scope_view_->GetResultTextureContainers(); |
3545 | 939 | std::vector<ResultViewTexture::Ptr> top_textures; | 914 | std::vector<ResultViewTexture::Ptr> top_textures; |
3546 | 940 | 915 | ||
3547 | 941 | int height_concat_below = 0; | 916 | int height_concat_below = 0; |
3548 | @@ -973,7 +948,7 @@ | |||
3549 | 973 | // off the bottom | 948 | // off the bottom |
3550 | 974 | if (geo_tex_top.y <= geo_layout.y + geo_layout.height) | 949 | if (geo_tex_top.y <= geo_layout.y + geo_layout.height) |
3551 | 975 | { | 950 | { |
3553 | 976 | preview_lens_view_->RenderResultTexture(result_texture); | 951 | preview_scope_view_->RenderResultTexture(result_texture); |
3554 | 977 | // If we haven't got it now, we're not going to get it | 952 | // If we haven't got it now, we're not going to get it |
3555 | 978 | if (!result_texture->texture.IsValid()) | 953 | if (!result_texture->texture.IsValid()) |
3556 | 979 | continue; | 954 | continue; |
3557 | @@ -1014,7 +989,7 @@ | |||
3558 | 1014 | // off the top | 989 | // off the top |
3559 | 1015 | if (geo_tex_top.y + geo_tex_top.height >= geo_layout.y) | 990 | if (geo_tex_top.y + geo_tex_top.height >= geo_layout.y) |
3560 | 1016 | { | 991 | { |
3562 | 1017 | preview_lens_view_->RenderResultTexture(result_texture); | 992 | preview_scope_view_->RenderResultTexture(result_texture); |
3563 | 1018 | // If we haven't got it now, we're not going to get it | 993 | // If we haven't got it now, we're not going to get it |
3564 | 1019 | if (!result_texture->texture.IsValid()) | 994 | if (!result_texture->texture.IsValid()) |
3565 | 1020 | continue; | 995 | continue; |
3566 | @@ -1106,11 +1081,11 @@ | |||
3567 | 1106 | { | 1081 | { |
3568 | 1107 | glib::String uri; | 1082 | glib::String uri; |
3569 | 1108 | glib::String search_string; | 1083 | glib::String search_string; |
3571 | 1109 | dash::HandledType handled_type; | 1084 | ScopeHandledType handled_type; |
3572 | 1110 | 1085 | ||
3573 | 1111 | g_variant_get(args, "(sus)", &uri, &handled_type, &search_string); | 1086 | g_variant_get(args, "(sus)", &uri, &handled_type, &search_string); |
3574 | 1112 | 1087 | ||
3576 | 1113 | std::string id(AnalyseLensURI(uri.Str())); | 1088 | std::string id(AnalyseScopeURI(uri.Str())); |
3577 | 1114 | 1089 | ||
3578 | 1115 | // we got an activation request, we should probably close the preview | 1090 | // we got an activation request, we should probably close the preview |
3579 | 1116 | if (preview_displaying_) | 1091 | if (preview_displaying_) |
3580 | @@ -1120,43 +1095,43 @@ | |||
3581 | 1120 | 1095 | ||
3582 | 1121 | if (!visible_) | 1096 | if (!visible_) |
3583 | 1122 | { | 1097 | { |
3585 | 1123 | lens_bar_->Activate(id); | 1098 | scope_bar_->Activate(id); |
3586 | 1124 | ubus_manager_.SendMessage(UBUS_DASH_EXTERNAL_ACTIVATION); | 1099 | ubus_manager_.SendMessage(UBUS_DASH_EXTERNAL_ACTIVATION); |
3587 | 1125 | } | 1100 | } |
3589 | 1126 | else if (/* visible_ && */ handled_type == NOT_HANDLED) | 1101 | else if (/* visible_ && */ handled_type == ScopeHandledType::NOT_HANDLED) |
3590 | 1127 | { | 1102 | { |
3591 | 1128 | ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST, NULL, | 1103 | ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST, NULL, |
3592 | 1129 | glib::Source::Priority::HIGH); | 1104 | glib::Source::Priority::HIGH); |
3593 | 1130 | } | 1105 | } |
3595 | 1131 | else if (/* visible_ && */ handled_type == GOTO_DASH_URI) | 1106 | else if (/* visible_ && */ handled_type == ScopeHandledType::GOTO_DASH_URI) |
3596 | 1132 | { | 1107 | { |
3598 | 1133 | lens_bar_->Activate(id); | 1108 | scope_bar_->Activate(id); |
3599 | 1134 | } | 1109 | } |
3600 | 1135 | } | 1110 | } |
3601 | 1136 | 1111 | ||
3603 | 1137 | std::string DashView::AnalyseLensURI(std::string const& uri) | 1112 | std::string DashView::AnalyseScopeURI(std::string const& uri) |
3604 | 1138 | { | 1113 | { |
3606 | 1139 | impl::LensFilter filter = impl::parse_lens_uri(uri); | 1114 | impl::ScopeFilter filter = impl::parse_scope_uri(uri); |
3607 | 1140 | 1115 | ||
3608 | 1141 | if (!filter.filters.empty()) | 1116 | if (!filter.filters.empty()) |
3609 | 1142 | { | 1117 | { |
3612 | 1143 | lens_views_[filter.id]->filters_expanded = true; | 1118 | scope_views_[filter.id]->filters_expanded = true; |
3613 | 1144 | // update the lens for each filter | 1119 | // update the scope for each filter |
3614 | 1145 | for (auto p : filter.filters) { | 1120 | for (auto p : filter.filters) { |
3616 | 1146 | UpdateLensFilter(filter.id, p.first, p.second); | 1121 | UpdateScopeFilter(filter.id, p.first, p.second); |
3617 | 1147 | } | 1122 | } |
3618 | 1148 | } | 1123 | } |
3619 | 1149 | 1124 | ||
3620 | 1150 | return filter.id; | 1125 | return filter.id; |
3621 | 1151 | } | 1126 | } |
3622 | 1152 | 1127 | ||
3624 | 1153 | void DashView::UpdateLensFilter(std::string lens_id, std::string filter_name, std::string value) | 1128 | void DashView::UpdateScopeFilter(std::string scope_id, std::string filter_name, std::string value) |
3625 | 1154 | { | 1129 | { |
3627 | 1155 | if (lenses_.GetLens(lens_id)) | 1130 | if (scopes_ && scopes_->GetScope(scope_id)) |
3628 | 1156 | { | 1131 | { |
3630 | 1157 | Lens::Ptr lens = lenses_.GetLens(lens_id); | 1132 | Scope::Ptr scope = scopes_->GetScope(scope_id); |
3631 | 1158 | 1133 | ||
3633 | 1159 | Filters::Ptr filters = lens->filters; | 1134 | Filters::Ptr filters = scope->filters; |
3634 | 1160 | 1135 | ||
3635 | 1161 | for (unsigned int i = 0; i < filters->count(); ++i) | 1136 | for (unsigned int i = 0; i < filters->count(); ++i) |
3636 | 1162 | { | 1137 | { |
3637 | @@ -1164,13 +1139,13 @@ | |||
3638 | 1164 | 1139 | ||
3639 | 1165 | if (filter->id() == filter_name) | 1140 | if (filter->id() == filter_name) |
3640 | 1166 | { | 1141 | { |
3642 | 1167 | UpdateLensFilterValue(filter, value); | 1142 | UpdateScopeFilterValue(filter, value); |
3643 | 1168 | } | 1143 | } |
3644 | 1169 | } | 1144 | } |
3645 | 1170 | } | 1145 | } |
3646 | 1171 | } | 1146 | } |
3647 | 1172 | 1147 | ||
3649 | 1173 | void DashView::UpdateLensFilterValue(Filter::Ptr filter, std::string value) | 1148 | void DashView::UpdateScopeFilterValue(Filter::Ptr filter, std::string value) |
3650 | 1174 | { | 1149 | { |
3651 | 1175 | if (filter->renderer_name == "filter-radiooption") | 1150 | if (filter->renderer_name == "filter-radiooption") |
3652 | 1176 | { | 1151 | { |
3653 | @@ -1186,7 +1161,7 @@ | |||
3654 | 1186 | void DashView::OnSearchChanged(std::string const& search_string) | 1161 | void DashView::OnSearchChanged(std::string const& search_string) |
3655 | 1187 | { | 1162 | { |
3656 | 1188 | LOG_DEBUG(logger) << "Search changed: " << search_string; | 1163 | LOG_DEBUG(logger) << "Search changed: " << search_string; |
3658 | 1189 | if (active_lens_view_) | 1164 | if (active_scope_view_) |
3659 | 1190 | { | 1165 | { |
3660 | 1191 | search_in_progress_ = true; | 1166 | search_in_progress_ = true; |
3661 | 1192 | // it isn't guaranteed that we get a SearchFinished signal, so we need | 1167 | // it isn't guaranteed that we get a SearchFinished signal, so we need |
3662 | @@ -1201,7 +1176,7 @@ | |||
3663 | 1201 | 1176 | ||
3664 | 1202 | // 150ms to hide the no reults message if its take a while to return results | 1177 | // 150ms to hide the no reults message if its take a while to return results |
3665 | 1203 | hide_message_delay_.reset(new glib::Timeout(150, [&] () { | 1178 | hide_message_delay_.reset(new glib::Timeout(150, [&] () { |
3667 | 1204 | active_lens_view_->HideResultsMessage(); | 1179 | active_scope_view_->HideResultsMessage(); |
3668 | 1205 | return false; | 1180 | return false; |
3669 | 1206 | })); | 1181 | })); |
3670 | 1207 | } | 1182 | } |
3671 | @@ -1210,67 +1185,63 @@ | |||
3672 | 1210 | void DashView::OnLiveSearchReached(std::string const& search_string) | 1185 | void DashView::OnLiveSearchReached(std::string const& search_string) |
3673 | 1211 | { | 1186 | { |
3674 | 1212 | LOG_DEBUG(logger) << "Live search reached: " << search_string; | 1187 | LOG_DEBUG(logger) << "Live search reached: " << search_string; |
3676 | 1213 | if (active_lens_view_) | 1188 | if (active_scope_view_) |
3677 | 1214 | { | 1189 | { |
3679 | 1215 | active_lens_view_->PerformSearch(search_string, | 1190 | active_scope_view_->PerformSearch(search_string, |
3680 | 1216 | sigc::mem_fun(this, &DashView::OnSearchFinished)); | 1191 | sigc::mem_fun(this, &DashView::OnSearchFinished)); |
3681 | 1217 | } | 1192 | } |
3682 | 1218 | } | 1193 | } |
3683 | 1219 | 1194 | ||
3685 | 1220 | void DashView::OnLensAdded(Lens::Ptr& lens) | 1195 | void DashView::OnScopeAdded(Scope::Ptr const& scope, int position) |
3686 | 1221 | { | 1196 | { |
3691 | 1222 | std::string id = lens->id; | 1197 | LOG_DEBUG(logger) << "Scope Added: " << scope->id(); |
3692 | 1223 | lens_bar_->AddLens(lens); | 1198 | |
3693 | 1224 | 1199 | std::string id = scope->id; | |
3694 | 1225 | nux::ObjectPtr<LensView> view(new LensView(lens, search_bar_->show_filters())); | 1200 | scope_bar_->AddScope(scope); |
3695 | 1201 | |||
3696 | 1202 | nux::ObjectPtr<ScopeView> view(new ScopeView(scope, search_bar_->show_filters())); | ||
3697 | 1226 | AddChild(view.GetPointer()); | 1203 | AddChild(view.GetPointer()); |
3698 | 1227 | view->SetVisible(false); | 1204 | view->SetVisible(false); |
3699 | 1228 | view->uri_activated.connect(sigc::mem_fun(this, &DashView::OnUriActivated)); | 1205 | view->uri_activated.connect(sigc::mem_fun(this, &DashView::OnUriActivated)); |
3700 | 1229 | 1206 | ||
3703 | 1230 | lenses_layout_->AddView(view.GetPointer(), 1); | 1207 | scopes_layout_->AddView(view.GetPointer(), 1); |
3704 | 1231 | lens_views_[lens->id] = view; | 1208 | scope_views_[scope->id] = view; |
3705 | 1232 | 1209 | ||
3718 | 1233 | lens->activated.connect(sigc::mem_fun(this, &DashView::OnUriActivatedReply)); | 1210 | scope->activated.connect(sigc::mem_fun(this, &DashView::OnUriActivatedReply)); |
3719 | 1234 | lens->connected.changed.connect([&] (bool value) | 1211 | scope->connected.changed.connect([&] (bool value) { }); |
3708 | 1235 | { | ||
3709 | 1236 | std::string const& search_string = search_bar_->search_string; | ||
3710 | 1237 | if (value && lens->search_in_global && active_lens_view_ == home_view_ | ||
3711 | 1238 | && !search_string.empty()) | ||
3712 | 1239 | { | ||
3713 | 1240 | // force a (global!) search with the correct string | ||
3714 | 1241 | lens->GlobalSearch(search_bar_->search_string, | ||
3715 | 1242 | sigc::mem_fun(this, &DashView::OnSearchFinished)); | ||
3716 | 1243 | } | ||
3717 | 1244 | }); | ||
3720 | 1245 | 1212 | ||
3721 | 1246 | // Hook up to the new preview infrastructure | 1213 | // Hook up to the new preview infrastructure |
3723 | 1247 | lens->preview_ready.connect([&] (std::string const& uri, Preview::Ptr model) | 1214 | scope->preview_ready.connect([&] (std::string const& uri, Preview::Ptr model) |
3724 | 1248 | { | 1215 | { |
3725 | 1249 | LOG_DEBUG(logger) << "Got preview for: " << uri; | 1216 | LOG_DEBUG(logger) << "Got preview for: " << uri; |
3726 | 1250 | preview_state_machine_.ActivatePreview(model); // this does not immediately display a preview - we now wait. | 1217 | preview_state_machine_.ActivatePreview(model); // this does not immediately display a preview - we now wait. |
3727 | 1251 | }); | 1218 | }); |
3728 | 1219 | |||
3729 | 1220 | if (!active_scope_view_) | ||
3730 | 1221 | OnScopeBarActivated(scope->id()); | ||
3731 | 1252 | } | 1222 | } |
3732 | 1253 | 1223 | ||
3734 | 1254 | void DashView::OnLensBarActivated(std::string const& id) | 1224 | void DashView::OnScopeBarActivated(std::string const& id) |
3735 | 1255 | { | 1225 | { |
3737 | 1256 | if (lens_views_.find(id) == lens_views_.end()) | 1226 | if (scope_views_.find(id) == scope_views_.end()) |
3738 | 1257 | { | 1227 | { |
3740 | 1258 | LOG_WARN(logger) << "Unable to find Lens " << id; | 1228 | LOG_WARN(logger) << "Unable to find Scope " << id; |
3741 | 1259 | return; | 1229 | return; |
3742 | 1260 | } | 1230 | } |
3743 | 1261 | 1231 | ||
3746 | 1262 | if (active_lens_view_.IsValid()) | 1232 | if (active_scope_view_.IsValid()) |
3747 | 1263 | active_lens_view_->SetVisible(false); | 1233 | active_scope_view_->SetVisible(false); |
3748 | 1234 | scope_can_refine_connection_.disconnect(); | ||
3749 | 1264 | 1235 | ||
3751 | 1265 | nux::ObjectPtr<LensView> view = active_lens_view_ = lens_views_[id]; | 1236 | nux::ObjectPtr<ScopeView> view = active_scope_view_ = scope_views_[id]; |
3752 | 1266 | 1237 | ||
3753 | 1267 | view->SetVisible(true); | 1238 | view->SetVisible(true); |
3754 | 1268 | view->AboutToShow(); | 1239 | view->AboutToShow(); |
3755 | 1269 | 1240 | ||
3757 | 1270 | for (auto it: lens_views_) | 1241 | for (auto it: scope_views_) |
3758 | 1271 | { | 1242 | { |
3759 | 1272 | bool id_matches = it.first == id; | 1243 | bool id_matches = it.first == id; |
3761 | 1273 | ViewType view_type = id_matches ? LENS_VIEW : (view == home_view_ ? HOME_VIEW : HIDDEN); | 1244 | ScopeViewType view_type = id_matches ? ScopeViewType::SCOPE_VIEW : ScopeViewType::HIDDEN; |
3762 | 1274 | it.second->SetVisible(id_matches); | 1245 | it.second->SetVisible(id_matches); |
3763 | 1275 | it.second->view_type = view_type; | 1246 | it.second->view_type = view_type; |
3764 | 1276 | 1247 | ||
3765 | @@ -1281,8 +1252,8 @@ | |||
3766 | 1281 | search_bar_->SetVisible(true); | 1252 | search_bar_->SetVisible(true); |
3767 | 1282 | QueueRelayout(); | 1253 | QueueRelayout(); |
3768 | 1283 | search_bar_->search_string = view->search_string; | 1254 | search_bar_->search_string = view->search_string; |
3771 | 1284 | search_bar_->search_hint = view->lens()->search_hint; | 1255 | search_bar_->search_hint = view->scope()->search_hint; |
3772 | 1285 | // lenses typically return immediately from Search() if the search query | 1256 | // scopes typically return immediately from Search() if the search query |
3773 | 1286 | // doesn't change, so SearchFinished will be called in a few ms | 1257 | // doesn't change, so SearchFinished will be called in a few ms |
3774 | 1287 | // FIXME: if we're forcing a search here, why don't we get rid of view types? | 1258 | // FIXME: if we're forcing a search here, why don't we get rid of view types? |
3775 | 1288 | search_bar_->ForceSearchChanged(); | 1259 | search_bar_->ForceSearchChanged(); |
3776 | @@ -1294,23 +1265,26 @@ | |||
3777 | 1294 | 1265 | ||
3778 | 1295 | search_bar_->text_entry()->SelectAll(); | 1266 | search_bar_->text_entry()->SelectAll(); |
3779 | 1296 | search_bar_->can_refine_search = view->can_refine_search(); | 1267 | search_bar_->can_refine_search = view->can_refine_search(); |
3780 | 1268 | scope_can_refine_connection_ = view->can_refine_search.changed.connect([this] (bool can_refine_search) { | ||
3781 | 1269 | search_bar_->can_refine_search = can_refine_search; | ||
3782 | 1270 | }); | ||
3783 | 1297 | hide_message_delay_.reset(); | 1271 | hide_message_delay_.reset(); |
3784 | 1298 | 1272 | ||
3785 | 1299 | view->QueueDraw(); | 1273 | view->QueueDraw(); |
3786 | 1300 | QueueDraw(); | 1274 | QueueDraw(); |
3787 | 1301 | } | 1275 | } |
3788 | 1302 | 1276 | ||
3790 | 1303 | void DashView::OnSearchFinished(Lens::Hints const& hints, glib::Error const& err) | 1277 | void DashView::OnSearchFinished(glib::HintsMap const& hints, glib::Error const& err) |
3791 | 1304 | { | 1278 | { |
3792 | 1305 | hide_message_delay_.reset(); | 1279 | hide_message_delay_.reset(); |
3793 | 1306 | 1280 | ||
3795 | 1307 | if (!active_lens_view_.IsValid()) return; | 1281 | if (!active_scope_view_.IsValid()) return; |
3796 | 1308 | 1282 | ||
3799 | 1309 | // FIXME: bind the lens_view in PerformSearch | 1283 | // FIXME: bind the scope_view in PerformSearch |
3800 | 1310 | active_lens_view_->CheckNoResults(hints); | 1284 | active_scope_view_->CheckNoResults(hints); |
3801 | 1311 | std::string const& search_string = search_bar_->search_string; | 1285 | std::string const& search_string = search_bar_->search_string; |
3802 | 1312 | 1286 | ||
3804 | 1313 | if (active_lens_view_->search_string == search_string) | 1287 | if (active_scope_view_->search_string == search_string) |
3805 | 1314 | { | 1288 | { |
3806 | 1315 | search_bar_->SearchFinished(); | 1289 | search_bar_->SearchFinished(); |
3807 | 1316 | search_in_progress_ = false; | 1290 | search_in_progress_ = false; |
3808 | @@ -1319,29 +1293,7 @@ | |||
3809 | 1319 | } | 1293 | } |
3810 | 1320 | } | 1294 | } |
3811 | 1321 | 1295 | ||
3835 | 1322 | void DashView::OnGlobalSearchFinished(Lens::Hints const& hints, glib::Error const& error) | 1296 | void DashView::OnUriActivatedReply(std::string const& uri, ScopeHandledType type, glib::HintsMap const&) |
3813 | 1323 | { | ||
3814 | 1324 | if (active_lens_view_ == home_view_) | ||
3815 | 1325 | OnSearchFinished(hints, error); | ||
3816 | 1326 | } | ||
3817 | 1327 | |||
3818 | 1328 | void DashView::OnAppsGlobalSearchFinished(Lens::Ptr const& lens) | ||
3819 | 1329 | { | ||
3820 | 1330 | if (active_lens_view_ == home_view_ && lens->id() == "applications.lens") | ||
3821 | 1331 | { | ||
3822 | 1332 | /* HACKITY HACK! We're resetting the state of search_in_progress when | ||
3823 | 1333 | * doing searches in the home lens and we get results from apps lens. | ||
3824 | 1334 | * This way typing a search query and pressing enter immediately will | ||
3825 | 1335 | * wait for the apps lens results and will run correct application. | ||
3826 | 1336 | * See lp:966417 and lp:856206 for more info about why we do this. | ||
3827 | 1337 | */ | ||
3828 | 1338 | search_in_progress_ = false; | ||
3829 | 1339 | if (activate_on_finish_) | ||
3830 | 1340 | this->OnEntryActivated(); | ||
3831 | 1341 | } | ||
3832 | 1342 | } | ||
3833 | 1343 | |||
3834 | 1344 | void DashView::OnUriActivatedReply(std::string const& uri, HandledType type, Lens::Hints const&) | ||
3836 | 1345 | { | 1297 | { |
3837 | 1346 | // We don't want to close the dash if there was another activation pending | 1298 | // We don't want to close the dash if there was another activation pending |
3838 | 1347 | if (type == NOT_HANDLED) | 1299 | if (type == NOT_HANDLED) |
3839 | @@ -1362,11 +1314,11 @@ | |||
3840 | 1362 | size_t pos = fake_uri.find(":"); | 1314 | size_t pos = fake_uri.find(":"); |
3841 | 1363 | std::string uri = fake_uri.substr(++pos); | 1315 | std::string uri = fake_uri.substr(++pos); |
3842 | 1364 | 1316 | ||
3843 | 1365 | LOG_DEBUG(logger) << "Fallback activating " << uri; | ||
3844 | 1366 | |||
3845 | 1367 | if (g_str_has_prefix(uri.c_str(), "application://")) | 1317 | if (g_str_has_prefix(uri.c_str(), "application://")) |
3846 | 1368 | { | 1318 | { |
3847 | 1369 | std::string appname = uri.substr(14); | 1319 | std::string appname = uri.substr(14); |
3848 | 1320 | |||
3849 | 1321 | printf("Actrivating app: %s", appname.c_str()); | ||
3850 | 1370 | return LaunchApp(appname); | 1322 | return LaunchApp(appname); |
3851 | 1371 | } | 1323 | } |
3852 | 1372 | else if (g_str_has_prefix(uri.c_str(), "unity-runner://")) | 1324 | else if (g_str_has_prefix(uri.c_str(), "unity-runner://")) |
3853 | @@ -1436,9 +1388,9 @@ | |||
3854 | 1436 | } | 1388 | } |
3855 | 1437 | void DashView::OnEntryActivated() | 1389 | void DashView::OnEntryActivated() |
3856 | 1438 | { | 1390 | { |
3858 | 1439 | if (active_lens_view_.IsValid() && !search_in_progress_) | 1391 | if (active_scope_view_.IsValid() && !search_in_progress_) |
3859 | 1440 | { | 1392 | { |
3861 | 1441 | active_lens_view_->ActivateFirst(); | 1393 | active_scope_view_->ActivateFirst(); |
3862 | 1442 | } | 1394 | } |
3863 | 1443 | // delay the activation until we get the SearchFinished signal | 1395 | // delay the activation until we get the SearchFinished signal |
3864 | 1444 | activate_on_finish_ = search_in_progress_; | 1396 | activate_on_finish_ = search_in_progress_; |
3865 | @@ -1452,9 +1404,9 @@ | |||
3866 | 1452 | 1404 | ||
3867 | 1453 | std::string const DashView::GetIdForShortcutActivation(std::string const& shortcut) const | 1405 | std::string const DashView::GetIdForShortcutActivation(std::string const& shortcut) const |
3868 | 1454 | { | 1406 | { |
3872 | 1455 | Lens::Ptr lens = lenses_.GetLensForShortcut(shortcut); | 1407 | Scope::Ptr scope = scopes_ ? scopes_->GetScopeForShortcut(shortcut) : Scope::Ptr(); |
3873 | 1456 | if (lens) | 1408 | if (scope) |
3874 | 1457 | return lens->id; | 1409 | return scope->id; |
3875 | 1458 | return ""; | 1410 | return ""; |
3876 | 1459 | } | 1411 | } |
3877 | 1460 | 1412 | ||
3878 | @@ -1462,11 +1414,14 @@ | |||
3879 | 1462 | { | 1414 | { |
3880 | 1463 | std::vector<char> result; | 1415 | std::vector<char> result; |
3881 | 1464 | 1416 | ||
3883 | 1465 | for (Lens::Ptr lens: lenses_.GetLenses()) | 1417 | if (scopes_) |
3884 | 1466 | { | 1418 | { |
3888 | 1467 | std::string shortcut = lens->shortcut; | 1419 | for (Scope::Ptr scope: scopes_->GetScopes()) |
3889 | 1468 | if(shortcut.size() > 0) | 1420 | { |
3890 | 1469 | result.push_back(shortcut.at(0)); | 1421 | std::string shortcut = scope->shortcut; |
3891 | 1422 | if(shortcut.size() > 0) | ||
3892 | 1423 | result.push_back(shortcut.at(0)); | ||
3893 | 1424 | } | ||
3894 | 1470 | } | 1425 | } |
3895 | 1471 | return result; | 1426 | return result; |
3896 | 1472 | } | 1427 | } |
3897 | @@ -1505,8 +1460,8 @@ | |||
3898 | 1505 | dash::Style& style = dash::Style::Instance(); | 1460 | dash::Style& style = dash::Style::Instance(); |
3899 | 1506 | int num_rows = 1; // The search bar | 1461 | int num_rows = 1; // The search bar |
3900 | 1507 | 1462 | ||
3903 | 1508 | if (active_lens_view_.IsValid()) | 1463 | if (active_scope_view_.IsValid()) |
3904 | 1509 | num_rows += active_lens_view_->GetNumRows(); | 1464 | num_rows += active_scope_view_->GetNumRows(); |
3905 | 1510 | 1465 | ||
3906 | 1511 | std::string form_factor("unknown"); | 1466 | std::string form_factor("unknown"); |
3907 | 1512 | 1467 | ||
3908 | @@ -1533,17 +1488,17 @@ | |||
3909 | 1533 | { | 1488 | { |
3910 | 1534 | return preview_container_->KeyNavIteration(direction); | 1489 | return preview_container_->KeyNavIteration(direction); |
3911 | 1535 | } | 1490 | } |
3913 | 1536 | else if (direction == nux::KEY_NAV_DOWN && search_bar_ && active_lens_view_.IsValid()) | 1491 | else if (direction == nux::KEY_NAV_DOWN && search_bar_ && active_scope_view_.IsValid()) |
3914 | 1537 | { | 1492 | { |
3915 | 1538 | auto show_filters = search_bar_->show_filters(); | 1493 | auto show_filters = search_bar_->show_filters(); |
3917 | 1539 | auto fscroll_view = active_lens_view_->fscroll_view(); | 1494 | auto fscroll_view = active_scope_view_->fscroll_view(); |
3918 | 1540 | 1495 | ||
3919 | 1541 | if (show_filters && show_filters->HasKeyFocus()) | 1496 | if (show_filters && show_filters->HasKeyFocus()) |
3920 | 1542 | { | 1497 | { |
3921 | 1543 | if (fscroll_view->IsVisible() && fscroll_view) | 1498 | if (fscroll_view->IsVisible() && fscroll_view) |
3922 | 1544 | return fscroll_view->KeyNavIteration(direction); | 1499 | return fscroll_view->KeyNavIteration(direction); |
3923 | 1545 | else | 1500 | else |
3925 | 1546 | return active_lens_view_->KeyNavIteration(direction); | 1501 | return active_scope_view_->KeyNavIteration(direction); |
3926 | 1547 | } | 1502 | } |
3927 | 1548 | } | 1503 | } |
3928 | 1549 | return this; | 1504 | return this; |
3929 | @@ -1621,9 +1576,9 @@ | |||
3930 | 1621 | if (direction != KEY_NAV_NONE && key_symbol == nux::NUX_KEYDOWN && !search_bar_->im_preedit) | 1576 | if (direction != KEY_NAV_NONE && key_symbol == nux::NUX_KEYDOWN && !search_bar_->im_preedit) |
3931 | 1622 | { | 1577 | { |
3932 | 1623 | std::list<nux::Area*> tabs; | 1578 | std::list<nux::Area*> tabs; |
3934 | 1624 | if (active_lens_view_.IsValid()) | 1579 | if (active_scope_view_.IsValid()) |
3935 | 1625 | { | 1580 | { |
3937 | 1626 | for (auto category : active_lens_view_->categories()) | 1581 | for (auto category : active_scope_view_->categories()) |
3938 | 1627 | { | 1582 | { |
3939 | 1628 | if (category->IsVisible()) | 1583 | if (category->IsVisible()) |
3940 | 1629 | tabs.push_back(category); | 1584 | tabs.push_back(category); |
3941 | @@ -1636,11 +1591,11 @@ | |||
3942 | 1636 | tabs.push_back(search_bar_->show_filters()); | 1591 | tabs.push_back(search_bar_->show_filters()); |
3943 | 1637 | } | 1592 | } |
3944 | 1638 | 1593 | ||
3948 | 1639 | if (active_lens_view_.IsValid() && | 1594 | if (active_scope_view_.IsValid() && |
3949 | 1640 | active_lens_view_->filter_bar() && active_lens_view_->fscroll_view() && | 1595 | active_scope_view_->filter_bar() && active_scope_view_->fscroll_view() && |
3950 | 1641 | active_lens_view_->fscroll_view()->IsVisible()) | 1596 | active_scope_view_->fscroll_view()->IsVisible()) |
3951 | 1642 | { | 1597 | { |
3953 | 1643 | for (auto child : active_lens_view_->filter_bar()->GetLayout()->GetChildren()) | 1598 | for (auto child : active_scope_view_->filter_bar()->GetLayout()->GetChildren()) |
3954 | 1644 | { | 1599 | { |
3955 | 1645 | FilterExpanderLabel* filter = dynamic_cast<FilterExpanderLabel*>(child); | 1600 | FilterExpanderLabel* filter = dynamic_cast<FilterExpanderLabel*>(child); |
3956 | 1646 | if (filter) | 1601 | if (filter) |
3957 | @@ -1652,7 +1607,7 @@ | |||
3958 | 1652 | { | 1607 | { |
3959 | 1653 | if (ctrl) | 1608 | if (ctrl) |
3960 | 1654 | { | 1609 | { |
3962 | 1655 | lens_bar_->ActivatePrevious(); | 1610 | scope_bar_->ActivatePrevious(); |
3963 | 1656 | } | 1611 | } |
3964 | 1657 | else | 1612 | else |
3965 | 1658 | { | 1613 | { |
3966 | @@ -1679,7 +1634,7 @@ | |||
3967 | 1679 | { | 1634 | { |
3968 | 1680 | if (ctrl) | 1635 | if (ctrl) |
3969 | 1681 | { | 1636 | { |
3971 | 1682 | lens_bar_->ActivateNext(); | 1637 | scope_bar_->ActivateNext(); |
3972 | 1683 | } | 1638 | } |
3973 | 1684 | else | 1639 | else |
3974 | 1685 | { | 1640 | { |
3975 | 1686 | 1641 | ||
3976 | === modified file 'dash/DashView.h' | |||
3977 | --- dash/DashView.h 2013-01-28 23:57:38 +0000 | |||
3978 | +++ dash/DashView.h 2013-02-21 10:37:29 +0000 | |||
3979 | @@ -24,8 +24,7 @@ | |||
3980 | 24 | #include <Nux/View.h> | 24 | #include <Nux/View.h> |
3981 | 25 | #include <Nux/VLayout.h> | 25 | #include <Nux/VLayout.h> |
3982 | 26 | 26 | ||
3985 | 27 | #include <UnityCore/FilesystemLenses.h> | 27 | #include <UnityCore/Scopes.h> |
3984 | 28 | #include <UnityCore/HomeLens.h> | ||
3986 | 29 | #include <UnityCore/GLibSource.h> | 28 | #include <UnityCore/GLibSource.h> |
3987 | 30 | 29 | ||
3988 | 31 | #include "LensBar.h" | 30 | #include "LensBar.h" |
3989 | @@ -55,10 +54,12 @@ | |||
3990 | 55 | class DashView : public nux::View, public unity::debug::Introspectable | 54 | class DashView : public nux::View, public unity::debug::Introspectable |
3991 | 56 | { | 55 | { |
3992 | 57 | NUX_DECLARE_OBJECT_TYPE(DashView, nux::View); | 56 | NUX_DECLARE_OBJECT_TYPE(DashView, nux::View); |
3994 | 58 | typedef std::map<std::string, nux::ObjectPtr<LensView>> LensViews; | 57 | typedef std::map<std::string, nux::ObjectPtr<ScopeView>> ScopeViews; |
3995 | 59 | 58 | ||
3996 | 60 | public: | 59 | public: |
3998 | 61 | DashView(); | 60 | typedef std::function<void()> ScopesCreator; |
3999 | 61 | |||
4000 | 62 | DashView(ScopesCreator scopes_creator = nullptr); | ||
4001 | 62 | ~DashView(); | 63 | ~DashView(); |
4002 | 63 | 64 | ||
4003 | 64 | void AboutToShow(); | 65 | void AboutToShow(); |
4004 | @@ -108,20 +109,17 @@ | |||
4005 | 108 | void OnBackgroundColorChanged(GVariant* args); | 109 | void OnBackgroundColorChanged(GVariant* args); |
4006 | 109 | void OnSearchChanged(std::string const& search_string); | 110 | void OnSearchChanged(std::string const& search_string); |
4007 | 110 | void OnLiveSearchReached(std::string const& search_string); | 111 | void OnLiveSearchReached(std::string const& search_string); |
4013 | 111 | void OnLensAdded(Lens::Ptr& lens); | 112 | void OnScopeAdded(Scope::Ptr const& scope, int position); |
4014 | 112 | void OnLensBarActivated(std::string const& id); | 113 | void OnScopeBarActivated(std::string const& id); |
4015 | 113 | void OnSearchFinished(Lens::Hints const& hints, glib::Error const& error); | 114 | void OnSearchFinished(glib::HintsMap const& hints, glib::Error const& error); |
4011 | 114 | void OnGlobalSearchFinished(Lens::Hints const& hints, glib::Error const& error); | ||
4012 | 115 | void OnAppsGlobalSearchFinished(Lens::Ptr const& lens); | ||
4016 | 116 | void OnUriActivated(ResultView::ActivateType type, std::string const& uri, GVariant* data, std::string const& unique_id); | 115 | void OnUriActivated(ResultView::ActivateType type, std::string const& uri, GVariant* data, std::string const& unique_id); |
4018 | 117 | void OnUriActivatedReply(std::string const& uri, HandledType type, Lens::Hints const&); | 116 | void OnUriActivatedReply(std::string const& uri, ScopeHandledType type, glib::HintsMap const& hints); |
4019 | 118 | bool DoFallbackActivation(std::string const& uri); | 117 | bool DoFallbackActivation(std::string const& uri); |
4020 | 119 | bool LaunchApp(std::string const& appname); | 118 | bool LaunchApp(std::string const& appname); |
4021 | 120 | void OnEntryActivated(); | 119 | void OnEntryActivated(); |
4026 | 121 | std::string AnalyseLensURI(std::string const& uri); | 120 | std::string AnalyseScopeURI(std::string const& uri); |
4027 | 122 | void UpdateLensFilter(std::string lens, std::string filter, std::string value); | 121 | void UpdateScopeFilter(std::string scope_id, std::string filter, std::string value); |
4028 | 123 | void UpdateLensFilterValue(Filter::Ptr filter, std::string value); | 122 | void UpdateScopeFilterValue(Filter::Ptr filter, std::string value); |
4025 | 124 | void EnsureLensesInitialized(); | ||
4029 | 125 | 123 | ||
4030 | 126 | bool AcceptKeyNavFocus(); | 124 | bool AcceptKeyNavFocus(); |
4031 | 127 | bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character); | 125 | bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character); |
4032 | @@ -131,9 +129,8 @@ | |||
4033 | 131 | nux::Area* KeyNavIteration(nux::KeyNavDirection direction); | 129 | nux::Area* KeyNavIteration(nux::KeyNavDirection direction); |
4034 | 132 | 130 | ||
4035 | 133 | UBusManager ubus_manager_; | 131 | UBusManager ubus_manager_; |
4039 | 134 | FilesystemLenses lenses_; | 132 | Scopes::Ptr scopes_; |
4040 | 135 | HomeLens::Ptr home_lens_; | 133 | ScopeViews scope_views_; |
4038 | 136 | LensViews lens_views_; | ||
4041 | 137 | 134 | ||
4042 | 138 | // View related | 135 | // View related |
4043 | 139 | PreviewStateMachine preview_state_machine_; | 136 | PreviewStateMachine preview_state_machine_; |
4044 | @@ -147,12 +144,12 @@ | |||
4045 | 147 | nux::View* content_view_; | 144 | nux::View* content_view_; |
4046 | 148 | nux::HLayout* search_bar_layout_; | 145 | nux::HLayout* search_bar_layout_; |
4047 | 149 | SearchBar* search_bar_; | 146 | SearchBar* search_bar_; |
4050 | 150 | nux::VLayout* lenses_layout_; | 147 | nux::VLayout* scopes_layout_; |
4051 | 151 | LensBar* lens_bar_; | 148 | ScopeBar* scope_bar_; |
4052 | 152 | 149 | ||
4056 | 153 | nux::ObjectPtr<LensView> home_view_; | 150 | nux::ObjectPtr<ScopeView> active_scope_view_; |
4057 | 154 | nux::ObjectPtr<LensView> active_lens_view_; | 151 | nux::ObjectPtr<ScopeView> preview_scope_view_; |
4058 | 155 | nux::ObjectPtr<LensView> preview_lens_view_; | 152 | sigc::connection scope_can_refine_connection_; |
4059 | 156 | 153 | ||
4060 | 157 | // Drawing related | 154 | // Drawing related |
4061 | 158 | nux::Geometry content_geo_; | 155 | nux::Geometry content_geo_; |
4062 | @@ -165,6 +162,7 @@ | |||
4063 | 165 | 162 | ||
4064 | 166 | bool visible_; | 163 | bool visible_; |
4065 | 167 | 164 | ||
4066 | 165 | glib::Source::UniquePtr init_timeout_; | ||
4067 | 168 | glib::Source::UniquePtr searching_timeout_; | 166 | glib::Source::UniquePtr searching_timeout_; |
4068 | 169 | glib::Source::UniquePtr hide_message_delay_; | 167 | glib::Source::UniquePtr hide_message_delay_; |
4069 | 170 | 168 | ||
4070 | 171 | 169 | ||
4071 | === modified file 'dash/DashViewPrivate.cpp' | |||
4072 | --- dash/DashViewPrivate.cpp 2012-05-06 23:48:38 +0000 | |||
4073 | +++ dash/DashViewPrivate.cpp 2013-02-21 10:37:29 +0000 | |||
4074 | @@ -28,9 +28,9 @@ | |||
4075 | 28 | namespace impl | 28 | namespace impl |
4076 | 29 | { | 29 | { |
4077 | 30 | 30 | ||
4079 | 31 | LensFilter parse_lens_uri(std::string const& uri) | 31 | ScopeFilter parse_scope_uri(std::string const& uri) |
4080 | 32 | { | 32 | { |
4082 | 33 | LensFilter filter; | 33 | ScopeFilter filter; |
4083 | 34 | 34 | ||
4084 | 35 | filter.id = uri; | 35 | filter.id = uri; |
4085 | 36 | std::size_t pos = uri.find("?"); | 36 | std::size_t pos = uri.find("?"); |
4086 | 37 | 37 | ||
4087 | === modified file 'dash/DashViewPrivate.h' | |||
4088 | --- dash/DashViewPrivate.h 2012-05-06 23:48:38 +0000 | |||
4089 | +++ dash/DashViewPrivate.h 2013-02-21 10:37:29 +0000 | |||
4090 | @@ -35,7 +35,9 @@ | |||
4091 | 35 | std::map<std::string, std::string> filters; | 35 | std::map<std::string, std::string> filters; |
4092 | 36 | }; | 36 | }; |
4093 | 37 | 37 | ||
4095 | 38 | LensFilter parse_lens_uri(std::string const& uri); | 38 | typedef LensFilter ScopeFilter; |
4096 | 39 | |||
4097 | 40 | ScopeFilter parse_scope_uri(std::string const& uri); | ||
4098 | 39 | 41 | ||
4099 | 40 | } // namespace impl | 42 | } // namespace impl |
4100 | 41 | } // namespace dash | 43 | } // namespace dash |
4101 | 42 | 44 | ||
4102 | === modified file 'dash/FilterBar.cpp' | |||
4103 | --- dash/FilterBar.cpp 2012-11-27 23:37:20 +0000 | |||
4104 | +++ dash/FilterBar.cpp 2013-02-21 10:37:29 +0000 | |||
4105 | @@ -33,17 +33,13 @@ | |||
4106 | 33 | { | 33 | { |
4107 | 34 | namespace dash | 34 | namespace dash |
4108 | 35 | { | 35 | { |
4110 | 36 | DECLARE_LOGGER(logger, "unity.dash.filter.bar"); | 36 | DECLARE_LOGGER(logger, "unity.dash.filterbar"); |
4111 | 37 | 37 | ||
4112 | 38 | NUX_IMPLEMENT_OBJECT_TYPE(FilterBar); | 38 | NUX_IMPLEMENT_OBJECT_TYPE(FilterBar); |
4113 | 39 | 39 | ||
4114 | 40 | FilterBar::FilterBar(NUX_FILE_LINE_DECL) | 40 | FilterBar::FilterBar(NUX_FILE_LINE_DECL) |
4115 | 41 | : View(NUX_FILE_LINE_PARAM) | 41 | : View(NUX_FILE_LINE_PARAM) |
4116 | 42 | { | 42 | { |
4117 | 43 | // TODO - does the filterbar associate itself with a model of some sort? | ||
4118 | 44 | // does libunity provide a Lens.Filters model or something that we can update on? | ||
4119 | 45 | // don't want to associate a Filterbar with just a lens model, its a filter bar not a | ||
4120 | 46 | // lens parser | ||
4121 | 47 | Init(); | 43 | Init(); |
4122 | 48 | } | 44 | } |
4123 | 49 | 45 | ||
4124 | @@ -95,6 +91,17 @@ | |||
4125 | 95 | } | 91 | } |
4126 | 96 | } | 92 | } |
4127 | 97 | 93 | ||
4128 | 94 | void FilterBar::ClearFilters() | ||
4129 | 95 | { | ||
4130 | 96 | for (auto iter: filter_map_) | ||
4131 | 97 | { | ||
4132 | 98 | FilterExpanderLabel* filter_view = iter.second; | ||
4133 | 99 | RemoveChild(filter_view); | ||
4134 | 100 | GetLayout()->RemoveChildObject(filter_view); | ||
4135 | 101 | } | ||
4136 | 102 | filter_map_.clear(); | ||
4137 | 103 | } | ||
4138 | 104 | |||
4139 | 98 | void FilterBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) | 105 | void FilterBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) |
4140 | 99 | { | 106 | { |
4141 | 100 | 107 | ||
4142 | 101 | 108 | ||
4143 | === modified file 'dash/FilterBar.h' | |||
4144 | --- dash/FilterBar.h 2012-09-13 13:15:29 +0000 | |||
4145 | +++ dash/FilterBar.h 2013-02-21 10:37:29 +0000 | |||
4146 | @@ -48,6 +48,7 @@ | |||
4147 | 48 | 48 | ||
4148 | 49 | void AddFilter(Filter::Ptr const& filter); | 49 | void AddFilter(Filter::Ptr const& filter); |
4149 | 50 | void RemoveFilter(Filter::Ptr const& filter); | 50 | void RemoveFilter(Filter::Ptr const& filter); |
4150 | 51 | void ClearFilters(); | ||
4151 | 51 | 52 | ||
4152 | 52 | protected: | 53 | protected: |
4153 | 53 | virtual bool AcceptKeyNavFocus(); | 54 | virtual bool AcceptKeyNavFocus(); |
4154 | 54 | 55 | ||
4155 | === modified file 'dash/FilterRatingsButton.cpp' | |||
4156 | --- dash/FilterRatingsButton.cpp 2012-12-18 11:41:38 +0000 | |||
4157 | +++ dash/FilterRatingsButton.cpp 2013-02-21 10:37:29 +0000 | |||
4158 | @@ -90,7 +90,7 @@ | |||
4159 | 90 | // FIXME: 9/26/2011 | 90 | // FIXME: 9/26/2011 |
4160 | 91 | // We should probably support an API for saying whether the ratings | 91 | // We should probably support an API for saying whether the ratings |
4161 | 92 | // should or shouldn't support half stars...but our only consumer at | 92 | // should or shouldn't support half stars...but our only consumer at |
4163 | 93 | // the moment is the applications lens which according to design | 93 | // the moment is the applications scope which according to design |
4164 | 94 | // (Bug #839759) shouldn't. So for now just force rounding. | 94 | // (Bug #839759) shouldn't. So for now just force rounding. |
4165 | 95 | // int total_half_stars = rating % 2; | 95 | // int total_half_stars = rating % 2; |
4166 | 96 | // int total_full_stars = rating / 2; | 96 | // int total_full_stars = rating / 2; |
4167 | 97 | 97 | ||
4168 | === modified file 'dash/LensBar.cpp' | |||
4169 | --- dash/LensBar.cpp 2012-12-17 18:00:40 +0000 | |||
4170 | +++ dash/LensBar.cpp 2013-02-21 10:37:29 +0000 | |||
4171 | @@ -27,25 +27,24 @@ | |||
4172 | 27 | #include "unity-shared/StaticCairoText.h" | 27 | #include "unity-shared/StaticCairoText.h" |
4173 | 28 | #include "unity-shared/CairoTexture.h" | 28 | #include "unity-shared/CairoTexture.h" |
4174 | 29 | #include "unity-shared/GraphicsUtils.h" | 29 | #include "unity-shared/GraphicsUtils.h" |
4175 | 30 | #include "LensBar.h" | ||
4176 | 31 | #include "unity-shared/UBusMessages.h" | 30 | #include "unity-shared/UBusMessages.h" |
4177 | 32 | 31 | ||
4178 | 33 | namespace unity | 32 | namespace unity |
4179 | 34 | { | 33 | { |
4180 | 35 | namespace dash | 34 | namespace dash |
4181 | 36 | { | 35 | { |
4183 | 37 | DECLARE_LOGGER(logger, "unity.dash.lensbar"); | 36 | DECLARE_LOGGER(logger, "unity.dash.scopebar"); |
4184 | 38 | namespace | 37 | namespace |
4185 | 39 | { | 38 | { |
4187 | 40 | // according to Q design the inner area of the lensbar should be 40px | 39 | // according to Q design the inner area of the scopebar should be 40px |
4188 | 41 | // (without any borders) | 40 | // (without any borders) |
4190 | 42 | const int LENSBAR_HEIGHT = 41; | 41 | const int SCOPEBAR_HEIGHT = 41; |
4191 | 43 | 42 | ||
4192 | 44 | } | 43 | } |
4193 | 45 | 44 | ||
4195 | 46 | NUX_IMPLEMENT_OBJECT_TYPE(LensBar); | 45 | NUX_IMPLEMENT_OBJECT_TYPE(ScopeBar); |
4196 | 47 | 46 | ||
4198 | 48 | LensBar::LensBar() | 47 | ScopeBar::ScopeBar() |
4199 | 49 | : nux::View(NUX_TRACKER_LOCATION) | 48 | : nux::View(NUX_TRACKER_LOCATION) |
4200 | 50 | , info_previously_shown_(false) | 49 | , info_previously_shown_(false) |
4201 | 51 | { | 50 | { |
4202 | @@ -55,10 +54,9 @@ | |||
4203 | 55 | 54 | ||
4204 | 56 | SetupBackground(); | 55 | SetupBackground(); |
4205 | 57 | SetupLayout(); | 56 | SetupLayout(); |
4206 | 58 | SetupHomeLens(); | ||
4207 | 59 | } | 57 | } |
4208 | 60 | 58 | ||
4210 | 61 | void LensBar::SetupBackground() | 59 | void ScopeBar::SetupBackground() |
4211 | 62 | { | 60 | { |
4212 | 63 | nux::ROPConfig rop; | 61 | nux::ROPConfig rop; |
4213 | 64 | rop.Blend = true; | 62 | rop.Blend = true; |
4214 | @@ -67,7 +65,7 @@ | |||
4215 | 67 | bg_layer_.reset(new nux::ColorLayer(nux::Color(0.0f, 0.0f, 0.0f, 0.2f), true, rop)); | 65 | bg_layer_.reset(new nux::ColorLayer(nux::Color(0.0f, 0.0f, 0.0f, 0.2f), true, rop)); |
4216 | 68 | } | 66 | } |
4217 | 69 | 67 | ||
4219 | 70 | void LensBar::SetupLayout() | 68 | void ScopeBar::SetupLayout() |
4220 | 71 | { | 69 | { |
4221 | 72 | legal_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION); | 70 | legal_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION); |
4222 | 73 | std::string legal_text("<span underline='single'>"); | 71 | std::string legal_text("<span underline='single'>"); |
4223 | @@ -113,24 +111,11 @@ | |||
4224 | 113 | 111 | ||
4225 | 114 | SetLayout(layered_layout_); | 112 | SetLayout(layered_layout_); |
4226 | 115 | 113 | ||
4245 | 116 | SetMinimumHeight(LENSBAR_HEIGHT); | 114 | SetMinimumHeight(SCOPEBAR_HEIGHT); |
4246 | 117 | SetMaximumHeight(LENSBAR_HEIGHT); | 115 | SetMaximumHeight(SCOPEBAR_HEIGHT); |
4247 | 118 | } | 116 | } |
4248 | 119 | 117 | ||
4249 | 120 | void LensBar::SetupHomeLens() | 118 | void ScopeBar::DoOpenLegalise() |
4232 | 121 | { | ||
4233 | 122 | LensBarIcon* icon = new LensBarIcon("home.lens", PKGDATADIR"/lens-nav-home.svg"); | ||
4234 | 123 | icon->SetVisible(true); | ||
4235 | 124 | icon->active = true; | ||
4236 | 125 | icons_.push_back(icon); | ||
4237 | 126 | layout_->AddView(icon, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); | ||
4238 | 127 | AddChild(icon); | ||
4239 | 128 | |||
4240 | 129 | icon->mouse_click.connect([&, icon] (int x, int y, unsigned long button, unsigned long keyboard) { SetActive(icon); }); | ||
4241 | 130 | icon->key_nav_focus_activate.connect([&, icon](nux::Area*){ SetActive(icon); }); | ||
4242 | 131 | } | ||
4243 | 132 | |||
4244 | 133 | void LensBar::DoOpenLegalise() | ||
4250 | 134 | { | 119 | { |
4251 | 135 | glib::Error error; | 120 | glib::Error error; |
4252 | 136 | std::string legal_file_path = "file://"; | 121 | std::string legal_file_path = "file://"; |
4253 | @@ -147,11 +132,12 @@ | |||
4254 | 147 | ubus_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST); | 132 | ubus_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST); |
4255 | 148 | } | 133 | } |
4256 | 149 | 134 | ||
4258 | 150 | void LensBar::AddLens(Lens::Ptr& lens) | 135 | void ScopeBar::AddScope(Scope::Ptr const& scope) |
4259 | 151 | { | 136 | { |
4263 | 152 | LensBarIcon* icon = new LensBarIcon(lens->id, lens->icon_hint); | 137 | ScopeBarIcon* icon = new ScopeBarIcon(scope->id, scope->icon_hint); |
4264 | 153 | icon->SetVisible(lens->visible); | 138 | |
4265 | 154 | lens->visible.changed.connect([icon](bool visible) { icon->SetVisible(visible); } ); | 139 | icon->SetVisible(scope->visible); |
4266 | 140 | scope->visible.changed.connect([icon](bool visible) { icon->SetVisible(visible); } ); | ||
4267 | 155 | icons_.push_back(icon); | 141 | icons_.push_back(icon); |
4268 | 156 | layout_->AddView(icon, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX); | 142 | layout_->AddView(icon, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX); |
4269 | 157 | AddChild(icon); | 143 | AddChild(icon); |
4270 | @@ -160,7 +146,7 @@ | |||
4271 | 160 | icon->key_nav_focus_activate.connect([&, icon](nux::Area*){ SetActive(icon); }); | 146 | icon->key_nav_focus_activate.connect([&, icon](nux::Area*){ SetActive(icon); }); |
4272 | 161 | } | 147 | } |
4273 | 162 | 148 | ||
4275 | 163 | void LensBar::Activate(std::string id) | 149 | void ScopeBar::Activate(std::string id) |
4276 | 164 | { | 150 | { |
4277 | 165 | for (auto icon: icons_) | 151 | for (auto icon: icons_) |
4278 | 166 | { | 152 | { |
4279 | @@ -172,7 +158,7 @@ | |||
4280 | 172 | } | 158 | } |
4281 | 173 | } | 159 | } |
4282 | 174 | 160 | ||
4284 | 175 | void LensBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) | 161 | void ScopeBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) |
4285 | 176 | { | 162 | { |
4286 | 177 | nux::Geometry const& base = GetGeometry(); | 163 | nux::Geometry const& base = GetGeometry(); |
4287 | 178 | 164 | ||
4288 | @@ -190,7 +176,7 @@ | |||
4289 | 190 | graphics_engine.PopClippingRectangle(); | 176 | graphics_engine.PopClippingRectangle(); |
4290 | 191 | } | 177 | } |
4291 | 192 | 178 | ||
4293 | 193 | void LensBar::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) | 179 | void ScopeBar::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) |
4294 | 194 | { | 180 | { |
4295 | 195 | nux::Geometry const& base = GetGeometry(); | 181 | nux::Geometry const& base = GetGeometry(); |
4296 | 196 | 182 | ||
4297 | @@ -201,7 +187,7 @@ | |||
4298 | 201 | { | 187 | { |
4299 | 202 | if (RedirectedAncestor()) | 188 | if (RedirectedAncestor()) |
4300 | 203 | { | 189 | { |
4302 | 204 | // Whole Lens bar needs to be cleared because the PaintAll forces redraw. | 190 | // Whole Scope bar needs to be cleared because the PaintAll forces redraw. |
4303 | 205 | graphics::ClearGeometry(base); | 191 | graphics::ClearGeometry(base); |
4304 | 206 | } | 192 | } |
4305 | 207 | 193 | ||
4306 | @@ -251,10 +237,10 @@ | |||
4307 | 251 | graphics_engine.PopClippingRectangle(); | 237 | graphics_engine.PopClippingRectangle(); |
4308 | 252 | } | 238 | } |
4309 | 253 | 239 | ||
4311 | 254 | nux::Area* LensBar::FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type) | 240 | nux::Area* ScopeBar::FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type) |
4312 | 255 | { | 241 | { |
4313 | 256 | //LayeredLayout is acting a little screwy, events are not passing past the first layout like instructed, | 242 | //LayeredLayout is acting a little screwy, events are not passing past the first layout like instructed, |
4315 | 257 | //so we manually override if the cursor is on the right hand side of the lensbar | 243 | //so we manually override if the cursor is on the right hand side of the scopebar |
4316 | 258 | auto geo = GetAbsoluteGeometry(); | 244 | auto geo = GetAbsoluteGeometry(); |
4317 | 259 | int info_width = (info_previously_shown_) ? info_icon_->GetGeometry().width : legal_->GetGeometry().width; | 245 | int info_width = (info_previously_shown_) ? info_icon_->GetGeometry().width : legal_->GetGeometry().width; |
4318 | 260 | 246 | ||
4319 | @@ -272,7 +258,7 @@ | |||
4320 | 272 | 258 | ||
4321 | 273 | } | 259 | } |
4322 | 274 | 260 | ||
4324 | 275 | void LensBar::SetActive(LensBarIcon* activated) | 261 | void ScopeBar::SetActive(ScopeBarIcon* activated) |
4325 | 276 | { | 262 | { |
4326 | 277 | bool state_changed = false; | 263 | bool state_changed = false; |
4327 | 278 | 264 | ||
4328 | @@ -287,13 +273,13 @@ | |||
4329 | 287 | } | 273 | } |
4330 | 288 | 274 | ||
4331 | 289 | if (state_changed) | 275 | if (state_changed) |
4333 | 290 | lens_activated.emit(activated->id); | 276 | scope_activated.emit(activated->id); |
4334 | 291 | } | 277 | } |
4335 | 292 | 278 | ||
4337 | 293 | void LensBar::ActivateNext() | 279 | void ScopeBar::ActivateNext() |
4338 | 294 | { | 280 | { |
4341 | 295 | // Special case when switching from the command lens. | 281 | // Special case when switching from the command scope. |
4342 | 296 | if (GetActiveLensId() == "commands.lens") | 282 | if (GetActiveScopeId() == "commands.scope") |
4343 | 297 | { | 283 | { |
4344 | 298 | SetActive(icons_[0]); | 284 | SetActive(icons_[0]); |
4345 | 299 | return; | 285 | return; |
4346 | @@ -304,7 +290,7 @@ | |||
4347 | 304 | it < icons_.end(); | 290 | it < icons_.end(); |
4348 | 305 | it++) | 291 | it++) |
4349 | 306 | { | 292 | { |
4351 | 307 | LensBarIcon *icon = *it; | 293 | ScopeBarIcon *icon = *it; |
4352 | 308 | 294 | ||
4353 | 309 | if (activate_next && icon->IsVisible()) | 295 | if (activate_next && icon->IsVisible()) |
4354 | 310 | { | 296 | { |
4355 | @@ -318,10 +304,10 @@ | |||
4356 | 318 | 304 | ||
4357 | 319 | } | 305 | } |
4358 | 320 | 306 | ||
4360 | 321 | void LensBar::ActivatePrevious() | 307 | void ScopeBar::ActivatePrevious() |
4361 | 322 | { | 308 | { |
4364 | 323 | // Special case when switching from the command lens. | 309 | // Special case when switching from the command scope. |
4365 | 324 | if (GetActiveLensId() == "commands.lens") | 310 | if (GetActiveScopeId() == "commands.scope") |
4366 | 325 | { | 311 | { |
4367 | 326 | SetActive(icons_.back()); | 312 | SetActive(icons_.back()); |
4368 | 327 | return; | 313 | return; |
4369 | @@ -332,7 +318,7 @@ | |||
4370 | 332 | it < icons_.rend(); | 318 | it < icons_.rend(); |
4371 | 333 | ++it) | 319 | ++it) |
4372 | 334 | { | 320 | { |
4374 | 335 | LensBarIcon *icon = *it; | 321 | ScopeBarIcon *icon = *it; |
4375 | 336 | 322 | ||
4376 | 337 | if (activate_previous && icon->IsVisible()) | 323 | if (activate_previous && icon->IsVisible()) |
4377 | 338 | { | 324 | { |
4378 | @@ -347,34 +333,34 @@ | |||
4379 | 347 | } | 333 | } |
4380 | 348 | 334 | ||
4381 | 349 | // Keyboard navigation | 335 | // Keyboard navigation |
4383 | 350 | bool LensBar::AcceptKeyNavFocus() | 336 | bool ScopeBar::AcceptKeyNavFocus() |
4384 | 351 | { | 337 | { |
4385 | 352 | return false; | 338 | return false; |
4386 | 353 | } | 339 | } |
4387 | 354 | 340 | ||
4388 | 355 | // Introspectable | 341 | // Introspectable |
4390 | 356 | std::string LensBar::GetName() const | 342 | std::string ScopeBar::GetName() const |
4391 | 357 | { | 343 | { |
4393 | 358 | return "LensBar"; | 344 | return "ScopeBar"; |
4394 | 359 | } | 345 | } |
4395 | 360 | 346 | ||
4397 | 361 | void LensBar::AddProperties(GVariantBuilder* builder) | 347 | void ScopeBar::AddProperties(GVariantBuilder* builder) |
4398 | 362 | { | 348 | { |
4399 | 363 | unity::variant::BuilderWrapper wrapper(builder); | 349 | unity::variant::BuilderWrapper wrapper(builder); |
4400 | 364 | 350 | ||
4402 | 365 | wrapper.add("focused-lens-icon", ""); | 351 | wrapper.add("focused-scope-icon", ""); |
4403 | 366 | 352 | ||
4404 | 367 | for( auto icon : icons_) | 353 | for( auto icon : icons_) |
4405 | 368 | { | 354 | { |
4406 | 369 | if (icon->active) | 355 | if (icon->active) |
4408 | 370 | wrapper.add("active-lens", icon->id.Get()); | 356 | wrapper.add("active-scope", icon->id.Get()); |
4409 | 371 | 357 | ||
4410 | 372 | if (icon->HasKeyFocus()) | 358 | if (icon->HasKeyFocus()) |
4412 | 373 | wrapper.add("focused-lens-icon", icon->id.Get()); | 359 | wrapper.add("focused-scope-icon", icon->id.Get()); |
4413 | 374 | } | 360 | } |
4414 | 375 | } | 361 | } |
4415 | 376 | 362 | ||
4417 | 377 | std::string LensBar::GetActiveLensId() const | 363 | std::string ScopeBar::GetActiveScopeId() const |
4418 | 378 | { | 364 | { |
4419 | 379 | for (auto icon : icons_) | 365 | for (auto icon : icons_) |
4420 | 380 | { | 366 | { |
4421 | 381 | 367 | ||
4422 | === modified file 'dash/LensBar.h' | |||
4423 | --- dash/LensBar.h 2012-12-14 12:14:34 +0000 | |||
4424 | +++ dash/LensBar.h 2013-02-21 10:37:29 +0000 | |||
4425 | @@ -27,7 +27,7 @@ | |||
4426 | 27 | #include <Nux/Nux.h> | 27 | #include <Nux/Nux.h> |
4427 | 28 | #include <Nux/PaintLayer.h> | 28 | #include <Nux/PaintLayer.h> |
4428 | 29 | #include <Nux/View.h> | 29 | #include <Nux/View.h> |
4430 | 30 | #include <UnityCore/Lens.h> | 30 | #include <UnityCore/Scope.h> |
4431 | 31 | 31 | ||
4432 | 32 | #include "unity-shared/IconTexture.h" | 32 | #include "unity-shared/IconTexture.h" |
4433 | 33 | #include "unity-shared/Introspectable.h" | 33 | #include "unity-shared/Introspectable.h" |
4434 | @@ -49,25 +49,24 @@ | |||
4435 | 49 | namespace dash | 49 | namespace dash |
4436 | 50 | { | 50 | { |
4437 | 51 | 51 | ||
4439 | 52 | class LensBar : public nux::View, public unity::debug::Introspectable | 52 | class ScopeBar : public nux::View, public unity::debug::Introspectable |
4440 | 53 | { | 53 | { |
4443 | 54 | NUX_DECLARE_OBJECT_TYPE(LensBar, nux::View); | 54 | NUX_DECLARE_OBJECT_TYPE(ScopeBar, nux::View); |
4444 | 55 | typedef std::vector<LensBarIcon*> LensIcons; | 55 | typedef std::vector<ScopeBarIcon*> ScopeIcons; |
4445 | 56 | 56 | ||
4446 | 57 | public: | 57 | public: |
4448 | 58 | LensBar(); | 58 | ScopeBar(); |
4449 | 59 | 59 | ||
4451 | 60 | void AddLens(Lens::Ptr& lens); | 60 | void AddScope(Scope::Ptr const& scope); |
4452 | 61 | void Activate(std::string id); | 61 | void Activate(std::string id); |
4453 | 62 | void ActivateNext(); | 62 | void ActivateNext(); |
4454 | 63 | void ActivatePrevious(); | 63 | void ActivatePrevious(); |
4455 | 64 | 64 | ||
4457 | 65 | sigc::signal<void, std::string const&> lens_activated; | 65 | sigc::signal<void, std::string const&> scope_activated; |
4458 | 66 | 66 | ||
4459 | 67 | private: | 67 | private: |
4460 | 68 | void SetupBackground(); | 68 | void SetupBackground(); |
4461 | 69 | void SetupLayout(); | 69 | void SetupLayout(); |
4462 | 70 | void SetupHomeLens(); | ||
4463 | 71 | void DoOpenLegalise(); | 70 | void DoOpenLegalise(); |
4464 | 72 | 71 | ||
4465 | 73 | void Draw(nux::GraphicsEngine& gfx_context, bool force_draw); | 72 | void Draw(nux::GraphicsEngine& gfx_context, bool force_draw); |
4466 | @@ -75,16 +74,16 @@ | |||
4467 | 75 | 74 | ||
4468 | 76 | nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type); | 75 | nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type); |
4469 | 77 | 76 | ||
4471 | 78 | void SetActive(LensBarIcon* icon); | 77 | void SetActive(ScopeBarIcon* icon); |
4472 | 79 | 78 | ||
4473 | 80 | bool AcceptKeyNavFocus(); | 79 | bool AcceptKeyNavFocus(); |
4474 | 81 | std::string GetName() const; | 80 | std::string GetName() const; |
4475 | 82 | void AddProperties(GVariantBuilder* builder); | 81 | void AddProperties(GVariantBuilder* builder); |
4476 | 83 | 82 | ||
4478 | 84 | std::string GetActiveLensId() const; | 83 | std::string GetActiveScopeId() const; |
4479 | 85 | typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr; | 84 | typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr; |
4480 | 86 | 85 | ||
4482 | 87 | LensIcons icons_; | 86 | ScopeIcons icons_; |
4483 | 88 | 87 | ||
4484 | 89 | UBusManager ubus_; | 88 | UBusManager ubus_; |
4485 | 90 | 89 | ||
4486 | @@ -97,6 +96,8 @@ | |||
4487 | 97 | 96 | ||
4488 | 98 | bool info_previously_shown_; | 97 | bool info_previously_shown_; |
4489 | 99 | std::string legal_seen_file_path_; | 98 | std::string legal_seen_file_path_; |
4490 | 99 | |||
4491 | 100 | friend class TestScopeBar; | ||
4492 | 100 | }; | 101 | }; |
4493 | 101 | 102 | ||
4494 | 102 | } // namespace dash | 103 | } // namespace dash |
4495 | 103 | 104 | ||
4496 | === modified file 'dash/LensBarIcon.cpp' | |||
4497 | --- dash/LensBarIcon.cpp 2012-12-17 09:28:31 +0000 | |||
4498 | +++ dash/LensBarIcon.cpp 2013-02-21 10:37:29 +0000 | |||
4499 | @@ -35,9 +35,9 @@ | |||
4500 | 35 | 35 | ||
4501 | 36 | } | 36 | } |
4502 | 37 | 37 | ||
4504 | 38 | NUX_IMPLEMENT_OBJECT_TYPE(LensBarIcon); | 38 | NUX_IMPLEMENT_OBJECT_TYPE(ScopeBarIcon); |
4505 | 39 | 39 | ||
4507 | 40 | LensBarIcon::LensBarIcon(std::string id_, std::string icon_hint) | 40 | ScopeBarIcon::ScopeBarIcon(std::string id_, std::string icon_hint) |
4508 | 41 | : IconTexture(icon_hint, 24) | 41 | : IconTexture(icon_hint, 24) |
4509 | 42 | , id(id_) | 42 | , id(id_) |
4510 | 43 | , active(false) | 43 | , active(false) |
4511 | @@ -56,14 +56,14 @@ | |||
4512 | 56 | SetAcceptKeyNavFocusOnMouseDown(false); | 56 | SetAcceptKeyNavFocusOnMouseDown(false); |
4513 | 57 | SetAcceptKeyNavFocusOnMouseEnter(true); | 57 | SetAcceptKeyNavFocusOnMouseEnter(true); |
4514 | 58 | 58 | ||
4516 | 59 | active.changed.connect(sigc::mem_fun(this, &LensBarIcon::OnActiveChanged)); | 59 | active.changed.connect(sigc::mem_fun(this, &ScopeBarIcon::OnActiveChanged)); |
4517 | 60 | key_nav_focus_change.connect([&](nux::Area*, bool, nux::KeyNavDirection){ QueueDraw(); }); | 60 | key_nav_focus_change.connect([&](nux::Area*, bool, nux::KeyNavDirection){ QueueDraw(); }); |
4518 | 61 | } | 61 | } |
4519 | 62 | 62 | ||
4521 | 63 | LensBarIcon::~LensBarIcon() | 63 | ScopeBarIcon::~ScopeBarIcon() |
4522 | 64 | {} | 64 | {} |
4523 | 65 | 65 | ||
4525 | 66 | void LensBarIcon::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) | 66 | void ScopeBarIcon::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) |
4526 | 67 | { | 67 | { |
4527 | 68 | nux::Geometry const& geo = GetGeometry(); | 68 | nux::Geometry const& geo = GetGeometry(); |
4528 | 69 | 69 | ||
4529 | @@ -109,18 +109,18 @@ | |||
4530 | 109 | graphics_engine.PopClippingRectangle(); | 109 | graphics_engine.PopClippingRectangle(); |
4531 | 110 | } | 110 | } |
4532 | 111 | 111 | ||
4534 | 112 | void LensBarIcon::OnActiveChanged(bool is_active) | 112 | void ScopeBarIcon::OnActiveChanged(bool is_active) |
4535 | 113 | { | 113 | { |
4536 | 114 | QueueDraw(); | 114 | QueueDraw(); |
4537 | 115 | } | 115 | } |
4538 | 116 | 116 | ||
4539 | 117 | // Introspectable | 117 | // Introspectable |
4541 | 118 | std::string LensBarIcon::GetName() const | 118 | std::string ScopeBarIcon::GetName() const |
4542 | 119 | { | 119 | { |
4544 | 120 | return "LensBarIcon"; | 120 | return "ScopeBarIcon"; |
4545 | 121 | } | 121 | } |
4546 | 122 | 122 | ||
4548 | 123 | void LensBarIcon::AddProperties(GVariantBuilder* builder) | 123 | void ScopeBarIcon::AddProperties(GVariantBuilder* builder) |
4549 | 124 | { | 124 | { |
4550 | 125 | unity::variant::BuilderWrapper wrapper(builder); | 125 | unity::variant::BuilderWrapper wrapper(builder); |
4551 | 126 | 126 | ||
4552 | 127 | 127 | ||
4553 | === modified file 'dash/LensBarIcon.h' | |||
4554 | --- dash/LensBarIcon.h 2012-05-06 23:48:38 +0000 | |||
4555 | +++ dash/LensBarIcon.h 2013-02-21 10:37:29 +0000 | |||
4556 | @@ -33,12 +33,12 @@ | |||
4557 | 33 | namespace dash | 33 | namespace dash |
4558 | 34 | { | 34 | { |
4559 | 35 | 35 | ||
4561 | 36 | class LensBarIcon : public IconTexture | 36 | class ScopeBarIcon : public IconTexture |
4562 | 37 | { | 37 | { |
4564 | 38 | NUX_DECLARE_OBJECT_TYPE(LensBarIcon, IconTexture); | 38 | NUX_DECLARE_OBJECT_TYPE(ScopeBarIcon, IconTexture); |
4565 | 39 | public: | 39 | public: |
4568 | 40 | LensBarIcon(std::string id, std::string icon_hint); | 40 | ScopeBarIcon(std::string id, std::string icon_hint); |
4569 | 41 | ~LensBarIcon(); | 41 | ~ScopeBarIcon(); |
4570 | 42 | 42 | ||
4571 | 43 | nux::Property<std::string> id; | 43 | nux::Property<std::string> id; |
4572 | 44 | nux::Property<bool> active; | 44 | nux::Property<bool> active; |
4573 | 45 | 45 | ||
4574 | === modified file 'dash/LensView.cpp' | |||
4575 | --- dash/LensView.cpp 2013-01-15 21:53:55 +0000 | |||
4576 | +++ dash/LensView.cpp 2013-02-21 10:37:29 +0000 | |||
4577 | @@ -43,7 +43,7 @@ | |||
4578 | 43 | { | 43 | { |
4579 | 44 | namespace dash | 44 | namespace dash |
4580 | 45 | { | 45 | { |
4582 | 46 | DECLARE_LOGGER(logger, "unity.dash.lensview"); | 46 | DECLARE_LOGGER(logger, "unity.dash.scopeview"); |
4583 | 47 | namespace | 47 | namespace |
4584 | 48 | { | 48 | { |
4585 | 49 | const int CARD_VIEW_GAP_VERT = 24; // pixels | 49 | const int CARD_VIEW_GAP_VERT = 24; // pixels |
4586 | @@ -51,10 +51,10 @@ | |||
4587 | 51 | } | 51 | } |
4588 | 52 | 52 | ||
4589 | 53 | // This is so we can access some protected members in scrollview. | 53 | // This is so we can access some protected members in scrollview. |
4591 | 54 | class LensScrollView: public nux::ScrollView | 54 | class ScopeScrollView: public nux::ScrollView |
4592 | 55 | { | 55 | { |
4593 | 56 | public: | 56 | public: |
4595 | 57 | LensScrollView(nux::VScrollBar* scroll_bar, NUX_FILE_LINE_DECL) | 57 | ScopeScrollView(nux::VScrollBar* scroll_bar, NUX_FILE_LINE_DECL) |
4596 | 58 | : nux::ScrollView(NUX_FILE_LINE_PARAM) | 58 | : nux::ScrollView(NUX_FILE_LINE_PARAM) |
4597 | 59 | , right_area_(nullptr) | 59 | , right_area_(nullptr) |
4598 | 60 | , up_area_(nullptr) | 60 | , up_area_(nullptr) |
4599 | @@ -146,37 +146,36 @@ | |||
4600 | 146 | }; | 146 | }; |
4601 | 147 | 147 | ||
4602 | 148 | 148 | ||
4604 | 149 | NUX_IMPLEMENT_OBJECT_TYPE(LensView); | 149 | NUX_IMPLEMENT_OBJECT_TYPE(ScopeView); |
4605 | 150 | 150 | ||
4616 | 151 | LensView::LensView(Lens::Ptr lens, nux::Area* show_filters) | 151 | ScopeView::ScopeView(Scope::Ptr scope, nux::Area* show_filters) |
4617 | 152 | : nux::View(NUX_TRACKER_LOCATION) | 152 | : nux::View(NUX_TRACKER_LOCATION) |
4618 | 153 | , filters_expanded(false) | 153 | , filters_expanded(false) |
4619 | 154 | , can_refine_search(false) | 154 | , can_refine_search(false) |
4620 | 155 | , lens_(lens) | 155 | , scope_(scope) |
4621 | 156 | , initial_activation_(true) | 156 | , cancellable_(g_cancellable_new()) |
4622 | 157 | , no_results_active_(false) | 157 | , initial_activation_(true) |
4623 | 158 | , last_expanded_group_(nullptr) | 158 | , no_results_active_(false) |
4624 | 159 | , last_good_filter_model_(-1) | 159 | , last_expanded_group_(nullptr) |
4625 | 160 | , filter_expansion_pushed_(false) | 160 | , last_good_filter_model_(-1) |
4626 | 161 | , filter_expansion_pushed_(false) | ||
4627 | 161 | { | 162 | { |
4628 | 162 | SetupViews(show_filters); | 163 | SetupViews(show_filters); |
4629 | 163 | SetupCategories(); | 164 | SetupCategories(); |
4630 | 164 | SetupResults(); | 165 | SetupResults(); |
4631 | 165 | SetupFilters(); | 166 | SetupFilters(); |
4632 | 166 | 167 | ||
4634 | 167 | dash::Style::Instance().columns_changed.connect(sigc::mem_fun(this, &LensView::OnColumnsChanged)); | 168 | dash::Style::Instance().columns_changed.connect(sigc::mem_fun(this, &ScopeView::OnColumnsChanged)); |
4635 | 168 | 169 | ||
4640 | 169 | search_string.SetGetterFunction(sigc::mem_fun(this, &LensView::get_search_string)); | 170 | search_string.SetGetterFunction(sigc::mem_fun(this, &ScopeView::get_search_string)); |
4641 | 170 | filters_expanded.changed.connect(sigc::mem_fun(this, &LensView::OnLensFilterExpanded)); | 171 | filters_expanded.changed.connect(sigc::mem_fun(this, &ScopeView::OnScopeFilterExpanded)); |
4642 | 171 | view_type.changed.connect(sigc::mem_fun(this, &LensView::OnViewTypeChanged)); | 172 | view_type.changed.connect(sigc::mem_fun(this, &ScopeView::OnViewTypeChanged)); |
4643 | 172 | if (lens_) | 173 | if (scope_) |
4644 | 173 | { | 174 | { |
4647 | 174 | lens_->connected.changed.connect([&](bool is_connected) | 175 | scope_->connected.changed.connect([&](bool is_connected) { |
4646 | 175 | { | ||
4648 | 176 | if (is_connected) | 176 | if (is_connected) |
4649 | 177 | initial_activation_ = true; | 177 | initial_activation_ = true; |
4650 | 178 | }); | 178 | }); |
4651 | 179 | lens_->categories_reordered.connect(sigc::mem_fun(this, &LensView::OnCategoryOrderChanged)); | ||
4652 | 180 | } | 179 | } |
4653 | 181 | 180 | ||
4654 | 182 | ubus_manager_.RegisterInterest(UBUS_RESULT_VIEW_KEYNAV_CHANGED, [&] (GVariant* data) { | 181 | ubus_manager_.RegisterInterest(UBUS_RESULT_VIEW_KEYNAV_CHANGED, [&] (GVariant* data) { |
4655 | @@ -209,17 +208,28 @@ | |||
4656 | 209 | OnVisibleChanged.connect([&] (nux::Area* area, bool visible) { | 208 | OnVisibleChanged.connect([&] (nux::Area* area, bool visible) { |
4657 | 210 | scroll_view_->SetVisible(visible); | 209 | scroll_view_->SetVisible(visible); |
4658 | 211 | }); | 210 | }); |
4663 | 212 | 211 | } | |
4664 | 213 | } | 212 | |
4665 | 214 | 213 | ScopeView::~ScopeView() | |
4666 | 215 | void LensView::SetupViews(nux::Area* show_filters) | 214 | { |
4667 | 215 | result_added_connection.disconnect(); | ||
4668 | 216 | result_removed_connection.disconnect(); | ||
4669 | 217 | category_added_connection.disconnect(); | ||
4670 | 218 | category_removed_connection.disconnect(); | ||
4671 | 219 | filter_added_connection.disconnect(); | ||
4672 | 220 | filter_removed_connection.disconnect(); | ||
4673 | 221 | |||
4674 | 222 | g_cancellable_cancel(cancellable_); | ||
4675 | 223 | } | ||
4676 | 224 | |||
4677 | 225 | void ScopeView::SetupViews(nux::Area* show_filters) | ||
4678 | 216 | { | 226 | { |
4679 | 217 | dash::Style& style = dash::Style::Instance(); | 227 | dash::Style& style = dash::Style::Instance(); |
4680 | 218 | 228 | ||
4681 | 219 | layout_ = new nux::HLayout(NUX_TRACKER_LOCATION); | 229 | layout_ = new nux::HLayout(NUX_TRACKER_LOCATION); |
4683 | 220 | layout_->SetSpaceBetweenChildren(style.GetSpaceBetweenLensAndFilters()); | 230 | layout_->SetSpaceBetweenChildren(style.GetSpaceBetweenScopeAndFilters()); |
4684 | 221 | 231 | ||
4686 | 222 | scroll_view_ = new LensScrollView(new PlacesOverlayVScrollBar(NUX_TRACKER_LOCATION), | 232 | scroll_view_ = new ScopeScrollView(new PlacesOverlayVScrollBar(NUX_TRACKER_LOCATION), |
4687 | 223 | NUX_TRACKER_LOCATION); | 233 | NUX_TRACKER_LOCATION); |
4688 | 224 | scroll_view_->EnableVerticalScrollBar(true); | 234 | scroll_view_->EnableVerticalScrollBar(true); |
4689 | 225 | scroll_view_->EnableHorizontalScrollBar(false); | 235 | scroll_view_->EnableHorizontalScrollBar(false); |
4690 | @@ -239,7 +249,7 @@ | |||
4691 | 239 | no_results_->SetVisible(false); | 249 | no_results_->SetVisible(false); |
4692 | 240 | scroll_layout_->AddView(no_results_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT); | 250 | scroll_layout_->AddView(no_results_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT); |
4693 | 241 | 251 | ||
4695 | 242 | fscroll_view_ = new LensScrollView(new PlacesVScrollBar(NUX_TRACKER_LOCATION), NUX_TRACKER_LOCATION); | 252 | fscroll_view_ = new ScopeScrollView(new PlacesVScrollBar(NUX_TRACKER_LOCATION), NUX_TRACKER_LOCATION); |
4696 | 243 | fscroll_view_->EnableVerticalScrollBar(true); | 253 | fscroll_view_->EnableVerticalScrollBar(true); |
4697 | 244 | fscroll_view_->EnableHorizontalScrollBar(false); | 254 | fscroll_view_->EnableHorizontalScrollBar(false); |
4698 | 245 | fscroll_view_->SetVisible(false); | 255 | fscroll_view_->SetVisible(false); |
4699 | @@ -264,35 +274,48 @@ | |||
4700 | 264 | SetLayout(layout_); | 274 | SetLayout(layout_); |
4701 | 265 | } | 275 | } |
4702 | 266 | 276 | ||
4704 | 267 | void LensView::SetupCategories() | 277 | void ScopeView::SetupCategories() |
4705 | 268 | { | 278 | { |
4707 | 269 | if (!lens_) | 279 | if (!scope_) |
4708 | 270 | return; | 280 | return; |
4709 | 271 | 281 | ||
4715 | 272 | Categories::Ptr categories = lens_->categories; | 282 | Categories::Ptr categories = scope_->categories; |
4716 | 273 | categories->category_added.connect(sigc::mem_fun(this, &LensView::OnCategoryAdded)); | 283 | category_added_connection = categories->category_added.connect(sigc::mem_fun(this, &ScopeView::OnCategoryAdded)); |
4717 | 274 | 284 | category_removed_connection = categories->category_removed.connect(sigc::mem_fun(this, &ScopeView::OnCategoryRemoved)); | |
4718 | 275 | for (unsigned int i = 0; i < categories->count(); ++i) | 285 | |
4719 | 276 | OnCategoryAdded(categories->RowAtIndex(i)); | 286 | auto resync_categories = [categories, this] (glib::Object<DeeModel> model) |
4720 | 287 | { | ||
4721 | 288 | ClearCategories(); | ||
4722 | 289 | for (unsigned int i = 0; i < categories->count(); ++i) | ||
4723 | 290 | OnCategoryAdded(categories->RowAtIndex(i)); | ||
4724 | 291 | }; | ||
4725 | 292 | |||
4726 | 293 | categories->model.changed.connect(resync_categories); | ||
4727 | 294 | resync_categories(categories->model()); | ||
4728 | 295 | |||
4729 | 296 | scope_->category_order.changed.connect([this](std::vector<int> const& category_order) { | ||
4730 | 297 | LOG_DEBUG(logger) << scope_->id() << ": category order changed"; | ||
4731 | 298 | }); | ||
4732 | 277 | } | 299 | } |
4733 | 278 | 300 | ||
4735 | 279 | void LensView::SetupResults() | 301 | void ScopeView::SetupResults() |
4736 | 280 | { | 302 | { |
4738 | 281 | if (!lens_) | 303 | if (!scope_) |
4739 | 282 | return; | 304 | return; |
4740 | 283 | 305 | ||
4744 | 284 | Results::Ptr results = lens_->results; | 306 | Results::Ptr results = scope_->results; |
4745 | 285 | results->result_added.connect(sigc::mem_fun(this, &LensView::OnResultAdded)); | 307 | result_added_connection = results->result_added.connect(sigc::mem_fun(this, &ScopeView::OnResultAdded)); |
4746 | 286 | results->result_removed.connect(sigc::mem_fun(this, &LensView::OnResultRemoved)); | 308 | result_added_connection = results->result_removed.connect(sigc::mem_fun(this, &ScopeView::OnResultRemoved)); |
4747 | 287 | 309 | ||
4748 | 288 | results->model.changed.connect([this] (glib::Object<DeeModel> model) | 310 | results->model.changed.connect([this] (glib::Object<DeeModel> model) |
4749 | 289 | { | 311 | { |
4750 | 290 | for (unsigned int i = 0; i < categories_.size(); ++i) | 312 | for (unsigned int i = 0; i < categories_.size(); ++i) |
4751 | 291 | { | 313 | { |
4752 | 292 | ResultViewGrid* grid = GetGridForCategory(i); | 314 | ResultViewGrid* grid = GetGridForCategory(i); |
4756 | 293 | glib::Object<DeeModel> filter_model(lens_->GetFilterModelForCategory(i)); | 315 | if (grid) |
4757 | 294 | Results::Ptr results_model = lens_->results; | 316 | { |
4758 | 295 | grid->SetModel(filter_model, results_model->GetTag()); | 317 | grid->SetResultsModel(scope_->GetResultsForCategory(i)); |
4759 | 318 | } | ||
4760 | 296 | } | 319 | } |
4761 | 297 | }); | 320 | }); |
4762 | 298 | 321 | ||
4763 | @@ -300,20 +323,31 @@ | |||
4764 | 300 | OnResultAdded(results->RowAtIndex(i)); | 323 | OnResultAdded(results->RowAtIndex(i)); |
4765 | 301 | } | 324 | } |
4766 | 302 | 325 | ||
4768 | 303 | void LensView::SetupFilters() | 326 | void ScopeView::SetupFilters() |
4769 | 304 | { | 327 | { |
4771 | 305 | if (!lens_) | 328 | if (!scope_) |
4772 | 306 | return; | 329 | return; |
4773 | 307 | 330 | ||
4780 | 308 | Filters::Ptr filters = lens_->filters; | 331 | Filters::Ptr filters = scope_->filters; |
4781 | 309 | filters->filter_added.connect(sigc::mem_fun(this, &LensView::OnFilterAdded)); | 332 | filter_added_connection = filters->filter_added.connect(sigc::mem_fun(this, &ScopeView::OnFilterAdded)); |
4782 | 310 | filters->filter_removed.connect(sigc::mem_fun(this, &LensView::OnFilterRemoved)); | 333 | filter_removed_connection = filters->filter_removed.connect(sigc::mem_fun(this, &ScopeView::OnFilterRemoved)); |
4783 | 311 | 334 | ||
4784 | 312 | for (unsigned int i = 0; i < filters->count(); ++i) | 335 | auto resync_filters = [filters, this] (glib::Object<DeeModel> model) |
4785 | 313 | OnFilterAdded(filters->FilterAtIndex(i)); | 336 | { |
4786 | 337 | bool blocked = filter_added_connection.block(true); | ||
4787 | 338 | |||
4788 | 339 | filter_bar_->ClearFilters(); | ||
4789 | 340 | for (unsigned int i = 0; i < filters->count(); ++i) | ||
4790 | 341 | OnFilterAdded(filters->FilterAtIndex(i)); | ||
4791 | 342 | |||
4792 | 343 | filter_added_connection.block(blocked); | ||
4793 | 344 | }; | ||
4794 | 345 | |||
4795 | 346 | filters->model.changed.connect(resync_filters); | ||
4796 | 347 | resync_filters(filters->model()); | ||
4797 | 314 | } | 348 | } |
4798 | 315 | 349 | ||
4800 | 316 | void LensView::OnCategoryAdded(Category const& category) | 350 | void ScopeView::OnCategoryAdded(Category const& category) |
4801 | 317 | { | 351 | { |
4802 | 318 | std::string name = category.name; | 352 | std::string name = category.name; |
4803 | 319 | std::string icon_hint = category.icon_hint; | 353 | std::string icon_hint = category.icon_hint; |
4804 | @@ -328,10 +362,11 @@ | |||
4805 | 328 | 362 | ||
4806 | 329 | if (index < categories_.size()) | 363 | if (index < categories_.size()) |
4807 | 330 | { | 364 | { |
4809 | 331 | // the lens might have restarted and we don't want to create | 365 | // the scope might have restarted and we don't want to create |
4810 | 332 | // new PlacesGroup if we can reuse the old one | 366 | // new PlacesGroup if we can reuse the old one |
4811 | 333 | PlacesGroup* existing_group = categories_.at(index); | 367 | PlacesGroup* existing_group = categories_.at(index); |
4813 | 334 | if (existing_group->GetCategoryIndex() == index) return; | 368 | if (existing_group->GetCategoryIndex() == index) |
4814 | 369 | return; | ||
4815 | 335 | } | 370 | } |
4816 | 336 | 371 | ||
4817 | 337 | PlacesGroup* group = CreatePlacesGroup(); | 372 | PlacesGroup* group = CreatePlacesGroup(); |
4818 | @@ -341,7 +376,7 @@ | |||
4819 | 341 | group->SetCategoryIndex(index); | 376 | group->SetCategoryIndex(index); |
4820 | 342 | group->SetExpanded(false); | 377 | group->SetExpanded(false); |
4821 | 343 | group->SetVisible(false); | 378 | group->SetVisible(false); |
4823 | 344 | group->expanded.connect(sigc::mem_fun(this, &LensView::OnGroupExpanded)); | 379 | group->expanded.connect(sigc::mem_fun(this, &ScopeView::OnGroupExpanded)); |
4824 | 345 | 380 | ||
4825 | 346 | reset_filter_models = index < categories_.size(); | 381 | reset_filter_models = index < categories_.size(); |
4826 | 347 | /* Add the group at the correct offset into the categories vector */ | 382 | /* Add the group at the correct offset into the categories vector */ |
4827 | @@ -375,9 +410,9 @@ | |||
4828 | 375 | } | 410 | } |
4829 | 376 | group->SetChildView(grid); | 411 | group->SetChildView(grid); |
4830 | 377 | 412 | ||
4832 | 378 | if (lens_) | 413 | if (scope_) |
4833 | 379 | { | 414 | { |
4835 | 380 | std::string unique_id = name + lens_->name(); | 415 | std::string unique_id = name + scope_->name(); |
4836 | 381 | grid->unique_id = unique_id; | 416 | grid->unique_id = unique_id; |
4837 | 382 | grid->expanded = false; | 417 | grid->expanded = false; |
4838 | 383 | 418 | ||
4839 | @@ -389,24 +424,21 @@ | |||
4840 | 389 | { | 424 | { |
4841 | 390 | case ResultView::ActivateType::DIRECT: | 425 | case ResultView::ActivateType::DIRECT: |
4842 | 391 | { | 426 | { |
4844 | 392 | lens_->Activate(uri); | 427 | scope_->Activate(uri, nullptr, cancellable_); |
4845 | 393 | } break; | 428 | } break; |
4846 | 394 | case ResultView::ActivateType::PREVIEW: | 429 | case ResultView::ActivateType::PREVIEW: |
4847 | 395 | { | 430 | { |
4849 | 396 | lens_->Preview(uri); | 431 | scope_->Preview(uri, nullptr, cancellable_); |
4850 | 397 | } break; | 432 | } break; |
4851 | 398 | default: break; | 433 | default: break; |
4852 | 399 | }; | 434 | }; |
4853 | 400 | }); | 435 | }); |
4854 | 401 | 436 | ||
4855 | 402 | |||
4856 | 403 | /* Set up filter model for this category */ | 437 | /* Set up filter model for this category */ |
4863 | 404 | Results::Ptr results_model = lens_->results; | 438 | Results::Ptr results_model = scope_->GetResultsForCategory(index); |
4864 | 405 | if (results_model->model()) | 439 | counts_[group] = results_model ? results_model->count() : 0; |
4865 | 406 | { | 440 | |
4866 | 407 | glib::Object<DeeModel> filter_model(lens_->GetFilterModelForCategory(index)); | 441 | grid->SetResultsModel(results_model); |
4861 | 408 | grid->SetModel(filter_model, results_model->GetTag()); | ||
4862 | 409 | } | ||
4867 | 410 | 442 | ||
4868 | 411 | if (reset_filter_models) | 443 | if (reset_filter_models) |
4869 | 412 | { | 444 | { |
4870 | @@ -416,7 +448,7 @@ | |||
4871 | 416 | for (auto it = categories_.begin() + (index + 1); it != categories_.end(); ++it) | 448 | for (auto it = categories_.begin() + (index + 1); it != categories_.end(); ++it) |
4872 | 417 | { | 449 | { |
4873 | 418 | grid = static_cast<ResultViewGrid*>((*it)->GetChildView()); | 450 | grid = static_cast<ResultViewGrid*>((*it)->GetChildView()); |
4875 | 419 | grid->SetModel(glib::Object<DeeModel>(), NULL); | 451 | grid->SetResultsModel(Results::Ptr()); |
4876 | 420 | } | 452 | } |
4877 | 421 | 453 | ||
4878 | 422 | if (static_cast<int>(index) < last_good_filter_model_ || last_good_filter_model_ < 0) | 454 | if (static_cast<int>(index) < last_good_filter_model_ || last_good_filter_model_ < 0) |
4879 | @@ -425,7 +457,7 @@ | |||
4880 | 425 | } | 457 | } |
4881 | 426 | if (!fix_filter_models_idle_) | 458 | if (!fix_filter_models_idle_) |
4882 | 427 | { | 459 | { |
4884 | 428 | fix_filter_models_idle_.reset(new glib::Idle(sigc::mem_fun(this, &LensView::ReinitializeFilterModels), glib::Source::Priority::HIGH)); | 460 | fix_filter_models_idle_.reset(new glib::Idle(sigc::mem_fun(this, &ScopeView::ReinitializeFilterModels), glib::Source::Priority::HIGH)); |
4885 | 429 | } | 461 | } |
4886 | 430 | } | 462 | } |
4887 | 431 | } | 463 | } |
4888 | @@ -435,50 +467,59 @@ | |||
4889 | 435 | scroll_layout_->AddView(group, 0, nux::MinorDimensionPosition::MINOR_POSITION_START, | 467 | scroll_layout_->AddView(group, 0, nux::MinorDimensionPosition::MINOR_POSITION_START, |
4890 | 436 | nux::MinorDimensionSize::MINOR_SIZE_FULL, 100.0f, | 468 | nux::MinorDimensionSize::MINOR_SIZE_FULL, 100.0f, |
4891 | 437 | (nux::LayoutPosition)index); | 469 | (nux::LayoutPosition)index); |
4928 | 438 | } | 470 | |
4929 | 439 | 471 | UpdateCounts(group); | |
4930 | 440 | void LensView::OnCategoryOrderChanged() | 472 | } |
4931 | 441 | { | 473 | |
4932 | 442 | LOG_DEBUG(logger) << "Reordering categories for " << lens_->name(); | 474 | void ScopeView::OnCategoryRemoved(Category const& category) |
4933 | 443 | 475 | { | |
4934 | 444 | // need references so that the Layout doesn't destroy the views | 476 | std::string name = category.name; |
4935 | 445 | std::vector<nux::ObjectPtr<PlacesGroup> > child_views; | 477 | std::string icon_hint = category.icon_hint; |
4936 | 446 | for (unsigned i = 0; i < categories_.size(); i++) | 478 | std::string renderer_name = category.renderer_name; |
4937 | 447 | { | 479 | unsigned index = (category.index == unsigned(-1)) ? categories_.size() : category.index; |
4938 | 448 | child_views.push_back(nux::ObjectPtr<PlacesGroup>(categories_.at(i))); | 480 | |
4939 | 449 | scroll_layout_->RemoveChildObject(categories_.at(i)); | 481 | LOG_DEBUG(logger) << "Category removed: " << name |
4940 | 450 | } | 482 | << "(" << icon_hint |
4941 | 451 | 483 | << ", " << renderer_name | |
4942 | 452 | if (lens_) | 484 | << ", " << boost::lexical_cast<int>(index) << ")"; |
4943 | 453 | { | 485 | |
4944 | 454 | // there should be ~10 categories, so this shouldn't be too big of a deal | 486 | if (index >= categories_.size()) |
4945 | 455 | std::vector<unsigned> order(lens_->GetCategoriesOrder()); | 487 | return; |
4946 | 456 | for (unsigned i = 0; i < order.size(); i++) | 488 | |
4947 | 457 | { | 489 | auto category_position = categories_.begin() + index; |
4948 | 458 | unsigned desired_category_index = order[i]; | 490 | PlacesGroup* existing_group = *category_position; |
4949 | 459 | for (unsigned j = 0; j < child_views.size(); j++) | 491 | categories_.erase(category_position); |
4950 | 460 | { | 492 | counts_.erase(existing_group); |
4951 | 461 | if (child_views[j]->GetCategoryIndex() == desired_category_index) | 493 | |
4952 | 462 | { | 494 | RemoveChild(existing_group); |
4953 | 463 | scroll_layout_->AddView(child_views[j].GetPointer(), 0); | 495 | scroll_layout_->RemoveChildObject(existing_group); |
4954 | 464 | break; | 496 | QueueRelayout(); |
4955 | 465 | } | 497 | } |
4956 | 466 | } | 498 | |
4957 | 467 | } | 499 | void ScopeView::ClearCategories() |
4958 | 468 | } | 500 | { |
4959 | 469 | } | 501 | for (auto category_position = categories_.begin(), end = categories_.end(); category_position != end; ++category_position) |
4960 | 470 | 502 | { | |
4961 | 471 | bool LensView::ReinitializeFilterModels() | 503 | PlacesGroup* group = *category_position; |
4962 | 472 | { | 504 | RemoveChild(group); |
4963 | 473 | if (!lens_) | 505 | scroll_layout_->RemoveChildObject(group); |
4964 | 506 | } | ||
4965 | 507 | counts_.clear(); | ||
4966 | 508 | categories_.clear(); | ||
4967 | 509 | QueueRelayout(); | ||
4968 | 510 | } | ||
4969 | 511 | |||
4970 | 512 | bool ScopeView::ReinitializeFilterModels() | ||
4971 | 513 | { | ||
4972 | 514 | if (!scope_) | ||
4973 | 474 | return false; | 515 | return false; |
4974 | 475 | 516 | ||
4976 | 476 | Results::Ptr results_model = lens_->results; | 517 | Results::Ptr results_model = scope_->results; |
4977 | 477 | for (unsigned i = last_good_filter_model_ + 1; i < categories_.size(); ++i) | 518 | for (unsigned i = last_good_filter_model_ + 1; i < categories_.size(); ++i) |
4978 | 478 | { | 519 | { |
4979 | 479 | ResultViewGrid* grid = GetGridForCategory(i); | 520 | ResultViewGrid* grid = GetGridForCategory(i); |
4982 | 480 | glib::Object<DeeModel> filter_model(lens_->GetFilterModelForCategory(i)); | 521 | if (grid) |
4983 | 481 | grid->SetModel(filter_model, results_model->GetTag()); | 522 | grid->SetResultsModel(scope_->GetResultsForCategory(i)); |
4984 | 482 | } | 523 | } |
4985 | 483 | 524 | ||
4986 | 484 | last_good_filter_model_ = -1; | 525 | last_good_filter_model_ = -1; |
4987 | @@ -486,21 +527,21 @@ | |||
4988 | 486 | return false; | 527 | return false; |
4989 | 487 | } | 528 | } |
4990 | 488 | 529 | ||
4992 | 489 | ResultViewGrid* LensView::GetGridForCategory(unsigned category_index) | 530 | ResultViewGrid* ScopeView::GetGridForCategory(unsigned category_index) |
4993 | 490 | { | 531 | { |
4994 | 491 | if (category_index >= categories_.size()) return nullptr; | 532 | if (category_index >= categories_.size()) return nullptr; |
4995 | 492 | PlacesGroup* group = categories_.at(category_index); | 533 | PlacesGroup* group = categories_.at(category_index); |
4996 | 493 | return static_cast<ResultViewGrid*>(group->GetChildView()); | 534 | return static_cast<ResultViewGrid*>(group->GetChildView()); |
4997 | 494 | } | 535 | } |
4998 | 495 | 536 | ||
5000 | 496 | ResultView* LensView::GetResultViewForCategory(unsigned category_index) | 537 | ResultView* ScopeView::GetResultViewForCategory(unsigned category_index) |
334 +const std::string ALWAYS_ SEARCH_ SETTINGS_ KEY = "always-search";
This is only relevant for the home scope implementation, unity doesn't need to know. All it needs are the scopes key, which it displays icons in LensBar for.
3010 + <default>[ 'home.scope' , 'applications. scope' ]</default>
We'll need to change the default before merging (to include files, music etc). Order is already specified by design in bug 1056196.