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