Skip to content

Commit

Permalink
pomf URL list downloading.
Browse files Browse the repository at this point in the history
  • Loading branch information
ckaiser committed Aug 7, 2016
1 parent 0bd7e28 commit 550dab3
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 39 deletions.
2 changes: 1 addition & 1 deletion tools/uploader/imguruploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void ImgurUploader::authorizationReply(QNetworkReply *reply, AuthorizationCallba
newSettings["refresh_token"] = imgurResponse.value("refresh_token").toString();
newSettings["account_username"] = imgurResponse.value("account_username").toString();
newSettings["expires_in"] = imgurResponse.value("expires_in").toInt();
saveSettings("imgur", newSettings);
ImgurUploader::saveSettings("imgur", newSettings);

authorized = true;
}
Expand Down
49 changes: 43 additions & 6 deletions widgets/pomfoptionswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ PomfOptionsWidget::PomfOptionsWidget(QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);

ui.progressIndicatorBar->setVisible(false);

connect(ui.verifyButton, &QPushButton::clicked, this, [&]() {
ui.verifyButton->setEnabled(false);
ui.pomfUrlComboBox->setEnabled(false);
ui.downloadListButton->setEnabled(false);
ui.progressIndicatorBar->setVisible(true);

QPointer<QWidget> guard(parentWidget());
PomfUploader::verify(ui.pomfUrlComboBox->currentText(), [&, guard](bool result) {
if (guard.isNull()) return;

ui.verifyButton->setEnabled(true);
ui.pomfUrlComboBox->setEnabled(true);
ui.downloadListButton->setEnabled(true);
ui.progressIndicatorBar->setVisible(false);

if (result) {
ui.verifyButton->setText(tr("Valid uploader!"));
Expand All @@ -34,7 +38,7 @@ PomfOptionsWidget::PomfOptionsWidget(QWidget *parent) : QWidget(parent)
} else {
ui.verifyButton->setStyleSheet("color: red;");
ui.verifyButton->setIcon(os::icon("no"));
ui.verifyButton->setText(tr("Invalid :("));
ui.verifyButton->setText(tr("Invalid uploader :("));
}
});
});
Expand All @@ -45,7 +49,6 @@ PomfOptionsWidget::PomfOptionsWidget(QWidget *parent) : QWidget(parent)
validUrl = true;
}

ui.visitButton->setEnabled(validUrl);
ui.verifyButton->setEnabled(validUrl);

if (ui.verifyButton->styleSheet().count() > 0) {
Expand All @@ -55,7 +58,41 @@ PomfOptionsWidget::PomfOptionsWidget(QWidget *parent) : QWidget(parent)
}
});

connect(ui.visitButton, &QPushButton::clicked, this, [&]() {
QDesktopServices::openUrl(ui.pomfUrlComboBox->currentText());
connect(ui.helpLabel, &QLabel::linkActivated, this, [&](const QString &url) {
QDesktopServices::openUrl(url);
});

connect(ui.downloadListButton, &QPushButton::clicked, this, [&]() {
ui.verifyButton->setEnabled(false);
ui.downloadListButton->setEnabled(false);
ui.progressIndicatorBar->setVisible(true);

auto pomflistReply = Uploader::instance()->nam()->get(QNetworkRequest(QUrl("https://lightscreen.com.ar/pomf.json")));

QPointer<QWidget> guard(parentWidget());
connect(pomflistReply, &QNetworkReply::finished, [&, guard, pomflistReply] {
if (guard.isNull()) return;

ui.verifyButton->setEnabled(true);
ui.downloadListButton->setEnabled(true);
ui.progressIndicatorBar->setVisible(false);

if (pomflistReply->error() != QNetworkReply::NoError) {
QMessageBox::warning(parentWidget(), tr("Connection error"), pomflistReply->errorString());
return;
}

auto pomfListData = QJsonDocument::fromJson(pomflistReply->readAll()).object();

if (pomfListData.contains("url")) {
auto urlList = pomfListData["url"].toArray();

for (auto url : qAsConst(urlList)) {
ui.pomfUrlComboBox->addItem(url.toString());
}

ui.pomfUrlComboBox->showPopup();
}
});
});
}
97 changes: 65 additions & 32 deletions widgets/pomfoptionswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,92 @@
<rect>
<x>0</x>
<y>0</y>
<width>305</width>
<height>75</height>
<width>297</width>
<height>84</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="pomfUrlLabel">
<property name="text">
<string>Pomf Clone URL:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="pomfUrlComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>URL to a pomf.se clone</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="visitButton">
<property name="text">
<string>Visit Site</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="verifyButton">
<property name="text">
<string>Verify</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="1">
<item row="4" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>198</width>
<height>97</height>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="verifyButton">
<property name="text">
<string>Verify</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="helpLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;a href=&quot;https://lightscreen.com.ar/help#pomf&quot;&gt;View Help&lt;/a&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QPushButton" name="downloadListButton">
<property name="text">
<string>Download List</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QProgressBar" name="progressIndicatorBar">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>2</height>
</size>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down

0 comments on commit 550dab3

Please sign in to comment.