X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/93cb7e02616df9746f7cdae09434e7488f4e7d28..740e9569327c0026257dfcea38ab2efac4a29d67:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index a53934ddc..71c67b1cf 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -90,7 +90,7 @@ 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(), @@ -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,9 +163,7 @@ 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"); KItemListController* controller = m_container->controller(); controller->setSelectionBehavior(KItemListController::MultiSelection); @@ -180,6 +177,11 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : 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 +189,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))); @@ -354,8 +356,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 +369,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 +382,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) @@ -521,10 +525,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; @@ -812,8 +816,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); @@ -877,7 +885,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 +896,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 +925,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 +954,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 +1000,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()) { @@ -1044,7 +1059,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 +1068,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 @@ -1142,25 +1157,25 @@ void DolphinView::applyViewProperties() }*/ const DolphinView::Sorting sorting = props.sorting(); - KItemModelBase* model = m_container->controller()->model(); + KFileItemModel* model = fileItemModel(); 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 +1204,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 +1296,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"