diff --git a/document/kpDocument.h b/document/kpDocument.h --- a/document/kpDocument.h +++ b/document/kpDocument.h @@ -139,7 +139,10 @@ // // e.g. If the user types "kolourpaint doesnotexist.png" to start // KolourPaint, this method will return false. - bool isFromExistingURL (bool checkURLStillExists = true) const; + bool isFromExistingURL () const; + + // Checks whether @p url still exists + bool urlExists (const QUrl &url) const; // (will convert: empty Url --> "Untitled") QString prettyUrl () const; diff --git a/document/kpDocument.cpp b/document/kpDocument.cpp --- a/document/kpDocument.cpp +++ b/document/kpDocument.cpp @@ -145,19 +145,19 @@ //--------------------------------------------------------------------- // public -bool kpDocument::isFromExistingURL (bool checkURLStillExists) const +bool kpDocument::isFromExistingURL () const { - if (!m_isFromExistingURL) { - return false; - } + return m_isFromExistingURL; +} - if (!checkURLStillExists) { - return true; - } +//--------------------------------------------------------------------- - return (!m_url.isEmpty () && - KIO::NetAccess::exists (m_url, KIO::NetAccess::SourceSide/*open*/, - d->environ->dialogParent ())); +// public +bool kpDocument::urlExists (const QUrl &url) const +{ + return (!url.isEmpty () && + KIO::NetAccess::exists (url, KIO::NetAccess::SourceSide/*open*/, + d->environ->dialogParent ())); } //--------------------------------------------------------------------- diff --git a/document/kpDocument_Open.cpp b/document/kpDocument_Open.cpp --- a/document/kpDocument_Open.cpp +++ b/document/kpDocument_Open.cpp @@ -222,9 +222,7 @@ if (newDocSameNameIfNotExist) { - if (!url.isEmpty () && - // not just a permission error? - !KIO::NetAccess::exists (url, KIO::NetAccess::SourceSide/*open*/, d->environ->dialogParent ())) + if (urlExists (url)) // not just a permission error? { openNew (url); } diff --git a/mainWindow/kpMainWindow.cpp b/mainWindow/kpMainWindow.cpp --- a/mainWindow/kpMainWindow.cpp +++ b/mainWindow/kpMainWindow.cpp @@ -376,12 +376,11 @@ // Not from URL e.g. "kolourpaint doesnotexist.png"? // // Note that "kolourpaint doesexist.png" is considered to be from - // a URL even if it was deleted in the background (hence the - // "false" arg to isFromExistingURL()). This is because the user expects + // a URL even if it was deleted in the background. This is because the user expects // it to be from a URL, so when we session restore, we pop up a // "cannot find file" dialog, instead of silently creating a new, // blank document. - if (!d->document->isFromExistingURL (false/*don't bother checking exists*/)) + if (!d->document->isFromExistingURL ()) { // If we don't have a URL either: // diff --git a/mainWindow/kpMainWindow_File.cpp b/mainWindow/kpMainWindow_File.cpp --- a/mainWindow/kpMainWindow_File.cpp +++ b/mainWindow/kpMainWindow_File.cpp @@ -57,7 +57,6 @@ #include #include #include // kdelibs4support -#include // kdelibs4support #include #include #include @@ -421,7 +420,7 @@ newDocSameNameIfNotExist); if (newDoc) { - if (newDoc->isFromExistingURL (false/*don't bother checking exists*/)) + if (newDoc->isFromExistingURL ()) addRecentURL (url); return true; } @@ -1081,7 +1080,7 @@ { int result = KMessageBox::Cancel; - if (d->document->isFromExistingURL (false/*don't bother checking exists*/) && !oldURL.isEmpty ()) + if (d->document->isFromExistingURL () && !oldURL.isEmpty ()) { result = KMessageBox::warningContinueCancel (this, i18n ("The document \"%1\" has been modified.\n" @@ -1110,9 +1109,9 @@ kpDocument *doc = nullptr; - // If it's _supposed to_ come from a URL or it exists - if (d->document->isFromExistingURL (false/*don't bother checking exists*/) || - (!oldURL.isEmpty () && KIO::NetAccess::exists (oldURL, KIO::NetAccess::SourceSide/*open*/, this))) + // If it's _supposed to_ come from an existing URL or it actually exists + if (d->document->isFromExistingURL () || + d->document->urlExists (oldURL)) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotReload() reloading from disk!"; @@ -1412,7 +1411,7 @@ toolEndShape (); if (d->document->url ().isEmpty ()/*no name*/ || - !d->document->isFromExistingURL () || + !(d->document->isFromExistingURL () && d->document->urlExists (d->document->url ())) || d->document->isModified ()/*needs to be saved*/) { int result = KMessageBox::questionYesNo (this,