Exemplo n.º 1
0
void AsyncFileTester::statResult(KJob *job)
{
    if (object && !job->error()) {
        KIO::StatJob *statJob = static_cast<KIO::StatJob*>(job);
        callResultMethod(object.data(), member, index, statJob->statResult().isDir());
    }
    deleteLater();
}
Exemplo n.º 2
0
void KSysinfoPart::slotResult( KIO::Job *job )
{
    KIO::StatJob *sjob = dynamic_cast<KIO::StatJob*>( job );
    if (!job)
        return;

    KFileItem item(sjob->statResult(), sjob->url());
    KFileItemList list;
    list.append(&item);
    emit browserExtension()->popupMenu( 0, QCursor::pos(), list );
}
Exemplo n.º 3
0
KUrl KDirSelectDialog::url() const
{
    KUrl comboUrl(d->m_urlCombo->currentText());

    if ( comboUrl.isValid() ) {
       KIO::StatJob *statJob = KIO::stat(comboUrl, KIO::HideProgressInfo);
       const bool ok = KIO::NetAccess::synchronousRun(statJob, d->m_parent);
       if (ok && statJob->statResult().isDir()) {
           return comboUrl;
       }
    }

    kDebug() << comboUrl.path() << " is not an accessible directory";
    return d->m_treeView->currentUrl();
}
Exemplo n.º 4
0
void RecentDocuments::listDir(const QUrl& url)
{
    if (isRootUrl(url)) {
        QStringList list = KRecentDocument::recentDocuments();
        KIO::UDSEntryList udslist;
        QSet<QString> urlSet;
        Q_FOREACH(const QString & entry, list) {
            if (KDesktopFile::isDesktopFile(entry)) {
                QFileInfo info(entry);
                KDesktopFile file(entry);

                QUrl urlInside(file.readUrl());
                QString toDisplayString = urlInside.toDisplayString();
                if (urlInside.scheme() == "recentdocuments" || urlSet.contains(toDisplayString))
                    continue;

                KIO::UDSEntry uds;
                if (urlInside.isLocalFile()) {
                    KIO::StatJob* job = KIO::stat(urlInside, KIO::HideProgressInfo);
                    // we do not want to wait for the event loop to delete the job
                    QScopedPointer<KIO::StatJob> sp(job);
                    job->setAutoDelete(false);
                    if (KIO::NetAccess::synchronousRun(job, 0)) {
                        uds = job->statResult();
                    }
                }

                urlSet.insert(toDisplayString);
                uds.insert(KIO::UDSEntry::UDS_NAME, info.completeBaseName());

                if (urlInside.isLocalFile()) {
                    uds.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, urlInside.toLocalFile());
                    uds.insert(KIO::UDSEntry::UDS_LOCAL_PATH, urlInside.path());
                } else {
                    uds.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, toDisplayString);
                    uds.insert(KIO::UDSEntry::UDS_ICON_NAME, file.readIcon());
                }
                uds.insert(KIO::UDSEntry::UDS_TARGET_URL, toDisplayString);
                udslist << uds;
            }
        }
        listEntries(udslist);
        finished();
    }
    else
Exemplo n.º 5
0
void AccessManagerReply::slotStatResult(KJob* kJob)
{
    if (jobError(kJob)) {
        emit error (error());
        emitFinished(true);
        return;
    }

    KIO::StatJob* statJob = qobject_cast<KIO::StatJob*>(kJob);
    Q_ASSERT(statJob);

    KIO::UDSEntry entry =  statJob->statResult();
    QString mimeType = entry.stringValue(KIO::UDSEntry::UDS_MIME_TYPE);
    if (mimeType.isEmpty() && entry.isDir())
        mimeType = QL1S("inode/directory");

    if (!mimeType.isEmpty())
        setHeader(QNetworkRequest::ContentTypeHeader, mimeType.toUtf8());

    emitFinished(true);
}
Exemplo n.º 6
0
void OpenProjectDialog::validateOpenUrl( const QUrl& url_ )
{
    bool isDir = false;
    QString extension;
    bool isValid = false;

    const QUrl url = url_.adjusted(QUrl::StripTrailingSlash);

    if( url.isLocalFile() )
    {
        QFileInfo info( url.toLocalFile() );
        isValid = info.exists();
        if ( isValid ) {
            isDir = info.isDir();
            extension = info.suffix();
        }
    } else if ( url.isValid() )
    {
        KIO::StatJob* statJob = KIO::stat( url, KIO::HideProgressInfo );
        KJobWidgets::setWindow(statJob, Core::self()->uiControllerInternal()->defaultMainWindow() );
        isValid = statJob->exec(); // TODO: do this asynchronously so that the user isn't blocked while typing every letter of the hostname in sftp://hostname
        if ( isValid ) {
            KIO::UDSEntry entry = statJob->statResult();
            isDir = entry.isDir();
            extension = QFileInfo( entry.stringValue( KIO::UDSEntry::UDS_NAME ) ).suffix();
        }
    }

    if ( isValid ) {
        // reset header
        openPage->setHeader(i18n("Open \"%1\" as project", url.fileName()));
    } else {
        // report error
        KColorScheme scheme(palette().currentColorGroup());
        const QString errorMsg = i18n("Selected URL is invalid");
        openPage->setHeader(QStringLiteral("<font color='%1'>%2</font>")
            .arg(scheme.foreground(KColorScheme::NegativeText).color().name(), errorMsg)
        );
        setAppropriate( projectInfoPage, false );
        setAppropriate( openPage, true );
        setValid( openPage, false );
        return;
    }

    if( isDir || extension != ShellExtension::getInstance()->projectFileExtension() )
    {
        setAppropriate( projectInfoPage, true );
        m_url = url;
        if( !isDir ) {
            m_url = m_url.adjusted(QUrl::StripTrailingSlash | QUrl::RemoveFilename);
        }
        ProjectInfoPage* page = qobject_cast<ProjectInfoPage*>( projectInfoPage->widget() );
        if( page )
        {
            page->setProjectName( m_url.fileName() );
            OpenProjectPage* page2 = qobject_cast<OpenProjectPage*>( openPage->widget() );
            if( page2 )
            {
                // Default manager
                page->setProjectManager( QStringLiteral("Generic Project Manager") );
                // clear the filelist
                m_fileList.clear();

                if( isDir ) {
                    // If a dir was selected fetch all files in it
                    KIO::ListJob* job = KIO::listDir( m_url );
                    connect( job, &KIO::ListJob::entries,
                                  this, &OpenProjectDialog::storeFileList);
                    KJobWidgets::setWindow(job, Core::self()->uiController()->activeMainWindow());
                    job->exec();
                } else {
                    // Else we'lll just take the given file
                    m_fileList << url.fileName();
                }
                // Now find a manager for the file(s) in our filelist.
                bool managerFound = false;
                foreach( const QString& manager, page2->projectFilters().keys() )
                {
                    foreach( const QString& filterexp, page2->projectFilters().value(manager) )
                    {
                        if( !m_fileList.filter( QRegExp( filterexp, Qt::CaseSensitive, QRegExp::Wildcard ) ).isEmpty() )
                        {
                            managerFound = true;
                            break;
                        }
                    }
                    if( managerFound )
                    {
                        page->setProjectManager( manager );
                        break;
                    }
                }
            }
        }
        m_url.setPath( m_url.path() + '/' + m_url.fileName() + '.' + ShellExtension::getInstance()->projectFileExtension() );
    } else