Unity 8
launcheritem.cpp
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  */
19 
20 #include "launcheritem.h"
21 #include "quicklistmodel.h"
22 
23 #include <libintl.h>
24 
25 LauncherItem::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_surfaceCount(0),
39  m_quickList(new QuickListModel(this))
40 {
41  Q_ASSERT(parent != nullptr);
42  QuickListEntry nameAction;
43  nameAction.setActionId(QStringLiteral("launch_item"));
44  nameAction.setText(m_name);
45  m_quickList->appendAction(nameAction);
46 
47  QuickListEntry pinningAction;
48  pinningAction.setActionId(QStringLiteral("pin_item"));
49  pinningAction.setText(gettext("Pin shortcut"));
50  m_quickList->appendAction(pinningAction);
51 
52  m_quitAction.setActionId(QStringLiteral("stop_item"));
53  m_quitAction.setIcon(QStringLiteral("application-exit"));
54  m_quitAction.setText(gettext("Quit"));
55 }
56 
57 QString LauncherItem::appId() const
58 {
59  return m_appId;
60 }
61 
62 QString LauncherItem::name() const
63 {
64  return m_name;
65 }
66 
67 void LauncherItem::setName(const QString &name)
68 {
69  if (m_name != name) {
70  m_name = name;
71  QuickListEntry entry;
72  entry.setActionId(QStringLiteral("launch_item"));
73  entry.setText(m_name);
74  m_quickList->updateAction(entry);
75  Q_EMIT nameChanged(name);
76  }
77 }
78 
79 QString LauncherItem::icon() const
80 {
81  return m_icon;
82 }
83 
84 void LauncherItem::setIcon(const QString &icon)
85 {
86  if (m_icon != icon) {
87  m_icon = icon;
88  Q_EMIT iconChanged(icon);
89  }
90 }
91 
92 bool LauncherItem::pinned() const
93 {
94  return m_pinned;
95 }
96 
97 void LauncherItem::setPinned(bool pinned)
98 {
99  if (m_pinned != pinned) {
100  m_pinned = pinned;
101  Q_EMIT pinnedChanged(pinned);
102  }
103 
104  // Even if pinned status didn't change, we want to update text in case
105  // the locale has changed since we last set pinned status.
106  QuickListEntry entry;
107  entry.setActionId(QStringLiteral("pin_item"));
108  entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
109  m_quickList->updateAction(entry);
110 }
111 
112 bool LauncherItem::running() const
113 {
114  return m_running;
115 }
116 
117 void LauncherItem::setRunning(bool running)
118 {
119  if (m_running != running) {
120  m_running = running;
121  if (m_running) { // add the quit action
122  m_quickList->appendAction(m_quitAction);
123  } else { // remove the quit action
124  m_quickList->removeAction(m_quitAction);
125  }
126  Q_EMIT runningChanged(running);
127  }
128 }
129 
130 bool LauncherItem::recent() const
131 {
132  return m_recent;
133 }
134 
135 void LauncherItem::setRecent(bool recent)
136 {
137  if (m_recent != recent) {
138  m_recent = recent;
139  Q_EMIT recentChanged(recent);
140  }
141 }
142 
143 int LauncherItem::progress() const
144 {
145  return m_progress;
146 }
147 
148 void LauncherItem::setProgress(int progress)
149 {
150  if (m_progress != progress) {
151  m_progress = progress;
152  Q_EMIT progressChanged(progress);
153  }
154 }
155 
156 int LauncherItem::count() const
157 {
158  return m_count;
159 }
160 
161 void LauncherItem::setCount(int count)
162 {
163  if (m_count != count) {
164  m_count = count;
165  Q_EMIT countChanged(count);
166  }
167 }
168 
169 bool LauncherItem::countVisible() const
170 {
171  return m_countVisible;
172 }
173 
174 void LauncherItem::setCountVisible(bool countVisible)
175 {
176  if (m_countVisible != countVisible) {
177  m_countVisible = countVisible;
178  Q_EMIT countVisibleChanged(countVisible);
179  }
180 }
181 
182 bool LauncherItem::focused() const
183 {
184  return m_focused;
185 }
186 
187 void LauncherItem::setFocused(bool focused)
188 {
189  if (m_focused != focused) {
190  m_focused = focused;
191  Q_EMIT focusedChanged(focused);
192  }
193 }
194 
195 bool LauncherItem::alerting() const
196 {
197  return m_alerting;
198 }
199 
200 void LauncherItem::setAlerting(bool alerting)
201 {
202  if (m_alerting != alerting) {
203  m_alerting = alerting;
204  Q_EMIT alertingChanged(alerting);
205  }
206 }
207 
208 int LauncherItem::surfaceCount() const
209 {
210  return m_surfaceCount;
211 }
212 
213 void LauncherItem::setSurfaceCount(int surfaceCount)
214 {
215  if (m_surfaceCount != surfaceCount) {
216  m_surfaceCount = surfaceCount;
217  Q_EMIT surfaceCountChanged(surfaceCount);
218  }
219 }
220 
221 unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
222 {
223  return m_quickList;
224 }