-}
-
-void DolphinView::updateProgress(int percent)
-{
- if (m_showProgress) {
- m_statusBar->setProgress(percent);
- }
-}
-
-void DolphinView::updateItemCount()
-{
- if (m_showProgress) {
- m_statusBar->setProgressText(QString());
- m_statusBar->setProgress(100);
- m_showProgress = false;
- }
-
- KFileItemList items(m_dirLister->items());
- KFileItemList::const_iterator it = items.begin();
- const KFileItemList::const_iterator end = items.end();
-
- m_fileCount = 0;
- m_folderCount = 0;
-
- while (it != end) {
- KFileItem* item = *it;
- if (item->isDir()) {
- ++m_folderCount;
- }
- else {
- ++m_fileCount;
- }
- ++it;
- }
-
- updateStatusBar();
-
- QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
-}
-
-void DolphinView::generatePreviews(const KFileItemList& items)
-{
- if (m_controller->showPreview()) {
- KIO::PreviewJob* job = KIO::filePreview(items, 128);
- connect(job, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)),
- this, SLOT(showPreview(const KFileItem*, const QPixmap&)));
- }
-
- const QMimeData* mimeData = QApplication::clipboard()->mimeData();
- if (KonqMimeData::decodeIsCutSelection(mimeData)) {
- QTimer::singleShot(0, this, SLOT(applyCutEffect()));
- }
-}
-
-void DolphinView::showPreview(const KFileItem* item, const QPixmap& pixmap)
-{
- Q_ASSERT(item != 0);
- const QModelIndex idx = m_dirModel->indexForItem(*item);
- if (idx.isValid() && (idx.column() == 0)) {
- const QMimeData* mimeData = QApplication::clipboard()->mimeData();
- if (KonqMimeData::decodeIsCutSelection(mimeData) && isCutItem(*item)) {
- KIconEffect iconEffect;
- QPixmap cutPixmap = iconEffect.apply(pixmap, K3Icon::Desktop, K3Icon::DisabledState);
- m_dirModel->setData(idx, cutPixmap, Qt::DecorationRole);
- }
- else {
- m_dirModel->setData(idx, pixmap, Qt::DecorationRole);
- }
- }
-}
-
-void DolphinView::restoreContentsPos()
-{
- int index = 0;
- const QLinkedList<UrlNavigator::HistoryElem> history = urlHistory(index);
- if (!history.isEmpty()) {
- QAbstractItemView* view = itemView();
- // TODO: view->setCurrentItem(history[index].currentFileName());
-
- QLinkedList<UrlNavigator::HistoryElem>::const_iterator it = history.begin();
- it += index;
- view->horizontalScrollBar()->setValue((*it).contentsX());
- view->verticalScrollBar()->setValue((*it).contentsY());
- }
-}
-
-void DolphinView::showInfoMessage(const QString& msg)
-{
- m_statusBar->setMessage(msg, DolphinStatusBar::Information);
-}
-
-void DolphinView::showErrorMessage(const QString& msg)
-{
- m_statusBar->setMessage(msg, DolphinStatusBar::Error);
-}
-
-void DolphinView::emitSelectionChangedSignal()
-{
- emit selectionChanged();
-}
-
-void DolphinView::closeFilterBar()
-{
- m_filterBar->hide();
- emit showFilterBarChanged(false);
-}
-
-void DolphinView::startDirLister(const KUrl& url, bool reload)
-{
- if (!url.isValid()) {
- const QString location(url.pathOrUrl());
- if (location.isEmpty()) {
- m_statusBar->setMessage(i18n("The location is empty."), DolphinStatusBar::Error);
- }
- else {
- m_statusBar->setMessage(i18n("The location '%1' is invalid.",location),
- DolphinStatusBar::Error);
- }
- return;
- }
-
- // Only show the directory loading progress if the status bar does
- // not contain another progress information. This means that
- // the directory loading progress information has the lowest priority.
- const QString progressText(m_statusBar->progressText());
- m_showProgress = progressText.isEmpty() ||
- (progressText == i18n("Loading directory..."));
- if (m_showProgress) {
- m_statusBar->setProgressText(i18n("Loading directory..."));
- m_statusBar->setProgress(0);
- }
-
- m_dirLister->stop();
- m_dirLister->openUrl(url, false, reload);
-}
-
-QString DolphinView::defaultStatusBarText() const
-{
- return KIO::itemsSummaryString(m_fileCount + m_folderCount,
- m_fileCount,
- m_folderCount,
- 0, false);
-}
-
-QString DolphinView::selectionStatusBarText() const
-{
- QString text;
- const KFileItemList list = selectedItems();
- if (list.isEmpty()) {
- // when an item is triggered, it is temporary selected but selectedItems()
- // will return an empty list
- return QString();
- }
-
- int fileCount = 0;
- int folderCount = 0;
- KIO::filesize_t byteSize = 0;
- KFileItemList::const_iterator it = list.begin();
- const KFileItemList::const_iterator end = list.end();
- while (it != end){
- KFileItem* item = *it;
- if (item->isDir()) {
- ++folderCount;
- }
- else {
- ++fileCount;
- byteSize += item->size();
- }
- ++it;
- }
-
- if (folderCount > 0) {
- text = i18np("1 Folder selected", "%1 Folders selected", folderCount);
- if (fileCount > 0) {
- text += ", ";
- }
- }
-
- if (fileCount > 0) {
- const QString sizeText(KIO::convertSize(byteSize));
- text += i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText);
- }
-
- return text;
-}
-
-void DolphinView::showFilterBar(bool show)
-{
- Q_ASSERT(m_filterBar != 0);
- if (show) {
- m_filterBar->show();
- }
- else {
- m_filterBar->hide();
- }
-}
-
-void DolphinView::updateStatusBar()
-{
- // As the item count information is less important
- // in comparison with other messages, it should only
- // be shown if:
- // - the status bar is empty or
- // - shows already the item count information or
- // - shows only a not very important information
- // - if any progress is given don't show the item count info at all
- const QString msg(m_statusBar->message());
- const bool updateStatusBarMsg = (msg.isEmpty() ||
- (msg == m_statusBar->defaultText()) ||
- (m_statusBar->type() == DolphinStatusBar::Information)) &&
- (m_statusBar->progress() == 100);
-
- const QString text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
- m_statusBar->setDefaultText(text);
-
- if (updateStatusBarMsg) {
- m_statusBar->setMessage(text, DolphinStatusBar::Default);
- }
-}
-
-void DolphinView::requestActivation()
-{
- m_mainWindow->setActiveView(this);
-}
-
-void DolphinView::updateCutItems()
-{
- const QMimeData* mimeData = QApplication::clipboard()->mimeData();
- if (!KonqMimeData::decodeIsCutSelection(mimeData)) {
- return;
- }
-
- KFileItemList items(m_dirLister->items());
- KFileItemList::const_iterator it = items.begin();
- const KFileItemList::const_iterator end = items.end();
- while (it != end) {
- KFileItem* item = *it;
- if (isCutItem(*item)) {
- QPixmap pixmap = item->pixmap(0);
- KIconEffect iconEffect;
- pixmap = iconEffect.apply(pixmap, K3Icon::Desktop, K3Icon::DisabledState);
- const QModelIndex idx = m_dirModel->indexForItem(*item);
- if (idx.isValid()) {
- m_dirModel->setData(idx, pixmap, Qt::DecorationRole);
- }
- }
- ++it;
- }
-}
-
-void DolphinView::changeNameFilter(const QString& nameFilter)
-{
- // The name filter of KDirLister does a 'hard' filtering, which
- // means that only the items are shown where the names match
- // exactly the filter. This is non-transparent for the user, which
- // just wants to have a 'soft' filtering: does the name contain
- // the filter string?
- QString adjustedFilter(nameFilter);
- adjustedFilter.insert(0, '*');
- adjustedFilter.append('*');
-
- // Use the ProxyModel to filter:
- // This code is #ifdefed as setNameFilter behaves
- // slightly different than the QSortFilterProxyModel
- // as it will not remove directories. I will ask
- // our beloved usability experts for input
- // -- z.
-#if 0
- m_dirLister->setNameFilter(adjustedFilter);
- m_dirLister->emitChanges();
-#else
- m_proxyModel->setFilterRegExp( nameFilter );
-#endif