]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.cpp
Fix compilation
[dolphin.git] / src / dolphinview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "dolphinview.h"
22
23 #include <assert.h>
24
25 #include <QDropEvent>
26 #include <QItemSelectionModel>
27 #include <QMouseEvent>
28 #include <QVBoxLayout>
29
30 #include <kdirmodel.h>
31 #include <kfileitemdelegate.h>
32 #include <klocale.h>
33 #include <kio/netaccess.h>
34 #include <kio/renamedialog.h>
35 #include <kmimetyperesolver.h>
36 #include <konq_operations.h>
37 #include <kurl.h>
38
39 #include "dolphinstatusbar.h"
40 #include "dolphinmainwindow.h"
41 #include "dolphindirlister.h"
42 #include "dolphinsortfilterproxymodel.h"
43 #include "dolphindetailsview.h"
44 #include "dolphiniconsview.h"
45 #include "dolphincontextmenu.h"
46 #include "filterbar.h"
47 #include "renamedialog.h"
48 #include "urlnavigator.h"
49 #include "viewproperties.h"
50
51 DolphinView::DolphinView(DolphinMainWindow* mainWindow,
52 QWidget* parent,
53 const KUrl& url,
54 Mode mode,
55 bool showHiddenFiles) :
56 QWidget(parent),
57 m_showProgress(false),
58 m_mode(mode),
59 m_iconSize(0),
60 m_folderCount(0),
61 m_fileCount(0),
62 m_mainWindow(mainWindow),
63 m_topLayout(0),
64 m_urlNavigator(0),
65 m_iconsView(0),
66 m_detailsView(0),
67 m_filterBar(0),
68 m_statusBar(0),
69 m_dirModel(0),
70 m_dirLister(0),
71 m_proxyModel(0)
72 {
73 hide();
74 setFocusPolicy(Qt::StrongFocus);
75 m_topLayout = new QVBoxLayout(this);
76 m_topLayout->setSpacing(0);
77 m_topLayout->setMargin(0);
78
79 m_urlNavigator = new UrlNavigator(url, this);
80 connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
81 this, SLOT(loadDirectory(const KUrl&)));
82
83 m_statusBar = new DolphinStatusBar(this);
84
85 m_dirLister = new DolphinDirLister();
86 m_dirLister->setAutoUpdate(true);
87 m_dirLister->setMainWindow(this);
88 m_dirLister->setShowingDotFiles(showHiddenFiles);
89 m_dirLister->setDelayedMimeTypes(true);
90
91 connect(m_dirLister, SIGNAL(clear()),
92 this, SLOT(updateStatusBar()));
93 connect(m_dirLister, SIGNAL(percent(int)),
94 this, SLOT(updateProgress(int)));
95 connect(m_dirLister, SIGNAL(deleteItem(KFileItem*)),
96 this, SLOT(updateStatusBar()));
97 connect(m_dirLister, SIGNAL(completed()),
98 this, SLOT(updateItemCount()));
99 connect(m_dirLister, SIGNAL(infoMessage(const QString&)),
100 this, SLOT(showInfoMessage(const QString&)));
101 connect(m_dirLister, SIGNAL(errorMessage(const QString&)),
102 this, SLOT(showErrorMessage(const QString&)));
103
104 m_dirModel = new KDirModel();
105 m_dirModel->setDirLister(m_dirLister);
106 m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory);
107
108 m_proxyModel = new DolphinSortFilterProxyModel(this);
109 m_proxyModel->setSourceModel(m_dirModel);
110
111 createView();
112
113 m_iconSize = K3Icon::SizeMedium;
114
115 m_filterBar = new FilterBar(this);
116 m_filterBar->hide();
117 connect(m_filterBar, SIGNAL(filterChanged(const QString&)),
118 this, SLOT(changeNameFilter(const QString&)));
119 connect(m_filterBar, SIGNAL(closed()),
120 this, SLOT(closeFilterBar()));
121
122 m_topLayout->addWidget(m_urlNavigator);
123 m_topLayout->addWidget(itemView());
124 m_topLayout->addWidget(m_filterBar);
125 m_topLayout->addWidget(m_statusBar);
126
127 loadDirectory(m_urlNavigator->url());
128 }
129
130 DolphinView::~DolphinView()
131 {
132 delete m_dirLister;
133 m_dirLister = 0;
134 }
135
136 void DolphinView::setUrl(const KUrl& url)
137 {
138 m_urlNavigator->setUrl(url);
139 }
140
141 const KUrl& DolphinView::url() const
142 {
143 return m_urlNavigator->url();
144 }
145
146 void DolphinView::requestActivation()
147 {
148 mainWindow()->setActiveView(this);
149 }
150
151 bool DolphinView::isActive() const
152 {
153 return (mainWindow()->activeView() == this);
154 }
155
156 void DolphinView::setMode(Mode mode)
157 {
158 if (mode == m_mode) {
159 return; // the wished mode is already set
160 }
161
162 m_mode = mode;
163
164 ViewProperties props(m_urlNavigator->url());
165 props.setViewMode(m_mode);
166
167 createView();
168 startDirLister(m_urlNavigator->url());
169
170 emit modeChanged();
171 }
172
173 DolphinView::Mode DolphinView::mode() const
174 {
175 return m_mode;
176 }
177
178 void DolphinView::setShowPreview(bool show)
179 {
180 ViewProperties props(m_urlNavigator->url());
181 props.setShowPreview(show);
182
183 // TODO: wait until previews are possible with KFileItemDelegate
184
185 emit showPreviewChanged();
186 }
187
188 bool DolphinView::showPreview() const
189 {
190 // TODO: wait until previews are possible with KFileItemDelegate
191 return true;
192 }
193
194 void DolphinView::setShowHiddenFiles(bool show)
195 {
196 if (m_dirLister->showingDotFiles() == show) {
197 return;
198 }
199
200 ViewProperties props(m_urlNavigator->url());
201 props.setShowHiddenFiles(show);
202 props.save();
203
204 m_dirLister->setShowingDotFiles(show);
205
206 emit showHiddenFilesChanged();
207
208 reload();
209 }
210
211 bool DolphinView::showHiddenFiles() const
212 {
213 return m_dirLister->showingDotFiles();
214 }
215
216 void DolphinView::renameSelectedItems()
217 {
218 const KUrl::List urls = selectedUrls();
219 if (urls.count() > 1) {
220 // More than one item has been selected for renaming. Open
221 // a rename dialog and rename all items afterwards.
222 RenameDialog dialog(urls);
223 if (dialog.exec() == QDialog::Rejected) {
224 return;
225 }
226
227 DolphinView* view = mainWindow()->activeView();
228 const QString& newName = dialog.newName();
229 if (newName.isEmpty()) {
230 view->statusBar()->setMessage(i18n("The new item name is invalid."),
231 DolphinStatusBar::Error);
232 }
233 else {
234 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
235
236 //UndoManager& undoMan = UndoManager::instance();
237 //undoMan.beginMacro();
238
239 assert(newName.contains('#'));
240
241 const int urlsCount = urls.count();
242
243 // iterate through all selected items and rename them...
244 const int replaceIndex = newName.indexOf('#');
245 assert(replaceIndex >= 0);
246 for (int i = 0; i < urlsCount; ++i) {
247 const KUrl& source = urls[i];
248 QString number;
249 number.setNum(i + 1);
250
251 QString name(newName);
252 name.replace(replaceIndex, 1, number);
253
254 if (source.fileName() != name) {
255 KUrl dest(source.upUrl());
256 dest.addPath(name);
257
258 const bool destExists = KIO::NetAccess::exists(dest, false, view);
259 if (destExists) {
260 view->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name),
261 DolphinStatusBar::Error);
262 break;
263 }
264 else if (KIO::NetAccess::file_move(source, dest)) {
265 // TODO: From the users point of view he executed one 'rename n files' operation,
266 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
267 //DolphinCommand command(DolphinCommand::Rename, source, dest);
268 //undoMan.addCommand(command);
269 }
270 }
271 }
272
273 //undoMan.endMacro();
274 }
275 }
276 else {
277 // Only one item has been selected for renaming. Use the custom
278 // renaming mechanism from the views.
279 assert(urls.count() == 1);
280 // TODO:
281 /*if (m_mode == DetailsView) {
282 Q3ListViewItem* item = m_iconsView->firstChild();
283 while (item != 0) {
284 if (item->isSelected()) {
285 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
286 break;
287 }
288 item = item->nextSibling();
289 }
290 }
291 else {
292 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
293 while (item != 0) {
294 if (item->isSelected()) {
295 item->rename();
296 break;
297 }
298 item = static_cast<KFileIconViewItem*>(item->nextItem());
299 }
300 }*/
301 }
302 }
303
304 void DolphinView::selectAll()
305 {
306 selectAll(QItemSelectionModel::Select);
307 }
308
309 void DolphinView::invertSelection()
310 {
311 selectAll(QItemSelectionModel::Toggle);
312 }
313
314 DolphinStatusBar* DolphinView::statusBar() const
315 {
316 return m_statusBar;
317 }
318
319 int DolphinView::contentsX() const
320 {
321
322 return 0; //scrollView()->contentsX();
323 }
324
325 int DolphinView::contentsY() const
326 {
327 return 0; //scrollView()->contentsY();
328 }
329
330 void DolphinView::refreshSettings()
331 {
332 startDirLister(m_urlNavigator->url());
333 }
334
335 void DolphinView::emitRequestItemInfo(const KUrl& url)
336 {
337 emit requestItemInfo(url);
338 }
339
340 bool DolphinView::isFilterBarVisible() const
341 {
342 return m_filterBar->isVisible();
343 }
344
345 bool DolphinView::isUrlEditable() const
346 {
347 return m_urlNavigator->isUrlEditable();
348 }
349
350 void DolphinView::zoomIn()
351 {
352 //itemEffectsManager()->zoomIn();
353 }
354
355 void DolphinView::zoomOut()
356 {
357 //itemEffectsManager()->zoomOut();
358 }
359
360 bool DolphinView::isZoomInPossible() const
361 {
362 return false; //itemEffectsManager()->isZoomInPossible();
363 }
364
365 bool DolphinView::isZoomOutPossible() const
366 {
367 return false; //itemEffectsManager()->isZoomOutPossible();
368 }
369
370 void DolphinView::setSorting(Sorting sorting)
371 {
372 if (sorting != this->sorting()) {
373 ViewProperties props(url());
374 props.setSorting(sorting);
375
376 m_proxyModel->setSorting(sorting);
377
378 emit sortingChanged(sorting);
379 }
380 }
381
382 DolphinView::Sorting DolphinView::sorting() const
383 {
384 return m_proxyModel->sorting();
385 }
386
387 void DolphinView::setSortOrder(Qt::SortOrder order)
388 {
389 if (sortOrder() != order) {
390 ViewProperties props(url());
391 props.setSortOrder(order);
392
393 m_proxyModel->setSortOrder(order);
394
395 emit sortOrderChanged(order);
396 }
397 }
398
399 Qt::SortOrder DolphinView::sortOrder() const
400 {
401 return m_proxyModel->sortOrder();
402 }
403
404 void DolphinView::goBack()
405 {
406 m_urlNavigator->goBack();
407 }
408
409 void DolphinView::goForward()
410 {
411 m_urlNavigator->goForward();
412 }
413
414 void DolphinView::goUp()
415 {
416 m_urlNavigator->goUp();
417 }
418
419 void DolphinView::goHome()
420 {
421 m_urlNavigator->goHome();
422 }
423
424 void DolphinView::setUrlEditable(bool editable)
425 {
426 m_urlNavigator->editUrl(editable);
427 }
428
429 const QLinkedList<UrlNavigator::HistoryElem> DolphinView::urlHistory(int& index) const
430 {
431 return m_urlNavigator->history(index);
432 }
433
434 bool DolphinView::hasSelection() const
435 {
436 return itemView()->selectionModel()->hasSelection();
437 }
438
439 KFileItemList DolphinView::selectedItems() const
440 {
441 const QAbstractItemView* view = itemView();
442
443 // Our view has a selection, we will map them back to the DirModel
444 // and then fill the KFileItemList.
445 assert((view != 0) && (view->selectionModel() != 0));
446
447 const QItemSelection selection = m_proxyModel->mapSelectionToSource(view->selectionModel()->selection());
448 KFileItemList itemList;
449
450 const QModelIndexList indexList = selection.indexes();
451 QModelIndexList::const_iterator end = indexList.end();
452 for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
453 assert((*it).isValid());
454
455 KFileItem* item = m_dirModel->itemForIndex(*it);
456 if (item != 0) {
457 itemList.append(item);
458 }
459 }
460
461 return itemList;
462 }
463
464 KUrl::List DolphinView::selectedUrls() const
465 {
466 KUrl::List urls;
467
468 const KFileItemList list = selectedItems();
469 KFileItemList::const_iterator it = list.begin();
470 const KFileItemList::const_iterator end = list.end();
471 while (it != end) {
472 KFileItem* item = *it;
473 urls.append(item->url());
474 ++it;
475 }
476
477 return urls;
478 }
479
480 KFileItem* DolphinView::fileItem(const QModelIndex index) const
481 {
482 const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index);
483 return m_dirModel->itemForIndex(dirModelIndex);
484 }
485
486 void DolphinView::openContextMenu(KFileItem* fileInfo, const QPoint& pos)
487 {
488 DolphinContextMenu contextMenu(this, fileInfo, pos);
489 contextMenu.open();
490 }
491
492 void DolphinView::rename(const KUrl& source, const QString& newName)
493 {
494 bool ok = false;
495
496 if (newName.isEmpty() || (source.fileName() == newName)) {
497 return;
498 }
499
500 KUrl dest(source.upUrl());
501 dest.addPath(newName);
502
503 const bool destExists = KIO::NetAccess::exists(dest,
504 false,
505 mainWindow()->activeView());
506 if (destExists) {
507 // the destination already exists, hence ask the user
508 // how to proceed...
509 KIO::RenameDialog renameDialog(this,
510 i18n("File Already Exists"),
511 source.path(),
512 dest.path(),
513 KIO::M_OVERWRITE);
514 switch (renameDialog.exec()) {
515 case KIO::R_OVERWRITE:
516 // the destination should be overwritten
517 ok = KIO::NetAccess::file_move(source, dest, -1, true);
518 break;
519
520 case KIO::R_RENAME: {
521 // a new name for the destination has been used
522 KUrl newDest(renameDialog.newDestUrl());
523 ok = KIO::NetAccess::file_move(source, newDest);
524 break;
525 }
526
527 default:
528 // the renaming operation has been canceled
529 reload();
530 return;
531 }
532 }
533 else {
534 // no destination exists, hence just move the file to
535 // do the renaming
536 ok = KIO::NetAccess::file_move(source, dest);
537 }
538
539 const QString destFileName = dest.fileName();
540 if (ok) {
541 m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.",source.fileName(), destFileName),
542 DolphinStatusBar::OperationCompleted);
543
544 KonqOperations::rename(this, source, destFileName);
545 }
546 else {
547 m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source.fileName(), destFileName),
548 DolphinStatusBar::Error);
549 reload();
550 }
551 }
552
553 void DolphinView::reload()
554 {
555 startDirLister(m_urlNavigator->url(), true);
556 }
557
558 void DolphinView::declareViewActive()
559 {
560 mainWindow()->setActiveView( this );
561 }
562
563 void DolphinView::mouseReleaseEvent(QMouseEvent* event)
564 {
565 QWidget::mouseReleaseEvent(event);
566 mainWindow()->setActiveView(this);
567 }
568
569 DolphinMainWindow* DolphinView::mainWindow() const
570 {
571 return m_mainWindow;
572 }
573
574 void DolphinView::loadDirectory(const KUrl& url)
575 {
576 const ViewProperties props(url);
577
578 const Mode mode = props.viewMode();
579 if (m_mode != mode) {
580 m_mode = mode;
581 createView();
582 emit modeChanged();
583 }
584
585 const bool showHiddenFiles = props.showHiddenFiles();
586 if (showHiddenFiles != m_dirLister->showingDotFiles()) {
587 m_dirLister->setShowingDotFiles(showHiddenFiles);
588 emit showHiddenFilesChanged();
589 }
590
591 const DolphinView::Sorting sorting = props.sorting();
592 if (sorting != m_proxyModel->sorting()) {
593 m_proxyModel->setSorting(sorting);
594 emit sortingChanged(sorting);
595 }
596
597 const Qt::SortOrder sortOrder = props.sortOrder();
598 if (sortOrder != m_proxyModel->sortOrder()) {
599 m_proxyModel->setSortOrder(sortOrder);
600 emit sortOrderChanged(sortOrder);
601 }
602
603 // TODO: handle previews (props.showPreview())
604
605 startDirLister(url);
606 emit urlChanged(url);
607
608 m_statusBar->clear();
609 }
610
611 void DolphinView::triggerItem(const QModelIndex& index)
612 {
613 KFileItem* item = m_dirModel->itemForIndex(m_proxyModel->mapToSource(index));
614 if (item == 0) {
615 return;
616 }
617
618 if (item->isDir()) {
619 // Prefer the local path over the Url. This assures that the
620 // volume space information is correct. Assuming that the Url is media:/sda1,
621 // and the local path is /windows/C: For the Url the space info is related
622 // to the root partition (and hence wrong) and for the local path the space
623 // info is related to the windows partition (-> correct).
624 const QString localPath(item->localPath());
625 if (localPath.isEmpty()) {
626 setUrl(item->url());
627 }
628 else {
629 setUrl(KUrl(localPath));
630 }
631 }
632 else {
633 item->run();
634 }
635 }
636
637 void DolphinView::updateProgress(int percent)
638 {
639 if (m_showProgress) {
640 m_statusBar->setProgress(percent);
641 }
642 }
643
644 void DolphinView::updateItemCount()
645 {
646 if (m_showProgress) {
647 m_statusBar->setProgressText(QString::null);
648 m_statusBar->setProgress(100);
649 m_showProgress = false;
650 }
651
652 KFileItemList items(m_dirLister->items());
653 KFileItemList::const_iterator it = items.begin();
654 const KFileItemList::const_iterator end = items.end();
655
656 m_fileCount = 0;
657 m_folderCount = 0;
658
659 while (it != end) {
660 KFileItem* item = *it;
661 if (item->isDir()) {
662 ++m_folderCount;
663 }
664 else {
665 ++m_fileCount;
666 }
667 ++it;
668 }
669
670 updateStatusBar();
671 }
672
673 void DolphinView::showInfoMessage(const QString& msg)
674 {
675 m_statusBar->setMessage(msg, DolphinStatusBar::Information);
676 }
677
678 void DolphinView::showErrorMessage(const QString& msg)
679 {
680 m_statusBar->setMessage(msg, DolphinStatusBar::Error);
681 }
682
683 void DolphinView::emitSelectionChangedSignal()
684 {
685 emit selectionChanged();
686 }
687
688 void DolphinView::closeFilterBar()
689 {
690 m_filterBar->hide();
691 emit showFilterBarChanged(false);
692 }
693
694 void DolphinView::startDirLister(const KUrl& url, bool reload)
695 {
696 if (!url.isValid()) {
697 const QString location(url.pathOrUrl());
698 if (location.isEmpty()) {
699 m_statusBar->setMessage(i18n("The location is empty."), DolphinStatusBar::Error);
700 }
701 else {
702 m_statusBar->setMessage(i18n("The location '%1' is invalid.",location),
703 DolphinStatusBar::Error);
704 }
705 return;
706 }
707
708 // Only show the directory loading progress if the status bar does
709 // not contain another progress information. This means that
710 // the directory loading progress information has the lowest priority.
711 const QString progressText(m_statusBar->progressText());
712 m_showProgress = progressText.isEmpty() ||
713 (progressText == i18n("Loading directory..."));
714 if (m_showProgress) {
715 m_statusBar->setProgressText(i18n("Loading directory..."));
716 m_statusBar->setProgress(0);
717 }
718
719 m_dirLister->stop();
720 m_dirLister->openUrl(url, false, reload);
721 }
722
723 QString DolphinView::defaultStatusBarText() const
724 {
725 // TODO: the following code is not suitable for languages where multiple forms
726 // of plurals are given (e. g. in Poland three forms of plurals exist).
727 const int itemCount = m_folderCount + m_fileCount;
728
729 QString text;
730 if (itemCount == 1) {
731 text = i18n("1 Item");
732 }
733 else {
734 text = i18n("%1 Items",itemCount);
735 }
736
737 text += " (";
738
739 if (m_folderCount == 1) {
740 text += i18n("1 Folder");
741 }
742 else {
743 text += i18n("%1 Folders",m_folderCount);
744 }
745
746 text += ", ";
747
748 if (m_fileCount == 1) {
749 text += i18n("1 File");
750 }
751 else {
752 text += i18n("%1 Files",m_fileCount);
753 }
754
755 text += ")";
756
757 return text;
758 }
759
760 QString DolphinView::selectionStatusBarText() const
761 {
762 // TODO: the following code is not suitable for languages where multiple forms
763 // of plurals are given (e. g. in Poland three forms of plurals exist).
764 QString text;
765 const KFileItemList list = selectedItems();
766 if (list.isEmpty()) {
767 // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
768 // DolphinView::hasSelection() is true. Inconsistent behavior?
769 return QString();
770 }
771
772 int fileCount = 0;
773 int folderCount = 0;
774 KIO::filesize_t byteSize = 0;
775 KFileItemList::const_iterator it = list.begin();
776 const KFileItemList::const_iterator end = list.end();
777 while (it != end){
778 KFileItem* item = *it;
779 if (item->isDir()) {
780 ++folderCount;
781 }
782 else {
783 ++fileCount;
784 byteSize += item->size();
785 }
786 ++it;
787 }
788
789 if (folderCount == 1) {
790 text = i18n("1 Folder selected");
791 }
792 else if (folderCount > 1) {
793 text = i18n("%1 Folders selected",folderCount);
794 }
795
796 if ((fileCount > 0) && (folderCount > 0)) {
797 text += ", ";
798 }
799
800 const QString sizeText(KIO::convertSize(byteSize));
801 if (fileCount == 1) {
802 text += i18n("1 File selected (%1)",sizeText);
803 }
804 else if (fileCount > 1) {
805 text += i18n("%1 Files selected (%1)",fileCount,sizeText);
806 }
807
808 return text;
809 }
810
811 void DolphinView::showFilterBar(bool show)
812 {
813 assert(m_filterBar != 0);
814 if (show) {
815 m_filterBar->show();
816 }
817 else {
818 m_filterBar->hide();
819 }
820 }
821
822 void DolphinView::updateStatusBar()
823 {
824 // As the item count information is less important
825 // in comparison with other messages, it should only
826 // be shown if:
827 // - the status bar is empty or
828 // - shows already the item count information or
829 // - shows only a not very important information
830 // - if any progress is given don't show the item count info at all
831 const QString msg(m_statusBar->message());
832 const bool updateStatusBarMsg = (msg.isEmpty() ||
833 (msg == m_statusBar->defaultText()) ||
834 (m_statusBar->type() == DolphinStatusBar::Information)) &&
835 (m_statusBar->progress() == 100);
836
837 const QString text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
838 m_statusBar->setDefaultText(text);
839
840 if (updateStatusBarMsg) {
841 m_statusBar->setMessage(text, DolphinStatusBar::Default);
842 }
843 }
844
845 void DolphinView::changeNameFilter(const QString& nameFilter)
846 {
847 // The name filter of KDirLister does a 'hard' filtering, which
848 // means that only the items are shown where the names match
849 // exactly the filter. This is non-transparent for the user, which
850 // just wants to have a 'soft' filtering: does the name contain
851 // the filter string?
852 QString adjustedFilter(nameFilter);
853 adjustedFilter.insert(0, '*');
854 adjustedFilter.append('*');
855
856 // Use the ProxyModel to filter:
857 // This code is #ifdefed as setNameFilter behaves
858 // slightly different than the QSortFilterProxyModel
859 // as it will not remove directories. I will ask
860 // our beloved usability experts for input
861 // -- z.
862 #if 0
863 m_dirLister->setNameFilter(adjustedFilter);
864 m_dirLister->emitChanges();
865 #else
866 m_proxyModel->setFilterRegExp( nameFilter );
867 #endif
868 }
869
870 void DolphinView::createView()
871 {
872 // delete current view
873 QAbstractItemView* view = itemView();
874 if (view != 0) {
875 m_topLayout->removeWidget(view);
876 view->close();
877 view->deleteLater();
878 m_iconsView = 0;
879 m_detailsView = 0;
880 }
881
882 assert(m_iconsView == 0);
883 assert(m_detailsView == 0);
884
885 // ... and recreate it representing the current mode
886 switch (m_mode) {
887 case IconsView:
888 m_iconsView = new DolphinIconsView(this);
889 m_iconsView->setViewMode(QListView::IconMode);
890 m_iconsView->setSpacing(32);
891 view = m_iconsView;
892 // TODO: read out view settings
893 break;
894
895 case DetailsView:
896 m_detailsView = new DolphinDetailsView(this);
897 view = m_detailsView;
898 // TODO: read out view settings
899 break;
900 }
901
902 view->setModel(m_proxyModel);
903
904 view->setSelectionMode(QAbstractItemView::ExtendedSelection);
905
906 KFileItemDelegate* delegate = new KFileItemDelegate(this);
907 delegate->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType);
908 view->setItemDelegate(delegate);
909
910 new KMimeTypeResolver(view, m_dirModel);
911
912 connect(view, SIGNAL(clicked(const QModelIndex&)),
913 this, SLOT(triggerItem(const QModelIndex&)));
914 connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
915 this, SLOT(emitSelectionChangedSignal()));
916
917 m_topLayout->insertWidget(1, view);
918 }
919
920 int DolphinView::columnIndex(Sorting sorting) const
921 {
922 int index = 0;
923 switch (sorting) {
924 case SortByName: index = KDirModel::Name; break;
925 case SortBySize: index = KDirModel::Size; break;
926 case SortByDate: index = KDirModel::ModifiedTime; break;
927 default: assert(false);
928 }
929 return index;
930 }
931
932 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags)
933 {
934 QItemSelectionModel* selectionModel = itemView()->selectionModel();
935 const QAbstractItemModel* itemModel = selectionModel->model();
936
937 const QModelIndex topLeft = itemModel->index(0, 0);
938 const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
939 itemModel->columnCount() - 1);
940
941 QItemSelection selection(topLeft, bottomRight);
942 selectionModel->select(selection, flags);
943 }
944
945 QAbstractItemView* DolphinView::itemView() const
946 {
947 assert((m_iconsView == 0) || (m_detailsView == 0));
948 if (m_detailsView != 0) {
949 return m_detailsView;
950 }
951 return m_iconsView;
952 }
953
954 #include "dolphinview.moc"