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