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); }
QVariant DirModel::data( const QModelIndex & index, int role ) const { if (role != Qt::DisplayRole) { return KDirModel::data(index, role); } KFileItem item = itemForIndex(index); if(item.isDesktopFile()) { KDesktopFile f(item.url().path()); QString name = f.readName(); if(!name.isEmpty()){ return name; } } return item.text(); }
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 KonqOperations::asyncDrop( const KFileItem & destItem ) { assert(m_info); // setDropInfo should have been called before asyncDrop bool m_destIsLocal = false; m_destUrl = destItem.mostLocalUrl(m_destIsLocal); // #168154 //kDebug(1203) << "destItem->mode=" << destItem->mode() << " url=" << m_destUrl; // Check what the destination is if ( destItem.isDir() ) { doDropFileCopy(); return; } if ( !m_destIsLocal ) { // We dropped onto a remote URL that is not a directory! // (e.g. an HTTP link in the sidebar). // Can't do that, but we can't prevent it before stating the dest.... kWarning(1203) << "Cannot drop onto " << m_destUrl ; deleteLater(); return; } if ( destItem.isDesktopFile() ) { // Local .desktop file. What type ? KDesktopFile desktopFile( m_destUrl.path() ); KConfigGroup desktopGroup = desktopFile.desktopGroup(); if ( desktopFile.hasApplicationType() ) { QString error; const QStringList urlStrList = m_info->urls.toStringList(); if ( KToolInvocation::startServiceByDesktopPath( m_destUrl.path(), urlStrList, &error ) > 0 ) KMessageBox::error( parentWidget(), error ); } else { // Device or Link -> adjust dest if ( desktopFile.hasDeviceType() && desktopGroup.hasKey("MountPoint") ) { QString point = desktopGroup.readEntry( "MountPoint" ); m_destUrl.setPath( point ); QString dev = desktopFile.readDevice(); KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByDevice( dev ); // Is the device already mounted ? if ( mp ) { doDropFileCopy(); } else { const bool ro = desktopGroup.readEntry( "ReadOnly", false ); const QByteArray fstype = desktopGroup.readEntry( "FSType" ).toLatin1(); KAutoMount* am = new KAutoMount( ro, fstype, dev, point, m_destUrl.path(), false ); connect( am, SIGNAL(finished()), this, SLOT(doDropFileCopy()) ); } return; } else if ( desktopFile.hasLinkType() && desktopGroup.hasKey("URL") ) { m_destUrl = desktopGroup.readPathEntry("URL", QString()); doDropFileCopy(); return; } // else, well: mimetype, service, servicetype or .directory. Can't really drop anything on those. } } else { // Should be a local executable // (If this fails, there is a bug in KFileItem::acceptsDrops / KDirModel::flags) kDebug(1203) << m_destUrl.path() << "should be an executable"; Q_ASSERT ( access( QFile::encodeName(m_destUrl.path()), X_OK ) == 0 ); // Launch executable for each of the files QStringList args; const KUrl::List lst = m_info->urls; KUrl::List::ConstIterator it = lst.begin(); for ( ; it != lst.end() ; it++ ) args << (*it).path(); // assume local files kDebug(1203) << "starting " << m_destUrl.path() << " with " << lst.count() << " arguments"; QProcess::startDetached( m_destUrl.path(), args ); } deleteLater(); }