added more sound
This commit is contained in:
parent
f9d6091440
commit
0537766392
@ -12,6 +12,8 @@
|
||||
#include <formatter.hpp>
|
||||
#include <io/ioutils.hpp>
|
||||
#include <notifications.hpp>
|
||||
#include <QMediaPlayer>
|
||||
#include "mainwindow.hpp"
|
||||
|
||||
using formats::normalFormatFromName;
|
||||
using formats::normalFormatMIME;
|
||||
@ -212,6 +214,7 @@ void CustomUploader::parseResult(QJsonDocument result, QByteArray data, QString
|
||||
if (result.isObject()) {
|
||||
QString url
|
||||
= formatter::format(urlPrepend, "") + parsePathspec(result, returnPathspec) + formatter::format(urlAppend, "");
|
||||
playSuccessSound();
|
||||
if (!url.isEmpty()) {
|
||||
QApplication::clipboard()->setText(url);
|
||||
notifications::notify(tr("KShare Custom Uploader ") + name, tr("Copied upload link to clipboard!"));
|
||||
@ -220,6 +223,7 @@ void CustomUploader::parseResult(QJsonDocument result, QByteArray data, QString
|
||||
QApplication::clipboard()->setText(data);
|
||||
}
|
||||
} else {
|
||||
playErrorSound();
|
||||
notifications::notify(tr("KShare Custom Uploader ") + name,
|
||||
tr("Upload done, but result is not JSON Object! Result in clipboard."));
|
||||
QApplication::clipboard()->setText(data);
|
||||
@ -338,6 +342,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
||||
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
||||
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
||||
for (auto arr : arraysToDelete) delete arr;
|
||||
playSuccessSound();
|
||||
notifications::notify(tr("KShare Custom Uploader ") + name(),
|
||||
tr("Copied upload result to clipboard!"));
|
||||
});
|
||||
@ -355,6 +360,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
||||
}
|
||||
}
|
||||
if (limit > 0 && data.size() > limit) {
|
||||
playErrorSound();
|
||||
notifications::notify(tr("KShare Custom Uploader ") + name(), tr("File limit exceeded!"));
|
||||
return;
|
||||
}
|
||||
@ -363,6 +369,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
||||
if (returnPathspec == "|") {
|
||||
ioutils::postData(target, h, data, [&](QByteArray result, QNetworkReply *) {
|
||||
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
||||
playSuccessSound();
|
||||
notifications::notify(tr("KShare Custom Uploader ") + name(), tr("Copied upload result to clipboard!"));
|
||||
});
|
||||
} else {
|
||||
@ -373,3 +380,23 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CustomUploader::playSuccessSound() {
|
||||
QMediaPlayer* mediaPlayer = new QMediaPlayer(MainWindow::inst());
|
||||
mediaPlayer->setMedia(QUrl("qrc:/successsound.wav"));
|
||||
mediaPlayer->setVolume(50);
|
||||
mediaPlayer->play();
|
||||
|
||||
if(mediaPlayer->error() != QMediaPlayer::NoError && mediaPlayer->error() != QMediaPlayer::ServiceMissingError)
|
||||
notifications::notify(QString::number(mediaPlayer->error()), mediaPlayer->errorString(), QSystemTrayIcon::Warning);
|
||||
}
|
||||
|
||||
void CustomUploader::playErrorSound() {
|
||||
QMediaPlayer* mediaPlayer = new QMediaPlayer(MainWindow::inst());
|
||||
mediaPlayer->setMedia(QUrl("qrc:/errorsound.wav"));
|
||||
mediaPlayer->setVolume(50);
|
||||
mediaPlayer->play();
|
||||
|
||||
if(mediaPlayer->error() != QMediaPlayer::NoError && mediaPlayer->error() != QMediaPlayer::ServiceMissingError)
|
||||
notifications::notify(QString::number(mediaPlayer->error()), mediaPlayer->errorString(), QSystemTrayIcon::Warning);
|
||||
}
|
@ -33,6 +33,8 @@ private:
|
||||
QString returnPathspec;
|
||||
QString urlPrepend, urlAppend;
|
||||
void parseResult(QJsonDocument result, QByteArray data, QString returnPathspec, QString name);
|
||||
void playSuccessSound();
|
||||
void playErrorSound();
|
||||
};
|
||||
|
||||
#endif // CUSTOMUPLOADER_HPP
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <notifications.hpp>
|
||||
#include <settings.hpp>
|
||||
#include <utils.hpp>
|
||||
#include <QMediaPlayer>
|
||||
#include "mainwindow.hpp"
|
||||
|
||||
struct SegfaultWorkaround { // I'm a scrub for doing this
|
||||
SegfaultWorkaround(QByteArray a, ImgurUploader *u, QString m) : byteArray(), dis(u), mime(m) {
|
||||
@ -90,11 +92,33 @@ void ImgurUploader::handleSend(QString auth, QString mime, QByteArray byteArray)
|
||||
if (!result.isEmpty()) {
|
||||
utils::toClipboard(result);
|
||||
notifications::notify(tr("KShare imgur Uploader"), tr("Uploaded to imgur!"));
|
||||
playSuccessSound();
|
||||
} else {
|
||||
notifications::notify(tr("KShare imgur Uploader "),
|
||||
QString(tr("Failed upload! imgur said: HTTP %1: %2"))
|
||||
.arg(r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt())
|
||||
.arg(r->errorString()));
|
||||
playErrorSound();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ImgurUploader::playSuccessSound() {
|
||||
QMediaPlayer* mediaPlayer = new QMediaPlayer(MainWindow::inst());
|
||||
mediaPlayer->setMedia(QUrl("qrc:/successsound.wav"));
|
||||
mediaPlayer->setVolume(50);
|
||||
mediaPlayer->play();
|
||||
|
||||
if(mediaPlayer->error() != QMediaPlayer::NoError && mediaPlayer->error() != QMediaPlayer::ServiceMissingError)
|
||||
notifications::notify(QString::number(mediaPlayer->error()), mediaPlayer->errorString(), QSystemTrayIcon::Warning);
|
||||
}
|
||||
|
||||
void ImgurUploader::playErrorSound() {
|
||||
QMediaPlayer*mediaPlayer = new QMediaPlayer(MainWindow::inst());
|
||||
mediaPlayer->setMedia(QUrl("qrc:/errorsound.wav"));
|
||||
mediaPlayer->setVolume(50);
|
||||
mediaPlayer->play();
|
||||
|
||||
if(mediaPlayer->error() != QMediaPlayer::NoError && mediaPlayer->error() != QMediaPlayer::ServiceMissingError)
|
||||
notifications::notify(QString::number(mediaPlayer->error()), mediaPlayer->errorString(), QSystemTrayIcon::Warning);
|
||||
}
|
@ -20,6 +20,8 @@ public:
|
||||
|
||||
private:
|
||||
void handleSend(QString auth, QString mime, QByteArray byteArray);
|
||||
void playSuccessSound();
|
||||
void playErrorSound();
|
||||
};
|
||||
|
||||
#endif // IMGURUPLOADER_HPP
|
||||
|
Loading…
Reference in New Issue
Block a user