Merge lp:~njpatel/unity/dash-fixes-2011-08-30 into lp:unity
- dash-fixes-2011-08-30
- Merge into trunk
Proposed by
Neil J. Patel
Status: | Merged | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | Gord Allott | ||||||||||||||||||||
Approved revision: | no longer in the source branch. | ||||||||||||||||||||
Merged at revision: | 1476 | ||||||||||||||||||||
Proposed branch: | lp:~njpatel/unity/dash-fixes-2011-08-30 | ||||||||||||||||||||
Merge into: | lp:unity | ||||||||||||||||||||
Diff against target: |
503 lines (+156/-136) 6 files modified
plugins/unityshell/src/DashView.cpp (+78/-5) plugins/unityshell/src/DashView.h (+5/-0) plugins/unityshell/src/LensView.cpp (+7/-0) plugins/unityshell/src/PlacesGroup.cpp (+13/-10) plugins/unityshell/src/PlacesHomeView.cpp (+50/-107) plugins/unityshell/src/PlacesHomeView.h (+3/-14) |
||||||||||||||||||||
To merge this branch: | bzr merge lp:~njpatel/unity/dash-fixes-2011-08-30 | ||||||||||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity Team | Pending | ||
Review via email: mp+73662@code.launchpad.net |
Commit message
Description of the change
Bugs attached.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'plugins/unityshell/src/DashView.cpp' | |||
2 | --- plugins/unityshell/src/DashView.cpp 2011-08-30 16:04:19 +0000 | |||
3 | +++ plugins/unityshell/src/DashView.cpp 2011-09-01 12:59:25 +0000 | |||
4 | @@ -24,6 +24,7 @@ | |||
5 | 24 | 24 | ||
6 | 25 | #include <NuxCore/Logger.h> | 25 | #include <NuxCore/Logger.h> |
7 | 26 | #include <UnityCore/GLibWrapper.h> | 26 | #include <UnityCore/GLibWrapper.h> |
8 | 27 | #include <UnityCore/RadioOptionFilter.h> | ||
9 | 27 | 28 | ||
10 | 28 | #include "PlacesStyle.h" | 29 | #include "PlacesStyle.h" |
11 | 29 | #include "DashSettings.h" | 30 | #include "DashSettings.h" |
12 | @@ -45,6 +46,7 @@ | |||
13 | 45 | : nux::View(NUX_TRACKER_LOCATION) | 46 | : nux::View(NUX_TRACKER_LOCATION) |
14 | 46 | , active_lens_view_(0) | 47 | , active_lens_view_(0) |
15 | 47 | , last_activated_uri_("") | 48 | , last_activated_uri_("") |
16 | 49 | , visible_(false) | ||
17 | 48 | 50 | ||
18 | 49 | { | 51 | { |
19 | 50 | SetupBackground(); | 52 | SetupBackground(); |
20 | @@ -68,6 +70,7 @@ | |||
21 | 68 | void DashView::AboutToShow() | 70 | void DashView::AboutToShow() |
22 | 69 | { | 71 | { |
23 | 70 | ubus_manager_.SendMessage(UBUS_BACKGROUND_REQUEST_COLOUR_EMIT); | 72 | ubus_manager_.SendMessage(UBUS_BACKGROUND_REQUEST_COLOUR_EMIT); |
24 | 73 | visible_ = true; | ||
25 | 71 | bg_effect_helper_.enabled = true; | 74 | bg_effect_helper_.enabled = true; |
26 | 72 | search_bar_->text_entry()->SelectAll(); | 75 | search_bar_->text_entry()->SelectAll(); |
27 | 73 | search_bar_->text_entry()->SetFocused(true); | 76 | search_bar_->text_entry()->SetFocused(true); |
28 | @@ -75,6 +78,7 @@ | |||
29 | 75 | 78 | ||
30 | 76 | void DashView::AboutToHide() | 79 | void DashView::AboutToHide() |
31 | 77 | { | 80 | { |
32 | 81 | visible_ = false; | ||
33 | 78 | bg_effect_helper_.enabled = false; | 82 | bg_effect_helper_.enabled = false; |
34 | 79 | } | 83 | } |
35 | 80 | 84 | ||
36 | @@ -463,18 +467,87 @@ | |||
37 | 463 | 467 | ||
38 | 464 | void DashView::OnActivateRequest(GVariant* args) | 468 | void DashView::OnActivateRequest(GVariant* args) |
39 | 465 | { | 469 | { |
41 | 466 | glib::String id; | 470 | glib::String uri; |
42 | 467 | glib::String search_string; | 471 | glib::String search_string; |
43 | 468 | 472 | ||
47 | 469 | g_variant_get(args, "(sus)", &id, NULL, &search_string); | 473 | g_variant_get(args, "(sus)", &uri, NULL, &search_string); |
48 | 470 | 474 | ||
49 | 471 | lens_bar_->Activate(id.Str()); | 475 | std::string id = AnalyseLensURI(uri.Str()); |
50 | 476 | |||
51 | 477 | home_view_->search_string = ""; | ||
52 | 478 | lens_bar_->Activate(id); | ||
53 | 472 | 479 | ||
54 | 473 | // Reset focus | 480 | // Reset focus |
55 | 474 | SetFocused(false); | 481 | SetFocused(false); |
56 | 475 | SetFocused(true); | 482 | SetFocused(true); |
57 | 476 | 483 | ||
59 | 477 | ubus_manager_.SendMessage(UBUS_DASH_EXTERNAL_ACTIVATION); | 484 | if (id == "home.lens" || !visible_) |
60 | 485 | ubus_manager_.SendMessage(UBUS_DASH_EXTERNAL_ACTIVATION); | ||
61 | 486 | } | ||
62 | 487 | |||
63 | 488 | std::string DashView::AnalyseLensURI(std::string uri) | ||
64 | 489 | { | ||
65 | 490 | std::string id = uri; | ||
66 | 491 | std::size_t pos = uri.find("?"); | ||
67 | 492 | |||
68 | 493 | // It is a real URI | ||
69 | 494 | if (pos) | ||
70 | 495 | { | ||
71 | 496 | id = uri.substr(0, pos); | ||
72 | 497 | |||
73 | 498 | std::string components = uri.substr(++pos); | ||
74 | 499 | gchar** tokens = g_strsplit(components.c_str(), "&", -1); | ||
75 | 500 | |||
76 | 501 | for (int i = 0; tokens[i]; ++i) | ||
77 | 502 | { | ||
78 | 503 | gchar** subs = g_strsplit(tokens[i], "=", 2); | ||
79 | 504 | |||
80 | 505 | if (g_str_has_prefix(subs[0], "filter_")) | ||
81 | 506 | { | ||
82 | 507 | UpdateLensFilter(id, subs[0] + 7, subs[1]); | ||
83 | 508 | lens_views_[id]->filters_expanded = true; | ||
84 | 509 | } | ||
85 | 510 | |||
86 | 511 | g_strfreev(subs); | ||
87 | 512 | } | ||
88 | 513 | |||
89 | 514 | g_strfreev(tokens); | ||
90 | 515 | } | ||
91 | 516 | |||
92 | 517 | return id; | ||
93 | 518 | } | ||
94 | 519 | |||
95 | 520 | void DashView::UpdateLensFilter(std::string lens_id, std::string filter_name, std::string value) | ||
96 | 521 | { | ||
97 | 522 | if (lenses_.GetLens(lens_id)) | ||
98 | 523 | { | ||
99 | 524 | Lens::Ptr lens = lenses_.GetLens(lens_id); | ||
100 | 525 | |||
101 | 526 | Filters::Ptr filters = lens->filters; | ||
102 | 527 | |||
103 | 528 | for (unsigned int i = 0; i < filters->count(); ++i) | ||
104 | 529 | { | ||
105 | 530 | Filter::Ptr filter = filters->FilterAtIndex(i); | ||
106 | 531 | |||
107 | 532 | if (filter->id() == filter_name) | ||
108 | 533 | { | ||
109 | 534 | UpdateLensFilterValue(filter, value); | ||
110 | 535 | } | ||
111 | 536 | } | ||
112 | 537 | } | ||
113 | 538 | } | ||
114 | 539 | |||
115 | 540 | void DashView::UpdateLensFilterValue(Filter::Ptr filter, std::string value) | ||
116 | 541 | { | ||
117 | 542 | if (filter->renderer_name == "filter-radiooption") | ||
118 | 543 | { | ||
119 | 544 | RadioOptionFilter::Ptr radio = std::static_pointer_cast<RadioOptionFilter>(filter); | ||
120 | 545 | for (auto option: radio->options()) | ||
121 | 546 | { | ||
122 | 547 | if (option->id == value) | ||
123 | 548 | option->active = true; | ||
124 | 549 | } | ||
125 | 550 | } | ||
126 | 478 | } | 551 | } |
127 | 479 | 552 | ||
128 | 480 | void DashView::OnBackgroundColorChanged(GVariant* args) | 553 | void DashView::OnBackgroundColorChanged(GVariant* args) |
129 | 481 | 554 | ||
130 | === modified file 'plugins/unityshell/src/DashView.h' | |||
131 | --- plugins/unityshell/src/DashView.h 2011-08-25 10:18:58 +0000 | |||
132 | +++ plugins/unityshell/src/DashView.h 2011-09-01 12:59:25 +0000 | |||
133 | @@ -81,6 +81,9 @@ | |||
134 | 81 | bool DoFallbackActivation(std::string const& uri); | 81 | bool DoFallbackActivation(std::string const& uri); |
135 | 82 | bool LaunchApp(std::string const& appname); | 82 | bool LaunchApp(std::string const& appname); |
136 | 83 | void OnEntryActivated(); | 83 | void OnEntryActivated(); |
137 | 84 | std::string AnalyseLensURI(std::string uri); | ||
138 | 85 | void UpdateLensFilter(std::string lens, std::string filter, std::string value); | ||
139 | 86 | void UpdateLensFilterValue(Filter::Ptr filter, std::string value); | ||
140 | 84 | 87 | ||
141 | 85 | bool AcceptKeyNavFocus(); | 88 | bool AcceptKeyNavFocus(); |
142 | 86 | bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character); | 89 | bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character); |
143 | @@ -112,6 +115,8 @@ | |||
144 | 112 | nux::ObjectPtr <nux::IOpenGLBaseTexture> bg_blur_texture_; | 115 | nux::ObjectPtr <nux::IOpenGLBaseTexture> bg_blur_texture_; |
145 | 113 | 116 | ||
146 | 114 | std::string last_activated_uri_; | 117 | std::string last_activated_uri_; |
147 | 118 | |||
148 | 119 | bool visible_; | ||
149 | 115 | }; | 120 | }; |
150 | 116 | 121 | ||
151 | 117 | 122 | ||
152 | 118 | 123 | ||
153 | === modified file 'plugins/unityshell/src/LensView.cpp' | |||
154 | --- plugins/unityshell/src/LensView.cpp 2011-08-31 16:52:32 +0000 | |||
155 | +++ plugins/unityshell/src/LensView.cpp 2011-09-01 12:59:25 +0000 | |||
156 | @@ -161,6 +161,13 @@ | |||
157 | 161 | group->SetChildView(grid); | 161 | group->SetChildView(grid); |
158 | 162 | 162 | ||
159 | 163 | scroll_layout_->AddView(group, 0); | 163 | scroll_layout_->AddView(group, 0); |
160 | 164 | |||
161 | 165 | Categories::Ptr categories = lens_->categories; | ||
162 | 166 | if (category.index + 1 == categories->count()) | ||
163 | 167 | { | ||
164 | 168 | lens_->Search("---"); | ||
165 | 169 | lens_->Search(""); | ||
166 | 170 | } | ||
167 | 164 | } | 171 | } |
168 | 165 | 172 | ||
169 | 166 | void LensView::OnResultAdded(Result const& result) | 173 | void LensView::OnResultAdded(Result const& result) |
170 | 167 | 174 | ||
171 | === modified file 'plugins/unityshell/src/PlacesGroup.cpp' | |||
172 | --- plugins/unityshell/src/PlacesGroup.cpp 2011-08-24 22:28:46 +0000 | |||
173 | +++ plugins/unityshell/src/PlacesGroup.cpp 2011-09-01 12:59:25 +0000 | |||
174 | @@ -266,17 +266,20 @@ | |||
175 | 266 | gboolean | 266 | gboolean |
176 | 267 | PlacesGroup::OnIdleRelayout(PlacesGroup* self) | 267 | PlacesGroup::OnIdleRelayout(PlacesGroup* self) |
177 | 268 | { | 268 | { |
186 | 269 | self->Refresh(); | 269 | if (self->GetChildView()) |
179 | 270 | self->QueueDraw(); | ||
180 | 271 | self->_group_layout->QueueDraw(); | ||
181 | 272 | self->GetChildView()->QueueDraw(); | ||
182 | 273 | self->ComputeChildLayout(); | ||
183 | 274 | self->_idle_id = 0; | ||
184 | 275 | |||
185 | 276 | if (self->GetFocused()) | ||
187 | 277 | { | 270 | { |
190 | 278 | self->SetFocused(false); // unset focus on all children | 271 | self->Refresh(); |
191 | 279 | self->SetFocused(true); // set focus on first child | 272 | self->QueueDraw(); |
192 | 273 | self->_group_layout->QueueDraw(); | ||
193 | 274 | self->GetChildView()->QueueDraw(); | ||
194 | 275 | self->ComputeChildLayout(); | ||
195 | 276 | self->_idle_id = 0; | ||
196 | 277 | |||
197 | 278 | if (self->GetFocused()) | ||
198 | 279 | { | ||
199 | 280 | self->SetFocused(false); // unset focus on all children | ||
200 | 281 | self->SetFocused(true); // set focus on first child | ||
201 | 282 | } | ||
202 | 280 | } | 283 | } |
203 | 281 | 284 | ||
204 | 282 | return FALSE; | 285 | return FALSE; |
205 | 283 | 286 | ||
206 | === modified file 'plugins/unityshell/src/PlacesHomeView.cpp' | |||
207 | --- plugins/unityshell/src/PlacesHomeView.cpp 2011-08-30 16:04:19 +0000 | |||
208 | +++ plugins/unityshell/src/PlacesHomeView.cpp 2011-09-01 12:59:25 +0000 | |||
209 | @@ -41,18 +41,16 @@ | |||
210 | 41 | 41 | ||
211 | 42 | #include "PlacesSimpleTile.h" | 42 | #include "PlacesSimpleTile.h" |
212 | 43 | #include "PlacesStyle.h" | 43 | #include "PlacesStyle.h" |
213 | 44 | #include <UnityCore/GLibWrapper.h> | ||
214 | 44 | #include <UnityCore/Variant.h> | 45 | #include <UnityCore/Variant.h> |
215 | 45 | 46 | ||
216 | 46 | #include <string> | 47 | #include <string> |
217 | 47 | #include <vector> | 48 | #include <vector> |
218 | 48 | 49 | ||
219 | 49 | #define DESKTOP_DIR "/desktop/gnome/applications" | ||
220 | 50 | #define BROWSER_DIR DESKTOP_DIR"/browser" | ||
221 | 51 | #define MAIL_DIR "/desktop/gnome/url-handlers/mailto" | ||
222 | 52 | #define MEDIA_DIR DESKTOP_DIR"/media" | ||
223 | 53 | |||
224 | 54 | #define DELTA_DOUBLE_REQUEST 500000000 | 50 | #define DELTA_DOUBLE_REQUEST 500000000 |
225 | 55 | 51 | ||
226 | 52 | using namespace unity; | ||
227 | 53 | |||
228 | 56 | enum | 54 | enum |
229 | 57 | { | 55 | { |
230 | 58 | TYPE_PLACE = 0, | 56 | TYPE_PLACE = 0, |
231 | @@ -101,47 +99,14 @@ | |||
232 | 101 | _layout->SetChildrenSize(style->GetHomeTileWidth(), style->GetHomeTileHeight()); | 99 | _layout->SetChildrenSize(style->GetHomeTileWidth(), style->GetHomeTileHeight()); |
233 | 102 | _layout->EnablePartialVisibility(false); | 100 | _layout->EnablePartialVisibility(false); |
234 | 103 | _layout->SetHeightMatchContent(true); | 101 | _layout->SetHeightMatchContent(true); |
235 | 104 | //_layout->SetVerticalExternalMargin(24); | ||
236 | 105 | _layout->SetHorizontalExternalMargin(32); | 102 | _layout->SetHorizontalExternalMargin(32); |
237 | 106 | _layout->SetVerticalInternalMargin(32); | 103 | _layout->SetVerticalInternalMargin(32); |
238 | 107 | _layout->SetHorizontalInternalMargin(32); | 104 | _layout->SetHorizontalInternalMargin(32); |
239 | 108 | _layout->SetMinMaxSize((style->GetHomeTileWidth() * 4) + (32 * 5), | 105 | _layout->SetMinMaxSize((style->GetHomeTileWidth() * 4) + (32 * 5), |
240 | 109 | (style->GetHomeTileHeight() * 2) + 32); | 106 | (style->GetHomeTileHeight() * 2) + 32); |
241 | 110 | 107 | ||
242 | 111 | _client = gconf_client_get_default(); | ||
243 | 112 | gconf_client_add_dir(_client, | ||
244 | 113 | BROWSER_DIR, | ||
245 | 114 | GCONF_CLIENT_PRELOAD_NONE, | ||
246 | 115 | NULL); | ||
247 | 116 | gconf_client_add_dir(_client, | ||
248 | 117 | MAIL_DIR, | ||
249 | 118 | GCONF_CLIENT_PRELOAD_NONE, | ||
250 | 119 | NULL); | ||
251 | 120 | gconf_client_add_dir(_client, | ||
252 | 121 | MEDIA_DIR, | ||
253 | 122 | GCONF_CLIENT_PRELOAD_NONE, | ||
254 | 123 | NULL); | ||
255 | 124 | _browser_gconf_notify = gconf_client_notify_add(_client, | ||
256 | 125 | BROWSER_DIR"/exec", | ||
257 | 126 | (GConfClientNotifyFunc)OnKeyChanged, | ||
258 | 127 | this, | ||
259 | 128 | NULL, NULL); | ||
260 | 129 | _mail_gconf_notify = gconf_client_notify_add(_client, | ||
261 | 130 | MAIL_DIR"/command", | ||
262 | 131 | (GConfClientNotifyFunc)OnKeyChanged, | ||
263 | 132 | this, | ||
264 | 133 | NULL, NULL); | ||
265 | 134 | _media_gconf_notify = gconf_client_notify_add(_client, | ||
266 | 135 | MEDIA_DIR"/exec", | ||
267 | 136 | (GConfClientNotifyFunc)OnKeyChanged, | ||
268 | 137 | this, | ||
269 | 138 | NULL, NULL); | ||
270 | 139 | |||
271 | 140 | _last_activate_time.tv_sec = 0; | ||
272 | 141 | _last_activate_time.tv_nsec = 0; | ||
273 | 142 | |||
274 | 143 | _ubus_handle = ubus_server_register_interest(ubus_server_get_default(), | 108 | _ubus_handle = ubus_server_register_interest(ubus_server_get_default(), |
276 | 144 | UBUS_DASH_EXTERNAL_ACTIVATION, | 109 | UBUS_PLACE_VIEW_SHOWN, |
277 | 145 | (UBusCallback) &PlacesHomeView::DashVisible, | 110 | (UBusCallback) &PlacesHomeView::DashVisible, |
278 | 146 | this); | 111 | this); |
279 | 147 | 112 | ||
280 | @@ -175,47 +140,14 @@ | |||
281 | 175 | 140 | ||
282 | 176 | PlacesHomeView::~PlacesHomeView() | 141 | PlacesHomeView::~PlacesHomeView() |
283 | 177 | { | 142 | { |
284 | 178 | g_object_unref(_client); | ||
285 | 179 | |||
286 | 180 | if (_ubus_handle != 0) | 143 | if (_ubus_handle != 0) |
287 | 181 | ubus_server_unregister_interest(ubus_server_get_default(), _ubus_handle); | 144 | ubus_server_unregister_interest(ubus_server_get_default(), _ubus_handle); |
288 | 182 | |||
289 | 183 | if (_browser_gconf_notify) | ||
290 | 184 | gconf_client_notify_remove(_client, _browser_gconf_notify); | ||
291 | 185 | if (_mail_gconf_notify) | ||
292 | 186 | gconf_client_notify_remove(_client, _mail_gconf_notify); | ||
293 | 187 | if (_media_gconf_notify) | ||
294 | 188 | gconf_client_notify_remove(_client, _media_gconf_notify); | ||
295 | 189 | gconf_client_remove_dir(_client, BROWSER_DIR, NULL); | ||
296 | 190 | gconf_client_remove_dir(_client, MAIL_DIR, NULL); | ||
297 | 191 | gconf_client_remove_dir(_client, MEDIA_DIR, NULL); | ||
298 | 192 | } | 145 | } |
299 | 193 | 146 | ||
300 | 194 | void | 147 | void |
301 | 195 | PlacesHomeView::DashVisible(GVariant* data, void* val) | 148 | PlacesHomeView::DashVisible(GVariant* data, void* val) |
302 | 196 | { | 149 | { |
303 | 197 | PlacesHomeView* self = (PlacesHomeView*)val; | 150 | PlacesHomeView* self = (PlacesHomeView*)val; |
304 | 198 | |||
305 | 199 | struct timespec event_time, delta; | ||
306 | 200 | clock_gettime(CLOCK_MONOTONIC, &event_time); | ||
307 | 201 | delta = self->time_diff(self->_last_activate_time, event_time); | ||
308 | 202 | |||
309 | 203 | self->_last_activate_time.tv_sec = event_time.tv_sec; | ||
310 | 204 | self->_last_activate_time.tv_nsec = event_time.tv_nsec; | ||
311 | 205 | |||
312 | 206 | // FIXME: this should be handled by ubus (not sending the request twice | ||
313 | 207 | // for some selected ones). Too intrusive for now. | ||
314 | 208 | if (!((delta.tv_sec == 0) && (delta.tv_nsec < DELTA_DOUBLE_REQUEST))) | ||
315 | 209 | self->Refresh(); | ||
316 | 210 | |||
317 | 211 | } | ||
318 | 212 | |||
319 | 213 | void | ||
320 | 214 | PlacesHomeView::OnKeyChanged(GConfClient* client, | ||
321 | 215 | guint cnxn_id, | ||
322 | 216 | GConfEntry* entry, | ||
323 | 217 | PlacesHomeView* self) | ||
324 | 218 | { | ||
325 | 219 | self->Refresh(); | 151 | self->Refresh(); |
326 | 220 | } | 152 | } |
327 | 221 | 153 | ||
328 | @@ -236,7 +168,7 @@ | |||
329 | 236 | markup, | 168 | markup, |
330 | 237 | icon_size); | 169 | icon_size); |
331 | 238 | shortcut->_id = TYPE_PLACE; | 170 | shortcut->_id = TYPE_PLACE; |
333 | 239 | shortcut->_place_id = g_strdup("/com/canonical/unity/applicationsplace/applications"); | 171 | shortcut->_place_id = g_strdup("applications.lens?filter_type=media"); |
334 | 240 | shortcut->_place_section = 9; | 172 | shortcut->_place_section = 9; |
335 | 241 | _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull); | 173 | _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull); |
336 | 242 | shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked)); | 174 | shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked)); |
337 | @@ -248,7 +180,7 @@ | |||
338 | 248 | markup, | 180 | markup, |
339 | 249 | icon_size); | 181 | icon_size); |
340 | 250 | shortcut->_id = TYPE_PLACE; | 182 | shortcut->_id = TYPE_PLACE; |
342 | 251 | shortcut->_place_id = g_strdup("/com/canonical/unity/applicationsplace/applications"); | 183 | shortcut->_place_id = g_strdup("applications.lens?filter_type=internet"); |
343 | 252 | shortcut->_place_section = 8; | 184 | shortcut->_place_section = 8; |
344 | 253 | _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull); | 185 | _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull); |
345 | 254 | shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked)); | 186 | shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked)); |
346 | @@ -260,7 +192,7 @@ | |||
347 | 260 | markup, | 192 | markup, |
348 | 261 | icon_size); | 193 | icon_size); |
349 | 262 | shortcut->_id = TYPE_PLACE; | 194 | shortcut->_id = TYPE_PLACE; |
351 | 263 | shortcut->_place_id = g_strdup("/com/canonical/unity/applicationsplace/applications"); | 195 | shortcut->_place_id = g_strdup("applications.lens"); |
352 | 264 | shortcut->_place_section = 0; | 196 | shortcut->_place_section = 0; |
353 | 265 | _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull); | 197 | _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull); |
354 | 266 | shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked)); | 198 | shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked)); |
355 | @@ -272,33 +204,25 @@ | |||
356 | 272 | markup, | 204 | markup, |
357 | 273 | icon_size); | 205 | icon_size); |
358 | 274 | shortcut->_id = TYPE_PLACE; | 206 | shortcut->_id = TYPE_PLACE; |
360 | 275 | shortcut->_place_id = g_strdup("/com/canonical/unity/filesplace/files"); | 207 | shortcut->_place_id = g_strdup("files.lens"); |
361 | 276 | shortcut->_place_section = 0; | 208 | shortcut->_place_section = 0; |
362 | 277 | _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull); | 209 | _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull); |
363 | 278 | shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked)); | 210 | shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked)); |
364 | 279 | g_free(markup); | 211 | g_free(markup); |
365 | 280 | 212 | ||
366 | 281 | // Browser | 213 | // Browser |
370 | 282 | markup = gconf_client_get_string(_client, BROWSER_DIR"/exec", NULL); | 214 | CreateShortcutFromMime("x-scheme-handler/http", _("Browse the Web"), _browser_alternatives); |
368 | 283 | CreateShortcutFromExec(markup, _("Browse the Web"), _browser_alternatives); | ||
369 | 284 | g_free(markup); | ||
371 | 285 | 215 | ||
372 | 286 | // Photos | 216 | // Photos |
373 | 287 | // FIXME: Need to figure out the default | 217 | // FIXME: Need to figure out the default |
374 | 288 | CreateShortcutFromExec("shotwell", _("View Photos"), _photo_alternatives); | 218 | CreateShortcutFromExec("shotwell", _("View Photos"), _photo_alternatives); |
375 | 289 | 219 | ||
388 | 290 | 220 | CreateShortcutFromMime("x-scheme-handler/mailto", _("Check Email"), _email_alternatives); | |
389 | 291 | markup = gconf_client_get_string(_client, MAIL_DIR"/command", NULL); | 221 | |
390 | 292 | // get the first word on key (the executable name itself) | 222 | CreateShortcutFromMime("audio/x-vorbis+ogg", _("Listen to Music"), _music_alternatives); |
391 | 293 | gchar** temp_array = g_strsplit(markup, " ", 0); | 223 | |
392 | 294 | g_free(markup); | 224 | SetExpanded(true); |
393 | 295 | CreateShortcutFromExec(temp_array[0], _("Check Email"), _email_alternatives); | 225 | SetCounts(8, 8); |
382 | 296 | g_strfreev(temp_array); | ||
383 | 297 | |||
384 | 298 | // Music | ||
385 | 299 | markup = gconf_client_get_string(_client, MEDIA_DIR"/exec", NULL); | ||
386 | 300 | CreateShortcutFromExec(markup, _("Listen to Music"), _music_alternatives); | ||
387 | 301 | g_free(markup); | ||
394 | 302 | 226 | ||
395 | 303 | QueueDraw(); | 227 | QueueDraw(); |
396 | 304 | _layout->QueueDraw(); | 228 | _layout->QueueDraw(); |
397 | @@ -373,6 +297,41 @@ | |||
398 | 373 | g_free(markup); | 297 | g_free(markup); |
399 | 374 | } | 298 | } |
400 | 375 | 299 | ||
401 | 300 | void PlacesHomeView::CreateShortcutFromMime(const char* mime, | ||
402 | 301 | const char* name, | ||
403 | 302 | std::vector<std::string>& alternatives) | ||
404 | 303 | { | ||
405 | 304 | PlacesStyle* style = PlacesStyle::GetDefault(); | ||
406 | 305 | GAppInfo* info = g_app_info_get_default_for_type(mime, FALSE); | ||
407 | 306 | |||
408 | 307 | // If it was invalid check alternatives for backup | ||
409 | 308 | if (!G_IS_DESKTOP_APP_INFO(info)) | ||
410 | 309 | { | ||
411 | 310 | for (auto alt: alternatives) | ||
412 | 311 | { | ||
413 | 312 | std::string id = alt + ".desktop"; | ||
414 | 313 | info = G_APP_INFO(g_desktop_app_info_new(id.c_str())); | ||
415 | 314 | |||
416 | 315 | if (G_IS_DESKTOP_APP_INFO(info)) | ||
417 | 316 | break; | ||
418 | 317 | } | ||
419 | 318 | } | ||
420 | 319 | |||
421 | 320 | if (G_IS_DESKTOP_APP_INFO(info)) | ||
422 | 321 | { | ||
423 | 322 | glib::String icon(g_icon_to_string(g_app_info_get_icon(G_APP_INFO(info)))); | ||
424 | 323 | glib::String markup(g_strdup_printf("<big>%s</big>", name)); | ||
425 | 324 | |||
426 | 325 | Shortcut* shortcut = new Shortcut(icon.Value(), markup.Value(), style->GetHomeTileIconSize()); | ||
427 | 326 | shortcut->_id = TYPE_EXEC; | ||
428 | 327 | shortcut->_exec = g_strdup (g_app_info_get_executable(G_APP_INFO(info)));; | ||
429 | 328 | shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked)); | ||
430 | 329 | _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull); | ||
431 | 330 | |||
432 | 331 | g_object_unref(info); | ||
433 | 332 | } | ||
434 | 333 | } | ||
435 | 334 | |||
436 | 376 | void | 335 | void |
437 | 377 | PlacesHomeView::OnShortcutClicked(PlacesTile* tile) | 336 | PlacesHomeView::OnShortcutClicked(PlacesTile* tile) |
438 | 378 | { | 337 | { |
439 | @@ -423,19 +382,3 @@ | |||
440 | 423 | unity::variant::BuilderWrapper(builder).add(GetGeometry()); | 382 | unity::variant::BuilderWrapper(builder).add(GetGeometry()); |
441 | 424 | } | 383 | } |
442 | 425 | 384 | ||
443 | 426 | // TODO: put that in some "util" toolbox | ||
444 | 427 | struct timespec PlacesHomeView::time_diff(struct timespec start, struct timespec end) | ||
445 | 428 | { | ||
446 | 429 | struct timespec temp; | ||
447 | 430 | if ((end.tv_nsec - start.tv_nsec) < 0) | ||
448 | 431 | { | ||
449 | 432 | temp.tv_sec = end.tv_sec - start.tv_sec - 1; | ||
450 | 433 | temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec; | ||
451 | 434 | } | ||
452 | 435 | else | ||
453 | 436 | { | ||
454 | 437 | temp.tv_sec = end.tv_sec - start.tv_sec; | ||
455 | 438 | temp.tv_nsec = end.tv_nsec - start.tv_nsec; | ||
456 | 439 | } | ||
457 | 440 | return temp; | ||
458 | 441 | } | ||
459 | 442 | 385 | ||
460 | === modified file 'plugins/unityshell/src/PlacesHomeView.h' | |||
461 | --- plugins/unityshell/src/PlacesHomeView.h 2011-08-11 01:32:45 +0000 | |||
462 | +++ plugins/unityshell/src/PlacesHomeView.h 2011-09-01 12:59:25 +0000 | |||
463 | @@ -32,9 +32,6 @@ | |||
464 | 32 | #include "PlacesTile.h" | 32 | #include "PlacesTile.h" |
465 | 33 | #include "PlacesGroup.h" | 33 | #include "PlacesGroup.h" |
466 | 34 | 34 | ||
467 | 35 | #include <gconf/gconf-client.h> | ||
468 | 36 | #include <time.h> | ||
469 | 37 | |||
470 | 38 | class PlacesHomeView : public unity::Introspectable, public PlacesGroup | 35 | class PlacesHomeView : public unity::Introspectable, public PlacesGroup |
471 | 39 | { | 36 | { |
472 | 40 | public: | 37 | public: |
473 | @@ -52,29 +49,21 @@ | |||
474 | 52 | private: | 49 | private: |
475 | 53 | static void DashVisible(GVariant* data, void* val); | 50 | static void DashVisible(GVariant* data, void* val); |
476 | 54 | void OnShortcutClicked(PlacesTile* _tile); | 51 | void OnShortcutClicked(PlacesTile* _tile); |
477 | 55 | static void OnKeyChanged(GConfClient* client, | ||
478 | 56 | guint cnxn_id, | ||
479 | 57 | GConfEntry* entry, | ||
480 | 58 | PlacesHomeView* self); | ||
481 | 59 | void CreateShortcutFromExec(const char* exec, | 52 | void CreateShortcutFromExec(const char* exec, |
482 | 60 | const char* name, | 53 | const char* name, |
483 | 61 | std::vector<std::string>& alternatives); | 54 | std::vector<std::string>& alternatives); |
484 | 55 | void CreateShortcutFromMime(const char* mime, | ||
485 | 56 | const char* name, | ||
486 | 57 | std::vector<std::string>& alternatives); | ||
487 | 62 | 58 | ||
488 | 63 | private: | 59 | private: |
489 | 64 | nux::GridHLayout* _layout; | 60 | nux::GridHLayout* _layout; |
490 | 65 | GConfClient* _client; | ||
491 | 66 | std::vector<std::string> _browser_alternatives; | 61 | std::vector<std::string> _browser_alternatives; |
492 | 67 | std::vector<std::string> _photo_alternatives; | 62 | std::vector<std::string> _photo_alternatives; |
493 | 68 | std::vector<std::string> _email_alternatives; | 63 | std::vector<std::string> _email_alternatives; |
494 | 69 | std::vector<std::string> _music_alternatives; | 64 | std::vector<std::string> _music_alternatives; |
495 | 70 | 65 | ||
496 | 71 | struct timespec time_diff(struct timespec start, struct timespec end); | ||
497 | 72 | struct timespec _last_activate_time; | ||
498 | 73 | |||
499 | 74 | guint _ubus_handle; | 66 | guint _ubus_handle; |
500 | 75 | guint _browser_gconf_notify; | ||
501 | 76 | guint _mail_gconf_notify; | ||
502 | 77 | guint _media_gconf_notify; | ||
503 | 78 | }; | 67 | }; |
504 | 79 | 68 | ||
505 | 80 | 69 |