X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a18550fb768a5ea27231e52206f10bd31d28237a..0a6257bce3de877e4ae869f974df645c428d32c9:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index fa43656c1..4ed32ed43 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -20,28 +20,25 @@ #include "dolphinview.h" -#include +#include #include #include -#include #include #include #include -#include -#include #include #include - +#include +#include +#include #include #include -#include #include #include -#include #include #include -#include +#include #include #include #include @@ -49,17 +46,17 @@ #include #include #include +#include #include #include #include #include +#include #include -#include +#include #include -#include +#include #include -#include -#include #include #include "dolphinnewfilemenuobserver.h" @@ -74,9 +71,10 @@ #include "views/tooltips/tooltipmanager.h" #include "zoomlevelinfo.h" -#ifdef HAVE_NEPOMUK - #include +#ifdef HAVE_BALOO + #include #endif +#include namespace { const int MaxModeEnum = DolphinView::CompactView; @@ -114,14 +112,14 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : // When a new item has been created by the "Create New..." menu, the item should // get selected and it must be assured that the item will get visible. As the // creation is done asynchronously, several signals must be checked: - connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(itemCreated(KUrl)), - this, SLOT(observeCreatedItem(KUrl))); + connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::itemCreated, + this, &DolphinView::observeCreatedItem); m_selectionChangedTimer = new QTimer(this); m_selectionChangedTimer->setSingleShot(true); m_selectionChangedTimer->setInterval(300); - connect(m_selectionChangedTimer, SIGNAL(timeout()), - this, SLOT(emitSelectionChangedSignal())); + connect(m_selectionChangedTimer, &QTimer::timeout, + this, &DolphinView::emitSelectionChangedSignal); m_model = new KFileItemModel(this); m_view = new DolphinItemListView(); @@ -140,59 +138,60 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : m_container = new KItemListContainer(controller, this); m_container->installEventFilter(this); setFocusProxy(m_container); - connect(m_container->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip())); - connect(m_container->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip())); + connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip); + connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip); controller->setSelectionBehavior(KItemListController::MultiSelection); - connect(controller, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int))); - connect(controller, SIGNAL(itemsActivated(QSet)), this, SLOT(slotItemsActivated(QSet))); - connect(controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int))); - connect(controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF))); - connect(controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF))); - connect(controller, SIGNAL(headerContextMenuRequested(QPointF)), this, SLOT(slotHeaderContextMenuRequested(QPointF))); - connect(controller, SIGNAL(mouseButtonPressed(int,Qt::MouseButtons)), this, SLOT(slotMouseButtonPressed(int,Qt::MouseButtons))); - connect(controller, SIGNAL(itemHovered(int)), this, SLOT(slotItemHovered(int))); - connect(controller, SIGNAL(itemUnhovered(int)), this, SLOT(slotItemUnhovered(int))); - connect(controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*))); - connect(controller, SIGNAL(modelChanged(KItemModelBase*,KItemModelBase*)), this, SLOT(slotModelChanged(KItemModelBase*,KItemModelBase*))); - - connect(m_model, SIGNAL(directoryLoadingStarted()), this, SLOT(slotDirectoryLoadingStarted())); - connect(m_model, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted())); - connect(m_model, SIGNAL(directoryLoadingCanceled()), this, SIGNAL(directoryLoadingCanceled())); - connect(m_model, SIGNAL(directoryLoadingProgress(int)), this, SIGNAL(directoryLoadingProgress(int))); - connect(m_model, SIGNAL(directorySortingProgress(int)), this, SIGNAL(directorySortingProgress(int))); - connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet)), - this, SLOT(slotItemsChanged())); - connect(m_model, SIGNAL(itemsRemoved(KItemRangeList)), this, SIGNAL(itemCountChanged())); - connect(m_model, SIGNAL(itemsInserted(KItemRangeList)), this, SIGNAL(itemCountChanged())); - connect(m_model, SIGNAL(infoMessage(QString)), this, SIGNAL(infoMessage(QString))); - connect(m_model, SIGNAL(errorMessage(QString)), this, SIGNAL(errorMessage(QString))); - connect(m_model, SIGNAL(directoryRedirection(KUrl,KUrl)), this, SLOT(slotDirectoryRedirection(KUrl,KUrl))); - connect(m_model, SIGNAL(urlIsFileError(KUrl)), this, SIGNAL(urlIsFileError(KUrl))); + connect(controller, &KItemListController::itemActivated, this, &DolphinView::slotItemActivated); + connect(controller, &KItemListController::itemsActivated, this, &DolphinView::slotItemsActivated); + connect(controller, &KItemListController::itemMiddleClicked, this, &DolphinView::slotItemMiddleClicked); + connect(controller, &KItemListController::itemContextMenuRequested, this, &DolphinView::slotItemContextMenuRequested); + connect(controller, &KItemListController::viewContextMenuRequested, this, &DolphinView::slotViewContextMenuRequested); + connect(controller, &KItemListController::headerContextMenuRequested, this, &DolphinView::slotHeaderContextMenuRequested); + connect(controller, &KItemListController::mouseButtonPressed, this, &DolphinView::slotMouseButtonPressed); + connect(controller, &KItemListController::itemHovered, this, &DolphinView::slotItemHovered); + connect(controller, &KItemListController::itemUnhovered, this, &DolphinView::slotItemUnhovered); + connect(controller, &KItemListController::itemDropEvent, this, &DolphinView::slotItemDropEvent); + connect(controller, &KItemListController::escapePressed, this, &DolphinView::stopLoading); + connect(controller, &KItemListController::modelChanged, this, &DolphinView::slotModelChanged); + + connect(m_model, &KFileItemModel::directoryLoadingStarted, this, &DolphinView::slotDirectoryLoadingStarted); + connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::slotDirectoryLoadingCompleted); + connect(m_model, &KFileItemModel::directoryLoadingCanceled, this, &DolphinView::directoryLoadingCanceled); + connect(m_model, &KFileItemModel::directoryLoadingProgress, this, &DolphinView::directoryLoadingProgress); + connect(m_model, &KFileItemModel::directorySortingProgress, this, &DolphinView::directorySortingProgress); + connect(m_model, &KFileItemModel::itemsChanged, + this, &DolphinView::slotItemsChanged); + connect(m_model, &KFileItemModel::itemsRemoved, this, &DolphinView::itemCountChanged); + connect(m_model, &KFileItemModel::itemsInserted, this, &DolphinView::itemCountChanged); + connect(m_model, &KFileItemModel::infoMessage, this, &DolphinView::infoMessage); + connect(m_model, &KFileItemModel::errorMessage, this, &DolphinView::errorMessage); + connect(m_model, &KFileItemModel::directoryRedirection, this, &DolphinView::slotDirectoryRedirection); + connect(m_model, &KFileItemModel::urlIsFileError, this, &DolphinView::urlIsFileError); m_view->installEventFilter(this); - connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)), - this, SLOT(slotSortOrderChangedByHeader(Qt::SortOrder,Qt::SortOrder))); - connect(m_view, SIGNAL(sortRoleChanged(QByteArray,QByteArray)), - this, SLOT(slotSortRoleChangedByHeader(QByteArray,QByteArray))); - connect(m_view, SIGNAL(visibleRolesChanged(QList,QList)), - this, SLOT(slotVisibleRolesChangedByHeader(QList,QList))); - connect(m_view, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)), - this, SLOT(slotRoleEditingCanceled())); - connect(m_view->header(), SIGNAL(columnWidthChanged(QByteArray,qreal,qreal)), - this, SLOT(slotHeaderColumnWidthChanged(QByteArray,qreal,qreal))); + connect(m_view, &DolphinItemListView::sortOrderChanged, + this, &DolphinView::slotSortOrderChangedByHeader); + connect(m_view, &DolphinItemListView::sortRoleChanged, + this, &DolphinView::slotSortRoleChangedByHeader); + connect(m_view, &DolphinItemListView::visibleRolesChanged, + this, &DolphinView::slotVisibleRolesChangedByHeader); + connect(m_view, &DolphinItemListView::roleEditingCanceled, + this, &DolphinView::slotRoleEditingCanceled); + connect(m_view->header(), &KItemListHeader::columnWidthChanged, + this, &DolphinView::slotHeaderColumnWidthChanged); KItemListSelectionManager* selectionManager = controller->selectionManager(); - connect(selectionManager, SIGNAL(selectionChanged(QSet,QSet)), - this, SLOT(slotSelectionChanged(QSet,QSet))); + connect(selectionManager, &KItemListSelectionManager::selectionChanged, + this, &DolphinView::slotSelectionChanged); m_toolTipManager = new ToolTipManager(this); m_versionControlObserver = new VersionControlObserver(this); m_versionControlObserver->setModel(m_model); - connect(m_versionControlObserver, SIGNAL(infoMessage(QString)), this, SIGNAL(infoMessage(QString))); - connect(m_versionControlObserver, SIGNAL(errorMessage(QString)), this, SIGNAL(errorMessage(QString))); - connect(m_versionControlObserver, SIGNAL(operationCompletedMessage(QString)), this, SIGNAL(operationCompletedMessage(QString))); + connect(m_versionControlObserver, &VersionControlObserver::infoMessage, this, &DolphinView::infoMessage); + connect(m_versionControlObserver, &VersionControlObserver::errorMessage, this, &DolphinView::errorMessage); + connect(m_versionControlObserver, &VersionControlObserver::operationCompletedMessage, this, &DolphinView::operationCompletedMessage); applyViewProperties(); m_topLayout->addWidget(m_container); @@ -294,7 +293,7 @@ void DolphinView::setHiddenFilesShown(bool show) const KFileItemList itemList = selectedItems(); m_selectedUrls.clear(); - m_selectedUrls = itemList.urlList(); + m_selectedUrls = KUrl::List(itemList.urlList()); ViewProperties props(viewPropertiesUrl()); props.setHiddenFilesShown(show); @@ -349,14 +348,9 @@ int DolphinView::itemsCount() const KFileItemList DolphinView::selectedItems() const { const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); - QList selectedIndexes = selectionManager->selectedItems().toList(); - - qSort(selectedIndexes); KFileItemList selectedItems; - QListIterator it(selectedIndexes); - while (it.hasNext()) { - const int index = it.next(); + foreach (int index, selectionManager->selectedItems()) { selectedItems.append(m_model->fileItem(index)); } return selectedItems; @@ -389,9 +383,9 @@ void DolphinView::selectItems(const QRegExp& pattern, bool enabled) for (int index = 0; index < m_model->count(); index++) { const KFileItem item = m_model->fileItem(index); if (pattern.exactMatch(item.text())) { - // An alternative approach would be to store the matching items in a QSet and + // An alternative approach would be to store the matching items in a KItemSet and // select them in one go after the loop, but we'd need a new function - // KItemListSelectionManager::setSelected(QSet, SelectionMode mode) + // KItemListSelectionManager::setSelected(KItemSet, SelectionMode mode) // for that. selectionManager->setSelected(index, 1, mode); } @@ -476,7 +470,7 @@ void DolphinView::reload() const KFileItemList itemList = selectedItems(); m_selectedUrls.clear(); - m_selectedUrls = itemList.urlList(); + m_selectedUrls = KUrl::List(itemList.urlList()); setUrl(url()); loadDirectory(url(), true); @@ -485,16 +479,11 @@ void DolphinView::reload() restoreState(restoreStream); } -void DolphinView::stopLoading() -{ - m_model->cancelDirectoryLoading(); -} - void DolphinView::readSettings() { const int oldZoomLevel = m_view->zoomLevel(); - GeneralSettings::self()->readConfig(); + GeneralSettings::self()->load(); m_view->readSettings(); applyViewProperties(); @@ -509,7 +498,7 @@ void DolphinView::readSettings() void DolphinView::writeSettings() { - GeneralSettings::self()->writeConfig(); + GeneralSettings::self()->save(); m_view->writeSettings(); } @@ -556,8 +545,8 @@ QString DolphinView::statusBarText() const } if (folderCount + fileCount == 1) { - // If only one item is selected, show the filename - filesText = i18nc("@info:status", "%1 selected", list.first().text()); + // If only one item is selected, show info about it + return list.first().getStatusBarInfo(); } else { // At least 2 items are selected foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount); @@ -572,11 +561,11 @@ QString DolphinView::statusBarText() const if (fileCount > 0 && folderCount > 0) { summary = i18nc("@info:status folders, files (size)", "%1, %2 (%3)", foldersText, filesText, - KGlobal::locale()->formatByteSize(totalFileSize)); + KFormat().formatByteSize(totalFileSize)); } else if (fileCount > 0) { summary = i18nc("@info:status files (size)", "%1 (%2)", filesText, - KGlobal::locale()->formatByteSize(totalFileSize)); + KFormat().formatByteSize(totalFileSize)); } else if (folderCount > 0) { summary = foldersText; } else { @@ -615,8 +604,8 @@ void DolphinView::setUrl(const KUrl& url) hideToolTip(); - disconnect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)), - this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant))); + disconnect(m_view, &DolphinItemListView::roleEditingFinished, + this, &DolphinView::slotRoleEditingFinished); // It is important to clear the items from the model before // applying the view properties, otherwise expensive operations @@ -658,8 +647,10 @@ void DolphinView::renameSelectedItems() const int index = m_model->index(items.first()); m_view->editRole(index, "text"); - connect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)), - this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant))); + hideToolTip(); + + connect(m_view, &DolphinItemListView::roleEditingFinished, + this, &DolphinView::slotRoleEditingFinished); } else { RenameDialog* dialog = new RenameDialog(this, items); dialog->setAttribute(Qt::WA_DeleteOnClose); @@ -677,31 +668,35 @@ void DolphinView::renameSelectedItems() void DolphinView::trashSelectedItems() { const KUrl::List list = simplifiedSelectedUrls(); - KonqOperations::del(this, KonqOperations::TRASH, list); + KIO::JobUiDelegate uiDelegate; + uiDelegate.setWindow(window()); + if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { + KIO::Job* job = KIO::trash(list); + KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, KUrl("trash:/"), job); + KJobWidgets::setWindow(job, this); + connect(job, &KIO::Job::result, + this, &DolphinView::slotTrashFileFinished); + } } void DolphinView::deleteSelectedItems() { const KUrl::List list = simplifiedSelectedUrls(); - const bool del = KonqOperations::askDeleteConfirmation(list, - KonqOperations::DEL, - KonqOperations::DEFAULT_CONFIRMATION, - this); - if (del) { + KIO::JobUiDelegate uiDelegate; + uiDelegate.setWindow(window()); + if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { KIO::Job* job = KIO::del(list); - if (job->ui()) { - job->ui()->setWindow(this); - } - connect(job, SIGNAL(result(KJob*)), - this, SLOT(slotDeleteFileFinished(KJob*))); + KJobWidgets::setWindow(job, this); + connect(job, &KIO::Job::result, + this, &DolphinView::slotDeleteFileFinished); } } void DolphinView::cutSelectedItems() { QMimeData* mimeData = selectionMimeData(); - KonqMimeData::addIsCutSelection(mimeData, true); + KIO::setClipboardDataCut(mimeData, true); QApplication::clipboard()->setMimeData(mimeData); } @@ -724,6 +719,11 @@ void DolphinView::pasteIntoFolder() } } +void DolphinView::stopLoading() +{ + m_model->cancelDirectoryLoading(); +} + bool DolphinView::eventFilter(QObject* watched, QEvent* event) { switch (event->type()) { @@ -802,7 +802,7 @@ void DolphinView::slotItemActivated(int index) } } -void DolphinView::slotItemsActivated(const QSet& indexes) +void DolphinView::slotItemsActivated(const KItemSet& indexes) { Q_ASSERT(indexes.count() >= 2); @@ -817,9 +817,7 @@ void DolphinView::slotItemsActivated(const QSet& indexes) KFileItemList items; items.reserve(indexes.count()); - QSetIterator it(indexes); - while (it.hasNext()) { - const int index = it.next(); + foreach (int index, indexes) { KFileItem item = m_model->fileItem(index); const KUrl& url = openItemAsFolderUrl(item); @@ -869,19 +867,15 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos) { ViewProperties props(viewPropertiesUrl()); - QPointer menu = new KMenu(QApplication::activeWindow()); + QPointer menu = new QMenu(QApplication::activeWindow()); KItemListView* view = m_container->controller()->view(); const QSet visibleRolesSet = view->visibleRoles().toSet(); - bool nepomukRunning = false; bool indexingEnabled = false; -#ifdef HAVE_NEPOMUK - nepomukRunning = (Nepomuk2::ResourceManager::instance()->initialized()); - if (nepomukRunning) { - KConfig config("nepomukserverrc"); - indexingEnabled = config.group("Service-nepomukfileindexer").readEntry("autostart", true); - } +#ifdef HAVE_BALOO + Baloo::IndexerConfig config; + indexingEnabled = config.fileIndexingEnabled(); #endif QString groupName; @@ -912,8 +906,8 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos) action->setChecked(visibleRolesSet.contains(info.role)); action->setData(info.role); - const bool enable = (!info.requiresNepomuk && !info.requiresIndexer) || - (info.requiresNepomuk && nepomukRunning) || + const bool enable = (!info.requiresBaloo && !info.requiresIndexer) || + (info.requiresBaloo) || (info.requiresIndexer && indexingEnabled); action->setEnabled(enable); } @@ -1054,7 +1048,8 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even if (op && destUrl == url()) { // Mark the dropped urls as selected. m_clearSelectionBeforeSelectingNewItems = true; - connect(op, SIGNAL(urlPasted(KUrl)), this, SLOT(slotUrlPasted(KUrl))); + m_markFirstNewlySelectedItemAsCurrent = true; + connect(op, static_cast(&KonqOperations::aboutToCreate), this, &DolphinView::slotAboutToCreate); } setActive(true); @@ -1063,32 +1058,30 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous) { if (previous != 0) { - disconnect(previous, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted())); + Q_ASSERT(qobject_cast(previous)); + KFileItemModel* fileItemModel = static_cast(previous); + disconnect(fileItemModel, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::slotDirectoryLoadingCompleted); m_versionControlObserver->setModel(0); } if (current) { Q_ASSERT(qobject_cast(current)); - connect(current, SIGNAL(loadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted())); - KFileItemModel* fileItemModel = static_cast(current); + connect(fileItemModel, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::slotDirectoryLoadingCompleted); m_versionControlObserver->setModel(fileItemModel); } } void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons) { + Q_UNUSED(itemIndex); + hideToolTip(); - if (itemIndex < 0) { - // Trigger the history navigation only when clicking on the viewport: - // Above an item the XButtons provide a simple way to select items in - // the singleClick mode. - if (buttons & Qt::XButton1) { - emit goBackRequested(); - } else if (buttons & Qt::XButton2) { - emit goForwardRequested(); - } + if (buttons & Qt::BackButton) { + emit goBackRequested(); + } else if (buttons & Qt::ForwardButton) { + emit goForwardRequested(); } } @@ -1099,11 +1092,11 @@ void DolphinView::slotAboutToCreate(const KUrl::List& urls) markUrlAsCurrent(urls.first()); m_markFirstNewlySelectedItemAsCurrent = false; } - m_selectedUrls << urls; + m_selectedUrls << KUrl::List(KDirModel::simplifiedUrlList(urls)); } } -void DolphinView::slotSelectionChanged(const QSet& current, const QSet& previous) +void DolphinView::slotSelectionChanged(const KItemSet& current, const KItemSet& previous) { const int currentCount = current.count(); const int previousCount = previous.count(); @@ -1176,6 +1169,14 @@ bool DolphinView::itemsExpandable() const void DolphinView::restoreState(QDataStream& stream) { + // Read the version number of the view state and check if the version is supported. + quint32 version = 0; + stream >> version; + if (version != 1) { + // The version of the view state isn't supported, we can't restore it. + return; + } + // Restore the current item that had the keyboard focus stream >> m_currentItemUrl; @@ -1190,6 +1191,8 @@ void DolphinView::restoreState(QDataStream& stream) void DolphinView::saveState(QDataStream& stream) { + stream << quint32(1); // View state version + // Save the current item that has the keyboard focus const int currentIndex = m_container->controller()->selectionManager()->currentItem(); if (currentIndex != -1) { @@ -1254,10 +1257,13 @@ KUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseTh } if (mimetype == QLatin1String("application/x-desktop")) { - // Redirect to the URL in Type=Link desktop files + // Redirect to the URL in Type=Link desktop files, unless it is a http(s) URL. KDesktopFile desktopFile(url.toLocalFile()); if (desktopFile.hasLinkType()) { - return desktopFile.readUrl(); + const QString linkUrl = desktopFile.readUrl(); + if (!linkUrl.startsWith(QLatin1String("http"))) { + return linkUrl; + } } } } @@ -1295,11 +1301,11 @@ void DolphinView::updateViewState() m_view->scrollToItem(currentIndex); m_scrollToCurrentItem = false; } - - m_currentItemUrl = KUrl(); } else { selectionManager->setCurrentItem(0); } + + m_currentItemUrl = KUrl(); } if (!m_restoredContentsPosition.isNull()) { @@ -1319,7 +1325,7 @@ void DolphinView::updateViewState() m_clearSelectionBeforeSelectingNewItems = false; } - QSet selectedItems = selectionManager->selectedItems(); + KItemSet selectedItems = selectionManager->selectedItems(); QList::iterator it = m_selectedUrls.begin(); while (it != m_selectedUrls.end()) { @@ -1359,14 +1365,13 @@ void DolphinView::calculateItemCount(int& fileCount, } } -void DolphinView::showHoverInformation(const KFileItem& item) +void DolphinView::slotTrashFileFinished(KJob* job) { - emit requestItemInfo(item); -} - -void DolphinView::clearHoverInformation() -{ - emit requestItemInfo(KFileItem()); + if (job->error() == 0) { + emit operationCompletedMessage(i18nc("@info:status", "Trash operation completed.")); + } else if (job->error() != KIO::ERR_USER_CANCELED) { + emit errorMessage(job->errorString()); + } } void DolphinView::slotDeleteFileFinished(KJob* job) @@ -1378,13 +1383,19 @@ void DolphinView::slotDeleteFileFinished(KJob* job) } } -void DolphinView::slotRenamingFailed(const KUrl& oldUrl, const KUrl& newUrl) +void DolphinView::slotRenamingResult(KJob* job) { - const int index = m_model->index(newUrl); - if (index >= 0) { - QHash data; - data.insert("text", oldUrl.fileName()); - m_model->setData(index, data); + if (job->error()) { + KIO::CopyJob *copyJob = qobject_cast(job); + Q_ASSERT(copyJob); + const QUrl newUrl = copyJob->destUrl(); + const int index = m_model->index(KUrl(newUrl)); + if (index >= 0) { + QHash data; + const QUrl oldUrl = copyJob->srcUrls().first(); + data.insert("text", oldUrl.fileName()); + m_model->setData(index, data); + } } } @@ -1456,14 +1467,14 @@ void DolphinView::slotVisibleRolesChangedByHeader(const QList& curre void DolphinView::slotRoleEditingCanceled() { - disconnect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)), - this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant))); + disconnect(m_view, &DolphinItemListView::roleEditingFinished, + this, &DolphinView::slotRoleEditingFinished); } void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value) { - disconnect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)), - this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant))); + disconnect(m_view, &DolphinItemListView::roleEditingFinished, + this, &DolphinView::slotRoleEditingFinished); if (index < 0 || index >= m_model->count()) { return; @@ -1475,12 +1486,14 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) { const KUrl oldUrl = oldItem.url(); - const KUrl newUrl(url().path(KUrl::AddTrailingSlash) + newName); - const bool newNameExistsAlready = (m_model->index(newUrl) >= 0); + QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename); + newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName)); + + const bool newNameExistsAlready = (m_model->index(KUrl(newUrl)) >= 0); if (!newNameExistsAlready) { // Only change the data in the model if no item with the new name // is in the model yet. If there is an item with the new name - // already, calling KonqOperations::rename() will open a dialog + // already, calling KIO::CopyJob will open a dialog // asking for a new name, and KFileItemModel will update the // data when the dir lister signals that the file name has changed. QHash data; @@ -1488,9 +1501,15 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con m_model->setData(index, data); } - KonqOperations* op = KonqOperations::renameV2(this, oldUrl, newName); - if (op) { - connect(op, SIGNAL(renamingFailed(KUrl,KUrl)), SLOT(slotRenamingFailed(KUrl,KUrl))); + KIO::Job * job = KIO::moveAs(oldUrl, newUrl); + KJobWidgets::setWindow(job, this); + KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, QList() << oldUrl, newUrl, job); + job->ui()->setAutoErrorHandlingEnabled(true); + + if (!newNameExistsAlready) { + // Only connect the result signal if there is no item with the new name + // in the model yet, see bug 328262. + connect(job, &KJob::result, this, &DolphinView::slotRenamingResult); } } } @@ -1631,7 +1650,7 @@ void DolphinView::pasteToUrl(const KUrl& url) if (op) { m_clearSelectionBeforeSelectingNewItems = true; m_markFirstNewlySelectedItemAsCurrent = true; - connect(op, SIGNAL(aboutToCreate(KUrl::List)), this, SLOT(slotAboutToCreate(KUrl::List))); + connect(op, static_cast(&KonqOperations::aboutToCreate), this, &DolphinView::slotAboutToCreate); } } @@ -1655,7 +1674,7 @@ KUrl::List DolphinView::simplifiedSelectedUrls() const QMimeData* DolphinView::selectionMimeData() const { const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); - const QSet selectedIndexes = selectionManager->selectedItems(); + const KItemSet selectedIndexes = selectionManager->selectedItems(); return m_model->createMimeData(selectedIndexes); } @@ -1663,13 +1682,18 @@ QMimeData* DolphinView::selectionMimeData() const void DolphinView::updateWritableState() { const bool wasFolderWritable = m_isFolderWritable; - m_isFolderWritable = true; + m_isFolderWritable = false; - const KFileItem item = m_model->rootItem(); - if (!item.isNull()) { - KFileItemListProperties capabilities(KFileItemList() << item); - m_isFolderWritable = capabilities.supportsWriting(); + KFileItem item = m_model->rootItem(); + if (item.isNull()) { + // Try to find out if the URL is writable even if the "root item" is + // null, see https://bugs.kde.org/show_bug.cgi?id=330001 + item = KFileItem(KFileItem::Unknown, KFileItem::Unknown, url(), true); } + + KFileItemListProperties capabilities(KFileItemList() << item); + m_isFolderWritable = capabilities.supportsWriting(); + if (m_isFolderWritable != wasFolderWritable) { emit writeStateChanged(m_isFolderWritable); } @@ -1687,4 +1711,3 @@ KUrl DolphinView::viewPropertiesUrl() const return url; } -#include "dolphinview.moc"