on c293465 help sign in
unity8/plugins/Unity/Launcher/launcheritem.cpp
204 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>
24#include <iostream>
26LauncherItem::LauncherItem(const QString &appId, const QString &name, const QString &icon, QObject *parent) :
27 LauncherItemInterface(parent),
28 m_appId(appId),
29 m_name(name),
30 m_icon(icon),
31 m_pinned(false),
32 m_running(false),
33 m_recent(false),
34 m_progress(-1),
35 m_count(0),
36 m_countVisible(false),
37 m_focused(false),
38 m_alerting(false),
39 m_quickList(new QuickListModel(this))
41 QuickListEntry nameAction;
42 nameAction.setActionId("launch_item");
43 nameAction.setText(m_name);
44 m_quickList->appendAction(nameAction);
45 QuickListEntry pinningAction;
46 pinningAction.setActionId("pin_item");
47 pinningAction.setText(gettext("Pin shortcut"));
48 m_quickList->appendAction(pinningAction);
51QString LauncherItem::appId() const
53 return m_appId;
56QString LauncherItem::name() const
58 return m_name;
61void LauncherItem::setName(const QString &name)
63 if (m_name != name) {
64 m_name = name;
65 QuickListEntry entry;
66 entry.setActionId("launch_item");
67 entry.setText(m_name);
68 m_quickList->updateAction(entry);
69 Q_EMIT nameChanged(name);
70 }
73QString LauncherItem::icon() const
75 return m_icon;
78void LauncherItem::setIcon(const QString &icon)
80 if (m_icon != icon) {
81 m_icon = icon;
82 Q_EMIT iconChanged(icon);
83 }
86bool LauncherItem::pinned() const
88 return m_pinned;
91void LauncherItem::setPinned(bool pinned)
93 if (m_pinned != pinned) {
94 m_pinned = pinned;
95 Q_EMIT pinnedChanged(pinned);
96 }
98 // Even if pinned status didn't change, we want to update text in case
99 // the locale has changed since we last set pinned status.
100 QuickListEntry entry;
101 entry.setActionId("pin_item");
102 entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
103 m_quickList->updateAction(entry);
106bool LauncherItem::running() const
108 return m_running;
111void LauncherItem::setRunning(bool running)
113 if (m_running != running) {
114 m_running = running;
115 Q_EMIT runningChanged(running);
116 }
119bool LauncherItem::recent() const
121 return m_recent;
124void LauncherItem::setRecent(bool recent)
126 if (m_recent != recent) {
127 m_recent = recent;
128 Q_EMIT recentChanged(recent);
129 }
132int LauncherItem::progress() const
134 return m_progress;
137void LauncherItem::setProgress(int progress)
139 if (m_progress != progress) {
140 m_progress = progress;
141 Q_EMIT progressChanged(progress);
142 }
145int LauncherItem::count() const
147 return m_count;
150void LauncherItem::setCount(int count)
152 if (m_count != count) {
153 m_count = count;
154 Q_EMIT countChanged(count);
155 }
158bool LauncherItem::countVisible() const
160 return m_countVisible;
163void LauncherItem::setCountVisible(bool countVisible)
165 if (m_countVisible != countVisible) {
166 m_countVisible = countVisible;
167 Q_EMIT countVisibleChanged(countVisible);
168 }
171bool LauncherItem::focused() const
173 return m_focused;
176void LauncherItem::setFocused(bool focused)
178 if (m_focused != focused) {
179 m_focused = focused;
180 if (!focused) {
181 setAlerting(false);
182 }
183 Q_EMIT focusedChanged(focused);
184 }
187bool LauncherItem::alerting() const
189 return m_alerting;
192void LauncherItem::setAlerting(bool alerting)
194 std::cout << "LauncherItem::setAlerting()" << std::endl;
195 if (m_alerting != alerting) {
196 m_alerting = alerting;
197 Q_EMIT alertingChanged(alerting);
198 }
201unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
203 return m_quickList;