Changeset View
Changeset View
Standalone View
Standalone View
krusader/Panel/panelfunc.cpp
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | |||||
77 | #include "../Dialogs/packgui.h" | 77 | #include "../Dialogs/packgui.h" | ||
78 | #include "../Dialogs/krdialogs.h" | 78 | #include "../Dialogs/krdialogs.h" | ||
79 | #include "../Dialogs/krpleasewait.h" | 79 | #include "../Dialogs/krpleasewait.h" | ||
80 | #include "../Dialogs/krspwidgets.h" | 80 | #include "../Dialogs/krspwidgets.h" | ||
81 | #include "../Dialogs/checksumdlg.h" | 81 | #include "../Dialogs/checksumdlg.h" | ||
82 | #include "../KViewer/krviewer.h" | 82 | #include "../KViewer/krviewer.h" | ||
83 | #include "../MountMan/kmountman.h" | 83 | #include "../MountMan/kmountman.h" | ||
84 | 84 | | |||
85 | | ||||
85 | QPointer<ListPanelFunc> ListPanelFunc::copyToClipboardOrigin; | 86 | QPointer<ListPanelFunc> ListPanelFunc::copyToClipboardOrigin; | ||
86 | 87 | | |||
87 | ListPanelFunc::ListPanelFunc(ListPanel *parent) : QObject(parent), | 88 | ListPanelFunc::ListPanelFunc(ListPanel *parent) : QObject(parent), | ||
88 | panel(parent), fileSystemP(0), urlManuallyEntered(false), | 89 | panel(parent), fileSystemP(0), urlManuallyEntered(false), | ||
89 | _isPaused(true), _refreshAfterPaused(true), _quickSizeCalculator(0) | 90 | _isPaused(true), _refreshAfterPaused(true), _quickSizeCalculator(0) | ||
90 | { | 91 | { | ||
91 | history = new DirHistoryQueue(panel); | 92 | history = new DirHistoryQueue(panel); | ||
92 | delayTimer.setSingleShot(true); | 93 | delayTimer.setSingleShot(true); | ||
▲ Show 20 Lines • Show All 373 Lines • ▼ Show 20 Line(s) | 461 | { | |||
466 | KrViewer::view(dest); // view the file | 467 | KrViewer::view(dest); // view the file | ||
467 | } | 468 | } | ||
468 | 469 | | |||
469 | void ListPanelFunc::terminal() | 470 | void ListPanelFunc::terminal() | ||
470 | { | 471 | { | ||
471 | SLOTS->runTerminal(panel->lastLocalPath()); | 472 | SLOTS->runTerminal(panel->lastLocalPath()); | ||
472 | } | 473 | } | ||
473 | 474 | | |||
474 | void ListPanelFunc::edit() | 475 | void ListPanelFunc::editFile(const QUrl &newFilePath) | ||
475 | { | 476 | { | ||
476 | panel->searchBar->hideBarIfSearching(); | 477 | panel->searchBar->hideBarIfSearching(); | ||
477 | KFileItem tmp; | | |||
478 | 478 | | |||
479 | if (fileToCreate.isEmpty()) { | 479 | QUrl editPath; | ||
480 | QString name = panel->getCurrentName(); | 480 | if (!newFilePath.isEmpty()) { | ||
481 | editPath = newFilePath; | ||||
482 | } else { | ||||
483 | const QString name = panel->getCurrentName(); | ||||
481 | if (name.isNull()) | 484 | if (name.isNull()) | ||
482 | return; | 485 | return; | ||
483 | fileToCreate = files()->getUrl(name); | 486 | editPath = files()->getUrl(name); | ||
484 | } | 487 | } | ||
485 | 488 | | |||
486 | tmp = KFileItem(fileToCreate); | 489 | const KFileItem fileToEdit = KFileItem(newFilePath); | ||
487 | 490 | | |||
488 | if (tmp.isDir()) { | 491 | if (fileToEdit.isDir()) { | ||
489 | KMessageBox::sorry(krMainWindow, i18n("You cannot edit a folder")); | 492 | KMessageBox::sorry(krMainWindow, i18n("You cannot edit a folder")); | ||
490 | fileToCreate = QUrl(); | | |||
491 | return; | 493 | return; | ||
492 | } | 494 | } | ||
493 | 495 | | |||
494 | if (!tmp.isReadable()) { | 496 | if (!fileToEdit.isReadable()) { | ||
495 | KMessageBox::sorry(0, i18n("No permissions to edit this file.")); | 497 | KMessageBox::sorry(0, i18n("No permissions to edit this file.")); | ||
496 | fileToCreate = QUrl(); | | |||
497 | return; | 498 | return; | ||
498 | } | 499 | } | ||
499 | 500 | | |||
500 | KrViewer::edit(fileToCreate); | 501 | KrViewer::edit(editPath); | ||
501 | fileToCreate = QUrl(); | | |||
502 | } | 502 | } | ||
503 | 503 | | |||
504 | void ListPanelFunc::editNew() | 504 | void ListPanelFunc::editNewFile() | ||
505 | { | 505 | { | ||
506 | if(!fileToCreate.isEmpty()) | | |||
507 | return; | | |||
508 | | ||||
509 | // ask the user for the filename to edit | 506 | // ask the user for the filename to edit | ||
510 | fileToCreate = KChooseDir::getFile(i18n("Enter the filename to edit:"), QUrl(panel->getCurrentName()), panel->virtualPath()); | 507 | const QUrl filePath = KChooseDir::getFile(i18n("Enter the filename to edit:"), | ||
511 | if(fileToCreate.isEmpty()) | 508 | QUrl(panel->getCurrentName()), panel->virtualPath()); | ||
509 | if(filePath.isEmpty()) | ||||
512 | return ; // the user canceled | 510 | return ; // the user canceled | ||
513 | 511 | | |||
514 | // if the file exists, edit it instead of creating a new one | 512 | // if the file exists, edit it instead of creating a new one | ||
515 | QFile f(fileToCreate.toLocalFile()); | 513 | QFile file(filePath.toLocalFile()); | ||
514 | if(file.exists()) { | ||||
515 | editFile(); | ||||
516 | return; | ||||
517 | } | ||||
516 | 518 | | |||
nmel: code suggestion: return here and on line 524 could be combined into a single return inside the… | |||||
abika: I think its more clear with two returns. | |||||
517 | if(f.exists()) { | | |||
518 | edit(); | | |||
519 | } else { | | |||
520 | QTemporaryFile *tempFile = new QTemporaryFile; | 519 | QTemporaryFile *tempFile = new QTemporaryFile; | ||
521 | tempFile->open(); | 520 | tempFile->setAutoRemove(false); // done below | ||
521 | tempFile->open(); // create file | ||||
522 | tempFile->setPermissions(QFile::ReadOwner | QFile::WriteOwner | ||||
523 | | QFile::ReadGroup | QFile::ReadOther); | ||||
nmel: Doesn't build: missing semicolon. | |||||
522 | 524 | | |||
523 | KIO::CopyJob *job = KIO::copy(QUrl::fromLocalFile(tempFile->fileName()), fileToCreate); | 525 | KIO::CopyJob *job = KIO::copy(QUrl::fromLocalFile(tempFile->fileName()), filePath); | ||
524 | job->setUiDelegate(0); | 526 | job->setUiDelegate(nullptr); | ||
525 | job->setDefaultPermissions(true); | 527 | job->setDefaultPermissions(true); | ||
526 | connect(job, SIGNAL(result(KJob*)), SLOT(slotFileCreated(KJob*))); | 528 | connect(job, &KIO::CopyJob::result, this, [=](KJob *job) { slotFileCreated(job, filePath); }); | ||
527 | connect(job, SIGNAL(result(KJob*)), tempFile, SLOT(deleteLater())); | 529 | connect(job, &KIO::CopyJob::result, tempFile, &QTemporaryFile::deleteLater); | ||
528 | } | | |||
529 | } | 530 | } | ||
530 | 531 | | |||
531 | void ListPanelFunc::slotFileCreated(KJob *job) | 532 | void ListPanelFunc::slotFileCreated(KJob *job, const QUrl filePath) | ||
532 | { | 533 | { | ||
533 | if(!job->error() || job->error() == KIO::ERR_FILE_ALREADY_EXIST) { | 534 | if (!job->error() || job->error() == KIO::ERR_FILE_ALREADY_EXIST) { | ||
534 | KrViewer::edit(fileToCreate); | 535 | KrViewer::edit(filePath); | ||
535 | 536 | | |||
536 | if(KIO::upUrl(fileToCreate).matches(panel->virtualPath(), QUrl::StripTrailingSlash)) | 537 | if (KIO::upUrl(filePath).matches(panel->virtualPath(), QUrl::StripTrailingSlash)) { | ||
537 | refresh(); | 538 | refresh(); | ||
538 | else if(KIO::upUrl(fileToCreate).matches(panel->otherPanel()->virtualPath(), QUrl::StripTrailingSlash)) | 539 | } | ||
540 | if (KIO::upUrl(filePath).matches(panel->otherPanel()->virtualPath(), QUrl::StripTrailingSlash)) { | ||||
539 | otherFunc()->refresh(); | 541 | otherFunc()->refresh(); | ||
540 | } | 542 | } | ||
541 | else | 543 | } else { | ||
542 | KMessageBox::sorry(krMainWindow, job->errorString()); | 544 | KMessageBox::sorry(krMainWindow, job->errorString()); | ||
543 | 545 | } | |||
544 | fileToCreate = QUrl(); | | |||
545 | } | 546 | } | ||
546 | 547 | | |||
547 | void ListPanelFunc::copyFiles(bool enqueue, bool move) | 548 | void ListPanelFunc::copyFiles(bool enqueue, bool move) | ||
548 | { | 549 | { | ||
549 | panel->searchBar->hideBarIfSearching(); | 550 | panel->searchBar->hideBarIfSearching(); | ||
550 | 551 | | |||
551 | const QStringList fileNames = panel->getSelectedNames(); | 552 | const QStringList fileNames = panel->getSelectedNames(); | ||
552 | if (fileNames.isEmpty()) | 553 | if (fileNames.isEmpty()) | ||
▲ Show 20 Lines • Show All 740 Lines • Show Last 20 Lines |
code suggestion: return here and on line 524 could be combined into a single return inside the parent if