on aa291ee help sign in
unity8/plugins/Unity/Launcher/launcheritem.cpp
218 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 QuickListEntry nameAction;
41 nameAction.setActionId(QStringLiteral("launch_item"));
42 nameAction.setText(m_name);
43 m_quickList->appendAction(nameAction);
45 QuickListEntry pinningAction;
46 pinningAction.setActionId(QStringLiteral("pin_item"));
47 pinningAction.setText(gettext("Pin shortcut"));
48 m_quickList->appendAction(pinningAction);
50 m_quitAction.setActionId(QStringLiteral("stop_item"));
51 m_quitAction.setIcon(QStringLiteral("application-exit"));
52 m_quitAction.setText(gettext("Quit"));
55QString LauncherItem::appId() const
57 return m_appId;
60QString LauncherItem::name() const
62 return m_name;
65void LauncherItem::setName(const QString &name)
67 if (m_name != name) {
68 m_name = name;
69 QuickListEntry entry;
70 entry.setActionId(QStringLiteral("launch_item"));
71 entry.setText(m_name);
72 m_quickList->updateAction(entry);
73 Q_EMIT nameChanged(name);
74 }
77QString LauncherItem::icon() const
79 return m_icon;
82void LauncherItem::setIcon(const QString &icon)
84 if (m_icon != icon) {
85 m_icon = icon;
86 Q_EMIT iconChanged(icon);
87 }
90bool LauncherItem::pinned() const
92 return m_pinned;
95void LauncherItem::setPinned(bool pinned)
97 if (m_pinned != pinned) {
98 m_pinned = pinned;
99 Q_EMIT pinnedChanged(pinned);
100 }
102 // Even if pinned status didn't change, we want to update text in case
103 // the locale has changed since we last set pinned status.
104 QuickListEntry entry;
105 entry.setActionId(QStringLiteral("pin_item"));
106 entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
107 m_quickList->updateAction(entry);
110bool LauncherItem::running() const
112 return m_running;
115void LauncherItem::setRunning(bool running)
117 if (m_running != running) {
118 m_running = running;
119 if (m_running) { // add the quit action
120 m_quickList->appendAction(m_quitAction);
121 } else { // remove the quit action
122 m_quickList->removeAction(m_quitAction);
123 }
124 Q_EMIT runningChanged(running);
125 }
128bool LauncherItem::recent() const
130 return m_recent;
133void LauncherItem::setRecent(bool recent)
135 if (m_recent != recent) {
136 m_recent = recent;
137 Q_EMIT recentChanged(recent);
138 }
141int LauncherItem::progress() const
143 return m_progress;
146void LauncherItem::setProgress(int progress)
148 if (m_progress != progress) {
149 m_progress = progress;
150 Q_EMIT progressChanged(progress);
151 }
154int LauncherItem::count() const
156 return m_count;
159void LauncherItem::setCount(int count)
161 if (m_count != count) {
162 m_count = count;
163 Q_EMIT countChanged(count);
164 if (m_countVisible) {
165 setAlerting(true);
166 }
167 }
170bool LauncherItem::countVisible() const
172 return m_countVisible;
175void LauncherItem::setCountVisible(bool countVisible)
177 if (m_countVisible != countVisible) {
178 m_countVisible = countVisible;
179 Q_EMIT countVisibleChanged(countVisible);
180 if (countVisible) {
181 setAlerting(true);
182 }
183 }
186bool LauncherItem::focused() const
188 return m_focused;
191void LauncherItem::setFocused(bool focused)
193 if (m_focused != focused) {
194 m_focused = focused;
195 if (focused) {
196 setAlerting(false);
197 }
198 Q_EMIT focusedChanged(focused);
199 }
202bool LauncherItem::alerting() const
204 return m_alerting;
207void LauncherItem::setAlerting(bool alerting)
209 if (m_alerting != alerting) {
210 m_alerting = alerting;
211 Q_EMIT alertingChanged(alerting);
212 }
215unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
217 return m_quickList;