PageRenderTime 75ms CodeModel.GetById 27ms app.highlight 5ms RepoModel.GetById 28ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand_LoadSocialActions.h

http://github.com/tomahawk-player/tomahawk
C Header | 123 lines | 42 code | 18 blank | 63 comment | 0 complexity | 258c1e7175288c5bd85e2e9b18ef5c88 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2011, Christopher Reichert <creichert07@gmail.com>
  4 *   Copyright 2012, Leo Franchi <lfranchi@kde.org>
  5 *
  6 *   Tomahawk is free software: you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation, either version 3 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   Tomahawk is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#ifndef DATABASECOMMAND_LOADSOCIALACTIONS_H
 21#define DATABASECOMMAND_LOADSOCIALACTIONS_H
 22
 23#include <QDateTime>
 24#include <QList>
 25#include "database/DatabaseCommand.h"
 26
 27#include "SourceList.h"
 28#include "Typedefs.h"
 29#include "Artist.h"
 30#include "Track.h"
 31
 32#include "DllMacro.h"
 33
 34namespace Tomahawk
 35{
 36
 37/**
 38 * \class DatabaseCommand_LoadSocialActions
 39 * \brief Database command used to load social actions from the database.
 40 *
 41 * This Database command allows Tomahawk to load social actions from
 42 * the local database. The loaded social actions can be used to create
 43 * dynamic playlists, generate statistics and provide data to share with
 44 * friends on tomahawk.
 45 *
 46 * \see DatabaseCommand_SocialAction
 47 */
 48class DLLEXPORT DatabaseCommand_LoadSocialActions : public DatabaseCommand
 49{
 50Q_OBJECT
 51
 52public:
 53    typedef QMap<Tomahawk::track_ptr, Tomahawk::SocialAction> TrackActions;
 54    /**
 55     * \brief Default constructor for DatabaseCommand_LoadSocialActions.
 56     *
 57     * Constructs an empty database command for loading social actions.
 58     */
 59    explicit DatabaseCommand_LoadSocialActions( QObject* parent = 0 )
 60        : DatabaseCommand( parent )
 61    {}
 62
 63    /**
 64     * \brief Overloaded constructor for DatabaseCommand_LoadSocialAction.
 65     * \param result A Tomahawk Query object.
 66     * \param parent Parent class.
 67     *
 68     * Constructor which creates a new database command for loading all social actions.
 69     */
 70    explicit DatabaseCommand_LoadSocialActions( const Tomahawk::trackdata_ptr& track, QObject* parent = 0 )
 71        : DatabaseCommand( parent ), m_track( track )
 72    {
 73        setSource( SourceList::instance()->getLocal() );
 74    }
 75
 76    /**
 77     * Load all tracks with a specific social action
 78     */
 79    explicit DatabaseCommand_LoadSocialActions( const QString& action, const Tomahawk::source_ptr& source, QObject* parent = 0 )
 80        : DatabaseCommand( parent ), m_actionOnly( action )
 81    {
 82        setSource( source );
 83        qRegisterMetaType<TrackActions>( "DatabaseCommand_LoadSocialActions::TrackActions" );
 84    }
 85
 86    /**
 87     * \brief Returns the name of this database command.
 88     * \return QString containing the database command name 'loadsocialaction'.
 89     */
 90    virtual QString commandname() const { return "loadsocialactions"; }
 91
 92    /**
 93     * \brief Executes the database command.
 94     * \param dbi Database instance.
 95     *
 96     * This method prepares an sql query to load the social actions
 97     * from the database into a list of all social actions.
 98     *
 99     * \see Result::setAllSocialActions()
100     */
101    virtual void exec( DatabaseImpl* );
102
103    virtual bool doesMutates() const { return false; }
104
105signals:
106    /**
107     * All loaded social actions for each track found, for queries that generate all tracks
108     * with matching actions.
109     */
110    void done( DatabaseCommand_LoadSocialActions::TrackActions actionsForTracks );
111
112private:
113    Tomahawk::trackdata_ptr m_track;
114    QString m_actionOnly;
115
116};
117
118}
119
120//FIXME: Qt5: this fails with Qt5, is it needed at all? It compiles fine without in Qt4 as well
121// Q_DECLARE_METATYPE( DatabaseCommand_LoadSocialActions::TrackActions )
122
123#endif // DATABASECOMMAND_LOADSOCIALACTIONS_H