File indexing completed on 2024-05-12 15:31:19
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de> 0004 // 0005 0006 #ifndef BBCPARSER_H 0007 #define BBCPARSER_H 0008 0009 // Marble 0010 #include "AbstractWorkerThread.h" 0011 #include "WeatherData.h" 0012 0013 // Qt 0014 #include <QHash> 0015 #include <QList> 0016 #include <QMutex> 0017 #include <QPointer> 0018 #include <QStack> 0019 #include <QXmlStreamReader> 0020 0021 class QObject; 0022 0023 namespace Marble 0024 { 0025 0026 class BBCWeatherItem; 0027 0028 struct ScheduleEntry 0029 { 0030 QString path; 0031 QPointer<BBCWeatherItem> item; 0032 QString type; 0033 }; 0034 0035 class BBCParser : public AbstractWorkerThread, public QXmlStreamReader 0036 { 0037 Q_OBJECT 0038 public: 0039 ~BBCParser() override; 0040 0041 static BBCParser *instance(); 0042 void scheduleRead( const QString& path, BBCWeatherItem *item, const QString& type ); 0043 0044 protected: 0045 bool workAvailable() override; 0046 void work() override; 0047 0048 Q_SIGNALS: 0049 void parsedFile(); 0050 0051 private: 0052 explicit BBCParser( QObject *parent = nullptr ); 0053 QList<WeatherData> read( QIODevice *device ); 0054 0055 void readUnknownElement(); 0056 void readBBC(); 0057 void readChannel(); 0058 void readItem(); 0059 void readDescription( WeatherData *data ); 0060 void readTitle( WeatherData *data ); 0061 void readPubDate( WeatherData *data ); 0062 0063 QList<WeatherData> m_list; 0064 QStack<ScheduleEntry> m_schedule; 0065 QMutex m_scheduleMutex; 0066 0067 QHash<QString, WeatherData::WeatherCondition> m_dayConditions; 0068 QHash<QString, WeatherData::WeatherCondition> m_nightConditions; 0069 QHash<QString, WeatherData::WindDirection> m_windDirections; 0070 QHash<QString, WeatherData::PressureDevelopment> m_pressureDevelopments; 0071 QHash<QString, WeatherData::Visibility> m_visibilityStates; 0072 QHash<QString, int> m_monthNames; 0073 }; 0074 0075 } // Marble namespace 0076 0077 #endif // BBCPARSER_H