Commit d56aabf4 authored by Ragnar Thomsen's avatar Ragnar Thomsen

Fix handling of drag'n'drop adding files to archives

Multi-volume archives are set to read-only (only when non-empty) in
Archive class. This is needed because rar and 7z don't support modifying
such archives.
Also, a KMessageWidget is now shown when user drags files to a read-only
archive or an encrypted archive when password is unknown.

Unfortunately, we cant set encrypted archives with unknown password to
read-only, because we still want to support deleting files from them.

Differential Revision: D2274
parent 23424950
......@@ -210,7 +210,8 @@ QMimeType Archive::mimeType()
bool Archive::isReadOnly() const
{
return isValid() ? (m_iface->isReadOnly() || m_isReadOnly) : false;
return isValid() ? (m_iface->isReadOnly() || m_isReadOnly ||
(isMultiVolume() && (m_numberOfFiles > 0 || m_numberOfFolders > 0))) : false;
}
bool Archive::isSingleFolderArchive()
......
......@@ -591,6 +591,13 @@ bool ArchiveModel::dropMimeData(const QMimeData * data, Qt::DropAction action, i
return false;
}
if (archive()->isReadOnly() ||
(archive()->encryptionType() != Archive::Unencrypted &&
archive()->password().isEmpty())) {
emit messageWidget(KMessageWidget::Error, i18n("Adding files is not supported for this archive."));
return false;
}
QStringList paths;
foreach(const QUrl &url, data->urls()) {
paths << url.toLocalFile();
......
......@@ -25,6 +25,7 @@
#include <QAbstractItemModel>
#include <QScopedPointer>
#include <KMessageWidget>
#include <kjobtrackerinterface.h>
#include "kerfuffle/archive_kerfuffle.h"
......@@ -96,6 +97,7 @@ signals:
void extractionFinished(bool success);
void error(const QString& error, const QString& details);
void droppedFiles(const QStringList& files, const QString& path = QString());
void messageWidget(KMessageWidget::MessageType type, const QString& msg);
private slots:
void slotNewEntryFromSetArchive(const ArchiveEntry& entry);
......
......@@ -171,6 +171,8 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList& args)
this, static_cast<void (Part::*)(const QStringList&, const QString&)>(&Part::slotAddFiles));
connect(m_model, &ArchiveModel::error,
this, &Part::slotError);
connect(m_model, &ArchiveModel::messageWidget,
this, &Part::displayMsgWidget);
connect(this, &Part::busy,
this, &Part::setBusyGui);
......@@ -409,8 +411,7 @@ void Part::setupActions()
void Part::updateActions()
{
bool isWritable = m_model->archive() && !m_model->archive()->isReadOnly() &&
!(m_model->rowCount() > 0 && m_model->archive()->isMultiVolume());
bool isWritable = m_model->archive() && !m_model->archive()->isReadOnly();
bool isDirectory = m_model->entryForIndex(m_view->selectionModel()->currentIndex())[IsDirectory].toBool();
int selectedEntriesCount = m_view->selectionModel()->selectedRows().count();
......
......@@ -126,6 +126,7 @@ private slots:
void slotAddComment();
void slotCommentChanged();
void slotTestArchive();
void displayMsgWidget(KMessageWidget::MessageType type, const QString& msg);
signals:
void busy();
......@@ -142,7 +143,6 @@ private:
QList<QVariant> filesAndRootNodesForIndexes(const QModelIndexList& list) const;
QModelIndexList addChildren(const QModelIndexList &list) const;
void registerJob(KJob *job);
void displayMsgWidget(KMessageWidget::MessageType type, const QString& msg);
ArchiveModel *m_model;
QTreeView *m_view;
......
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