Merge lp:~njpatel/unity/dash-fixes-2011-08-30 into lp:unity

Proposed by Neil J. Patel on 2011-09-01
Status: Merged
Approved by: Gord Allott on 2011-09-01
Approved revision: 1469
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
Reviewer Review Type Date Requested Status
Unity Team 2011-09-01 Pending
Review via email: mp+73662@code.launchpad.net

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