X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/81fcd720a2cc095262e52b8a40dd1472d774a415..c8072005fada01d772595ec64adca449134f421e:/src/dolphinviewcontainer.cpp diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 32d5a407f..c30b2d0bc 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -27,7 +27,6 @@ #include #include -#include #include #include #include @@ -41,6 +40,7 @@ #include #include +#include "dolphinmodel.h" #include "dolphincolumnview.h" #include "dolphincontroller.h" #include "dolphinstatusbar.h" @@ -50,7 +50,6 @@ #include "dolphindetailsview.h" #include "dolphiniconsview.h" #include "dolphincontextmenu.h" -#include "dolphinitemcategorizer.h" #include "filterbar.h" #include "renamedialog.h" #include "kurlnavigator.h" @@ -71,7 +70,6 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow, m_view(0), m_filterBar(0), m_statusBar(0), - m_dirModel(0), m_dirLister(0), m_proxyModel(0) { @@ -81,10 +79,6 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow, m_topLayout->setSpacing(0); m_topLayout->setMargin(0); - QClipboard* clipboard = QApplication::clipboard(); - connect(clipboard, SIGNAL(dataChanged()), - this, SLOT(updateCutItems())); - m_urlNavigator = new KUrlNavigator(DolphinSettings::instance().placesModel(), url, this); connect(m_urlNavigator, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&)), m_mainWindow, SLOT(dropUrls(const KUrl::List&, const KUrl&))); @@ -100,12 +94,13 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow, m_dirLister->setMainWindow(this); m_dirLister->setDelayedMimeTypes(true); - m_dirModel = new KDirModel(); - m_dirModel->setDirLister(m_dirLister); - m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory); + m_dolphinModel = new DolphinModel(); + m_dolphinModel->setDirLister(m_dirLister); + m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); + m_proxyModel = new DolphinSortFilterProxyModel(this); - m_proxyModel->setSourceModel(m_dirModel); + m_proxyModel->setSourceModel(m_dolphinModel); connect(m_dirLister, SIGNAL(clear()), this, SLOT(updateStatusBar())); @@ -123,7 +118,7 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow, m_view = new DolphinView(this, url, m_dirLister, - m_dirModel, + m_dolphinModel, m_proxyModel); connect(m_view, SIGNAL(urlChanged(const KUrl&)), m_urlNavigator, SLOT(setUrl(const KUrl&))); @@ -139,11 +134,15 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow, this, SLOT(showErrorMessage(const QString&))); connect(m_view, SIGNAL(infoMessage(const QString&)), this, SLOT(showInfoMessage(const QString&))); + connect(m_view, SIGNAL(itemTriggered(KFileItem)), + this, SLOT(slotItemTriggered(KFileItem))); connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)), m_view, SLOT(setUrl(const KUrl&))); m_statusBar = new DolphinStatusBar(this, url); + connect(m_view, SIGNAL(urlChanged(const KUrl&)), + m_statusBar, SLOT(updateSpaceInfoContent(const KUrl&))); m_filterBar = new FilterBar(this); m_filterBar->setVisible(settings->filterBar()); @@ -189,11 +188,11 @@ bool DolphinViewContainer::isActive() const void DolphinViewContainer::renameSelectedItems() { DolphinViewContainer* view = m_mainWindow->activeViewContainer(); - const KUrl::List urls = m_view->selectedUrls(); - if (urls.count() > 1) { + const QList items = m_view->selectedItems(); + if (items.count() > 1) { // More than one item has been selected for renaming. Open // a rename dialog and rename all items afterwards. - RenameDialog dialog(urls); + RenameDialog dialog(items); if (dialog.exec() == QDialog::Rejected) { return; } @@ -212,10 +211,10 @@ void DolphinViewContainer::renameSelectedItems() Q_ASSERT(replaceIndex >= 0); int index = 1; - KUrl::List::const_iterator it = urls.begin(); - KUrl::List::const_iterator end = urls.end(); + QList::const_iterator it = items.begin(); + QList::const_iterator end = items.end(); while (it != end) { - const KUrl& oldUrl = *it; + const KUrl& oldUrl = (*it).url(); QString number; number.setNum(index++); @@ -233,12 +232,12 @@ void DolphinViewContainer::renameSelectedItems() } else { // Only one item has been selected for renaming. Use the custom // renaming mechanism from the views. - Q_ASSERT(urls.count() == 1); + Q_ASSERT(items.count() == 1); // TODO: Think about using KFileItemDelegate as soon as it supports editing. // Currently the RenameDialog is used, but I'm not sure whether inline renaming // is a benefit for the user at all -> let's wait for some input first... - RenameDialog dialog(urls); + RenameDialog dialog(items); if (dialog.exec() == QDialog::Rejected) { return; } @@ -248,7 +247,7 @@ void DolphinViewContainer::renameSelectedItems() view->statusBar()->setMessage(dialog.errorString(), DolphinStatusBar::Error); } else { - const KUrl& oldUrl = urls.first(); + const KUrl& oldUrl = items.first().url(); KUrl newUrl = oldUrl; newUrl.setFileName(newName); m_mainWindow->rename(oldUrl, newUrl); @@ -268,8 +267,8 @@ bool DolphinViewContainer::isUrlEditable() const KFileItem DolphinViewContainer::fileItem(const QModelIndex& index) const { - const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index); - return m_dirModel->itemForIndex(dirModelIndex); + const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); + return m_dolphinModel->itemForIndex(dolphinModelIndex); } void DolphinViewContainer::updateProgress(int percent) @@ -349,6 +348,21 @@ void DolphinViewContainer::closeFilterBar() QString DolphinViewContainer::defaultStatusBarText() const { + int m_fileCount = 0; + int m_folderCount = 0; + + for (int i = 0; i < m_proxyModel->rowCount(); i++) + { + if (m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(m_proxyModel->index(i, m_proxyModel->sortColumn()))).isDir()) + { + m_folderCount++; + } + else + { + m_fileCount++; + } + } + return KIO::itemsSummaryString(m_fileCount + m_folderCount, m_fileCount, m_folderCount, @@ -448,6 +462,8 @@ void DolphinViewContainer::changeNameFilter(const QString& nameFilter) #else m_proxyModel->setFilterRegExp(nameFilter); #endif + + updateStatusBar(); } void DolphinViewContainer::openContextMenu(const KFileItem& item, @@ -475,4 +491,33 @@ void DolphinViewContainer::activate() setActive(true); } +void DolphinViewContainer::slotItemTriggered(const KFileItem& item) +{ + // Prefer the local path over the URL. + bool isLocal; + KUrl url = item.mostLocalUrl(isLocal); + + if (item.isDir()) { + m_view->setUrl(url); + } else if (item.isFile()) { + // allow to browse through ZIP and tar files + KMimeType::Ptr mime = item.mimeTypePtr(); + if (mime->is("application/zip")) { + url.setProtocol("zip"); + m_view->setUrl(url); + } else if (mime->is("application/x-tar") || + mime->is("application/x-tarz") || + mime->is("application/x-bzip-compressed-tar") || + mime->is("application/x-compressed-tar") || + mime->is("application/x-tzo")) { + url.setProtocol("tar"); + m_view->setUrl(url); + } else { + item.run(); + } + } else { + item.run(); + } +} + #include "dolphinviewcontainer.moc"