mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 16:29:43 +01:00
Have dbcmd_ShareTrack inherit from dbcmd_SocialAction and write to db.
This commit is contained in:
parent
4fff01b56d
commit
d0d2278e17
@ -29,36 +29,24 @@
|
||||
#include "jobview/ErrorStatusMessage.h"
|
||||
|
||||
DatabaseCommand_ShareTrack::DatabaseCommand_ShareTrack( QObject* parent )
|
||||
: DatabaseCommandLoggable( parent )
|
||||
: DatabaseCommand_SocialAction( parent )
|
||||
{}
|
||||
|
||||
|
||||
DatabaseCommand_ShareTrack::DatabaseCommand_ShareTrack( const Tomahawk::query_ptr& query,
|
||||
const QString& recipientDbid,
|
||||
QObject* parent )
|
||||
: DatabaseCommandLoggable( parent )
|
||||
, m_query( query )
|
||||
: DatabaseCommand_SocialAction( query, "Inbox", "", parent )
|
||||
, m_recipient( recipientDbid )
|
||||
{
|
||||
setSource( SourceList::instance()->getLocal() );
|
||||
|
||||
setArtist( query->artist() );
|
||||
setTrack( query->track() );
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
DatabaseCommand_ShareTrack::DatabaseCommand_ShareTrack( const Tomahawk::result_ptr& result,
|
||||
const QString& recipientDbid,
|
||||
QObject* parent )
|
||||
: DatabaseCommandLoggable( parent )
|
||||
, m_result( result )
|
||||
: DatabaseCommand_SocialAction( result->toQuery(), "Inbox", "", parent )
|
||||
, m_recipient( recipientDbid )
|
||||
{
|
||||
setSource( SourceList::instance()->getLocal() );
|
||||
|
||||
setArtist( result->artist()->name() );
|
||||
setTrack( result->track() );
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
QString
|
||||
@ -71,6 +59,21 @@ void
|
||||
DatabaseCommand_ShareTrack::exec( DatabaseImpl* dbi )
|
||||
{
|
||||
Q_ASSERT( !source().isNull() );
|
||||
|
||||
QString myDbid = SourceList::instance()->getLocal()->nodeId();
|
||||
QString sourceDbid = source()->nodeId();
|
||||
if ( myDbid != m_recipient || sourceDbid == m_recipient )
|
||||
return;
|
||||
|
||||
//we store the comment field as JSON: { sender: dbid, unlistened: bool }
|
||||
QVariantMap comment;
|
||||
comment.insert( "sender", sourceDbid );
|
||||
comment.insert( "unlistened", true );
|
||||
|
||||
QJson::Serializer serializer;
|
||||
setComment( serializer.serialize( comment ) );
|
||||
|
||||
DatabaseCommand_SocialAction::exec( dbi );
|
||||
}
|
||||
|
||||
void
|
||||
@ -88,14 +91,7 @@ DatabaseCommand_ShareTrack::postCommitHook()
|
||||
return;
|
||||
|
||||
//From here on, everything happens only on the recipient, and only if recipient!=source
|
||||
if ( !m_result.isNull() && m_query.isNull() )
|
||||
{
|
||||
m_query = m_result->toQuery();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_query = Tomahawk::Query::get( m_artist, m_track, QString() );
|
||||
}
|
||||
m_query = Tomahawk::Query::get( artist(), track(), QString() );
|
||||
|
||||
if ( m_query.isNull() )
|
||||
return;
|
||||
@ -118,7 +114,7 @@ DatabaseCommand_ShareTrack::postCommitHook()
|
||||
bool
|
||||
DatabaseCommand_ShareTrack::doesMutates() const
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -143,34 +139,6 @@ DatabaseCommand_ShareTrack::groupable() const
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
DatabaseCommand_ShareTrack::artist() const
|
||||
{
|
||||
return m_artist;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCommand_ShareTrack::setArtist( const QString& s )
|
||||
{
|
||||
m_artist = s;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
DatabaseCommand_ShareTrack::track() const
|
||||
{
|
||||
return m_track;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCommand_ShareTrack::setTrack( const QString& s )
|
||||
{
|
||||
m_track = s;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
DatabaseCommand_ShareTrack::recipient() const
|
||||
{
|
||||
|
@ -22,17 +22,15 @@
|
||||
#include <QObject>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include "database/DatabaseCommandLoggable.h"
|
||||
#include "database/DatabaseCommand_SocialAction.h"
|
||||
#include "SourceList.h"
|
||||
#include "Typedefs.h"
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
class DLLEXPORT DatabaseCommand_ShareTrack : public DatabaseCommandLoggable
|
||||
class DLLEXPORT DatabaseCommand_ShareTrack : public DatabaseCommand_SocialAction
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( QString artist READ artist WRITE setArtist )
|
||||
Q_PROPERTY( QString track READ track WRITE setTrack )
|
||||
Q_PROPERTY( QString recipient READ recipient WRITE setRecipient )
|
||||
|
||||
public:
|
||||
@ -58,21 +56,10 @@ public:
|
||||
virtual bool localOnly() const;
|
||||
virtual bool groupable() const;
|
||||
|
||||
QString artist() const;
|
||||
void setArtist( const QString& s );
|
||||
|
||||
QString track() const;
|
||||
void setTrack( const QString& s );
|
||||
|
||||
QString recipient() const;
|
||||
void setRecipient( const QString& s );
|
||||
virtual QString recipient() const;
|
||||
virtual void setRecipient( const QString& s );
|
||||
|
||||
private:
|
||||
Tomahawk::query_ptr m_query;
|
||||
Tomahawk::result_ptr m_result;
|
||||
|
||||
QString m_artist;
|
||||
QString m_track;
|
||||
QString m_recipient;
|
||||
};
|
||||
|
||||
|
@ -51,7 +51,7 @@ DatabaseCommand_SocialAction::exec( DatabaseImpl* dbi )
|
||||
|
||||
QVariant srcid = source()->isLocal() ? QVariant( QVariant::Int ) : source()->id();
|
||||
|
||||
if ( m_artist.isNull() || m_track.isEmpty() )
|
||||
if ( m_artist.isNull() || m_track.isEmpty() || m_action.isEmpty() )
|
||||
return;
|
||||
|
||||
int artid = dbi->artistId( m_artist, true );
|
||||
|
@ -104,28 +104,28 @@ public:
|
||||
* \return Name of the artist.
|
||||
* \see setArtist()
|
||||
*/
|
||||
QString artist() const { return m_artist; }
|
||||
virtual QString artist() const { return m_artist; }
|
||||
|
||||
/**
|
||||
* \brief Sets the artist name for this database command.
|
||||
* \param s QString containing the artist name.
|
||||
* \see artist()
|
||||
*/
|
||||
void setArtist( const QString& s ) { m_artist = s; }
|
||||
virtual void setArtist( const QString& s ) { m_artist = s; }
|
||||
|
||||
/**
|
||||
* \brief Returns the track name associated with this social action.
|
||||
* \return QString containing the track name.
|
||||
* \see setTrack()
|
||||
*/
|
||||
QString track() const { return m_track; }
|
||||
virtual QString track() const { return m_track; }
|
||||
|
||||
/**
|
||||
* \brief Sets the track name associated with this database command.
|
||||
* \param track QString containing the track name.
|
||||
* \see track()
|
||||
*/
|
||||
void setTrack( const QString& track ) { m_track = track; }
|
||||
virtual void setTrack( const QString& track ) { m_track = track; }
|
||||
|
||||
/**
|
||||
* \brief Returns the social action for this database command instance.
|
||||
@ -146,40 +146,41 @@ public:
|
||||
* \return QString containing comment associated with this social action.
|
||||
* \see setComment()
|
||||
*/
|
||||
QString comment() const { return m_comment; }
|
||||
virtual QString comment() const { return m_comment; }
|
||||
|
||||
/**
|
||||
* \brief Sets the comment associated with this social action.
|
||||
* \param com Comment associated with this social action.
|
||||
* \see comment()
|
||||
*/
|
||||
void setComment( const QString& com ) { m_comment = com; }
|
||||
virtual void setComment( const QString& com ) { m_comment = com; }
|
||||
|
||||
/**
|
||||
* \brief Returns the timestamp associated with this social action.
|
||||
* \return unsigned integer containing timestamp
|
||||
* \see setTimesetamp()
|
||||
*/
|
||||
int timestamp() const { return m_timestamp; }
|
||||
virtual int timestamp() const { return m_timestamp; }
|
||||
|
||||
/**
|
||||
* \brief Sets the timestamp associated with this social action.
|
||||
* \param ts unsigned integer associated with this social action.
|
||||
* \see timestamp()
|
||||
*/
|
||||
void setTimestamp( const int ts ) { m_timestamp = ts; }
|
||||
virtual void setTimestamp( const int ts ) { m_timestamp = ts; }
|
||||
|
||||
virtual bool doesMutates() const { return true; }
|
||||
virtual bool groupable() const { return true; }
|
||||
|
||||
private:
|
||||
protected:
|
||||
Tomahawk::query_ptr m_query;
|
||||
|
||||
private:
|
||||
QString m_artist;
|
||||
QString m_track;
|
||||
int m_timestamp;
|
||||
QString m_comment;
|
||||
QString m_action;
|
||||
QString m_action; //! currently used values: Love, Inbox
|
||||
};
|
||||
|
||||
#endif // DATABASECOMMAND_SOCIALACTION_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user