| 13 | #include <tools/os.h> |
| 14 | |
| 15 | PomfOptionsWidget::PomfOptionsWidget(QWidget *parent) : QWidget(parent) |
| 16 | { |
| 17 | ui.setupUi(this); |
| 18 | |
| 19 | ui.progressIndicatorBar->setVisible(false); |
| 20 | ui.cancelButton->setVisible(false); |
| 21 | |
| 22 | connect(ui.verifyButton, &QPushButton::clicked, this, [&]() { |
| 23 | ui.verifyButton->setEnabled(false); |
| 24 | ui.downloadListButton->setEnabled(false); |
| 25 | ui.progressIndicatorBar->setVisible(true); |
| 26 | ui.cancelButton->setVisible(true); |
| 27 | disconnect(ui.cancelButton); |
| 28 | ui.cancelButton->disconnect(); |
| 29 | |
| 30 | QPointer<QWidget> guard(parentWidget()); |
| 31 | QPointer<QNetworkReply> reply = PomfUploader::verify(ui.pomfUrlComboBox->currentText(), [&, guard](bool result) { |
| 32 | if (guard.isNull()) return; |
| 33 | |
| 34 | ui.verifyButton->setEnabled(true); |
| 35 | ui.downloadListButton->setEnabled(true); |
| 36 | ui.progressIndicatorBar->setVisible(false); |
| 37 | |
| 38 | if (result) { |
| 39 | ui.verifyButton->setText(tr("Valid uploader!")); |
| 40 | ui.verifyButton->setStyleSheet("color: green;"); |
| 41 | ui.verifyButton->setIcon(os::icon("yes")); |
| 42 | } else if (ui.cancelButton->isVisible() == true) { // Not cancelled |
| 43 | ui.verifyButton->setStyleSheet("color: red;"); |
| 44 | ui.verifyButton->setIcon(os::icon("no")); |
| 45 | ui.verifyButton->setText(tr("Invalid uploader :(")); |
| 46 | } |
| 47 | |
| 48 | ui.cancelButton->setVisible(false); |
| 49 | }); |
| 50 | |
| 51 | if (reply) { |
| 52 | connect(ui.cancelButton, &QPushButton::clicked, [&, reply] { |
| 53 | if (reply) { |
| 54 | ui.cancelButton->setVisible(false); |
| 55 | reply->abort(); |
| 56 | } |
| 57 | }); |
| 58 | } |
| 59 | }); |
| 60 | |
| 61 | connect(ui.pomfUrlComboBox, &QComboBox::currentTextChanged, [&](const QString &text) { |
| 62 | bool validUrl = false; |
| 63 | |
| 64 | if (!text.isEmpty() && (text.startsWith("http://") || text.startsWith("https://"))) { // TODO: Something a bit more complex |
| 65 | validUrl = true; |
| 66 | } |
| 67 | |
| 68 | ui.verifyButton->setEnabled(validUrl); |
| 69 | |
| 70 | if (ui.verifyButton->styleSheet().count() > 0) { |
| 71 | ui.verifyButton->setStyleSheet(""); |
| 72 | ui.verifyButton->setIcon(QIcon()); |