Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kdiroperator.cpp
| Show All 17 Lines | 1 | /* This file is part of the KDE libraries | |||
|---|---|---|---|---|---|
| 18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
| 19 | */ | 19 | */ | ||
| 20 | 20 | | |||
| 21 | #include "kdiroperator.h" | 21 | #include "kdiroperator.h" | ||
| 22 | #include <kprotocolmanager.h> | 22 | #include <kprotocolmanager.h> | ||
| 23 | #include <kiconloader.h> | 23 | #include <kiconloader.h> | ||
| 24 | #include "kdirmodel.h" | 24 | #include "kdirmodel.h" | ||
| 25 | #include "kdiroperatordetailview_p.h" | 25 | #include "kdiroperatordetailview_p.h" | ||
| 26 | #include "kdiroperatorcolumnview_p.h" | ||||
| 26 | #include "kdirsortfilterproxymodel.h" | 27 | #include "kdirsortfilterproxymodel.h" | ||
| 27 | #include "kfileitem.h" | 28 | #include "kfileitem.h" | ||
| 28 | #include "kfilemetapreview_p.h" | 29 | #include "kfilemetapreview_p.h" | ||
| 29 | #include "kpreviewwidgetbase.h" | 30 | #include "kpreviewwidgetbase.h" | ||
| 30 | #include "knewfilemenu.h" | 31 | #include "knewfilemenu.h" | ||
| 31 | 32 | | |||
| 32 | #include <config-kiofilewidgets.h> | 33 | #include <config-kiofilewidgets.h> | ||
| 33 | #include <defaults-kfile.h> // ConfigGroup, DefaultShowHidden, DefaultDirsFirst, DefaultSortReversed | 34 | #include <defaults-kfile.h> // ConfigGroup, DefaultShowHidden, DefaultDirsFirst, DefaultSortReversed | ||
| 34 | 35 | | |||
| 35 | #include <QApplication> | 36 | #include <QApplication> | ||
| 37 | #include <QColumnView> | ||||
| 36 | #include <QHeaderView> | 38 | #include <QHeaderView> | ||
| 37 | #include <QListView> | 39 | #include <QListView> | ||
| 38 | #include <QMenu> | 40 | #include <QMenu> | ||
| 39 | #include <QMimeData> | 41 | #include <QMimeData> | ||
| 40 | #include <QProgressBar> | 42 | #include <QProgressBar> | ||
| 41 | #include <QScrollBar> | 43 | #include <QScrollBar> | ||
| 42 | #include <QSplitter> | 44 | #include <QSplitter> | ||
| 43 | #include <QWheelEvent> | 45 | #include <QWheelEvent> | ||
| ▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Line(s) | 172 | public: | |||
| 189 | 191 | | |||
| 190 | KFile::FileView allViews(); | 192 | KFile::FileView allViews(); | ||
| 191 | 193 | | |||
| 192 | // private slots | 194 | // private slots | ||
| 193 | void _k_slotDetailedView(); | 195 | void _k_slotDetailedView(); | ||
| 194 | void _k_slotSimpleView(); | 196 | void _k_slotSimpleView(); | ||
| 195 | void _k_slotTreeView(); | 197 | void _k_slotTreeView(); | ||
| 196 | void _k_slotDetailedTreeView(); | 198 | void _k_slotDetailedTreeView(); | ||
| 199 | void _k_slotColumnView(); | ||||
| 197 | void _k_slotToggleHidden(bool); | 200 | void _k_slotToggleHidden(bool); | ||
| 198 | void _k_togglePreview(bool); | 201 | void _k_togglePreview(bool); | ||
| 199 | void _k_toggleInlinePreviews(bool); | 202 | void _k_toggleInlinePreviews(bool); | ||
| 200 | void _k_slotOpenFileManager(); | 203 | void _k_slotOpenFileManager(); | ||
| 201 | void _k_slotSortByName(); | 204 | void _k_slotSortByName(); | ||
| 202 | void _k_slotSortBySize(); | 205 | void _k_slotSortBySize(); | ||
| 203 | void _k_slotSortByDate(); | 206 | void _k_slotSortByDate(); | ||
| 204 | void _k_slotSortByType(); | 207 | void _k_slotSortByType(); | ||
| ▲ Show 20 Lines • Show All 369 Lines • ▼ Show 20 Line(s) | |||||
| 574 | 577 | | |||
| 575 | KActionCollection *KDirOperator::actionCollection() const | 578 | KActionCollection *KDirOperator::actionCollection() const | ||
| 576 | { | 579 | { | ||
| 577 | return d->actionCollection; | 580 | return d->actionCollection; | ||
| 578 | } | 581 | } | ||
| 579 | 582 | | |||
| 580 | KFile::FileView KDirOperator::Private::allViews() | 583 | KFile::FileView KDirOperator::Private::allViews() | ||
| 581 | { | 584 | { | ||
| 582 | return static_cast<KFile::FileView>(KFile::Simple | KFile::Detail | KFile::Tree | KFile::DetailTree); | 585 | return static_cast<KFile::FileView>(KFile::Simple | KFile::Detail | KFile::Tree | KFile::DetailTree | KFile::ColumnView); | ||
| 583 | } | 586 | } | ||
| 584 | 587 | | |||
| 585 | void KDirOperator::Private::_k_slotDetailedView() | 588 | void KDirOperator::Private::_k_slotDetailedView() | ||
| 586 | { | 589 | { | ||
| 587 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | 590 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | ||
| 588 | parent->setView(view); | 591 | parent->setView(view); | ||
| 589 | } | 592 | } | ||
| 590 | 593 | | |||
| Show All 10 Lines | |||||
| 601 | } | 604 | } | ||
| 602 | 605 | | |||
| 603 | void KDirOperator::Private::_k_slotDetailedTreeView() | 606 | void KDirOperator::Private::_k_slotDetailedTreeView() | ||
| 604 | { | 607 | { | ||
| 605 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | 608 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | ||
| 606 | parent->setView(view); | 609 | parent->setView(view); | ||
| 607 | } | 610 | } | ||
| 608 | 611 | | |||
| 612 | void KDirOperator::Private::_k_slotColumnView() | ||||
| 613 | { | ||||
| 614 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::ColumnView); | ||||
| 615 | parent->setView(view); | ||||
| 616 | } | ||||
| 617 | | ||||
| 609 | void KDirOperator::Private::_k_slotToggleHidden(bool show) | 618 | void KDirOperator::Private::_k_slotToggleHidden(bool show) | ||
| 610 | { | 619 | { | ||
| 611 | dirLister->setShowingDotFiles(show); | 620 | dirLister->setShowingDotFiles(show); | ||
| 612 | parent->updateDir(); | 621 | parent->updateDir(); | ||
| 613 | _k_assureVisibleSelection(); | 622 | _k_assureVisibleSelection(); | ||
| 614 | } | 623 | } | ||
| 615 | 624 | | |||
| 616 | void KDirOperator::Private::_k_togglePreview(bool on) | 625 | void KDirOperator::Private::_k_togglePreview(bool on) | ||
| ▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Line(s) | 895 | { | |||
| 902 | const int val = (maxSize * value / 100) + KIconLoader::SizeSmall; | 911 | const int val = (maxSize * value / 100) + KIconLoader::SizeSmall; | ||
| 903 | d->itemView->setIconSize(QSize(val, val)); | 912 | d->itemView->setIconSize(QSize(val, val)); | ||
| 904 | d->updateListViewGrid(); | 913 | d->updateListViewGrid(); | ||
| 905 | d->previewGenerator->updatePreviews(); | 914 | d->previewGenerator->updatePreviews(); | ||
| 906 | 915 | | |||
| 907 | emit currentIconSizeChanged(value); | 916 | emit currentIconSizeChanged(value); | ||
| 908 | } | 917 | } | ||
| 909 | 918 | | |||
| 919 | void KDirOperator::scrollToUrl(const QUrl &url) | ||||
| 920 | { | ||||
| 921 | if (!KFile::isColumnView(viewMode())) | ||||
| 922 | return; | ||||
| 923 | | ||||
| 924 | const KFileItem item = d->dirLister->findByUrl(url); | ||||
| 925 | const QModelIndex index = d->dirModel->indexForItem(item); | ||||
| 926 | const QModelIndex _index = d->proxyModel->mapFromSource(index); | ||||
| 927 | d->itemView->scrollTo(_index); | ||||
| 928 | } | ||||
| 929 | | ||||
| 910 | void KDirOperator::close() | 930 | void KDirOperator::close() | ||
| 911 | { | 931 | { | ||
| 912 | resetCursor(); | 932 | resetCursor(); | ||
| 913 | d->pendingMimeTypes.clear(); | 933 | d->pendingMimeTypes.clear(); | ||
| 914 | d->completion.clear(); | 934 | d->completion.clear(); | ||
| 915 | d->dirCompletion.clear(); | 935 | d->dirCompletion.clear(); | ||
| 916 | d->completeListDirty = true; | 936 | d->completeListDirty = true; | ||
| 917 | d->dirLister->stop(); | 937 | d->dirLister->stop(); | ||
| ▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Line(s) | |||||
| 1052 | void KDirOperator::rereadDir() | 1072 | void KDirOperator::rereadDir() | ||
| 1053 | { | 1073 | { | ||
| 1054 | pathChanged(); | 1074 | pathChanged(); | ||
| 1055 | d->openUrl(d->currUrl, KDirLister::Reload); | 1075 | d->openUrl(d->currUrl, KDirLister::Reload); | ||
| 1056 | } | 1076 | } | ||
| 1057 | 1077 | | |||
| 1058 | bool KDirOperator::Private::openUrl(const QUrl &url, KDirLister::OpenUrlFlags flags) | 1078 | bool KDirOperator::Private::openUrl(const QUrl &url, KDirLister::OpenUrlFlags flags) | ||
| 1059 | { | 1079 | { | ||
| 1080 | if (KFile::isColumnView(parent->viewMode())) { | ||||
| 1081 | QUrl root = url; | ||||
| 1082 | root.setPath(QStringLiteral("/")); | ||||
| 1083 | if (dirLister->url() != root || flags & KDirLister::Reload) { | ||||
| 1084 | dirLister->clear(); | ||||
| 1085 | dirLister->openUrl(root); | ||||
| 1086 | } | ||||
| 1087 | | ||||
| 1088 | auto urlIndex = dirModel->indexForUrl(url); | ||||
| 1089 | if (urlIndex.isValid() || url == root) { | ||||
| 1090 | auto columnView = qobject_cast<KColumnView*>(itemView); | ||||
| 1091 | columnView->showPathTo(proxyModel->mapFromSource(urlIndex)); | ||||
| 1092 | _k_slotIOFinished(); | ||||
| 1093 | } else { | ||||
| 1094 | if (!KProtocolManager::supportsListing(url)) { | ||||
| 1095 | _k_slotCanceled(); | ||||
| 1096 | return false; | ||||
| 1097 | } | ||||
| 1098 | | ||||
| 1099 | // Calls openURL internally | ||||
| 1100 | dirModel->expandToUrl(url); | ||||
| 1101 | } | ||||
| 1102 | | ||||
| 1103 | return true; | ||||
| 1104 | } | ||||
| 1105 | | ||||
| 1060 | const bool result = KProtocolManager::supportsListing(url) && dirLister->openUrl(url, flags); | 1106 | const bool result = KProtocolManager::supportsListing(url) && dirLister->openUrl(url, flags); | ||
| 1061 | if (!result) { // in that case, neither completed() nor canceled() will be emitted by KDL | 1107 | if (!result) { // in that case, neither completed() nor canceled() will be emitted by KDL | ||
| 1062 | _k_slotCanceled(); | 1108 | _k_slotCanceled(); | ||
| 1063 | } | 1109 | } | ||
| 1064 | 1110 | | |||
| 1065 | return result; | 1111 | return result; | ||
| 1066 | } | 1112 | } | ||
| 1067 | 1113 | | |||
| ▲ Show 20 Lines • Show All 356 Lines • ▼ Show 20 Line(s) | |||||
| 1424 | 1470 | | |||
| 1425 | QAbstractItemView *KDirOperator::createView(QWidget *parent, KFile::FileView viewKind) | 1471 | QAbstractItemView *KDirOperator::createView(QWidget *parent, KFile::FileView viewKind) | ||
| 1426 | { | 1472 | { | ||
| 1427 | QAbstractItemView *itemView = nullptr; | 1473 | QAbstractItemView *itemView = nullptr; | ||
| 1428 | if (KFile::isDetailView(viewKind) || KFile::isTreeView(viewKind) || KFile::isDetailTreeView(viewKind)) { | 1474 | if (KFile::isDetailView(viewKind) || KFile::isTreeView(viewKind) || KFile::isDetailTreeView(viewKind)) { | ||
| 1429 | KDirOperatorDetailView *detailView = new KDirOperatorDetailView(parent); | 1475 | KDirOperatorDetailView *detailView = new KDirOperatorDetailView(parent); | ||
| 1430 | detailView->setViewMode(viewKind); | 1476 | detailView->setViewMode(viewKind); | ||
| 1431 | itemView = detailView; | 1477 | itemView = detailView; | ||
| 1478 | } else if (KFile::isColumnView(viewKind)) { | ||||
| 1479 | itemView = new KDirOperatorColumnView(parent); | ||||
| 1432 | } else { | 1480 | } else { | ||
| 1433 | itemView = new KDirOperatorIconView(this, parent); | 1481 | itemView = new KDirOperatorIconView(this, parent); | ||
| 1434 | } | 1482 | } | ||
| 1435 | 1483 | | |||
| 1436 | return itemView; | 1484 | return itemView; | ||
| 1437 | } | 1485 | } | ||
| 1438 | 1486 | | |||
| 1439 | void KDirOperator::setAcceptDrops(bool b) | 1487 | void KDirOperator::setAcceptDrops(bool b) | ||
| Show All 18 Lines | 1504 | { | |||
| 1458 | 1506 | | |||
| 1459 | if (viewKind == KFile::Default) { | 1507 | if (viewKind == KFile::Default) { | ||
| 1460 | if (KFile::isDetailView((KFile::FileView)d->defaultView)) { | 1508 | if (KFile::isDetailView((KFile::FileView)d->defaultView)) { | ||
| 1461 | viewKind = KFile::Detail; | 1509 | viewKind = KFile::Detail; | ||
| 1462 | } else if (KFile::isTreeView((KFile::FileView)d->defaultView)) { | 1510 | } else if (KFile::isTreeView((KFile::FileView)d->defaultView)) { | ||
| 1463 | viewKind = KFile::Tree; | 1511 | viewKind = KFile::Tree; | ||
| 1464 | } else if (KFile::isDetailTreeView((KFile::FileView)d->defaultView)) { | 1512 | } else if (KFile::isDetailTreeView((KFile::FileView)d->defaultView)) { | ||
| 1465 | viewKind = KFile::DetailTree; | 1513 | viewKind = KFile::DetailTree; | ||
| 1514 | } else if (KFile::isColumnView((KFile::FileView)d->defaultView)) { | ||||
| 1515 | viewKind = KFile::ColumnView; | ||||
| 1466 | } else { | 1516 | } else { | ||
| 1467 | viewKind = KFile::Simple; | 1517 | viewKind = KFile::Simple; | ||
| 1468 | } | 1518 | } | ||
| 1469 | 1519 | | |||
| 1470 | const KFile::FileView defaultViewKind = static_cast<KFile::FileView>(d->defaultView); | 1520 | const KFile::FileView defaultViewKind = static_cast<KFile::FileView>(d->defaultView); | ||
| 1471 | preview = (KFile::isPreviewInfo(defaultViewKind) || KFile::isPreviewContents(defaultViewKind)) | 1521 | preview = (KFile::isPreviewInfo(defaultViewKind) || KFile::isPreviewContents(defaultViewKind)) | ||
| 1472 | && d->actionCollection->action(QStringLiteral("preview"))->isEnabled(); | 1522 | && d->actionCollection->action(QStringLiteral("preview"))->isEnabled(); | ||
| 1473 | } | 1523 | } | ||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
| 1515 | void KDirOperator::setView(QAbstractItemView *view) | 1565 | void KDirOperator::setView(QAbstractItemView *view) | ||
| 1516 | { | 1566 | { | ||
| 1517 | if (view == d->itemView) { | 1567 | if (view == d->itemView) { | ||
| 1518 | return; | 1568 | return; | ||
| 1519 | } | 1569 | } | ||
| 1520 | 1570 | | |||
| 1521 | // TODO: do a real timer and restart it after that | 1571 | // TODO: do a real timer and restart it after that | ||
| 1522 | d->pendingMimeTypes.clear(); | 1572 | d->pendingMimeTypes.clear(); | ||
| 1523 | const bool listDir = (d->itemView == nullptr); | 1573 | bool listDir = d->itemView == nullptr; | ||
| 1574 | | ||||
| 1575 | if (!listDir) { | ||||
| 1576 | const bool wasColumnView = qobject_cast<KColumnView*>(d->itemView) || qobject_cast<QColumnView*>(d->itemView); | ||||
| 1577 | const bool isColumnView = qobject_cast<KColumnView*>(view) || qobject_cast<QColumnView*>(view); | ||||
| 1578 | // Column Views need a different representation of the directory tree, with the root node being the filesystem root and not an arbitrary changing directory. So reload if the requirement changes. | ||||
| 1579 | listDir = wasColumnView != isColumnView; | ||||
| 1580 | } | ||||
| 1524 | 1581 | | |||
| 1525 | if (d->mode & KFile::Files) { | 1582 | if (d->mode & KFile::Files) { | ||
| 1526 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); | 1583 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); | ||
| 1527 | } else { | 1584 | } else { | ||
| 1528 | view->setSelectionMode(QAbstractItemView::SingleSelection); | 1585 | view->setSelectionMode(QAbstractItemView::SingleSelection); | ||
| 1529 | } | 1586 | } | ||
| 1530 | 1587 | | |||
| 1531 | QItemSelectionModel *selectionModel = nullptr; | 1588 | QItemSelectionModel *selectionModel = nullptr; | ||
| 1532 | if ((d->itemView != nullptr) && d->itemView->selectionModel()->hasSelection()) { | 1589 | if ((d->itemView != nullptr) && d->itemView->selectionModel()->hasSelection()) { | ||
| 1533 | // remember the selection of the current item view and apply this selection | 1590 | // remember the selection of the current item view and apply this selection | ||
| 1534 | // to the new view later | 1591 | // to the new view later | ||
| 1535 | const QItemSelection selection = d->itemView->selectionModel()->selection(); | 1592 | const QItemSelection selection = d->itemView->selectionModel()->selection(); | ||
| 1536 | selectionModel = new QItemSelectionModel(d->proxyModel, this); | 1593 | selectionModel = new QItemSelectionModel(d->proxyModel, this); | ||
| 1537 | selectionModel->select(selection, QItemSelectionModel::Select); | 1594 | selectionModel->select(selection, QItemSelectionModel::Select); | ||
| 1538 | } | 1595 | } | ||
| 1539 | 1596 | | |||
| 1540 | setFocusProxy(nullptr); | 1597 | setFocusProxy(nullptr); | ||
| 1541 | delete d->itemView; | 1598 | delete d->itemView; | ||
| 1542 | d->itemView = view; | 1599 | d->itemView = view; | ||
| 1543 | d->itemView->setModel(d->proxyModel); | | |||
| 1544 | setFocusProxy(d->itemView); | | |||
| 1545 | | ||||
| 1546 | view->viewport()->installEventFilter(this); | | |||
| 1547 | 1600 | | |||
| 1601 | /* QColumnView/KColumnView do not react correctly to ItemDelegate changes after colums got created | ||||
| 1602 | * (it can't, the delegate is not shared between the child list views and there is no | ||||
| 1603 | * notification mechanism), so make sure the the delegate is the right one | ||||
| 1604 | * before assigning a model. | ||||
| 1605 | */ | ||||
| 1548 | KFileItemDelegate *delegate = new KFileItemDelegate(d->itemView); | 1606 | KFileItemDelegate *delegate = new KFileItemDelegate(d->itemView); | ||
| 1549 | d->itemView->setItemDelegate(delegate); | 1607 | d->itemView->setItemDelegate(delegate); | ||
| 1550 | d->itemView->viewport()->setAttribute(Qt::WA_Hover); | 1608 | d->itemView->viewport()->setAttribute(Qt::WA_Hover); | ||
| 1551 | d->itemView->setContextMenuPolicy(Qt::CustomContextMenu); | 1609 | d->itemView->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 1552 | d->itemView->setMouseTracking(true); | 1610 | d->itemView->setMouseTracking(true); | ||
| 1553 | //d->itemView->setDropOptions(d->dropOptions); | 1611 | //d->itemView->setDropOptions(d->dropOptions); | ||
| 1554 | 1612 | | |||
| 1613 | d->itemView->setModel(d->proxyModel); | ||||
| 1614 | setFocusProxy(d->itemView); | ||||
| 1615 | | ||||
| 1616 | view->viewport()->installEventFilter(this); | ||||
| 1617 | | ||||
| 1555 | // first push our settings to the view, then listen for changes from the view | 1618 | // first push our settings to the view, then listen for changes from the view | ||
| 1556 | QTreeView *treeView = qobject_cast<QTreeView *>(d->itemView); | 1619 | QTreeView *treeView = qobject_cast<QTreeView *>(d->itemView); | ||
| 1557 | if (treeView) { | 1620 | if (treeView) { | ||
| 1558 | QHeaderView *headerView = treeView->header(); | 1621 | QHeaderView *headerView = treeView->header(); | ||
| 1559 | headerView->setSortIndicator(d->sortColumn(), d->sortOrder()); | 1622 | headerView->setSortIndicator(d->sortColumn(), d->sortOrder()); | ||
| 1560 | connect(headerView, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), | 1623 | connect(headerView, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), | ||
| 1561 | this, SLOT(_k_synchronizeSortingState(int,Qt::SortOrder))); | 1624 | this, SLOT(_k_synchronizeSortingState(int,Qt::SortOrder))); | ||
| 1562 | } | 1625 | } | ||
| Show All 27 Lines | |||||
| 1590 | connect(d->itemView->selectionModel(), | 1653 | connect(d->itemView->selectionModel(), | ||
| 1591 | SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | 1654 | SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | ||
| 1592 | this, SLOT(_k_slotSelectionChanged())); | 1655 | this, SLOT(_k_slotSelectionChanged())); | ||
| 1593 | 1656 | | |||
| 1594 | // if we cannot cast it to a QListView, disable the "Icon Position" menu. Note that this check | 1657 | // if we cannot cast it to a QListView, disable the "Icon Position" menu. Note that this check | ||
| 1595 | // needs to be done here, and not in createView, since we can be set an external view | 1658 | // needs to be done here, and not in createView, since we can be set an external view | ||
| 1596 | d->decorationMenu->setEnabled(qobject_cast<QListView *>(d->itemView)); | 1659 | d->decorationMenu->setEnabled(qobject_cast<QListView *>(d->itemView)); | ||
| 1597 | 1660 | | |||
| 1598 | d->shouldFetchForItems = qobject_cast<QTreeView *>(view); | 1661 | d->shouldFetchForItems = qobject_cast<QTreeView *>(view) || KFile::isColumnView(viewMode()); | ||
| 1599 | if (d->shouldFetchForItems) { | 1662 | if (d->shouldFetchForItems) { | ||
| 1600 | connect(d->dirModel, SIGNAL(expand(QModelIndex)), this, SLOT(_k_slotExpandToUrl(QModelIndex))); | 1663 | connect(d->dirModel, SIGNAL(expand(QModelIndex)), this, SLOT(_k_slotExpandToUrl(QModelIndex))); | ||
| 1601 | } else { | 1664 | } else { | ||
| 1602 | d->itemsToBeSetAsCurrent.clear(); | 1665 | d->itemsToBeSetAsCurrent.clear(); | ||
| 1603 | } | 1666 | } | ||
| 1604 | 1667 | | |||
| 1605 | const bool previewForcedToTrue = d->inlinePreviewState == Private::ForcedToTrue; | 1668 | const bool previewForcedToTrue = d->inlinePreviewState == Private::ForcedToTrue; | ||
| 1606 | const bool previewShown = d->inlinePreviewState == Private::NotForced ? d->showPreviews : previewForcedToTrue; | 1669 | const bool previewShown = d->inlinePreviewState == Private::NotForced ? d->showPreviews : previewForcedToTrue; | ||
| Show All 29 Lines | 1689 | { | |||
| 1636 | 1699 | | |||
| 1637 | //delete d->dirLister; // deleted by KDirModel already, which took ownership | 1700 | //delete d->dirLister; // deleted by KDirModel already, which took ownership | ||
| 1638 | d->dirLister = lister; | 1701 | d->dirLister = lister; | ||
| 1639 | 1702 | | |||
| 1640 | d->dirModel = new KDirModel(); | 1703 | d->dirModel = new KDirModel(); | ||
| 1641 | d->dirModel->setDirLister(d->dirLister); | 1704 | d->dirModel->setDirLister(d->dirLister); | ||
| 1642 | d->dirModel->setDropsAllowed(KDirModel::DropOnDirectory); | 1705 | d->dirModel->setDropsAllowed(KDirModel::DropOnDirectory); | ||
| 1643 | 1706 | | |||
| 1644 | d->shouldFetchForItems = qobject_cast<QTreeView *>(d->itemView); | 1707 | d->shouldFetchForItems = qobject_cast<QTreeView *>(d->itemView) || KFile::isColumnView(viewMode()); | ||
| 1645 | if (d->shouldFetchForItems) { | 1708 | if (d->shouldFetchForItems) { | ||
| 1646 | connect(d->dirModel, SIGNAL(expand(QModelIndex)), this, SLOT(_k_slotExpandToUrl(QModelIndex))); | 1709 | connect(d->dirModel, SIGNAL(expand(QModelIndex)), this, SLOT(_k_slotExpandToUrl(QModelIndex))); | ||
| 1647 | } else { | 1710 | } else { | ||
| 1648 | d->itemsToBeSetAsCurrent.clear(); | 1711 | d->itemsToBeSetAsCurrent.clear(); | ||
| 1649 | } | 1712 | } | ||
| 1650 | 1713 | | |||
| 1651 | d->proxyModel = new KDirSortFilterProxyModel(this); | 1714 | d->proxyModel = new KDirSortFilterProxyModel(this); | ||
| 1652 | d->proxyModel->setSourceModel(d->dirModel); | 1715 | d->proxyModel->setSourceModel(d->dirModel); | ||
| ▲ Show 20 Lines • Show All 274 Lines • ▼ Show 20 Line(s) | 1888 | { | |||
| 1927 | treeAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | 1990 | treeAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | ||
| 1928 | connect(treeAction, SIGNAL(triggered()), SLOT(_k_slotTreeView())); | 1991 | connect(treeAction, SIGNAL(triggered()), SLOT(_k_slotTreeView())); | ||
| 1929 | 1992 | | |||
| 1930 | KToggleAction *detailedTreeAction = new KToggleAction(i18n("Detailed Tree View"), this); | 1993 | KToggleAction *detailedTreeAction = new KToggleAction(i18n("Detailed Tree View"), this); | ||
| 1931 | d->actionCollection->addAction(QStringLiteral("detailed tree view"), detailedTreeAction); | 1994 | d->actionCollection->addAction(QStringLiteral("detailed tree view"), detailedTreeAction); | ||
| 1932 | detailedTreeAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | 1995 | detailedTreeAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | ||
| 1933 | connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView())); | 1996 | connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView())); | ||
| 1934 | 1997 | | |||
| 1998 | KToggleAction *columnViewAction = new KToggleAction(i18n("Column View"), this); | ||||
| 1999 | d->actionCollection->addAction(QStringLiteral("column view"), columnViewAction); | ||||
| 2000 | columnViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-file-columns"))); | ||||
| 2001 | connect(columnViewAction, SIGNAL(triggered()), SLOT(_k_slotColumnView())); | ||||
| 2002 | | ||||
| 1935 | QActionGroup *viewGroup = new QActionGroup(this); | 2003 | QActionGroup *viewGroup = new QActionGroup(this); | ||
| 1936 | shortAction->setActionGroup(viewGroup); | 2004 | shortAction->setActionGroup(viewGroup); | ||
| 1937 | detailedAction->setActionGroup(viewGroup); | 2005 | detailedAction->setActionGroup(viewGroup); | ||
| 1938 | treeAction->setActionGroup(viewGroup); | 2006 | treeAction->setActionGroup(viewGroup); | ||
| 1939 | detailedTreeAction->setActionGroup(viewGroup); | 2007 | detailedTreeAction->setActionGroup(viewGroup); | ||
| 2008 | columnViewAction->setActionGroup(viewGroup); | ||||
| 1940 | 2009 | | |||
| 1941 | KToggleAction *showHiddenAction = new KToggleAction(i18n("Show Hidden Files"), this); | 2010 | KToggleAction *showHiddenAction = new KToggleAction(i18n("Show Hidden Files"), this); | ||
| 1942 | d->actionCollection->addAction(QStringLiteral("show hidden"), showHiddenAction); | 2011 | d->actionCollection->addAction(QStringLiteral("show hidden"), showHiddenAction); | ||
| 1943 | connect(showHiddenAction, SIGNAL(toggled(bool)), SLOT(_k_slotToggleHidden(bool))); | 2012 | connect(showHiddenAction, SIGNAL(toggled(bool)), SLOT(_k_slotToggleHidden(bool))); | ||
| 1944 | 2013 | | |||
| 1945 | KToggleAction *previewAction = new KToggleAction(i18n("Show Aside Preview"), this); | 2014 | KToggleAction *previewAction = new KToggleAction(i18n("Show Aside Preview"), this); | ||
| 1946 | d->actionCollection->addAction(QStringLiteral("preview"), previewAction); | 2015 | d->actionCollection->addAction(QStringLiteral("preview"), previewAction); | ||
| 1947 | connect(previewAction, SIGNAL(toggled(bool)), | 2016 | connect(previewAction, SIGNAL(toggled(bool)), | ||
| Show All 18 Lines | |||||
| 1966 | // the view menu actions | 2035 | // the view menu actions | ||
| 1967 | KActionMenu *viewMenu = new KActionMenu(i18n("&View"), this); | 2036 | KActionMenu *viewMenu = new KActionMenu(i18n("&View"), this); | ||
| 1968 | d->actionCollection->addAction(QStringLiteral("view menu"), viewMenu); | 2037 | d->actionCollection->addAction(QStringLiteral("view menu"), viewMenu); | ||
| 1969 | viewMenu->addAction(shortAction); | 2038 | viewMenu->addAction(shortAction); | ||
| 1970 | viewMenu->addAction(detailedAction); | 2039 | viewMenu->addAction(detailedAction); | ||
| 1971 | // Comment following lines to hide the extra two modes | 2040 | // Comment following lines to hide the extra two modes | ||
| 1972 | viewMenu->addAction(treeAction); | 2041 | viewMenu->addAction(treeAction); | ||
| 1973 | viewMenu->addAction(detailedTreeAction); | 2042 | viewMenu->addAction(detailedTreeAction); | ||
| 2043 | viewMenu->addAction(columnViewAction); | ||||
| 1974 | // TODO: QAbstractItemView does not offer an action collection. Provide | 2044 | // TODO: QAbstractItemView does not offer an action collection. Provide | ||
| 1975 | // an interface to add a custom action collection. | 2045 | // an interface to add a custom action collection. | ||
| 1976 | 2046 | | |||
| 1977 | d->newFileMenu = new KNewFileMenu(d->actionCollection, QStringLiteral("new"), this); | 2047 | d->newFileMenu = new KNewFileMenu(d->actionCollection, QStringLiteral("new"), this); | ||
| 1978 | connect(d->newFileMenu, SIGNAL(directoryCreated(QUrl)), this, SLOT(_k_slotDirectoryCreated(QUrl))); | 2048 | connect(d->newFileMenu, SIGNAL(directoryCreated(QUrl)), this, SLOT(_k_slotDirectoryCreated(QUrl))); | ||
| 1979 | 2049 | | |||
| 1980 | d->actionCollection->addAssociatedWidget(this); | 2050 | d->actionCollection->addAssociatedWidget(this); | ||
| 1981 | foreach (QAction *action, d->actionCollection->actions()) { | 2051 | foreach (QAction *action, d->actionCollection->actions()) { | ||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 2133 | { | |||
| 2066 | //QAction *separateDirs = d->actionCollection->action("separate dirs"); | 2136 | //QAction *separateDirs = d->actionCollection->action("separate dirs"); | ||
| 2067 | //separateDirs->setChecked(KFile::isSeparateDirs(fv) && | 2137 | //separateDirs->setChecked(KFile::isSeparateDirs(fv) && | ||
| 2068 | // separateDirs->isEnabled()); | 2138 | // separateDirs->isEnabled()); | ||
| 2069 | 2139 | | |||
| 2070 | d->actionCollection->action(QStringLiteral("short view"))->setChecked(KFile::isSimpleView(fv)); | 2140 | d->actionCollection->action(QStringLiteral("short view"))->setChecked(KFile::isSimpleView(fv)); | ||
| 2071 | d->actionCollection->action(QStringLiteral("detailed view"))->setChecked(KFile::isDetailView(fv)); | 2141 | d->actionCollection->action(QStringLiteral("detailed view"))->setChecked(KFile::isDetailView(fv)); | ||
| 2072 | d->actionCollection->action(QStringLiteral("tree view"))->setChecked(KFile::isTreeView(fv)); | 2142 | d->actionCollection->action(QStringLiteral("tree view"))->setChecked(KFile::isTreeView(fv)); | ||
| 2073 | d->actionCollection->action(QStringLiteral("detailed tree view"))->setChecked(KFile::isDetailTreeView(fv)); | 2143 | d->actionCollection->action(QStringLiteral("detailed tree view"))->setChecked(KFile::isDetailTreeView(fv)); | ||
| 2144 | d->actionCollection->action(QStringLiteral("column view"))->setChecked(KFile::isColumnView(fv)); | ||||
| 2074 | } | 2145 | } | ||
| 2075 | 2146 | | |||
| 2076 | void KDirOperator::readConfig(const KConfigGroup &configGroup) | 2147 | void KDirOperator::readConfig(const KConfigGroup &configGroup) | ||
| 2077 | { | 2148 | { | ||
| 2078 | d->defaultView = 0; | 2149 | d->defaultView = 0; | ||
| 2079 | QString viewStyle = configGroup.readEntry("View Style", "Simple"); | 2150 | QString viewStyle = configGroup.readEntry("View Style", "Simple"); | ||
| 2080 | if (viewStyle == QLatin1String("Detail")) { | 2151 | if (viewStyle == QLatin1String("Detail")) { | ||
| 2081 | d->defaultView |= KFile::Detail; | 2152 | d->defaultView |= KFile::Detail; | ||
| 2082 | } else if (viewStyle == QLatin1String("Tree")) { | 2153 | } else if (viewStyle == QLatin1String("Tree")) { | ||
| 2083 | d->defaultView |= KFile::Tree; | 2154 | d->defaultView |= KFile::Tree; | ||
| 2084 | } else if (viewStyle == QLatin1String("DetailTree")) { | 2155 | } else if (viewStyle == QLatin1String("DetailTree")) { | ||
| 2085 | d->defaultView |= KFile::DetailTree; | 2156 | d->defaultView |= KFile::DetailTree; | ||
| 2157 | } else if (viewStyle == QLatin1String("Columns")) { | ||||
| 2158 | d->defaultView |= KFile::ColumnView; | ||||
| 2086 | } else { | 2159 | } else { | ||
| 2087 | d->defaultView |= KFile::Simple; | 2160 | d->defaultView |= KFile::Simple; | ||
| 2088 | } | 2161 | } | ||
| 2089 | //if (configGroup.readEntry(QLatin1String("Separate Directories"), | 2162 | //if (configGroup.readEntry(QLatin1String("Separate Directories"), | ||
| 2090 | // DefaultMixDirsAndFiles)) { | 2163 | // DefaultMixDirsAndFiles)) { | ||
| 2091 | // d->defaultView |= KFile::SeparateDirs; | 2164 | // d->defaultView |= KFile::SeparateDirs; | ||
| 2092 | //} | 2165 | //} | ||
| 2093 | if (configGroup.readEntry(QStringLiteral("Show Preview"), false)) { | 2166 | if (configGroup.readEntry(QStringLiteral("Show Preview"), false)) { | ||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 2207 | { | |||
| 2179 | if (KFile::isDetailView(fv)) { | 2252 | if (KFile::isDetailView(fv)) { | ||
| 2180 | style = QStringLiteral("Detail"); | 2253 | style = QStringLiteral("Detail"); | ||
| 2181 | } else if (KFile::isSimpleView(fv)) { | 2254 | } else if (KFile::isSimpleView(fv)) { | ||
| 2182 | style = QStringLiteral("Simple"); | 2255 | style = QStringLiteral("Simple"); | ||
| 2183 | } else if (KFile::isTreeView(fv)) { | 2256 | } else if (KFile::isTreeView(fv)) { | ||
| 2184 | style = QStringLiteral("Tree"); | 2257 | style = QStringLiteral("Tree"); | ||
| 2185 | } else if (KFile::isDetailTreeView(fv)) { | 2258 | } else if (KFile::isDetailTreeView(fv)) { | ||
| 2186 | style = QStringLiteral("DetailTree"); | 2259 | style = QStringLiteral("DetailTree"); | ||
| 2260 | } else if (KFile::isColumnView(fv)) { | ||||
| 2261 | style = QStringLiteral("Columns"); | ||||
| 2187 | } | 2262 | } | ||
| 2188 | configGroup.writeEntry(QStringLiteral("View Style"), style); | 2263 | configGroup.writeEntry(QStringLiteral("View Style"), style); | ||
| 2189 | 2264 | | |||
| 2190 | if (d->inlinePreviewState == Private::NotForced) { | 2265 | if (d->inlinePreviewState == Private::NotForced) { | ||
| 2191 | configGroup.writeEntry(QStringLiteral("Previews"), d->showPreviews); | 2266 | configGroup.writeEntry(QStringLiteral("Previews"), d->showPreviews); | ||
| 2192 | if (qobject_cast<QListView *>(d->itemView)) { | 2267 | if (qobject_cast<QListView *>(d->itemView)) { | ||
| 2193 | configGroup.writeEntry(QStringLiteral("listViewIconSize"), d->iconsZoom); | 2268 | configGroup.writeEntry(QStringLiteral("listViewIconSize"), d->iconsZoom); | ||
| 2194 | } else { | 2269 | } else { | ||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 2334 | { | |||
| 2261 | // we have to redraw this as fast as possible | 2336 | // we have to redraw this as fast as possible | ||
| 2262 | if (progressBar->isVisible()) { | 2337 | if (progressBar->isVisible()) { | ||
| 2263 | QApplication::flush(); | 2338 | QApplication::flush(); | ||
| 2264 | } | 2339 | } | ||
| 2265 | } | 2340 | } | ||
| 2266 | 2341 | | |||
| 2267 | void KDirOperator::Private::_k_slotIOFinished() | 2342 | void KDirOperator::Private::_k_slotIOFinished() | ||
| 2268 | { | 2343 | { | ||
| 2344 | if (itemView && KFile::isColumnView(parent->viewMode())) | ||||
| 2345 | qobject_cast<KColumnView*>(itemView)->showPathTo(proxyModel->mapFromSource(dirModel->indexForUrl(currUrl))); | ||||
| 2346 | | ||||
| 2269 | progressDelayTimer->stop(); | 2347 | progressDelayTimer->stop(); | ||
| 2270 | _k_slotProgress(100); | 2348 | _k_slotProgress(100); | ||
| 2271 | progressBar->hide(); | 2349 | progressBar->hide(); | ||
| 2272 | emit parent->finishedLoading(); | 2350 | emit parent->finishedLoading(); | ||
| 2273 | parent->resetCursor(); | 2351 | parent->resetCursor(); | ||
| 2274 | 2352 | | |||
| 2275 | if (preview) { | 2353 | if (preview) { | ||
| 2276 | preview->clearPreview(); | 2354 | preview->clearPreview(); | ||
| ▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Line(s) | 2544 | { | |||
| 2488 | 2566 | | |||
| 2489 | itemView->update(); | 2567 | itemView->update(); | ||
| 2490 | } | 2568 | } | ||
| 2491 | 2569 | | |||
| 2492 | void KDirOperator::Private::_k_slotExpandToUrl(const QModelIndex &index) | 2570 | void KDirOperator::Private::_k_slotExpandToUrl(const QModelIndex &index) | ||
| 2493 | { | 2571 | { | ||
| 2494 | QTreeView *treeView = qobject_cast<QTreeView *>(itemView); | 2572 | QTreeView *treeView = qobject_cast<QTreeView *>(itemView); | ||
| 2495 | 2573 | | |||
| 2496 | if (!treeView) { | | |||
| 2497 | return; | | |||
| 2498 | } | | |||
| 2499 | | ||||
| 2500 | const KFileItem item = dirModel->itemForIndex(index); | 2574 | const KFileItem item = dirModel->itemForIndex(index); | ||
| 2501 | 2575 | | |||
| 2502 | if (item.isNull()) { | 2576 | if (item.isNull()) { | ||
| 2503 | return; | 2577 | return; | ||
| 2504 | } | 2578 | } | ||
| 2505 | 2579 | | |||
| 2506 | if (!item.isDir()) { | 2580 | if (!item.isDir()) { | ||
| 2507 | const QModelIndex proxyIndex = proxyModel->mapFromSource(index); | 2581 | const QModelIndex proxyIndex = proxyModel->mapFromSource(index); | ||
| 2508 | 2582 | | |||
| 2509 | QList<QUrl>::Iterator it = itemsToBeSetAsCurrent.begin(); | 2583 | QList<QUrl>::Iterator it = itemsToBeSetAsCurrent.begin(); | ||
| 2510 | while (it != itemsToBeSetAsCurrent.end()) { | 2584 | while (it != itemsToBeSetAsCurrent.end()) { | ||
| 2511 | const QUrl url = *it; | 2585 | const QUrl url = *it; | ||
| 2512 | if (url.matches(item.url(), QUrl::StripTrailingSlash) || url.isParentOf(item.url())) { | 2586 | if (url.matches(item.url(), QUrl::StripTrailingSlash) || url.isParentOf(item.url())) { | ||
| 2513 | const KFileItem _item = dirLister->findByUrl(url); | 2587 | const KFileItem _item = dirLister->findByUrl(url); | ||
| 2514 | if (!_item.isNull() && _item.isDir()) { | 2588 | if (!_item.isNull() && _item.isDir()) { | ||
| 2515 | const QModelIndex _index = dirModel->indexForItem(_item); | 2589 | const QModelIndex _index = dirModel->indexForItem(_item); | ||
| 2516 | const QModelIndex _proxyIndex = proxyModel->mapFromSource(_index); | 2590 | const QModelIndex _proxyIndex = proxyModel->mapFromSource(_index); | ||
| 2591 | if (treeView) | ||||
| 2517 | treeView->expand(_proxyIndex); | 2592 | treeView->expand(_proxyIndex); | ||
| 2518 | 2593 | | |||
| 2519 | // if we have expanded the last parent of this item, select it | 2594 | // if we have expanded the last parent of this item, select it | ||
| 2520 | if (item.url().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash) == url.adjusted(QUrl::StripTrailingSlash)) { | 2595 | if (item.url().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash) == url.adjusted(QUrl::StripTrailingSlash)) { | ||
| 2521 | treeView->selectionModel()->select(proxyIndex, QItemSelectionModel::Select); | 2596 | itemView->selectionModel()->select(proxyIndex, QItemSelectionModel::Select); | ||
| 2522 | } | 2597 | } | ||
| 2523 | } | 2598 | } | ||
| 2524 | it = itemsToBeSetAsCurrent.erase(it); | 2599 | it = itemsToBeSetAsCurrent.erase(it); | ||
| 2525 | } else { | 2600 | } else { | ||
| 2526 | ++it; | 2601 | ++it; | ||
| 2527 | } | 2602 | } | ||
| 2528 | } | 2603 | } | ||
| 2529 | } else if (!itemsToBeSetAsCurrent.contains(item.url())) { | 2604 | } else if (!itemsToBeSetAsCurrent.contains(item.url())) { | ||
| ▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines | |||||