~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 
2
 *
 
3
 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
 
4
 *
 
5
 *   Tomahawk is free software: you can redistribute it and/or modify
 
6
 *   it under the terms of the GNU General Public License as published by
 
7
 *   the Free Software Foundation, either version 3 of the License, or
 
8
 *   (at your option) any later version.
 
9
 *
 
10
 *   Tomahawk is distributed in the hope that it will be useful,
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
 *   GNU General Public License for more details.
 
14
 *
 
15
 *   You should have received a copy of the GNU General Public License
 
16
 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#ifndef DATABASECOMMAND_SETPLAYLISTREVISION_H
 
20
#define DATABASECOMMAND_SETPLAYLISTREVISION_H
 
21
 
 
22
#include "DatabaseCommandLoggable.h"
 
23
#include "Playlist.h"
 
24
#include "qjson/qobjecthelper.h"
 
25
 
 
26
#include "DllMacro.h"
 
27
 
 
28
using namespace Tomahawk;
 
29
 
 
30
class DLLEXPORT DatabaseCommand_SetPlaylistRevision : public DatabaseCommandLoggable
 
31
{
 
32
Q_OBJECT
 
33
Q_PROPERTY( QString playlistguid      READ playlistguid  WRITE setPlaylistguid )
 
34
Q_PROPERTY( QString newrev            READ newrev        WRITE setNewrev )
 
35
Q_PROPERTY( QString oldrev            READ oldrev        WRITE setOldrev )
 
36
Q_PROPERTY( QVariantList orderedguids READ orderedguids  WRITE setOrderedguids )
 
37
Q_PROPERTY( QVariantList addedentries READ addedentriesV WRITE setAddedentriesV )
 
38
Q_PROPERTY( bool metadataUpdate       READ metadataUpdate WRITE setMetadataUpdate )
 
39
 
 
40
public:
 
41
    explicit DatabaseCommand_SetPlaylistRevision( QObject* parent = 0 )
 
42
        : DatabaseCommandLoggable( parent )
 
43
        , m_applied( false )
 
44
        , m_localOnly( false )
 
45
        , m_metadataUpdate( false )
 
46
    {}
 
47
 
 
48
    // Constructor for inserting or removing entries
 
49
    DatabaseCommand_SetPlaylistRevision( const source_ptr& s,
 
50
                                                  const QString& playlistguid,
 
51
                                                  const QString& newrev,
 
52
                                                  const QString& oldrev,
 
53
                                                  const QStringList& orderedguids,
 
54
                                                  const QList<Tomahawk::plentry_ptr>& addedentries,
 
55
                                                  const QList<Tomahawk::plentry_ptr>& entries );
 
56
 
 
57
    // constructor for updating metadata only
 
58
    DatabaseCommand_SetPlaylistRevision( const source_ptr& s,
 
59
                                                  const QString& playlistguid,
 
60
                                                  const QString& newrev,
 
61
                                                  const QString& oldrev,
 
62
                                                  const QStringList& orderedguids,
 
63
                                                  const QList<Tomahawk::plentry_ptr>& entriesToUpdate );
 
64
 
 
65
 
 
66
    QString commandname() const { return "setplaylistrevision"; }
 
67
 
 
68
    virtual void exec( DatabaseImpl* lib );
 
69
    virtual void postCommitHook();
 
70
 
 
71
    virtual bool doesMutates() const { return true; }
 
72
    virtual bool localOnly() const { return m_localOnly; }
 
73
    virtual bool groupable() const { return true; }
 
74
 
 
75
    void setAddedentriesV( const QVariantList& vlist )
 
76
    {
 
77
        m_addedentries.clear();
 
78
        foreach( const QVariant& v, vlist )
 
79
        {
 
80
            PlaylistEntry* pep = new PlaylistEntry;
 
81
            QJson::QObjectHelper::qvariant2qobject( v.toMap(), pep );
 
82
 
 
83
            if ( pep->isValid() )
 
84
                m_addedentries << plentry_ptr( pep );
 
85
        }
 
86
    }
 
87
 
 
88
    QVariantList addedentriesV() const
 
89
    {
 
90
        QVariantList vlist;
 
91
        foreach( const plentry_ptr& pe, m_addedentries )
 
92
        {
 
93
            if ( !pe->isValid() )
 
94
                continue;
 
95
 
 
96
            QVariant v = QJson::QObjectHelper::qobject2qvariant( pe.data() );
 
97
            vlist << v;
 
98
        }
 
99
        return vlist;
 
100
    }
 
101
 
 
102
    void setPlaylistguid( const QString& s ) { m_playlistguid = s; }
 
103
 
 
104
    void setNewrev( const QString& s ) { m_newrev = s; }
 
105
    void setOldrev( const QString& s ) { m_oldrev = s; }
 
106
    QString newrev() const { return m_newrev; }
 
107
    QString oldrev() const { return m_oldrev; }
 
108
    QString playlistguid() const { return m_playlistguid; }
 
109
    bool metadataUpdate() const { return m_metadataUpdate; }
 
110
    void setMetadataUpdate( bool metadataUpdate ) { m_metadataUpdate = metadataUpdate; }
 
111
 
 
112
    void setOrderedguids( const QVariantList& l ) { m_orderedguids = l; }
 
113
    QVariantList orderedguids() const { return m_orderedguids; }
 
114
 
 
115
protected:
 
116
    bool m_applied;
 
117
    QStringList m_previous_rev_orderedguids;
 
118
    QString m_playlistguid;
 
119
    QString m_newrev, m_oldrev;
 
120
    QMap<QString, Tomahawk::plentry_ptr> m_addedmap;
 
121
 
 
122
    QString m_currentRevision;
 
123
 
 
124
private:
 
125
    QString hintFromQuery( const query_ptr& query ) const;
 
126
 
 
127
    QVariantList m_orderedguids;
 
128
    QList<Tomahawk::plentry_ptr> m_addedentries, m_entries;
 
129
 
 
130
    bool m_localOnly, m_metadataUpdate;
 
131
};
 
132
 
 
133
#endif // DATABASECOMMAND_SETPLAYLISTREVISION_H