on e198a75 help sign in
unity8/plugins/Unity/Launcher/launcheritem.cpp
208 lines 4.5 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("launch_item");
42 nameAction.setText(m_name);
43 m_quickList->appendAction(nameAction);
44 QuickListEntry pinningAction;
45 pinningAction.setActionId("pin_item");
46 pinningAction.setText(gettext("Pin shortcut"));
47 m_quickList->appendAction(pinningAction);
50QString LauncherItem::appId() const
52 return m_appId;
55QString LauncherItem::name() const
57 return m_name;
60void LauncherItem::setName(const QString &name)
62 if (m_name != name) {
63 m_name = name;
64 QuickListEntry entry;
65 entry.setActionId("launch_item");
66 entry.setText(m_name);
67 m_quickList->updateAction(entry);
68 Q_EMIT nameChanged(name);
69 }
72QString LauncherItem::icon() const
74 return m_icon;
77void LauncherItem::setIcon(const QString &icon)
79 if (m_icon != icon) {
80 m_icon = icon;
81 Q_EMIT iconChanged(icon);
82 }
85bool LauncherItem::pinned() const
87 return m_pinned;
90void LauncherItem::setPinned(bool pinned)
92 if (m_pinned != pinned) {
93 m_pinned = pinned;
94 Q_EMIT pinnedChanged(pinned);
95 }
97 // Even if pinned status didn't change, we want to update text in case
98 // the locale has changed since we last set pinned status.
99 QuickListEntry entry;
100 entry.setActionId("pin_item");
101 entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
102 m_quickList->updateAction(entry);
105bool LauncherItem::running() const
107 return m_running;
110void LauncherItem::setRunning(bool running)
112 if (m_running != running) {
113 m_running = running;
114 Q_EMIT runningChanged(running);
115 }
118bool LauncherItem::recent() const
120 return m_recent;
123void LauncherItem::setRecent(bool recent)
125 if (m_recent != recent) {
126 m_recent = recent;
127 Q_EMIT recentChanged(recent);
128 }
131int LauncherItem::progress() const
133 return m_progress;
136void LauncherItem::setProgress(int progress)
138 if (m_progress != progress) {
139 m_progress = progress;
140 Q_EMIT progressChanged(progress);
141 }
144int LauncherItem::count() const
146 return m_count;
149void LauncherItem::setCount(int count)
151 if (m_count != count) {
152 m_count = count;
153 Q_EMIT countChanged(count);
154 if (m_countVisible) {
155 setAlerting(true);
156 }
157 }
160bool LauncherItem::countVisible() const
162 return m_countVisible;
165void LauncherItem::setCountVisible(bool countVisible)
167 if (m_countVisible != countVisible) {
168 m_countVisible = countVisible;
169 Q_EMIT countVisibleChanged(countVisible);
170 if (countVisible) {
171 setAlerting(true);
172 }
173 }
176bool LauncherItem::focused() const
178 return m_focused;
181void LauncherItem::setFocused(bool focused)
183 if (m_focused != focused) {
184 m_focused = focused;
185 if (focused) {
186 setAlerting(false);
187 }
188 Q_EMIT focusedChanged(focused);
189 }
192bool LauncherItem::alerting() const
194 return m_alerting;
197void LauncherItem::setAlerting(bool alerting)
199 if (m_alerting != alerting) {
200 m_alerting = alerting;
201 Q_EMIT alertingChanged(alerting);
202 }
205unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
207 return m_quickList;