Changeset View
Changeset View
Standalone View
Standalone View
krusader/FileSystem/virtualfilesystem.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
42 | #include "../krglobal.h" | 42 | #include "../krglobal.h" | ||
43 | #include "../krservices.h" | 43 | #include "../krservices.h" | ||
44 | 44 | | |||
45 | #define VIRTUALFILESYSTEM_DB "virtualfilesystem.db" | 45 | #define VIRTUALFILESYSTEM_DB "virtualfilesystem.db" | ||
46 | 46 | | |||
47 | QHash<QString, QList<QUrl> *> VirtualFileSystem::_virtFilesystemDict; | 47 | QHash<QString, QList<QUrl> *> VirtualFileSystem::_virtFilesystemDict; | ||
48 | QHash<QString, QString> VirtualFileSystem::_metaInfoDict; | 48 | QHash<QString, QString> VirtualFileSystem::_metaInfoDict; | ||
49 | 49 | | |||
50 | VirtualFileSystem::VirtualFileSystem() : FileSystem() | 50 | VirtualFileSystem::VirtualFileSystem() | ||
51 | { | 51 | { | ||
52 | if (_virtFilesystemDict.isEmpty()) { | 52 | if (_virtFilesystemDict.isEmpty()) { | ||
53 | restore(); | 53 | restore(); | ||
54 | } | 54 | } | ||
55 | 55 | | |||
56 | _type = FS_VIRTUAL; | 56 | _type = FS_VIRTUAL; | ||
57 | } | 57 | } | ||
58 | 58 | | |||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 105 | if (parentDir == "/") { // remove virtual directory | |||
106 | for (const QString &filename : fileNames) { | 106 | for (const QString &filename : fileNames) { | ||
107 | _virtFilesystemDict["/"]->removeAll(QUrl(QStringLiteral("virt:/") + filename)); | 107 | _virtFilesystemDict["/"]->removeAll(QUrl(QStringLiteral("virt:/") + filename)); | ||
108 | delete _virtFilesystemDict[filename]; | 108 | delete _virtFilesystemDict[filename]; | ||
109 | _virtFilesystemDict.remove(filename); | 109 | _virtFilesystemDict.remove(filename); | ||
110 | _metaInfoDict.remove(filename); | 110 | _metaInfoDict.remove(filename); | ||
111 | } | 111 | } | ||
112 | } else { | 112 | } else { | ||
113 | // remove the URLs from the collection | 113 | // remove the URLs from the collection | ||
114 | for (const QString name : fileNames) { | 114 | for (const QString& name : fileNames) { | ||
115 | if (_virtFilesystemDict.find(parentDir) != _virtFilesystemDict.end()) { | 115 | if (_virtFilesystemDict.find(parentDir) != _virtFilesystemDict.end()) { | ||
116 | QList<QUrl> *urlList = _virtFilesystemDict[parentDir]; | 116 | QList<QUrl> *urlList = _virtFilesystemDict[parentDir]; | ||
117 | urlList->removeAll(getUrl(name)); | 117 | urlList->removeAll(getUrl(name)); | ||
118 | } | 118 | } | ||
119 | } | 119 | } | ||
120 | } | 120 | } | ||
121 | 121 | | |||
122 | emit fileSystemChanged(currentDirectory(), true); // will call refresh() | 122 | emit fileSystemChanged(currentDirectory(), true); // will call refresh() | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 148 | { | |||
173 | connect(job, &KIO::Job::result, this, [=]() { emit fileSystemChanged(currentDirectory(), false); }); | 173 | connect(job, &KIO::Job::result, this, [=]() { emit fileSystemChanged(currentDirectory(), false); }); | ||
174 | } | 174 | } | ||
175 | 175 | | |||
176 | bool VirtualFileSystem::canMoveToTrash(const QStringList &fileNames) const | 176 | bool VirtualFileSystem::canMoveToTrash(const QStringList &fileNames) const | ||
177 | { | 177 | { | ||
178 | if (isRoot()) | 178 | if (isRoot()) | ||
179 | return false; | 179 | return false; | ||
180 | 180 | | |||
181 | for (const QString fileName : fileNames) { | 181 | for (const QString& fileName : fileNames) { | ||
182 | if (!getUrl(fileName).isLocalFile()) { | 182 | if (!getUrl(fileName).isLocalFile()) { | ||
183 | return false; | 183 | return false; | ||
184 | } | 184 | } | ||
185 | } | 185 | } | ||
186 | return true; | 186 | return true; | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | void VirtualFileSystem::setMetaInformation(const QString &info) | 189 | void VirtualFileSystem::setMetaInformation(const QString &info) | ||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Line(s) | 307 | if (path.isEmpty()) | |||
308 | path = '/'; | 308 | path = '/'; | ||
309 | return FileItem::createVirtualDir(path, url); | 309 | return FileItem::createVirtualDir(path, url); | ||
310 | } | 310 | } | ||
311 | 311 | | |||
312 | const QUrl directory = url.adjusted(QUrl::RemoveFilename); | 312 | const QUrl directory = url.adjusted(QUrl::RemoveFilename); | ||
313 | 313 | | |||
314 | if (url.isLocalFile()) { | 314 | if (url.isLocalFile()) { | ||
315 | QFileInfo file(url.path()); | 315 | QFileInfo file(url.path()); | ||
316 | return file.exists() ? FileSystem::createLocalFileItem(url.fileName(), directory.path(), true) : 0; | 316 | return file.exists() ? FileSystem::createLocalFileItem(url.fileName(), directory.path(), true) : nullptr; | ||
317 | } | 317 | } | ||
318 | 318 | | |||
319 | KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo); | 319 | KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo); | ||
320 | connect(statJob, &KIO::Job::result, this, &VirtualFileSystem::slotStatResult); | 320 | connect(statJob, &KIO::Job::result, this, &VirtualFileSystem::slotStatResult); | ||
321 | 321 | | |||
322 | // ugly: we have to wait here until the stat job is finished | 322 | // ugly: we have to wait here until the stat job is finished | ||
323 | QEventLoop eventLoop; | 323 | QEventLoop eventLoop; | ||
324 | connect(statJob, &KJob::finished, &eventLoop, &QEventLoop::quit); | 324 | connect(statJob, &KJob::finished, &eventLoop, &QEventLoop::quit); | ||
325 | eventLoop.exec(); // blocking until quit() | 325 | eventLoop.exec(); // blocking until quit() | ||
326 | 326 | | |||
327 | if (_fileEntry.count() == 0) { | 327 | if (_fileEntry.count() == 0) { | ||
328 | return 0; // stat job failed | 328 | return nullptr; // stat job failed | ||
329 | } | 329 | } | ||
330 | 330 | | |||
331 | if (!_fileEntry.contains(KIO::UDSEntry::UDS_MODIFICATION_TIME)) { | 331 | if (!_fileEntry.contains(KIO::UDSEntry::UDS_MODIFICATION_TIME)) { | ||
332 | // TODO this also happens for FTP directories | 332 | // TODO this also happens for FTP directories | ||
333 | return 0; // file not found | 333 | return nullptr; // file not found | ||
334 | } | 334 | } | ||
335 | 335 | | |||
336 | return FileSystem::createFileItemFromKIO(_fileEntry, directory, true); | 336 | return FileSystem::createFileItemFromKIO(_fileEntry, directory, true); | ||
337 | } | 337 | } | ||
338 | 338 | | |||
339 | KConfig &VirtualFileSystem::getVirtDB() | 339 | KConfig &VirtualFileSystem::getVirtDB() | ||
340 | { | 340 | { | ||
341 | //virtualfilesystem_db = new KConfig("data",VIRTUALFILESYSTEM_DB,KConfig::NoGlobals); | 341 | //virtualfilesystem_db = new KConfig("data",VIRTUALFILESYSTEM_DB,KConfig::NoGlobals); | ||
342 | static KConfig db(VIRTUALFILESYSTEM_DB, KConfig::CascadeConfig, QStandardPaths::AppDataLocation); | 342 | static KConfig db(VIRTUALFILESYSTEM_DB, KConfig::CascadeConfig, QStandardPaths::AppDataLocation); | ||
343 | return db; | 343 | return db; | ||
344 | } | 344 | } | ||
345 | 345 | | |||
346 | void VirtualFileSystem::slotStatResult(KJob *job) | 346 | void VirtualFileSystem::slotStatResult(KJob *job) | ||
347 | { | 347 | { | ||
348 | _fileEntry = job->error() ? KIO::UDSEntry() : static_cast<KIO::StatJob *>(job)->statResult(); | 348 | _fileEntry = job->error() ? KIO::UDSEntry() : dynamic_cast<KIO::StatJob *>(job)->statResult(); | ||
349 | } | 349 | } | ||
350 | 350 | | |||
351 | void VirtualFileSystem::showError(const QString &error) | 351 | void VirtualFileSystem::showError(const QString &error) | ||
352 | { | 352 | { | ||
353 | QWidget *window = QApplication::activeWindow(); | 353 | QWidget *window = QApplication::activeWindow(); | ||
354 | KMessageBox::sorry(window, error); // window can be null, is allowed | 354 | KMessageBox::sorry(window, error); // window can be null, is allowed | ||
355 | } | 355 | } |