Changeset View
Changeset View
Standalone View
Standalone View
importer/importer.cpp
Show All 19 Lines | |||||
20 | */ | 20 | */ | ||
21 | // Self | 21 | // Self | ||
22 | #include "importer.h" | 22 | #include "importer.h" | ||
23 | 23 | | |||
24 | // Qt | 24 | // Qt | ||
25 | #include <QDateTime> | 25 | #include <QDateTime> | ||
26 | #include <QDebug> | 26 | #include <QDebug> | ||
27 | #include <QUrl> | 27 | #include <QUrl> | ||
28 | #include <QTemporaryDir> | ||||
28 | 29 | | |||
29 | // KDE | 30 | // KDE | ||
30 | #include <KFileItem> | 31 | #include <KFileItem> | ||
31 | #include <KIO/CopyJob> | 32 | #include <KIO/CopyJob> | ||
32 | #include <KIO/DeleteJob> | 33 | #include <KIO/DeleteJob> | ||
33 | #include <KIO/Job> | 34 | #include <KIO/Job> | ||
34 | #include <KIO/JobUiDelegate> | 35 | #include <KIO/JobUiDelegate> | ||
35 | #include <KJobWidgets> | 36 | #include <KJobWidgets> | ||
Show All 12 Lines | |||||
48 | { | 49 | { | ||
49 | 50 | | |||
50 | struct ImporterPrivate | 51 | struct ImporterPrivate | ||
51 | { | 52 | { | ||
52 | Importer* q; | 53 | Importer* q; | ||
53 | QWidget* mAuthWindow; | 54 | QWidget* mAuthWindow; | ||
54 | std::unique_ptr<FileNameFormater> mFileNameFormater; | 55 | std::unique_ptr<FileNameFormater> mFileNameFormater; | ||
55 | QUrl mTempImportDirUrl; | 56 | QUrl mTempImportDirUrl; | ||
57 | QTemporaryDir* mTempImportDir; | ||||
56 | 58 | | |||
57 | /* @defgroup reset Should be reset in start() | 59 | /* @defgroup reset Should be reset in start() | ||
58 | * @{ */ | 60 | * @{ */ | ||
59 | QList<QUrl> mUrlList; | 61 | QList<QUrl> mUrlList; | ||
60 | QList<QUrl> mImportedUrlList; | 62 | QList<QUrl> mImportedUrlList; | ||
61 | QList<QUrl> mSkippedUrlList; | 63 | QList<QUrl> mSkippedUrlList; | ||
62 | int mRenamedCount; | 64 | int mRenamedCount; | ||
63 | int mProgress; | 65 | int mProgress; | ||
64 | int mJobProgress; | 66 | int mJobProgress; | ||
65 | /* @} */ | 67 | /* @} */ | ||
66 | 68 | | |||
67 | QUrl mCurrentUrl; | 69 | QUrl mCurrentUrl; | ||
68 | 70 | | |||
69 | bool createImportDir(const QUrl& url) | 71 | bool createImportDir(const QUrl& url) | ||
70 | { | 72 | { | ||
71 | Q_ASSERT(url.isLocalFile()); | 73 | Q_ASSERT(url.isLocalFile()); | ||
72 | // FIXME: Support remote urls | 74 | // FIXME: Support remote urls | ||
73 | 75 | | |||
74 | if (!QDir().mkpath(url.toLocalFile())) { | 76 | if (!QDir().mkpath(url.toLocalFile())) { | ||
75 | emit q->error(i18n("Could not create destination folder.")); | 77 | emit q->error(i18n("Could not create destination folder.")); | ||
76 | return false; | 78 | return false; | ||
77 | } | 79 | } | ||
78 | QString message; | 80 | | ||
79 | QString dir = FileUtils::createTempDir(url.toLocalFile(), ".gwenview_importer-", &message); | 81 | QString tempDirPath = url.toLocalFile() + "/.gwenview_importer-XXXXXX"; | ||
80 | mTempImportDirUrl = QUrl::fromLocalFile(dir); | 82 | mTempImportDir = new QTemporaryDir(tempDirPath); | ||
81 | if (mTempImportDirUrl.isEmpty()) { | 83 | | ||
82 | emit q->error(i18n("Could not create temporary upload folder:\n%1", message)); | 84 | if (!mTempImportDir->isValid()) { | ||
85 | emit q->error(i18n("Could not create temporary upload folder.")); | ||||
86 | return false; | ||||
87 | } | ||||
88 | | ||||
89 | mTempImportDirUrl = QUrl::fromLocalFile(mTempImportDir->path() + '/'); | ||||
90 | if (!mTempImportDirUrl.isValid()) { | ||||
91 | emit q->error(i18n("Could not create temporary upload folder.")); | ||||
83 | return false; | 92 | return false; | ||
84 | } | 93 | } | ||
94 | | ||||
85 | return true; | 95 | return true; | ||
86 | } | 96 | } | ||
87 | 97 | | |||
88 | void importNext() | 98 | void importNext() | ||
89 | { | 99 | { | ||
90 | if (mUrlList.empty()) { | 100 | if (mUrlList.empty()) { | ||
91 | q->finalizeImport(); | 101 | q->finalizeImport(); | ||
92 | return; | 102 | return; | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 198 | if (job->error()) { | |||
192 | return; | 202 | return; | ||
193 | } | 203 | } | ||
194 | 204 | | |||
195 | d->renameImportedUrl(url); | 205 | d->renameImportedUrl(url); | ||
196 | } | 206 | } | ||
197 | 207 | | |||
198 | void Importer::finalizeImport() | 208 | void Importer::finalizeImport() | ||
199 | { | 209 | { | ||
200 | KIO::Job* job = KIO::del(d->mTempImportDirUrl, KIO::HideProgressInfo); | 210 | delete d->mTempImportDir; | ||
201 | KJobWidgets::setWindow(job, d->mAuthWindow); | | |||
202 | emit importFinished(); | 211 | emit importFinished(); | ||
203 | } | 212 | } | ||
204 | 213 | | |||
205 | void Importer::advance() | 214 | void Importer::advance() | ||
206 | { | 215 | { | ||
207 | ++d->mProgress; | 216 | ++d->mProgress; | ||
208 | d->mJobProgress = 0; | 217 | d->mJobProgress = 0; | ||
209 | emitProgressChanged(); | 218 | emitProgressChanged(); | ||
Show All 29 Lines |