on xenial help sign in
add backend
commit2fd0bb0f09a6c224e56b44813b0dbe956fbb6039 authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 2 Jul 2013, 12:03 (13 years ago) parentb1d8d0f
5 files changed+383
plugins/Unity/Launcher/backend/applicationlistmodel.cpp+40 plugins/Unity/Launcher/backend/applicationlistmodel.h+62 plugins/Unity/Launcher/backend/launcherbackend.cpp+103 plugins/Unity/Launcher/backend/launcherbackend.h+115 plugins/Unity/Launcher/backend/quicklistmodel.h+63
plugins/Unity/Launcher/backend/applicationlistmodel.cppnew file+40
@@ -0,0 +1,40 @@
1+#include "applicationlistmodel.h"
2+
3+#include <QDebug>
4+
5+ApplicationListModel::ApplicationListModel(QObject *parent):
6+ QAbstractListModel(parent)
7+{
8+
9+}
10+
11+void ApplicationListModel::addApplication(const QString &appId, int index)
12+{
13+ beginInsertRows(QModelIndex(), index, index);
14+ qDebug() << "inserting" << appId << "at" << index;
15+ m_list.insert(index, appId);
16+ endInsertRows();
17+}
18+
19+void ApplicationListModel::removeApplication(const QString &appId)
20+{
21+
22+}
23+
24+void ApplicationListModel::moveApplication(const QString &appId, int newIndex)
25+{
26+
27+}
28+
29+int ApplicationListModel::rowCount(const QModelIndex &parent) const
30+{
31+ return m_list.count();
32+}
33+
34+QVariant ApplicationListModel::data(const QModelIndex &index, int role) const
35+{
36+ if (role == RoleAppId) {
37+ return m_list.at(index.row());
38+ }
39+ return QVariant();
40+}
plugins/Unity/Launcher/backend/applicationlistmodel.hnew file+62
@@ -0,0 +1,62 @@
1+/* Copyright (C) 2013 Canonical, Ltd.
2+ *
3+ * Authors:
4+ * Michael Zanetti <michael.zanetti@canonical.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; version 3.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17+ */
18+
19+#ifndef APPLICATIONLISTMODEL_H
20+#define APPLICATIONLISTMODEL_H
21+
22+#include <QAbstractListModel>
23+
24+class ApplicationListModel: public QAbstractListModel
25+{
26+ Q_OBJECT
27+public:
28+ enum Roles {
29+ RoleAppId = Qt::UserRole +1
30+ };
31+
32+ explicit ApplicationListModel(QObject *parent = 0);
33+
34+ /**
35+ * @brief Add an application to the list of applications.
36+ * @param appId The ID of the application to be added.
37+ */
38+ void addApplication(const QString &appId, int index);
39+
40+ /**
41+ * @brief Remove an application from the list of applications.
42+ * @param appId The ID of the application to be removed.
43+ */
44+ void removeApplication(const QString &appId);
45+
46+ /**
47+ * @brief Move an application within the list
48+ * @param appId The ID of the application to be moved.
49+ * @param newIndex The new position for the entry.
50+ */
51+ void moveApplication(const QString &appId, int newIndex);
52+
53+
54+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
55+ QVariant data(const QModelIndex &index, int role) const;
56+
57+private:
58+ QList<QString> m_list;
59+};
60+
61+#endif // APPLICATIONLISTMODEL_H
62+
plugins/Unity/Launcher/backend/launcherbackend.cppnew file+103
@@ -0,0 +1,103 @@
1+#include "launcherbackend.h"
2+
3+#include "applicationlistmodel.h"
4+
5+LauncherBackend::LauncherBackend(QObject *parent):
6+ QObject(parent)
7+{
8+
9+ // TODO: load default pinned ones from default config, instead of hardcoding here...
10+
11+ m_favoriteApps <<
12+ QLatin1String("phone-app.desktop") <<
13+ QLatin1String("camera-app.desktop") <<
14+ QLatin1String("gallery-app.desktop") <<
15+ QLatin1String("facebook-webapp.desktop") <<
16+ QLatin1String("webbrowser-app.desktop") <<
17+ QLatin1String("twitter-webapp.desktop") <<
18+ QLatin1String("gmail-webapp.desktop") <<
19+ QLatin1String("ubuntu-weather-app.desktop") <<
20+ QLatin1String("notes-app.desktop") <<
21+ QLatin1String("ubuntu-calendar-app.desktop");
22+}
23+
24+LauncherBackend::~LauncherBackend()
25+{
26+
27+}
28+
29+QStringList LauncherBackend::favoriteApplications() const
30+{
31+ return m_favoriteApps;
32+}
33+
34+void LauncherBackend::setFavoriteApplications(const QStringList &appIds)
35+{
36+ m_favoriteApps = appIds;
37+ // TODO: Cleanup pinned state from settings for apps not in list any more.
38+}
39+
40+QString LauncherBackend::displayName(const QString &appId) const
41+{
42+ // TODO: get stuff from desktop files instead this hardcoded map
43+ QHash<QString, QString> map;
44+ map.insert("phone-app.desktop", "Phone");
45+ map.insert("camera-app.desktop", "Camera");
46+ map.insert("gallery-app.desktop", "Gallery");
47+ map.insert("facebook-webapp.desktop", "Facebook");
48+ map.insert("webbrowser-app.desktop", "Browser");
49+ map.insert("twitter-webapp.desktop", "Twitter");
50+ map.insert("gmail-webapp.desktop", "GMail");
51+ map.insert("ubuntu-weather-app.desktop", "Weather");
52+ map.insert("notes-app.desktop", "Notes");
53+ map.insert("ubuntu-calendar-app.desktop", "Calendar");
54+ return map.value(appId);
55+}
56+
57+QString LauncherBackend::icon(const QString &appId) const
58+{
59+ // TODO: get stuff from desktop files instead this hardcoded map
60+ QHash<QString, QString> map;
61+ map.insert("phone-app.desktop", "phone-app");
62+ map.insert("camera-app.desktop", "camera");
63+ map.insert("gallery-app.desktop", "gallery");
64+ map.insert("facebook-webapp.desktop", "facebook");
65+ map.insert("webbrowser-app.desktop", "browser");
66+ map.insert("twitter-webapp.desktop", "twitter");
67+ map.insert("gmail-webapp.desktop", "gmail");
68+ map.insert("ubuntu-weather-app.desktop", "weather");
69+ map.insert("notes-app.desktop", "notepad");
70+ map.insert("ubuntu-calendar-app.desktop", "calendar");
71+ return map.value(appId);
72+}
73+
74+bool LauncherBackend::isPinned(const QString &appId) const
75+{
76+ // TODO: return app's pinned state from settings
77+ return true;
78+}
79+
80+void LauncherBackend::setPinned(const QString &appId, bool pinned)
81+{
82+ // TODO: Store pinned state in settings.
83+}
84+
85+QuickListModelInterface* LauncherBackend::quickList(const QString &appId) const
86+{
87+ // TODO: No clue where to get the quicklist from, but this is the place to return it.
88+ return 0;
89+}
90+
91+int LauncherBackend::progress(const QString &appId) const
92+{
93+ // TODO: Return value for progress emblem.
94+ // TODO: emit progressChanged() when this value changes.
95+ return -1;
96+}
97+
98+int LauncherBackend::count(const QString &appId) const
99+{
100+ // TODO: Return value for count emblem.
101+ // TODO: emit countChanged() when this value changes.
102+ return 0;
103+}
plugins/Unity/Launcher/backend/launcherbackend.hnew file+115
@@ -0,0 +1,115 @@
1+/* Copyright (C) 2013 Canonical, Ltd.
2+ *
3+ * Authors:
4+ * Michael Zanetti <michael.zanetti@canonical.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; version 3.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17+ */
18+
19+#ifndef LAUNCHERBACKEND_H
20+#define LAUNCHERBACKEND_H
21+
22+#include <QObject>
23+#include <QStringList>
24+
25+class QuickListModelInterface;
26+
27+/**
28+ * @brief An interface that provides all the data needed by the launcher.
29+ */
30+
31+class LauncherBackend : public QObject
32+{
33+ Q_OBJECT
34+
35+
36+public:
37+ LauncherBackend(QObject *parent = 0);
38+ virtual ~LauncherBackend();
39+
40+ /**
41+ * @brief Returns a list of favorite applications.
42+ * @returns A list of application IDs.
43+ */
44+ QStringList favoriteApplications() const;
45+
46+ /**
47+ * @brief Set the list of favorite applications.
48+ *
49+ * Any previously stored information for apps not contained
50+ * in the list any more, e.g. the pinned state, will be
51+ * discarded.
52+ *
53+ * @param appIds The new list of stored applications.
54+ */
55+ void setFavoriteApplications(const QStringList &appIds);
56+
57+ /**
58+ * @brief Get the user friendly name of an application.
59+ * @param appId The ID of the application.
60+ * @returns The user friendly name of the application.
61+ */
62+ QString displayName(const QString &appId) const;
63+
64+ /**
65+ * @brief Get the icon of an application.
66+ * @param appId The ID of the application.
67+ * @returns The full path to the icon for the application.
68+ */
69+ QString icon(const QString &appId) const;
70+
71+ /**
72+ * @brief Is the app manually pinned?
73+ * @returns true if pinned, otherwise false.
74+ */
75+ bool isPinned(const QString &appId) const;
76+
77+ /**
78+ * @brief Change the pinned state of an application.
79+ * @param appId The application where the pinned flag should be set.
80+ * @param pinned true if pinned, otherwise false.
81+ */
82+ void setPinned(const QString &appId, bool pinned);
83+
84+ //TODO: Fill in getters for all the other things needed from the .desktop file.
85+
86+ /**
87+ * @brief Get the QuickList for an application.
88+ * @param appId The ID of the application.
89+ * @returns A QuickListModelInterface containing the QuickList.
90+ */
91+ QuickListModelInterface* quickList(const QString &appId) const;
92+
93+ /**
94+ * @brief Get the progress for the progress overlay of an application.
95+ * @param appId The ID of the application.
96+ * @returns The percentage of the overlay progress bar. -1 if no progress bar available.
97+ */
98+ int progress(const QString &appId) const;
99+
100+ /**
101+ * @brief Get the count of the count overlay of an application.
102+ * @param appId The ID of the application.
103+ * @returns The number to be displayed in the overlay. -1 if no count overlay is available.
104+ */
105+ int count(const QString &appId) const;
106+
107+Q_SIGNALS:
108+ void progressChanged(const QString &appId, int progress);
109+ void countChanged(const QString &appId, int count);
110+
111+private:
112+ QStringList m_favoriteApps;
113+};
114+
115+#endif // LAUNCHERBACKEND_H
plugins/Unity/Launcher/backend/quicklistmodel.hnew file+63
@@ -0,0 +1,63 @@
1+/* Copyright (C) 2013 Canonical, Ltd.
2+ *
3+ * Authors:
4+ * Michael Zanetti <michael.zanetti@canonical.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; version 3.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17+ */
18+
19+#ifndef QUICKLISTMODEL_H
20+#define QUICKLISTMODEL_H
21+
22+/**
23+ * @brief A model containing QuickList actions for an application in the launcher.
24+ *
25+ * @description The model has the following roles:
26+ * - RoleLabel: The text entry in the QuickList menu (QString).
27+ * - RoleIcon: The icon to be shown for this entry (QString).
28+ * - RoleCheckable: Wether the item is checkable or not (bool).
29+ * - RoleGroup: A group this item is in. Items in the same group are exclusive (int). -1 for no group.
30+ */
31+class QuickListModelInterface: public QAbstractListModel
32+{
33+ Q_OBJECT
34+
35+protected:
36+ /// @cond
37+ explicit QuickListModelInterface(QObject *parent = 0) : QAbstractListModel(parent) {}
38+ /// @endcond
39+public:
40+ enum Roles {
41+ RoleLabel,
42+ RoleIcon,
43+ RoleCheckable,
44+ RoleGroup
45+ }
46+
47+ /// @cond
48+ virtual ~QuickListModelInterface() {}
49+ /// @endcond
50+
51+ /// @cond
52+ QHash<int, QByteArray> roleNames() const {
53+ QHash<int, QByteArray> roles;
54+ roles.insert(RoleText, "label");
55+ roles.insert(RoleIcon, "icon");
56+ roles.insert(RoleCheckable, "checkable");
57+ roles.insert(RoleGroup, "group");
58+ }
59+ /// @endcond
60+
61+}
62+
63+#endif // QUICKLISTMODE_H