PageRenderTime 101ms CodeModel.GetById 38ms app.highlight 16ms RepoModel.GetById 32ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 174 lines | 115 code | 41 blank | 18 comment | 1 complexity | 2902ebea0d0417e1dc2945810f11ad3b MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2013,      Uwe L. Korn <uwelk@xhochy.com>
  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#include "DatabaseCommand_p.h"
 21
 22#include "utils/Logger.h"
 23
 24#include "Source.h"
 25
 26
 27namespace Tomahawk
 28{
 29
 30DatabaseCommand::DatabaseCommand( QObject* parent )
 31    : QObject( parent )
 32    , d_ptr( new DatabaseCommandPrivate( this ) )
 33{
 34}
 35
 36
 37DatabaseCommand::DatabaseCommand( const Tomahawk::source_ptr& src, QObject* parent )
 38    : QObject( parent )
 39    , d_ptr( new DatabaseCommandPrivate( this, src ) )
 40{
 41}
 42
 43
 44DatabaseCommand::DatabaseCommand( const DatabaseCommand& other )
 45    : QObject( other.parent() )
 46    , d_ptr( new DatabaseCommandPrivate( this ) )
 47{
 48}
 49
 50
 51DatabaseCommand::~DatabaseCommand()
 52{
 53}
 54
 55
 56DatabaseCommand::State
 57DatabaseCommand::state() const
 58{
 59    Q_D( const DatabaseCommand );
 60    return d->state;
 61}
 62
 63
 64void
 65DatabaseCommand::_exec( DatabaseImpl* lib )
 66{
 67    Q_D( DatabaseCommand );
 68    d->state = RUNNING;
 69    emitRunning();
 70    exec( lib );
 71    d->state = FINISHED;
 72}
 73
 74
 75void
 76DatabaseCommand::setSource( const Tomahawk::source_ptr& s )
 77{
 78    Q_D( DatabaseCommand );
 79    d->source = s;
 80}
 81
 82
 83const Tomahawk::source_ptr&
 84DatabaseCommand::source() const
 85{
 86    Q_D( const DatabaseCommand );
 87    return d->source;
 88}
 89
 90
 91QVariant
 92DatabaseCommand::data() const
 93{
 94    Q_D( const DatabaseCommand );
 95    return d->data;
 96}
 97
 98
 99void
100DatabaseCommand::setData( const QVariant& data )
101{
102    Q_D( DatabaseCommand );
103    d->data = data;
104}
105
106
107QString
108DatabaseCommand::guid() const
109{
110    Q_D( const DatabaseCommand );
111    if( d->guid.isEmpty() )
112        d->guid = uuid();
113
114    return d->guid;
115}
116
117
118void
119DatabaseCommand::setGuid( const QString& g)
120{
121    Q_D( DatabaseCommand );
122    d->guid = g;
123}
124
125
126void
127DatabaseCommand::emitFinished()
128{
129    Q_D( DatabaseCommand );
130    emit finished( d->ownRef.toStrongRef() );
131    emit finished();
132}
133
134void
135DatabaseCommand::emitCommitted()
136{
137    Q_D( DatabaseCommand );
138    emit committed( d->ownRef.toStrongRef() );
139    emit committed();
140}
141
142
143void
144DatabaseCommand::emitRunning()
145{
146    Q_D( DatabaseCommand );
147    emit running( d->ownRef.toStrongRef() );
148    emit running();
149}
150
151
152QWeakPointer< DatabaseCommand >
153DatabaseCommand::weakRef() const
154{
155    Q_D( const DatabaseCommand );
156    return d->ownRef;
157}
158
159
160void
161DatabaseCommand::setWeakRef( QWeakPointer< DatabaseCommand > weakRef )
162{
163    Q_D( DatabaseCommand );
164    d->ownRef = weakRef;
165}
166
167DatabaseCommand::DatabaseCommand( QObject* parent, DatabaseCommandPrivate* d)
168    : QObject( parent )
169    , d_ptr( d )
170{
171
172}
173
174}