/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. #include "DatabaseControl.h"
  20. using namespace Tomahawk;
  21. DatabaseControl::DatabaseControl( const QString& selectedType, const QStringList& typeSelectors, QObject* parent )
  22. : DynamicControl ( selectedType.isEmpty() ? "Artist" : selectedType, typeSelectors, parent )
  23. {
  24. setType( "database" );
  25. m_editingTimer.setInterval( 500 ); //timeout to edits
  26. m_editingTimer.setSingleShot( true );
  27. connect( &m_editingTimer, SIGNAL( timeout() ), this, SLOT( editTimerFired() ) );
  28. m_delayedEditTimer.setInterval( 250 ); // additional timer for "just typing" without enter or focus change
  29. m_delayedEditTimer.setSingleShot( true );
  30. connect( &m_delayedEditTimer, SIGNAL( timeout() ), &m_editingTimer, SLOT( start() ) );
  31. }
  32. DatabaseControl::DatabaseControl( const QString& sql, const QString& summary, const QStringList& typeSelectors, QObject* parent )
  33. : DynamicControl ( "SQL", typeSelectors )
  34. , m_sql( sql )
  35. , m_sqlSummary( summary )
  36. {
  37. Q_UNUSED( parent );
  38. setType( "database" );
  39. }
  40. QString DatabaseControl::input() const
  41. {
  42. // TODO
  43. return QString();
  44. }
  45. QWidget* DatabaseControl::inputField()
  46. {
  47. return 0;
  48. }
  49. QString DatabaseControl::match() const
  50. {
  51. return m_matchData;
  52. }
  53. QWidget* DatabaseControl::matchSelector()
  54. {
  55. return 0;
  56. }
  57. QString DatabaseControl::matchString() const
  58. {
  59. return m_matchString;
  60. }
  61. void DatabaseControl::setInput ( const QString& input )
  62. {
  63. Q_UNUSED( input );
  64. // TODO
  65. updateWidgets();
  66. }
  67. void DatabaseControl::setMatch ( const QString& match )
  68. {
  69. m_matchData = match;
  70. updateWidgets();
  71. }
  72. void DatabaseControl::setSelectedType ( const QString& type )
  73. {
  74. if ( type != selectedType() ) {
  75. if ( !m_input.isNull() )
  76. delete m_input.data();
  77. if ( !m_match.isNull() )
  78. delete m_match.data();
  79. Tomahawk::DynamicControl::setSelectedType ( type );
  80. updateWidgets();
  81. updateData();
  82. // qDebug() << "Setting new type, set data to:" << m_data.first << m_data.second;
  83. }
  84. }
  85. void DatabaseControl::editingFinished()
  86. {
  87. }
  88. void DatabaseControl::editTimerFired()
  89. {
  90. }
  91. void DatabaseControl::updateData()
  92. {
  93. }
  94. void DatabaseControl::updateWidgets()
  95. {
  96. }
  97. void DatabaseControl::updateWidgetsFromData()
  98. {
  99. }
  100. void DatabaseControl::calculateSummary()
  101. {
  102. if( !m_sqlSummary.isEmpty() )
  103. return;
  104. }
  105. QString
  106. DatabaseControl::sql() const
  107. {
  108. return m_sql;
  109. }
  110. QString
  111. DatabaseControl::summary() const
  112. {
  113. if( !m_sqlSummary.isEmpty() )
  114. return m_sqlSummary;
  115. return m_summary;
  116. }