added upload from clipboard
This commit is contained in:
parent
31a02ab592
commit
b5b54cefd8
@ -19,6 +19,7 @@ It has many features, including:
|
|||||||
* Hotkeys,
|
* Hotkeys,
|
||||||
* Color picker, and last but not least,
|
* Color picker, and last but not least,
|
||||||
* Custom upload destinations
|
* Custom upload destinations
|
||||||
|
* Upload from clipboard
|
||||||
|
|
||||||
## Enough talking, show us how it looks
|
## Enough talking, show us how it looks
|
||||||
The main window is rather simple, with only a log, and a button in it:
|
The main window is rather simple, with only a log, and a button in it:
|
||||||
|
68
src/clipboard/clipboardcopy.cpp
Normal file
68
src/clipboard/clipboardcopy.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include "clipboardcopy.hpp"
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QString>
|
||||||
|
#include <QMimeDatabase>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QTemporaryFile>
|
||||||
|
#include <QIODevice>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QMediaPlayer>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <logger.hpp>
|
||||||
|
#include <io/ioutils.hpp>
|
||||||
|
#include <notifications.hpp>
|
||||||
|
#include <uploaders/uploadersingleton.hpp>
|
||||||
|
#include "mainwindow.hpp"
|
||||||
|
|
||||||
|
void clipboardcopy::copyClipboard() {
|
||||||
|
const QClipboard *clipboard = QApplication::clipboard();
|
||||||
|
const QMimeData *mimeData = clipboard->mimeData();
|
||||||
|
|
||||||
|
if(mimeData->hasImage()) {
|
||||||
|
QPixmap map = qvariant_cast<QPixmap>(mimeData->imageData());
|
||||||
|
} else if(mimeData->hasText()) {
|
||||||
|
QFileInfo fileInfo(mimeData->text());
|
||||||
|
if(fileInfo.exists() && fileInfo.isReadable() && fileInfo.isFile()) {
|
||||||
|
QMimeDatabase db;
|
||||||
|
QMimeType mimeType = db.mimeTypeForFile(fileInfo);
|
||||||
|
QString type = mimeType.name();
|
||||||
|
QFile file(fileInfo.absoluteFilePath());
|
||||||
|
logger::info(type);
|
||||||
|
UploaderSingleton::inst().upload(file);
|
||||||
|
} else if (fileInfo.exists() && fileInfo.isReadable() && fileInfo.isDir()) {
|
||||||
|
notifications::notify("KShare - Directory is not uploadable", fileInfo.absolutePath(), QSystemTrayIcon::Warning);
|
||||||
|
playErrorSound();
|
||||||
|
} else {
|
||||||
|
QTemporaryFile tmpFile;
|
||||||
|
tmpFile.setAutoRemove(true);
|
||||||
|
if(tmpFile.open()) {
|
||||||
|
QTextStream stream(&tmpFile);
|
||||||
|
stream << mimeData->text();
|
||||||
|
stream.flush();
|
||||||
|
tmpFile.seek(0);
|
||||||
|
UploaderSingleton::inst().upload(tmpFile);
|
||||||
|
} else {
|
||||||
|
logger::warn("Can not open tmp file");
|
||||||
|
playErrorSound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
notifications::notify("Unsupported File Format", "Can not upload clipboard", QSystemTrayIcon::Warning);
|
||||||
|
playErrorSound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void clipboardcopy::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);
|
||||||
|
}
|
11
src/clipboard/clipboardcopy.hpp
Normal file
11
src/clipboard/clipboardcopy.hpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef KSHARE_CLIPBOARDCOPY_HPP
|
||||||
|
#define KSHARE_CLIPBOARDCOPY_HPP
|
||||||
|
|
||||||
|
|
||||||
|
namespace clipboardcopy {
|
||||||
|
void copyClipboard();
|
||||||
|
void playErrorSound();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //KSHARE_CLIPBOARDCOPY_HPP
|
@ -25,6 +25,7 @@
|
|||||||
#include <logs/requestlogging.hpp>
|
#include <logs/requestlogging.hpp>
|
||||||
#include "io/ioutils.hpp"
|
#include "io/ioutils.hpp"
|
||||||
#include <monospacetextdialog.hpp>
|
#include <monospacetextdialog.hpp>
|
||||||
|
#include <clipboard/clipboardcopy.hpp>
|
||||||
|
|
||||||
MainWindow *MainWindow::instance;
|
MainWindow *MainWindow::instance;
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
connect(ui->areaButton, &QPushButton::clicked, this, [] { screenshotter::areaDelayed(); });
|
connect(ui->areaButton, &QPushButton::clicked, this, [] { screenshotter::areaDelayed(); });
|
||||||
connect(ui->aboutButton, &QPushButton::clicked, this, &MainWindow::on_actionAbout_triggered);
|
connect(ui->aboutButton, &QPushButton::clicked, this, &MainWindow::on_actionAbout_triggered);
|
||||||
connect(ui->screenshotFolderButton, &QPushButton::clicked, this, &MainWindow::openScreenshotFolder);
|
connect(ui->screenshotFolderButton, &QPushButton::clicked, this, &MainWindow::openScreenshotFolder);
|
||||||
connect(ui->clipboardButton, &QPushButton::clicked, this, &MainWindow::openScreenshotFolder);
|
connect(ui->clipboardButton, &QPushButton::clicked, this, &clipboardcopy::copyClipboard);
|
||||||
connect(ui->colorPickerButton, &QPushButton::clicked, this, [] { ColorPickerScene::showPicker(); });
|
connect(ui->colorPickerButton, &QPushButton::clicked, this, [] { ColorPickerScene::showPicker(); });
|
||||||
|
|
||||||
ui->treeWidget->addAction(ui->actionOpenURL);
|
ui->treeWidget->addAction(ui->actionOpenURL);
|
||||||
@ -128,6 +129,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
addHotkey("area", [] { screenshotter::area(); });
|
addHotkey("area", [] { screenshotter::area(); });
|
||||||
addHotkey("active", [] { screenshotter::active(); });
|
addHotkey("active", [] { screenshotter::active(); });
|
||||||
addHotkey("picker", [] { ColorPickerScene::showPicker(); });
|
addHotkey("picker", [] { ColorPickerScene::showPicker(); });
|
||||||
|
addHotkey("clipboard", [] { clipboardcopy::copyClipboard(); });
|
||||||
addHotkey("recordingstop", [&] { controller->end(); });
|
addHotkey("recordingstop", [&] { controller->end(); });
|
||||||
addHotkey("recordingabort", [&] { controller->abort(); });
|
addHotkey("recordingabort", [&] { controller->abort(); });
|
||||||
addHotkey("recordingstart", [&] { this->rec(); });
|
addHotkey("recordingstart", [&] { this->rec(); });
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <screenshotter.hpp>
|
#include <screenshotter.hpp>
|
||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
#include <uploaders/uploadersingleton.hpp>
|
#include <uploaders/uploadersingleton.hpp>
|
||||||
|
#include <clipboard/clipboardcopy.hpp>
|
||||||
|
|
||||||
static QMap<QString, std::function<void()>> fncs;
|
static QMap<QString, std::function<void()>> fncs;
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se
|
|||||||
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
|
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
|
||||||
addHotkeyItem(ui->hotkeys, tr("Active window"), "active", [&] { screenshotter::active(); });
|
addHotkeyItem(ui->hotkeys, tr("Active window"), "active", [&] { screenshotter::active(); });
|
||||||
#endif
|
#endif
|
||||||
|
addHotkeyItem(ui->hotkeys, tr("Copy Clipboard"), "clipboard", [] { clipboardcopy::copyClipboard(); });
|
||||||
addHotkeyItem(ui->hotkeys, tr("Color picker"), "picker", [] { ColorPickerScene::showPicker(); });
|
addHotkeyItem(ui->hotkeys, tr("Color picker"), "picker", [] { ColorPickerScene::showPicker(); });
|
||||||
addHotkeyItem(ui->hotkeys, tr("Stop Recording"), "recordingstop", [&] { MainWindow::inst()->controller->end(); });
|
addHotkeyItem(ui->hotkeys, tr("Stop Recording"), "recordingstop", [&] { MainWindow::inst()->controller->end(); });
|
||||||
addHotkeyItem(ui->hotkeys, tr("Start Recording"), "recordingstart", [&] { MainWindow::inst()->rec(); });
|
addHotkeyItem(ui->hotkeys, tr("Start Recording"), "recordingstart", [&] { MainWindow::inst()->rec(); });
|
||||||
|
@ -72,7 +72,8 @@ SOURCES += main.cpp\
|
|||||||
screenoverlay/screenoverlayview.cpp \
|
screenoverlay/screenoverlayview.cpp \
|
||||||
screenoverlay/screenoverlay.cpp \
|
screenoverlay/screenoverlay.cpp \
|
||||||
screenoverlay/screenoverlaysettings.cpp \
|
screenoverlay/screenoverlaysettings.cpp \
|
||||||
logger.cpp
|
logger.cpp \
|
||||||
|
clipboard/clipboardcopy.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.hpp \
|
HEADERS += mainwindow.hpp \
|
||||||
cropeditor/cropeditor.hpp \
|
cropeditor/cropeditor.hpp \
|
||||||
@ -123,7 +124,8 @@ HEADERS += mainwindow.hpp \
|
|||||||
screenoverlay/screenoverlayview.hpp \
|
screenoverlay/screenoverlayview.hpp \
|
||||||
screenoverlay/screenoverlay.hpp \
|
screenoverlay/screenoverlay.hpp \
|
||||||
screenoverlay/screenoverlaysettings.hpp \
|
screenoverlay/screenoverlaysettings.hpp \
|
||||||
logger.hpp
|
logger.hpp \
|
||||||
|
clipboard/clipboardcopy.hpp
|
||||||
|
|
||||||
nopkg {
|
nopkg {
|
||||||
# win32 {
|
# win32 {
|
||||||
|
@ -117,6 +117,16 @@ void UploaderSingleton::upload(QFile &img, QString format) {
|
|||||||
notifications::notify(tr("KShare - Failed to save picture"), img.errorString(), QSystemTrayIcon::Warning);
|
notifications::notify(tr("KShare - Failed to save picture"), img.errorString(), QSystemTrayIcon::Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UploaderSingleton::upload(QFile &img) {
|
||||||
|
updateSaveSettings();
|
||||||
|
if (img.size() <= 0) return;
|
||||||
|
QFileInfo fileInfo(img.fileName());
|
||||||
|
if (img.open(QFile::ReadWrite))
|
||||||
|
uploaders.value(uploader)->doUpload(img.readAll(), "", fileInfo.fileName());
|
||||||
|
else
|
||||||
|
notifications::notify(tr("KShare - Failed to open File"), img.errorString(), QSystemTrayIcon::Warning);
|
||||||
|
}
|
||||||
|
|
||||||
void UploaderSingleton::showSettings() {
|
void UploaderSingleton::showSettings() {
|
||||||
uploaders.value(uploader)->showSettings();
|
uploaders.value(uploader)->showSettings();
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ public:
|
|||||||
void upload(QPixmap pixmap);
|
void upload(QPixmap pixmap);
|
||||||
void upload(QByteArray img, QString format);
|
void upload(QByteArray img, QString format);
|
||||||
void upload(QFile &img, QString format);
|
void upload(QFile &img, QString format);
|
||||||
|
void upload(QFile &img);
|
||||||
void showSettings();
|
void showSettings();
|
||||||
QList<Uploader *> uploaderList();
|
QList<Uploader *> uploaderList();
|
||||||
void set(QString uploader);
|
void set(QString uploader);
|
||||||
|
Loading…
Reference in New Issue
Block a user