File indexing completed on 2024-04-21 04:47:52
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Bart Cerneels <bart.cerneels@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef OPMLWRITER_H 0018 #define OPMLWRITER_H 0019 0020 #include "OpmlOutline.h" 0021 0022 #include <ThreadWeaver/Job> 0023 0024 #include <QUrl> 0025 #include <QXmlStreamWriter> 0026 0027 class AMAROK_EXPORT OpmlWriter : public QObject, public ThreadWeaver::Job 0028 { 0029 Q_OBJECT 0030 public: 0031 /** OpmlWriter will write the OPML outline objects as XML text. 0032 * @arg rootOutlines the \<body\> of the OPML 0033 * @arg headerData these fields are put in the \<head\> of the OPML 0034 * @arg device QIODevice to write to 0035 * The children of IncludeNodes will not be written. Remove the type="include" attribute 0036 * from the include node to force a save of those child nodes. 0037 */ 0038 OpmlWriter( const QList<OpmlOutline *> &rootOutlines, 0039 const QMap<QString,QString> &headerData, 0040 QIODevice *device ); 0041 0042 void setHeaderData( const QMap<QString,QString> &data ) { m_headerData = data; } 0043 /** 0044 * The function that starts the actual work. Inherited from ThreadWeaver::Job 0045 * Note the work is performed in a separate thread 0046 * @return Returns @c true on success and @c false on failure 0047 */ 0048 void run(ThreadWeaver::JobPointer self = QSharedPointer<ThreadWeaver::Job>(), ThreadWeaver::Thread *thread = nullptr) override; 0049 0050 QIODevice *device() { return m_xmlWriter->device(); } 0051 0052 Q_SIGNALS: 0053 /** 0054 * Signal emitted when writing is complete. 0055 */ 0056 void result( int error ); 0057 0058 /** This signal is emitted when this job is being processed by a thread. */ 0059 void started(ThreadWeaver::JobPointer); 0060 /** This signal is emitted when the job has been finished (no matter if it succeeded or not). */ 0061 void done(ThreadWeaver::JobPointer); 0062 /** This job has failed. 0063 * This signal is emitted when success() returns false after the job is executed. */ 0064 void failed(ThreadWeaver::JobPointer); 0065 0066 private: 0067 void writeOutline( const OpmlOutline *outline ); 0068 QList<OpmlOutline *> m_rootOutlines; 0069 QMap<QString,QString> m_headerData; 0070 0071 QUrl m_fileUrl; 0072 QXmlStreamWriter *m_xmlWriter; 0073 0074 protected: 0075 void defaultBegin(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override; 0076 void defaultEnd(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override; 0077 0078 }; 0079 0080 #endif // OPMLWRITER_H