Make the project translatable
Jeeeesh that's alot
This commit is contained in:
parent
e0ee91d4a3
commit
9f57a10bb8
@ -16,7 +16,7 @@ ColorPickerScene::ColorPickerScene(QPixmap pixmap, QWidget *parentWidget)
|
|||||||
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
|
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
|
||||||
setCursor(QCursor(Qt::CrossCursor));
|
setCursor(QCursor(Qt::CrossCursor));
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
setWindowTitle("KShare Color Picker");
|
setWindowTitle(tr("KShare Color Picker"));
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
pItem = addPixmap(pixmap);
|
pItem = addPixmap(pixmap);
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <screenshotutil.hpp>
|
#include <screenshotutil.hpp>
|
||||||
|
|
||||||
class ColorPickerScene : public QGraphicsScene, public QGraphicsView {
|
class ColorPickerScene : public QGraphicsScene, public QGraphicsView {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ColorPickerScene(QPixmap pixmap, QWidget *parentWidget);
|
ColorPickerScene(QPixmap pixmap, QWidget *parentWidget);
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
@ -24,7 +24,7 @@ CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) {
|
|||||||
QPoint p = screenshotutil::smallestScreenCoordinate()
|
QPoint p = screenshotutil::smallestScreenCoordinate()
|
||||||
+ QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt());
|
+ QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt());
|
||||||
view->move(p.x(), p.y());
|
view->move(p.x(), p.y());
|
||||||
view->setWindowTitle("KShare Crop Editor");
|
view->setWindowTitle(tr("KShare Crop Editor"));
|
||||||
view->activateWindow();
|
view->activateWindow();
|
||||||
|
|
||||||
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
|
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
|
||||||
|
@ -35,18 +35,18 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap)
|
|||||||
static_cast<Qt::BrushStyle>(settings::settings().value("brushStyle", static_cast<int>(Qt::SolidPattern)).toInt()));
|
static_cast<Qt::BrushStyle>(settings::settings().value("brushStyle", static_cast<int>(Qt::SolidPattern)).toInt()));
|
||||||
|
|
||||||
menu = new QMenuBar;
|
menu = new QMenuBar;
|
||||||
addDrawingAction(menu, "Free draw", ":/icons/pencil.png", [] { return new PathItem; });
|
addDrawingAction(menu, tr("Free draw"), ":/icons/pencil.png", [] { return new PathItem; });
|
||||||
addDrawingAction(menu, "Blur", ":/icons/blur.png", [] { return new BlurItem; });
|
addDrawingAction(menu, tr("Blur"), ":/icons/blur.png", [] { return new BlurItem; });
|
||||||
addDrawingAction(menu, "Straight line", ":/icons/line.png", [] { return new LineItem; });
|
addDrawingAction(menu, tr("Straight line"), ":/icons/line.png", [] { return new LineItem; });
|
||||||
addDrawingAction(menu, "Text", ":/icons/text.png", [] { return new TextItem; });
|
addDrawingAction(menu, tr("Text"), ":/icons/text.png", [] { return new TextItem; });
|
||||||
addDrawingAction(menu, "Rectangle", ":/icons/rectangle.png", [] { return new RectItem; });
|
addDrawingAction(menu, tr("Rectangle"), ":/icons/rectangle.png", [] { return new RectItem; });
|
||||||
addDrawingAction(menu, "Ellipse", ":/icons/circle.png", [] { return new EllipseItem; });
|
addDrawingAction(menu, tr("Ellipse"), ":/icons/circle.png", [] { return new EllipseItem; });
|
||||||
addDrawingAction(menu, "Arrow", ":/icons/arrow.png", [] { return new ArrowItem; });
|
addDrawingAction(menu, tr("Arrow"), ":/icons/arrow.png", [] { return new ArrowItem; });
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
addDrawingAction(menu, "Eraser", ":/icons/erase.png", [] { return new EraserItem; });
|
addDrawingAction(menu, tr("Eraser"), ":/icons/erase.png", [] { return new EraserItem; });
|
||||||
QAction *clear = menu->addAction("");
|
QAction *clear = menu->addAction("");
|
||||||
clear->setToolTip("Clear all drawing");
|
clear->setToolTip(tr("Clear all drawing"));
|
||||||
clear->setIcon(QIcon(":/icons/delete.png"));
|
clear->setIcon(QIcon(":/icons/delete.png"));
|
||||||
connect(clear, &QAction::triggered, [&] {
|
connect(clear, &QAction::triggered, [&] {
|
||||||
auto its = items();
|
auto its = items();
|
||||||
@ -60,11 +60,11 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addDrawingAction(menu, "Crop", ":/icons/crop.png", [] { return nullptr; });
|
addDrawingAction(menu, tr("Crop"), ":/icons/crop.png", [] { return nullptr; });
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
QAction *settings = menu->addAction("");
|
QAction *settings = menu->addAction("");
|
||||||
settings->setToolTip("Settings");
|
settings->setToolTip(tr("Settings"));
|
||||||
settings->setIcon(QIcon(":/icons/settings.png"));
|
settings->setIcon(QIcon(":/icons/settings.png"));
|
||||||
connect(settings, &QAction::triggered, [&] {
|
connect(settings, &QAction::triggered, [&] {
|
||||||
hide();
|
hide();
|
||||||
@ -82,13 +82,13 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap)
|
|||||||
menu->addAction(fonts);
|
menu->addAction(fonts);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
QAction *confirm = menu->addAction("");
|
QAction *confirm = menu->addAction("");
|
||||||
confirm->setToolTip("Confirm");
|
confirm->setToolTip(tr("Confirm"));
|
||||||
confirm->setIcon(QIcon(":/icons/accept.png"));
|
confirm->setIcon(QIcon(":/icons/accept.png"));
|
||||||
connect(confirm, &QAction::triggered, [this] { done(true); });
|
connect(confirm, &QAction::triggered, [this] { done(true); });
|
||||||
menu->addAction(confirm);
|
menu->addAction(confirm);
|
||||||
|
|
||||||
QAction *cancel = menu->addAction("");
|
QAction *cancel = menu->addAction("");
|
||||||
cancel->setToolTip("Cancel");
|
cancel->setToolTip(tr("Cancel"));
|
||||||
cancel->setIcon(QIcon(":/icons/cancel.png"));
|
cancel->setIcon(QIcon(":/icons/cancel.png"));
|
||||||
connect(cancel, &QAction::triggered, [this] { done(false); });
|
connect(cancel, &QAction::triggered, [this] { done(false); });
|
||||||
menu->addAction(cancel);
|
menu->addAction(cancel);
|
||||||
@ -207,7 +207,7 @@ void CropScene::setVisible(bool visible) {
|
|||||||
QPoint p = screenshotutil::smallestScreenCoordinate() + QPoint(settings::settings().value("cropx", 0).toInt(),
|
QPoint p = screenshotutil::smallestScreenCoordinate() + QPoint(settings::settings().value("cropx", 0).toInt(),
|
||||||
settings::settings().value("cropy", 0).toInt());
|
settings::settings().value("cropy", 0).toInt());
|
||||||
view->move(p.x(), p.y());
|
view->move(p.x(), p.y());
|
||||||
view->setWindowTitle("KShare Crop Editor");
|
view->setWindowTitle(tr("KShare Crop Editor"));
|
||||||
view->activateWindow();
|
view->activateWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
bool TextItem::init(CropScene *s) {
|
bool TextItem::init(CropScene *s) {
|
||||||
bool ok;
|
bool ok;
|
||||||
s->hide();
|
s->hide();
|
||||||
text = QInputDialog::getText(nullptr, "Text to add", "Input", QLineEdit::Normal, QString(), &ok);
|
text = QInputDialog::getText(nullptr, tr("Text to add"), tr("Input"), QLineEdit::Normal, QString(), &ok);
|
||||||
s->show();
|
s->show();
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
#define TEXTITEM_HPP
|
#define TEXTITEM_HPP
|
||||||
|
|
||||||
#include "drawitem.hpp"
|
#include "drawitem.hpp"
|
||||||
|
#include <QApplication>
|
||||||
#include <QGraphicsSimpleTextItem>
|
#include <QGraphicsSimpleTextItem>
|
||||||
|
|
||||||
class TextItem : public DrawItem {
|
class TextItem : public DrawItem {
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(TextItem)
|
||||||
public:
|
public:
|
||||||
QString name() override;
|
QString name() override;
|
||||||
bool init(CropScene *s) override;
|
bool init(CropScene *s) override;
|
||||||
|
@ -37,7 +37,7 @@ BrushPenSelection::BrushPenSelection(CropScene *scene) : QDialog(), ui(new Ui::B
|
|||||||
ui->alphaSlider->setValue(brush.alpha());
|
ui->alphaSlider->setValue(brush.alpha());
|
||||||
ui->alphaSpin->setValue(brush.alpha());
|
ui->alphaSpin->setValue(brush.alpha());
|
||||||
|
|
||||||
setWindowTitle("Crop editor settings");
|
setWindowTitle(tr("Crop editor settings"));
|
||||||
this->scene = scene;
|
this->scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,12 +46,12 @@ BrushPenSelection::~BrushPenSelection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BrushPenSelection::on_penColor_clicked(bool) {
|
void BrushPenSelection::on_penColor_clicked(bool) {
|
||||||
pen = QColorDialog::getColor(pen, this, "Pen Color");
|
pen = QColorDialog::getColor(pen, this, tr("Pen Color"));
|
||||||
pen.setAlpha(ui->penAlphaSpin->value());
|
pen.setAlpha(ui->penAlphaSpin->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrushPenSelection::on_brushColor_clicked(bool) {
|
void BrushPenSelection::on_brushColor_clicked(bool) {
|
||||||
brush = QColorDialog::getColor(brush, this, "Brush Color");
|
brush = QColorDialog::getColor(brush, this, tr("Brush Color"));
|
||||||
brush.setAlpha(ui->alphaSpin->value());
|
brush.setAlpha(ui->alphaSpin->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
formats.cpp
14
formats.cpp
@ -4,13 +4,10 @@ QString formats::normalFormatName(formats::Normal format) {
|
|||||||
switch (format) {
|
switch (format) {
|
||||||
case Normal::JPG:
|
case Normal::JPG:
|
||||||
return "JPG";
|
return "JPG";
|
||||||
break;
|
|
||||||
case Normal::PNG:
|
case Normal::PNG:
|
||||||
return "PNG";
|
return "PNG";
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return QString();
|
return QString();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,13 +22,10 @@ QString formats::normalFormatMIME(formats::Normal format) {
|
|||||||
switch (format) {
|
switch (format) {
|
||||||
case Normal::JPG:
|
case Normal::JPG:
|
||||||
return "image/jpeg";
|
return "image/jpeg";
|
||||||
break;
|
|
||||||
case Normal::PNG:
|
case Normal::PNG:
|
||||||
return "image/png";
|
return "image/png";
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return QString();
|
return QString();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,16 +33,12 @@ QString formats::recordingFormatName(formats::Recording format) {
|
|||||||
switch (format) {
|
switch (format) {
|
||||||
case Recording::GIF:
|
case Recording::GIF:
|
||||||
return "GIF";
|
return "GIF";
|
||||||
break;
|
|
||||||
case Recording::WebM:
|
case Recording::WebM:
|
||||||
return "WEBM";
|
return "WEBM";
|
||||||
break;
|
|
||||||
case Recording::MP4:
|
case Recording::MP4:
|
||||||
return "MP4";
|
return "MP4";
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return QString();
|
return QString();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,15 +53,11 @@ QString formats::recordingFormatMIME(formats::Recording format) {
|
|||||||
switch (format) {
|
switch (format) {
|
||||||
case Recording::GIF:
|
case Recording::GIF:
|
||||||
return "image/gif";
|
return "image/gif";
|
||||||
break;
|
|
||||||
case Recording::WebM:
|
case Recording::WebM:
|
||||||
return "video/webm";
|
return "video/webm";
|
||||||
break;
|
|
||||||
case Recording::MP4:
|
case Recording::MP4:
|
||||||
return "video/mp4";
|
return "video/mp4";
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return QString();
|
return QString();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ void hotkeying::hotkey(QString seqName, QKeySequence seq, std::function<void()>
|
|||||||
settings::settings().setValue(seqName.prepend("hotkey_"), seq.toString());
|
settings::settings().setValue(seqName.prepend("hotkey_"), seq.toString());
|
||||||
if (!hotkey->isRegistered() && !seq.toString().isEmpty())
|
if (!hotkey->isRegistered() && !seq.toString().isEmpty())
|
||||||
qWarning().noquote().nospace()
|
qWarning().noquote().nospace()
|
||||||
<< "Could not bind the hotkey " << seqName << "! Is the keybind already registered?";
|
<< QObject::tr("Could not bind the hotkey %1! Is the keybind already registered?").arg(seqName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// forces the hotkey from settings
|
// forces the hotkey from settings
|
||||||
@ -37,7 +37,8 @@ void hotkeying::load(QString seqName, std::function<void()> func, QString def) {
|
|||||||
hotkeys.insert(seqName, h);
|
hotkeys.insert(seqName, h);
|
||||||
if (!h->isRegistered() && !h->shortcut().toString().isEmpty())
|
if (!h->isRegistered() && !h->shortcut().toString().isEmpty())
|
||||||
qWarning().noquote().nospace()
|
qWarning().noquote().nospace()
|
||||||
<< "Could not bind the hotkey " << seqName << "! Is the keybind already registered?";
|
<< QObject::tr("Could not bind the hotkey %1! Is the keybind already registered?").arg(seqName);
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hotkeying::valid(QString seq) {
|
bool hotkeying::valid(QString seq) {
|
||||||
|
@ -28,11 +28,11 @@ void HotkeyInputDialog::keyPressEvent(QKeyEvent *e) {
|
|||||||
QKeySequence seq(e->modifiers() + e->key());
|
QKeySequence seq(e->modifiers() + e->key());
|
||||||
ui->keySeq->setText(seq.toString());
|
ui->keySeq->setText(seq.toString());
|
||||||
recording = false;
|
recording = false;
|
||||||
ui->recordButton->setText("Record");
|
ui->recordButton->setText(tr("Record"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HotkeyInputDialog::on_recordButton_clicked() {
|
void HotkeyInputDialog::on_recordButton_clicked() {
|
||||||
recording = !recording;
|
recording = !recording;
|
||||||
ui->recordButton->setText(recording ? "Stop recording" : "Record");
|
ui->recordButton->setText(recording ? tr("Stop recording") : tr("Record"));
|
||||||
}
|
}
|
||||||
|
17
main.cpp
17
main.cpp
@ -13,6 +13,7 @@ extern "C" {
|
|||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
}
|
}
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
|
#include <QTranslator>
|
||||||
#include <notifications.hpp>
|
#include <notifications.hpp>
|
||||||
#include <platformbackend.hpp>
|
#include <platformbackend.hpp>
|
||||||
#include <worker/worker.hpp>
|
#include <worker/worker.hpp>
|
||||||
@ -59,6 +60,19 @@ void handler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loadTranslation(QString locale) {
|
||||||
|
QFile resource(":/langs/kshare_" + locale + ".qm");
|
||||||
|
if (!resource.exists()) return;
|
||||||
|
resource.open(QIODevice::ReadOnly);
|
||||||
|
|
||||||
|
QTranslator *translator = new QTranslator;
|
||||||
|
QByteArray file = resource.readAll();
|
||||||
|
QByteArray *permFile = new QByteArray;
|
||||||
|
permFile->swap(file);
|
||||||
|
translator->load((const unsigned char *)permFile->constData(), permFile->size());
|
||||||
|
QApplication::installTranslator(translator);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
av_register_all();
|
av_register_all();
|
||||||
qInstallMessageHandler(handler);
|
qInstallMessageHandler(handler);
|
||||||
@ -68,6 +82,9 @@ int main(int argc, char *argv[]) {
|
|||||||
a.setOrganizationName("ArsenArsen");
|
a.setOrganizationName("ArsenArsen");
|
||||||
a.setApplicationVersion("4.1");
|
a.setApplicationVersion("4.1");
|
||||||
|
|
||||||
|
QString locale = QLocale::system().name();
|
||||||
|
if (locale != "en_US") loadTranslation(locale);
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
|
|
||||||
|
@ -19,10 +19,10 @@ MainWindow *MainWindow::instance;
|
|||||||
|
|
||||||
void MainWindow::rec() {
|
void MainWindow::rec() {
|
||||||
if (controller->isRunning()) return;
|
if (controller->isRunning()) return;
|
||||||
auto f
|
auto f = static_cast<formats::Recording>(
|
||||||
= static_cast<formats::Recording>(settings::settings().value("recording/format", (int)formats::Recording::None).toInt());
|
settings::settings().value("recording/format", static_cast<int>(formats::Recording::None)).toInt());
|
||||||
if (f >= formats::Recording::None) {
|
if (f >= formats::Recording::None) {
|
||||||
qWarning() << "Recording format not set in settings. Aborting.";
|
qWarning() << tr("Recording format not set in settings. Aborting.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RecordingContext *ctx = new RecordingContext;
|
RecordingContext *ctx = new RecordingContext;
|
||||||
@ -36,6 +36,22 @@ void MainWindow::rec() {
|
|||||||
controller->start(ctx);
|
controller->start(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ACTION(english, menu) \
|
||||||
|
[&]() -> QAction * { \
|
||||||
|
QAction *a = menu->addAction(tr(english)); \
|
||||||
|
acts.insert(a, english); \
|
||||||
|
return a; \
|
||||||
|
}()
|
||||||
|
|
||||||
|
void MainWindow::changeEvent(QEvent *e) {
|
||||||
|
if (e->type() == QEvent::LocaleChange) {
|
||||||
|
ui->retranslateUi(this);
|
||||||
|
for (auto key : acts.keys()) {
|
||||||
|
key->setText(tr(acts.value(key)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void addHotkey(QString name, std::function<void()> action) {
|
void addHotkey(QString name, std::function<void()> action) {
|
||||||
hotkeying::load(name, action);
|
hotkeying::load(name, action);
|
||||||
}
|
}
|
||||||
@ -48,19 +64,19 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
tray->setToolTip("KShare");
|
tray->setToolTip("KShare");
|
||||||
tray->setVisible(true);
|
tray->setVisible(true);
|
||||||
QMenu *menu = new QMenu(this);
|
QMenu *menu = new QMenu(this);
|
||||||
QAction *quit = new QAction("Quit", this);
|
QAction *quit = ACTION("Quit", menu);
|
||||||
QAction *shtoggle = new QAction("Show/Hide", this);
|
QAction *shtoggle = ACTION("Show/Hide", menu);
|
||||||
QAction *fullscreen = new QAction("Take fullscreen shot", this);
|
QAction *fullscreen = ACTION("Take fullscreen shot", menu);
|
||||||
QAction *area = new QAction("Take area shot", this);
|
QAction *area = ACTION("Take area shot", menu);
|
||||||
|
|
||||||
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
|
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
|
||||||
QAction *active = new QAction("Screenshot active window", this);
|
QAction *active = ACTION("Screenshot active window", menu);
|
||||||
connect(active, &QAction::triggered, this, [] { screenshotter::activeDelayed(); });
|
connect(active, &QAction::triggered, this, [] { screenshotter::activeDelayed(); });
|
||||||
#endif
|
#endif
|
||||||
QAction *picker = new QAction("Show color picker", this);
|
QAction *picker = ACTION("Show color picker", menu);
|
||||||
QAction *rec = new QAction("Record screen", this);
|
QAction *rec = ACTION("Record screen", menu);
|
||||||
QAction *recoff = new QAction("Stop recording", this);
|
QAction *recoff = ACTION("Stop recording", menu);
|
||||||
QAction *recabort = new QAction("Abort recording", this);
|
QAction *recabort = ACTION("Abort recording", menu);
|
||||||
menu->addActions({ quit, shtoggle, picker });
|
menu->addActions({ quit, shtoggle, picker });
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
menu->addActions({ fullscreen, area });
|
menu->addActions({ fullscreen, area });
|
||||||
|
@ -45,10 +45,12 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool val = false;
|
bool val = false;
|
||||||
|
QMap<QAction *, const char *> acts;
|
||||||
static MainWindow *instance;
|
static MainWindow *instance;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void changeEvent(QEvent *e) override;
|
||||||
|
void closeEvent(QCloseEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_HPP
|
#endif // MAINWINDOW_HPP
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
EncoderSettingsDialog::EncoderSettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::EncoderSettingsDialog) {
|
EncoderSettingsDialog::EncoderSettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::EncoderSettingsDialog) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setWindowTitle("KShare Encoder Settings");
|
setWindowTitle(tr("KShare Encoder Settings"));
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, [&] {
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, [&] {
|
||||||
EncoderSettings::inst().setbitrate(ui->bitrate->value());
|
EncoderSettings::inst().setbitrate(ui->bitrate->value());
|
||||||
EncoderSettings::inst().seth264Crf(ui->crf->value());
|
EncoderSettings::inst().seth264Crf(ui->crf->value());
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
RecordingFormats::RecordingFormats(formats::Recording f) {
|
RecordingFormats::RecordingFormats(formats::Recording f) {
|
||||||
if (!tmpDir.isValid()) {
|
if (!tmpDir.isValid()) {
|
||||||
validator = [](QSize) { return false; };
|
validator = [](QSize) { return false; };
|
||||||
qCritical().noquote() << "Could not create temporary directory. Error: " + tmpDir.errorString();
|
qCritical().noquote() << tr("Could not create temporary directory. Error: ") + tmpDir.errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
iFormat = QImage::Format_RGB888;
|
iFormat = QImage::Format_RGB888;
|
||||||
@ -39,7 +39,7 @@ RecordingFormats::RecordingFormats(formats::Recording f) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (std::runtime_error &e) {
|
} catch (std::runtime_error &e) {
|
||||||
qCritical() << "Encoder error: " << e.what();
|
qCritical() << tr("Encoder error: ") << e.what();
|
||||||
interrupt = true;
|
interrupt = true;
|
||||||
delete enc;
|
delete enc;
|
||||||
return false;
|
return false;
|
||||||
@ -52,7 +52,7 @@ RecordingFormats::RecordingFormats(formats::Recording f) {
|
|||||||
frameAdded = true;
|
frameAdded = true;
|
||||||
enc->addFrame(img);
|
enc->addFrame(img);
|
||||||
} catch (std::runtime_error &e) {
|
} catch (std::runtime_error &e) {
|
||||||
qCritical() << "Encoder error: " << e.what();
|
qCritical() << tr("Encoder error: ") << e.what();
|
||||||
interrupt = true;
|
interrupt = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef RECORDINGFORMATS_HPP
|
#ifndef RECORDINGFORMATS_HPP
|
||||||
#define RECORDINGFORMATS_HPP
|
#define RECORDINGFORMATS_HPP
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
@ -12,6 +13,7 @@
|
|||||||
#include <recording/encoders/encoder.hpp>
|
#include <recording/encoders/encoder.hpp>
|
||||||
|
|
||||||
class RecordingFormats {
|
class RecordingFormats {
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(RecordingFormats)
|
||||||
public:
|
public:
|
||||||
RecordingFormats(formats::Recording f);
|
RecordingFormats(formats::Recording f);
|
||||||
std::function<void(QImage)> getConsumer();
|
std::function<void(QImage)> getConsumer();
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <hotkeying.hpp>
|
#include <hotkeying.hpp>
|
||||||
|
|
||||||
QSize max(300, 300);
|
static QSize max(300, 300);
|
||||||
|
|
||||||
inline bool sizeGreater(QSize one, QSize two) {
|
inline bool sizeGreater(QSize one, QSize two) {
|
||||||
return one.height() > two.height() || one.width() > two.width();
|
return one.height() > two.height() || one.width() > two.width();
|
||||||
@ -44,7 +44,7 @@ RecordingPreview::RecordingPreview(QRect area, QWidget *parent) : QWidget(parent
|
|||||||
label->setPixmap(empty);
|
label->setPixmap(empty);
|
||||||
layout()->addWidget(hintLabel);
|
layout()->addWidget(hintLabel);
|
||||||
layout()->addWidget(label);
|
layout()->addWidget(label);
|
||||||
hintLabel->setText(QString("Time: 00:00\nFrame: 0\nStop key: ") + hotkeying::sequence("recordingstop"));
|
hintLabel->setText(QString(tr("Time: 00:00\nFrame: 0\nStop key: ")) + hotkeying::sequence("recordingstop"));
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordingPreview::~RecordingPreview() {
|
RecordingPreview::~RecordingPreview() {
|
||||||
@ -58,6 +58,6 @@ void RecordingPreview::setPixmap(QPixmap map) {
|
|||||||
}
|
}
|
||||||
void RecordingPreview::setTime(QString time, int frame) {
|
void RecordingPreview::setTime(QString time, int frame) {
|
||||||
if (isVisible())
|
if (isVisible())
|
||||||
hintLabel->setText(QString("Time: ") + time + "\nFrame: " + QString::number(frame)
|
hintLabel->setText(
|
||||||
+ "\nStop key: " + hotkeying::sequence("recordingstop"));
|
tr("Time: %1\nFrame: %2\nStop key: %3").arg(time).arg(frame).arg(hotkeying::sequence("recordingstop")));
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,14 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
|
|
||||||
static QString hintPattern("Set the recording region by resizing this.\n%1x%2");
|
static QString hintPattern(ScreenAreaSelector::tr("Set the recording region by resizing this.\n%1x%2"));
|
||||||
|
|
||||||
ScreenAreaSelector::ScreenAreaSelector() {
|
ScreenAreaSelector::ScreenAreaSelector() {
|
||||||
setAttribute(Qt::WA_TranslucentBackground);
|
setAttribute(Qt::WA_TranslucentBackground);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
|
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
|
||||||
setStyleSheet("background-color: rgba(0, 0, 0, 0.5);");
|
setStyleSheet("background-color: rgba(0, 0, 0, 0.5);");
|
||||||
setWindowTitle("KShare: Select Area (By resizing this window)");
|
setWindowTitle(tr("KShare: Select Area (By resizing this window)"));
|
||||||
setAutoFillBackground(true);
|
setAutoFillBackground(true);
|
||||||
QTimer::singleShot(0, [&] {
|
QTimer::singleShot(0, [&] {
|
||||||
QVariant val = settings::settings().value("screenareaselector/rect");
|
QVariant val = settings::settings().value("screenareaselector/rect");
|
||||||
|
@ -13,7 +13,7 @@ QDir settings::dir() {
|
|||||||
if (configDir.dirName() != "KShare") {
|
if (configDir.dirName() != "KShare") {
|
||||||
if (!configDir.cd("KShare")) {
|
if (!configDir.cd("KShare")) {
|
||||||
if (!configDir.mkdir("KShare")) {
|
if (!configDir.mkdir("KShare")) {
|
||||||
qFatal("Could not make config directory");
|
qFatal("%s", QObject::tr("Could not make config directory").toLocal8Bit().constData());
|
||||||
} else {
|
} else {
|
||||||
configDir.cd("KShare");
|
configDir.cd("KShare");
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
#include <uploaders/uploadersingleton.hpp>
|
#include <uploaders/uploadersingleton.hpp>
|
||||||
|
|
||||||
QMap<QString, std::function<void()>> fncs;
|
static QMap<QString, std::function<void()>> fncs;
|
||||||
|
|
||||||
void addHotkeyItem(QListWidget *hotkeys, QString text, QString name, std::function<void()> func, QString def = QString()) {
|
void addHotkeyItem(QListWidget *hotkeys, QString text, QString name, std::function<void()> func, QString def = QString()) {
|
||||||
QListWidgetItem *item = new QListWidgetItem(text, hotkeys);
|
QListWidgetItem *item = new QListWidgetItem(text, hotkeys);
|
||||||
@ -52,14 +52,14 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se
|
|||||||
|
|
||||||
ui->hotkeys->setSelectionMode(QListWidget::SingleSelection);
|
ui->hotkeys->setSelectionMode(QListWidget::SingleSelection);
|
||||||
|
|
||||||
addHotkeyItem(ui->hotkeys, "Fullscreen image", "fullscreen", [] { screenshotter::fullscreen(); });
|
addHotkeyItem(ui->hotkeys, tr("Fullscreen image"), "fullscreen", [] { screenshotter::fullscreen(); });
|
||||||
addHotkeyItem(ui->hotkeys, "Area image", "area", [] { screenshotter::area(); });
|
addHotkeyItem(ui->hotkeys, tr("Area image"), "area", [] { screenshotter::area(); });
|
||||||
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
|
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
|
||||||
addHotkeyItem(ui->hotkeys, "Active window", "active", [&] { screenshotter::active(); });
|
addHotkeyItem(ui->hotkeys, tr("Active window"), "active", [&] { screenshotter::active(); });
|
||||||
#endif
|
#endif
|
||||||
addHotkeyItem(ui->hotkeys, "Color picker", "picker", [] { ColorPickerScene::showPicker(); });
|
addHotkeyItem(ui->hotkeys, tr("Color picker"), "picker", [] { ColorPickerScene::showPicker(); });
|
||||||
addHotkeyItem(ui->hotkeys, "Stop Recording", "recordingstop", [&] { MainWindow::inst()->controller->end(); });
|
addHotkeyItem(ui->hotkeys, tr("Stop Recording"), "recordingstop", [&] { MainWindow::inst()->controller->end(); });
|
||||||
addHotkeyItem(ui->hotkeys, "Start Recording", "recordingstart", [&] { MainWindow::inst()->rec(); });
|
addHotkeyItem(ui->hotkeys, tr("Start Recording"), "recordingstart", [&] { MainWindow::inst()->rec(); });
|
||||||
|
|
||||||
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
|
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
|
||||||
ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool());
|
ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool());
|
||||||
@ -81,7 +81,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se
|
|||||||
ui->nameScheme->setValidator(new FilenameValidator(ui->nameScheme));
|
ui->nameScheme->setValidator(new FilenameValidator(ui->nameScheme));
|
||||||
#ifndef PLATFORM_CAPABILITY_CURSOR
|
#ifndef PLATFORM_CAPABILITY_CURSOR
|
||||||
ui->captureCursor->setEnabled(false);
|
ui->captureCursor->setEnabled(false);
|
||||||
ui->captureCursor->setText("Capture cursor (disabled: implementation missing)");
|
ui->captureCursor->setText(tr("Capture cursor (disabled: implementation missing)"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ using formats::recordingFormatFromName;
|
|||||||
using formats::recordingFormatMIME;
|
using formats::recordingFormatMIME;
|
||||||
using std::runtime_error;
|
using std::runtime_error;
|
||||||
|
|
||||||
void error(QString absFilePath, QString err) {
|
[[noreturn]] void error(QString absFilePath, QString err) {
|
||||||
throw runtime_error((QString("Invalid file: ").append(absFilePath) + ": " + err).toStdString());
|
throw runtime_error((QObject::tr("Invalid file: ").append(absFilePath) + ": " + err).toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomUploader::CustomUploader(QString absFilePath) {
|
CustomUploader::CustomUploader(QString absFilePath) {
|
||||||
@ -28,16 +28,16 @@ CustomUploader::CustomUploader(QString absFilePath) {
|
|||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) error(absFilePath, file.errorString());
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) error(absFilePath, file.errorString());
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
|
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
|
||||||
if (!doc.isObject()) {
|
if (!doc.isObject()) {
|
||||||
error(absFilePath, "Root not an object");
|
error(absFilePath, tr("Root not an object"));
|
||||||
}
|
}
|
||||||
QJsonObject obj = doc.object();
|
QJsonObject obj = doc.object();
|
||||||
if (!obj["name"].isString())
|
if (!obj["name"].isString())
|
||||||
error(absFilePath, "name is not a string");
|
error(absFilePath, tr("name is not a string"));
|
||||||
else
|
else
|
||||||
uName = obj["name"].toString();
|
uName = obj["name"].toString();
|
||||||
if (obj.contains("desc")) {
|
if (obj.contains("desc")) {
|
||||||
if (!obj["desc"].isString())
|
if (!obj["desc"].isString())
|
||||||
/*t*/ error(absFilePath, "desc not a string");
|
/*t*/ error(absFilePath, tr("desc not a string"));
|
||||||
else
|
else
|
||||||
|
|
||||||
desc = obj["desc"].toString();
|
desc = obj["desc"].toString();
|
||||||
@ -45,19 +45,19 @@ CustomUploader::CustomUploader(QString absFilePath) {
|
|||||||
desc = absFilePath;
|
desc = absFilePath;
|
||||||
QJsonValue m = obj["method"];
|
QJsonValue m = obj["method"];
|
||||||
if (!m.isUndefined() && !m.isNull()) {
|
if (!m.isUndefined() && !m.isNull()) {
|
||||||
if (!m.isString()) error(absFilePath, "method not a string");
|
if (!m.isString()) error(absFilePath, tr("method not a string"));
|
||||||
QString toCheck = m.toString().toLower();
|
QString toCheck = m.toString().toLower();
|
||||||
if (toCheck == "post")
|
if (toCheck == "post")
|
||||||
method = HttpMethod::POST;
|
method = HttpMethod::POST;
|
||||||
else
|
else
|
||||||
error(absFilePath, "method invalid");
|
error(absFilePath, tr("method invalid"));
|
||||||
}
|
}
|
||||||
QJsonValue url = obj["target"];
|
QJsonValue url = obj["target"];
|
||||||
if (!url.isString()) {
|
if (!url.isString()) {
|
||||||
error(absFilePath, "target missing");
|
error(absFilePath, tr("target missing"));
|
||||||
}
|
}
|
||||||
QUrl target(url.toString());
|
QUrl target(url.toString());
|
||||||
if (!target.isValid()) error(absFilePath, "target not URL");
|
if (!target.isValid()) error(absFilePath, tr("target not URL"));
|
||||||
this->target = target;
|
this->target = target;
|
||||||
QJsonValue formatValue = obj["format"];
|
QJsonValue formatValue = obj["format"];
|
||||||
if (!formatValue.isUndefined() && !formatValue.isNull()) {
|
if (!formatValue.isUndefined() && !formatValue.isNull()) {
|
||||||
@ -72,45 +72,47 @@ CustomUploader::CustomUploader(QString absFilePath) {
|
|||||||
else if (formatString == "multipart-form-data")
|
else if (formatString == "multipart-form-data")
|
||||||
rFormat = RequestFormat::MULTIPART_FORM_DATA;
|
rFormat = RequestFormat::MULTIPART_FORM_DATA;
|
||||||
else
|
else
|
||||||
error(absFilePath, "format invalid");
|
error(absFilePath, tr("format invalid"));
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
error(absFilePath, "format provided but not string");
|
error(absFilePath, tr("format provided but not string"));
|
||||||
QJsonValue bodyValue = obj["body"];
|
QJsonValue bodyValue = obj["body"];
|
||||||
if (rFormat != RequestFormat::PLAIN) {
|
if (rFormat != RequestFormat::PLAIN) {
|
||||||
if (bodyValue.isUndefined()) error(absFilePath, "body not set");
|
if (bodyValue.isUndefined()) error(absFilePath, tr("body not set"));
|
||||||
if (rFormat == RequestFormat::MULTIPART_FORM_DATA) {
|
if (rFormat == RequestFormat::MULTIPART_FORM_DATA) {
|
||||||
if (bodyValue.isArray()) {
|
if (bodyValue.isArray()) {
|
||||||
for (QJsonValue val : bodyValue.toArray()) {
|
for (QJsonValue val : bodyValue.toArray()) {
|
||||||
if (!val.isObject()) error(absFilePath, "all elements of body must be objects");
|
if (!val.isObject()) error(absFilePath, tr("all elements of body must be objects"));
|
||||||
if (!val.toObject()["body"].isObject() && !val.toObject().value("body").isString())
|
if (!val.toObject()["body"].isObject() && !val.toObject().value("body").isString())
|
||||||
error(absFilePath, "all parts must have a body which is object or string!");
|
error(absFilePath, tr("all parts must have a body which is object or string!"));
|
||||||
QJsonObject vo = val.toObject();
|
QJsonObject vo = val.toObject();
|
||||||
for (auto v : vo["body"].toObject())
|
for (auto v : vo["body"].toObject())
|
||||||
if (!v.isObject() && !v.isString())
|
if (!v.isObject() && !v.isString())
|
||||||
error(absFilePath, "all parts of body must be string or object");
|
error(absFilePath, tr("all parts of body must be string or object"));
|
||||||
for (auto v : vo.keys())
|
for (auto v : vo.keys())
|
||||||
if (v.startsWith("__") && !vo[v].isString())
|
if (v.startsWith("__") && !vo[v].isString())
|
||||||
error(absFilePath, "all __headers must be strings");
|
//: __<whatever is the word for header>
|
||||||
|
error(absFilePath, tr("all __headers must be strings"));
|
||||||
}
|
}
|
||||||
body = bodyValue;
|
body = bodyValue;
|
||||||
} else
|
} else
|
||||||
error(absFilePath, "body not array (needed for multipart)");
|
error(absFilePath, tr("body not array (needed for multipart)"));
|
||||||
} else {
|
} else {
|
||||||
if (bodyValue.isObject())
|
if (bodyValue.isObject())
|
||||||
body = bodyValue;
|
body = bodyValue;
|
||||||
else
|
else
|
||||||
error(absFilePath, "body not object");
|
error(absFilePath, tr("body not object"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (bodyValue.isString()) {
|
if (bodyValue.isString()) {
|
||||||
body = bodyValue;
|
body = bodyValue;
|
||||||
} else
|
} else
|
||||||
error(absFilePath, "body not string (reason: format: PLAIN)");
|
//: `format: PLAIN` should stay the same
|
||||||
|
error(absFilePath, tr("body not string (reason: format: PLAIN)"));
|
||||||
}
|
}
|
||||||
QJsonValue headerVal = obj["headers"];
|
QJsonValue headerVal = obj["headers"];
|
||||||
if (!(headerVal.isUndefined() || headerVal.isNull())) {
|
if (!(headerVal.isUndefined() || headerVal.isNull())) {
|
||||||
if (!headerVal.isObject()) error(absFilePath, "headers must be object");
|
if (!headerVal.isObject()) error(absFilePath, tr("headers must be object"));
|
||||||
headers = headerVal.toObject();
|
headers = headerVal.toObject();
|
||||||
} else
|
} else
|
||||||
headers = QJsonObject();
|
headers = QJsonObject();
|
||||||
@ -118,17 +120,18 @@ CustomUploader::CustomUploader(QString absFilePath) {
|
|||||||
if (returnPsVal.isString()) {
|
if (returnPsVal.isString()) {
|
||||||
returnPathspec = returnPsVal.toString();
|
returnPathspec = returnPsVal.toString();
|
||||||
} else
|
} else
|
||||||
error(absFilePath, "return invalid");
|
error(absFilePath, tr("return invalid"));
|
||||||
QJsonValue fileLimit = obj["fileLimit"];
|
QJsonValue fileLimit = obj["fileLimit"];
|
||||||
if (!fileLimit.isNull() && !fileLimit.isUndefined()) {
|
if (!fileLimit.isNull() && !fileLimit.isUndefined()) {
|
||||||
if (!fileLimit.isDouble()) error(absFilePath, "fileLimit not double");
|
//: fileLimit stays English
|
||||||
|
if (!fileLimit.isDouble()) error(absFilePath, tr("fileLimit not decimal"));
|
||||||
limit = fileLimit.toDouble();
|
limit = fileLimit.toDouble();
|
||||||
}
|
}
|
||||||
QJsonValue bool64 = obj["base64"];
|
QJsonValue bool64 = obj["base64"];
|
||||||
if (!bool64.isNull() && !bool64.isUndefined()) {
|
if (!bool64.isNull() && !bool64.isUndefined()) {
|
||||||
if (!bool64.isBool()) error(absFilePath, "base64 must be boolean");
|
if (!bool64.isBool()) error(absFilePath, tr("base64 must be boolean"));
|
||||||
base64 = bool64.toBool();
|
base64 = bool64.toBool();
|
||||||
if (rFormat == RequestFormat::JSON && !base64) error(absFilePath, "base64 required with json");
|
if (rFormat == RequestFormat::JSON && !base64) error(absFilePath, tr("base64 required with json"));
|
||||||
}
|
}
|
||||||
urlPrepend = obj["return_prepend"].toString();
|
urlPrepend = obj["return_prepend"].toString();
|
||||||
urlAppend = obj["return_append"].toString();
|
urlAppend = obj["return_append"].toString();
|
||||||
@ -204,19 +207,19 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseResult(QJsonDocument result, QByteArray data, QString returnPathspec, QString name, QString urlPrepend, QString urlAppend) {
|
void CustomUploader::parseResult(QJsonDocument result, QByteArray data, QString returnPathspec, QString name) {
|
||||||
if (result.isObject()) {
|
if (result.isObject()) {
|
||||||
QString url = urlPrepend + parsePathspec(result, returnPathspec) + urlAppend;
|
QString url = urlPrepend + parsePathspec(result, returnPathspec) + urlAppend;
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
QApplication::clipboard()->setText(url);
|
QApplication::clipboard()->setText(url);
|
||||||
notifications::notify("KShare Custom Uploader " + name, "Copied upload link to clipboard!");
|
notifications::notify(tr("KShare Custom Uploader ") + name, tr("Copied upload link to clipboard!"));
|
||||||
} else {
|
} else {
|
||||||
notifications::notify("KShare Custom Uploader " + name, "Upload done, but result empty!");
|
notifications::notify(tr("KShare Custom Uploader ") + name, tr("Upload done, but result empty!"));
|
||||||
QApplication::clipboard()->setText(data);
|
QApplication::clipboard()->setText(data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
notifications::notify("KShare Custom Uploader " + name,
|
notifications::notify(tr("KShare Custom Uploader ") + name,
|
||||||
"Upload done, but result is not JSON Object! Result in clipboard.");
|
tr("Upload done, but result is not JSON Object! Result in clipboard."));
|
||||||
QApplication::clipboard()->setText(data);
|
QApplication::clipboard()->setText(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -328,18 +331,20 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
switch (method) {
|
switch (method) {
|
||||||
case HttpMethod::POST:
|
case HttpMethod::POST:
|
||||||
if (returnPathspec == "|") {
|
if (returnPathspec == "|") {
|
||||||
ioutils::postMultipartData(target, h, multipart, [&, buffersToDelete, arraysToDelete](QByteArray result, QNetworkReply *) {
|
ioutils::postMultipartData(target, h, multipart,
|
||||||
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
[&, buffersToDelete, arraysToDelete](QByteArray result, QNetworkReply *) {
|
||||||
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
||||||
for (auto arr : arraysToDelete) delete arr;
|
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
||||||
notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
|
for (auto arr : arraysToDelete) delete arr;
|
||||||
});
|
notifications::notify(tr("KShare Custom Uploader ") + name(),
|
||||||
|
tr("Copied upload result to clipboard!"));
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
ioutils::postMultipart(target, h, multipart,
|
ioutils::postMultipart(target, h, multipart,
|
||||||
[&, buffersToDelete, arraysToDelete](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
[&, buffersToDelete, arraysToDelete](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
||||||
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
||||||
for (auto arr : arraysToDelete) delete arr;
|
for (auto arr : arraysToDelete) delete arr;
|
||||||
parseResult(result, data, returnPathspec, name(), urlPrepend, urlAppend);
|
parseResult(result, data, returnPathspec, name());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -348,7 +353,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (limit > 0 && data.size() > limit) {
|
if (limit > 0 && data.size() > limit) {
|
||||||
notifications::notify("KShare Custom Uploader " + name(), "File limit exceeded!");
|
notifications::notify(tr("KShare Custom Uploader ") + name(), tr("File limit exceeded!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (method) {
|
switch (method) {
|
||||||
@ -356,11 +361,11 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
if (returnPathspec == "|") {
|
if (returnPathspec == "|") {
|
||||||
ioutils::postData(target, h, data, [&](QByteArray result, QNetworkReply *) {
|
ioutils::postData(target, h, data, [&](QByteArray result, QNetworkReply *) {
|
||||||
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
||||||
notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
|
notifications::notify(tr("KShare Custom Uploader ") + name(), tr("Copied upload result to clipboard!"));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
||||||
parseResult(result, data, returnPathspec, name(), urlPrepend, urlAppend);
|
parseResult(result, data, returnPathspec, name());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define CUSTOMUPLOADER_HPP
|
#define CUSTOMUPLOADER_HPP
|
||||||
|
|
||||||
#include "uploader.hpp"
|
#include "uploader.hpp"
|
||||||
|
#include <QApplication>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
@ -11,6 +12,8 @@ enum class HttpMethod { POST };
|
|||||||
enum class RequestFormat { X_WWW_FORM_URLENCODED, JSON, MULTIPART_FORM_DATA, PLAIN };
|
enum class RequestFormat { X_WWW_FORM_URLENCODED, JSON, MULTIPART_FORM_DATA, PLAIN };
|
||||||
|
|
||||||
class CustomUploader : public Uploader {
|
class CustomUploader : public Uploader {
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(CustomUploader)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CustomUploader(QString absFilePath);
|
CustomUploader(QString absFilePath);
|
||||||
QString name();
|
QString name();
|
||||||
@ -29,6 +32,7 @@ private:
|
|||||||
bool base64 = false;
|
bool base64 = false;
|
||||||
QString returnPathspec;
|
QString returnPathspec;
|
||||||
QString urlPrepend, urlAppend;
|
QString urlPrepend, urlAppend;
|
||||||
|
void parseResult(QJsonDocument result, QByteArray data, QString returnPathspec, QString name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CUSTOMUPLOADER_HPP
|
#endif // CUSTOMUPLOADER_HPP
|
||||||
|
@ -14,5 +14,5 @@ void ClipboardUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
QApplication::clipboard()->setMimeData(data);
|
QApplication::clipboard()->setMimeData(data);
|
||||||
} else
|
} else
|
||||||
QApplication::clipboard()->setImage(QImage::fromData(imgData, format.toLocal8Bit().constData()));
|
QApplication::clipboard()->setImage(QImage::fromData(imgData, format.toLocal8Bit().constData()));
|
||||||
notifications::notify("KShare", "Copied to clipboard!");
|
notifications::notify(tr("KShare"), tr("Copied to clipboard!"));
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#ifndef CLIPBOARDUPLOADER_HPP
|
#ifndef CLIPBOARDUPLOADER_HPP
|
||||||
#define CLIPBOARDUPLOADER_HPP
|
#define CLIPBOARDUPLOADER_HPP
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <uploaders/uploader.hpp>
|
#include <uploaders/uploader.hpp>
|
||||||
|
|
||||||
class ClipboardUploader : public Uploader {
|
class ClipboardUploader : public Uploader {
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(ClipboardUploader)
|
||||||
public:
|
public:
|
||||||
QString name() {
|
QString name() {
|
||||||
return "clipboard";
|
return "clipboard";
|
||||||
|
@ -36,14 +36,15 @@ void ImgplusUploader::doUpload(QByteArray byteArray, QString format) {
|
|||||||
[](QByteArray link, QNetworkReply *) {
|
[](QByteArray link, QNetworkReply *) {
|
||||||
QApplication::clipboard()->setText(QString::fromUtf8(link));
|
QApplication::clipboard()->setText(QString::fromUtf8(link));
|
||||||
if (!link.startsWith("http"))
|
if (!link.startsWith("http"))
|
||||||
qCritical() << "Failed to upload! Copied the response to clipboard";
|
qCritical() << QObject::tr("Failed to upload! Copied the response to clipboard");
|
||||||
else
|
else
|
||||||
notifications::notify("KShare imgur Uploader ", "Uploaded to ImagePlus!");
|
notifications::notify(QObject::tr("KShare imgplus Uploader"),
|
||||||
|
QObject::tr("Uploaded to ImagePlus!"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImgplusUploader::showSettings() {
|
void ImgplusUploader::showSettings() {
|
||||||
QString text = QInputDialog::getText(0, "imgplus API key", "Enter the imgpl.us API key (Found in Settings)",
|
QString text = QInputDialog::getText(0, tr("imgplus API key"), tr("Enter the imgpl.us API key (Found in Settings)"),
|
||||||
QLineEdit::Normal, settings::settings().value("imgplus/apikey").toString());
|
QLineEdit::Normal, settings::settings().value("imgplus/apikey").toString());
|
||||||
if (!text.isNull()) settings::settings().setValue("imgplus/apikey", text);
|
if (!text.isNull()) settings::settings().setValue("imgplus/apikey", text);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
#ifndef IMGPLUSUPLOADER_HPP
|
#ifndef IMGPLUSUPLOADER_HPP
|
||||||
#define IMGPLUSUPLOADER_HPP
|
#define IMGPLUSUPLOADER_HPP
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <uploaders/uploader.hpp>
|
#include <uploaders/uploader.hpp>
|
||||||
|
|
||||||
class ImgplusUploader : public Uploader {
|
class ImgplusUploader : public Uploader {
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(ImgplusUploader)
|
||||||
public:
|
public:
|
||||||
QString name() override {
|
QString name() override {
|
||||||
return "ImagePlus";
|
return "ImagePlus";
|
||||||
|
@ -60,7 +60,7 @@ void ImgurSettingsDialog::on_authorize_clicked() {
|
|||||||
QDateTime::currentDateTimeUtc().addSecs(res["expires_in"].toInt()));
|
QDateTime::currentDateTimeUtc().addSecs(res["expires_in"].toInt()));
|
||||||
settings::settings().setValue("imgur/refresh", res["refresh_token"].toString());
|
settings::settings().setValue("imgur/refresh", res["refresh_token"].toString());
|
||||||
settings::settings().setValue("imgur/access", res["refresh_token"].toString());
|
settings::settings().setValue("imgur/access", res["refresh_token"].toString());
|
||||||
ui->status->setText("It works!");
|
ui->status->setText(tr("It works!"));
|
||||||
ui->status->setStyleSheet("* { color: green; }");
|
ui->status->setStyleSheet("* { color: green; }");
|
||||||
|
|
||||||
ui->authorize->setEnabled(false);
|
ui->authorize->setEnabled(false);
|
||||||
|
@ -53,7 +53,7 @@ private:
|
|||||||
|
|
||||||
void ImgurUploader::doUpload(QByteArray byteArray, QString format) {
|
void ImgurUploader::doUpload(QByteArray byteArray, QString format) {
|
||||||
if (byteArray.size() > 1e+7) {
|
if (byteArray.size() > 1e+7) {
|
||||||
notifications::notify("KShare imgur Uploader ", "Failed upload! Image too big");
|
notifications::notify(tr("KShare imgur Uploader"), tr("Failed upload! Image too big"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString mime;
|
QString mime;
|
||||||
@ -89,10 +89,10 @@ void ImgurUploader::handleSend(QString auth, QString mime, QByteArray byteArray)
|
|||||||
}
|
}
|
||||||
if (!result.isEmpty()) {
|
if (!result.isEmpty()) {
|
||||||
screenshotutil::toClipboard(result);
|
screenshotutil::toClipboard(result);
|
||||||
notifications::notify("KShare imgur Uploader ", "Uploaded to imgur!");
|
notifications::notify(tr("KShare imgur Uploader"), tr("Uploaded to imgur!"));
|
||||||
} else {
|
} else {
|
||||||
notifications::notify("KShare imgur Uploader ",
|
notifications::notify(tr("KShare imgur Uploader "),
|
||||||
QString("Failed upload! imgur said: HTTP %1: %2")
|
QString(tr("Failed upload! imgur said: HTTP %1: %2"))
|
||||||
.arg(r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt())
|
.arg(r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt())
|
||||||
.arg(r->errorString()));
|
.arg(r->errorString()));
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
#define IMGURUPLOADER_HPP
|
#define IMGURUPLOADER_HPP
|
||||||
|
|
||||||
#include "../uploader.hpp"
|
#include "../uploader.hpp"
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
class ImgurUploader : public Uploader {
|
class ImgurUploader : public Uploader {
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(ImgurUploader)
|
||||||
friend struct SegfaultWorkaround;
|
friend struct SegfaultWorkaround;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -18,18 +18,17 @@ UploaderSingleton::UploaderSingleton() : QObject() {
|
|||||||
case 0:
|
case 0:
|
||||||
saveDir = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
saveDir = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
||||||
if (QStandardPaths::writableLocation(QStandardPaths::PicturesLocation).isEmpty()) {
|
if (QStandardPaths::writableLocation(QStandardPaths::PicturesLocation).isEmpty()) {
|
||||||
qFatal("Cannot determine location for pictures");
|
qFatal("%s", tr("Cannot determine location for pictures").toLocal8Bit().constData());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (QStandardPaths::writableLocation(QStandardPaths::HomeLocation).isEmpty()) {
|
if (QStandardPaths::writableLocation(QStandardPaths::HomeLocation).isEmpty()) {
|
||||||
qFatal("Cannot determine location of your home directory");
|
qFatal("%s", tr("Cannot determine location of your home directory").toLocal8Bit().constData());
|
||||||
}
|
}
|
||||||
saveDir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/Screenshots";
|
saveDir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/Screenshots";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
qFatal("Invalid config [saveLocation not int or is not in range]");
|
qFatal("%s", tr("Invalid config [saveLocation not int or is not in range]").toLocal8Bit().constData());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!saveDir.exists()) {
|
if (!saveDir.exists()) {
|
||||||
@ -68,7 +67,7 @@ UploaderSingleton::UploaderSingleton() : QObject() {
|
|||||||
|
|
||||||
void UploaderSingleton::registerUploader(Uploader *uploader) {
|
void UploaderSingleton::registerUploader(Uploader *uploader) {
|
||||||
if (uploaders.contains(uploader->name()))
|
if (uploaders.contains(uploader->name()))
|
||||||
throw std::runtime_error(("Ambigious uploader " + uploader->name()).toStdString());
|
throw std::runtime_error((tr("Ambigious uploader ") + uploader->name()).toStdString());
|
||||||
uploaders.insert(uploader->name(), uploader);
|
uploaders.insert(uploader->name(), uploader);
|
||||||
emit newUploader(uploader);
|
emit newUploader(uploader);
|
||||||
}
|
}
|
||||||
@ -78,7 +77,7 @@ void UploaderSingleton::upload(QPixmap pixmap) {
|
|||||||
if (!u->validate()) {
|
if (!u->validate()) {
|
||||||
u = uploaders.value("imgur");
|
u = uploaders.value("imgur");
|
||||||
set("imgur");
|
set("imgur");
|
||||||
qWarning() << "Currently selected uploader is not set up properly! Falling back to imgur";
|
qWarning() << tr("Currently selected uploader is not set up properly! Falling back to imgur");
|
||||||
}
|
}
|
||||||
QString format = settings::settings().value("captureformat", "PNG").toString();
|
QString format = settings::settings().value("captureformat", "PNG").toString();
|
||||||
QFile file(saveDir.absoluteFilePath(
|
QFile file(saveDir.absoluteFilePath(
|
||||||
@ -90,7 +89,7 @@ void UploaderSingleton::upload(QPixmap pixmap) {
|
|||||||
file.seek(0);
|
file.seek(0);
|
||||||
u->doUpload(file.readAll(), format);
|
u->doUpload(file.readAll(), format);
|
||||||
} else
|
} else
|
||||||
notifications::notify("KShare - Failed to save picture", file.errorString(), QSystemTrayIcon::Warning);
|
notifications::notify(tr("KShare - Failed to save picture"), file.errorString(), QSystemTrayIcon::Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UploaderSingleton::upload(QByteArray img, QString format) {
|
void UploaderSingleton::upload(QByteArray img, QString format) {
|
||||||
@ -113,9 +112,9 @@ void UploaderSingleton::upload(QFile &img, QString format) {
|
|||||||
if (img.open(QFile::ReadWrite))
|
if (img.open(QFile::ReadWrite))
|
||||||
uploaders.value(uploader)->doUpload(img.readAll(), format);
|
uploaders.value(uploader)->doUpload(img.readAll(), format);
|
||||||
else
|
else
|
||||||
notifications::notify("KShare - Failed to save picture", img.errorString(), QSystemTrayIcon::Warning);
|
notifications::notify(tr("KShare - Failed to save picture"), img.errorString(), QSystemTrayIcon::Warning);
|
||||||
} else
|
} else
|
||||||
notifications::notify("KShare - Failed to save picture", img.errorString(), QSystemTrayIcon::Warning);
|
notifications::notify(tr("KShare - Failed to save picture"), img.errorString(), QSystemTrayIcon::Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UploaderSingleton::showSettings() {
|
void UploaderSingleton::showSettings() {
|
||||||
|
@ -30,10 +30,10 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QDir saveDir;
|
QDir saveDir;
|
||||||
UploaderSingleton();
|
|
||||||
QMap<QString, Uploader *> uploaders;
|
QMap<QString, Uploader *> uploaders;
|
||||||
QString uploader = "imgur";
|
QString uploader = "imgur";
|
||||||
QList<std::runtime_error> errs;
|
QList<std::runtime_error> errs;
|
||||||
|
UploaderSingleton();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UPLOADERSINGLETON_HPP
|
#endif // UPLOADERSINGLETON_HPP
|
||||||
|
Loading…
Reference in New Issue
Block a user