PageRenderTime 193ms CodeModel.GetById 60ms app.highlight 71ms RepoModel.GetById 60ms app.codeStats 0ms

/src/libtomahawk/playlist/dynamic/database/DatabaseControl.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 150 lines | 95 code | 34 blank | 21 comment | 6 complexity | 13ab3b1747f76ff4c6020b7fd2ca45fc 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 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.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#include "DatabaseControl.h"
 21
 22using namespace Tomahawk;
 23
 24DatabaseControl::DatabaseControl( const QString& selectedType, const QStringList& typeSelectors, QObject* parent )
 25: DynamicControl ( selectedType.isEmpty() ? "Artist" : selectedType, typeSelectors, parent )
 26{
 27    setType( "database" );
 28
 29    m_editingTimer.setInterval( 500 ); //timeout to edits
 30    m_editingTimer.setSingleShot( true );
 31    connect( &m_editingTimer, SIGNAL( timeout() ), this, SLOT( editTimerFired() ) );
 32
 33    m_delayedEditTimer.setInterval( 250 ); // additional timer for "just typing" without enter or focus change
 34    m_delayedEditTimer.setSingleShot( true );
 35    connect( &m_delayedEditTimer, SIGNAL( timeout() ), &m_editingTimer, SLOT( start() ) );
 36
 37}
 38
 39DatabaseControl::DatabaseControl( const QString& sql, const QString& summary, const QStringList& typeSelectors, QObject* parent )
 40    : DynamicControl ( "SQL", typeSelectors )
 41    , m_sql( sql )
 42    , m_sqlSummary( summary )
 43{
 44    Q_UNUSED( parent );
 45    setType( "database" );
 46}
 47
 48
 49QString DatabaseControl::input() const
 50{
 51    // TODO
 52    return QString();
 53}
 54
 55QWidget* DatabaseControl::inputField()
 56{
 57    return 0;
 58}
 59
 60QString DatabaseControl::match() const
 61{
 62    return m_matchData;
 63}
 64
 65QWidget* DatabaseControl::matchSelector()
 66{
 67    return 0;
 68}
 69
 70QString DatabaseControl::matchString() const
 71{
 72    return m_matchString;
 73}
 74
 75void DatabaseControl::setInput ( const QString& input )
 76{
 77    Q_UNUSED( input );
 78    // TODO
 79    updateWidgets();
 80}
 81
 82void DatabaseControl::setMatch ( const QString& match )
 83{
 84    m_matchData = match;
 85
 86    updateWidgets();
 87}
 88
 89void DatabaseControl::setSelectedType ( const QString& type )
 90{
 91    if ( type != selectedType() ) {
 92        if ( !m_input.isNull() )
 93            delete m_input.data();
 94        if ( !m_match.isNull() )
 95            delete m_match.data();
 96
 97        Tomahawk::DynamicControl::setSelectedType ( type );
 98        updateWidgets();
 99        updateData();
100        //        qDebug() << "Setting new type, set data to:" << m_data.first << m_data.second;
101    }
102}
103
104void DatabaseControl::editingFinished()
105{
106
107}
108
109void DatabaseControl::editTimerFired()
110{
111
112}
113
114void DatabaseControl::updateData()
115{
116
117}
118
119void DatabaseControl::updateWidgets()
120{
121
122}
123
124void DatabaseControl::updateWidgetsFromData()
125{
126
127}
128
129void DatabaseControl::calculateSummary()
130{
131    if( !m_sqlSummary.isEmpty() )
132        return;
133
134}
135
136QString
137DatabaseControl::sql() const
138{
139    return m_sql;
140}
141
142
143QString
144DatabaseControl::summary() const
145{
146    if( !m_sqlSummary.isEmpty() )
147        return m_sqlSummary;
148
149    return m_summary;
150}