Unity 8
 All Classes Functions
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_focused(false),
36  m_quickList(new QuickListModel(this))
37 {
38  QuickListEntry nameAction;
39  nameAction.setActionId("launch_item");
40  nameAction.setText(m_name);
41  m_quickList->appendAction(nameAction);
42  QuickListEntry pinningAction;
43  pinningAction.setActionId("pin_item");
44  pinningAction.setText(gettext("Pin shortcut"));
45  m_quickList->appendAction(pinningAction);
46 }
47 
48 QString LauncherItem::appId() const
49 {
50  return m_appId;
51 }
52 
53 QString LauncherItem::name() const
54 {
55  return m_name;
56 }
57 
58 QString LauncherItem::icon() const
59 {
60  return m_icon;
61 }
62 
63 bool LauncherItem::pinned() const
64 {
65  return m_pinned;
66 }
67 
68 void LauncherItem::setPinned(bool pinned)
69 {
70  if (m_pinned != pinned) {
71  m_pinned = pinned;
72  QuickListEntry entry;
73  entry.setActionId("pin_item");
74  entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
75  m_quickList->updateAction(entry);
76  Q_EMIT pinnedChanged(pinned);
77  }
78 }
79 
80 bool LauncherItem::running() const
81 {
82  return m_running;
83 }
84 
85 void LauncherItem::setRunning(bool running)
86 {
87  if (m_running != running) {
88  m_running = running;
89  Q_EMIT runningChanged(running);
90  }
91 }
92 
93 bool LauncherItem::recent() const
94 {
95  return m_recent;
96 }
97 
98 void LauncherItem::setRecent(bool recent)
99 {
100  if (m_recent != recent) {
101  m_recent = recent;
102  Q_EMIT recentChanged(recent);
103  }
104 }
105 
106 int LauncherItem::progress() const
107 {
108  return m_progress;
109 }
110 
111 void LauncherItem::setProgress(int progress)
112 {
113  if (m_progress != progress) {
114  m_progress = progress;
115  Q_EMIT progressChanged(progress);
116  }
117 }
118 
119 int LauncherItem::count() const
120 {
121  return m_count;
122 }
123 
124 void LauncherItem::setCount(int count)
125 {
126  if (m_count != count) {
127  m_count = count;
128  Q_EMIT countChanged(count);
129  }
130 }
131 
132 bool LauncherItem::focused() const
133 {
134  return m_focused;
135 }
136 
137 void LauncherItem::setFocused(bool focused)
138 {
139  if (m_focused != focused) {
140  m_focused = focused;
141  Q_EMIT focusedChanged(focused);
142  }
143 }
144 
145 unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
146 {
147  return m_quickList;
148 }