PageRenderTime 93ms CodeModel.GetById 40ms app.highlight 13ms RepoModel.GetById 37ms app.codeStats 0ms

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