QtTvDB 0.3.0

qttvdb.h

Go to the documentation of this file.
00001 /* This file is part of QtTvDB
00002  *
00003  * Copyright (C) 2009-2011 Corentin Chary <corentin.chary@gmail.com>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef QTTVDB_H
00022 #define QTTVDB_H
00023 
00024 #include "qttvdb_export.h"
00025 
00026 #include <QtCore/QObject>
00027 #include <QtCore/QStringList>
00028 #include <QtCore/QUrl>
00029 #include <QtCore/QDateTime>
00030 #include <QtXml/QDomNode>
00031 #include <QtCore/QVariant>
00032 #include <QtCore/QPair>
00033 
00034 #define TVDB_PROPERTY(type_, name_, getter_, setter_)                   \
00035 private:                                                                \
00036   type_ name_##_;                                                       \
00037 public:                                                                 \
00038   inline type_ & getter_() {                                            \
00039       return name_##_;                                                  \
00040   }                                                                     \
00041   inline type_ const & getter_() const {                                \
00042       return name_##_;                                                  \
00043   }                                                                     \
00044   inline void setter_(type_ const & name_##__) {                        \
00045       name_##_ = name_##__;                                             \
00046       emit name_##Changed();                                            \
00047   }
00048 
00049 namespace QtTvDB {
00050 
00051    class QTTVDB_EXPORT Mirrors : public QObject {
00052         Q_OBJECT
00053 
00054         TVDB_PROPERTY(QString, key, key, setKey);
00055         TVDB_PROPERTY(QList<QUrl>, xmlMirrors, xmlMirrors, setXmlMirrors);
00056         TVDB_PROPERTY(QList<QUrl>, bannerMirrors, bannerMirrors, setBannerMirrors);
00057         TVDB_PROPERTY(QList<QUrl>, zipMirrors, zipMirrors, setZipMirrors);
00058         TVDB_PROPERTY(QStringList, languages, languages, setLanguages);
00059 
00060         Q_PROPERTY(QString key READ key WRITE setKey NOTIFY keyChanged);
00061         Q_PROPERTY(QList<QUrl> xmlMirrors READ xmlMirrors WRITE setXmlMirrors NOTIFY xmlMirrorsChanged);
00062         Q_PROPERTY(QList<QUrl> bannerMirrors READ bannerMirrors WRITE setBannerMirrors NOTIFY bannerMirrorsChanged);
00063         Q_PROPERTY(QList<QUrl> zipMirrors READ zipMirrors WRITE setZipMirrors NOTIFY zipMirrorsChanged);
00064         Q_PROPERTY(QStringList languages READ languages WRITE setLanguages NOTIFY languagesChanged);
00065 
00066     signals:
00067         void keyChanged();
00068         void xmlMirrorsChanged();
00069         void bannerMirrorsChanged();
00070         void zipMirrorsChanged();
00071         void languagesChanged();
00072 
00073     public:
00074         Mirrors(QObject * parent = NULL);
00075         Mirrors(const QString & key, QObject *parent = NULL);
00076         ~Mirrors();
00077 
00078         enum Mask {
00079           XML = 1,
00080           BANNER = 2,
00081           ZIP = 4
00082         };
00083 
00084         QUrl mirrorsUrl();
00085         QUrl languagesUrl();
00086         QUrl serverTimeUrl();
00087         QUrl searchShowUrl(const QString & showName, const QString & language = QString());
00088         QUrl showUrl(qint64 showId);
00089         QUrl episodeUrl(qint64 episodeId);
00090         QUrl showAndEpisodesUrl(qint64 showId, const QString & language = QString());
00091         QUrl showAndEpisodesUrlZip(qint64 showId, const QString & language);
00092         QUrl updatesUrl(const QString & period);
00093         QUrl updatedShowsUrl(const QDateTime & period);
00094         QUrl updatedEpisodesUrl(const QDateTime & period);
00095         QUrl bannersUrl(qint64 showId);
00096         QUrl bannerUrl(const QString & path);
00097         int languageId(const QString & l);
00098         QString languageById(int id);
00099         QString languageNameById(int id);
00100         QString languageName(const QString & l);
00101         static QList< QPair < Mask, QUrl > > parseMirrors(const QString & xml);
00102         static QList< QPair < Mask, QUrl > > parseMirrors(const QDomNode & node);
00103         QUrl randomMirror(const QList<QUrl> & mirrors, bool key = false,
00104                           const QString & postfix = QString(), bool api = true);
00105     private:
00106         void init();
00107         QMap < QString, QPair < int, QString > > languagesDb_;
00108         QMap < int, QString > languagesById_;
00109     };
00110 
00111     class QTTVDB_EXPORT Episode : public QObject {
00112         Q_OBJECT
00113 
00114 
00115         TVDB_PROPERTY(qint64, id, id, setId);
00116         TVDB_PROPERTY(qint64, showId, showId, setShowId);
00117         TVDB_PROPERTY(qint64, seasonId, seasonId, setSeasonId);
00118         TVDB_PROPERTY(QString, name, name, setName);
00119         TVDB_PROPERTY(QString, overview, overview, setOverview);
00120         TVDB_PROPERTY(int, season, season, setSeason);
00121         TVDB_PROPERTY(int, episode, episode, setEpisode);
00122         TVDB_PROPERTY(QString, director, director, setDirector);
00123         TVDB_PROPERTY(QStringList, guestStars, guestStars, setGuestStars);
00124         TVDB_PROPERTY(QString, language, language, setLanguage);
00125         TVDB_PROPERTY(QString, productionCode, productionCode, setProductionCode);
00126         TVDB_PROPERTY(QString, rating, rating, setRating);
00127         TVDB_PROPERTY(QString, writer, writer, setWriter);
00128         TVDB_PROPERTY(QDateTime, firstAired, firstAired, setFirstAired);
00129         TVDB_PROPERTY(QString, dvdChapter, dvdChapter, setDvdChapter);
00130         TVDB_PROPERTY(QString, dvdDiscId, dvdDiscId, setDvdDiscId);
00131         TVDB_PROPERTY(QString, dvdEpisodeNumber, dvdEpisodeNumber, setDvdEpisodeNumber);
00132         TVDB_PROPERTY(QString, dvdSeason, dvdSeason, setDvdSeason);
00133         TVDB_PROPERTY(QString, image, image, setImage);
00134         TVDB_PROPERTY(QString, airsAfterSeason, airsAfterSeason, setAirsAfterSeason);
00135         TVDB_PROPERTY(QString, airsBeforeSeason, airsBeforeSeason, setAirsBeforeSeason);
00136         TVDB_PROPERTY(QString, airsBeforeEpisode, airsBeforeEpisode, setAirsBeforeEpisode);
00137         TVDB_PROPERTY(int, combinedEpisode, combinedEpisode, setCombinedEpisode);
00138         TVDB_PROPERTY(int, combinedSeason, combinedSeason, setCombinedSeason);
00139         TVDB_PROPERTY(int, absoluteNumber, absoluteNumber, setAbsoluteNumber);
00140         TVDB_PROPERTY(QString, epImgFlag, epImgFlag, setEpImgFlag);
00141         TVDB_PROPERTY(QString, imdbId, imdbId, setImdbId);
00142         TVDB_PROPERTY(QDateTime, lastUpdated, lastUpdated, setLastUpdated);
00143 
00144         Q_PROPERTY(qint64 id READ id WRITE setId NOTIFY idChanged);
00145         Q_PROPERTY(qint64 showId READ showId WRITE setShowId NOTIFY showIdChanged);
00146         Q_PROPERTY(qint64 seasonId READ seasonId WRITE setSeasonId NOTIFY seasonIdChanged);
00147         Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged);
00148         Q_PROPERTY(QString overview READ overview WRITE setOverview NOTIFY overviewChanged);
00149         Q_PROPERTY(int season READ season WRITE setSeason NOTIFY seasonChanged);
00150         Q_PROPERTY(int episode READ episode WRITE setEpisode NOTIFY episodeChanged);
00151         Q_PROPERTY(QString director READ director WRITE setDirector NOTIFY directorChanged);
00152         Q_PROPERTY(QStringList guestStars READ guestStars WRITE setGuestStars NOTIFY guestStarsChanged);
00153         Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged);
00154         Q_PROPERTY(QString productionCode READ productionCode WRITE setProductionCode NOTIFY productionCodeChanged);
00155         Q_PROPERTY(QString rating READ rating WRITE setRating NOTIFY ratingChanged);
00156         Q_PROPERTY(QString writer READ writer WRITE setWriter NOTIFY writerChanged);
00157         Q_PROPERTY(QDateTime firstAired READ firstAired WRITE setFirstAired NOTIFY firstAiredChanged);
00158         Q_PROPERTY(QString dvdChapter READ dvdChapter WRITE setDvdChapter NOTIFY dvdChapterChanged);
00159         Q_PROPERTY(QString dvdDiscId READ dvdDiscId WRITE setDvdDiscId NOTIFY dvdDiscIdChanged);
00160         Q_PROPERTY(QString dvdEpisodeNumber READ dvdEpisodeNumber WRITE setDvdEpisodeNumber NOTIFY dvdEpisodeNumberChanged);
00161         Q_PROPERTY(QString dvdSeason READ dvdSeason WRITE setDvdSeason NOTIFY dvdSeasonChanged);
00162         Q_PROPERTY(QString image READ image WRITE setImage NOTIFY imageChanged);
00163         Q_PROPERTY(QString airsAfterSeason READ airsAfterSeason WRITE setAirsAfterSeason NOTIFY airsAfterSeasonChanged);
00164         Q_PROPERTY(QString airsBeforeSeason READ airsBeforeSeason WRITE setAirsBeforeSeason NOTIFY airsBeforeSeasonChanged);
00165         Q_PROPERTY(QString airsBeforeEpisode READ airsBeforeEpisode WRITE setAirsBeforeEpisode NOTIFY airsBeforeEpisodeChanged);
00166         Q_PROPERTY(int combinedEpisode READ combinedEpisode WRITE setCombinedEpisode NOTIFY combinedEpisodeChanged);
00167         Q_PROPERTY(int combinedSeason READ combinedSeason WRITE setCombinedSeason NOTIFY combinedSeasonChanged);
00168         Q_PROPERTY(int absoluteNumber READ absoluteNumber WRITE setAbsoluteNumber NOTIFY absoluteNumberChanged);
00169         Q_PROPERTY(QString epImgFlag READ epImgFlag WRITE setEpImgFlag NOTIFY epImgFlagChanged);
00170         Q_PROPERTY(QString imdbId READ imdbId WRITE setImdbId NOTIFY imdbIdChanged);
00171         Q_PROPERTY(QDateTime lastUpdated READ lastUpdated WRITE setLastUpdated NOTIFY lastUpdatedChanged);
00172 
00173     signals:
00174         void idChanged();
00175         void showIdChanged();
00176         void seasonIdChanged();
00177         void nameChanged();
00178         void overviewChanged();
00179         void seasonChanged();
00180         void episodeChanged();
00181         void directorChanged();
00182         void guestStarsChanged();
00183         void languageChanged();
00184         void productionCodeChanged();
00185         void ratingChanged();
00186         void writerChanged();
00187         void firstAiredChanged();
00188         void dvdChapterChanged();
00189         void dvdDiscIdChanged();
00190         void dvdEpisodeNumberChanged();
00191         void dvdSeasonChanged();
00192         void imageChanged();
00193         void airsAfterSeasonChanged();
00194         void airsBeforeSeasonChanged();
00195         void airsBeforeEpisodeChanged();
00196         void combinedEpisodeChanged();
00197         void combinedSeasonChanged();
00198         void absoluteNumberChanged();
00199         void epImgFlagChanged();
00200         void imdbIdChanged();
00201         void lastUpdatedChanged();
00202 
00203     public:
00204         Episode(QObject *parent = NULL);
00205         Episode(const QString & xml, QObject *parent = NULL);
00206         Episode(const QDomNode & node, QObject *parent = NULL);
00207         ~Episode();
00208 
00209         bool isNull();
00210 
00211         static QList< Episode * > parseEpisodes(const QString & xml);
00212         static QList< Episode * > parseEpisodes(const QDomNode & node);
00213 
00214     private:
00215         void init();
00216         void init(const QDomNode &node);
00217     };
00218 
00219     class QTTVDB_EXPORT Show : public QObject {
00220         Q_OBJECT
00221 
00222 
00223         TVDB_PROPERTY(qint64, id, id, setId);
00224         TVDB_PROPERTY(QString, name, name, setName);
00225         TVDB_PROPERTY(QString, overview, overview, setOverview);
00226         TVDB_PROPERTY(QStringList, genre, genre, setGenre);
00227         TVDB_PROPERTY(QStringList, actors, actors, setActors);
00228         TVDB_PROPERTY(QString, network, network, setNetwork);
00229         TVDB_PROPERTY(QString, contentRating, contentRating, setContentRating);
00230         TVDB_PROPERTY(QString, rating, rating, setRating);
00231         TVDB_PROPERTY(QTime, runtime, runtime, setRuntime);
00232         TVDB_PROPERTY(QString, status, status, setStatus);
00233         TVDB_PROPERTY(QString, language, language, setLanguage);
00234         TVDB_PROPERTY(QDateTime, firstAired, firstAired, setFirstAired);
00235         TVDB_PROPERTY(QString, airsDay, airsDay, setAirsDay);
00236         TVDB_PROPERTY(QTime, airsTime, airsTime, setAirsTime);
00237         TVDB_PROPERTY(QString, banner, banner, setBanner);
00238         TVDB_PROPERTY(QString, poster, poster, setPoster);
00239         TVDB_PROPERTY(QString, fanArt, fanArt, setFanArt);
00240         TVDB_PROPERTY(QString, imdbId, imdbId, setImdbId);
00241         TVDB_PROPERTY(QString, seriesId, seriesId, setSeriesId);
00242         TVDB_PROPERTY(QString, zap2ItId, zap2ItId, setZap2ItId);
00243         TVDB_PROPERTY(QDateTime, lastUpdated, lastUpdated, setLastUpdated);
00244 
00245         Q_PROPERTY(qint64 id READ id WRITE setId NOTIFY idChanged);
00246         Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged);
00247         Q_PROPERTY(QString overview READ overview WRITE setOverview NOTIFY overviewChanged);
00248         Q_PROPERTY(QStringList genre READ genre WRITE setGenre NOTIFY genreChanged);
00249         Q_PROPERTY(QStringList actors READ actors WRITE setActors NOTIFY actorsChanged);
00250         Q_PROPERTY(QString network READ network WRITE setNetwork NOTIFY networkChanged);
00251         Q_PROPERTY(QString contentRating READ contentRating WRITE setContentRating NOTIFY contentRatingChanged);
00252         Q_PROPERTY(QString rating READ rating WRITE setRating NOTIFY ratingChanged);
00253         Q_PROPERTY(QTime runtime READ runtime WRITE setRuntime NOTIFY runtimeChanged);
00254         Q_PROPERTY(QString status READ status WRITE setStatus NOTIFY statusChanged);
00255         Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged);
00256         Q_PROPERTY(QDateTime firstAired READ firstAired WRITE setFirstAired NOTIFY firstAiredChanged);
00257         Q_PROPERTY(QString airsDay READ airsDay WRITE setAirsDay NOTIFY airsDayChanged);
00258         Q_PROPERTY(QTime airsTime READ airsTime WRITE setAirsTime NOTIFY airsTimeChanged);
00259         Q_PROPERTY(QString banner READ banner WRITE setBanner NOTIFY bannerChanged);
00260         Q_PROPERTY(QString poster READ poster WRITE setPoster NOTIFY posterChanged);
00261         Q_PROPERTY(QString fanArt READ fanArt WRITE setFanArt NOTIFY fanArtChanged);
00262         Q_PROPERTY(QString imdbId READ imdbId WRITE setImdbId NOTIFY imdbIdChanged);
00263         Q_PROPERTY(QString seriesId READ seriesId WRITE setSeriesId NOTIFY seriesIdChanged);
00264         Q_PROPERTY(QString zap2ItId READ zap2ItId WRITE setZap2ItId NOTIFY zap2ItIdChanged);
00265         Q_PROPERTY(QDateTime lastUpdated READ lastUpdated WRITE setLastUpdated NOTIFY lastUpdatedChanged);
00266 
00267     signals:
00268         void idChanged();
00269         void nameChanged();
00270         void overviewChanged();
00271         void genreChanged();
00272         void actorsChanged();
00273         void networkChanged();
00274         void contentRatingChanged();
00275         void ratingChanged();
00276         void runtimeChanged();
00277         void statusChanged();
00278         void languageChanged();
00279         void firstAiredChanged();
00280         void airsDayChanged();
00281         void airsTimeChanged();
00282         void bannerChanged();
00283         void posterChanged();
00284         void fanArtChanged();
00285         void imdbIdChanged();
00286         void seriesIdChanged();
00287         void zap2ItIdChanged();
00288         void lastUpdatedChanged();
00289 
00290     public:
00291         Show(QObject *parent = NULL);
00292         Show(const QString & xml, QObject *parent = NULL);
00293         Show(const QDomNode & node, QObject *parent = NULL);
00294         ~Show();
00295 
00296         bool isNull();
00297 
00298         static QList< Show * > parseShows(const QString & xml);
00299         static QList< Show * > parseShows(const QDomNode & node);
00300 
00301     private:
00302         void init();
00303         void init(const QDomNode &node);
00304     };
00305 
00306     class QTTVDB_EXPORT Banner : public QObject {
00307         Q_OBJECT
00308 
00309 
00310         TVDB_PROPERTY(qint64, id, id, setId);
00311         TVDB_PROPERTY(QString, path, path, setPath);
00312         TVDB_PROPERTY(QString, type, type, setType);
00313         TVDB_PROPERTY(QString, type2, type2, setType2);
00314         TVDB_PROPERTY(QString, language, language, setLanguage);
00315         TVDB_PROPERTY(QString, season, season, setSeason);
00316 
00317         Q_PROPERTY(qint64 id READ id WRITE setId NOTIFY idChanged);
00318         Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged);
00319         Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged);
00320         Q_PROPERTY(QString type2 READ type2 WRITE setType2 NOTIFY type2Changed);
00321         Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged);
00322         Q_PROPERTY(QString season READ season WRITE setSeason NOTIFY seasonChanged);
00323 
00324     signals:
00325         void idChanged();
00326         void pathChanged();
00327         void typeChanged();
00328         void type2Changed();
00329         void languageChanged();
00330         void seasonChanged();
00331 
00332     public:
00333         Banner(QObject *parent = NULL);
00334         Banner(const QString & xml, QObject *parent = NULL);
00335         Banner(const QDomNode & node, QObject *parent = NULL);
00336         ~Banner();
00337 
00338         bool isNull();
00339 
00340         static QList< Banner * > parseBanners(const QString & xml);
00341         static QList< Banner * > parseBanners(const QDomNode & node);
00342 
00343     private:
00344         void init();
00345         void init(const QDomNode &node);
00346     };
00347 };
00348 
00349 Q_DECLARE_METATYPE(QtTvDB::Mirrors *);
00350 Q_DECLARE_METATYPE(QtTvDB::Episode *);
00351 Q_DECLARE_METATYPE(QtTvDB::Show *);
00352 Q_DECLARE_METATYPE(QtTvDB::Banner *);
00353 
00354 #endif // QTTVDB_H