diff --git a/src/oauth/oauthconnection.cpp b/src/oauth/oauthconnection.cpp index bf6a320..6b71462 100644 --- a/src/oauth/oauthconnection.cpp +++ b/src/oauth/oauthconnection.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -44,6 +45,9 @@ namespace Vreen { const static QUrl authUrl("http://api.vk.com/oauth/authorize"); const static QUrl apiUrl("https://api.vk.com/method/"); +const static char *scopeNames[] = { "notify", "friends", "photos", "audio", + "video", "docs", "notes", "pages", "status", "offers", "questions", "wall", + "groups", "messages", "notifications", "stats", "ads", "offline" }; class OAuthConnection; class OAuthConnectionPrivate : public ConnectionPrivate @@ -53,24 +57,24 @@ class OAuthConnectionPrivate : public ConnectionPrivate OAuthConnectionPrivate(OAuthConnection *q, int appId) : ConnectionPrivate(q), connectionState(Client::StateOffline), clientId(appId), - scope(QStringList() << QLatin1String("notify") - << QLatin1String("friends") - << QLatin1String("photos") - << QLatin1String("audio") - << QLatin1String("video") - << QLatin1String("docs") - << QLatin1String("notes") - << QLatin1String("pages") - << QLatin1String("status") - << QLatin1String("offers") - << QLatin1String("questions") - << QLatin1String("wall") - << QLatin1String("groups") - << QLatin1String("messages") - << QLatin1String("notifications") - << QLatin1String("stats") - << QLatin1String("ads") - << QLatin1String("offline")), + scope(OAuthConnection::notify| + OAuthConnection::friends| + OAuthConnection::photos| + OAuthConnection::audio| + OAuthConnection::video| + OAuthConnection::docs| + OAuthConnection::notes| + OAuthConnection::pages| + OAuthConnection::status| + OAuthConnection::offers| + OAuthConnection::questions| + OAuthConnection::wall| + OAuthConnection::groups| + OAuthConnection::messages| + OAuthConnection::notifications| + OAuthConnection::stats| + OAuthConnection::ads| + OAuthConnection::offline), redirectUri(QLatin1String("http://oauth.vk.com/blank.html")), displayType(OAuthConnection::Touch), responseType(QLatin1String("token")), @@ -84,7 +88,7 @@ class OAuthConnectionPrivate : public ConnectionPrivate //OAuth settings int clientId; - QStringList scope; //settings + OAuthConnection::Scopes scope; //settings QString redirectUri; OAuthConnection::DisplayType displayType; QString responseType; @@ -238,6 +242,20 @@ void OAuthConnection::setDisplayType(OAuthConnection::DisplayType displayType) } } +OAuthConnection::Scopes OAuthConnection::scopes() const +{ + return d_func()->scope; +} + +void OAuthConnection::setScopes(OAuthConnection::Scopes scopes) +{ + Q_D(OAuthConnection); + if( d->scope != scopes ) { + d->scope = scopes; + emit scopesChanged(scopes); + } +} + void OAuthConnectionPrivate::requestToken() { Q_Q(OAuthConnection); @@ -248,7 +266,7 @@ void OAuthConnectionPrivate::requestToken() } QUrl url = authUrl; url.addQueryItem(QLatin1String("client_id"), QByteArray::number(clientId)); - url.addQueryItem(QLatin1String("scope"), scope.join(",")); + url.addQueryItem(QLatin1String("scope"), flagsToStrList(scope, scopeNames).join(",")); url.addQueryItem(QLatin1String("redirect_uri"), redirectUri); const char *type[] = { "page", diff --git a/src/oauth/oauthconnection.h b/src/oauth/oauthconnection.h index 1c246bf..1935917 100644 --- a/src/oauth/oauthconnection.h +++ b/src/oauth/oauthconnection.h @@ -39,8 +39,10 @@ class OAuthConnection : public Connection Q_OBJECT Q_DECLARE_PRIVATE(OAuthConnection) Q_ENUMS(DisplayType) + Q_FLAGS(Scopes) Q_PROPERTY(int clientId READ clientId WRITE setClientId NOTIFY clientIdChanged) Q_PROPERTY(DisplayType displayType READ displayType WRITE setDisplayType) + Q_PROPERTY(Scopes scopes READ scopes WRITE setScopes NOTIFY scopesChanged) public: enum DisplayType { Page, @@ -48,6 +50,28 @@ class OAuthConnection : public Connection Touch, Wap }; + enum Scope { + notify = 0x1, + friends = 0x2, + photos = 0x4, + audio = 0x8, + video = 0x10, + docs = 0x20, + notes = 0x40, + pages = 0x80, + status = 0x100, + offers = 0x200, + questions = 0x400, + wall = 0x800, + groups = 0x1000, + messages = 0x2000, + notifications = 0x4000, + stats = 0x8000, + ads = 0x10000, + offline = 0x20000 + }; + Q_DECLARE_FLAGS(Scopes, Scope) + explicit OAuthConnection(int clientId, QObject *parent = 0); explicit OAuthConnection(QObject *parent = 0); virtual ~OAuthConnection(); @@ -67,10 +91,13 @@ class OAuthConnection : public Connection void setClientId(int clientId); DisplayType displayType() const; void setDisplayType(DisplayType displayType); + Scopes scopes() const; + void setScopes(Scopes scopes); signals: void authConfirmRequested(QWebPage *page); void accessTokenChanged(const QByteArray &token, time_t expiresIn); void clientIdChanged(int clientId); + void scopesChanged(Vreen::OAuthConnection::Scopes scopes); protected: QNetworkRequest makeRequest(const QString &method, const QVariantMap &args = QVariantMap()); void decorateRequest(QNetworkRequest &); @@ -78,6 +105,8 @@ class OAuthConnection : public Connection Q_PRIVATE_SLOT(d_func(), void _q_loadFinished(bool)) }; +Q_DECLARE_OPERATORS_FOR_FLAGS(OAuthConnection::Scopes) + } // namespace Vreen #endif // VK_OAUTHCONNECTION_H