]>
cloud.milkyroute.net Git - dolphin.git/blob - 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> *
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"
25 #include <Q3ValueList>
27 #include <QMouseEvent>
28 #include <Q3VBoxLayout>
31 #include <kio/netaccess.h>
32 #include <kio/renamedlg.h>
35 #include "urlnavigator.h"
36 #include "dolphinstatusbar.h"
38 #include "dolphindirlister.h"
39 #include "viewproperties.h"
40 #include "dolphindetailsview.h"
41 #include "dolphiniconsview.h"
42 #include "dolphincontextmenu.h"
43 #include "undomanager.h"
44 #include "renamedialog.h"
45 #include "progressindicator.h"
47 #include "filterbar.h"
49 DolphinView::DolphinView(QWidget
*parent
,
52 bool showHiddenFiles
) :
55 m_showProgress(false),
65 setFocusPolicy(Qt::StrongFocus
);
66 m_topLayout
= new Q3VBoxLayout(this);
68 Dolphin
& dolphin
= Dolphin::mainWin();
70 connect(this, SIGNAL(signalModeChanged()),
71 &dolphin
, SLOT(slotViewModeChanged()));
72 connect(this, SIGNAL(signalShowHiddenFilesChanged()),
73 &dolphin
, SLOT(slotShowHiddenFilesChanged()));
74 connect(this, SIGNAL(signalSortingChanged(DolphinView::Sorting
)),
75 &dolphin
, SLOT(slotSortingChanged(DolphinView::Sorting
)));
76 connect(this, SIGNAL(signalSortOrderChanged(Qt::SortOrder
)),
77 &dolphin
, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
79 m_urlNavigator
= new URLNavigator(url
, this);
80 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
81 this, SLOT(slotURLChanged(const KUrl
&)));
82 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
83 &dolphin
, SLOT(slotURLChanged(const KUrl
&)));
84 connect(m_urlNavigator
, SIGNAL(historyChanged()),
85 &dolphin
, SLOT(slotHistoryChanged()));
87 m_statusBar
= new DolphinStatusBar(this);
89 m_dirLister
= new DolphinDirLister();
90 m_dirLister
->setAutoUpdate(true);
91 m_dirLister
->setMainWindow(this);
92 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
93 connect(m_dirLister
, SIGNAL(clear()),
94 this, SLOT(slotClear()));
95 connect(m_dirLister
, SIGNAL(percent(int)),
96 this, SLOT(slotPercent(int)));
97 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
98 this, SLOT(slotDeleteItem(KFileItem
*)));
99 connect(m_dirLister
, SIGNAL(completed()),
100 this, SLOT(slotCompleted()));
101 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
102 this, SLOT(slotInfoMessage(const QString
&)));
103 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
104 this, SLOT(slotErrorMessage(const QString
&)));
105 connect(m_dirLister
, SIGNAL(refreshItems(const KFileItemList
&)),
106 this, SLOT(slotRefreshItems(const KFileItemList
&)));
107 connect(m_dirLister
, SIGNAL(redirection(const KUrl
&, const KUrl
&)),
108 this, SIGNAL(redirection(const KUrl
&, const KUrl
&)));
109 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
110 this, SLOT(slotAddItems(const KFileItemList
&)));
112 m_iconSize
= K3Icon::SizeMedium
;
114 m_topLayout
->addWidget(m_urlNavigator
);
117 m_filterBar
= new FilterBar(this);
119 m_topLayout
->addWidget(m_filterBar
);
120 connect(m_filterBar
, SIGNAL(signalFilterChanged(const QString
&)),
121 this, SLOT(slotChangeNameFilter(const QString
&)));
123 m_topLayout
->addWidget(m_statusBar
);
126 DolphinView::~DolphinView()
132 void DolphinView::setURL(const KUrl
& url
)
134 m_urlNavigator
->setURL(url
);
137 const KUrl
& DolphinView::url() const
139 return m_urlNavigator
->url();
142 void DolphinView::requestActivation()
144 Dolphin::mainWin().setActiveView(this);
147 bool DolphinView::isActive() const
149 return (Dolphin::mainWin().activeView() == this);
152 void DolphinView::setMode(Mode mode
)
154 if (mode
== m_mode
) {
155 return; // the wished mode is already set
158 QWidget
* view
= (m_iconsView
!= 0) ? static_cast<QWidget
*>(m_iconsView
) :
159 static_cast<QWidget
*>(m_detailsView
);
161 m_topLayout
->remove(view
);
172 ViewProperties
props(m_urlNavigator
->url());
173 props
.setViewMode(m_mode
);
175 emit
signalModeChanged();
178 DolphinView::Mode
DolphinView::mode() const
183 void DolphinView::setShowHiddenFilesEnabled(bool show
)
185 if (m_dirLister
->showingDotFiles() == show
) {
189 ViewProperties
props(m_urlNavigator
->url());
190 props
.setShowHiddenFilesEnabled(show
);
193 m_dirLister
->setShowingDotFiles(show
);
195 emit
signalShowHiddenFilesChanged();
200 bool DolphinView::isShowHiddenFilesEnabled() const
202 return m_dirLister
->showingDotFiles();
205 void DolphinView::setViewProperties(const ViewProperties
& props
)
207 setMode(props
.viewMode());
208 setSorting(props
.sorting());
209 setSortOrder(props
.sortOrder());
210 setShowHiddenFilesEnabled(props
.isShowHiddenFilesEnabled());
213 void DolphinView::renameSelectedItems()
215 const KUrl::List urls
= selectedURLs();
216 if (urls
.count() > 1) {
217 // More than one item has been selected for renaming. Open
218 // a rename dialog and rename all items afterwards.
219 RenameDialog
dialog(urls
);
220 if (dialog
.exec() == QDialog::Rejected
) {
224 DolphinView
* view
= Dolphin::mainWin().activeView();
225 const QString
& newName
= dialog
.newName();
226 if (newName
.isEmpty()) {
227 view
->statusBar()->setMessage(i18n("The new item name is invalid."),
228 DolphinStatusBar::Error
);
231 UndoManager
& undoMan
= UndoManager::instance();
232 undoMan
.beginMacro();
234 assert(newName
.contains('#'));
236 const int urlsCount
= urls
.count();
237 ProgressIndicator
* progressIndicator
=
238 new ProgressIndicator(i18n("Renaming items..."),
239 i18n("Renaming finished."),
242 // iterate through all selected items and rename them...
243 const int replaceIndex
= newName
.find('#');
244 assert(replaceIndex
>= 0);
245 for (int i
= 0; i
< urlsCount
; ++i
) {
246 const KUrl
& source
= urls
[i
];
247 QString
name(newName
);
248 name
.replace(replaceIndex
, 1, renameIndexPresentation(i
+ 1, urlsCount
));
250 if (source
.fileName() != name
) {
251 KUrl
dest(source
.upUrl());
254 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
256 delete progressIndicator
;
257 progressIndicator
= 0;
258 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).").arg(name
),
259 DolphinStatusBar::Error
);
262 else if (KIO::NetAccess::file_move(source
, dest
)) {
263 // TODO: From the users point of view he executed one 'rename n files' operation,
264 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
265 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
266 undoMan
.addCommand(command
);
270 progressIndicator
->execOperation();
272 delete progressIndicator
;
273 progressIndicator
= 0;
279 // Only one item has been selected for renaming. Use the custom
280 // renaming mechanism from the views.
281 assert(urls
.count() == 1);
282 if (m_mode
== DetailsView
) {
283 Q3ListViewItem
* item
= m_detailsView
->firstChild();
285 if (item
->isSelected()) {
286 m_detailsView
->rename(item
, DolphinDetailsView::NameColumn
);
289 item
= item
->nextSibling();
293 KFileIconViewItem
* item
= static_cast<KFileIconViewItem
*>(m_iconsView
->firstItem());
295 if (item
->isSelected()) {
299 item
= static_cast<KFileIconViewItem
*>(item
->nextItem());
305 void DolphinView::selectAll()
307 fileView()->selectAll();
310 void DolphinView::invertSelection()
312 fileView()->invertSelection();
315 DolphinStatusBar
* DolphinView::statusBar() const
320 int DolphinView::contentsX() const
322 return scrollView()->contentsX();
325 int DolphinView::contentsY() const
327 return scrollView()->contentsY();
330 void DolphinView::refreshSettings()
332 if (m_iconsView
!= 0) {
333 m_iconsView
->refreshSettings();
336 if (m_detailsView
!= 0) {
337 // TODO: There is no usable interface in QListView/KFileDetailView
338 // to hide/show columns. The easiest approach is to delete
339 // the current instance and recreate a new one, which automatically
340 // refreshs the settings. If a proper interface is available in Qt4
341 // m_detailsView->refreshSettings() would be enough.
342 m_topLayout
->remove(m_detailsView
);
343 m_detailsView
->close();
344 m_detailsView
->deleteLater();
351 void DolphinView::updateStatusBar()
353 // As the item count information is less important
354 // in comparison with other messages, it should only
356 // - the status bar is empty or
357 // - shows already the item count information or
358 // - shows only a not very important information
359 // - if any progress is given don't show the item count info at all
360 const QString
msg(m_statusBar
->message());
361 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
362 (msg
== m_statusBar
->defaultText()) ||
363 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
364 (m_statusBar
->progress() == 100);
366 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
367 m_statusBar
->setDefaultText(text
);
369 if (updateStatusBarMsg
) {
370 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
374 void DolphinView::requestItemInfo(const KUrl
& url
)
376 emit
signalRequestItemInfo(url
);
379 bool DolphinView::isURLEditable() const
381 return m_urlNavigator
->isURLEditable();
384 void DolphinView::zoomIn()
386 itemEffectsManager()->zoomIn();
389 void DolphinView::zoomOut()
391 itemEffectsManager()->zoomOut();
394 bool DolphinView::isZoomInPossible() const
396 return itemEffectsManager()->isZoomInPossible();
399 bool DolphinView::isZoomOutPossible() const
401 return itemEffectsManager()->isZoomOutPossible();
404 void DolphinView::setSorting(Sorting sorting
)
406 if (sorting
!= this->sorting()) {
407 KFileView
* view
= fileView();
408 int spec
= view
->sorting() & ~QDir::Name
& ~QDir::Size
& ~QDir::Time
& ~QDir::Unsorted
;
411 case SortByName
: spec
= spec
| QDir::Name
; break;
412 case SortBySize
: spec
= spec
| QDir::Size
; break;
413 case SortByDate
: spec
= spec
| QDir::Time
; break;
417 ViewProperties
props(url());
418 props
.setSorting(sorting
);
420 view
->setSorting(static_cast<QDir::SortSpec
>(spec
));
422 emit
signalSortingChanged(sorting
);
426 DolphinView::Sorting
DolphinView::sorting() const
428 const QDir::SortSpec spec
= fileView()->sorting();
430 if (spec
& QDir::Time
) {
434 if (spec
& QDir::Size
) {
441 void DolphinView::setSortOrder(Qt::SortOrder order
)
443 if (sortOrder() != order
) {
444 KFileView
* view
= fileView();
445 int sorting
= view
->sorting();
446 sorting
= (order
== Qt::Ascending
) ? (sorting
& ~QDir::Reversed
) :
447 (sorting
| QDir::Reversed
);
449 ViewProperties
props(url());
450 props
.setSortOrder(order
);
452 view
->setSorting(static_cast<QDir::SortSpec
>(sorting
));
454 emit
signalSortOrderChanged(order
);
458 Qt::SortOrder
DolphinView::sortOrder() const
460 return fileView()->isReversed() ? Qt::Descending
: Qt::Ascending
;
463 void DolphinView::goBack()
465 m_urlNavigator
->goBack();
468 void DolphinView::goForward()
470 m_urlNavigator
->goForward();
473 void DolphinView::goUp()
475 m_urlNavigator
->goUp();
478 void DolphinView::goHome()
480 m_urlNavigator
->goHome();
483 void DolphinView::setURLEditable(bool editable
)
485 m_urlNavigator
->editURL(editable
);
488 const Q3ValueList
<URLNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
490 return m_urlNavigator
->history(index
);
493 bool DolphinView::hasSelection() const
495 const KFileItemList
* list
= selectedItems();
496 return (list
!= 0) && !list
->isEmpty();
499 const KFileItemList
* DolphinView::selectedItems() const
501 return fileView()->selectedItems();
504 KUrl::List
DolphinView::selectedURLs() const
508 const KFileItemList
* list
= fileView()->selectedItems();
510 KFileItemList::const_iterator it
= list
->begin();
511 const KFileItemList::const_iterator end
= list
->end();
514 urls
.append(item
->url());
522 const KFileItem
* DolphinView::currentFileItem() const
524 return fileView()->currentFileItem();
527 void DolphinView::openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
)
529 DolphinContextMenu
contextMenu(this, fileInfo
, pos
);
533 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
537 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
541 KUrl
dest(source
.upUrl());
542 dest
.addPath(newName
);
544 const bool destExists
= KIO::NetAccess::exists(dest
,
546 Dolphin::mainWin().activeView());
548 // the destination already exists, hence ask the user
550 KIO::RenameDlg
renameDialog(this,
551 i18n("File Already Exists"),
555 switch (renameDialog
.exec()) {
556 case KIO::R_OVERWRITE
:
557 // the destination should be overwritten
558 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
561 case KIO::R_RENAME
: {
562 // a new name for the destination has been used
563 KUrl
newDest(renameDialog
.newDestUrl());
564 ok
= KIO::NetAccess::file_move(source
, newDest
);
569 // the renaming operation has been canceled
575 // no destination exists, hence just move the file to
577 ok
= KIO::NetAccess::file_move(source
, dest
);
581 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.").arg(source
.fileName(), dest
.fileName()),
582 DolphinStatusBar::OperationCompleted
);
584 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
585 UndoManager::instance().addCommand(command
);
588 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.").arg(source
.fileName(), dest
.fileName()),
589 DolphinStatusBar::Error
);
594 void DolphinView::reload()
596 startDirLister(m_urlNavigator
->url(), true);
599 void DolphinView::slotURLListDropped(QDropEvent
* /* event */,
600 const KUrl::List
& urls
,
603 KUrl
destination(url
);
604 if (destination
.isEmpty()) {
605 destination
= m_urlNavigator
->url();
608 // Check whether the destination URL is a directory. If this is not the
609 // case, use the navigator URL as destination (otherwise the destination,
610 // which represents a file, would be replaced by a copy- or move-operation).
611 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, destination
);
612 if (!fileItem
.isDir()) {
613 destination
= m_urlNavigator
->url();
617 Dolphin::mainWin().dropURLs(urls
, destination
);
620 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
622 QWidget::mouseReleaseEvent(event
);
623 Dolphin::mainWin().setActiveView(this);
626 void DolphinView::slotURLChanged(const KUrl
& url
)
628 const ViewProperties
props(url
);
629 setMode(props
.viewMode());
631 const bool showHiddenFiles
= props
.isShowHiddenFilesEnabled();
632 setShowHiddenFilesEnabled(showHiddenFiles
);
633 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
635 setSorting(props
.sorting());
636 setSortOrder(props
.sortOrder());
640 // The selectionChanged signal is not emitted when a new view object is
641 // created. The application does not care whether a view is represented by a
642 // different instance, hence inform the application that the selection might have
643 // changed so that it can update it's actions.
644 Dolphin::mainWin().slotSelectionChanged();
646 emit
signalURLChanged(url
);
649 void DolphinView::triggerIconsViewItem(Q3IconViewItem
* item
)
652 const Qt::ButtonState keyboardState = KApplication::keyboardMouseState();
653 const bool isSelectionActive = ((keyboardState & Qt::ShiftModifier) > 0) ||
654 ((keyboardState & Qt::ControlModifier) > 0);*/
655 const bool isSelectionActive
= false;
656 if ((item
!= 0) && !isSelectionActive
) {
657 // Updating the URL must be done outside the scope of this slot,
658 // as iconview items will get deleted.
659 QTimer::singleShot(0, this, SLOT(updateURL()));
660 Dolphin::mainWin().setActiveView(this);
664 void DolphinView::triggerDetailsViewItem(Q3ListViewItem
* item
,
672 if (m_detailsView
->isOnFilename(item
, pos
)) {
673 // Updating the URL must be done outside the scope of this slot,
674 // as listview items will get deleted.
675 QTimer::singleShot(0, this, SLOT(updateURL()));
676 Dolphin::mainWin().setActiveView(this);
679 m_detailsView
->clearSelection();
683 void DolphinView::triggerDetailsViewItem(Q3ListViewItem
* item
)
685 const QPoint
pos(0, item
->itemPos());
686 triggerDetailsViewItem(item
, pos
, 0);
689 void DolphinView::updateURL()
691 KFileView
* fileView
= (m_iconsView
!= 0) ? static_cast<KFileView
*>(m_iconsView
) :
692 static_cast<KFileView
*>(m_detailsView
);
694 KFileItem
* fileItem
= fileView
->currentFileItem();
699 if (fileItem
->isDir()) {
700 // Prefer the local path over the URL. This assures that the
701 // volume space information is correct. Assuming that the URL is media:/sda1,
702 // and the local path is /windows/C: For the URL the space info is related
703 // to the root partition (and hence wrong) and for the local path the space
704 // info is related to the windows partition (-> correct).
705 const QString
localPath(fileItem
->localPath());
706 if (localPath
.isEmpty()) {
707 setURL(fileItem
->url());
710 setURL(KUrl(localPath
));
718 void DolphinView::slotPercent(int percent
)
720 if (m_showProgress
) {
721 m_statusBar
->setProgress(percent
);
725 void DolphinView::slotClear()
727 fileView()->clearView();
731 void DolphinView::slotDeleteItem(KFileItem
* item
)
733 fileView()->removeItem(item
);
737 void DolphinView::slotCompleted()
741 KFileView
* view
= fileView();
744 // TODO: in Qt4 the code should get a lot
745 // simpler and nicer due to Interview...
746 if (m_iconsView
!= 0) {
747 m_iconsView
->beginItemUpdates();
749 if (m_detailsView
!= 0) {
750 m_detailsView
->beginItemUpdates();
753 if (m_showProgress
) {
754 m_statusBar
->setProgressText(QString::null
);
755 m_statusBar
->setProgress(100);
756 m_showProgress
= false;
759 KFileItemList
items(m_dirLister
->items());
760 KFileItemList::const_iterator it
= items
.begin();
761 const KFileItemList::const_iterator end
= items
.end();
768 view
->insertItem(item
);
780 if (m_iconsView
!= 0) {
781 // Prevent a flickering of the icon view widget by giving a small
782 // timeslot to swallow asynchronous update events.
783 m_iconsView
->setUpdatesEnabled(false);
784 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
787 if (m_detailsView
!= 0) {
788 m_detailsView
->endItemUpdates();
789 m_refreshing
= false;
793 void DolphinView::slotDelayedUpdate()
795 if (m_iconsView
!= 0) {
796 m_iconsView
->setUpdatesEnabled(true);
797 m_iconsView
->endItemUpdates();
799 m_refreshing
= false;
802 void DolphinView::slotInfoMessage(const QString
& msg
)
804 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
807 void DolphinView::slotErrorMessage(const QString
& msg
)
809 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
812 void DolphinView::slotRefreshItems(const KFileItemList
& /* list */)
814 QTimer::singleShot(0, this, SLOT(reload()));
817 void DolphinView::slotAddItems(const KFileItemList
& list
)
819 fileView()->addItemList(list
);
820 fileView()->updateView();
823 void DolphinView::slotGrabActivation()
825 Dolphin::mainWin().setActiveView(this);
828 void DolphinView::slotContentsMoving(int x
, int y
)
831 // Only emit a 'contents moved' signal if the user
832 // moved the content by adjusting the sliders. Adjustments
833 // resulted by refreshing a directory should not be respected.
834 emit
contentsMoved(x
, y
);
838 void DolphinView::createView()
840 assert(m_iconsView
== 0);
841 assert(m_detailsView
== 0);
846 const DolphinIconsView::LayoutMode layoutMode
= (m_mode
== IconsView
) ?
847 DolphinIconsView::Icons
:
848 DolphinIconsView::Previews
;
849 m_iconsView
= new DolphinIconsView(this, layoutMode
);
850 m_topLayout
->insertWidget(1, m_iconsView
);
851 setFocusProxy(m_iconsView
);
853 connect(m_iconsView
, SIGNAL(executed(Q3IconViewItem
*)),
854 this, SLOT(triggerIconsViewItem(Q3IconViewItem
*)));
855 connect(m_iconsView
, SIGNAL(returnPressed(Q3IconViewItem
*)),
856 this, SLOT(triggerIconsViewItem(Q3IconViewItem
*)));
857 connect(m_iconsView
, SIGNAL(signalRequestActivation()),
858 this, SLOT(slotGrabActivation()));
860 m_iconsView
->endItemUpdates();
862 m_iconsView
->setFocus();
867 m_detailsView
= new DolphinDetailsView(this);
868 m_topLayout
->insertWidget(1, m_detailsView
);
869 setFocusProxy(m_detailsView
);
871 connect(m_detailsView
, SIGNAL(executed(Q3ListViewItem
*, const QPoint
&, int)),
872 this, SLOT(triggerDetailsViewItem(Q3ListViewItem
*, const QPoint
&, int)));
873 connect(m_detailsView
, SIGNAL(returnPressed(Q3ListViewItem
*)),
874 this, SLOT(triggerDetailsViewItem(Q3ListViewItem
*)));
875 connect(m_detailsView
, SIGNAL(signalRequestActivation()),
876 this, SLOT(slotGrabActivation()));
877 m_detailsView
->show();
878 m_detailsView
->setFocus();
886 connect(scrollView(), SIGNAL(contentsMoving(int, int)),
887 this, SLOT(slotContentsMoving(int, int)));
889 startDirLister(m_urlNavigator
->url());
892 KFileView
* DolphinView::fileView() const
894 return (m_mode
== DetailsView
) ? static_cast<KFileView
*>(m_detailsView
) :
895 static_cast<KFileView
*>(m_iconsView
);
898 Q3ScrollView
* DolphinView::scrollView() const
900 return (m_mode
== DetailsView
) ? static_cast<Q3ScrollView
*>(m_detailsView
) :
901 static_cast<Q3ScrollView
*>(m_iconsView
);
904 ItemEffectsManager
* DolphinView::itemEffectsManager() const
906 return (m_mode
== DetailsView
) ? static_cast<ItemEffectsManager
*>(m_detailsView
) :
907 static_cast<ItemEffectsManager
*>(m_iconsView
);
910 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
912 if (!url
.isValid()) {
913 const QString
location(url
.pathOrUrl());
914 if (location
.isEmpty()) {
915 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
918 m_statusBar
->setMessage(i18n("The location '%1' is invalid.").arg(location
),
919 DolphinStatusBar::Error
);
924 // Only show the directory loading progress if the status bar does
925 // not contain another progress information. This means that
926 // the directory loading progress information has the lowest priority.
927 const QString
progressText(m_statusBar
->progressText());
928 m_showProgress
= progressText
.isEmpty() ||
929 (progressText
== i18n("Loading directory..."));
930 if (m_showProgress
) {
931 m_statusBar
->setProgressText(i18n("Loading directory..."));
932 m_statusBar
->setProgress(0);
937 m_dirLister
->openUrl(url
, false, reload
);
940 QString
DolphinView::defaultStatusBarText() const
942 // TODO: the following code is not suitable for languages where multiple forms
943 // of plurals are given (e. g. in Poland three forms of plurals exist).
944 const int itemCount
= m_folderCount
+ m_fileCount
;
947 if (itemCount
== 1) {
948 text
= i18n("1 Item");
951 text
= i18n("%1 Items").arg(itemCount
);
956 if (m_folderCount
== 1) {
957 text
+= i18n("1 Folder");
960 text
+= i18n("%1 Folders").arg(m_folderCount
);
965 if (m_fileCount
== 1) {
966 text
+= i18n("1 File");
969 text
+= i18n("%1 Files").arg(m_fileCount
);
977 QString
DolphinView::selectionStatusBarText() const
979 // TODO: the following code is not suitable for languages where multiple forms
980 // of plurals are given (e. g. in Poland three forms of plurals exist).
982 const KFileItemList
* list
= selectedItems();
983 assert((list
!= 0) && !list
->isEmpty());
987 KIO::filesize_t byteSize
= 0;
988 KFileItemList::const_iterator it
= list
->begin();
989 const KFileItemList::const_iterator end
= list
->end();
991 KFileItem
* item
= *it
;
997 byteSize
+= item
->size();
1002 if (folderCount
== 1) {
1003 text
= i18n("1 Folder selected");
1005 else if (folderCount
> 1) {
1006 text
= i18n("%1 Folders selected").arg(folderCount
);
1009 if ((fileCount
> 0) && (folderCount
> 0)) {
1013 const QString
sizeText(KIO::convertSize(byteSize
));
1014 if (fileCount
== 1) {
1015 text
+= i18n("1 File selected (%1)").arg(sizeText
);
1017 else if (fileCount
> 1) {
1018 text
+= i18n("%1 Files selected (%1)").arg(fileCount
).arg(sizeText
);
1024 QString
DolphinView::renameIndexPresentation(int index
, int itemCount
) const
1026 // assure that the string reprentation for all indicess have the same
1027 // number of characters based on the given number of items
1028 QString
str(QString::number(index
));
1030 while (itemCount
>= 10) {
1034 str
.reserve(chrCount
);
1036 const int insertCount
= chrCount
- str
.length();
1037 for (int i
= 0; i
< insertCount
; ++i
) {
1043 void DolphinView::slotShowFilterBar(bool show
)
1045 assert(m_filterBar
!= 0);
1047 m_filterBar
->show();
1050 m_filterBar
->hide();
1054 void DolphinView::slotChangeNameFilter(const QString
& nameFilter
)
1056 // The name filter of KDirLister does a 'hard' filtering, which
1057 // means that only the items are shown where the names match
1058 // exactly the filter. This is non-transparent for the user, which
1059 // just wants to have a 'soft' filtering: does the name contain
1060 // the filter string?
1061 QString
adjustedFilter(nameFilter
);
1062 adjustedFilter
.insert(0, '*');
1063 adjustedFilter
.append('*');
1065 m_dirLister
->setNameFilter(adjustedFilter
);
1066 m_dirLister
->emitChanges();
1068 // TODO: this is a workaround for QIconView: the item position
1069 // stay as they are by filtering, only an inserting of an item
1070 // results to an automatic adjusting of the item position. In Qt4/KDE4
1071 // this workaround should get obsolete due to Interview.
1072 KFileView
* view
= fileView();
1073 if (view
== m_iconsView
) {
1074 KFileItem
* first
= view
->firstFileItem();
1076 view
->removeItem(first
);
1077 view
->insertItem(first
);
1082 bool DolphinView::isFilterBarVisible()
1084 return m_filterBar
->isVisible();
1087 #include "dolphinview.moc"