on 877dfdf help sign in
unity8/plugins/Unity/Launcher/launcheritem.cpp
219 lines 5.0 kB history raw
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 */
20#include "launcheritem.h"
21#include "quicklistmodel.h"
23#include <libintl.h>
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))
40 Q_ASSERT(parent != nullptr);
41 QuickListEntry nameAction;
42 nameAction.setActionId(QStringLiteral("launch_item"));
43 nameAction.setText(m_name);
44 m_quickList->appendAction(nameAction);
46 QuickListEntry pinningAction;
47 pinningAction.setActionId(QStringLiteral("pin_item"));
48 pinningAction.setText(gettext("Pin shortcut"));
49 m_quickList->appendAction(pinningAction);
51 m_quitAction.setActionId(QStringLiteral("stop_item"));
52 m_quitAction.setIcon(QStringLiteral("application-exit"));
53 m_quitAction.setText(gettext("Quit"));
56QString LauncherItem::appId() const
58 return m_appId;
61QString LauncherItem::name() const
63 return m_name;
66void LauncherItem::setName(const QString &name)
68 if (m_name != name) {
69 m_name = name;
70 QuickListEntry entry;
71 entry.setActionId(QStringLiteral("launch_item"));
72 entry.setText(m_name);
73 m_quickList->updateAction(entry);
74 Q_EMIT nameChanged(name);
75 }
78QString LauncherItem::icon() const
80 return m_icon;
83void LauncherItem::setIcon(const QString &icon)
85 if (m_icon != icon) {
86 m_icon = icon;
87 Q_EMIT iconChanged(icon);
88 }
91bool LauncherItem::pinned() const
93 return m_pinned;
96void LauncherItem::setPinned(bool pinned)
98 if (m_pinned != pinned) {
99 m_pinned = pinned;
100 Q_EMIT pinnedChanged(pinned);
101 }
103 // Even if pinned status didn't change, we want to update text in case
104 // the locale has changed since we last set pinned status.
105 QuickListEntry entry;
106 entry.setActionId(QStringLiteral("pin_item"));
107 entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
108 m_quickList->updateAction(entry);
111bool LauncherItem::running() const
113 return m_running;
116void LauncherItem::setRunning(bool running)
118 if (m_running != running) {
119 m_running = running;
120 if (m_running) { // add the quit action
121 m_quickList->appendAction(m_quitAction);
122 } else { // remove the quit action
123 m_quickList->removeAction(m_quitAction);
124 }
125 Q_EMIT runningChanged(running);
126 }
129bool LauncherItem::recent() const
131 return m_recent;
134void LauncherItem::setRecent(bool recent)
136 if (m_recent != recent) {
137 m_recent = recent;
138 Q_EMIT recentChanged(recent);
139 }
142int LauncherItem::progress() const
144 return m_progress;
147void LauncherItem::setProgress(int progress)
149 if (m_progress != progress) {
150 m_progress = progress;
151 Q_EMIT progressChanged(progress);
152 }
155int LauncherItem::count() const
157 return m_count;
160void LauncherItem::setCount(int count)
162 if (m_count != count) {
163 m_count = count;
164 Q_EMIT countChanged(count);
165 if (m_countVisible) {
166 setAlerting(true);
167 }
168 }
171bool LauncherItem::countVisible() const
173 return m_countVisible;
176void LauncherItem::setCountVisible(bool countVisible)
178 if (m_countVisible != countVisible) {
179 m_countVisible = countVisible;
180 Q_EMIT countVisibleChanged(countVisible);
181 if (countVisible) {
182 setAlerting(true);
183 }
184 }
187bool LauncherItem::focused() const
189 return m_focused;
192void LauncherItem::setFocused(bool focused)
194 if (m_focused != focused) {
195 m_focused = focused;
196 if (focused) {
197 setAlerting(false);
198 }
199 Q_EMIT focusedChanged(focused);
200 }
203bool LauncherItem::alerting() const
205 return m_alerting;
208void LauncherItem::setAlerting(bool alerting)
210 if (m_alerting != alerting) {
211 m_alerting = alerting;
212 Q_EMIT alertingChanged(alerting);
213 }
216unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
218 return m_quickList;