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