Merge lp:~aacid/unity-2d/lenses_shortcuts into lp:unity-2d

Proposed by Albert Astals Cid on 2012-04-03
Status: Merged
Approved by: Paweł Stołowski on 2012-04-04
Approved revision: 1032
Merged at revision: 1041
Proposed branch: lp:~aacid/unity-2d/lenses_shortcuts
Merge into: lp:unity-2d
Diff against target: 130 lines (+52/-0)
3 files modified
libunity-2d-private/src/lenses.cpp (+42/-0)
libunity-2d-private/src/lenses.h (+9/-0)
shell/dash/Dash.qml (+1/-0)
To merge this branch: bzr merge lp:~aacid/unity-2d/lenses_shortcuts
Reviewer Review Type Date Requested Status
Paweł Stołowski 2012-04-03 Approve on 2012-04-04
Florian Boucault 2012-04-03 Pending
Review via email: mp+100619@code.launchpad.net

Commit message

[Dash] Obey the shortcut property of the lenses

Description of the change

[Dash] Obey the shortcut property of the lenses

To post a comment you must log in.
lp:~aacid/unity-2d/lenses_shortcuts updated on 2012-04-04
1032. By Albert Astals Cid on 2012-04-04

Use UQ_WARNING instead of qWarning

Paweł Stołowski (stolowski) wrote :

Works great!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/lenses.cpp'
2--- libunity-2d-private/src/lenses.cpp 2012-02-22 08:45:31 +0000
3+++ libunity-2d-private/src/lenses.cpp 2012-04-04 09:44:20 +0000
4@@ -21,9 +21,13 @@
5 #include "lenses.h"
6
7 // Local
8+#include "debug_p.h"
9 #include "lens.h"
10+#include "hotkey.h"
11+#include "hotkeymonitor.h"
12
13 // Qt
14+#include <QKeySequence>
15
16 // libunity-core
17 #include <UnityCore/FilesystemLenses.h>
18@@ -44,6 +48,8 @@
19 m_homeLens->lens_added.connect(sigc::mem_fun(this, &Lenses::onLensAdded));
20 unity::dash::HomeLens::Ptr homeLensPtr(m_homeLens);
21 addUnityLens(homeLensPtr, 0);
22+
23+ connect(&m_shortcutMapper, SIGNAL(mapped(QString)), this, SIGNAL(activateLensRequested(QString)));
24 }
25
26 Lenses::~Lenses()
27@@ -115,12 +121,48 @@
28 /* DOCME */
29 QObject::connect(lens, SIGNAL(visibleChanged(bool)), this, SLOT(onLensPropertyChanged()));
30 m_lenses.insert(index, lens);
31+
32+ setLensShortcut(lens);
33+ connect(lens, SIGNAL(shortcutChanged(std::string)), this, SLOT(onLensShortcutChanged()));
34 }
35
36 void Lenses::removeUnityLens(int index)
37 {
38 Lens* lens = m_lenses.takeAt(index);
39+
40+ Hotkey *hk = m_lensShorcuts.take(lens);
41+ if (hk != NULL) {
42+ m_shortcutMapper.removeMappings(hk);
43+ }
44+
45 delete lens;
46 }
47
48+void Lenses::onLensShortcutChanged()
49+{
50+ Lens *lens = qobject_cast<Lens*>(sender());
51+ Q_ASSERT(lens != 0);
52+ if (lens != 0) {
53+ setLensShortcut(lens);
54+ }
55+}
56+
57+void Lenses::setLensShortcut(Lens *lens)
58+{
59+ Hotkey *hk = m_lensShorcuts.take(lens);
60+ if (hk != NULL) {
61+ m_shortcutMapper.removeMappings(hk);
62+ }
63+ if (!lens->shortcut().isEmpty()) {
64+ const QKeySequence ks(lens->shortcut());
65+ if (ks.count() == 1) {
66+ hk = HotkeyMonitor::instance().getHotkeyFor((Qt::Key)ks[0], Qt::MetaModifier);
67+ m_shortcutMapper.setMapping(hk, lens->id());
68+ connect(hk, SIGNAL(pressed()), &m_shortcutMapper, SLOT(map()));
69+ } else {
70+ UQ_WARNING << "Couldn't parse shortcut for Lens. Shorcut is " << lens->shortcut();
71+ }
72+ }
73+}
74+
75 #include "lenses.moc"
76
77=== modified file 'libunity-2d-private/src/lenses.h'
78--- libunity-2d-private/src/lenses.h 2012-01-27 17:48:24 +0000
79+++ libunity-2d-private/src/lenses.h 2012-04-04 09:44:20 +0000
80@@ -23,6 +23,7 @@
81 // Qt
82 #include <QAbstractListModel>
83 #include <QList>
84+#include <QSignalMapper>
85
86 // libunity-core
87 #include <UnityCore/Lens.h>
88@@ -36,6 +37,7 @@
89 }
90 }
91
92+class Hotkey;
93 class Lens;
94
95 class Lenses : public QAbstractListModel
96@@ -59,15 +61,22 @@
97 Q_INVOKABLE QVariant get(int row) const;
98 Q_INVOKABLE QVariant get(const QString& lens_id) const;
99
100+Q_SIGNALS:
101+ void activateLensRequested(const QString& lens_id);
102+
103 private Q_SLOTS:
104 void onLensAdded(unity::dash::Lens::Ptr& lens);
105 void onLensPropertyChanged();
106+ void onLensShortcutChanged();
107
108 private:
109 unity::dash::Lenses* m_unityLenses;
110 unity::dash::HomeLens* m_homeLens;
111 QList<Lens*> m_lenses;
112+ QHash<Lens*, Hotkey*> m_lensShorcuts;
113+ QSignalMapper m_shortcutMapper;
114
115+ void setLensShortcut(Lens *lens);
116 void addUnityLens(unity::dash::Lens::Ptr unity_lens, int index);
117 void removeUnityLens(int index);
118 };
119
120=== modified file 'shell/dash/Dash.qml'
121--- shell/dash/Dash.qml 2012-04-03 10:10:02 +0000
122+++ shell/dash/Dash.qml 2012-04-04 09:44:20 +0000
123@@ -226,6 +226,7 @@
124 }
125 }
126 }
127+ onActivateLensRequested: activateLens(lens_id)
128 }
129
130 Background {

Subscribers

People subscribed via source and target branches