Changeset View
Changeset View
Standalone View
Standalone View
src/Config.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2020 Carson Black <uhhadd@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2, or | ||||
7 | * (at your option) any later version. | ||||
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 Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "Config.h" | ||||
21 | | ||||
22 | Config::Config(QObject *parent) : QObject(parent) | ||||
23 | { | ||||
24 | m_settings = new QSettings("KDE", "Kirigami Gallery", this); | ||||
25 | #ifndef Q_OS_ANDROID | ||||
26 | auto map = QList<std::tuple<QString,int,int*>>{ | ||||
27 | {QStringLiteral("x"), 0, &m_windowX}, | ||||
28 | {QStringLiteral("y"), 0, &m_windowY}, | ||||
29 | {QStringLiteral("width"), 600, &m_windowWidth}, | ||||
30 | {QStringLiteral("height"), 800, &m_windowHeight}, | ||||
31 | }; | ||||
32 | for (const auto &x: map) { | ||||
33 | *std::get<2>(x) = m_settings->value(std::get<0>(x), std::get<1>(x)).toInt(); | ||||
34 | } | ||||
35 | Q_EMIT coordinatesChanged(); | ||||
36 | #endif | ||||
37 | m_lastPage = m_settings->value(QStringLiteral("lastPage"), QStringLiteral("")).value<QString>(); | ||||
38 | Q_EMIT lastPageChanged(); | ||||
39 | } | ||||
40 | | ||||
41 | Config::~Config() | ||||
42 | { | ||||
43 | #ifndef Q_OS_ANDROID | ||||
44 | auto map = QList<std::tuple<QString,int*>>{ | ||||
45 | {QStringLiteral("x"), &m_windowX}, | ||||
46 | {QStringLiteral("y"), &m_windowY}, | ||||
47 | {QStringLiteral("width"), &m_windowWidth}, | ||||
48 | {QStringLiteral("height"), &m_windowHeight}, | ||||
49 | }; | ||||
50 | for (const auto &x: map) { | ||||
51 | m_settings->setValue(std::get<0>(x), *std::get<1>(x)); | ||||
52 | } | ||||
53 | #endif | ||||
54 | m_settings->setValue(QStringLiteral("lastPage"), m_lastPage); | ||||
55 | } | ||||
56 | | ||||
57 | #ifndef Q_OS_ANDROID | ||||
58 | | ||||
59 | void Config::setWindowX(int x) | ||||
60 | { | ||||
61 | if (m_windowX != x) { | ||||
62 | m_windowX = x; | ||||
63 | Q_EMIT coordinatesChanged(); | ||||
64 | } | ||||
65 | } | ||||
66 | | ||||
67 | void Config::setWindowY(int y) | ||||
68 | { | ||||
69 | if (m_windowY != y) { | ||||
70 | m_windowY = y; | ||||
71 | Q_EMIT coordinatesChanged(); | ||||
72 | } | ||||
73 | } | ||||
74 | | ||||
75 | void Config::setWindowWidth(int width) | ||||
76 | { | ||||
77 | if (m_windowWidth != width) { | ||||
78 | m_windowWidth = width; | ||||
79 | Q_EMIT coordinatesChanged(); | ||||
80 | } | ||||
81 | } | ||||
82 | | ||||
83 | void Config::setWindowHeight(int height) | ||||
84 | { | ||||
85 | if (m_windowHeight != height) { | ||||
86 | m_windowHeight = height; | ||||
87 | Q_EMIT coordinatesChanged(); | ||||
88 | } | ||||
89 | } | ||||
90 | | ||||
91 | #endif | ||||
92 | | ||||
93 | void Config::setLastPage(const QString& page) | ||||
94 | { | ||||
95 | if (m_lastPage != page) { | ||||
96 | m_lastPage = page; | ||||
97 | Q_EMIT lastPageChanged(); | ||||
98 | } | ||||
99 | } | ||||
100 | No newline at end of file |