Lomiri
Loading...
Searching...
No Matches
windowstatestorage.h
1/*
2 * Copyright 2015-2016 Canonical Ltd.
3 * Copyright 2021 UBports Foundation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <QObject>
19#include <QSqlDatabase>
20#include <QSqlQuery>
21#include <QMutex>
22#include <QFuture>
23#include <QThread>
24
25// lomiri-api
26#include <lomiri/shell/application/Mir.h>
27
28class AsyncQuery;
29
30class WindowStateStorage: public QObject
31{
32 Q_OBJECT
33public:
34 enum WindowState {
35 WindowStateNormal = 1 << 0,
36 WindowStateMaximized = 1 << 1,
37 WindowStateMinimized = 1 << 2,
38 WindowStateFullscreen = 1 << 3,
39 WindowStateMaximizedLeft = 1 << 4,
40 WindowStateMaximizedRight = 1 << 5,
41 WindowStateMaximizedHorizontally = 1 << 6,
42 WindowStateMaximizedVertically = 1 << 7,
43 WindowStateMaximizedTopLeft = 1 << 8,
44 WindowStateMaximizedTopRight = 1 << 9,
45 WindowStateMaximizedBottomLeft = 1 << 10,
46 WindowStateMaximizedBottomRight = 1 << 11,
47 WindowStateRestored = 1 << 12
48 };
49 Q_ENUM(WindowState)
50 Q_DECLARE_FLAGS(WindowStates, WindowState)
51 Q_FLAG(WindowStates)
52
53 WindowStateStorage(const QString &dbName = QString(), QObject *parent = nullptr);
54 virtual ~WindowStateStorage();
55
56 Q_INVOKABLE WindowState getState(const QString &windowId, WindowState defaultValue) const;
57
58 Q_INVOKABLE QRect getGeometry(const QString &windowId, const QRect &defaultValue) const;
59
60 Q_INVOKABLE int getStage(const QString &appId, int defaultValue) const;
61
62 Q_INVOKABLE Mir::State toMirState(WindowState state) const;
63
64 const QString getDbName();
65
66Q_SIGNALS:
67 void saveStage(const QString &appId, int stage);
68 void saveGeometry(const QString &windowId, const QRect &rect);
69 void saveState(const QString &windowId, WindowStateStorage::WindowState state);
70
71private:
72 QThread m_thread;
73 AsyncQuery *m_asyncQuery;
74};