Made the add entry dialog non-blocking

develop
tastytea 2018-10-14 03:53:30 +02:00
parent 768ba4d42b
commit 60df552d8e
No known key found for this signature in database
GPG Key ID: CFC39497F1B26E07
2 changed files with 44 additions and 32 deletions

View File

@ -17,7 +17,6 @@
#include <regex> #include <regex>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include <iostream>
#include "version.hpp" #include "version.hpp"
#include "whyblocked.hpp" #include "whyblocked.hpp"
#include "interface_qt.hpp" #include "interface_qt.hpp"
@ -81,30 +80,8 @@ void MainWindow::add_row(const QString &user, const int &blocked, const QString
void MainWindow::add() void MainWindow::add()
{ {
DialogAdd dialog; DialogAdd *dialog = new DialogAdd(this);
if (dialog.exec()) dialog->show();
{
auto data = dialog.get_data();
const string user = std::get<0>(data);
const int blocked = static_cast<int>(std::get<1>(data));
const string reason = std::get<2>(data);
if (user.empty())
{
return;
}
add_block(user, blocked, reason);
add_row(QString::fromStdString(user),
blocked,
QString::fromStdString(reason));
for (const string &receipt : std::get<3>(data))
{
add_url(user, receipt);
}
statusBar()->showMessage(tr("Added %1 to database.")
.arg(QString::fromStdString(user)));
}
} }
void MainWindow::remove() void MainWindow::remove()
@ -170,9 +147,12 @@ const string MainWindow::urls_to_hyperlinks(const string &text)
return std::regex_replace(text, re_url, "<a href=\"$1\">$1</a>"); return std::regex_replace(text, re_url, "<a href=\"$1\">$1</a>");
} }
DialogAdd::DialogAdd(QMainWindow *parent) : QDialog(parent) DialogAdd::DialogAdd(QMainWindow *parent)
: QDialog(parent)
, _parent(static_cast<MainWindow*>(parent))
{ {
setupUi(this); setupUi(this);
connect(button_receipt_add, &QPushButton::clicked, this, &DialogAdd::add_receipt); connect(button_receipt_add, &QPushButton::clicked, this, &DialogAdd::add_receipt);
connect(button_receipt_remove, &QPushButton::clicked, this, &DialogAdd::remove_receipt); connect(button_receipt_remove, &QPushButton::clicked, this, &DialogAdd::remove_receipt);
} }
@ -207,6 +187,32 @@ void DialogAdd::remove_receipt()
} }
} }
void DialogAdd::accept()
{
auto data = get_data();
const string user = std::get<0>(data);
const int blocked = static_cast<int>(std::get<1>(data));
const string reason = std::get<2>(data);
if (user.empty())
{
return;
}
::add_block(user, blocked, reason);
_parent->add_row(QString::fromStdString(user),
blocked,
QString::fromStdString(reason));
for (const string &receipt : std::get<3>(data))
{
::add_url(user, receipt);
}
_parent->statusBar()->showMessage(tr("Added %1 to database.")
.arg(QString::fromStdString(user)));
delete this;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);

View File

@ -38,6 +38,13 @@ class MainWindow : public QMainWindow, private Ui::MainWindow
public: public:
explicit MainWindow(QMainWindow *parent = nullptr); explicit MainWindow(QMainWindow *parent = nullptr);
void add_row(const QString &user, const int &blocked, const QString &reason);
private:
void populate_tableview();
const string urls_to_hyperlinks(const string &text);
QStandardItemModel *_model;
private slots: private slots:
void add(); void add();
@ -45,12 +52,6 @@ private slots:
void about(); void about();
void show_details(QModelIndex index); void show_details(QModelIndex index);
private:
void populate_tableview();
void add_row(const QString &user, const int &blocked, const QString &reason);
const string urls_to_hyperlinks(const string &text);
QStandardItemModel *_model;
}; };
class DialogAdd : public QDialog, private Ui::DialogAdd class DialogAdd : public QDialog, private Ui::DialogAdd
@ -59,11 +60,16 @@ class DialogAdd : public QDialog, private Ui::DialogAdd
public: public:
explicit DialogAdd(QMainWindow *parent = nullptr); explicit DialogAdd(QMainWindow *parent = nullptr);
private:
const dialogdata get_data(); const dialogdata get_data();
MainWindow *_parent;
private slots: private slots:
void add_receipt(); void add_receipt();
void remove_receipt(); void remove_receipt();
void accept();
}; };
#endif // INTERFACE_QT_HPP #endif // INTERFACE_QT_HPP