예제 #1
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);
}
예제 #2
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