diff --git a/lgpl/generic/kpColorCollection.h b/lgpl/generic/kpColorCollection.h --- a/lgpl/generic/kpColorCollection.h +++ b/lgpl/generic/kpColorCollection.h @@ -112,7 +112,7 @@ // name() is set to an empty string. // // Added for KolourPaint. - bool saveAs(const QUrl &url, bool showOverwritePrompt, QWidget *parent) const; + bool saveAs(const QUrl &url, QWidget *parent) const; /** * Save the collection to the KDE-local store diff --git a/lgpl/generic/kpColorCollection.cpp b/lgpl/generic/kpColorCollection.cpp --- a/lgpl/generic/kpColorCollection.cpp +++ b/lgpl/generic/kpColorCollection.cpp @@ -30,7 +30,8 @@ #include "kpUrlFormatter.h" -#include // kdelibs4support +#include +#include #include #include #include "kpLogCategories.h" @@ -124,36 +125,30 @@ bool kpColorCollection::open(const QUrl &url, QWidget *parent) { - QString tempPaletteFilePath; - if (url.isEmpty () || !KIO::NetAccess::download (url, tempPaletteFilePath, parent)) - { - #if DEBUG_KP_COLOR_COLLECTION - qCDebug(kpLogColorCollection) << "\tcould not download"; - #endif - ::CouldNotOpenDialog (url, parent); - return false; - } + if (url.isEmpty()) { + return false; + } - // sync: remember to "KIO::NetAccess::removeTempFile (tempPaletteFilePath)" in all exit paths + KIO::StoredTransferJob *job = KIO::storedGet (url); + KJobWidgets::setWindow (job, parent); - QFile paletteFile(tempPaletteFilePath); - if (!paletteFile.exists() || - !paletteFile.open(QIODevice::ReadOnly)) - { - #if DEBUG_KP_COLOR_COLLECTION - qCDebug(kpLogColorCollection) << "\tcould not open qfile"; - #endif - KIO::NetAccess::removeTempFile (tempPaletteFilePath); - ::CouldNotOpenDialog (url, parent); - return false; - } + if (!job->exec ()) + { +#if DEBUG_KP_COLOR_COLLECTION + qCDebug(kpLogColorCollection) << "\tcould not download"; +#endif + ::CouldNotOpenDialog (url, parent); + return false; + } + + const QByteArray &data = job->data(); + QTextStream stream(data); // Read first line // Expected "GIMP Palette" - QString line = QString::fromLocal8Bit(paletteFile.readLine()); + QString line = stream.readLine(); if (line.indexOf(QLatin1String(" Palette")) == -1) { - KIO::NetAccess::removeTempFile (tempPaletteFilePath); KMessageBox::sorry (parent, i18n ("Could not open color palette \"%1\" - unsupported format.\n" "The file may be corrupt.", @@ -164,9 +159,9 @@ QList newColorList; QString newDesc; - while( !paletteFile.atEnd() ) + while( !stream.atEnd() ) { - line = QString::fromLocal8Bit(paletteFile.readLine()); + line = stream.readLine(); if (line[0] == '#') { // This is a comment line @@ -199,7 +194,6 @@ d->name.clear (); d->desc = newDesc; - KIO::NetAccess::removeTempFile (tempPaletteFilePath); return true; } @@ -286,22 +280,8 @@ } bool -kpColorCollection::saveAs(const QUrl &url, bool showOverwritePrompt, - QWidget *parent) const +kpColorCollection::saveAs(const QUrl &url, QWidget *parent) const { - if (showOverwritePrompt && - KIO::NetAccess::exists (url, KIO::NetAccess::DestinationSide/*write*/, parent)) - { - int result = KMessageBox::warningContinueCancel (parent, - i18n ("A color palette called \"%1\" already exists.\n" - "Do you want to overwrite it?", - kpUrlFormatter::PrettyFilename (url)), - QString (), - KStandardGuiItem::overwrite ()); - if (result != KMessageBox::Continue) - return false; - } - if (url.isLocalFile ()) { const QString filename = url.toLocalFile (); @@ -379,10 +359,12 @@ } // Copy local temporary file to overwrite remote. - // TODO: No one seems to know how to do this atomically - // [http://lists.kde.org/?l=kde-core-devel&m=117845162728484&w=2]. - // At least, fish:// (ssh) is definitely not atomic. - if (!KIO::NetAccess::upload (tempFileName, url, parent)) + KIO::FileCopyJob *job = KIO::file_copy (QUrl::fromLocalFile (tempFileName), + url, + -1, + KIO::Overwrite); + KJobWidgets::setWindow (job, parent); + if (!job->exec ()) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "\treturning false because could not upload"; @@ -402,7 +384,7 @@ const QString name = d->name; QString filename = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "colors/" + name; - const bool ret = saveAs (QUrl::fromLocalFile (filename), false/*no overwite prompt*/, parent); + const bool ret = saveAs (QUrl::fromLocalFile (filename), parent); // (d->name is wiped by saveAs()). d->name = name; return ret; diff --git a/mainWindow/kpMainWindow_Colors.cpp b/mainWindow/kpMainWindow_Colors.cpp --- a/mainWindow/kpMainWindow_Colors.cpp +++ b/mainWindow/kpMainWindow_Colors.cpp @@ -452,6 +452,7 @@ fd.setDirectoryUrl(colorCells ()->url()); fd.setWindowTitle(i18n("Save Color Palette As")); fd.setAcceptMode(QFileDialog::AcceptSave); + // Note that QFileDialog takes care of asking the user to confirm overwriting. if (fd.exec ()) { diff --git a/widgets/kpColorCells.cpp b/widgets/kpColorCells.cpp --- a/widgets/kpColorCells.cpp +++ b/widgets/kpColorCells.cpp @@ -447,7 +447,7 @@ bool kpColorCells::saveColorCollectionAs (const QUrl &url) { // (this will pop up an error dialog on failure) - if (d->colorCol.saveAs (url, true/*show overwrite prompt*/, this)) + if (d->colorCol.saveAs (url, this)) { d->url = url; setModified (false); @@ -464,7 +464,7 @@ bool kpColorCells::saveColorCollection () { // (this will pop up an error dialog on failure) - if (d->colorCol.saveAs (d->url, false/*no overwrite prompt*/, this)) + if (d->colorCol.saveAs (d->url, this)) { setModified (false); return true;