]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
fix: forgot to invoke base implementation
[dolphin.git] / src / dolphinview.cpp
index d74d9a64c4f5e9a9c7244f480236e145a5ba4996..0041ab35d55b89645a312a4f9a7ddb93c7a0b5b8 100644 (file)
@@ -84,8 +84,8 @@ DolphinView::DolphinView(QWidget* parent,
 
     connect(m_dirLister, SIGNAL(completed()),
             this, SLOT(updateCutItems()));
-    connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)),
-            this, SLOT(generatePreviews(const KFileItemList&)));
+    connect(m_dirLister, SIGNAL(newItems(const QList<KFileItem>&)),
+            this, SLOT(generatePreviews(const QList<KFileItem>&)));
 
     m_controller = new DolphinController(this);
     m_controller->setUrl(url);
@@ -262,22 +262,15 @@ void DolphinView::selectAll()
 
 void DolphinView::invertSelection()
 {
-    if (isColumnViewActive()) {
-        // In opposite to QAbstractItemView::selectAll() there is no virtual method
-        // for adjusting the invertion of a selection. As the generic approach by using
-        // the selection model does not work for the column view, we delegate this task:
-        m_columnView->invertSelection();
-    } else {
-        QItemSelectionModel* selectionModel = itemView()->selectionModel();
-        const QAbstractItemModel* itemModel = selectionModel->model();
+    QItemSelectionModel* selectionModel = itemView()->selectionModel();
+    const QAbstractItemModel* itemModel = selectionModel->model();
 
-        const QModelIndex topLeft = itemModel->index(0, 0);
-        const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
-                                                         itemModel->columnCount() - 1);
+    const QModelIndex topLeft = itemModel->index(0, 0);
+    const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
+                                                     itemModel->columnCount() - 1);
 
-        QItemSelection selection(topLeft, bottomRight);
-        selectionModel->select(selection, QItemSelectionModel::Toggle);
-    }
+    QItemSelection selection(topLeft, bottomRight);
+    selectionModel->select(selection, QItemSelectionModel::Toggle);
 }
 
 bool DolphinView::hasSelection() const
@@ -302,11 +295,8 @@ QList<KFileItem> DolphinView::selectedItems() const
     QList<KFileItem> itemList;
 
     const QModelIndexList indexList = selection.indexes();
-    QModelIndexList::const_iterator end = indexList.end();
-    for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
-        Q_ASSERT((*it).isValid());
-
-        KFileItem item = m_dirModel->itemForIndex(*it);
+    foreach (QModelIndex index, indexList) {
+        KFileItem item = m_dirModel->itemForIndex(index);
         if (!item.isNull()) {
             itemList.append(item);
         }
@@ -335,7 +325,11 @@ KFileItem DolphinView::fileItem(const QModelIndex& index) const
 void DolphinView::setContentsPosition(int x, int y)
 {
     QAbstractItemView* view = itemView();
-    view->horizontalScrollBar()->setValue(x);
+
+    // the ColumnView takes care itself for the horizontal scrolling
+    if (!isColumnViewActive()) {
+        view->horizontalScrollBar()->setValue(x);
+    }
     view->verticalScrollBar()->setValue(y);
 
     m_loadingDirectory = false;
@@ -430,12 +424,12 @@ void DolphinView::setUrl(const KUrl& url)
         return;
     }
 
-    m_controller->setUrl(url);
+    m_controller->setUrl(url); // emits urlChanged, which we forward
 
     applyViewProperties(url);
 
     startDirLister(url);
-    emit urlChanged(url);
+    itemView()->setFocus();
 }
 
 void DolphinView::mouseReleaseEvent(QMouseEvent* event)
@@ -450,11 +444,7 @@ void DolphinView::activate()
 
 void DolphinView::triggerItem(const QModelIndex& index)
 {
-    if (!isValidNameIndex(index)) {
-        clearSelection();
-        showHoverInformation(index);
-        return;
-    }
+    Q_ASSERT(index.isValid());
 
     const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
     if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) {
@@ -463,50 +453,18 @@ void DolphinView::triggerItem(const QModelIndex& index)
         return;
     }
 
-    KFileItem item = m_dirModel->itemForIndex(m_proxyModel->mapToSource(index));
+    const KFileItem item = m_dirModel->itemForIndex(m_proxyModel->mapToSource(index));
     if (item.isNull()) {
         return;
     }
 
-    // The stuff below should be moved to ViewContainer and be just a signal?
-
-    // Prefer the local path over the URL.
-    bool isLocal;
-    KUrl url = item.mostLocalUrl(isLocal);
-
-    if (item.isDir()) {
-        setUrl(url);
-    } else if (item.isFile()) {
-        // allow to browse through ZIP and tar files
-        KMimeType::Ptr mime = item.mimeTypePtr();
-        if (mime->is("application/zip")) {
-            url.setProtocol("zip");
-            setUrl(url);
-        } else if (mime->is("application/x-tar") ||
-                   mime->is("application/x-tarz") ||
-                   mime->is("application/x-bzip-compressed-tar") ||
-                   mime->is("application/x-compressed-tar") ||
-                   mime->is("application/x-tzo")) {
-            url.setProtocol("tar");
-            setUrl(url);
-        } else {
-            item.run();
-        }
-    } else {
-        item.run();
-    }
+    emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
 }
 
-void DolphinView::generatePreviews(const KFileItemList& items)
+void DolphinView::generatePreviews(const QList<KFileItem>& items)
 {
     if (m_controller->showPreview()) {
-        // QList<KFileItem*> must be turned to QList<KFileItem>...
-        QList<KFileItem> itemsToPreview;
-        foreach (KFileItem* it, items) {
-            itemsToPreview.append(*it);
-        }
-
-        KIO::PreviewJob* job = KIO::filePreview(itemsToPreview, 128);
+        KIO::PreviewJob* job = KIO::filePreview(items, 128);
         connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
                 this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
     }
@@ -582,7 +540,7 @@ void DolphinView::startDirLister(const KUrl& url, bool reload)
             const KUrl& dirListerUrl = m_dirLister->url();
             if ((dirListerUrl == url) || !m_dirLister->url().isParentOf(url)) {
                 // The current URL is not a child of the dir lister
-                // URL. This may happen when e. g. a bookmark has been selected
+                // URL. This may happen when e. g. a place has been selected
                 // and hence the view must be reset.
                 keepOldDirs = false;
             }
@@ -875,6 +833,7 @@ void DolphinView::createView()
             this, SLOT(emitContentsMoved()));
     connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
             this, SLOT(emitContentsMoved()));
+    view->setFocus();
 }
 
 QAbstractItemView* DolphinView::itemView() const
@@ -951,9 +910,9 @@ void DolphinView::applyCutItemEffect()
 
 void DolphinView::updateViewportColor()
 {
-    QColor color = KColorScheme(KColorScheme::View).background();
+    QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
     if (m_active) {
-        emit urlChanged(url());
+        emit urlChanged(url()); // Hmm, this is a hack; the url hasn't really changed.
         emit selectionChanged(selectedItems());
     } else {
         color.setAlpha(0);