Kstars

profilesettings.cpp
1/*
2 SPDX-FileCopyrightText: 2022 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "profilesettings.h"
8#include <kstars_debug.h>
9
10#include "kstars.h"
11#include "kstarsdata.h"
12#include "ksuserdb.h"
13
14#include <QJsonDocument>
15
16namespace Ekos
17{
18
19ProfileSettings *ProfileSettings::m_Instance = nullptr;
20
21////////////////////////////////////////////////////////////////////////////
22///
23////////////////////////////////////////////////////////////////////////////
24ProfileSettings *ProfileSettings::Instance()
25{
26 if (m_Instance == nullptr)
27 m_Instance = new ProfileSettings(KStars::Instance());
28
29 return m_Instance;
30}
31
32////////////////////////////////////////////////////////////////////////////
33///
34////////////////////////////////////////////////////////////////////////////
35void ProfileSettings::release()
36{
37 delete (m_Instance);
38 m_Instance = nullptr;
39}
40
41////////////////////////////////////////////////////////////////////////////
42///
43////////////////////////////////////////////////////////////////////////////
44ProfileSettings::ProfileSettings(QObject *parent) : QObject(parent)
45{
46}
47
48////////////////////////////////////////////////////////////////////////////
49///
50////////////////////////////////////////////////////////////////////////////
51void ProfileSettings::setProfile(const QSharedPointer<ProfileInfo> &profile)
52{
53 m_Profile = profile;
54 // If not in database yet, create an empty entry.
55 if (KStars::Instance()->data()->userdb()->GetProfileSettings(m_Profile->id, m_Settings) == false)
56 {
57 initSettings();
58 KStars::Instance()->data()->userdb()->GetProfileSettings(m_Profile->id, m_Settings);
59 }
60}
61
62////////////////////////////////////////////////////////////////////////////
63///
64////////////////////////////////////////////////////////////////////////////
65void ProfileSettings::initSettings()
66{
67 auto object = QJsonObject::fromVariantMap(QVariantMap());
68 KStars::Instance()->data()->userdb()->AddProfileSettings(m_Profile->id,
70}
71
72////////////////////////////////////////////////////////////////////////////
73///
74////////////////////////////////////////////////////////////////////////////
75void ProfileSettings::setSettings(const QVariantMap &settings)
76{
77 m_Settings = settings;
78 auto object = QJsonObject::fromVariantMap(m_Settings);
79 KStars::Instance()->data()->userdb()->UpdateProfileSettings(m_Profile->id,
81}
82
83////////////////////////////////////////////////////////////////////////////
84///
85////////////////////////////////////////////////////////////////////////////
86QVariant ProfileSettings::getOneSetting(Settings id)
87{
88 return m_Settings[QString::number(id)];
89}
90
91////////////////////////////////////////////////////////////////////////////
92///
93////////////////////////////////////////////////////////////////////////////
94void ProfileSettings::setOneSetting(Settings id, const QVariant &value)
95{
96 m_Settings[QString::number(id)] = value;
97 auto object = QJsonObject::fromVariantMap(m_Settings);
98 KStars::Instance()->data()->userdb()->UpdateProfileSettings(m_Profile->id,
100}
101}
void AddProfileSettings(uint32_t profile, const QByteArray &settings)
Add new profile settings to the database.
bool GetProfileSettings(uint32_t profile, QVariantMap &settings)
Populate the reference passed with settings for one paritcular profile.
KSUserDB * userdb()
Definition kstarsdata.h:217
static KStars * Instance()
Definition kstars.h:121
KStarsData * data() const
Definition kstars.h:133
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
QJsonObject fromVariantMap(const QVariantMap &map)
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.