/src/libtomahawk/infosystem/InfoSystemCache.h

http://github.com/tomahawk-player/tomahawk · C Header · 79 lines · 38 code · 18 blank · 23 comment · 0 complexity · c4fe777060575537e9fe6a349ebbe5e8 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. *
  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. #ifndef TOMAHAWK_INFOSYSTEMCACHE_H
  20. #define TOMAHAWK_INFOSYSTEMCACHE_H
  21. #include <QCache>
  22. #include <QDateTime>
  23. #include <QObject>
  24. #include <QtDebug>
  25. #include <QTimer>
  26. #include "InfoSystem.h"
  27. namespace Tomahawk
  28. {
  29. namespace InfoSystem
  30. {
  31. class DLLEXPORT InfoSystemCache : public QObject
  32. {
  33. Q_OBJECT
  34. public:
  35. InfoSystemCache( QObject *parent = 0 );
  36. virtual ~InfoSystemCache();
  37. signals:
  38. void info( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
  39. public slots:
  40. void getCachedInfoSlot( Tomahawk::InfoSystem::InfoStringHash criteria, qint64 newMaxAge, Tomahawk::InfoSystem::InfoRequestData requestData );
  41. void updateCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output );
  42. private slots:
  43. void pruneTimerFired();
  44. private:
  45. /**
  46. * Version number of the infosystem cache.
  47. * If you change existing cached data,
  48. * increase this number.
  49. */
  50. static const int s_infosystemCacheVersion;
  51. void notInCache( QObject *receiver, Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
  52. const QString criteriaMd5( const Tomahawk::InfoSystem::InfoStringHash &criteria, Tomahawk::InfoSystem::InfoType type = Tomahawk::InfoSystem::InfoNoInfo ) const;
  53. QString m_cacheBaseDir;
  54. QHash< InfoType, QHash< QString, QString > > m_fileLocationCache;
  55. QTimer m_pruneTimer;
  56. QCache< QString, QVariant > m_dataCache;
  57. };
  58. } //namespace InfoSystem
  59. } //namespace Tomahawk
  60. Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoSystemCache* )
  61. #endif //TOMAHAWK_INFOSYSTEMCACHE_H