mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-24 02:42:52 +00:00
gwenview: simplify the save job
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
984399a1dc
commit
5449379ca6
1 changed files with 11 additions and 26 deletions
|
@ -46,7 +46,6 @@ struct SaveJobPrivate
|
||||||
KUrl mOldUrl;
|
KUrl mOldUrl;
|
||||||
KUrl mNewUrl;
|
KUrl mNewUrl;
|
||||||
QByteArray mFormat;
|
QByteArray mFormat;
|
||||||
QString mTemporaryFile;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SaveJob::SaveJob(DocumentLoadedImpl* impl, const KUrl& url, const QByteArray& format)
|
SaveJob::SaveJob(DocumentLoadedImpl* impl, const KUrl& url, const QByteArray& format)
|
||||||
|
@ -65,36 +64,22 @@ SaveJob::~SaveJob()
|
||||||
|
|
||||||
void SaveJob::doStart()
|
void SaveJob::doStart()
|
||||||
{
|
{
|
||||||
setError(NoError);
|
const QString temporaryFileTemplate = QString::fromLatin1("XXXXXXXXXX.%1").arg(d->mFormat.constData());
|
||||||
{
|
const QString temporaryFile = KTemporaryFile::filePath(temporaryFileTemplate);
|
||||||
QScopedPointer<KTemporaryFile> temporaryFile(new KTemporaryFile());
|
if (!d->mImpl->saveInternal(temporaryFile, d->mFormat)) {
|
||||||
temporaryFile->setAutoRemove(true);
|
QFile::remove(temporaryFile);
|
||||||
temporaryFile->setSuffix(QString::fromLatin1(".%1").arg(d->mFormat.constData()));
|
|
||||||
|
|
||||||
if (!temporaryFile->open()) {
|
|
||||||
KUrl dirUrl = d->mNewUrl;
|
|
||||||
dirUrl.setFileName(QString());
|
|
||||||
setError(UserDefinedError + 1);
|
|
||||||
setErrorText(i18nc("@info", "Could not open file for writing, check that you have the necessary rights in <filename>%1</filename>.", dirUrl.pathOrUrl()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
d->mTemporaryFile = temporaryFile->fileName();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!d->mImpl->saveInternal(d->mTemporaryFile, d->mFormat)) {
|
|
||||||
QFile::remove(d->mTemporaryFile);
|
|
||||||
setError(UserDefinedError + 2);
|
setError(UserDefinedError + 2);
|
||||||
setErrorText(d->mImpl->document()->errorString());
|
setErrorText(d->mImpl->document()->errorString());
|
||||||
|
emitResult();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// qDebug() << Q_FUNC_INFO << error() << d->mTemporaryFile << d->mNewUrl;
|
// qDebug() << Q_FUNC_INFO << error() << temporaryFile << d->mNewUrl;
|
||||||
emitResult(); // nope, this does not sunder the sub-job
|
emitResult(); // nope, this does not sunder the sub-job
|
||||||
if (!error()) {
|
// whether to overwite has already been asked for
|
||||||
// whether to overwite has already been asked for
|
KIO::Job* job = KIO::move(KUrl::fromPath(temporaryFile), d->mNewUrl, KIO::Overwrite);
|
||||||
KIO::Job* job = KIO::move(KUrl::fromPath(d->mTemporaryFile), d->mNewUrl, KIO::Overwrite);
|
job->setUiDelegate(uiDelegate());
|
||||||
job->setUiDelegate(uiDelegate());
|
KIO::NetAccess::synchronousRun(job, KApplication::kApplication()->activeWindow());
|
||||||
KIO::NetAccess::synchronousRun(job, KApplication::kApplication()->activeWindow());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KUrl SaveJob::oldUrl() const
|
KUrl SaveJob::oldUrl() const
|
||||||
|
|
Loading…
Add table
Reference in a new issue