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