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),
70 setFocusPolicy(Qt::StrongFocus
);
71 m_topLayout
= new QVBoxLayout(this);
72 m_topLayout
->setSpacing(0);
73 m_topLayout
->setMargin(0);
75 connect(this, SIGNAL(signalModeChanged()),
76 mainWindow
, SLOT(slotViewModeChanged()));
77 connect(this, SIGNAL(signalShowHiddenFilesChanged()),
78 mainWindow
, SLOT(slotShowHiddenFilesChanged()));
79 connect(this, SIGNAL(signalSortingChanged(DolphinView::Sorting
)),
80 mainWindow
, SLOT(slotSortingChanged(DolphinView::Sorting
)));
81 connect(this, SIGNAL(signalSortOrderChanged(Qt::SortOrder
)),
82 mainWindow
, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
84 m_urlNavigator
= new UrlNavigator(url
, this);
85 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
86 this, SLOT(slotUrlChanged(const KUrl
&)));
87 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
88 mainWindow
, SLOT(slotUrlChanged(const KUrl
&)));
89 connect(m_urlNavigator
, SIGNAL(historyChanged()),
90 mainWindow
, SLOT(slotHistoryChanged()));
92 m_statusBar
= new DolphinStatusBar(this);
94 m_dirLister
= new DolphinDirLister();
95 m_dirLister
->setAutoUpdate(true);
96 m_dirLister
->setMainWindow(this);
97 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
98 connect(m_dirLister
, SIGNAL(clear()),
99 this, SLOT(slotClear()));
100 connect(m_dirLister
, SIGNAL(percent(int)),
101 this, SLOT(slotPercent(int)));
102 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
103 this, SLOT(slotDeleteItem(KFileItem
*)));
104 connect(m_dirLister
, SIGNAL(completed()),
105 this, SLOT(slotCompleted()));
106 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
107 this, SLOT(slotInfoMessage(const QString
&)));
108 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
109 this, SLOT(slotErrorMessage(const QString
&)));
111 m_iconsView
= new DolphinIconsView(this);
112 connect(m_iconsView
, SIGNAL(clicked(const QModelIndex
&)),
113 this, SLOT(triggerItem(const QModelIndex
&)));
116 KDirModel
* model
= new KDirModel();
117 model
->setDirLister(m_dirLister
);
118 m_iconsView
->setModel(model
);
120 m_dirLister
->setDelayedMimeTypes(true);
121 new KMimeTypeResolver( m_iconsView
, model
);
123 m_iconSize
= K3Icon::SizeMedium
;
125 m_filterBar
= new FilterBar(mainWindow
, this);
127 connect(m_filterBar
, SIGNAL(signalFilterChanged(const QString
&)),
128 this, SLOT(slotChangeNameFilter(const QString
&)));
130 m_topLayout
->addWidget(m_urlNavigator
);
131 m_topLayout
->addWidget(m_iconsView
);
132 m_topLayout
->addWidget(m_filterBar
);
133 m_topLayout
->addWidget(m_statusBar
);
135 startDirLister(m_urlNavigator
->url());
138 DolphinView::~DolphinView()
144 void DolphinView::setUrl(const KUrl
& url
)
146 m_urlNavigator
->setUrl(url
);
149 const KUrl
& DolphinView::url() const
151 return m_urlNavigator
->url();
154 void DolphinView::requestActivation()
156 mainWindow()->setActiveView(this);
159 bool DolphinView::isActive() const
161 return (mainWindow()->activeView() == this);
164 void DolphinView::setMode(Mode mode
)
166 if (mode
== m_mode
) {
167 return; // the wished mode is already set
172 ViewProperties
props(m_urlNavigator
->url());
173 props
.setViewMode(m_mode
);
176 startDirLister(m_urlNavigator
->url());
178 emit
signalModeChanged();
181 DolphinView::Mode
DolphinView::mode() const
186 void DolphinView::setShowHiddenFilesEnabled(bool show
)
188 if (m_dirLister
->showingDotFiles() == show
) {
192 ViewProperties
props(m_urlNavigator
->url());
193 props
.setShowHiddenFilesEnabled(show
);
196 m_dirLister
->setShowingDotFiles(show
);
198 emit
signalShowHiddenFilesChanged();
203 bool DolphinView::isShowHiddenFilesEnabled() const
205 return m_dirLister
->showingDotFiles();
208 void DolphinView::setViewProperties(const ViewProperties
& props
)
210 setMode(props
.viewMode());
211 setSorting(props
.sorting());
212 setSortOrder(props
.sortOrder());
213 setShowHiddenFilesEnabled(props
.isShowHiddenFilesEnabled());
216 void DolphinView::renameSelectedItems()
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
) {
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
);
234 UndoManager
& undoMan
= UndoManager::instance();
235 undoMan
.beginMacro();
237 assert(newName
.contains('#'));
239 const int urlsCount
= urls
.count();
240 ProgressIndicator
* progressIndicator
=
241 new ProgressIndicator(mainWindow(),
242 i18n("Renaming items..."),
243 i18n("Renaming finished."),
246 // iterate through all selected items and rename them...
247 const int replaceIndex
= newName
.indexOf('#');
248 assert(replaceIndex
>= 0);
249 for (int i
= 0; i
< urlsCount
; ++i
) {
250 const KUrl
& source
= urls
[i
];
251 QString
name(newName
);
252 name
.replace(replaceIndex
, 1, renameIndexPresentation(i
+ 1, urlsCount
));
254 if (source
.fileName() != name
) {
255 KUrl
dest(source
.upUrl());
258 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
260 delete progressIndicator
;
261 progressIndicator
= 0;
262 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name
),
263 DolphinStatusBar::Error
);
266 else if (KIO::NetAccess::file_move(source
, dest
)) {
267 // TODO: From the users point of view he executed one 'rename n files' operation,
268 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
269 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
270 undoMan
.addCommand(command
);
274 progressIndicator
->execOperation();
276 delete progressIndicator
;
277 progressIndicator
= 0;
283 // Only one item has been selected for renaming. Use the custom
284 // renaming mechanism from the views.
285 assert(urls
.count() == 1);
287 /*if (m_mode == DetailsView) {
288 Q3ListViewItem* item = m_iconsView->firstChild();
290 if (item->isSelected()) {
291 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
294 item = item->nextSibling();
298 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
300 if (item->isSelected()) {
304 item = static_cast<KFileIconViewItem*>(item->nextItem());
310 void DolphinView::selectAll()
312 //fileView()->selectAll();
315 void DolphinView::invertSelection()
317 //fileView()->invertSelection();
320 DolphinStatusBar
* DolphinView::statusBar() const
325 int DolphinView::contentsX() const
328 return 0; //scrollView()->contentsX();
331 int DolphinView::contentsY() const
333 return 0; //scrollView()->contentsY();
336 void DolphinView::refreshSettings()
338 startDirLister(m_urlNavigator
->url());
341 void DolphinView::updateStatusBar()
343 // As the item count information is less important
344 // in comparison with other messages, it should only
346 // - the status bar is empty or
347 // - shows already the item count information or
348 // - shows only a not very important information
349 // - if any progress is given don't show the item count info at all
350 const QString
msg(m_statusBar
->message());
351 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
352 (msg
== m_statusBar
->defaultText()) ||
353 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
354 (m_statusBar
->progress() == 100);
356 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
357 m_statusBar
->setDefaultText(text
);
359 if (updateStatusBarMsg
) {
360 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
364 void DolphinView::requestItemInfo(const KUrl
& url
)
366 emit
signalRequestItemInfo(url
);
369 bool DolphinView::isUrlEditable() const
371 return m_urlNavigator
->isUrlEditable();
374 void DolphinView::zoomIn()
376 //itemEffectsManager()->zoomIn();
379 void DolphinView::zoomOut()
381 //itemEffectsManager()->zoomOut();
384 bool DolphinView::isZoomInPossible() const
386 return false; //itemEffectsManager()->isZoomInPossible();
389 bool DolphinView::isZoomOutPossible() const
391 return false; //itemEffectsManager()->isZoomOutPossible();
394 void DolphinView::setSorting(Sorting sorting
)
396 if (sorting
!= this->sorting()) {
397 /*KFileView* view = fileView();
398 int spec = view->sorting() & ~QDir::Name & ~QDir::Size & ~QDir::Time & ~QDir::Unsorted;
401 case SortByName: spec = spec | QDir::Name; break;
402 case SortBySize: spec = spec | QDir::Size; break;
403 case SortByDate: spec = spec | QDir::Time; break;
407 ViewProperties props(url());
408 props.setSorting(sorting);
410 view->setSorting(static_cast<QDir::SortFlags>(spec));
412 emit signalSortingChanged(sorting);*/
416 DolphinView::Sorting
DolphinView::sorting() const
418 /*const QDir::SortFlags spec = fileView()->sorting();
420 if (spec & QDir::Time) {
424 if (spec & QDir::Size) {
431 void DolphinView::setSortOrder(Qt::SortOrder order
)
433 if (sortOrder() != order
) {
434 /*KFileView* view = fileView();
435 int sorting = view->sorting();
436 sorting = (order == Qt::Ascending) ? (sorting & ~QDir::Reversed) :
437 (sorting | QDir::Reversed);
439 ViewProperties props(url());
440 props.setSortOrder(order);
442 view->setSorting(static_cast<QDir::SortFlags>(sorting));
444 emit signalSortOrderChanged(order);*/
448 Qt::SortOrder
DolphinView::sortOrder() const
450 //return fileView()->isReversed() ? Qt::Descending : Qt::Ascending;
451 return Qt::Descending
;
454 void DolphinView::goBack()
456 m_urlNavigator
->goBack();
459 void DolphinView::goForward()
461 m_urlNavigator
->goForward();
464 void DolphinView::goUp()
466 m_urlNavigator
->goUp();
469 void DolphinView::goHome()
471 m_urlNavigator
->goHome();
474 void DolphinView::setUrlEditable(bool editable
)
476 m_urlNavigator
->editUrl(editable
);
479 const Q3ValueList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
481 return m_urlNavigator
->history(index
);
484 bool DolphinView::hasSelection() const
486 return m_iconsView
->selectionModel()->hasSelection();
489 KFileItemList
DolphinView::selectedItems() const
491 QItemSelectionModel
* selModel
= m_iconsView
->selectionModel();
492 assert(selModel
!= 0);
494 KFileItemList itemList
;
495 if (selModel
->hasSelection()) {
496 KDirModel
* dirModel
= static_cast<KDirModel
*>(m_iconsView
->model());
497 const QModelIndexList indexList
= selModel
->selectedIndexes();
499 QModelIndexList::const_iterator end
= indexList
.end();
500 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
501 KFileItem
* item
= dirModel
->itemForIndex(*it
);
503 itemList
.append(item
);
510 KUrl::List
DolphinView::selectedUrls() const
514 const KFileItemList list
= selectedItems();
515 KFileItemList::const_iterator it
= list
.begin();
516 const KFileItemList::const_iterator end
= list
.end();
518 KFileItem
* item
= *it
;
519 urls
.append(item
->url());
526 const KFileItem
* DolphinView::currentFileItem() const
528 return 0; // fileView()->currentFileItem();
531 void DolphinView::openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
)
533 DolphinContextMenu
contextMenu(this, fileInfo
, pos
);
537 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
541 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
545 KUrl
dest(source
.upUrl());
546 dest
.addPath(newName
);
548 const bool destExists
= KIO::NetAccess::exists(dest
,
550 mainWindow()->activeView());
552 // the destination already exists, hence ask the user
554 KIO::RenameDlg
renameDialog(this,
555 i18n("File Already Exists"),
559 switch (renameDialog
.exec()) {
560 case KIO::R_OVERWRITE
:
561 // the destination should be overwritten
562 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
565 case KIO::R_RENAME
: {
566 // a new name for the destination has been used
567 KUrl
newDest(renameDialog
.newDestUrl());
568 ok
= KIO::NetAccess::file_move(source
, newDest
);
573 // the renaming operation has been canceled
579 // no destination exists, hence just move the file to
581 ok
= KIO::NetAccess::file_move(source
, dest
);
585 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), dest
.fileName()),
586 DolphinStatusBar::OperationCompleted
);
588 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
589 UndoManager::instance().addCommand(command
);
592 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), dest
.fileName()),
593 DolphinStatusBar::Error
);
598 void DolphinView::reload()
600 startDirLister(m_urlNavigator
->url(), true);
603 void DolphinView::slotUrlListDropped(QDropEvent
* /* event */,
604 const KUrl::List
& urls
,
607 KUrl
destination(url
);
608 if (destination
.isEmpty()) {
609 destination
= m_urlNavigator
->url();
612 // Check whether the destination Url is a directory. If this is not the
613 // case, use the navigator Url as destination (otherwise the destination,
614 // which represents a file, would be replaced by a copy- or move-operation).
615 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, destination
);
616 if (!fileItem
.isDir()) {
617 destination
= m_urlNavigator
->url();
621 mainWindow()->dropUrls(urls
, destination
);
624 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
626 QWidget::mouseReleaseEvent(event
);
627 mainWindow()->setActiveView(this);
630 DolphinMainWindow
* DolphinView::mainWindow() const
635 void DolphinView::slotUrlChanged(const KUrl
& url
)
637 const ViewProperties
props(url
);
638 setMode(props
.viewMode());
640 const bool showHiddenFiles
= props
.isShowHiddenFilesEnabled();
641 setShowHiddenFilesEnabled(showHiddenFiles
);
642 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
644 setSorting(props
.sorting());
645 setSortOrder(props
.sortOrder());
649 // The selectionChanged signal is not emitted when a new view object is
650 // created. The application does not care whether a view is represented by a
651 // different instance, hence inform the application that the selection might have
652 // changed so that it can update it's actions.
653 mainWindow()->slotSelectionChanged();
655 emit
signalUrlChanged(url
);
658 void DolphinView::triggerIconsViewItem(Q3IconViewItem
* item
)
661 const Qt::ButtonState keyboardState = KApplication::keyboardMouseState();
662 const bool isSelectionActive = ((keyboardState & Qt::ShiftModifier) > 0) ||
663 ((keyboardState & Qt::ControlModifier) > 0);*/
664 const bool isSelectionActive
= false;
665 if ((item
!= 0) && !isSelectionActive
) {
666 // Updating the Url must be done outside the scope of this slot,
667 // as iconview items will get deleted.
668 QTimer::singleShot(0, this, SLOT(updateUrl()));
669 mainWindow()->setActiveView(this);
673 void DolphinView::triggerItem(const QModelIndex
& index
)
675 KDirModel
* dirModel
= static_cast<KDirModel
*>(m_iconsView
->model());
676 KFileItem
* item
= dirModel
->itemForIndex(index
);
682 // Prefer the local path over the Url. This assures that the
683 // volume space information is correct. Assuming that the Url is media:/sda1,
684 // and the local path is /windows/C: For the Url the space info is related
685 // to the root partition (and hence wrong) and for the local path the space
686 // info is related to the windows partition (-> correct).
687 //m_dirLister->stop();
688 //m_dirLister->openUrl(item->url());
691 const QString
localPath(item
->localPath());
692 if (localPath
.isEmpty()) {
696 setUrl(KUrl(localPath
));
704 void DolphinView::updateUrl()
706 //KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) :
707 // static_cast<KFileView*>(m_iconsView);
709 KFileItem
* fileItem
= 0; // TODO: fileView->currentFileItem();
714 if (fileItem
->isDir()) {
715 // Prefer the local path over the Url. This assures that the
716 // volume space information is correct. Assuming that the Url is media:/sda1,
717 // and the local path is /windows/C: For the Url the space info is related
718 // to the root partition (and hence wrong) and for the local path the space
719 // info is related to the windows partition (-> correct).
720 const QString
localPath(fileItem
->localPath());
721 if (localPath
.isEmpty()) {
722 setUrl(fileItem
->url());
725 setUrl(KUrl(localPath
));
733 void DolphinView::slotPercent(int percent
)
735 if (m_showProgress
) {
736 m_statusBar
->setProgress(percent
);
740 void DolphinView::slotClear()
742 //fileView()->clearView();
746 void DolphinView::slotDeleteItem(KFileItem
* item
)
748 //fileView()->removeItem(item);
752 void DolphinView::slotCompleted()
756 //KFileView* view = fileView();
759 // TODO: in Qt4 the code should get a lot
760 // simpler and nicer due to Interview...
761 /*if (m_iconsView != 0) {
762 m_iconsView->beginItemUpdates();
764 if (m_iconsView != 0) {
765 m_iconsView->beginItemUpdates();
768 if (m_showProgress
) {
769 m_statusBar
->setProgressText(QString::null
);
770 m_statusBar
->setProgress(100);
771 m_showProgress
= false;
774 KFileItemList
items(m_dirLister
->items());
775 KFileItemList::const_iterator it
= items
.begin();
776 const KFileItemList::const_iterator end
= items
.end();
782 KFileItem
* item
= *it
;
783 //view->insertItem(item);
795 /*if (m_iconsView != 0) {
796 // Prevent a flickering of the icon view widget by giving a small
797 // timeslot to swallow asynchronous update events.
798 m_iconsView->setUpdatesEnabled(false);
799 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
802 if (m_iconsView != 0) {
803 m_iconsView->endItemUpdates();
804 m_refreshing = false;
808 void DolphinView::slotInfoMessage(const QString
& msg
)
810 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
813 void DolphinView::slotErrorMessage(const QString
& msg
)
815 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
818 void DolphinView::slotGrabActivation()
820 mainWindow()->setActiveView(this);
823 void DolphinView::slotContentsMoving(int x
, int y
)
826 // Only emit a 'contents moved' signal if the user
827 // moved the content by adjusting the sliders. Adjustments
828 // resulted by refreshing a directory should not be respected.
829 emit
contentsMoved(x
, y
);
833 /*KFileView* DolphinView::fileView() const
835 return (m_mode == DetailsView) ? static_cast<KFileView*>(m_iconsView) :
836 static_cast<KFileView*>(m_iconsView);
839 Q3ScrollView
* DolphinView::scrollView() const
841 return 0; //(m_mode == DetailsView) ? static_cast<Q3ScrollView*>(m_iconsView) :
842 // static_cast<Q3ScrollView*>(m_iconsView);
845 ItemEffectsManager
* DolphinView::itemEffectsManager() const
850 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
852 if (!url
.isValid()) {
853 const QString
location(url
.pathOrUrl());
854 if (location
.isEmpty()) {
855 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
858 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
859 DolphinStatusBar::Error
);
864 // Only show the directory loading progress if the status bar does
865 // not contain another progress information. This means that
866 // the directory loading progress information has the lowest priority.
867 const QString
progressText(m_statusBar
->progressText());
868 m_showProgress
= progressText
.isEmpty() ||
869 (progressText
== i18n("Loading directory..."));
870 if (m_showProgress
) {
871 m_statusBar
->setProgressText(i18n("Loading directory..."));
872 m_statusBar
->setProgress(0);
877 m_dirLister
->openUrl(url
, false, reload
);
880 QString
DolphinView::defaultStatusBarText() const
882 // TODO: the following code is not suitable for languages where multiple forms
883 // of plurals are given (e. g. in Poland three forms of plurals exist).
884 const int itemCount
= m_folderCount
+ m_fileCount
;
887 if (itemCount
== 1) {
888 text
= i18n("1 Item");
891 text
= i18n("%1 Items",itemCount
);
896 if (m_folderCount
== 1) {
897 text
+= i18n("1 Folder");
900 text
+= i18n("%1 Folders",m_folderCount
);
905 if (m_fileCount
== 1) {
906 text
+= i18n("1 File");
909 text
+= i18n("%1 Files",m_fileCount
);
917 QString
DolphinView::selectionStatusBarText() const
919 // TODO: the following code is not suitable for languages where multiple forms
920 // of plurals are given (e. g. in Poland three forms of plurals exist).
922 const KFileItemList list
= selectedItems();
923 if (list
.isEmpty()) {
924 // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
925 // DolphinView::hasSelection() is true. Inconsistent behavior?
931 KIO::filesize_t byteSize
= 0;
932 KFileItemList::const_iterator it
= list
.begin();
933 const KFileItemList::const_iterator end
= list
.end();
935 KFileItem
* item
= *it
;
941 byteSize
+= item
->size();
946 if (folderCount
== 1) {
947 text
= i18n("1 Folder selected");
949 else if (folderCount
> 1) {
950 text
= i18n("%1 Folders selected",folderCount
);
953 if ((fileCount
> 0) && (folderCount
> 0)) {
957 const QString
sizeText(KIO::convertSize(byteSize
));
958 if (fileCount
== 1) {
959 text
+= i18n("1 File selected (%1)",sizeText
);
961 else if (fileCount
> 1) {
962 text
+= i18n("%1 Files selected (%1)",fileCount
,sizeText
);
968 QString
DolphinView::renameIndexPresentation(int index
, int itemCount
) const
970 // assure that the string reprentation for all indicess have the same
971 // number of characters based on the given number of items
972 QString
str(QString::number(index
));
974 while (itemCount
>= 10) {
978 str
.reserve(chrCount
);
980 const int insertCount
= chrCount
- str
.length();
981 for (int i
= 0; i
< insertCount
; ++i
) {
987 void DolphinView::slotShowFilterBar(bool show
)
989 assert(m_filterBar
!= 0);
998 void DolphinView::declareViewActive()
1000 mainWindow()->setActiveView( this );
1003 void DolphinView::slotChangeNameFilter(const QString
& nameFilter
)
1005 // The name filter of KDirLister does a 'hard' filtering, which
1006 // means that only the items are shown where the names match
1007 // exactly the filter. This is non-transparent for the user, which
1008 // just wants to have a 'soft' filtering: does the name contain
1009 // the filter string?
1010 QString
adjustedFilter(nameFilter
);
1011 adjustedFilter
.insert(0, '*');
1012 adjustedFilter
.append('*');
1014 m_dirLister
->setNameFilter(adjustedFilter
);
1015 m_dirLister
->emitChanges();
1017 // TODO: this is a workaround for QIconView: the item position
1018 // stay as they are by filtering, only an inserting of an item
1019 // results to an automatic adjusting of the item position. In Qt4/KDE4
1020 // this workaround should get obsolete due to Interview.
1021 /*KFileView* view = fileView();
1022 if (view == m_iconsView) {
1023 KFileItem* first = view->firstFileItem();
1025 view->removeItem(first);
1026 view->insertItem(first);
1031 bool DolphinView::isFilterBarVisible()
1033 return m_filterBar
->isVisible();
1036 void DolphinView::applyModeToView()
1038 // TODO: the following code just tries to test some QListView capabilities
1041 m_iconsView
->setViewMode(QListView::IconMode
);
1042 m_iconsView
->setGridSize(QSize(128, 64));
1046 m_iconsView
->setViewMode(QListView::ListMode
);
1047 m_iconsView
->setGridSize(QSize(256, 24));
1051 m_iconsView
->setViewMode(QListView::IconMode
);
1052 m_iconsView
->setGridSize(QSize(128, 128));
1057 #include "dolphinview.moc"