Unity 8
launcheritem.cpp
1 /*
2  * Copyright 2014-2015 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 
17 #include "launcheritem.h"
18 #include "quicklistmodel.h"
19 
20 #include <libintl.h>
21 
22 LauncherItem::LauncherItem(const QString &appId, const QString &name, const QString &icon, QObject *parent) :
23  LauncherItemInterface(parent),
24  m_appId(appId),
25  m_name(name),
26  m_icon(icon),
27  m_pinned(false),
28  m_running(false),
29  m_recent(false),
30  m_progress(-1),
31  m_count(0),
32  m_countVisible(false),
33  m_focused(false),
34  m_alerting(false),
35  m_quickList(new QuickListModel(this))
36 {
37  QuickListEntry nameAction;
38  nameAction.setActionId(QStringLiteral("launch_item"));
39  nameAction.setText(m_name);
40  m_quickList->appendAction(nameAction);
41 }
42 
43 QString LauncherItem::appId() const
44 {
45  return m_appId;
46 }
47 
48 QString LauncherItem::name() const
49 {
50  return m_name;
51 }
52 
53 void LauncherItem::setName(const QString &name)
54 {
55  if (m_name != name) {
56  m_name = name;
57  QuickListEntry entry;
58  entry.setActionId(QStringLiteral("launch_item"));
59  entry.setText(m_name);
60  m_quickList->updateAction(entry);
61  Q_EMIT nameChanged(name);
62  }
63 }
64 
65 QString LauncherItem::icon() const
66 {
67  return m_icon;
68 }
69 
70 void LauncherItem::setIcon(const QString &icon)
71 {
72  if (m_icon != icon) {
73  m_icon = icon;
74  Q_EMIT iconChanged(icon);
75  }
76 }
77 
78 bool LauncherItem::pinned() const
79 {
80  return m_pinned;
81 }
82 
83 void LauncherItem::setPinned(bool pinned)
84 {
85  if (m_pinned != pinned) {
86  m_pinned = pinned;
87  Q_EMIT pinnedChanged(pinned);
88  }
89 }
90 
91 bool LauncherItem::running() const
92 {
93  return m_running;
94 }
95 
96 void LauncherItem::setRunning(bool running)
97 {
98  if (m_running != running) {
99  m_running = running;
100  Q_EMIT runningChanged(running);
101  }
102 }
103 
104 bool LauncherItem::recent() const
105 {
106  return m_recent;
107 }
108 
109 void LauncherItem::setRecent(bool recent)
110 {
111  if (m_recent != recent) {
112  m_recent = recent;
113  Q_EMIT recentChanged(recent);
114  }
115 }
116 
117 int LauncherItem::progress() const
118 {
119  return m_progress;
120 }
121 
122 void LauncherItem::setProgress(int progress)
123 {
124  if (m_progress != progress) {
125  m_progress = progress;
126  Q_EMIT progressChanged(progress);
127  }
128 }
129 
130 int LauncherItem::count() const
131 {
132  return m_count;
133 }
134 
135 void LauncherItem::setCount(int count)
136 {
137  if (m_count != count) {
138  m_count = count;
139  Q_EMIT countChanged(count);
140  }
141 }
142 
143 bool LauncherItem::countVisible() const
144 {
145  return m_countVisible;
146 }
147 
148 void LauncherItem::setCountVisible(bool countVisible)
149 {
150  if (m_countVisible != countVisible) {
151  m_countVisible = countVisible;
152  Q_EMIT countVisibleChanged(countVisible);
153  }
154 }
155 
156 bool LauncherItem::focused() const
157 {
158  return m_focused;
159 }
160 
161 void LauncherItem::setFocused(bool focused)
162 {
163  if (m_focused != focused) {
164  m_focused = focused;
165  Q_EMIT focusedChanged(focused);
166  }
167 }
168 
169 bool LauncherItem::alerting() const
170 {
171  return m_alerting;
172 }
173 
174 void LauncherItem::setAlerting(bool alerting)
175 {
176  if (m_alerting != alerting) {
177  m_alerting = alerting;
178  Q_EMIT alertingChanged(alerting);
179  }
180 }
181 
182 unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
183 {
184  return m_quickList;
185 }