SVN commit 1124160 by fredrik: Split the folder testing code out into a separate class. M +2 -1 CMakeLists.txt A asyncfiletester.cpp [License: LGPL (v2+)] A asyncfiletester.h [License: LGPL (v2+)] M +10 -49 iconview.cpp M +1 -2 iconview.h M +9 -2 popupview.cpp M +1 -1 popupview.h --- trunk/KDE/kdebase/apps/plasma/applets/folderview/CMakeLists.txt #1124159:1124160 @@ -21,7 +21,8 @@ style.cpp itemeditor.cpp animator.cpp - actionoverlay.cpp) + actionoverlay.cpp + asyncfiletester.cpp) kde4_add_ui_files(folderview_SRCS folderviewFilterConfig.ui --- trunk/KDE/kdebase/apps/plasma/applets/folderview/iconview.cpp #1124159:1124160 @@ -39,7 +39,6 @@ #include #include -#include #include #include #include @@ -57,6 +56,7 @@ #include "previewpluginsmodel.h" #include "tooltipwidget.h" #include "animator.h" +#include "asyncfiletester.h" #include #include @@ -1544,7 +1544,6 @@ // Close the popup view if one is open m_toolTipShowTimer.stop(); m_popupCausedWidget = 0; - m_popupUrl = KUrl(); if (m_popupView) { m_popupView->delayedHide(); } @@ -1566,56 +1565,20 @@ return; } - if (m_popupView && m_hoveredIndex == m_popupIndex) { - // If we're already showing a popup view for this index + if (!m_popupView || m_hoveredIndex != m_popupIndex) { + // If we're not already showing a popup view for this index + m_popupCausedWidget = causedWidget; + AsyncFileTester::checkIfFolder(m_hoveredIndex, this, "checkIfFolderResult"); return; } - - // Decide if we're going to show a popup view or a regular tooltip - IconView::ToolTipType type = IconView::FileTip; - bool delayedResult = false; - - KFileItem item = m_model->itemForIndex(m_hoveredIndex); - KUrl url = item.targetUrl(); - - if (item.isDir()) { - type = IconView::FolderTip; - } else if (item.isDesktopFile()) { - // Check if the desktop file is a link to a local folder - KDesktopFile file(url.path()); - if (file.readType() == "Link") { - url = file.readUrl(); - if (url.isLocalFile()) { - KFileItem destItem(KFileItem::Unknown, KFileItem::Unknown, url); - type = destItem.isDir() ? IconView::FolderTip : IconView::FileTip; - } else if (KProtocolInfo::protocolClass(url.protocol()) == QString(":local")) { - KIO::StatJob *job = KIO::stat(url, KIO::HideProgressInfo); - job->setSide(KIO::StatJob::SourceSide); // We will only read the file - connect(job, SIGNAL(result(KJob*)), SLOT(statResult(KJob*))); - delayedResult = true; } - } - } - m_popupUrl = url; - m_popupCausedWidget = causedWidget; - - if (!delayedResult) { - triggerToolTip(type); - } -} - -void IconView::statResult(KJob *job) +void IconView::checkIfFolderResult(const QModelIndex &index, bool isFolder) { - if (!job->error()) { - KIO::StatJob *statJob = static_cast(job); - if (statJob->statResult().isDir()) { - triggerToolTip(IconView::FolderTip); - } else { - triggerToolTip(IconView::FileTip); + if (index == m_hoveredIndex) { + triggerToolTip(isFolder ? FolderTip : FileTip); } } -} void IconView::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { @@ -2655,7 +2618,6 @@ return; } - if (!m_popupUrl.isEmpty()) { const QPointF viewPos = mapFromViewport(visualRect(m_hoveredIndex)).center(); const QPoint scenePos = mapToScene(viewPos).toPoint(); QGraphicsView *gv = 0; @@ -2673,11 +2635,10 @@ } const QPoint pos = gv ? gv->mapToGlobal(gv->mapFromScene(scenePos)) : QPoint(); - m_popupView = new PopupView(m_popupUrl, pos, m_popupShowPreview, m_popupPreviewPlugins, this); + m_popupIndex = m_hoveredIndex; + m_popupView = new PopupView(m_popupIndex, pos, m_popupShowPreview, m_popupPreviewPlugins, this); connect(m_popupView, SIGNAL(destroyed(QObject*)), SIGNAL(popupViewClosed())); connect(m_popupView, SIGNAL(requestClose()), SLOT(popupCloseRequested())); - m_popupIndex = m_hoveredIndex; - } } else if (event->timerId() == m_searchQueryTimer.timerId()) { m_searchQuery.clear(); m_searchQueryTimer.stop(); --- trunk/KDE/kdebase/apps/plasma/applets/folderview/iconview.h #1124159:1124160 @@ -187,9 +187,9 @@ void popupCloseRequested(); void dropActionTriggered(QAction *action); void dropCompleted(); - void statResult(KJob *job); void repositionWidgetsManually(); void closeEditor(QGraphicsWidget *editor, QAbstractItemDelegate::EndEditHint hint); + void checkIfFolderResult(const QModelIndex &index, bool isFolder); private: void paintMessage(QPainter *painter, const QRect &rect, const QString &message, @@ -256,7 +256,6 @@ ToolTipWidget *m_toolTipWidget; QPointer m_popupView; QPointer m_popupCausedWidget; - KUrl m_popupUrl; KonqOperations *m_dropOperation; QActionGroup *m_dropActions; QPersistentModelIndex m_popupIndex; --- trunk/KDE/kdebase/apps/plasma/applets/folderview/popupview.cpp #1124159:1124160 @@ -62,7 +62,7 @@ QTime PopupView::s_lastOpenClose; -PopupView::PopupView(const KUrl &url, const QPoint &pos, +PopupView::PopupView(const QModelIndex &index, const QPoint &pos, const bool &showPreview, const QStringList &previewPlugins, const IconView *parentView) : QWidget(0, Qt::X11BypassWindowManagerHint), @@ -72,7 +72,6 @@ m_iconView(0), m_dirModel(0), m_model(0), - m_url(url), m_actionCollection(this), m_newMenu(0), m_itemActions(0), @@ -100,6 +99,14 @@ pal.setColor(QPalette::Text, Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)); setPalette(pal); + KFileItem item = static_cast(index.model())->itemForIndex(index); + if (item.isDesktopFile()) { + KDesktopFile file(item.localPath()); + m_url = file.readUrl(); + } else { + m_url = item.targetUrl(); + } + m_background = new Plasma::FrameSvg(this); m_background->setImagePath("widgets/tooltip"); --- trunk/KDE/kdebase/apps/plasma/applets/folderview/popupview.h #1124159:1124160 @@ -52,7 +52,7 @@ Q_OBJECT public: - PopupView(const KUrl &url, const QPoint &pos, + PopupView(const QModelIndex &index, const QPoint &pos, const bool &showPreview, const QStringList &previewPlugins, const IconView *parentView); ~PopupView();