7#include "customdrivers.h"
12#include "driverinfo.h"
14#include "kstarsdata.h"
15#include "ksnotification.h"
19 m_DriversList(driversList)
25 model->setTable(
"customdrivers");
27 driversView->setModel(model);
28 driversView->hideColumn(0);
33 cautionLabel->setPixmap((
QIcon::fromTheme(
"emblem-warning").pixmap(32, 32)));
35 familyCombo->addItems(DeviceFamilyLabels.values());
37 for (
const auto &oneDriver : driversList)
49 driverCombo->addItem(label);
55 this, &CustomDrivers::syncDriver);
59 addDriverB->setEnabled(labelIN->text().isEmpty() ==
false);
64 removeDriverB->setEnabled(
true);
71CustomDrivers::~CustomDrivers()
76void CustomDrivers::refreshFromDB()
78 KStarsData::Instance()->
userdb()->GetAllCustomDrivers(m_CustomDrivers);
82void CustomDrivers::syncDriver()
84 const QString currentDriverLabel = driverCombo->currentText();
86 for (
auto oneDriver : m_DriversList)
88 if (currentDriverLabel == oneDriver->getLabel())
90 familyCombo->setCurrentIndex(oneDriver->getType());
91 execIN->setText(oneDriver->getExecutable());
92 nameIN->setText(oneDriver->getName());
93 manufacturerIN->setText(oneDriver->manufacturer());
99void CustomDrivers::addDriver()
102 for (
auto &oneDriver : m_DriversList)
104 if (labelIN->text() == oneDriver->getLabel())
106 KSNotification::error(
i18n(
"Label already exists. Label must be unique."));
111 QVariantMap newDriver;
113 newDriver[
"Label"] = labelIN->text();
114 newDriver[
"Name"] = nameIN->text();
115 newDriver[
"Family"] = familyCombo->currentText();
116 newDriver[
"Manufacturer"] = manufacturerIN->text();
117 newDriver[
"Exec"] = execIN->text();
119 newDriver[
"Version"] =
"1.0";
121 if (KStarsData::Instance()->userdb()->AddCustomDriver(newDriver) ==
false)
122 KSNotification::error(
i18n(
"Failed to add new driver. Is the label unique?"));
128void CustomDrivers::removeDriver()
130 int row = driversView->currentIndex().row();
135 QVariantMap oneDriver = m_CustomDrivers[row];
137 KStarsData::Instance()->
userdb()->DeleteCustomDriver(oneDriver[
"id"].
toString());
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
QString label(StandardShortcut id)
void pressed(const QModelIndex &index)
void activated(int index)
QIcon fromTheme(const QString &name)
void textChanged(const QString &text)
QSqlDatabase database(const QString &connectionName, bool open)
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)