1 /* This file is part of Clementine.
2    Copyright 2012, David Sansome <me@davidsansome.com>
3    Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
4    Copyright 2014, John Maguire <john.maguire@gmail.com>
5 
6    Clementine is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10 
11    Clementine is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef INTERNET_PODCASTS_PODCAST_H_
21 #define INTERNET_PODCASTS_PODCAST_H_
22 
23 #include "podcastepisode.h"
24 
25 #include <QSharedDataPointer>
26 #include <QSqlQuery>
27 #include <QUrl>
28 #include <QVariantMap>
29 
30 namespace mygpo {
31 class Podcast;
32 }
33 
34 class Podcast {
35  public:
36   Podcast();
37   Podcast(const Podcast& other);
38   ~Podcast();
39 
40   static const QStringList kColumns;
41   static const QString kColumnSpec;
42   static const QString kJoinSpec;
43   static const QString kBindSpec;
44   static const QString kUpdateSpec;
45 
46   void InitFromQuery(const QSqlQuery& query);
47   void InitFromGpo(const mygpo::Podcast* podcast);
48 
49   void BindToQuery(QSqlQuery* query) const;
50 
is_valid()51   bool is_valid() const { return database_id() != -1; }
52 
53   int database_id() const;
54   const QUrl& url() const;
55   const QString& title() const;
56   const QString& description() const;
57   const QString& copyright() const;
58   const QUrl& link() const;
59   const QUrl& image_url_large() const;
60   const QUrl& image_url_small() const;
61   const QString& author() const;
62   const QString& owner_name() const;
63   const QString& owner_email() const;
64   const QDateTime& last_updated() const;
65   const QString& last_update_error() const;
66   const QVariantMap& extra() const;
67   QVariant extra(const QString& key) const;
68 
69   void set_database_id(int v);
70   void set_url(const QUrl& v);
71   void set_title(const QString& v);
72   void set_description(const QString& v);
73   void set_copyright(const QString& v);
74   void set_link(const QUrl& v);
75   void set_image_url_large(const QUrl& v);
76   void set_image_url_small(const QUrl& v);
77   void set_author(const QString& v);
78   void set_owner_name(const QString& v);
79   void set_owner_email(const QString& v);
80   void set_last_updated(const QDateTime& v);
81   void set_last_update_error(const QString& v);
82   void set_extra(const QVariantMap& v);
83   void set_extra(const QString& key, const QVariant& value);
84 
85   // Small images are suitable for 16x16 icons in lists.  Large images are
86   // used in detailed information displays.
ImageUrlLarge()87   const QUrl& ImageUrlLarge() const {
88     return image_url_large().isValid() ? image_url_large() : image_url_small();
89   }
ImageUrlSmall()90   const QUrl& ImageUrlSmall() const {
91     return image_url_small().isValid() ? image_url_small() : image_url_large();
92   }
93 
94   // These are stored in a different database table, and aren't loaded or
95   // persisted by InitFromQuery or BindToQuery.
96   const PodcastEpisodeList& episodes() const;
97   PodcastEpisodeList* mutable_episodes();
98   void set_episodes(const PodcastEpisodeList& v);
99   void add_episode(const PodcastEpisode& episode);
100 
101   Podcast& operator=(const Podcast& other);
102 
103  private:
104   struct Private;
105   QSharedDataPointer<Private> d;
106 };
107 Q_DECLARE_METATYPE(Podcast)
108 
109 typedef QList<Podcast> PodcastList;
110 Q_DECLARE_METATYPE(QList<Podcast>)
111 
112 #endif  // INTERNET_PODCASTS_PODCAST_H_
113