#include <QAbstractItemView>
#include <QApplication>
+#include <QBoxLayout>
#include <QClipboard>
+#include <QDropEvent>
+#include <QGraphicsSceneDragDropEvent>
#include <QKeyEvent>
#include <QItemSelection>
-#include <QBoxLayout>
#include <QTimer>
#include <QScrollBar>
#include <KActionCollection>
#include <KColorScheme>
#include <KDirLister>
+#include <KDirModel>
#include <KIconEffect>
#include <KFileItem>
#include <KFileItemListProperties>
#include <KLocale>
#include <kitemviews/kfileitemmodel.h>
#include <kitemviews/kfileitemlistview.h>
+#include <kitemviews/kitemlistselectionmanager.h>
#include <kitemviews/kitemlistview.h>
#include <kitemviews/kitemlistcontroller.h>
#include <KIO/DeleteJob>
#include "dolphinnewfilemenuobserver.h"
#include "dolphin_detailsmodesettings.h"
#include "dolphin_generalsettings.h"
+#include "dolphinitemlistcontainer.h"
+#include "draganddrophelper.h"
#include "renamedialog.h"
#include "settings/dolphinsettings.h"
+#include "versioncontrol/versioncontrolobserver.h"
#include "viewmodecontroller.h"
#include "viewproperties.h"
+#include "views/tooltips/tooltipmanager.h"
#include "zoomlevelinfo.h"
-// TODO:
-#include "dolphinitemlistcontainer.h"
-
namespace {
const int MaxModeEnum = DolphinView::CompactView;
const int MaxSortingEnum = DolphinView::SortByPath;
m_active(true),
m_tabsForFiles(false),
m_assureVisibleCurrentIndex(false),
- m_expanderActive(false),
m_isFolderWritable(true),
m_url(url),
m_mode(DolphinView::IconsView),
m_topLayout(0),
m_dirLister(0),
m_container(0),
+ m_toolTipManager(0),
m_selectionChangedTimer(0),
- m_activeItemUrl(),
+ m_currentItemUrl(),
m_restoredContentsPosition(),
m_createdItemUrl(),
- m_selectedItems(),
- m_newFileNames()
+ m_selectedUrls(),
+ m_versionControlObserver(0)
{
m_topLayout = new QVBoxLayout(this);
m_topLayout->setSpacing(0);
this, SLOT(updateSortFoldersFirst(bool)));
connect(m_dolphinViewController, SIGNAL(additionalInfoChanged(QList<DolphinView::AdditionalInfo>)),
this, SLOT(updateAdditionalInfo(QList<DolphinView::AdditionalInfo>)));*/
- //connect(m_dolphinViewController, SIGNAL(itemTriggered(KFileItem)),
+ //connect(m_dolphinViewController, SIGNAL(itemActivated(KFileItem)),
// this, SLOT(triggerItem(KFileItem)));
//connect(m_dolphinViewController, SIGNAL(tabRequested(KUrl)),
// this, SIGNAL(tabRequested(KUrl)));
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<QPair<KFileItem,KFileItem> >)),
this, SLOT(slotRefreshItems()));
connect(m_dirLister, SIGNAL(itemsDeleted(KFileItemList)), this, SIGNAL(itemCountChanged()));
m_container = new DolphinItemListContainer(m_dirLister, this);
- QHash<QByteArray, int> visibleRoles;
- visibleRoles.insert("name", 0);
- m_container->setVisibleRoles(visibleRoles);
+ m_container->setVisibleRoles(QList<QByteArray>() << "name");
KItemListController* controller = m_container->controller();
- connect(controller, SIGNAL(itemClicked(int,Qt::MouseButton)),
- this, SLOT(slotItemClicked(int,Qt::MouseButton)));
+ 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(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<int>,QSet<int>)),
+ this, SLOT(slotSelectionChanged(QSet<int>,QSet<int>)));
+
+ m_toolTipManager = new ToolTipManager(this);
+
+ m_versionControlObserver = new VersionControlObserver(this);
+ 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)));
applyViewProperties();
m_topLayout->addWidget(m_container);
// view->setFocus();
//}
emit activated();
- emitSelectionChangedSignal();
emit writeStateChanged(m_isFolderWritable);
}
KFileItemList DolphinView::selectedItems() const
{
- return KFileItemList();
-/* KFileItemList itemList;
- const QAbstractItemView* view = m_viewAccessor.itemView();
- if (!view) {
- return itemList;
- }
-
- const QItemSelection selection = m_viewAccessor.proxyModel()->mapSelectionToSource(view->selectionModel()->selection());
+ const KFileItemModel* model = fileItemModel();
+ const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
+ const QSet<int> selectedIndexes = selectionManager->selectedItems();
- const QModelIndexList indexList = selection.indexes();
- foreach (const QModelIndex &index, indexList) {
- KFileItem item = m_viewAccessor.dirModel()->itemForIndex(index);
- if (!item.isNull()) {
- itemList.append(item);
- }
+ KFileItemList selectedItems;
+ QSetIterator<int> it(selectedIndexes);
+ while (it.hasNext()) {
+ const int index = it.next();
+ selectedItems.append(model->fileItem(index));
}
-
- return itemList;*/
+ return selectedItems;
}
int DolphinView::selectedItemsCount() const
{
- return 0;
- /*const QAbstractItemView* view = m_viewAccessor.itemView();
- if (!view) {
- return 0;
- }
-
- return view->selectionModel()->selectedIndexes().count();*/
+ const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
+ return selectionManager->selectedItems().count();
}
void DolphinView::markUrlsAsSelected(const QList<KUrl>& 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)
{
- Q_UNUSED(pattern);
- Q_UNUSED(enabled);
- /*const QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), pattern);
- const QItemSelectionModel::SelectionFlags command = enabled
- ? QItemSelectionModel::Select
- : QItemSelectionModel::Deselect;
- m_viewAccessor.itemView()->selectionModel()->select(matchingIndexes, command);*/
+ const KItemListSelectionManager::SelectionMode mode = enabled
+ ? KItemListSelectionManager::Select
+ : KItemListSelectionManager::Deselect;
+ const KFileItemModel* model = fileItemModel();
+ KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
+
+ for (int index = 0; index < model->count(); index++) {
+ const KFileItem item = model->fileItem(index);
+ if (pattern.exactMatch(item.name())) {
+ // An alternative approach would be to store the matching items in a QSet<int> and
+ // select them in one go after the loop, but we'd need a new function
+ // KItemListSelectionManager::setSelected(QSet<int>, SelectionMode mode)
+ // for that.
+ selectionManager->setSelected(index, 1, mode);
+ }
+ }
}
void DolphinView::setZoomLevel(int level)
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)
Qt::SortOrder DolphinView::sortOrder() const
{
- return Qt::AscendingOrder; // m_viewAccessor.proxyModel()->sortOrder();
+ KItemModelBase* model = fileItemModel();
+ return model->sortOrder();
}
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<AdditionalInfo>& info)
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);
QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) const
{
- Q_UNUSED(items);
- return QList<QAction*>(); //m_dolphinViewController->versionControlActions(items);
+ QList<QAction*> actions;
+
+ if (items.isEmpty()) {
+ const KFileItem item = fileItemModel()->rootItem();
+ actions = m_versionControlObserver->actions(KFileItemList() << item);
+ } else {
+ actions = m_versionControlObserver->actions(items);
+ }
+
+ return actions;
}
void DolphinView::setUrl(const KUrl& url)
}
emit urlAboutToBeChanged(url);
-
- const bool hadSelection = hasSelection();
- m_newFileNames.clear();
m_url = url;
+ if (GeneralSettings::showToolTips()) {
+ m_toolTipManager->hideToolTip();
+ }
+
// It is important to clear the items from the model before
// applying the view properties, otherwise expensive operations
// might be done on the existing items although they get cleared
loadDirectory(url);
emit urlChanged(url);
- if (hadSelection || hasSelection()) {
- emitSelectionChangedSignal();
- }
}
void DolphinView::selectAll()
{
- //m_viewAccessor.itemView()->selectAll();
+ KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
+ selectionManager->setSelected(0, fileItemModel()->count());
}
void DolphinView::invertSelection()
{
-/* // Implementation note: Using selectionModel->select(selection, QItemSelectionModel::Toggle) does not
- // work, as QItemSelectionModel::hasSelection() provides invalid values in this case. This might be a Qt-issue -
- // when changing the implementation with an updated Qt-version don't forget to run the Dolphin-unit-tests that
- // verify this usecase.
- const KFileItemList selItems = selectedItems();
- clearSelection();
-
- QItemSelection invertedSelection;
- foreach (const KFileItem& item, items()) {
- if (!selItems.contains(item)) {
- const QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
- invertedSelection.select(index, index);
- }
- }
-
- QItemSelectionModel* selectionModel = m_viewAccessor.itemView()->selectionModel();
- selectionModel->select(invertedSelection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current);
- */
+ KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
+ selectionManager->setSelected(0, fileItemModel()->count(), KItemListSelectionManager::Toggle);
}
void DolphinView::clearSelection()
{
- //m_viewAccessor.itemView()->clearSelection();
+ m_container->controller()->selectionManager()->clearSelection();
}
void DolphinView::renameSelectedItems()
return;
}
- m_selectedItems = selectedItems();
+ const KFileItemList itemList = selectedItems();
+ m_selectedUrls.clear();
+ m_selectedUrls = itemList.urlList();
ViewProperties props(url());
props.setHiddenFilesShown(show);
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 slotItemClicked())
+ // (the context-menu for items is handled in slotContextMenuRequested())
requestContextMenu(KFileItem(), url(), QList<QAction*>());
}
}
+void DolphinView::wheelEvent(QWheelEvent* event)
+{
+ if (event->modifiers().testFlag(Qt::ControlModifier)) {
+ const int numDegrees = event->delta() / 8;
+ const int numSteps = numDegrees / 15;
+
+ setZoomLevel(zoomLevel() + numSteps);
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+
void DolphinView::activate()
{
setActive(true);
}
-void DolphinView::slotItemClicked(int index, Qt::MouseButton button)
+void DolphinView::slotItemActivated(int index)
{
- const KFileItem item = fileItemModel()->fileItem(index);
+ Q_UNUSED(index);
+
+ const KFileItemList items = selectedItems();
+ if (items.isEmpty()) {
+ return;
+ }
- if (button & Qt::LeftButton) {
- emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
- } else if (button & Qt::MidButton) {
- if (item.isDir() || isTabsForFilesEnabled()) {
- emit tabRequested(item.url());
+ if (items.count() == 1) {
+ emit itemActivated(items.at(0)); // caught by DolphinViewContainer or DolphinPart
+ } else {
+ foreach (const KFileItem& item, items) {
+ if (item.isDir()) {
+ emit tabRequested(item.url());
+ } else {
+ emit itemActivated(item);
+ }
}
- } else if (button & Qt::RightButton) {
- // TODO: attach customActions for the details-view
- emit requestContextMenu(item, url(), QList<QAction*>());
}
}
+void DolphinView::slotItemMiddleClicked(int index)
+{
+ const KFileItem item = fileItemModel()->fileItem(index);
+ if (item.isDir() || isTabsForFilesEnabled()) {
+ emit tabRequested(item.url());
+ }
+}
+
+void DolphinView::slotContextMenuRequested(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<QAction*>());
+}
+
void DolphinView::slotItemExpansionToggleClicked(int index)
{
+ // TODO: When doing a model->setExpanded(false) it should
+ // be checked here whether the current index is part of the
+ // closed sub-tree. If this is the case, the current index
+ // should be adjusted to the parent index.
KFileItemModel* model = fileItemModel();
const bool expanded = model->isExpanded(index);
model->setExpanded(index, !expanded);
}
-void DolphinView::slotSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
+void DolphinView::slotItemHovered(int index)
{
- const int count = selectedItemsCount();
- const bool selectionStateChanged = ((count > 0) && (selected.count() == count)) ||
- ((count == 0) && !deselected.isEmpty());
+ const KFileItem item = fileItemModel()->fileItem(index);
+
+ if (GeneralSettings::showToolTips()) {
+ QRectF itemRect = m_container->controller()->view()->itemBoundingRect(index);
+ const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint());
+ itemRect.moveTo(pos);
+
+ m_toolTipManager->showToolTip(item, itemRect);
+ }
+
+ emit requestItemInfo(item);
+}
+
+void DolphinView::slotItemUnhovered(int index)
+{
+ Q_UNUSED(index);
+ if (GeneralSettings::showToolTips()) {
+ m_toolTipManager->hideToolTip();
+ }
+ emit requestItemInfo(KFileItem());
+}
+
+void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
+{
+ const KFileItem destItem = fileItemModel()->fileItem(index);
+
+ QDropEvent dropEvent(event->pos().toPoint(),
+ event->possibleActions(),
+ event->mimeData(),
+ event->buttons(),
+ event->modifiers());
+
+ DragAndDropHelper::dropUrls(destItem, url(), &dropEvent, this);
+}
+
+void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous)
+{
+ if (previous != 0) {
+ disconnect(previous, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
+ }
+
+ Q_ASSERT(qobject_cast<KFileItemModel*>(current));
+ connect(current, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
+
+ KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(current);
+ m_versionControlObserver->setModel(fileItemModel);
+}
+
+void DolphinView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
+{
+ const int currentCount = current.count();
+ const int previousCount = previous.count();
+ const bool selectionStateChanged = (currentCount == 0 && previousCount > 0) ||
+ (currentCount > 0 && previousCount == 0);
// If nothing has been selected before and something got selected (or if something
// was selected before and now nothing is selected) the selectionChangedSignal must
void DolphinView::openContextMenu(const QPoint& pos,
const QList<QAction*>& customActions)
{
- Q_UNUSED(pos);
KFileItem item;
- /*QAbstractItemView* view = m_viewAccessor.itemView();
- QModelIndex index;
- if (view) {
- index = view->indexAt(pos);
+ const int index = m_container->controller()->view()->itemAt(pos);
+ if (index >= 0) {
+ item = fileItemModel()->fileItem(index);
}
- if (index.isValid() && (index.column() == DolphinModel::Name)) {
- const QModelIndex dolphinModelIndex = m_viewAccessor.proxyModel()->mapToSource(index);
- item = m_viewAccessor.dirModel()->itemForIndex(dolphinModelIndex);
- }*/
-
emit requestContextMenu(item, url(), customActions);
}
{
Q_UNUSED(destItem);
Q_UNUSED(destPath);
- addNewFileNames(event->mimeData());
+ markPastedUrlsAsSelected(event->mimeData());
//DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
}
ViewProperties props(url());
props.setSortOrder(order);
- //m_viewAccessor.proxyModel()->setSortOrder(order);
+ KItemModelBase* model = fileItemModel();
+ model->setSortOrder(order);
emit sortOrderChanged(order);
}
ViewProperties props(url());
props.setSortFoldersFirst(foldersFirst);
- //m_viewAccessor.proxyModel()->setSortFoldersFirst(foldersFirst);
+ KFileItemModel* model = fileItemModel();
+ model->setSortFoldersFirst(foldersFirst);
emit sortFoldersFirstChanged(foldersFirst);
}
bool DolphinView::itemsExpandable() const
{
- return false; //m_viewAccessor.itemsExpandable();
+ return m_mode == DetailsView;
}
void DolphinView::restoreState(QDataStream& stream)
{
- // Restore the URL of the current item that had the keyboard focus
- stream >> m_activeItemUrl;
+ // Restore the current item that had the keyboard focus
+ 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<KUrl> 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<KUrl> urls;
+ stream >> urls;
+ fileItemModel()->restoreExpandedUrls(urls);
}
void DolphinView::saveState(QDataStream& stream)
{
- // Save the URL of the current item that has the keyboard focus
-
- KUrl currentItemUrl;
- //if (!currentItem.isNull()) {
- // currentItemUrl = currentItem.url();
- //}
-
- stream << currentItemUrl;
+ // Save the current item that has the keyboard focus
+ 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();
const qreal y = m_container->verticalScrollBar()->value();
stream << QPoint(x, y);
- kDebug() << "saving view state" << 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
{
- //const QAbstractItemView* view = m_viewAccessor.itemView();
- //return view && view->selectionModel()->hasSelection();
- return false;
+ return m_container->controller()->selectionManager()->hasSelection();
}
KFileItem DolphinView::rootItem() const
}
}
-void DolphinView::restoreContentsPosition()
+void DolphinView::updateViewState()
{
+ if (m_currentItemUrl != KUrl()) {
+ KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
+ const int currentIndex = fileItemModel()->index(m_currentItemUrl);
+ if (currentIndex != -1) {
+ selectionManager->setCurrentItem(currentIndex);
+ } else {
+ selectionManager->setCurrentItem(0);
+ }
+ m_currentItemUrl = KUrl();
+ }
+
if (!m_restoredContentsPosition.isNull()) {
const int x = m_restoredContentsPosition.x();
const int y = m_restoredContentsPosition.y();
m_container->horizontalScrollBar()->setValue(x);
m_container->verticalScrollBar()->setValue(y);
}
-}
-/*void DolphinView::slotUrlChangeRequested(const KUrl& url)
-{
- m_viewModeController->setUrl(url);
- updateWritableState();
-}*/
+ if (!m_selectedUrls.isEmpty()) {
+ KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
+ QSet<int> selectedItems = selectionManager->selectedItems();
+ const KFileItemModel* model = fileItemModel();
+
+ foreach (const KUrl& url, m_selectedUrls) {
+ const int index = model->index(url);
+ if (index >= 0) {
+ selectedItems.insert(index);
+ }
+ }
+
+ selectionManager->setSelectedItems(selectedItems);
+ m_selectedUrls.clear();
+ }
+}
void DolphinView::showHoverInformation(const KFileItem& item)
{
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);
emit startedPathLoading(url);
}
-void DolphinView::slotDirListerCompleted()
-{
- if (!m_expanderActive) {
- slotLoadingCompleted();
- }
-
- if (!m_newFileNames.isEmpty()) {
- // select all newly added items created by a paste operation or
- // a drag & drop operation, and clear the previous selection
- /*QAbstractItemView* view = m_viewAccessor.itemView();
- if (view) {
- view->clearSelection();
- const int rowCount = m_viewAccessor.proxyModel()->rowCount();
- QItemSelection selection;
- for (int row = 0; row < rowCount; ++row) {
- const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->index(row, 0);
- const QModelIndex dirIndex = m_viewAccessor.proxyModel()->mapToSource(proxyIndex);
- const KUrl url = m_viewAccessor.dirModel()->itemForIndex(dirIndex).url();
- if (m_newFileNames.contains(url.fileName())) {
- selection.merge(QItemSelection(proxyIndex, proxyIndex), QItemSelectionModel::Select);
- }
- }
- view->selectionModel()->select(selection, QItemSelectionModel::Select);
- }*/
-
- m_newFileNames.clear();
- }
-
- updateWritableState();
-}
-
void DolphinView::slotLoadingCompleted()
{
- m_expanderActive = false;
-
- if (!m_activeItemUrl.isEmpty()) {
- // assure that the current item remains visible
- /*const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForUrl(m_activeItemUrl);
- if (dirIndex.isValid()) {
- const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex);
- QAbstractItemView* view = m_viewAccessor.itemView();
- if (view) {
- const bool clearSelection = !hasSelection();
- view->setCurrentIndex(proxyIndex);
- if (clearSelection) {
- view->clearSelection();
- }
- }
- m_activeItemUrl.clear();
- }*/
- }
-
- if (!m_selectedItems.isEmpty()) {
- /*const KUrl& baseUrl = url();
- KUrl url;
- QItemSelection newSelection;
- foreach(const KFileItem& item, m_selectedItems) {
- url = item.url().upUrl();
- if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
- const QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
- newSelection.select(index, index);
- }
- }
- QAbstractItemView* view = m_viewAccessor.itemView();
- if (view) {
- view->selectionModel()->select(newSelection,
- QItemSelectionModel::ClearAndSelect
- | QItemSelectionModel::Current);
- }*/
- m_selectedItems.clear();
- }
-
- // Restore the contents position. This has to be done using a Qt::QueuedConnection
- // because the view might not be in its final state yet.
- QTimer::singleShot(0, this, SLOT(restoreContentsPosition()));
+ // 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
+ // listens to the completed()-signal from KDirLister and the order of
+ // of slots is undefined).
+ QTimer::singleShot(0, this, SLOT(updateViewState()));
emit finishedPathLoading(url());
+
+ updateWritableState();
}
void DolphinView::slotRefreshItems()
}*/
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<DolphinView::AdditionalInfo> infoList = props.additionalInfoList();
if (infoList != m_additionalInfoList) {
const QList<DolphinView::AdditionalInfo> previousList = m_additionalInfoList;
{
const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance();
- QHash<QByteArray, int> visibleRoles;
- visibleRoles.insert("name", 0);
+ QList<QByteArray> 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);
void DolphinView::pasteToUrl(const KUrl& url)
{
- addNewFileNames(QApplication::clipboard()->mimeData());
+ markPastedUrlsAsSelected(QApplication::clipboard()->mimeData());
KonqOperations::doPaste(this, url);
}
KUrl::List DolphinView::simplifiedSelectedUrls() const
{
- Q_ASSERT(false); // TODO
KUrl::List urls;
-/*
+
const KFileItemList items = selectedItems();
foreach (const KFileItem &item, items) {
urls.append(item.url());
}
-
if (itemsExpandable()) {
+ // TODO: Check if we still need KDirModel for this in KDE 5.0
urls = KDirModel::simplifiedUrlList(urls);
- }*/
+ }
return urls;
}
QMimeData* DolphinView::selectionMimeData() const
{
- /*const QAbstractItemView* view = m_viewAccessor.itemView();
- Q_ASSERT((view) && (view->selectionModel()));
- const QItemSelection selection = m_viewAccessor.proxyModel()->mapSelectionToSource(view->selectionModel()->selection());
- return m_viewAccessor.dirModel()->mimeData(selection.indexes());*/
- return 0;
-}
+ const KFileItemModel* model = fileItemModel();
+ const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
+ const QSet<int> selectedIndexes = selectionManager->selectedItems();
-void DolphinView::addNewFileNames(const QMimeData* mimeData)
-{
- const KUrl::List urls = KUrl::List::fromMimeData(mimeData);
- foreach (const KUrl& url, urls) {
- m_newFileNames.insert(url.fileName());
- }
+ return model->createMimeData(selectedIndexes);
}
-QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const
+void DolphinView::markPastedUrlsAsSelected(const QMimeData* mimeData)
{
- Q_UNUSED(parent);
- Q_UNUSED(pattern);
- QItemSelection matchingIndexes;
- /*const DolphinSortFilterProxyModel* proxyModel = m_viewAccessor.proxyModel();
- const DolphinModel* dolphinModel = m_viewAccessor.dirModel();
-
- const int rowCount = proxyModel->rowCount(parent);
-
- for (int row = 0; row < rowCount; ++row) {
- QModelIndex index = proxyModel->index(row, 0, parent);
- QModelIndex sourceIndex = proxyModel->mapToSource(index);
-
- if (sourceIndex.isValid() && pattern.exactMatch(dolphinModel->data(sourceIndex).toString())) {
- matchingIndexes += QItemSelectionRange(index);
- }
-
- if (proxyModel->hasChildren(index)) {
- matchingIndexes += childrenMatchingPattern(index, pattern);
- }
- }*/
-
- return matchingIndexes;
+ const KUrl::List urls = KUrl::List::fromMimeData(mimeData);
+ markUrlsAsSelected(urls);
}
void DolphinView::updateWritableState()
const bool wasFolderWritable = m_isFolderWritable;
m_isFolderWritable = true;
- const KFileItem item; // = m_viewAccessor.dirLister()->rootItem();
+ const KFileItem item = m_dirLister->rootItem();
if (!item.isNull()) {
KFileItemListProperties capabilities(KFileItemList() << item);
m_isFolderWritable = capabilities.supportsWriting();
return QByteArray();
}
+DolphinView::Sorting DolphinView::sortingForSortRole(const QByteArray& sortRole) const
+{
+ static QHash<QByteArray, DolphinView::Sorting> 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"