Lomiri
Loading...
Searching...
No Matches
appdrawermodel.h
1/*
2 * Copyright (C) 2016 Canonical Ltd.
3 * Copyright (C) 2020 UBports Foundation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <memory>
19#include <QFutureWatcher>
20#include <lomiri/shell/launcher/AppDrawerModelInterface.h>
21
22#include "launcheritem.h"
23
24class UalWrapper;
25class XdgWatcher;
26
27class AppDrawerModel: public AppDrawerModelInterface
28{
29 Q_OBJECT
30 // TODO: Add this to AppDrawerModelInterface in lomiri-api.
31 // Or, better yet, remove AppDrawerModelInterface from lomiri-api.
32 Q_PROPERTY(bool refreshing READ refreshing NOTIFY refreshingChanged)
33public:
34 AppDrawerModel(QObject* parent = nullptr);
35
36 int rowCount(const QModelIndex &parent) const override;
37 QVariant data(const QModelIndex &index, int role) const override;
38
39 // TODO: add these to AppDrawerModelInterface too.
40 bool refreshing();
41 Q_INVOKABLE void refresh();
42
43Q_SIGNALS:
44 void refreshingChanged();
45
46private Q_SLOTS:
47 void appAdded(const QString &appId);
48 void appRemoved(const QString &appId);
49 void appInfoChanged(const QString &appId);
50
51 void onRefreshFinished();
52
53private:
54 // Using shared_ptr is unavoidable in order to share the refresh result
55 // from the worker thread safely without a memory leak, in case the model
56 // is destructed before the worker finishes.
57 typedef QList<std::shared_ptr<LauncherItem>> ItemList;
58
59 ItemList m_list;
60 UalWrapper *m_ual;
61 XdgWatcher *m_xdgWatcher;
62 QFutureWatcher<ItemList> m_refreshFutureWatcher;
63 bool m_refreshing;
64};