Example #1
0
void
NepomukTrack::valueChangedInNepomuk( qint64 value, const Soprano::LiteralValue &literal )
{
    
    // TODO: find a better way to ignore own writes
    // ignore if last own write is less than 3 seconds ago
    // the change will be our own
    if ( !m_lastWrote.isNull() && m_lastWrote.secsTo( QTime::currentTime() ) < 3 )
        return;

    debug() << "nepo data changed " << m_collection->getNameForValue( value ) << " last wrote " << m_lastWrote.secsTo( QTime::currentTime() ) << endl;
    switch ( value )
    {
        case Meta::valUrl:
            m_url = KUrl ( literal.toString() );
            break;
        case Meta::valRating:
            m_rating = literal.toInt();
            break;
    }
    emit notifyObservers();
}
Example #2
0
NepomukTrack::NepomukTrack( NepomukCollection *collection, NepomukRegistry *registry, const Soprano::BindingSet &data )
        : Track()
        , m_collection ( collection )
        , m_registry ( registry )
{
    // init all dates to "0" (because amarok defines that date as "never"

    m_firstPlayed = QDateTime::fromTime_t( 0 );
    m_lastPlayed =  QDateTime::fromTime_t( 0 );
    m_createDate = QDateTime::fromTime_t( 0 );

    m_nepores = Nepomuk::Resource( data[ "r"].uri() ) ;
    m_uid = data[ "trackuid" ].toString();
    m_title = data[ collection->getNameForValue( Meta::valTitle ) ].toString();
    m_url = KUrl( data[ collection->getNameForValue( Meta::valUrl ) ].toString() );
    m_artist = data[ collection->getNameForValue( Meta::valArtist ) ].toString();
    m_album = data[ collection->getNameForValue( Meta::valAlbum ) ].toString();
    m_genre = data[ collection->getNameForValue( Meta::valGenre ) ].toString();
    m_type = data[ collection->getNameForValue( Meta::valFormat ) ].toString();
    m_comment = data[ collection->getNameForValue( Meta::valComment ) ].toString();
    m_composer = data[ collection->getNameForValue( Meta::valComposer ) ].toString();
    m_trackNumber = data[ collection->getNameForValue( Meta::valTrackNr ) ]
            .literal().toInt();
    m_length = data[ collection->getNameForValue( Meta::valLength ) ]
            .literal().toInt();
    m_rating = data[ collection->getNameForValue( Meta::valRating ) ]
            .literal().toInt();
    m_bitrate = data[ collection->getNameForValue( Meta::valBitrate ) ]
            .literal().toInt();
    m_discNumber = data[ collection->getNameForValue( Meta::valDiscNr ) ]
            .literal().toInt();
    m_filesize = data[ collection->getNameForValue( Meta::valFilesize ) ]
            .literal().toInt();
    m_playCount = data[ collection->getNameForValue( Meta::valPlaycount ) ]
            .literal().toInt();
    m_sampleRate = data[ collection->getNameForValue( Meta::valSamplerate ) ]
            .literal().toInt();
    m_score = data[ collection->getNameForValue( Meta::valScore ) ]
            .literal().toInt();
    
    // Soprano gives a warning when they are empty
    Soprano::LiteralValue litval;
    
    litval = data[ collection->getNameForValue( Meta::valFirstPlayed ) ]
            .literal();
    if ( litval.isDateTime() )
        m_firstPlayed = litval.toDateTime();

    litval = data[ collection->getNameForValue( Meta::valLastPlayed ) ]
            .literal();
    if ( litval.isDateTime() )
        m_lastPlayed = litval.toDateTime();
    
    litval = data[ collection->getNameForValue( Meta::valCreateDate ) ]
            .literal();
    if ( litval.isDateTime() )
        m_createDate = litval.toDateTime();
 
    // assuming that Xesam content created is a DateTime, we only want the year
    litval = data[ collection->getNameForValue( Meta::valYear ) ].literal();
    if ( litval.isDateTime() )
        m_year = litval.toDateTime().toString( "yyyy");
}
QDebug operator<<( QDebug dbg, const Soprano::LiteralValue& v )
{
    dbg << v.toString();
    return dbg;
}