PageRenderTime 203ms CodeModel.GetById 100ms app.highlight 4ms RepoModel.GetById 97ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand_ClientAuthValid.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 61 lines | 35 code | 9 blank | 17 comment | 2 complexity | d92ce7177f5239291808ab2ec0a5569b MD5 | raw file
 1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 2 *
 3 *   Copyright 2010-2011, Leo Franchi   <lfranchi@kde.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#include "DatabaseCommand_ClientAuthValid.h"
20
21#include "DatabaseImpl.h"
22#include "TomahawkSqlQuery.h"
23#include "utils/Logger.h"
24#include "Source.h"
25
26
27namespace Tomahawk
28{
29
30DatabaseCommand_ClientAuthValid::DatabaseCommand_ClientAuthValid( const QString& clientToken, QObject* parent )
31    : DatabaseCommand( parent )
32    , m_clientToken( clientToken )
33{
34}
35
36
37void DatabaseCommand_ClientAuthValid::exec( DatabaseImpl* lib )
38{
39    TomahawkSqlQuery q = lib->newquery();
40    q.prepare( "SELECT name FROM http_client_auth WHERE token = ?" );
41    q.addBindValue( m_clientToken );
42
43    if ( q.exec() )
44    {
45        if ( q.next() )
46        {
47            QString name = q.value( 0 ).toString();
48            emit authValid( m_clientToken, name, true );
49        }
50        else
51        {
52            emit authValid( m_clientToken, QString(), false );
53        }
54    }
55    else
56    {
57        qWarning() << "Failed to query http auth table for client:" << m_clientToken;
58    }
59}
60
61}