diff --git a/flameshot.pro b/flameshot.pro index 07966b20..10e77506 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -113,7 +113,6 @@ SOURCES += src/main.cpp \ src/cli/commandargument.cpp \ src/capture/workers/screenshotsaver.cpp \ src/capture/workers/imgur/imguruploader.cpp \ - src/capture/workers/graphicalscreenshotsaver.cpp \ src/capture/workers/imgur/loadspinner.cpp \ src/capture/workers/imgur/imagelabel.cpp \ src/capture/workers/imgur/notificationwidget.cpp \ @@ -170,7 +169,6 @@ HEADERS += src/capture/widget/buttonhandler.h \ src/cli/commandargument.h \ src/capture/workers/screenshotsaver.h \ src/capture/workers/imgur/imguruploader.h \ - src/capture/workers/graphicalscreenshotsaver.h \ src/capture/workers/imgur/loadspinner.h \ src/capture/workers/imgur/imagelabel.h \ src/capture/workers/imgur/notificationwidget.h \ diff --git a/src/capture/workers/graphicalscreenshotsaver.cpp b/src/capture/workers/graphicalscreenshotsaver.cpp deleted file mode 100644 index e5802fde..00000000 --- a/src/capture/workers/graphicalscreenshotsaver.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors -// -// This file is part of Flameshot. -// -// Flameshot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Flameshot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Flameshot. If not, see . - -#include "graphicalscreenshotsaver.h" -#include "src/utils/confighandler.h" -#include "src/utils/systemnotification.h" -#include "src/utils/filenamehandler.h" -#include -#include -#include -#include -#include - -/* - * AƱadir la captura de pantalla a la derecha y boton de copiar - * - */ - -GraphicalScreenshotSaver::GraphicalScreenshotSaver(const QPixmap &capture, - QWidget *parent) : - QWidget(parent), m_pixmap(capture) -{ - setAttribute(Qt::WA_DeleteOnClose); - setWindowTitle(QObject::tr("Save As")); - - new QShortcut(Qt::Key_Escape, this, SLOT(close())); - - m_layout = new QVBoxLayout(this); - m_fileDialog = new QFileDialog(); - initFileDialog(); - m_layout->addWidget(m_fileDialog); - -} - -void GraphicalScreenshotSaver::initFileDialog() { - m_fileDialog->setOption(QFileDialog::DontUseNativeDialog, true); - m_fileDialog->setFileMode(QFileDialog::AnyFile); - m_fileDialog->setAcceptMode(QFileDialog::AcceptSave); - QString fileName, directory; - FileNameHandler().absoluteSavePath(directory, fileName); - m_fileDialog->selectFile(fileName); - m_fileDialog->setDirectory(directory); - - QStringList mimeTypes; - for (const QByteArray &bf: QImageWriter::supportedMimeTypes()) - mimeTypes.append(QLatin1String(bf)); - m_fileDialog->setMimeTypeFilters(mimeTypes); - m_fileDialog->selectMimeTypeFilter("image/png"); - m_fileDialog->setDefaultSuffix("png"); - - connect(m_fileDialog, &QFileDialog::rejected, - this, &GraphicalScreenshotSaver::close); - connect(m_fileDialog, &QFileDialog::accepted, - this, &GraphicalScreenshotSaver::checkSaveAcepted); -} - -void GraphicalScreenshotSaver::showErrorMessage(const QString &msg) { - QMessageBox saveErrBox( - QMessageBox::Warning, - QObject::tr("Save Error"), - msg); - saveErrBox.setWindowIcon(QIcon(":img/flameshot.png")); - saveErrBox.exec(); -} - -void GraphicalScreenshotSaver::checkSaveAcepted() { - m_fileDialog->show(); - QString path = m_fileDialog->selectedFiles().first(); - bool ok = m_pixmap.save(path); - if (ok) { - QString pathNoFile = path.left(path.lastIndexOf("/")); - ConfigHandler().setSavePath(pathNoFile); - QString msg = QObject::tr("Capture saved as ") + path; - SystemNotification().sendMessage(msg); - close(); - } else { - QString msg = QObject::tr("Error trying to save as ") + path; - showErrorMessage(msg); - } -} diff --git a/src/capture/workers/graphicalscreenshotsaver.h b/src/capture/workers/graphicalscreenshotsaver.h deleted file mode 100644 index 037f4a6f..00000000 --- a/src/capture/workers/graphicalscreenshotsaver.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors -// -// This file is part of Flameshot. -// -// Flameshot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Flameshot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Flameshot. If not, see . - -#ifndef GRAPHICALSCREENSHOTSAVER_H -#define GRAPHICALSCREENSHOTSAVER_H - -#include - -class QFileDialog; -class QVBoxLayout; - -class GraphicalScreenshotSaver : public QWidget -{ - Q_OBJECT -public: - explicit GraphicalScreenshotSaver(const QPixmap &capture, - QWidget *parent = nullptr); - -private: - QPixmap m_pixmap; - QFileDialog *m_fileDialog; - QVBoxLayout *m_layout; - - void initFileDialog(); - void showErrorMessage(const QString &msg); - void checkSaveAcepted(); -}; - -#endif // GRAPHICALSCREENSHOTSAVER_H diff --git a/src/capture/workers/screenshotsaver.cpp b/src/capture/workers/screenshotsaver.cpp index 22c76b4c..5917f0c4 100644 --- a/src/capture/workers/screenshotsaver.cpp +++ b/src/capture/workers/screenshotsaver.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include ScreenshotSaver::ScreenshotSaver() { @@ -47,4 +49,33 @@ void ScreenshotSaver::saveToFilesystem(const QPixmap &capture, SystemNotification().sendMessage(saveMessage); } +void ScreenshotSaver::saveToFilesystemGUI(const QPixmap &capture) { + bool ok = false; + while (!ok) { + QString savePath = QFileDialog::getSaveFileName( + nullptr, + QString(), + FileNameHandler().absoluteSavePath() + ".png"); + + if (savePath.isNull()) { + return; + } + ok = capture.save(savePath); + if (ok) { + QString pathNoFile = savePath.left(savePath.lastIndexOf("/")); + ConfigHandler().setSavePath(pathNoFile); + QString msg = QObject::tr("Capture saved as ") + savePath; + SystemNotification().sendMessage(msg); + } else { + QString msg = QObject::tr("Error trying to save as ") + savePath; + QMessageBox saveErrBox( + QMessageBox::Warning, + QObject::tr("Save Error"), + msg); + saveErrBox.setWindowIcon(QIcon(":img/flameshot.png")); + saveErrBox.exec(); + } + } +} + diff --git a/src/capture/workers/screenshotsaver.h b/src/capture/workers/screenshotsaver.h index 656b35ad..948ffcc6 100644 --- a/src/capture/workers/screenshotsaver.h +++ b/src/capture/workers/screenshotsaver.h @@ -28,6 +28,7 @@ public: void saveToClipboard(const QPixmap &capture); void saveToFilesystem(const QPixmap &capture, const QString &path); + void saveToFilesystemGUI(const QPixmap &capture); }; diff --git a/src/core/resourceexporter.cpp b/src/core/resourceexporter.cpp index 4dedf5a0..18caa790 100644 --- a/src/core/resourceexporter.cpp +++ b/src/core/resourceexporter.cpp @@ -18,7 +18,6 @@ #include "resourceexporter.h" #include "src/capture/workers/imgur/imguruploader.h" #include "src/capture/workers/screenshotsaver.h" -#include "src/capture/workers/graphicalscreenshotsaver.h" #include "src/capture/workers/launcher/openwithprogram.h" ResourceExporter::ResourceExporter() { @@ -34,8 +33,7 @@ void ResourceExporter::captureToFile(const QPixmap &p, const QString &path) { } void ResourceExporter::captureToFileUi(const QPixmap &p) { - auto w = new GraphicalScreenshotSaver(p); - w->show(); + ScreenshotSaver().saveToFilesystemGUI(p); } void ResourceExporter::captureToImgur(const QPixmap &p) { diff --git a/src/utils/filenamehandler.cpp b/src/utils/filenamehandler.cpp index 4fe01316..03f93029 100644 --- a/src/utils/filenamehandler.cpp +++ b/src/utils/filenamehandler.cpp @@ -72,6 +72,11 @@ QString FileNameHandler::absoluteSavePath(QString &directory, QString &filename) return directory + filename; } +QString FileNameHandler::absoluteSavePath() { + QString dir, file; + return absoluteSavePath(dir, file); +} + QString FileNameHandler::charArrToQString(const char *c) { return QString::fromLocal8Bit(c, MAX_CHARACTERS); } diff --git a/src/utils/filenamehandler.h b/src/utils/filenamehandler.h index 09cc3676..e205435c 100644 --- a/src/utils/filenamehandler.h +++ b/src/utils/filenamehandler.h @@ -31,6 +31,8 @@ public: QString parseFilename(const QString &name); QString generateAbsolutePath(const QString &path); QString absoluteSavePath(QString &directory, QString &filename); + QString absoluteSavePath(); + static const int MAX_CHARACTERS = 70;