1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
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. *
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. *
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "dolphinview.h"
23 #include <QItemSelectionModel>
25 #include <kdirmodel.h>
29 #include <Q3ValueList>
31 #include <QMouseEvent>
32 #include <QVBoxLayout>
35 #include <kio/netaccess.h>
36 #include <kio/renamedlg.h>
37 #include <kmimetyperesolver.h>
40 #include "urlnavigator.h"
41 #include "dolphinstatusbar.h"
42 #include "dolphinmainwindow.h"
43 #include "dolphindirlister.h"
44 #include "viewproperties.h"
45 #include "dolphindetailsview.h"
46 #include "dolphiniconsview.h"
47 #include "dolphincontextmenu.h"
48 #include "undomanager.h"
49 #include "renamedialog.h"
50 #include "progressindicator.h"
52 #include "filterbar.h"
54 DolphinView::DolphinView(DolphinMainWindow
*mainWindow
,
58 bool showHiddenFiles
) :
60 m_mainWindow(mainWindow
),
62 m_showProgress(false),
71 setFocusPolicy(Qt::StrongFocus
);
72 m_topLayout
= new QVBoxLayout(this);
73 m_topLayout
->setSpacing(0);
74 m_topLayout
->setMargin(0);
76 connect(this, SIGNAL(signalModeChanged()),
77 mainWindow
, SLOT(slotViewModeChanged()));
78 connect(this, SIGNAL(signalShowHiddenFilesChanged()),
79 mainWindow
, SLOT(slotShowHiddenFilesChanged()));
80 connect(this, SIGNAL(signalSortingChanged(DolphinView::Sorting
)),
81 mainWindow
, SLOT(slotSortingChanged(DolphinView::Sorting
)));
82 connect(this, SIGNAL(signalSortOrderChanged(Qt::SortOrder
)),
83 mainWindow
, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
85 m_urlNavigator
= new UrlNavigator(url
, this);
86 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
87 this, SLOT(slotUrlChanged(const KUrl
&)));
88 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
89 mainWindow
, SLOT(slotUrlChanged(const KUrl
&)));
90 connect(m_urlNavigator
, SIGNAL(historyChanged()),
91 mainWindow
, SLOT(slotHistoryChanged()));
93 m_statusBar
= new DolphinStatusBar(this);
95 m_dirLister
= new DolphinDirLister();
96 m_dirLister
->setAutoUpdate(true);
97 m_dirLister
->setMainWindow(this);
98 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
99 connect(m_dirLister
, SIGNAL(clear()),
100 this, SLOT(slotClear()));
101 connect(m_dirLister
, SIGNAL(percent(int)),
102 this, SLOT(slotPercent(int)));
103 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
104 this, SLOT(slotDeleteItem(KFileItem
*)));
105 connect(m_dirLister
, SIGNAL(completed()),
106 this, SLOT(slotCompleted()));
107 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
108 this, SLOT(slotInfoMessage(const QString
&)));
109 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
110 this, SLOT(slotErrorMessage(const QString
&)));
112 m_iconsView
= new DolphinIconsView(this);
113 connect(m_iconsView
, SIGNAL(clicked(const QModelIndex
&)),
114 this, SLOT(triggerItem(const QModelIndex
&)));
117 KDirModel
* model
= new KDirModel();
118 model
->setDirLister(m_dirLister
);
119 m_iconsView
->setModel(model
);
121 m_dirLister
->setDelayedMimeTypes(true);
122 new KMimeTypeResolver( m_iconsView
, model
);
124 m_iconSize
= K3Icon::SizeMedium
;
126 m_filterBar
= new FilterBar(mainWindow
, this);
128 connect(m_filterBar
, SIGNAL(signalFilterChanged(const QString
&)),
129 this, SLOT(slotChangeNameFilter(const QString
&)));
131 m_topLayout
->addWidget(m_urlNavigator
);
132 m_topLayout
->addWidget(m_iconsView
);
133 m_topLayout
->addWidget(m_filterBar
);
134 m_topLayout
->addWidget(m_statusBar
);
136 startDirLister(m_urlNavigator
->url());
139 DolphinView::~DolphinView()
145 void DolphinView::setUrl(const KUrl
& url
)
147 m_urlNavigator
->setUrl(url
);
150 const KUrl
& DolphinView::url() const
152 return m_urlNavigator
->url();
155 void DolphinView::requestActivation()
157 mainWindow()->setActiveView(this);
160 bool DolphinView::isActive() const
162 return (mainWindow()->activeView() == this);
165 void DolphinView::setMode(Mode mode
)
167 if (mode
== m_mode
) {
168 return; // the wished mode is already set
173 ViewProperties
props(m_urlNavigator
->url());
174 props
.setViewMode(m_mode
);
177 startDirLister(m_urlNavigator
->url());
179 emit
signalModeChanged();
182 DolphinView::Mode
DolphinView::mode() const
187 void DolphinView::setShowHiddenFilesEnabled(bool show
)
189 if (m_dirLister
->showingDotFiles() == show
) {
193 ViewProperties
props(m_urlNavigator
->url());
194 props
.setShowHiddenFilesEnabled(show
);
197 m_dirLister
->setShowingDotFiles(show
);
199 emit
signalShowHiddenFilesChanged();
204 bool DolphinView::isShowHiddenFilesEnabled() const
206 return m_dirLister
->showingDotFiles();
209 void DolphinView::setViewProperties(const ViewProperties
& props
)
211 setMode(props
.viewMode());
212 setSorting(props
.sorting());
213 setSortOrder(props
.sortOrder());
214 setShowHiddenFilesEnabled(props
.isShowHiddenFilesEnabled());
217 void DolphinView::renameSelectedItems()
219 const KUrl::List urls
= selectedUrls();
220 if (urls
.count() > 1) {
221 // More than one item has been selected for renaming. Open
222 // a rename dialog and rename all items afterwards.
223 RenameDialog
dialog(urls
);
224 if (dialog
.exec() == QDialog::Rejected
) {
228 DolphinView
* view
= mainWindow()->activeView();
229 const QString
& newName
= dialog
.newName();
230 if (newName
.isEmpty()) {
231 view
->statusBar()->setMessage(i18n("The new item name is invalid."),
232 DolphinStatusBar::Error
);
235 UndoManager
& undoMan
= UndoManager::instance();
236 undoMan
.beginMacro();
238 assert(newName
.contains('#'));
240 const int urlsCount
= urls
.count();
241 ProgressIndicator
* progressIndicator
=
242 new ProgressIndicator(mainWindow(),
243 i18n("Renaming items..."),
244 i18n("Renaming finished."),
247 // iterate through all selected items and rename them...
248 const int replaceIndex
= newName
.indexOf('#');
249 assert(replaceIndex
>= 0);
250 for (int i
= 0; i
< urlsCount
; ++i
) {
251 const KUrl
& source
= urls
[i
];
252 QString
name(newName
);
253 name
.replace(replaceIndex
, 1, renameIndexPresentation(i
+ 1, urlsCount
));
255 if (source
.fileName() != name
) {
256 KUrl
dest(source
.upUrl());
259 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
261 delete progressIndicator
;
262 progressIndicator
= 0;
263 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name
),
264 DolphinStatusBar::Error
);
267 else if (KIO::NetAccess::file_move(source
, dest
)) {
268 // TODO: From the users point of view he executed one 'rename n files' operation,
269 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
270 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
271 undoMan
.addCommand(command
);
275 progressIndicator
->execOperation();
277 delete progressIndicator
;
278 progressIndicator
= 0;
284 // Only one item has been selected for renaming. Use the custom
285 // renaming mechanism from the views.
286 assert(urls
.count() == 1);
288 /*if (m_mode == DetailsView) {
289 Q3ListViewItem* item = m_iconsView->firstChild();
291 if (item->isSelected()) {
292 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
295 item = item->nextSibling();
299 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
301 if (item->isSelected()) {
305 item = static_cast<KFileIconViewItem*>(item->nextItem());
311 void DolphinView::selectAll()
313 //fileView()->selectAll();
316 void DolphinView::invertSelection()
318 //fileView()->invertSelection();
321 DolphinStatusBar
* DolphinView::statusBar() const
326 int DolphinView::contentsX() const
329 return 0; //scrollView()->contentsX();
332 int DolphinView::contentsY() const
334 return 0; //scrollView()->contentsY();
337 void DolphinView::refreshSettings()
339 startDirLister(m_urlNavigator
->url());
342 void DolphinView::updateStatusBar()
344 // As the item count information is less important
345 // in comparison with other messages, it should only
347 // - the status bar is empty or
348 // - shows already the item count information or
349 // - shows only a not very important information
350 // - if any progress is given don't show the item count info at all
351 const QString
msg(m_statusBar
->message());
352 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
353 (msg
== m_statusBar
->defaultText()) ||
354 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
355 (m_statusBar
->progress() == 100);
357 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
358 m_statusBar
->setDefaultText(text
);
360 if (updateStatusBarMsg
) {
361 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
365 void DolphinView::requestItemInfo(const KUrl
& url
)
367 emit
signalRequestItemInfo(url
);
370 bool DolphinView::isUrlEditable() const
372 return m_urlNavigator
->isUrlEditable();
375 void DolphinView::zoomIn()
377 //itemEffectsManager()->zoomIn();
380 void DolphinView::zoomOut()
382 //itemEffectsManager()->zoomOut();
385 bool DolphinView::isZoomInPossible() const
387 return false; //itemEffectsManager()->isZoomInPossible();
390 bool DolphinView::isZoomOutPossible() const
392 return false; //itemEffectsManager()->isZoomOutPossible();
395 void DolphinView::setSorting(Sorting sorting
)
397 if (sorting
!= this->sorting()) {
398 /*KFileView* view = fileView();
399 int spec = view->sorting() & ~QDir::Name & ~QDir::Size & ~QDir::Time & ~QDir::Unsorted;
402 case SortByName: spec = spec | QDir::Name; break;
403 case SortBySize: spec = spec | QDir::Size; break;
404 case SortByDate: spec = spec | QDir::Time; break;
408 ViewProperties props(url());
409 props.setSorting(sorting);
411 view->setSorting(static_cast<QDir::SortFlags>(spec));
413 emit signalSortingChanged(sorting);*/
417 DolphinView::Sorting
DolphinView::sorting() const
419 /*const QDir::SortFlags spec = fileView()->sorting();
421 if (spec & QDir::Time) {
425 if (spec & QDir::Size) {
432 void DolphinView::setSortOrder(Qt::SortOrder order
)
434 if (sortOrder() != order
) {
435 /*KFileView* view = fileView();
436 int sorting = view->sorting();
437 sorting = (order == Qt::Ascending) ? (sorting & ~QDir::Reversed) :
438 (sorting | QDir::Reversed);
440 ViewProperties props(url());
441 props.setSortOrder(order);
443 view->setSorting(static_cast<QDir::SortFlags>(sorting));
445 emit signalSortOrderChanged(order);*/
449 Qt::SortOrder
DolphinView::sortOrder() const
451 //return fileView()->isReversed() ? Qt::Descending : Qt::Ascending;
452 return Qt::Descending
;
455 void DolphinView::goBack()
457 m_urlNavigator
->goBack();
460 void DolphinView::goForward()
462 m_urlNavigator
->goForward();
465 void DolphinView::goUp()
467 m_urlNavigator
->goUp();
470 void DolphinView::goHome()
472 m_urlNavigator
->goHome();
475 void DolphinView::setUrlEditable(bool editable
)
477 m_urlNavigator
->editUrl(editable
);
480 const Q3ValueList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
482 return m_urlNavigator
->history(index
);
485 bool DolphinView::hasSelection() const
487 return m_iconsView
->selectionModel()->hasSelection();
490 KFileItemList
DolphinView::selectedItems() const
492 QItemSelectionModel
* selModel
= m_iconsView
->selectionModel();
493 assert(selModel
!= 0);
495 KFileItemList itemList
;
496 if (selModel
->hasSelection()) {
497 KDirModel
* dirModel
= static_cast<KDirModel
*>(m_iconsView
->model());
498 const QModelIndexList indexList
= selModel
->selectedIndexes();
500 QModelIndexList::const_iterator end
= indexList
.end();
501 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
502 KFileItem
* item
= dirModel
->itemForIndex(*it
);
504 itemList
.append(item
);
511 KUrl::List
DolphinView::selectedUrls() const
515 const KFileItemList list
= selectedItems();
516 KFileItemList::const_iterator it
= list
.begin();
517 const KFileItemList::const_iterator end
= list
.end();
519 KFileItem
* item
= *it
;
520 urls
.append(item
->url());
527 const KFileItem
* DolphinView::currentFileItem() const
529 return 0; // fileView()->currentFileItem();
532 void DolphinView::openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
)
534 DolphinContextMenu
contextMenu(this, fileInfo
, pos
);
538 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
542 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
546 KUrl
dest(source
.upUrl());
547 dest
.addPath(newName
);
549 const bool destExists
= KIO::NetAccess::exists(dest
,
551 mainWindow()->activeView());
553 // the destination already exists, hence ask the user
555 KIO::RenameDlg
renameDialog(this,
556 i18n("File Already Exists"),
560 switch (renameDialog
.exec()) {
561 case KIO::R_OVERWRITE
:
562 // the destination should be overwritten
563 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
566 case KIO::R_RENAME
: {
567 // a new name for the destination has been used
568 KUrl
newDest(renameDialog
.newDestUrl());
569 ok
= KIO::NetAccess::file_move(source
, newDest
);
574 // the renaming operation has been canceled
580 // no destination exists, hence just move the file to
582 ok
= KIO::NetAccess::file_move(source
, dest
);
586 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), dest
.fileName()),
587 DolphinStatusBar::OperationCompleted
);
589 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
590 UndoManager::instance().addCommand(command
);
593 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), dest
.fileName()),
594 DolphinStatusBar::Error
);
599 void DolphinView::reload()
601 startDirLister(m_urlNavigator
->url(), true);
604 void DolphinView::slotUrlListDropped(QDropEvent
* /* event */,
605 const KUrl::List
& urls
,
608 KUrl
destination(url
);
609 if (destination
.isEmpty()) {
610 destination
= m_urlNavigator
->url();
613 // Check whether the destination Url is a directory. If this is not the
614 // case, use the navigator Url as destination (otherwise the destination,
615 // which represents a file, would be replaced by a copy- or move-operation).
616 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, destination
);
617 if (!fileItem
.isDir()) {
618 destination
= m_urlNavigator
->url();
622 mainWindow()->dropUrls(urls
, destination
);
625 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
627 QWidget::mouseReleaseEvent(event
);
628 mainWindow()->setActiveView(this);
631 DolphinMainWindow
* DolphinView::mainWindow() const
636 void DolphinView::slotUrlChanged(const KUrl
& url
)
638 const ViewProperties
props(url
);
639 setMode(props
.viewMode());
641 const bool showHiddenFiles
= props
.isShowHiddenFilesEnabled();
642 setShowHiddenFilesEnabled(showHiddenFiles
);
643 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
645 setSorting(props
.sorting());
646 setSortOrder(props
.sortOrder());
650 // The selectionChanged signal is not emitted when a new view object is
651 // created. The application does not care whether a view is represented by a
652 // different instance, hence inform the application that the selection might have
653 // changed so that it can update it's actions.
654 mainWindow()->slotSelectionChanged();
656 emit
signalUrlChanged(url
);
659 void DolphinView::triggerIconsViewItem(Q3IconViewItem
* item
)
662 const Qt::ButtonState keyboardState = KApplication::keyboardMouseState();
663 const bool isSelectionActive = ((keyboardState & Qt::ShiftModifier) > 0) ||
664 ((keyboardState & Qt::ControlModifier) > 0);*/
665 const bool isSelectionActive
= false;
666 if ((item
!= 0) && !isSelectionActive
) {
667 // Updating the Url must be done outside the scope of this slot,
668 // as iconview items will get deleted.
669 QTimer::singleShot(0, this, SLOT(updateUrl()));
670 mainWindow()->setActiveView(this);
674 void DolphinView::triggerItem(const QModelIndex
& index
)
676 KDirModel
* dirModel
= static_cast<KDirModel
*>(m_iconsView
->model());
677 KFileItem
* item
= dirModel
->itemForIndex(index
);
683 // Prefer the local path over the Url. This assures that the
684 // volume space information is correct. Assuming that the Url is media:/sda1,
685 // and the local path is /windows/C: For the Url the space info is related
686 // to the root partition (and hence wrong) and for the local path the space
687 // info is related to the windows partition (-> correct).
688 //m_dirLister->stop();
689 //m_dirLister->openUrl(item->url());
692 const QString
localPath(item
->localPath());
693 if (localPath
.isEmpty()) {
697 setUrl(KUrl(localPath
));
705 void DolphinView::updateUrl()
707 //KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) :
708 // static_cast<KFileView*>(m_iconsView);
710 KFileItem
* fileItem
= 0; // TODO: fileView->currentFileItem();
715 if (fileItem
->isDir()) {
716 // Prefer the local path over the Url. This assures that the
717 // volume space information is correct. Assuming that the Url is media:/sda1,
718 // and the local path is /windows/C: For the Url the space info is related
719 // to the root partition (and hence wrong) and for the local path the space
720 // info is related to the windows partition (-> correct).
721 const QString
localPath(fileItem
->localPath());
722 if (localPath
.isEmpty()) {
723 setUrl(fileItem
->url());
726 setUrl(KUrl(localPath
));
734 void DolphinView::slotPercent(int percent
)
736 if (m_showProgress
) {
737 m_statusBar
->setProgress(percent
);
741 void DolphinView::slotClear()
743 //fileView()->clearView();
747 void DolphinView::slotDeleteItem(KFileItem
* item
)
749 //fileView()->removeItem(item);
753 void DolphinView::slotCompleted()
757 //KFileView* view = fileView();
760 // TODO: in Qt4 the code should get a lot
761 // simpler and nicer due to Interview...
762 /*if (m_iconsView != 0) {
763 m_iconsView->beginItemUpdates();
765 if (m_iconsView != 0) {
766 m_iconsView->beginItemUpdates();
769 if (m_showProgress
) {
770 m_statusBar
->setProgressText(QString::null
);
771 m_statusBar
->setProgress(100);
772 m_showProgress
= false;
775 KFileItemList
items(m_dirLister
->items());
776 KFileItemList::const_iterator it
= items
.begin();
777 const KFileItemList::const_iterator end
= items
.end();
783 KFileItem
* item
= *it
;
784 //view->insertItem(item);
796 /*if (m_iconsView != 0) {
797 // Prevent a flickering of the icon view widget by giving a small
798 // timeslot to swallow asynchronous update events.
799 m_iconsView->setUpdatesEnabled(false);
800 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
803 if (m_iconsView != 0) {
804 m_iconsView->endItemUpdates();
805 m_refreshing = false;
809 void DolphinView::slotInfoMessage(const QString
& msg
)
811 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
814 void DolphinView::slotErrorMessage(const QString
& msg
)
816 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
819 void DolphinView::slotGrabActivation()
821 mainWindow()->setActiveView(this);
824 void DolphinView::slotContentsMoving(int x
, int y
)
827 // Only emit a 'contents moved' signal if the user
828 // moved the content by adjusting the sliders. Adjustments
829 // resulted by refreshing a directory should not be respected.
830 emit
contentsMoved(x
, y
);
834 /*KFileView* DolphinView::fileView() const
836 return (m_mode == DetailsView) ? static_cast<KFileView*>(m_iconsView) :
837 static_cast<KFileView*>(m_iconsView);
840 Q3ScrollView
* DolphinView::scrollView() const
842 return 0; //(m_mode == DetailsView) ? static_cast<Q3ScrollView*>(m_iconsView) :
843 // static_cast<Q3ScrollView*>(m_iconsView);
846 ItemEffectsManager
* DolphinView::itemEffectsManager() const
851 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
853 if (!url
.isValid()) {
854 const QString
location(url
.pathOrUrl());
855 if (location
.isEmpty()) {
856 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
859 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
860 DolphinStatusBar::Error
);
865 // Only show the directory loading progress if the status bar does
866 // not contain another progress information. This means that
867 // the directory loading progress information has the lowest priority.
868 const QString
progressText(m_statusBar
->progressText());
869 m_showProgress
= progressText
.isEmpty() ||
870 (progressText
== i18n("Loading directory..."));
871 if (m_showProgress
) {
872 m_statusBar
->setProgressText(i18n("Loading directory..."));
873 m_statusBar
->setProgress(0);
878 m_dirLister
->openUrl(url
, false, reload
);
881 QString
DolphinView::defaultStatusBarText() const
883 // TODO: the following code is not suitable for languages where multiple forms
884 // of plurals are given (e. g. in Poland three forms of plurals exist).
885 const int itemCount
= m_folderCount
+ m_fileCount
;
888 if (itemCount
== 1) {
889 text
= i18n("1 Item");
892 text
= i18n("%1 Items",itemCount
);
897 if (m_folderCount
== 1) {
898 text
+= i18n("1 Folder");
901 text
+= i18n("%1 Folders",m_folderCount
);
906 if (m_fileCount
== 1) {
907 text
+= i18n("1 File");
910 text
+= i18n("%1 Files",m_fileCount
);
918 QString
DolphinView::selectionStatusBarText() const
920 // TODO: the following code is not suitable for languages where multiple forms
921 // of plurals are given (e. g. in Poland three forms of plurals exist).
923 const KFileItemList list
= selectedItems();
924 if (list
.isEmpty()) {
925 // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
926 // DolphinView::hasSelection() is true. Inconsistent behavior?
932 KIO::filesize_t byteSize
= 0;
933 KFileItemList::const_iterator it
= list
.begin();
934 const KFileItemList::const_iterator end
= list
.end();
936 KFileItem
* item
= *it
;
942 byteSize
+= item
->size();
947 if (folderCount
== 1) {
948 text
= i18n("1 Folder selected");
950 else if (folderCount
> 1) {
951 text
= i18n("%1 Folders selected",folderCount
);
954 if ((fileCount
> 0) && (folderCount
> 0)) {
958 const QString
sizeText(KIO::convertSize(byteSize
));
959 if (fileCount
== 1) {
960 text
+= i18n("1 File selected (%1)",sizeText
);
962 else if (fileCount
> 1) {
963 text
+= i18n("%1 Files selected (%1)",fileCount
,sizeText
);
969 QString
DolphinView::renameIndexPresentation(int index
, int itemCount
) const
971 // assure that the string reprentation for all indicess have the same
972 // number of characters based on the given number of items
973 QString
str(QString::number(index
));
975 while (itemCount
>= 10) {
979 str
.reserve(chrCount
);
981 const int insertCount
= chrCount
- str
.length();
982 for (int i
= 0; i
< insertCount
; ++i
) {
988 void DolphinView::slotShowFilterBar(bool show
)
990 assert(m_filterBar
!= 0);
999 void DolphinView::declareViewActive()
1001 mainWindow()->setActiveView( this );
1004 void DolphinView::slotChangeNameFilter(const QString
& nameFilter
)
1006 // The name filter of KDirLister does a 'hard' filtering, which
1007 // means that only the items are shown where the names match
1008 // exactly the filter. This is non-transparent for the user, which
1009 // just wants to have a 'soft' filtering: does the name contain
1010 // the filter string?
1011 QString
adjustedFilter(nameFilter
);
1012 adjustedFilter
.insert(0, '*');
1013 adjustedFilter
.append('*');
1015 m_dirLister
->setNameFilter(adjustedFilter
);
1016 m_dirLister
->emitChanges();
1018 // TODO: this is a workaround for QIconView: the item position
1019 // stay as they are by filtering, only an inserting of an item
1020 // results to an automatic adjusting of the item position. In Qt4/KDE4
1021 // this workaround should get obsolete due to Interview.
1022 /*KFileView* view = fileView();
1023 if (view == m_iconsView) {
1024 KFileItem* first = view->firstFileItem();
1026 view->removeItem(first);
1027 view->insertItem(first);
1032 bool DolphinView::isFilterBarVisible()
1034 return m_filterBar
->isVisible();
1037 void DolphinView::applyModeToView()
1039 // TODO: the following code just tries to test some QListView capabilities
1042 m_iconsView
->setViewMode(QListView::IconMode
);
1043 m_iconsView
->setGridSize(QSize(128, 64));
1047 m_iconsView
->setViewMode(QListView::ListMode
);
1048 m_iconsView
->setGridSize(QSize(256, 24));
1052 m_iconsView
->setViewMode(QListView::IconMode
);
1053 m_iconsView
->setGridSize(QSize(128, 128));
1058 #include "dolphinview.moc"