void AsyncFileTester::checkIfFolder(const QModelIndex &index, QObject *object, const char *method) { if (!index.isValid()) { callResultMethod(object, method, index, false); return; } KFileItem item = static_cast<const ProxyModel*>(index.model())->itemForIndex(index); KUrl url = item.targetUrl(); if (item.isDir()) { callResultMethod(object, method, index, true); return; } 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); callResultMethod(object, method, index, destItem.isDir()); return; } if (KProtocolInfo::protocolClass(url.protocol()) == QString(":local")) { AsyncFileTester *tester = new AsyncFileTester(index, object, method); tester->delayedFolderCheck(url); return; } } } callResultMethod(object, method, index, false); }
void DolphinViewContainer::slotItemTriggered(const KFileItem& item) { KUrl url = item.targetUrl(); if (item.isDir()) { m_view->setUrl(url); return; } const GeneralSettings* settings = DolphinSettings::instance().generalSettings(); const bool browseThroughArchives = settings->browseThroughArchives(); if (browseThroughArchives && item.isFile() && url.isLocalFile()) { // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file, // zip:/<path>/ when clicking on a zip file, etc. // The .protocol file specifies the mimetype that the kioslave handles. // Note that we don't use mimetype inheritance since we don't want to // open OpenDocument files as zip folders... const QString protocol = KProtocolManager::protocolForArchiveMimetype(item.mimetype()); if (!protocol.isEmpty()) { url.setProtocol(protocol); m_view->setUrl(url); return; } } if (item.mimetype() == "application/x-desktop") { // redirect to the url in Type=Link desktop files KDesktopFile desktopFile(url.toLocalFile()); if (desktopFile.hasLinkType()) { url = desktopFile.readUrl(); m_view->setUrl(url); return; } } item.run(); }
PopupView::PopupView(const QModelIndex &index, const QPoint &pos, const bool &showPreview, const QStringList &previewPlugins, const IconView *parentView) : QWidget(0, Qt::X11BypassWindowManagerHint), m_view(0), m_parentView(parentView), m_busyWidget(0), m_iconView(0), m_parentViewModel(0), m_dirModel(0), m_model(0), m_actionCollection(this), m_newMenu(0), m_itemActions(0), m_showingMenu(false), m_showPreview(showPreview), m_delayedClose(false), m_previewPlugins(previewPlugins) { setAttribute(Qt::WA_TranslucentBackground); #ifdef Q_WS_X11 if (KWindowSystem::compositingActive()) { setAttribute(Qt::WA_NoSystemBackground, false); } #endif #ifdef Q_WS_WIN setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool); #endif KWindowSystem::setState(effectiveWinId(), NET::SkipTaskbar | NET::SkipPager); setAcceptDrops(true); QPalette pal = palette(); pal.setColor(backgroundRole(), Qt::transparent); pal.setColor(QPalette::Text, Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)); setPalette(pal); m_parentViewModel = static_cast<const ProxyModel*>(index.model()); KFileItem item = m_parentViewModel->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("dialogs/background"); int left = m_background->marginSize(Plasma::LeftMargin); int top = m_background->marginSize(Plasma::TopMargin); int right = m_background->marginSize(Plasma::RightMargin); int bottom = m_background->marginSize(Plasma::BottomMargin); setContentsMargins(left, top, right, bottom); resize(parentView->sizeForRowsColumns(2, 3) + QSize(left + right, top + bottom)); const QRect available = QApplication::desktop()->availableGeometry(pos); QPoint pt = pos; if (pt.x() + width() > available.right()) { pt.rx() -= width(); } if (pt.x() < available.left()) { pt.rx() = available.left(); } if (pt.y() + height() > available.bottom()) { pt.ry() -= height(); } if (pt.y() < available.top()) { pt.ry() = available.top(); } Plasma::WindowEffects::overrideShadow(winId(), true); move(pt); show(); QTimer::singleShot(10, this, SLOT(init())); s_lastOpenClose.restart(); }
void InformationPanelContent::showItem(const KFileItem& item) { // If there is a preview job, kill it to prevent that we have jobs for // multiple items running, and thus a race condition (bug 250787). if (m_previewJob) { m_previewJob->kill(); } const QUrl itemUrl = item.url(); const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && item.localPath().isEmpty(); if (!applyPlace(itemUrl)) { setNameLabelText(item.text()); if (isSearchUrl) { // in the case of a search-URL the URL is not readable for humans // (at least not useful to show in the Information Panel) KIconLoader iconLoader; QPixmap icon = iconLoader.loadIcon(QStringLiteral("nepomuk"), KIconLoader::NoGroup, KIconLoader::SizeEnormous); m_preview->setPixmap(icon); } else { // try to get a preview pixmap from the item... // Mark the currently shown preview as outdated. This is done // with a small delay to prevent a flickering when the next preview // can be shown within a short timeframe. This timer is not started // for directories, as directory previews might fail and return the // same icon. if (!item.isDir()) { m_outdatedPreviewTimer->start(); } m_previewJob = new KIO::PreviewJob(KFileItemList() << item, QSize(m_preview->width(), m_preview->height())); m_previewJob->setScaleType(KIO::PreviewJob::Unscaled); m_previewJob->setIgnoreMaximumSize(item.isLocalFile()); if (m_previewJob->ui()) { KJobWidgets::setWindow(m_previewJob, this); } connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, this, &InformationPanelContent::showPreview); connect(m_previewJob.data(), &KIO::PreviewJob::failed, this, &InformationPanelContent::showIcon); } } if (m_metaDataWidget) { m_metaDataWidget->show(); m_metaDataWidget->setItems(KFileItemList() << item); } if (InformationPanelSettings::previewsShown()) { const QString mimeType = item.mimetype(); const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || mimeType.startsWith(QLatin1String("video/")); if (usePhonon) { m_phononWidget->show(); m_phononWidget->setUrl(item.targetUrl()); if (m_preview->isVisible()) { m_phononWidget->setVideoSize(m_preview->size()); } } else { m_phononWidget->hide(); m_preview->setVisible(true); } } else { m_phononWidget->hide(); } m_item = item; }
void InformationPanelContent::showItem(const KFileItem& item) { m_pendingPreview = false; const KUrl itemUrl = item.url(); const bool isSearchUrl = itemUrl.protocol().contains("search") && item.nepomukUri().isEmpty(); if (!applyPlace(itemUrl)) { setNameLabelText(item.text()); if (isSearchUrl) { // in the case of a search-URL the URL is not readable for humans // (at least not useful to show in the Information Panel) KIconLoader iconLoader; QPixmap icon = iconLoader.loadIcon("nepomuk", KIconLoader::NoGroup, KIconLoader::SizeEnormous); m_preview->setPixmap(icon); } else { // try to get a preview pixmap from the item... m_pendingPreview = true; // Mark the currently shown preview as outdated. This is done // with a small delay to prevent a flickering when the next preview // can be shown within a short timeframe. This timer is not started // for directories, as directory previews might fail and return the // same icon. if (!item.isDir()) { m_outdatedPreviewTimer->start(); } KIO::PreviewJob* job = new KIO::PreviewJob(KFileItemList() << item, QSize(m_preview->width(), m_preview->height())); job->setScaleType(KIO::PreviewJob::Unscaled); job->setIgnoreMaximumSize(item.isLocalFile()); if (job->ui()) { job->ui()->setWindow(this); } connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)), this, SLOT(showPreview(KFileItem,QPixmap))); connect(job, SIGNAL(failed(KFileItem)), this, SLOT(showIcon(KFileItem))); } } if (m_metaDataWidget) { m_metaDataWidget->show(); m_metaDataWidget->setItems(KFileItemList() << item); } if (InformationPanelSettings::previewsShown()) { const QString mimeType = item.mimetype(); const bool usePhonon = mimeType.startsWith("audio/") || mimeType.startsWith("video/"); if (usePhonon) { m_phononWidget->show(); m_phononWidget->setUrl(item.targetUrl()); if (m_preview->isVisible()) { m_phononWidget->setVideoSize(m_preview->size()); } } else { m_phononWidget->hide(); m_preview->setVisible(true); } } else { m_phononWidget->hide(); } m_item = item; }