X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/73c30c7ea25891d3579277734393b70d9d1e2ab3..36a816d7a63c58ead01002db59c2cf8862c72c97:/src/views/dolphinview.cpp?ds=sidebyside diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 6a21885e6..f0fad1976 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -73,7 +73,7 @@ #include "zoomlevelinfo.h" #ifdef HAVE_NEPOMUK - #include + #include #endif namespace { @@ -98,9 +98,10 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : m_toolTipManager(0), m_selectionChangedTimer(0), m_currentItemUrl(), + m_scrollToCurrentItem(false), m_restoredContentsPosition(), - m_createdItemUrl(), m_selectedUrls(), + m_clearSelectionBeforeSelectingNewItems(false), m_versionControlObserver(0) { m_topLayout = new QVBoxLayout(this); @@ -122,7 +123,6 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : m_model = new KFileItemModel(this); m_view = new DolphinItemListView(); m_view->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle()); - m_view->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews()); m_view->setVisibleRoles(QList() << "text"); applyModeToView(); @@ -130,6 +130,10 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1; controller->setAutoActivationDelay(delay); + // The EnlargeSmallPreviews setting can only be changed after the model + // has been set in the view by KItemListController. + m_view->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews()); + m_container = new KItemListContainer(controller, this); m_container->installEventFilter(this); setFocusProxy(m_container); @@ -151,6 +155,7 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : 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)), @@ -160,6 +165,7 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : 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))); m_view->installEventFilter(this); connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)), @@ -259,8 +265,14 @@ void DolphinView::setPreviewsShown(bool show) ViewProperties props(viewPropertiesUrl()); props.setPreviewsShown(show); + const int oldZoomLevel = m_view->zoomLevel(); m_view->setPreviewsShown(show); emit previewsShownChanged(show); + + const int newZoomLevel = m_view->zoomLevel(); + if (newZoomLevel != oldZoomLevel) { + emit zoomLevelChanged(newZoomLevel, oldZoomLevel); + } } bool DolphinView::previewsShown() const @@ -331,10 +343,12 @@ int DolphinView::itemsCount() const KFileItemList DolphinView::selectedItems() const { const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); - const QSet selectedIndexes = selectionManager->selectedItems(); + QList selectedIndexes = selectionManager->selectedItems().toList(); + + qSort(selectedIndexes); KFileItemList selectedItems; - QSetIterator it(selectedIndexes); + QListIterator it(selectedIndexes); while (it.hasNext()) { const int index = it.next(); selectedItems.append(m_model->fileItem(index)); @@ -356,6 +370,7 @@ void DolphinView::markUrlsAsSelected(const QList& urls) void DolphinView::markUrlAsCurrent(const KUrl& url) { m_currentItemUrl = url; + m_scrollToCurrentItem = true; } void DolphinView::selectItems(const QRegExp& pattern, bool enabled) @@ -382,6 +397,7 @@ void DolphinView::setZoomLevel(int level) const int oldZoomLevel = zoomLevel(); m_view->setZoomLevel(level); if (zoomLevel() != oldZoomLevel) { + hideToolTip(); emit zoomLevelChanged(zoomLevel(), oldZoomLevel); } } @@ -501,6 +517,16 @@ QString DolphinView::nameFilter() const return m_model->nameFilter(); } +void DolphinView::setMimeTypeFilters(const QStringList& filters) +{ + return m_model->setMimeTypeFilters(filters); +} + +QStringList DolphinView::mimeTypeFilters() const +{ + return m_model->mimeTypeFilters(); +} + QString DolphinView::statusBarText() const { QString summary; @@ -576,6 +602,8 @@ void DolphinView::setUrl(const KUrl& url) return; } + clearSelection(); + emit urlAboutToBeChanged(url); m_url = url; @@ -606,31 +634,32 @@ void DolphinView::invertSelection() void DolphinView::clearSelection() { + m_selectedUrls.clear(); m_container->controller()->selectionManager()->clearSelection(); } void DolphinView::renameSelectedItems() { const KFileItemList items = selectedItems(); - if (items.isEmpty()) { - return; - } - - if (items.count() == 1) { - const int index = m_model->index(items.first()); - m_container->controller()->view()->editRole(index, "text"); - } else { - RenameDialog* dialog = new RenameDialog(this, items); - dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->show(); - dialog->raise(); - dialog->activateWindow(); - } - - // Assure that the current index remains visible when KFileItemModel - // will notify the view about changed items (which might result in - // a changed sorting). - m_assureVisibleCurrentIndex = true; + if (items.isEmpty()) { + return; + } + + if (items.count() == 1 && GeneralSettings::renameInline()) { + const int index = m_model->index(items.first()); + m_view->editRole(index, "text"); + } else { + RenameDialog* dialog = new RenameDialog(this, items); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); + dialog->raise(); + dialog->activateWindow(); + } + + // Assure that the current index remains visible when KFileItemModel + // will notify the view about changed items (which might result in + // a changed sorting). + m_assureVisibleCurrentIndex = true; } void DolphinView::trashSelectedItems() @@ -734,6 +763,20 @@ void DolphinView::hideEvent(QHideEvent* event) QWidget::hideEvent(event); } +bool DolphinView::event(QEvent* event) +{ + /* See Bug 297355 + * Dolphin leaves file preview tooltips open even when is not visible. + * + * Hide tool-tip when Dolphin loses focus. + */ + if (event->type() == QEvent::WindowDeactivate) { + hideToolTip(); + } + + return QWidget::event(event); +} + void DolphinView::activate() { setActive(true); @@ -751,21 +794,34 @@ void DolphinView::slotItemsActivated(const QSet& indexes) { Q_ASSERT(indexes.count() >= 2); + if (indexes.count() > 5) { + QString question = i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes.count()); + const int answer = KMessageBox::warningYesNo(this, question); + if (answer != KMessageBox::Yes) { + return; + } + } + KFileItemList items; + items.reserve(indexes.count()); QSetIterator it(indexes); while (it.hasNext()) { const int index = it.next(); - items.append(m_model->fileItem(index)); - } + KFileItem item = m_model->fileItem(index); - foreach (const KFileItem& item, items) { - if (item.isDir()) { + if (item.isDir()) { // Open folders in new tabs emit tabRequested(item.url()); } else { - emit itemActivated(item); + items.append(item); } } + + if (items.count() == 1) { + emit itemActivated(items.first()); + } else if (items.count() > 1) { + emit itemsActivated(items); + } } void DolphinView::slotItemMiddleClicked(int index) @@ -799,10 +855,10 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos) bool nepomukRunning = false; bool indexingEnabled = false; #ifdef HAVE_NEPOMUK - nepomukRunning = (Nepomuk::ResourceManager::instance()->initialized()); + nepomukRunning = (Nepomuk2::ResourceManager::instance()->initialized()); if (nepomukRunning) { KConfig config("nepomukserverrc"); - indexingEnabled = config.group("Service-nepomukfileindexer").readEntry("autostart", false); + indexingEnabled = config.group("Service-nepomukfileindexer").readEntry("autostart", true); } #endif @@ -1134,25 +1190,11 @@ QString DolphinView::viewPropertiesContext() const void DolphinView::observeCreatedItem(const KUrl& url) { - m_createdItemUrl = url; - connect(m_model, SIGNAL(directoryLoadingCompleted()), - this, SLOT(selectAndScrollToCreatedItem())); -} - -void DolphinView::selectAndScrollToCreatedItem() -{ - KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); - const int index = m_model->index(m_createdItemUrl); - if (index != -1) { - selectionManager->setCurrentItem(index); - selectionManager->clearSelection(); - selectionManager->setSelected(index); - m_view->scrollToItem(index); + if (m_active) { + clearSelection(); + markUrlAsCurrent(url); + markUrlsAsSelected(QList() << url); } - - disconnect(m_model, SIGNAL(directoryLoadingCompleted()), - this, SLOT(selectAndScrollToCreatedItem())); - m_createdItemUrl = KUrl(); } void DolphinView::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl) @@ -1170,6 +1212,12 @@ void DolphinView::updateViewState() const int currentIndex = m_model->index(m_currentItemUrl); if (currentIndex != -1) { selectionManager->setCurrentItem(currentIndex); + + // scroll to current item and reset the state + if (m_scrollToCurrentItem) { + m_view->scrollToItem(currentIndex); + m_scrollToCurrentItem = false; + } } else { selectionManager->setCurrentItem(0); } @@ -1186,20 +1234,27 @@ void DolphinView::updateViewState() } if (!m_selectedUrls.isEmpty()) { - clearSelection(); - KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); + + if (m_clearSelectionBeforeSelectingNewItems) { + selectionManager->clearSelection(); + m_clearSelectionBeforeSelectingNewItems = false; + } + QSet selectedItems = selectionManager->selectedItems(); - foreach (const KUrl& url, m_selectedUrls) { - const int index = m_model->index(url); + QList::iterator it = m_selectedUrls.begin(); + while (it != m_selectedUrls.end()) { + const int index = m_model->index(*it); if (index >= 0) { selectedItems.insert(index); + it = m_selectedUrls.erase(it); + } else { + ++it; } } selectionManager->setSelectedItems(selectedItems); - m_selectedUrls.clear(); } } @@ -1313,11 +1368,30 @@ void DolphinView::slotVisibleRolesChangedByHeader(const QList& curre void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value) { + if (index < 0 || index >= m_model->count()) { + return; + } + if (role == "text") { - const KFileItem item = m_model->fileItem(index); + const KFileItem oldItem = m_model->fileItem(index); const QString newName = value.toString(); - if (!newName.isEmpty() && newName != item.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) { - KonqOperations::rename(this, item.url(), newName); + 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); + 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 + // asking for a new name, and KFileItemModel will update the + // data when the dir lister signals that the file name has changed. + QHash data; + data.insert(role, value); + m_model->setData(index, data); + } + + KonqOperations::rename(this, oldUrl, newName); } } } @@ -1458,7 +1532,7 @@ KUrl::List DolphinView::simplifiedSelectedUrls() const KUrl::List urls; const KFileItemList items = selectedItems(); - foreach (const KFileItem &item, items) { + foreach (const KFileItem& item, items) { urls.append(item.url()); } @@ -1483,10 +1557,11 @@ void DolphinView::markPastedUrlsAsSelected(const QMimeData* mimeData) const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData); KUrl::List destUrls; foreach (const KUrl& source, sourceUrls) { - KUrl destination(url().url() + "/" + source.fileName()); + KUrl destination(url().url() + '/' + source.fileName()); destUrls << destination; } markUrlsAsSelected(destUrls); + m_clearSelectionBeforeSelectingNewItems = true; } void DolphinView::updateWritableState()