X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/3b4dfa2040c1e970ba6689bd7a874fab5f423e2d..de4ffa3322c8d919ebdb0cdb51115bace8aa8d11:/src/dolphinview.cpp diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 1a02ddea0..c0c18f90e 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include @@ -105,13 +105,15 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow, m_dirModel = new KDirModel(); m_dirModel->setDirLister(m_dirLister); + m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory); m_proxyModel = new DolphinSortFilterProxyModel(this); m_proxyModel->setSourceModel(m_dirModel); - m_iconsView->setModel(m_dirModel); // TODO: using m_proxyModel crashed when clicking on an item + m_iconsView->setModel(m_proxyModel); KFileItemDelegate* delegate = new KFileItemDelegate(this); + delegate->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType); m_iconsView->setItemDelegate(delegate); m_dirLister->setDelayedMimeTypes(true); @@ -136,7 +138,7 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow, connect(m_iconsView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(emitSelectionChangedSignal())); - startDirLister(m_urlNavigator->url()); + loadDirectory(m_urlNavigator->url()); } DolphinView::~DolphinView() @@ -187,6 +189,22 @@ DolphinView::Mode DolphinView::mode() const return m_mode; } +void DolphinView::setShowPreview(bool show) +{ + ViewProperties props(m_urlNavigator->url()); + props.setShowPreview(show); + + // TODO: wait until previews are possible with KFileItemDelegate + + emit showPreviewChanged(); +} + +bool DolphinView::showPreview() const +{ + // TODO: wait until previews are possible with KFileItemDelegate + return true; +} + void DolphinView::setShowHiddenFiles(bool show) { if (m_dirLister->showingDotFiles() == show) { @@ -209,14 +227,6 @@ bool DolphinView::showHiddenFiles() const return m_dirLister->showingDotFiles(); } -void DolphinView::setViewProperties(const ViewProperties& props) -{ - setMode(props.viewMode()); - setSorting(props.sorting()); - setSortOrder(props.sortOrder()); - setShowHiddenFiles(props.showHiddenFiles()); -} - void DolphinView::renameSelectedItems() { const KUrl::List urls = selectedUrls(); @@ -471,21 +481,24 @@ bool DolphinView::hasSelection() const KFileItemList DolphinView::selectedItems() const { - QItemSelectionModel* selModel = m_iconsView->selectionModel(); - assert(selModel != 0); + // Our view has a selection, we will map them back to the DirModel + // and then fill the KFileItemList. + assert(m_iconsView && m_iconsView->selectionModel()); + const QItemSelection selection = m_proxyModel->mapSelectionToSource(m_iconsView->selectionModel()->selection()); KFileItemList itemList; - if (selModel->hasSelection()) { - const QModelIndexList indexList = selModel->selectedIndexes(); - - QModelIndexList::const_iterator end = indexList.end(); - for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) { - KFileItem* item = m_dirModel->itemForIndex(*it); - if (item != 0) { - itemList.append(item); - } + + const QModelIndexList indexList = selection.indexes(); + QModelIndexList::const_iterator end = indexList.end(); + for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) { + assert((*it).isValid()); + + KFileItem* item = m_dirModel->itemForIndex(*it); + if (item != 0) { + itemList.append(item); } } + return itemList; } @@ -533,11 +546,11 @@ void DolphinView::rename(const KUrl& source, const QString& newName) if (destExists) { // the destination already exists, hence ask the user // how to proceed... - KIO::RenameDlg renameDialog(this, - i18n("File Already Exists"), - source.path(), - dest.path(), - KIO::M_OVERWRITE); + KIO::RenameDialog renameDialog(this, + i18n("File Already Exists"), + source.path(), + dest.path(), + KIO::M_OVERWRITE); switch (renameDialog.exec()) { case KIO::R_OVERWRITE: // the destination should be overwritten @@ -617,37 +630,41 @@ DolphinMainWindow* DolphinView::mainWindow() const void DolphinView::loadDirectory(const KUrl& url) { const ViewProperties props(url); - setMode(props.viewMode()); + + const Mode mode = props.viewMode(); + if (m_mode != mode) { + m_mode = mode; + applyModeToView(); + emit modeChanged(); + } const bool showHiddenFiles = props.showHiddenFiles(); - setShowHiddenFiles(showHiddenFiles); - m_dirLister->setShowingDotFiles(showHiddenFiles); + if (showHiddenFiles != m_dirLister->showingDotFiles()) { + m_dirLister->setShowingDotFiles(showHiddenFiles); + emit showHiddenFilesChanged(); + } + + const DolphinView::Sorting sorting = props.sorting(); + if (sorting != m_proxyModel->sorting()) { + m_proxyModel->setSorting(sorting); + emit sortingChanged(sorting); + } + + const Qt::SortOrder sortOrder = props.sortOrder(); + if (sortOrder != m_proxyModel->sortOrder()) { + m_proxyModel->setSortOrder(sortOrder); + emit sortOrderChanged(sortOrder); + } - setSorting(props.sorting()); - setSortOrder(props.sortOrder()); + // TODO: handle previews (props.showPreview()) startDirLister(url); emit urlChanged(url); } -void DolphinView::triggerIconsViewItem(Q3IconViewItem* item) -{ - /* KDE4-TODO: - const Qt::ButtonState keyboardState = KApplication::keyboardMouseState(); - const bool isSelectionActive = ((keyboardState & Qt::ShiftModifier) > 0) || - ((keyboardState & Qt::ControlModifier) > 0);*/ - const bool isSelectionActive = false; - if ((item != 0) && !isSelectionActive) { - // Updating the Url must be done outside the scope of this slot, - // as iconview items will get deleted. - QTimer::singleShot(0, this, SLOT(updateUrl())); - mainWindow()->setActiveView(this); - } -} - void DolphinView::triggerItem(const QModelIndex& index) { - KFileItem* item = m_dirModel->itemForIndex(index); + KFileItem* item = m_dirModel->itemForIndex(m_proxyModel->mapToSource(index)); if (item == 0) { return; } @@ -675,35 +692,6 @@ void DolphinView::triggerItem(const QModelIndex& index) } } -void DolphinView::updateUrl() -{ - //KFileView* fileView = (m_iconsView != 0) ? static_cast(m_iconsView) : - // static_cast(m_iconsView); - - KFileItem* fileItem = 0; // TODO: fileView->currentFileItem(); - if (fileItem == 0) { - return; - } - - if (fileItem->isDir()) { - // Prefer the local path over the Url. This assures that the - // volume space information is correct. Assuming that the Url is media:/sda1, - // and the local path is /windows/C: For the Url the space info is related - // to the root partition (and hence wrong) and for the local path the space - // info is related to the windows partition (-> correct). - const QString localPath(fileItem->localPath()); - if (localPath.isEmpty()) { - setUrl(fileItem->url()); - } - else { - setUrl(KUrl(localPath)); - } - } - else { - fileItem->run(); - } -} - void DolphinView::slotPercent(int percent) { if (m_showProgress) { @@ -979,25 +967,38 @@ void DolphinView::slotChangeNameFilter(const QString& nameFilter) adjustedFilter.insert(0, '*'); adjustedFilter.append('*'); + // Use the ProxyModel to filter: + // This code is #ifdefed as setNameFilter behaves + // slightly different than the QSortFilterProxyModel + // as it will not remove directories. I will ask + // our beloved usability experts for input + // -- z. +#if 0 m_dirLister->setNameFilter(adjustedFilter); m_dirLister->emitChanges(); +#else + m_proxyModel->setFilterRegExp( nameFilter ); +#endif } void DolphinView::applyModeToView() { - //m_iconsView->setAlternatingRowColors(true); m_iconsView->setSelectionMode(QAbstractItemView::ExtendedSelection); // TODO: the following code just tries to test some QListView capabilities switch (m_mode) { case IconsView: m_iconsView->setViewMode(QListView::IconMode); - m_iconsView->setGridSize(QSize(128, 64)); + m_iconsView->setSpacing(32); + // m_iconsView->setAlternatingRowColors(false); + // m_iconsView->setGridSize(QSize(128, 64)); break; case DetailsView: m_iconsView->setViewMode(QListView::ListMode); - m_iconsView->setGridSize(QSize(256, 24)); + m_iconsView->setSpacing(0); + // m_iconsView->setAlternatingRowColors(true); + // m_iconsView->setGridSize(QSize(256, 24)); break; } }