diff options
-rw-r--r-- | src/gui.cpp | 16 | ||||
-rw-r--r-- | src/gui.h | 4 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/gui.cpp b/src/gui.cpp index e27086a..02925ad 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -11,6 +11,7 @@ #include <QJsonDocument> #include <QJsonObject> #include <QJsonArray> +#include <QCloseEvent> static QString STATE_COPYING("COPYING"); // Still busy copying original file, new chunks are only accepted in already copied range static QString STATE_WAITING_FOR_UPLOAD_DONE("WAITING_FOR_UPLOAD_DONE"); // Copying done, just waiting for new chunks until client signals that it's done @@ -27,13 +28,14 @@ Gui::Gui(const char *urlbase, const char *uuid, QWidget *parent) , _urlAbort(QString(urlbase).append("abort/").append(uuid)) , _urlFinish(QString(urlbase).append("finish/").append(uuid)) , _denyInteraction(false) + , _allowClose(false) , _tmrStatus(new QTimer(this)) , _status(nullptr) { _nam->setAutoDeleteReplies(true); _nam->setTransferTimeout(5000); setupUi(); - auto flags = windowFlags(); + auto flags = windowFlags() | Qt::WindowStaysOnTopHint; setWindowFlags(flags & ~(Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint)); _tmrStatus->start(2500); QObject::connect(_tmrStatus, &QTimer::timeout, [this]() { @@ -154,6 +156,7 @@ void Gui::updateButtons() void Gui::pushedCancel(bool) { if (_remoteState == STATE_ERROR) { + _allowClose = true; this->close(); return; } @@ -181,6 +184,7 @@ void Gui::pushedCancel(bool) _remoteState = STATE_ERROR; QMessageBox::information(this, tr("Ergebnis"), msg); QTimer::singleShot(2000, [this]() { + _allowClose = true; this->close(); }); } @@ -190,6 +194,7 @@ void Gui::pushedCancel(bool) void Gui::pushedOk(bool) { if (_remoteState == STATE_COMPLETELY_DONE || _remoteState == STATE_PROCESSING) { + _allowClose = true; this->close(); return; } @@ -215,3 +220,12 @@ void Gui::pushedOk(bool) } }); } + +void Gui::closeEvent(QCloseEvent *e) +{ + if (_allowClose) { + QDialog::closeEvent(e); + } else { + e->ignore(); + } +} @@ -19,6 +19,9 @@ public: explicit Gui(const char *urlbase, const char *uuid, QWidget *parent = nullptr); ~Gui(); +protected: + virtual void closeEvent(QCloseEvent *event) override; + private slots: void pushedCancel(bool pushed); void pushedOk(bool pushed); @@ -32,6 +35,7 @@ private: QString _remoteState; QString _urlStatus, _urlAbort, _urlFinish; bool _denyInteraction; + bool _allowClose; QPushButton *_btnAbort, *_btnOk; QTimer *_tmrStatus; QHash<QString, Progress*> _items; |