]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.cpp
Assure that the grid size for Icons View, Details View and Previews View has some...
[dolphin.git] / src / dolphinview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "dolphinview.h"
22
23 #include <kdirmodel.h>
24
25
26 #include <qlayout.h>
27 //Added by qt3to4:
28 #include <Q3ValueList>
29 #include <QDropEvent>
30 #include <QMouseEvent>
31 #include <Q3VBoxLayout>
32 #include <kurl.h>
33 #include <klocale.h>
34 #include <kio/netaccess.h>
35 #include <kio/renamedlg.h>
36 #include <assert.h>
37
38 #include "urlnavigator.h"
39 #include "dolphinstatusbar.h"
40 #include "dolphin.h"
41 #include "dolphindirlister.h"
42 #include "viewproperties.h"
43 #include "dolphindetailsview.h"
44 #include "dolphiniconsview.h"
45 #include "dolphincontextmenu.h"
46 #include "undomanager.h"
47 #include "renamedialog.h"
48 #include "progressindicator.h"
49
50 #include "filterbar.h"
51
52 DolphinView::DolphinView(QWidget *parent,
53 const KUrl& url,
54 Mode mode,
55 bool showHiddenFiles) :
56 QWidget(parent),
57 m_refreshing(false),
58 m_showProgress(false),
59 m_mode(mode),
60 m_statusBar(0),
61 m_iconSize(0),
62 m_folderCount(0),
63 m_fileCount(0),
64 m_filterBar(0)
65 {
66 setFocusPolicy(Qt::StrongFocus);
67 m_topLayout = new Q3VBoxLayout(this);
68
69 Dolphin& dolphin = Dolphin::mainWin();
70
71 connect(this, SIGNAL(signalModeChanged()),
72 &dolphin, SLOT(slotViewModeChanged()));
73 connect(this, SIGNAL(signalShowHiddenFilesChanged()),
74 &dolphin, SLOT(slotShowHiddenFilesChanged()));
75 connect(this, SIGNAL(signalSortingChanged(DolphinView::Sorting)),
76 &dolphin, SLOT(slotSortingChanged(DolphinView::Sorting)));
77 connect(this, SIGNAL(signalSortOrderChanged(Qt::SortOrder)),
78 &dolphin, SLOT(slotSortOrderChanged(Qt::SortOrder)));
79
80 m_urlNavigator = new UrlNavigator(url, this);
81 connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
82 this, SLOT(slotUrlChanged(const KUrl&)));
83 connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
84 &dolphin, SLOT(slotUrlChanged(const KUrl&)));
85 connect(m_urlNavigator, SIGNAL(historyChanged()),
86 &dolphin, SLOT(slotHistoryChanged()));
87
88 m_statusBar = new DolphinStatusBar(this);
89
90 m_dirLister = new DolphinDirLister();
91 m_dirLister->setAutoUpdate(true);
92 m_dirLister->setMainWindow(this);
93 m_dirLister->setShowingDotFiles(showHiddenFiles);
94 connect(m_dirLister, SIGNAL(clear()),
95 this, SLOT(slotClear()));
96 connect(m_dirLister, SIGNAL(percent(int)),
97 this, SLOT(slotPercent(int)));
98 connect(m_dirLister, SIGNAL(deleteItem(KFileItem*)),
99 this, SLOT(slotDeleteItem(KFileItem*)));
100 connect(m_dirLister, SIGNAL(completed()),
101 this, SLOT(slotCompleted()));
102 connect(m_dirLister, SIGNAL(infoMessage(const QString&)),
103 this, SLOT(slotInfoMessage(const QString&)));
104 connect(m_dirLister, SIGNAL(errorMessage(const QString&)),
105 this, SLOT(slotErrorMessage(const QString&)));
106
107 m_iconsView = new DolphinIconsView(this);
108 connect(m_iconsView, SIGNAL(clicked(const QModelIndex&)),
109 this, SLOT(triggerItem(const QModelIndex&)));
110 applyModeToView();
111
112 KDirModel* model = new KDirModel();
113 model->setDirLister(m_dirLister);
114 m_iconsView->setModel(model);
115
116 m_iconSize = K3Icon::SizeMedium;
117
118 m_filterBar = new FilterBar(this);
119 m_filterBar->hide();
120 connect(m_filterBar, SIGNAL(signalFilterChanged(const QString&)),
121 this, SLOT(slotChangeNameFilter(const QString&)));
122
123 m_topLayout->addWidget(m_urlNavigator);
124 m_topLayout->addWidget(m_iconsView);
125 m_topLayout->addWidget(m_filterBar);
126 m_topLayout->addWidget(m_statusBar);
127
128 startDirLister(m_urlNavigator->url());
129 }
130
131 DolphinView::~DolphinView()
132 {
133 delete m_dirLister;
134 m_dirLister = 0;
135 }
136
137 void DolphinView::setUrl(const KUrl& url)
138 {
139 m_urlNavigator->setUrl(url);
140 }
141
142 const KUrl& DolphinView::url() const
143 {
144 return m_urlNavigator->url();
145 }
146
147 void DolphinView::requestActivation()
148 {
149 Dolphin::mainWin().setActiveView(this);
150 }
151
152 bool DolphinView::isActive() const
153 {
154 return (Dolphin::mainWin().activeView() == this);
155 }
156
157 void DolphinView::setMode(Mode mode)
158 {
159 if (mode == m_mode) {
160 return; // the wished mode is already set
161 }
162
163 m_mode = mode;
164
165 ViewProperties props(m_urlNavigator->url());
166 props.setViewMode(m_mode);
167
168 applyModeToView();
169 startDirLister(m_urlNavigator->url());
170
171 emit signalModeChanged();
172 }
173
174 DolphinView::Mode DolphinView::mode() const
175 {
176 return m_mode;
177 }
178
179 void DolphinView::setShowHiddenFilesEnabled(bool show)
180 {
181 if (m_dirLister->showingDotFiles() == show) {
182 return;
183 }
184
185 ViewProperties props(m_urlNavigator->url());
186 props.setShowHiddenFilesEnabled(show);
187 props.save();
188
189 m_dirLister->setShowingDotFiles(show);
190
191 emit signalShowHiddenFilesChanged();
192
193 reload();
194 }
195
196 bool DolphinView::isShowHiddenFilesEnabled() const
197 {
198 return m_dirLister->showingDotFiles();
199 }
200
201 void DolphinView::setViewProperties(const ViewProperties& props)
202 {
203 setMode(props.viewMode());
204 setSorting(props.sorting());
205 setSortOrder(props.sortOrder());
206 setShowHiddenFilesEnabled(props.isShowHiddenFilesEnabled());
207 }
208
209 void DolphinView::renameSelectedItems()
210 {
211 const KUrl::List urls = selectedUrls();
212 if (urls.count() > 1) {
213 // More than one item has been selected for renaming. Open
214 // a rename dialog and rename all items afterwards.
215 RenameDialog dialog(urls);
216 if (dialog.exec() == QDialog::Rejected) {
217 return;
218 }
219
220 DolphinView* view = Dolphin::mainWin().activeView();
221 const QString& newName = dialog.newName();
222 if (newName.isEmpty()) {
223 view->statusBar()->setMessage(i18n("The new item name is invalid."),
224 DolphinStatusBar::Error);
225 }
226 else {
227 UndoManager& undoMan = UndoManager::instance();
228 undoMan.beginMacro();
229
230 assert(newName.contains('#'));
231
232 const int urlsCount = urls.count();
233 ProgressIndicator* progressIndicator =
234 new ProgressIndicator(i18n("Renaming items..."),
235 i18n("Renaming finished."),
236 urlsCount);
237
238 // iterate through all selected items and rename them...
239 const int replaceIndex = newName.find('#');
240 assert(replaceIndex >= 0);
241 for (int i = 0; i < urlsCount; ++i) {
242 const KUrl& source = urls[i];
243 QString name(newName);
244 name.replace(replaceIndex, 1, renameIndexPresentation(i + 1, urlsCount));
245
246 if (source.fileName() != name) {
247 KUrl dest(source.upUrl());
248 dest.addPath(name);
249
250 const bool destExists = KIO::NetAccess::exists(dest, false, view);
251 if (destExists) {
252 delete progressIndicator;
253 progressIndicator = 0;
254 view->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name),
255 DolphinStatusBar::Error);
256 break;
257 }
258 else if (KIO::NetAccess::file_move(source, dest)) {
259 // TODO: From the users point of view he executed one 'rename n files' operation,
260 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
261 DolphinCommand command(DolphinCommand::Rename, source, dest);
262 undoMan.addCommand(command);
263 }
264 }
265
266 progressIndicator->execOperation();
267 }
268 delete progressIndicator;
269 progressIndicator = 0;
270
271 undoMan.endMacro();
272 }
273 }
274 else {
275 // Only one item has been selected for renaming. Use the custom
276 // renaming mechanism from the views.
277 assert(urls.count() == 1);
278 // TODO:
279 /*if (m_mode == DetailsView) {
280 Q3ListViewItem* item = m_iconsView->firstChild();
281 while (item != 0) {
282 if (item->isSelected()) {
283 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
284 break;
285 }
286 item = item->nextSibling();
287 }
288 }
289 else {
290 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
291 while (item != 0) {
292 if (item->isSelected()) {
293 item->rename();
294 break;
295 }
296 item = static_cast<KFileIconViewItem*>(item->nextItem());
297 }
298 }*/
299 }
300 }
301
302 void DolphinView::selectAll()
303 {
304 //fileView()->selectAll();
305 }
306
307 void DolphinView::invertSelection()
308 {
309 //fileView()->invertSelection();
310 }
311
312 DolphinStatusBar* DolphinView::statusBar() const
313 {
314 return m_statusBar;
315 }
316
317 int DolphinView::contentsX() const
318 {
319
320 return 0; //scrollView()->contentsX();
321 }
322
323 int DolphinView::contentsY() const
324 {
325 return 0; //scrollView()->contentsY();
326 }
327
328 void DolphinView::refreshSettings()
329 {
330 startDirLister(m_urlNavigator->url());
331 }
332
333 void DolphinView::updateStatusBar()
334 {
335 // As the item count information is less important
336 // in comparison with other messages, it should only
337 // be shown if:
338 // - the status bar is empty or
339 // - shows already the item count information or
340 // - shows only a not very important information
341 // - if any progress is given don't show the item count info at all
342 const QString msg(m_statusBar->message());
343 const bool updateStatusBarMsg = (msg.isEmpty() ||
344 (msg == m_statusBar->defaultText()) ||
345 (m_statusBar->type() == DolphinStatusBar::Information)) &&
346 (m_statusBar->progress() == 100);
347
348 const QString text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
349 m_statusBar->setDefaultText(text);
350
351 if (updateStatusBarMsg) {
352 m_statusBar->setMessage(text, DolphinStatusBar::Default);
353 }
354 }
355
356 void DolphinView::requestItemInfo(const KUrl& url)
357 {
358 emit signalRequestItemInfo(url);
359 }
360
361 bool DolphinView::isUrlEditable() const
362 {
363 return m_urlNavigator->isUrlEditable();
364 }
365
366 void DolphinView::zoomIn()
367 {
368 //itemEffectsManager()->zoomIn();
369 }
370
371 void DolphinView::zoomOut()
372 {
373 //itemEffectsManager()->zoomOut();
374 }
375
376 bool DolphinView::isZoomInPossible() const
377 {
378 return false; //itemEffectsManager()->isZoomInPossible();
379 }
380
381 bool DolphinView::isZoomOutPossible() const
382 {
383 return false; //itemEffectsManager()->isZoomOutPossible();
384 }
385
386 void DolphinView::setSorting(Sorting sorting)
387 {
388 if (sorting != this->sorting()) {
389 /*KFileView* view = fileView();
390 int spec = view->sorting() & ~QDir::Name & ~QDir::Size & ~QDir::Time & ~QDir::Unsorted;
391
392 switch (sorting) {
393 case SortByName: spec = spec | QDir::Name; break;
394 case SortBySize: spec = spec | QDir::Size; break;
395 case SortByDate: spec = spec | QDir::Time; break;
396 default: break;
397 }
398
399 ViewProperties props(url());
400 props.setSorting(sorting);
401
402 view->setSorting(static_cast<QDir::SortFlags>(spec));
403
404 emit signalSortingChanged(sorting);*/
405 }
406 }
407
408 DolphinView::Sorting DolphinView::sorting() const
409 {
410 /*const QDir::SortFlags spec = fileView()->sorting();
411
412 if (spec & QDir::Time) {
413 return SortByDate;
414 }
415
416 if (spec & QDir::Size) {
417 return SortBySize;
418 }*/
419
420 return SortByName;
421 }
422
423 void DolphinView::setSortOrder(Qt::SortOrder order)
424 {
425 if (sortOrder() != order) {
426 /*KFileView* view = fileView();
427 int sorting = view->sorting();
428 sorting = (order == Qt::Ascending) ? (sorting & ~QDir::Reversed) :
429 (sorting | QDir::Reversed);
430
431 ViewProperties props(url());
432 props.setSortOrder(order);
433
434 view->setSorting(static_cast<QDir::SortFlags>(sorting));
435
436 emit signalSortOrderChanged(order);*/
437 }
438 }
439
440 Qt::SortOrder DolphinView::sortOrder() const
441 {
442 //return fileView()->isReversed() ? Qt::Descending : Qt::Ascending;
443 return Qt::Descending;
444 }
445
446 void DolphinView::goBack()
447 {
448 m_urlNavigator->goBack();
449 }
450
451 void DolphinView::goForward()
452 {
453 m_urlNavigator->goForward();
454 }
455
456 void DolphinView::goUp()
457 {
458 m_urlNavigator->goUp();
459 }
460
461 void DolphinView::goHome()
462 {
463 m_urlNavigator->goHome();
464 }
465
466 void DolphinView::setUrlEditable(bool editable)
467 {
468 m_urlNavigator->editUrl(editable);
469 }
470
471 const Q3ValueList<UrlNavigator::HistoryElem> DolphinView::urlHistory(int& index) const
472 {
473 return m_urlNavigator->history(index);
474 }
475
476 bool DolphinView::hasSelection() const
477 {
478 const KFileItemList* list = selectedItems();
479 return (list != 0) && !list->isEmpty();
480 }
481
482 const KFileItemList* DolphinView::selectedItems() const
483 {
484 return 0; //fileView()->selectedItems();
485 }
486
487 KUrl::List DolphinView::selectedUrls() const
488 {
489 KUrl::List urls;
490
491 /*const KFileItemList* list = fileView()->selectedItems();
492 if (list != 0) {
493 KFileItemList::const_iterator it = list->begin();
494 const KFileItemList::const_iterator end = list->end();
495 while (it != end) {
496 KFileItem* item = *it;
497 urls.append(item->url());
498 ++it;
499 }
500 }*/
501
502 return urls;
503 }
504
505 const KFileItem* DolphinView::currentFileItem() const
506 {
507 return 0; // fileView()->currentFileItem();
508 }
509
510 void DolphinView::openContextMenu(KFileItem* fileInfo, const QPoint& pos)
511 {
512 DolphinContextMenu contextMenu(this, fileInfo, pos);
513 contextMenu.open();
514 }
515
516 void DolphinView::rename(const KUrl& source, const QString& newName)
517 {
518 bool ok = false;
519
520 if (newName.isEmpty() || (source.fileName() == newName)) {
521 return;
522 }
523
524 KUrl dest(source.upUrl());
525 dest.addPath(newName);
526
527 const bool destExists = KIO::NetAccess::exists(dest,
528 false,
529 Dolphin::mainWin().activeView());
530 if (destExists) {
531 // the destination already exists, hence ask the user
532 // how to proceed...
533 KIO::RenameDlg renameDialog(this,
534 i18n("File Already Exists"),
535 source.path(),
536 dest.path(),
537 KIO::M_OVERWRITE);
538 switch (renameDialog.exec()) {
539 case KIO::R_OVERWRITE:
540 // the destination should be overwritten
541 ok = KIO::NetAccess::file_move(source, dest, -1, true);
542 break;
543
544 case KIO::R_RENAME: {
545 // a new name for the destination has been used
546 KUrl newDest(renameDialog.newDestUrl());
547 ok = KIO::NetAccess::file_move(source, newDest);
548 break;
549 }
550
551 default:
552 // the renaming operation has been canceled
553 reload();
554 return;
555 }
556 }
557 else {
558 // no destination exists, hence just move the file to
559 // do the renaming
560 ok = KIO::NetAccess::file_move(source, dest);
561 }
562
563 if (ok) {
564 m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.",source.fileName(), dest.fileName()),
565 DolphinStatusBar::OperationCompleted);
566
567 DolphinCommand command(DolphinCommand::Rename, source, dest);
568 UndoManager::instance().addCommand(command);
569 }
570 else {
571 m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source.fileName(), dest.fileName()),
572 DolphinStatusBar::Error);
573 reload();
574 }
575 }
576
577 void DolphinView::reload()
578 {
579 startDirLister(m_urlNavigator->url(), true);
580 }
581
582 void DolphinView::slotUrlListDropped(QDropEvent* /* event */,
583 const KUrl::List& urls,
584 const KUrl& url)
585 {
586 KUrl destination(url);
587 if (destination.isEmpty()) {
588 destination = m_urlNavigator->url();
589 }
590 else {
591 // Check whether the destination Url is a directory. If this is not the
592 // case, use the navigator Url as destination (otherwise the destination,
593 // which represents a file, would be replaced by a copy- or move-operation).
594 KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, destination);
595 if (!fileItem.isDir()) {
596 destination = m_urlNavigator->url();
597 }
598 }
599
600 Dolphin::mainWin().dropUrls(urls, destination);
601 }
602
603 void DolphinView::mouseReleaseEvent(QMouseEvent* event)
604 {
605 QWidget::mouseReleaseEvent(event);
606 Dolphin::mainWin().setActiveView(this);
607 }
608
609 void DolphinView::slotUrlChanged(const KUrl& url)
610 {
611 const ViewProperties props(url);
612 setMode(props.viewMode());
613
614 const bool showHiddenFiles = props.isShowHiddenFilesEnabled();
615 setShowHiddenFilesEnabled(showHiddenFiles);
616 m_dirLister->setShowingDotFiles(showHiddenFiles);
617
618 setSorting(props.sorting());
619 setSortOrder(props.sortOrder());
620
621 startDirLister(url);
622
623 // The selectionChanged signal is not emitted when a new view object is
624 // created. The application does not care whether a view is represented by a
625 // different instance, hence inform the application that the selection might have
626 // changed so that it can update it's actions.
627 Dolphin::mainWin().slotSelectionChanged();
628
629 emit signalUrlChanged(url);
630 }
631
632 void DolphinView::triggerIconsViewItem(Q3IconViewItem* item)
633 {
634 /* KDE4-TODO:
635 const Qt::ButtonState keyboardState = KApplication::keyboardMouseState();
636 const bool isSelectionActive = ((keyboardState & Qt::ShiftModifier) > 0) ||
637 ((keyboardState & Qt::ControlModifier) > 0);*/
638 const bool isSelectionActive = false;
639 if ((item != 0) && !isSelectionActive) {
640 // Updating the Url must be done outside the scope of this slot,
641 // as iconview items will get deleted.
642 QTimer::singleShot(0, this, SLOT(updateUrl()));
643 Dolphin::mainWin().setActiveView(this);
644 }
645 }
646
647 void DolphinView::triggerItem(const QModelIndex& index)
648 {
649 KDirModel* dirModel = static_cast<KDirModel*>(m_iconsView->model());
650 KFileItem* item = dirModel->itemForIndex(index);
651 if (item == 0) {
652 return;
653 }
654
655 if (item->isDir()) {
656 // Prefer the local path over the Url. This assures that the
657 // volume space information is correct. Assuming that the Url is media:/sda1,
658 // and the local path is /windows/C: For the Url the space info is related
659 // to the root partition (and hence wrong) and for the local path the space
660 // info is related to the windows partition (-> correct).
661 //m_dirLister->stop();
662 //m_dirLister->openUrl(item->url());
663 //return;
664
665 const QString localPath(item->localPath());
666 if (localPath.isEmpty()) {
667 setUrl(item->url());
668 }
669 else {
670 setUrl(KUrl(localPath));
671 }
672 }
673 else {
674 item->run();
675 }
676 }
677
678 void DolphinView::updateUrl()
679 {
680 //KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) :
681 // static_cast<KFileView*>(m_iconsView);
682
683 KFileItem* fileItem = 0; // TODO: fileView->currentFileItem();
684 if (fileItem == 0) {
685 return;
686 }
687
688 if (fileItem->isDir()) {
689 // Prefer the local path over the Url. This assures that the
690 // volume space information is correct. Assuming that the Url is media:/sda1,
691 // and the local path is /windows/C: For the Url the space info is related
692 // to the root partition (and hence wrong) and for the local path the space
693 // info is related to the windows partition (-> correct).
694 const QString localPath(fileItem->localPath());
695 if (localPath.isEmpty()) {
696 setUrl(fileItem->url());
697 }
698 else {
699 setUrl(KUrl(localPath));
700 }
701 }
702 else {
703 fileItem->run();
704 }
705 }
706
707 void DolphinView::slotPercent(int percent)
708 {
709 if (m_showProgress) {
710 m_statusBar->setProgress(percent);
711 }
712 }
713
714 void DolphinView::slotClear()
715 {
716 //fileView()->clearView();
717 updateStatusBar();
718 }
719
720 void DolphinView::slotDeleteItem(KFileItem* item)
721 {
722 //fileView()->removeItem(item);
723 updateStatusBar();
724 }
725
726 void DolphinView::slotCompleted()
727 {
728 m_refreshing = true;
729
730 //KFileView* view = fileView();
731 //view->clearView();
732
733 // TODO: in Qt4 the code should get a lot
734 // simpler and nicer due to Interview...
735 /*if (m_iconsView != 0) {
736 m_iconsView->beginItemUpdates();
737 }
738 if (m_iconsView != 0) {
739 m_iconsView->beginItemUpdates();
740 }*/
741
742 if (m_showProgress) {
743 m_statusBar->setProgressText(QString::null);
744 m_statusBar->setProgress(100);
745 m_showProgress = false;
746 }
747
748 KFileItemList items(m_dirLister->items());
749 KFileItemList::const_iterator it = items.begin();
750 const KFileItemList::const_iterator end = items.end();
751
752 m_fileCount = 0;
753 m_folderCount = 0;
754
755 while (it != end) {
756 KFileItem* item = *it;
757 //view->insertItem(item);
758 if (item->isDir()) {
759 ++m_folderCount;
760 }
761 else {
762 ++m_fileCount;
763 }
764 ++it;
765 }
766
767 updateStatusBar();
768
769 /*if (m_iconsView != 0) {
770 // Prevent a flickering of the icon view widget by giving a small
771 // timeslot to swallow asynchronous update events.
772 m_iconsView->setUpdatesEnabled(false);
773 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
774 }
775
776 if (m_iconsView != 0) {
777 m_iconsView->endItemUpdates();
778 m_refreshing = false;
779 }*/
780 }
781
782 void DolphinView::slotInfoMessage(const QString& msg)
783 {
784 m_statusBar->setMessage(msg, DolphinStatusBar::Information);
785 }
786
787 void DolphinView::slotErrorMessage(const QString& msg)
788 {
789 m_statusBar->setMessage(msg, DolphinStatusBar::Error);
790 }
791
792 void DolphinView::slotGrabActivation()
793 {
794 Dolphin::mainWin().setActiveView(this);
795 }
796
797 void DolphinView::slotContentsMoving(int x, int y)
798 {
799 if (!m_refreshing) {
800 // Only emit a 'contents moved' signal if the user
801 // moved the content by adjusting the sliders. Adjustments
802 // resulted by refreshing a directory should not be respected.
803 emit contentsMoved(x, y);
804 }
805 }
806
807 /*KFileView* DolphinView::fileView() const
808 {
809 return (m_mode == DetailsView) ? static_cast<KFileView*>(m_iconsView) :
810 static_cast<KFileView*>(m_iconsView);
811 }*/
812
813 Q3ScrollView* DolphinView::scrollView() const
814 {
815 return 0; //(m_mode == DetailsView) ? static_cast<Q3ScrollView*>(m_iconsView) :
816 // static_cast<Q3ScrollView*>(m_iconsView);
817 }
818
819 ItemEffectsManager* DolphinView::itemEffectsManager() const
820 {
821 return 0;
822 }
823
824 void DolphinView::startDirLister(const KUrl& url, bool reload)
825 {
826 if (!url.isValid()) {
827 const QString location(url.pathOrUrl());
828 if (location.isEmpty()) {
829 m_statusBar->setMessage(i18n("The location is empty."), DolphinStatusBar::Error);
830 }
831 else {
832 m_statusBar->setMessage(i18n("The location '%1' is invalid.",location),
833 DolphinStatusBar::Error);
834 }
835 return;
836 }
837
838 // Only show the directory loading progress if the status bar does
839 // not contain another progress information. This means that
840 // the directory loading progress information has the lowest priority.
841 const QString progressText(m_statusBar->progressText());
842 m_showProgress = progressText.isEmpty() ||
843 (progressText == i18n("Loading directory..."));
844 if (m_showProgress) {
845 m_statusBar->setProgressText(i18n("Loading directory..."));
846 m_statusBar->setProgress(0);
847 }
848
849 m_refreshing = true;
850 m_dirLister->stop();
851 m_dirLister->openUrl(url, false, reload);
852 }
853
854 QString DolphinView::defaultStatusBarText() const
855 {
856 // TODO: the following code is not suitable for languages where multiple forms
857 // of plurals are given (e. g. in Poland three forms of plurals exist).
858 const int itemCount = m_folderCount + m_fileCount;
859
860 QString text;
861 if (itemCount == 1) {
862 text = i18n("1 Item");
863 }
864 else {
865 text = i18n("%1 Items",itemCount);
866 }
867
868 text += " (";
869
870 if (m_folderCount == 1) {
871 text += i18n("1 Folder");
872 }
873 else {
874 text += i18n("%1 Folders",m_folderCount);
875 }
876
877 text += ", ";
878
879 if (m_fileCount == 1) {
880 text += i18n("1 File");
881 }
882 else {
883 text += i18n("%1 Files",m_fileCount);
884 }
885
886 text += ")";
887
888 return text;
889 }
890
891 QString DolphinView::selectionStatusBarText() const
892 {
893 // TODO: the following code is not suitable for languages where multiple forms
894 // of plurals are given (e. g. in Poland three forms of plurals exist).
895 QString text;
896 const KFileItemList* list = selectedItems();
897 assert((list != 0) && !list->isEmpty());
898
899 int fileCount = 0;
900 int folderCount = 0;
901 KIO::filesize_t byteSize = 0;
902 KFileItemList::const_iterator it = list->begin();
903 const KFileItemList::const_iterator end = list->end();
904 while (it != end){
905 KFileItem* item = *it;
906 if (item->isDir()) {
907 ++folderCount;
908 }
909 else {
910 ++fileCount;
911 byteSize += item->size();
912 }
913 ++it;
914 }
915
916 if (folderCount == 1) {
917 text = i18n("1 Folder selected");
918 }
919 else if (folderCount > 1) {
920 text = i18n("%1 Folders selected",folderCount);
921 }
922
923 if ((fileCount > 0) && (folderCount > 0)) {
924 text += ", ";
925 }
926
927 const QString sizeText(KIO::convertSize(byteSize));
928 if (fileCount == 1) {
929 text += i18n("1 File selected (%1)",sizeText);
930 }
931 else if (fileCount > 1) {
932 text += i18n("%1 Files selected (%1)",fileCount,sizeText);
933 }
934
935 return text;
936 }
937
938 QString DolphinView::renameIndexPresentation(int index, int itemCount) const
939 {
940 // assure that the string reprentation for all indicess have the same
941 // number of characters based on the given number of items
942 QString str(QString::number(index));
943 int chrCount = 1;
944 while (itemCount >= 10) {
945 ++chrCount;
946 itemCount /= 10;
947 }
948 str.reserve(chrCount);
949
950 const int insertCount = chrCount - str.length();
951 for (int i = 0; i < insertCount; ++i) {
952 str.insert(0, '0');
953 }
954 return str;
955 }
956
957 void DolphinView::slotShowFilterBar(bool show)
958 {
959 assert(m_filterBar != 0);
960 if (show) {
961 m_filterBar->show();
962 }
963 else {
964 m_filterBar->hide();
965 }
966 }
967
968 void DolphinView::slotChangeNameFilter(const QString& nameFilter)
969 {
970 // The name filter of KDirLister does a 'hard' filtering, which
971 // means that only the items are shown where the names match
972 // exactly the filter. This is non-transparent for the user, which
973 // just wants to have a 'soft' filtering: does the name contain
974 // the filter string?
975 QString adjustedFilter(nameFilter);
976 adjustedFilter.insert(0, '*');
977 adjustedFilter.append('*');
978
979 m_dirLister->setNameFilter(adjustedFilter);
980 m_dirLister->emitChanges();
981
982 // TODO: this is a workaround for QIconView: the item position
983 // stay as they are by filtering, only an inserting of an item
984 // results to an automatic adjusting of the item position. In Qt4/KDE4
985 // this workaround should get obsolete due to Interview.
986 /*KFileView* view = fileView();
987 if (view == m_iconsView) {
988 KFileItem* first = view->firstFileItem();
989 if (first != 0) {
990 view->removeItem(first);
991 view->insertItem(first);
992 }
993 }*/
994 }
995
996 bool DolphinView::isFilterBarVisible()
997 {
998 return m_filterBar->isVisible();
999 }
1000
1001 void DolphinView::applyModeToView()
1002 {
1003 // TODO: the following code just tries to test some QListView capabilities
1004 switch (m_mode) {
1005 case IconsView:
1006 m_iconsView->setViewMode(QListView::IconMode);
1007 m_iconsView->setGridSize(QSize(128, 64));
1008 break;
1009
1010 case DetailsView:
1011 m_iconsView->setViewMode(QListView::ListMode);
1012 m_iconsView->setGridSize(QSize(256, 24));
1013 break;
1014
1015 case PreviewsView:
1016 m_iconsView->setViewMode(QListView::IconMode);
1017 m_iconsView->setGridSize(QSize(128, 128));
1018 break;
1019 }
1020 }
1021
1022 #include "dolphinview.moc"