Changeset View
Changeset View
Standalone View
Standalone View
src/views/dolphinview.cpp
Show First 20 Lines • Show All 1485 Lines • ▼ Show 20 Line(s) | 1485 | if (job->error() == 0) { | |||
---|---|---|---|---|---|
1486 | emit operationCompletedMessage(i18nc("@info:status", "Delete operation completed.")); | 1486 | emit operationCompletedMessage(i18nc("@info:status", "Delete operation completed.")); | ||
1487 | } else if (job->error() != KIO::ERR_USER_CANCELED) { | 1487 | } else if (job->error() != KIO::ERR_USER_CANCELED) { | ||
1488 | emit errorMessage(job->errorString()); | 1488 | emit errorMessage(job->errorString()); | ||
1489 | } | 1489 | } | ||
1490 | } | 1490 | } | ||
1491 | 1491 | | |||
1492 | void DolphinView::slotRenamingResult(KJob* job) | 1492 | void DolphinView::slotRenamingResult(KJob* job) | ||
1493 | { | 1493 | { | ||
1494 | if (job->error()) { | 1494 | if (job->error() == 0) { | ||
1495 | KIO::CopyJob *copyJob = qobject_cast<KIO::CopyJob *>(job); | 1495 | // Nothing to do | ||
1496 | Q_ASSERT(copyJob); | 1496 | } else if (job->error() != KIO::ERR_USER_CANCELED) { | ||
meven: You can combine this ` if (job->error() != 0 && job->error() != KIO::ERR_USER_CANCELED) `
It is… | |||||
1497 | const QUrl newUrl = copyJob->destUrl(); | 1497 | emit errorMessage(job->errorString()); | ||
1498 | const int index = m_model->index(newUrl); | | |||
1499 | if (index >= 0) { | | |||
1500 | QHash<QByteArray, QVariant> data; | | |||
1501 | const QUrl oldUrl = copyJob->srcUrls().at(0); | | |||
1502 | data.insert("text", oldUrl.fileName()); | | |||
1503 | m_model->setData(index, data); | | |||
1504 | } | | |||
1505 | } | 1498 | } | ||
1506 | } | 1499 | } | ||
1507 | 1500 | | |||
1508 | void DolphinView::slotDirectoryLoadingStarted() | 1501 | void DolphinView::slotDirectoryLoadingStarted() | ||
1509 | { | 1502 | { | ||
1510 | // Disable the writestate temporary until it can be determined in a fast way | 1503 | // Disable the writestate temporary until it can be determined in a fast way | ||
1511 | // in DolphinView::slotDirectoryLoadingCompleted() | 1504 | // in DolphinView::slotDirectoryLoadingCompleted() | ||
1512 | if (m_isFolderWritable) { | 1505 | if (m_isFolderWritable) { | ||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 1597 | const auto code = KMessageBox::questionYesNo(this, | |||
1613 | ); | 1606 | ); | ||
1614 | 1607 | | |||
1615 | if (code == KMessageBox::No) { | 1608 | if (code == KMessageBox::No) { | ||
1616 | return; | 1609 | return; | ||
1617 | } | 1610 | } | ||
1618 | } | 1611 | } | ||
1619 | #endif | 1612 | #endif | ||
1620 | 1613 | | |||
1621 | const bool newNameExistsAlready = (m_model->index(newUrl) >= 0); | | |||
1622 | if (!newNameExistsAlready) { | | |||
1623 | // Only change the data in the model if no item with the new name | | |||
1624 | // is in the model yet. If there is an item with the new name | | |||
1625 | // already, calling KIO::CopyJob will open a dialog | | |||
1626 | // asking for a new name, and KFileItemModel will update the | | |||
1627 | // data when the dir lister signals that the file name has changed. | | |||
1628 | QHash<QByteArray, QVariant> data; | | |||
1629 | data.insert(role, value); | | |||
1630 | m_model->setData(index, data); | | |||
1631 | } | | |||
1632 | | ||||
1633 | KIO::Job * job = KIO::moveAs(oldUrl, newUrl); | 1614 | KIO::Job * job = KIO::moveAs(oldUrl, newUrl); | ||
1634 | KJobWidgets::setWindow(job, this); | 1615 | KJobWidgets::setWindow(job, this); | ||
1635 | KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); | 1616 | KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); | ||
1636 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | | |||
1637 | | ||||
1638 | forceUrlsSelection(newUrl, {newUrl}); | | |||
This is still needed, otherwise the renamed file won't get selected. elvisangelaccio: This is still needed, otherwise the renamed file won't get selected. | |||||
1639 | | ||||
1640 | if (!newNameExistsAlready) { | | |||
1641 | // Only connect the result signal if there is no item with the new name | | |||
1642 | // in the model yet, see bug 328262. | | |||
1643 | connect(job, &KJob::result, this, &DolphinView::slotRenamingResult); | 1617 | connect(job, &KJob::result, this, &DolphinView::slotRenamingResult); | ||
1644 | } | 1618 | } | ||
1645 | } | 1619 | } | ||
1646 | } | 1620 | } | ||
1647 | } | | |||
1648 | 1621 | | |||
1649 | void DolphinView::loadDirectory(const QUrl& url, bool reload) | 1622 | void DolphinView::loadDirectory(const QUrl& url, bool reload) | ||
1650 | { | 1623 | { | ||
1651 | if (!url.isValid()) { | 1624 | if (!url.isValid()) { | ||
1652 | const QString location(url.toDisplayString(QUrl::PreferLocalFile)); | 1625 | const QString location(url.toDisplayString(QUrl::PreferLocalFile)); | ||
1653 | if (location.isEmpty()) { | 1626 | if (location.isEmpty()) { | ||
1654 | emit errorMessage(i18nc("@info:status", "The location is empty.")); | 1627 | emit errorMessage(i18nc("@info:status", "The location is empty.")); | ||
1655 | } else { | 1628 | } else { | ||
▲ Show 20 Lines • Show All 203 Lines • Show Last 20 Lines |
You can combine this if (job->error() != 0 && job->error() != KIO::ERR_USER_CANCELED)
It is clearer IMO