2012-03-09 16:25:49 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GPODDERSYNC_H
|
|
|
|
#define GPODDERSYNC_H
|
|
|
|
|
2012-03-09 17:47:56 +01:00
|
|
|
#include "podcastepisode.h"
|
|
|
|
|
|
|
|
#include <QDateTime>
|
2012-03-09 16:25:49 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QScopedPointer>
|
2012-03-09 17:47:56 +01:00
|
|
|
#include <QSet>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QUrl>
|
2012-03-09 16:25:49 +01:00
|
|
|
|
2012-03-19 22:16:37 +01:00
|
|
|
#include <ApiRequest.h>
|
|
|
|
|
2012-03-09 16:25:49 +01:00
|
|
|
class Application;
|
2012-03-09 17:47:56 +01:00
|
|
|
class Podcast;
|
|
|
|
class PodcastBackend;
|
|
|
|
class PodcastUrlLoader;
|
|
|
|
class PodcastUrlLoaderReply;
|
2012-03-09 16:25:49 +01:00
|
|
|
|
|
|
|
class QNetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
2012-03-09 17:47:56 +01:00
|
|
|
class QTimer;
|
2012-03-09 16:25:49 +01:00
|
|
|
|
|
|
|
class GPodderSync : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
GPodderSync(Application* app, QObject* parent = 0);
|
|
|
|
~GPodderSync();
|
|
|
|
|
|
|
|
static const char* kSettingsGroup;
|
2012-03-09 17:47:56 +01:00
|
|
|
static const int kFlushUpdateQueueDelay;
|
2012-03-10 13:25:58 +01:00
|
|
|
static const int kGetUpdatesInterval;
|
2012-03-09 16:25:49 +01:00
|
|
|
|
|
|
|
static QString DefaultDeviceName();
|
|
|
|
static QString DeviceId();
|
|
|
|
|
|
|
|
bool is_logged_in() const;
|
|
|
|
|
|
|
|
// Tries to login using the given username and password. Also sets the
|
|
|
|
// device name and type on gpodder.net. You do NOT need to deleteLater()
|
|
|
|
// the QNetworkReply returned from this function.
|
|
|
|
// If login succeeds the username and password will be saved in QSettings.
|
|
|
|
QNetworkReply* Login(const QString& username, const QString& password,
|
|
|
|
const QString& device_name);
|
|
|
|
|
|
|
|
// Clears any saved username and password from QSettings.
|
|
|
|
void Logout();
|
|
|
|
|
2012-03-09 17:47:56 +01:00
|
|
|
public slots:
|
|
|
|
void GetUpdatesNow();
|
|
|
|
|
2012-03-09 16:25:49 +01:00
|
|
|
private slots:
|
|
|
|
void ReloadSettings();
|
|
|
|
void LoginFinished(QNetworkReply* reply,
|
|
|
|
const QString& username, const QString& password);
|
|
|
|
|
2012-03-19 22:16:37 +01:00
|
|
|
void DeviceUpdatesFinished(mygpo::DeviceUpdatesPtr reply);
|
|
|
|
void DeviceUpdatesFailed(mygpo::DeviceUpdatesPtr reply);
|
2012-03-09 17:47:56 +01:00
|
|
|
|
|
|
|
void NewPodcastLoaded(PodcastUrlLoaderReply* reply, const QUrl& url,
|
2012-03-19 22:16:37 +01:00
|
|
|
const QList<mygpo::EpisodePtr>& actions);
|
2012-03-09 17:47:56 +01:00
|
|
|
|
2012-03-19 22:16:37 +01:00
|
|
|
void ApplyActions(const QList<mygpo::EpisodePtr>& actions,
|
2012-03-09 17:47:56 +01:00
|
|
|
PodcastEpisodeList* episodes);
|
|
|
|
|
|
|
|
void SubscriptionAdded(const Podcast& podcast);
|
|
|
|
void SubscriptionRemoved(const Podcast& podcast);
|
|
|
|
void FlushUpdateQueue();
|
|
|
|
|
2012-03-19 22:16:37 +01:00
|
|
|
void AddRemoveFinished(mygpo::AddRemoveResultPtr reply,
|
2012-03-09 17:47:56 +01:00
|
|
|
const QList<QUrl>& affected_urls);
|
2012-03-19 22:16:37 +01:00
|
|
|
void AddRemoveFailed(mygpo::AddRemoveResultPtr reply);
|
2012-03-09 17:47:56 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void LoadQueue();
|
|
|
|
void SaveQueue();
|
|
|
|
|
|
|
|
void DoInitialSync();
|
|
|
|
|
2012-03-09 16:25:49 +01:00
|
|
|
private:
|
|
|
|
Application* app_;
|
|
|
|
QNetworkAccessManager* network_;
|
|
|
|
QScopedPointer<mygpo::ApiRequest> api_;
|
|
|
|
|
2012-03-09 17:47:56 +01:00
|
|
|
PodcastBackend* backend_;
|
|
|
|
PodcastUrlLoader* loader_;
|
|
|
|
|
2012-03-09 16:25:49 +01:00
|
|
|
QString username_;
|
|
|
|
QString password_;
|
2012-03-09 17:47:56 +01:00
|
|
|
QDateTime last_successful_get_;
|
2012-03-10 13:25:58 +01:00
|
|
|
QTimer* get_updates_timer_;
|
2012-03-09 17:47:56 +01:00
|
|
|
|
|
|
|
QTimer* flush_queue_timer_;
|
|
|
|
QSet<QUrl> queued_add_subscriptions_;
|
|
|
|
QSet<QUrl> queued_remove_subscriptions_;
|
|
|
|
bool flushing_queue_;
|
2012-03-09 16:25:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GPODDERSYNC_H
|