Merge lp:~osomon/unity-2d/custom-quicklists-static into lp:unity-2d/3.0

Proposed by Olivier Tilloy
Status: Merged
Approved by: Florian Boucault
Approved revision: 552
Merged at revision: 550
Proposed branch: lp:~osomon/unity-2d/custom-quicklists-static
Merge into: lp:unity-2d/3.0
Diff against target: 167 lines (+55/-9)
4 files modified
launcher/UnityApplications/CMakeLists.txt (+3/-0)
launcher/UnityApplications/launcherapplication.cpp (+34/-1)
launcher/UnityApplications/launcherapplication.h (+7/-0)
launcher/UnityApplications/launchermenu.cpp (+11/-8)
To merge this branch: bzr merge lp:~osomon/unity-2d/custom-quicklists-static
Reviewer Review Type Date Requested Status
Florian Boucault (community) code Approve
Review via email: mp+59329@code.launchpad.net

Commit message

[launcher] Support static shortcuts in the quicklists.

Static shortcuts are defined in the application’s desktop file.
See https://wiki.ubuntu.com/Unity/LauncherAPI#Static%20Quicklist%20entries for documentation.

To post a comment you must log in.
Revision history for this message
Florian Boucault (fboucault) wrote :

Behaves properly after extensive testing.

review: Approve (functional)
Revision history for this message
Florian Boucault (fboucault) wrote :

In launcher/UnityApplications/launchermenu.cpp:

