Skip to content

Commit

Permalink
Introducing a second uploader service: pomf.se clones!
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris K authored and Chris K committed Jul 22, 2016
1 parent 1d6579e commit 0bd7e28
Show file tree
Hide file tree
Showing 17 changed files with 455 additions and 23 deletions.
32 changes: 26 additions & 6 deletions dialogs/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@ void OptionsDialog::loadSettings()
settings()->beginGroup("imgur");
ui.imgurOptions->setUser(settings()->value("account_username", "").toString());
settings()->endGroup();

settings()->beginGroup("pomf");
QString pomf_url = settings()->value("pomf_url", "").toString();

if (!pomf_url.isEmpty()) {
if (ui.pomfOptions->ui.pomfUrlComboBox->findText(pomf_url, Qt::MatchFixedString) == -1) {
ui.pomfOptions->ui.pomfUrlComboBox->addItem(pomf_url);
}

ui.pomfOptions->ui.pomfUrlComboBox->setCurrentText(settings()->value("pomf_url", "").toString());
}
settings()->endGroup();

settings()->endGroup();

QTimer::singleShot(0, this, &OptionsDialog::updatePreview);
Expand Down Expand Up @@ -381,8 +394,12 @@ void OptionsDialog::saveSettings()
settings()->setValue("service", ui.uploadServiceComboBox->currentIndex());

settings()->beginGroup("imgur");
settings()->setValue("anonymous", settings()->value("account_username").toString().isEmpty());
settings()->setValue("album" , ui.imgurOptions->ui.albumComboBox->property("currentData").toString());
settings()->setValue("anonymous", settings()->value("account_username").toString().isEmpty());
settings()->setValue("album" , ui.imgurOptions->ui.albumComboBox->property("currentData").toString());
settings()->endGroup();

settings()->beginGroup("pomf");
settings()->setValue("pomf_url", ui.pomfOptions->ui.pomfUrlComboBox->currentText());
settings()->endGroup();

settings()->endGroup();
Expand Down Expand Up @@ -576,6 +593,8 @@ void OptionsDialog::init()
// Version
ui.versionLabel->setText(tr("Version %1").arg(qApp->applicationVersion()));

ui.uploadSslWarningLabel->setVisible(!QSslSocket::supportsSsl());

setEnabled(false); // We disable the widgets to prevent any user interaction until the settings have loaded.

//
Expand Down Expand Up @@ -650,12 +669,13 @@ void OptionsDialog::init()
}
});

connect(ui.mainLabel , &QLabel::linkActivated, this, &OptionsDialog::openUrl);
connect(ui.licenseAboutLabel, &QLabel::linkActivated, this, &OptionsDialog::openUrl);
connect(ui.linksLabel, &QLabel::linkActivated, this, &OptionsDialog::openUrl);
connect(ui.mainLabel , &QLabel::linkActivated, this, &OptionsDialog::openUrl);
connect(ui.licenseAboutLabel, &QLabel::linkActivated, this, &OptionsDialog::openUrl);
connect(ui.linksLabel, &QLabel::linkActivated, this, &OptionsDialog::openUrl);
connect(ui.uploadSslWarningLabel,&QLabel::linkActivated, this, &OptionsDialog::openUrl);

