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