Notifications
This commit is contained in:
parent
895960c1b0
commit
9a90814891
@ -36,7 +36,8 @@ SOURCES += main.cpp\
|
||||
settings.cpp \
|
||||
uploaders/default/clipboarduploader.cpp \
|
||||
formatter.cpp \
|
||||
uploaders/customuploader.cpp
|
||||
uploaders/customuploader.cpp \
|
||||
notifications.cpp
|
||||
|
||||
HEADERS += mainwindow.hpp \
|
||||
cropeditor/cropeditor.hpp \
|
||||
@ -51,7 +52,8 @@ HEADERS += mainwindow.hpp \
|
||||
settings.hpp \
|
||||
uploaders/default/clipboarduploader.hpp \
|
||||
formatter.hpp \
|
||||
uploaders/customuploader.hpp
|
||||
uploaders/customuploader.hpp \
|
||||
notifications.hpp
|
||||
|
||||
FORMS += mainwindow.ui
|
||||
|
||||
|
@ -13,8 +13,11 @@
|
||||
#include <settings.hpp>
|
||||
#include <uploaders/uploadersingleton.hpp>
|
||||
|
||||
MainWindow *MainWindow::instance;
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
||||
{
|
||||
instance = this;
|
||||
ui->setupUi(this);
|
||||
setWindowIcon(QIcon(":/icons/icon.jpg"));
|
||||
tray = new QSystemTrayIcon(windowIcon(), this);
|
||||
@ -51,7 +54,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
if (errors.length() == 1)
|
||||
statusBar()->showMessage(errors.at(0).what());
|
||||
else
|
||||
statusBar()->showMessage(QString("Errors visible in console. Count: " + errors.size()));
|
||||
statusBar()->showMessage(QString("Errors visible in console (if present). Count: " + QString::number(errors.size())));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -64,6 +67,11 @@ void MainWindow::setScheme(QString scheme)
|
||||
ui->nameScheme->setText(scheme);
|
||||
}
|
||||
|
||||
MainWindow *MainWindow::inst()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
event->ignore();
|
||||
|
@ -29,11 +29,14 @@ class MainWindow : public QMainWindow
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
QSystemTrayIcon *tray;
|
||||
void setScheme(QString scheme);
|
||||
|
||||
static MainWindow *inst();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QSystemTrayIcon *tray;
|
||||
static MainWindow *instance;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>312</width>
|
||||
<height>317</height>
|
||||
<width>470</width>
|
||||
<height>315</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -59,7 +59,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>312</width>
|
||||
<width>470</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
10
notifications.cpp
Normal file
10
notifications.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "notifications.hpp"
|
||||
|
||||
#include "mainwindow.hpp"
|
||||
#include <QStatusBar>
|
||||
|
||||
void notifications::notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon)
|
||||
{
|
||||
MainWindow::inst()->tray->showMessage(title, body, icon, 5000);
|
||||
MainWindow::inst()->statusBar()->showMessage(title + ": " + body);
|
||||
}
|
12
notifications.hpp
Normal file
12
notifications.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef NOTIFICATIONS_HPP
|
||||
#define NOTIFICATIONS_HPP
|
||||
|
||||
#include <QString>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
namespace notifications
|
||||
{
|
||||
void notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
|
||||
}
|
||||
|
||||
#endif // NOTIFICATIONS_HPP
|
@ -8,6 +8,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QNetworkReply>
|
||||
#include <io/ioutils.hpp>
|
||||
#include <notifications.hpp>
|
||||
|
||||
using std::runtime_error;
|
||||
|
||||
@ -257,6 +258,21 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec)
|
||||
return "";
|
||||
}
|
||||
|
||||
void parseResult(QJsonDocument result, QString returnPathspec, QString name)
|
||||
{
|
||||
if (result.isObject())
|
||||
{
|
||||
QString url = parsePathspec(result, returnPathspec);
|
||||
if (!url.isEmpty())
|
||||
{
|
||||
QApplication::clipboard()->setText(url);
|
||||
notifications::notify("KShare Custom Uploader " + name, "Copied upload link to clipboard!");
|
||||
}
|
||||
else
|
||||
notifications::notify("KShare Custom Uploader " + name, "Upload done, but result empty!");
|
||||
}
|
||||
}
|
||||
|
||||
void CustomUploader::doUpload(QPixmap *pixmap)
|
||||
{
|
||||
auto h = getHeaders(headers, getFormatString(false), types, this->format);
|
||||
@ -329,16 +345,13 @@ void CustomUploader::doUpload(QPixmap *pixmap)
|
||||
{
|
||||
ioutils::postData(target, h, data, [&](QByteArray result, QNetworkReply *) {
|
||||
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
||||
notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ioutils::postJson(target, h, data, [&](QJsonDocument result, QNetworkReply *) {
|
||||
if (result.isObject())
|
||||
{
|
||||
QApplication::clipboard()->setText(parsePathspec(result, returnPathspec));
|
||||
}
|
||||
});
|
||||
ioutils::postJson(target, h, data,
|
||||
[&](QJsonDocument result, QNetworkReply *) { parseResult(result, returnPathspec, name()); });
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <notifications.hpp>
|
||||
|
||||
void ClipboardUploader::doUpload(QPixmap *pixmap)
|
||||
{
|
||||
QApplication::clipboard()->setImage(pixmap->toImage());
|
||||
notifications::notify("KShare", "Copied to clipboard!");
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <io/ioutils.hpp>
|
||||
#include <notifications.hpp>
|
||||
#include <screenshotutil.hpp>
|
||||
|
||||
void ImgurUploader::doUpload(QPixmap *pixmap)
|
||||
@ -16,6 +17,9 @@ void ImgurUploader::doUpload(QPixmap *pixmap)
|
||||
<< QPair<QString, QString>("Content-Type", "application/x-www-form-urlencoded")
|
||||
<< QPair<QString, QString>("Authorization", "Client-ID 8a98f183fc895da"),
|
||||
byteArray, [](QJsonDocument res, QNetworkReply *) {
|
||||
screenshotutil::toClipboard(res.object()["data"].toObject()["link"].toString());
|
||||
QString result = res.object()["data"].toObject()["link"].toString();
|
||||
screenshotutil::toClipboard(result);
|
||||
notifications::notify("KShare imgur Uploader ",
|
||||
result.isEmpty() ? "Failed upload!" : "Upload done, but result empty!");
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user