[...]
    if (folded) {
        /* Remove all actions but the title. */
        for (int i = actions().size(); i > 0; --i) {
            QAction* action = actions().at(i - 1);
[...]

The use of a reverse for loop does not seem necessary. A forward one would be simpler. And even better would be to use a Q_FOREACH.

review: Needs Fixing
Revision history for this message
Olivier Tilloy (osomon) wrote :

> The use of a reverse for loop does not seem necessary. A forward one would be
> simpler. And even better would be to use a Q_FOREACH.

It *is* necessary because in this loop we are potentially removing the current action from the list, thus invalidating greater indexes. Iterating backward ensures the current index is always valid without having to resort to complex arithmetics.

Revision history for this message
Florian Boucault (fboucault) wrote :

> > The use of a reverse for loop does not seem necessary. A forward one would
> be
> > simpler. And even better would be to use a Q_FOREACH.
>
> It *is* necessary because in this loop we are potentially removing the current
> action from the list, thus invalidating greater indexes. Iterating backward
> ensures the current index is always valid without having to resort to complex
> arithmetics.

I had not seen that.
Q_FOREACH would still work in that case because it operates on a copy of the list as soon as it is modified I believe.

Revision history for this message
Florian Boucault (fboucault) wrote :

The rest of the code looks good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/UnityApplications/CMakeLists.txt'
--- launcher/UnityApplications/CMakeLists.txt 2011-03-22 22:55:11 +0000
+++ launcher/UnityApplications/CMakeLists.txt 2011-04-28 08:01:10 +0000
@@ -8,6 +8,7 @@
8pkg_check_modules(GIO REQUIRED gio-2.0)8pkg_check_modules(GIO REQUIRED gio-2.0)
9pkg_check_modules(WNCK REQUIRED libwnck-1.0)9pkg_check_modules(WNCK REQUIRED libwnck-1.0)
10pkg_check_modules(STARTUPNOTIFICATION REQUIRED libstartup-notification-1.0)10pkg_check_modules(STARTUPNOTIFICATION REQUIRED libstartup-notification-1.0)
11pkg_check_modules(INDICATOR REQUIRED indicator)
1112
12# Sources13# Sources
13set(UnityApplications_SRCS14set(UnityApplications_SRCS
@@ -70,6 +71,7 @@
70 ${GIO_INCLUDE_DIRS}71 ${GIO_INCLUDE_DIRS}
71 ${WNCK_INCLUDE_DIRS}72 ${WNCK_INCLUDE_DIRS}
72 ${STARTUPNOTIFICATION_INCLUDE_DIRS}73 ${STARTUPNOTIFICATION_INCLUDE_DIRS}
74 ${INDICATOR_INCLUDE_DIRS}
73 )75 )
7476
75target_link_libraries(UnityApplications77target_link_libraries(UnityApplications
@@ -86,6 +88,7 @@
86 ${GIO_LDFLAGS}88 ${GIO_LDFLAGS}
87 ${WNCK_LDFLAGS}89 ${WNCK_LDFLAGS}
88 ${STARTUPNOTIFICATION_LDFLAGS}90 ${STARTUPNOTIFICATION_LDFLAGS}
91 ${INDICATOR_LDFLAGS}
89 )92 )
9093
91# Install94# Install
9295
=== modified file 'launcher/UnityApplications/launcherapplication.cpp'
--- launcher/UnityApplications/launcherapplication.cpp 2011-04-14 14:27:36 +0000
+++ launcher/UnityApplications/launcherapplication.cpp 2011-04-28 08:01:10 +0000
@@ -61,6 +61,8 @@
61#include <libsn/sn.h>61#include <libsn/sn.h>
62}62}
6363
64const char* SHORTCUT_NICK_PROPERTY = "nick";
65
64LauncherApplication::LauncherApplication()66LauncherApplication::LauncherApplication()
65 : m_application(NULL)67 : m_application(NULL)
66 , m_desktopFileWatcher(NULL)68 , m_desktopFileWatcher(NULL)
@@ -290,6 +292,10 @@
290 Q_EMIT executableChanged(executable());292 Q_EMIT executableChanged(executable());
291 }293 }
292294
295 /* Update the list of static shortcuts
296 (quicklist entries defined in the desktop file). */
297 m_staticShortcuts.reset(indicator_desktop_shortcuts_new(newDesktopFile.toUtf8().constData(), "Unity"));
298
293 monitorDesktopFile(newDesktopFile);299 monitorDesktopFile(newDesktopFile);
294}300}
295301
@@ -840,9 +846,27 @@
840void846void
841LauncherApplication::createStaticMenuActions()847LauncherApplication::createStaticMenuActions()
842{848{
843 m_menu->addSeparator();
844 QList<QAction*> actions;849 QList<QAction*> actions;
845850
851 /* Custom menu actions from the desktop file. */
852 if (!m_staticShortcuts.isNull()) {
853 const gchar** nicks = indicator_desktop_shortcuts_get_nicks(m_staticShortcuts.data());
854 if (nicks) {
855 int i = 0;
856 while (((gpointer*) nicks)[i]) {
857 const gchar* nick = nicks[i];
858 QAction* action = new QAction(m_menu);
859 action->setText(QString::fromUtf8(indicator_desktop_shortcuts_nick_get_name(m_staticShortcuts.data(), nick)));
860 action->setProperty(SHORTCUT_NICK_PROPERTY, QVariant(nick));
861 actions.append(action);
862 connect(action, SIGNAL(triggered()), SLOT(onStaticShortcutTriggered()));
863 ++i;
864 }
865 }
866 }
867 m_menu->insertActions(m_menu->actions().first(), actions);
868
869 actions.clear();
846 bool is_running = running();870 bool is_running = running();
847871
848 /* Only applications with a corresponding desktop file can be kept in the launcher */872 /* Only applications with a corresponding desktop file can be kept in the launcher */
@@ -911,6 +935,15 @@
911}935}
912936
913void937void
938LauncherApplication::onStaticShortcutTriggered()
939{
940 QAction* action = static_cast<QAction*>(sender());
941 QString nick = action->property(SHORTCUT_NICK_PROPERTY).toString();
942 m_menu->hide();
943 indicator_desktop_shortcuts_nick_exec(m_staticShortcuts.data(), nick.toUtf8().constData());
944}
945
946void
914LauncherApplication::onKeepTriggered()947LauncherApplication::onKeepTriggered()
915{948{
916 QAction* keep = static_cast<QAction*>(sender());949 QAction* keep = static_cast<QAction*>(sender());
917950
=== modified file 'launcher/UnityApplications/launcherapplication.h'
--- launcher/UnityApplications/launcherapplication.h 2011-04-07 09:16:50 +0000
+++ launcher/UnityApplications/launcherapplication.h 2011-04-28 08:01:10 +0000
@@ -20,6 +20,9 @@
20#include <gio/gdesktopappinfo.h>20#include <gio/gdesktopappinfo.h>
21#include <libwnck/libwnck.h>21#include <libwnck/libwnck.h>
2222
23// libindicator
24#include <libindicator/indicator-desktop-shortcuts.h>
25
23#include "launcheritem.h"26#include "launcheritem.h"
2427
25// libunity-2d28// libunity-2d
@@ -47,6 +50,7 @@
47typedef GObjectScopedPointer<GAppInfo> GAppInfoPointer;50typedef GObjectScopedPointer<GAppInfo> GAppInfoPointer;
48typedef GObjectScopedPointer<GDesktopAppInfo> GDesktopAppInfoPointer;51typedef GObjectScopedPointer<GDesktopAppInfo> GDesktopAppInfoPointer;
49typedef GScopedPointer<SnStartupSequence, sn_startup_sequence_unref> SnStartupSequencePointer;52typedef GScopedPointer<SnStartupSequence, sn_startup_sequence_unref> SnStartupSequencePointer;
53typedef GObjectScopedPointer<IndicatorDesktopShortcuts> IndicatorDesktopShortcutsPointer;
50class LauncherApplication : public LauncherItem54class LauncherApplication : public LauncherItem
51{55{
52 Q_OBJECT56 Q_OBJECT
@@ -135,6 +139,7 @@
135 void show();139 void show();
136140
137 /* Contextual menu callbacks */141 /* Contextual menu callbacks */
142 void onStaticShortcutTriggered();
138 void onKeepTriggered();143 void onKeepTriggered();
139 void onQuitTriggered();144 void onQuitTriggered();
140145
@@ -175,6 +180,8 @@
175 template<typename T>180 template<typename T>
176 bool updateOverlayState(QMap<QString, QVariant> properties,181 bool updateOverlayState(QMap<QString, QVariant> properties,
177 QString propertyName, T* member);182 QString propertyName, T* member);
183
184 IndicatorDesktopShortcutsPointer m_staticShortcuts;
178};185};
179186
180Q_DECLARE_METATYPE(LauncherApplication*)187Q_DECLARE_METATYPE(LauncherApplication*)
181188
=== modified file 'launcher/UnityApplications/launchermenu.cpp'
--- launcher/UnityApplications/launchermenu.cpp 2011-03-21 13:03:36 +0000
+++ launcher/UnityApplications/launchermenu.cpp 2011-04-28 08:01:10 +0000
@@ -190,17 +190,20 @@
190 }190 }
191191
192 if (folded) {192 if (folded) {
193 /* Remove all actions but the first one (the title). */193 /* Remove all actions but the title. */
194 while (actions().size() > 1) {194 for (int i = actions().size(); i > 0; --i) {
195 QAction* action = actions().last();195 QAction* action = actions().at(i - 1);
196 removeAction(action);196 if (action != m_titleAction) {
197 if (action->parent() == this) {197 removeAction(action);
198 /* Delete the action only if we "own" it,198 if (action->parent() == this) {
199 otherwise let its parent take care of it. */199 /* Delete the action only if we "own" it,
200 delete action;200 otherwise let its parent take care of it. */
201 delete action;
202 }
201 }203 }
202 }204 }
203 } else {205 } else {
206 insertSeparator(m_titleAction);
204 addSeparator();207 addSeparator();
205 m_launcherItem->createMenuActions();208 m_launcherItem->createMenuActions();
206209

Subscribers

People subscribed via source and target branches