From 034da1717c205b35397cdf3f0def0eddd50b30ae Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sat, 10 Mar 2012 12:25:58 +0000 Subject: [PATCH] deviceUpdates takes timestamps in seconds, not milliseconds. Also do updates from gpodder.net every 30 minutes --- src/podcasts/gpoddersync.cpp | 16 +++++++++------- src/podcasts/gpoddersync.h | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/podcasts/gpoddersync.cpp b/src/podcasts/gpoddersync.cpp index c60b5fb9f..5a1e5fd42 100644 --- a/src/podcasts/gpoddersync.cpp +++ b/src/podcasts/gpoddersync.cpp @@ -34,7 +34,8 @@ #include const char* GPodderSync::kSettingsGroup = "Podcasts"; -const int GPodderSync::kFlushUpdateQueueDelay = 5 * kMsecPerSec; +const int GPodderSync::kFlushUpdateQueueDelay = 30 * kMsecPerSec; // 30 seconds +const int GPodderSync::kGetUpdatesInterval = 30*60 * kMsecPerSec; // 30 minutes GPodderSync::GPodderSync(Application* app, QObject* parent) : QObject(parent), @@ -42,6 +43,7 @@ GPodderSync::GPodderSync(Application* app, QObject* parent) network_(new NetworkAccessManager(this)), backend_(app_->podcast_backend()), loader_(new PodcastUrlLoader(this)), + get_updates_timer_(new QTimer(this)), flush_queue_timer_(new QTimer(this)), flushing_queue_(false) { @@ -52,6 +54,9 @@ GPodderSync::GPodderSync(Application* app, QObject* parent) connect(backend_, SIGNAL(SubscriptionAdded(Podcast)), SLOT(SubscriptionAdded(Podcast))); connect(backend_, SIGNAL(SubscriptionRemoved(Podcast)), SLOT(SubscriptionRemoved(Podcast))); + get_updates_timer_->setInterval(kGetUpdatesInterval); + connect(get_updates_timer_, SIGNAL(timeout()), SLOT(GetUpdatesNow())); + flush_queue_timer_->setInterval(kFlushUpdateQueueDelay); flush_queue_timer_->setSingleShot(true); connect(flush_queue_timer_, SIGNAL(timeout()), SLOT(FlushUpdateQueue())); @@ -59,6 +64,7 @@ GPodderSync::GPodderSync(Application* app, QObject* parent) if (is_logged_in()) { GetUpdatesNow(); flush_queue_timer_->start(); + get_updates_timer_->start(); } } @@ -141,12 +147,7 @@ void GPodderSync::GetUpdatesNow() { qlonglong timestamp = 0; if (last_successful_get_.isValid()) { -#if QT_VERSION >= 0x040700 - timestamp = last_successful_get_.toMSecsSinceEpoch(); -#else - timestamp = qlonglong(last_successful_get_.toTime_t()) * kMsecPerSec + - last_successful_get_.time().msec(); -#endif + timestamp = last_successful_get_.toTime_t(); } mygpo::DeviceUpdates* reply = api_->deviceUpdates(username_, DeviceId(), timestamp); @@ -378,6 +379,7 @@ void GPodderSync::AddRemoveFinished(mygpo::AddRemoveResult* reply, void GPodderSync::DoInitialSync() { // Get updates from the server GetUpdatesNow(); + get_updates_timer_->start(); // Send our complete list of subscriptions queued_remove_subscriptions_.clear(); diff --git a/src/podcasts/gpoddersync.h b/src/podcasts/gpoddersync.h index 5b017c900..6de7904af 100644 --- a/src/podcasts/gpoddersync.h +++ b/src/podcasts/gpoddersync.h @@ -53,6 +53,7 @@ public: static const char* kSettingsGroup; static const int kFlushUpdateQueueDelay; + static const int kGetUpdatesInterval; static QString DefaultDeviceName(); static QString DeviceId(); @@ -111,6 +112,7 @@ private: QString username_; QString password_; QDateTime last_successful_get_; + QTimer* get_updates_timer_; QTimer* flush_queue_timer_; QSet queued_add_subscriptions_;