]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinview.cpp
Fix crash when opening a tab during a tooltip is shown
[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 connect(controller, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int)));
141 connect(controller, SIGNAL(itemsActivated(QSet<int>)), this, SLOT(slotItemsActivated(QSet<int>)));
142 connect(controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
143 connect(controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF)));
144 connect(controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF)));
145 connect(controller, SIGNAL(headerContextMenuRequested(QPointF)), this, SLOT(slotHeaderContextMenuRequested(QPointF)));
146 connect(controller, SIGNAL(itemPressed(int,Qt::MouseButton)), this, SLOT(hideToolTip()));
147 connect(controller, SIGNAL(itemHovered(int)), this, SLOT(slotItemHovered(int)));
148 connect(controller, SIGNAL(itemUnhovered(int)), this, SLOT(slotItemUnhovered(int)));
149 connect(controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*)));
150 connect(controller, SIGNAL(modelChanged(KItemModelBase*,KItemModelBase*)), this, SLOT(slotModelChanged(KItemModelBase*,KItemModelBase*)));
151
152 KFileItemModel* model = fileItemModel();
153 if (model) {
154 connect(model, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
155 }
156
157 KItemListView* view = controller->view();
158 connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
159 this, SLOT(slotSortOrderChangedByHeader(Qt::SortOrder,Qt::SortOrder)));
160 connect(view, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
161 this, SLOT(slotSortRoleChangedByHeader(QByteArray,QByteArray)));
162
163 KItemListSelectionManager* selectionManager = controller->selectionManager();
164 connect(selectionManager, SIGNAL(selectionChanged(QSet<int>,QSet<int>)),
165 this, SLOT(slotSelectionChanged(QSet<int>,QSet<int>)));
166
167 m_toolTipManager = new ToolTipManager(this);
168
169 m_versionControlObserver = new VersionControlObserver(this);
170 m_versionControlObserver->setModel(model);
171 connect(m_versionControlObserver, SIGNAL(infoMessage(QString)), this, SIGNAL(infoMessage(QString)));
172 connect(m_versionControlObserver, SIGNAL(errorMessage(QString)), this, SIGNAL(errorMessage(QString)));
173 connect(m_versionControlObserver, SIGNAL(operationCompletedMessage(QString)), this, SIGNAL(operationCompletedMessage(QString)));
174
175 applyViewProperties();
176 m_topLayout->addWidget(m_container);
177
178 loadDirectory(url);
179 }
180
181 DolphinView::~DolphinView()
182 {
183 }
184
185 KUrl DolphinView::url() const
186 {
187 return m_url;
188 }
189
190 void DolphinView::setActive(bool active)
191 {
192 if (active == m_active) {
193 return;
194 }
195
196 m_active = active;
197
198 QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
199 if (!active) {
200 color.setAlpha(150);
201 }
202
203 QWidget* viewport = m_container->viewport();
204 if (viewport) {
205 QPalette palette;
206 palette.setColor(viewport->backgroundRole(), color);
207 viewport->setPalette(palette);
208 }
209
210 update();
211
212 if (active) {
213 m_container->setFocus();
214 emit activated();
215 emit writeStateChanged(m_isFolderWritable);
216 }
217 }
218
219 bool DolphinView::isActive() const
220 {
221 return m_active;
222 }
223
224 void DolphinView::setMode(Mode mode)
225 {
226 if (mode != m_mode) {
227 ViewProperties props(url());
228 props.setViewMode(mode);
229 props.save();
230
231 applyViewProperties();
232 }
233 }
234
235 DolphinView::Mode DolphinView::mode() const
236 {
237 return m_mode;
238 }
239
240 void DolphinView::setPreviewsShown(bool show)
241 {
242 if (previewsShown() == show) {
243 return;
244 }
245
246 ViewProperties props(url());
247 props.setPreviewsShown(show);
248
249 m_container->setPreviewsShown(show);
250 emit previewsShownChanged(show);
251 }
252
253 bool DolphinView::previewsShown() const
254 {
255 return m_container->previewsShown();
256 }
257
258 void DolphinView::setHiddenFilesShown(bool show)
259 {
260 if (m_dirLister->showingDotFiles() == show) {
261 return;
262 }
263
264 const KFileItemList itemList = selectedItems();
265 m_selectedUrls.clear();
266 m_selectedUrls = itemList.urlList();
267
268 ViewProperties props(url());
269 props.setHiddenFilesShown(show);
270
271 fileItemModel()->setShowHiddenFiles(show);
272 emit hiddenFilesShownChanged(show);
273 }
274
275 bool DolphinView::hiddenFilesShown() const
276 {
277 return m_dirLister->showingDotFiles();
278 }
279
280 void DolphinView::setGroupedSorting(bool grouped)
281 {
282 if (grouped == groupedSorting()) {
283 return;
284 }
285
286 ViewProperties props(url());
287 props.setGroupedSorting(grouped);
288 props.save();
289
290 m_container->controller()->model()->setGroupedSorting(grouped);
291
292 emit groupedSortingChanged(grouped);
293 }
294
295 bool DolphinView::groupedSorting() const
296 {
297 return fileItemModel()->groupedSorting();
298 }
299
300 KFileItemList DolphinView::items() const
301 {
302 return m_dirLister->items();
303 }
304
305 KFileItemList DolphinView::selectedItems() const
306 {
307 const KFileItemModel* model = fileItemModel();
308 const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
309 const QSet<int> selectedIndexes = selectionManager->selectedItems();
310
311 KFileItemList selectedItems;
312 QSetIterator<int> it(selectedIndexes);
313 while (it.hasNext()) {
314 const int index = it.next();
315 selectedItems.append(model->fileItem(index));
316 }
317 return selectedItems;
318 }
319
320 int DolphinView::selectedItemsCount() const
321 {
322 const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
323 return selectionManager->selectedItems().count();
324 }
325
326 void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
327 {
328 m_selectedUrls = urls;
329 }
330
331 void DolphinView::markUrlAsCurrent(const KUrl& url)
332 {
333 m_currentItemUrl = url;
334 }
335
336 void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled)
337 {
338 const KItemListSelectionManager::SelectionMode mode = enabled
339 ? KItemListSelectionManager::Select
340 : KItemListSelectionManager::Deselect;
341 const KFileItemModel* model = fileItemModel();
342 KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
343
344 for (int index = 0; index < model->count(); index++) {
345 const KFileItem item = model->fileItem(index);
346 if (pattern.exactMatch(item.text())) {
347 // An alternative approach would be to store the matching items in a QSet<int> and
348 // select them in one go after the loop, but we'd need a new function
349 // KItemListSelectionManager::setSelected(QSet<int>, SelectionMode mode)
350 // for that.
351 selectionManager->setSelected(index, 1, mode);
352 }
353 }
354 }
355
356 void DolphinView::setZoomLevel(int level)
357 {
358 const int oldZoomLevel = zoomLevel();
359 m_container->setZoomLevel(level);
360 if (zoomLevel() != oldZoomLevel) {
361 emit zoomLevelChanged(zoomLevel(), oldZoomLevel);
362 }
363 }
364
365 int DolphinView::zoomLevel() const
366 {
367 return m_container->zoomLevel();
368 }
369
370 void DolphinView::setSorting(Sorting sorting)
371 {
372 if (sorting != this->sorting()) {
373 updateSorting(sorting);
374 }
375 }
376
377 DolphinView::Sorting DolphinView::sorting() const
378 {
379 KItemModelBase* model = m_container->controller()->model();
380 return sortingForSortRole(model->sortRole());
381 }
382
383 void DolphinView::setSortOrder(Qt::SortOrder order)
384 {
385 if (sortOrder() != order) {
386 updateSortOrder(order);
387 }
388 }
389
390 Qt::SortOrder DolphinView::sortOrder() const
391 {
392 KItemModelBase* model = fileItemModel();
393 return model->sortOrder();
394 }
395
396 void DolphinView::setSortFoldersFirst(bool foldersFirst)
397 {
398 if (sortFoldersFirst() != foldersFirst) {
399 updateSortFoldersFirst(foldersFirst);
400 }
401 }
402
403 bool DolphinView::sortFoldersFirst() const
404 {
405 KFileItemModel* model = fileItemModel();
406 return model->sortFoldersFirst();
407 }
408
409 void DolphinView::setAdditionalInfoList(const QList<AdditionalInfo>& info)
410 {
411 const QList<AdditionalInfo> previousList = info;
412
413 ViewProperties props(url());
414 props.setAdditionalInfoList(info);
415
416 m_additionalInfoList = info;
417 applyAdditionalInfoListToView();
418
419 emit additionalInfoListChanged(m_additionalInfoList, previousList);
420 }
421
422 QList<DolphinView::AdditionalInfo> DolphinView::additionalInfoList() const
423 {
424 return m_additionalInfoList;
425 }
426
427 void DolphinView::reload()
428 {
429 QByteArray viewState;
430 QDataStream saveStream(&viewState, QIODevice::WriteOnly);
431 saveState(saveStream);
432
433 const KFileItemList itemList = selectedItems();
434 m_selectedUrls.clear();
435 m_selectedUrls = itemList.urlList();
436
437 setUrl(url());
438 loadDirectory(url(), true);
439
440 QDataStream restoreStream(viewState);
441 restoreState(restoreStream);
442 }
443
444 void DolphinView::stopLoading()
445 {
446 m_dirLister->stop();
447 }
448
449 void DolphinView::readSettings()
450 {
451 const int oldZoomLevel = m_container->zoomLevel();
452
453 GeneralSettings::self()->readConfig();
454 m_container->readSettings();
455 applyViewProperties();
456
457 const int newZoomLevel = m_container->zoomLevel();
458 if (newZoomLevel != oldZoomLevel) {
459 emit zoomLevelChanged(newZoomLevel, oldZoomLevel);
460 }
461 }
462
463 void DolphinView::writeSettings()
464 {
465 GeneralSettings::self()->writeConfig();
466 m_container->writeSettings();
467 }
468
469 void DolphinView::setNameFilter(const QString& nameFilter)
470 {
471 fileItemModel()->setNameFilter(nameFilter);
472 }
473
474 QString DolphinView::nameFilter() const
475 {
476 return fileItemModel()->nameFilter();
477 }
478
479 void DolphinView::calculateItemCount(int& fileCount,
480 int& folderCount,
481 KIO::filesize_t& totalFileSize) const
482 {
483 foreach (const KFileItem& item, m_dirLister->items()) {
484 if (item.isDir()) {
485 ++folderCount;
486 } else {
487 ++fileCount;
488 totalFileSize += item.size();
489 }
490 }
491 }
492
493 QString DolphinView::statusBarText() const
494 {
495 QString summary;
496 QString foldersText;
497 QString filesText;
498
499 int folderCount = 0;
500 int fileCount = 0;
501 KIO::filesize_t totalFileSize = 0;
502
503 if (hasSelection()) {
504 // Give a summary of the status of the selected files
505 const KFileItemList list = selectedItems();
506 foreach (const KFileItem& item, list) {
507 if (item.isDir()) {
508 ++folderCount;
509 } else {
510 ++fileCount;
511 totalFileSize += item.size();
512 }
513 }
514
515 if (folderCount + fileCount == 1) {
516 // If only one item is selected, show the filename
517 filesText = i18nc("@info:status", "<filename>%1</filename> selected", list.first().text());
518 } else {
519 // At least 2 items are selected
520 foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
521 filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount);
522 }
523 } else {
524 calculateItemCount(fileCount, folderCount, totalFileSize);
525 foldersText = i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount);
526 filesText = i18ncp("@info:status", "1 File", "%1 Files", fileCount);
527 }
528
529 if (fileCount > 0 && folderCount > 0) {
530 summary = i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
531 foldersText, filesText, fileSizeText(totalFileSize));
532 } else if (fileCount > 0) {
533 summary = i18nc("@info:status files (size)", "%1 (%2)", filesText, fileSizeText(totalFileSize));
534 } else if (folderCount > 0) {
535 summary = foldersText;
536 }
537
538 return summary;
539 }
540
541 QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) const
542 {
543 QList<QAction*> actions;
544
545 if (items.isEmpty()) {
546 const KFileItem item = fileItemModel()->rootItem();
547 actions = m_versionControlObserver->actions(KFileItemList() << item);
548 } else {
549 actions = m_versionControlObserver->actions(items);
550 }
551
552 return actions;
553 }
554
555 void DolphinView::setUrl(const KUrl& url)
556 {
557 if (url == m_url) {
558 return;
559 }
560
561 emit urlAboutToBeChanged(url);
562 m_url = url;
563
564 hideToolTip();
565
566 // It is important to clear the items from the model before
567 // applying the view properties, otherwise expensive operations
568 // might be done on the existing items although they get cleared
569 // anyhow afterwards by loadDirectory().
570 fileItemModel()->clear();
571 applyViewProperties();
572 loadDirectory(url);
573
574 emit urlChanged(url);
575 }
576
577 void DolphinView::selectAll()
578 {
579 KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
580 selectionManager->setSelected(0, fileItemModel()->count());
581 }
582
583 void DolphinView::invertSelection()
584 {
585 KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
586 selectionManager->setSelected(0, fileItemModel()->count(), KItemListSelectionManager::Toggle);
587 }
588
589 void DolphinView::clearSelection()
590 {
591 m_container->controller()->selectionManager()->clearSelection();
592 }
593
594 void DolphinView::renameSelectedItems()
595 {
596 KFileItemList items = selectedItems();
597 const int itemCount = items.count();
598 if (itemCount < 1) {
599 return;
600 }
601
602 // TODO: The new view-engine introduced with Dolphin 2.0 does not support inline
603 // renaming yet.
604 /*if ((itemCount == 1) && DolphinSettings::instance().generalSettings()->renameInline()) {
605 const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForItem(items.first());
606 const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex);
607 m_viewAccessor.itemView()->edit(proxyIndex);
608 } else {*/
609 RenameDialog* dialog = new RenameDialog(this, items);
610 dialog->setAttribute(Qt::WA_DeleteOnClose);
611 dialog->show();
612 dialog->raise();
613 dialog->activateWindow();
614 //}
615
616 // assure that the current index remains visible when KDirLister
617 // will notify the view about changed items
618 m_assureVisibleCurrentIndex = true;
619 }
620
621 void DolphinView::trashSelectedItems()
622 {
623 const KUrl::List list = simplifiedSelectedUrls();
624 KonqOperations::del(this, KonqOperations::TRASH, list);
625 }
626
627 void DolphinView::deleteSelectedItems()
628 {
629 const KUrl::List list = simplifiedSelectedUrls();
630 const bool del = KonqOperations::askDeleteConfirmation(list,
631 KonqOperations::DEL,
632 KonqOperations::DEFAULT_CONFIRMATION,
633 this);
634
635 if (del) {
636 KIO::Job* job = KIO::del(list);
637 connect(job, SIGNAL(result(KJob*)),
638 this, SLOT(slotDeleteFileFinished(KJob*)));
639 }
640 }
641
642 void DolphinView::cutSelectedItems()
643 {
644 QMimeData* mimeData = selectionMimeData();
645 KonqMimeData::addIsCutSelection(mimeData, true);
646 QApplication::clipboard()->setMimeData(mimeData);
647 }
648
649 void DolphinView::copySelectedItems()
650 {
651 QMimeData* mimeData = selectionMimeData();
652 QApplication::clipboard()->setMimeData(mimeData);
653 }
654
655 void DolphinView::paste()
656 {
657 pasteToUrl(url());
658 }
659
660 void DolphinView::pasteIntoFolder()
661 {
662 const KFileItemList items = selectedItems();
663 if ((items.count() == 1) && items.first().isDir()) {
664 pasteToUrl(items.first().url());
665 }
666 }
667
668 bool DolphinView::eventFilter(QObject* watched, QEvent* event)
669 {
670 switch (event->type()) {
671 case QEvent::FocusIn:
672 if (watched == m_container) {
673 setActive(true);
674 }
675 break;
676
677 default:
678 break;
679 }
680
681 return QWidget::eventFilter(watched, event);
682 }
683
684 void DolphinView::wheelEvent(QWheelEvent* event)
685 {
686 if (event->modifiers().testFlag(Qt::ControlModifier)) {
687 const int numDegrees = event->delta() / 8;
688 const int numSteps = numDegrees / 15;
689
690 setZoomLevel(zoomLevel() + numSteps);
691 event->accept();
692 } else {
693 event->ignore();
694 }
695 }
696
697 void DolphinView::hideEvent(QHideEvent* event)
698 {
699 hideToolTip();
700 QWidget::hideEvent(event);
701 }
702
703 void DolphinView::activate()
704 {
705 setActive(true);
706 }
707
708 void DolphinView::slotItemActivated(int index)
709 {
710 const KFileItem item = fileItemModel()->fileItem(index);
711 if (!item.isNull()) {
712 emit itemActivated(item);
713 }
714 }
715
716 void DolphinView::slotItemsActivated(const QSet<int>& indexes)
717 {
718 Q_ASSERT(indexes.count() >= 2);
719
720 KFileItemList items;
721
722 KFileItemModel* model = fileItemModel();
723 QSetIterator<int> it(indexes);
724 while (it.hasNext()) {
725 const int index = it.next();
726 items.append(model->fileItem(index));
727 }
728
729 foreach (const KFileItem& item, items) {
730 if (item.isDir()) {
731 emit tabRequested(item.url());
732 } else {
733 emit itemActivated(item);
734 }
735 }
736 }
737
738 void DolphinView::slotItemMiddleClicked(int index)
739 {
740 const KFileItem item = fileItemModel()->fileItem(index);
741 if (item.isDir() || isTabsForFilesEnabled()) {
742 emit tabRequested(item.url());
743 }
744 }
745
746 void DolphinView::slotItemContextMenuRequested(int index, const QPointF& pos)
747 {
748 const KFileItem item = fileItemModel()->fileItem(index);
749 emit requestContextMenu(pos.toPoint(), item, url(), QList<QAction*>());
750 }
751
752 void DolphinView::slotViewContextMenuRequested(const QPointF& pos)
753 {
754 emit requestContextMenu(pos.toPoint(), KFileItem(), url(), QList<QAction*>());
755 }
756
757 void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
758 {
759 QWeakPointer<KMenu> menu = new KMenu(QApplication::activeWindow());
760
761 KItemListView* view = m_container->controller()->view();
762 const QSet<QByteArray> visibleRolesSet = view->visibleRoles().toSet();
763
764 // Add all roles to the menu that can be shown or hidden by the user
765 const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance();
766 const QList<DolphinView::AdditionalInfo> keys = infoAccessor.keys();
767 foreach (const DolphinView::AdditionalInfo info, keys) {
768 const QByteArray& role = infoAccessor.role(info);
769 if (role != "name") {
770 const QString text = fileItemModel()->roleDescription(role);
771
772 QAction* action = menu.data()->addAction(text);
773 action->setCheckable(true);
774 action->setChecked(visibleRolesSet.contains(role));
775 action->setData(info);
776 }
777 }
778
779 QAction* action = menu.data()->exec(pos.toPoint());
780 if (action) {
781 // Show or hide the selected role
782 const DolphinView::AdditionalInfo info =
783 static_cast<DolphinView::AdditionalInfo>(action->data().toInt());
784
785 ViewProperties props(url());
786 QList<DolphinView::AdditionalInfo> infoList = props.additionalInfoList();
787
788 const QByteArray selectedRole = infoAccessor.role(info);
789 QList<QByteArray> visibleRoles = view->visibleRoles();
790
791 if (action->isChecked()) {
792 const int index = keys.indexOf(info) + 1;
793 visibleRoles.insert(index, selectedRole);
794 infoList.insert(index, info);
795 } else {
796 visibleRoles.removeOne(selectedRole);
797 infoList.removeOne(info);
798 }
799
800 view->setVisibleRoles(visibleRoles);
801 props.setAdditionalInfoList(infoList);
802 }
803
804 delete menu.data();
805 }
806
807 void DolphinView::slotItemHovered(int index)
808 {
809 const KFileItem item = fileItemModel()->fileItem(index);
810
811 if (GeneralSettings::showToolTips() && QApplication::mouseButtons() == Qt::NoButton) {
812 QRectF itemRect = m_container->controller()->view()->itemContextRect(index);
813 const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint());
814 itemRect.moveTo(pos);
815
816 m_toolTipManager->showToolTip(item, itemRect);
817 }
818
819 emit requestItemInfo(item);
820 }
821
822 void DolphinView::slotItemUnhovered(int index)
823 {
824 Q_UNUSED(index);
825 hideToolTip();
826 emit requestItemInfo(KFileItem());
827 }
828
829 void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
830 {
831 KUrl destUrl;
832 KFileItem destItem = fileItemModel()->fileItem(index);
833 if (destItem.isNull()) {
834 destItem = fileItemModel()->rootItem();
835 destUrl = url();
836 } else {
837 destUrl = destItem.url();
838 }
839
840 QDropEvent dropEvent(event->pos().toPoint(),
841 event->possibleActions(),
842 event->mimeData(),
843 event->buttons(),
844 event->modifiers());
845
846 const QString error = DragAndDropHelper::dropUrls(destItem, destUrl, &dropEvent);
847 if (!error.isEmpty()) {
848 emit errorMessage(error);
849 }
850 }
851
852 void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous)
853 {
854 if (previous != 0) {
855 disconnect(previous, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
856 }
857
858 Q_ASSERT(qobject_cast<KFileItemModel*>(current));
859 connect(current, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
860
861 KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(current);
862 m_versionControlObserver->setModel(fileItemModel);
863 }
864
865 void DolphinView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
866 {
867 const int currentCount = current.count();
868 const int previousCount = previous.count();
869 const bool selectionStateChanged = (currentCount == 0 && previousCount > 0) ||
870 (currentCount > 0 && previousCount == 0);
871
872 // If nothing has been selected before and something got selected (or if something
873 // was selected before and now nothing is selected) the selectionChangedSignal must
874 // be emitted asynchronously as fast as possible to update the edit-actions.
875 m_selectionChangedTimer->setInterval(selectionStateChanged ? 0 : 300);
876 m_selectionChangedTimer->start();
877 }
878
879 void DolphinView::emitSelectionChangedSignal()
880 {
881 m_selectionChangedTimer->stop();
882 emit selectionChanged(selectedItems());
883 }
884
885 void DolphinView::updateSorting(DolphinView::Sorting sorting)
886 {
887 ViewProperties props(url());
888 props.setSorting(sorting);
889
890 KItemModelBase* model = m_container->controller()->model();
891 model->setSortRole(sortRoleForSorting(sorting));
892
893 emit sortingChanged(sorting);
894 }
895
896 void DolphinView::updateSortOrder(Qt::SortOrder order)
897 {
898 ViewProperties props(url());
899 props.setSortOrder(order);
900
901 KItemModelBase* model = fileItemModel();
902 model->setSortOrder(order);
903
904 emit sortOrderChanged(order);
905 }
906
907 void DolphinView::updateSortFoldersFirst(bool foldersFirst)
908 {
909 ViewProperties props(url());
910 props.setSortFoldersFirst(foldersFirst);
911
912 KFileItemModel* model = fileItemModel();
913 model->setSortFoldersFirst(foldersFirst);
914
915 emit sortFoldersFirstChanged(foldersFirst);
916 }
917
918 QPair<bool, QString> DolphinView::pasteInfo() const
919 {
920 return KonqOperations::pasteInfo(url());
921 }
922
923 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles)
924 {
925 m_tabsForFiles = tabsForFiles;
926 }
927
928 bool DolphinView::isTabsForFilesEnabled() const
929 {
930 return m_tabsForFiles;
931 }
932
933 bool DolphinView::itemsExpandable() const
934 {
935 return m_mode == DetailsView;
936 }
937
938 void DolphinView::restoreState(QDataStream& stream)
939 {
940 // Restore the current item that had the keyboard focus
941 stream >> m_currentItemUrl;
942
943 // Restore the view position
944 stream >> m_restoredContentsPosition;
945
946 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
947 QSet<KUrl> urls;
948 stream >> urls;
949 fileItemModel()->restoreExpandedUrls(urls);
950 }
951
952 void DolphinView::saveState(QDataStream& stream)
953 {
954 // Save the current item that has the keyboard focus
955 const int currentIndex = m_container->controller()->selectionManager()->currentItem();
956 if (currentIndex != -1) {
957 KFileItem item = fileItemModel()->fileItem(currentIndex);
958 Q_ASSERT(!item.isNull()); // If the current index is valid a item must exist
959 KUrl currentItemUrl = item.url();
960 stream << currentItemUrl;
961 } else {
962 stream << KUrl();
963 }
964
965 // Save view position
966 const qreal x = m_container->horizontalScrollBar()->value();
967 const qreal y = m_container->verticalScrollBar()->value();
968 stream << QPoint(x, y);
969
970 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
971 stream << fileItemModel()->expandedUrls();
972 }
973
974 bool DolphinView::hasSelection() const
975 {
976 return m_container->controller()->selectionManager()->hasSelection();
977 }
978
979 KFileItem DolphinView::rootItem() const
980 {
981 return m_dirLister->rootItem();
982 }
983
984 void DolphinView::observeCreatedItem(const KUrl& url)
985 {
986 m_createdItemUrl = url;
987 //connect(m_dirModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
988 // this, SLOT(selectAndScrollToCreatedItem()));
989 }
990
991 void DolphinView::selectAndScrollToCreatedItem()
992 {
993 /*const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForUrl(m_createdItemUrl);
994 if (dirIndex.isValid()) {
995 const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex);
996 QAbstractItemView* view = m_viewAccessor.itemView();
997 if (view) {
998 view->setCurrentIndex(proxyIndex);
999 }
1000 }
1001
1002 disconnect(m_viewAccessor.dirModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
1003 this, SLOT(selectAndScrollToCreatedItem()));*/
1004 m_createdItemUrl = KUrl();
1005 }
1006
1007 void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
1008 {
1009 if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash)) {
1010 emit redirection(oldUrl, newUrl);
1011 m_url = newUrl; // #186947
1012 }
1013 }
1014
1015 void DolphinView::updateViewState()
1016 {
1017 if (m_currentItemUrl != KUrl()) {
1018 KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
1019 const int currentIndex = fileItemModel()->index(m_currentItemUrl);
1020 if (currentIndex != -1) {
1021 selectionManager->setCurrentItem(currentIndex);
1022 } else {
1023 selectionManager->setCurrentItem(0);
1024 }
1025 m_currentItemUrl = KUrl();
1026 }
1027
1028 if (!m_restoredContentsPosition.isNull()) {
1029 const int x = m_restoredContentsPosition.x();
1030 const int y = m_restoredContentsPosition.y();
1031 m_restoredContentsPosition = QPoint();
1032
1033 m_container->horizontalScrollBar()->setValue(x);
1034 m_container->verticalScrollBar()->setValue(y);
1035 }
1036
1037 if (!m_selectedUrls.isEmpty()) {
1038 KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
1039 QSet<int> selectedItems = selectionManager->selectedItems();
1040 const KFileItemModel* model = fileItemModel();
1041
1042 foreach (const KUrl& url, m_selectedUrls) {
1043 const int index = model->index(url);
1044 if (index >= 0) {
1045 selectedItems.insert(index);
1046 }
1047 }
1048
1049 selectionManager->setSelectedItems(selectedItems);
1050 m_selectedUrls.clear();
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"