void VideoResourceWidget::setResource(Nepomuk::Resource resource)
{
    m_video = Nepomuk::Video(resource);
    kDebug() << "VERT:" << m_video.heights();
    kDebug() << "WITH" << m_video.widths();
    m_width = resource.property(Nepomuk::Image().verticalResolutionUri()).toString().toInt();
    m_height = resource.property(Nepomuk::Image().horizontalResolutionUri()).toString().toInt();
    kDebug() << "------> video resolution wxh::" << m_width << m_height;
    ResourceWidget::setResource(resource);
}
示例#2
0
void ResourceBrowser::slotOpenLinkedResource(QModelIndex selectedResource)
{
    m_linkedResourceView->selectionModel()->setCurrentIndex(selectedResource,QItemSelectionModel::NoUpdate);
    Nepomuk::Resource currentResource = (m_linkedResourceViewModel->resourceForIndex(
                                             m_linkedResourceView->selectionModel()->currentIndex()));
    KUrl url = currentResource.property(Nepomuk::Vocabulary::NIE::url()).toString();
    qDebug()<<url<<"usagecount="<<currentResource.usageCount();
    if(!url.isEmpty()) {
        new KRun(url,this);
        currentResource.increaseUsageCount();
    }
}
示例#3
0
void ResourceBrowser::slotRecommendedResources()
{
    Nepomuk::Resource resource = m_resourceViewModel->resourceForIndex(m_resourceView->selectionModel()->currentIndex() );
    QList<Nepomuk::Resource> recommendations;

    if(!(resource.label().isEmpty() && resource.genericLabel().isEmpty())) {
        if (!resource.topics().empty()) {
            recommendations = topicResourceSearch(resource);
            qDebug()<<recommendations;
        }
        qDebug()<<"length :"<<recommendations.length();
        if (recommendations.length() < 10 && !resource.label().isEmpty()) {
            qDebug()<<"less than 10";
            recommendations.append(contentResourceSearch(resource.label()));
            qDebug()<<recommendations;
        }

        if (recommendations.length() < 10 && !resource.genericLabel().isEmpty()) {
            qDebug()<<"less than 10";
            recommendations.append(contentResourceSearch(resource.genericLabel()));
            qDebug()<<recommendations;
        }

        m_recommendationViewModel->setResources(recommendations);
    }
    else qDebug()<<"label empty";
}
示例#4
0
void Nepomuk::TagAnnotation::doCreate( Nepomuk::Resource resource )
{
    kDebug() << "tagging" << resource.resourceUri() << "with" << d->m_tag;
    Nepomuk::Tag tag;
    if( d->m_tagUri.isValid() )
        tag = d->m_tagUri;
    else
        tag = d->m_tag;
    if ( tag.label().isEmpty() &&
         !tag.identifiers().isEmpty() ) {
        tag.setLabel( d->m_tag );
    }
    resource.addTag( tag );
    emitFinished();
}
示例#5
0
文件: entity.cpp 项目: KDE/ktp-kde
Entity::Entity(const Nepomuk::Resource &resource)
  : d(new Entity::Private)
{
    kDebug();

    d->resource = resource;
    d->resourceUri = resource.resourceUri();
}
void Nepomuk::QueryClientWrapper::slotNewEntries(const QList<Nepomuk::Query::Result>& results)
{
    QList<Plasma::QueryMatch> matches;
    foreach(const Query::Result& result, results) {
        Plasma::QueryMatch match(m_runner);
        match.setType(Plasma::QueryMatch::PossibleMatch);
        match.setRelevance(normalizeScore(result.score()));

        Nepomuk::Resource res = result.resource();

        QString type;
        QString iconName;

        KMimeType::Ptr mimetype;
        if (res.hasProperty(Nepomuk::Vocabulary::NIE::mimeType())) {
            mimetype = KMimeType::mimeType(res.property(Nepomuk::Vocabulary::NIE::mimeType()).toString());
        }
        if (!mimetype && res.isFile() && res.toFile().url().isLocalFile()) {
            const KUrl url(res.toFile().url());
            mimetype = KMimeType::findByUrl(url);
        }

        if (mimetype) {
            type = mimetype->comment();
            iconName = mimetype->iconName();
        }

        if (type.isEmpty() ) {
            type = Nepomuk::Types::Class(res.resourceType()).label();
            iconName = res.genericIcon();
        }

        match.setText(res.genericLabel());
        match.setSubtext(type);
        match.setIcon(KIcon(iconName.isEmpty() ? QString::fromLatin1("nepomuk") : iconName));

        match.setData(qVariantFromValue(res));
        match.setId(KUrl(res.resourceUri()).url());
        matches << match;
    }
示例#7
0
bool NW::Executive::canProcess( const Nepomuk::Resource & res) const
{
    // If no filter set up, then no filter is necessary
    if ( d->typeFilters.isEmpty() )
        return true;

    // Create a query
    /*
    for( int i = 0; i < d->typeFilters; i++)
    {
    }*/
    static QString unionString = QString( "UNION" );
    QStringList queryExactList;
    QStringList querySubclassList;
    bool currentType = d->typeFilters[0].allowed;

            
    /* General idea - unite consiquent records with same .allowed field into
     * one group, and  when prepare to switch to another group - create a query
     * from accumulated strings, ask it and determine the result. 
     * Reaching the end of filter list is treated as switching to another group
     */
    foreach( const FilterRecord & record, d->typeFilters)
    {
        if ( record.allowed != currentType ) {

            // After this function call, queryExactList will change!
            QString query = buildFilterQuery(res.resourceUri(), queryExactList, querySubclassList);


            Soprano::QueryResultIterator it = res.manager()->mainModel()->executeQuery(query, Soprano::Query::QueryLanguageSparql );
            if ( it.next() ) {
                // Has answer
                if ( it.boolValue() ) {
                    return currentType;
                }
            }
            else {
                // Wow. Ask query doesn't return an answer. May be it is incorrect ?
                qCritical() << "Filter query is incorrect. Report a BUG please";
                return false;
            }

            // Clear
            queryExactList.clear();
            querySubclassList.clear();

            // Switch current type
            currentType = record.allowed;
        }

        // Accumulate to the group
        if ( record.matchType == ExactMatch or record.matchType == SubclassOrExactMatch ) {
            queryExactList << FilterRecord::queryString(ExactMatch, record.typeUrl) << unionString;
        }

        if ( record.matchType == SubclassOrExactMatch or record.matchType == SubclassMatch ) {
            querySubclassList << FilterRecord::queryString(SubclassMatch, record.typeUrl) << unionString;
        }
    }
    // Build for the last group
    QString query = buildFilterQuery(res.resourceUri(), queryExactList, querySubclassList);


    Soprano::QueryResultIterator it = res.manager()->mainModel()->executeQuery(query, Soprano::Query::QueryLanguageSparql );
    if ( it.isBool() ) {
        // Has answer
        if ( it.boolValue() ) {
            return currentType;
        }
        else {
            // return default rule
            return d->defaultTypeRule;
        }
    }
    else {
        // Wow. Ask query doesn't return an answer. May be it is incorrect ?
        qCritical() << "Filter query is incorrect. Report a BUG please";
        return false;
    }


}
示例#8
0
void IMDB::successResponse(QNetworkReply *reply)
{
    QByteArray data = reply->readAll();
    this->responseJSON = new QString(data);
    //qDebug("got successfully!");
    //qDebug(this->responseJSON->toLatin1().data());

    //QJson::Parser parser;
    parser = new QJson::Parser();
    bool ok;

    //parsedResponse = new QVariantMap();

    parsedResponse = parser->parse(this->responseJSON->toLatin1(), &ok).toMap();
    if (!ok) {
      qFatal("An error occured during parsing");
      exit (1);
    }

    if(true/*parsedResponse["Response"].toString().compare("True") == 0*/)
    {

        qDebug() << "Movie Title:" << parsedResponse["Title"].toString();

        QDownloader* downloader = new QDownloader("/home/sandeep/.moviemanager/", parsedResponse["ID"].toString() + ".jpg");
        downloader->setFile(parsedResponse["Poster"].toString());

        /*
          {"Title":"Avatar",
            "Year":"2009",
            "Rated":"PG-13",
            "Released":"18 Dec 2009",
            "Genre":"Action, Adventure, Fantasy, Sci-Fi",
            "Director":"James Cameron",
            "Writer":"James Cameron",
            "Actors":"Sam Worthington, Zoe Saldana, Sigourney Weaver, Michelle Rodriguez",
            "Plot":"A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.",
            "Poster":"http://ia.media-imdb.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_SX320.jpg",
            "Runtime":"2 hrs 42 mins",
            "Rating":"8.1",
            "Votes":"386930",
            "ID":"tt0499549",
            "Response":"True"}
          */

        /*
            // create all the regular actor resources which we will add to all episodes
             QList<Nepomuk::NCO::Contact> regularActors;
             foreach(const QString& actor, series.actors()) {
                 Nepomuk::NCO::Contact contact;
                 contact.setFullname(actor);
                 regularActors << contact;
                 graph << contact;
             }

        */

       Nepomuk::Resource tempActor;
       tempActor.addType(Nepomuk::Vocabulary::NCO::Contact());
       tempActor.setLabel(QString("Phaneendra hegde"));


        //accessing mResource
        qDebug() << mResource.property(Nepomuk::Vocabulary::NFO::fileName()).toString() << "wohoooo";
        //how to add another actor? tvnamer.cpp line no.333 to 340
//        mResource.setProperty(Nepomuk::Vocabulary::NMM::actor(),parsedResponse["Actors"].toString());
        qDebug() << parsedResponse["Actors"].toString();
        qDebug() << parsedResponse["Director"].toString();
//        qDebug() << parsedResponse["Actors"].toString();
//        qDebug() << parsedResponse["Actors"].toString();
//        qDebug() << parsedResponse["Actors"].toString();
        //mResource.addProperty(QUrl::fromEncoded("http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#hero", QUrl::StrictMode),"Upendra");

        //mResource.setProperty(Nepomuk::Vocabulary::NMM::artwork(),parsedResponse["Poster"].toString());//qurl
        /*mResource.setProperty(Nepomuk::Vocabulary::NMM::director(),parsedResponse["Director"].toString());
        mResource.setProperty(Nepomuk::Vocabulary::NMM::writer(),parsedResponse["Writer"].toString());
        mResource.setProperty(Nepomuk::Vocabulary::NMM::genre(),parsedResponse["Genre"].toString());
        mResource.setProperty(Nepomuk::Vocabulary::NMM::releaseDate(),parsedResponse["Released"].toString());
        mResource.setProperty(Nepomuk::Vocabulary::NMM::audienceRating(),parsedResponse["Rating"].toString());
        mResource.setProperty(Nepomuk::Vocabulary::NMM::actor(),tempActor);
        */
        Nepomuk::Resource tempActor2;
        tempActor2.addType(Nepomuk::Vocabulary::NCO::Contact());
        tempActor2.setLabel(QString("Vijay Mahantesh"));

        mResource.setProperty(Nepomuk::Vocabulary::NMM::writer(),tempActor2 );

        mResource.setProperty(Nepomuk::Vocabulary::NMM::synopsis(),parsedResponse["ID"].toString());

        Nepomuk::Resource* tempImage = new Nepomuk::Resource("/home/sandeep/.moviemanager/"+parsedResponse["ID"].toString() +".jpg");
        tempImage->addType(Nepomuk::Vocabulary::NFO::Image());
        //tempActor.set

        mResource.setProperty(Nepomuk::Vocabulary::NMM::artwork(),*tempImage);

        //mResource.setProperty(Nepomuk::Vocabulary);


    }
    else
    {
        qDebug("movie not found!");
    }




}
示例#9
0
文件: person.cpp 项目: KDE/ktp-kde
Person::Person(const Nepomuk::Resource &pimoPerson)
  : ContactSet(),
    Entity(pimoPerson),
    d(new Private)
{
    kDebug();

    // Check the resource we have been passed is a valid PIMO:Person.
    if (pimoPerson.hasType(Nepomuk::Vocabulary::PIMO::Person())) {
        kDebug() << "We have been passed a valid PIMO:Person";
        setValid(true);
        d->pimoPerson = pimoPerson;

        // Setup the contact set.
        d->query = new Nepomuk::Query::QueryServiceClient(this);

        connect(d->query, SIGNAL(newEntries(QList<Nepomuk::Query::Result>)),
                this, SLOT(onNewEntries(QList<Nepomuk::Query::Result>)));
        connect(d->query, SIGNAL(entriesRemoved(QList<QUrl>)),
                this, SLOT(onEntriesRemoved(QList<QUrl>)));

        connect(this, SIGNAL(contactAdded(KTelepathy::ContactPtr)),
                SLOT(onContactAdded(KTelepathy::ContactPtr)));
        connect(this, SIGNAL(contactRemoved(KTelepathy::ContactPtr)),
                SLOT(onContactRemoved(KTelepathy::ContactPtr)));

        // Get all Telepathy PersonContacts which belong to this PIMO:Person
        {
            using namespace Nepomuk::Query;
            using namespace Nepomuk::Vocabulary;


            // Find grounding occurrences of ME
            ComparisonTerm meGroundingOccurrencesTerm(PIMO::groundingOccurrence(),
                                                      ResourceTerm(d->mePimoPerson));
            meGroundingOccurrencesTerm.setInverted(true);

            // Filter the grounding occurrences to include only those that are PersonContacts.
            AndTerm mePersonContactsTerm(ResourceTypeTerm(NCO::PersonContact()),
                                         meGroundingOccurrencesTerm);

            // Find all the IMAccounts of these person contacts
            ComparisonTerm meImAccountsTerm(NCO::hasIMAccount(),
                                            mePersonContactsTerm);
            meImAccountsTerm.setInverted(true);

            // Get all the IM Accounts that are accessed by this IM account of ours.
            ComparisonTerm isAccessedByTerm(NCO::isAccessedBy(),
                                            ResourceTypeTerm(NCO::IMAccount()));
            isAccessedByTerm.setVariableName(QLatin1String("localAccount"));


            // Ensure that the resource accessed through us are IM Accounts.
            AndTerm themImAccountsTerm(ResourceTypeTerm(NCO::IMAccount()),
                                       isAccessedByTerm);

            // Get the PersonContact associated with that IM Account.
            ComparisonTerm themPersonContactsTerm(NCO::hasIMAccount(), themImAccountsTerm);
            themPersonContactsTerm.setVariableName(QLatin1String("account"));

            // Check that the PersonContact is a grounding occurrence of this Person.
            ComparisonTerm themGroundingOccurrencesTerm(PIMO::groundingOccurrence(),
                                                        ResourceTerm(d->pimoPerson));
            themGroundingOccurrencesTerm.setInverted(true);

            // Get the PIMO person which the PersonContact was a grounding occurrence of.
            Query query(AndTerm(ResourceTypeTerm(NCO::PersonContact()),
                                themPersonContactsTerm, themGroundingOccurrencesTerm));

            bool queryResult = d->query->query(query);

            if (!queryResult) {
                kWarning() << "Failed to query the Nepomuk database. QueryServiceClient may not be running";
            }
        }
    } else {
        kWarning() << "Person object requires a valid PIMO:Person";
    }
}