Exemple #1
0
void TrashProtocol::listDir(const KUrl& url)
{
    INIT_IMPL;
    kDebug() << "listdir: " << url;
    if ( url.path(KUrl::AddTrailingSlash) == QLatin1String("/") ) {
        listRoot();
        return;
    }
    int trashId;
    QString fileId;
    QString relativePath;
    bool ok = TrashImpl::parseURL( url, trashId, fileId, relativePath );
    if ( !ok ) {
        error( KIO::ERR_SLAVE_DEFINED, i18n( "Malformed URL %1", url.prettyUrl() ) );
        return;
    }
    //was: const QString physicalPath = impl.physicalPath( trashId, fileId, relativePath );

    // Get info for deleted directory - the date of deletion and orig path will be used
    // for all the items in it, and we need the physicalPath.
    TrashedFileInfo info;
    ok = impl.infoForFile( trashId, fileId, info );
    if ( !ok || info.physicalPath.isEmpty() ) {
        error( impl.lastErrorCode(), impl.lastErrorMessage() );
        return;
    }
    if ( !relativePath.isEmpty() ) {
        info.physicalPath += QLatin1Char('/');
        info.physicalPath += relativePath;
    }

    // List subdir. Can't use kio_file here since we provide our own info...
    kDebug() << "listing " << info.physicalPath;
    const QStringList entryNames = impl.listDir( info.physicalPath );
    totalSize( entryNames.count() );
    KIO::UDSEntry entry;
    for ( QStringList::const_iterator entryIt = entryNames.begin(), entryEnd = entryNames.end();
          entryIt != entryEnd ; ++entryIt )
    {
        const QString fileName = *entryIt;
        if (fileName == QLatin1String(".."))
            continue;
        const QString filePath = info.physicalPath + QLatin1Char('/') + fileName;
        // shouldn't be necessary
        //const QString url = TrashImpl::makeURL( trashId, fileId, relativePath + '/' + fileName );
        entry.clear();
        TrashedFileInfo infoForItem( info );
        infoForItem.origPath += QLatin1Char('/');
        infoForItem.origPath += fileName;

        if (createUDSEntry(filePath, fileName, fileName, entry, infoForItem)) {
            listEntry( entry, false );
        }
    }
    entry.clear();
    listEntry( entry, true );
    finished();
}
Exemple #2
0
void TrashProtocol::listDir(const KURL &url)
{
    INIT_IMPL;
    kdDebug() << "listdir: " << url << endl;
    if(url.path().length() <= 1)
    {
        listRoot();
        return;
    }
    int trashId;
    QString fileId;
    QString relativePath;
    bool ok = TrashImpl::parseURL(url, trashId, fileId, relativePath);
    if(!ok)
    {
        error(KIO::ERR_SLAVE_DEFINED, i18n("Malformed URL %1").arg(url.prettyURL()));
        return;
    }
    // was: const QString physicalPath = impl.physicalPath( trashId, fileId, relativePath );

    // Get info for deleted directory - the date of deletion and orig path will be used
    // for all the items in it, and we need the physicalPath.
    TrashedFileInfo info;
    ok = impl.infoForFile(trashId, fileId, info);
    if(!ok || info.physicalPath.isEmpty())
    {
        error(impl.lastErrorCode(), impl.lastErrorMessage());
        return;
    }
    if(!relativePath.isEmpty())
    {
        info.physicalPath += "/";
        info.physicalPath += relativePath;
    }

    // List subdir. Can't use kio_file here since we provide our own info...
    kdDebug() << k_funcinfo << "listing " << info.physicalPath << endl;
    QStrList entryNames = impl.listDir(info.physicalPath);
    totalSize(entryNames.count());
    KIO::UDSEntry entry;
    QStrListIterator entryIt(entryNames);
    for(; entryIt.current(); ++entryIt)
    {
        QString fileName = QFile::decodeName(entryIt.current());
        if(fileName == "..")
            continue;
        const QString filePath = info.physicalPath + "/" + fileName;
        // shouldn't be necessary
        // const QString url = TrashImpl::makeURL( trashId, fileId, relativePath + "/" + fileName );
        entry.clear();
        TrashedFileInfo infoForItem(info);
        infoForItem.origPath += '/';
        infoForItem.origPath += fileName;
        if(ok && createUDSEntry(filePath, fileName, QString::null /*url*/, entry, infoForItem))
        {
            listEntry(entry, false);
        }
    }
    entry.clear();
    listEntry(entry, true);
    finished();
}