示例#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();
}
示例#2
0
void RemoteProtocol::listRoot()
{
	KIO::UDSEntry entry;

	KIO::UDSEntryList remote_entries;
        m_impl.listRoot(remote_entries);

	totalSize(remote_entries.count()+2);

	m_impl.createTopLevelEntry(entry);
	listEntry(entry, false);

	m_impl.createWizardEntry(entry);
	listEntry(entry, false);

	KIO::UDSEntryList::ConstIterator it = remote_entries.constBegin();
	const KIO::UDSEntryList::ConstIterator end = remote_entries.constEnd();
	for(; it!=end; ++it)
	{
		listEntry(*it, false);
	}

	entry.clear();
	listEntry(entry, true);

	finished();
}
示例#3
0
void MediaProtocol::listRoot()
{
    KIO::UDSEntry entry;

    KIO::UDSEntryList media_entries;
    bool ok = m_impl.listMedia(media_entries);

    if (!ok)
    {
        error( m_impl.lastErrorCode(), m_impl.lastErrorMessage() );
        return;
    }

    totalSize(media_entries.count()+1);

    m_impl.createTopLevelEntry(entry);
    listEntry(entry, false);

    KIO::UDSEntryListIterator it = media_entries.begin();
    KIO::UDSEntryListIterator end = media_entries.end();

    for(; it!=end; ++it)
    {
        listEntry(*it, false);
    }

    entry.clear();
    listEntry(entry, true);

    finished();
}
示例#4
0
bool MediaImpl::listMedia(QValueList< KIO::UDSEntry > &list)
{
    kdDebug(1219) << "MediaImpl::listMedia" << endl;

    DCOPRef mediamanager("kded", "mediamanager");
    DCOPReply reply = mediamanager.call("fullList");

    if(!reply.isValid())
    {
        m_lastErrorCode = KIO::ERR_SLAVE_DEFINED;
        m_lastErrorMessage = i18n("The KDE mediamanager is not running.");
        return false;
    }

    Medium::List media = Medium::createList(reply);

    KIO::UDSEntry entry;

    Medium::List::iterator it = media.begin();
    Medium::List::iterator end = media.end();

    for(; it != end; ++it)
    {
        entry.clear();

        createMediumEntry(entry, *it);

        list.append(entry);
    }

    return true;
}
示例#5
0
bool MediaImpl::statMedium(const QString &name, KIO::UDSEntry &entry)
{
    kdDebug(1219) << "MediaImpl::statMedium: " << name << endl;

    DCOPRef mediamanager("kded", "mediamanager");
    DCOPReply reply = mediamanager.call("properties", name);

    if(!reply.isValid())
    {
        m_lastErrorCode = KIO::ERR_SLAVE_DEFINED;
        m_lastErrorMessage = i18n("The KDE mediamanager is not running.");
        return false;
    }

    Medium m = Medium::create(reply);

    if(m.id().isEmpty())
    {
        entry.clear();
        return false;
    }

    createMediumEntry(entry, m);

    return true;
}
示例#6
0
void HomeImpl::createHomeEntry(KIO::UDSEntry &entry,
                               const KUser &user)
{
	kdDebug() << "HomeImpl::createHomeEntry" << endl;
	
	entry.clear();
	
	QString full_name = user.loginName();
	
	if (!user.fullName().isEmpty())
	{
		full_name = user.fullName()+" ("+user.loginName()+")";
	}
	
	full_name = KIO::encodeFileName( full_name );
	
	addAtom(entry, KIO::UDS_NAME, 0, full_name);
	addAtom(entry, KIO::UDS_URL, 0, "home:/"+user.loginName());
	
	addAtom(entry, KIO::UDS_FILE_TYPE, S_IFDIR);
	addAtom(entry, KIO::UDS_MIME_TYPE, 0, "inode/directory");

	QString icon_name = "folder_home2";

	if (user.uid()==m_effectiveUid)
	{
		icon_name = "folder_home";
	}
	
	addAtom(entry, KIO::UDS_ICON_NAME, 0, icon_name);

	KURL url;
	url.setPath(user.homeDir());
	entry += extractUrlInfos(url);
}
示例#7
0
void MediaImpl::createTopLevelEntry(KIO::UDSEntry &entry) const
{
    entry.clear();
    addAtom(entry, KIO::UDS_URL, 0, "media:/");
    addAtom(entry, KIO::UDS_NAME, 0, ".");
    addAtom(entry, KIO::UDS_FILE_TYPE, S_IFDIR);
    addAtom(entry, KIO::UDS_ACCESS, 0555);
    addAtom(entry, KIO::UDS_MIME_TYPE, 0, "inode/directory");
    addAtom(entry, KIO::UDS_ICON_NAME, 0, "blockdevice");
}
示例#8
0
void TrashProtocol::createTopLevelDirEntry(KIO::UDSEntry &entry)
{
    entry.clear();
    addAtom(entry, KIO::UDS_NAME, 0, ".");
    addAtom(entry, KIO::UDS_FILE_TYPE, S_IFDIR);
    addAtom(entry, KIO::UDS_ACCESS, 0700);
    addAtom(entry, KIO::UDS_MIME_TYPE, 0, "inode/directory");
    addAtom(entry, KIO::UDS_USER, 0, m_userName);
    addAtom(entry, KIO::UDS_GROUP, 0, m_groupName);
}
示例#9
0
void TrashProtocol::createTopLevelDirEntry(KIO::UDSEntry& entry)
{
    entry.clear();
    entry.insert( KIO::UDSEntry::UDS_NAME, QString::fromLatin1("."));
    entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
    entry.insert( KIO::UDSEntry::UDS_ACCESS, 0700);
    entry.insert( KIO::UDSEntry::UDS_MIME_TYPE, QString::fromLatin1("inode/directory"));
    entry.insert( KIO::UDSEntry::UDS_USER, m_userName);
    entry.insert( KIO::UDSEntry::UDS_GROUP, m_groupName);
}
示例#10
0
void ArchiveProtocol::createRootUDSEntry( KIO::UDSEntry & entry )
{
    entry.clear();
    entry.insert( KIO::UDSEntry::UDS_NAME, "." );
    entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR );
    entry.insert( KIO::UDSEntry::UDS_MODIFICATION_TIME, m_mtime );
    //entry.insert( KIO::UDSEntry::UDS_ACCESS, 07777 ); // fake 'x' permissions, this is a pseudo-directory
    entry.insert( KIO::UDSEntry::UDS_USER, m_user);
    entry.insert( KIO::UDSEntry::UDS_GROUP, m_group);
}
示例#11
0
void HomeImpl::createTopLevelEntry(KIO::UDSEntry &entry) const
{
	entry.clear();
	addAtom(entry, KIO::UDS_NAME, 0, ".");
	addAtom(entry, KIO::UDS_FILE_TYPE, S_IFDIR);
	addAtom(entry, KIO::UDS_ACCESS, 0555);
	addAtom(entry, KIO::UDS_MIME_TYPE, 0, "inode/directory");
	addAtom(entry, KIO::UDS_ICON_NAME, 0, "kfm_home");
	addAtom(entry, KIO::UDS_USER, 0, "root");
	addAtom(entry, KIO::UDS_GROUP, 0, "root");
}
示例#12
0
static void createDirEntry(KIO::UDSEntry& entry, const QString& name, const QString& url, const QString& mime,const QString& iconName)
{
    entry.clear();
    entry.insert( KIO::UDSEntry::UDS_NAME, name );
    entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR );
    entry.insert( KIO::UDSEntry::UDS_ACCESS, 0500 );
    entry.insert( KIO::UDSEntry::UDS_MIME_TYPE, mime );
    if (!url.isEmpty())
        entry.insert( KIO::UDSEntry::UDS_URL, url );
    entry.insert( KIO::UDSEntry::UDS_ICON_NAME, iconName );
}
示例#13
0
文件: kamera.cpp 项目: KDE/kamera
// translate a simple text to a UDS entry
void KameraProtocol::translateTextToUDS(KIO::UDSEntry &udsEntry,
    const QString &fn,
    const char *text)
{
    udsEntry.clear();
    udsEntry.insert(KIO::UDSEntry::UDS_FILE_TYPE,S_IFREG);
    udsEntry.insert(KIO::UDSEntry::UDS_NAME,path_quote(fn));
    udsEntry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME,fn);
    udsEntry.insert(KIO::UDSEntry::UDS_SIZE,strlen(text));
    udsEntry.insert(KIO::UDSEntry::UDS_ACCESS,(S_IRUSR | S_IRGRP | S_IROTH));
}
示例#14
0
void KMobileDevice::createDirEntry(KIO::UDSEntry& entry, const QString& name, const QString& url, const QString& mime) const
{
	entry.clear();
	addAtom(entry, KIO::UDS_NAME, 0, name);
	addAtom(entry, KIO::UDS_FILE_TYPE, S_IFDIR);
	addAtom(entry, KIO::UDS_ACCESS, 0500);
	addAtom(entry, KIO::UDS_MIME_TYPE, 0, mime);
	addAtom(entry, KIO::UDS_URL, 0, url);
	PRINT_DEBUG << QString("createDirEntry: File: %1  MIME: %2  URL: %3\n").arg(name).arg(mime).arg(url);
//	addAtom(entry, KIO::UDS_SIZE, 0);
	addAtom(entry, KIO::UDS_GUESSED_MIME_TYPE, 0, mime);
}
示例#15
0
void TrashProtocol::listRoot()
{
    INIT_IMPL;
    const TrashedFileInfoList lst = impl.list();
    totalSize(lst.count());
    KIO::UDSEntry entry;
    createTopLevelDirEntry(entry);
    listEntry(entry, false);
    for(TrashedFileInfoList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
    {
        const KURL url = TrashImpl::makeURL((*it).trashId, (*it).fileId, QString::null);
        KURL origURL;
        origURL.setPath((*it).origPath);
        entry.clear();
        if(createUDSEntry((*it).physicalPath, origURL.fileName(), url.url(), entry, *it))
            listEntry(entry, false);
    }
    entry.clear();
    listEntry(entry, true);
    finished();
}
示例#16
0
void KMobileDevice::createFileEntry(KIO::UDSEntry& entry, const QString& name, const QString& url, const QString& mime,
		const unsigned long size) const
{
	entry.clear();
	addAtom(entry, KIO::UDS_NAME, 0, name);
	addAtom(entry, KIO::UDS_FILE_TYPE, S_IFREG);
	addAtom(entry, KIO::UDS_URL, 0, url);
	addAtom(entry, KIO::UDS_ACCESS, 0400);
	addAtom(entry, KIO::UDS_MIME_TYPE, 0, mime);
	if (size) addAtom(entry, KIO::UDS_SIZE, size);
	addAtom(entry, KIO::UDS_GUESSED_MIME_TYPE, 0, mime);
	PRINT_DEBUG << QString("createFileEntry: File: %1, Size: %2,  MIME: %3\n").arg(name).arg(size).arg(mime);
}
示例#17
0
static void createFileEntry(KIO::UDSEntry& entry, const KService::Ptr& service, const KUrl& parentUrl)
{
    entry.clear();
    entry.insert(KIO::UDSEntry::UDS_NAME, KIO::encodeFileName(service->name()));
    entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG);
    const QString fileUrl = parentUrl.url(KUrl::AddTrailingSlash) + service->desktopEntryName();
    entry.insert(KIO::UDSEntry::UDS_URL, fileUrl);
    entry.insert(KIO::UDSEntry::UDS_ACCESS, 0500);
    entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "application/x-desktop");
    entry.insert(KIO::UDSEntry::UDS_SIZE, 0);
    entry.insert(KIO::UDSEntry::UDS_LOCAL_PATH, KStandardDirs::locate("apps", service->entryPath()));
    entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, time(0));
    entry.insert(KIO::UDSEntry::UDS_ICON_NAME, service->icon());
}
示例#18
0
文件: kamera.cpp 项目: KDE/kamera
// translate a directory name to a UDSFieldType
// which we can return as a directory listing entry
void KameraProtocol::translateDirectoryToUDS(KIO::UDSEntry &udsEntry,
                                             const QString &dirname)
{

    udsEntry.clear();

    udsEntry.insert(KIO::UDSEntry::UDS_FILE_TYPE,S_IFDIR);
    udsEntry.insert(KIO::UDSEntry::UDS_NAME,path_quote(dirname));
    udsEntry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, dirname);
    udsEntry.insert(KIO::UDSEntry::UDS_ACCESS,
            S_IRUSR | S_IRGRP | S_IROTH |S_IWUSR | S_IWGRP |
            S_IWOTH | S_IXUSR | S_IXOTH | S_IXGRP);
    udsEntry.insert(KIO::UDSEntry::UDS_MIME_TYPE, QString("inode/directory"));
}
示例#19
0
文件: pak.cpp 项目: Uiomae/kio_pak
void PakProtocol::createUDSEntry(const KArchiveEntry *archiveEntry, KIO::UDSEntry &entry) {
	KIO::UDSAtom atom;
	entry.clear();

	atom.m_uds = KIO::UDS_NAME;
	atom.m_str = remoteEncoding()->decode(archiveEntry->name().local8Bit());
	entry.append(atom);

	atom.m_uds = KIO::UDS_SIZE;
	atom.m_long = archiveEntry->isFile() ? ((KArchiveFile *)archiveEntry)->size() : 0L ;
	entry.append(atom);

	atom.m_uds = KIO::UDS_FILE_TYPE;
	atom.m_long = archiveEntry->permissions() & S_IFMT; // keep file type only
	entry.append(atom);

	atom.m_uds = KIO::UDS_ACCESS;
	atom.m_long = archiveEntry->permissions() & 07777; // keep permissions only
	entry.append(atom);
}
示例#20
0
void MediaImpl::createMediumEntry(KIO::UDSEntry &entry, const Medium &medium)
{
    kdDebug(1219) << "MediaProtocol::createMedium" << endl;

    QString url = "media:/" + medium.name();

    kdDebug(1219) << "url = " << url << ", mime = " << medium.mimeType() << endl;

    entry.clear();

    addAtom(entry, KIO::UDS_URL, 0, url);

    QString label = KIO::encodeFileName(medium.prettyLabel());
    addAtom(entry, KIO::UDS_NAME, 0, label);

    addAtom(entry, KIO::UDS_FILE_TYPE, S_IFDIR);

    addAtom(entry, KIO::UDS_MIME_TYPE, 0, medium.mimeType());
    addAtom(entry, KIO::UDS_GUESSED_MIME_TYPE, 0, "inode/directory");

    if(!medium.iconName().isEmpty())
    {
        addAtom(entry, KIO::UDS_ICON_NAME, 0, medium.iconName());
    }
    else
    {
        QString mime = medium.mimeType();
        QString icon = KMimeType::mimeType(mime)->icon(mime, false);
        addAtom(entry, KIO::UDS_ICON_NAME, 0, icon);
    }

    if(medium.needMounting())
    {
        addAtom(entry, KIO::UDS_ACCESS, 0400);
    }
    else
    {
        KURL url = medium.prettyBaseURL();
        entry += extractUrlInfos(url);
    }
}
示例#21
0
文件: kamera.cpp 项目: KDE/kamera
// translate a CameraFileInfo to a UDSFieldType
// which we can return as a directory listing entry
void KameraProtocol::translateFileToUDS(KIO::UDSEntry &udsEntry,
                                        const CameraFileInfo &info,
                                        QString name)
{

    udsEntry.clear();

    udsEntry.insert(KIO::UDSEntry::UDS_FILE_TYPE,S_IFREG);
    udsEntry.insert(KIO::UDSEntry::UDS_NAME,path_quote(name));
    udsEntry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME,name);

    if (info.file.fields & GP_FILE_INFO_SIZE) {
        udsEntry.insert(KIO::UDSEntry::UDS_SIZE,info.file.size);
    }

    if (info.file.fields & GP_FILE_INFO_MTIME) {
        udsEntry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME,info.file.mtime);
    } else {
        udsEntry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME,time(NULL));
    }

    if (info.file.fields & GP_FILE_INFO_TYPE) {
        udsEntry.insert(KIO::UDSEntry::UDS_MIME_TYPE,
                        QString::fromLatin1(info.file.type));
    }

    if (info.file.fields & GP_FILE_INFO_PERMISSIONS) {
        udsEntry.insert(KIO::UDSEntry::UDS_ACCESS,
                        ((info.file.permissions & GP_FILE_PERM_READ) ?
                             (S_IRUSR | S_IRGRP | S_IROTH) : 0)
                        );
    } else {
        udsEntry.insert(KIO::UDSEntry::UDS_ACCESS,S_IRUSR | S_IRGRP | S_IROTH);
    }

    // TODO: We do not handle info.preview in any way
}
示例#22
0
bool MediaImpl::statMediumByLabel(const QString &label, KIO::UDSEntry &entry)
{
    kdDebug(1219) << "MediaImpl::statMediumByLabel: " << label << endl;

    DCOPRef mediamanager("kded", "mediamanager");
    DCOPReply reply = mediamanager.call("nameForLabel", label);

    if(!reply.isValid())
    {
        m_lastErrorCode = KIO::ERR_SLAVE_DEFINED;
        m_lastErrorMessage = i18n("The KDE mediamanager is not running.");
        return false;
    }

    QString name = reply;

    if(name.isEmpty())
    {
        entry.clear();
        return false;
    }

    return statMedium(name, entry);
}
示例#23
0
文件: kamera.cpp 项目: KDE/kamera
// The KIO slave "listDir" function.
void KameraProtocol::listDir(const QUrl &yurl)
{
    QString directory, file;
    qCDebug(KAMERA_KIOSLAVE) << "KameraProtocol::listDir(" << yurl.path() << ")";

    split_url2camerapath(yurl.path(), directory, file);

    if (!file.isEmpty()) {
        if (directory == "/") {
            directory = "/" + file;
        } else {
            directory = directory + "/" + file;
        }
    }

    if (yurl.path() == "/") {
        QUrl xurl;
        // List the available cameras
        QStringList groupList = m_config->groupList();
        qCDebug(KAMERA_KIOSLAVE) << "Found cameras: " << groupList.join(", ");
        QStringList::Iterator it;
        KIO::UDSEntry entry;


        /*
         * What we do:
         * - Autodetect cameras and remember them with their ports.
         * - List all saved and possible offline cameras.
         * - List all autodetected and not yet printed cameras.
         */
        QMap<QString,QString>	ports, names;
        QMap<QString,int>	modelcnt;

        /* Autodetect USB cameras ... */
        GPContext *glob_context = NULL;
        int i, count;
        CameraList *list;
        CameraAbilitiesList *al;
        GPPortInfoList *il;

        gp_list_new (&list);
        gp_abilities_list_new (&al);
        gp_abilities_list_load (al, glob_context);
        gp_port_info_list_new (&il);
        gp_port_info_list_load (il);
        gp_abilities_list_detect (al, il, list, glob_context);
        gp_abilities_list_free (al);
        gp_port_info_list_free (il);

        count = gp_list_count (list);

        for (i = 0 ; i<count ; i++) {
            const char *model, *value;

            gp_list_get_name  (list, i, &model);
            gp_list_get_value (list, i, &value);

            ports[value] = model;
            // NOTE: We might get different ports than usb: later!
            if (strcmp(value,"usb:") != 0) {
                names[model] = value;
            }

            /* Save them, even though we can autodetect them for
             * offline listing.
             */
#if 0
            KConfigGroup cg(m_config, model);
            cg.writeEntry("Model", model);
            cg.writeEntry("Path", value);
#endif
            modelcnt[model]++;
        }
        gp_list_free (list);

        /* Avoid duplicated entry, that is a camera with both
         * port usb: and usb:001,042 entries. */
        if (ports.contains("usb:") &&
                names.contains(ports["usb:"]) &&
                names[ports["usb:"]] != "usb:") {
            ports.remove("usb:");
        }

        for (it = groupList.begin(); it != groupList.end(); it++) {
            QString m_cfgPath;
            if (*it == "<default>") {
                continue;
            }

            KConfigGroup cg(m_config, *it);
            m_cfgPath = cg.readEntry("Path");

            // we autodetected those ...
            if (m_cfgPath.contains(QString("usb:"))) {
                cg.deleteGroup();
                continue;
            }

            QString xname;

            entry.clear();
            entry.insert(KIO::UDSEntry::UDS_FILE_TYPE,S_IFDIR);
            entry.insert(KIO::UDSEntry::UDS_ACCESS,
                    (S_IRUSR | S_IRGRP | S_IROTH |S_IWUSR | S_IWGRP | S_IWOTH));
            xname = (*it)+"@"+m_cfgPath;
            entry.insert(KIO::UDSEntry::UDS_NAME,path_quote(xname));
            // do not confuse regular users with the @usb...
            entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME,*it);
            listEntry(entry);
        }

        QMap<QString,QString>::iterator portsit;

        for (portsit = ports.begin(); portsit != ports.end(); portsit++) {
            entry.clear();
            entry.insert(KIO::UDSEntry::UDS_FILE_TYPE,S_IFDIR);
            // do not confuse regular users with the @usb...
            entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME,portsit.value());
            entry.insert(KIO::UDSEntry::UDS_NAME,
                    path_quote(portsit.value()+"@"+portsit.key()));

            entry.insert(KIO::UDSEntry::UDS_ACCESS,
                    (S_IRUSR | S_IRGRP | S_IROTH |S_IWUSR | S_IWGRP | S_IWOTH));
            listEntry(entry);
        }
        finished();
        return;
    }

    if (directory.isEmpty()) {
        QUrl rooturl(yurl);

        qCDebug(KAMERA_KIOSLAVE) << "redirecting to /";
        if (!current_camera.isEmpty() && !current_port.isEmpty()) {
            rooturl.setPath("/"+current_camera+"@"+current_port+"/");
        } else {
            rooturl.setPath("/");
        }
        redirection(rooturl);
        finished();
        return;
    }

    if (!openCamera()) {
        error(KIO::ERR_COULD_NOT_READ, yurl.path());
        return;
    }

    CameraList *dirList;
    CameraList *fileList;
    CameraList *specialList;
    gp_list_new(&dirList);
    gp_list_new(&fileList);
    gp_list_new(&specialList);
    int gpr;

    if (!directory.compare("/")) {
        CameraText text;
        if (GP_OK == gp_camera_get_manual(m_camera, &text, m_context)) {
            gp_list_append(specialList,"manual.txt",NULL);
        }
        if (GP_OK == gp_camera_get_about(m_camera, &text, m_context)) {
            gp_list_append(specialList,"about.txt",NULL);
        }
        if (GP_OK == gp_camera_get_summary(m_camera, &text, m_context)) {
            gp_list_append(specialList,"summary.txt",NULL);
        }
    }

    gpr = readCameraFolder(directory, dirList, fileList);
    if(gpr != GP_OK) {
        qCDebug(KAMERA_KIOSLAVE) << "read Camera Folder failed:"
                                 << gp_result_as_string(gpr);
        gp_list_free(dirList);
        gp_list_free(fileList);
        gp_list_free(specialList);
        error(KIO::ERR_SLAVE_DEFINED, i18n("Could not read. Reason: %1",
                    QString::fromLocal8Bit(gp_result_as_string(gpr))));
        return;
    }

    totalSize(gp_list_count(specialList) +
              gp_list_count(dirList) +
              gp_list_count(fileList));

    KIO::UDSEntry entry;
    const char *name;

    for(int i = 0; i < gp_list_count(dirList); ++i) {
        gp_list_get_name(dirList, i, &name);
        translateDirectoryToUDS(entry, QString::fromLocal8Bit(name));
        listEntry(entry);
    }

    CameraFileInfo info;

    for(int i = 0; i < gp_list_count(fileList); ++i) {
        gp_list_get_name(fileList, i, &name);
        // we want to know more info about files (size, type...)
        gp_camera_file_get_info(m_camera,
                                tocstr(directory),
                                name,
                                &info,
                                m_context);
        translateFileToUDS(entry, info, QString::fromLocal8Bit(name));
        listEntry(entry);
    }
    if (!directory.compare("/")) {
        CameraText text;
        if (GP_OK == gp_camera_get_manual(m_camera, &text, m_context)) {
            translateTextToUDS(entry, "manual.txt", text.text);
            listEntry(entry);
        }
        if (GP_OK == gp_camera_get_about(m_camera, &text, m_context)) {
            translateTextToUDS(entry, "about.txt", text.text);
            listEntry(entry);
        }
        if (GP_OK == gp_camera_get_summary(m_camera, &text, m_context)) {
            translateTextToUDS(entry, "summary.txt", text.text);
            listEntry(entry);
        }
    }


    gp_list_free(fileList);
    gp_list_free(dirList);
    gp_list_free(specialList);

    finished();
}
示例#24
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();
}