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

Proposed by Albert Astals Cid
Status: Merged
Approved by: Paweł Stołowski
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 (community) Approve
Florian Boucault 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
1032. By Albert Astals Cid

Use UQ_WARNING instead of qWarning

Revision history for this message
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
=== modified file 'libunity-2d-private/src/lenses.cpp'
--- libunity-2d-private/src/lenses.cpp 2012-02-22 08:45:31 +0000
+++ libunity-2d-private/src/lenses.cpp 2012-04-04 09:44:20 +0000
@@ -21,9 +21,13 @@
21#include "lenses.h"21#include "lenses.h"
2222
23// Local23// Local
24#include "debug_p.h"
24#include "lens.h"25#include "lens.h"
26#include "hotkey.h"
27#include "hotkeymonitor.h"
2528
26// Qt29// Qt
30#include <QKeySequence>
2731
28// libunity-core32// libunity-core
29#include <UnityCore/FilesystemLenses.h>33#include <UnityCore/FilesystemLenses.h>
@@ -44,6 +48,8 @@
44 m_homeLens->lens_added.connect(sigc::mem_fun(this, &Lenses::onLensAdded));48 m_homeLens->lens_added.connect(sigc::mem_fun(this, &Lenses::onLensAdded));
45 unity::dash::HomeLens::Ptr homeLensPtr(m_homeLens);49 unity::dash::HomeLens::Ptr homeLensPtr(m_homeLens);
46 addUnityLens(homeLensPtr, 0);50 addUnityLens(homeLensPtr, 0);
51
52 connect(&m_shortcutMapper, SIGNAL(mapped(QString)), this, SIGNAL(activateLensRequested(QString)));
47}53}
4854
49Lenses::~Lenses()55Lenses::~Lenses()
@@ -115,12 +121,48 @@
115 /* DOCME */121 /* DOCME */
116 QObject::connect(lens, SIGNAL(visibleChanged(bool)), this, SLOT(onLensPropertyChanged()));122 QObject::connect(lens, SIGNAL(visibleChanged(bool)), this, SLOT(onLensPropertyChanged()));
117 m_lenses.insert(index, lens);123 m_lenses.insert(index, lens);
124
125 setLensShortcut(lens);
126 connect(lens, SIGNAL(shortcutChanged(std::string)), this, SLOT(onLensShortcutChanged()));
118}127}
119128
120void Lenses::removeUnityLens(int index)129void Lenses::removeUnityLens(int index)
121{130{
122 Lens* lens = m_lenses.takeAt(index);131 Lens* lens = m_lenses.takeAt(index);
132
133 Hotkey *hk = m_lensShorcuts.take(lens);
134 if (hk != NULL) {
135 m_shortcutMapper.removeMappings(hk);
136 }
137
123 delete lens;138 delete lens;
124}139}
125140
141void Lenses::onLensShortcutChanged()
142{
143 Lens *lens = qobject_cast<Lens*>(sender());
144 Q_ASSERT(lens != 0);
145 if (lens != 0) {
146 setLensShortcut(lens);
147 }
148}
149
150void Lenses::setLensShortcut(Lens *lens)
151{
152 Hotkey *hk = m_lensShorcuts.take(lens);
153 if (hk != NULL) {
154 m_shortcutMapper.removeMappings(hk);
155 }
156 if (!lens->shortcut().isEmpty()) {
157 const QKeySequence ks(lens->shortcut());
158 if (ks.count() == 1) {
159 hk = HotkeyMonitor::instance().getHotkeyFor((Qt::Key)ks[0], Qt::MetaModifier);
160 m_shortcutMapper.setMapping(hk, lens->id());
161 connect(hk, SIGNAL(pressed()), &m_shortcutMapper, SLOT(map()));
162 } else {
163 UQ_WARNING << "Couldn't parse shortcut for Lens. Shorcut is " << lens->shortcut();
164 }
165 }
166}
167
126#include "lenses.moc"168#include "lenses.moc"
127169
=== modified file 'libunity-2d-private/src/lenses.h'
--- libunity-2d-private/src/lenses.h 2012-01-27 17:48:24 +0000
+++ libunity-2d-private/src/lenses.h 2012-04-04 09:44:20 +0000
@@ -23,6 +23,7 @@
23// Qt23// Qt
24#include <QAbstractListModel>24#include <QAbstractListModel>
25#include <QList>25#include <QList>
26#include <QSignalMapper>
2627
27// libunity-core28// libunity-core
28#include <UnityCore/Lens.h>29#include <UnityCore/Lens.h>
@@ -36,6 +37,7 @@
36}37}
37}38}
3839
40class Hotkey;
39class Lens;41class Lens;
4042
41class Lenses : public QAbstractListModel43class Lenses : public QAbstractListModel
@@ -59,15 +61,22 @@
59 Q_INVOKABLE QVariant get(int row) const;61 Q_INVOKABLE QVariant get(int row) const;
60 Q_INVOKABLE QVariant get(const QString& lens_id) const;62 Q_INVOKABLE QVariant get(const QString& lens_id) const;
6163
64Q_SIGNALS:
65 void activateLensRequested(const QString& lens_id);
66
62private Q_SLOTS:67private Q_SLOTS:
63 void onLensAdded(unity::dash::Lens::Ptr& lens);68 void onLensAdded(unity::dash::Lens::Ptr& lens);
64 void onLensPropertyChanged();69 void onLensPropertyChanged();
70 void onLensShortcutChanged();
6571
66private:72private:
67 unity::dash::Lenses* m_unityLenses;73 unity::dash::Lenses* m_unityLenses;
68 unity::dash::HomeLens* m_homeLens;74 unity::dash::HomeLens* m_homeLens;
69 QList<Lens*> m_lenses;75 QList<Lens*> m_lenses;
76 QHash<Lens*, Hotkey*> m_lensShorcuts;
77 QSignalMapper m_shortcutMapper;
7078
79 void setLensShortcut(Lens *lens);
71 void addUnityLens(unity::dash::Lens::Ptr unity_lens, int index);80 void addUnityLens(unity::dash::Lens::Ptr unity_lens, int index);
72 void removeUnityLens(int index);81 void removeUnityLens(int index);
73};82};
7483
=== modified file 'shell/dash/Dash.qml'
--- shell/dash/Dash.qml 2012-04-03 10:10:02 +0000
+++ shell/dash/Dash.qml 2012-04-04 09:44:20 +0000
@@ -226,6 +226,7 @@
226 }226 }
227 }227 }
228 }228 }
229 onActivateLensRequested: activateLens(lens_id)
229 }230 }
230231
231 Background {232 Background {

Subscribers

People subscribed via source and target branches