Merge lp:~mhr3/unity/update-core-preview-api into lp:unity
- update-core-preview-api
- Merge into trunk
| Status: | Merged |
|---|---|
| Approved by: | Didier Roche on 2012-07-18 |
| Approved revision: | 2445 |
| Merged at revision: | 2510 |
| Proposed branch: | lp:~mhr3/unity/update-core-preview-api |
| Merge into: | lp:unity |
| Diff against target: |
2547 lines (+1668/-359) 27 files modified
CMakeLists.txt (+2/-2) UnityCore/ApplicationPreview.cpp (+74/-19) UnityCore/ApplicationPreview.h (+15/-16) UnityCore/CMakeLists.txt (+11/-3) UnityCore/Filter.cpp (+6/-6) UnityCore/GenericPreview.cpp (+11/-19) UnityCore/GenericPreview.h (+4/-18) UnityCore/Lens.cpp (+99/-23) UnityCore/Lens.h (+7/-1) UnityCore/ModelRowAdaptor.cpp (+14/-0) UnityCore/ModelRowAdaptor.h (+2/-0) UnityCore/MoviePreview.cpp (+82/-0) UnityCore/MoviePreview.h (+55/-0) UnityCore/MusicPreview.cpp (+83/-59) UnityCore/MusicPreview.h (+23/-68) UnityCore/Preview.cpp (+228/-73) UnityCore/Preview.h (+81/-15) UnityCore/SeriesPreview.cpp (+149/-0) UnityCore/SeriesPreview.h (+73/-0) UnityCore/Track.cpp (+66/-0) UnityCore/Track.h (+68/-0) UnityCore/Tracks.cpp (+58/-0) UnityCore/Tracks.h (+54/-0) tests/CMakeLists.txt (+1/-0) tests/test_lens.cpp (+97/-30) tests/test_previews.cpp (+262/-0) tests/test_service_lens.c (+43/-7) |
| To merge this branch: | bzr merge lp:~mhr3/unity/update-core-preview-api |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| jenkins (community) | continuous-integration | Needs Fixing on 2012-07-17 | |
| Marco Trevisan (Treviño) | Approve on 2012-07-02 | ||
| Gord Allott (community) | 2012-06-29 | Approve on 2012-06-29 | |
|
Review via email:
|
|||
Commit Message
Updated the Preview API present in UnityCore to match latest protocol used by libunity
Description of the Change
Updated the Preview API present in UnityCore to match latest protocol used by libunity.
Added both deserialization unit-tests as well as communication integration tests with the testlens service.
| Gord Allott (gordallott) wrote : | # |
303 + //unsigned int date_modified;
304 + //unsigned int size;
305 + //std::string type;
probably don't want to leave commented out stuff in public headers
apart from that, had a few q's resolved over irc, approving here.
| jenkins (martin-mrazik+qa) wrote : | # |
FAILED: Continuous integration, rev:2437
http://
| jenkins (martin-mrazik+qa) wrote : | # |
FAILED: Continuous integration, rev:2438
http://
| Marco Trevisan (Treviño) (3v1n0) wrote : | # |
+ glib::Object<GIcon> icon(unity_
93 + glib::AddRef());
94 + app_icon_ = icon;
doing just:
app_icon_ = unity_protocol_
does not work here?
+ glib::String activation_
Why not instead:
std::string activation_uri = action_id + ":" + uri;
std::string renderer_name(
1125 + unity_protocol_
1126 + UNITY_PROTOCOL_
I've read this is always non-null... But maybe a check can avoid any change on the library side...
| Michal Hruby (mhr3) wrote : | # |
> + glib::Object<GIcon>
> icon(unity_
> 93 + glib::AddRef());
> 94 + app_icon_ = icon;
>
> doing just:
>
> app_icon_ = unity_protocol_
>
> does not work here?
Wouldn't that try to consume a reference which is doesn't get? (_get_app_icon() return unowned instance)
>
> + glib::String activation_
> uri.c_str()));
>
> Why not instead:
> std::string activation_uri = action_id + ":" + uri;
>
Fewer temporary objects? :)
> std::string renderer_name(
> 1125 + unity_protocol_
> 1126 + UNITY_PROTOCOL_
>
> I've read this is always non-null... But maybe a check can avoid any change on
> the library side...
I'd rather keep it this way, this call returning null would be a bug in the library, if that ever happens we'd notice it easier.
| Marco Trevisan (Treviño) (3v1n0) wrote : | # |
> > app_icon_ = unity_protocol_
> >
> > does not work here?
>
> Wouldn't that try to consume a reference which is doesn't get?
> (_get_app_icon() return unowned instance)
Ah, ok if you need to reference it, that's fine. Using a temporary object should be fine as well...
> > + glib::String activation_
> > uri.c_str()));
> >
> > Why not instead:
> > std::string activation_uri = action_id + ":" + uri;
> >
>
> Fewer temporary objects? :)
Oh, yes... But as it doesn't seem a so critical code path, I thought you could have been more C++ friendly, without the need to allocate a glib::String, free it and generate a new std::string.
If you just want to avoid temporary objects, you can have the same with:
std::string activation_uri = action_id;
activation_uri += ':';
activation_uri += uri;
| Michal Hruby (mhr3) wrote : | # |
> Oh, yes... But as it doesn't seem a so critical code path, I thought you could
> have been more C++ friendly, without the need to allocate a glib::String, free
> it and generate a new std::string.
> If you just want to avoid temporary objects, you can have the same with:
>
> std::string activation_uri = action_id;
> activation_uri += ':';
> activation_uri += uri;
Ok, if you like std::strings so much :)
| jenkins (martin-mrazik+qa) wrote : | # |
FAILED: Continuous integration, rev:2439
http://
| jenkins (martin-mrazik+qa) wrote : | # |
FAILED: Continuous integration, rev:2440
http://
| Nick Dedekind (nick-dedekind) wrote : | # |
Couple of ommissions:
dash::Preview:
dash::Applicati
| Michal Hruby (mhr3) wrote : | # |
> Couple of ommissions:
> dash::Preview:
> dash::Applicati
Fixed.
| Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
| Timo Jyrinki (timo-jyrinki) wrote : | # |
As a comment, even giving LD_LIBRARY_
One can reproduce the build problem with bzr branch lp:ubuntu/unity, bzr merge lp:unity, bzr merge lp:~mhr3/unity/update-core-preview-api, bzr bd
So far I haven't found how private libraries from other packages should be properly used.
| jenkins (martin-mrazik+qa) wrote : | # |
FAILED: Continuous integration, rev:2442
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
| Martin Mrazik (mrazik) wrote : | # |
The jenkins failure above (unity-ci job) is because of connectivity issues to us.archive.
- 2443. By Michal Hruby on 2012-07-17
-
Use enum for Track play_state, not just a bool
| jenkins (martin-mrazik+qa) wrote : | # |
FAILED: Continuous integration, rev:2443
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
- 2444. By Michal Hruby on 2012-07-17
-
Merge trunk
- 2445. By Michal Hruby on 2012-07-17
-
Get rid of NoReplyCallback usage, as it disappeared
| jenkins (martin-mrazik+qa) wrote : | # |
FAILED: Continuous integration, rev:2445
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Preview Diff
| 1 | === modified file 'CMakeLists.txt' |
| 2 | --- CMakeLists.txt 2012-07-09 07:51:54 +0000 |
| 3 | +++ CMakeLists.txt 2012-07-17 13:45:25 +0000 |
| 4 | @@ -133,8 +133,8 @@ |
| 5 | # |
| 6 | # Compiz Plugins |
| 7 | # |
| 8 | - |
| 9 | -set (UNITY_PLUGIN_DEPS "compiz;nux-3.0>=3.0.0;libbamf3;dee-1.0;gio-2.0;gio-unix-2.0;dbusmenu-glib-0.4;x11;libstartup-notification-1.0;gthread-2.0;indicator3-0.4>=0.4.90;atk;unity-misc>=0.4.0;gconf-2.0;libutouch-geis;gtk+-3.0>=3.1;sigc++-2.0;json-glib-1.0;libnotify;xfixes") |
| 10 | +set (UNITY_PLUGIN_DEPS "compiz;nux-3.0>=3.0.0;libbamf3;dee-1.0;gio-2.0;gio-unix-2.0;dbusmenu-glib-0.4;x11;libstartup-notification-1.0;gthread-2.0;indicator3-0.4>=0.4.90;atk;unity-misc>=0.4.0;gconf-2.0;libutouch-geis;gtk+-3.0>=3.1;sigc++-2.0;json-glib-1.0;libnotify;xfixes;unity-protocol-private") |
| 11 | +# FIXME: unity-protocol-private shouldn't be there, but building of unityshell is just broken |
| 12 | |
| 13 | find_package (PkgConfig) |
| 14 | pkg_check_modules (CACHED_UNITY_DEPS REQUIRED ${UNITY_PLUGIN_DEPS}) |
| 15 | |
| 16 | === modified file 'UnityCore/ApplicationPreview.cpp' |
| 17 | --- UnityCore/ApplicationPreview.cpp 2011-08-02 22:50:10 +0000 |
| 18 | +++ UnityCore/ApplicationPreview.cpp 2012-07-17 13:45:25 +0000 |
| 19 | @@ -1,6 +1,6 @@ |
| 20 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 21 | /* |
| 22 | - * Copyright (C) 2011 Canonical Ltd |
| 23 | + * Copyright (C) 2011-2012 Canonical Ltd |
| 24 | * |
| 25 | * This program is free software: you can redistribute it and/or modify |
| 26 | * it under the terms of the GNU General Public License version 3 as |
| 27 | @@ -15,8 +15,11 @@ |
| 28 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 29 | * |
| 30 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 31 | + * Michal Hruby <michal.hruby@canonical.com> |
| 32 | */ |
| 33 | |
| 34 | +#include <unity-protocol.h> |
| 35 | + |
| 36 | #include "ApplicationPreview.h" |
| 37 | |
| 38 | namespace unity |
| 39 | @@ -24,24 +27,76 @@ |
| 40 | namespace dash |
| 41 | { |
| 42 | |
| 43 | -ApplicationPreview::ApplicationPreview(Preview::Properties& properties) |
| 44 | - : name(PropertyToString(properties, "name")) |
| 45 | - , version(PropertyToString(properties, "version")) |
| 46 | - , size(PropertyToString(properties, "size")) |
| 47 | - , license(PropertyToString(properties, "license")) |
| 48 | - , last_updated(PropertyToString(properties, "last-updated")) |
| 49 | - , rating(PropertyToFloat(properties, "rating")) |
| 50 | - , n_ratings(PropertyToUnsignedInt(properties, "n-ratings")) |
| 51 | - , description(PropertyToString(properties, "string")) |
| 52 | - , icon_hint(PropertyToString(properties, "icon-hint")) |
| 53 | - , screenshot_icon_hint(PropertyToString(properties, "screenshot-icon-hint")) |
| 54 | - , primary_action_name(PropertyToString(properties, "primary-action-name")) |
| 55 | - , primary_action_icon_hint(PropertyToString(properties, "primary-action-icon-hint")) |
| 56 | - , primary_action_uri(PropertyToString(properties, "primary-action-uri")) |
| 57 | -{ |
| 58 | - renderer_name = "preview-application"; |
| 59 | -} |
| 60 | - |
| 61 | +class ApplicationPreview::Impl |
| 62 | +{ |
| 63 | +public: |
| 64 | + Impl(ApplicationPreview* owner, glib::Object<GObject> const& proto_obj); |
| 65 | + |
| 66 | + void SetupGetters(); |
| 67 | + std::string get_last_update() { return last_update_; }; |
| 68 | + std::string get_copyright() { return copyright_; }; |
| 69 | + std::string get_license() { return license_; }; |
| 70 | + glib::Object<GIcon> get_app_icon() { return app_icon_; }; |
| 71 | + float get_rating() const { return rating_; }; |
| 72 | + unsigned int get_num_ratings() const { return num_ratings_; }; |
| 73 | + |
| 74 | + ApplicationPreview* owner_; |
| 75 | + |
| 76 | + std::string last_update_; |
| 77 | + std::string copyright_; |
| 78 | + std::string license_; |
| 79 | + glib::Object<GIcon> app_icon_; |
| 80 | + float rating_; |
| 81 | + unsigned int num_ratings_; |
| 82 | +}; |
| 83 | + |
| 84 | +ApplicationPreview::Impl::Impl(ApplicationPreview* owner, glib::Object<GObject> const& proto_obj) |
| 85 | + : owner_(owner) |
| 86 | +{ |
| 87 | + const gchar* s; |
| 88 | + auto preview = glib::object_cast<UnityProtocolApplicationPreview>(proto_obj); |
| 89 | + |
| 90 | + s = unity_protocol_application_preview_get_last_update(preview); |
| 91 | + if (s) last_update_ = s; |
| 92 | + s = unity_protocol_application_preview_get_copyright(preview); |
| 93 | + if (s) copyright_ = s; |
| 94 | + s = unity_protocol_application_preview_get_license(preview); |
| 95 | + if (s) license_ = s; |
| 96 | + |
| 97 | + glib::Object<GIcon> icon(unity_protocol_application_preview_get_app_icon(preview), |
| 98 | + glib::AddRef()); |
| 99 | + app_icon_ = icon; |
| 100 | + rating_ = unity_protocol_application_preview_get_rating(preview); |
| 101 | + num_ratings_ = unity_protocol_application_preview_get_num_ratings(preview); |
| 102 | + |
| 103 | + SetupGetters(); |
| 104 | +} |
| 105 | + |
| 106 | +void ApplicationPreview::Impl::SetupGetters() |
| 107 | +{ |
| 108 | + owner_->last_update.SetGetterFunction( |
| 109 | + sigc::mem_fun(this, &ApplicationPreview::Impl::get_last_update)); |
| 110 | + owner_->copyright.SetGetterFunction( |
| 111 | + sigc::mem_fun(this, &ApplicationPreview::Impl::get_copyright)); |
| 112 | + owner_->license.SetGetterFunction( |
| 113 | + sigc::mem_fun(this, &ApplicationPreview::Impl::get_license)); |
| 114 | + owner_->app_icon.SetGetterFunction( |
| 115 | + sigc::mem_fun(this, &ApplicationPreview::Impl::get_app_icon)); |
| 116 | + owner_->rating.SetGetterFunction( |
| 117 | + sigc::mem_fun(this, &ApplicationPreview::Impl::get_rating)); |
| 118 | + owner_->num_ratings.SetGetterFunction( |
| 119 | + sigc::mem_fun(this, &ApplicationPreview::Impl::get_num_ratings)); |
| 120 | +} |
| 121 | + |
| 122 | +ApplicationPreview::ApplicationPreview(unity::glib::Object<GObject> const& proto_obj) |
| 123 | + : Preview(proto_obj) |
| 124 | + , pimpl(new Impl(this, proto_obj)) |
| 125 | +{ |
| 126 | +} |
| 127 | + |
| 128 | +ApplicationPreview::~ApplicationPreview() |
| 129 | +{ |
| 130 | +} |
| 131 | |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | === modified file 'UnityCore/ApplicationPreview.h' |
| 136 | --- UnityCore/ApplicationPreview.h 2011-08-02 22:50:10 +0000 |
| 137 | +++ UnityCore/ApplicationPreview.h 2012-07-17 13:45:25 +0000 |
| 138 | @@ -1,6 +1,6 @@ |
| 139 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 140 | /* |
| 141 | - * Copyright (C) 2011 Canonical Ltd |
| 142 | + * Copyright (C) 2011-2012 Canonical Ltd |
| 143 | * |
| 144 | * This program is free software: you can redistribute it and/or modify |
| 145 | * it under the terms of the GNU General Public License version 3 as |
| 146 | @@ -15,6 +15,7 @@ |
| 147 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 148 | * |
| 149 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 150 | + * Michal Hruby <michal.hruby@canonical.com> |
| 151 | */ |
| 152 | |
| 153 | #ifndef UNITY_APPLICATION_PREVIEW_H |
| 154 | @@ -36,21 +37,19 @@ |
| 155 | public: |
| 156 | typedef std::shared_ptr<ApplicationPreview> Ptr; |
| 157 | |
| 158 | - ApplicationPreview(Preview::Properties& properties); |
| 159 | - |
| 160 | - std::string name; |
| 161 | - std::string version; |
| 162 | - std::string size; |
| 163 | - std::string license; |
| 164 | - std::string last_updated; |
| 165 | - float rating; |
| 166 | - uint n_ratings; |
| 167 | - std::string description; |
| 168 | - std::string icon_hint; |
| 169 | - std::string screenshot_icon_hint; |
| 170 | - std::string primary_action_name; |
| 171 | - std::string primary_action_icon_hint; |
| 172 | - std::string primary_action_uri; |
| 173 | + ApplicationPreview(unity::glib::Object<GObject> const& proto_obj); |
| 174 | + ~ApplicationPreview(); |
| 175 | + |
| 176 | + nux::RWProperty<std::string> last_update; |
| 177 | + nux::RWProperty<std::string> copyright; |
| 178 | + nux::RWProperty<std::string> license; |
| 179 | + nux::RWProperty<glib::Object<GIcon>> app_icon; |
| 180 | + nux::RWProperty<float> rating; |
| 181 | + nux::RWProperty<unsigned int> num_ratings; |
| 182 | + |
| 183 | +private: |
| 184 | + class Impl; |
| 185 | + std::unique_ptr<Impl> pimpl; |
| 186 | }; |
| 187 | |
| 188 | } |
| 189 | |
| 190 | === modified file 'UnityCore/CMakeLists.txt' |
| 191 | --- UnityCore/CMakeLists.txt 2012-06-29 21:00:00 +0000 |
| 192 | +++ UnityCore/CMakeLists.txt 2012-07-17 13:45:25 +0000 |
| 193 | @@ -1,5 +1,5 @@ |
| 194 | find_package (PkgConfig) |
| 195 | -pkg_check_modules (CORE_DEPS REQUIRED glib-2.0 gio-2.0 dee-1.0 sigc++-2.0 nux-core-3.0 gdk-pixbuf-2.0 unity) |
| 196 | +pkg_check_modules (CORE_DEPS REQUIRED glib-2.0 gio-2.0 dee-1.0 sigc++-2.0 nux-core-3.0 gdk-pixbuf-2.0 unity-protocol-private) |
| 197 | |
| 198 | execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} unity --variable lensesdir OUTPUT_VARIABLE _lensesdir OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 199 | |
| 200 | @@ -31,8 +31,9 @@ |
| 201 | Indicators.h |
| 202 | Lens.h |
| 203 | Lenses.h |
| 204 | + MoviePreview.h |
| 205 | MultiRangeFilter.h |
| 206 | - MusicPreviews.h |
| 207 | + MusicPreview.h |
| 208 | Model.h |
| 209 | Model-inl.h |
| 210 | ModelRowAdaptor.h |
| 211 | @@ -42,6 +43,9 @@ |
| 212 | RatingsFilter.h |
| 213 | Result.h |
| 214 | Results.h |
| 215 | + SeriesPreview.h |
| 216 | + Track.h |
| 217 | + Tracks.h |
| 218 | Variant.h |
| 219 | ) |
| 220 | |
| 221 | @@ -67,14 +71,18 @@ |
| 222 | IndicatorEntry.cpp |
| 223 | Indicators.cpp |
| 224 | Lens.cpp |
| 225 | + MoviePreview.cpp |
| 226 | MultiRangeFilter.cpp |
| 227 | - MusicPreviews.cpp |
| 228 | + MusicPreview.cpp |
| 229 | ModelRowAdaptor.cpp |
| 230 | Preview.cpp |
| 231 | RatingsFilter.cpp |
| 232 | RadioOptionFilter.cpp |
| 233 | Result.cpp |
| 234 | Results.cpp |
| 235 | + SeriesPreview.cpp |
| 236 | + Track.cpp |
| 237 | + Tracks.cpp |
| 238 | Variant.cpp |
| 239 | ) |
| 240 | |
| 241 | |
| 242 | === modified file 'UnityCore/Filter.cpp' |
| 243 | --- UnityCore/Filter.cpp 2012-06-18 02:57:23 +0000 |
| 244 | +++ UnityCore/Filter.cpp 2012-07-17 13:45:25 +0000 |
| 245 | @@ -113,11 +113,6 @@ |
| 246 | ignore_changes_ = ignore; |
| 247 | } |
| 248 | |
| 249 | -void Filter::OnModelDestroyed(Filter* self, DeeModel* old_location) |
| 250 | -{ |
| 251 | - self->OnRowRemoved(self->model_, self->iter_); |
| 252 | -} |
| 253 | - |
| 254 | void Filter::OnRowChanged(DeeModel* model, DeeModelIter* iter) |
| 255 | { |
| 256 | if (iter_ != iter || ignore_changes_) |
| 257 | @@ -132,12 +127,17 @@ |
| 258 | filtering.EmitChanged(get_filtering()); |
| 259 | } |
| 260 | |
| 261 | +void Filter::OnModelDestroyed(Filter* self, DeeModel* old_location) |
| 262 | +{ |
| 263 | + self->model_ = 0; |
| 264 | + self->OnRowRemoved(old_location, self->iter_); |
| 265 | +} |
| 266 | + |
| 267 | void Filter::OnRowRemoved(DeeModel* model, DeeModelIter* iter) |
| 268 | { |
| 269 | if (iter_ != iter) |
| 270 | return; |
| 271 | |
| 272 | - model_ = 0; |
| 273 | iter_ = 0; |
| 274 | removed.emit(); |
| 275 | } |
| 276 | |
| 277 | === modified file 'UnityCore/GenericPreview.cpp' |
| 278 | --- UnityCore/GenericPreview.cpp 2011-08-02 22:58:20 +0000 |
| 279 | +++ UnityCore/GenericPreview.cpp 2012-07-17 13:45:25 +0000 |
| 280 | @@ -1,6 +1,6 @@ |
| 281 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 282 | /* |
| 283 | - * Copyright (C) 2011 Canonical Ltd |
| 284 | + * Copyright (C) 2011-2012 Canonical Ltd |
| 285 | * |
| 286 | * This program is free software: you can redistribute it and/or modify |
| 287 | * it under the terms of the GNU General Public License version 3 as |
| 288 | @@ -15,8 +15,11 @@ |
| 289 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 290 | * |
| 291 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 292 | + * Michal Hruby <michal.hruby@canonical.com> |
| 293 | */ |
| 294 | |
| 295 | +#include <unity-protocol.h> |
| 296 | + |
| 297 | #include "GenericPreview.h" |
| 298 | |
| 299 | namespace unity |
| 300 | @@ -24,24 +27,13 @@ |
| 301 | namespace dash |
| 302 | { |
| 303 | |
| 304 | -GenericPreview::GenericPreview(Preview::Properties& properties) |
| 305 | - : name(PropertyToString(properties, "name")) |
| 306 | - , date_modified(PropertyToUnsignedInt(properties, "date-modified")) |
| 307 | - , size(PropertyToUnsignedInt(properties, "size")) |
| 308 | - , type(PropertyToString(properties, "type")) |
| 309 | - , description(PropertyToString(properties, "string")) |
| 310 | - , icon_hint(PropertyToString(properties, "icon-hint")) |
| 311 | - , primary_action_name(PropertyToString(properties, "primary-action-name")) |
| 312 | - , primary_action_icon_hint(PropertyToString(properties, "primary-action-icon-hint")) |
| 313 | - , primary_action_uri(PropertyToString(properties, "primary-action-uri")) |
| 314 | - , secondary_action_name(PropertyToString(properties, "secondary-action-name")) |
| 315 | - , secondary_action_icon_hint(PropertyToString(properties, "secondary-action-icon-hint")) |
| 316 | - , secondary_action_uri(PropertyToString(properties, "secondary-action-uri")) |
| 317 | - , tertiary_action_name(PropertyToString(properties, "tertiary-action-name")) |
| 318 | - , tertiary_action_icon_hint(PropertyToString(properties, "tertiary-action-icon-hint")) |
| 319 | - , tertiary_action_uri(PropertyToString(properties, "tertiary-action-uri")) |
| 320 | -{ |
| 321 | - renderer_name = "preview-generic"; |
| 322 | +GenericPreview::GenericPreview(unity::glib::Object<GObject> const& proto_obj) |
| 323 | + : Preview(proto_obj) |
| 324 | +{ |
| 325 | +} |
| 326 | + |
| 327 | +GenericPreview::~GenericPreview() |
| 328 | +{ |
| 329 | } |
| 330 | |
| 331 | |
| 332 | |
| 333 | === modified file 'UnityCore/GenericPreview.h' |
| 334 | --- UnityCore/GenericPreview.h 2011-08-02 22:58:20 +0000 |
| 335 | +++ UnityCore/GenericPreview.h 2012-07-17 13:45:25 +0000 |
| 336 | @@ -1,6 +1,6 @@ |
| 337 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 338 | /* |
| 339 | - * Copyright (C) 2011 Canonical Ltd |
| 340 | + * Copyright (C) 2011-2012 Canonical Ltd |
| 341 | * |
| 342 | * This program is free software: you can redistribute it and/or modify |
| 343 | * it under the terms of the GNU General Public License version 3 as |
| 344 | @@ -15,6 +15,7 @@ |
| 345 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 346 | * |
| 347 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 348 | + * Michal Hruby <michal.hruby@canonical.com> |
| 349 | */ |
| 350 | |
| 351 | #ifndef UNITY_GENERIC_PREVIEW_H |
| 352 | @@ -36,23 +37,8 @@ |
| 353 | public: |
| 354 | typedef std::shared_ptr<GenericPreview> Ptr; |
| 355 | |
| 356 | - GenericPreview(Preview::Properties& properties); |
| 357 | - |
| 358 | - std::string name; |
| 359 | - unsigned int date_modified; |
| 360 | - unsigned int size; |
| 361 | - std::string type; |
| 362 | - std::string description; |
| 363 | - std::string icon_hint; |
| 364 | - std::string primary_action_name; |
| 365 | - std::string primary_action_icon_hint; |
| 366 | - std::string primary_action_uri; |
| 367 | - std::string secondary_action_name; |
| 368 | - std::string secondary_action_icon_hint; |
| 369 | - std::string secondary_action_uri; |
| 370 | - std::string tertiary_action_name; |
| 371 | - std::string tertiary_action_icon_hint; |
| 372 | - std::string tertiary_action_uri; |
| 373 | + GenericPreview(unity::glib::Object<GObject> const& proto_obj); |
| 374 | + ~GenericPreview(); |
| 375 | }; |
| 376 | |
| 377 | } |
| 378 | |
| 379 | === modified file 'UnityCore/Lens.cpp' |
| 380 | --- UnityCore/Lens.cpp 2012-03-14 06:24:18 +0000 |
| 381 | +++ UnityCore/Lens.cpp 2012-07-17 13:45:25 +0000 |
| 382 | @@ -22,6 +22,7 @@ |
| 383 | #include <gio/gio.h> |
| 384 | #include <glib.h> |
| 385 | #include <NuxCore/Logger.h> |
| 386 | +#include <unity-protocol.h> |
| 387 | |
| 388 | #include "config.h" |
| 389 | #include "GLibDBusProxy.h" |
| 390 | @@ -84,7 +85,11 @@ |
| 391 | void Activate(std::string const& uri); |
| 392 | void ActivationReply(GVariant* parameters); |
| 393 | void Preview(std::string const& uri); |
| 394 | - void PreviewReply(GVariant* parameters); |
| 395 | + void ActivatePreviewAction(std::string const& action_id, |
| 396 | + std::string const& uri); |
| 397 | + void SignalPreview(std::string const& preview_uri, |
| 398 | + glib::Variant const& preview_update, |
| 399 | + glib::DBusProxy::ReplyCallback reply_cb); |
| 400 | |
| 401 | string const& id() const; |
| 402 | string const& dbus_name() const; |
| 403 | @@ -126,6 +131,7 @@ |
| 404 | glib::DBusProxy* proxy_; |
| 405 | glib::Object<GCancellable> search_cancellable_; |
| 406 | glib::Object<GCancellable> global_search_cancellable_; |
| 407 | + glib::Object<GCancellable> preview_cancellable_; |
| 408 | |
| 409 | GVariant *results_variant_; |
| 410 | GVariant *global_results_variant_; |
| 411 | @@ -495,7 +501,8 @@ |
| 412 | } |
| 413 | |
| 414 | proxy_->Call("Activate", |
| 415 | - g_variant_new("(su)", uri.c_str(), 0), |
| 416 | + g_variant_new("(su)", uri.c_str(), |
| 417 | + UNITY_PROTOCOL_ACTION_TYPE_ACTIVATE_RESULT), |
| 418 | sigc::mem_fun(this, &Lens::Impl::ActivationReply)); |
| 419 | } |
| 420 | |
| 421 | @@ -511,7 +518,29 @@ |
| 422 | glib::Variant dict (hints_variant, glib::StealRef()); |
| 423 | dict.ASVToHints(hints); |
| 424 | |
| 425 | - owner_->activated.emit(uri.Str(), static_cast<HandledType>(handled), hints); |
| 426 | + if (handled == UNITY_PROTOCOL_HANDLED_TYPE_SHOW_PREVIEW) |
| 427 | + { |
| 428 | + auto iter = hints.find("preview"); |
| 429 | + if (iter != hints.end()) |
| 430 | + { |
| 431 | + Preview::Ptr preview(Preview::PreviewForVariant(iter->second)); |
| 432 | + if (preview) |
| 433 | + { |
| 434 | + // would be nice to make parent_lens a shared_ptr, |
| 435 | + // but that's not really doable from here |
| 436 | + preview->parent_lens = owner_; |
| 437 | + preview->preview_uri = uri.Str(); |
| 438 | + owner_->preview_ready.emit(uri.Str(), preview); |
| 439 | + return; |
| 440 | + } |
| 441 | + } |
| 442 | + |
| 443 | + LOG_WARNING(logger) << "Unable to deserialize Preview"; |
| 444 | + } |
| 445 | + else |
| 446 | + { |
| 447 | + owner_->activated.emit(uri.Str(), static_cast<HandledType>(handled), hints); |
| 448 | + } |
| 449 | } |
| 450 | |
| 451 | void Lens::Impl::Preview(std::string const& uri) |
| 452 | @@ -524,26 +553,59 @@ |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | - proxy_->Call("Preview", |
| 457 | - g_variant_new("(s)", uri.c_str()), |
| 458 | - sigc::mem_fun(this, &Lens::Impl::PreviewReply)); |
| 459 | -} |
| 460 | - |
| 461 | -void Lens::Impl::PreviewReply(GVariant* parameters) |
| 462 | -{ |
| 463 | - glib::String uri; |
| 464 | - glib::String renderer_name; |
| 465 | - GVariant* hints_variant; |
| 466 | - Hints hints; |
| 467 | - |
| 468 | - g_variant_get(parameters, "((ss@a{sv}))", &uri, &renderer_name, &hints_variant); |
| 469 | - |
| 470 | - glib::Variant dict (hints_variant, glib::StealRef()); |
| 471 | - dict.ASVToHints(hints); |
| 472 | - |
| 473 | - Preview::Ptr preview = Preview::PreviewForProperties(renderer_name.Str(), hints); |
| 474 | - owner_->preview_ready.emit(uri.Str(), preview); |
| 475 | -} |
| 476 | + if (preview_cancellable_) |
| 477 | + { |
| 478 | + g_cancellable_cancel(preview_cancellable_); |
| 479 | + } |
| 480 | + preview_cancellable_ = g_cancellable_new (); |
| 481 | + |
| 482 | + proxy_->Call("Activate", |
| 483 | + g_variant_new("(su)", uri.c_str(), |
| 484 | + UNITY_PROTOCOL_ACTION_TYPE_PREVIEW_RESULT), |
| 485 | + sigc::mem_fun(this, &Lens::Impl::ActivationReply), |
| 486 | + preview_cancellable_); |
| 487 | +} |
| 488 | + |
| 489 | +void Lens::Impl::ActivatePreviewAction(std::string const& action_id, |
| 490 | + std::string const& uri) |
| 491 | +{ |
| 492 | + LOG_DEBUG(logger) << "Activating action '" << action_id << "' on '" << id_ << "'"; |
| 493 | + |
| 494 | + if (!proxy_->IsConnected()) |
| 495 | + { |
| 496 | + LOG_DEBUG(logger) << "Skipping activation. Proxy not connected. ('" << id_ << "')"; |
| 497 | + return; |
| 498 | + } |
| 499 | + |
| 500 | + std::string activation_uri(action_id); |
| 501 | + activation_uri += ":"; |
| 502 | + activation_uri += uri; |
| 503 | + |
| 504 | + proxy_->Call("Activate", |
| 505 | + g_variant_new("(su)", activation_uri.c_str(), |
| 506 | + UNITY_PROTOCOL_ACTION_TYPE_PREVIEW_ACTION), |
| 507 | + sigc::mem_fun(this, &Lens::Impl::ActivationReply)); |
| 508 | +} |
| 509 | + |
| 510 | +void Lens::Impl::SignalPreview(std::string const& preview_uri, |
| 511 | + glib::Variant const& preview_update, |
| 512 | + glib::DBusProxy::ReplyCallback reply_cb) |
| 513 | +{ |
| 514 | + LOG_DEBUG(logger) << "Signalling preview '" << preview_uri << "' on '" << id_ << "'"; |
| 515 | + |
| 516 | + if (!proxy_->IsConnected()) |
| 517 | + { |
| 518 | + LOG_DEBUG(logger) << "Can't signal preview. Proxy not connected. ('" << id_ << "')"; |
| 519 | + return; |
| 520 | + } |
| 521 | + |
| 522 | + GVariant *preview_update_variant = preview_update; |
| 523 | + proxy_->Call("UpdatePreviewProperty", |
| 524 | + g_variant_new("(s@a{sv})", preview_uri.c_str(), |
| 525 | + preview_update_variant), |
| 526 | + reply_cb); |
| 527 | +} |
| 528 | + |
| 529 | string const& Lens::Impl::id() const |
| 530 | { |
| 531 | return id_; |
| 532 | @@ -702,5 +764,19 @@ |
| 533 | pimpl->Preview(uri); |
| 534 | } |
| 535 | |
| 536 | +void Lens::ActivatePreviewAction(std::string const& action_id, |
| 537 | + std::string const& uri) |
| 538 | +{ |
| 539 | + pimpl->ActivatePreviewAction(action_id, uri); |
| 540 | +} |
| 541 | + |
| 542 | +void Lens::SignalPreview(std::string const& uri, |
| 543 | + glib::Variant const& preview_update, |
| 544 | + glib::DBusProxy::ReplyCallback reply_cb) |
| 545 | +{ |
| 546 | + pimpl->SignalPreview(uri, preview_update, reply_cb); |
| 547 | +} |
| 548 | + |
| 549 | + |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | === modified file 'UnityCore/Lens.h' |
| 554 | --- UnityCore/Lens.h 2012-03-14 06:24:18 +0000 |
| 555 | +++ UnityCore/Lens.h 2012-07-17 13:45:25 +0000 |
| 556 | @@ -26,6 +26,7 @@ |
| 557 | #include <sigc++/trackable.h> |
| 558 | |
| 559 | #include "Variant.h" |
| 560 | +#include "GLibDBusProxy.h" |
| 561 | #include "Categories.h" |
| 562 | #include "Filters.h" |
| 563 | #include "Preview.h" |
| 564 | @@ -84,6 +85,11 @@ |
| 565 | virtual void Search(std::string const& search_string); |
| 566 | virtual void Activate(std::string const& uri); |
| 567 | virtual void Preview(std::string const& uri); |
| 568 | + virtual void ActivatePreviewAction(std::string const& action_id, |
| 569 | + std::string const& uri); |
| 570 | + virtual void SignalPreview(std::string const& uri, |
| 571 | + glib::Variant const& preview_update, |
| 572 | + glib::DBusProxy::ReplyCallback reply_cb = nullptr); |
| 573 | |
| 574 | nux::RWProperty<std::string> id; |
| 575 | nux::RWProperty<std::string> dbus_name; |
| 576 | @@ -106,7 +112,7 @@ |
| 577 | sigc::signal<void, Hints const&> search_finished; |
| 578 | sigc::signal<void, Hints const&> global_search_finished; |
| 579 | sigc::signal<void, std::string const&, HandledType, Hints const&> activated; |
| 580 | - sigc::signal<void, std::string const&, Preview::Ptr> preview_ready; |
| 581 | + sigc::signal<void, std::string const&, Preview::Ptr const&> preview_ready; |
| 582 | |
| 583 | private: |
| 584 | class Impl; |
| 585 | |
| 586 | === modified file 'UnityCore/ModelRowAdaptor.cpp' |
| 587 | --- UnityCore/ModelRowAdaptor.cpp 2011-11-25 02:46:50 +0000 |
| 588 | +++ UnityCore/ModelRowAdaptor.cpp 2012-07-17 13:45:25 +0000 |
| 589 | @@ -63,6 +63,13 @@ |
| 590 | return dee_model_get_bool(model_, iter_, position); |
| 591 | } |
| 592 | |
| 593 | +int RowAdaptorBase::GetIntAt(int position) |
| 594 | +{ |
| 595 | + if (!model_ || !iter_) |
| 596 | + return 0; |
| 597 | + return dee_model_get_int32(model_, iter_, position); |
| 598 | +} |
| 599 | + |
| 600 | unsigned int RowAdaptorBase::GetUIntAt(int position) |
| 601 | { |
| 602 | if (!model_ || !iter_) |
| 603 | @@ -70,5 +77,12 @@ |
| 604 | return dee_model_get_uint32(model_, iter_, position); |
| 605 | } |
| 606 | |
| 607 | +float RowAdaptorBase::GetFloatAt(int position) |
| 608 | +{ |
| 609 | + if (!model_ || !iter_) |
| 610 | + return 0.0; |
| 611 | + return static_cast<float>(dee_model_get_double(model_, iter_, position)); |
| 612 | +} |
| 613 | + |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | === modified file 'UnityCore/ModelRowAdaptor.h' |
| 618 | --- UnityCore/ModelRowAdaptor.h 2011-07-31 08:39:48 +0000 |
| 619 | +++ UnityCore/ModelRowAdaptor.h 2012-07-17 13:45:25 +0000 |
| 620 | @@ -54,7 +54,9 @@ |
| 621 | |
| 622 | std::string GetStringAt(int position); |
| 623 | bool GetBoolAt(int position); |
| 624 | + int GetIntAt(int position); |
| 625 | unsigned int GetUIntAt(int position); |
| 626 | + float GetFloatAt(int position); |
| 627 | |
| 628 | template<typename T> |
| 629 | void set_renderer(T renderer); |
| 630 | |
| 631 | === added file 'UnityCore/MoviePreview.cpp' |
| 632 | --- UnityCore/MoviePreview.cpp 1970-01-01 00:00:00 +0000 |
| 633 | +++ UnityCore/MoviePreview.cpp 2012-07-17 13:45:25 +0000 |
| 634 | @@ -0,0 +1,82 @@ |
| 635 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 636 | +/* |
| 637 | + * Copyright (C) 2011-2012 Canonical Ltd |
| 638 | + * |
| 639 | + * This program is free software: you can redistribute it and/or modify |
| 640 | + * it under the terms of the GNU General Public License version 3 as |
| 641 | + * published by the Free Software Foundation. |
| 642 | + * |
| 643 | + * This program is distributed in the hope that it will be useful, |
| 644 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 645 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 646 | + * GNU General Public License for more details. |
| 647 | + * |
| 648 | + * You should have received a copy of the GNU General Public License |
| 649 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 650 | + * |
| 651 | + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 652 | + * Michal Hruby <michal.hruby@canonical.com> |
| 653 | + */ |
| 654 | + |
| 655 | +#include <unity-protocol.h> |
| 656 | + |
| 657 | +#include "MoviePreview.h" |
| 658 | + |
| 659 | +namespace unity |
| 660 | +{ |
| 661 | +namespace dash |
| 662 | +{ |
| 663 | + |
| 664 | +class MoviePreview::Impl |
| 665 | +{ |
| 666 | +public: |
| 667 | + Impl(MoviePreview* owner, glib::Object<GObject> const& proto_obj); |
| 668 | + |
| 669 | + void SetupGetters(); |
| 670 | + std::string get_year() const { return year_; }; |
| 671 | + float get_rating() const { return rating_; }; |
| 672 | + unsigned int get_num_ratings() const { return num_ratings_; }; |
| 673 | + |
| 674 | + MoviePreview* owner_; |
| 675 | + |
| 676 | + std::string year_; |
| 677 | + float rating_; |
| 678 | + unsigned int num_ratings_; |
| 679 | +}; |
| 680 | + |
| 681 | +MoviePreview::Impl::Impl(MoviePreview* owner, |
| 682 | + glib::Object<GObject> const& proto_obj) |
| 683 | + : owner_(owner) |
| 684 | +{ |
| 685 | + auto preview = glib::object_cast<UnityProtocolMoviePreview>(proto_obj); |
| 686 | + const gchar* s; |
| 687 | + s = unity_protocol_movie_preview_get_year(preview); |
| 688 | + if (s) year_ = s; |
| 689 | + rating_ = unity_protocol_movie_preview_get_rating(preview); |
| 690 | + num_ratings_ = unity_protocol_movie_preview_get_num_ratings(preview); |
| 691 | + |
| 692 | + SetupGetters(); |
| 693 | +} |
| 694 | + |
| 695 | +void MoviePreview::Impl::SetupGetters() |
| 696 | +{ |
| 697 | + owner_->year.SetGetterFunction( |
| 698 | + sigc::mem_fun(this, &MoviePreview::Impl::get_year)); |
| 699 | + owner_->rating.SetGetterFunction( |
| 700 | + sigc::mem_fun(this, &MoviePreview::Impl::get_rating)); |
| 701 | + owner_->num_ratings.SetGetterFunction( |
| 702 | + sigc::mem_fun(this, &MoviePreview::Impl::get_num_ratings)); |
| 703 | +} |
| 704 | + |
| 705 | +MoviePreview::MoviePreview(unity::glib::Object<GObject> const& proto_obj) |
| 706 | + : Preview(proto_obj) |
| 707 | + , pimpl(new Impl(this, proto_obj)) |
| 708 | +{ |
| 709 | +} |
| 710 | + |
| 711 | +MoviePreview::~MoviePreview() |
| 712 | +{ |
| 713 | +} |
| 714 | + |
| 715 | +} |
| 716 | +} |
| 717 | |
| 718 | === added file 'UnityCore/MoviePreview.h' |
| 719 | --- UnityCore/MoviePreview.h 1970-01-01 00:00:00 +0000 |
| 720 | +++ UnityCore/MoviePreview.h 2012-07-17 13:45:25 +0000 |
| 721 | @@ -0,0 +1,55 @@ |
| 722 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 723 | +/* |
| 724 | + * Copyright (C) 2012 Canonical Ltd |
| 725 | + * |
| 726 | + * This program is free software: you can redistribute it and/or modify |
| 727 | + * it under the terms of the GNU General Public License version 3 as |
| 728 | + * published by the Free Software Foundation. |
| 729 | + * |
| 730 | + * This program is distributed in the hope that it will be useful, |
| 731 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 732 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 733 | + * GNU General Public License for more details. |
| 734 | + * |
| 735 | + * You should have received a copy of the GNU General Public License |
| 736 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 737 | + * |
| 738 | + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 739 | + * Michal Hruby <michal.hruby@canonical.com> |
| 740 | + */ |
| 741 | + |
| 742 | +#ifndef UNITY_MOVIE_PREVIEW_H |
| 743 | +#define UNITY_MOVIE_PREVIEW_H |
| 744 | + |
| 745 | +#include <memory> |
| 746 | + |
| 747 | +#include <sigc++/trackable.h> |
| 748 | + |
| 749 | +#include "Preview.h" |
| 750 | + |
| 751 | +namespace unity |
| 752 | +{ |
| 753 | +namespace dash |
| 754 | +{ |
| 755 | + |
| 756 | +class MoviePreview : public Preview |
| 757 | +{ |
| 758 | +public: |
| 759 | + typedef std::shared_ptr<MoviePreview> Ptr; |
| 760 | + |
| 761 | + MoviePreview(unity::glib::Object<GObject> const& proto_obj); |
| 762 | + ~MoviePreview(); |
| 763 | + |
| 764 | + nux::RWProperty<std::string> year; |
| 765 | + nux::RWProperty<float> rating; |
| 766 | + nux::RWProperty<unsigned int> num_ratings; |
| 767 | + |
| 768 | +private: |
| 769 | + class Impl; |
| 770 | + std::unique_ptr<Impl> pimpl; |
| 771 | +}; |
| 772 | + |
| 773 | +} |
| 774 | +} |
| 775 | + |
| 776 | +#endif |
| 777 | |
| 778 | === renamed file 'UnityCore/MusicPreviews.cpp' => 'UnityCore/MusicPreview.cpp' |
| 779 | --- UnityCore/MusicPreviews.cpp 2011-08-09 12:47:25 +0000 |
| 780 | +++ UnityCore/MusicPreview.cpp 2012-07-17 13:45:25 +0000 |
| 781 | @@ -1,6 +1,6 @@ |
| 782 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 783 | /* |
| 784 | - * Copyright (C) 2011 Canonical Ltd |
| 785 | + * Copyright (C) 2011-2012 Canonical Ltd |
| 786 | * |
| 787 | * This program is free software: you can redistribute it and/or modify |
| 788 | * it under the terms of the GNU General Public License version 3 as |
| 789 | @@ -15,74 +15,98 @@ |
| 790 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 791 | * |
| 792 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 793 | + * Michal Hruby <michal.hruby@canonical.com> |
| 794 | */ |
| 795 | |
| 796 | -#include "MusicPreviews.h" |
| 797 | +#include <unity-protocol.h> |
| 798 | + |
| 799 | +#include "MusicPreview.h" |
| 800 | +#include "Tracks.h" |
| 801 | |
| 802 | namespace unity |
| 803 | { |
| 804 | namespace dash |
| 805 | { |
| 806 | |
| 807 | -TrackPreview::TrackPreview(Preview::Properties& properties) |
| 808 | - : number(PropertyToUnsignedInt(properties, "number")) |
| 809 | - , title(PropertyToString(properties, "title")) |
| 810 | - , artist(PropertyToString(properties, "artist")) |
| 811 | - , album(PropertyToString(properties, "album")) |
| 812 | - , length(PropertyToUnsignedInt(properties, "length")) |
| 813 | - , genres(PropertyToStringVector(properties, "genres")) |
| 814 | - , album_cover(PropertyToString(properties, "album-cover")) |
| 815 | - , primary_action_name(PropertyToString(properties, "primary-action-name")) |
| 816 | - , primary_action_icon_hint(PropertyToString(properties, "primary-action-icon-hint")) |
| 817 | - , primary_action_uri(PropertyToString(properties, "primary-action-uri")) |
| 818 | - , play_action_uri(PropertyToString(properties, "play-action-uri")) |
| 819 | - , pause_action_uri(PropertyToString(properties, "pause-action-uri")) |
| 820 | -{ |
| 821 | - renderer_name = "preview-track"; |
| 822 | -} |
| 823 | - |
| 824 | -AlbumPreview::AlbumPreview(Preview::Properties& properties) |
| 825 | - : name(PropertyToString(properties, "name")) |
| 826 | - , artist(PropertyToString(properties, "artist")) |
| 827 | - , year(PropertyToString(properties, "year")) |
| 828 | - , genres(PropertyToStringVector(properties, "genres")) |
| 829 | - , album_cover(PropertyToString(properties, "album-cover")) |
| 830 | - , primary_action_name(PropertyToString(properties, "primary-action-name")) |
| 831 | - , primary_action_icon_hint(PropertyToString(properties, "primary-action-icon-hint")) |
| 832 | - , primary_action_uri(PropertyToString(properties, "primary-action-uri")) |
| 833 | -{ |
| 834 | - renderer_name = "preview-album"; |
| 835 | - LoadTracks(properties); |
| 836 | -} |
| 837 | - |
| 838 | -void AlbumPreview::LoadTracks(Properties& properties) |
| 839 | -{ |
| 840 | - GVariantIter *iter = NULL; |
| 841 | - unsigned int track_number = 0; |
| 842 | - char* track_title; |
| 843 | - unsigned int track_length = 0; |
| 844 | - char* track_play_uri; |
| 845 | - char* track_pause_uri; |
| 846 | - |
| 847 | - if (properties.find("tracks") == properties.end()) |
| 848 | - return; |
| 849 | - |
| 850 | - g_variant_get(properties["tracks"], "(ususs)", &iter); |
| 851 | - |
| 852 | - while (g_variant_iter_loop(iter, "ususs", |
| 853 | - &track_number, |
| 854 | - &track_title, |
| 855 | - &track_length, |
| 856 | - &track_play_uri, |
| 857 | - &track_pause_uri)) |
| 858 | +class MusicPreview::Impl |
| 859 | +{ |
| 860 | +public: |
| 861 | + Impl(MusicPreview* owner, glib::Object<GObject> const& proto_obj); |
| 862 | + |
| 863 | + void PlayUri(std::string const& uri) const; |
| 864 | + void PauseUri(std::string const& uri) const; |
| 865 | + |
| 866 | + MusicPreview* owner_; |
| 867 | + |
| 868 | + glib::Object<UnityProtocolMusicPreview> raw_preview_; |
| 869 | + Tracks::Ptr tracks_model; |
| 870 | +}; |
| 871 | + |
| 872 | +MusicPreview::Impl::Impl(MusicPreview* owner, |
| 873 | + glib::Object<GObject> const& proto_obj) |
| 874 | + : owner_(owner) |
| 875 | + , tracks_model(new Tracks()) |
| 876 | +{ |
| 877 | + const gchar* s; |
| 878 | + raw_preview_ = glib::object_cast<UnityProtocolMusicPreview>(proto_obj); |
| 879 | + |
| 880 | + s = unity_protocol_music_preview_get_track_data_swarm_name(raw_preview_); |
| 881 | + std::string swarm_name(s != NULL ? s : ""); |
| 882 | + s = unity_protocol_music_preview_get_track_data_address(raw_preview_); |
| 883 | + std::string peer_address(s != NULL ? s : ""); |
| 884 | + |
| 885 | + // TODO: we're not using private connection yet |
| 886 | + if (!swarm_name.empty()) |
| 887 | { |
| 888 | - Track track(track_number, track_title, track_length, track_play_uri, track_pause_uri); |
| 889 | - tracks.push_back(track); |
| 890 | - |
| 891 | - length += track_length; |
| 892 | + tracks_model->swarm_name = swarm_name; |
| 893 | } |
| 894 | - |
| 895 | - g_variant_iter_free(iter); |
| 896 | +} |
| 897 | + |
| 898 | +void MusicPreview::Impl::PlayUri(std::string const& uri) const |
| 899 | +{ |
| 900 | + UnityProtocolPreview *preview = UNITY_PROTOCOL_PREVIEW(raw_preview_.RawPtr()); |
| 901 | + |
| 902 | + unity_protocol_preview_begin_updates(preview); |
| 903 | + unity_protocol_music_preview_play_uri(raw_preview_, uri.c_str()); |
| 904 | + glib::Variant properties(unity_protocol_preview_end_updates(preview), |
| 905 | + glib::StealRef()); |
| 906 | + owner_->Update(properties); |
| 907 | +} |
| 908 | + |
| 909 | +void MusicPreview::Impl::PauseUri(std::string const& uri) const |
| 910 | +{ |
| 911 | + UnityProtocolPreview *preview = UNITY_PROTOCOL_PREVIEW(raw_preview_.RawPtr()); |
| 912 | + |
| 913 | + unity_protocol_preview_begin_updates(preview); |
| 914 | + unity_protocol_music_preview_pause_uri(raw_preview_, uri.c_str()); |
| 915 | + glib::Variant properties(unity_protocol_preview_end_updates(preview), |
| 916 | + glib::StealRef()); |
| 917 | + owner_->Update(properties); |
| 918 | +} |
| 919 | + |
| 920 | +MusicPreview::MusicPreview(unity::glib::Object<GObject> const& proto_obj) |
| 921 | + : Preview(proto_obj) |
| 922 | + , pimpl(new Impl(this, proto_obj)) |
| 923 | +{ |
| 924 | +} |
| 925 | + |
| 926 | +MusicPreview::~MusicPreview() |
| 927 | +{ |
| 928 | +} |
| 929 | + |
| 930 | +Tracks::Ptr MusicPreview::GetTracksModel() const |
| 931 | +{ |
| 932 | + return pimpl->tracks_model; |
| 933 | +} |
| 934 | + |
| 935 | +void MusicPreview::PlayUri(std::string const& uri) const |
| 936 | +{ |
| 937 | + pimpl->PlayUri(uri); |
| 938 | +} |
| 939 | + |
| 940 | +void MusicPreview::PauseUri(std::string const& uri) const |
| 941 | +{ |
| 942 | + pimpl->PauseUri(uri); |
| 943 | } |
| 944 | |
| 945 | } |
| 946 | |
| 947 | === renamed file 'UnityCore/MusicPreviews.h' => 'UnityCore/MusicPreview.h' |
| 948 | --- UnityCore/MusicPreviews.h 2011-08-02 22:50:10 +0000 |
| 949 | +++ UnityCore/MusicPreview.h 2012-07-17 13:45:25 +0000 |
| 950 | @@ -1,6 +1,6 @@ |
| 951 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 952 | /* |
| 953 | - * Copyright (C) 2011 Canonical Ltd |
| 954 | + * Copyright (C) 2011-2012 Canonical Ltd |
| 955 | * |
| 956 | * This program is free software: you can redistribute it and/or modify |
| 957 | * it under the terms of the GNU General Public License version 3 as |
| 958 | @@ -15,87 +15,42 @@ |
| 959 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 960 | * |
| 961 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 962 | + * Michal Hruby <michal.hruby@canonical.com> |
| 963 | */ |
| 964 | |
| 965 | -#ifndef UNITY_MUSIC_PREVIEWS_H |
| 966 | -#define UNITY_MUSIC_PREVIEWS_H |
| 967 | +#ifndef UNITY_MUSIC_PREVIEW_H |
| 968 | +#define UNITY_MUSIC_PREVIEW_H |
| 969 | |
| 970 | #include <memory> |
| 971 | |
| 972 | #include <sigc++/trackable.h> |
| 973 | |
| 974 | #include "Preview.h" |
| 975 | +#include "Tracks.h" |
| 976 | |
| 977 | namespace unity |
| 978 | { |
| 979 | namespace dash |
| 980 | { |
| 981 | |
| 982 | -class TrackPreview : public Preview |
| 983 | -{ |
| 984 | -public: |
| 985 | - typedef std::shared_ptr<TrackPreview> Ptr; |
| 986 | - typedef std::vector<std::string> Genres; |
| 987 | - |
| 988 | - TrackPreview(Preview::Properties& properties); |
| 989 | - |
| 990 | - unsigned int number; |
| 991 | - std::string title; |
| 992 | - std::string artist; |
| 993 | - std::string album; |
| 994 | - unsigned int length; |
| 995 | - Genres genres; |
| 996 | - std::string album_cover; |
| 997 | - std::string primary_action_name; |
| 998 | - std::string primary_action_icon_hint; |
| 999 | - std::string primary_action_uri; |
| 1000 | - std::string play_action_uri; |
| 1001 | - std::string pause_action_uri; |
| 1002 | -}; |
| 1003 | - |
| 1004 | -class AlbumPreview : public Preview |
| 1005 | -{ |
| 1006 | -public: |
| 1007 | - typedef std::shared_ptr<AlbumPreview> Ptr; |
| 1008 | - typedef std::vector<std::string> Genres; |
| 1009 | - |
| 1010 | - struct Track |
| 1011 | - { |
| 1012 | - public: |
| 1013 | - |
| 1014 | - Track(unsigned int number_, std::string title_, unsigned int length_, |
| 1015 | - std::string play_action_uri_, std::string pause_action_uri_) |
| 1016 | - : number(number_) |
| 1017 | - , title(title_) |
| 1018 | - , length(length_) |
| 1019 | - , play_action_uri(play_action_uri_) |
| 1020 | - , pause_action_uri(pause_action_uri_) |
| 1021 | - {} |
| 1022 | - |
| 1023 | - unsigned int number; |
| 1024 | - std::string title; |
| 1025 | - unsigned int length; |
| 1026 | - std::string play_action_uri; |
| 1027 | - std::string pause_action_uri; |
| 1028 | - }; |
| 1029 | - |
| 1030 | - typedef std::vector<Track> Tracks; |
| 1031 | - |
| 1032 | - AlbumPreview(Preview::Properties& properties); |
| 1033 | - |
| 1034 | - void LoadTracks(Properties& properties); |
| 1035 | - |
| 1036 | - std::string name; |
| 1037 | - std::string artist; |
| 1038 | - std::string year; |
| 1039 | - unsigned int length; |
| 1040 | - Genres genres; |
| 1041 | - Tracks tracks; |
| 1042 | - std::string album_cover; |
| 1043 | - std::string primary_action_name; |
| 1044 | - std::string primary_action_icon_hint; |
| 1045 | - std::string primary_action_uri; |
| 1046 | -}; |
| 1047 | +class MusicPreview : public Preview |
| 1048 | +{ |
| 1049 | +public: |
| 1050 | + typedef std::shared_ptr<MusicPreview> Ptr; |
| 1051 | + |
| 1052 | + MusicPreview(unity::glib::Object<GObject> const& proto_obj); |
| 1053 | + ~MusicPreview(); |
| 1054 | + |
| 1055 | + Tracks::Ptr GetTracksModel() const; |
| 1056 | + |
| 1057 | + void PlayUri(std::string const& uri) const; |
| 1058 | + void PauseUri(std::string const& uri) const; |
| 1059 | + |
| 1060 | +private: |
| 1061 | + class Impl; |
| 1062 | + std::unique_ptr<Impl> pimpl; |
| 1063 | +}; |
| 1064 | + |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | === modified file 'UnityCore/Preview.cpp' |
| 1070 | --- UnityCore/Preview.cpp 2011-08-09 12:47:25 +0000 |
| 1071 | +++ UnityCore/Preview.cpp 2012-07-17 13:45:25 +0000 |
| 1072 | @@ -1,6 +1,6 @@ |
| 1073 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 1074 | /* |
| 1075 | - * Copyright (C) 2011 Canonical Ltd |
| 1076 | + * Copyright (C) 2011-2012 Canonical Ltd |
| 1077 | * |
| 1078 | * This program is free software: you can redistribute it and/or modify |
| 1079 | * it under the terms of the GNU General Public License version 3 as |
| 1080 | @@ -15,90 +15,245 @@ |
| 1081 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 1082 | * |
| 1083 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 1084 | + * Michal Hruby <michal.hruby@canonical.com> |
| 1085 | */ |
| 1086 | |
| 1087 | +#include <NuxCore/Logger.h> |
| 1088 | +#include <unity-protocol.h> |
| 1089 | + |
| 1090 | +#include "Lens.h" |
| 1091 | #include "Preview.h" |
| 1092 | |
| 1093 | #include "ApplicationPreview.h" |
| 1094 | #include "GenericPreview.h" |
| 1095 | -#include "MusicPreviews.h" |
| 1096 | +#include "MusicPreview.h" |
| 1097 | +#include "MoviePreview.h" |
| 1098 | +#include "SeriesPreview.h" |
| 1099 | |
| 1100 | namespace unity |
| 1101 | { |
| 1102 | namespace dash |
| 1103 | { |
| 1104 | |
| 1105 | -Preview::Ptr Preview::PreviewForProperties(std::string const& renderer_name_, |
| 1106 | - Properties& properties) |
| 1107 | -{ |
| 1108 | - if (renderer_name_ == "preview-application") |
| 1109 | - { |
| 1110 | - return Preview::Ptr(new ApplicationPreview(properties)); |
| 1111 | - } |
| 1112 | - else if (renderer_name_ == "preview-generic") |
| 1113 | - { |
| 1114 | - return Preview::Ptr(new GenericPreview(properties)); |
| 1115 | - } |
| 1116 | - else if (renderer_name_ == "preview-track") |
| 1117 | - { |
| 1118 | - return Preview::Ptr(new TrackPreview(properties)); |
| 1119 | - } |
| 1120 | - else if (renderer_name_ == "preview-album") |
| 1121 | - { |
| 1122 | - return Preview::Ptr(new AlbumPreview(properties)); |
| 1123 | - } |
| 1124 | - else |
| 1125 | - { |
| 1126 | - return Preview::Ptr(new NoPreview()); |
| 1127 | - } |
| 1128 | +namespace |
| 1129 | +{ |
| 1130 | + nux::logging::Logger logger("unity.dash.preview"); |
| 1131 | +} |
| 1132 | + |
| 1133 | +Preview::Ptr Preview::PreviewForProtocolObject(glib::Object<GObject> const& proto_obj) |
| 1134 | +{ |
| 1135 | + if (!proto_obj || !UNITY_PROTOCOL_IS_PREVIEW(proto_obj.RawPtr())) |
| 1136 | + { |
| 1137 | + LOG_WARN(logger) << "Unable to create Preview object from " << proto_obj.RawPtr(); |
| 1138 | + return nullptr; |
| 1139 | + } |
| 1140 | + |
| 1141 | + std::string renderer_name( |
| 1142 | + unity_protocol_preview_get_renderer_name( |
| 1143 | + UNITY_PROTOCOL_PREVIEW(proto_obj.RawPtr()))); |
| 1144 | + |
| 1145 | + if (renderer_name == "preview-generic") |
| 1146 | + { |
| 1147 | + return Preview::Ptr(new GenericPreview(proto_obj)); |
| 1148 | + } |
| 1149 | + else if (renderer_name == "preview-application") |
| 1150 | + { |
| 1151 | + return Preview::Ptr(new ApplicationPreview(proto_obj)); |
| 1152 | + } |
| 1153 | + else if (renderer_name == "preview-music") |
| 1154 | + { |
| 1155 | + return Preview::Ptr(new MusicPreview(proto_obj)); |
| 1156 | + } |
| 1157 | + else if (renderer_name == "preview-movie") |
| 1158 | + { |
| 1159 | + return Preview::Ptr(new MoviePreview(proto_obj)); |
| 1160 | + } |
| 1161 | + else if (renderer_name == "preview-series") |
| 1162 | + { |
| 1163 | + return Preview::Ptr(new SeriesPreview(proto_obj)); |
| 1164 | + } |
| 1165 | + else |
| 1166 | + { |
| 1167 | + LOG_WARN(logger) << "Unable to create Preview for renderer: " << renderer_name; |
| 1168 | + } |
| 1169 | + |
| 1170 | + return nullptr; |
| 1171 | +} |
| 1172 | + |
| 1173 | +Preview::Ptr Preview::PreviewForVariant(glib::Variant &properties) |
| 1174 | +{ |
| 1175 | + glib::Object<UnityProtocolPreview> preview(unity_protocol_preview_parse(properties)); |
| 1176 | + if (!preview) |
| 1177 | + { |
| 1178 | + LOG_WARN(logger) << "Unable to create Preview object for variant type: " << g_variant_get_type_string(properties); |
| 1179 | + return nullptr; |
| 1180 | + } |
| 1181 | + |
| 1182 | + auto proto_obj = unity::glib::object_cast<GObject>(preview); |
| 1183 | + return PreviewForProtocolObject(proto_obj); |
| 1184 | +} |
| 1185 | + |
| 1186 | +unity::glib::Object<GIcon> Preview::IconForString(std::string const& icon_hint) |
| 1187 | +{ |
| 1188 | + glib::Error error; |
| 1189 | + glib::Object<GIcon> icon(g_icon_new_for_string(icon_hint.c_str(), &error)); |
| 1190 | + |
| 1191 | + if (error) |
| 1192 | + { |
| 1193 | + LOG_WARN(logger) << "Unable to instantiate icon: " << icon_hint; |
| 1194 | + } |
| 1195 | + |
| 1196 | + return icon; |
| 1197 | +} |
| 1198 | + |
| 1199 | +class Preview::Impl |
| 1200 | +{ |
| 1201 | +public: |
| 1202 | + Impl(Preview* owner, glib::Object<GObject> const& proto_obj); |
| 1203 | + |
| 1204 | + void SetupGetters(); |
| 1205 | + std::string get_renderer_name() const { return renderer_name_; }; |
| 1206 | + std::string get_title() const { return title_; }; |
| 1207 | + std::string get_subtitle() const { return subtitle_; }; |
| 1208 | + std::string get_description() const { return description_; }; |
| 1209 | + unity::glib::Object<GIcon> get_image() const { return image_; }; |
| 1210 | + ActionPtrList get_actions() const { return actions_list_; }; |
| 1211 | + InfoHintPtrList get_info_hints() const { return info_hint_list_; }; |
| 1212 | + |
| 1213 | + Lens* get_parent_lens() const { return parent_lens_; }; |
| 1214 | + bool set_parent_lens(Lens* lens) |
| 1215 | + { |
| 1216 | + parent_lens_ = lens; |
| 1217 | + return false; // TODO: do we need the notifications here? |
| 1218 | + }; |
| 1219 | + |
| 1220 | + Preview* owner_; |
| 1221 | + |
| 1222 | + std::string renderer_name_; |
| 1223 | + std::string title_; |
| 1224 | + std::string subtitle_; |
| 1225 | + std::string description_; |
| 1226 | + unity::glib::Object<GIcon> image_; |
| 1227 | + ActionPtrList actions_list_; |
| 1228 | + InfoHintPtrList info_hint_list_; |
| 1229 | + Lens* parent_lens_; |
| 1230 | +}; |
| 1231 | + |
| 1232 | +Preview::Impl::Impl(Preview* owner, glib::Object<GObject> const& proto_obj) |
| 1233 | + : owner_(owner) |
| 1234 | + , parent_lens_(nullptr) |
| 1235 | +{ |
| 1236 | + if (!proto_obj) |
| 1237 | + { |
| 1238 | + LOG_WARN(logger) << "Passed nullptr to Preview constructor"; |
| 1239 | + } |
| 1240 | + else if (UNITY_PROTOCOL_IS_PREVIEW(proto_obj.RawPtr())) |
| 1241 | + { |
| 1242 | + auto preview = glib::object_cast<UnityProtocolPreview>(proto_obj); |
| 1243 | + const gchar *s; |
| 1244 | + // renderer is guaranteed to be non-NULL, if it is it's a bug in proto lib |
| 1245 | + renderer_name_ = unity_protocol_preview_get_renderer_name(preview); |
| 1246 | + s = unity_protocol_preview_get_title(preview); |
| 1247 | + if (s) title_ = s; |
| 1248 | + s = unity_protocol_preview_get_subtitle(preview); |
| 1249 | + if (s) subtitle_ = s; |
| 1250 | + s = unity_protocol_preview_get_description(preview); |
| 1251 | + if (s) description_ = s; |
| 1252 | + glib::Object<GIcon> icon(unity_protocol_preview_get_thumbnail(preview), |
| 1253 | + unity::glib::AddRef()); |
| 1254 | + image_ = icon; |
| 1255 | + |
| 1256 | + int actions_len; |
| 1257 | + auto actions = unity_protocol_preview_get_actions(preview, &actions_len); |
| 1258 | + for (int i = 0; i < actions_len; i++) |
| 1259 | + { |
| 1260 | + UnityProtocolPreviewActionRaw *raw_action = &actions[i]; |
| 1261 | + actions_list_.push_back(std::make_shared<Action>( |
| 1262 | + raw_action->id, raw_action->display_name, |
| 1263 | + raw_action->icon_hint, |
| 1264 | + static_cast<LayoutHint>(raw_action->layout_hint))); |
| 1265 | + } |
| 1266 | + |
| 1267 | + int info_hints_len; |
| 1268 | + auto info_hints = unity_protocol_preview_get_info_hints(preview, &info_hints_len); |
| 1269 | + for (int i = 0; i < info_hints_len; i++) |
| 1270 | + { |
| 1271 | + UnityProtocolInfoHintRaw *raw_hint = &info_hints[i]; |
| 1272 | + info_hint_list_.push_back(std::make_shared<InfoHint>( |
| 1273 | + raw_hint->id, raw_hint->display_name, raw_hint->icon_hint, |
| 1274 | + raw_hint->value)); |
| 1275 | + } |
| 1276 | + } |
| 1277 | + else |
| 1278 | + { |
| 1279 | + LOG_WARN(logger) << "Object passed to Preview constructor isn't UnityProtocolPreview"; |
| 1280 | + } |
| 1281 | + |
| 1282 | + SetupGetters(); |
| 1283 | +} |
| 1284 | + |
| 1285 | +void Preview::Impl::SetupGetters() |
| 1286 | +{ |
| 1287 | + owner_->renderer_name.SetGetterFunction( |
| 1288 | + sigc::mem_fun(this, &Preview::Impl::get_renderer_name)); |
| 1289 | + owner_->title.SetGetterFunction( |
| 1290 | + sigc::mem_fun(this, &Preview::Impl::get_title)); |
| 1291 | + owner_->subtitle.SetGetterFunction( |
| 1292 | + sigc::mem_fun(this, &Preview::Impl::get_subtitle)); |
| 1293 | + owner_->description.SetGetterFunction( |
| 1294 | + sigc::mem_fun(this, &Preview::Impl::get_description)); |
| 1295 | + owner_->image.SetGetterFunction( |
| 1296 | + sigc::mem_fun(this, &Preview::Impl::get_image)); |
| 1297 | + |
| 1298 | + owner_->parent_lens.SetGetterFunction( |
| 1299 | + sigc::mem_fun(this, &Preview::Impl::get_parent_lens)); |
| 1300 | + owner_->parent_lens.SetSetterFunction( |
| 1301 | + sigc::mem_fun(this, &Preview::Impl::set_parent_lens)); |
| 1302 | +} |
| 1303 | + |
| 1304 | +Preview::Preview(glib::Object<GObject> const& proto_obj) |
| 1305 | + : pimpl(new Impl(this, proto_obj)) |
| 1306 | +{ |
| 1307 | } |
| 1308 | |
| 1309 | Preview::~Preview() |
| 1310 | -{} |
| 1311 | - |
| 1312 | -unsigned int Preview::PropertyToUnsignedInt (Properties& properties, const char* key) |
| 1313 | -{ |
| 1314 | - return g_variant_get_uint32(properties[key]); |
| 1315 | -} |
| 1316 | - |
| 1317 | -std::string Preview::PropertyToString(Properties& properties, const char *key) |
| 1318 | -{ |
| 1319 | - if (properties.find(key) == properties.end()) |
| 1320 | - return ""; |
| 1321 | - return g_variant_get_string(properties[key], NULL); |
| 1322 | -} |
| 1323 | - |
| 1324 | -std::vector<std::string> Preview::PropertyToStringVector(Properties& properties, const char *key) |
| 1325 | -{ |
| 1326 | - GVariantIter* iter = NULL; |
| 1327 | - char* value = NULL; |
| 1328 | - std::vector<std::string> property; |
| 1329 | - |
| 1330 | - if (properties.find(key) == properties.end()) |
| 1331 | - return property; |
| 1332 | - |
| 1333 | - g_variant_get(properties[key], "as", &iter); |
| 1334 | - |
| 1335 | - while (g_variant_iter_loop(iter, "s", &value)) |
| 1336 | - property.push_back(value); |
| 1337 | - |
| 1338 | - g_variant_iter_free(iter); |
| 1339 | - |
| 1340 | - return property; |
| 1341 | -} |
| 1342 | - |
| 1343 | -float Preview::PropertyToFloat(Properties& properties, const char* key) |
| 1344 | -{ |
| 1345 | - if (properties.find(key) == properties.end()) |
| 1346 | - return 0.0f; |
| 1347 | - |
| 1348 | - return (float)g_variant_get_double(properties[key]); |
| 1349 | -} |
| 1350 | - |
| 1351 | -NoPreview::NoPreview() |
| 1352 | -{ |
| 1353 | - renderer_name = "preview-none"; |
| 1354 | -} |
| 1355 | - |
| 1356 | -} |
| 1357 | -} |
| 1358 | +{ |
| 1359 | +} |
| 1360 | + |
| 1361 | +Preview::ActionPtrList Preview::GetActions() const |
| 1362 | +{ |
| 1363 | + return pimpl->get_actions(); |
| 1364 | +} |
| 1365 | + |
| 1366 | +Preview::InfoHintPtrList Preview::GetInfoHints() const |
| 1367 | +{ |
| 1368 | + return pimpl->get_info_hints(); |
| 1369 | +} |
| 1370 | + |
| 1371 | +void Preview::Update(glib::Variant const& properties, |
| 1372 | + glib::DBusProxy::ReplyCallback reply_callback) const |
| 1373 | +{ |
| 1374 | + if (pimpl->parent_lens_) |
| 1375 | + { |
| 1376 | + pimpl->parent_lens_->SignalPreview(preview_uri, properties, reply_callback); |
| 1377 | + } |
| 1378 | + else |
| 1379 | + { |
| 1380 | + LOG_WARN(logger) << "Unable to update Preview, parent_lens wasn't set!"; |
| 1381 | + } |
| 1382 | +} |
| 1383 | + |
| 1384 | +void Preview::PerformAction(std::string const& id) const |
| 1385 | +{ |
| 1386 | + if (pimpl->parent_lens_) |
| 1387 | + { |
| 1388 | + pimpl->parent_lens_->ActivatePreviewAction(id, preview_uri); |
| 1389 | + } |
| 1390 | + else |
| 1391 | + { |
| 1392 | + LOG_WARN(logger) << "Unable to perform action, parent_lens wasn't set!"; |
| 1393 | + } |
| 1394 | +} |
| 1395 | + |
| 1396 | +} // namespace dash |
| 1397 | +} // namespace unity |
| 1398 | |
| 1399 | === modified file 'UnityCore/Preview.h' |
| 1400 | --- UnityCore/Preview.h 2012-03-14 06:24:18 +0000 |
| 1401 | +++ UnityCore/Preview.h 2012-07-17 13:45:25 +0000 |
| 1402 | @@ -1,6 +1,6 @@ |
| 1403 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 1404 | /* |
| 1405 | - * Copyright (C) 2011 Canonical Ltd |
| 1406 | + * Copyright (C) 2011-2012 Canonical Ltd |
| 1407 | * |
| 1408 | * This program is free software: you can redistribute it and/or modify |
| 1409 | * it under the terms of the GNU General Public License version 3 as |
| 1410 | @@ -15,6 +15,7 @@ |
| 1411 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 1412 | * |
| 1413 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 1414 | + * Michal Hruby <michal.hruby@canonical.com> |
| 1415 | */ |
| 1416 | |
| 1417 | #ifndef UNITY_PREVIEW_H |
| 1418 | @@ -25,9 +26,13 @@ |
| 1419 | #include <string> |
| 1420 | #include <vector> |
| 1421 | |
| 1422 | +#include <glib.h> |
| 1423 | +#include <gio/gio.h> |
| 1424 | #include <sigc++/trackable.h> |
| 1425 | +#include <NuxCore/Property.h> |
| 1426 | |
| 1427 | -#include <glib.h> |
| 1428 | +#include "GLibWrapper.h" |
| 1429 | +#include "GLibDBusProxy.h" |
| 1430 | #include "Variant.h" |
| 1431 | |
| 1432 | namespace unity |
| 1433 | @@ -35,29 +40,90 @@ |
| 1434 | namespace dash |
| 1435 | { |
| 1436 | |
| 1437 | +class Lens; |
| 1438 | + |
| 1439 | +enum LayoutHint |
| 1440 | +{ |
| 1441 | + NONE, |
| 1442 | + LEFT, |
| 1443 | + RIGHT, |
| 1444 | + TOP, |
| 1445 | + BOTTOM |
| 1446 | +}; |
| 1447 | + |
| 1448 | class Preview : public sigc::trackable |
| 1449 | { |
| 1450 | public: |
| 1451 | + struct Action |
| 1452 | + { |
| 1453 | + std::string id; |
| 1454 | + std::string display_name; |
| 1455 | + std::string icon_hint; |
| 1456 | + LayoutHint layout_hint; |
| 1457 | + // TODO: there's also a HashTable here (although unused atm) |
| 1458 | + |
| 1459 | + Action() {}; |
| 1460 | + Action(const gchar* id_, const gchar* display_name_, |
| 1461 | + const gchar* icon_hint_, LayoutHint layout_hint_) |
| 1462 | + : id(id_ != NULL ? id_ : "") |
| 1463 | + , display_name(display_name_ != NULL ? display_name_ : "") |
| 1464 | + , icon_hint(icon_hint_ != NULL ? icon_hint_ : "") |
| 1465 | + , layout_hint(layout_hint_) {}; |
| 1466 | + }; |
| 1467 | + |
| 1468 | + struct InfoHint |
| 1469 | + { |
| 1470 | + std::string id; |
| 1471 | + std::string display_name; |
| 1472 | + std::string icon_hint; |
| 1473 | + unity::glib::Variant value; |
| 1474 | + |
| 1475 | + InfoHint() {}; |
| 1476 | + InfoHint(const gchar* id_, const gchar* display_name_, |
| 1477 | + const gchar* icon_hint_, GVariant* value_) |
| 1478 | + : id(id_ != NULL ? id_ : "") |
| 1479 | + , display_name(display_name_ != NULL ? display_name_ : "") |
| 1480 | + , icon_hint(icon_hint_ != NULL ? icon_hint_ : "") |
| 1481 | + , value(value_) {}; |
| 1482 | + }; |
| 1483 | + |
| 1484 | typedef std::shared_ptr<Preview> Ptr; |
| 1485 | - typedef std::map<std::string, unity::glib::Variant> Properties; |
| 1486 | + typedef std::shared_ptr<Action> ActionPtr; |
| 1487 | + typedef std::shared_ptr<InfoHint> InfoHintPtr; |
| 1488 | + typedef std::vector<ActionPtr> ActionPtrList; |
| 1489 | + typedef std::vector<InfoHintPtr> InfoHintPtrList; |
| 1490 | |
| 1491 | virtual ~Preview(); |
| 1492 | |
| 1493 | - static Preview::Ptr PreviewForProperties(std::string const& renderer_name, Properties& properties); |
| 1494 | - |
| 1495 | - std::string renderer_name; |
| 1496 | + static Preview::Ptr PreviewForVariant(glib::Variant& properties); |
| 1497 | + static Preview::Ptr PreviewForProtocolObject(glib::Object<GObject> const& proto_obj); |
| 1498 | + |
| 1499 | + nux::ROProperty<std::string> renderer_name; |
| 1500 | + nux::ROProperty<std::string> title; |
| 1501 | + nux::ROProperty<std::string> subtitle; |
| 1502 | + nux::ROProperty<std::string> description; |
| 1503 | + nux::ROProperty<unity::glib::Object<GIcon>> image; |
| 1504 | + |
| 1505 | + // can't use Lens::Ptr to avoid circular dependency |
| 1506 | + nux::RWProperty<Lens*> parent_lens; |
| 1507 | + nux::Property<std::string> preview_uri; |
| 1508 | + |
| 1509 | + ActionPtrList GetActions() const; |
| 1510 | + InfoHintPtrList GetInfoHints() const; |
| 1511 | + |
| 1512 | + void PerformAction(std::string const& id) const; |
| 1513 | |
| 1514 | protected: |
| 1515 | - unsigned int PropertyToUnsignedInt (Properties& properties, const char* key); |
| 1516 | - std::string PropertyToString(Properties& properties, const char *key); |
| 1517 | - std::vector<std::string> PropertyToStringVector(Properties& properties, const char *key); |
| 1518 | - float PropertyToFloat(Properties& properties, const char* key); |
| 1519 | -}; |
| 1520 | + // this should be UnityProtocolPreview, but we want to keep the usage |
| 1521 | + // of libunity-protocol-private private to unity-core |
| 1522 | + Preview(glib::Object<GObject> const& proto_obj); |
| 1523 | + void Update(glib::Variant const& properties, |
| 1524 | + glib::DBusProxy::ReplyCallback reply_callback = nullptr) const; |
| 1525 | + static glib::Object<GIcon> IconForString(std::string const& icon_hint); |
| 1526 | |
| 1527 | -class NoPreview : public Preview |
| 1528 | -{ |
| 1529 | -public: |
| 1530 | - NoPreview(); |
| 1531 | +private: |
| 1532 | + class Impl; |
| 1533 | + std::unique_ptr<Impl> pimpl; |
| 1534 | }; |
| 1535 | |
| 1536 | } |
| 1537 | |
| 1538 | === added file 'UnityCore/SeriesPreview.cpp' |
| 1539 | --- UnityCore/SeriesPreview.cpp 1970-01-01 00:00:00 +0000 |
| 1540 | +++ UnityCore/SeriesPreview.cpp 2012-07-17 13:45:25 +0000 |
| 1541 | @@ -0,0 +1,149 @@ |
| 1542 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 1543 | +/* |
| 1544 | + * Copyright (C) 2012 Canonical Ltd |
| 1545 | + * |
| 1546 | + * This program is free software: you can redistribute it and/or modify |
| 1547 | + * it under the terms of the GNU General Public License version 3 as |
| 1548 | + * published by the Free Software Foundation. |
| 1549 | + * |
| 1550 | + * This program is distributed in the hope that it will be useful, |
| 1551 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1552 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 1553 | + * GNU General Public License for more details. |
| 1554 | + * |
| 1555 | + * You should have received a copy of the GNU General Public License |
| 1556 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 1557 | + * |
| 1558 | + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 1559 | + * Michal Hruby <michal.hruby@canonical.com> |
| 1560 | + */ |
| 1561 | + |
| 1562 | +#include <unity-protocol.h> |
| 1563 | + |
| 1564 | +#include "SeriesPreview.h" |
| 1565 | + |
| 1566 | +namespace unity |
| 1567 | +{ |
| 1568 | +namespace dash |
| 1569 | +{ |
| 1570 | + |
| 1571 | +class SeriesPreview::Impl |
| 1572 | +{ |
| 1573 | +public: |
| 1574 | + Impl(SeriesPreview* owner, glib::Object<GObject> const& proto_obj); |
| 1575 | + |
| 1576 | + void SetupGetters(); |
| 1577 | + void selected_item_reply(GVariant* reply); |
| 1578 | + int get_selected_item_index() const { return selected_item_index_; }; |
| 1579 | + bool set_selected_item_index(int index); |
| 1580 | + SeriesItemPtrList get_items() const { return items_list_; }; |
| 1581 | + Preview::Ptr get_child_preview() const |
| 1582 | + { |
| 1583 | + if (!child_preview_->parent_lens) |
| 1584 | + child_preview_->parent_lens = owner_->parent_lens(); |
| 1585 | + if (child_preview_->preview_uri().empty()) |
| 1586 | + child_preview_->preview_uri = owner_->preview_uri(); |
| 1587 | + return child_preview_; |
| 1588 | + }; |
| 1589 | + |
| 1590 | + SeriesPreview* owner_; |
| 1591 | + glib::Object<UnityProtocolSeriesPreview> raw_preview_; |
| 1592 | + |
| 1593 | + Preview::Ptr child_preview_; |
| 1594 | + SeriesItemPtrList items_list_; |
| 1595 | + int selected_item_index_; |
| 1596 | +}; |
| 1597 | + |
| 1598 | +SeriesPreview::Impl::Impl(SeriesPreview* owner, |
| 1599 | + glib::Object<GObject> const& proto_obj) |
| 1600 | + : owner_(owner) |
| 1601 | + , selected_item_index_(-1) |
| 1602 | +{ |
| 1603 | + raw_preview_ = glib::object_cast<UnityProtocolSeriesPreview>(proto_obj); |
| 1604 | + |
| 1605 | + int items_len; |
| 1606 | + auto items = unity_protocol_series_preview_get_items(raw_preview_, |
| 1607 | + &items_len); |
| 1608 | + for (int i = 0; i < items_len; i++) |
| 1609 | + { |
| 1610 | + UnityProtocolSeriesItemRaw* raw_item = &items[i]; |
| 1611 | + items_list_.push_back(std::make_shared<SeriesItem>( |
| 1612 | + raw_item->uri, raw_item->title, raw_item->icon_hint)); |
| 1613 | + } |
| 1614 | + |
| 1615 | + glib::Object<UnityProtocolPreview> child_preview( |
| 1616 | + unity_protocol_series_preview_get_child_preview(raw_preview_), |
| 1617 | + glib::AddRef()); |
| 1618 | + child_preview_ = Preview::PreviewForProtocolObject(glib::object_cast<GObject>(child_preview)); |
| 1619 | + |
| 1620 | + selected_item_index_ = |
| 1621 | + unity_protocol_series_preview_get_selected_item(raw_preview_); |
| 1622 | + |
| 1623 | + SetupGetters(); |
| 1624 | +} |
| 1625 | + |
| 1626 | +void SeriesPreview::Impl::SetupGetters() |
| 1627 | +{ |
| 1628 | + owner_->selected_item_index.SetGetterFunction( |
| 1629 | + sigc::mem_fun(this, &SeriesPreview::Impl::get_selected_item_index)); |
| 1630 | + owner_->selected_item_index.SetSetterFunction( |
| 1631 | + sigc::mem_fun(this, &SeriesPreview::Impl::set_selected_item_index)); |
| 1632 | +} |
| 1633 | + |
| 1634 | +bool SeriesPreview::Impl::set_selected_item_index(int index) |
| 1635 | +{ |
| 1636 | + if (index != selected_item_index_) |
| 1637 | + { |
| 1638 | + selected_item_index_ = index; |
| 1639 | + |
| 1640 | + UnityProtocolPreview *preview = UNITY_PROTOCOL_PREVIEW(raw_preview_.RawPtr()); |
| 1641 | + unity_protocol_preview_begin_updates(preview); |
| 1642 | + unity_protocol_series_preview_set_selected_item(raw_preview_, index); |
| 1643 | + glib::Variant properties(unity_protocol_preview_end_updates(preview), |
| 1644 | + glib::StealRef()); |
| 1645 | + owner_->Update(properties, sigc::mem_fun(this, &SeriesPreview::Impl::selected_item_reply)); |
| 1646 | + return true; |
| 1647 | + } |
| 1648 | + |
| 1649 | + return false; |
| 1650 | +} |
| 1651 | + |
| 1652 | +void SeriesPreview::Impl::selected_item_reply(GVariant *reply) |
| 1653 | +{ |
| 1654 | + glib::Variant dict(reply); |
| 1655 | + glib::HintsMap hints; |
| 1656 | + dict.ASVToHints(hints); |
| 1657 | + |
| 1658 | + auto iter = hints.find("preview"); |
| 1659 | + if (iter != hints.end()) |
| 1660 | + { |
| 1661 | + Preview::Ptr new_child = Preview::PreviewForVariant(iter->second); |
| 1662 | + new_child->parent_lens = owner_->parent_lens(); |
| 1663 | + new_child->preview_uri = owner_->preview_uri(); // FIXME: really? |
| 1664 | + child_preview_ = new_child; |
| 1665 | + owner_->child_preview_changed.emit(new_child); |
| 1666 | + } |
| 1667 | +} |
| 1668 | + |
| 1669 | +SeriesPreview::SeriesPreview(unity::glib::Object<GObject> const& proto_obj) |
| 1670 | + : Preview(proto_obj) |
| 1671 | + , pimpl(new Impl(this, proto_obj)) |
| 1672 | +{ |
| 1673 | +} |
| 1674 | + |
| 1675 | +SeriesPreview::~SeriesPreview() |
| 1676 | +{ |
| 1677 | +} |
| 1678 | + |
| 1679 | +Preview::Ptr SeriesPreview::GetChildPreview() const |
| 1680 | +{ |
| 1681 | + return pimpl->get_child_preview(); |
| 1682 | +} |
| 1683 | + |
| 1684 | +SeriesPreview::SeriesItemPtrList SeriesPreview::GetItems() const |
| 1685 | +{ |
| 1686 | + return pimpl->get_items(); |
| 1687 | +} |
| 1688 | + |
| 1689 | +} |
| 1690 | +} |
| 1691 | |
| 1692 | === added file 'UnityCore/SeriesPreview.h' |
| 1693 | --- UnityCore/SeriesPreview.h 1970-01-01 00:00:00 +0000 |
| 1694 | +++ UnityCore/SeriesPreview.h 2012-07-17 13:45:25 +0000 |
| 1695 | @@ -0,0 +1,73 @@ |
| 1696 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 1697 | +/* |
| 1698 | + * Copyright (C) 2012 Canonical Ltd |
| 1699 | + * |
| 1700 | + * This program is free software: you can redistribute it and/or modify |
| 1701 | + * it under the terms of the GNU General Public License version 3 as |
| 1702 | + * published by the Free Software Foundation. |
| 1703 | + * |
| 1704 | + * This program is distributed in the hope that it will be useful, |
| 1705 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1706 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 1707 | + * GNU General Public License for more details. |
| 1708 | + * |
| 1709 | + * You should have received a copy of the GNU General Public License |
| 1710 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 1711 | + * |
| 1712 | + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 1713 | + * Michal Hruby <michal.hruby@canonical.com> |
| 1714 | + */ |
| 1715 | + |
| 1716 | +#ifndef UNITY_SERIES_PREVIEW_H |
| 1717 | +#define UNITY_SERIES_PREVIEW_H |
| 1718 | + |
| 1719 | +#include <memory> |
| 1720 | + |
| 1721 | +#include <sigc++/trackable.h> |
| 1722 | + |
| 1723 | +#include "Preview.h" |
| 1724 | + |
| 1725 | +namespace unity |
| 1726 | +{ |
| 1727 | +namespace dash |
| 1728 | +{ |
| 1729 | + |
| 1730 | +class SeriesPreview : public Preview |
| 1731 | +{ |
| 1732 | +public: |
| 1733 | + struct SeriesItem |
| 1734 | + { |
| 1735 | + std::string uri; |
| 1736 | + std::string title; |
| 1737 | + std::string icon_hint; |
| 1738 | + |
| 1739 | + SeriesItem() {}; |
| 1740 | + SeriesItem(const gchar* uri_, const gchar* title_, const gchar* icon_hint_) |
| 1741 | + : uri(uri_ != NULL ? uri_ : "") |
| 1742 | + , title(title_ != NULL ? title_ : "") |
| 1743 | + , icon_hint(icon_hint_ != NULL ? icon_hint_ : "") {}; |
| 1744 | + }; |
| 1745 | + |
| 1746 | + typedef std::shared_ptr<SeriesPreview> Ptr; |
| 1747 | + typedef std::shared_ptr<SeriesItem> SeriesItemPtr; |
| 1748 | + typedef std::vector<SeriesItemPtr> SeriesItemPtrList; |
| 1749 | + |
| 1750 | + SeriesPreview(unity::glib::Object<GObject> const& proto_obj); |
| 1751 | + ~SeriesPreview(); |
| 1752 | + |
| 1753 | + nux::RWProperty<int> selected_item_index; |
| 1754 | + |
| 1755 | + SeriesItemPtrList GetItems() const; |
| 1756 | + Preview::Ptr GetChildPreview() const; |
| 1757 | + |
| 1758 | + sigc::signal<void, Preview::Ptr const&> child_preview_changed; |
| 1759 | + |
| 1760 | +private: |
| 1761 | + class Impl; |
| 1762 | + std::unique_ptr<Impl> pimpl; |
| 1763 | +}; |
| 1764 | + |
| 1765 | +} |
| 1766 | +} |
| 1767 | + |
| 1768 | +#endif |
| 1769 | |
| 1770 | === added file 'UnityCore/Track.cpp' |
| 1771 | --- UnityCore/Track.cpp 1970-01-01 00:00:00 +0000 |
| 1772 | +++ UnityCore/Track.cpp 2012-07-17 13:45:25 +0000 |
| 1773 | @@ -0,0 +1,66 @@ |
| 1774 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 1775 | +/* |
| 1776 | + * Copyright (C) 2011 Canonical Ltd |
| 1777 | + * |
| 1778 | + * This program is free software: you can redistribute it and/or modify |
| 1779 | + * it under the terms of the GNU General Public License version 3 as |
| 1780 | + * published by the Free Software Foundation. |
| 1781 | + * |
| 1782 | + * This program is distributed in the hope that it will be useful, |
| 1783 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1784 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 1785 | + * GNU General Public License for more details. |
| 1786 | + * |
| 1787 | + * You should have received a copy of the GNU General Public License |
| 1788 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 1789 | + * |
| 1790 | + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 1791 | + */ |
| 1792 | + |
| 1793 | +#include "Track.h" |
| 1794 | +#include <sigc++/bind.h> |
| 1795 | + |
| 1796 | +namespace unity |
| 1797 | +{ |
| 1798 | +namespace dash |
| 1799 | +{ |
| 1800 | + |
| 1801 | +Track::Track(DeeModel* model, |
| 1802 | + DeeModelIter* iter, |
| 1803 | + DeeModelTag* renderer_tag) |
| 1804 | + : RowAdaptorBase(model, iter, renderer_tag) |
| 1805 | +{ |
| 1806 | + SetupGetters(); |
| 1807 | +} |
| 1808 | + |
| 1809 | +Track::Track(Track const& other) |
| 1810 | + : RowAdaptorBase(other) |
| 1811 | +{ |
| 1812 | + SetupGetters(); |
| 1813 | +} |
| 1814 | + |
| 1815 | +Track& Track::operator=(Track const& other) |
| 1816 | +{ |
| 1817 | + RowAdaptorBase::operator=(other); |
| 1818 | + SetupGetters(); |
| 1819 | + return *this; |
| 1820 | +} |
| 1821 | + |
| 1822 | +PlayState Track::GetPlayState(int position) |
| 1823 | +{ |
| 1824 | + unsigned state = GetUIntAt(position); |
| 1825 | + return static_cast<PlayState>(state); |
| 1826 | +} |
| 1827 | + |
| 1828 | +void Track::SetupGetters() |
| 1829 | +{ |
| 1830 | + uri.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 0)); |
| 1831 | + track_number.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetIntAt), 1)); |
| 1832 | + title.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 2)); |
| 1833 | + length.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetUIntAt), 3)); |
| 1834 | + play_state.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &Track::GetPlayState), 4)); |
| 1835 | + progress.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetFloatAt), 5)); |
| 1836 | +} |
| 1837 | + |
| 1838 | +} |
| 1839 | +} |
| 1840 | |
| 1841 | === added file 'UnityCore/Track.h' |
| 1842 | --- UnityCore/Track.h 1970-01-01 00:00:00 +0000 |
| 1843 | +++ UnityCore/Track.h 2012-07-17 13:45:25 +0000 |
| 1844 | @@ -0,0 +1,68 @@ |
| 1845 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 1846 | +/* |
| 1847 | + * Copyright (C) 2011 Canonical Ltd |
| 1848 | + * |
| 1849 | + * This program is free software: you can redistribute it and/or modify |
| 1850 | + * it under the terms of the GNU General Public License version 3 as |
| 1851 | + * published by the Free Software Foundation. |
| 1852 | + * |
| 1853 | + * This program is distributed in the hope that it will be useful, |
| 1854 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1855 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 1856 | + * GNU General Public License for more details. |
| 1857 | + * |
| 1858 | + * You should have received a copy of the GNU General Public License |
| 1859 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 1860 | + * |
| 1861 | + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 1862 | + */ |
| 1863 | + |
| 1864 | +#ifndef UNITY_TRACK_H |
| 1865 | +#define UNITY_TRACK_H |
| 1866 | + |
| 1867 | +#include <NuxCore/Property.h> |
| 1868 | + |
| 1869 | +#include "ModelRowAdaptor.h" |
| 1870 | + |
| 1871 | +namespace unity |
| 1872 | +{ |
| 1873 | +namespace dash |
| 1874 | +{ |
| 1875 | + |
| 1876 | +enum PlayState |
| 1877 | +{ |
| 1878 | + STOPPED, |
| 1879 | + PLAYING, |
| 1880 | + PAUSED |
| 1881 | +}; |
| 1882 | + |
| 1883 | +/* This class represents a DeeModelIter for a TracksModel |
| 1884 | + * It's slightly chunky, but that is because it's optimized to be stack-allocated |
| 1885 | + * as it is not expected to be kept by the views, rather views can easily attach |
| 1886 | + * a "renderer" to the iter, so when the changed or removed signals are called, |
| 1887 | + * the view can easily find which widget/view belongs to this iter. |
| 1888 | + */ |
| 1889 | +class Track : public RowAdaptorBase |
| 1890 | +{ |
| 1891 | +public: |
| 1892 | + Track(DeeModel* model, DeeModelIter* iter, DeeModelTag* tag); |
| 1893 | + |
| 1894 | + Track(Track const& other); |
| 1895 | + Track& operator=(Track const& other); |
| 1896 | + |
| 1897 | + nux::ROProperty<std::string> uri; |
| 1898 | + nux::ROProperty<int> track_number; |
| 1899 | + nux::ROProperty<std::string> title; |
| 1900 | + nux::ROProperty<unsigned> length; |
| 1901 | + nux::ROProperty<PlayState> play_state; |
| 1902 | + nux::ROProperty<float> progress; |
| 1903 | + |
| 1904 | +private: |
| 1905 | + void SetupGetters(); |
| 1906 | + PlayState GetPlayState(int position); |
| 1907 | +}; |
| 1908 | + |
| 1909 | +} |
| 1910 | +} |
| 1911 | + |
| 1912 | +#endif |
| 1913 | |
| 1914 | === added file 'UnityCore/Tracks.cpp' |
| 1915 | --- UnityCore/Tracks.cpp 1970-01-01 00:00:00 +0000 |
| 1916 | +++ UnityCore/Tracks.cpp 2012-07-17 13:45:25 +0000 |
| 1917 | @@ -0,0 +1,58 @@ |
| 1918 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 1919 | +/* |
| 1920 | + * Copyright (C) 2011 Canonical Ltd |
| 1921 | + * |
| 1922 | + * This program is free software: you can redistribute it and/or modify |
| 1923 | + * it under the terms of the GNU General Public License version 3 as |
| 1924 | + * published by the Free Software Foundation. |
| 1925 | + * |
| 1926 | + * This program is distributed in the hope that it will be useful, |
| 1927 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1928 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 1929 | + * GNU General Public License for more details. |
| 1930 | + * |
| 1931 | + * You should have received a copy of the GNU General Public License |
| 1932 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 1933 | + * |
| 1934 | + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 1935 | + */ |
| 1936 | + |
| 1937 | +#include "Tracks.h" |
| 1938 | + |
| 1939 | +namespace unity |
| 1940 | +{ |
| 1941 | +namespace dash |
| 1942 | +{ |
| 1943 | + |
| 1944 | +Tracks::Tracks() |
| 1945 | +{ |
| 1946 | + row_added.connect(sigc::mem_fun(this, &Tracks::OnRowAdded)); |
| 1947 | + row_changed.connect(sigc::mem_fun(this, &Tracks::OnRowChanged)); |
| 1948 | + row_removed.connect(sigc::mem_fun(this, &Tracks::OnRowRemoved)); |
| 1949 | +} |
| 1950 | + |
| 1951 | +Tracks::Tracks(ModelType model_type) |
| 1952 | + : Model<Track>::Model(model_type) |
| 1953 | +{ |
| 1954 | + row_added.connect(sigc::mem_fun(this, &Tracks::OnRowAdded)); |
| 1955 | + row_changed.connect(sigc::mem_fun(this, &Tracks::OnRowChanged)); |
| 1956 | + row_removed.connect(sigc::mem_fun(this, &Tracks::OnRowRemoved)); |
| 1957 | +} |
| 1958 | + |
| 1959 | +void Tracks::OnRowAdded(Track& result) |
| 1960 | +{ |
| 1961 | + track_added.emit(result); |
| 1962 | +} |
| 1963 | + |
| 1964 | +void Tracks::OnRowChanged(Track& result) |
| 1965 | +{ |
| 1966 | + track_changed.emit(result); |
| 1967 | +} |
| 1968 | + |
| 1969 | +void Tracks::OnRowRemoved(Track& result) |
| 1970 | +{ |
| 1971 | + track_removed.emit(result); |
| 1972 | +} |
| 1973 | + |
| 1974 | +} |
| 1975 | +} |
| 1976 | |
| 1977 | === added file 'UnityCore/Tracks.h' |
| 1978 | --- UnityCore/Tracks.h 1970-01-01 00:00:00 +0000 |
| 1979 | +++ UnityCore/Tracks.h 2012-07-17 13:45:25 +0000 |
| 1980 | @@ -0,0 +1,54 @@ |
| 1981 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 1982 | +/* |
| 1983 | + * Copyright (C) 2011 Canonical Ltd |
| 1984 | + * |
| 1985 | + * This program is free software: you can redistribute it and/or modify |
| 1986 | + * it under the terms of the GNU General Public License version 3 as |
| 1987 | + * published by the Free Software Foundation. |
| 1988 | + * |
| 1989 | + * This program is distributed in the hope that it will be useful, |
| 1990 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1991 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 1992 | + * GNU General Public License for more details. |
| 1993 | + * |
| 1994 | + * You should have received a copy of the GNU General Public License |
| 1995 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 1996 | + * |
| 1997 | + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
| 1998 | + */ |
| 1999 | + |
| 2000 | +#ifndef UNITY_TRACKS_H |
| 2001 | +#define UNITY_TRACKS_H |
| 2002 | + |
| 2003 | +#include <memory> |
| 2004 | + |
| 2005 | +#include "Model.h" |
| 2006 | +#include "Track.h" |
| 2007 | + |
| 2008 | +namespace unity |
| 2009 | +{ |
| 2010 | +namespace dash |
| 2011 | +{ |
| 2012 | + |
| 2013 | +class Tracks : public Model<Track> |
| 2014 | +{ |
| 2015 | +public: |
| 2016 | + typedef std::shared_ptr<Tracks> Ptr; |
| 2017 | + |
| 2018 | + Tracks(); |
| 2019 | + Tracks(ModelType model_type); |
| 2020 | + |
| 2021 | + sigc::signal<void, Track const&> track_added; |
| 2022 | + sigc::signal<void, Track const&> track_changed; |
| 2023 | + sigc::signal<void, Track const&> track_removed; |
| 2024 | + |
| 2025 | +private: |
| 2026 | + void OnRowAdded(Track& result); |
| 2027 | + void OnRowChanged(Track& result); |
| 2028 | + void OnRowRemoved(Track& result); |
| 2029 | +}; |
| 2030 | + |
| 2031 | +} |
| 2032 | +} |
| 2033 | + |
| 2034 | +#endif |
| 2035 | |
| 2036 | === modified file 'tests/CMakeLists.txt' |
| 2037 | --- tests/CMakeLists.txt 2012-07-13 11:08:50 +0000 |
| 2038 | +++ tests/CMakeLists.txt 2012-07-17 13:45:25 +0000 |
| 2039 | @@ -144,6 +144,7 @@ |
| 2040 | test_favorite_store_private.cpp |
| 2041 | test_home_lens.cpp |
| 2042 | test_launcher_entry_remote.cpp |
| 2043 | + test_previews.cpp |
| 2044 | test_shortcut_model.cpp |
| 2045 | test_shortcut_private.cpp |
| 2046 | test_introspection.cpp |
| 2047 | |
| 2048 | === modified file 'tests/test_lens.cpp' |
| 2049 | --- tests/test_lens.cpp 2012-07-16 11:03:32 +0000 |
| 2050 | +++ tests/test_lens.cpp 2012-07-17 13:45:25 +0000 |
| 2051 | @@ -6,7 +6,9 @@ |
| 2052 | #include <UnityCore/GLibWrapper.h> |
| 2053 | #include <UnityCore/Lens.h> |
| 2054 | #include <UnityCore/MultiRangeFilter.h> |
| 2055 | -#include <UnityCore/MusicPreviews.h> |
| 2056 | +#include <UnityCore/Preview.h> |
| 2057 | +#include <UnityCore/SeriesPreview.h> |
| 2058 | +#include <UnityCore/Variant.h> |
| 2059 | #include <UnityCore/RadioOptionFilter.h> |
| 2060 | #include <UnityCore/RatingsFilter.h> |
| 2061 | |
| 2062 | @@ -52,7 +54,7 @@ |
| 2063 | void WaitForConnected() |
| 2064 | { |
| 2065 | bool timeout_reached = false; |
| 2066 | - guint32 timeout_id = Utils::ScheduleTimeout(&timeout_reached); |
| 2067 | + guint32 timeout_id = Utils::ScheduleTimeout(&timeout_reached, 2000); |
| 2068 | |
| 2069 | while (!lens_->connected && !timeout_reached) |
| 2070 | { |
| 2071 | @@ -68,7 +70,7 @@ |
| 2072 | void WaitForModel(Model<Adaptor>* model, unsigned int n_rows) |
| 2073 | { |
| 2074 | bool timeout_reached = false; |
| 2075 | - guint32 timeout_id = Utils::ScheduleTimeout(&timeout_reached); |
| 2076 | + guint32 timeout_id = Utils::ScheduleTimeout(&timeout_reached, 2000); |
| 2077 | |
| 2078 | while (model->count != n_rows && !timeout_reached) |
| 2079 | { |
| 2080 | @@ -209,37 +211,102 @@ |
| 2081 | |
| 2082 | TEST_F(TestLens, TestPreview) |
| 2083 | { |
| 2084 | - // FIXME: fix up when unity-core supports current preview protocol |
| 2085 | - /* |
| 2086 | std::string uri = PopulateAndGetFirstResultURI(); |
| 2087 | bool previewed = false; |
| 2088 | |
| 2089 | auto preview_cb = [&previewed, &uri] (std::string const& uri_, |
| 2090 | - Preview::Ptr preview) |
| 2091 | - { |
| 2092 | - EXPECT_EQ(uri, uri_); |
| 2093 | - EXPECT_EQ(preview->renderer_name, "preview-generic"); |
| 2094 | - |
| 2095 | - TrackPreview::Ptr track_preview = std::static_pointer_cast<TrackPreview>(preview); |
| 2096 | - EXPECT_EQ(track_preview->number, (unsigned int)1); |
| 2097 | - EXPECT_EQ(track_preview->title, "Animus Vox"); |
| 2098 | - EXPECT_EQ(track_preview->artist, "The Glitch Mob"); |
| 2099 | - EXPECT_EQ(track_preview->album, "Drink The Sea"); |
| 2100 | - EXPECT_EQ(track_preview->length, (unsigned int)404); |
| 2101 | - EXPECT_EQ(track_preview->album_cover, "file://music/the/track"); |
| 2102 | - EXPECT_EQ(track_preview->primary_action_name, "Play"); |
| 2103 | - EXPECT_EQ(track_preview->primary_action_icon_hint, ""); |
| 2104 | - EXPECT_EQ(track_preview->primary_action_uri, "play://music/the/track"); |
| 2105 | - EXPECT_EQ(track_preview->play_action_uri, "preview://music/the/track"); |
| 2106 | - EXPECT_EQ(track_preview->pause_action_uri, "pause://music/the/track"); |
| 2107 | - EXPECT_EQ(track_preview->genres.size(), (unsigned int)1); |
| 2108 | - previewed = true; |
| 2109 | - }; |
| 2110 | - lens_->preview_ready.connect(preview_cb); |
| 2111 | - |
| 2112 | - lens_->Preview(uri); |
| 2113 | - Utils::WaitUntil(previewed); |
| 2114 | - */ |
| 2115 | + Preview::Ptr const& preview) |
| 2116 | + { |
| 2117 | + EXPECT_EQ(uri, uri_); |
| 2118 | + EXPECT_EQ(preview->renderer_name, "preview-series"); |
| 2119 | + |
| 2120 | + auto series = std::dynamic_pointer_cast<SeriesPreview>(preview); |
| 2121 | + EXPECT_EQ(series->GetItems().size(), (unsigned)4); |
| 2122 | + EXPECT_EQ(series->selected_item_index, 2); |
| 2123 | + |
| 2124 | + auto child = series->GetChildPreview(); |
| 2125 | + EXPECT_EQ(child->title, "A preview"); |
| 2126 | + previewed = true; |
| 2127 | + }; |
| 2128 | + |
| 2129 | + lens_->preview_ready.connect(preview_cb); |
| 2130 | + |
| 2131 | + lens_->Preview(uri); |
| 2132 | + Utils::WaitUntil(previewed); |
| 2133 | +} |
| 2134 | + |
| 2135 | +TEST_F(TestLens, TestPreviewAction) |
| 2136 | +{ |
| 2137 | + std::string uri = PopulateAndGetFirstResultURI(); |
| 2138 | + bool previewed = false; |
| 2139 | + Preview::Ptr preview; |
| 2140 | + |
| 2141 | + auto preview_cb = [&previewed, &uri, &preview] |
| 2142 | + (std::string const& uri_, |
| 2143 | + Preview::Ptr const& preview_) |
| 2144 | + { |
| 2145 | + EXPECT_EQ(uri, uri_); |
| 2146 | + EXPECT_EQ(preview_->renderer_name, "preview-series"); |
| 2147 | + |
| 2148 | + preview = preview_; |
| 2149 | + previewed = true; |
| 2150 | + }; |
| 2151 | + |
| 2152 | + lens_->preview_ready.connect(preview_cb); |
| 2153 | + lens_->Preview(uri); |
| 2154 | + |
| 2155 | + Utils::WaitUntil(previewed); |
| 2156 | + |
| 2157 | + bool action_executed = false; |
| 2158 | + auto activated_cb = [&action_executed] (std::string const& uri, |
| 2159 | + HandledType handled_type, |
| 2160 | + Lens::Hints const& hints) |
| 2161 | + { |
| 2162 | + EXPECT_EQ(handled_type, HandledType::SHOW_DASH); |
| 2163 | + action_executed = true; |
| 2164 | + }; |
| 2165 | + |
| 2166 | + lens_->activated.connect(activated_cb); |
| 2167 | + EXPECT_GT(preview->GetActions().size(), (unsigned)0); |
| 2168 | + auto action = preview->GetActions()[0]; |
| 2169 | + preview->PerformAction(action->id); |
| 2170 | + |
| 2171 | + Utils::WaitUntil(action_executed); |
| 2172 | +} |
| 2173 | + |
| 2174 | +TEST_F(TestLens, TestPreviewSignal) |
| 2175 | +{ |
| 2176 | + std::string uri = PopulateAndGetFirstResultURI(); |
| 2177 | + bool previewed = false; |
| 2178 | + SeriesPreview::Ptr series_preview; |
| 2179 | + |
| 2180 | + auto preview_cb = [&previewed, &uri, &series_preview] |
| 2181 | + (std::string const& uri_, |
| 2182 | + Preview::Ptr const& preview) |
| 2183 | + { |
| 2184 | + EXPECT_EQ(uri, uri_); |
| 2185 | + EXPECT_EQ(preview->renderer_name, "preview-series"); |
| 2186 | + |
| 2187 | + series_preview = std::dynamic_pointer_cast<SeriesPreview>(preview); |
| 2188 | + previewed = true; |
| 2189 | + }; |
| 2190 | + |
| 2191 | + lens_->preview_ready.connect(preview_cb); |
| 2192 | + lens_->Preview(uri); |
| 2193 | + |
| 2194 | + Utils::WaitUntil(previewed); |
| 2195 | + |
| 2196 | + bool child_changed = false; |
| 2197 | + auto child_changed_cb = [&child_changed] (Preview::Ptr const& new_child) |
| 2198 | + { |
| 2199 | + EXPECT_EQ(new_child->title, "A preview"); |
| 2200 | + child_changed = true; |
| 2201 | + }; |
| 2202 | + |
| 2203 | + series_preview->child_preview_changed.connect(child_changed_cb); |
| 2204 | + series_preview->selected_item_index = 1; |
| 2205 | + |
| 2206 | + Utils::WaitUntil(child_changed); |
| 2207 | } |
| 2208 | |
| 2209 | TEST_F(TestLens, TestFilterSync) |
| 2210 | |
| 2211 | === added file 'tests/test_previews.cpp' |
| 2212 | --- tests/test_previews.cpp 1970-01-01 00:00:00 +0000 |
| 2213 | +++ tests/test_previews.cpp 2012-07-17 13:45:25 +0000 |
| 2214 | @@ -0,0 +1,262 @@ |
| 2215 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
| 2216 | +/* |
| 2217 | + * Copyright (C) 2011 Canonical Ltd |
| 2218 | + * |
| 2219 | + * This program is free software: you can redistribute it and/or modify |
| 2220 | + * it under the terms of the GNU General Public License version 3 as |
| 2221 | + * published by the Free Software Foundation. |
| 2222 | + * |
| 2223 | + * This program is distributed in the hope that it will be useful, |
| 2224 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 2225 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 2226 | + * GNU General Public License for more details. |
| 2227 | + * |
| 2228 | + * You should have received a copy of the GNU General Public License |
| 2229 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 2230 | + * |
| 2231 | + * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com> |
| 2232 | + */ |
| 2233 | + |
| 2234 | +#include <list> |
| 2235 | +#include <algorithm> |
| 2236 | +#include <gmock/gmock.h> |
| 2237 | +#include <gio/gio.h> |
| 2238 | +#include <UnityCore/Variant.h> |
| 2239 | +#include <UnityCore/Preview.h> |
| 2240 | +#include <UnityCore/ApplicationPreview.h> |
| 2241 | +#include <UnityCore/MoviePreview.h> |
| 2242 | +#include <UnityCore/MusicPreview.h> |
| 2243 | +#include <UnityCore/SeriesPreview.h> |
| 2244 | +#include <unity-protocol.h> |
| 2245 | + |
| 2246 | +using namespace std; |
| 2247 | +using namespace testing; |
| 2248 | +using namespace unity; |
| 2249 | +using namespace unity::glib; |
| 2250 | +using namespace unity::dash; |
| 2251 | + |
| 2252 | +namespace |
| 2253 | +{ |
| 2254 | + |
| 2255 | +bool IsVariant(Variant const& variant) |
| 2256 | +{ |
| 2257 | + return g_variant_get_type_string(variant) != NULL; |
| 2258 | +} |
| 2259 | + |
| 2260 | +TEST(TestPreviews, DeserializeGeneric) |
| 2261 | +{ |
| 2262 | + Object<GIcon> icon(g_icon_new_for_string("accessories", NULL)); |
| 2263 | + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_generic_preview_new())); |
| 2264 | + unity_protocol_preview_set_title(proto_obj, "Title"); |
| 2265 | + unity_protocol_preview_set_subtitle(proto_obj, "Subtitle"); |
| 2266 | + unity_protocol_preview_set_description(proto_obj, "Description"); |
| 2267 | + unity_protocol_preview_set_thumbnail(proto_obj, icon); |
| 2268 | + |
| 2269 | + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), |
| 2270 | + glib::StealRef()); |
| 2271 | + EXPECT_TRUE(IsVariant(v)); |
| 2272 | + |
| 2273 | + Preview::Ptr preview = Preview::PreviewForVariant(v); |
| 2274 | + EXPECT_TRUE(preview != nullptr); |
| 2275 | + |
| 2276 | + EXPECT_EQ(preview->renderer_name, "preview-generic"); |
| 2277 | + EXPECT_EQ(preview->title, "Title"); |
| 2278 | + EXPECT_EQ(preview->subtitle, "Subtitle"); |
| 2279 | + EXPECT_EQ(preview->description, "Description"); |
| 2280 | + EXPECT_TRUE(g_icon_equal(preview->image(), icon) != FALSE); |
| 2281 | +} |
| 2282 | + |
| 2283 | +TEST(TestPreviews, DeserializeGenericWithMeta) |
| 2284 | +{ |
| 2285 | + Object<GIcon> icon(g_icon_new_for_string("accessories", NULL)); |
| 2286 | + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_generic_preview_new())); |
| 2287 | + unity_protocol_preview_set_title(proto_obj, "Title"); |
| 2288 | + unity_protocol_preview_set_subtitle(proto_obj, "Subtitle"); |
| 2289 | + unity_protocol_preview_set_description(proto_obj, "Description"); |
| 2290 | + unity_protocol_preview_set_thumbnail(proto_obj, icon); |
| 2291 | + unity_protocol_preview_add_action(proto_obj, "action1", "Action #1", NULL, 0); |
| 2292 | + unity_protocol_preview_add_action(proto_obj, "action2", "Action #2", NULL, 0); |
| 2293 | + unity_protocol_preview_add_info_hint(proto_obj, "hint1", "Hint 1", NULL, g_variant_new("i", 34)); |
| 2294 | + unity_protocol_preview_add_info_hint(proto_obj, "hint2", "Hint 2", NULL, g_variant_new("s", "string hint")); |
| 2295 | + |
| 2296 | + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), |
| 2297 | + glib::StealRef()); |
| 2298 | + EXPECT_TRUE(IsVariant(v)); |
| 2299 | + |
| 2300 | + Preview::Ptr preview = Preview::PreviewForVariant(v); |
| 2301 | + EXPECT_TRUE(preview != nullptr); |
| 2302 | + |
| 2303 | + EXPECT_EQ(preview->renderer_name, "preview-generic"); |
| 2304 | + EXPECT_EQ(preview->title, "Title"); |
| 2305 | + EXPECT_EQ(preview->subtitle, "Subtitle"); |
| 2306 | + EXPECT_EQ(preview->description, "Description"); |
| 2307 | + EXPECT_TRUE(g_icon_equal(preview->image(), icon) != FALSE); |
| 2308 | + |
| 2309 | + auto actions = preview->GetActions(); |
| 2310 | + auto info_hints = preview->GetInfoHints(); |
| 2311 | + |
| 2312 | + EXPECT_EQ(actions.size(), 2); |
| 2313 | + |
| 2314 | + auto action1 = actions[0]; |
| 2315 | + EXPECT_EQ(action1->id, "action1"); |
| 2316 | + EXPECT_EQ(action1->display_name, "Action #1"); |
| 2317 | + EXPECT_EQ(action1->icon_hint, ""); |
| 2318 | + EXPECT_EQ(action1->layout_hint, 0); |
| 2319 | + |
| 2320 | + auto action2 = actions[1]; |
| 2321 | + EXPECT_EQ(action2->id, "action2"); |
| 2322 | + EXPECT_EQ(action2->display_name, "Action #2"); |
| 2323 | + EXPECT_EQ(action2->icon_hint, ""); |
| 2324 | + |
| 2325 | + EXPECT_EQ(info_hints.size(), 2); |
| 2326 | + auto hint1 = info_hints[0]; |
| 2327 | + EXPECT_EQ(hint1->id, "hint1"); |
| 2328 | + EXPECT_EQ(hint1->display_name, "Hint 1"); |
| 2329 | + EXPECT_EQ(hint1->icon_hint, ""); |
| 2330 | + EXPECT_EQ(hint1->value.GetInt(), 34); |
| 2331 | + auto hint2 = info_hints[1]; |
| 2332 | + EXPECT_EQ(hint2->id, "hint2"); |
| 2333 | + EXPECT_EQ(hint2->display_name, "Hint 2"); |
| 2334 | + EXPECT_EQ(hint2->icon_hint, ""); |
| 2335 | + EXPECT_EQ(hint2->value.GetString(), "string hint"); |
| 2336 | +} |
| 2337 | + |
| 2338 | +TEST(TestPreviews, DeserializeApplication) |
| 2339 | +{ |
| 2340 | + Object<GIcon> icon(g_icon_new_for_string("application", NULL)); |
| 2341 | + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_application_preview_new())); |
| 2342 | + unity_protocol_preview_set_title(proto_obj, "Title"); |
| 2343 | + unity_protocol_preview_set_subtitle(proto_obj, "Subtitle"); |
| 2344 | + unity_protocol_preview_set_description(proto_obj, "Description"); |
| 2345 | + unity_protocol_preview_set_thumbnail(proto_obj, icon); |
| 2346 | + auto app_proto_obj = glib::object_cast<UnityProtocolApplicationPreview>(proto_obj); |
| 2347 | + unity_protocol_application_preview_set_last_update(app_proto_obj, "2012/06/13"); |
| 2348 | + unity_protocol_application_preview_set_copyright(app_proto_obj, "(c) Canonical"); |
| 2349 | + unity_protocol_application_preview_set_license(app_proto_obj, "GPLv3"); |
| 2350 | + unity_protocol_application_preview_set_app_icon(app_proto_obj, icon); |
| 2351 | + unity_protocol_application_preview_set_rating(app_proto_obj, 4.0); |
| 2352 | + unity_protocol_application_preview_set_num_ratings(app_proto_obj, 12); |
| 2353 | + |
| 2354 | + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), |
| 2355 | + glib::StealRef()); |
| 2356 | + EXPECT_TRUE(IsVariant(v)); |
| 2357 | + |
| 2358 | + Preview::Ptr base_preview = Preview::PreviewForVariant(v); |
| 2359 | + ApplicationPreview::Ptr preview = std::dynamic_pointer_cast<ApplicationPreview>(base_preview); |
| 2360 | + EXPECT_TRUE(preview != nullptr); |
| 2361 | + |
| 2362 | + EXPECT_EQ(preview->renderer_name, "preview-application"); |
| 2363 | + EXPECT_EQ(preview->title, "Title"); |
| 2364 | + EXPECT_EQ(preview->subtitle, "Subtitle"); |
| 2365 | + EXPECT_EQ(preview->description, "Description"); |
| 2366 | + EXPECT_TRUE(g_icon_equal(preview->image(), icon) != FALSE); |
| 2367 | + EXPECT_EQ(preview->last_update, "2012/06/13"); |
| 2368 | + EXPECT_EQ(preview->copyright, "(c) Canonical"); |
| 2369 | + EXPECT_EQ(preview->license, "GPLv3"); |
| 2370 | + EXPECT_TRUE(g_icon_equal(preview->app_icon(), icon) != FALSE); |
| 2371 | + EXPECT_EQ(preview->rating, 4.0); |
| 2372 | + EXPECT_EQ(preview->num_ratings, static_cast<unsigned>(12)); |
| 2373 | +} |
| 2374 | + |
| 2375 | +TEST(TestPreviews, DeserializeMovie) |
| 2376 | +{ |
| 2377 | + Object<GIcon> icon(g_icon_new_for_string("movie", NULL)); |
| 2378 | + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_movie_preview_new())); |
| 2379 | + unity_protocol_preview_set_title(proto_obj, "Title"); |
| 2380 | + unity_protocol_preview_set_subtitle(proto_obj, "Subtitle"); |
| 2381 | + unity_protocol_preview_set_description(proto_obj, "Description"); |
| 2382 | + unity_protocol_preview_set_thumbnail(proto_obj, icon); |
| 2383 | + auto movie_proto_obj = glib::object_cast<UnityProtocolMoviePreview>(proto_obj); |
| 2384 | + unity_protocol_movie_preview_set_year(movie_proto_obj, "2012"); |
| 2385 | + unity_protocol_movie_preview_set_rating(movie_proto_obj, 4.0); |
| 2386 | + unity_protocol_movie_preview_set_num_ratings(movie_proto_obj, 12); |
| 2387 | + |
| 2388 | + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), |
| 2389 | + glib::StealRef()); |
| 2390 | + EXPECT_TRUE(IsVariant(v)); |
| 2391 | + |
| 2392 | + Preview::Ptr base_preview = Preview::PreviewForVariant(v); |
| 2393 | + MoviePreview::Ptr preview = std::dynamic_pointer_cast<MoviePreview>(base_preview); |
| 2394 | + EXPECT_TRUE(preview != nullptr); |
| 2395 | + |
| 2396 | + EXPECT_EQ(preview->renderer_name, "preview-movie"); |
| 2397 | + EXPECT_EQ(preview->title, "Title"); |
| 2398 | + EXPECT_EQ(preview->subtitle, "Subtitle"); |
| 2399 | + EXPECT_EQ(preview->description, "Description"); |
| 2400 | + EXPECT_TRUE(g_icon_equal(preview->image(), icon) != FALSE); |
| 2401 | + EXPECT_EQ(preview->year, "2012"); |
| 2402 | + EXPECT_EQ(preview->rating, 4.0); |
| 2403 | + EXPECT_EQ(preview->num_ratings, static_cast<unsigned int>(12)); |
| 2404 | +} |
| 2405 | + |
| 2406 | +TEST(TestPreviews, DeserializeMusic) |
| 2407 | +{ |
| 2408 | + Object<GIcon> icon(g_icon_new_for_string("music", NULL)); |
| 2409 | + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_music_preview_new())); |
| 2410 | + unity_protocol_preview_set_title(proto_obj, "Title"); |
| 2411 | + unity_protocol_preview_set_subtitle(proto_obj, "Subtitle"); |
| 2412 | + unity_protocol_preview_set_description(proto_obj, "Description"); |
| 2413 | + unity_protocol_preview_set_thumbnail(proto_obj, icon); |
| 2414 | + auto music_proto_obj = glib::object_cast<UnityProtocolMusicPreview>(proto_obj); |
| 2415 | + |
| 2416 | + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), |
| 2417 | + glib::StealRef()); |
| 2418 | + EXPECT_TRUE(IsVariant(v)); |
| 2419 | + |
| 2420 | + Preview::Ptr base_preview = Preview::PreviewForVariant(v); |
| 2421 | + MusicPreview::Ptr preview = std::dynamic_pointer_cast<MusicPreview>(base_preview); |
| 2422 | + EXPECT_TRUE(preview != nullptr); |
| 2423 | + |
| 2424 | + EXPECT_EQ(preview->renderer_name, "preview-music"); |
| 2425 | + EXPECT_EQ(preview->title, "Title"); |
| 2426 | + EXPECT_EQ(preview->subtitle, "Subtitle"); |
| 2427 | + EXPECT_EQ(preview->description, "Description"); |
| 2428 | + EXPECT_TRUE(g_icon_equal(preview->image(), icon) != FALSE); |
| 2429 | +} |
| 2430 | + |
| 2431 | +TEST(TestPreviews, DeserializeSeries) |
| 2432 | +{ |
| 2433 | + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_series_preview_new())); |
| 2434 | + auto series_proto_obj = glib::object_cast<UnityProtocolSeriesPreview>(proto_obj); |
| 2435 | + unity_protocol_series_preview_add_series_item( |
| 2436 | + series_proto_obj, "#1", "scheme://path/0", NULL); |
| 2437 | + unity_protocol_series_preview_add_series_item( |
| 2438 | + series_proto_obj, "#2", "scheme://path/1", NULL); |
| 2439 | + unity_protocol_series_preview_set_selected_item(series_proto_obj, 1); |
| 2440 | + |
| 2441 | + Object<GIcon> icon(g_icon_new_for_string("accessories", NULL)); |
| 2442 | + Object<UnityProtocolPreview> child_proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_generic_preview_new())); |
| 2443 | + unity_protocol_preview_set_title(child_proto_obj, "Title"); |
| 2444 | + unity_protocol_preview_set_subtitle(child_proto_obj, "Subtitle"); |
| 2445 | + unity_protocol_preview_set_description(child_proto_obj, "Description"); |
| 2446 | + unity_protocol_preview_set_thumbnail(child_proto_obj, icon); |
| 2447 | + |
| 2448 | + unity_protocol_series_preview_set_child_preview(series_proto_obj, |
| 2449 | + child_proto_obj); |
| 2450 | + |
| 2451 | + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), |
| 2452 | + glib::StealRef()); |
| 2453 | + EXPECT_TRUE(IsVariant(v)); |
| 2454 | + |
| 2455 | + Preview::Ptr base_preview = Preview::PreviewForVariant(v); |
| 2456 | + SeriesPreview::Ptr preview = std::dynamic_pointer_cast<SeriesPreview>(base_preview); |
| 2457 | + EXPECT_TRUE(preview != nullptr); |
| 2458 | + |
| 2459 | + EXPECT_EQ(preview->renderer_name, "preview-series"); |
| 2460 | + |
| 2461 | + auto items = preview->GetItems(); |
| 2462 | + EXPECT_EQ(items.size(), 2); |
| 2463 | + |
| 2464 | + auto item1 = preview->GetItems()[1]; |
| 2465 | + EXPECT_EQ(item1->uri, "scheme://path/1"); |
| 2466 | + EXPECT_EQ(item1->title, "#2"); |
| 2467 | + |
| 2468 | + auto child_preview = preview->GetChildPreview(); |
| 2469 | + EXPECT_EQ(child_preview->renderer_name, "preview-generic"); |
| 2470 | + EXPECT_EQ(child_preview->title, "Title"); |
| 2471 | + EXPECT_EQ(child_preview->subtitle, "Subtitle"); |
| 2472 | + EXPECT_EQ(child_preview->description, "Description"); |
| 2473 | + EXPECT_TRUE(g_icon_equal(child_preview->image(), icon) != FALSE); |
| 2474 | +} |
| 2475 | + |
| 2476 | +} // Namespace |
| 2477 | |
| 2478 | === modified file 'tests/test_service_lens.c' |
| 2479 | --- tests/test_service_lens.c 2012-06-06 12:42:59 +0000 |
| 2480 | +++ tests/test_service_lens.c 2012-07-17 13:45:25 +0000 |
| 2481 | @@ -174,7 +174,7 @@ |
| 2482 | g_free(name); |
| 2483 | } |
| 2484 | |
| 2485 | - g_signal_emit_by_name (search, "finished"); |
| 2486 | + unity_lens_search_finished (search); |
| 2487 | } |
| 2488 | |
| 2489 | static UnityActivationResponse* |
| 2490 | @@ -183,15 +183,51 @@ |
| 2491 | return unity_activation_response_new(UNITY_HANDLED_TYPE_HIDE_DASH, ""); |
| 2492 | } |
| 2493 | |
| 2494 | +static UnityActivationResponse* |
| 2495 | +preview_action_activated(UnityPreviewAction* action, const char* uri) |
| 2496 | +{ |
| 2497 | + return unity_activation_response_new(UNITY_HANDLED_TYPE_SHOW_DASH, ""); |
| 2498 | +} |
| 2499 | + |
| 2500 | +static UnityPreview* |
| 2501 | +generate_child_preview(UnitySeriesPreview* parent, const char* uri) |
| 2502 | +{ |
| 2503 | + UnityPreview* preview; |
| 2504 | + UnityPreviewAction *action; |
| 2505 | + |
| 2506 | + gchar* desc = g_strdup_printf("Description for an item with uri %s", uri); |
| 2507 | + preview = (UnityPreview*) unity_generic_preview_new("A preview", desc, NULL); |
| 2508 | + action = unity_preview_action_new("child_action_X", "An action", NULL); |
| 2509 | + unity_preview_add_action(preview, action); |
| 2510 | + g_signal_connect(action, "activated", |
| 2511 | + G_CALLBACK(preview_action_activated), NULL); |
| 2512 | + |
| 2513 | + g_free(desc); |
| 2514 | + return preview; |
| 2515 | +} |
| 2516 | + |
| 2517 | static UnityPreview* |
| 2518 | on_preview_uri(UnityScope* scope, const char* uri, ServiceLens *self) |
| 2519 | { |
| 2520 | - return NULL; |
| 2521 | - // FIXME: update when the new preview types are well defined |
| 2522 | - /* |
| 2523 | - return (UnityPreview*)unity_generic_preview_new( |
| 2524 | - "Animus Vox", "The Glitch Mob - Drink The Sea", NULL); |
| 2525 | - */ |
| 2526 | + UnityPreviewAction* action; |
| 2527 | + UnitySeriesPreview* preview; |
| 2528 | + UnitySeriesItem* series_items[4]; |
| 2529 | + |
| 2530 | + series_items[0] = unity_series_item_new("scheme://item/1", "Item #1", NULL); |
| 2531 | + series_items[1] = unity_series_item_new("scheme://item/2", "Item #2", NULL); |
| 2532 | + series_items[2] = unity_series_item_new("scheme://item/3", "Item #3", NULL); |
| 2533 | + series_items[3] = unity_series_item_new("scheme://item/4", "Item #4", NULL); |
| 2534 | + |
| 2535 | + preview = unity_series_preview_new(series_items, 4, "scheme://item/3"); |
| 2536 | + g_signal_connect(preview, "request-item-preview", |
| 2537 | + G_CALLBACK(generate_child_preview), NULL); |
| 2538 | + |
| 2539 | + action = unity_preview_action_new("series_action_A", "An action", NULL); |
| 2540 | + unity_preview_add_action(UNITY_PREVIEW(preview), action); |
| 2541 | + g_signal_connect(action, "activated", |
| 2542 | + G_CALLBACK(preview_action_activated), NULL); |
| 2543 | + |
| 2544 | + return (UnityPreview*) preview; |
| 2545 | } |
| 2546 | |
| 2547 | ServiceLens* |


FAILED: Continuous integration, rev:2436 s-jenkins: 8080/job/ unity-ci/ 45/
http://