Commit d6ef2fb8 authored by David Faure's avatar David Faure
Browse files

Porting away from NetAccess, step 1: code refactoring

Summary:
* Split out the NetAccess::exists call from isFromExistingURL(bool),
only one caller was passing true (the default value). Simpler to
remove that bool and call both methods in that one location.

* Provide a urlExists() method to wrap the calls to NetAccess::exists
and call it from as many places as possible.

Test Plan:
Builds, I can open and save a file, but it would take time to figure
out how to trigger all the changed code paths.

Reviewers: broulik, vkrause

Reviewed By: vkrause

Maniphest Tasks: T11576

Differential Revision: https://phabricator.kde.org/D25468
parent 9f03f67e
......@@ -145,19 +145,19 @@ void kpDocument::setURL (const QUrl &url, bool isFromExistingURL)
//---------------------------------------------------------------------
// 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 ()));
}
//---------------------------------------------------------------------
......
......@@ -139,7 +139,10 @@ public:
//
// 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;
......
......@@ -222,9 +222,7 @@ bool kpDocument::open (const QUrl &url, bool newDocSameNameIfNotExist)
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);
}
......
......@@ -376,12 +376,11 @@ void kpMainWindow::saveProperties (KConfigGroup &configGroup)
// 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:
//
......
......@@ -57,7 +57,6 @@
#include <kconfiggroup.h>
#include <KPluralHandlingSpinBox>
#include <kfiledialog.h> // kdelibs4support
#include <kio/netaccess.h> // kdelibs4support
#include <kmessagebox.h>
#include <krecentfilesaction.h>
#include <kstandardshortcut.h>
......@@ -421,7 +420,7 @@ bool kpMainWindow::open (const QUrl &url, bool newDocSameNameIfNotExist)
newDocSameNameIfNotExist);
if (newDoc)
{
if (newDoc->isFromExistingURL (false/*don't bother checking exists*/))
if (newDoc->isFromExistingURL ())
addRecentURL (url);
return true;
}
......@@ -1081,7 +1080,7 @@ bool kpMainWindow::slotReload ()
{
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 @@ bool kpMainWindow::slotReload ()
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 @@ void kpMainWindow::slotMail ()
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,
......
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