on 2b42fc5 help sign in
unity8/plugins/Unity/Launcher/launcheritem.cpp
195 lines 4.4 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_quickList(new QuickListModel(this))
39 QuickListEntry nameAction;
40 nameAction.setActionId("launch_item");
41 nameAction.setText(m_name);
42 m_quickList->appendAction(nameAction);
44 QuickListEntry pinningAction;
45 pinningAction.setActionId("pin_item");
46 pinningAction.setText(gettext("Pin shortcut"));
47 m_quickList->appendAction(pinningAction);
49 m_quitAction.setActionId("stop_item");
50 m_quitAction.setIcon("application-exit");
51 m_quitAction.setText(gettext("Quit"));
54QString LauncherItem::appId() const
56 return m_appId;
59QString LauncherItem::name() const
61 return m_name;
64void LauncherItem::setName(const QString &name)
66 if (m_name != name) {
67 m_name = name;
68 QuickListEntry entry;
69 entry.setActionId("launch_item");
70 entry.setText(m_name);
71 m_quickList->updateAction(entry);
72 Q_EMIT nameChanged(name);
73 }
76QString LauncherItem::icon() const
78 return m_icon;
81void LauncherItem::setIcon(const QString &icon)
83 if (m_icon != icon) {
84 m_icon = icon;
85 Q_EMIT iconChanged(icon);
86 }
89bool LauncherItem::pinned() const
91 return m_pinned;
94void LauncherItem::setPinned(bool pinned)
96 if (m_pinned != pinned) {
97 m_pinned = pinned;
98 Q_EMIT pinnedChanged(pinned);
99 }
101 // Even if pinned status didn't change, we want to update text in case
102 // the locale has changed since we last set pinned status.
103 QuickListEntry entry;
104 entry.setActionId("pin_item");
105 entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
106 m_quickList->updateAction(entry);
109bool LauncherItem::running() const
111 return m_running;
114void LauncherItem::setRunning(bool running)
116 if (m_running != running) {
117 m_running = running;
118 if (m_running) { // add the quit action
119 m_quickList->appendAction(m_quitAction);
120 } else { // remove the quit action
121 m_quickList->removeAction(m_quitAction);
122 }
123 Q_EMIT runningChanged(running);
124 }
127bool LauncherItem::recent() const
129 return m_recent;
132void LauncherItem::setRecent(bool recent)
134 if (m_recent != recent) {
135 m_recent = recent;
136 Q_EMIT recentChanged(recent);
137 }
140int LauncherItem::progress() const
142 return m_progress;
145void LauncherItem::setProgress(int progress)
147 if (m_progress != progress) {
148 m_progress = progress;
149 Q_EMIT progressChanged(progress);
150 }
153int LauncherItem::count() const
155 return m_count;
158void LauncherItem::setCount(int count)
160 if (m_count != count) {
161 m_count = count;
162 Q_EMIT countChanged(count);
163 }
166bool LauncherItem::countVisible() const
168 return m_countVisible;
171void LauncherItem::setCountVisible(bool countVisible)
173 if (m_countVisible != countVisible) {
174 m_countVisible = countVisible;
175 Q_EMIT countVisibleChanged(countVisible);
176 }
179bool LauncherItem::focused() const
181 return m_focused;
184void LauncherItem::setFocused(bool focused)
186 if (m_focused != focused) {
187 m_focused = focused;
188 Q_EMIT focusedChanged(focused);
189 }
192unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
194 return m_quickList;