void Syncer::CheckRemoteStorage () { connect (DM_, SIGNAL (gotChanges (QList<DriveChanges>, qlonglong)), this, SLOT (handleGotDriveChanges (QList<DriveChanges>, qlonglong))); DM_->RequestFileChanges (LastChangesId_); }
void Syncer::handleGotDriveChanges (const QList<DriveChanges>& changes, qlonglong id) { disconnect (DM_, SIGNAL (gotChanges (QList<DriveChanges>, qlonglong)), this, SLOT (handleGotDriveChanges (QList<DriveChanges>, qlonglong))); XmlSettingsManager::Instance ().setProperty ("LastChangesId", id); LastChangesId_ = id; }
void DriveManager::handleGetFileChanges () { QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ()); if (!reply) return; reply->deleteLater (); bool ok = false; auto ba = reply->readAll (); const auto& res = QJson::Parser ().parse (ba, &ok); if (!ok) { qDebug () << Q_FUNC_INFO << "parse error"; return; } const QVariantMap& map = res.toMap (); if (map.contains ("error")) { ParseError (map); return; } QList<DriveChanges> changes; if (!map.contains ("items") || map ["items"].toList ().isEmpty ()) return; const QString nextPageTokent = map ["nextPageToken"].toString (); qlonglong largestId = map ["largestChangeId"].toLongLong (); XmlSettingsManager::Instance ().setProperty ("largestChangeId", largestId); for (auto itemVar : map ["items"].toList ()) { QVariantMap itemMap = itemVar.toMap (); DriveChanges change; change.FileId_ = itemMap ["fileId"].toString (); change.Id_ = itemMap ["id"].toString (); change.Deleted_ = itemMap ["deleted"].toBool (); if (!change.Deleted_) change.FileResource_ =CreateDriveItem (itemMap ["file"]); changes << change; } emit gotChanges (changes); if (!nextPageTokent.isEmpty ()) RequestFileChanges (largestId, nextPageTokent); }
void DriveManager::handleGetFileChanges () { QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ()); if (!reply) return; reply->deleteLater (); bool ok = false; auto ba = reply->readAll (); const auto& res = QJson::Parser ().parse (ba, &ok); if (!ok) { qDebug () << Q_FUNC_INFO << "parse error"; return; } const QVariantMap& map = res.toMap (); if (map.contains ("error")) { ParseError (map); return; } QList<DriveChanges> changes; if (!map.contains ("items") || map ["items"].toList ().isEmpty ()) return; for (auto itemVar : map ["items"].toList ()) { QVariantMap itemMap = itemVar.toMap (); DriveItem driveItem = CreateDriveItem (itemMap ["file"]); DriveChanges change; change.FileId_ = itemMap ["fileId"].toString (); change.Id_ = itemMap ["id"].toString (); change.Deleted_ = itemMap ["deleted"].toBool (); change.FileResource_ = driveItem; changes << change; } gotChanges (changes, map ["largestChangeId"].toLongLong () + 1); }
void Account::handleGotChanges (const QList<DriveChanges>& driveChanges) { QList<Change> changes; for (const auto& driveChange : driveChanges) { //TODO setting for shared files if (driveChange.FileResource_.PermissionRole_ != DriveItem::Roles::Owner) continue; Change change; change.Deleted_ = driveChange.Deleted_; change.ID_ = driveChange.Id_.toUtf8 (); change.ItemID_ = driveChange.FileId_.toUtf8 (); if (!change.Deleted_) change.Item_ = CreateItem (driveChange.FileResource_); changes << change; } emit gotChanges (changes); }