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 IconCacheWatcher;
28class AppDrawerModel: public AppDrawerModelInterface
29{
30 Q_OBJECT
31 // TODO: Add this to AppDrawerModelInterface in lomiri-api.
32 // Or, better yet, remove AppDrawerModelInterface from lomiri-api.
33 Q_PROPERTY(bool refreshing READ refreshing NOTIFY refreshingChanged)
34public:
35 AppDrawerModel(QObject* parent = nullptr);
36
37 int rowCount(const QModelIndex &parent) const override;
38 QVariant data(const QModelIndex &index, int role) const override;
39
40 // TODO: add these to AppDrawerModelInterface too.
41 bool refreshing();
42 Q_INVOKABLE void refresh();
43
44Q_SIGNALS:
45 void refreshingChanged();
46
47private Q_SLOTS:
48 void appAdded(const QString &appId);
49 void appRemoved(const QString &appId);
50 void appInfoChanged(const QString &appId);
51
52 void onRefreshFinished();
53
54private:
55 // Using shared_ptr is unavoidable in order to share the refresh result
56 // from the worker thread safely without a memory leak, in case the model
57 // is destructed before the worker finishes.
58 typedef QList<std::shared_ptr<LauncherItem>> ItemList;
59
60 ItemList m_list;
61 UalWrapper *m_ual;
62 XdgWatcher *m_xdgWatcher;
63 IconCacheWatcher *m_iconCacheWatcher;
64 QFutureWatcher<ItemList> m_refreshFutureWatcher;
65 bool m_refreshing;
66};