| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org> * |
| 3 |
* Copyright (c) 2009 Bart Cerneels <bart.cerneels@kde.org> * |
| 4 |
* * |
| 5 |
* This program is free software; you can redistribute it and/or modify it under * |
| 6 |
* the terms of the GNU General Public License as published by the Free Software * |
| 7 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 8 |
* version. * |
| 9 |
* * |
| 10 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 11 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 12 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 13 |
* * |
| 14 |
* You should have received a copy of the GNU General Public License along with * |
| 15 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 16 |
****************************************************************************************/ |
| 17 |
|
| 18 |
#ifndef OPMLPARSER_H |
| 19 |
#define OPMLPARSER_H |
| 20 |
|
| 21 |
#include "amarok_export.h" |
| 22 |
#include "OpmlOutline.h" |
| 23 |
|
| 24 |
#include <threadweaver/Job.h> |
| 25 |
|
| 26 |
#include <QDomElement> |
| 27 |
#include <QMap> |
| 28 |
#include <QString> |
| 29 |
#include <QStringList> |
| 30 |
|
| 31 |
/** |
| 32 |
* Parser for OPML files. |
| 33 |
*/ |
| 34 |
class AMAROK_EXPORT OpmlParser : public ThreadWeaver::Job |
| 35 |
{ |
| 36 |
Q_OBJECT |
| 37 |
|
| 38 |
public: |
| 39 |
static const QString OPML_MIME; |
| 40 |
/** |
| 41 |
* Constructor |
| 42 |
* @param fileName The file to parse |
| 43 |
* @return Pointer to new object |
| 44 |
*/ |
| 45 |
OpmlParser( const QString &fileName ); |
| 46 |
|
| 47 |
/** |
| 48 |
* The function that starts the actual work. Inherited from ThreadWeaver::Job |
| 49 |
* Note the work is performed in a separate thread |
| 50 |
* @return Returns true on success and false on failure |
| 51 |
*/ |
| 52 |
void run(); |
| 53 |
|
| 54 |
/** |
| 55 |
* Destructor |
| 56 |
* @return none |
| 57 |
*/ |
| 58 |
~OpmlParser(); |
| 59 |
|
| 60 |
/** |
| 61 |
* Reads, and starts parsing, file. Should not be used directly. |
| 62 |
* @param filename The file to read |
| 63 |
*/ |
| 64 |
void readConfigFile( const QString &filename ); |
| 65 |
|
| 66 |
/** |
| 67 |
* Get the result of the parsing as a list of OpmlOutlines. |
| 68 |
* This list contains only root outlines that can be found in the <body> of the OPML. |
| 69 |
* The rest are children of these root items. |
| 70 |
*/ |
| 71 |
QList<OpmlOutline *> results() const { return m_rootOutlines; } |
| 72 |
|
| 73 |
signals: |
| 74 |
/** |
| 75 |
* Signal emmited when parsing is complete. |
| 76 |
*/ |
| 77 |
void doneParsing(); |
| 78 |
|
| 79 |
/** |
| 80 |
* Emitted when a new outline item is available. |
| 81 |
* Emitted after the attributes have been read but before any of the children is |
| 82 |
* available. The |
| 83 |
* Each child will be reported seperatly in an element. |
| 84 |
*/ |
| 85 |
void outlineParsed( OpmlOutline *outline ); |
| 86 |
|
| 87 |
private: |
| 88 |
QList<OpmlOutline *> m_rootOutlines; |
| 89 |
QString m_sFileName; |
| 90 |
|
| 91 |
void parseOpmlBody( const QDomElement &e ); |
| 92 |
|
| 93 |
OpmlOutline *parseOutlineElement( const QDomElement &e ); |
| 94 |
}; |
| 95 |
|
| 96 |
#endif |