Esempio n. 1
0
QString KFileItemPrivate::group() const
{
    QString groupName = m_entry.stringValue( KIO::UDSEntry::UDS_GROUP );
    if (groupName.isEmpty() && m_bIsLocalUrl )
    {
#ifdef Q_WS_WIN
        QFileInfo a(m_url.toLocalFile( KUrl::RemoveTrailingSlash ));
        groupName = a.group();
        m_entry.insert( KIO::UDSEntry::UDS_GROUP, groupName );
#else
        KDE_struct_stat buff;
        if ( KDE::lstat( m_url.toLocalFile( KUrl::RemoveTrailingSlash ), &buff ) == 0) // get uid/gid of the link, if it's a link
        {
            struct group *ge = getgrgid( buff.st_gid );
            if ( ge != 0 ) {
                groupName = QString::fromLocal8Bit(ge->gr_name);
                if (groupName.isEmpty())
                    groupName.sprintf("%d",ge->gr_gid);
            }
            else
                groupName.sprintf("%d",buff.st_gid);
            m_entry.insert( KIO::UDSEntry::UDS_GROUP, groupName );
        }
#endif
    }
    return groupName;
}
Esempio n. 2
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);
}
Esempio n. 3
0
// 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));
}
Esempio n. 4
0
// 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"));
}
Esempio n. 5
0
// Implements stat("/") -- which always returns the same value.
void KameraProtocol::statRoot(void)
{
    KIO::UDSEntry entry;

    entry.insert( KIO::UDSEntry::UDS_NAME, QString::fromLocal8Bit("/"));

    entry.insert(KIO::UDSEntry::UDS_FILE_TYPE,S_IFDIR);

    entry.insert(KIO::UDSEntry::UDS_ACCESS,(S_IRUSR | S_IRGRP | S_IROTH));
    statEntry(entry);
    finished();
    // If we just do this call, timeout right away if no other requests are
    // pending. This is for the kdemm autodetection using media://camera
    idletime = MAXIDLETIME;
}
Esempio n. 6
0
void KioKdeconnect::listAllDevices()
{
    infoMessage(i18n("Listing devices..."));

    //TODO: Change to all devices and show different icons for connected and disconnected?
    QStringList devices = m_dbusInterface->devices(true, true);

    Q_FOREACH(const QString& deviceId, devices) {

        DeviceDbusInterface interface(deviceId);

        if (!interface.hasPlugin(QStringLiteral("kdeconnect_sftp"))) continue;

        const QString path = QStringLiteral("kdeconnect://").append(deviceId).append("/");
        const QString name = interface.name();
        const QString icon = QStringLiteral("kdeconnect");

        KIO::UDSEntry entry;
        entry.insert(KIO::UDSEntry::UDS_NAME, name);
        entry.insert(KIO::UDSEntry::UDS_ICON_NAME, icon);
        entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
        entry.insert(KIO::UDSEntry::UDS_ACCESS, S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
        entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, QLatin1String(""));
        entry.insert(KIO::UDSEntry::UDS_URL, path);
        listEntry(entry);
    }
Esempio n. 7
0
void Nepomuk2::TimelineProtocol::stat( const KUrl& url )
{
    switch( parseTimelineUrl( url, &m_date, &m_filename ) ) {
    case RootFolder: {
        KIO::UDSEntry uds;
        uds.insert( KIO::UDSEntry::UDS_NAME, QString::fromLatin1( "/" ) );
        uds.insert( KIO::UDSEntry::UDS_ICON_NAME, QString::fromLatin1( "nepomuk" ) );
        uds.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR );
        uds.insert( KIO::UDSEntry::UDS_MIME_TYPE, QString::fromLatin1( "inode/directory" ) );
        statEntry( uds );
        finished();
        break;
    }

    case CalendarFolder:
        statEntry( createFolderUDSEntry( QLatin1String("calendar"), i18n("Calendar"), QDate::currentDate() ) );
        finished();
        break;

    case MonthFolder:
        statEntry( createMonthUDSEntry( m_date.month(), m_date.year() ) );
        finished();
        break;

    case DayFolder:
        if ( m_filename.isEmpty() ) {
            statEntry( createDayUDSEntry( m_date ) );
            finished();
        }
        else {
            ForwardingSlaveBase::stat( url );
        }
        break;

    default:
        error( KIO::ERR_DOES_NOT_EXIST, url.prettyUrl() );
        break;
    }
}
Esempio n. 8
0
QString KFileItemPrivate::user() const
{
    QString userName = m_entry.stringValue(KIO::UDSEntry::UDS_USER);
    if (userName.isEmpty() && m_bIsLocalUrl) {
#ifdef Q_WS_WIN
        QFileInfo a(m_url.toLocalFile( KUrl::RemoveTrailingSlash ));
        userName = a.owner();
        m_entry.insert( KIO::UDSEntry::UDS_USER, userName );
#else
        KDE_struct_stat buff;
        if ( KDE::lstat( m_url.toLocalFile( KUrl::RemoveTrailingSlash ), &buff ) == 0) // get uid/gid of the link, if it's a link
        {
            struct passwd *pwuser = getpwuid( buff.st_uid );
            if ( pwuser != 0 ) {
                userName = QString::fromLocal8Bit(pwuser->pw_name);
                m_entry.insert( KIO::UDSEntry::UDS_USER, userName );
            }
        }
#endif
    }
    return userName;
}
Esempio n. 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);
}
Esempio n. 10
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());
}
Esempio n. 11
0
void Nepomuk2::TvshowProtocol::stat( const KUrl& url )
{
    // for basic functionality we only need to stat the folders
    const QStringList pathTokens = url.path().split('/', QString::SkipEmptyParts);
    if(pathTokens.count() == 1 && pathTokens.first() == QLatin1String("latest")) {
        KIO::UDSEntry uds = createFolderUDSEntry(QLatin1String("latest"), i18n("Next Episodes To Watch"));
        uds.insert(KIO::UDSEntry::UDS_ICON_NAME, QLatin1String("favorites"));
        statEntry(uds);
        finished();
    }

    else if(pathTokens.count() == 1) {
        // stat series folder
        Soprano::QueryResultIterator it
                = Nepomuk2::ResourceManager::instance()->mainModel()->executeQuery(QString::fromLatin1("select distinct * where { "
                                                                                                      "?r a nmm:TVSeries ; "
                                                                                                      "nie:title %1 ; "
                                                                                                      "nao:created ?cd ; "
                                                                                                      "nao:lastModified ?md ; "
                                                                                                      "nie:description ?d . } LIMIT 1")
                                                                                  .arg(Soprano::Node::literalToN3(pathTokens[0])),
                                                                                  Soprano::Query::QueryLanguageSparql);
        if(it.next()) {
            statEntry(createSeriesUDSEntry(it["r"].uri(),
                                           pathTokens[0],
                                           pathTokens[0],
                                           it["d"].toString(),
                                           it["cd"].literal().toDateTime(),
                                           it["md"].literal().toDateTime()));
            finished();
        }
        else {
            error( ERR_DOES_NOT_EXIST, url.prettyUrl() );
        }
    }

    else if(pathTokens.count() == 2) {
        // stat season folder
        statEntry(createFolderUDSEntry(pathTokens[0], pathTokens[1]));
        finished();
    }

    else {
        // FIXME
        error( ERR_UNSUPPORTED_ACTION, url.prettyUrl() );
    }
}
Esempio n. 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 );
}
Esempio n. 13
0
void KFileItemPrivate::init()
{
    m_access.clear();
    //  metaInfo = KFileMetaInfo();

    // stat() local files if needed
    // TODO: delay this until requested
    if (m_fileMode == KFileItem::Unknown || m_permissions == KFileItem::Unknown || m_entry.count() == 0) {
        if (m_url.isLocalFile()) {
            /* directories may not have a slash at the end if
             * we want to stat() them; it requires that we
             * change into it .. which may not be allowed
             * stat("/is/unaccessible")  -> rwx------
             * stat("/is/unaccessible/") -> EPERM            H.Z.
             * This is the reason for the StripTrailingSlash
             */
            QT_STATBUF buf;
            const QString path = m_url.adjusted(QUrl::StripTrailingSlash).toLocalFile();
            const QByteArray pathBA = QFile::encodeName(path);
            if (QT_LSTAT(pathBA.constData(), &buf) == 0) {
                m_entry.insert(KIO::UDSEntry::UDS_DEVICE_ID,           buf.st_dev);
                m_entry.insert(KIO::UDSEntry::UDS_INODE,               buf.st_ino);

                mode_t mode = buf.st_mode;
                if ((buf.st_mode & QT_STAT_MASK) == QT_STAT_LNK) {
                    m_bLink = true;
                    if (QT_STAT(pathBA, &buf) == 0) {
                        mode = buf.st_mode;
                    } else {// link pointing to nowhere (see FileProtocol::createUDSEntry() in ioslaves/file/file.cpp)
                        mode = (QT_STAT_MASK - 1) | S_IRWXU | S_IRWXG | S_IRWXO;
                    }
                }
                m_entry.insert(KIO::UDSEntry::UDS_SIZE,      buf.st_size);
                m_entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, buf.st_mode & QT_STAT_MASK); // extract file type
                m_entry.insert(KIO::UDSEntry::UDS_ACCESS,    buf.st_mode & 07777); // extract permissions
                m_entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME,   buf.st_mtime); // TODO: we could use msecs too...
                m_entry.insert(KIO::UDSEntry::UDS_ACCESS_TIME,         buf.st_atime);
#ifndef Q_OS_WIN
                m_entry.insert(KIO::UDSEntry::UDS_USER,                KUser(buf.st_uid).loginName());
                m_entry.insert(KIO::UDSEntry::UDS_GROUP,               KUserGroup(buf.st_gid).name());
#endif

                // TODO: these can be removed, we can use UDS_FILE_TYPE and UDS_ACCESS everywhere
                if (m_fileMode == KFileItem::Unknown) {
                    m_fileMode = mode & QT_STAT_MASK; // extract file type
                }
                if (m_permissions == KFileItem::Unknown) {
                    m_permissions = mode & 07777; // extract permissions
                }
            }
        }
    }
}
Esempio n. 14
0
// 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
}
Esempio n. 15
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
Esempio n. 16
0
void KFileItemPrivate::setTime(KFileItem::FileTimes mappedWhich, uint time_t_val) const
{
    m_entry.insert(udsFieldForTime(mappedWhich), time_t_val);
}
Esempio n. 17
0
// Implements a regular stat() of a file / directory, returning all we know about it
void KameraProtocol::statRegular(const QUrl &xurl)
{
    KIO::UDSEntry entry;
    QString	directory, file;
    int gpr;

    qCDebug(KAMERA_KIOSLAVE) << "statRegular(\"" << xurl.path() << "\")";

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

    if (openCamera() == false) {
        error(KIO::ERR_DOES_NOT_EXIST, xurl.path());
        return;
    }

    if (directory == "/") {
        KIO::UDSEntry entry;

        QString xname = current_camera + "@" + current_port;
        entry.insert( KIO::UDSEntry::UDS_NAME, path_quote(xname));
        entry.insert( KIO::UDSEntry::UDS_DISPLAY_NAME, current_camera);
        entry.insert( KIO::UDSEntry::UDS_FILE_TYPE,S_IFDIR);
        entry.insert( KIO::UDSEntry::UDS_ACCESS,(S_IRUSR | S_IRGRP | S_IROTH));
        statEntry(entry);
        finished();
        return;
    }

    // Is "url" a directory?
    CameraList *dirList;
    gp_list_new(&dirList);
    qCDebug(KAMERA_KIOSLAVE) << "statRegular() Requesting directories list for "
                             << directory;

    gpr = gp_camera_folder_list_folders(m_camera,
                                        tocstr(fix_foldername(directory)),
                                        dirList,
                                        m_context);
    if (gpr != GP_OK) {
        if ((gpr == GP_ERROR_FILE_NOT_FOUND) ||
                (gpr == GP_ERROR_DIRECTORY_NOT_FOUND)) {
            error(KIO::ERR_DOES_NOT_EXIST, xurl.path());
        } else {
            error(KIO::ERR_UNKNOWN,
                  QString::fromLocal8Bit(gp_result_as_string(gpr)));
        }
        gp_list_free(dirList);
        return;
    }

#define GPHOTO_TEXT_FILE(xx) \
    if (!directory.compare("/") && !file.compare(#xx".txt")) { \
        CameraText xx; \
        gpr = gp_camera_get_about(m_camera,  &xx, m_context); \
        if (gpr != GP_OK) { \
            error(KIO::ERR_DOES_NOT_EXIST, xurl.fileName()); \
            return; \
        } \
        translateTextToUDS(entry,#xx".txt",xx.text); \
        statEntry(entry); \
        finished(); \
        return; \
    }
    GPHOTO_TEXT_FILE(about);
    GPHOTO_TEXT_FILE(manual);
    GPHOTO_TEXT_FILE(summary);
#undef GPHOTO_TEXT_FILE

    const char *name;
    for(int i = 0; i < gp_list_count(dirList); i++) {
        gp_list_get_name(dirList, i, &name);
        if (file.compare(name) == 0) {
            gp_list_free(dirList);
            KIO::UDSEntry entry;
            translateDirectoryToUDS(entry, file);
            statEntry(entry);
            finished();
            return;
        }
    }
    gp_list_free(dirList);

    // Is "url" a file?
    CameraFileInfo info;
    gpr = gp_camera_file_get_info(m_camera,
                                  tocstr(fix_foldername(directory)),
                                  tocstr(file),
                                  &info,
                                  m_context
                                  );
    if (gpr != GP_OK) {
        if ((gpr == GP_ERROR_FILE_NOT_FOUND) ||
                (gpr == GP_ERROR_DIRECTORY_NOT_FOUND)) {
            error(KIO::ERR_DOES_NOT_EXIST, xurl.path());
        } else {
            error(KIO::ERR_UNKNOWN,
                  QString::fromLocal8Bit(gp_result_as_string(gpr)));
        }
        return;
    }
    translateFileToUDS(entry, info, file);
    statEntry(entry);
    finished();
}
Esempio n. 18
0
void Nepomuk2::TvshowProtocol::listDir( const KUrl& url )
{
    // root folder
    if(url.path().length() <= 1) {
        // list all tv shows including title, description, and an optional depiction (for now we simply take one of them)
        Soprano::QueryResultIterator it
                = Nepomuk2::ResourceManager::instance()->mainModel()->executeQuery(QString::fromLatin1("select distinct ?r ?t ?d where { "
                                                                                                      "?r a %1 . "
                                                                                                      "?r %2 ?t . "
                                                                                                      "?r %3 ?d . "
                                                                                                      "?r %4 ?cd . "
                                                                                                      "?r %5 ?md . }")
                                                                                  .arg(Soprano::Node::resourceToN3(NMM::TVSeries()),
                                                                                       Soprano::Node::resourceToN3(NIE::title()),
                                                                                       Soprano::Node::resourceToN3(NIE::description()),
                                                                                       Soprano::Node::resourceToN3(NAO::created()),
                                                                                       Soprano::Node::resourceToN3(NAO::lastModified())),
                                                                                  Soprano::Query::QueryLanguageSparql);
        while(it.next()) {
            UDSEntry uds = createSeriesUDSEntry(it["r"].uri(),
                                                it["t"].toString(),
                                                it["t"].toString(),
                                                it["d"].toString(),
                                                it["cd"].literal().toDateTime(),
                                                it["md"].literal().toDateTime());
            listEntry(uds, false);
        }

        KIO::UDSEntry uds = createFolderUDSEntry(QLatin1String("latest"), i18n("Next Episodes To Watch"));
        uds.insert(KIO::UDSEntry::UDS_ICON_NAME, QLatin1String("favorites"));
        listEntry(uds, false);

        listEntry(UDSEntry(), true);
        finished();
    }

    // all other URLS
    else {
        const QStringList pathTokens = url.path().split('/', QString::SkipEmptyParts);
        if(pathTokens.count() == 1 && pathTokens.first() == QLatin1String("latest")) {
            // list the next unwatched episodes of all series
            // query the min episode which does not have any watched episode after it
            // TODO: find a way to also query the episode at the same time
            Soprano::QueryResultIterator it
                    = Nepomuk2::ResourceManager::instance()->mainModel()->executeQuery(QLatin1String("select ?st ?series min(1000*?s+?e) as ?x where { "
                                                                                                    "?r a nmm:TVShow ; "
                                                                                                    "nmm:episodeNumber ?e ; "
                                                                                                    "nmm:season ?s ; "
                                                                                                    "nmm:series ?series . "
                                                                                                    "?series nie:title ?st "
                                                                                                    "FILTER NOT EXISTS { ?r nuao:usageCount ?u . filter(?u>0) . } "
                                                                                                    "FILTER NOT EXISTS { "
                                                                                                    "?r2 a nmm:TVShow ; "
                                                                                                    "nmm:series ?series ; "
                                                                                                    "nmm:episodeNumber ?e2 ; "
                                                                                                    "nmm:season ?s2 ; "
                                                                                                    "nuao:usageCount ?uc . "
                                                                                                    "filter(?uc>0) . "
                                                                                                    "filter((1000*?s2+?e2) > (1000*?s+?e)) . } "
                                                                                                    "}"),
                                                                                      Soprano::Query::QueryLanguageSparql);
            while(it.next()) {
                const QString seriesTitle = it["st"].toString();
                const int seasonNum = it["x"].literal().toInt() / 1000;
                const int episodeNum = it["x"].literal().toInt() % 1000;
                Soprano::QueryResultIterator it2
                        = Nepomuk2::ResourceManager::instance()->mainModel()->executeQuery(QString::fromLatin1("select ?r ?url ?t where { "
                                                                                                              "?r a nmm:TVShow ; "
                                                                                                              "nie:url ?url ; "
                                                                                                              "nie:title ?t ; "
                                                                                                              "nmm:series %1 ; "
                                                                                                              "nmm:episodeNumber %2 ; "
                                                                                                              "nmm:season %3 . "
                                                                                                              "OPTIONAL { ?r nmm:releaseDate ?rd ; "
                                                                                                              "nmm:synopsis ?d . } . }")
                                                                                          .arg(it["series"].toN3())
                                                                                          .arg(episodeNum)
                                                                                          .arg(seasonNum),
                                                                                          Soprano::Query::QueryLanguageSparql);
                if(it2.next()) {
                    const QString episodeTitle = it2["t"].toString();
                    const QString title = i18n("Next episode of %1: %2x%3 - %4",
                                               seriesTitle,
                                               QString::number(seasonNum).rightJustified(2, QLatin1Char('0')),
                                               QString::number(episodeNum).rightJustified(2, QLatin1Char('0')),
                                               episodeTitle);
                    UDSEntry uds;
                    uds.insert( KIO::UDSEntry::UDS_NAME, title );
                    uds.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG );
                    uds.insert( KIO::UDSEntry::UDS_DISPLAY_TYPE, i18n("TV Show") );
                    uds.insert( KIO::UDSEntry::UDS_ACCESS, 0700 );
                    uds.insert( KIO::UDSEntry::UDS_USER, KUser().loginName() );
                    uds.insert( KIO::UDSEntry::UDS_CREATION_TIME, it2["rd"].literal().toDateTime().toTime_t() );
                    uds.insert( KIO::UDSEntry::UDS_COMMENT, it2["d"].toString() );
                    uds.insert( KIO::UDSEntry::UDS_URL, KUrl(it2["url"].uri()).url() );
                    uds.insert( KIO::UDSEntry::UDS_NEPOMUK_URI, KUrl(it2["r"].uri()).url() );
                    listEntry(uds, false);
                }
            }
            listEntry(UDSEntry(), true);
            finished();
        }

        if(pathTokens.count() == 1) {
            // list one TV Series: list seasons
            Soprano::QueryResultIterator it
                    = Nepomuk2::ResourceManager::instance()->mainModel()->executeQuery(QString::fromLatin1("select distinct ?s where { "
                                                                                                          "?r nmm:series ?tv . "
                                                                                                          "?tv nie:title %1 . "
                                                                                                          "?r nmm:season ?s . "
                                                                                                          "OPTIONAL { ?sr a nmm:TVSeason ; nmm:seasonOf ?tv ; nmm:seasonNumber ?s . } . }")
                                                                                      .arg(Soprano::Node::literalToN3(pathTokens.first())),
                                                                                      Soprano::Query::QueryLanguageSparql);
            while(it.next()) {
                const QString name = pathTokens.first() + QLatin1String(" - ") + i18n("Season %1", it["s"].literal().toInt());
                UDSEntry uds = createFolderUDSEntry(name, name);
                if(it["sr"].isResource()) {
                    uds.insert( KIO::UDSEntry::UDS_NEPOMUK_URI, KUrl(it["sr"].uri()).url() );
                }
                listEntry(uds, false);
            }
            listEntry(UDSEntry(), true);
            finished();
        }

        else if(pathTokens.count() == 2) {
            const QString seriesTitle = pathTokens[0];
            const int season = pathTokens[1].mid(pathTokens[1].lastIndexOf(' ')+1).toInt();
            Soprano::QueryResultIterator it
                    = Nepomuk2::ResourceManager::instance()->mainModel()->executeQuery(QString::fromLatin1("select distinct * where { "
                                                                                                          "?r a nmm:TVShow ; "
                                                                                                          "nmm:season %1 ; "
                                                                                                          "nmm:series [ nie:title %2 ] ; "
                                                                                                          "nie:title ?t ; "
                                                                                                          "nmm:episodeNumber ?e ; "
                                                                                                          "nie:url ?url . "
                                                                                                          "OPTIONAL { ?r nmm:releaseDate ?rd ; "
                                                                                                          "nmm:synopsis ?d . } . }")
                                                                                      .arg(Soprano::Node::literalToN3(season),
                                                                                           Soprano::Node::literalToN3(seriesTitle)),
                                                                                      Soprano::Query::QueryLanguageSparql);
            while(it.next()) {
                const QString episodeName = seriesTitle + QString::fromLatin1(" - %1x%2 - ").arg(season, 2, 10, QLatin1Char('0')).arg(it["e"].literal().toInt(), 2, 10, QLatin1Char('0')) + it["t"].toString();
                UDSEntry uds;
                uds.insert( KIO::UDSEntry::UDS_NAME, episodeName );
                uds.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG );
                uds.insert( KIO::UDSEntry::UDS_DISPLAY_TYPE, i18n("TV Show") );
                uds.insert( KIO::UDSEntry::UDS_ACCESS, 0700 );
                uds.insert( KIO::UDSEntry::UDS_USER, KUser().loginName() );
                uds.insert( KIO::UDSEntry::UDS_CREATION_TIME, it["rd"].literal().toDateTime().toTime_t() );
                uds.insert( KIO::UDSEntry::UDS_COMMENT, it["d"].toString() );
                uds.insert( KIO::UDSEntry::UDS_URL, KUrl(it["url"].uri()).url() );
                uds.insert( KIO::UDSEntry::UDS_NEPOMUK_URI, KUrl(it["r"].uri()).url() );
                listEntry(uds, false);
            }
            listEntry(UDSEntry(), true);
            finished();
        }

        else {
            error( KIO::ERR_CANNOT_ENTER_DIRECTORY, url.prettyUrl() );
        }
    }
}
Esempio n. 19
0
const KIO::UDSEntry vfile::vfile_getEntry()
{
    KIO::UDSEntry entry;

    entry.insert(KIO::UDSEntry::UDS_NAME, vfile_getName());
    entry.insert(KIO::UDSEntry::UDS_SIZE, vfile_getSize());
    entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, vfile_getTime_t());
    entry.insert(KIO::UDSEntry::UDS_USER, vfile_getOwner());
    entry.insert(KIO::UDSEntry::UDS_GROUP, vfile_getGroup());
    entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, vfile_getMime());
    entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, vfile_getMode() & S_IFMT);
    entry.insert(KIO::UDSEntry::UDS_ACCESS, vfile_getMode() & 07777);

    if (vfile_isSymLink())
        entry.insert(KIO::UDSEntry::UDS_LINK_DEST, vfile_getSymDest());

    if (!vfile_acl_loaded)
        vfile_loadACL();
    if (vfile_has_acl) {
        entry.insert(KIO::UDSEntry::UDS_EXTENDED_ACL, 1);

        if (!vfile_acl.isNull())
            entry.insert(KIO::UDSEntry::UDS_ACL_STRING, vfile_acl);

        if (!vfile_def_acl.isNull())
            entry.insert(KIO::UDSEntry::UDS_DEFAULT_ACL_STRING, vfile_acl);
    }

    return entry;
}
Esempio n. 20
0
// 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();
}
Esempio n. 21
0
bool TrashProtocol::createUDSEntry( const QString& physicalPath, const QString& displayFileName, const QString& internalFileName, KIO::UDSEntry& entry, const TrashedFileInfo& info )
{
    QByteArray physicalPath_c = QFile::encodeName( physicalPath );
    KDE_struct_stat buff;
    if ( KDE_lstat( physicalPath_c, &buff ) == -1 ) {
        kWarning() << "couldn't stat " << physicalPath ;
        return false;
    }
    if (S_ISLNK(buff.st_mode)) {
        char buffer2[ 1000 ];
        int n = readlink( physicalPath_c, buffer2, 999 );
        if ( n != -1 ) {
            buffer2[ n ] = 0;
        }

        entry.insert( KIO::UDSEntry::UDS_LINK_DEST, QFile::decodeName( buffer2 ) );
        // Follow symlink
        // That makes sense in kio_file, but not in the trash, especially for the size
        // #136876
#if 0
        if ( KDE_stat( physicalPath_c, &buff ) == -1 ) {
            // It is a link pointing to nowhere
            buff.st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
            buff.st_mtime = 0;
            buff.st_atime = 0;
            buff.st_size = 0;
        }
#endif
    }
    mode_t type = buff.st_mode & S_IFMT; // extract file type
    mode_t access = buff.st_mode & 07777; // extract permissions
    access &= 07555; // make it readonly, since it's in the trashcan
    Q_ASSERT(!internalFileName.isEmpty());
    entry.insert( KIO::UDSEntry::UDS_NAME, internalFileName ); // internal filename, like "0-foo"
    entry.insert( KIO::UDSEntry::UDS_DISPLAY_NAME, displayFileName ); // user-visible filename, like "foo"
    entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, type );
    //if ( !url.isEmpty() )
    //    entry.insert( KIO::UDSEntry::UDS_URL, url );

    KMimeType::Ptr mt = KMimeType::findByPath( physicalPath, buff.st_mode );
    if ( mt )
        entry.insert( KIO::UDSEntry::UDS_MIME_TYPE, mt->name() );
    entry.insert( KIO::UDSEntry::UDS_ACCESS, access );
    entry.insert( KIO::UDSEntry::UDS_SIZE, buff.st_size );
    entry.insert( KIO::UDSEntry::UDS_USER, m_userName ); // assumption
    entry.insert( KIO::UDSEntry::UDS_GROUP, m_groupName ); // assumption
    entry.insert( KIO::UDSEntry::UDS_MODIFICATION_TIME, buff.st_mtime );
    entry.insert( KIO::UDSEntry::UDS_ACCESS_TIME, buff.st_atime ); // ## or use it for deletion time?
    entry.insert( KIO::UDSEntry::UDS_EXTRA, info.origPath );
    entry.insert( KIO::UDSEntry::UDS_EXTRA + 1, info.deletionDate.toString( Qt::ISODate ) );
    return true;
}