35 #include <QtCore/QDir>
36 #include <QtCore/QRegExp>
37 #include <QtCore/QTimer>
38 #include <QtCore/QAbstractItemModel>
39 #include <QtGui/QApplication>
40 #include <QtGui/QDialog>
41 #include <QtGui/QHeaderView>
42 #include <QtGui/QLabel>
43 #include <QtGui/QLayout>
44 #include <QtGui/QListView>
45 #include <QtGui/QMouseEvent>
46 #include <QtGui/QTreeView>
47 #include <QtGui/QPushButton>
48 #include <QtGui/QProgressBar>
49 #include <QtGui/QScrollBar>
50 #include <QtGui/QSplitter>
51 #include <QtGui/QWheelEvent>
82 #include <kdeversion.h>
95 class KDirOperatorIconView :
public QListView
99 virtual ~KDirOperatorIconView();
102 virtual QStyleOptionViewItem viewOptions()
const;
103 virtual void dragEnterEvent(QDragEnterEvent* event);
104 virtual void mousePressEvent(QMouseEvent *event);
105 virtual void wheelEvent(QWheelEvent *event);
115 setViewMode(QListView::IconMode);
116 setFlow(QListView::TopToBottom);
117 setResizeMode(QListView::Adjust);
119 setMovement(QListView::Static);
120 setDragDropMode(QListView::DragOnly);
121 setVerticalScrollMode(QListView::ScrollPerPixel);
122 setHorizontalScrollMode(QListView::ScrollPerPixel);
123 setEditTriggers(QAbstractItemView::NoEditTriggers);
128 KDirOperatorIconView::~KDirOperatorIconView()
132 QStyleOptionViewItem KDirOperatorIconView::viewOptions()
const
134 QStyleOptionViewItem viewOptions = QListView::viewOptions();
135 viewOptions.showDecorationSelected =
true;
136 viewOptions.decorationPosition = ops->decorationPosition();
138 viewOptions.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
140 viewOptions.displayAlignment = Qt::AlignCenter;
146 void KDirOperatorIconView::dragEnterEvent(QDragEnterEvent* event)
148 if (event->mimeData()->hasUrls()) {
149 event->acceptProposedAction();
153 void KDirOperatorIconView::mousePressEvent(QMouseEvent *event)
155 if (!indexAt(event->pos()).isValid()) {
156 const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
157 if (!(modifiers & Qt::ShiftModifier) && !(modifiers & Qt::ControlModifier)) {
162 QListView::mousePressEvent(event);
165 void KDirOperatorIconView::wheelEvent(QWheelEvent *event)
167 QListView::wheelEvent(event);
171 if (event->orientation() == Qt::Vertical) {
172 QWheelEvent horizEvent(event->pos(),
177 QApplication::sendEvent(horizontalScrollBar(), &horizEvent);
183 if (!(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter )) {
184 QWidget::keyPressEvent(e);
188 class KDirOperator::Private
194 enum InlinePreviewState {
201 bool checkPreviewInternal()
const;
202 void checkPath(
const QString &txt,
bool takeFiles =
false);
204 int sortColumn()
const;
205 Qt::SortOrder sortOrder()
const;
206 void updateSorting(QDir::SortFlags sort);
208 static bool isReadable(
const KUrl &url);
213 void _k_slotDetailedView();
214 void _k_slotSimpleView();
215 void _k_slotTreeView();
216 void _k_slotDetailedTreeView();
217 void _k_slotToggleHidden(
bool);
218 void _k_togglePreview(
bool);
219 void _k_toggleInlinePreviews(
bool);
220 void _k_slotOpenFileManager();
221 void _k_slotSortByName();
222 void _k_slotSortBySize();
223 void _k_slotSortByDate();
224 void _k_slotSortByType();
225 void _k_slotSortReversed(
bool doReverse);
226 void _k_slotToggleDirsFirst();
227 void _k_slotToggleIgnoreCase();
228 void _k_slotStarted();
229 void _k_slotProgress(
int);
230 void _k_slotShowProgress();
231 void _k_slotIOFinished();
232 void _k_slotCanceled();
233 void _k_slotRedirected(
const KUrl&);
234 void _k_slotProperties();
235 void _k_slotActivated(
const QModelIndex&);
236 void _k_slotSelectionChanged();
237 void _k_openContextMenu(
const QPoint&);
238 void _k_triggerPreview(
const QModelIndex&);
239 void _k_showPreview();
240 void _k_slotSplitterMoved(
int,
int);
241 void _k_assureVisibleSelection();
242 void _k_synchronizeSortingState(
int, Qt::SortOrder);
243 void _k_slotChangeDecorationPosition();
244 void _k_slotExpandToUrl(
const QModelIndex&);
245 void _k_slotItemsChanged();
246 void _k_slotDirectoryCreated(
const KUrl&);
248 void updateListViewGrid();
249 int iconSizeForViewType(QAbstractItemView *itemView)
const;
253 QStack<KUrl*> backStack;
254 QStack<KUrl*> forwardStack;
256 QModelIndex lastHoveredIndex;
263 bool completeListDirty;
264 QDir::SortFlags sorting;
265 QStyleOptionViewItem::Position decorationPosition;
269 QAbstractItemView *itemView;
280 QProgressBar *progressBar;
286 bool dirHighlighting;
287 bool onlyDoubleClickSelectsFiles;
289 QTimer *progressDelayTimer;
309 bool shouldFetchForItems;
310 InlinePreviewState inlinePreviewState;
316 decorationPosition(QStyleOptionViewItem::
Left),
325 dirHighlighting(false),
327 progressDelayTimer(0),
339 shouldFetchForItems(false),
340 inlinePreviewState(NotForced)
344 KDirOperator::Private::~Private()
354 qDeleteAll(backStack);
355 qDeleteAll(forwardStack);
367 delete progressDelayTimer;
368 progressDelayTimer = 0;
375 d->splitter =
new QSplitter(
this);
376 d->splitter->setChildrenCollapsible(
false);
377 connect(d->splitter, SIGNAL(splitterMoved(
int,
int)),
378 this, SLOT(_k_slotSplitterMoved(
int,
int)));
385 if (_url.isEmpty()) {
386 QString strPath = QDir::currentPath();
387 strPath.append(QChar(
'/'));
389 d->currUrl.setProtocol(QLatin1String(
"file"));
390 d->currUrl.setPath(strPath);
393 if (d->currUrl.protocol().isEmpty())
394 d->currUrl.setProtocol(QLatin1String(
"file"));
396 d->currUrl.addPath(
"/");
402 setLayoutDirection(Qt::LeftToRight);
405 connect(&d->completion, SIGNAL(match(
QString)),
408 d->progressBar =
new QProgressBar(
this);
409 d->progressBar->setObjectName(
"d->progressBar");
410 d->progressBar->adjustSize();
411 d->progressBar->move(2, height() - d->progressBar->height() - 2);
413 d->progressDelayTimer =
new QTimer(
this);
414 d->progressDelayTimer->setObjectName(QLatin1String(
"d->progressBar delay timer"));
415 connect(d->progressDelayTimer, SIGNAL(
timeout()),
416 SLOT(_k_slotShowProgress()));
418 d->completeListDirty =
false;
424 d->sorting = QDir::NoSort;
425 d->updateSorting(QDir::Name | QDir::DirsFirst);
427 setFocusPolicy(Qt::WheelFocus);
433 disconnect(d->dirLister, 0,
this, 0);
440 d->updateSorting(spec);
451 if (
url().isLocalFile()) {
453 if (path.length() == 3)
454 return (path[0].isLetter() && path[1] ==
':' && path[2] ==
'/');
469 QApplication::restoreOverrideCursor();
470 d->progressBar->hide();
475 d->updateSorting((d->sorting & ~
QDirSortMask) | QDir::Name);
480 d->updateSorting((d->sorting & ~
QDirSortMask) | QDir::Size);
485 d->updateSorting((d->sorting & ~
QDirSortMask) | QDir::Time);
490 d->updateSorting((d->sorting & ~
QDirSortMask) | QDir::Type);
496 d->_k_slotSortReversed(!(d->sorting & QDir::Reversed));
501 d->_k_slotToggleDirsFirst();
506 if (d->proxyModel != 0) {
507 Qt::CaseSensitivity cs = d->proxyModel->sortCaseSensitivity();
508 cs = (cs == Qt::CaseSensitive) ? Qt::CaseInsensitive : Qt::CaseSensitive;
509 d->proxyModel->setSortCaseSensitivity(cs);
515 const bool hasSelection = (d->itemView != 0) &&
516 d->itemView->selectionModel()->hasSelection();
517 d->actionCollection->action(
"trash")->setEnabled(hasSelection);
518 d->actionCollection->action(
"delete")->setEnabled(hasSelection);
519 d->actionCollection->action(
"properties")->setEnabled(hasSelection);
524 const bool showPreview = (w != 0);
528 d->viewKind = (d->viewKind & ~
KFile::PreviewContents);
535 d->splitter->addWidget(w);
539 previewAction->setEnabled(showPreview);
540 previewAction->setChecked(showPreview);
541 setView(static_cast<KFile::FileView>(d->viewKind));
547 if (d->itemView == 0) {
551 const QItemSelection selection = d->proxyModel->mapSelectionToSource(d->itemView->selectionModel()->selection());
553 const QModelIndexList indexList = selection.indexes();
554 foreach(
const QModelIndex &index, indexList) {
555 KFileItem item = d->dirModel->itemForIndex(index);
557 itemList.append(item);
566 if ((item.
isNull()) || (d->itemView == 0)) {
570 const QModelIndex dirIndex = d->dirModel->indexForItem(item);
571 const QModelIndex proxyIndex = d->proxyModel->mapFromSource(dirIndex);
572 return d->itemView->selectionModel()->isSelected(proxyIndex);
577 return (d->dirLister == 0) ? 0 : d->dirLister->directories().count();
582 return (d->dirLister == 0) ? 0 : d->dirLister->items().count() -
numDirs();
592 return const_cast<KCompletion *
>(&d->dirCompletion);
597 return d->actionCollection;
604 void KDirOperator::Private::_k_slotDetailedView()
607 parent->setView(view);
610 void KDirOperator::Private::_k_slotSimpleView()
613 parent->setView(view);
616 void KDirOperator::Private::_k_slotTreeView()
619 parent->setView(view);
622 void KDirOperator::Private::_k_slotDetailedTreeView()
625 parent->setView(view);
628 void KDirOperator::Private::_k_slotToggleHidden(
bool show)
630 dirLister->setShowingDotFiles(show);
632 _k_assureVisibleSelection();
635 void KDirOperator::Private::_k_togglePreview(
bool on)
641 actionCollection->action(
"preview")->setChecked(
true);
642 splitter->addWidget(preview);
647 QMetaObject::invokeMethod(parent,
"_k_assureVisibleSelection", Qt::QueuedConnection);
649 const QModelIndex index = itemView->selectionModel()->currentIndex();
650 if (index.isValid()) {
651 _k_triggerPreview(index);
654 }
else if (preview != 0) {
655 viewKind = viewKind & ~
KFile::PreviewContents;
660 void KDirOperator::Private::_k_toggleInlinePreviews(
bool show)
662 if (showPreviews == show) {
668 if (!previewGenerator) {
672 previewGenerator->setPreviewShown(show);
677 for (
int i = 0; i < model->rowCount(); ++i) {
678 QModelIndex index = model->index(i, 0);
679 const KFileItem item = dirModel->itemForIndex(index);
685 void KDirOperator::Private::_k_slotOpenFileManager()
687 new KRun(currUrl, parent);
690 void KDirOperator::Private::_k_slotSortByName()
692 parent->sortByName();
695 void KDirOperator::Private::_k_slotSortBySize()
697 parent->sortBySize();
700 void KDirOperator::Private::_k_slotSortByDate()
702 parent->sortByDate();
705 void KDirOperator::Private::_k_slotSortByType()
707 parent->sortByType();
710 void KDirOperator::Private::_k_slotSortReversed(
bool doReverse)
712 QDir::SortFlags s = sorting & ~QDir::Reversed;
719 void KDirOperator::Private::_k_slotToggleDirsFirst()
721 QDir::SortFlags s = (sorting ^ QDir::DirsFirst);
725 void KDirOperator::Private::_k_slotToggleIgnoreCase()
741 d->newFileMenu->setPopupFiles(
url());
743 d->newFileMenu->createDirectory();
752 bool writeOk =
false;
756 const QStringList dirs = directory.split(
'/', QString::SkipEmptyParts);
757 QStringList::ConstIterator it = dirs.begin();
759 for (; it != dirs.end(); ++it) {
767 }
else if (!writeOk) {
769 "create that folder."));
770 }
else if (enterDirectory) {
779 bool ask,
bool showProgress)
781 if (items.isEmpty()) {
783 i18n(
"You did not select a file to delete."),
784 i18n(
"Nothing to Delete"));
803 if (items.count() == 1) {
805 i18n(
"<qt>Do you really want to delete\n <b>'%1'</b>?</qt>" ,
808 KStandardGuiItem::del(),
809 KStandardGuiItem::cancel(),
"AskForDelete");
812 i18np(
"Do you really want to delete this item?",
"Do you really want to delete these %1 items?", items.count()),
814 i18n(
"Delete Files"),
815 KStandardGuiItem::del(),
816 KStandardGuiItem::cancel(),
"AskForDelete");
821 KIO::JobFlags flags = showProgress ? KIO::DefaultFlags : KIO::HideProgressInfo;
823 job->ui()->setWindow(
this);
824 job->ui()->setAutoErrorHandlingEnabled(
true);
834 if (!list.isEmpty()) {
841 bool ask,
bool showProgress)
843 if (items.isEmpty()) {
845 i18n(
"You did not select a file to trash."),
846 i18n(
"Nothing to Trash"));
861 if (items.count() == 1) {
863 i18n(
"<qt>Do you really want to trash\n <b>'%1'</b>?</qt>" ,
867 KStandardGuiItem::cancel(),
"AskForTrash");
870 i18np(
"translators: not called for n == 1",
"Do you really want to trash these %1 items?", items.count()),
874 KStandardGuiItem::cancel(),
"AskForTrash");
879 KIO::JobFlags flags = showProgress ? KIO::DefaultFlags : KIO::HideProgressInfo;
881 job->ui()->setWindow(
this);
882 job->ui()->setAutoErrorHandlingEnabled(
true);
891 return d->previewGenerator;
896 d->inlinePreviewState = show ? Private::ForcedToTrue : Private::ForcedToFalse;
901 return d->showPreviews;
921 if (d->itemView == 0) {
925 if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
931 if (!list.isEmpty()) {
938 if (d->iconsZoom == _value) {
943 value = qMin(100, value);
944 value = qMax(0, value);
946 d->iconsZoom = value;
948 if (d->configGroup && d->inlinePreviewState == Private::NotForced) {
949 if (qobject_cast<QListView*>(d->itemView)) {
950 d->configGroup->writeEntry(
"listViewIconSize", d->iconsZoom);
952 d->configGroup->writeEntry(
"detailedViewIconSize", d->iconsZoom);
956 if (!d->previewGenerator) {
961 const int val = (maxSize * value / 100) + KIconLoader::SizeSmall;
962 d->itemView->setIconSize(
QSize(val, val));
963 d->updateListViewGrid();
964 d->previewGenerator->updatePreviews();
972 d->pendingMimeTypes.clear();
973 d->completion.clear();
974 d->dirCompletion.clear();
975 d->completeListDirty =
true;
976 d->dirLister->stop();
979 void KDirOperator::Private::checkPath(
const QString &,
bool )
986 text = text.trimmed();
989 if (text.find(
':') < 0 && text[0] !=
'/')
990 text.insert(0, d->currUrl);
994 if (!selection.isNull()) {
995 int position = text.lastIndexOf(
'/');
996 ASSERT(position >= 0);
997 QString filename = text.mid(position + 1, text.length());
998 if (filename != selection)
1003 bool filenameEntered =
false;
1005 if (u.isLocalFile()) {
1012 if (acceptOnlyExisting && !i.isFile())
1013 warning(
"you entered an invalid URL");
1015 filenameEntered =
true;
1020 if (filenameEntered) {
1021 filename_ = u.url();
1022 emit fileSelected(filename_);
1024 QApplication::restoreOverrideCursor();
1029 kDebug(kfile_area) <<
"TODO KDirOperator::checkPath()";
1036 if (!_newurl.isValid())
1037 newurl.
setPath(QDir::homePath());
1053 if (!Private::isReadable(newurl)) {
1061 if ((!res || !Private::isReadable(newurl)) && i.
isDir()) {
1064 i18n(
"The specified folder does not exist "
1065 "or was not readable."));
1067 }
else if (!i.
isDir()) {
1074 d->backStack.push(
new KUrl(d->currUrl));
1075 qDeleteAll(d->forwardStack);
1076 d->forwardStack.clear();
1080 d->currUrl = newurl;
1086 QAction* forwardAction = d->actionCollection->action(
"forward");
1087 forwardAction->setEnabled(!d->forwardStack.isEmpty());
1089 QAction* backAction = d->actionCollection->action(
"back");
1090 backAction->setEnabled(!d->backStack.isEmpty());
1092 QAction* upAction = d->actionCollection->action(
"up");
1093 upAction->setEnabled(!
isRoot());
1100 QApplication::setOverrideCursor(Qt::WaitCursor);
1101 d->dirLister->emitChanges();
1102 QApplication::restoreOverrideCursor();
1112 bool KDirOperator::Private::openUrl(
const KUrl& url, KDirLister::OpenUrlFlags flags)
1121 int KDirOperator::Private::sortColumn()
const
1137 Qt::SortOrder KDirOperator::Private::sortOrder()
const
1139 return (sorting & QDir::Reversed) ? Qt::DescendingOrder :
1143 void KDirOperator::Private::updateSorting(QDir::SortFlags sort)
1145 kDebug(kfile_area) <<
"changing sort flags from" << sorting <<
"to" << sort;
1146 if (sort == sorting) {
1150 if ((sorting ^ sort) & QDir::DirsFirst) {
1156 Qt::SortOrder tmpSortOrder = (sortOrder() == Qt::AscendingOrder ? Qt::DescendingOrder : Qt::AscendingOrder);
1157 proxyModel->sort(sortOrder(), tmpSortOrder);
1158 proxyModel->setSortFoldersFirst(sort & QDir::DirsFirst);
1162 parent->updateSortActions();
1163 proxyModel->sort(sortColumn(), sortOrder());
1172 if (treeView != 0) {
1173 QHeaderView* headerView = treeView->header();
1174 headerView->blockSignals(
true);
1175 headerView->setSortIndicator(sortColumn(), sortOrder());
1176 headerView->blockSignals(
false);
1179 _k_assureVisibleSelection();
1185 if (d->itemView == 0)
1188 d->pendingMimeTypes.clear();
1190 d->completion.clear();
1191 d->dirCompletion.clear();
1194 QApplication::restoreOverrideCursor();
1197 QApplication::setOverrideCursor(Qt::WaitCursor);
1199 if (!Private::isReadable(d->currUrl)) {
1201 i18n(
"The specified folder does not exist "
1202 "or was not readable."));
1203 if (d->backStack.isEmpty())
1210 void KDirOperator::Private::_k_slotRedirected(
const KUrl& newURL)
1213 pendingMimeTypes.clear();
1215 dirCompletion.clear();
1216 completeListDirty =
true;
1217 emit parent->urlEntered(newURL);
1223 if (d->backStack.isEmpty())
1226 d->forwardStack.push(
new KUrl(d->currUrl));
1228 KUrl *s = d->backStack.pop();
1237 if (d->forwardStack.isEmpty())
1240 d->backStack.push(
new KUrl(d->currUrl));
1242 KUrl *s = d->forwardStack.pop();
1254 KUrl tmp(d->currUrl);
1255 tmp.
cd(QLatin1String(
".."));
1268 d->dirLister->setNameFilter(
QString());
1269 d->dirLister->clearMimeFilter();
1275 d->dirLister->setNameFilter(filter);
1281 return d->dirLister->nameFilter();
1286 d->dirLister->setMimeFilter(mimetypes);
1292 return d->dirLister->mimeFilters();
1297 d->newFileMenu->setSupportedMimeTypes(mimeTypes);
1302 return d->newFileMenu->supportedMimeTypes();
1309 bool hasPreviewSupport =
false;
1311 if (cg.
readEntry(
"Show Default Preview",
true))
1312 hasPreviewSupport = d->checkPreviewInternal();
1314 previewAction->setEnabled(hasPreviewSupport);
1315 return hasPreviewSupport;
1323 d->newFileMenu->setPopupFiles(
url());
1325 d->newFileMenu->checkUpToDate();
1329 d->actionMenu->menu()->exec(pos);
1334 QWidget::changeEvent(event);
1343 switch(event->type()) {
1344 case QEvent::MouseMove: {
1345 if (d->preview && !d->preview->isHidden()) {
1346 const QModelIndex hoveredIndex = d->itemView->indexAt(d->itemView->viewport()->mapFromGlobal(QCursor::pos()));
1348 if (d->lastHoveredIndex == hoveredIndex)
1349 return QWidget::eventFilter(watched, event);
1351 d->lastHoveredIndex = hoveredIndex;
1353 const QModelIndex focusedIndex = d->itemView->selectionModel() ? d->itemView->selectionModel()->currentIndex()
1356 if (!hoveredIndex.isValid() && focusedIndex.isValid() &&
1357 d->itemView->selectionModel()->isSelected(focusedIndex) &&
1358 (d->lastHoveredIndex != focusedIndex)) {
1359 const QModelIndex sourceFocusedIndex = d->proxyModel->mapToSource(focusedIndex);
1360 const KFileItem item = d->dirModel->itemForIndex(sourceFocusedIndex);
1362 d->preview->showPreview(item.
url());
1368 case QEvent::MouseButtonRelease: {
1369 if (d->preview != 0 && !d->preview->isHidden()) {
1370 const QModelIndex hoveredIndex = d->itemView->indexAt(d->itemView->viewport()->mapFromGlobal(QCursor::pos()));
1371 const QModelIndex focusedIndex = d->itemView->selectionModel() ? d->itemView->selectionModel()->currentIndex()
1374 if (((!focusedIndex.isValid()) ||
1375 !d->itemView->selectionModel()->isSelected(focusedIndex)) &&
1376 (!hoveredIndex.isValid())) {
1377 d->preview->clearPreview();
1382 case QEvent::Wheel: {
1383 QWheelEvent *evt =
static_cast<QWheelEvent*
>(event);
1384 if (evt->modifiers() & Qt::ControlModifier) {
1385 if (evt->delta() > 0) {
1398 return QWidget::eventFilter(watched, event);
1401 bool KDirOperator::Private::checkPreviewInternal()
const
1405 if (parent->dirOnlyMode() && supported.indexOf(
"inode/directory") == -1)
1409 const QStringList nameFilter = dirLister->nameFilter().split(
' ', QString::SkipEmptyParts);
1411 if (mimeTypes.isEmpty() && nameFilter.isEmpty() && !supported.isEmpty())
1415 r.setPatternSyntax(QRegExp::Wildcard);
1417 if (!mimeTypes.isEmpty()) {
1418 QStringList::ConstIterator it = supported.begin();
1420 for (; it != supported.end(); ++it) {
1424 if (!result.isEmpty()) {
1430 if (!nameFilter.isEmpty()) {
1432 QStringList::const_iterator it1 = nameFilter.begin();
1433 for (; it1 != nameFilter.end(); ++it1) {
1434 if ((*it1) ==
"*") {
1445 QStringList::ConstIterator it2 = supported.begin();
1446 for (; it2 != supported.end(); ++it2) {
1448 if (r.indexIn(mime) != -1) {
1461 QAbstractItemView *itemView = 0;
1465 itemView = detailView;
1467 itemView =
new KDirOperatorIconView(
this, parent);
1478 QWidget::setAcceptDrops(b);
1483 d->dropOptions = options;
1506 && d->actionCollection->action(
"preview")->isEnabled();
1509 d->viewKind =
static_cast<int>(viewKind);
1512 QAbstractItemView *newView =
createView(
this, viewKind);
1515 d->_k_togglePreview(preview);
1530 if (d->mode == mode)
1538 if (d->itemView != 0)
1539 setView(static_cast<KFile::FileView>(d->viewKind));
1544 if (view == d->itemView) {
1549 d->pendingMimeTypes.clear();
1550 const bool listDir = (d->itemView == 0);
1553 view->setSelectionMode(QAbstractItemView::ExtendedSelection);
1555 view->setSelectionMode(QAbstractItemView::SingleSelection);
1559 if ((d->itemView != 0) && d->itemView->selectionModel()->hasSelection()) {
1562 const QItemSelection selection = d->itemView->selectionModel()->selection();
1564 selectionModel->select(selection, QItemSelectionModel::Select);
1570 d->itemView->setModel(d->proxyModel);
1571 setFocusProxy(d->itemView);
1573 view->viewport()->installEventFilter(
this);
1576 d->itemView->setItemDelegate(delegate);
1577 d->itemView->viewport()->setAttribute(Qt::WA_Hover);
1578 d->itemView->setContextMenuPolicy(Qt::CustomContextMenu);
1579 d->itemView->setMouseTracking(
true);
1585 QHeaderView* headerView = treeView->header();
1586 headerView->setSortIndicator(d->sortColumn(), d->sortOrder());
1587 connect(headerView, SIGNAL(sortIndicatorChanged(
int,Qt::SortOrder)),
1588 this, SLOT(_k_synchronizeSortingState(
int,Qt::SortOrder)));
1591 connect(d->itemView, SIGNAL(activated(QModelIndex)),
1592 this, SLOT(_k_slotActivated(QModelIndex)));
1593 connect(d->itemView, SIGNAL(customContextMenuRequested(
QPoint)),
1594 this, SLOT(_k_openContextMenu(
QPoint)));
1595 connect(d->itemView, SIGNAL(entered(QModelIndex)),
1596 this, SLOT(_k_triggerPreview(QModelIndex)));
1599 d->splitter->insertWidget(0, d->itemView);
1601 d->splitter->resize(size());
1602 d->itemView->show();
1605 QApplication::setOverrideCursor(Qt::WaitCursor);
1606 d->openUrl(d->currUrl);
1609 if (selectionModel != 0) {
1610 d->itemView->setSelectionModel(selectionModel);
1611 QMetaObject::invokeMethod(
this,
"_k_assureVisibleSelection", Qt::QueuedConnection);
1614 connect(d->itemView->selectionModel(),
1615 SIGNAL(currentChanged(QModelIndex,QModelIndex)),
1616 this, SLOT(_k_triggerPreview(QModelIndex)));
1617 connect(d->itemView->selectionModel(),
1618 SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
1619 this, SLOT(_k_slotSelectionChanged()));
1623 d->decorationMenu->setEnabled(qobject_cast<QListView*>(d->itemView));
1626 if (d->shouldFetchForItems) {
1627 connect(d->dirModel, SIGNAL(expand(QModelIndex)),
this, SLOT(_k_slotExpandToUrl(QModelIndex)));
1629 d->itemsToBeSetAsCurrent.clear();
1632 const bool previewForcedToTrue = d->inlinePreviewState == Private::ForcedToTrue;
1633 const bool previewShown = d->inlinePreviewState == Private::NotForced ? d->showPreviews : previewForcedToTrue;
1636 const int val = (maxSize * d->iconsZoom / 100) + KIconLoader::SizeSmall;
1638 d->previewGenerator->setPreviewShown(previewShown);
1639 d->actionCollection->action(
"inline preview")->setChecked(previewShown);
1642 d->_k_slotChangeDecorationPosition();
1646 const int zoom = previewForcedToTrue ? (
KIconLoader::SizeHuge - KIconLoader::SizeSmall + 1) * 100 / maxSize : d->iconSizeForViewType(view);
1654 if (lister == d->dirLister)
1660 delete d->proxyModel;
1664 d->dirLister = lister;
1667 d->dirModel->setDirLister(d->dirLister);
1670 d->shouldFetchForItems = qobject_cast<
QTreeView*>(d->itemView);
1671 if (d->shouldFetchForItems) {
1672 connect(d->dirModel, SIGNAL(expand(QModelIndex)),
this, SLOT(_k_slotExpandToUrl(QModelIndex)));
1674 d->itemsToBeSetAsCurrent.clear();
1678 d->proxyModel->setSourceModel(d->dirModel);
1680 d->dirLister->setAutoUpdate(
true);
1681 d->dirLister->setDelayedMimeTypes(
true);
1683 QWidget* mainWidget = topLevelWidget();
1684 d->dirLister->setMainWindow(mainWidget);
1687 connect(d->dirLister, SIGNAL(percent(
int)),
1688 SLOT(_k_slotProgress(
int)));
1689 connect(d->dirLister, SIGNAL(started(
KUrl)), SLOT(_k_slotStarted()));
1690 connect(d->dirLister, SIGNAL(completed()), SLOT(_k_slotIOFinished()));
1691 connect(d->dirLister, SIGNAL(canceled()), SLOT(_k_slotCanceled()));
1692 connect(d->dirLister, SIGNAL(redirection(
KUrl)),
1693 SLOT(_k_slotRedirected(
KUrl)));
1694 connect(d->dirLister, SIGNAL(newItems(
KFileItemList)), SLOT(_k_slotItemsChanged()));
1695 connect(d->dirLister, SIGNAL(itemsDeleted(
KFileItemList)), SLOT(_k_slotItemsChanged()));
1696 connect(d->dirLister, SIGNAL(itemsFilteredByMime(
KFileItemList)), SLOT(_k_slotItemsChanged()));
1697 connect(d->dirLister, SIGNAL(
clear()), SLOT(_k_slotItemsChanged()));
1707 QApplication::restoreOverrideCursor();
1714 if ((d->preview != 0 && !d->preview->isHidden()) && !item.
isNull()) {
1715 d->preview->showPreview(item.
url());
1725 KFileItem item = d->dirLister->findByUrl(url);
1726 if (d->shouldFetchForItems && item.
isNull()) {
1727 d->itemsToBeSetAsCurrent <<
url;
1728 d->dirModel->expandToUrl(url);
1747 const QModelIndex dirIndex = d->dirModel->indexForItem(item);
1748 const QModelIndex proxyIndex = d->proxyModel->mapFromSource(dirIndex);
1749 selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::Select);
1763 foreach (
const QString &url, urls) {
1764 KFileItem item = d->dirLister->findByUrl(url);
1765 if (d->shouldFetchForItems && item.
isNull()) {
1766 d->itemsToBeSetAsCurrent <<
url;
1767 d->dirModel->expandToUrl(url);
1780 if (d->itemView == 0) {
1787 QModelIndex proxyIndex;
1788 foreach (
const KFileItem &item, items) {
1790 const QModelIndex dirIndex = d->dirModel->indexForItem(item);
1791 proxyIndex = d->proxyModel->mapFromSource(dirIndex);
1792 selModel->select(proxyIndex, QItemSelectionModel::Select);
1795 if (proxyIndex.isValid()) {
1796 selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::NoUpdate);
1803 if (
string.isEmpty()) {
1804 d->itemView->selectionModel()->clear();
1809 return d->completion.makeCompletion(
string);
1814 if (
string.isEmpty()) {
1815 d->itemView->selectionModel()->clear();
1820 return d->dirCompletion.makeCompletion(
string);
1825 if (d->itemView == 0) {
1829 if (d->completeListDirty) {
1831 foreach (
const KFileItem &item, itemList) {
1832 d->completion.addItem(item.
name());
1834 d->dirCompletion.addItem(item.
name());
1837 d->completeListDirty =
false;
1850 d->actionCollection->setObjectName(
"KDirOperator::actionCollection");
1853 d->actionCollection->addAction(
"popupMenu", d->actionMenu);
1855 QAction* upAction = d->actionCollection->addAction(KStandardAction::Up,
"up",
this, SLOT(
cdUp()));
1856 upAction->setText(
i18n(
"Parent Folder"));
1858 d->actionCollection->addAction(KStandardAction::Back,
"back",
this, SLOT(
back()));
1860 d->actionCollection->addAction(KStandardAction::Forward,
"forward",
this, SLOT(
forward()));
1862 QAction* homeAction = d->actionCollection->addAction(KStandardAction::Home,
"home",
this, SLOT(
home()));
1863 homeAction->setText(
i18n(
"Home Folder"));
1865 KAction* reloadAction = d->actionCollection->addAction(KStandardAction::Redisplay,
"reload",
this, SLOT(
rereadDir()));
1866 reloadAction->setText(
i18n(
"Reload"));
1867 reloadAction->
setShortcuts(KStandardShortcut::shortcut(KStandardShortcut::Reload));
1870 d->actionCollection->addAction(
"mkdir", mkdirAction);
1871 mkdirAction->setIcon(
KIcon(QLatin1String(
"folder-new")));
1872 connect(mkdirAction, SIGNAL(triggered(
bool)),
this, SLOT(
mkdir()));
1875 d->actionCollection->addAction(
"trash", trash);
1876 trash->setIcon(
KIcon(
"user-trash"));
1878 connect(trash, SIGNAL(triggered(
bool)), SLOT(
trashSelected()));
1881 d->actionCollection->addAction(
"delete", action);
1882 action->setIcon(
KIcon(
"edit-delete"));
1884 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(
deleteSelected()));
1888 d->actionCollection->addAction(
"sorting menu", sortMenu);
1891 d->actionCollection->addAction(
"by name", byNameAction);
1892 connect(byNameAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotSortByName()));
1895 d->actionCollection->addAction(
"by size", bySizeAction);
1896 connect(bySizeAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotSortBySize()));
1899 d->actionCollection->addAction(
"by date", byDateAction);
1900 connect(byDateAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotSortByDate()));
1903 d->actionCollection->addAction(
"by type", byTypeAction);
1904 connect(byTypeAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotSortByType()));
1907 d->actionCollection->addAction(
"descending", descendingAction);
1908 connect(descendingAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotSortReversed(
bool)));
1911 d->actionCollection->addAction(
"dirs first", dirsFirstAction);
1912 connect(dirsFirstAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotToggleDirsFirst()));
1914 QActionGroup* sortGroup =
new QActionGroup(
this);
1915 byNameAction->setActionGroup(sortGroup);
1916 bySizeAction->setActionGroup(sortGroup);
1917 byDateAction->setActionGroup(sortGroup);
1918 byTypeAction->setActionGroup(sortGroup);
1921 d->actionCollection->addAction(
"decoration menu", d->decorationMenu);
1924 d->actionCollection->addAction(
"decorationAtLeft", d->leftAction);
1925 connect(d->leftAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotChangeDecorationPosition()));
1928 d->actionCollection->addAction(
"decorationAtTop", topAction);
1929 connect(topAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotChangeDecorationPosition()));
1931 d->decorationMenu->addAction(d->leftAction);
1932 d->decorationMenu->addAction(topAction);
1934 QActionGroup* decorationGroup =
new QActionGroup(
this);
1935 d->leftAction->setActionGroup(decorationGroup);
1936 topAction->setActionGroup(decorationGroup);
1939 d->actionCollection->addAction(
"short view", shortAction);
1940 shortAction->setIcon(
KIcon(QLatin1String(
"view-list-icons")));
1941 connect(shortAction, SIGNAL(triggered()), SLOT(_k_slotSimpleView()));
1944 d->actionCollection->addAction(
"detailed view", detailedAction);
1945 detailedAction->setIcon(
KIcon(QLatin1String(
"view-list-details")));
1946 connect(detailedAction, SIGNAL(triggered()), SLOT(_k_slotDetailedView()));
1949 d->actionCollection->addAction(
"tree view", treeAction);
1950 treeAction->setIcon(
KIcon(QLatin1String(
"view-list-tree")));
1951 connect(treeAction, SIGNAL(triggered()), SLOT(_k_slotTreeView()));
1954 d->actionCollection->addAction(
"detailed tree view", detailedTreeAction);
1955 detailedTreeAction->setIcon(
KIcon(QLatin1String(
"view-list-tree")));
1956 connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView()));
1958 QActionGroup* viewGroup =
new QActionGroup(
this);
1959 shortAction->setActionGroup(viewGroup);
1960 detailedAction->setActionGroup(viewGroup);
1961 treeAction->setActionGroup(viewGroup);
1962 detailedTreeAction->setActionGroup(viewGroup);
1965 d->actionCollection->addAction(
"show hidden", showHiddenAction);
1966 connect(showHiddenAction, SIGNAL(toggled(
bool)), SLOT(_k_slotToggleHidden(
bool)));
1969 d->actionCollection->addAction(
"preview", previewAction);
1970 connect(previewAction, SIGNAL(toggled(
bool)),
1971 SLOT(_k_togglePreview(
bool)));
1974 i18n(
"Show Preview"),
this);
1975 d->actionCollection->addAction(
"inline preview", inlinePreview);
1976 connect(inlinePreview, SIGNAL(toggled(
bool)), SLOT(_k_toggleInlinePreviews(
bool)));
1979 d->actionCollection->addAction(
"file manager", fileManager);
1980 fileManager->setIcon(
KIcon(QLatin1String(
"system-file-manager")));
1981 connect(fileManager, SIGNAL(triggered()), SLOT(_k_slotOpenFileManager()));
1984 d->actionCollection->addAction(
"properties", action);
1985 action->setIcon(
KIcon(
"document-properties"));
1987 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotProperties()));
1991 d->actionCollection->addAction(
"view menu", viewMenu);
1996 viewMenu->
addAction(detailedTreeAction);
2000 d->newFileMenu =
new KNewFileMenu(d->actionCollection,
"new",
this);
2001 connect(d->newFileMenu, SIGNAL(directoryCreated(
KUrl)),
this, SLOT(_k_slotDirectoryCreated(
KUrl)));
2003 d->actionCollection->addAssociatedWidget(
this);
2004 foreach (
QAction* action, d->actionCollection->actions())
2005 action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
2017 sortMenu->
menu()->clear();
2018 sortMenu->
addAction(d->actionCollection->action(
"by name"));
2019 sortMenu->
addAction(d->actionCollection->action(
"by size"));
2020 sortMenu->
addAction(d->actionCollection->action(
"by date"));
2021 sortMenu->
addAction(d->actionCollection->action(
"by type"));
2023 sortMenu->
addAction(d->actionCollection->action(
"descending"));
2024 sortMenu->
addAction(d->actionCollection->action(
"dirs first"));
2027 d->actionMenu->menu()->clear();
2029 d->actionMenu->addAction(d->actionCollection->action(
"up"));
2030 d->actionMenu->addAction(d->actionCollection->action(
"back"));
2031 d->actionMenu->addAction(d->actionCollection->action(
"forward"));
2032 d->actionMenu->addAction(d->actionCollection->action(
"home"));
2033 d->actionMenu->addSeparator();
2037 d->actionMenu->addAction(d->actionCollection->action(
"new"));
2038 if (d->currUrl.isLocalFile() && !(QApplication::keyboardModifiers() & Qt::ShiftModifier)) {
2039 d->actionMenu->addAction(d->actionCollection->action(
"trash"));
2041 KConfigGroup cg(KGlobal::config(), QLatin1String(
"KDE"));
2042 const bool del = !d->currUrl.isLocalFile() ||
2043 (QApplication::keyboardModifiers() & Qt::ShiftModifier) ||
2044 cg.
readEntry(
"ShowDeleteCommand",
false);
2046 d->actionMenu->addAction(d->actionCollection->action(
"delete"));
2048 d->actionMenu->addSeparator();
2052 d->actionMenu->addAction(sortMenu);
2054 d->actionMenu->addSeparator();
2059 d->actionMenu->addAction(d->actionCollection->action(
"view menu"));
2060 d->actionMenu->addSeparator();
2063 if (whichActions & FileActions) {
2064 d->actionMenu->addAction(d->actionCollection->action(
"file manager"));
2065 d->actionMenu->addAction(d->actionCollection->action(
"properties"));
2072 d->actionCollection->action(
"by name")->setChecked(
true);
2074 d->actionCollection->action(
"by date")->setChecked(
true);
2076 d->actionCollection->action(
"by size")->setChecked(
true);
2078 d->actionCollection->action(
"by type")->setChecked(
true);
2080 d->actionCollection->action(
"descending")->setChecked(d->sorting & QDir::Reversed);
2081 d->actionCollection->action(
"dirs first")->setChecked(d->sorting & QDir::DirsFirst);
2102 if (viewStyle == QLatin1String(
"Detail")) {
2104 }
else if (viewStyle == QLatin1String(
"Tree")) {
2106 }
else if (viewStyle == QLatin1String(
"DetailTree")) {
2115 if (configGroup.
readEntry(QLatin1String(
"Show Preview"),
false)) {
2119 d->previewWidth = configGroup.
readEntry(QLatin1String(
"Preview Width"), 100);
2121 if (configGroup.
readEntry(QLatin1String(
"Show hidden files"),
2123 d->actionCollection->action(
"show hidden")->setChecked(
true);
2124 d->dirLister->setShowingDotFiles(
true);
2127 QDir::SortFlags
sorting = QDir::Name;
2128 if (configGroup.
readEntry(QLatin1String(
"Sort directories first"),
2130 sorting |= QDir::DirsFirst;
2134 if (sortBy == name) {
2135 sorting |= QDir::Name;
2136 }
else if (sortBy == QLatin1String(
"Size")) {
2137 sorting |= QDir::Size;
2138 }
else if (sortBy == QLatin1String(
"Date")) {
2139 sorting |= QDir::Time;
2140 }
else if (sortBy == QLatin1String(
"Type")) {
2141 sorting |= QDir::Type;
2144 sorting |= QDir::Reversed;
2146 d->updateSorting(sorting);
2148 if (d->inlinePreviewState == Private::NotForced) {
2149 d->showPreviews = configGroup.
readEntry(QLatin1String(
"Previews"),
false);
2157 QString sortBy = QLatin1String(
"Name");
2159 sortBy = QLatin1String(
"Size");
2161 sortBy = QLatin1String(
"Date");
2163 sortBy = QLatin1String(
"Type");
2166 configGroup.
writeEntry(QLatin1String(
"Sort by"), sortBy);
2168 configGroup.
writeEntry(QLatin1String(
"Sort reversed"),
2169 d->actionCollection->action(
"descending")->isChecked());
2171 configGroup.
writeEntry(QLatin1String(
"Sort directories first"),
2172 d->actionCollection->action(
"dirs first")->isChecked());
2175 bool appSpecificPreview =
false;
2178 appSpecificPreview = (tmp == 0);
2181 if (!appSpecificPreview) {
2183 if (previewAction->isEnabled()) {
2184 bool hasPreview = previewAction->isChecked();
2185 configGroup.
writeEntry(QLatin1String(
"Show Preview"), hasPreview);
2190 Q_ASSERT(sizes.count() == 2);
2191 configGroup.
writeEntry(QLatin1String(
"Preview Width"), sizes[1]);
2196 configGroup.
writeEntry(QLatin1String(
"Show hidden files"),
2197 d->actionCollection->action(
"show hidden")->isChecked());
2202 style = QLatin1String(
"Detail");
2204 style = QLatin1String(
"Simple");
2206 style = QLatin1String(
"Tree");
2208 style = QLatin1String(
"DetailTree");
2209 configGroup.
writeEntry(QLatin1String(
"View Style"), style);
2211 if (d->inlinePreviewState == Private::NotForced) {
2212 configGroup.
writeEntry(QLatin1String(
"Previews"), d->showPreviews);
2215 configGroup.
writeEntry(QLatin1String(
"Decoration position"), (
int) d->decorationPosition);
2223 const bool hasPreview = (sizes.count() == 2);
2225 d->splitter->resize(size());
2226 sizes = d->splitter->sizes();
2228 const bool restorePreviewWidth = hasPreview && (d->previewWidth != sizes[1]);
2229 if (restorePreviewWidth) {
2230 const int availableWidth = sizes[0] + sizes[1];
2231 sizes[0] = availableWidth - d->previewWidth;
2232 sizes[1] = d->previewWidth;
2233 d->splitter->setSizes(sizes);
2236 d->previewWidth = sizes[1];
2239 if (d->progressBar->parent() ==
this) {
2241 d->progressBar->move(2, height() - d->progressBar->height() - 2);
2247 d->onlyDoubleClickSelectsFiles = enable;
2256 return d->onlyDoubleClickSelectsFiles;
2259 void KDirOperator::Private::_k_slotStarted()
2261 progressBar->setValue(0);
2263 progressDelayTimer->setSingleShot(
true);
2264 progressDelayTimer->start(1000);
2267 void KDirOperator::Private::_k_slotShowProgress()
2269 progressBar->raise();
2270 progressBar->show();
2271 QApplication::flush();
2274 void KDirOperator::Private::_k_slotProgress(
int percent)
2276 progressBar->setValue(percent);
2278 if (progressBar->isVisible())
2279 QApplication::flush();
2283 void KDirOperator::Private::_k_slotIOFinished()
2285 progressDelayTimer->stop();
2286 _k_slotProgress(100);
2287 progressBar->hide();
2288 emit parent->finishedLoading();
2289 parent->resetCursor();
2292 preview->clearPreview();
2296 void KDirOperator::Private::_k_slotCanceled()
2298 emit parent->finishedLoading();
2299 parent->resetCursor();
2304 return d->progressBar;
2309 qDeleteAll(d->backStack);
2310 d->backStack.clear();
2311 d->actionCollection->action(
"back")->setEnabled(
false);
2313 qDeleteAll(d->forwardStack);
2314 d->forwardStack.clear();
2315 d->actionCollection->action(
"forward")->setEnabled(
false);
2320 d->dirHighlighting = enable;
2325 return d->dirHighlighting;
2339 void KDirOperator::Private::_k_slotProperties()
2341 if (itemView == 0) {
2346 if (!list.isEmpty()) {
2352 void KDirOperator::Private::_k_slotActivated(
const QModelIndex& index)
2354 const QModelIndex dirIndex = proxyModel->mapToSource(index);
2355 KFileItem item = dirModel->itemForIndex(dirIndex);
2357 const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
2358 if (item.
isNull() || (modifiers & Qt::ShiftModifier) || (modifiers & Qt::ControlModifier))
2362 parent->selectDir(item);
2364 parent->selectFile(item);
2368 void KDirOperator::Private::_k_slotSelectionChanged()
2370 if (itemView == 0) {
2377 const bool multiSelectionMode = (itemView->selectionMode() == QAbstractItemView::ExtendedSelection);
2378 const bool hasSelection = itemView->selectionModel()->hasSelection();
2379 if (multiSelectionMode || !hasSelection) {
2381 parent->highlightFile(nullItem);
2384 KFileItem selectedItem = parent->selectedItems().first();
2385 parent->highlightFile(selectedItem);
2389 void KDirOperator::Private::_k_openContextMenu(
const QPoint& pos)
2391 const QModelIndex proxyIndex = itemView->indexAt(pos);
2392 const QModelIndex dirIndex = proxyModel->mapToSource(proxyIndex);
2393 KFileItem item = dirModel->itemForIndex(dirIndex);
2398 parent->activatedMenu(item, QCursor::pos());
2401 void KDirOperator::Private::_k_triggerPreview(
const QModelIndex& index)
2403 if ((preview != 0 && !preview->isHidden()) && index.isValid() && (index.column() ==
KDirModel::Name)) {
2404 const QModelIndex dirIndex = proxyModel->mapToSource(index);
2405 const KFileItem item = dirModel->itemForIndex(dirIndex);
2410 if (!item.
isDir()) {
2411 previewUrl = item.
url();
2414 preview->clearPreview();
2419 void KDirOperator::Private::_k_showPreview()
2422 preview->showPreview(previewUrl);
2426 void KDirOperator::Private::_k_slotSplitterMoved(
int,
int)
2429 if (sizes.count() == 2) {
2431 previewWidth = sizes[1];
2435 void KDirOperator::Private::_k_assureVisibleSelection()
2437 if (itemView == 0) {
2442 if (selModel->hasSelection()) {
2443 const QModelIndex index = selModel->currentIndex();
2444 itemView->scrollTo(index, QAbstractItemView::EnsureVisible);
2445 _k_triggerPreview(index);
2450 void KDirOperator::Private::_k_synchronizeSortingState(
int logicalIndex, Qt::SortOrder order)
2452 QDir::SortFlags newSort = sorting & ~(
QDirSortMask | QDir::Reversed);
2454 switch (logicalIndex) {
2456 newSort |= QDir::Name;
2459 newSort |= QDir::Size;
2462 newSort |= QDir::Time;
2465 newSort |= QDir::Type;
2471 if (order == Qt::DescendingOrder) {
2472 newSort |= QDir::Reversed;
2475 updateSorting(newSort);
2477 QMetaObject::invokeMethod(parent,
"_k_assureVisibleSelection", Qt::QueuedConnection);
2480 void KDirOperator::Private::_k_slotChangeDecorationPosition()
2492 const bool leftChecked = actionCollection->action(
"decorationAtLeft")->isChecked();
2496 view->setFlow(QListView::TopToBottom);
2499 view->setFlow(QListView::LeftToRight);
2502 updateListViewGrid();
2507 void KDirOperator::Private::_k_slotExpandToUrl(
const QModelIndex &index)
2515 const KFileItem item = dirModel->itemForIndex(index);
2521 if (!item.
isDir()) {
2522 const QModelIndex proxyIndex = proxyModel->mapFromSource(index);
2524 KUrl::List::Iterator it = itemsToBeSetAsCurrent.begin();
2525 while (it != itemsToBeSetAsCurrent.end()) {
2526 const KUrl url = *it;
2528 const KFileItem _item = dirLister->findByUrl(url);
2530 const QModelIndex _index = dirModel->indexForItem(_item);
2531 const QModelIndex _proxyIndex = proxyModel->mapFromSource(_index);
2532 treeView->expand(_proxyIndex);
2536 treeView->selectionModel()->select(proxyIndex, QItemSelectionModel::Select);
2539 it = itemsToBeSetAsCurrent.erase(it);
2544 }
else if (!itemsToBeSetAsCurrent.contains(item.
url())) {
2545 itemsToBeSetAsCurrent << item.
url();
2549 void KDirOperator::Private::_k_slotItemsChanged()
2551 completeListDirty =
true;
2554 void KDirOperator::Private::updateListViewGrid()
2566 const bool leftChecked = actionCollection->action(
"decorationAtLeft")->isChecked();
2569 view->setGridSize(
QSize());
2575 const QFontMetrics metrics(itemView->viewport()->font());
2576 int size = itemView->iconSize().height() + metrics.height() * 2;
2578 view->setGridSize(
QSize(size * (3.0 / 2.0), size + metrics.height()));
2586 int KDirOperator::Private::iconSizeForViewType(QAbstractItemView *itemView)
const
2588 if (!itemView || !configGroup) {
2592 if (qobject_cast<QListView*>(itemView)) {
2593 return configGroup->readEntry(
"listViewIconSize", 0);
2595 return configGroup->readEntry(
"detailedViewIconSize", 0);
2601 delete d->configGroup;
2607 return d->configGroup;
2612 d->actionCollection->action(
"show hidden")->setChecked(s);
2617 return d->actionCollection->action(
"show hidden")->isChecked();
2622 return d->decorationPosition;
2627 d->decorationPosition = position;
2629 d->actionCollection->action(
"decorationAtLeft")->setChecked(decorationAtLeft);
2630 d->actionCollection->action(
"decorationAtTop")->setChecked(!decorationAtLeft);
2635 bool KDirOperator::Private::isReadable(
const KUrl& url)
2640 KDE_struct_stat buf;
2646 bool readable = (KDE::stat(ts, &buf) == 0);
2649 test = opendir(QFile::encodeName(ts));
2650 readable = (test != 0);
2657 void KDirOperator::Private::_k_slotDirectoryCreated(
const KUrl& url)
2659 parent->setUrl(url,
true);
2662 #include "kdiroperator.moc"