Changeset View
Changeset View
Standalone View
Standalone View
krusader/DiskUsage/diskusage.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | #include <QMenu> | 44 | #include <QMenu> | ||
45 | 45 | | |||
46 | #include <KConfigCore/KSharedConfig> | 46 | #include <KConfigCore/KSharedConfig> | ||
47 | #include <KI18n/KLocalizedString> | 47 | #include <KI18n/KLocalizedString> | ||
48 | #include <KWidgetsAddons/KMessageBox> | 48 | #include <KWidgetsAddons/KMessageBox> | ||
49 | #include <KWidgetsAddons/KStandardGuiItem> | 49 | #include <KWidgetsAddons/KStandardGuiItem> | ||
50 | #include <KIO/Job> | 50 | #include <KIO/Job> | ||
51 | #include <KIO/DeleteJob> | 51 | #include <KIO/DeleteJob> | ||
52 | #include <utility> | ||||
52 | 53 | | |||
53 | #include "dufilelight.h" | 54 | #include "dufilelight.h" | ||
54 | #include "dulines.h" | 55 | #include "dulines.h" | ||
55 | #include "dulistview.h" | 56 | #include "dulistview.h" | ||
56 | #include "filelightParts/Config.h" | 57 | #include "filelightParts/Config.h" | ||
57 | #include "../FileSystem/fileitem.h" | 58 | #include "../FileSystem/fileitem.h" | ||
58 | #include "../FileSystem/filesystemprovider.h" | 59 | #include "../FileSystem/filesystemprovider.h" | ||
59 | #include "../FileSystem/krpermhandler.h" | 60 | #include "../FileSystem/krpermhandler.h" | ||
Show All 24 Lines | |||||
84 | LoaderWidget::LoaderWidget(QWidget *parent) : QScrollArea(parent), cancelled(false) | 85 | LoaderWidget::LoaderWidget(QWidget *parent) : QScrollArea(parent), cancelled(false) | ||
85 | { | 86 | { | ||
86 | QPalette palette = viewport()->palette(); | 87 | QPalette palette = viewport()->palette(); | ||
87 | palette.setColor(viewport()->backgroundRole(), Qt::white); | 88 | palette.setColor(viewport()->backgroundRole(), Qt::white); | ||
88 | viewport()->setPalette(palette); | 89 | viewport()->setPalette(palette); | ||
89 | 90 | | |||
90 | widget = new QWidget(parent); | 91 | widget = new QWidget(parent); | ||
91 | 92 | | |||
92 | QGridLayout *loaderLayout = new QGridLayout(widget); | 93 | auto *loaderLayout = new QGridLayout(widget); | ||
93 | loaderLayout->setSpacing(0); | 94 | loaderLayout->setSpacing(0); | ||
94 | loaderLayout->setContentsMargins(0, 0, 0, 0); | 95 | loaderLayout->setContentsMargins(0, 0, 0, 0); | ||
95 | 96 | | |||
96 | QFrame *loaderBox = new QFrame(widget); | 97 | QFrame *loaderBox = new QFrame(widget); | ||
97 | loaderBox->setFrameShape(QFrame::Box); | 98 | loaderBox->setFrameShape(QFrame::Box); | ||
98 | loaderBox->setFrameShadow(QFrame::Sunken); | 99 | loaderBox->setFrameShadow(QFrame::Sunken); | ||
99 | loaderBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | 100 | loaderBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | ||
100 | loaderBox->setFrameStyle(QFrame::Panel + QFrame::Raised); | 101 | loaderBox->setFrameStyle(QFrame::Panel + QFrame::Raised); | ||
101 | loaderBox->setLineWidth(2); | 102 | loaderBox->setLineWidth(2); | ||
102 | 103 | | |||
103 | QGridLayout *synchGrid = new QGridLayout(loaderBox); | 104 | auto *synchGrid = new QGridLayout(loaderBox); | ||
104 | synchGrid->setSpacing(6); | 105 | synchGrid->setSpacing(6); | ||
105 | synchGrid->setContentsMargins(11, 11, 11, 11); | 106 | synchGrid->setContentsMargins(11, 11, 11, 11); | ||
106 | 107 | | |||
107 | QLabel *titleLabel = new QLabel(i18n("Loading Usage Information"), loaderBox); | 108 | QLabel *titleLabel = new QLabel(i18n("Loading Usage Information"), loaderBox); | ||
108 | titleLabel->setAlignment(Qt::AlignHCenter); | 109 | titleLabel->setAlignment(Qt::AlignHCenter); | ||
109 | synchGrid->addWidget(titleLabel, 0, 0, 1, 2); | 110 | synchGrid->addWidget(titleLabel, 0, 0, 1, 2); | ||
110 | 111 | | |||
111 | QLabel *filesLabel = new QLabel(i18n("Files:"), loaderBox); | 112 | QLabel *filesLabel = new QLabel(i18n("Files:"), loaderBox); | ||
Show All 37 Lines | |||||
149 | searchedDirectory->setMaximumWidth(width); | 150 | searchedDirectory->setMaximumWidth(width); | ||
150 | synchGrid->addWidget(searchedDirectory, 4, 0, 1, 2); | 151 | synchGrid->addWidget(searchedDirectory, 4, 0, 1, 2); | ||
151 | 152 | | |||
152 | QFrame *line = new QFrame(loaderBox); | 153 | QFrame *line = new QFrame(loaderBox); | ||
153 | line->setFrameStyle(QFrame::HLine | QFrame::Sunken); | 154 | line->setFrameStyle(QFrame::HLine | QFrame::Sunken); | ||
154 | synchGrid->addWidget(line, 5, 0, 1, 2); | 155 | synchGrid->addWidget(line, 5, 0, 1, 2); | ||
155 | 156 | | |||
156 | QWidget *hboxWidget = new QWidget(loaderBox); | 157 | QWidget *hboxWidget = new QWidget(loaderBox); | ||
157 | QHBoxLayout * hbox = new QHBoxLayout(hboxWidget); | 158 | auto * hbox = new QHBoxLayout(hboxWidget); | ||
158 | 159 | | |||
159 | QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); | 160 | auto* spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); | ||
160 | hbox->addItem(spacer); | 161 | hbox->addItem(spacer); | ||
161 | QPushButton *cancelButton = new QPushButton(hboxWidget); | 162 | auto *cancelButton = new QPushButton(hboxWidget); | ||
162 | KStandardGuiItem::assign(cancelButton, KStandardGuiItem::Cancel); | 163 | KStandardGuiItem::assign(cancelButton, KStandardGuiItem::Cancel); | ||
163 | hbox->addWidget(cancelButton); | 164 | hbox->addWidget(cancelButton); | ||
164 | 165 | | |||
165 | synchGrid->addWidget(hboxWidget, 6, 1); | 166 | synchGrid->addWidget(hboxWidget, 6, 1); | ||
166 | 167 | | |||
167 | loaderLayout->addWidget(loaderBox, 0, 0); | 168 | loaderLayout->addWidget(loaderBox, 0, 0); | ||
168 | 169 | | |||
169 | setWidget(widget); | 170 | setWidget(widget); | ||
Show All 20 Lines | |||||
190 | } | 191 | } | ||
191 | 192 | | |||
192 | void LoaderWidget::slotCancelled() | 193 | void LoaderWidget::slotCancelled() | ||
193 | { | 194 | { | ||
194 | cancelled = true; | 195 | cancelled = true; | ||
195 | } | 196 | } | ||
196 | 197 | | |||
197 | DiskUsage::DiskUsage(QString confGroup, QWidget *parent) : QStackedWidget(parent), | 198 | DiskUsage::DiskUsage(QString confGroup, QWidget *parent) : QStackedWidget(parent), | ||
198 | currentDirectory(0), root(0), configGroup(confGroup), loading(false), | 199 | currentDirectory(nullptr), root(nullptr), configGroup(std::move(confGroup)), loading(false), | ||
199 | abortLoading(false), clearAfterAbort(false), deleting(false), searchFileSystem(0) | 200 | abortLoading(false), clearAfterAbort(false), deleting(false), searchFileSystem(nullptr) | ||
200 | { | 201 | { | ||
201 | listView = new DUListView(this); | 202 | listView = new DUListView(this); | ||
202 | lineView = new DULines(this); | 203 | lineView = new DULines(this); | ||
203 | filelightView = new DUFilelight(this); | 204 | filelightView = new DUFilelight(this); | ||
204 | loaderView = new LoaderWidget(this); | 205 | loaderView = new LoaderWidget(this); | ||
205 | 206 | | |||
206 | addWidget(listView); | 207 | addWidget(listView); | ||
207 | addWidget(lineView); | 208 | addWidget(lineView); | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 237 | { | |||
249 | directoryStack.clear(); | 250 | directoryStack.clear(); | ||
250 | parentStack.clear(); | 251 | parentStack.clear(); | ||
251 | 252 | | |||
252 | directoryStack.push(""); | 253 | directoryStack.push(""); | ||
253 | parentStack.push(root); | 254 | parentStack.push(root); | ||
254 | 255 | | |||
255 | if (searchFileSystem) { | 256 | if (searchFileSystem) { | ||
256 | delete searchFileSystem; | 257 | delete searchFileSystem; | ||
257 | searchFileSystem = 0; | 258 | searchFileSystem = nullptr; | ||
258 | } | 259 | } | ||
259 | searchFileSystem = FileSystemProvider::instance().getFilesystem(baseDir); | 260 | searchFileSystem = FileSystemProvider::instance().getFilesystem(baseDir); | ||
260 | if (searchFileSystem == 0) { | 261 | if (searchFileSystem == nullptr) { | ||
261 | qWarning() << "could not get filesystem for directory=" << baseDir; | 262 | qWarning() << "could not get filesystem for directory=" << baseDir; | ||
262 | loading = abortLoading = clearAfterAbort = false; | 263 | loading = abortLoading = clearAfterAbort = false; | ||
263 | emit loadFinished(false); | 264 | emit loadFinished(false); | ||
264 | return; | 265 | return; | ||
265 | } | 266 | } | ||
266 | 267 | | |||
267 | currentFileItem = 0; | 268 | currentFileItem = nullptr; | ||
268 | 269 | | |||
269 | if (!loading) { | 270 | if (!loading) { | ||
270 | viewBeforeLoad = activeView; | 271 | viewBeforeLoad = activeView; | ||
271 | setView(VIEW_LOADER); | 272 | setView(VIEW_LOADER); | ||
272 | } | 273 | } | ||
273 | 274 | | |||
274 | loading = true; | 275 | loading = true; | ||
275 | 276 | | |||
276 | loaderView->init(); | 277 | loaderView->init(); | ||
277 | loaderView->setCurrentURL(baseURL); | 278 | loaderView->setCurrentURL(baseURL); | ||
278 | loaderView->setValues(fileNum, dirNum, currentSize); | 279 | loaderView->setValues(fileNum, dirNum, currentSize); | ||
279 | 280 | | |||
280 | loadingTimer.setSingleShot(true); | 281 | loadingTimer.setSingleShot(true); | ||
281 | loadingTimer.start(0); | 282 | loadingTimer.start(0); | ||
282 | } | 283 | } | ||
283 | 284 | | |||
284 | void DiskUsage::slotLoadDirectory() | 285 | void DiskUsage::slotLoadDirectory() | ||
285 | { | 286 | { | ||
286 | if ((currentFileItem == 0 && directoryStack.isEmpty()) || loaderView->wasCancelled() || abortLoading) { | 287 | if ((currentFileItem == nullptr && directoryStack.isEmpty()) || loaderView->wasCancelled() || abortLoading) { | ||
287 | if (searchFileSystem) | 288 | if (searchFileSystem) | ||
288 | delete searchFileSystem; | 289 | delete searchFileSystem; | ||
289 | 290 | | |||
290 | searchFileSystem = 0; | 291 | searchFileSystem = nullptr; | ||
291 | currentFileItem = 0; | 292 | currentFileItem = nullptr; | ||
292 | 293 | | |||
293 | setView(viewBeforeLoad); | 294 | setView(viewBeforeLoad); | ||
294 | 295 | | |||
295 | if (clearAfterAbort) | 296 | if (clearAfterAbort) | ||
296 | clear(); | 297 | clear(); | ||
297 | else { | 298 | else { | ||
298 | calculateSizes(); | 299 | calculateSizes(); | ||
299 | changeDirectory(root); | 300 | changeDirectory(root); | ||
300 | } | 301 | } | ||
301 | 302 | | |||
302 | emit loadFinished(!(loaderView->wasCancelled() || abortLoading)); | 303 | emit loadFinished(!(loaderView->wasCancelled() || abortLoading)); | ||
303 | 304 | | |||
304 | loading = abortLoading = clearAfterAbort = false; | 305 | loading = abortLoading = clearAfterAbort = false; | ||
305 | } else if (loading) { | 306 | } else if (loading) { | ||
306 | for (int counter = 0; counter != MAX_FILENUM; counter ++) { | 307 | for (int counter = 0; counter != MAX_FILENUM; counter ++) { | ||
307 | if (currentFileItem == 0) { | 308 | if (currentFileItem == nullptr) { | ||
308 | if (directoryStack.isEmpty()) | 309 | if (directoryStack.isEmpty()) | ||
309 | break; | 310 | break; | ||
310 | 311 | | |||
311 | dirToCheck = directoryStack.pop(); | 312 | dirToCheck = directoryStack.pop(); | ||
312 | currentParent = parentStack.pop(); | 313 | currentParent = parentStack.pop(); | ||
313 | 314 | | |||
314 | contentMap.insert(dirToCheck, currentParent); | 315 | contentMap.insert(dirToCheck, currentParent); | ||
315 | 316 | | |||
Show All 18 Lines | 334 | if (!searchFileSystem->scanDir(url)) | |||
334 | break; | 335 | break; | ||
335 | fileItems = searchFileSystem->fileItems(); | 336 | fileItems = searchFileSystem->fileItems(); | ||
336 | 337 | | |||
337 | dirNum++; | 338 | dirNum++; | ||
338 | 339 | | |||
339 | currentFileItem = fileItems.isEmpty() ? 0 : fileItems.takeFirst(); | 340 | currentFileItem = fileItems.isEmpty() ? 0 : fileItems.takeFirst(); | ||
340 | } else { | 341 | } else { | ||
341 | fileNum++; | 342 | fileNum++; | ||
342 | File *newItem = 0; | 343 | File *newItem = nullptr; | ||
343 | 344 | | |||
344 | QString mime = currentFileItem->getMime(); // fast == not using mimetype magic | 345 | QString mime = currentFileItem->getMime(); // fast == not using mimetype magic | ||
345 | 346 | | |||
346 | if (currentFileItem->isDir() && !currentFileItem->isSymLink()) { | 347 | if (currentFileItem->isDir() && !currentFileItem->isSymLink()) { | ||
347 | newItem = new Directory(currentParent, currentFileItem->getName(), dirToCheck, currentFileItem->getSize(), | 348 | newItem = new Directory(currentParent, currentFileItem->getName(), dirToCheck, currentFileItem->getSize(), | ||
348 | currentFileItem->getMode(), currentFileItem->getOwner(), currentFileItem->getGroup(), | 349 | currentFileItem->getMode(), currentFileItem->getOwner(), currentFileItem->getGroup(), | ||
349 | currentFileItem->getPerm(), currentFileItem->getTime_t(), currentFileItem->isSymLink(), | 350 | currentFileItem->getPerm(), currentFileItem->getTime_t(), currentFileItem->isSymLink(), | ||
350 | mime); | 351 | mime); | ||
Show All 28 Lines | 379 | { | |||
379 | if (loading) { | 380 | if (loading) { | ||
380 | abortLoading = true; | 381 | abortLoading = true; | ||
381 | clearAfterAbort = true; | 382 | clearAfterAbort = true; | ||
382 | } | 383 | } | ||
383 | } | 384 | } | ||
384 | 385 | | |||
385 | void DiskUsage::dirUp() | 386 | void DiskUsage::dirUp() | ||
386 | { | 387 | { | ||
387 | if (currentDirectory != 0) { | 388 | if (currentDirectory != nullptr) { | ||
388 | if (currentDirectory->parent() != 0) | 389 | if (currentDirectory->parent() != nullptr) | ||
389 | changeDirectory((Directory *)(currentDirectory->parent())); | 390 | changeDirectory((Directory *)(currentDirectory->parent())); | ||
390 | else { | 391 | else { | ||
391 | QUrl up = KIO::upUrl(baseURL); | 392 | QUrl up = KIO::upUrl(baseURL); | ||
392 | 393 | | |||
393 | if (KMessageBox::questionYesNo(this, i18n("Stepping into the parent folder requires " | 394 | if (KMessageBox::questionYesNo(this, i18n("Stepping into the parent folder requires " | ||
394 | "loading the content of the \"%1\" URL. Do you wish " | 395 | "loading the content of the \"%1\" URL. Do you wish " | ||
395 | "to continue?", up.toDisplayString(QUrl::PreferLocalFile)), | 396 | "to continue?", up.toDisplayString(QUrl::PreferLocalFile)), | ||
396 | i18n("Krusader::DiskUsage"), KStandardGuiItem::yes(), | 397 | i18n("Krusader::DiskUsage"), KStandardGuiItem::yes(), | ||
397 | KStandardGuiItem::no(), "DiskUsageLoadParentDir" | 398 | KStandardGuiItem::no(), "DiskUsageLoadParentDir" | ||
398 | ) == KMessageBox::Yes) | 399 | ) == KMessageBox::Yes) | ||
399 | load(up); | 400 | load(up); | ||
400 | } | 401 | } | ||
401 | } | 402 | } | ||
402 | } | 403 | } | ||
403 | 404 | | |||
404 | Directory * DiskUsage::getDirectory(QString dir) | 405 | Directory * DiskUsage::getDirectory(QString dir) | ||
405 | { | 406 | { | ||
406 | while (dir.endsWith('/')) | 407 | while (dir.endsWith('/')) | ||
407 | dir.truncate(dir.length() - 1); | 408 | dir.truncate(dir.length() - 1); | ||
408 | 409 | | |||
409 | if (dir.isEmpty()) | 410 | if (dir.isEmpty()) | ||
410 | return root; | 411 | return root; | ||
411 | 412 | | |||
412 | if (contentMap.find(dir) == contentMap.end()) | 413 | if (contentMap.find(dir) == contentMap.end()) | ||
413 | return 0; | 414 | return nullptr; | ||
414 | return contentMap[ dir ]; | 415 | return contentMap[ dir ]; | ||
415 | } | 416 | } | ||
416 | 417 | | |||
417 | File * DiskUsage::getFile(QString path) | 418 | File * DiskUsage::getFile(const QString& path) | ||
418 | { | 419 | { | ||
419 | if (path.isEmpty()) | 420 | if (path.isEmpty()) | ||
420 | return root; | 421 | return root; | ||
421 | 422 | | |||
422 | QString dir = path; | 423 | QString dir = path; | ||
423 | 424 | | |||
424 | int ndx = path.lastIndexOf('/'); | 425 | int ndx = path.lastIndexOf('/'); | ||
425 | QString file = path.mid(ndx + 1); | 426 | QString file = path.mid(ndx + 1); | ||
426 | 427 | | |||
427 | if (ndx == -1) | 428 | if (ndx == -1) | ||
428 | dir = ""; | 429 | dir = ""; | ||
429 | else | 430 | else | ||
430 | dir.truncate(ndx); | 431 | dir.truncate(ndx); | ||
431 | 432 | | |||
432 | Directory *dirEntry = getDirectory(dir); | 433 | Directory *dirEntry = getDirectory(dir); | ||
433 | if (dirEntry == 0) | 434 | if (dirEntry == nullptr) | ||
434 | return 0; | 435 | return nullptr; | ||
435 | 436 | | |||
436 | for (Iterator<File> it = dirEntry->iterator(); it != dirEntry->end(); ++it) | 437 | for (Iterator<File> it = dirEntry->iterator(); it != dirEntry->end(); ++it) | ||
437 | if ((*it)->name() == file) | 438 | if ((*it)->name() == file) | ||
438 | return *it; | 439 | return *it; | ||
439 | 440 | | |||
440 | return 0; | 441 | return nullptr; | ||
441 | } | 442 | } | ||
442 | 443 | | |||
443 | void DiskUsage::clear() | 444 | void DiskUsage::clear() | ||
444 | { | 445 | { | ||
445 | baseURL = QUrl(); | 446 | baseURL = QUrl(); | ||
446 | emit clearing(); | 447 | emit clearing(); | ||
447 | 448 | | |||
448 | QHashIterator< File *, Properties * > lit(propertyMap); | 449 | QHashIterator< File *, Properties * > lit(propertyMap); | ||
449 | while (lit.hasNext()) | 450 | while (lit.hasNext()) | ||
450 | delete lit.next().value(); | 451 | delete lit.next().value(); | ||
451 | 452 | | |||
452 | propertyMap.clear(); | 453 | propertyMap.clear(); | ||
453 | contentMap.clear(); | 454 | contentMap.clear(); | ||
454 | if (root) | 455 | if (root) | ||
455 | delete root; | 456 | delete root; | ||
456 | root = currentDirectory = 0; | 457 | root = currentDirectory = nullptr; | ||
457 | } | 458 | } | ||
458 | 459 | | |||
459 | int DiskUsage::calculateSizes(Directory *dirEntry, bool emitSig, int depth) | 460 | int DiskUsage::calculateSizes(Directory *dirEntry, bool emitSig, int depth) | ||
460 | { | 461 | { | ||
461 | int changeNr = 0; | 462 | int changeNr = 0; | ||
462 | 463 | | |||
463 | if (dirEntry == 0) | 464 | if (dirEntry == nullptr) | ||
464 | dirEntry = root; | 465 | dirEntry = root; | ||
465 | 466 | | |||
466 | KIO::filesize_t own = 0, total = 0; | 467 | KIO::filesize_t own = 0, total = 0; | ||
467 | 468 | | |||
468 | for (Iterator<File> it = dirEntry->iterator(); it != dirEntry->end(); ++it) { | 469 | for (Iterator<File> it = dirEntry->iterator(); it != dirEntry->end(); ++it) { | ||
469 | File * item = *it; | 470 | File * item = *it; | ||
470 | 471 | | |||
471 | if (!item->isExcluded()) { | 472 | if (!item->isExcluded()) { | ||
Show All 27 Lines | 499 | { | |||
499 | int changeNr = 0; | 500 | int changeNr = 0; | ||
500 | 501 | | |||
501 | if (!file->isExcluded()) { | 502 | if (!file->isExcluded()) { | ||
502 | file->exclude(true); | 503 | file->exclude(true); | ||
503 | emit changed(file); | 504 | emit changed(file); | ||
504 | changeNr++; | 505 | changeNr++; | ||
505 | 506 | | |||
506 | if (file->isDir()) { | 507 | if (file->isDir()) { | ||
507 | Directory *dir = dynamic_cast<Directory *>(file); | 508 | auto *dir = dynamic_cast<Directory *>(file); | ||
508 | for (Iterator<File> it = dir->iterator(); it != dir->end(); ++it) | 509 | for (Iterator<File> it = dir->iterator(); it != dir->end(); ++it) | ||
509 | changeNr += exclude(*it, false, depth + 1); | 510 | changeNr += exclude(*it, false, depth + 1); | ||
510 | } | 511 | } | ||
511 | } | 512 | } | ||
512 | 513 | | |||
513 | if (calcPercents) { | 514 | if (calcPercents) { | ||
514 | calculateSizes(root, true); | 515 | calculateSizes(root, true); | ||
515 | calculatePercents(true); | 516 | calculatePercents(true); | ||
516 | createStatus(); | 517 | createStatus(); | ||
517 | } | 518 | } | ||
518 | 519 | | |||
519 | if (depth == 0 && changeNr != 0) | 520 | if (depth == 0 && changeNr != 0) | ||
520 | emit changeFinished(); | 521 | emit changeFinished(); | ||
521 | 522 | | |||
522 | return changeNr; | 523 | return changeNr; | ||
523 | } | 524 | } | ||
524 | 525 | | |||
525 | int DiskUsage::include(Directory *dir, int depth) | 526 | int DiskUsage::include(Directory *dir, int depth) | ||
526 | { | 527 | { | ||
527 | int changeNr = 0; | 528 | int changeNr = 0; | ||
528 | 529 | | |||
529 | if (dir == 0) | 530 | if (dir == nullptr) | ||
530 | return 0; | 531 | return 0; | ||
531 | 532 | | |||
532 | for (Iterator<File> it = dir->iterator(); it != dir->end(); ++it) { | 533 | for (Iterator<File> it = dir->iterator(); it != dir->end(); ++it) { | ||
533 | File *item = *it; | 534 | File *item = *it; | ||
534 | 535 | | |||
535 | if (item->isDir()) | 536 | if (item->isDir()) | ||
536 | changeNr += include(dynamic_cast<Directory *>(item), depth + 1); | 537 | changeNr += include(dynamic_cast<Directory *>(item), depth + 1); | ||
537 | 538 | | |||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 571 | if (calcPercents) { | |||
591 | 592 | | |||
592 | emit status(i18n("Deleting %1...", file->name())); | 593 | emit status(i18n("Deleting %1...", file->name())); | ||
593 | } | 594 | } | ||
594 | 595 | | |||
595 | if (file == currentDirectory) | 596 | if (file == currentDirectory) | ||
596 | dirUp(); | 597 | dirUp(); | ||
597 | 598 | | |||
598 | if (file->isDir()) { | 599 | if (file->isDir()) { | ||
599 | Directory *dir = dynamic_cast<Directory *>(file); | 600 | auto *dir = dynamic_cast<Directory *>(file); | ||
600 | 601 | | |||
601 | Iterator<File> it; | 602 | Iterator<File> it; | ||
602 | while ((it = dir->iterator()) != dir->end()) | 603 | while ((it = dir->iterator()) != dir->end()) | ||
603 | deleteNr += del(*it, false, depth + 1); | 604 | deleteNr += del(*it, false, depth + 1); | ||
604 | 605 | | |||
605 | QString path; | 606 | QString path; | ||
606 | for (const Directory *d = (Directory*)file; d != root && d && d->parent() != 0; d = d->parent()) { | 607 | for (const Directory *d = (Directory*)file; d != root && d && d->parent() != nullptr; d = d->parent()) { | ||
607 | if (!path.isEmpty()) | 608 | if (!path.isEmpty()) | ||
608 | path = '/' + path; | 609 | path = '/' + path; | ||
609 | 610 | | |||
610 | path = d->name() + path; | 611 | path = d->name() + path; | ||
611 | } | 612 | } | ||
612 | 613 | | |||
613 | contentMap.remove(path); | 614 | contentMap.remove(path); | ||
614 | } | 615 | } | ||
Show All 34 Lines | |||||
649 | } | 650 | } | ||
650 | 651 | | |||
651 | if (depth == 0 && deleteNr != 0) | 652 | if (depth == 0 && deleteNr != 0) | ||
652 | emit deleteFinished(); | 653 | emit deleteFinished(); | ||
653 | 654 | | |||
654 | return deleteNr; | 655 | return deleteNr; | ||
655 | } | 656 | } | ||
656 | 657 | | |||
657 | void * DiskUsage::getProperty(File *item, QString key) | 658 | void * DiskUsage::getProperty(File *item, const QString& key) | ||
658 | { | 659 | { | ||
659 | QHash< File *, Properties *>::iterator itr = propertyMap.find(item); | 660 | QHash< File *, Properties *>::iterator itr = propertyMap.find(item); | ||
660 | if (itr == propertyMap.end()) | 661 | if (itr == propertyMap.end()) | ||
661 | return 0; | 662 | return nullptr; | ||
662 | 663 | | |||
663 | QHash<QString, void *>::iterator it = (*itr)->find(key); | 664 | QHash<QString, void *>::iterator it = (*itr)->find(key); | ||
664 | if (it == (*itr)->end()) | 665 | if (it == (*itr)->end()) | ||
665 | return 0; | 666 | return nullptr; | ||
666 | 667 | | |||
667 | return it.value(); | 668 | return it.value(); | ||
668 | } | 669 | } | ||
669 | 670 | | |||
670 | void DiskUsage::addProperty(File *item, QString key, void * prop) | 671 | void DiskUsage::addProperty(File *item, const QString& key, void * prop) | ||
671 | { | 672 | { | ||
672 | Properties *props; | 673 | Properties *props; | ||
673 | QHash< File *, Properties *>::iterator itr = propertyMap.find(item); | 674 | QHash< File *, Properties *>::iterator itr = propertyMap.find(item); | ||
674 | if (itr == propertyMap.end()) { | 675 | if (itr == propertyMap.end()) { | ||
675 | props = new Properties(); | 676 | props = new Properties(); | ||
676 | propertyMap.insert(item, props); | 677 | propertyMap.insert(item, props); | ||
677 | } else | 678 | } else | ||
678 | props = *itr; | 679 | props = *itr; | ||
679 | 680 | | |||
680 | props->insert(key, prop); | 681 | props->insert(key, prop); | ||
681 | } | 682 | } | ||
682 | 683 | | |||
683 | void DiskUsage::removeProperty(File *item, QString key) | 684 | void DiskUsage::removeProperty(File *item, const QString& key) | ||
684 | { | 685 | { | ||
685 | QHash< File *, Properties *>::iterator itr = propertyMap.find(item); | 686 | QHash< File *, Properties *>::iterator itr = propertyMap.find(item); | ||
686 | if (itr == propertyMap.end()) | 687 | if (itr == propertyMap.end()) | ||
687 | return; | 688 | return; | ||
688 | (*itr)->remove(key); | 689 | (*itr)->remove(key); | ||
689 | if ((*itr)->count() == 0) | 690 | if ((*itr)->count() == 0) | ||
690 | propertyMap.remove(item); | 691 | propertyMap.remove(item); | ||
691 | } | 692 | } | ||
692 | 693 | | |||
693 | void DiskUsage::createStatus() | 694 | void DiskUsage::createStatus() | ||
694 | { | 695 | { | ||
695 | Directory *dirEntry = currentDirectory; | 696 | Directory *dirEntry = currentDirectory; | ||
696 | 697 | | |||
697 | if (dirEntry == 0) | 698 | if (dirEntry == nullptr) | ||
698 | return; | 699 | return; | ||
699 | 700 | | |||
700 | QUrl url = baseURL; | 701 | QUrl url = baseURL; | ||
701 | if (dirEntry != root) { | 702 | if (dirEntry != root) { | ||
702 | url = url.adjusted(QUrl::StripTrailingSlash); | 703 | url = url.adjusted(QUrl::StripTrailingSlash); | ||
703 | url.setPath(url.path() + '/' + (dirEntry->directory())); | 704 | url.setPath(url.path() + '/' + (dirEntry->directory())); | ||
704 | } | 705 | } | ||
705 | 706 | | |||
Show All 14 Lines | 714 | { | |||
720 | emit enteringDirectory(dir); | 721 | emit enteringDirectory(dir); | ||
721 | } | 722 | } | ||
722 | 723 | | |||
723 | Directory* DiskUsage::getCurrentDir() | 724 | Directory* DiskUsage::getCurrentDir() | ||
724 | { | 725 | { | ||
725 | return currentDirectory; | 726 | return currentDirectory; | ||
726 | } | 727 | } | ||
727 | 728 | | |||
728 | void DiskUsage::rightClickMenu(const QPoint & pos, File *fileItem, QMenu *addPopup, QString addPopupName) | 729 | void DiskUsage::rightClickMenu(const QPoint & pos, File *fileItem, QMenu *addPopup, const QString& addPopupName) | ||
729 | { | 730 | { | ||
730 | QMenu popup(this); | 731 | QMenu popup(this); | ||
731 | 732 | | |||
732 | popup.setTitle(i18n("Disk Usage")); | 733 | popup.setTitle(i18n("Disk Usage")); | ||
733 | 734 | | |||
734 | QHash<void *, int> actionHash; | 735 | QHash<void *, int> actionHash; | ||
735 | 736 | | |||
736 | if (fileItem != 0) { | 737 | if (fileItem != nullptr) { | ||
737 | QAction * actDelete = popup.addAction(i18n("Delete")); | 738 | QAction * actDelete = popup.addAction(i18n("Delete")); | ||
738 | actionHash[ actDelete ] = DELETE_ID; | 739 | actionHash[ actDelete ] = DELETE_ID; | ||
739 | actDelete->setShortcut(Qt::Key_Delete); | 740 | actDelete->setShortcut(Qt::Key_Delete); | ||
740 | QAction * actExclude = popup.addAction(i18n("Exclude")); | 741 | QAction * actExclude = popup.addAction(i18n("Exclude")); | ||
741 | actionHash[ actExclude ] = EXCLUDE_ID; | 742 | actionHash[ actExclude ] = EXCLUDE_ID; | ||
742 | actExclude->setShortcut(Qt::CTRL + Qt::Key_E); | 743 | actExclude->setShortcut(Qt::CTRL + Qt::Key_E); | ||
743 | popup.addSeparator(); | 744 | popup.addSeparator(); | ||
744 | } | 745 | } | ||
Show All 16 Lines | |||||
761 | 762 | | |||
762 | myAct = popup.addAction(i18n("Step into")); | 763 | myAct = popup.addAction(i18n("Step into")); | ||
763 | actionHash[ myAct ] = STEP_INTO_ID; | 764 | actionHash[ myAct ] = STEP_INTO_ID; | ||
764 | myAct->setShortcut(Qt::SHIFT + Qt::Key_Down); | 765 | myAct->setShortcut(Qt::SHIFT + Qt::Key_Down); | ||
765 | 766 | | |||
766 | popup.addSeparator(); | 767 | popup.addSeparator(); | ||
767 | 768 | | |||
768 | 769 | | |||
769 | if (addPopup != 0) { | 770 | if (addPopup != nullptr) { | ||
770 | QAction * menu = popup.addMenu(addPopup); | 771 | QAction * menu = popup.addMenu(addPopup); | ||
771 | menu->setText(addPopupName); | 772 | menu->setText(addPopupName); | ||
772 | } | 773 | } | ||
773 | 774 | | |||
774 | QMenu viewPopup; | 775 | QMenu viewPopup; | ||
775 | 776 | | |||
776 | myAct = viewPopup.addAction(i18n("Lines")); | 777 | myAct = viewPopup.addAction(i18n("Lines")); | ||
777 | actionHash[ myAct ] = LINES_VIEW_ID; | 778 | actionHash[ myAct ] = LINES_VIEW_ID; | ||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Line(s) | 943 | if (activeView == VIEW_FILELIGHT) { | |||
944 | return; | 945 | return; | ||
945 | } | 946 | } | ||
946 | break; | 947 | break; | ||
947 | } | 948 | } | ||
948 | } | 949 | } | ||
949 | QStackedWidget::keyPressEvent(e); | 950 | QStackedWidget::keyPressEvent(e); | ||
950 | } | 951 | } | ||
951 | 952 | | |||
952 | QPixmap DiskUsage::getIcon(QString mime) | 953 | QPixmap DiskUsage::getIcon(const QString& mime) | ||
953 | { | 954 | { | ||
954 | QPixmap icon; | 955 | QPixmap icon; | ||
955 | 956 | | |||
956 | if (!QPixmapCache::find(mime, icon)) { | 957 | if (!QPixmapCache::find(mime, icon)) { | ||
957 | // get the icon. | 958 | // get the icon. | ||
958 | if (mime == "Broken Link !") // FIXME: this doesn't work anymore - the reported mimetype for a broken link is now "unknown" | 959 | if (mime == "Broken Link !") // FIXME: this doesn't work anymore - the reported mimetype for a broken link is now "unknown" | ||
959 | icon = FileListIcon("file-broken").pixmap(); | 960 | icon = FileListIcon("file-broken").pixmap(); | ||
960 | else { | 961 | else { | ||
Show All 10 Lines | |||||
971 | } | 972 | } | ||
972 | return icon; | 973 | return icon; | ||
973 | } | 974 | } | ||
974 | 975 | | |||
975 | int DiskUsage::calculatePercents(bool emitSig, Directory *dirEntry, int depth) | 976 | int DiskUsage::calculatePercents(bool emitSig, Directory *dirEntry, int depth) | ||
976 | { | 977 | { | ||
977 | int changeNr = 0; | 978 | int changeNr = 0; | ||
978 | 979 | | |||
979 | if (dirEntry == 0) | 980 | if (dirEntry == nullptr) | ||
980 | dirEntry = root; | 981 | dirEntry = root; | ||
981 | 982 | | |||
982 | for (Iterator<File> it = dirEntry->iterator(); it != dirEntry->end(); ++it) { | 983 | for (Iterator<File> it = dirEntry->iterator(); it != dirEntry->end(); ++it) { | ||
983 | File *item = *it; | 984 | File *item = *it; | ||
984 | 985 | | |||
985 | if (!item->isExcluded()) { | 986 | if (!item->isExcluded()) { | ||
986 | int newPerc; | 987 | int newPerc; | ||
987 | 988 | | |||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 1043 | { | |||
1056 | } | 1057 | } | ||
1057 | 1058 | | |||
1058 | // currentWidget()->setFocus(); | 1059 | // currentWidget()->setFocus(); | ||
1059 | emit viewChanged(activeView = view); | 1060 | emit viewChanged(activeView = view); | ||
1060 | } | 1061 | } | ||
1061 | 1062 | | |||
1062 | File * DiskUsage::getCurrentFile() | 1063 | File * DiskUsage::getCurrentFile() | ||
1063 | { | 1064 | { | ||
1064 | File * file = 0; | 1065 | File * file = nullptr; | ||
1065 | 1066 | | |||
1066 | switch (activeView) { | 1067 | switch (activeView) { | ||
1067 | case VIEW_LINES: | 1068 | case VIEW_LINES: | ||
1068 | file = lineView->getCurrentFile(); | 1069 | file = lineView->getCurrentFile(); | ||
1069 | break; | 1070 | break; | ||
1070 | case VIEW_DETAILED: | 1071 | case VIEW_DETAILED: | ||
1071 | file = listView->getCurrentFile(); | 1072 | file = listView->getCurrentFile(); | ||
1072 | break; | 1073 | break; | ||
Show All 17 Lines | 1084 | if (deleting) { // if we are deleting, disable the mouse and | |||
1090 | case QEvent::KeyRelease: | 1091 | case QEvent::KeyRelease: | ||
1091 | return true; | 1092 | return true; | ||
1092 | default: | 1093 | default: | ||
1093 | break; | 1094 | break; | ||
1094 | } | 1095 | } | ||
1095 | } | 1096 | } | ||
1096 | 1097 | | |||
1097 | if (e->type() == QEvent::ShortcutOverride) { | 1098 | if (e->type() == QEvent::ShortcutOverride) { | ||
1098 | QKeyEvent* ke = (QKeyEvent*) e; | 1099 | auto* ke = (QKeyEvent*) e; | ||
1099 | 1100 | | |||
1100 | if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::KeypadModifier) { | 1101 | if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::KeypadModifier) { | ||
1101 | switch (ke->key()) { | 1102 | switch (ke->key()) { | ||
1102 | case Qt::Key_Delete: | 1103 | case Qt::Key_Delete: | ||
1103 | case Qt::Key_Plus: | 1104 | case Qt::Key_Plus: | ||
1104 | case Qt::Key_Minus: | 1105 | case Qt::Key_Minus: | ||
1105 | ke->accept(); | 1106 | ke->accept(); | ||
1106 | break; | 1107 | break; | ||
Show All 27 Lines |