]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinview.cpp
f17749b8318ea2e01fcaa2a1134ce99b2de264c8
[dolphin.git] / src / views / dolphinview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006-2009 by Peter Penz <peter.penz19@gmail.com> *
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 <QAbstractItemView>
24 #include <QApplication>
25 #include <QBoxLayout>
26 #include <QClipboard>
27 #include <QDropEvent>
28 #include <QGraphicsSceneDragDropEvent>
29 #include <QKeyEvent>
30 #include <QItemSelection>
31 #include <QTimer>
32 #include <QScrollBar>
33
34 #include <KActionCollection>
35 #include <KColorScheme>
36 #include <KDirLister>
37 #include <KDirModel>
38 #include <KIconEffect>
39 #include <KFileItem>
40 #include <KFileItemListProperties>
41 #include <KLocale>
42 #include <kitemviews/kfileitemmodel.h>
43 #include <kitemviews/kfileitemlistview.h>
44 #include <kitemviews/kitemlistselectionmanager.h>
45 #include <kitemviews/kitemlistview.h>
46 #include <kitemviews/kitemlistcontroller.h>
47 #include <KIO/DeleteJob>
48 #include <KIO/NetAccess>
49 #include <KIO/PreviewJob>
50 #include <KJob>
51 #include <KMenu>
52 #include <KMessageBox>
53 #include <konq_fileitemcapabilities.h>
54 #include <konq_operations.h>
55 #include <konqmimedata.h>
56 #include <KToggleAction>
57 #include <KUrl>
58
59 #include "additionalinfoaccessor.h"
60 #include "dolphindirlister.h"
61 #include "dolphinnewfilemenuobserver.h"
62 #include "dolphin_detailsmodesettings.h"
63 #include "dolphin_generalsettings.h"
64 #include "dolphinitemlistcontainer.h"
65 #include "draganddrophelper.h"
66 #include "renamedialog.h"
67 #include "versioncontrol/versioncontrolobserver.h"
68 #include "viewmodecontroller.h"
69 #include "viewproperties.h"
70 #include "views/tooltips/tooltipmanager.h"
71 #include "zoomlevelinfo.h"
72
73 namespace {
74 const int MaxModeEnum = DolphinView::CompactView;
75 const int MaxSortingEnum = DolphinView::SortByPath;
76 };
77
78 DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
79 QWidget(parent),
80 m_active(true),
81 m_tabsForFiles(false),
82 m_assureVisibleCurrentIndex(false),
83 m_isFolderWritable(true),
84 m_url(url),
85 m_mode(DolphinView::IconsView),
86 m_additionalInfoList(),
87 m_topLayout(0),
88 m_dirLister(0),
89 m_container(0),
90 m_toolTipManager(0),
91 m_selectionChangedTimer(0),
92 m_currentItemUrl(),
93 m_restoredContentsPosition(),
94 m_createdItemUrl(),
95 m_selectedUrls(),
96 m_versionControlObserver(0)
97 {
98 m_topLayout = new QVBoxLayout(this);
99 m_topLayout->setSpacing(0);
100 m_topLayout->setMargin(0);
101
102 // When a new item has been created by the "Create New..." menu, the item should
103 // get selected and it must be assured that the item will get visible. As the
104 // creation is done asynchronously, several signals must be checked:
105 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(itemCreated(KUrl)),
106 this, SLOT(observeCreatedItem(KUrl)));
107
108 m_selectionChangedTimer = new QTimer(this);
109 m_selectionChangedTimer->setSingleShot(true);
110 m_selectionChangedTimer->setInterval(300);
111 connect(m_selectionChangedTimer, SIGNAL(timeout()),
112 this, SLOT(emitSelectionChangedSignal()));
113
114 m_dirLister = new DolphinDirLister(this);
115 m_dirLister->setAutoUpdate(true);
116 m_dirLister->setDelayedMimeTypes(true);
117
118 connect(m_dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl)));
119 connect(m_dirLister, SIGNAL(started(KUrl)), this, SLOT(slotDirListerStarted(KUrl)));
120 connect(m_dirLister, SIGNAL(refreshItems(QList<QPair<KFileItem,KFileItem> >)),
121 this, SLOT(slotRefreshItems()));
122
123 connect(m_dirLister, SIGNAL(clear()), this, SIGNAL(itemCountChanged()));
124 connect(m_dirLister, SIGNAL(newItems(KFileItemList)), this, SIGNAL(itemCountChanged()));
125 connect(m_dirLister, SIGNAL(infoMessage(QString)), this, SIGNAL(infoMessage(QString)));
126 connect(m_dirLister, SIGNAL(errorMessage(QString)), this, SIGNAL(infoMessage(QString)));
127 connect(m_dirLister, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int)));
128 connect(m_dirLister, SIGNAL(urlIsFileError(KUrl)), this, SIGNAL(urlIsFileError(KUrl)));
129 connect(m_dirLister, SIGNAL(itemsDeleted(KFileItemList)), this, SIGNAL(itemCountChanged()));
130
131 m_container = new DolphinItemListContainer(m_dirLister, this);
132 m_container->setVisibleRoles(QList<QByteArray>() << "name");
133 m_container->installEventFilter(this);
134 setFocusProxy(m_container);
135 connect(m_container->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip()));
136 connect(m_container->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip()));
137
138 KItemListController* controller = m_container->controller();
139 controller->setSelectionBehavior(KItemListController::MultiSelection);
140 if (GeneralSettings::autoExpandFolders()) {
141 controller->setAutoActivationDelay(750);
142 }
143 connect(controller, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int)));
144 connect(controller, SIGNAL(itemsActivated(QSet<int>)), this, SLOT(slotItemsActivated(QSet<int>)));
145 connect(controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
146 connect(controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF)));
147 connect(controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF)));
148 connect(controller, SIGNAL(headerContextMenuRequested(QPointF)), this, SLOT(slotHeaderContextMenuRequested(QPointF)));
149 connect(controller, SIGNAL(itemPressed(int,Qt::MouseButton)), this, SLOT(hideToolTip()));
150 connect(controller, SIGNAL(itemHovered(int)), this, SLOT(slotItemHovered(int)));
151 connect(controller, SIGNAL(itemUnhovered(int)), this, SLOT(slotItemUnhovered(int)));
152 connect(controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*)));
153 connect(controller, SIGNAL(modelChanged(KItemModelBase*,KItemModelBase*)), this, SLOT(slotModelChanged(KItemModelBase*,KItemModelBase*)));
154
155 KFileItemModel* model = fileItemModel();
156 if (model) {
157 connect(model, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
158 }
159
160 KItemListView* view = controller->view();
161 connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
162 this, SLOT(slotSortOrderChangedByHeader(Qt::SortOrder,Qt::SortOrder)));
163 connect(view, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
164 this, SLOT(slotSortRoleChangedByHeader(QByteArray,QByteArray)));
165
166 KItemListSelectionManager* selectionManager = controller->selectionManager();
167 connect(selectionManager, SIGNAL(selectionChanged(QSet<int>,QSet<int>)),
168 this, SLOT(slotSelectionChanged(QSet<int>,QSet<int>)));
169
170 m_toolTipManager = new ToolTipManager(this);
171
172 m_versionControlObserver = new VersionControlObserver(this);
173 m_versionControlObserver->setModel(model);
174 connect(m_versionControlObserver, SIGNAL(infoMessage(QString)), this, SIGNAL(infoMessage(QString)));
175 connect(m_versionControlObserver, SIGNAL(errorMessage(QString)), this, SIGNAL(errorMessage(QString)));
176 connect(m_versionControlObserver, SIGNAL(operationCompletedMessage(QString)), this, SIGNAL(operationCompletedMessage(QString)));
177
178 applyViewProperties();
179 m_topLayout->addWidget(m_container);
180
181 loadDirectory(url);
182 }
183
184 DolphinView::~DolphinView()
185 {
186 }
187
188 KUrl DolphinView::url() const
189 {
190 return m_url;
191 }
192
193 void DolphinView::setActive(bool active)
194 {
195 if (active == m_active) {
196 return;
197 }
198
199 m_active = active;
200
201 QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
202 if (!active) {
203 color.setAlpha(150);
204 }
205
206 QWidget* viewport = m_container->viewport();
207 if (viewport) {
208 QPalette palette;
209 palette.setColor(viewport->backgroundRole(), color);
210 viewport->setPalette(palette);
211 }
212
213 update();
214
215 if (active) {
216 m_container->setFocus();
217 emit activated();
218 emit writeStateChanged(m_isFolderWritable);
219 }
220 }
221
222 bool DolphinView::isActive() const
223 {
224 return m_active;
225 }
226
227 void DolphinView::setMode(Mode mode)
228 {
229 if (mode != m_mode) {
230 ViewProperties props(url());
231 props.setViewMode(mode);
232 props.save();
233
234 applyViewProperties();
235 }
236 }
237
238 DolphinView::Mode DolphinView::mode() const
239 {
240 return m_mode;
241 }
242
243 void DolphinView::setPreviewsShown(bool show)
244 {
245 if (previewsShown() == show) {
246 return;
247 }
248
249 ViewProperties props(url());
250 props.setPreviewsShown(show);
251
252 m_container->setPreviewsShown(show);
253 emit previewsShownChanged(show);
254 }
255
256 bool DolphinView::previewsShown() const
257 {
258 return m_container->previewsShown();
259 }
260
261 void DolphinView::setHiddenFilesShown(bool show)
262 {
263 if (m_dirLister->showingDotFiles() == show) {
264 return;
265 }
266
267 const KFileItemList itemList = selectedItems();
268 m_selectedUrls.clear();
269 m_selectedUrls = itemList.urlList();
270
271 ViewProperties props(url());
272 props.setHiddenFilesShown(show);
273
274 fileItemModel()->setShowHiddenFiles(show);
275 emit hiddenFilesShownChanged(show);
276 }
277
278 bool DolphinView::hiddenFilesShown() const
279 {
280 return m_dirLister->showingDotFiles();
281 }
282
283 void DolphinView::setGroupedSorting(bool grouped)
284 {
285 if (grouped == groupedSorting()) {
286 return;
287 }
288
289 ViewProperties props(url());
290 props.setGroupedSorting(grouped);
291 props.save();
292
293 m_container->controller()->model()->setGroupedSorting(grouped);
294
295 emit groupedSortingChanged(grouped);
296 }
297
298 bool DolphinView::groupedSorting() const
299 {
300 return fileItemModel()->groupedSorting();
301 }
302
303 KFileItemList DolphinView::items() const
304 {
305 return m_dirLister->items();
306 }
307
308 KFileItemList DolphinView::selectedItems() const
309 {
310 const KFileItemModel* model = fileItemModel();
311 const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
312 const QSet<int> selectedIndexes = selectionManager->selectedItems();
313
314 QList<int> sortedIndexes = selectedIndexes.toList();
315 qSort(sortedIndexes);
316
317 KFileItemList selectedItems;
318 QListIterator<int> it(sortedIndexes);
319 while (it.hasNext()) {
320 const int index = it.next();
321 selectedItems.append(model->fileItem(index));
322 }
323 return selectedItems;
324 }
325
326 int DolphinView::selectedItemsCount() const
327 {
328 const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
329 return selectionManager->selectedItems().count();
330 }
331
332 void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
333 {
334 m_selectedUrls = urls;
335 }
336
337 void DolphinView::markUrlAsCurrent(const KUrl& url)
338 {
339 m_currentItemUrl = url;
340 }
341
342 void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled)
343 {
344 const KItemListSelectionManager::SelectionMode mode = enabled
345 ? KItemListSelectionManager::Select
346 : KItemListSelectionManager::Deselect;
347 const KFileItemModel* model = fileItemModel();
348 KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
349
350 for (int index = 0; index < model->count(); index++) {
351 const KFileItem item = model->fileItem(index);
352 if (pattern.exactMatch(item.text())) {
353 // An alternative approach would be to store the matching items in a QSet<int> and
354 // select them in one go after the loop, but we'd need a new function
355 // KItemListSelectionManager::setSelected(QSet<int>, SelectionMode mode)
356 // for that.
357 selectionManager->setSelected(index, 1, mode);
358 }
359 }
360 }
361
362 void DolphinView::setZoomLevel(int level)
363 {
364 const int oldZoomLevel = zoomLevel();
365 m_container->setZoomLevel(level);
366 if (zoomLevel() != oldZoomLevel) {
367 emit zoomLevelChanged(zoomLevel(), oldZoomLevel);
368 }
369 }
370
371 int DolphinView::zoomLevel() const
372 {
373 return m_container->zoomLevel();
374 }
375
376 void DolphinView::setSorting(Sorting sorting)
377 {
378 if (sorting != this->sorting()) {
379 updateSorting(sorting);
380 }
381 }
382
383 DolphinView::Sorting DolphinView::sorting() const
384 {
385 KItemModelBase* model = m_container->controller()->model();
386 return sortingForSortRole(model->sortRole());
387 }
388
389 void DolphinView::setSortOrder(Qt::SortOrder order)
390 {
391 if (sortOrder() != order) {
392 updateSortOrder(order);
393 }
394 }
395
396 Qt::SortOrder DolphinView::sortOrder() const
397 {
398 KItemModelBase* model = fileItemModel();
399 return model->sortOrder();
400 }
401
402 void DolphinView::setSortFoldersFirst(bool foldersFirst)
403 {
404 if (sortFoldersFirst() != foldersFirst) {
405 updateSortFoldersFirst(foldersFirst);
406 }
407 }
408
409 bool DolphinView::sortFoldersFirst() const
410 {
411 KFileItemModel* model = fileItemModel();
412 return model->sortFoldersFirst();
413 }
414
415 void DolphinView::setAdditionalInfoList(const QList<AdditionalInfo>& info)
416 {
417 const QList<AdditionalInfo> previousList = info;
418
419 ViewProperties props(url());
420 props.setAdditionalInfoList(info);
421
422 m_additionalInfoList = info;
423 applyAdditionalInfoListToView();
424
425 emit additionalInfoListChanged(m_additionalInfoList, previousList);
426 }
427
428 QList<DolphinView::AdditionalInfo> DolphinView::additionalInfoList() const
429 {
430 return m_additionalInfoList;
431 }
432
433 void DolphinView::reload()
434 {
435 QByteArray viewState;
436 QDataStream saveStream(&viewState, QIODevice::WriteOnly);
437 saveState(saveStream);
438
439 const KFileItemList itemList = selectedItems();
440 m_selectedUrls.clear();
441 m_selectedUrls = itemList.urlList();
442
443 setUrl(url());
444 loadDirectory(url(), true);
445
446 QDataStream restoreStream(viewState);
447 restoreState(restoreStream);
448 }
449
450 void DolphinView::stopLoading()
451 {
452 m_dirLister->stop();
453 }
454
455 void DolphinView::refresh()
456 {
457 GeneralSettings::self()->readConfig();
458 m_container->refresh();
459 applyViewProperties();
460 }
461
462 void DolphinView::setNameFilter(const QString& nameFilter)
463 {
464 fileItemModel()->setNameFilter(nameFilter);
465 }
466
467 QString DolphinView::nameFilter() const
468 {
469 return fileItemModel()->nameFilter();
470 }
471
472 void DolphinView::calculateItemCount(int& fileCount,
473 int& folderCount,
474 KIO::filesize_t& totalFileSize) const
475 {
476 foreach (const KFileItem& item, m_dirLister->items()) {
477 if (item.isDir()) {
478 ++folderCount;
479 } else {
480 ++fileCount;
481 totalFileSize += item.size();
482 }
483 }
484 }
485
486 QString DolphinView::statusBarText() const
487 {
488 QString summary;
489 QString foldersText;
490 QString filesText;
491
492 int folderCount = 0;
493 int fileCount = 0;
494 KIO::filesize_t totalFileSize = 0;
495
496 if (hasSelection()) {
497 // Give a summary of the status of the selected files
498 const KFileItemList list = selectedItems();
499 foreach (const KFileItem& item, list) {
500 if (item.isDir()) {
501 ++folderCount;
502 } else {
503 ++fileCount;
504 totalFileSize += item.size();
505 }
506 }
507
508 if (folderCount + fileCount == 1) {
509 // If only one item is selected, show the filename
510 filesText = i18nc("@info:status", "<filename>%1</filename> selected", list.first().text());
511 } else {
512 // At least 2 items are selected
513 foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
514 filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount);
515 }
516 } else {
517 calculateItemCount(fileCount, folderCount, totalFileSize);
518 foldersText = i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount);
519 filesText = i18ncp("@info:status", "1 File", "%1 Files", fileCount);
520 }
521
522 if (fileCount > 0 && folderCount > 0) {
523 summary = i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
524 foldersText, filesText, fileSizeText(totalFileSize));
525 } else if (fileCount > 0) {
526 summary = i18nc("@info:status files (size)", "%1 (%2)", filesText, fileSizeText(totalFileSize));
527 } else if (folderCount > 0) {
528 summary = foldersText;
529 }
530
531 return summary;
532 }
533
534 QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) const
535 {
536 QList<QAction*> actions;
537
538 if (items.isEmpty()) {
539 const KFileItem item = fileItemModel()->rootItem();
540 actions = m_versionControlObserver->actions(KFileItemList() << item);
541 } else {
542 actions = m_versionControlObserver->actions(items);
543 }
544
545 return actions;
546 }
547
548 void DolphinView::setUrl(const KUrl& url)
549 {
550 if (url == m_url) {
551 return;
552 }
553
554 emit urlAboutToBeChanged(url);
555 m_url = url;
556
557 hideToolTip();
558
559 // It is important to clear the items from the model before
560 // applying the view properties, otherwise expensive operations
561 // might be done on the existing items although they get cleared
562 // anyhow afterwards by loadDirectory().
563 fileItemModel()->clear();
564 applyViewProperties();
565 loadDirectory(url);
566
567 emit urlChanged(url);
568 }
569
570 void DolphinView::selectAll()
571 {
572 KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
573 selectionManager->setSelected(0, fileItemModel()->count());
574 }
575
576 void DolphinView::invertSelection()
577 {
578 KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
579 selectionManager->setSelected(0, fileItemModel()->count(), KItemListSelectionManager::Toggle);
580 }
581
582 void DolphinView::clearSelection()
583 {
584 m_container->controller()->selectionManager()->clearSelection();
585 }
586
587 void DolphinView::renameSelectedItems()
588 {
589 KFileItemList items = selectedItems();
590 const int itemCount = items.count();
591 if (itemCount < 1) {
592 return;
593 }
594
595 // TODO: The new view-engine introduced with Dolphin 2.0 does not support inline
596 // renaming yet.
597 /*if ((itemCount == 1) && DolphinSettings::instance().generalSettings()->renameInline()) {
598 const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForItem(items.first());
599 const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex);
600 m_viewAccessor.itemView()->edit(proxyIndex);
601 } else {*/
602 RenameDialog* dialog = new RenameDialog(this, items);
603 dialog->setAttribute(Qt::WA_DeleteOnClose);
604 dialog->show();
605 dialog->raise();
606 dialog->activateWindow();
607 //}
608
609 // assure that the current index remains visible when KDirLister
610 // will notify the view about changed items
611 m_assureVisibleCurrentIndex = true;
612 }
613
614 void DolphinView::trashSelectedItems()
615 {
616 const KUrl::List list = simplifiedSelectedUrls();
617 KonqOperations::del(this, KonqOperations::TRASH, list);
618 }
619
620 void DolphinView::deleteSelectedItems()
621 {
622 const KUrl::List list = simplifiedSelectedUrls();
623 const bool del = KonqOperations::askDeleteConfirmation(list,
624 KonqOperations::DEL,
625 KonqOperations::DEFAULT_CONFIRMATION,
626 this);
627
628 if (del) {
629 KIO::Job* job = KIO::del(list);
630 connect(job, SIGNAL(result(KJob*)),
631 this, SLOT(slotDeleteFileFinished(KJob*)));
632 }
633 }
634
635 void DolphinView::cutSelectedItems()
636 {
637 QMimeData* mimeData = selectionMimeData();
638 KonqMimeData::addIsCutSelection(mimeData, true);
639 QApplication::clipboard()->setMimeData(mimeData);
640 }
641
642 void DolphinView::copySelectedItems()
643 {
644 QMimeData* mimeData = selectionMimeData();
645 QApplication::clipboard()->setMimeData(mimeData);
646 }
647
648 void DolphinView::paste()
649 {
650 pasteToUrl(url());
651 }
652
653 void DolphinView::pasteIntoFolder()
654 {
655 const KFileItemList items = selectedItems();
656 if ((items.count() == 1) && items.first().isDir()) {
657 pasteToUrl(items.first().url());
658 }
659 }
660
661 bool DolphinView::eventFilter(QObject* watched, QEvent* event)
662 {
663 switch (event->type()) {
664 case QEvent::FocusIn:
665 if (watched == m_container) {
666 setActive(true);
667 }
668 break;
669
670 default:
671 break;
672 }
673
674 return QWidget::eventFilter(watched, event);
675 }
676
677 void DolphinView::wheelEvent(QWheelEvent* event)
678 {
679 if (event->modifiers().testFlag(Qt::ControlModifier)) {
680 const int numDegrees = event->delta() / 8;
681 const int numSteps = numDegrees / 15;
682
683 setZoomLevel(zoomLevel() + numSteps);
684 event->accept();
685 } else {
686 event->ignore();
687 }
688 }
689
690 void DolphinView::activate()
691 {
692 setActive(true);
693 }
694
695 void DolphinView::slotItemActivated(int index)
696 {
697 const KFileItem item = fileItemModel()->fileItem(index);
698 if (!item.isNull()) {
699 emit itemActivated(item);
700 }
701 }
702
703 void DolphinView::slotItemsActivated(const QSet<int>& indexes)
704 {
705 Q_ASSERT(indexes.count() >= 2);
706
707 KFileItemList items;
708
709 KFileItemModel* model = fileItemModel();
710 QSetIterator<int> it(indexes);
711 while (it.hasNext()) {
712 const int index = it.next();
713 items.append(model->fileItem(index));
714 }
715
716 foreach (const KFileItem& item, items) {
717 if (item.isDir()) {
718 emit tabRequested(item.url());
719 } else {
720 emit itemActivated(item);
721 }
722 }
723 }
724
725 void DolphinView::slotItemMiddleClicked(int index)
726 {
727 const KFileItem item = fileItemModel()->fileItem(index);
728 if (item.isDir() || isTabsForFilesEnabled()) {
729 emit tabRequested(item.url());
730 }
731 }
732
733 void DolphinView::slotItemContextMenuRequested(int index, const QPointF& pos)
734 {
735 const KFileItem item = fileItemModel()->fileItem(index);
736 emit requestContextMenu(pos.toPoint(), item, url(), QList<QAction*>());
737 }
738
739 void DolphinView::slotViewContextMenuRequested(const QPointF& pos)
740 {
741 emit requestContextMenu(pos.toPoint(), KFileItem(), url(), QList<QAction*>());
742 }
743
744 void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
745 {
746 QWeakPointer<KMenu> menu = new KMenu(QApplication::activeWindow());
747
748 KItemListView* view = m_container->controller()->view();
749 const QSet<QByteArray> visibleRolesSet = view->visibleRoles().toSet();
750
751 // Add all roles to the menu that can be shown or hidden by the user
752 const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance();
753 const QList<DolphinView::AdditionalInfo> keys = infoAccessor.keys();
754 foreach (const DolphinView::AdditionalInfo info, keys) {
755 const QByteArray& role = infoAccessor.role(info);
756 if (role != "name") {
757 const QString text = fileItemModel()->roleDescription(role);
758
759 QAction* action = menu.data()->addAction(text);
760 action->setCheckable(true);
761 action->setChecked(visibleRolesSet.contains(role));
762 action->setData(info);
763 }
764 }
765
766 QAction* action = menu.data()->exec(pos.toPoint());
767 if (action) {
768 // Show or hide the selected role
769 const DolphinView::AdditionalInfo info =
770 static_cast<DolphinView::AdditionalInfo>(action->data().toInt());
771
772 ViewProperties props(url());
773 QList<DolphinView::AdditionalInfo> infoList = props.additionalInfoList();
774
775 const QByteArray selectedRole = infoAccessor.role(info);
776 QList<QByteArray> visibleRoles = view->visibleRoles();
777
778 if (action->isChecked()) {
779 const int index = keys.indexOf(info) + 1;
780 visibleRoles.insert(index, selectedRole);
781 infoList.insert(index, info);
782 } else {
783 visibleRoles.removeOne(selectedRole);
784 infoList.removeOne(info);
785 }
786
787 view->setVisibleRoles(visibleRoles);
788 props.setAdditionalInfoList(infoList);
789 }
790
791 delete menu.data();
792 }
793
794 void DolphinView::slotItemHovered(int index)
795 {
796 const KFileItem item = fileItemModel()->fileItem(index);
797
798 if (GeneralSettings::showToolTips() && QApplication::mouseButtons() == Qt::NoButton) {
799 QRectF itemRect = m_container->controller()->view()->itemContextRect(index);
800 const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint());
801 itemRect.moveTo(pos);
802
803 m_toolTipManager->showToolTip(item, itemRect);
804 }
805
806 emit requestItemInfo(item);
807 }
808
809 void DolphinView::slotItemUnhovered(int index)
810 {
811 Q_UNUSED(index);
812 hideToolTip();
813 emit requestItemInfo(KFileItem());
814 }
815
816 void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
817 {
818 KFileItem destItem = fileItemModel()->fileItem(index);
819 if (destItem.isNull()) {
820 destItem = fileItemModel()->rootItem();
821 if (destItem.isNull()) {
822 kWarning() << "No destination item available for drop operation.";
823 return;
824 }
825 }
826
827 QDropEvent dropEvent(event->pos().toPoint(),
828 event->possibleActions(),
829 event->mimeData(),
830 event->buttons(),
831 event->modifiers());
832
833 const QString error = DragAndDropHelper::dropUrls(destItem, &dropEvent);
834 if (!error.isEmpty()) {
835 emit errorMessage(error);
836 }
837 }
838
839 void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous)
840 {
841 if (previous != 0) {
842 disconnect(previous, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
843 }
844
845 Q_ASSERT(qobject_cast<KFileItemModel*>(current));
846 connect(current, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
847
848 KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(current);
849 m_versionControlObserver->setModel(fileItemModel);
850 }
851
852 void DolphinView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
853 {
854 const int currentCount = current.count();
855 const int previousCount = previous.count();
856 const bool selectionStateChanged = (currentCount == 0 && previousCount > 0) ||
857 (currentCount > 0 && previousCount == 0);
858
859 // If nothing has been selected before and something got selected (or if something
860 // was selected before and now nothing is selected) the selectionChangedSignal must
861 // be emitted asynchronously as fast as possible to update the edit-actions.
862 m_selectionChangedTimer->setInterval(selectionStateChanged ? 0 : 300);
863 m_selectionChangedTimer->start();
864 }
865
866 void DolphinView::emitSelectionChangedSignal()
867 {
868 m_selectionChangedTimer->stop();
869 emit selectionChanged(selectedItems());
870 }
871
872 void DolphinView::dropUrls(const KFileItem& destItem,
873 const KUrl& destPath,
874 QDropEvent* event)
875 {
876 Q_UNUSED(destItem);
877 Q_UNUSED(destPath);
878 markPastedUrlsAsSelected(event->mimeData());
879 //DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
880 }
881
882 void DolphinView::updateSorting(DolphinView::Sorting sorting)
883 {
884 ViewProperties props(url());
885 props.setSorting(sorting);
886
887 KItemModelBase* model = m_container->controller()->model();
888 model->setSortRole(sortRoleForSorting(sorting));
889
890 emit sortingChanged(sorting);
891 }
892
893 void DolphinView::updateSortOrder(Qt::SortOrder order)
894 {
895 ViewProperties props(url());
896 props.setSortOrder(order);
897
898 KItemModelBase* model = fileItemModel();
899 model->setSortOrder(order);
900
901 emit sortOrderChanged(order);
902 }
903
904 void DolphinView::updateSortFoldersFirst(bool foldersFirst)
905 {
906 ViewProperties props(url());
907 props.setSortFoldersFirst(foldersFirst);
908
909 KFileItemModel* model = fileItemModel();
910 model->setSortFoldersFirst(foldersFirst);
911
912 emit sortFoldersFirstChanged(foldersFirst);
913 }
914
915 QPair<bool, QString> DolphinView::pasteInfo() const
916 {
917 return KonqOperations::pasteInfo(url());
918 }
919
920 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles)
921 {
922 m_tabsForFiles = tabsForFiles;
923 }
924
925 bool DolphinView::isTabsForFilesEnabled() const
926 {
927 return m_tabsForFiles;
928 }
929
930 bool DolphinView::itemsExpandable() const
931 {
932 return m_mode == DetailsView;
933 }
934
935 void DolphinView::restoreState(QDataStream& stream)
936 {
937 // Restore the current item that had the keyboard focus
938 stream >> m_currentItemUrl;
939
940 // Restore the view position
941 stream >> m_restoredContentsPosition;
942
943 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
944 QSet<KUrl> urls;
945 stream >> urls;
946 fileItemModel()->restoreExpandedUrls(urls);
947 }
948
949 void DolphinView::saveState(QDataStream& stream)
950 {
951 // Save the current item that has the keyboard focus
952 const int currentIndex = m_container->controller()->selectionManager()->currentItem();
953 if (currentIndex != -1) {
954 KFileItem item = fileItemModel()->fileItem(currentIndex);
955 Q_ASSERT(!item.isNull()); // If the current index is valid a item must exist
956 KUrl currentItemUrl = item.url();
957 stream << currentItemUrl;
958 } else {
959 stream << KUrl();
960 }
961
962 // Save view position
963 const qreal x = m_container->horizontalScrollBar()->value();
964 const qreal y = m_container->verticalScrollBar()->value();
965 stream << QPoint(x, y);
966
967 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
968 stream << fileItemModel()->expandedUrls();
969 }
970
971 bool DolphinView::hasSelection() const
972 {
973 return m_container->controller()->selectionManager()->hasSelection();
974 }
975
976 KFileItem DolphinView::rootItem() const
977 {
978 return m_dirLister->rootItem();
979 }
980
981 void DolphinView::observeCreatedItem(const KUrl& url)
982 {
983 m_createdItemUrl = url;
984 //connect(m_dirModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
985 // this, SLOT(selectAndScrollToCreatedItem()));
986 }
987
988 void DolphinView::selectAndScrollToCreatedItem()
989 {
990 /*const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForUrl(m_createdItemUrl);
991 if (dirIndex.isValid()) {
992 const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex);
993 QAbstractItemView* view = m_viewAccessor.itemView();
994 if (view) {
995 view->setCurrentIndex(proxyIndex);
996 }
997 }
998
999 disconnect(m_viewAccessor.dirModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
1000 this, SLOT(selectAndScrollToCreatedItem()));*/
1001 m_createdItemUrl = KUrl();
1002 }
1003
1004 void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
1005 {
1006 if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash)) {
1007 emit redirection(oldUrl, newUrl);
1008 m_url = newUrl; // #186947
1009 }
1010 }
1011
1012 void DolphinView::updateViewState()
1013 {
1014 if (m_currentItemUrl != KUrl()) {
1015 KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
1016 const int currentIndex = fileItemModel()->index(m_currentItemUrl);
1017 if (currentIndex != -1) {
1018 selectionManager->setCurrentItem(currentIndex);
1019 } else {
1020 selectionManager->setCurrentItem(0);
1021 }
1022 m_currentItemUrl = KUrl();
1023 }
1024
1025 if (!m_restoredContentsPosition.isNull()) {
1026 const int x = m_restoredContentsPosition.x();
1027 const int y = m_restoredContentsPosition.y();
1028 m_restoredContentsPosition = QPoint();
1029
1030 m_container->horizontalScrollBar()->setValue(x);
1031 m_container->verticalScrollBar()->setValue(y);
1032 }
1033
1034 if (!m_selectedUrls.isEmpty()) {
1035 KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
1036 QSet<int> selectedItems = selectionManager->selectedItems();
1037 const KFileItemModel* model = fileItemModel();
1038
1039 foreach (const KUrl& url, m_selectedUrls) {
1040 const int index = model->index(url);
1041 if (index >= 0) {
1042 selectedItems.insert(index);
1043 }
1044 }
1045
1046 selectionManager->setSelectedItems(selectedItems);
1047 m_selectedUrls.clear();
1048 }
1049 }
1050
1051 void DolphinView::hideToolTip()
1052 {
1053 if (GeneralSettings::showToolTips()) {
1054 m_toolTipManager->hideToolTip();
1055 }
1056 }
1057
1058 void DolphinView::showHoverInformation(const KFileItem& item)
1059 {
1060 emit requestItemInfo(item);
1061 }
1062
1063 void DolphinView::clearHoverInformation()
1064 {
1065 emit requestItemInfo(KFileItem());
1066 }
1067
1068 void DolphinView::slotDeleteFileFinished(KJob* job)
1069 {
1070 if (job->error() == 0) {
1071 emit operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1072 } else if (job->error() != KIO::ERR_USER_CANCELED) {
1073 emit errorMessage(job->errorString());
1074 }
1075 }
1076
1077 void DolphinView::slotDirListerStarted(const KUrl& url)
1078 {
1079 // Disable the writestate temporary until it can be determined in a fast way
1080 // in DolphinView::slotLoadingCompleted()
1081 if (m_isFolderWritable) {
1082 m_isFolderWritable = false;
1083 emit writeStateChanged(m_isFolderWritable);
1084 }
1085
1086 emit startedPathLoading(url);
1087 }
1088
1089 void DolphinView::slotLoadingCompleted()
1090 {
1091 // Update the view-state. This has to be done using a Qt::QueuedConnection
1092 // because the view might not be in its final state yet (the view also
1093 // listens to the completed()-signal from KDirLister and the order of
1094 // of slots is undefined).
1095 QTimer::singleShot(0, this, SLOT(updateViewState()));
1096
1097 emit finishedPathLoading(url());
1098
1099 updateWritableState();
1100 }
1101
1102 void DolphinView::slotRefreshItems()
1103 {
1104 if (m_assureVisibleCurrentIndex) {
1105 m_assureVisibleCurrentIndex = false;
1106 //QAbstractItemView* view = m_viewAccessor.itemView();
1107 //if (view) {
1108 // m_viewAccessor.itemView()->scrollTo(m_viewAccessor.itemView()->currentIndex());
1109 //}
1110 }
1111 }
1112
1113 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOrder previous)
1114 {
1115 Q_UNUSED(previous);
1116 Q_ASSERT(fileItemModel()->sortOrder() == current);
1117
1118 ViewProperties props(url());
1119 props.setSortOrder(current);
1120
1121 emit sortOrderChanged(current);
1122 }
1123
1124 void DolphinView::slotSortRoleChangedByHeader(const QByteArray& current, const QByteArray& previous)
1125 {
1126 Q_UNUSED(previous);
1127 Q_ASSERT(fileItemModel()->sortRole() == current);
1128
1129 ViewProperties props(url());
1130 const Sorting sorting = sortingForSortRole(current);
1131 props.setSorting(sorting);
1132
1133 emit sortingChanged(sorting);
1134 }
1135
1136 KFileItemModel* DolphinView::fileItemModel() const
1137 {
1138 return static_cast<KFileItemModel*>(m_container->controller()->model());
1139 }
1140
1141 void DolphinView::loadDirectory(const KUrl& url, bool reload)
1142 {
1143 if (!url.isValid()) {
1144 const QString location(url.pathOrUrl());
1145 if (location.isEmpty()) {
1146 emit errorMessage(i18nc("@info:status", "The location is empty."));
1147 } else {
1148 emit errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location));
1149 }
1150 return;
1151 }
1152
1153 m_dirLister->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
1154 }
1155
1156 void DolphinView::applyViewProperties()
1157 {
1158 m_container->beginTransaction();
1159
1160 const ViewProperties props(url());
1161 KFileItemModel* model = fileItemModel();
1162
1163 const Mode mode = props.viewMode();
1164 if (m_mode != mode) {
1165 // Prevent an animated transition of the position and size of the items when switching
1166 // the view-mode by temporary clearing the model and updating it again after the view mode
1167 // has been modified.
1168 const bool restoreModel = (model->count() > 0);
1169 if (restoreModel) {
1170 const int currentItemIndex = m_container->controller()->selectionManager()->currentItem();
1171 if (currentItemIndex >= 0) {
1172 m_currentItemUrl = model->fileItem(currentItemIndex).url();
1173 }
1174 m_selectedUrls = selectedItems().urlList();
1175 model->clear();
1176 }
1177
1178 const Mode previousMode = m_mode;
1179 m_mode = mode;
1180
1181 // Changing the mode might result in changing
1182 // the zoom level. Remember the old zoom level so
1183 // that zoomLevelChanged() can get emitted.
1184 const int oldZoomLevel = m_container->zoomLevel();
1185
1186 switch (m_mode) {
1187 case IconsView: m_container->setItemLayout(KFileItemListView::IconsLayout); break;
1188 case CompactView: m_container->setItemLayout(KFileItemListView::CompactLayout); break;
1189 case DetailsView: m_container->setItemLayout(KFileItemListView::DetailsLayout); break;
1190 default: Q_ASSERT(false); break;
1191 }
1192
1193 emit modeChanged(m_mode, previousMode);
1194
1195 if (m_container->zoomLevel() != oldZoomLevel) {
1196 emit zoomLevelChanged(m_container->zoomLevel(), oldZoomLevel);
1197 }
1198
1199 if (restoreModel) {
1200 loadDirectory(url());
1201 }
1202 }
1203
1204 const bool hiddenFilesShown = props.hiddenFilesShown();
1205 if (hiddenFilesShown != model->showHiddenFiles()) {
1206 model->setShowHiddenFiles(hiddenFilesShown);
1207 emit hiddenFilesShownChanged(hiddenFilesShown);
1208 }
1209
1210 const bool groupedSorting = props.groupedSorting();
1211 if (groupedSorting != model->groupedSorting()) {
1212 model->setGroupedSorting(groupedSorting);
1213 emit groupedSortingChanged(groupedSorting);
1214 }
1215
1216 const DolphinView::Sorting sorting = props.sorting();
1217 const QByteArray newSortRole = sortRoleForSorting(sorting);
1218 if (newSortRole != model->sortRole()) {
1219 model->setSortRole(newSortRole);
1220 emit sortingChanged(sorting);
1221 }
1222
1223 const Qt::SortOrder sortOrder = props.sortOrder();
1224 if (sortOrder != model->sortOrder()) {
1225 model->setSortOrder(sortOrder);
1226 emit sortOrderChanged(sortOrder);
1227 }
1228
1229 const bool sortFoldersFirst = props.sortFoldersFirst();
1230 if (sortFoldersFirst != model->sortFoldersFirst()) {
1231 model->setSortFoldersFirst(sortFoldersFirst);
1232 emit sortFoldersFirstChanged(sortFoldersFirst);
1233 }
1234
1235 const QList<DolphinView::AdditionalInfo> infoList = props.additionalInfoList();
1236 if (infoList != m_additionalInfoList) {
1237 const QList<DolphinView::AdditionalInfo> previousList = m_additionalInfoList;
1238 m_additionalInfoList = infoList;
1239 applyAdditionalInfoListToView();
1240 emit additionalInfoListChanged(m_additionalInfoList, previousList);
1241 }
1242
1243 const bool previewsShown = props.previewsShown();
1244 if (previewsShown != m_container->previewsShown()) {
1245 const int oldZoomLevel = zoomLevel();
1246
1247 m_container->setPreviewsShown(previewsShown);
1248 emit previewsShownChanged(previewsShown);
1249
1250 // Changing the preview-state might result in a changed zoom-level
1251 if (oldZoomLevel != zoomLevel()) {
1252 emit zoomLevelChanged(zoomLevel(), oldZoomLevel);
1253 }
1254 }
1255
1256 m_container->endTransaction();
1257 }
1258
1259 void DolphinView::applyAdditionalInfoListToView()
1260 {
1261 const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance();
1262
1263 QList<QByteArray> visibleRoles;
1264 visibleRoles.reserve(m_additionalInfoList.count() + 1);
1265 visibleRoles.append("name");
1266
1267 foreach (AdditionalInfo info, m_additionalInfoList) {
1268 visibleRoles.append(infoAccessor.role(info));
1269 }
1270
1271 m_container->setVisibleRoles(visibleRoles);
1272 }
1273
1274 void DolphinView::pasteToUrl(const KUrl& url)
1275 {
1276 markPastedUrlsAsSelected(QApplication::clipboard()->mimeData());
1277 KonqOperations::doPaste(this, url);
1278 }
1279
1280 KUrl::List DolphinView::simplifiedSelectedUrls() const
1281 {
1282 KUrl::List urls;
1283
1284 const KFileItemList items = selectedItems();
1285 foreach (const KFileItem &item, items) {
1286 urls.append(item.url());
1287 }
1288
1289 if (itemsExpandable()) {
1290 // TODO: Check if we still need KDirModel for this in KDE 5.0
1291 urls = KDirModel::simplifiedUrlList(urls);
1292 }
1293
1294 return urls;
1295 }
1296
1297 QMimeData* DolphinView::selectionMimeData() const
1298 {
1299 const KFileItemModel* model = fileItemModel();
1300 const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
1301 const QSet<int> selectedIndexes = selectionManager->selectedItems();
1302
1303 return model->createMimeData(selectedIndexes);
1304 }
1305
1306 void DolphinView::markPastedUrlsAsSelected(const QMimeData* mimeData)
1307 {
1308 const KUrl::List urls = KUrl::List::fromMimeData(mimeData);
1309 markUrlsAsSelected(urls);
1310 }
1311
1312 void DolphinView::updateWritableState()
1313 {
1314 const bool wasFolderWritable = m_isFolderWritable;
1315 m_isFolderWritable = true;
1316
1317 const KFileItem item = m_dirLister->rootItem();
1318 if (!item.isNull()) {
1319 KFileItemListProperties capabilities(KFileItemList() << item);
1320 m_isFolderWritable = capabilities.supportsWriting();
1321 }
1322 if (m_isFolderWritable != wasFolderWritable) {
1323 emit writeStateChanged(m_isFolderWritable);
1324 }
1325 }
1326
1327 QByteArray DolphinView::sortRoleForSorting(Sorting sorting) const
1328 {
1329 switch (sorting) {
1330 case SortByName: return "name";
1331 case SortBySize: return "size";
1332 case SortByDate: return "date";
1333 case SortByPermissions: return "permissions";
1334 case SortByOwner: return "owner";
1335 case SortByGroup: return "group";
1336 case SortByType: return "type";
1337 case SortByDestination: return "destination";
1338 case SortByPath: return "path";
1339 default: break;
1340 }
1341
1342 return QByteArray();
1343 }
1344
1345 DolphinView::Sorting DolphinView::sortingForSortRole(const QByteArray& sortRole) const
1346 {
1347 static QHash<QByteArray, DolphinView::Sorting> sortHash;
1348 if (sortHash.isEmpty()) {
1349 sortHash.insert("name", SortByName);
1350 sortHash.insert("size", SortBySize);
1351 sortHash.insert("date", SortByDate);
1352 sortHash.insert("permissions", SortByPermissions);
1353 sortHash.insert("owner", SortByOwner);
1354 sortHash.insert("group", SortByGroup);
1355 sortHash.insert("type", SortByType);
1356 sortHash.insert("destination", SortByDestination);
1357 sortHash.insert("path", SortByPath);
1358 }
1359 return sortHash.value(sortRole);
1360 }
1361
1362 QString DolphinView::fileSizeText(KIO::filesize_t fileSize)
1363 {
1364 const KLocale* locale = KGlobal::locale();
1365 const unsigned int multiplier = (locale->binaryUnitDialect() == KLocale::MetricBinaryDialect)
1366 ? 1000 : 1024;
1367
1368 QString text;
1369 if (fileSize < multiplier) {
1370 // Show the size in bytes
1371 text = locale->formatByteSize(fileSize, 0, KLocale::DefaultBinaryDialect, KLocale::UnitByte);
1372 } else if (fileSize < multiplier * multiplier) {
1373 // Show the size in kilobytes and always round up. This is done
1374 // for consistency with the values shown e.g. in the "Size" column
1375 // of the details-view.
1376 fileSize += (multiplier / 2) - 1;
1377 text = locale->formatByteSize(fileSize, 0, KLocale::DefaultBinaryDialect, KLocale::UnitKiloByte);
1378 } else {
1379 // Show the size in the best fitting unit having one decimal
1380 text = locale->formatByteSize(fileSize, 1);
1381 }
1382 return text;
1383 }
1384
1385 #include "dolphinview.moc"