Commit 199ec52c authored by Laurent Montel's avatar Laurent Montel 😁

Allow to remove temporary file

parent 4dfa4504
......@@ -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)
......@@ -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()
......
......@@ -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();
......
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment