X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/de3e2ae40f626c1368dfd40bace54ef3e7815833..3653c8ad6bfb21a4b098f4e89d5ff34ed6df2901:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index ce8e08210..0b3209aee 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -24,26 +24,21 @@ #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 @@ -51,19 +46,17 @@ #include #include #include +#include #include #include #include #include +#include #include -#include -#include +#include #include #include -#include #include -#include -#include #include #include "dolphinnewfilemenuobserver.h" @@ -81,12 +74,13 @@ #ifdef HAVE_BALOO #include #endif +#include namespace { const int MaxModeEnum = DolphinView::CompactView; }; -DolphinView::DolphinView(const KUrl& url, QWidget* parent) : +DolphinView::DolphinView(const QUrl& url, QWidget* parent) : QWidget(parent), m_active(true), m_tabsForFiles(false), @@ -209,7 +203,7 @@ DolphinView::~DolphinView() { } -KUrl DolphinView::url() const +QUrl DolphinView::url() const { return m_url; } @@ -368,12 +362,12 @@ int DolphinView::selectedItemsCount() const return selectionManager->selectedItems().count(); } -void DolphinView::markUrlsAsSelected(const QList& urls) +void DolphinView::markUrlsAsSelected(const QList& urls) { m_selectedUrls = urls; } -void DolphinView::markUrlAsCurrent(const KUrl& url) +void DolphinView::markUrlAsCurrent(const QUrl &url) { m_currentItemUrl = url; m_scrollToCurrentItem = true; @@ -489,7 +483,7 @@ void DolphinView::readSettings() { const int oldZoomLevel = m_view->zoomLevel(); - GeneralSettings::self()->readConfig(); + GeneralSettings::self()->load(); m_view->readSettings(); applyViewProperties(); @@ -504,7 +498,7 @@ void DolphinView::readSettings() void DolphinView::writeSettings() { - GeneralSettings::self()->writeConfig(); + GeneralSettings::self()->save(); m_view->writeSettings(); } @@ -567,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 { @@ -674,22 +668,26 @@ 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()) { - KJobWidgets::setWindow(job, this); - } + KJobWidgets::setWindow(job, this); connect(job, &KIO::Job::result, this, &DolphinView::slotDeleteFileFinished); } @@ -698,7 +696,7 @@ void DolphinView::deleteSelectedItems() void DolphinView::cutSelectedItems() { QMimeData* mimeData = selectionMimeData(); - KonqMimeData::addIsCutSelection(mimeData, true); + KIO::setClipboardDataCut(mimeData, true); QApplication::clipboard()->setMimeData(mimeData); } @@ -869,7 +867,7 @@ 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(); @@ -1051,7 +1049,7 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even // Mark the dropped urls as selected. m_clearSelectionBeforeSelectingNewItems = true; m_markFirstNewlySelectedItemAsCurrent = true; - connect(op, static_cast(&KonqOperations::aboutToCreate), this, &DolphinView::slotAboutToCreate); + connect(op, static_cast&)>(&KonqOperations::aboutToCreate), this, &DolphinView::slotAboutToCreate); } setActive(true); @@ -1080,22 +1078,21 @@ void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons hideToolTip(); - // TODO: Qt5: Replace Qt::XButton1 by Qt::BackButton and Qt::XButton2 by Qt::ForwardButton - if (buttons & Qt::XButton1) { + if (buttons & Qt::BackButton) { emit goBackRequested(); - } else if (buttons & Qt::XButton2) { + } else if (buttons & Qt::ForwardButton) { emit goForwardRequested(); } } -void DolphinView::slotAboutToCreate(const KUrl::List& urls) +void DolphinView::slotAboutToCreate(const QList& urls) { if (!urls.isEmpty()) { if (m_markFirstNewlySelectedItemAsCurrent) { markUrlAsCurrent(urls.first()); m_markFirstNewlySelectedItemAsCurrent = false; } - m_selectedUrls << KUrl::List(KDirModel::simplifiedUrlList(urls)); + m_selectedUrls << KDirModel::simplifiedUrlList(urls); } } @@ -1172,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; @@ -1179,13 +1184,15 @@ void DolphinView::restoreState(QDataStream& stream) stream >> m_restoredContentsPosition; // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes) - QSet urls; + QSet urls; stream >> urls; m_model->restoreExpandedDirectories(urls); } 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) { @@ -1264,18 +1271,18 @@ KUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseTh return KUrl(); } -void DolphinView::observeCreatedItem(const KUrl& url) +void DolphinView::observeCreatedItem(const QUrl& url) { if (m_active) { clearSelection(); markUrlAsCurrent(url); - markUrlsAsSelected(QList() << url); + markUrlsAsSelected(QList() << url); } } -void DolphinView::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl) +void DolphinView::slotDirectoryRedirection(const QUrl& oldUrl, const QUrl& newUrl) { - if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash)) { + if (oldUrl.matches(url(), QUrl::StripTrailingSlash)) { emit redirection(oldUrl, newUrl); m_url = newUrl; // #186947 } @@ -1283,7 +1290,7 @@ void DolphinView::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUr void DolphinView::updateViewState() { - if (m_currentItemUrl != KUrl()) { + if (m_currentItemUrl != QUrl()) { KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); const int currentIndex = m_model->index(m_currentItemUrl); if (currentIndex != -1) { @@ -1294,11 +1301,11 @@ void DolphinView::updateViewState() m_view->scrollToItem(currentIndex); m_scrollToCurrentItem = false; } - - m_currentItemUrl = KUrl(); } else { selectionManager->setCurrentItem(0); } + + m_currentItemUrl = QUrl(); } if (!m_restoredContentsPosition.isNull()) { @@ -1320,7 +1327,7 @@ void DolphinView::updateViewState() KItemSet selectedItems = selectionManager->selectedItems(); - QList::iterator it = m_selectedUrls.begin(); + QList::iterator it = m_selectedUrls.begin(); while (it != m_selectedUrls.end()) { const int index = m_model->index(*it); if (index >= 0) { @@ -1358,6 +1365,15 @@ void DolphinView::calculateItemCount(int& fileCount, } } +void DolphinView::slotTrashFileFinished(KJob* job) +{ + 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) { if (job->error() == 0) { @@ -1367,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(newUrl); + if (index >= 0) { + QHash data; + const QUrl oldUrl = copyJob->srcUrls().first(); + data.insert("text", oldUrl.fileName()); + m_model->setData(index, data); + } } } @@ -1464,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; @@ -1477,11 +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 && !newNameExistsAlready) { - // Only connect the renamingFailed signal if there is no item with the new name + 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(op, &KonqOperations::renamingFailed, this, &DolphinView::slotRenamingFailed); + connect(job, &KJob::result, this, &DolphinView::slotRenamingResult); } } } @@ -1618,11 +1646,11 @@ void DolphinView::applyModeToView() void DolphinView::pasteToUrl(const KUrl& url) { - KonqOperations* op = KonqOperations::doPasteV2(this, url); + KonqOperations* op = KonqOperations::doPaste(this, url); if (op) { m_clearSelectionBeforeSelectingNewItems = true; m_markFirstNewlySelectedItemAsCurrent = true; - connect(op, static_cast(&KonqOperations::aboutToCreate), this, &DolphinView::slotAboutToCreate); + connect(op, static_cast&)>(&KonqOperations::aboutToCreate), this, &DolphinView::slotAboutToCreate); } }