Commit 9e077005 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Project archiving: check after each file if archiving works, add option to use...

Project archiving: check after each file if archiving works, add option to use zip instead of tar.gz
CCBUG: 421565
parent c18bf45a
Pipeline #38346 canceled with stage
......@@ -34,6 +34,7 @@
#include <KMessageBox>
#include <KMessageWidget>
#include <KTar>
#include <KZip>
#include <kio/directorysizejob.h>
#include <klocalizedstring.h>
......@@ -203,7 +204,6 @@ ArchiveWidget::ArchiveWidget(const QString &projectName, const QString xmlData,
if (m_name.isEmpty()) {
m_name = i18n("Untitled");
}
compressed_archive->setText(compressed_archive->text() + QStringLiteral(" (") + m_name + QStringLiteral(".tar.gz)"));
project_files->setText(i18np("%1 file to archive, requires %2", "%1 files to archive, requires %2", total, KIO::convertSize(m_requestedSize)));
buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Archive"));
connect(buttonBox->button(QDialogButtonBox::Apply), &QAbstractButton::clicked, this, &ArchiveWidget::slotStartArchiving);
......@@ -538,6 +538,10 @@ bool ArchiveWidget::slotStartArchiving(bool firstPass)
m_abortArchive = true;
return true;
}
m_infoMessage->setMessageType(KMessageWidget::Information);
m_infoMessage->setText(i18n("Starting archive job"));
m_infoMessage->animatedShow();
bool isArchive = compressed_archive->isChecked();
if (!firstPass) {
m_copyJob = nullptr;
......@@ -644,6 +648,7 @@ bool ArchiveWidget::slotStartArchiving(bool firstPass)
QUrl startJobSrc = i.key();
QUrl startJobDst = i.value();
m_duplicateFiles.remove(startJobSrc);
m_infoMessage->setText(i18n("Copying %1", startJobSrc.fileName()));
KIO::CopyJob *job = KIO::copyAs(startJobSrc, startJobDst, KIO::HideProgressInfo);
connect(job, &KJob::result, this, [this] (KJob *jb) {
slotArchivingFinished(jb, false);
......@@ -876,7 +881,7 @@ bool ArchiveWidget::processProjectFile()
endString = QLatin1Char('>') + basePath;
playList.replace(startString, endString);
}
m_archiveName.clear();
if (isArchive) {
m_temp = new QTemporaryFile;
if (!m_temp->open()) {
......@@ -916,16 +921,26 @@ bool ArchiveWidget::processProjectFile()
void ArchiveWidget::createArchive()
{
QString archiveName(archive_url->url().toLocalFile() + QDir::separator() + m_name + QStringLiteral(".tar.gz"));
if (QFile::exists(archiveName) &&
KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", archiveName)) == KMessageBox::No) {
m_archiveName = QString(archive_url->url().toLocalFile() + QDir::separator() + m_name);
if (compression_type->currentIndex() == 1) {
m_archiveName.append(QStringLiteral(".zip"));
} else {
m_archiveName.append(QStringLiteral(".tar.gz"));
}
if (QFile::exists(m_archiveName) &&
KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", m_archiveName)) == KMessageBox::No) {
return;
}
QFileInfo dirInfo(archive_url->url().toLocalFile());
QString user = dirInfo.owner();
QString group = dirInfo.group();
KTar archive(archiveName, QStringLiteral("application/x-gzip"));
archive.open(QIODevice::WriteOnly);
std::unique_ptr<KArchive> archive;
if (compression_type->currentIndex() == 1) {
archive.reset(new KZip(m_archiveName));
} else {
archive.reset(new KTar(m_archiveName, QStringLiteral("application/x-gzip")));
}
archive->open(QIODevice::WriteOnly);
// Create folders
for (const QString &path : qAsConst(m_foldersList)) {
......@@ -934,29 +949,40 @@ void ArchiveWidget::createArchive()
// Add files
int ix = 0;
bool success = true;
QMapIterator<QString, QString> i(m_filesList);
while (i.hasNext()) {
i.next();
archive.addLocalFile(i.key(), i.value());
m_infoMessage->setText(i18n("Archiving %1", i.key()));
success = archive->addLocalFile(i.key(), i.value());
emit archiveProgress((int)100 * ix / m_filesList.count());
ix++;
if (!success) {
break;
}
}
// Add project file
bool result = false;
if (m_temp) {
archive.addLocalFile(m_temp->fileName(), m_name + QStringLiteral(".kdenlive"));
result = archive.close();
if (!m_temp) {
success = false;
}
if (success) {
success = archive->addLocalFile(m_temp->fileName(), m_name + QStringLiteral(".kdenlive"));
delete m_temp;
m_temp = nullptr;
}
emit archivingFinished(result);
if (success) {
success = archive->close();
} else {
archive->close();
}
emit archivingFinished(success);
}
void ArchiveWidget::slotArchivingBoolFinished(bool result)
{
if (result) {
slotJobResult(true, i18n("Project was successfully archived."));
slotJobResult(true, i18n("Project was successfully archived.\n%1", m_archiveName));
buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
} else {
slotJobResult(false, i18n("There was an error processing project file"));
......
......@@ -84,6 +84,7 @@ private:
QMap<QUrl, QUrl> m_duplicateFiles;
QMap<QUrl, QUrl> m_replacementList;
QString m_name;
QString m_archiveName;
QDomDocument m_doc;
QTemporaryFile *m_temp;
bool m_abortArchive;
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>285</width>
<height>329</height>
<width>313</width>
<height>331</height>
</rect>
</property>
<property name="windowTitle">
......@@ -41,11 +41,29 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="compressed_archive">
<property name="text">
<string>Compressed archive</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QCheckBox" name="compressed_archive">
<property name="text">
<string>Compressed archive</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="compression_type">
<item>
<property name="text">
<string>tar.gz</string>
</property>
</item>
<item>
<property name="text">
<string>zip</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="proxy_only">
......@@ -138,6 +156,7 @@
<class>KUrlRequester</class>
<extends>QWidget</extends>
<header>kurlrequester.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
......
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