KItemListController *controller = new KItemListController(m_model, m_view, this);
const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1;
controller->setAutoActivationDelay(delay);
+ connect(controller, &KItemListController::doubleClickViewBackground, this, &DolphinView::doubleClickViewBackground);
// The EnlargeSmallPreviews setting can only be changed after the model
// has been set in the view by KItemListController.
// This is made using a heavily-modified QLabel rather than a KTitleWidget
// because KTitleWidget can't be told to turn off mouse-selectable text
m_placeholderLabel = new QLabel(this);
+ // Don't consume mouse events
+ m_placeholderLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
+
QFont placeholderLabelFont;
// To match the size of a level 2 Heading/KTitleWidget
placeholderLabelFont.setPointSize(qRound(placeholderLabelFont.pointSize() * 1.3));
m_placeholderLabel->setFont(placeholderLabelFont);
- m_placeholderLabel->setTextInteractionFlags(Qt::NoTextInteraction);
m_placeholderLabel->setWordWrap(true);
m_placeholderLabel->setAlignment(Qt::AlignCenter);
// Match opacity of QML placeholder label component
auto *centeringLayout = new QVBoxLayout(m_container);
centeringLayout->addWidget(m_placeholderLabel);
centeringLayout->setAlignment(m_placeholderLabel, Qt::AlignCenter);
- m_placeholderLabel->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(m_placeholderLabel, &QWidget::customContextMenuRequested, this, [this](const QPoint &pos) {
- slotViewContextMenuRequested(m_placeholderLabel->mapToGlobal(pos));
- });
controller->setSelectionBehavior(KItemListController::MultiSelection);
connect(controller, &KItemListController::itemActivated, this, &DolphinView::slotItemActivated);
m_versionControlObserver->setView(this);
m_versionControlObserver->setModel(m_model);
connect(m_versionControlObserver, &VersionControlObserver::infoMessage, this, &DolphinView::infoMessage);
- connect(m_versionControlObserver, &VersionControlObserver::errorMessage, this, &DolphinView::errorMessage);
+ connect(m_versionControlObserver, &VersionControlObserver::errorMessage, this, [this](const QString &message) {
+ Q_EMIT errorMessage(message, KIO::ERR_UNKNOWN);
+ });
connect(m_versionControlObserver, &VersionControlObserver::operationCompletedMessage, this, &DolphinView::operationCompletedMessage);
m_twoClicksRenamingTimer = new QTimer(this);
m_view->setStyle(m_proxyStyle.get());
m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::False);
} else {
- setStyle(QApplication::style());
- m_view->setStyle(QApplication::style());
+ setStyle(nullptr);
+ m_view->setStyle(nullptr);
m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting);
}
m_container->controller()->setSelectionModeEnabled(enabled);
ViewProperties props(viewPropertiesUrl());
props.setGroupedSorting(grouped);
- props.save();
- m_container->controller()->model()->setGroupedSorting(grouped);
+ m_model->setGroupedSorting(grouped);
Q_EMIT groupedSortingChanged(grouped);
}
void DolphinView::setSortRole(const QByteArray &role)
{
if (role != sortRole()) {
- updateSortRole(role);
+ ViewProperties props(viewPropertiesUrl());
+ props.setSortRole(role);
+
+ KItemModelBase *model = m_container->controller()->model();
+ model->setSortRole(role);
+
+ Q_EMIT sortRoleChanged(role);
}
}
void DolphinView::setSortOrder(Qt::SortOrder order)
{
if (sortOrder() != order) {
- updateSortOrder(order);
+ ViewProperties props(viewPropertiesUrl());
+ props.setSortOrder(order);
+
+ m_model->setSortOrder(order);
+
+ Q_EMIT sortOrderChanged(order);
}
}
if (items.count() == 1 && GeneralSettings::renameInline()) {
const int index = m_model->index(items.first());
- QMetaObject::Connection *const connection = new QMetaObject::Connection;
- *connection = connect(m_view, &KItemListView::scrollingStopped, this, [=]() {
- QObject::disconnect(*connection);
- delete connection;
-
- m_view->editRole(index, "text");
+ connect(
+ m_view,
+ &KItemListView::scrollingStopped,
+ this,
+ [this, index]() {
+ m_view->editRole(index, "text");
- hideToolTip();
+ hideToolTip();
- connect(m_view, &DolphinItemListView::roleEditingFinished, this, &DolphinView::slotRoleEditingFinished);
- });
+ connect(m_view, &DolphinItemListView::roleEditingFinished, this, &DolphinView::slotRoleEditingFinished);
+ },
+ Qt::SingleShotConnection);
m_view->scrollToItem(index);
} else {
KIO::RenameFileDialog *dialog = new KIO::RenameFileDialog(items, this);
- connect(dialog, &KIO::RenameFileDialog::renamingFinished, this, &DolphinView::slotRenameDialogRenamingFinished);
+ connect(dialog, &KIO::RenameFileDialog::renamingFinished, this, [this, items](const QList<QUrl> &urls) {
+ // The model may have already been updated, so it's possible that we don't find the old items.
+ for (int i = 0; i < items.count(); ++i) {
+ const int index = m_model->index(items[i]);
+ if (index >= 0) {
+ QHash<QByteArray, QVariant> data;
+ data.insert("text", urls[i].fileName());
+ m_model->setData(index, data);
+ }
+ }
+
+ forceUrlsSelection(urls.first(), urls);
+ updateSelectionState();
+ });
+ connect(dialog, &KIO::RenameFileDialog::error, this, [this](KJob *job) {
+ KMessageBox::error(this, job->errorString());
+ });
dialog->open();
}
const QMimeDatabase db;
+ m_clearSelectionBeforeSelectingNewItems = true;
+ m_markFirstNewlySelectedItemAsCurrent = true;
+ m_selectJobCreatedItems = true;
+
// Duplicate all selected items and append "copy" to the end of the file name
// but before the filename extension, if present
- QList<QUrl> newSelection;
for (const auto &item : itemList) {
const QUrl originalURL = item.url();
const QString originalDirectoryPath = originalURL.adjusted(QUrl::RemoveFilename).path();
}
KIO::CopyJob *job = KIO::copyAs(originalURL, duplicateURL);
+ job->setAutoRename(true);
KJobWidgets::setWindow(job, this);
- if (job) {
- newSelection << duplicateURL;
- KIO::FileUndoManager::self()->recordCopyJob(job);
- }
+ connect(job, &KIO::CopyJob::result, this, &DolphinView::slotJobResult);
+ connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotItemCreatedFromJob);
+ connect(job, &KIO::CopyJob::copyingLinkDone, this, &DolphinView::slotItemLinkCreatedFromJob);
+ KIO::FileUndoManager::self()->recordCopyJob(job);
}
-
- forceUrlsSelection(newSelection.first(), newSelection);
}
void DolphinView::stopLoading()
void DolphinView::slotItemMiddleClicked(int index)
{
const KFileItem &item = m_model->fileItem(index);
- const QUrl &url = openItemAsFolderUrl(item);
+ const QUrl &url = openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives());
const auto modifiers = QGuiApplication::keyboardModifiers();
- const QString &archiveProtocol = KProtocolManager::protocolForArchiveMimetype(item.mimetype());
if (!url.isEmpty()) {
// keep in sync with KUrlNavigator::slotNavigatorButtonClicked
if (modifiers & Qt::ShiftModifier) {
} else {
Q_EMIT tabRequested(url);
}
- } else if (!archiveProtocol.isEmpty() && isTabsForFilesEnabled()) {
+ } else if (isTabsForFilesEnabled()) {
// keep in sync with KUrlNavigator::slotNavigatorButtonClicked
if (modifiers & Qt::ShiftModifier) {
Q_EMIT activeTabRequested(item.url());
slotItemCreated(to);
}
+void DolphinView::slotItemLinkCreatedFromJob(KIO::Job *, const QUrl &, const QString &, const QUrl &to)
+{
+ slotItemCreated(to);
+}
+
void DolphinView::slotItemCreated(const QUrl &url)
{
if (m_markFirstNewlySelectedItemAsCurrent) {
}
}
-void DolphinView::onDirectoryLoadingCompleted()
+void DolphinView::onDirectoryLoadingCompletedAfterJob()
{
// the model should now contain all the items created by the job
- updateSelectionState();
+ m_selectJobCreatedItems = true; // to make sure we overwrite selection
+ // update the view: scroll into View and selection
+ updateViewState();
m_selectJobCreatedItems = false;
m_selectedUrls.clear();
}
void DolphinView::slotJobResult(KJob *job)
{
if (job->error() && job->error() != KIO::ERR_USER_CANCELED) {
- Q_EMIT errorMessage(job->errorString());
+ Q_EMIT errorMessage(job->errorString(), job->error());
}
if (!m_selectJobCreatedItems) {
m_selectedUrls.clear();
updateSelectionState();
if (!m_selectedUrls.isEmpty()) {
// not all urls were found, the model may not be up to date
- connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::onDirectoryLoadingCompleted, Qt::UniqueConnection);
+ connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::onDirectoryLoadingCompletedAfterJob, Qt::SingleShotConnection);
} else {
m_selectJobCreatedItems = false;
m_selectedUrls.clear();
emitStatusBarText(folderCount, fileCount, totalFileSize, NoSelection);
}
-void DolphinView::updateSortRole(const QByteArray &role)
-{
- ViewProperties props(viewPropertiesUrl());
- props.setSortRole(role);
-
- KItemModelBase *model = m_container->controller()->model();
- model->setSortRole(role);
-
- Q_EMIT sortRoleChanged(role);
-}
-
-void DolphinView::updateSortOrder(Qt::SortOrder order)
-{
- ViewProperties props(viewPropertiesUrl());
- props.setSortOrder(order);
-
- m_model->setSortOrder(order);
-
- Q_EMIT sortOrderChanged(order);
-}
-
void DolphinView::updateSortFoldersFirst(bool foldersFirst)
{
ViewProperties props(viewPropertiesUrl());
if (!m_selectedUrls.isEmpty()) {
KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager();
+ const bool shouldScrollToCurrentItem = m_clearSelectionBeforeSelectingNewItems;
// if there is a selection already, leave it that way
// unless some drop/paste job are in the process of creating items
if (!selectionManager->hasSelection() || m_selectJobCreatedItems) {
if (!selectedItems.isEmpty()) {
selectionManager->beginAnchoredSelection(selectionManager->currentItem());
selectionManager->setSelectedItems(selectedItems);
+ selectionManager->endAnchoredSelection();
+ if (shouldScrollToCurrentItem) {
+ m_view->scrollToItem(selectedItems.first());
+ }
}
}
}
selectNextItem(); // Fixes BUG: 419914 via selecting next item
Q_EMIT operationCompletedMessage(i18nc("@info:status", "Trash operation completed."));
} else if (job->error() != KIO::ERR_USER_CANCELED) {
- Q_EMIT errorMessage(job->errorString());
+ Q_EMIT errorMessage(job->errorString(), job->error());
}
}
selectNextItem(); // Fixes BUG: 419914 via selecting next item
Q_EMIT operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
} else if (job->error() != KIO::ERR_USER_CANCELED) {
- Q_EMIT errorMessage(job->errorString());
+ Q_EMIT errorMessage(job->errorString(), job->error());
}
}
if (!newNameExistsAlready) {
forceUrlsSelection(newUrl, {newUrl});
+ updateSelectionState();
// Only connect the result signal if there is no item with the new name
// in the model yet, see bug 328262.
if (!url.isValid()) {
const QString location(url.toDisplayString(QUrl::PreferLocalFile));
if (location.isEmpty()) {
- Q_EMIT errorMessage(i18nc("@info:status", "The location is empty."));
+ Q_EMIT errorMessage(i18nc("@info:status", "The location is empty."), KIO::ERR_UNKNOWN);
} else {
- Q_EMIT errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location));
+ Q_EMIT errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location), KIO::ERR_UNKNOWN);
}
return;
}
m_clearSelectionBeforeSelectingNewItems = true;
m_markFirstNewlySelectedItemAsCurrent = true;
m_selectJobCreatedItems = true;
- // TODO KF6 use KIO::PasteJob::copyJobStarted to hook to earlier events copying/moving
connect(job, &KIO::PasteJob::itemCreated, this, &DolphinView::slotItemCreated);
+ connect(job, &KIO::PasteJob::copyJobStarted, this, [this](const KIO::CopyJob *copyJob) {
+ connect(copyJob, &KIO::CopyJob::copying, this, &DolphinView::slotItemCreatedFromJob);
+ connect(copyJob, &KIO::CopyJob::moving, this, &DolphinView::slotItemCreatedFromJob);
+ connect(copyJob, &KIO::CopyJob::linking, this, [this](KIO::Job *job, const QString &src, const QUrl &dest) {
+ Q_UNUSED(job)
+ Q_UNUSED(src)
+ slotItemCreated(dest);
+ });
+ });
connect(job, &KIO::PasteJob::result, this, &DolphinView::slotJobResult);
}
return url;
}
-void DolphinView::slotRenameDialogRenamingFinished(const QList<QUrl> &urls)
-{
- forceUrlsSelection(urls.first(), urls);
-}
-
void DolphinView::forceUrlsSelection(const QUrl ¤t, const QList<QUrl> &selected)
{
clearSelection();