-
- const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
- if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) {
- // items are selected by the user, hence don't trigger the
- // item specified by 'index'
- return;
- }
-
- KFileItem* item = m_dirModel->itemForIndex(m_proxyModel->mapToSource(index));
- if (item == 0) {
- return;
- }
-
- // Prefer the local path over the URL. This assures that the
- // volume space information is correct. Assuming that the URL is media:/sda1,
- // and the local path is /windows/C: For the URL the space info is related
- // to the root partition (and hence wrong) and for the local path the space
- // info is related to the windows partition (-> correct).
- const QString localPath(item->localPath());
- KUrl url;
- if (localPath.isEmpty()) {
- url = item->url();
- } else {
- url = localPath;
- }
-
- if (item->isDir()) {
- 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");
- 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");
- setUrl(url);
- } else {
- item->run();
- }
- } else {
- item->run();
- }
-}
-
-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();
-
- m_blockContentsMovedSignal = false;
- QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
-}
-
-void DolphinView::generatePreviews(const KFileItemList& items)
-{
- if (m_controller->showPreview()) {
-
- // Must turn QList<KFileItem *> to QList<KFileItem>...
- QList<KFileItem> itemsToPreview;
- foreach( KFileItem* it, items )
- itemsToPreview.append( *it );
-
- KIO::PreviewJob* job = KIO::filePreview(itemsToPreview, 128);
- connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
- this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
- }
-}
-
-void DolphinView::showPreview(const KFileItem& item, const QPixmap& pixmap)
-{
- Q_ASSERT(!item.isNull());
- if (item.url().directory() != m_dirLister->url().path()) {
- // the preview job is still working on items of an older URL, hence
- // the item is not part of the directory model anymore
- return;
- }
-
- 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;
- const QPixmap cutPixmap = iconEffect.apply(pixmap, K3Icon::Desktop, K3Icon::DisabledState);
- m_dirModel->setData(idx, QIcon(cutPixmap), Qt::DecorationRole);
- } else {
- m_dirModel->setData(idx, QIcon(pixmap), Qt::DecorationRole);
- }
- }
-}
-
-void DolphinView::restoreContentsPos()
-{
- KUrl currentUrl = m_urlNavigator->url();
- if (!currentUrl.isEmpty()) {
- QAbstractItemView* view = itemView();
- // TODO: view->setCurrentItem(m_urlNavigator->currentFileName());
- QPoint pos = m_urlNavigator->savedPosition();
- view->horizontalScrollBar()->setValue(pos.x());
- view->verticalScrollBar()->setValue(pos.y());
- }
-}
-
-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(DolphinView::selectedItems());
-}
-
-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 folder..."));
- if (m_showProgress) {
- m_statusBar->setProgressText(i18n("Loading folder..."));
- m_statusBar->setProgress(0);
- }
-
- m_cutItemsCache.clear();
- m_blockContentsMovedSignal = true;
- m_dirLister->stop();
-
- bool openDir = true;
- bool keepOldDirs = isColumnViewActive() && !m_initializeColumnView;
- m_initializeColumnView = false;
-
- if (keepOldDirs) {
- if (reload) {
- keepOldDirs = false;
-
- const KUrl& dirListerUrl = m_dirLister->url();
- if (dirListerUrl.isValid()) {
- const KUrl::List dirs = m_dirLister->directories();
- KUrl url;
- foreach(url, dirs) {
- m_dirLister->updateDirectory(url);
- }
- openDir = false;
- }
- } else if (m_dirLister->directories().contains(url)) {
- // The dir lister contains the directory already, so
- // KDirLister::openUrl() may not been invoked twice.
- m_dirLister->updateDirectory(url);
- openDir = false;
- } else {
- const KUrl& dirListerUrl = m_dirLister->url();
- if ((dirListerUrl == url) || !m_dirLister->url().isParentOf(url)) {
- // The current URL is not a child of the dir lister
- // URL. This may happen when e. g. a bookmark has been selected
- // and hence the view must be reset.
- keepOldDirs = false;
- }
- }
- }
-
- if (openDir) {
- m_dirLister->openUrl(url, keepOldDirs, 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::changeSelection(const KFileItemList& selection)
-{
- clearSelection();
- if (selection.isEmpty()) {
- return;
- }
- KUrl baseUrl = url();