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