Index: document/kpDocument.h =================================================================== --- document/kpDocument.h +++ document/kpDocument.h @@ -111,13 +111,11 @@ const QUrl &url, const kpDocumentSaveOptions &saveOptions, const kpDocumentMetaInfo &metaInfo, - bool overwritePrompt, bool lossyPrompt, QWidget *parent); - bool save (bool overwritePrompt = false, bool lossyPrompt = false); + bool save (bool lossyPrompt = false); bool saveAs (const QUrl &url, const kpDocumentSaveOptions &saveOptions, - bool overwritePrompt = true, bool lossyPrompt = true); Index: document/kpDocumentSaveOptions.cpp =================================================================== --- document/kpDocumentSaveOptions.cpp +++ document/kpDocumentSaveOptions.cpp @@ -157,6 +157,7 @@ // public void kpDocumentSaveOptions::setMimeType (const QString &mimeType) { + Q_ASSERT(mimeType.isEmpty () || mimeType.contains ('/')); d->m_mimeType = mimeType; } Index: document/kpDocument_Save.cpp =================================================================== --- document/kpDocument_Save.cpp +++ document/kpDocument_Save.cpp @@ -67,11 +67,10 @@ #include "views/manager/kpViewManager.h" -bool kpDocument::save (bool overwritePrompt, bool lossyPrompt) +bool kpDocument::save (bool lossyPrompt) { #if DEBUG_KP_DOCUMENT qCDebug(kpLogDocument) << "kpDocument::save(" - << "overwritePrompt=" << overwritePrompt << ",lossyPrompt=" << lossyPrompt << ") url=" << m_url << " savedAtLeastOnceBefore=" << savedAtLeastOnceBefore (); @@ -93,7 +92,6 @@ } return saveAs (m_url, *m_saveOptions, - overwritePrompt, lossyPrompt); } @@ -311,7 +309,6 @@ const QUrl &url, const kpDocumentSaveOptions &saveOptions, const kpDocumentMetaInfo &metaInfo, - bool overwritePrompt, bool lossyPrompt, QWidget *parent) { @@ -321,39 +318,12 @@ #if DEBUG_KP_DOCUMENT qCDebug(kpLogDocument) << "kpDocument::savePixmapToFile (" << url - << ",overwritePrompt=" << overwritePrompt << ",lossyPrompt=" << lossyPrompt << ")"; saveOptions.printDebug (QLatin1String ("\tsaveOptions")); metaInfo.printDebug (QLatin1String ("\tmetaInfo")); #endif - if (overwritePrompt) - { - // A probably better solution would be to do file_copy without Overwrite, - // and on "already exists" error, prompt and redo file_copy with Overwrite. - KIO::StatJob *job = KIO::stat (url, KIO::StatJob::DestinationSide/*write*/, 0); - KJobWidgets::setWindow (job, parent); - if (job->exec ()) { - int result = KMessageBox::warningContinueCancel (parent, - i18n ("A document called \"%1\" already exists.\n" - "Do you want to overwrite it?", - kpUrlFormatter::PrettyFilename (url)), - QString(), - KStandardGuiItem::overwrite ()); - - if (result != KMessageBox::Continue) - { - #if DEBUG_KP_DOCUMENT - qCDebug(kpLogDocument) << "\tuser doesn't want to overwrite"; - #endif - - return false; - } - } - } - - if (lossyPrompt && !lossyPromptContinue (pixmap, saveOptions, parent)) { #if DEBUG_KP_DOCUMENT @@ -490,7 +460,6 @@ bool kpDocument::saveAs (const QUrl &url, const kpDocumentSaveOptions &saveOptions, - bool overwritePrompt, bool lossyPrompt) { #if DEBUG_KP_DOCUMENT @@ -501,7 +470,6 @@ if (kpDocument::savePixmapToFile (imageWithSelection (), url, saveOptions, *metaInfo (), - overwritePrompt, lossyPrompt, d->environ->dialogParent ())) { Index: mainWindow/kpMainWindow.h =================================================================== --- mainWindow/kpMainWindow.h +++ mainWindow/kpMainWindow.h @@ -354,7 +354,6 @@ bool localOnly, kpDocumentSaveOptions *chosenSaveOptions, bool isSavingForFirstTime, - bool *allowOverwritePrompt, bool *allowLossyPrompt); private slots: Index: mainWindow/kpMainWindow_Edit.cpp =================================================================== --- mainWindow/kpMainWindow_Edit.cpp +++ mainWindow/kpMainWindow_Edit.cpp @@ -854,7 +854,7 @@ kpDocumentSaveOptions chosenSaveOptions; - bool allowOverwritePrompt, allowLossyPrompt; + bool allowLossyPrompt; QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Copy to File"), d->lastCopyToURL.url (), imageToSave, @@ -864,7 +864,6 @@ false/*allow remote files*/, &chosenSaveOptions, d->copyToFirstTime, - &allowOverwritePrompt, &allowLossyPrompt); if (chosenURL.isEmpty ()) { @@ -875,7 +874,6 @@ if (!kpDocument::savePixmapToFile (imageToSave, chosenURL, chosenSaveOptions, kpDocumentMetaInfo (), - allowOverwritePrompt, allowLossyPrompt, this)) { Index: mainWindow/kpMainWindow_File.cpp =================================================================== --- mainWindow/kpMainWindow_File.cpp +++ mainWindow/kpMainWindow_File.cpp @@ -56,7 +56,6 @@ #include #include #include -#include // kdelibs4support #include #include #include @@ -746,8 +745,7 @@ return saveAs (localOnly); } - if (d->document->save (false/*no overwrite prompt*/, - !d->document->savedAtLeastOnceBefore ()/*lossy prompt*/)) + if (d->document->save (!d->document->savedAtLeastOnceBefore ()/*lossy prompt*/)) { addRecentURL (d->document->url ()); return true; @@ -778,7 +776,6 @@ bool localOnly, kpDocumentSaveOptions *chosenSaveOptions, bool isSavingForFirstTime, - bool *allowOverwritePrompt, bool *allowLossyPrompt) { #if DEBUG_KP_MAIN_WINDOW @@ -805,10 +802,6 @@ *chosenSaveOptions = kpDocumentSaveOptions (); } - if (allowOverwritePrompt) { - *allowOverwritePrompt = true; // play it safe for now - } - if (allowLossyPrompt) { *allowLossyPrompt = true; // play it safe for now } @@ -889,18 +882,27 @@ docMetaInfo, this); - KFileDialog fd (QUrl (startURL), QString(), this, - saveOptionsWidget); - saveOptionsWidget->setVisualParent (&fd); + QFileDialog fd(this); + fd.setAcceptMode (QFileDialog::AcceptSave); + fd.setOption (QFileDialog::DontUseNativeDialog); + fd.setDirectoryUrl (QUrl (startURL)); fd.setWindowTitle (caption); - fd.setOperationMode (KFileDialog::Saving); - fd.setMimeFilter (mimeTypes, fdSaveOptions.mimeType ()); + fd.setMimeTypeFilters (mimeTypes); + fd.selectMimeTypeFilter (fdSaveOptions.mimeType ()); if (localOnly) { - fd.setMode (KFile::File | KFile::LocalOnly); + fd.setSupportedSchemes ({QStringLiteral("file")}); + } + + // insert the checkbox below the filter box + if (QGridLayout* gl = qobject_cast(fd.layout ())) { + gl->addWidget (saveOptionsWidget, gl->rowCount (), 0, 1, gl->columnCount ()); } + saveOptionsWidget->setVisualParent (&fd); - connect (&fd, &KFileDialog::filterChanged, - saveOptionsWidget, &kpDocumentSaveOptionsWidget::setMimeType); + connect (&fd, &QFileDialog::filterSelected, + this, [saveOptionsWidget, &fd]() { + saveOptionsWidget->setMimeType(fd.selectedMimeTypeFilter()); + }); if ( fd.exec() == QDialog::Accepted ) { @@ -921,26 +923,20 @@ *chosenSaveOptions = newSaveOptions; } - - bool shouldAllowOverwritePrompt = - (fd.selectedUrl () != QUrl (startURL) || - newSaveOptions.mimeType () != startSaveOptions.mimeType ()); - if (allowOverwritePrompt) - { - *allowOverwritePrompt = shouldAllowOverwritePrompt; - #if DEBUG_KP_MAIN_WINDOW - qCDebug(kpLogMainWindow) << "\tallowOverwritePrompt=" << *allowOverwritePrompt; - #endif + const QList selectedUrls = fd.selectedUrls (); + if (selectedUrls.isEmpty()) { // shouldn't happen + return {}; } + const QUrl selectedUrl = selectedUrls.at(0); if (allowLossyPrompt) { // SYNC: kpDocumentSaveOptions elements - everything except quality // (one quality setting is "just as lossy" as another so no // need to continually warn due to quality change) *allowLossyPrompt = (isSavingForFirstTime || - shouldAllowOverwritePrompt || + selectedUrl != QUrl (startURL) || newSaveOptions.mimeType () != startSaveOptions.mimeType () || newSaveOptions.colorDepth () != startSaveOptions.colorDepth () || newSaveOptions.dither () != startSaveOptions.dither ()); @@ -951,9 +947,9 @@ #if DEBUG_KP_MAIN_WINDOW - qCDebug(kpLogMainWindow) << "\tselectedUrl=" << fd.selectedUrl (); + qCDebug(kpLogMainWindow) << "\tselectedUrl=" << selectedUrl; #endif - return fd.selectedUrl (); + return selectedUrl; } return {}; @@ -966,7 +962,7 @@ bool kpMainWindow::saveAs (bool localOnly) { kpDocumentSaveOptions chosenSaveOptions; - bool allowOverwritePrompt, allowLossyPrompt; + bool allowLossyPrompt; QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Save Image As"), d->document->url ().url (), d->document->imageWithSelection (), @@ -976,7 +972,6 @@ localOnly, &chosenSaveOptions, !d->document->savedAtLeastOnceBefore (), - &allowOverwritePrompt, &allowLossyPrompt); @@ -986,7 +981,6 @@ if (!d->document->saveAs (chosenURL, chosenSaveOptions, - allowOverwritePrompt, allowLossyPrompt)) { return false; @@ -1016,7 +1010,7 @@ toolEndShape (); kpDocumentSaveOptions chosenSaveOptions; - bool allowOverwritePrompt, allowLossyPrompt; + bool allowLossyPrompt; QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Export"), d->lastExportURL.url (), d->document->imageWithSelection (), @@ -1026,7 +1020,6 @@ false/*allow remote files*/, &chosenSaveOptions, d->exportFirstTime, - &allowOverwritePrompt, &allowLossyPrompt); @@ -1037,7 +1030,6 @@ if (!kpDocument::savePixmapToFile (d->document->imageWithSelection (), chosenURL, chosenSaveOptions, *d->document->metaInfo (), - allowOverwritePrompt, allowLossyPrompt, this)) {