diff --git a/importer/dialogpage.h b/importer/dialogpage.h --- a/importer/dialogpage.h +++ b/importer/dialogpage.h @@ -46,6 +46,11 @@ int addButton(const KGuiItem&); int exec(); +public Q_SLOTS: + void slotShowErrors(const QStringList&, const QStringList&); + void slotShowFailedFileDetails(); + void slotShowFailedDirDetails(); + private: DialogPagePrivate* const d; }; diff --git a/importer/dialogpage.cpp b/importer/dialogpage.cpp --- a/importer/dialogpage.cpp +++ b/importer/dialogpage.cpp @@ -26,12 +26,15 @@ #include #include #include +#include // KDE #include +#include // Local #include +#include "importdialog.h" namespace Gwenview { @@ -41,14 +44,81 @@ QVBoxLayout* mLayout; QList mButtons; QEventLoop* mEventLoop; + DialogPage* q; + QStringList failedFileList; + QStringList failedDirList; + QAction* fileDetails; + QAction* dirDetails; + + void setupFailedListActions() + { + fileDetails = new QAction("Show failed files..."); + mErrorMessageWidget->addAction(fileDetails); + QObject::connect(fileDetails, &QAction::triggered, + q, &DialogPage::slotShowFailedFileDetails); + fileDetails->setVisible(false); + + dirDetails = new QAction("Show failed subfolders..."); + mErrorMessageWidget->addAction(dirDetails); + QObject::connect(dirDetails, &QAction::triggered, + q, &DialogPage::slotShowFailedDirDetails); + dirDetails->setVisible(false); + } + + void showErrors(const QStringList& files, const QStringList& dirs) + { + mErrorMessageWidget->setVisible(true); + failedFileList.clear(); + failedDirList.clear(); + QStringList message; + if (files.count() > 0) { + failedFileList = files; + message << i18np("Failed to import one document.", + "Failed to import %1 documents.", + files.count()); + fileDetails->setVisible(true); + } else fileDetails->setVisible(false); + + if (dirs.count() > 0) { + failedDirList = dirs; + message << i18np("Failed to create one destination subfolder.", + "Failed to create %1 destination subfolders.", + dirs.count()); + dirDetails->setVisible(true); + } else dirDetails->setVisible(false); + + mErrorMessageWidget->setText("" + message.join("
") + ""); + mErrorMessageWidget->animatedShow(); + } + + void showFailedFileDetails() + { + QString message = "Failed to import documents:"; + KMessageBox::errorList(q, + message, + failedFileList + ); + } + + void showFailedDirDetails() + { + QString message = "Failed to create subfolders:"; + KMessageBox::errorList(q, + message, + failedDirList + ); + } }; DialogPage::DialogPage(QWidget* parent) : QWidget(parent) , d(new DialogPagePrivate) { + d->q = this; d->setupUi(this); d->mLayout = new QVBoxLayout(d->mButtonContainer); + d->setupFailedListActions(); + d->mErrorMessageWidget->hide(); } DialogPage::~DialogPage() @@ -82,6 +152,21 @@ return id; } +void DialogPage::slotShowErrors(const QStringList& files, const QStringList& dirs) +{ + d->showErrors(files, dirs); +} + +void DialogPage::slotShowFailedFileDetails() +{ + d->showFailedFileDetails(); +} + +void DialogPage::slotShowFailedDirDetails() +{ + d->showFailedDirDetails(); +} + int DialogPage::exec() { QEventLoop loop; diff --git a/importer/dialogpage.ui b/importer/dialogpage.ui --- a/importer/dialogpage.ui +++ b/importer/dialogpage.ui @@ -6,18 +6,28 @@ 0 0 - 400 - 239 + 355 + 287 - - + + Qt::Vertical - - QSizePolicy::Expanding + + + 20 + 55 + + + + + + + + Qt::Vertical @@ -27,7 +37,7 @@ - + Qt::Horizontal @@ -40,7 +50,7 @@ - + @@ -70,7 +80,7 @@ - + Qt::Horizontal @@ -83,34 +93,44 @@ - - + + Qt::Vertical + + QSizePolicy::Expanding + 20 - 55 + 40 - - - - Qt::Vertical + + + + + 0 + 0 + - - - 20 - 40 - + + KMessageWidget::Error - + + + + KMessageWidget + QFrame +
kmessagewidget.h
+
+
diff --git a/importer/importdialog.h b/importer/importdialog.h --- a/importer/importdialog.h +++ b/importer/importdialog.h @@ -50,6 +50,9 @@ void slotImportFinished(); void showImportError(const QString&); +Q_SIGNALS: + void showErrors(const QStringList&, const QStringList&); + private: ImportDialogPrivate* const d; }; diff --git a/importer/importdialog.cpp b/importer/importdialog.cpp --- a/importer/importdialog.cpp +++ b/importer/importdialog.cpp @@ -58,6 +58,25 @@ DialogPage* mDialogPage; Importer* mImporter; + void checkForFailedUrls() + { + // First check for errors on file imports or subfolder creation + QList failedUrls = mImporter->failedUrlList(); + QList failedSubFolders = mImporter->failedSubFolderList(); + int failedUrlCount = failedUrls.count(); + int failedSubFolderCount = failedSubFolders.count(); + if (failedUrlCount + failedSubFolderCount > 0) { + QStringList files, dirs; + for (int i=0; ishowErrors(files, dirs); + } + } + void deleteImportedUrls() { QList importedUrls = mImporter->importedUrlList(); @@ -204,6 +223,8 @@ this, &QWidget::close); connect(d->mImporter, &Importer::importFinished, this, &ImportDialog::slotImportFinished); + connect(this, &ImportDialog::showErrors, + d->mDialogPage, &DialogPage::slotShowErrors); d->mCentralWidget->setCurrentWidget(d->mThumbnailPage); @@ -254,6 +275,7 @@ void ImportDialog::slotImportFinished() { + d->checkForFailedUrls(); d->deleteImportedUrls(); d->showWhatNext(); } diff --git a/importer/importer.h b/importer/importer.h --- a/importer/importer.h +++ b/importer/importer.h @@ -57,6 +57,16 @@ */ QList skippedUrlList() const; + /** + * Documents which have failed during import + */ + QList failedUrlList() const; + + /** + * Subfolders which failed to create during import + */ + QList failedSubFolderList() const; + /** * How many documents have been renamed during import */ diff --git a/importer/importer.cpp b/importer/importer.cpp --- a/importer/importer.cpp +++ b/importer/importer.cpp @@ -62,6 +62,8 @@ QList mUrlList; QList mImportedUrlList; QList mSkippedUrlList; + QList mFailedUrlList; + QList mFailedSubFolderList; int mRenamedCount; int mProgress; int mJobProgress; @@ -138,6 +140,9 @@ KJobWidgets::setWindow(job,mAuthWindow); if (!job->exec()) { // if subfolder creation fails qWarning() << "Could not create subfolder:" << subFolder; + if (!mFailedSubFolderList.contains(subFolder)) { + mFailedSubFolderList << subFolder; + } result = FileUtils::RenameFailed; } else { // if subfolder creation succeeds result = FileUtils::rename(src, dst, mAuthWindow); @@ -155,6 +160,7 @@ mSkippedUrlList << mCurrentUrl; break; case FileUtils::RenameFailed: + mFailedUrlList << mCurrentUrl; qWarning() << "Rename failed for" << mCurrentUrl; } q->advance(); @@ -189,6 +195,8 @@ d->mUrlList = list; d->mImportedUrlList.clear(); d->mSkippedUrlList.clear(); + d->mFailedUrlList.clear(); + d->mFailedSubFolderList.clear(); d->mRenamedCount = 0; d->mProgress = 0; d->mJobProgress = 0; @@ -208,7 +216,8 @@ KIO::CopyJob* job = static_cast(_job); QUrl url = job->destUrl(); if (job->error()) { - qWarning() << "FIXME: What do we do with failed urls?"; + // Add document to failed url list and proceed with next one + d->mFailedUrlList << d->mCurrentUrl; advance(); d->importNext(); return; @@ -251,6 +260,16 @@ return d->mSkippedUrlList; } +QList Importer::failedUrlList() const +{ + return d->mFailedUrlList; +} + +QList Importer::failedSubFolderList() const +{ + return d->mFailedSubFolderList; +} + int Importer::renamedCount() const { return d->mRenamedCount;