2019-04-01 10:43:36 +02:00
|
|
|
#include "opendialog.h"
|
|
|
|
|
#include "ui_opendialog.h"
|
|
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QStringBuilder>
|
|
|
|
|
#include <QSqlError>
|
2019-04-07 18:20:01 +02:00
|
|
|
#include <QSqlQuery>
|
2019-04-01 10:43:36 +02:00
|
|
|
|
|
|
|
|
OpenDialog::OpenDialog(QWidget *parent) :
|
|
|
|
|
QDialog(parent),
|
|
|
|
|
m_ui(std::make_unique<Ui::OpenDialog>())
|
|
|
|
|
{
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &OpenDialog::submit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenDialog::~OpenDialog() = default;
|
|
|
|
|
|
2019-04-07 18:20:01 +02:00
|
|
|
std::unique_ptr<Project> &OpenDialog::project()
|
2019-04-01 10:43:36 +02:00
|
|
|
{
|
2019-04-07 18:20:01 +02:00
|
|
|
return m_project;
|
2019-04-01 10:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenDialog::submit()
|
|
|
|
|
{
|
2019-04-07 18:20:01 +02:00
|
|
|
auto project = std::make_unique<Project>();
|
2019-04-20 11:39:37 +02:00
|
|
|
project->database = QSqlDatabase::addDatabase(m_ui->databaseWidget->driver());
|
|
|
|
|
|
|
|
|
|
if (project->database.driverName() == "QSQLITE")
|
|
|
|
|
project->database.setDatabaseName(m_ui->databaseWidget->sqliteFilepath());
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
project->database.setHostName(m_ui->databaseWidget->mysqlHostname());
|
|
|
|
|
project->database.setUserName(m_ui->databaseWidget->mysqlUsername());
|
|
|
|
|
project->database.setPassword(m_ui->databaseWidget->mysqlPassword());
|
|
|
|
|
project->database.setDatabaseName(m_ui->databaseWidget->mysqlDatabase());
|
|
|
|
|
}
|
2019-04-01 10:43:36 +02:00
|
|
|
|
2019-04-07 18:20:01 +02:00
|
|
|
if (!project->database.open())
|
2019-04-01 10:43:36 +02:00
|
|
|
{
|
2019-04-07 18:20:01 +02:00
|
|
|
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % project->database.lastError().text());
|
2019-04-01 10:43:36 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-07 18:20:01 +02:00
|
|
|
{
|
|
|
|
|
QSqlQuery query("SELECT `ID`, `Name` FROM `Hosts`;", project->database);
|
|
|
|
|
if (query.lastError().isValid())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % query.lastError().text());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while(query.next())
|
|
|
|
|
project->hosts.insert(query.value(0).toInt(), query.value(1).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QSqlQuery query("SELECT `ID`, `Name` FROM `Processes`;", project->database);
|
|
|
|
|
if (query.lastError().isValid())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % query.lastError().text());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while(query.next())
|
|
|
|
|
project->processes.insert(query.value(0).toInt(), query.value(1).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QSqlQuery query("SELECT `ID`, `Name` FROM `Filenames`;", project->database);
|
|
|
|
|
if (query.lastError().isValid())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % query.lastError().text());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while(query.next())
|
|
|
|
|
project->filenames.insert(query.value(0).toInt(), query.value(1).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QSqlQuery query("SELECT `ID`, `Name` FROM `Threads`;", project->database);
|
|
|
|
|
if (query.lastError().isValid())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % query.lastError().text());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while(query.next())
|
|
|
|
|
project->threads.insert(query.value(0).toInt(), query.value(1).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QSqlQuery query("SELECT `ID`, `Name` FROM `Types`;", project->database);
|
|
|
|
|
if (query.lastError().isValid())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % query.lastError().text());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while(query.next())
|
|
|
|
|
project->types.insert(query.value(0).toInt(), query.value(1).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_project = std::move(project);
|
|
|
|
|
|
2019-04-01 10:43:36 +02:00
|
|
|
accept();
|
|
|
|
|
}
|