diff --git a/dbus/org.dharkael.Flameshot.xml b/dbus/org.dharkael.Flameshot.xml index b48d2adc..02c62c24 100644 --- a/dbus/org.dharkael.Flameshot.xml +++ b/dbus/org.dharkael.Flameshot.xml @@ -2,48 +2,31 @@ - - - - - - - + + - - - - - - + diff --git a/src/capture/capturewidget.cpp b/src/capture/capturewidget.cpp index 8fcc965c..c2da75f8 100644 --- a/src/capture/capturewidget.cpp +++ b/src/capture/capturewidget.cpp @@ -47,13 +47,11 @@ namespace { // size of the handlers at the corners of the selection const int HANDLE_SIZE = 9; } - -// http://doc.qt.io/qt-5/qwidget.html#setMask - -CaptureWidget::CaptureWidget(bool enableSaveWindow, QWidget *parent) : +// enableSaveWIndow +CaptureWidget::CaptureWidget(const QString &forcedSavePath, QWidget *parent) : QWidget(parent), m_mouseOverHandle(0), m_mouseIsClicked(false), m_rightClick(false), m_newSelection(false), m_grabbing(false), - m_onButton(false), m_enableSaveWindow(enableSaveWindow), + m_onButton(false), m_forcedSavePath(forcedSavePath), m_state(CaptureButton::TYPE_MOVESELECTION) { m_showInitialMsg = ConfigHandler().getShowHelp(); @@ -389,37 +387,29 @@ void CaptureWidget::keyPressEvent(QKeyEvent *e) { } QString CaptureWidget::saveScreenshot(bool toClipboard) { - hide(); - QString path; - if (m_selection.isNull()) { - path = m_screenshot->graphicalSave(QRect(), this); - } else { // save full screen when no selection - path = m_screenshot->graphicalSave(getExtendedSelection(), this); - } - if (!path.isEmpty()) { - QString saveMessage(tr("Capture saved in ")); - Q_EMIT newMessage(saveMessage + path); + QString savePath, saveMessage; + bool ok = true; + if(m_forcedSavePath.isEmpty()) { + if(isVisible()) { + hide(); + } + savePath = m_screenshot->graphicalSave(ok, getExtendedSelection(), this); + } else { + ConfigHandler config; + config.setSavePath(m_forcedSavePath); + savePath = m_screenshot->fileSave(ok, getExtendedSelection()); + if(!ok || config.getSavePath() != m_forcedSavePath) { + saveMessage = tr("Error trying to save in ") + savePath; + Q_EMIT newMessage(saveMessage); + } } if (toClipboard) { copyScreenshot(); } - close(); - return path; -} - -QString CaptureWidget::saveScreenshot(QString path, bool toClipboard) { - ConfigHandler().setSavePath(path); - QString savePath; - if (m_selection.isNull()) { - savePath = m_screenshot->fileSave(); - } else { // save full screen when no selection - savePath = m_screenshot->fileSave(getExtendedSelection()); + if(ok) { + saveMessage = tr("Capture saved in ") + savePath; + Q_EMIT newMessage(saveMessage); } - if (toClipboard) { - copyScreenshot(); - } - QString saveMessage(tr("Capture saved in ")); - Q_EMIT newMessage(saveMessage + savePath); close(); return savePath; } @@ -556,9 +546,7 @@ void CaptureWidget::handleButtonSignal(CaptureTool::Request r) { setCursor(Qt::CrossCursor); break; case CaptureTool::REQ_SAVE_SCREENSHOT: - m_enableSaveWindow ? - saveScreenshot() : - saveScreenshot(ConfigHandler().getSavePath()); + saveScreenshot(); break; case CaptureTool::REQ_SELECT_ALL: m_selection = rect(); @@ -649,6 +637,7 @@ QPoint CaptureWidget::limitPointToRect(const QPoint &p, const QRect &r) const { } QRect CaptureWidget::getExtendedSelection() const { + if(m_selection.isNull()) return QRect(); auto devicePixelRatio = m_screenshot->getScreenshot().devicePixelRatio(); return QRect(m_selection.left() * devicePixelRatio, diff --git a/src/capture/capturewidget.h b/src/capture/capturewidget.h index 00457876..1196cac4 100644 --- a/src/capture/capturewidget.h +++ b/src/capture/capturewidget.h @@ -45,13 +45,13 @@ class CaptureWidget : public QWidget { friend class CaptureButton; public: - explicit CaptureWidget(bool enableSaveWindow = true, QWidget *parent = nullptr); + explicit CaptureWidget(const QString &forcedSavePath = "", + QWidget *parent = nullptr); ~CaptureWidget(); void updateButtons(); public slots: QString saveScreenshot(bool toClipboard = false); - QString saveScreenshot(QString path, bool toClipboard = false); void handleButtonSignal(CaptureTool::Request r); signals: @@ -97,7 +97,8 @@ protected: bool m_grabbing; bool m_onButton; bool m_showInitialMsg; - bool m_enableSaveWindow; + + const QString m_forcedSavePath; // naming convention for handles // T top, B bottom, R Right, L left diff --git a/src/capture/screenshot.cpp b/src/capture/screenshot.cpp index bf0087a9..6e56e8cb 100644 --- a/src/capture/screenshot.cpp +++ b/src/capture/screenshot.cpp @@ -59,7 +59,10 @@ QPixmap Screenshot::getScreenshot() const { // graphicalSave generates a graphical window to ask about the save path and // saves the screenshot with all the modifications in such directory -QString Screenshot::graphicalSave(const QRect &selection, QWidget *parent) const { +QString Screenshot::graphicalSave(bool &ok, + const QRect &selection, + QWidget *parent) const +{ QString savePath = FileNameHandler().getAbsoluteSavePath(); // setup window QFileDialog fileDialog(parent, QObject::tr("Save As"), savePath); @@ -74,7 +77,6 @@ QString Screenshot::graphicalSave(const QRect &selection, QWidget *parent) const fileDialog.setDefaultSuffix("png"); fileDialog.setWindowIcon(QIcon(":img/flameshot.png")); - bool saved = false; QString fileName; do { if (fileDialog.exec() != QDialog::Accepted) { return ""; } @@ -89,8 +91,8 @@ QString Screenshot::graphicalSave(const QRect &selection, QWidget *parent) const } else { // save full screen when no selection pixToSave = m_modifiedScreenshot.copy(selection); } - saved = pixToSave.save(fileName); - if (!saved) { + ok = pixToSave.save(fileName); + if (!ok) { QMessageBox saveErrBox( QMessageBox::Warning, QObject::tr("Save Error"), @@ -99,11 +101,11 @@ QString Screenshot::graphicalSave(const QRect &selection, QWidget *parent) const saveErrBox.setWindowIcon(QIcon(":img/flameshot.png")); saveErrBox.exec(); } - } while(!saved); + } while(!ok); return savePath; } -QString Screenshot::fileSave(const QRect &selection) const { +QString Screenshot::fileSave(bool &ok, const QRect &selection) const { QString savePath = FileNameHandler().getAbsoluteSavePath(); QPixmap pixToSave; if (selection.isEmpty()) { @@ -111,7 +113,8 @@ QString Screenshot::fileSave(const QRect &selection) const { } else { // save full screen when no selection pixToSave = m_modifiedScreenshot.copy(selection); } - return pixToSave.save(savePath) ? savePath : ""; + ok = pixToSave.save(savePath); + return savePath; } // paintModification adds a new modification to the screenshot diff --git a/src/capture/screenshot.h b/src/capture/screenshot.h index 2e9b5e22..559ac81c 100644 --- a/src/capture/screenshot.h +++ b/src/capture/screenshot.h @@ -37,8 +37,10 @@ public: QPixmap getBaseScreenshot() const; QPixmap getScreenshot() const; - QString graphicalSave(const QRect &selection = QRect(), QWidget *parent = 0) const; - QString fileSave(const QRect &selection = QRect()) const; + QString graphicalSave(bool &ok, + const QRect &selection = QRect(), + QWidget *parent = 0) const; + QString fileSave(bool &ok, const QRect &selection = QRect()) const; void uploadToImgur(QNetworkAccessManager *, const QRect &selection = QRect()); QPixmap paintModification(const CaptureModification*); diff --git a/src/controller.cpp b/src/controller.cpp index 6f453607..29d1f70f 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -46,16 +46,12 @@ Controller::Controller(QObject *parent) : QObject(parent), } -QString Controller::saveScreenshot(bool toClipboard) { - QPointer w = createCapture(); +QString Controller::saveScreenshot(const QString &path, + bool const toClipboard) { + QPointer w = createCaptureWidget(path); return w->saveScreenshot(toClipboard); } -QString Controller::saveScreenshot(QString path, bool toClipboard) { - QPointer w = createCapture(); - return w->saveScreenshot(path, toClipboard); -} - // creates the items of the trayIcon void Controller::createActions() { m_configAction = new QAction(tr("&Configuration"), this); @@ -104,17 +100,17 @@ void Controller::trayIconActivated(QSystemTrayIcon::ActivationReason r) { } // creation of a new capture -QPointer Controller::createCapture(bool enableSaveWindow) { - QPointer w = new CaptureWidget(enableSaveWindow); +QPointer Controller::createCaptureWidget(const QString &forcedSavePath) { + QPointer w = new CaptureWidget(forcedSavePath); connect(w, &CaptureWidget::newMessage, this, &Controller::showDesktopNotification); return w; } // creation of a new capture in GUI mode -void Controller::createVisualCapture(bool enableSaveWindow) { +void Controller::createVisualCapture(const QString &forcedSavePath) { if (!m_captureWindow) { - m_captureWindow = createCapture(enableSaveWindow); + m_captureWindow = createCaptureWidget(forcedSavePath); m_captureWindow->showFullScreen(); } } diff --git a/src/controller.h b/src/controller.h index 26573c10..897651e3 100644 --- a/src/controller.h +++ b/src/controller.h @@ -35,12 +35,11 @@ class Controller : public QObject { public: explicit Controller(QObject *parent = nullptr); - QString saveScreenshot(bool toClipboard = false); - QString saveScreenshot(QString path, bool toClipboard = false); - public slots: - QPointer createCapture(bool enableSaveWindow = true); - void createVisualCapture(bool enableSaveWindow = true); + QString saveScreenshot(const QString &path = "", + bool const toClipboard = false); + void createVisualCapture(const QString &forcedSavePath = ""); + void openConfigWindow(); void openInfoWindow(); void showDesktopNotification(QString); @@ -50,6 +49,8 @@ private slots: void trayIconActivated(QSystemTrayIcon::ActivationReason r); private: + QPointer createCaptureWidget(const QString &forcedSavePath = ""); + void createActions(); void createTrayIcon(); diff --git a/src/flameshotdbusadapter.cpp b/src/flameshotdbusadapter.cpp index 403e4e66..38492e3a 100644 --- a/src/flameshotdbusadapter.cpp +++ b/src/flameshotdbusadapter.cpp @@ -17,6 +17,7 @@ #include "flameshotdbusadapter.h" #include "src/utils/confighandler.h" +#include FlameshotDBusAdapter::FlameshotDBusAdapter(Controller *parent) : QDBusAbstractAdaptor(parent) @@ -32,25 +33,19 @@ Controller *FlameshotDBusAdapter::parent() const { return static_cast(QObject::parent()); } -void FlameshotDBusAdapter::openCapture() { - parent()->createVisualCapture(); +void FlameshotDBusAdapter::graphicCapture(QString path, int delay) { + auto p = parent(); + auto f = [p, path, this]() { + p->createVisualCapture(path); + }; + QTimer::singleShot(delay, p, f); } -void FlameshotDBusAdapter::openCaptureWithPath(QString path) { - ConfigHandler().setSavePath(path); - parent()->createVisualCapture(false); -} +void FlameshotDBusAdapter::fullScreen(QString path, bool toClipboard, int delay) { + auto p = parent(); + auto f = [p, path, toClipboard, this]() { + p->saveScreenshot(path, toClipboard); + }; + QTimer::singleShot(delay, p, f); -void FlameshotDBusAdapter::fullScreen(bool toClipboard) { - QString path = parent()->saveScreenshot(toClipboard); - if (!path.isEmpty()) { - QString saveMessage(tr("Capture saved in ")); - parent()->showDesktopNotification(saveMessage + path); - } -} - -void FlameshotDBusAdapter::fullScreenWithPath(QString path, bool toClipboard) { - QString finalPath = parent()->saveScreenshot(path, toClipboard); - QString saveMessage(tr("Capture saved in ")); - parent()->showDesktopNotification(saveMessage + finalPath); } diff --git a/src/flameshotdbusadapter.h b/src/flameshotdbusadapter.h index 5b53de70..9ea38903 100644 --- a/src/flameshotdbusadapter.h +++ b/src/flameshotdbusadapter.h @@ -32,11 +32,9 @@ public: inline Controller *parent() const; public slots: - Q_NOREPLY void openCapture(); - Q_NOREPLY void openCaptureWithPath(QString path); + Q_NOREPLY void graphicCapture(QString path, int delay); + Q_NOREPLY void fullScreen(QString path, bool toClipboard, int delay); - Q_NOREPLY void fullScreen(bool toClipboard); - Q_NOREPLY void fullScreenWithPath(QString path, bool toClipboard); }; #endif // FLAMESHOTDBUSADAPTER_H diff --git a/src/main.cpp b/src/main.cpp index 8a5676af..3d30174c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,53 +72,53 @@ int main(int argc, char *argv[]) { "pathVal"); QCommandLineOption clipboardOption({{"c", "clipboard"}, QObject::tr("Save the capture to the clipboard")}); + QCommandLineOption delayOption(QStringList() << "d" << "delay", + QObject::tr("Delay time in milliseconds"), + "pathVal"); if (command == "full") { parser.clearPositionalArguments(); parser.addPositionalArgument( "full", fullDescription, "full [full_options]"); - parser.addOptions({ pathOption, clipboardOption }); + parser.addOptions({ pathOption, clipboardOption, delayOption }); } else if (command == "gui") { parser.clearPositionalArguments(); parser.addPositionalArgument( "gui", guiDescription, "gui [gui_options]"); - parser.addOption(pathOption); + parser.addOptions({ pathOption, delayOption }); } parser.process(app); + // obtain values QDBusMessage m; QString pathValue; - bool pathIsSetAndValid = parser.isSet("path"); - if (pathIsSetAndValid) { + if (parser.isSet("path")) { pathValue = QString::fromStdString(parser.value("path").toStdString()); - pathIsSetAndValid = QDir(pathValue).exists(); - if (!pathIsSetAndValid) { + if (!QDir(pathValue).exists()) { qWarning() << QObject::tr("Invalid path."); return 0; } } - - if (command == "gui") { - if (pathIsSetAndValid) { - m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", - "/", "", "openCaptureWithPath"); - m << pathValue; - } else { - m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", - "/", "", "openCapture"); + int delay = 0; + if (parser.isSet("delay")) { + delay = parser.value("delay").toInt(); + if (delay < 0) { + qWarning() << QObject::tr("Invalid negative delay."); + return 0; } + } + + // process commands + if (command == "gui") { + m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", + "/", "", "graphicCapture"); + m << pathValue << delay; QDBusConnection::sessionBus().call(m); } else if (command == "full") { - if (pathIsSetAndValid) { - m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", - "/", "", "fullScreenWithPath"); - m << pathValue; - } else { - m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", - "/", "", "fullScreen"); - } - m << parser.isSet("clipboard"); + m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", + "/", "", "fullScreen"); + m << pathValue << parser.isSet("clipboard") << delay; QDBusConnection::sessionBus().call(m); } return 0; diff --git a/src/utils/filenamehandler.cpp b/src/utils/filenamehandler.cpp index 88b828de..29041f39 100644 --- a/src/utils/filenamehandler.cpp +++ b/src/utils/filenamehandler.cpp @@ -58,14 +58,14 @@ QString FileNameHandler::getAbsoluteSavePath() { if (savePath.isEmpty() || !QDir(savePath).exists() || !QFileInfo(savePath).isWritable()) { changed = true; savePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); - if (savePath.isEmpty()) { - savePath = QDir::currentPath(); - } } if(changed) { config.setSavePath(savePath); } - QString tempName = "/"+ FileNameHandler().getParsedPattern(); + // first add slash if needed + QString tempName = savePath.endsWith("/") ? "" : "/"; + // add the parsed pattern in a correct format for the filesystem + tempName += FileNameHandler().getParsedPattern().replace("/", "⁄"); // find unused name adding _n where n is a number QFileInfo checkFile(savePath + tempName + ".png"); if (checkFile.exists()) { diff --git a/translation/Internationalization_es.qm b/translation/Internationalization_es.qm index 1b21936f..ad702a8e 100644 Binary files a/translation/Internationalization_es.qm and b/translation/Internationalization_es.qm differ diff --git a/translation/Internationalization_es.ts b/translation/Internationalization_es.ts index 3e579f4f..860e60bc 100644 --- a/translation/Internationalization_es.ts +++ b/translation/Internationalization_es.ts @@ -17,7 +17,7 @@ CaptureWidget - + Select an area with the mouse, or press Esc to exit. Press Enter to capture the screen. Press Right Click to show the color picker. @@ -26,13 +26,17 @@ Presiona Enter para capturar la pantalla. Presiona click derecho para mostrar el selector de color. - - + + Error trying to save in + Error intentando guardar en + + + Capture saved in Captura guardada en - + Uploading image... Subiendo imagen... @@ -71,17 +75,17 @@ Presiona click derecho para mostrar el selector de color. Controller - + &Configuration &Configuración - + &Information &Información - + &Quit &Salir @@ -153,15 +157,6 @@ Presiona click derecho para mostrar el selector de color. captura - - FlameshotDBusAdapter - - - - Capture saved in - Captura guardada en - - GeneneralConf @@ -322,17 +317,17 @@ Presiona click derecho para mostrar el selector de color. QObject - + Save As Guardar Como - + Save Error Error al Guardar - + The image could not be saved to "%1". la imagen no pudo ser guardada en "%1". @@ -362,17 +357,27 @@ Presiona click derecho para mostrar el selector de color. Guarda la captura en el portapapeles - - Invalid path. - Rura inválida. + + Delay time in milliseconds + Tiempo de espera en milisegundos - + + Invalid path. + Ruta inválida. + + + + Invalid negative delay. + Valor negativo de espera inválido. + + + Resource Error Error de Recurso - + Unable to open the URL. No puede abrir la URL.