parent
75af31920b
commit
71999b516b
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) 2013 <copyright holder> <email>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LXIMAGE_GRAPHICSSCENE_H
|
||||||
|
#define LXIMAGE_GRAPHICSSCENE_H
|
||||||
|
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsSceneDragDropEvent>
|
||||||
|
|
||||||
|
namespace LxImage {
|
||||||
|
|
||||||
|
class GraphicsScene : public QGraphicsScene
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
GraphicsScene(QObject *parent = 0);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
|
||||||
|
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
|
||||||
|
virtual void dropEvent(QGraphicsSceneDragDropEvent* event);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void fileDropped(const QString file);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LXIMAGE_GRAPHICSSCENE_H
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* <one line to give the library's name and an idea of what it does.>
|
|
||||||
* Copyright (C) 2014 <copyright holder> <email>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "job.h"
|
|
||||||
|
|
||||||
namespace LxImage {
|
|
||||||
|
|
||||||
Job::Job():
|
|
||||||
cancellable_(g_cancellable_new()),
|
|
||||||
error_(NULL) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Job::~Job() {
|
|
||||||
g_object_unref(cancellable_);
|
|
||||||
if(error_)
|
|
||||||
g_error_free(error_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is called from the worker thread, not main thread
|
|
||||||
gboolean Job::_jobThread(GIOSchedulerJob* job, GCancellable* cancellable, Job* pThis) {
|
|
||||||
pThis->run();
|
|
||||||
// do final step in the main thread
|
|
||||||
if(!g_cancellable_is_cancelled(pThis->cancellable_))
|
|
||||||
g_io_scheduler_job_send_to_mainloop(job, GSourceFunc(_finish), pThis, NULL);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Job::start() {
|
|
||||||
g_io_scheduler_push_job(GIOSchedulerJobFunc(_jobThread),
|
|
||||||
this, GDestroyNotify(_freeMe),
|
|
||||||
G_PRIORITY_DEFAULT, cancellable_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// this function is called from main thread only
|
|
||||||
gboolean Job::_finish(Job* pThis) {
|
|
||||||
// only do processing if the job is not cancelled
|
|
||||||
if(!g_cancellable_is_cancelled(pThis->cancellable_)) {
|
|
||||||
pThis->finish();
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Job::_freeMe(Job* pThis) {
|
|
||||||
delete pThis;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
<one line to give the library's name and an idea of what it does.>
|
||||||
|
Copyright (C) 2013 <copyright holder> <email>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "screenshotselectarea.h"
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
using namespace LxImage;
|
||||||
|
|
||||||
|
ScreenshotSelectArea::ScreenshotSelectArea(const QImage & image, QWidget* parent) : QDialog(parent)
|
||||||
|
{
|
||||||
|
scene_ = new QGraphicsScene(this);
|
||||||
|
scene_->addPixmap(QPixmap::fromImage(image));
|
||||||
|
|
||||||
|
view_ = new ScreenshotSelectAreaGraphicsView(scene_, this);
|
||||||
|
view_->setRenderHints( QPainter::Antialiasing );
|
||||||
|
view_->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
|
||||||
|
view_->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
|
||||||
|
view_->show();
|
||||||
|
view_->move(0,0);
|
||||||
|
view_->resize(image.width(), image.height());
|
||||||
|
setWindowState(windowState() | Qt::WindowFullScreen);
|
||||||
|
connect(view_, &ScreenshotSelectAreaGraphicsView::selectedArea, this, &ScreenshotSelectArea::areaSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
QRect ScreenshotSelectArea::selectedArea()
|
||||||
|
{
|
||||||
|
return selectedRect_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenshotSelectArea::areaSelected(QRect rect)
|
||||||
|
{
|
||||||
|
this->selectedRect_ = rect;
|
||||||
|
accept();
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
<one line to give the library's name and an idea of what it does.>
|
||||||
|
Copyright (C) 2013 <copyright holder> <email>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LXIMAGE_SCREENSHOTDIALOG_SELECT_AREA_H
|
||||||
|
#define LXIMAGE_SCREENSHOTDIALOG_SELECT_AREA_H
|
||||||
|
|
||||||
|
#include "screenshotselectareagraphicsview.h"
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QGraphicsRectItem>
|
||||||
|
|
||||||
|
|
||||||
|
namespace LxImage {
|
||||||
|
|
||||||
|
class ScreenshotSelectArea : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ScreenshotSelectArea(const QImage & image, QWidget* parent = 0);
|
||||||
|
QRect selectedArea();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void areaSelected(QRect rect);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QGraphicsScene *scene_;
|
||||||
|
ScreenshotSelectAreaGraphicsView *view_;
|
||||||
|
QRect selectedRect_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LXIMAGE_SCREENSHOTDIALOG_SELECT_AREA_H
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
<one line to give the library's name and an idea of what it does.>
|
||||||
|
Copyright (C) 2013 <copyright holder> <email>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "screenshotselectareagraphicsview.h"
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
using namespace LxImage;
|
||||||
|
|
||||||
|
ScreenshotSelectAreaGraphicsView::ScreenshotSelectAreaGraphicsView(QGraphicsScene* scene, QWidget* parent) : QGraphicsView(scene, parent)
|
||||||
|
{
|
||||||
|
p0_ = QPointF(-1.0, -1.0);
|
||||||
|
selectedAreaRect_ = nullptr;
|
||||||
|
setCursor(Qt::CrossCursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenshotSelectAreaGraphicsView::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(p0_.x() < 0) {
|
||||||
|
p0_ = QPointF(event->pos());
|
||||||
|
} else {
|
||||||
|
if(selectedAreaRect_ == nullptr) {
|
||||||
|
QColor highlight = palette().color(QPalette::Active,QPalette::Highlight);
|
||||||
|
QPen pen(highlight, 3, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin);
|
||||||
|
QColor color(highlight);
|
||||||
|
color.setAlpha(128);
|
||||||
|
QBrush brush(color);
|
||||||
|
selectedAreaRect_ = scene()->addRect(QRectF(), pen, brush);
|
||||||
|
}
|
||||||
|
selectedAreaRect_->setRect(QRectF(p0_,QPointF(event->pos())).normalized());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenshotSelectAreaGraphicsView::mouseMoveEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
mousePressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenshotSelectAreaGraphicsView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
Q_EMIT selectedArea(QRectF(p0_,QPointF(event->pos())).normalized().toRect());
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
<one line to give the library's name and an idea of what it does.>
|
||||||
|
Copyright (C) 2013 <copyright holder> <email>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LXIMAGE_SCREENSHOTDIALOG_SELECT_AREA_GRAPICS_VIEW_H
|
||||||
|
#define LXIMAGE_SCREENSHOTDIALOG_SELECT_AREA_GRAPICS_VIEW_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QGraphicsRectItem>
|
||||||
|
|
||||||
|
|
||||||
|
namespace LxImage {
|
||||||
|
|
||||||
|
class ScreenshotSelectAreaGraphicsView : public QGraphicsView {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ScreenshotSelectAreaGraphicsView(QGraphicsScene* scene, QWidget* parent = 0);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void selectedArea(QRect rect);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPointF p0_;
|
||||||
|
QGraphicsRectItem *selectedAreaRect_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LXIMAGE_SCREENSHOTDIALOG_SELECT_AREA_H
|
@ -0,0 +1,4 @@
|
|||||||
|
#Translations
|
||||||
|
Name[lt]=Ekrano kopija
|
||||||
|
GenericName[lt]=Ekrano kopija
|
||||||
|
Comment[lt]=Padaryti ekrano kopiją
|
@ -0,0 +1,4 @@
|
|||||||
|
#Translations
|
||||||
|
Name[lt]=LXImage
|
||||||
|
GenericName[lt]=Paveikslų žiūryklė
|
||||||
|
Comment[lt]=LXQt paveikslų žiūryklė
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QHttpMultiPart>
|
||||||
|
#include <QHttpPart>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QUrlQuery>
|
||||||
|
|
||||||
|
#include "imageshackprovider.h"
|
||||||
|
#include "imageshackupload.h"
|
||||||
|
|
||||||
|
using namespace LxImage;
|
||||||
|
|
||||||
|
const QString gUploadURL = "https://api.imageshack.com/v2/images";
|
||||||
|
const QByteArray gAPIKey = "4DINORVXbcbda9ac64b424a0e6b37caed4cf3b8b";
|
||||||
|
|
||||||
|
Upload *ImageShackProvider::upload(QIODevice *device)
|
||||||
|
{
|
||||||
|
// Construct the URL that will be used for the upload
|
||||||
|
QUrlQuery query;
|
||||||
|
query.addQueryItem("api_key", gAPIKey);
|
||||||
|
QUrl url(gUploadURL);
|
||||||
|
url.setQuery(query);
|
||||||
|
|
||||||
|
// The first (and only) part is the file upload
|
||||||
|
QHttpPart filePart;
|
||||||
|
filePart.setBodyDevice(device);
|
||||||
|
filePart.setHeader(
|
||||||
|
QNetworkRequest::ContentDispositionHeader,
|
||||||
|
"form-data; name=\"file\"; filename=\"upload.jpg\""
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create the multipart and append the file part
|
||||||
|
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType, device);
|
||||||
|
multiPart->append(filePart);
|
||||||
|
|
||||||
|
// Start the request and wrap it in an ImageShackUpload
|
||||||
|
return new ImageShackUpload(sManager.post(QNetworkRequest(url), multiPart));
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LXIMAGE_IMAGESHACKPROVIDER_H
|
||||||
|
#define LXIMAGE_IMAGESHACKPROVIDER_H
|
||||||
|
|
||||||
|
#include "provider.h"
|
||||||
|
|
||||||
|
namespace LxImage {
|
||||||
|
|
||||||
|
class Upload;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create uploads to ImageShack's API
|
||||||
|
*/
|
||||||
|
class ImageShackProvider : public Provider
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual Upload *upload(QIODevice *device);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LXIMAGE_IMAGESHACKPROVIDER_H
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonValue>
|
||||||
|
|
||||||
|
#include "imageshackupload.h"
|
||||||
|
|
||||||
|
using namespace LxImage;
|
||||||
|
|
||||||
|
ImageShackUpload::ImageShackUpload(QNetworkReply *reply)
|
||||||
|
: Upload(reply)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageShackUpload::processReply(const QByteArray &data)
|
||||||
|
{
|
||||||
|
// Obtain the root object from the JSON response
|
||||||
|
QJsonObject object(QJsonDocument::fromJson(data).object());
|
||||||
|
|
||||||
|
// Attempt to retrieve the link
|
||||||
|
bool success = object.value("success").toBool();
|
||||||
|
QString link = object.value("result").toObject().value("images").toArray()
|
||||||
|
.at(0).toObject().value("direct_link").toString();
|
||||||
|
|
||||||
|
// Check for success
|
||||||
|
if (!success || link.isNull()) {
|
||||||
|
QString errorMessage = object.value("error").toObject()
|
||||||
|
.value("error_message").toString();
|
||||||
|
if (errorMessage.isNull()) {
|
||||||
|
errorMessage = tr("unknown error response");
|
||||||
|
}
|
||||||
|
Q_EMIT error(errorMessage);
|
||||||
|
} else {
|
||||||
|
Q_EMIT completed("https://" + link);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LXIMAGE_IMAGESHACKUPLOAD_H
|
||||||
|
#define LXIMAGE_IMAGESHACKUPLOAD_H
|
||||||
|
|
||||||
|
#include "upload.h"
|
||||||
|
|
||||||
|
namespace LxImage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Upload to ImageShack's API
|
||||||
|
*/
|
||||||
|
class ImageShackUpload : public Upload
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit ImageShackUpload(QNetworkReply *reply);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void processReply(const QByteArray &data);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LXIMAGE_IMAGESHACKUPLOAD_H
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include "imgurprovider.h"
|
||||||
|
#include "imgurupload.h"
|
||||||
|
|
||||||
|
using namespace LxImage;
|
||||||
|
|
||||||
|
const QUrl gUploadURL("https://api.imgur.com/3/upload.json");
|
||||||
|
const QByteArray gAuthHeader = "Client-ID 63ff047cd8bcf9e";
|
||||||
|
const QByteArray gTypeHeader = "application/x-www-form-urlencoded";
|
||||||
|
|
||||||
|
Upload *ImgurProvider::upload(QIODevice *device)
|
||||||
|
{
|
||||||
|
// Create the request with the correct HTTP headers
|
||||||
|
QNetworkRequest request(gUploadURL);
|
||||||
|
request.setHeader(QNetworkRequest::ContentTypeHeader, gTypeHeader);
|
||||||
|
request.setRawHeader("Authorization", gAuthHeader);
|
||||||
|
|
||||||
|
// Start the request and wrap it in an ImgurUpload
|
||||||
|
return new ImgurUpload(sManager.post(request, device));
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LXIMAGE_IMGURPROVIDER_H
|
||||||
|
#define LXIMAGE_IMGURPROVIDER_H
|
||||||
|
|
||||||
|
#include "provider.h"
|
||||||
|
|
||||||
|
namespace LxImage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create uploads to Imgur's API
|
||||||
|
*/
|
||||||
|
class ImgurProvider : public Provider
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual Upload *upload(QIODevice *device);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LXIMAGE_IMGURPROVIDER_H
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "imgurupload.h"
|
||||||
|
|
||||||
|
using namespace LxImage;
|
||||||
|
|
||||||
|
ImgurUpload::ImgurUpload(QNetworkReply *reply)
|
||||||
|
: Upload(reply)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImgurUpload::processReply(const QByteArray &data)
|
||||||
|
{
|
||||||
|
// Obtain the root object from the JSON response
|
||||||
|
QJsonObject object(QJsonDocument::fromJson(data).object());
|
||||||
|
|
||||||
|
// Attempt to retrieve the value for "success" and "data->link"
|
||||||
|
bool success = object.value("success").toBool();
|
||||||
|
QJsonObject dataObject = object.value("data").toObject();
|
||||||
|
QString dataLink = dataObject.value("link").toString();
|
||||||
|
QString dataError = dataObject.value("error").toString();
|
||||||
|
|
||||||
|
// Ensure that "success" is true & link is valid, otherwise throw an error
|
||||||
|
if (!success || dataLink.isNull()) {
|
||||||
|
if (dataError.isNull()) {
|
||||||
|
dataError = tr("unknown error response");
|
||||||
|
}
|
||||||
|
Q_EMIT error(dataError);
|
||||||
|
} else {
|
||||||
|
Q_EMIT completed(dataLink);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LXIMAGE_IMGURUPLOAD_H
|
||||||
|
#define LXIMAGE_IMGURUPLOAD_H
|
||||||
|
|
||||||
|
#include "upload.h"
|
||||||
|
|
||||||
|
namespace LxImage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Process uploads to Imgur's API
|
||||||
|
*/
|
||||||
|
class ImgurUpload : public Upload
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit ImgurUpload(QNetworkReply *reply);
|
||||||
|
|
||||||
|
virtual void processReply(const QByteArray &data);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LXIMAGE_IMGURUPLOAD_H
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "provider.h"
|
||||||
|
|
||||||
|
using namespace LxImage;
|
||||||
|
|
||||||
|
QNetworkAccessManager Provider::sManager;
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LXIMAGE_PROVIDER_H
|
||||||
|
#define LXIMAGE_PROVIDER_H
|
||||||
|
|
||||||
|
#include <QIODevice>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace LxImage {
|
||||||
|
|
||||||
|
class Upload;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Base class for providers
|
||||||
|
*/
|
||||||
|
class Provider : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Upload the provided data
|
||||||
|
* @param device reader for uploaded data from
|
||||||
|
* @return newly created upload
|
||||||
|
*/
|
||||||
|
virtual Upload *upload(QIODevice *device) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
static QNetworkAccessManager sManager;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LXIMAGE_PROVIDER_H
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "upload.h"
|
||||||
|
|
||||||
|
using namespace LxImage;
|
||||||
|
|
||||||
|
Upload::Upload(QNetworkReply *reply)
|
||||||
|
: mReply(reply)
|
||||||
|
{
|
||||||
|
// Reparent the reply to this object
|
||||||
|
mReply->setParent(this);
|
||||||
|
|
||||||
|
// Emit progress() when upload progress changes
|
||||||
|
connect(mReply, &QNetworkReply::uploadProgress, [this](qint64 bytesSent, qint64 bytesTotal) {
|
||||||
|
Q_EMIT progress(static_cast<int>(
|
||||||
|
static_cast<double>(bytesSent) / static_cast<double>(bytesTotal) * 100.0
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Emit error() when a socket error occurs
|
||||||
|
connect(mReply, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), [this](QNetworkReply::NetworkError) {
|
||||||
|
Q_EMIT error(mReply->errorString());
|
||||||
|
});
|
||||||
|
|
||||||
|
// Process the request when it finishes
|
||||||
|
connect(mReply, &QNetworkReply::finished, [this]() {
|
||||||
|
if (mReply->error() == QNetworkReply::NoError) {
|
||||||
|
processReply(mReply->readAll());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Emit finished() when completed() or error() is emitted
|
||||||
|
connect(this, &Upload::completed, this, &Upload::finished);
|
||||||
|
connect(this, &Upload::error, this, &Upload::finished);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Upload::abort()
|
||||||
|
{
|
||||||
|
mReply->abort();
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LXIMAGE_UPLOAD_H
|
||||||
|
#define LXIMAGE_UPLOAD_H
|
||||||
|
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace LxImage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Base class for uploads
|
||||||
|
*/
|
||||||
|
class Upload : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create an upload
|
||||||
|
* @param reply network reply
|
||||||
|
*
|
||||||
|
* The upload will assume ownership of the network reply and connect to its
|
||||||
|
* signals, emitting uploadError() when something goes wrong.
|
||||||
|
*/
|
||||||
|
explicit Upload(QNetworkReply *reply);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Abort the upload
|
||||||
|
*/
|
||||||
|
void abort();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Indicate that upload progress has changed
|
||||||
|
* @param value new progress value
|
||||||
|
*/
|
||||||
|
void progress(int value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Indicate that the upload completed
|
||||||
|
* @param url new URL of the upload
|
||||||
|
*/
|
||||||
|
void completed(const QString &url);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Indicate that an error occurred
|
||||||
|
* @param message description of the error
|
||||||
|
*/
|
||||||
|
void error(const QString &message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Indicate that the upload finished
|
||||||
|
*
|
||||||
|
* This signal is emitted after either completed() or error().
|
||||||
|
*/
|
||||||
|
void finished();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Process the data from the reply
|
||||||
|
* @param data content from the reply
|
||||||
|
*
|
||||||
|
* This method should parse the data and either emit the completed() or
|
||||||
|
* error() signal.
|
||||||
|
*/
|
||||||
|
virtual void processReply(const QByteArray &data) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QNetworkReply *mReply;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LXIMAGE_UPLOAD_H
|
@ -0,0 +1,141 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QProgressBar>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include "imageshackprovider.h"
|
||||||
|
#include "imgurprovider.h"
|
||||||
|
#include "provider.h"
|
||||||
|
#include "upload.h"
|
||||||
|
#include "uploaddialog.h"
|
||||||
|
|
||||||
|
using namespace LxImage;
|
||||||
|
|
||||||
|
ImgurProvider gImgurProvider;
|
||||||
|
ImageShackProvider gImageShackProvider;
|
||||||
|
|
||||||
|
UploadDialog::UploadDialog(QWidget *parent, const QString &filename)
|
||||||
|
: QDialog(parent),
|
||||||
|
mState(SelectProvider),
|
||||||
|
mFile(filename),
|
||||||
|
mUpload(nullptr)
|
||||||
|
{
|
||||||
|
ui.setupUi(this);
|
||||||
|
|
||||||
|
// Populate the list of providers
|
||||||
|
ui.providerComboBox->addItem(tr("Imgur"), QVariant::fromValue(&gImgurProvider));
|
||||||
|
ui.providerComboBox->addItem(tr("ImageShack"), QVariant::fromValue(&gImageShackProvider));
|
||||||
|
|
||||||
|
updateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UploadDialog::on_actionButton_clicked()
|
||||||
|
{
|
||||||
|
switch (mState) {
|
||||||
|
case SelectProvider:
|
||||||
|
start();
|
||||||
|
break;
|
||||||
|
case UploadInProgress:
|
||||||
|
mUpload->abort();
|
||||||
|
break;
|
||||||
|
case Completed:
|
||||||
|
accept();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UploadDialog::start()
|
||||||
|
{
|
||||||
|
// Attempt to open the file
|
||||||
|
if (!mFile.open(QIODevice::ReadOnly)) {
|
||||||
|
showError(mFile.errorString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the selected provider
|
||||||
|
Provider *provider = ui.providerComboBox->itemData(
|
||||||
|
ui.providerComboBox->currentIndex()
|
||||||
|
).value<Provider*>();
|
||||||
|
|
||||||
|
// Create the upload
|
||||||
|
mUpload = provider->upload(&mFile);
|
||||||
|
|
||||||
|
// Update the progress bar as the upload progresses
|
||||||
|
connect(mUpload, &Upload::progress, ui.progressBar, &QProgressBar::setValue);
|
||||||
|
|
||||||
|
// If the request completes, show the link to the user
|
||||||
|
connect(mUpload, &Upload::completed, [this](const QString &url) {
|
||||||
|
ui.linkLineEdit->setText(url);
|
||||||
|
|
||||||
|
mState = Completed;
|
||||||
|
updateUi();
|
||||||
|
});
|
||||||
|
|
||||||
|
// If the request fails, show an error
|
||||||
|
connect(mUpload, &Upload::error, [this](const QString &message) {
|
||||||
|
showError(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Destroy the upload when it completes
|
||||||
|
connect(mUpload, &Upload::finished, [this]() {
|
||||||
|
mFile.close();
|
||||||
|
mUpload->deleteLater();
|
||||||
|
mUpload = nullptr;
|
||||||
|
});
|
||||||
|
|
||||||
|
mState = UploadInProgress;
|
||||||
|
updateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UploadDialog::updateUi()
|
||||||
|
{
|
||||||
|
// Show the appropriate control given the current state
|
||||||
|
ui.providerComboBox->setVisible(mState == SelectProvider);
|
||||||
|
ui.progressBar->setVisible(mState == UploadInProgress);
|
||||||
|
ui.linkLineEdit->setVisible(mState == Completed);
|
||||||
|
|
||||||
|
// Reset the progress bar to zero
|
||||||
|
ui.progressBar->setValue(0);
|
||||||
|
|
||||||
|
// Set the correct button text
|
||||||
|
switch (mState) {
|
||||||
|
case SelectProvider:
|
||||||
|
ui.actionButton->setText(tr("Start"));
|
||||||
|
break;
|
||||||
|
case UploadInProgress:
|
||||||
|
ui.actionButton->setText(tr("Stop"));
|
||||||
|
break;
|
||||||
|
case Completed:
|
||||||
|
ui.actionButton->setText(tr("Close"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UploadDialog::showError(const QString &message)
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Error"), message);
|
||||||
|
|
||||||
|
mState = SelectProvider;
|
||||||
|
updateUi();
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
LxImage - image viewer and screenshot tool for lxqt
|
||||||
|
Copyright (C) 2017 Nathan Osman <nathan@quickmediasolutions.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LXIMAGE_UPLOADDIALOG_H
|
||||||
|
#define LXIMAGE_UPLOADDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
#include "ui_uploaddialog.h"
|
||||||
|
|
||||||
|
namespace LxImage {
|
||||||
|
|
||||||
|
class Upload;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Dialog for uploading an image
|
||||||
|
*/
|
||||||
|
class UploadDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a dialog for uploading the specified file
|
||||||
|
* @param parent widget parent
|
||||||
|
* @param filename absolute path to file
|
||||||
|
*/
|
||||||
|
UploadDialog(QWidget *parent, const QString &filename);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
|
||||||
|
void on_actionButton_clicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void start();
|
||||||
|
void updateUi();
|
||||||
|
void showError(const QString &message);
|
||||||
|
|
||||||
|
Ui::UploadDialog ui;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
SelectProvider,
|
||||||
|
UploadInProgress,
|
||||||
|
Completed,
|
||||||
|
} mState;
|
||||||
|
|
||||||
|
QFile mFile;
|
||||||
|
|
||||||
|
Upload *mUpload;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LXIMAGE_UPLOADDIALOG_H
|
@ -0,0 +1,79 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>UploadDialog</class>
|
||||||
|
<widget class="QDialog" name="UploadDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>300</width>
|
||||||
|
<height>100</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Upload</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="providerComboBox"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QProgressBar" name="progressBar">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="linkLineEdit">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="actionButton">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in new issue