connect(ui.tabWidget, &QTabWidget::currentChanged, [&](int index) {
if (index == 2 && !ui.imgurOptions->mCurrentUser.isEmpty() && ui.imgurOptions->ui.albumComboBox->count() == 1) {
if (index == 2 && ui.uploadServiceStackWidget->currentIndex() == 0 && !ui.imgurOptions->mCurrentUser.isEmpty() && ui.imgurOptions->ui.albumComboBox->count() == 1) {
QTimer::singleShot(20, ui.imgurOptions, &ImgurOptionsWidget::requestAlbumList);
}
});
Expand Down
97 changes: 94 additions & 3 deletions dialogs/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>399</width>
<width>401</width>
<height>318</height>
</rect>
</property>
Expand Down Expand Up @@ -555,6 +555,22 @@ Quality is related to file size and of course to readability and overall quality
<string>Upload</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<widget class="QLabel" name="uploadSslWarningLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">QLabel { padding: 4px; border: 1px solid red; background-color: rgba(248, 182, 182, 60); }</string>
</property>
<property name="text">
<string>WARNING: You have no SSL support, &lt;a href=&quot;http://lightscreen.com.ar/help#SSL&quot;&gt;click here&lt;/a&gt; to learn more.</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="uploadCheckBox">
<property name="text">
Expand Down Expand Up @@ -585,6 +601,11 @@ Quality is related to file size and of course to readability and overall quality
<string>Imgur</string>
</property>
</item>
<item>
<property name="text">
<string>Pomf-clone</string>
</property>
</item>
</widget>
</item>
<item>
Expand Down Expand Up @@ -624,7 +645,55 @@ Quality is related to file size and of course to readability and overall quality
<number>4</number>
</property>
<item>
<widget class="ImgurOptionsWidget" name="imgurOptions" native="true"/>
<widget class="QStackedWidget" name="uploadServiceStackWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_13">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="ImgurOptionsWidget" name="imgurOptions" native="true"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_14">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="PomfOptionsWidget" name="pomfOptions" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
Expand Down Expand Up @@ -676,7 +745,7 @@ Quality is related to file size and of course to readability and overall quality
<rect>
<x>0</x>
<y>0</y>
<width>358</width>
<width>360</width>
<height>706</height>
</rect>
</property>
Expand Down Expand Up @@ -1360,6 +1429,12 @@ Created by &lt;a href=&quot;https://ckaiser.com.ar&quot;&gt;Christian Kaiser&lt;
<header location="global">widgets/imguroptionswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>PomfOptionsWidget</class>
<extends>QWidget</extends>
<header location="global">widgets/pomfoptionswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>fileGroupBox</tabstop>
Expand Down Expand Up @@ -1459,5 +1534,21 @@ Created by &lt;a href=&quot;https://ckaiser.com.ar&quot;&gt;Christian Kaiser&lt;
</hint>
</hints>
</connection>
<connection>
<sender>uploadServiceComboBox</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>uploadServiceStackWidget</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>92</x>
<y>96</y>
</hint>
<hint type="destinationlabel">
<x>198</x>
<y>196</y>
</hint>
</hints>
</connection>
</connections>
</ui>
11 changes: 8 additions & 3 deletions lightscreen.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ HEADERS += dialogs/areadialog.h \
widgets/hotkeywidget.h \
tools/uploader/imageuploader.h \
tools/uploader/imguruploader.h \
tools/uploader/pomfuploader.h \
tools/uploader/uploader.h \
widgets/imguroptionswidget.h
widgets/imguroptionswidget.h \
widgets/pomfoptionswidget.h

SOURCES += dialogs/areadialog.cpp \
dialogs/historydialog.cpp \
Expand All @@ -35,14 +37,17 @@ SOURCES += dialogs/areadialog.cpp \
widgets/hotkeywidget.cpp \
tools/uploader/imageuploader.cpp \
tools/uploader/imguruploader.cpp \
tools/uploader/pomfuploader.cpp \
tools/uploader/uploader.cpp \
widgets/imguroptionswidget.cpp
widgets/imguroptionswidget.cpp \
widgets/pomfoptionswidget.cpp

FORMS += dialogs/historydialog.ui \
dialogs/namingdialog.ui \
dialogs/optionsdialog.ui \
lightscreenwindow.ui \
widgets/imguroptions.ui
widgets/pomfoptionswidget.ui \
widgets/imguroptionswidget.ui

RESOURCES += lightscreen.qrc
CODECFORSRC = UTF-8
Expand Down
4 changes: 2 additions & 2 deletions lightscreenwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ void LightscreenWindow::screenshotAction(int mode)
options.upload = settings()->value("options/uploadAuto", false).toBool();
options.optimize = settings()->value("options/optipng", false).toBool();

options.uploadService = settings()->value("options/upload/service", "imgur").toString();
options.uploadService = Uploader::serviceName(settings()->value("upload/service", 0).toInt());

Screenshot::NamingOptions namingOptions;
namingOptions.naming = (Screenshot::Naming) settings()->value("file/naming").toInt();
Expand Down Expand Up @@ -780,7 +780,7 @@ void LightscreenWindow::updaterDone(bool result)

void LightscreenWindow::upload(const QString &fileName)
{
Uploader::instance()->upload(fileName, settings()->value("options/upload/service", "imgur").toString());
Uploader::instance()->upload(fileName, Uploader::serviceName(settings()->value("upload/service", 0).toInt()));
}

void LightscreenWindow::uploadCancel()
Expand Down
5 changes: 4 additions & 1 deletion tools/uploader/imageuploader.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "imageuploader.h"
#include "imguruploader.h"
#include "pomfuploader.h"

#include <QSettings>
#include "../screenshotmanager.h"

ImageUploader *ImageUploader::factory(const QString &name)
{
if (name == "imgur") {
return new ImgurUploader(0);
return new ImgurUploader;
} else if (name == "pomf") {
return new PomfUploader;
}

return 0;
Expand Down
3 changes: 3 additions & 0 deletions tools/uploader/imguruploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void ImgurUploader::upload(const QString &fileName)
QNetworkReply *reply = Uploader::instance()->nam()->post(request, multiPart);
reply->setProperty("fileName", fileName);
this->setProperty("fileName", fileName);
multiPart->setParent(reply);

connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgress(qint64, qint64)));
connect(this , SIGNAL(cancelRequest()), reply, SLOT(abort()));
Expand Down Expand Up @@ -177,6 +178,8 @@ void ImgurUploader::uploadProgress(qint64 bytesReceived, qint64 bytesTotal)

void ImgurUploader::authorizationReply(QNetworkReply *reply, AuthorizationCallback callback)
{
reply->deleteLater();

connect(reply, &QNetworkReply::finished, [reply, callback] {
bool authorized = false;

Expand Down
2 changes: 1 addition & 1 deletion tools/uploader/imguruploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ImgurUploader : public ImageUploader
public:
typedef std::function<void(bool)> AuthorizationCallback;

ImgurUploader(QObject *parent);
ImgurUploader(QObject *parent = 0);
static const QString clientId();
static const QString clientSecret();
static void authorize(const QString &pin, AuthorizationCallback callback);
Expand Down
Loading

0 comments on commit 0bd7e28

Please sign in to comment.