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(
'/'));
388 d->currUrl = QUrl::fromLocalFile(strPath);
391 if (d->currUrl.protocol().isEmpty())
392 d->currUrl.setProtocol(QLatin1String(
"file"));
394 d->currUrl.addPath(
"/");
400 setLayoutDirection(Qt::LeftToRight);
403 connect(&d->completion, SIGNAL(match(
QString)),
406 d->progressBar =
new QProgressBar(
this);
407 d->progressBar->setObjectName(
"d->progressBar");
408 d->progressBar->adjustSize();
409 d->progressBar->move(2, height() - d->progressBar->height() - 2);
411 d->progressDelayTimer =
new QTimer(
this);
412 d->progressDelayTimer->setObjectName(QLatin1String(
"d->progressBar delay timer"));
413 connect(d->progressDelayTimer, SIGNAL(
timeout()),
414 SLOT(_k_slotShowProgress()));
416 d->completeListDirty =
false;
422 d->sorting = QDir::NoSort;
423 d->updateSorting(QDir::Name | QDir::DirsFirst);
425 setFocusPolicy(Qt::WheelFocus);
431 disconnect(d->dirLister, 0,
this, 0);
438 d->updateSorting(spec);
449 if (
url().isLocalFile()) {
451 if (path.length() == 3)
452 return (path[0].isLetter() && path[1] ==
':' && path[2] ==
'/');
467 QApplication::restoreOverrideCursor();
468 d->progressBar->hide();
473 d->updateSorting((d->sorting & ~
QDirSortMask) | QDir::Name);
478 d->updateSorting((d->sorting & ~
QDirSortMask) | QDir::Size);
483 d->updateSorting((d->sorting & ~
QDirSortMask) | QDir::Time);
488 d->updateSorting((d->sorting & ~
QDirSortMask) | QDir::Type);
494 d->_k_slotSortReversed(!(d->sorting & QDir::Reversed));
499 d->_k_slotToggleDirsFirst();
504 if (d->proxyModel != 0) {
505 Qt::CaseSensitivity cs = d->proxyModel->sortCaseSensitivity();
506 cs = (cs == Qt::CaseSensitive) ? Qt::CaseInsensitive : Qt::CaseSensitive;
507 d->proxyModel->setSortCaseSensitivity(cs);
513 const bool hasSelection = (d->itemView != 0) &&
514 d->itemView->selectionModel()->hasSelection();
515 d->actionCollection->action(
"trash")->setEnabled(hasSelection);
516 d->actionCollection->action(
"delete")->setEnabled(hasSelection);
517 d->actionCollection->action(
"properties")->setEnabled(hasSelection);
522 const bool showPreview = (w != 0);
526 d->viewKind = (d->viewKind & ~
KFile::PreviewContents);
533 d->splitter->addWidget(w);
537 previewAction->setEnabled(showPreview);
538 previewAction->setChecked(showPreview);
539 setView(static_cast<KFile::FileView>(d->viewKind));
545 if (d->itemView == 0) {
549 const QItemSelection selection = d->proxyModel->mapSelectionToSource(d->itemView->selectionModel()->selection());
551 const QModelIndexList indexList = selection.indexes();
552 foreach(
const QModelIndex &index, indexList) {
553 KFileItem item = d->dirModel->itemForIndex(index);
555 itemList.append(item);
564 if ((item.
isNull()) || (d->itemView == 0)) {
568 const QModelIndex dirIndex = d->dirModel->indexForItem(item);
569 const QModelIndex proxyIndex = d->proxyModel->mapFromSource(dirIndex);
570 return d->itemView->selectionModel()->isSelected(proxyIndex);
575 return (d->dirLister == 0) ? 0 : d->dirLister->directories().count();
580 return (d->dirLister == 0) ? 0 : d->dirLister->items().count() -
numDirs();
590 return const_cast<KCompletion *
>(&d->dirCompletion);
595 return d->actionCollection;
602 void KDirOperator::Private::_k_slotDetailedView()
605 parent->setView(view);
608 void KDirOperator::Private::_k_slotSimpleView()
611 parent->setView(view);
614 void KDirOperator::Private::_k_slotTreeView()
617 parent->setView(view);
620 void KDirOperator::Private::_k_slotDetailedTreeView()
623 parent->setView(view);
626 void KDirOperator::Private::_k_slotToggleHidden(
bool show)
628 dirLister->setShowingDotFiles(show);
630 _k_assureVisibleSelection();
633 void KDirOperator::Private::_k_togglePreview(
bool on)
639 actionCollection->action(
"preview")->setChecked(
true);
640 splitter->addWidget(preview);
645 QMetaObject::invokeMethod(parent,
"_k_assureVisibleSelection", Qt::QueuedConnection);
647 const QModelIndex index = itemView->selectionModel()->currentIndex();
648 if (index.isValid()) {
649 _k_triggerPreview(index);
652 }
else if (preview != 0) {
653 viewKind = viewKind & ~
KFile::PreviewContents;
658 void KDirOperator::Private::_k_toggleInlinePreviews(
bool show)
660 if (showPreviews == show) {
666 if (!previewGenerator) {
670 previewGenerator->setPreviewShown(show);
675 for (
int i = 0; i < model->rowCount(); ++i) {
676 QModelIndex index = model->index(i, 0);
677 const KFileItem item = dirModel->itemForIndex(index);
683 void KDirOperator::Private::_k_slotOpenFileManager()
685 new KRun(currUrl, parent);
688 void KDirOperator::Private::_k_slotSortByName()
690 parent->sortByName();
693 void KDirOperator::Private::_k_slotSortBySize()
695 parent->sortBySize();
698 void KDirOperator::Private::_k_slotSortByDate()
700 parent->sortByDate();
703 void KDirOperator::Private::_k_slotSortByType()
705 parent->sortByType();
708 void KDirOperator::Private::_k_slotSortReversed(
bool doReverse)
710 QDir::SortFlags s = sorting & ~QDir::Reversed;
717 void KDirOperator::Private::_k_slotToggleDirsFirst()
719 QDir::SortFlags s = (sorting ^ QDir::DirsFirst);
723 void KDirOperator::Private::_k_slotToggleIgnoreCase()
739 d->newFileMenu->setPopupFiles(
url());
741 d->newFileMenu->createDirectory();
750 bool writeOk =
false;
754 const QStringList dirs = directory.split(
'/', QString::SkipEmptyParts);
755 QStringList::ConstIterator it = dirs.begin();
757 for (; it != dirs.end(); ++it) {
765 }
else if (!writeOk) {
767 "create that folder."));
768 }
else if (enterDirectory) {
777 bool ask,
bool showProgress)
779 if (items.isEmpty()) {
781 i18n(
"You did not select a file to delete."),
782 i18n(
"Nothing to Delete"));
801 if (items.count() == 1) {
803 i18n(
"<qt>Do you really want to delete\n <b>'%1'</b>?</qt>" ,
810 i18np(
"Do you really want to delete this item?",
"Do you really want to delete these %1 items?", items.count()),
812 i18n(
"Delete Files"),
821 job->ui()->setWindow(
this);
822 job->ui()->setAutoErrorHandlingEnabled(
true);
832 if (!list.isEmpty()) {
839 bool ask,
bool showProgress)
841 if (items.isEmpty()) {
843 i18n(
"You did not select a file to trash."),
844 i18n(
"Nothing to Trash"));
859 if (items.count() == 1) {
861 i18n(
"<qt>Do you really want to trash\n <b>'%1'</b>?</qt>" ,
868 i18np(
"translators: not called for n == 1",
"Do you really want to trash these %1 items?", items.count()),
879 job->ui()->setWindow(
this);
880 job->ui()->setAutoErrorHandlingEnabled(
true);
889 return d->previewGenerator;
894 d->inlinePreviewState = show ? Private::ForcedToTrue : Private::ForcedToFalse;
899 return d->showPreviews;
919 if (d->itemView == 0) {
923 if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
929 if (!list.isEmpty()) {
936 if (d->iconsZoom == _value) {
941 value = qMin(100, value);
942 value = qMax(0, value);
944 d->iconsZoom = value;
946 if (!d->previewGenerator) {
951 const int val = (maxSize * value / 100) + KIconLoader::SizeSmall;
952 d->itemView->setIconSize(
QSize(val, val));
953 d->updateListViewGrid();
954 d->previewGenerator->updatePreviews();
962 d->pendingMimeTypes.clear();
963 d->completion.clear();
964 d->dirCompletion.clear();
965 d->completeListDirty =
true;
966 d->dirLister->stop();
969 void KDirOperator::Private::checkPath(
const QString &,
bool )
976 text = text.trimmed();
979 if (text.find(
':') < 0 && text[0] !=
'/')
980 text.insert(0, d->currUrl);
984 if (!selection.isNull()) {
985 int position = text.lastIndexOf(
'/');
986 ASSERT(position >= 0);
987 QString filename = text.mid(position + 1, text.length());
988 if (filename != selection)
993 bool filenameEntered =
false;
995 if (u.isLocalFile()) {
1002 if (acceptOnlyExisting && !i.isFile())
1003 warning(
"you entered an invalid URL");
1005 filenameEntered =
true;
1010 if (filenameEntered) {
1011 filename_ = u.url();
1012 emit fileSelected(filename_);
1014 QApplication::restoreOverrideCursor();
1019 kDebug(kfile_area) <<
"TODO KDirOperator::checkPath()";
1026 if (!_newurl.isValid())
1027 newurl = QUrl::fromLocalFile(QDir::homePath());
1037 if (!Private::isReadable(newurl)) {
1045 if ((!res || !Private::isReadable(newurl)) && i.
isDir()) {
1048 i18n(
"The specified folder does not exist "
1049 "or was not readable."));
1051 }
else if (!i.
isDir()) {
1058 d->backStack.push(
new KUrl(d->currUrl));
1059 qDeleteAll(d->forwardStack);
1060 d->forwardStack.clear();
1064 d->currUrl = newurl;
1070 QAction* forwardAction = d->actionCollection->action(
"forward");
1071 forwardAction->setEnabled(!d->forwardStack.isEmpty());
1073 QAction* backAction = d->actionCollection->action(
"back");
1074 backAction->setEnabled(!d->backStack.isEmpty());
1076 QAction* upAction = d->actionCollection->action(
"up");
1077 upAction->setEnabled(!
isRoot());
1084 QApplication::setOverrideCursor(Qt::WaitCursor);
1085 d->dirLister->emitChanges();
1086 QApplication::restoreOverrideCursor();
1096 bool KDirOperator::Private::openUrl(
const KUrl& url, KDirLister::OpenUrlFlags flags)
1105 int KDirOperator::Private::sortColumn()
const
1121 Qt::SortOrder KDirOperator::Private::sortOrder()
const
1123 return (sorting & QDir::Reversed) ? Qt::DescendingOrder :
1127 void KDirOperator::Private::updateSorting(QDir::SortFlags sort)
1129 kDebug(kfile_area) <<
"changing sort flags from" << sorting <<
"to" << sort;
1130 if (sort == sorting) {
1134 if ((sorting ^ sort) & QDir::DirsFirst) {
1140 Qt::SortOrder tmpSortOrder = (sortOrder() == Qt::AscendingOrder ? Qt::DescendingOrder : Qt::AscendingOrder);
1141 proxyModel->sort(sortOrder(), tmpSortOrder);
1142 proxyModel->setSortFoldersFirst(sort & QDir::DirsFirst);
1146 parent->updateSortActions();
1147 proxyModel->sort(sortColumn(), sortOrder());
1156 if (treeView != 0) {
1157 QHeaderView* headerView = treeView->header();
1158 headerView->blockSignals(
true);
1159 headerView->setSortIndicator(sortColumn(), sortOrder());
1160 headerView->blockSignals(
false);
1163 _k_assureVisibleSelection();
1169 if (d->itemView == 0)
1172 d->pendingMimeTypes.clear();
1174 d->completion.clear();
1175 d->dirCompletion.clear();
1178 QApplication::restoreOverrideCursor();
1181 QApplication::setOverrideCursor(Qt::WaitCursor);
1183 if (!Private::isReadable(d->currUrl)) {
1185 i18n(
"The specified folder does not exist "
1186 "or was not readable."));
1187 if (d->backStack.isEmpty())
1194 void KDirOperator::Private::_k_slotRedirected(
const KUrl& newURL)
1197 pendingMimeTypes.clear();
1199 dirCompletion.clear();
1200 completeListDirty =
true;
1201 emit parent->urlEntered(newURL);
1207 if (d->backStack.isEmpty())
1210 d->forwardStack.push(
new KUrl(d->currUrl));
1212 KUrl *s = d->backStack.pop();
1221 if (d->forwardStack.isEmpty())
1224 d->backStack.push(
new KUrl(d->currUrl));
1226 KUrl *s = d->forwardStack.pop();
1238 KUrl tmp(d->currUrl);
1239 tmp.
cd(QLatin1String(
".."));
1245 KUrl u = QUrl::fromLocalFile(QDir::homePath());
1251 d->dirLister->setNameFilter(
QString());
1252 d->dirLister->clearMimeFilter();
1258 d->dirLister->setNameFilter(filter);
1264 return d->dirLister->nameFilter();
1269 d->dirLister->setMimeFilter(mimetypes);
1275 return d->dirLister->mimeFilters();
1280 d->newFileMenu->setSupportedMimeTypes(mimeTypes);
1285 return d->newFileMenu->supportedMimeTypes();
1292 bool hasPreviewSupport =
false;
1294 if (cg.
readEntry(
"Show Default Preview",
true))
1295 hasPreviewSupport = d->checkPreviewInternal();
1297 previewAction->setEnabled(hasPreviewSupport);
1298 return hasPreviewSupport;
1306 d->newFileMenu->setPopupFiles(
url());
1308 d->newFileMenu->checkUpToDate();
1312 d->actionMenu->menu()->exec(pos);
1317 QWidget::changeEvent(event);
1326 switch(event->type()) {
1327 case QEvent::MouseMove: {
1328 if (d->preview && !d->preview->isHidden()) {
1329 const QModelIndex hoveredIndex = d->itemView->indexAt(d->itemView->viewport()->mapFromGlobal(QCursor::pos()));
1331 if (d->lastHoveredIndex == hoveredIndex)
1332 return QWidget::eventFilter(watched, event);
1334 d->lastHoveredIndex = hoveredIndex;
1336 const QModelIndex focusedIndex = d->itemView->selectionModel() ? d->itemView->selectionModel()->currentIndex()
1339 if (!hoveredIndex.isValid() && focusedIndex.isValid() &&
1340 d->itemView->selectionModel()->isSelected(focusedIndex) &&
1341 (d->lastHoveredIndex != focusedIndex)) {
1342 const QModelIndex sourceFocusedIndex = d->proxyModel->mapToSource(focusedIndex);
1343 const KFileItem item = d->dirModel->itemForIndex(sourceFocusedIndex);
1345 d->preview->showPreview(item.
url());
1351 case QEvent::MouseButtonRelease: {
1352 if (d->preview != 0 && !d->preview->isHidden()) {
1353 const QModelIndex hoveredIndex = d->itemView->indexAt(d->itemView->viewport()->mapFromGlobal(QCursor::pos()));
1354 const QModelIndex focusedIndex = d->itemView->selectionModel() ? d->itemView->selectionModel()->currentIndex()
1357 if (((!focusedIndex.isValid()) ||
1358 !d->itemView->selectionModel()->isSelected(focusedIndex)) &&
1359 (!hoveredIndex.isValid())) {
1360 d->preview->clearPreview();
1365 case QEvent::Wheel: {
1366 QWheelEvent *evt =
static_cast<QWheelEvent*
>(event);
1367 if (evt->modifiers() & Qt::ControlModifier) {
1368 if (evt->delta() > 0) {
1381 return QWidget::eventFilter(watched, event);
1384 bool KDirOperator::Private::checkPreviewInternal()
const
1388 if (parent->dirOnlyMode() && supported.indexOf(
"inode/directory") == -1)
1392 const QStringList nameFilter = dirLister->nameFilter().split(
' ', QString::SkipEmptyParts);
1394 if (mimeTypes.isEmpty() && nameFilter.isEmpty() && !supported.isEmpty())
1398 r.setPatternSyntax(QRegExp::Wildcard);
1400 if (!mimeTypes.isEmpty()) {
1401 QStringList::ConstIterator it = supported.begin();
1403 for (; it != supported.end(); ++it) {
1407 if (!result.isEmpty()) {
1413 if (!nameFilter.isEmpty()) {
1415 QStringList::const_iterator it1 = nameFilter.begin();
1416 for (; it1 != nameFilter.end(); ++it1) {
1417 if ((*it1) ==
"*") {
1421 KMimeType::Ptr mt = KMimeType::findByPath(*it1, 0,
true );
1428 QStringList::ConstIterator it2 = supported.begin();
1429 for (; it2 != supported.end(); ++it2) {
1431 if (r.indexIn(mime) != -1) {
1444 QAbstractItemView *itemView = 0;
1448 itemView = detailView;
1450 itemView =
new KDirOperatorIconView(
this, parent);
1461 QWidget::setAcceptDrops(b);
1466 d->dropOptions = options;
1489 && d->actionCollection->action(
"preview")->isEnabled();
1492 d->viewKind =
static_cast<int>(viewKind);
1495 QAbstractItemView *newView =
createView(
this, viewKind);
1498 d->_k_togglePreview(preview);
1513 if (d->mode == mode)
1521 if (d->itemView != 0)
1522 setView(static_cast<KFile::FileView>(d->viewKind));
1527 if (view == d->itemView) {
1532 d->pendingMimeTypes.clear();
1533 const bool listDir = (d->itemView == 0);
1536 view->setSelectionMode(QAbstractItemView::ExtendedSelection);
1538 view->setSelectionMode(QAbstractItemView::SingleSelection);
1542 if ((d->itemView != 0) && d->itemView->selectionModel()->hasSelection()) {
1545 const QItemSelection selection = d->itemView->selectionModel()->selection();
1547 selectionModel->select(selection, QItemSelectionModel::Select);
1553 d->itemView->setModel(d->proxyModel);
1554 setFocusProxy(d->itemView);
1556 view->viewport()->installEventFilter(
this);
1559 d->itemView->setItemDelegate(delegate);
1560 d->itemView->viewport()->setAttribute(Qt::WA_Hover);
1561 d->itemView->setContextMenuPolicy(Qt::CustomContextMenu);
1562 d->itemView->setMouseTracking(
true);
1568 QHeaderView* headerView = treeView->header();
1569 headerView->setSortIndicator(d->sortColumn(), d->sortOrder());
1570 connect(headerView, SIGNAL(sortIndicatorChanged(
int,Qt::SortOrder)),
1571 this, SLOT(_k_synchronizeSortingState(
int,Qt::SortOrder)));
1574 connect(d->itemView, SIGNAL(activated(QModelIndex)),
1575 this, SLOT(_k_slotActivated(QModelIndex)));
1576 connect(d->itemView, SIGNAL(customContextMenuRequested(
QPoint)),
1577 this, SLOT(_k_openContextMenu(
QPoint)));
1578 connect(d->itemView, SIGNAL(entered(QModelIndex)),
1579 this, SLOT(_k_triggerPreview(QModelIndex)));
1582 d->splitter->insertWidget(0, d->itemView);
1584 d->splitter->resize(size());
1585 d->itemView->show();
1588 QApplication::setOverrideCursor(Qt::WaitCursor);
1589 d->openUrl(d->currUrl);
1592 if (selectionModel != 0) {
1593 d->itemView->setSelectionModel(selectionModel);
1594 QMetaObject::invokeMethod(
this,
"_k_assureVisibleSelection", Qt::QueuedConnection);
1597 connect(d->itemView->selectionModel(),
1598 SIGNAL(currentChanged(QModelIndex,QModelIndex)),
1599 this, SLOT(_k_triggerPreview(QModelIndex)));
1600 connect(d->itemView->selectionModel(),
1601 SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
1602 this, SLOT(_k_slotSelectionChanged()));
1606 d->decorationMenu->setEnabled(qobject_cast<QListView*>(d->itemView));
1609 if (d->shouldFetchForItems) {
1610 connect(d->dirModel, SIGNAL(expand(QModelIndex)),
this, SLOT(_k_slotExpandToUrl(QModelIndex)));
1612 d->itemsToBeSetAsCurrent.clear();
1615 const bool previewForcedToTrue = d->inlinePreviewState == Private::ForcedToTrue;
1616 const bool previewShown = d->inlinePreviewState == Private::NotForced ? d->showPreviews : previewForcedToTrue;
1619 const int val = (maxSize * d->iconsZoom / 100) + KIconLoader::SizeSmall;
1621 d->previewGenerator->setPreviewShown(previewShown);
1622 d->actionCollection->action(
"inline preview")->setChecked(previewShown);
1625 d->_k_slotChangeDecorationPosition();
1629 const int zoom = previewForcedToTrue ? (
KIconLoader::SizeHuge - KIconLoader::SizeSmall + 1) * 100 / maxSize : d->iconSizeForViewType(view);
1637 if (lister == d->dirLister)
1643 delete d->proxyModel;
1647 d->dirLister = lister;
1650 d->dirModel->setDirLister(d->dirLister);
1653 d->shouldFetchForItems = qobject_cast<
QTreeView*>(d->itemView);
1654 if (d->shouldFetchForItems) {
1655 connect(d->dirModel, SIGNAL(expand(QModelIndex)),
this, SLOT(_k_slotExpandToUrl(QModelIndex)));
1657 d->itemsToBeSetAsCurrent.clear();
1661 d->proxyModel->setSourceModel(d->dirModel);
1663 d->dirLister->setAutoUpdate(
true);
1664 d->dirLister->setDelayedMimeTypes(
true);
1666 QWidget* mainWidget = topLevelWidget();
1667 d->dirLister->setMainWindow(mainWidget);
1670 connect(d->dirLister, SIGNAL(percent(
int)),
1671 SLOT(_k_slotProgress(
int)));
1672 connect(d->dirLister, SIGNAL(started(
KUrl)), SLOT(_k_slotStarted()));
1673 connect(d->dirLister, SIGNAL(completed()), SLOT(_k_slotIOFinished()));
1674 connect(d->dirLister, SIGNAL(canceled()), SLOT(_k_slotCanceled()));
1675 connect(d->dirLister, SIGNAL(redirection(
KUrl)),
1676 SLOT(_k_slotRedirected(
KUrl)));
1677 connect(d->dirLister, SIGNAL(newItems(
KFileItemList)), SLOT(_k_slotItemsChanged()));
1678 connect(d->dirLister, SIGNAL(itemsDeleted(
KFileItemList)), SLOT(_k_slotItemsChanged()));
1679 connect(d->dirLister, SIGNAL(itemsFilteredByMime(
KFileItemList)), SLOT(_k_slotItemsChanged()));
1680 connect(d->dirLister, SIGNAL(
clear()), SLOT(_k_slotItemsChanged()));
1690 QApplication::restoreOverrideCursor();
1697 if ((d->preview != 0 && !d->preview->isHidden()) && !item.
isNull()) {
1698 d->preview->showPreview(item.
url());
1708 KFileItem item = d->dirLister->findByUrl(url);
1709 if (d->shouldFetchForItems && item.
isNull()) {
1710 d->itemsToBeSetAsCurrent <<
url;
1711 d->dirModel->expandToUrl(url);
1730 const QModelIndex dirIndex = d->dirModel->indexForItem(item);
1731 const QModelIndex proxyIndex = d->proxyModel->mapFromSource(dirIndex);
1732 selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::Select);
1746 foreach (
const QString &url, urls) {
1747 KFileItem item = d->dirLister->findByUrl(url);
1748 if (d->shouldFetchForItems && item.
isNull()) {
1749 d->itemsToBeSetAsCurrent <<
url;
1750 d->dirModel->expandToUrl(url);
1763 if (d->itemView == 0) {
1770 QModelIndex proxyIndex;
1771 foreach (
const KFileItem &item, items) {
1773 const QModelIndex dirIndex = d->dirModel->indexForItem(item);
1774 proxyIndex = d->proxyModel->mapFromSource(dirIndex);
1775 selModel->select(proxyIndex, QItemSelectionModel::Select);
1778 if (proxyIndex.isValid()) {
1779 selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::NoUpdate);
1786 if (
string.isEmpty()) {
1787 d->itemView->selectionModel()->clear();
1792 return d->completion.makeCompletion(
string);
1797 if (
string.isEmpty()) {
1798 d->itemView->selectionModel()->clear();
1803 return d->dirCompletion.makeCompletion(
string);
1808 if (d->itemView == 0) {
1812 if (d->completeListDirty) {
1814 foreach (
const KFileItem &item, itemList) {
1815 d->completion.addItem(item.
name());
1817 d->dirCompletion.addItem(item.
name());
1820 d->completeListDirty =
false;
1833 d->actionCollection->setObjectName(
"KDirOperator::actionCollection");
1836 d->actionCollection->addAction(
"popupMenu", d->actionMenu);
1839 upAction->setText(
i18n(
"Parent Folder"));
1846 homeAction->setText(
i18n(
"Home Folder"));
1849 reloadAction->setText(
i18n(
"Reload"));
1853 d->actionCollection->addAction(
"mkdir", mkdirAction);
1854 mkdirAction->setIcon(
KIcon(QLatin1String(
"folder-new")));
1855 connect(mkdirAction, SIGNAL(triggered(
bool)),
this, SLOT(
mkdir()));
1858 d->actionCollection->addAction(
"trash", trash);
1859 trash->setIcon(
KIcon(
"user-trash"));
1861 connect(trash, SIGNAL(triggered(
bool)), SLOT(
trashSelected()));
1864 d->actionCollection->addAction(
"delete", action);
1865 action->setIcon(
KIcon(
"edit-delete"));
1867 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(
deleteSelected()));
1871 d->actionCollection->addAction(
"sorting menu", sortMenu);
1874 d->actionCollection->addAction(
"by name", byNameAction);
1875 connect(byNameAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotSortByName()));
1878 d->actionCollection->addAction(
"by size", bySizeAction);
1879 connect(bySizeAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotSortBySize()));
1882 d->actionCollection->addAction(
"by date", byDateAction);
1883 connect(byDateAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotSortByDate()));
1886 d->actionCollection->addAction(
"by type", byTypeAction);
1887 connect(byTypeAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotSortByType()));
1890 d->actionCollection->addAction(
"descending", descendingAction);
1891 connect(descendingAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotSortReversed(
bool)));
1894 d->actionCollection->addAction(
"dirs first", dirsFirstAction);
1895 connect(dirsFirstAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotToggleDirsFirst()));
1897 QActionGroup* sortGroup =
new QActionGroup(
this);
1898 byNameAction->setActionGroup(sortGroup);
1899 bySizeAction->setActionGroup(sortGroup);
1900 byDateAction->setActionGroup(sortGroup);
1901 byTypeAction->setActionGroup(sortGroup);
1904 d->actionCollection->addAction(
"decoration menu", d->decorationMenu);
1907 d->actionCollection->addAction(
"decorationAtLeft", d->leftAction);
1908 connect(d->leftAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotChangeDecorationPosition()));
1911 d->actionCollection->addAction(
"decorationAtTop", topAction);
1912 connect(topAction, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotChangeDecorationPosition()));
1914 d->decorationMenu->addAction(d->leftAction);
1915 d->decorationMenu->addAction(topAction);
1917 QActionGroup* decorationGroup =
new QActionGroup(
this);
1918 d->leftAction->setActionGroup(decorationGroup);
1919 topAction->setActionGroup(decorationGroup);
1922 d->actionCollection->addAction(
"short view", shortAction);
1923 shortAction->setIcon(
KIcon(QLatin1String(
"view-list-icons")));
1924 connect(shortAction, SIGNAL(triggered()), SLOT(_k_slotSimpleView()));
1927 d->actionCollection->addAction(
"detailed view", detailedAction);
1928 detailedAction->setIcon(
KIcon(QLatin1String(
"view-list-details")));
1929 connect(detailedAction, SIGNAL(triggered()), SLOT(_k_slotDetailedView()));
1932 d->actionCollection->addAction(
"tree view", treeAction);
1933 treeAction->setIcon(
KIcon(QLatin1String(
"view-list-tree")));
1934 connect(treeAction, SIGNAL(triggered()), SLOT(_k_slotTreeView()));
1937 d->actionCollection->addAction(
"detailed tree view", detailedTreeAction);
1938 detailedTreeAction->setIcon(
KIcon(QLatin1String(
"view-list-tree")));
1939 connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView()));
1941 QActionGroup* viewGroup =
new QActionGroup(
this);
1942 shortAction->setActionGroup(viewGroup);
1943 detailedAction->setActionGroup(viewGroup);
1944 treeAction->setActionGroup(viewGroup);
1945 detailedTreeAction->setActionGroup(viewGroup);
1948 d->actionCollection->addAction(
"show hidden", showHiddenAction);
1949 connect(showHiddenAction, SIGNAL(toggled(
bool)), SLOT(_k_slotToggleHidden(
bool)));
1952 d->actionCollection->addAction(
"preview", previewAction);
1953 connect(previewAction, SIGNAL(toggled(
bool)),
1954 SLOT(_k_togglePreview(
bool)));
1957 i18n(
"Show Preview"),
this);
1958 d->actionCollection->addAction(
"inline preview", inlinePreview);
1959 connect(inlinePreview, SIGNAL(toggled(
bool)), SLOT(_k_toggleInlinePreviews(
bool)));
1962 d->actionCollection->addAction(
"file manager", fileManager);
1963 fileManager->setIcon(
KIcon(QLatin1String(
"system-file-manager")));
1964 connect(fileManager, SIGNAL(triggered()), SLOT(_k_slotOpenFileManager()));
1967 d->actionCollection->addAction(
"properties", action);
1968 action->setIcon(
KIcon(
"document-properties"));
1970 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(_k_slotProperties()));
1974 d->actionCollection->addAction(
"view menu", viewMenu);
1979 viewMenu->
addAction(detailedTreeAction);
1983 d->newFileMenu =
new KNewFileMenu(d->actionCollection,
"new",
this);
1984 connect(d->newFileMenu, SIGNAL(directoryCreated(
KUrl)),
this, SLOT(_k_slotDirectoryCreated(
KUrl)));
1986 d->actionCollection->addAssociatedWidget(
this);
1987 foreach (
QAction* action, d->actionCollection->actions())
1988 action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
2000 sortMenu->
menu()->clear();
2001 sortMenu->
addAction(d->actionCollection->action(
"by name"));
2002 sortMenu->
addAction(d->actionCollection->action(
"by size"));
2003 sortMenu->
addAction(d->actionCollection->action(
"by date"));
2004 sortMenu->
addAction(d->actionCollection->action(
"by type"));
2006 sortMenu->
addAction(d->actionCollection->action(
"descending"));
2007 sortMenu->
addAction(d->actionCollection->action(
"dirs first"));
2010 d->actionMenu->menu()->clear();
2012 d->actionMenu->addAction(d->actionCollection->action(
"up"));
2013 d->actionMenu->addAction(d->actionCollection->action(
"back"));
2014 d->actionMenu->addAction(d->actionCollection->action(
"forward"));
2015 d->actionMenu->addAction(d->actionCollection->action(
"home"));
2016 d->actionMenu->addSeparator();
2020 d->actionMenu->addAction(d->actionCollection->action(
"new"));
2021 if (d->currUrl.isLocalFile() && !(QApplication::keyboardModifiers() & Qt::ShiftModifier)) {
2022 d->actionMenu->addAction(d->actionCollection->action(
"trash"));
2025 const bool del = !d->currUrl.isLocalFile() ||
2026 (QApplication::keyboardModifiers() & Qt::ShiftModifier) ||
2027 cg.
readEntry(
"ShowDeleteCommand",
false);
2029 d->actionMenu->addAction(d->actionCollection->action(
"delete"));
2031 d->actionMenu->addSeparator();
2035 d->actionMenu->addAction(sortMenu);
2037 d->actionMenu->addSeparator();
2042 d->actionMenu->addAction(d->actionCollection->action(
"view menu"));
2043 d->actionMenu->addSeparator();
2046 if (whichActions & FileActions) {
2047 d->actionMenu->addAction(d->actionCollection->action(
"file manager"));
2048 d->actionMenu->addAction(d->actionCollection->action(
"properties"));
2055 d->actionCollection->action(
"by name")->setChecked(
true);
2057 d->actionCollection->action(
"by date")->setChecked(
true);
2059 d->actionCollection->action(
"by size")->setChecked(
true);
2061 d->actionCollection->action(
"by type")->setChecked(
true);
2063 d->actionCollection->action(
"descending")->setChecked(d->sorting & QDir::Reversed);
2064 d->actionCollection->action(
"dirs first")->setChecked(d->sorting & QDir::DirsFirst);
2085 if (viewStyle == QLatin1String(
"Detail")) {
2087 }
else if (viewStyle == QLatin1String(
"Tree")) {
2089 }
else if (viewStyle == QLatin1String(
"DetailTree")) {
2098 if (configGroup.
readEntry(QLatin1String(
"Show Preview"),
false)) {
2102 d->previewWidth = configGroup.
readEntry(QLatin1String(
"Preview Width"), 100);
2104 if (configGroup.
readEntry(QLatin1String(
"Show hidden files"),
2106 d->actionCollection->action(
"show hidden")->setChecked(
true);
2107 d->dirLister->setShowingDotFiles(
true);
2110 QDir::SortFlags
sorting = QDir::Name;
2111 if (configGroup.
readEntry(QLatin1String(
"Sort directories first"),
2113 sorting |= QDir::DirsFirst;
2117 if (sortBy == name) {
2118 sorting |= QDir::Name;
2119 }
else if (sortBy == QLatin1String(
"Size")) {
2120 sorting |= QDir::Size;
2121 }
else if (sortBy == QLatin1String(
"Date")) {
2122 sorting |= QDir::Time;
2123 }
else if (sortBy == QLatin1String(
"Type")) {
2124 sorting |= QDir::Type;
2127 sorting |= QDir::Reversed;
2129 d->updateSorting(sorting);
2131 if (d->inlinePreviewState == Private::NotForced) {
2132 d->showPreviews = configGroup.
readEntry(QLatin1String(
"Previews"),
false);
2140 QString sortBy = QLatin1String(
"Name");
2142 sortBy = QLatin1String(
"Size");
2144 sortBy = QLatin1String(
"Date");
2146 sortBy = QLatin1String(
"Type");
2149 configGroup.
writeEntry(QLatin1String(
"Sort by"), sortBy);
2151 configGroup.
writeEntry(QLatin1String(
"Sort reversed"),
2152 d->actionCollection->action(
"descending")->isChecked());
2154 configGroup.
writeEntry(QLatin1String(
"Sort directories first"),
2155 d->actionCollection->action(
"dirs first")->isChecked());
2158 bool appSpecificPreview =
false;
2161 appSpecificPreview = (tmp == 0);
2164 if (!appSpecificPreview) {
2166 if (previewAction->isEnabled()) {
2167 bool hasPreview = previewAction->isChecked();
2168 configGroup.
writeEntry(QLatin1String(
"Show Preview"), hasPreview);
2173 Q_ASSERT(sizes.count() == 2);
2174 configGroup.
writeEntry(QLatin1String(
"Preview Width"), sizes[1]);
2179 configGroup.
writeEntry(QLatin1String(
"Show hidden files"),
2180 d->actionCollection->action(
"show hidden")->isChecked());
2185 style = QLatin1String(
"Detail");
2187 style = QLatin1String(
"Simple");
2189 style = QLatin1String(
"Tree");
2191 style = QLatin1String(
"DetailTree");
2192 configGroup.
writeEntry(QLatin1String(
"View Style"), style);
2194 if (d->inlinePreviewState == Private::NotForced) {
2195 configGroup.
writeEntry(QLatin1String(
"Previews"), d->showPreviews);
2196 if (qobject_cast<QListView*>(d->itemView)) {
2197 configGroup.
writeEntry(QLatin1String(
"listViewIconSize"), d->iconsZoom);
2199 configGroup.
writeEntry(QLatin1String(
"detailedViewIconSize"), d->iconsZoom);
2203 configGroup.
writeEntry(QLatin1String(
"Decoration position"), (
int) d->decorationPosition);
2211 const bool hasPreview = (sizes.count() == 2);
2213 d->splitter->resize(size());
2214 sizes = d->splitter->sizes();
2216 const bool restorePreviewWidth = hasPreview && (d->previewWidth != sizes[1]);
2217 if (restorePreviewWidth) {
2218 const int availableWidth = sizes[0] + sizes[1];
2219 sizes[0] = availableWidth - d->previewWidth;
2220 sizes[1] = d->previewWidth;
2221 d->splitter->setSizes(sizes);
2224 d->previewWidth = sizes[1];
2227 if (d->progressBar->parent() ==
this) {
2229 d->progressBar->move(2, height() - d->progressBar->height() - 2);
2235 d->onlyDoubleClickSelectsFiles = enable;
2244 return d->onlyDoubleClickSelectsFiles;
2247 void KDirOperator::Private::_k_slotStarted()
2249 progressBar->setValue(0);
2251 progressDelayTimer->setSingleShot(
true);
2252 progressDelayTimer->start(1000);
2255 void KDirOperator::Private::_k_slotShowProgress()
2257 progressBar->raise();
2258 progressBar->show();
2259 QApplication::flush();
2262 void KDirOperator::Private::_k_slotProgress(
int percent)
2264 progressBar->setValue(percent);
2266 if (progressBar->isVisible())
2267 QApplication::flush();
2271 void KDirOperator::Private::_k_slotIOFinished()
2273 progressDelayTimer->stop();
2274 _k_slotProgress(100);
2275 progressBar->hide();
2276 emit parent->finishedLoading();
2277 parent->resetCursor();
2280 preview->clearPreview();
2284 void KDirOperator::Private::_k_slotCanceled()
2286 emit parent->finishedLoading();
2287 parent->resetCursor();
2292 return d->progressBar;
2297 qDeleteAll(d->backStack);
2298 d->backStack.clear();
2299 d->actionCollection->action(
"back")->setEnabled(
false);
2301 qDeleteAll(d->forwardStack);
2302 d->forwardStack.clear();
2303 d->actionCollection->action(
"forward")->setEnabled(
false);
2308 d->dirHighlighting = enable;
2313 return d->dirHighlighting;
2327 void KDirOperator::Private::_k_slotProperties()
2329 if (itemView == 0) {
2334 if (!list.isEmpty()) {
2340 void KDirOperator::Private::_k_slotActivated(
const QModelIndex& index)
2342 const QModelIndex dirIndex = proxyModel->mapToSource(index);
2343 KFileItem item = dirModel->itemForIndex(dirIndex);
2345 const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
2346 if (item.
isNull() || (modifiers & Qt::ShiftModifier) || (modifiers & Qt::ControlModifier))
2350 parent->selectDir(item);
2352 parent->selectFile(item);
2356 void KDirOperator::Private::_k_slotSelectionChanged()
2358 if (itemView == 0) {
2365 const bool multiSelectionMode = (itemView->selectionMode() == QAbstractItemView::ExtendedSelection);
2366 const bool hasSelection = itemView->selectionModel()->hasSelection();
2367 if (multiSelectionMode || !hasSelection) {
2369 parent->highlightFile(nullItem);
2372 KFileItem selectedItem = parent->selectedItems().first();
2373 parent->highlightFile(selectedItem);
2377 void KDirOperator::Private::_k_openContextMenu(
const QPoint& pos)
2379 const QModelIndex proxyIndex = itemView->indexAt(pos);
2380 const QModelIndex dirIndex = proxyModel->mapToSource(proxyIndex);
2381 KFileItem item = dirModel->itemForIndex(dirIndex);
2386 parent->activatedMenu(item, QCursor::pos());
2389 void KDirOperator::Private::_k_triggerPreview(
const QModelIndex& index)
2391 if ((preview != 0 && !preview->isHidden()) && index.isValid() && (index.column() ==
KDirModel::Name)) {
2392 const QModelIndex dirIndex = proxyModel->mapToSource(index);
2393 const KFileItem item = dirModel->itemForIndex(dirIndex);
2398 if (!item.
isDir()) {
2399 previewUrl = item.
url();
2402 preview->clearPreview();
2407 void KDirOperator::Private::_k_showPreview()
2410 preview->showPreview(previewUrl);
2414 void KDirOperator::Private::_k_slotSplitterMoved(
int,
int)
2417 if (sizes.count() == 2) {
2419 previewWidth = sizes[1];
2423 void KDirOperator::Private::_k_assureVisibleSelection()
2425 if (itemView == 0) {
2430 if (selModel->hasSelection()) {
2431 const QModelIndex index = selModel->currentIndex();
2432 itemView->scrollTo(index, QAbstractItemView::EnsureVisible);
2433 _k_triggerPreview(index);
2438 void KDirOperator::Private::_k_synchronizeSortingState(
int logicalIndex, Qt::SortOrder order)
2440 QDir::SortFlags newSort = sorting & ~(
QDirSortMask | QDir::Reversed);
2442 switch (logicalIndex) {
2444 newSort |= QDir::Name;
2447 newSort |= QDir::Size;
2450 newSort |= QDir::Time;
2453 newSort |= QDir::Type;
2459 if (order == Qt::DescendingOrder) {
2460 newSort |= QDir::Reversed;
2463 updateSorting(newSort);
2465 QMetaObject::invokeMethod(parent,
"_k_assureVisibleSelection", Qt::QueuedConnection);
2468 void KDirOperator::Private::_k_slotChangeDecorationPosition()
2480 const bool leftChecked = actionCollection->action(
"decorationAtLeft")->isChecked();
2484 view->setFlow(QListView::TopToBottom);
2487 view->setFlow(QListView::LeftToRight);
2490 updateListViewGrid();
2495 void KDirOperator::Private::_k_slotExpandToUrl(
const QModelIndex &index)
2503 const KFileItem item = dirModel->itemForIndex(index);
2509 if (!item.
isDir()) {
2510 const QModelIndex proxyIndex = proxyModel->mapFromSource(index);
2512 KUrl::List::Iterator it = itemsToBeSetAsCurrent.begin();
2513 while (it != itemsToBeSetAsCurrent.end()) {
2514 const KUrl url = *it;
2516 const KFileItem _item = dirLister->findByUrl(url);
2518 const QModelIndex _index = dirModel->indexForItem(_item);
2519 const QModelIndex _proxyIndex = proxyModel->mapFromSource(_index);
2520 treeView->expand(_proxyIndex);
2524 treeView->selectionModel()->select(proxyIndex, QItemSelectionModel::Select);
2527 it = itemsToBeSetAsCurrent.erase(it);
2532 }
else if (!itemsToBeSetAsCurrent.contains(item.
url())) {
2533 itemsToBeSetAsCurrent << item.
url();
2537 void KDirOperator::Private::_k_slotItemsChanged()
2539 completeListDirty =
true;
2542 void KDirOperator::Private::updateListViewGrid()
2554 const bool leftChecked = actionCollection->action(
"decorationAtLeft")->isChecked();
2557 view->setGridSize(
QSize());
2563 const QFontMetrics metrics(itemView->viewport()->font());
2564 int size = itemView->iconSize().height() + metrics.height() * 2;
2566 view->setGridSize(
QSize(size * (3.0 / 2.0), size + metrics.height()));
2574 int KDirOperator::Private::iconSizeForViewType(QAbstractItemView *itemView)
const
2576 if (!itemView || !configGroup) {
2580 if (qobject_cast<QListView*>(itemView)) {
2581 return configGroup->readEntry(
"listViewIconSize", 0);
2583 return configGroup->readEntry(
"detailedViewIconSize", 0);
2589 delete d->configGroup;
2595 return d->configGroup;
2600 d->actionCollection->action(
"show hidden")->setChecked(s);
2605 return d->actionCollection->action(
"show hidden")->isChecked();
2610 return d->decorationPosition;
2615 d->decorationPosition = position;
2617 d->actionCollection->action(
"decorationAtLeft")->setChecked(decorationAtLeft);
2618 d->actionCollection->action(
"decorationAtTop")->setChecked(!decorationAtLeft);
2623 bool KDirOperator::Private::isReadable(
const KUrl& url)
2628 KDE_struct_stat buf;
2634 bool readable = (
KDE::stat(ts, &buf) == 0);
2637 test = opendir(QFile::encodeName(ts));
2638 readable = (test != 0);
2645 void KDirOperator::Private::_k_slotDirectoryCreated(
const KUrl& url)
2647 parent->setUrl(url,
true);
2650 #include "kdiroperator.moc"
bool onlyDoubleClickSelectsFiles() const
static bool stat(const KUrl &url, KIO::UDSEntry &entry, QWidget *window)
bool isSelected(const KFileItem &item) const
QString i18n(const char *text)
KDirLister * dirLister() const
void adjustPath(AdjustPathOption trailing)
KConfigGroup * viewConfigGroup() const
static bool isSortByName(const QDir::SortFlags &sort)
void setupMenu()
Sets up the context-menu with all the necessary actions.
static bool isSortByDate(const QDir::SortFlags &sort)
void setShortcuts(const QList< QKeySequence > &shortcuts, ShortcutTypes type=ShortcutTypes(ActiveShortcut|DefaultShortcut))
QString directory(const DirectoryOptions &options=IgnoreTrailingSlash) const
void viewChanged(QAbstractItemView *newView)
Emitted whenever the current fileview is changed, either by an explicit call to setView() or by the u...
static bool isDetailTreeView(const FileView &view)
KFileItemList selectedItems() const
void close()
Stops loading immediately.
KActionCollection * actionCollection() const
an accessor to a collection of all available Actions.
virtual void writeConfig(KConfigGroup &configGroup)
Saves the current settings like sorting, simple or detailed view.
virtual void changeEvent(QEvent *event)
void setOnlyDoubleClickSelectsFiles(bool enable)
This toggles between double/single click file and directory selection mode.
Generates previews for files of an item view.
QDir::SortFlags sorting() const
virtual void keyPressEvent(QKeyEvent *event)
void setCurrentItems(const QStringList &urls)
Clears the current selection and attempts to set urls the current url files.
void setMaximumSize(const QSize &size)
KCompletion * dirCompletionObject() const
virtual void forward()
Goes one step forward in the history and opens that url.
void sortBySize()
Changes sorting to sort by size.
QString i18np(const char *sing, const char *plur, const A1 &a1)
Default detail view for KDirOperator using custom resizing options and columns.
const KShortcut & shortcut(StandardShortcut id)
Acts as proxy model for KDirModel to sort and filter KFileItems.
static void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
static bool isSortBySize(const QDir::SortFlags &sort)
virtual void setPreviewWidget(KPreviewWidgetBase *w)
Sets a preview-widget to be shown next to the file-view.
int stat(const QString &path, KDE_struct_stat *buf)
const char * name(StandardAction id)
void currentIconSizeChanged(int size)
Will notify that the icon size has changed.
QString makeCompletion(const QString &)
Tries to complete the given string (only completes files).
void sortByName()
Changes sorting to sort by name.
bool cd(const QString &_dir)
void updateSortActions()
Updates the sorting-related actions to comply with the current sorting.
QString makeDirCompletion(const QString &)
Tries to complete the given string (only completes directores).
virtual void setAcceptDrops(bool b)
Reimplemented - allow dropping of files if b is true.
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
QString toLocalFile(AdjustPathOption trailing=LeaveTrailingSlash) const
void completion(const QString &)
static bool mkdir(const KUrl &url, QWidget *window, int permissions=-1)
void fileHighlighted(const KFileItem &item)
Emitted when a file is highlighted or generally the selection changes in multiselection mode...
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
bool isParentOf(const KUrl &u) const
void updateSelectionDependentActions()
Enables/disables actions that are selection dependent.
virtual void setUrl(const KUrl &url, bool clearforward)
Sets a new url to list.
bool checkPreviewSupport()
Checks if there support from KIO::PreviewJob for the currently shown files, taking mimeFilter() and n...
static bool isPreviewInfo(const FileView &view)
virtual ~KDirOperator()
Destroys the KDirOperator.
QString i18nc(const char *ctxt, const char *text)
virtual void setEnableDirHighlighting(bool enable)
When going up in the directory hierarchy, KDirOperator can highlight the directory that was just left...
KSharedConfigPtr config()
int iconsZoom() const
Returns the icon zoom.
void setPath(const QString &path)
ListJob * listDir(const KUrl &url, JobFlags flags=DefaultFlags, bool includeHidden=true)
bool showHiddenFiles() const
virtual void setDirLister(KDirLister *lister)
Sets a custom KDirLister to list directories.
void updateViewActions()
Updates the view-related actions to comply with the current KFile::FileView.
static bool isSimpleView(const FileView &view)
void addPath(const QString &txt)
virtual void trashSelected()
Trashes the currently selected files/directories.
static bool exists(const KUrl &url, bool source, QWidget *window)
void setSorting(QDir::SortFlags)
Sets the way to sort files and directories.
void toggleIgnoreCase()
Toggles case sensitive / case insensitive sorting.
void sortByType()
Changes sorting to sort by date.
bool dirHighlighting() const
virtual void cdUp()
Goes one directory up from the current url.
virtual void setView(QAbstractItemView *view)
Sets a new view to be used for showing and browsing files.
QAbstractItemView * view() const
This widget works as a network transparent filebrowser.
void prepareCompletionObjects()
Synchronizes the completion objects with the entries of the currently listed url. ...
void selectFile(const KFileItem &item)
Emits fileSelected( item )
void setupActions()
Sets up all the actions.
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
void fileSelected(const KFileItem &item)
QString pathOrUrl() const
KFile::Modes mode() const
virtual void setDropOptions(int options)
Sets the options for dropping files.
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
void urlEntered(const KUrl &)
static const int QDirSortMask
void updateDir()
to update the view after changing the settings
void setNewFileMenuSupportedMimeTypes(const QStringList &mime)
Only show the files in a given set of mimetypes.
void sortByDate()
Changes sorting to sort by date.
virtual KIO::DeleteJob * del(const KFileItemList &items, QWidget *parent=0, bool ask=true, bool showProgress=true)
Starts and returns a KIO::DeleteJob to delete the given items.
virtual void home()
Enters the home directory.
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
virtual void setMode(KFile::Modes m)
Sets the listing/selection mode for the views, an OR'ed combination of.
static bool isPreviewContents(const FileView &view)
QStringList mimeTypes(Mode mode=Writing)
void setCurrentItem(const QString &url)
Clears the current selection and attempts to set url the current url file.
void setIconsZoom(int value)
Notifies that the icons size should change.
QString nameFilter() const
void setShortcut(const KShortcut &shortcut, ShortcutTypes type=ShortcutTypes(ActiveShortcut|DefaultShortcut))
KFilePreviewGenerator * previewGenerator() const
Returns the preview generator for the current view.
virtual void mkdir()
Opens a dialog to create a new directory.
KCompletion * completionObject() const
virtual bool eventFilter(QObject *watched, QEvent *event)
virtual void setShowHiddenFiles(bool s)
Enables/disables showing hidden files.
bool isSaving() const
Returns whether KDirOperator will force a double click to accept.
KAction * zoom(const QObject *recvr, const char *slot, QObject *parent)
static bool isSortByType(const QDir::SortFlags &sort)
DeleteJob * del(const KUrl &src, JobFlags flags=DefaultFlags)
void setMimeFilter(const QStringList &mimetypes)
Sets a list of mimetypes as filter.
KDirOperator(const KUrl &urlName=KUrl(), QWidget *parent=0)
Constructs the KDirOperator with no initial view.
void slotCompletionMatch(const QString &match)
Tries to make the given match as current item in the view and emits completion( match ) ...
QStringList newFileMenuSupportedMimeTypes() const
QStringList mimeFilter() const
virtual KIO::CopyJob * trash(const KFileItemList &items, QWidget *parent, bool ask=true, bool showProgress=true)
Starts and returns a KIO::CopyJob to trash the given items.
static bool isDetailView(const FileView &view)
virtual void selectDir(const KFileItem &item)
Enters the directory specified by the given item.
void clearFilter()
Clears both the namefilter and mimetype filter, so that all files and directories will be shown...
void setIsSaving(bool isSaving)
If the system is set up to trigger items on single click, if isSaving is true, we will force to doubl...
void clearHistory()
Clears the forward and backward history.
void pathChanged()
Called after setUrl() to load the directory, update the history, etc.
void sortReversed()
Changes sorting to reverse sorting.
QString name(bool lowerCase=false) const
void resetCursor()
Restores the normal cursor after showing the busy-cursor.
virtual void back()
Goes one step back in the history and opens that url.
QProgressBar * progressBar() const
virtual bool setViewMode(KFile::FileView viewMode)
Displays either Detail, Tree or DetailTree modes.
static int warningContinueCancelList(QWidget *parent, const QString &text, const QStringList &strlist, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
virtual void readConfig(const KConfigGroup &configGroup)
Reads the default settings for a view, i.e.
void highlightFile(const KFileItem &item)
Emits fileHighlighted(item)
virtual QAbstractItemView * createView(QWidget *parent, KFile::FileView viewKind)
A view factory for creating predefined fileviews.
QStyleOptionViewItem::Position decorationPosition() const
Returns the position where icons are shown relative to the labels of file items in the icon view...
void contextMenuAboutToShow(const KFileItem &item, QMenu *menu)
Emitted just before the context menu is shown, allows users to extend the menu with custom actions...
virtual void deleteSelected()
Deletes the currently selected files/directories.
static bool supportsListing(const KUrl &url)
bool isInlinePreviewShown() const
Returns whether the inline previews are shown or not.
static QStringList supportedMimeTypes()
#define DefaultSortReversed
virtual void rereadDir()
Re-reads the current url.
void setDecorationPosition(QStyleOptionViewItem::Position position)
Sets the position where icons shall be shown relative to the labels of file items in the icon view...
T readEntry(const QString &key, const T &aDefault) const
bool equals(const KUrl &u, const EqualsOptions &options=0) const
void toggleDirsFirst()
Toggles showing directories first / having them sorted like files.
static bool isTreeView(const FileView &view)
const KShortcut & completion()
static int warningContinueCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
void setNameFilter(const QString &filter)
Sets a filter like "*.cpp *.h *.o".
CopyJob * trash(const KUrl &src, JobFlags flags=DefaultFlags)
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
virtual void resizeEvent(QResizeEvent *event)
#define DefaultShowHidden
void setInlinePreviewShown(bool show)
Forces the inline previews to be shown or hidden, depending on show.
virtual void setViewConfig(KConfigGroup &configGroup)
Sets the config object and the to be used group in KDirOperator.
virtual void activatedMenu(const KFileItem &item, const QPoint &pos)
Called upon right-click to activate the popupmenu.
QStringList list(const QString &fileClass)