Changeset View
Changeset View
Standalone View
Standalone View
krusader/Panel/panelfunc.cpp
Context not available. | |||||
512 | // 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 | ||
---|---|---|---|---|---|
513 | QFile file(filePath.toLocalFile()); | 513 | QFile file(filePath.toLocalFile()); | ||
514 | if (file.exists()) { | 514 | if (file.exists()) { | ||
515 | editFile(); | 515 | editFile(filePath); | ||
516 | return; | 516 | return; | ||
517 | } else { | 517 | } else { | ||
518 | // simply create a local file | 518 | // simply create a local file | ||
Context not available. | |||||
526 | slotFileCreated(nullptr, filePath); | 526 | slotFileCreated(nullptr, filePath); | ||
527 | return; | 527 | return; | ||
528 | } | 528 | } | ||
529 | } else { | ||||
530 | KIO::StatJob* statJob = KIO::stat(filePath, KIO::HideProgressInfo); | ||||
531 | connect(statJob, &KIO::StatJob::result, this, &ListPanelFunc::slotStatEdit); | ||||
529 | } | 532 | } | ||
533 | } | ||||
530 | 534 | | |||
531 | auto *tempFile = new QTemporaryFile; | 535 | void ListPanelFunc::slotStatEdit(KJob* job) | ||
532 | tempFile->setAutoRemove(false); // done below | 536 | { | ||
533 | tempFile->open(); // create file | 537 | if (!job) | ||
538 | return; | ||||
539 | | ||||
540 | const KIO::StatJob *statJob = dynamic_cast<KIO::StatJob *>(job); | ||||
541 | const QUrl &url = statJob->url(); | ||||
542 | | ||||
543 | if (job->error()) { | ||||
544 | if (job->error() == KIO::ERR_DOES_NOT_EXIST) { | ||||
545 | // create a new file | ||||
546 | auto *tempFile = new QTemporaryFile; | ||||
547 | tempFile->setAutoRemove(false); // done below | ||||
548 | tempFile->open(); // create file | ||||
549 | | ||||
550 | KIO::CopyJob *job = KIO::copy(QUrl::fromLocalFile(tempFile->fileName()), url); | ||||
551 | job->setUiDelegate(nullptr); | ||||
552 | job->setDefaultPermissions(true); | ||||
553 | connect(job, &KIO::CopyJob::result, this, [=](KJob *job) { slotFileCreated(job, url); }); | ||||
554 | connect(job, &KIO::CopyJob::result, tempFile, &QTemporaryFile::deleteLater); | ||||
555 | return; | ||||
556 | } else { | ||||
557 | KMessageBox::error(nullptr, job->errorString()); | ||||
558 | return; | ||||
559 | } | ||||
560 | } | ||||
561 | | ||||
562 | if (statJob->statResult().isDir()) { | ||||
563 | KMessageBox::error(nullptr, i18n("You cannot edit a folder")); | ||||
564 | return; | ||||
565 | } | ||||
534 | 566 | | |||
535 | KIO::CopyJob *job = KIO::copy(QUrl::fromLocalFile(tempFile->fileName()), filePath); | 567 | KrViewer::edit(url); | ||
536 | job->setUiDelegate(nullptr); | | |||
537 | job->setDefaultPermissions(true); | | |||
538 | connect(job, &KIO::CopyJob::result, this, [=](KJob *job) { slotFileCreated(job, filePath); }); | | |||
539 | connect(job, &KIO::CopyJob::result, tempFile, &QTemporaryFile::deleteLater); | | |||
540 | } | 568 | } | ||
541 | 569 | | |||
542 | void ListPanelFunc::slotFileCreated(KJob *job, const QUrl filePath) | 570 | void ListPanelFunc::slotFileCreated(KJob *job, const QUrl filePath) | ||
Context not available. |