PageRenderTime 208ms CodeModel.GetById 40ms app.highlight 62ms RepoModel.GetById 99ms app.codeStats 1ms

/src/libtomahawk/utils/XspfLoader.h

http://github.com/tomahawk-player/tomahawk
C Header | 86 lines | 46 code | 15 blank | 25 comment | 0 complexity | c7bfef13a6ee493c944b04bac5ec3edc 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 2011-2012, Leo Franchi            <lfranchi@kde.org>
 5 *   Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
 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
21#pragma once
22#ifndef XSPFLOADER_H
23#define XSPFLOADER_H
24
25#include "DllMacro.h"
26#include "Playlist.h"
27#include "Typedefs.h"
28
29#include <QFile>
30
31/**
32 * @brief Fetches and parses an XSPF document from a QFile or QUrl.
33 */
34class DLLEXPORT XSPFLoader : public QObject
35{
36Q_OBJECT
37
38public:
39    enum XSPFErrorCode { ParseError, InvalidTrackError, FetchError };
40    explicit XSPFLoader( bool autoCreate = true, bool autoUpdate = false, QObject* parent = 0, const QString& guid = QString() );
41
42    virtual ~XSPFLoader();
43    QList< Tomahawk::query_ptr > entries() const;
44    QString title() const;
45
46    /**
47     * Get the playlist for the most recent parsed XSPF url.
48     */
49    Tomahawk::playlist_ptr getPlaylistForRecentUrl();
50    void setOverrideTitle( const QString& newTitle );
51    void setAutoResolveTracks( bool autoResolve );
52    void setAutoDelete( bool autoDelete );
53    void setErrorTitle( const QString& error );
54
55    static QString errorToString( XSPFErrorCode error );
56
57signals:
58    void error( XSPFLoader::XSPFErrorCode error );
59    void ok( const Tomahawk::playlist_ptr& );
60    void track( const Tomahawk::query_ptr& track );
61    void tracks( const QList< Tomahawk::query_ptr > tracks );
62
63public slots:
64    void load( const QUrl& url );
65    void load( QFile& file );
66
67private slots:
68    void networkLoadFinished();
69    void networkError( QNetworkReply::NetworkError e );
70
71private:
72    void reportError();
73    void gotBody();
74
75    bool m_autoCreate, m_autoUpdate, m_autoResolve, m_autoDelete;
76    QString m_guid;
77    QString m_NS,m_overrideTitle;
78    QList< Tomahawk::query_ptr > m_entries;
79    QString m_title, m_info, m_creator, m_errorTitle;
80
81    QUrl m_url;
82    QByteArray m_body;
83    Tomahawk::playlist_ptr m_playlist;
84};
85
86#endif // XSPFLOADER_H