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