~john.vrbanac/ubuntu-app-reviews/minicast

« back to all changes in this revision

Viewing changes to provider.h

  • Committer: Aaron Lewis
  • Date: 2012-07-09 08:00:58 UTC
  • Revision ID: the.warl0ck.1989@gmail.com-20120709080058-h0x8cbtuqrza88k4
Fix duplicate file contents

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
};
121
121
 
122
122
#endif // PROVIDER_H
123
 
/* BEGIN_COMMON_COPYRIGHT_HEADER
124
 
 * (c)LGPL2+
125
 
 *
126
 
 * Copyright: 2012 Labo A.L
127
 
 * Authors:
128
 
 *   Aaron Lewis <the.warl0ck.1989@gmail.com>
129
 
 *
130
 
 * This program or library is free software; you can redistribute it
131
 
 * and/or modify it under the terms of the GNU Lesser General Public
132
 
 * License as published by the Free Software Foundation; either
133
 
 * version 2.1 of the License, or (at your option) any later version.
134
 
 *
135
 
 * This library is distributed in the hope that it will be useful,
136
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
137
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
138
 
 * Lesser General Public License for more details.
139
 
 
140
 
 * You should have received a copy of the GNU Lesser General
141
 
 * Public License along with this library; if not, write to the
142
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
143
 
 * Boston, MA 02110-1301 USA
144
 
 *
145
 
 * END_COMMON_COPYRIGHT_HEADER */
146
 
#ifndef PROVIDER_H
147
 
#define PROVIDER_H
148
 
 
149
 
#include <QObject>
150
 
#include <QNetworkAccessManager>
151
 
#include <QNetworkReply>
152
 
#include <QNetworkRequest>
153
 
#include <QStandardItem>
154
 
#include <QDomDocument>
155
 
#include <QDebug>
156
 
#include <QStandardItemModel>
157
 
#include <QIcon>
158
 
#include <QWebPage>
159
 
#include <QWebFrame>
160
 
#include <QWebElement>
161
 
#include <QWebElementCollection>
162
 
 
163
 
#define OFFSET_TRANSCRIPT 1
164
 
 
165
 
class ProviderItem: public QStandardItem
166
 
{
167
 
public:
168
 
    ProviderItem (const QString & url, const QString & name,
169
 
                  const QString & icon, const QString & subtitle = QString ())
170
 
    {
171
 
        setText(name);
172
 
        setIcon(QIcon(icon));
173
 
        setData(url, Qt::UserRole);
174
 
 
175
 
        if ( ! subtitle.isEmpty() )
176
 
            setData(subtitle, Qt::UserRole + OFFSET_TRANSCRIPT);
177
 
    }
178
 
 
179
 
};
180
 
 
181
 
class Provider: public QObject
182
 
{
183
 
    Q_OBJECT
184
 
public:
185
 
    enum PlayOptions {
186
 
        None,
187
 
        HasTranscipts
188
 
    };
189
 
 
190
 
    explicit Provider(QStandardItemModel *model, QObject *parent = 0);
191
 
    ~Provider();
192
 
 
193
 
    /*!
194
 
        \brief start loading of network resources
195
 
    */
196
 
    virtual void start() {}
197
 
 
198
 
protected:
199
 
    QStandardItemModel *m_model;
200
 
    QNetworkAccessManager *m_nam;
201
 
    QNetworkReply *m_reply;
202
 
    QString m_text, m_icon;
203
 
    PlayOptions m_playOptions;
204
 
 
205
 
    void addItem (const QString & icon, const QString & url,
206
 
                  const QString & name, const QString & subtitle = QString());
207
 
    
208
 
signals:
209
 
    /*! all resources loaded */
210
 
    void loaded ();
211
 
 
212
 
public slots:
213
 
 
214
 
private slots:
215
 
    virtual void finished (QNetworkReply *reply) { Q_UNUSED (reply) }
216
 
 
217
 
};
218
 
 
219
 
class TedProvider: public Provider
220
 
{
221
 
    Q_OBJECT
222
 
public:
223
 
    explicit TedProvider (QStandardItemModel *model, QObject *parent = 0);
224
 
    ~TedProvider();
225
 
    void start();
226
 
private slots:
227
 
    void finished (QNetworkReply *reply);
228
 
};
229
 
 
230
 
class SciAmericanProvider: public Provider
231
 
{
232
 
    Q_OBJECT
233
 
public:
234
 
    explicit SciAmericanProvider (QStandardItemModel *model, QObject *parent = 0);
235
 
    ~SciAmericanProvider();
236
 
    void start();
237
 
private slots:
238
 
    void fini (bool ok);
239
 
private:
240
 
    QWebPage page;
241
 
    QMap<QString,QStandardItem*> mapping;
242
 
};
243
 
 
244
 
#endif // PROVIDER_H