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