summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2016-05-23 13:19:45 +0200
committerMontel Laurent <[email protected]>2016-05-23 13:19:45 +0200
commit199ec52c61982e8d671315be2c5a4b5532cd74b5 (patch)
tree6f106aa5324cf0ca416e9e01344fd627a8ddcb32
parent4dfa450444d01c2444857440596bd254ca44f622 (diff)
Allow to remove temporary file
-rw-r--r--webengineviewer/src/print/autotests/printpreviewpagewidgettest.cpp2
-rw-r--r--webengineviewer/src/print/printpreviewdialog.cpp4
-rw-r--r--webengineviewer/src/print/printpreviewdialog.h2
-rw-r--r--webengineviewer/src/print/printpreviewpagewidget.cpp18
-rw-r--r--webengineviewer/src/print/printpreviewpagewidget.h6
5 files changed, 27 insertions, 5 deletions
diff --git a/webengineviewer/src/print/autotests/printpreviewpagewidgettest.cpp b/webengineviewer/src/print/autotests/printpreviewpagewidgettest.cpp
index adaf0e8..c218aeb 100644
--- a/webengineviewer/src/print/autotests/printpreviewpagewidgettest.cpp
+++ b/webengineviewer/src/print/autotests/printpreviewpagewidgettest.cpp
@@ -59,6 +59,8 @@ void PrintPreviewPageWidgetTest::shouldHaveDefaultValue()
QComboBox *mPageComboBox = w.findChild<QComboBox *>(QStringLiteral("pagecombobox"));
QVERIFY(mPageComboBox);
QCOMPARE(mPageComboBox->count(), 0);
+
+ QVERIFY(!w.deleteFile());
}
QTEST_MAIN(PrintPreviewPageWidgetTest)
diff --git a/webengineviewer/src/print/printpreviewdialog.cpp b/webengineviewer/src/print/printpreviewdialog.cpp
index 4cfda2b..a787896 100644
--- a/webengineviewer/src/print/printpreviewdialog.cpp
+++ b/webengineviewer/src/print/printpreviewdialog.cpp
@@ -68,9 +68,9 @@ void PrintPreviewDialog::readConfig()
}
}
-void PrintPreviewDialog::loadFile(const QString &path)
+void PrintPreviewDialog::loadFile(const QString &path, bool deleteFile)
{
- mPrintPreviewWidget->loadFile(path);
+ mPrintPreviewWidget->loadFile(path, deleteFile);
}
void PrintPreviewDialog::slotPrint()
diff --git a/webengineviewer/src/print/printpreviewdialog.h b/webengineviewer/src/print/printpreviewdialog.h
index 033eb42..7467346 100644
--- a/webengineviewer/src/print/printpreviewdialog.h
+++ b/webengineviewer/src/print/printpreviewdialog.h
@@ -29,7 +29,7 @@ class PrintPreviewDialog : public QDialog
public:
explicit PrintPreviewDialog(QWidget *parent = Q_NULLPTR);
~PrintPreviewDialog();
- void loadFile(const QString &path);
+ void loadFile(const QString &path, bool deleteFile = false);
private Q_SLOTS:
void slotPrint();
diff --git a/webengineviewer/src/print/printpreviewpagewidget.cpp b/webengineviewer/src/print/printpreviewpagewidget.cpp
index 9713088..794470c 100644
--- a/webengineviewer/src/print/printpreviewpagewidget.cpp
+++ b/webengineviewer/src/print/printpreviewpagewidget.cpp
@@ -22,6 +22,7 @@
#include <QLabel>
#include <QComboBox>
+#include <QFile>
#include <QVBoxLayout>
#include <KMessageBox>
#include <KLocalizedString>
@@ -30,6 +31,7 @@ using namespace WebEngineViewer;
PrintPreviewPageWidget::PrintPreviewPageWidget(QWidget *parent)
: QWidget(parent),
+ mDeleteFile(false),
mDoc(Q_NULLPTR)
{
QVBoxLayout *layout = new QVBoxLayout;
@@ -58,15 +60,24 @@ PrintPreviewPageWidget::PrintPreviewPageWidget(QWidget *parent)
PrintPreviewPageWidget::~PrintPreviewPageWidget()
{
+ if (mDeleteFile && !mFilePath.isEmpty()) {
+ QFile file(mFilePath);
+ bool removeFile = file.remove();
+ if (!removeFile) {
+ qWarning() << "Impossible to remove file " << mFilePath;
+ }
+ }
delete mDoc;
mDoc = Q_NULLPTR;
}
-void PrintPreviewPageWidget::loadFile(const QString &path)
+void PrintPreviewPageWidget::loadFile(const QString &path, bool deleteFile)
{
if (path.isEmpty()) {
return;
}
+ mDeleteFile = deleteFile;
+ mFilePath = path;
mDoc = Poppler::Document::load(path);
if (!mDoc) {
KMessageBox::error(this, i18n("Unable to open file \"%1\"", path), i18n("Open file error"));
@@ -89,6 +100,11 @@ void PrintPreviewPageWidget::fillComboBox()
}
}
+bool PrintPreviewPageWidget::deleteFile() const
+{
+ return mDeleteFile;
+}
+
void PrintPreviewPageWidget::showPage(int index)
{
Poppler::Page *popplerPage = mDoc->page(index);
diff --git a/webengineviewer/src/print/printpreviewpagewidget.h b/webengineviewer/src/print/printpreviewpagewidget.h
index 222bcf2..792e799 100644
--- a/webengineviewer/src/print/printpreviewpagewidget.h
+++ b/webengineviewer/src/print/printpreviewpagewidget.h
@@ -35,14 +35,18 @@ public:
explicit PrintPreviewPageWidget(QWidget *parent = Q_NULLPTR);
~PrintPreviewPageWidget();
- void loadFile(const QString &path);
+ void loadFile(const QString &path, bool deleteFile = false);
void print(const QList<int> &page);
+ bool deleteFile() const;
+
private Q_SLOTS:
void showPage(int index);
private:
void fillComboBox();
+ QString mFilePath;
+ bool mDeleteFile;
PrintPreviewPageViewer *mPrintPreviewPage;
Poppler::Document *mDoc;
QComboBox *mPageComboBox;