Lomiri
Loading...
Searching...
No Matches
launcheritem.cpp
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#include "launcheritem.h"
21#include "quicklistmodel.h"
22
23#include <libintl.h>
24
25LauncherItem::LauncherItem(const QString &appId, const QString &name, const QString &icon, QObject *parent) :
26 LauncherItemInterface(parent),
27 m_appId(appId),
28 m_name(name),
29 m_icon(icon),
30 m_pinned(false),
31 m_running(false),
32 m_recent(false),
33 m_progress(-1),
34 m_count(0),
35 m_countVisible(false),
36 m_focused(false),
37 m_alerting(false),
38 m_quickList(new QuickListModel(this))
39{
40 QuickListEntry nameAction;
41 nameAction.setActionId(QStringLiteral("launch_item"));
42 nameAction.setText(m_name);
43 nameAction.setHasSeparator(true);
44 m_quickList->appendAction(nameAction);
45
46 QuickListEntry pinningAction;
47 pinningAction.setActionId(QStringLiteral("pin_item"));
48 pinningAction.setText(gettext("Pin shortcut"));
49 pinningAction.setIsPrivate(true);
50 m_quickList->appendAction(pinningAction);
51
52 m_quitAction.setActionId(QStringLiteral("stop_item"));
53 m_quitAction.setIcon(QStringLiteral("application-exit"));
54 m_quitAction.setText(gettext("Quit"));
55 m_quitAction.setIsPrivate(true);
56}
57
58QString LauncherItem::appId() const
59{
60 return m_appId;
61}
62
63QString LauncherItem::name() const
64{
65 return m_name;
66}
67
68void LauncherItem::setName(const QString &name)
69{
70 if (m_name != name) {
71 m_name = name;
72 QuickListEntry entry;
73 entry.setActionId(QStringLiteral("launch_item"));
74 entry.setText(m_name);
75 m_quickList->updateAction(entry);
76 Q_EMIT nameChanged(name);
77 }
78}
79
80QString LauncherItem::icon() const
81{
82 return m_icon;
83}
84
85void LauncherItem::setIcon(const QString &icon)
86{
87 if (m_icon != icon) {
88 m_icon = icon;
89 Q_EMIT iconChanged(icon);
90 }
91}
92
93QStringList LauncherItem::keywords() const
94{
95 return m_keywords;
96}
97
98void LauncherItem::setKeywords(const QStringList &keywords)
99{
100 if (m_keywords != keywords) {
101 m_keywords = keywords;
102 Q_EMIT keywordsChanged(keywords);
103 }
104}
105
106bool LauncherItem::pinned() const
107{
108 return m_pinned;
109}
110
111void LauncherItem::setPinned(bool pinned)
112{
113 if (m_pinned != pinned) {
114 m_pinned = pinned;
115 Q_EMIT pinnedChanged(pinned);
116 }
117
118 // Even if pinned status didn't change, we want to update text in case
119 // the locale has changed since we last set pinned status.
120 QuickListEntry entry;
121 entry.setActionId(QStringLiteral("pin_item"));
122 entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
123 entry.setIsPrivate(true);
124 m_quickList->updateAction(entry);
125}
126
127bool LauncherItem::running() const
128{
129 return m_running;
130}
131
132void LauncherItem::setRunning(bool running)
133{
134 if (m_running != running) {
135 m_running = running;
136 if (m_running) { // add the quit action
137 m_quickList->appendAction(m_quitAction);
138 } else { // remove the quit action
139 m_quickList->removeAction(m_quitAction);
140 }
141 Q_EMIT runningChanged(running);
142 }
143}
144
145bool LauncherItem::recent() const
146{
147 return m_recent;
148}
149
150void LauncherItem::setRecent(bool recent)
151{
152 if (m_recent != recent) {
153 m_recent = recent;
154 Q_EMIT recentChanged(recent);
155 }
156}
157
158int LauncherItem::progress() const
159{
160 return m_progress;
161}
162
163void LauncherItem::setProgress(int progress)
164{
165 if (m_progress != progress) {
166 m_progress = progress;
167 Q_EMIT progressChanged(progress);
168 }
169}
170
171int LauncherItem::count() const
172{
173 return m_count;
174}
175
176void LauncherItem::setCount(int count)
177{
178 if (m_count != count) {
179 m_count = count;
180 Q_EMIT countChanged(count);
181 }
182}
183
184bool LauncherItem::countVisible() const
185{
186 return m_countVisible;
187}
188
189void LauncherItem::setCountVisible(bool countVisible)
190{
191 if (m_countVisible != countVisible) {
192 m_countVisible = countVisible;
193 Q_EMIT countVisibleChanged(countVisible);
194 }
195}
196
197bool LauncherItem::focused() const
198{
199 return m_focused;
200}
201
202void LauncherItem::setFocused(bool focused)
203{
204 if (m_focused != focused) {
205 m_focused = focused;
206 Q_EMIT focusedChanged(focused);
207 }
208}
209
210bool LauncherItem::alerting() const
211{
212 return m_alerting;
213}
214
215void LauncherItem::setAlerting(bool alerting)
216{
217 if (m_alerting != alerting) {
218 m_alerting = alerting;
219 Q_EMIT alertingChanged(alerting);
220 }
221}
222
223int LauncherItem::surfaceCount() const
224{
225 return m_surfaces.count();
226}
227
228void LauncherItem::setSurfaces(const QList<QPair<QString, QString> > &surfaces)
229{
230 if (m_surfaces != surfaces) {
231 m_surfaces = surfaces;
232
233 QList<QuickListEntry> removedEntries;
234 for (int i = 0; i < m_quickList->rowCount(); ++i) {
235 QuickListEntry entry = m_quickList->get(i);
236 if (entry.actionId().startsWith(QStringLiteral("surface_"))) {
237 removedEntries.append(entry);
238 }
239 }
240 Q_FOREACH (const QuickListEntry &entry, removedEntries) {
241 m_quickList->removeAction(entry);
242 }
243 for (int i = 0; i < surfaces.count(); ++i) {
244 QuickListEntry entry;
245 entry.setActionId(QStringLiteral("surface_") + surfaces.at(i).first);
246 entry.setText(surfaces.at(i).second);
247 entry.setIsPrivate(true);
248 if (i == surfaces.count() - 1) {
249 entry.setHasSeparator(true);
250 }
251 m_quickList->insertAction(entry, i + 1);
252 }
253
254 Q_EMIT surfaceCountChanged(m_surfaces.count());
255 }
256}
257
258uint LauncherItem::popularity() const
259{
260 return m_popularity;
261}
262
263void LauncherItem::setPopularity(uint popularity)
264{
265 if (m_popularity != popularity) {
266 m_popularity = popularity;
267 Q_EMIT popularityChanged(popularity);
268 }
269}
270
271lomiri::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
272{
273 return m_quickList;
274}