PageRenderTime 31ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/src/libtomahawk/DropJob.h

http://github.com/tomahawk-player/tomahawk
C Header | 169 lines | 86 code | 30 blank | 53 comment | 0 complexity | fcf2fe394f5a93f7b8d6c935fe2c58a5 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2011, Michael Zanetti <mzanetti@kde.org>
  4. * Copyright 2011, Leo Franchi <lfranchi@kde.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 DROPJOB_H
  20. #define DROPJOB_H
  21. #include "Album.h"
  22. #include "DllMacro.h"
  23. #include "Typedefs.h"
  24. #include <QObject>
  25. #include <QStringList>
  26. #include <QMimeData>
  27. namespace Tomahawk {
  28. class DropJobNotifier;
  29. }
  30. class DLLEXPORT DropJob : public QObject
  31. {
  32. Q_OBJECT
  33. public:
  34. explicit DropJob( QObject *parent = 0 );
  35. ~DropJob();
  36. /**
  37. * QMimeData helpers
  38. *
  39. * Call this to parse the tracks in a QMimeData object to query_ptrs. This will parse internal tomahawk
  40. * data as well as all other formats supported (spotify, etc).
  41. *
  42. * Connect to tracks( QList< query_ptr> ); for the extracted tracks.
  43. */
  44. enum DropType {
  45. None = 0x00,
  46. Playlist = 0x01,
  47. Track = 0x02,
  48. Album = 0x04,
  49. Artist = 0x08,
  50. All = 0xFF
  51. };
  52. Q_DECLARE_FLAGS(DropTypes, DropType)
  53. enum DropAction {
  54. Default = 0,
  55. Append,
  56. Create,
  57. Move
  58. };
  59. /**
  60. * Returns if the caller should accept this mimetype.
  61. *
  62. * \param data The mimetype object to check
  63. * \param type The type of drop content to accept
  64. * \param action What action is requested from the content, if not all data types support all actions
  65. */
  66. static bool acceptsMimeData( const QMimeData* data, DropJob::DropTypes type = All, DropAction action = Append );
  67. /**
  68. * Return if the drop is primarily of the given type. Does not auto-convert (e.g. if the drop is of type playlist,
  69. * even thougha playlist can be converted into tracks, this will return true only for the Playlist drop type).
  70. *
  71. * TODO Only implemented for Playlist atm. Extend when you need it.
  72. */
  73. static bool isDropType( DropJob::DropType desired, const QMimeData* data );
  74. static QStringList mimeTypes();
  75. /**
  76. * Set the drop types that should be extracted from this drop
  77. */
  78. void setDropTypes( DropTypes types );
  79. /**
  80. * Set the action that the drop should do.
  81. *
  82. * For example, if dropping a playlist, Create will create a new playlist
  83. * but Append will generate the raw tracks
  84. */
  85. void setDropAction( DropAction action );
  86. DropTypes dropTypes() const;
  87. DropAction dropAction() const;
  88. /**
  89. * Begin the parsing of the mime data. The resulting tracks are exposed in the various signals
  90. */
  91. void parseMimeData( const QMimeData* data );
  92. void setGetWholeArtists( bool getWholeArtists );
  93. void setGetWholeAlbums( bool getWholeAlbums );
  94. void tracksFromMimeData( const QMimeData* data, bool allowDuplicates = false, bool onlyLocal = false, bool top10 = false );
  95. void handleXspfs( const QString& files );
  96. void handleM3u( const QString& urls );
  97. void handleSpotifyUrls( const QString& urls );
  98. void handleGroovesharkUrls( const QString& urls );
  99. static bool canParseSpotifyPlaylists();
  100. static void setCanParseSpotifyPlaylists( bool parseable );
  101. signals:
  102. /// QMimeData parsing results
  103. void tracks( const QList< Tomahawk::query_ptr >& tracks );
  104. private slots:
  105. void expandedUrls( QStringList );
  106. void informationForUrl( const QString& url, const QSharedPointer<QObject>& information );
  107. void onTracksAdded( const QList<Tomahawk::query_ptr>& );
  108. private:
  109. /// handle parsing mime data
  110. void handleAllUrls( const QString& urls );
  111. void handleTrackUrls( const QString& urls );
  112. QList< Tomahawk::query_ptr > tracksFromQueryList( const QMimeData* d );
  113. QList< Tomahawk::query_ptr > tracksFromResultList( const QMimeData* d );
  114. QList< Tomahawk::query_ptr > tracksFromArtistMetaData( const QMimeData* d );
  115. QList< Tomahawk::query_ptr > tracksFromAlbumMetaData( const QMimeData* d );
  116. void tracksFromMixedData( const QMimeData* d );
  117. QList< Tomahawk::query_ptr > getArtist( const QString& artist, Tomahawk::ModelMode mode = Tomahawk::Mixed );
  118. QList< Tomahawk::query_ptr > getAlbum( const QString& artist, const QString& album );
  119. QList< Tomahawk::query_ptr > getTopTen( const QString& artist );
  120. void removeDuplicates();
  121. void removeRemoteSources();
  122. static bool validateLocalFile( const QString& path, const QString& suffix = QString() );
  123. static bool validateLocalFiles( const QString& paths, const QString& suffix = QString() );
  124. int m_queryCount;
  125. bool m_allowDuplicates;
  126. bool m_onlyLocal;
  127. bool m_getWholeArtists;
  128. bool m_getWholeAlbums;
  129. bool m_top10;
  130. DropTypes m_dropTypes;
  131. DropAction m_dropAction;
  132. QList<Tomahawk::DropJobNotifier*> m_dropJob;
  133. QList< Tomahawk::query_ptr > m_resultList;
  134. QSet< Tomahawk::album_ptr > m_albumsToKeep;
  135. QSet< Tomahawk::artist_ptr > m_artistsToKeep;
  136. static bool s_canParseSpotifyPlaylists;
  137. };
  138. Q_DECLARE_OPERATORS_FOR_FLAGS(DropJob::DropTypes)
  139. #endif // DROPJOB_H