Commit b84e4945 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to open file

parent e6539cf2
......@@ -34,7 +34,9 @@
#include <QPushButton>
#include <QVBoxLayout>
#include <KRun>
#include <QFileDialog>
#include <QTemporaryDir>
#include <ktreewidgetsearchline.h>
ShowArchiveStructureDialog::ShowArchiveStructureDialog(const QString &filename, QWidget *parent)
......@@ -90,6 +92,7 @@ ShowArchiveStructureDialog::~ShowArchiveStructureDialog()
{
writeConfig();
delete mZip;
delete mTempDir;
}
void ShowArchiveStructureDialog::slotOpenFile()
......@@ -101,7 +104,24 @@ void ShowArchiveStructureDialog::slotOpenFile()
const KArchiveDirectory *topDirectory = mZip->directory();
const KArchiveEntry *currentEntry = topDirectory->entry(fullPath);
if (currentEntry && currentEntry->isFile()) {
//TODO
const KArchiveFile *currentFile = static_cast<const KArchiveFile *>(currentEntry);
if (!mTempDir) {
mTempDir = new QTemporaryDir;
}
const QString fileName = mTempDir->path() + QLatin1Char('/') + currentItem->text(0);
QFile f(fileName);
if (!f.open(QIODevice::WriteOnly)) {
qCWarning(PIMDATAEXPORTERGUI_LOG) << "Impossible to extract file: " << currentItem->text(0);
return;
}
const QByteArray data = currentFile->data();
if (f.write(data) != data.length()) {
qCWarning(PIMDATAEXPORTERGUI_LOG) << "Impossible to copy file: " << currentItem->text(0);
return;
}
KRun *runner = new KRun(QUrl::fromLocalFile(fileName), this); // will delete itself
runner->setRunExecutables(false);
}
}
}
......
......@@ -27,6 +27,7 @@ class KArchiveEntry;
class KArchiveDirectory;
class QPushButton;
class KZip;
class QTemporaryDir;
class ShowArchiveStructureDialog : public QDialog
{
Q_OBJECT
......@@ -58,6 +59,7 @@ private:
QPushButton *mExtractFile = nullptr;
QPushButton *mOpenFile = nullptr;
KZip *mZip = nullptr;
QTemporaryDir *mTempDir = nullptr;
};
#endif // SHOWARCHIVESTRUCTUREDIALOG_H
......@@ -29,4 +29,5 @@ target_link_libraries(showarchivestructuredialog_gui
pimdataexporterprivate
KF5::ItemViews
KF5::I18n
KF5::KIOWidgets
)
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