-
Notifications
You must be signed in to change notification settings - Fork 1
/
userdb.cpp
94 lines (71 loc) · 3.23 KB
/
userdb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************************
Copyright(c) 2020 Ikarus Technologies. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*******************************************************************************/
#include "userdb.h"
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlTableModel>
#include <QStandardPaths>
#include <QDir>
void ProfileDB::GetAllProfiles(QList<std::shared_ptr<ProfileInfo>> &profiles)
{
QSqlDatabase userdb = QSqlDatabase::addDatabase("QSQLITE", "userdb");
const QString dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/kstars/userdb.sqlite";
userdb.setDatabaseName(dbPath);
userdb.open();
QSqlTableModel profile(nullptr, userdb);
profile.setTable("profile");
profile.select();
for (int i = 0; i < profile.rowCount(); ++i)
{
QSqlRecord record = profile.record(i);
int id = record.value("id").toInt();
QString name = record.value("name").toString();
std::shared_ptr<ProfileInfo> pi(new ProfileInfo(id, name));
// Add host and port
pi->host = record.value("host").toString();
pi->port = record.value("port").toInt();
// City info
pi->city = record.value("city").toString();
pi->province = record.value("province").toString();
pi->country = record.value("country").toString();
pi->INDIWebManagerPort = record.value("indiwebmanagerport").toInt();
pi->autoConnect = (record.value("autoconnect").toInt() == 1);
pi->indihub = record.value("indihub").toInt();
pi->guidertype = record.value("guidertype").toInt();
if (pi->guidertype != 0)
{
pi->guiderhost = record.value("guiderhost").toString();
pi->guiderport = record.value("guiderport").toInt();
}
pi->primaryscope = record.value("primaryscope").toInt();
pi->guidescope = record.value("guidescope").toInt();
pi->remotedrivers = record.value("remotedrivers").toString();
QSqlTableModel driver(nullptr, userdb);
driver.setTable("driver");
driver.setFilter("profile=" + QString::number(pi->id));
driver.select();
for (int i = 0; i < driver.rowCount(); ++i)
{
QSqlRecord record = driver.record(i);
QString label = record.value("label").toString();
QString role = record.value("role").toString();
pi->drivers[role] = label;
}
driver.clear();
profiles.append(pi);
}
profile.clear();
userdb.close();
}