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(nullptr), urlManuallyEntered(false), | 89 | panel(parent), fileSystemP(nullptr), urlManuallyEntered(false), | ||
89 | _isPaused(true), _refreshAfterPaused(true), _quickSizeCalculator(nullptr) | 90 | _isPaused(true), _refreshAfterPaused(true), _quickSizeCalculator(nullptr) | ||
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 372 Lines • ▼ Show 20 Line(s) | 460 | { | |||
465 | KrViewer::view(dest); // view the file | 466 | KrViewer::view(dest); // view the file | ||
466 | } | 467 | } | ||
467 | 468 | | |||
468 | void ListPanelFunc::terminal() | 469 | void ListPanelFunc::terminal() | ||
469 | { | 470 | { | ||
470 | SLOTS->runTerminal(panel->lastLocalPath()); | 471 | SLOTS->runTerminal(panel->lastLocalPath()); | ||
471 | } | 472 | } | ||
472 | 473 | | |||
473 | void ListPanelFunc::edit() | 474 | void ListPanelFunc::editFile(const QUrl &newFilePath) | ||
474 | { | 475 | { | ||
475 | panel->searchBar->hideBarIfSearching(); | 476 | panel->searchBar->hideBarIfSearching(); | ||
476 | KFileItem tmp; | | |||
477 | 477 | | |||
478 | if (fileToCreate.isEmpty()) { | 478 | QUrl editPath; | ||
479 | QString name = panel->getCurrentName(); | 479 | if (!newFilePath.isEmpty()) { | ||
480 | editPath = newFilePath; | ||||
481 | } else { | ||||
482 | const QString name = panel->getCurrentName(); | ||||
480 | if (name.isNull()) | 483 | if (name.isNull()) | ||
481 | return; | 484 | return; | ||
482 | fileToCreate = files()->getUrl(name); | 485 | editPath = files()->getUrl(name); | ||
483 | } | 486 | } | ||
484 | 487 | | |||
485 | tmp = KFileItem(fileToCreate); | 488 | const KFileItem fileToEdit = KFileItem(newFilePath); | ||
486 | 489 | | |||
487 | if (tmp.isDir()) { | 490 | if (fileToEdit.isDir()) { | ||
488 | KMessageBox::sorry(krMainWindow, i18n("You cannot edit a folder")); | 491 | KMessageBox::sorry(krMainWindow, i18n("You cannot edit a folder")); | ||
489 | fileToCreate = QUrl(); | | |||
490 | return; | 492 | return; | ||
491 | } | 493 | } | ||
492 | 494 | | |||
493 | if (!tmp.isReadable()) { | 495 | if (!fileToEdit.isReadable()) { | ||
494 | KMessageBox::sorry(nullptr, i18n("No permissions to edit this file.")); | 496 | KMessageBox::sorry(nullptr, i18n("No permissions to edit this file.")); | ||
495 | fileToCreate = QUrl(); | | |||
496 | return; | 497 | return; | ||
497 | } | 498 | } | ||
498 | 499 | | |||
499 | KrViewer::edit(fileToCreate); | 500 | KrViewer::edit(editPath); | ||
500 | fileToCreate = QUrl(); | | |||
501 | } | 501 | } | ||
502 | 502 | | |||
503 | void ListPanelFunc::editNew() | 503 | void ListPanelFunc::editNewFile() | ||
504 | { | 504 | { | ||
505 | if(!fileToCreate.isEmpty()) | | |||
506 | return; | | |||
507 | | ||||
508 | // ask the user for the filename to edit | 505 | // ask the user for the filename to edit | ||
509 | fileToCreate = KChooseDir::getFile(i18n("Enter the filename to edit:"), QUrl(panel->getCurrentName()), panel->virtualPath()); | 506 | const QUrl filePath = KChooseDir::getFile(i18n("Enter the filename to edit:"), | ||
510 | if(fileToCreate.isEmpty()) | 507 | QUrl(panel->getCurrentName()), panel->virtualPath()); | ||
508 | if(filePath.isEmpty()) | ||||
511 | return ; // the user canceled | 509 | return ; // the user canceled | ||
512 | 510 | | |||
511 | if (filePath.isLocalFile()) { | ||||
513 | // 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 | ||
514 | QFile f(fileToCreate.toLocalFile()); | 513 | QFile file(filePath.toLocalFile()); | ||
515 | 514 | if (file.exists()) { | |||
516 | if(f.exists()) { | 515 | editFile(); | ||
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 | edit(); | 516 | return; | ||
518 | } else { | 517 | } else { | ||
518 | // simply create a local file | ||||
519 | // also because KIO::CopyJob::setDefaultPermissions does not work | ||||
520 | file.open(QIODevice::NewOnly); | ||||
nmel: Doesn't build: missing semicolon. | |||||
521 | file.close(); | ||||
522 | slotFileCreated(nullptr, filePath); | ||||
523 | return; | ||||
524 | } | ||||
525 | } | ||||
526 | | ||||
519 | auto *tempFile = new QTemporaryFile; | 527 | auto *tempFile = new QTemporaryFile; | ||
520 | tempFile->open(); | 528 | tempFile->setAutoRemove(false); // done below | ||
529 | tempFile->open(); // create file | ||||
521 | 530 | | |||
522 | KIO::CopyJob *job = KIO::copy(QUrl::fromLocalFile(tempFile->fileName()), fileToCreate); | 531 | KIO::CopyJob *job = KIO::copy(QUrl::fromLocalFile(tempFile->fileName()), filePath); | ||
523 | job->setUiDelegate(nullptr); | 532 | job->setUiDelegate(nullptr); | ||
524 | job->setDefaultPermissions(true); | 533 | job->setDefaultPermissions(true); | ||
525 | connect(job, &KIO::CopyJob::result, this, &ListPanelFunc::slotFileCreated); | 534 | connect(job, &KIO::CopyJob::result, this, [=](KJob *job) { slotFileCreated(job, filePath); }); | ||
526 | connect(job, &KIO::CopyJob::result, tempFile, &QTemporaryFile::deleteLater); | 535 | connect(job, &KIO::CopyJob::result, tempFile, &QTemporaryFile::deleteLater); | ||
527 | } | 536 | } | ||
528 | } | | |||
529 | 537 | | |||
530 | void ListPanelFunc::slotFileCreated(KJob *job) | 538 | void ListPanelFunc::slotFileCreated(KJob *job, const QUrl filePath) | ||
531 | { | 539 | { | ||
532 | if(!job->error() || job->error() == KIO::ERR_FILE_ALREADY_EXIST) { | 540 | if (!job || (!job->error() || job->error() == KIO::ERR_FILE_ALREADY_EXIST)) { | ||
533 | KrViewer::edit(fileToCreate); | 541 | KrViewer::edit(filePath); | ||
534 | 542 | | |||
535 | if(KIO::upUrl(fileToCreate).matches(panel->virtualPath(), QUrl::StripTrailingSlash)) | 543 | if (KIO::upUrl(filePath).matches(panel->virtualPath(), QUrl::StripTrailingSlash)) { | ||
536 | refresh(); | 544 | refresh(); | ||
537 | else if(KIO::upUrl(fileToCreate).matches(panel->otherPanel()->virtualPath(), QUrl::StripTrailingSlash)) | 545 | } | ||
546 | if (KIO::upUrl(filePath).matches(panel->otherPanel()->virtualPath(), QUrl::StripTrailingSlash)) { | ||||
538 | otherFunc()->refresh(); | 547 | otherFunc()->refresh(); | ||
539 | } | 548 | } | ||
540 | else | 549 | } else { | ||
541 | KMessageBox::sorry(krMainWindow, job->errorString()); | 550 | KMessageBox::sorry(krMainWindow, job->errorString()); | ||
542 | 551 | } | |||
543 | fileToCreate = QUrl(); | | |||
544 | } | 552 | } | ||
545 | 553 | | |||
546 | void ListPanelFunc::copyFiles(bool enqueue, bool move) | 554 | void ListPanelFunc::copyFiles(bool enqueue, bool move) | ||
547 | { | 555 | { | ||
548 | panel->searchBar->hideBarIfSearching(); | 556 | panel->searchBar->hideBarIfSearching(); | ||
549 | 557 | | |||
550 | const QStringList fileNames = panel->getSelectedNames(); | 558 | const QStringList fileNames = panel->getSelectedNames(); | ||
551 | if (fileNames.isEmpty()) | 559 | if (fileNames.isEmpty()) | ||
▲ Show 20 Lines • Show All 739 Lines • Show Last 20 Lines |
code suggestion: return here and on line 524 could be combined into a single return inside the parent if