/src/libtomahawk/database/DatabaseImpl.h

http://github.com/tomahawk-player/tomahawk · C Header · 120 lines · 74 code · 27 blank · 19 comment · 0 complexity · 54d15f46d61c56e66f4bbab8f1543823 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 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5. * Copyright 2014, Teo Mrnjavac <teo@kde.org>
  6. *
  7. * Tomahawk is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tomahawk is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef DATABASEIMPL_H
  21. #define DATABASEIMPL_H
  22. #include <QObject>
  23. #include <QList>
  24. #include <QMutex>
  25. #include <QPair>
  26. #include <QVariant>
  27. #include <QVariantMap>
  28. #include <QSqlDatabase>
  29. #include <QSqlError>
  30. #include <QSqlQuery>
  31. #include <QHash>
  32. #include <QThread>
  33. #include "DllMacro.h"
  34. #include "TomahawkSqlQuery.h"
  35. #include "Typedefs.h"
  36. namespace Tomahawk
  37. {
  38. class Database;
  39. class DatabaseFuzzyIndex;
  40. class DLLEXPORT DatabaseImpl : public QObject
  41. {
  42. Q_OBJECT
  43. friend class DatabaseFuzzyIndex;
  44. friend class DatabaseCommand_UpdateSearchIndex;
  45. public:
  46. DatabaseImpl( const QString& dbname );
  47. ~DatabaseImpl();
  48. DatabaseImpl* clone() const;
  49. TomahawkSqlQuery newquery();
  50. QSqlDatabase& database();
  51. int artistId( const QString& name_orig, bool autoCreate ); //also for composers!
  52. int trackId( int artistid, const QString& name_orig, bool autoCreate );
  53. int albumId( int artistid, const QString& name_orig, bool autoCreate );
  54. QList< QPair<int, float> > search( const Tomahawk::query_ptr& query, uint limit = 0 );
  55. QList< QPair<int, float> > searchAlbum( const Tomahawk::query_ptr& query, uint limit = 0 );
  56. QList< int > getTrackFids( int tid );
  57. static QString sortname( const QString& str, bool replaceArticle = false );
  58. QVariantMap artist( int id );
  59. QVariantMap album( int id );
  60. QVariantMap track( int id );
  61. Tomahawk::result_ptr file( int fid );
  62. Tomahawk::result_ptr resultFromHint( const Tomahawk::query_ptr& query );
  63. static bool scorepairSorter( const QPair<int,float>& left, const QPair<int,float>& right )
  64. {
  65. return left.second > right.second;
  66. }
  67. QString dbid() const { return m_dbid; }
  68. void loadIndex();
  69. signals:
  70. void indexStarted();
  71. void indexReady();
  72. void schemaUpdateStarted();
  73. void schemaUpdateStatus( const QString& message );
  74. void schemaUpdateDone();
  75. private:
  76. DatabaseImpl( const QString& dbname, bool internal );
  77. void setFuzzyIndex( DatabaseFuzzyIndex* fi ) { m_fuzzyIndex = fi; }
  78. void setDatabaseID( const QString& dbid ) { m_dbid = dbid; }
  79. void init();
  80. bool openDatabase( const QString& dbname, bool checkSchema = true );
  81. bool updateSchema( int oldVersion );
  82. void dumpDatabase();
  83. QString cleanSql( const QString& sql );
  84. bool m_ready;
  85. QSqlDatabase m_db;
  86. QString m_lastart, m_lastalb, m_lasttrk;
  87. int m_lastartid, m_lastalbid, m_lasttrkid;
  88. QString m_dbid;
  89. Tomahawk::DatabaseFuzzyIndex* m_fuzzyIndex;
  90. mutable QMutex m_mutex;
  91. };
  92. }
  93. #endif // DATABASEIMPL_H