X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/93cb7e02616df9746f7cdae09434e7488f4e7d28..283f97ac27c3cfe5c72682b0843503e31643a612:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index a53934ddc..871de946b 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -90,10 +90,10 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : m_container(0), m_toolTipManager(0), m_selectionChangedTimer(0), - m_currentItemIndex(-1), + m_currentItemUrl(), m_restoredContentsPosition(), m_createdItemUrl(), - m_selectedItems(), + m_selectedUrls(), m_versionControlObserver(0) { m_topLayout = new QVBoxLayout(this); @@ -151,7 +151,6 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : connect(m_dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl))); connect(m_dirLister, SIGNAL(started(KUrl)), this, SLOT(slotDirListerStarted(KUrl))); - connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted())); connect(m_dirLister, SIGNAL(refreshItems(QList >)), this, SLOT(slotRefreshItems())); @@ -164,22 +163,28 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : connect(m_dirLister, SIGNAL(itemsDeleted(KFileItemList)), this, SIGNAL(itemCountChanged())); m_container = new DolphinItemListContainer(m_dirLister, this); - QHash visibleRoles; - visibleRoles.insert("name", 0); - m_container->setVisibleRoles(visibleRoles); + m_container->setVisibleRoles(QList() << "name"); + m_container->installEventFilter(this); KItemListController* controller = m_container->controller(); controller->setSelectionBehavior(KItemListController::MultiSelection); connect(controller, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int))); connect(controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int))); - connect(controller, SIGNAL(contextMenuRequested(int,QPointF)), this, SLOT(slotContextMenuRequested(int,QPointF))); + 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(itemExpansionToggleClicked(int)), this, SLOT(slotItemExpansionToggleClicked(int))); 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*))); + KFileItemModel* model = fileItemModel(); + if (model) { + connect(model, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted())); + } + KItemListSelectionManager* selectionManager = controller->selectionManager(); connect(selectionManager, SIGNAL(selectionChanged(QSet,QSet)), this, SLOT(slotSelectionChanged(QSet,QSet))); @@ -187,7 +192,7 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : m_toolTipManager = new ToolTipManager(this); m_versionControlObserver = new VersionControlObserver(this); - m_versionControlObserver->setModel(fileItemModel()); + m_versionControlObserver->setModel(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))); @@ -262,19 +267,65 @@ DolphinView::Mode DolphinView::mode() const return m_mode; } +void DolphinView::setPreviewsShown(bool show) +{ + if (previewsShown() == show) { + return; + } + + ViewProperties props(url()); + props.setPreviewsShown(show); + + m_container->setPreviewsShown(show); + emit previewsShownChanged(show); +} + bool DolphinView::previewsShown() const { return m_container->previewsShown(); } +void DolphinView::setHiddenFilesShown(bool show) +{ + if (m_dirLister->showingDotFiles() == show) { + return; + } + + const KFileItemList itemList = selectedItems(); + m_selectedUrls.clear(); + m_selectedUrls = itemList.urlList(); + + ViewProperties props(url()); + props.setHiddenFilesShown(show); + + m_dirLister->setShowingDotFiles(show); + m_dirLister->emitChanges(); + emit hiddenFilesShownChanged(show); +} + bool DolphinView::hiddenFilesShown() const { return m_dirLister->showingDotFiles(); } -bool DolphinView::categorizedSorting() const +void DolphinView::setGroupedSorting(bool grouped) { - return false; //m_storedCategorizedSorting; + if (grouped == groupedSorting()) { + return; + } + + ViewProperties props(url()); + props.setGroupedSorting(grouped); + props.save(); + + m_container->controller()->model()->setGroupedSorting(grouped); + + emit groupedSortingChanged(grouped); +} + +bool DolphinView::groupedSorting() const +{ + return fileItemModel()->groupedSorting(); } KFileItemList DolphinView::items() const @@ -305,10 +356,7 @@ int DolphinView::selectedItemsCount() const void DolphinView::markUrlsAsSelected(const QList& urls) { - foreach (const KUrl& url, urls) { - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); - m_selectedItems.append(item); - } + m_selectedUrls = urls; } void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled) @@ -354,8 +402,8 @@ void DolphinView::setSorting(Sorting sorting) DolphinView::Sorting DolphinView::sorting() const { - return DolphinView::SortByName; - //return m_viewAccessor.proxyModel()->sorting(); + KItemModelBase* model = m_container->controller()->model(); + return sortingForSortRole(model->sortRole()); } void DolphinView::setSortOrder(Qt::SortOrder order) @@ -367,7 +415,8 @@ void DolphinView::setSortOrder(Qt::SortOrder order) Qt::SortOrder DolphinView::sortOrder() const { - return Qt::AscendingOrder; // m_viewAccessor.proxyModel()->sortOrder(); + KItemModelBase* model = fileItemModel(); + return model->sortOrder(); } void DolphinView::setSortFoldersFirst(bool foldersFirst) @@ -379,7 +428,8 @@ void DolphinView::setSortFoldersFirst(bool foldersFirst) bool DolphinView::sortFoldersFirst() const { - return true; // m_viewAccessor.proxyModel()->sortFoldersFirst(); + KFileItemModel* model = fileItemModel(); + return model->sortFoldersFirst(); } void DolphinView::setAdditionalInfoList(const QList& info) @@ -405,7 +455,10 @@ void DolphinView::reload() QByteArray viewState; QDataStream saveStream(&viewState, QIODevice::WriteOnly); saveState(saveStream); - m_selectedItems= selectedItems(); + + const KFileItemList itemList = selectedItems(); + m_selectedUrls.clear(); + m_selectedUrls = itemList.urlList(); setUrl(url()); loadDirectory(url(), true); @@ -521,10 +574,10 @@ QList DolphinView::versionControlActions(const KFileItemList& items) c QList actions; if (items.isEmpty()) { - const KUrl url = fileItemModel()->rootDirectory(); - actions = m_versionControlObserver->contextMenuActions(url.path(KUrl::AddTrailingSlash)); + const KFileItem item = fileItemModel()->rootItem(); + actions = m_versionControlObserver->actions(KFileItemList() << item); } else { - actions = m_versionControlObserver->contextMenuActions(items); + actions = m_versionControlObserver->actions(items); } return actions; @@ -643,67 +696,20 @@ void DolphinView::pasteIntoFolder() } } -void DolphinView::setPreviewsShown(bool show) +bool DolphinView::eventFilter(QObject* watched, QEvent* event) { - if (previewsShown() == show) { - return; - } - - ViewProperties props(url()); - props.setPreviewsShown(show); - - m_container->setPreviewsShown(show); - emit previewsShownChanged(show); -} - -void DolphinView::setHiddenFilesShown(bool show) -{ - if (m_dirLister->showingDotFiles() == show) { - return; - } - - m_selectedItems = selectedItems(); - - ViewProperties props(url()); - props.setHiddenFilesShown(show); - - m_dirLister->setShowingDotFiles(show); - m_dirLister->emitChanges(); - emit hiddenFilesShownChanged(show); -} + switch (event->type()) { + case QEvent::FocusIn: + if (watched == m_container) { + setActive(true); + } + break; -void DolphinView::setCategorizedSorting(bool categorized) -{ - if (categorized == categorizedSorting()) { - return; + default: + break; } - ViewProperties props(url()); - props.setCategorizedSorting(categorized); - props.save(); - - //m_viewAccessor.proxyModel()->setCategorizedModel(categorized); - - emit categorizedSortingChanged(categorized); -} - -void DolphinView::mouseReleaseEvent(QMouseEvent* event) -{ - QWidget::mouseReleaseEvent(event); - setActive(true); -} - -void DolphinView::contextMenuEvent(QContextMenuEvent* event) -{ - Q_UNUSED(event); - - const QPoint pos = m_container->mapFromGlobal(QCursor::pos()); - const KItemListView* view = m_container->controller()->view(); - if (view->itemAt(pos) < 0) { - // Only open the context-menu if the cursor is above the viewport - // (the context-menu for items is handled in slotContextMenuRequested()) - requestContextMenu(KFileItem(), url(), QList()); - } + return QWidget::eventFilter(watched, event); } void DolphinView::wheelEvent(QWheelEvent* event) @@ -713,8 +719,10 @@ void DolphinView::wheelEvent(QWheelEvent* event) const int numSteps = numDegrees / 15; setZoomLevel(zoomLevel() + numSteps); + event->accept(); + } else { + event->ignore(); } - event->accept(); } void DolphinView::activate() @@ -752,14 +760,71 @@ void DolphinView::slotItemMiddleClicked(int index) } } -void DolphinView::slotContextMenuRequested(int index, const QPointF& pos) +void DolphinView::slotItemContextMenuRequested(int index, const QPointF& pos) { - Q_UNUSED(pos); if (GeneralSettings::showToolTips()) { m_toolTipManager->hideToolTip(); } const KFileItem item = fileItemModel()->fileItem(index); - emit requestContextMenu(item, url(), QList()); + emit requestContextMenu(pos.toPoint(), item, url(), QList()); +} + +void DolphinView::slotViewContextMenuRequested(const QPointF& pos) +{ + if (GeneralSettings::showToolTips()) { + m_toolTipManager->hideToolTip(); + } + emit requestContextMenu(pos.toPoint(), KFileItem(), url(), QList()); +} + +void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos) +{ + QWeakPointer menu = new KMenu(QApplication::activeWindow()); + + KItemListView* view = m_container->controller()->view(); + const QSet visibleRolesSet = view->visibleRoles().toSet(); + + // Add all roles to the menu that can be shown or hidden by the user + const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); + const QList keys = infoAccessor.keys(); + foreach (const DolphinView::AdditionalInfo info, keys) { + const QByteArray& role = infoAccessor.role(info); + if (role != "name") { + const QString text = fileItemModel()->roleDescription(role); + + QAction* action = menu.data()->addAction(text); + action->setCheckable(true); + action->setChecked(visibleRolesSet.contains(role)); + action->setData(info); + } + } + + QAction* action = menu.data()->exec(pos.toPoint()); + if (action) { + // Show or hide the selected role + const DolphinView::AdditionalInfo info = + static_cast(action->data().toInt()); + + ViewProperties props(url()); + QList infoList = props.additionalInfoList(); + + const QByteArray selectedRole = infoAccessor.role(info); + QList visibleRoles = view->visibleRoles(); + + if (action->isChecked()) { + const int index = keys.indexOf(info) + 1; + visibleRoles.insert(index, selectedRole); + infoList.insert(index, info); + } else { + visibleRoles.removeOne(selectedRole); + infoList.removeOne(info); + } + + view->setVisibleRoles(visibleRoles); + props.setAdditionalInfoList(infoList); + } + + delete menu.data(); } void DolphinView::slotItemExpansionToggleClicked(int index) @@ -812,8 +877,12 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous) { - Q_UNUSED(previous); + if (previous != 0) { + disconnect(previous, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted())); + } + Q_ASSERT(qobject_cast(current)); + connect(current, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted())); KFileItemModel* fileItemModel = static_cast(current); m_versionControlObserver->setModel(fileItemModel); @@ -839,18 +908,6 @@ void DolphinView::emitSelectionChangedSignal() emit selectionChanged(selectedItems()); } -void DolphinView::openContextMenu(const QPoint& pos, - const QList& customActions) -{ - KFileItem item; - const int index = m_container->controller()->view()->itemAt(pos); - if (index >= 0) { - item = fileItemModel()->fileItem(index); - } - - emit requestContextMenu(item, url(), customActions); -} - void DolphinView::dropUrls(const KFileItem& destItem, const KUrl& destPath, QDropEvent* event) @@ -877,7 +934,8 @@ void DolphinView::updateSortOrder(Qt::SortOrder order) ViewProperties props(url()); props.setSortOrder(order); - //m_viewAccessor.proxyModel()->setSortOrder(order); + KItemModelBase* model = fileItemModel(); + model->setSortOrder(order); emit sortOrderChanged(order); } @@ -887,7 +945,8 @@ void DolphinView::updateSortFoldersFirst(bool foldersFirst) ViewProperties props(url()); props.setSortFoldersFirst(foldersFirst); - //m_viewAccessor.proxyModel()->setSortFoldersFirst(foldersFirst); + KFileItemModel* model = fileItemModel(); + model->setSortFoldersFirst(foldersFirst); emit sortFoldersFirstChanged(foldersFirst); } @@ -915,28 +974,28 @@ bool DolphinView::itemsExpandable() const void DolphinView::restoreState(QDataStream& stream) { // Restore the current item that had the keyboard focus - stream >> m_currentItemIndex; + stream >> m_currentItemUrl; // Restore the view position stream >> m_restoredContentsPosition; // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes) - QSet urlsToExpand; - stream >> urlsToExpand; - /*const DolphinDetailsViewExpander* expander = m_viewAccessor.setExpandedUrls(urlsToExpand); - if (expander) { - m_expanderActive = true; - connect (expander, SIGNAL(completed()), this, SLOT(slotLoadingCompleted())); - } - else { - m_expanderActive = false; - }*/ + QSet urls; + stream >> urls; + fileItemModel()->restoreExpandedUrls(urls); } void DolphinView::saveState(QDataStream& stream) { // Save the current item that has the keyboard focus - stream << m_container->controller()->selectionManager()->currentItem(); + const int currentIndex = m_container->controller()->selectionManager()->currentItem(); + if (currentIndex != -1) { + KFileItem item = fileItemModel()->fileItem(currentIndex); + KUrl currentItemUrl = item.url(); + stream << currentItemUrl; + } else { + stream << KUrl(); + } // Save view position const qreal x = m_container->horizontalScrollBar()->value(); @@ -944,7 +1003,7 @@ void DolphinView::saveState(QDataStream& stream) stream << QPoint(x, y); // Save expanded folders (only relevant for the details view - the set will be empty in other view modes) - //stream << m_viewAccessor.expandedUrls(); + stream << fileItemModel()->expandedUrls(); } bool DolphinView::hasSelection() const @@ -990,10 +1049,15 @@ void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl) void DolphinView::updateViewState() { - if (m_currentItemIndex >= 0) { + if (m_currentItemUrl != KUrl()) { KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); - selectionManager->setCurrentItem(m_currentItemIndex); - m_currentItemIndex =-1; + const int currentIndex = fileItemModel()->index(m_currentItemUrl); + if (currentIndex != -1) { + selectionManager->setCurrentItem(currentIndex); + } else { + selectionManager->setCurrentItem(0); + } + m_currentItemUrl = KUrl(); } if (!m_restoredContentsPosition.isNull()) { @@ -1005,20 +1069,20 @@ void DolphinView::updateViewState() m_container->verticalScrollBar()->setValue(y); } - if (!m_selectedItems.isEmpty()) { + if (!m_selectedUrls.isEmpty()) { KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); QSet selectedItems = selectionManager->selectedItems(); const KFileItemModel* model = fileItemModel(); - foreach (const KFileItem& selectedItem, m_selectedItems) { - const int index = model->index(selectedItem); + foreach (const KUrl& url, m_selectedUrls) { + const int index = model->index(url); if (index >= 0) { selectedItems.insert(index); } } selectionManager->setSelectedItems(selectedItems); - m_selectedItems.clear(); + m_selectedUrls.clear(); } } @@ -1044,7 +1108,7 @@ void DolphinView::slotDeleteFileFinished(KJob* job) void DolphinView::slotDirListerStarted(const KUrl& url) { // Disable the writestate temporary until it can be determined in a fast way - // in DolphinView::slotDirListerCompleted() + // in DolphinView::slotLoadingCompleted() if (m_isFolderWritable) { m_isFolderWritable = false; emit writeStateChanged(m_isFolderWritable); @@ -1053,7 +1117,7 @@ void DolphinView::slotDirListerStarted(const KUrl& url) emit startedPathLoading(url); } -void DolphinView::slotDirListerCompleted() +void DolphinView::slotLoadingCompleted() { // Update the view-state. This has to be done using a Qt::QueuedConnection // because the view might not be in its final state yet (the view also @@ -1134,33 +1198,33 @@ void DolphinView::applyViewProperties() emit hiddenFilesShownChanged(hiddenFilesShown); } -/* m_storedCategorizedSorting = props.categorizedSorting(); - const bool categorized = m_storedCategorizedSorting && supportsCategorizedSorting(); - if (categorized != m_viewAccessor.proxyModel()->isCategorizedModel()) { - m_viewAccessor.proxyModel()->setCategorizedModel(categorized); - emit categorizedSortingChanged(); - }*/ + KFileItemModel* model = fileItemModel(); + + const bool groupedSorting = props.groupedSorting(); + if (groupedSorting != model->groupedSorting()) { + model->setGroupedSorting(groupedSorting); + emit groupedSortingChanged(groupedSorting); + } const DolphinView::Sorting sorting = props.sorting(); - KItemModelBase* model = m_container->controller()->model(); const QByteArray newSortRole = sortRoleForSorting(sorting); if (newSortRole != model->sortRole()) { model->setSortRole(newSortRole); emit sortingChanged(sorting); } -/* + const Qt::SortOrder sortOrder = props.sortOrder(); - if (sortOrder != m_viewAccessor.proxyModel()->sortOrder()) { - m_viewAccessor.proxyModel()->setSortOrder(sortOrder); + if (sortOrder != model->sortOrder()) { + model->setSortOrder(sortOrder); emit sortOrderChanged(sortOrder); } const bool sortFoldersFirst = props.sortFoldersFirst(); - if (sortFoldersFirst != m_viewAccessor.proxyModel()->sortFoldersFirst()) { - m_viewAccessor.proxyModel()->setSortFoldersFirst(sortFoldersFirst); + if (sortFoldersFirst != model->sortFoldersFirst()) { + model->setSortFoldersFirst(sortFoldersFirst); emit sortFoldersFirstChanged(sortFoldersFirst); } -*/ + const QList infoList = props.additionalInfoList(); if (infoList != m_additionalInfoList) { const QList previousList = m_additionalInfoList; @@ -1189,13 +1253,12 @@ void DolphinView::applyAdditionalInfoListToView() { const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); - QHash visibleRoles; - visibleRoles.insert("name", 0); + QList visibleRoles; + visibleRoles.reserve(m_additionalInfoList.count() + 1); + visibleRoles.append("name"); - int index = 1; foreach (AdditionalInfo info, m_additionalInfoList) { - visibleRoles.insert(infoAccessor.role(info), index); - ++index; + visibleRoles.append(infoAccessor.role(info)); } m_container->setVisibleRoles(visibleRoles); @@ -1282,4 +1345,26 @@ QByteArray DolphinView::sortRoleForSorting(Sorting sorting) const return QByteArray(); } +DolphinView::Sorting DolphinView::sortingForSortRole(const QByteArray& sortRole) const +{ + static QHash sortHash; + if (sortHash.isEmpty()) { + sortHash.insert("name", SortByName); + sortHash.insert("size", SortBySize); + sortHash.insert("date", SortByDate); + sortHash.insert("permissions", SortByPermissions); + sortHash.insert("owner", SortByOwner); + sortHash.insert("group", SortByGroup); + sortHash.insert("type", SortByType); + sortHash.insert("destination", SortByDestination); + sortHash.insert("path", SortByPath); + } + return sortHash.value(sortRole); +} + +void DolphinView::markUrlAsCurrent(const KUrl& url) +{ + m_currentItemUrl = url; +} + #include "dolphinview.moc"