Warning, /pim/kdepim-runtime/resources/tomboynotes/o2/changes.patch is written in an unsupported language. File is not indexed.

0001 diff --git a/src/o0abstractstore.h b/src/o0abstractstore.h
0002 index 1397361..0464325 100644
0003 --- a/src/o0abstractstore.h
0004 +++ b/src/o0abstractstore.h
0005 @@ -5,11 +5,13 @@
0006  #include <QString>
0007  
0008  /// Storage for strings.
0009 -class O0AbstractStore: public QObject {
0010 +class O0AbstractStore: public QObject
0011 +{
0012      Q_OBJECT
0013  
0014  public:
0015 -    explicit O0AbstractStore(QObject *parent = 0): QObject(parent) {
0016 +    explicit O0AbstractStore(QObject *parent = 0): QObject(parent)
0017 +    {
0018      }
0019  
0020      /// Retrieve a string value by key.
0021 diff --git a/src/o0baseauth.cpp b/src/o0baseauth.cpp
0022 index d4f052d..c021776 100644
0023 --- a/src/o0baseauth.cpp
0024 +++ b/src/o0baseauth.cpp
0025 @@ -1,18 +1,20 @@
0026  #include <QDataStream>
0027  #include <QDebug>
0028  
0029 -#include "o0baseauth.h"
0030 -#include "o0globals.h"
0031 -#include "o0settingsstore.h"
0032 +#include "o2/o0baseauth.h"
0033 +#include "o2/o0globals.h"
0034 +#include "o2/o0settingsstore.h"
0035  
0036  static const quint16 DefaultLocalPort = 1965;
0037  
0038 -O0BaseAuth::O0BaseAuth(QObject *parent): QObject(parent) {
0039 +O0BaseAuth::O0BaseAuth(QObject *parent): QObject(parent)
0040 +{
0041      localPort_ = DefaultLocalPort;
0042      store_ = new O0SettingsStore(O2_ENCRYPTION_KEY, this);
0043  }
0044  
0045 -void O0BaseAuth::setStore(O0AbstractStore *store) {
0046 +void O0BaseAuth::setStore(O0AbstractStore *store)
0047 +{
0048      if (store_) {
0049          store_->deleteLater();
0050      }
0051 @@ -25,74 +27,87 @@ void O0BaseAuth::setStore(O0AbstractStore *store) {
0052      }
0053  }
0054  
0055 -bool O0BaseAuth::linked() {
0056 +bool O0BaseAuth::linked()
0057 +{
0058      QString key = QString(O2_KEY_LINKED).arg(clientId_);
0059      bool result = !store_->value(key).isEmpty();
0060 -    qDebug() << "O0BaseAuth::linked:" << (result? "Yes": "No");
0061 +    qDebug() << "O0BaseAuth::linked:" << (result ? "Yes" : "No");
0062      return result;
0063  }
0064  
0065 -void O0BaseAuth::setLinked(bool v) {
0066 -    qDebug() << "O0BaseAuth::setLinked:" << (v? "true": "false");
0067 +void O0BaseAuth::setLinked(bool v)
0068 +{
0069 +    qDebug() << "O0BaseAuth::setLinked:" << (v ? "true" : "false");
0070      bool oldValue = linked();
0071      QString key = QString(O2_KEY_LINKED).arg(clientId_);
0072 -    store_->setValue(key, v? "1": "");
0073 +    store_->setValue(key, v ? "1" : "");
0074      if (oldValue != v) {
0075          Q_EMIT linkedChanged();
0076      }
0077  }
0078  
0079 -QString O0BaseAuth::tokenSecret() {
0080 +QString O0BaseAuth::tokenSecret()
0081 +{
0082      QString key = QString(O2_KEY_TOKEN_SECRET).arg(clientId_);
0083      return store_->value(key);
0084  }
0085  
0086 -void O0BaseAuth::setTokenSecret(const QString &v) {
0087 +void O0BaseAuth::setTokenSecret(const QString &v)
0088 +{
0089      QString key = QString(O2_KEY_TOKEN_SECRET).arg(clientId_);
0090      store_->setValue(key, v);
0091      Q_EMIT tokenSecretChanged();
0092  }
0093  
0094 -QString O0BaseAuth::token() {
0095 +QString O0BaseAuth::token()
0096 +{
0097      QString key = QString(O2_KEY_TOKEN).arg(clientId_);
0098      return store_->value(key);
0099  }
0100  
0101 -void O0BaseAuth::setToken(const QString &v) {
0102 +void O0BaseAuth::setToken(const QString &v)
0103 +{
0104      QString key = QString(O2_KEY_TOKEN).arg(clientId_);
0105      store_->setValue(key, v);
0106      Q_EMIT tokenChanged();
0107  }
0108  
0109 -QString O0BaseAuth::clientId() {
0110 +QString O0BaseAuth::clientId()
0111 +{
0112      return clientId_;
0113  }
0114  
0115 -void O0BaseAuth::setClientId(const QString &value) {
0116 +void O0BaseAuth::setClientId(const QString &value)
0117 +{
0118      clientId_ = value;
0119      Q_EMIT clientIdChanged();
0120  }
0121  
0122 -QString O0BaseAuth::clientSecret() {
0123 +QString O0BaseAuth::clientSecret()
0124 +{
0125      return clientSecret_;
0126  }
0127  
0128 -void O0BaseAuth::setClientSecret(const QString &value) {
0129 +void O0BaseAuth::setClientSecret(const QString &value)
0130 +{
0131      clientSecret_ = value;
0132      Q_EMIT clientSecretChanged();
0133  }
0134  
0135 -int O0BaseAuth::localPort() {
0136 +int O0BaseAuth::localPort()
0137 +{
0138      return localPort_;
0139  }
0140  
0141 -void O0BaseAuth::setLocalPort(int value) {
0142 +void O0BaseAuth::setLocalPort(int value)
0143 +{
0144      qDebug() << "O0BaseAuth::setLocalPort:" << value;
0145      localPort_ = value;
0146      Q_EMIT localPortChanged();
0147  }
0148  
0149 -QVariantMap O0BaseAuth::extraTokens() {
0150 +QVariantMap O0BaseAuth::extraTokens()
0151 +{
0152      QString key = QString(O2_KEY_EXTRA_TOKENS).arg(clientId_);
0153      QString value = store_->value(key);
0154      QByteArray bytes = QByteArray::fromBase64(value.toLatin1());
0155 @@ -101,7 +116,8 @@ QVariantMap O0BaseAuth::extraTokens() {
0156      return extraTokens_;
0157  }
0158  
0159 -void O0BaseAuth::setExtraTokens(QVariantMap extraTokens) {
0160 +void O0BaseAuth::setExtraTokens(QVariantMap extraTokens)
0161 +{
0162      extraTokens_ = extraTokens;
0163      QByteArray bytes;
0164      QDataStream stream(&bytes, QIODevice::WriteOnly);
0165 @@ -111,7 +127,8 @@ void O0BaseAuth::setExtraTokens(QVariantMap extraTokens) {
0166      Q_EMIT extraTokensChanged();
0167  }
0168  
0169 -QByteArray O0BaseAuth::createQueryParameters(const QList<O0RequestParameter> &parameters) {
0170 +QByteArray O0BaseAuth::createQueryParameters(const QList<O0RequestParameter> &parameters)
0171 +{
0172      QByteArray ret;
0173      bool first = true;
0174      foreach (O0RequestParameter h, parameters) {
0175 diff --git a/src/o0baseauth.h b/src/o0baseauth.h
0176 index d8a68a2..c906edf 100644
0177 --- a/src/o0baseauth.h
0178 +++ b/src/o0baseauth.h
0179 @@ -8,11 +8,12 @@
0180  #include <QUrl>
0181  #include <QVariantMap>
0182  
0183 -#include "o0abstractstore.h"
0184 -#include "o0requestparameter.h"
0185 +#include "o2/o0abstractstore.h"
0186 +#include "o2/o0requestparameter.h"
0187  
0188  /// Base class of OAuth authenticators
0189 -class O0BaseAuth : public QObject {
0190 +class O0BaseAuth : public QObject
0191 +{
0192      Q_OBJECT
0193  
0194  public:
0195 diff --git a/src/o0requestparameter.h b/src/o0requestparameter.h
0196 index c793aad..c966987 100644
0197 --- a/src/o0requestparameter.h
0198 +++ b/src/o0requestparameter.h
0199 @@ -4,8 +4,9 @@
0200  /// Request parameter (name-value pair) participating in authentication.
0201  struct O0RequestParameter {
0202      O0RequestParameter(const QByteArray &n, const QByteArray &v): name(n), value(v) {}
0203 -    bool operator <(const O0RequestParameter &other) const {
0204 -        return (name == other.name)? (value < other.value): (name < other.name);
0205 +    bool operator <(const O0RequestParameter &other) const
0206 +    {
0207 +        return (name == other.name) ? (value < other.value) : (name < other.name);
0208      }
0209      QByteArray name;
0210      QByteArray value;
0211 diff --git a/src/o0settingsstore.cpp b/src/o0settingsstore.cpp
0212 index c475389..accba71 100644
0213 --- a/src/o0settingsstore.cpp
0214 +++ b/src/o0settingsstore.cpp
0215 @@ -1,28 +1,33 @@
0216  #include <QCryptographicHash>
0217  #include <QByteArray>
0218  
0219 -#include "o0settingsstore.h"
0220 +#include "o2/o0settingsstore.h"
0221  
0222 -static quint64 getHash(const QString &encryptionKey) {
0223 +static quint64 getHash(const QString &encryptionKey)
0224 +{
0225      return QCryptographicHash::hash(encryptionKey.toLatin1(), QCryptographicHash::Sha1).toULongLong();
0226  }
0227  
0228  O0SettingsStore::O0SettingsStore(const QString &encryptionKey, QObject *parent):
0229 -    O0AbstractStore(parent), crypt_(getHash(encryptionKey)) {
0230 +    O0AbstractStore(parent), crypt_(getHash(encryptionKey))
0231 +{
0232      settings_ = new QSettings(this);
0233  }
0234  
0235  O0SettingsStore::O0SettingsStore(QSettings *settings, const QString &encryptionKey, QObject *parent):
0236 -    O0AbstractStore(parent), crypt_(getHash(encryptionKey)) {
0237 +    O0AbstractStore(parent), crypt_(getHash(encryptionKey))
0238 +{
0239      settings_ = settings;
0240      settings_->setParent(this);
0241  }
0242  
0243 -QString O0SettingsStore::groupKey() const {
0244 +QString O0SettingsStore::groupKey() const
0245 +{
0246      return groupKey_;
0247  }
0248  
0249 -void O0SettingsStore::setGroupKey(const QString &groupKey) {
0250 +void O0SettingsStore::setGroupKey(const QString &groupKey)
0251 +{
0252      if (groupKey_ == groupKey) {
0253          return;
0254      }
0255 @@ -30,7 +35,8 @@ void O0SettingsStore::setGroupKey(const QString &groupKey) {
0256      Q_EMIT groupKeyChanged();
0257  }
0258  
0259 -QString O0SettingsStore::value(const QString &key, const QString &defaultValue) {
0260 +QString O0SettingsStore::value(const QString &key, const QString &defaultValue)
0261 +{
0262      QString fullKey = groupKey_.isEmpty() ? key : (groupKey_ + '/' + key);
0263      if (!settings_->contains(fullKey)) {
0264          return defaultValue;
0265 @@ -38,7 +44,8 @@ QString O0SettingsStore::value(const QString &key, const QString &defaultValue)
0266      return crypt_.decryptToString(settings_->value(fullKey).toString());
0267  }
0268  
0269 -void O0SettingsStore::setValue(const QString &key, const QString &value) {
0270 +void O0SettingsStore::setValue(const QString &key, const QString &value)
0271 +{
0272      QString fullKey = groupKey_.isEmpty() ? key : (groupKey_ + '/' + key);
0273      settings_->setValue(fullKey, crypt_.encryptToString(value));
0274  }
0275 diff --git a/src/o0settingsstore.h b/src/o0settingsstore.h
0276 index 2b6964a..4406503 100644
0277 --- a/src/o0settingsstore.h
0278 +++ b/src/o0settingsstore.h
0279 @@ -4,11 +4,12 @@
0280  #include <QSettings>
0281  #include <QString>
0282  
0283 -#include "o0abstractstore.h"
0284 -#include "o0simplecrypt.h"
0285 +#include "o2/o0abstractstore.h"
0286 +#include "o2/o0simplecrypt.h"
0287  
0288  /// Persistent storage for authentication tokens, using QSettings.
0289 -class O0SettingsStore: public O0AbstractStore {
0290 +class O0SettingsStore: public O0AbstractStore
0291 +{
0292      Q_OBJECT
0293  
0294  public:
0295 @@ -34,7 +35,7 @@ Q_SIGNALS:
0296      void groupKeyChanged();
0297  
0298  protected:
0299 -    QSettings* settings_;
0300 +    QSettings *settings_;
0301      QString groupKey_;
0302      O0SimpleCrypt crypt_;
0303  };
0304 diff --git a/src/o0simplecrypt.h b/src/o0simplecrypt.h
0305 index 64f916d..b28c210 100644
0306 --- a/src/o0simplecrypt.h
0307 +++ b/src/o0simplecrypt.h
0308 @@ -109,7 +109,10 @@ public:
0309      /**
0310        Returns true if SimpleCrypt has been initialized with a key.
0311        */
0312 -    bool hasKey() const {return !m_keyParts.isEmpty();}
0313 +    bool hasKey() const
0314 +    {
0315 +        return !m_keyParts.isEmpty();
0316 +    }
0317  
0318      /**
0319        Sets the compression mode to use when encrypting data. The default mode is Auto.
0320 @@ -117,11 +120,17 @@ public:
0321        Note that decryption is not influenced by this mode, as the decryption recognizes
0322        what mode was used when encrypting.
0323        */
0324 -    void setCompressionMode(CompressionMode mode) {m_compressionMode = mode;}
0325 +    void setCompressionMode(CompressionMode mode)
0326 +    {
0327 +        m_compressionMode = mode;
0328 +    }
0329      /**
0330        Returns the CompressionMode that is currently in use.
0331        */
0332 -    CompressionMode compressionMode() const {return m_compressionMode;}
0333 +    CompressionMode compressionMode() const
0334 +    {
0335 +        return m_compressionMode;
0336 +    }
0337  
0338      /**
0339        Sets the integrity mode to use when encrypting data. The default mode is Checksum.
0340 @@ -129,23 +138,32 @@ public:
0341        Note that decryption is not influenced by this mode, as the decryption recognizes
0342        what mode was used when encrypting.
0343        */
0344 -    void setIntegrityProtectionMode(IntegrityProtectionMode mode) {m_protectionMode = mode;}
0345 +    void setIntegrityProtectionMode(IntegrityProtectionMode mode)
0346 +    {
0347 +        m_protectionMode = mode;
0348 +    }
0349      /**
0350        Returns the IntegrityProtectionMode that is currently in use.
0351        */
0352 -    IntegrityProtectionMode integrityProtectionMode() const {return m_protectionMode;}
0353 +    IntegrityProtectionMode integrityProtectionMode() const
0354 +    {
0355 +        return m_protectionMode;
0356 +    }
0357  
0358      /**
0359        Returns the last error that occurred.
0360        */
0361 -    Error lastError() const {return m_lastError;}
0362 +    Error lastError() const
0363 +    {
0364 +        return m_lastError;
0365 +    }
0366  
0367      /**
0368        Encrypts the @arg plaintext string with the key the class was initialized with, and returns
0369        a cyphertext the result. The result is a base64 encoded version of the binary array that is the
0370        actual result of the string, so it can be stored easily in a text format.
0371        */
0372 -    QString encryptToString(const QString& plaintext) ;
0373 +    QString encryptToString(const QString &plaintext) ;
0374      /**
0375        Encrypts the @arg plaintext QByteArray with the key the class was initialized with, and returns
0376        a cyphertext the result. The result is a base64 encoded version of the binary array that is the
0377 @@ -159,7 +177,7 @@ public:
0378        This method returns a byte array, that is useable for storing a binary format. If you need
0379        a string you can store in a text file, use encryptToString() instead.
0380        */
0381 -    QByteArray encryptToByteArray(const QString& plaintext) ;
0382 +    QByteArray encryptToByteArray(const QString &plaintext) ;
0383      /**
0384        Encrypts the @arg plaintext QByteArray with the key the class was initialized with, and returns
0385        a binary cyphertext in a QByteArray the result.
0386 @@ -176,7 +194,7 @@ public:
0387        If an error occured, such as non-matching keys between encryption and decryption,
0388        an empty string or a string containing nonsense may be returned.
0389        */
0390 -    QString decryptToString(const QString& cyphertext) ;
0391 +    QString decryptToString(const QString &cyphertext) ;
0392      /**
0393        Decrypts a cyphertext string encrypted with this class with the set key back to the
0394        plain text version.
0395 @@ -184,7 +202,7 @@ public:
0396        If an error occured, such as non-matching keys between encryption and decryption,
0397        an empty string or a string containing nonsense may be returned.
0398        */
0399 -    QByteArray decryptToByteArray(const QString& cyphertext) ;
0400 +    QByteArray decryptToByteArray(const QString &cyphertext) ;
0401      /**
0402        Decrypts a cyphertext binary encrypted with this class with the set key back to the
0403        plain text version.
0404 @@ -204,11 +222,11 @@ public:
0405  
0406      //enum to describe options that have been used for the encryption. Currently only one, but
0407      //that only leaves room for future extensions like adding a cryptographic hash...
0408 -    enum CryptoFlag{CryptoFlagNone = 0,
0409 -                    CryptoFlagCompression = 0x01,
0410 -                    CryptoFlagChecksum = 0x02,
0411 -                    CryptoFlagHash = 0x04
0412 -                   };
0413 +    enum CryptoFlag {CryptoFlagNone = 0,
0414 +                     CryptoFlagCompression = 0x01,
0415 +                     CryptoFlagChecksum = 0x02,
0416 +                     CryptoFlagHash = 0x04
0417 +                    };
0418      Q_DECLARE_FLAGS(CryptoFlags, CryptoFlag)
0419  private:
0420  
0421 diff --git a/src/o1.cpp b/src/o1.cpp
0422 index 47783fc..67660fc 100644
0423 --- a/src/o1.cpp
0424 +++ b/src/o1.cpp
0425 @@ -15,12 +15,13 @@
0426  #include <QMessageAuthenticationCode>
0427  #endif
0428  
0429 -#include "o1.h"
0430 -#include "o2replyserver.h"
0431 -#include "o0globals.h"
0432 -#include "o0settingsstore.h"
0433 +#include "o2/o1.h"
0434 +#include "o2/o2replyserver.h"
0435 +#include "o2/o0globals.h"
0436 +#include "o2/o0settingsstore.h"
0437  
0438 -O1::O1(QObject *parent): O0BaseAuth(parent) {
0439 +O1::O1(QObject *parent): O0BaseAuth(parent)
0440 +{
0441      setSignatureMethod(O2_SIGNATURE_TYPE_HMAC_SHA1);
0442      manager_ = new QNetworkAccessManager(this);
0443      replyServer_ = new O2ReplyServer(this);
0444 @@ -29,59 +30,72 @@ O1::O1(QObject *parent): O0BaseAuth(parent) {
0445      setCallbackUrl(O2_CALLBACK_URL);
0446  }
0447  
0448 -QUrl O1::requestTokenUrl() {
0449 +QUrl O1::requestTokenUrl()
0450 +{
0451      return requestTokenUrl_;
0452  }
0453  
0454 -void O1::setRequestTokenUrl(const QUrl &v) {
0455 +void O1::setRequestTokenUrl(const QUrl &v)
0456 +{
0457      requestTokenUrl_ = v;
0458      Q_EMIT requestTokenUrlChanged();
0459  }
0460  
0461 -QList<O0RequestParameter> O1::requestParameters() {
0462 +QList<O0RequestParameter> O1::requestParameters()
0463 +{
0464      return requestParameters_;
0465  }
0466  
0467 -void O1::setRequestParameters(const QList<O0RequestParameter> &v) {
0468 +void O1::setRequestParameters(const QList<O0RequestParameter> &v)
0469 +{
0470      requestParameters_ = v;
0471  }
0472  
0473 -QString O1::callbackUrl() {
0474 +QString O1::callbackUrl()
0475 +{
0476      return callbackUrl_;
0477  }
0478  
0479 -void O1::setCallbackUrl(const QString &v) {
0480 +void O1::setCallbackUrl(const QString &v)
0481 +{
0482      callbackUrl_ = v;
0483  }
0484  
0485 -QUrl O1::authorizeUrl() {
0486 +QUrl O1::authorizeUrl()
0487 +{
0488      return authorizeUrl_;
0489  }
0490  
0491 -void O1::setAuthorizeUrl(const QUrl &value) {
0492 +void O1::setAuthorizeUrl(const QUrl &value)
0493 +{
0494      authorizeUrl_ = value;
0495      Q_EMIT authorizeUrlChanged();
0496  }
0497  
0498 -QUrl O1::accessTokenUrl() {
0499 +QUrl O1::accessTokenUrl()
0500 +{
0501      return accessTokenUrl_;
0502  }
0503  
0504 -void O1::setAccessTokenUrl(const QUrl &value) {
0505 +void O1::setAccessTokenUrl(const QUrl &value)
0506 +{
0507      accessTokenUrl_ = value;
0508      Q_EMIT accessTokenUrlChanged();
0509  }
0510  
0511 -QString O1::signatureMethod() {
0512 +QString O1::signatureMethod()
0513 +{
0514      return signatureMethod_;
0515  }
0516  
0517 -void O1::setSignatureMethod(const QString &value) {
0518 +void O1::setSignatureMethod(const QString &value)
0519 +{
0520      qDebug() << "O1::setSignatureMethod: " << value;
0521      signatureMethod_ = value;
0522  }
0523  
0524 -void O1::unlink() {
0525 +void O1::unlink()
0526 +{
0527      qDebug() << "O1::unlink";
0528      setLinked(false);
0529      setToken("");
0530 @@ -94,7 +108,8 @@ void O1::unlink() {
0531  /// Calculate the HMAC variant of SHA1 hash.
0532  /// @author     http://qt-project.org/wiki/HMAC-SHA1.
0533  /// @copyright  Creative Commons Attribution-ShareAlike 2.5 Generic.
0534 -static QByteArray hmacSha1(QByteArray key, QByteArray baseString) {
0535 +static QByteArray hmacSha1(QByteArray key, QByteArray baseString)
0536 +{
0537      int blockSize = 64;
0538      if (key.length() > blockSize) {
0539          key = QCryptographicHash::hash(key, QCryptographicHash::Sha1);
0540 @@ -115,7 +130,8 @@ static QByteArray hmacSha1(QByteArray key, QByteArray baseString) {
0541  #endif
0542  
0543  /// Get HTTP operation name.
0544 -static QString getOperationName(QNetworkAccessManager::Operation op) {
0545 +static QString getOperationName(QNetworkAccessManager::Operation op)
0546 +{
0547      switch (op) {
0548      case QNetworkAccessManager::GetOperation: return "GET";
0549      case QNetworkAccessManager::PostOperation: return "POST";
0550 @@ -126,12 +142,14 @@ static QString getOperationName(QNetworkAccessManager::Operation op) {
0551  }
0552  
0553  /// Build a concatenated/percent-encoded string from a list of headers.
0554 -QByteArray O1::encodeHeaders(const QList<O0RequestParameter> &headers) {
0555 +QByteArray O1::encodeHeaders(const QList<O0RequestParameter> &headers)
0556 +{
0557      return QUrl::toPercentEncoding(createQueryParameters(headers));
0558  }
0559  
0560  /// Build a base string for signing.
0561 -QByteArray O1::getRequestBase(const QList<O0RequestParameter> &oauthParams, const QList<O0RequestParameter> &otherParams, const QUrl &url, QNetworkAccessManager::Operation op) {
0562 +QByteArray O1::getRequestBase(const QList<O0RequestParameter> &oauthParams, const QList<O0RequestParameter> &otherParams, const QUrl &url, QNetworkAccessManager::Operation op)
0563 +{
0564      QByteArray base;
0565  
0566      // Initialize base string with the operation name (e.g. "GET") and the base URL
0567 @@ -147,7 +165,8 @@ QByteArray O1::getRequestBase(const QList<O0RequestParameter> &oauthParams, cons
0568      return base;
0569  }
0570  
0571 -QByteArray O1::sign(const QList<O0RequestParameter> &oauthParams, const QList<O0RequestParameter> &otherParams, const QUrl &url, QNetworkAccessManager::Operation op, const QString &consumerSecret, const QString &tokenSecret) {
0572 +QByteArray O1::sign(const QList<O0RequestParameter> &oauthParams, const QList<O0RequestParameter> &otherParams, const QUrl &url, QNetworkAccessManager::Operation op, const QString &consumerSecret, const QString &tokenSecret)
0573 +{
0574      QByteArray baseString = getRequestBase(oauthParams, otherParams, url, op);
0575      QByteArray secret = QUrl::toPercentEncoding(consumerSecret) + "&" + QUrl::toPercentEncoding(tokenSecret);
0576  #if QT_VERSION >= 0x050100
0577 @@ -157,7 +176,8 @@ QByteArray O1::sign(const QList<O0RequestParameter> &oauthParams, const QList<O0
0578  #endif
0579  }
0580  
0581 -QByteArray O1::buildAuthorizationHeader(const QList<O0RequestParameter> &oauthParams) {
0582 +QByteArray O1::buildAuthorizationHeader(const QList<O0RequestParameter> &oauthParams)
0583 +{
0584      bool first = true;
0585      QByteArray ret("OAuth ");
0586      QList<O0RequestParameter> headers(oauthParams);
0587 @@ -176,7 +196,8 @@ QByteArray O1::buildAuthorizationHeader(const QList<O0RequestParameter> &oauthPa
0588      return ret;
0589  }
0590  
0591 -QByteArray O1::generateSignature(const QList<O0RequestParameter> headers, const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, QNetworkAccessManager::Operation operation) {
0592 +QByteArray O1::generateSignature(const QList<O0RequestParameter> headers, const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, QNetworkAccessManager::Operation operation)
0593 +{
0594      QByteArray signature;
0595      if (signatureMethod() == O2_SIGNATURE_TYPE_HMAC_SHA1) {
0596          signature = sign(headers, signingParameters, req.url(), operation, clientSecret(), tokenSecret());
0597 @@ -186,7 +207,8 @@ QByteArray O1::generateSignature(const QList<O0RequestParameter> headers, const
0598      return signature;
0599  }
0600  
0601 -void O1::link() {
0602 +void O1::link()
0603 +{
0604      qDebug() << "O1::link";
0605      if (linked()) {
0606          qDebug() << "O1::link: Linked already";
0607 @@ -205,8 +227,9 @@ void O1::link() {
0608      // Get any query parameters for the request
0609      QUrlQuery requestData;
0610      O0RequestParameter param("", "");
0611 -    foreach(param, requestParameters())
0612 -      requestData.addQueryItem(QString(param.name), QUrl::toPercentEncoding(QString(param.value)));
0613 +    foreach (param, requestParameters()) {
0614 +        requestData.addQueryItem(QString(param.name), QUrl::toPercentEncoding(QString(param.value)));
0615 +    }
0616  
0617      // Get the request url and add parameters
0618      QUrl requestUrl = requestTokenUrl();
0619 @@ -237,13 +260,15 @@ void O1::link() {
0620      connect(reply, SIGNAL(finished()), this, SLOT(onTokenRequestFinished()));
0621  }
0622  
0623 -void O1::onTokenRequestError(QNetworkReply::NetworkError error) {
0624 +void O1::onTokenRequestError(QNetworkReply::NetworkError error)
0625 +{
0626      QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
0627      qWarning() << "O1::onTokenRequestError:" << (int)error << reply->errorString() << reply->readAll();
0628      Q_EMIT linkingFailed();
0629  }
0630  
0631 -void O1::onTokenRequestFinished() {
0632 +void O1::onTokenRequestFinished()
0633 +{
0634      qDebug() << "O1::onTokenRequestFinished";
0635      QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
0636      reply->deleteLater();
0637 @@ -282,7 +307,8 @@ void O1::onTokenRequestFinished() {
0638      Q_EMIT openBrowser(url);
0639  }
0640  
0641 -void O1::onVerificationReceived(QMap<QString, QString> params) {
0642 +void O1::onVerificationReceived(QMap<QString, QString> params)
0643 +{
0644      qDebug() << "O1::onVerificationReceived";
0645      Q_EMIT closeBrowser();
0646      verifier_ = params.value(O2_OAUTH_VERFIER, "");
0647 @@ -295,7 +321,8 @@ void O1::onVerificationReceived(QMap<QString, QString> params) {
0648      }
0649  }
0650  
0651 -void O1::exchangeToken() {
0652 +void O1::exchangeToken()
0653 +{
0654      qDebug() << "O1::exchangeToken";
0655  
0656      // Create token exchange request
0657 @@ -318,13 +345,15 @@ void O1::exchangeToken() {
0658      connect(reply, SIGNAL(finished()), this, SLOT(onTokenExchangeFinished()));
0659  }
0660  
0661 -void O1::onTokenExchangeError(QNetworkReply::NetworkError error) {
0662 +void O1::onTokenExchangeError(QNetworkReply::NetworkError error)
0663 +{
0664      QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
0665      qWarning() << "O1::onTokenExchangeError:" << (int)error << reply->errorString() << reply->readAll();
0666      Q_EMIT linkingFailed();
0667  }
0668  
0669 -void O1::onTokenExchangeFinished() {
0670 +void O1::onTokenExchangeFinished()
0671 +{
0672      qDebug() << "O1::onTokenExchangeFinished";
0673  
0674      QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
0675 @@ -344,7 +373,7 @@ void O1::onTokenExchangeFinished() {
0676          if (!response.isEmpty()) {
0677              QVariantMap extraTokens;
0678              foreach (QString key, response.keys()) {
0679 -               extraTokens.insert(key, response.value(key));
0680 +                extraTokens.insert(key, response.value(key));
0681              }
0682              setExtraTokens(extraTokens);
0683          }
0684 @@ -356,7 +385,8 @@ void O1::onTokenExchangeFinished() {
0685      }
0686  }
0687  
0688 -QMap<QString, QString> O1::parseResponse(const QByteArray &response) {
0689 +QMap<QString, QString> O1::parseResponse(const QByteArray &response)
0690 +{
0691      QMap<QString, QString> ret;
0692      foreach (QByteArray param, response.split('&')) {
0693          QList<QByteArray> kv = param.split('=');
0694 @@ -367,7 +397,8 @@ QMap<QString, QString> O1::parseResponse(const QByteArray &response) {
0695      return ret;
0696  }
0697  
0698 -QByteArray O1::nonce() {
0699 +QByteArray O1::nonce()
0700 +{
0701      static bool firstTime = true;
0702      if (firstTime) {
0703          firstTime = false;
0704 diff --git a/src/o1.h b/src/o1.h
0705 index 6d07b01..2330ca7 100644
0706 --- a/src/o1.h
0707 +++ b/src/o1.h
0708 @@ -5,12 +5,13 @@
0709  #include <QUrl>
0710  #include <QNetworkReply>
0711  
0712 -#include "o0baseauth.h"
0713 +#include "o2/o0baseauth.h"
0714  
0715  class O2ReplyServer;
0716  
0717  /// Simple OAuth 1.0 authenticator.
0718 -class O1: public O0BaseAuth {
0719 +class O1: public O0BaseAuth
0720 +{
0721      Q_OBJECT
0722  
0723  public:
0724 @@ -92,7 +93,7 @@ Q_SIGNALS:
0725  
0726  protected Q_SLOTS:
0727      /// Handle verification received from the reply server.
0728 -    virtual void onVerificationReceived(QMap<QString,QString> params);
0729 +    virtual void onVerificationReceived(QMap<QString, QString> params);
0730  
0731      /// Handle token request error.
0732      virtual void onTokenRequestError(QNetworkReply::NetworkError error);
0733 diff --git a/src/o1requestor.cpp b/src/o1requestor.cpp
0734 index fabb4fa..f3e049a 100644
0735 --- a/src/o1requestor.cpp
0736 +++ b/src/o1requestor.cpp
0737 @@ -3,41 +3,48 @@
0738  #include <QNetworkReply>
0739  #include <QNetworkAccessManager>
0740  
0741 -#include "o1requestor.h"
0742 -#include "o1timedreply.h"
0743 -#include "o0globals.h"
0744 +#include "o2/o1requestor.h"
0745 +#include "o2/o1timedreply.h"
0746 +#include "o2/o0globals.h"
0747  
0748 -O1Requestor::O1Requestor(QNetworkAccessManager *manager, O1 *authenticator, QObject *parent): QObject(parent) {
0749 +O1Requestor::O1Requestor(QNetworkAccessManager *manager, O1 *authenticator, QObject *parent): QObject(parent)
0750 +{
0751      manager_ = manager;
0752      authenticator_ = authenticator;
0753  }
0754  
0755 -QNetworkReply *O1Requestor::get(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters) {
0756 +QNetworkReply *O1Requestor::get(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters)
0757 +{
0758      QNetworkRequest request = setup(req, signingParameters, QNetworkAccessManager::GetOperation);
0759      return addTimer(manager_->get(request));
0760  }
0761  
0762 -QNetworkReply *O1Requestor::post(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, const QByteArray &data) {
0763 +QNetworkReply *O1Requestor::post(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, const QByteArray &data)
0764 +{
0765      QNetworkRequest request = setup(req, signingParameters, QNetworkAccessManager::PostOperation);
0766      return addTimer(manager_->post(request, data));
0767  }
0768  
0769 -QNetworkReply *O1Requestor::post(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, QHttpMultiPart * multiPart) {
0770 +QNetworkReply *O1Requestor::post(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, QHttpMultiPart *multiPart)
0771 +{
0772      QNetworkRequest request = setup(req, signingParameters, QNetworkAccessManager::PostOperation);
0773      return addTimer(manager_->post(request, multiPart));
0774  }
0775  
0776 -QNetworkReply *O1Requestor::put(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, const QByteArray &data) {
0777 +QNetworkReply *O1Requestor::put(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, const QByteArray &data)
0778 +{
0779      QNetworkRequest request = setup(req, signingParameters, QNetworkAccessManager::PutOperation);
0780      return addTimer(manager_->put(request, data));
0781  }
0782  
0783 -QNetworkReply *O1Requestor::addTimer(QNetworkReply *reply) {
0784 +QNetworkReply *O1Requestor::addTimer(QNetworkReply *reply)
0785 +{
0786      (void)new O1TimedReply(reply);
0787      return reply;
0788  }
0789  
0790 -QNetworkRequest O1Requestor::setup(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, QNetworkAccessManager::Operation operation) {
0791 +QNetworkRequest O1Requestor::setup(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, QNetworkAccessManager::Operation operation)
0792 +{
0793      // Collect OAuth parameters
0794      QList<O0RequestParameter> oauthParams;
0795      oauthParams.append(O0RequestParameter(O2_OAUTH_CONSUMER_KEY, authenticator_->clientId().toLatin1()));
0796 diff --git a/src/o1requestor.h b/src/o1requestor.h
0797 index 5de2fb2..0be21bc 100644
0798 --- a/src/o1requestor.h
0799 +++ b/src/o1requestor.h
0800 @@ -5,14 +5,15 @@
0801  #include <QNetworkRequest>
0802  #include <QByteArray>
0803  
0804 -#include "o1.h"
0805 +#include "o2/o1.h"
0806  
0807  class QNetworkAccessManager;
0808  class QNetworkReply;
0809  class O1;
0810  
0811  /// Makes authenticated requests using OAuth 1.0.
0812 -class O1Requestor: public QObject {
0813 +class O1Requestor: public QObject
0814 +{
0815      Q_OBJECT
0816  
0817  public:
0818 @@ -57,5 +58,4 @@ protected:
0819      O1 *authenticator_;
0820  };
0821  
0822 -
0823  #endif // O1REQUESTOR_H
0824 diff --git a/src/o1timedreply.cpp b/src/o1timedreply.cpp
0825 index 14897f5..4685be2 100644
0826 --- a/src/o1timedreply.cpp
0827 +++ b/src/o1timedreply.cpp
0828 @@ -1,20 +1,23 @@
0829  #include <QTimer>
0830  #include <QNetworkReply>
0831  
0832 -#include "o1timedreply.h"
0833 +#include "o2/o1timedreply.h"
0834  
0835 -O1TimedReply::O1TimedReply(QNetworkReply *parent, int pTimeout): QTimer(parent) {
0836 +O1TimedReply::O1TimedReply(QNetworkReply *parent, int pTimeout): QTimer(parent)
0837 +{
0838      setSingleShot(true);
0839      setInterval(pTimeout);
0840      connect(this, SIGNAL(timeout()), this, SLOT(onTimeout()));
0841      connect(parent, SIGNAL(finished()), this, SLOT(onFinished()));
0842  }
0843  
0844 -void O1TimedReply::onFinished() {
0845 +void O1TimedReply::onFinished()
0846 +{
0847      stop();
0848      Q_EMIT finished();
0849  }
0850  
0851 -void O1TimedReply::onTimeout() {
0852 +void O1TimedReply::onTimeout()
0853 +{
0854      Q_EMIT error(QNetworkReply::TimeoutError);
0855  }
0856 diff --git a/src/o1timedreply.h b/src/o1timedreply.h
0857 index 174cc0c..ddb4565 100644
0858 --- a/src/o1timedreply.h
0859 +++ b/src/o1timedreply.h
0860 @@ -5,11 +5,12 @@
0861  #include <QTimer>
0862  
0863  /// A timer connected to a network reply.
0864 -class O1TimedReply: public QTimer {
0865 +class O1TimedReply: public QTimer
0866 +{
0867      Q_OBJECT
0868  
0869  public:
0870 -    explicit O1TimedReply(QNetworkReply *parent, int pTimeout=60*1000);
0871 +    explicit O1TimedReply(QNetworkReply *parent, int pTimeout = 60 * 1000);
0872  
0873  Q_SIGNALS:
0874      /// Emitted when we have timed out waiting for the network reply.
0875 diff --git a/src/o2.cpp b/src/o2.cpp
0876 index e8108da..ec1799d 100644
0877 --- a/src/o2.cpp
0878 +++ b/src/o2.cpp
0879 @@ -26,7 +26,8 @@
0880  #include "o0settingsstore.h"
0881  
0882  /// Parse JSON data into a QVariantMap
0883 -static QVariantMap parseTokenResponse(const QByteArray &data) {
0884 +static QVariantMap parseTokenResponse(const QByteArray &data)
0885 +{
0886  #if QT_VERSION >= 0x050000
0887      QJsonParseError err;
0888      QJsonDocument doc = QJsonDocument::fromJson(data, &err);
0889 @@ -57,7 +58,8 @@ static QVariantMap parseTokenResponse(const QByteArray &data) {
0890  }
0891  
0892  /// Add query parameters to a query
0893 -static void addQueryParametersToUrl(QUrl &url,  QList<QPair<QString, QString> > parameters) {
0894 +static void addQueryParametersToUrl(QUrl &url,  QList<QPair<QString, QString> > parameters)
0895 +{
0896  #if QT_VERSION < 0x050000
0897      url.setQueryItems(parameters);
0898  #else
0899 @@ -67,7 +69,8 @@ static void addQueryParametersToUrl(QUrl &url,  QList<QPair<QString, QString> >
0900  #endif
0901  }
0902  
0903 -O2::O2(QObject *parent): O0BaseAuth(parent) {
0904 +O2::O2(QObject *parent): O0BaseAuth(parent)
0905 +{
0906      manager_ = new QNetworkAccessManager(this);
0907      replyServer_ = new O2ReplyServer(this);
0908      grantFlow_ = GrantFlowAuthorizationCode;
0909 @@ -76,70 +79,85 @@ O2::O2(QObject *parent): O0BaseAuth(parent) {
0910      connect(replyServer_, SIGNAL(verificationReceived(QMap<QString,QString>)), this, SLOT(onVerificationReceived(QMap<QString,QString>)));
0911  }
0912  
0913 -O2::GrantFlow O2::grantFlow() {
0914 +O2::GrantFlow O2::grantFlow()
0915 +{
0916      return grantFlow_;
0917  }
0918  
0919 -void O2::setGrantFlow(O2::GrantFlow value) {
0920 +void O2::setGrantFlow(O2::GrantFlow value)
0921 +{
0922      grantFlow_ = value;
0923      Q_EMIT grantFlowChanged();
0924  }
0925  
0926 -QString O2::username() {
0927 +QString O2::username()
0928 +{
0929      return username_;
0930  }
0931  
0932 -void O2::setUsername(const QString &value) {
0933 +void O2::setUsername(const QString &value)
0934 +{
0935      username_ = value;
0936      Q_EMIT usernameChanged();
0937  }
0938  
0939 -QString O2::password() {
0940 +QString O2::password()
0941 +{
0942      return password_;
0943  }
0944  
0945 -void O2::setPassword(const QString &value) {
0946 +void O2::setPassword(const QString &value)
0947 +{
0948      password_ = value;
0949      Q_EMIT passwordChanged();
0950  }
0951  
0952 -QString O2::scope() {
0953 +QString O2::scope()
0954 +{
0955      return scope_;
0956  }
0957  
0958 -void O2::setScope(const QString &value) {
0959 +void O2::setScope(const QString &value)
0960 +{
0961      scope_ = value;
0962      Q_EMIT scopeChanged();
0963  }
0964  
0965 -QString O2::requestUrl() {
0966 +QString O2::requestUrl()
0967 +{
0968      return requestUrl_.toString();
0969  }
0970  
0971 -void O2::setRequestUrl(const QString &value) {
0972 +void O2::setRequestUrl(const QString &value)
0973 +{
0974      requestUrl_ = value;
0975      Q_EMIT requestUrlChanged();
0976  }
0977  
0978 -QString O2::tokenUrl() {
0979 +QString O2::tokenUrl()
0980 +{
0981      return tokenUrl_.toString();
0982  }
0983  
0984 -void O2::setTokenUrl(const QString &value) {
0985 -    tokenUrl_= value;
0986 +void O2::setTokenUrl(const QString &value)
0987 +{
0988 +    tokenUrl_ = value;
0989      Q_EMIT tokenUrlChanged();
0990  }
0991  
0992 -QString O2::refreshTokenUrl() {
0993 +QString O2::refreshTokenUrl()
0994 +{
0995      return refreshTokenUrl_.toString();
0996  }
0997  
0998 -void O2::setRefreshTokenUrl(const QString &value) {
0999 +void O2::setRefreshTokenUrl(const QString &value)
1000 +{
1001      refreshTokenUrl_ = value;
1002      Q_EMIT refreshTokenUrlChanged();
1003  }
1004  
1005 -void O2::link() {
1006 +void O2::link()
1007 +{
1008      qDebug() << "O2::link";
1009  
1010      if (linked()) {
1011 @@ -164,7 +182,7 @@ void O2::link() {
1012  
1013          // Assemble intial authentication URL
1014          QList<QPair<QString, QString> > parameters;
1015 -        parameters.append(qMakePair(QString(O2_OAUTH2_RESPONSE_TYPE), (grantFlow_ == GrantFlowAuthorizationCode)? QString(O2_OAUTH2_GRANT_TYPE_CODE): QString(O2_OAUTH2_GRANT_TYPE_TOKEN)));
1016 +        parameters.append(qMakePair(QString(O2_OAUTH2_RESPONSE_TYPE), (grantFlow_ == GrantFlowAuthorizationCode) ? QString(O2_OAUTH2_GRANT_TYPE_CODE) : QString(O2_OAUTH2_GRANT_TYPE_TOKEN)));
1017          parameters.append(qMakePair(QString(O2_OAUTH2_CLIENT_ID), clientId_));
1018          parameters.append(qMakePair(QString(O2_OAUTH2_REDIRECT_URI), redirectUri_));
1019          parameters.append(qMakePair(QString(O2_OAUTH2_SCOPE), scope_));
1020 @@ -196,7 +214,8 @@ void O2::link() {
1021      }
1022  }
1023  
1024 -void O2::unlink() {
1025 +void O2::unlink()
1026 +{
1027      qDebug() << "O2::unlink";
1028      setLinked(false);
1029      setToken(QString());
1030 @@ -206,7 +225,8 @@ void O2::unlink() {
1031      Q_EMIT linkingSucceeded();
1032  }
1033  
1034 -void O2::onVerificationReceived(const QMap<QString, QString> response) {
1035 +void O2::onVerificationReceived(const QMap<QString, QString> response)
1036 +{
1037      qDebug() << "O2::onVerificationReceived:" << response;
1038      qDebug() << "O2::onVerificationReceived: Emitting closeBrowser()";
1039      Q_EMIT closeBrowser();
1040 @@ -223,8 +243,9 @@ void O2::onVerificationReceived(const QMap<QString, QString> response) {
1041  
1042          // Exchange access code for access/refresh tokens
1043          QString query;
1044 -        if(!apiKey_.isEmpty())
1045 +        if (!apiKey_.isEmpty()) {
1046              query = QString("?" + QString(O2_OAUTH2_API_KEY) + "=" + apiKey_);
1047 +        }
1048          QNetworkRequest tokenRequest(QUrl(tokenUrl_.toString() + query));
1049          tokenRequest.setHeader(QNetworkRequest::ContentTypeHeader, O2_MIME_TYPE_XFORM);
1050          QMap<QString, QString> parameters;
1051 @@ -244,17 +265,20 @@ void O2::onVerificationReceived(const QMap<QString, QString> response) {
1052      }
1053  }
1054  
1055 -QString O2::code() {
1056 +QString O2::code()
1057 +{
1058      QString key = QString(O2_KEY_CODE).arg(clientId_);
1059      return store_->value(key);
1060  }
1061  
1062 -void O2::setCode(const QString &c) {
1063 +void O2::setCode(const QString &c)
1064 +{
1065      QString key = QString(O2_KEY_CODE).arg(clientId_);
1066      store_->setValue(key, c);
1067  }
1068  
1069 -void O2::onTokenReplyFinished() {
1070 +void O2::onTokenReplyFinished()
1071 +{
1072      qDebug() << "O2::onTokenReplyFinished";
1073      QNetworkReply *tokenReply = qobject_cast<QNetworkReply *>(sender());
1074      if (tokenReply->error() == QNetworkReply::NoError) {
1075 @@ -283,7 +307,8 @@ void O2::onTokenReplyFinished() {
1076      tokenReply->deleteLater();
1077  }
1078  
1079 -void O2::onTokenReplyError(QNetworkReply::NetworkError error) {
1080 +void O2::onTokenReplyError(QNetworkReply::NetworkError error)
1081 +{
1082      QNetworkReply *tokenReply = qobject_cast<QNetworkReply *>(sender());
1083      qWarning() << "O2::onTokenReplyError: " << error << ": " << tokenReply->errorString();
1084      qDebug() << "O2::onTokenReplyError: " << tokenReply->readAll();
1085 @@ -293,7 +318,8 @@ void O2::onTokenReplyError(QNetworkReply::NetworkError error) {
1086      Q_EMIT linkingFailed();
1087  }
1088  
1089 -QByteArray O2::buildRequestBody(const QMap<QString, QString> &parameters) {
1090 +QByteArray O2::buildRequestBody(const QMap<QString, QString> &parameters)
1091 +{
1092      QByteArray body;
1093      bool first = true;
1094      foreach (QString key, parameters.keys()) {
1095 @@ -308,28 +334,33 @@ QByteArray O2::buildRequestBody(const QMap<QString, QString> &parameters) {
1096      return body;
1097  }
1098  
1099 -int O2::expires() {
1100 +int O2::expires()
1101 +{
1102      QString key = QString(O2_KEY_EXPIRES).arg(clientId_);
1103      return store_->value(key).toInt();
1104  }
1105  
1106 -void O2::setExpires(int v) {
1107 +void O2::setExpires(int v)
1108 +{
1109      QString key = QString(O2_KEY_EXPIRES).arg(clientId_);
1110      store_->setValue(key, QString::number(v));
1111  }
1112  
1113 -QString O2::refreshToken() {
1114 +QString O2::refreshToken()
1115 +{
1116      QString key = QString(O2_KEY_REFRESH_TOKEN).arg(clientId_);
1117      return store_->value(key);
1118  }
1119  
1120 -void O2::setRefreshToken(const QString &v) {
1121 +void O2::setRefreshToken(const QString &v)
1122 +{
1123      qDebug() << "O2::setRefreshToken" << v.left(4) << "...";
1124      QString key = QString(O2_KEY_REFRESH_TOKEN).arg(clientId_);
1125      store_->setValue(key, v);
1126  }
1127  
1128 -void O2::refresh() {
1129 +void O2::refresh()
1130 +{
1131      qDebug() << "O2::refresh: Token: ..." << refreshToken().right(7);
1132  
1133      if (refreshToken().isEmpty()) {
1134 @@ -358,7 +389,8 @@ void O2::refresh() {
1135      connect(refreshReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRefreshError(QNetworkReply::NetworkError)), Qt::QueuedConnection);
1136  }
1137  
1138 -void O2::onRefreshFinished() {
1139 +void O2::onRefreshFinished()
1140 +{
1141      QNetworkReply *refreshReply = qobject_cast<QNetworkReply *>(sender());
1142      qDebug() << "O2::onRefreshFinished: Error" << (int)refreshReply->error() << refreshReply->errorString();
1143      if (refreshReply->error() == QNetworkReply::NoError) {
1144 @@ -376,7 +408,8 @@ void O2::onRefreshFinished() {
1145      refreshReply->deleteLater();
1146  }
1147  
1148 -void O2::onRefreshError(QNetworkReply::NetworkError error) {
1149 +void O2::onRefreshError(QNetworkReply::NetworkError error)
1150 +{
1151      QNetworkReply *refreshReply = qobject_cast<QNetworkReply *>(sender());
1152      qWarning() << "O2::onRefreshError: " << error;
1153      unlink();
1154 @@ -384,34 +417,42 @@ void O2::onRefreshError(QNetworkReply::NetworkError error) {
1155      Q_EMIT refreshFinished(error);
1156  }
1157  
1158 -QString O2::localhostPolicy() const {
1159 +QString O2::localhostPolicy() const
1160 +{
1161      return localhostPolicy_;
1162  }
1163  
1164 -void O2::setLocalhostPolicy(const QString &value) {
1165 +void O2::setLocalhostPolicy(const QString &value)
1166 +{
1167      localhostPolicy_ = value;
1168  }
1169  
1170 -QString O2::apiKey() {
1171 +QString O2::apiKey()
1172 +{
1173      return apiKey_;
1174  }
1175  
1176 -void O2::setApiKey(const QString &value) {
1177 +void O2::setApiKey(const QString &value)
1178 +{
1179      apiKey_ = value;
1180  }
1181  
1182 -QByteArray O2::replyContent() {
1183 +QByteArray O2::replyContent()
1184 +{
1185      return replyServer_->replyContent();
1186  }
1187  
1188 -void O2::setReplyContent(const QByteArray &value) {
1189 +void O2::setReplyContent(const QByteArray &value)
1190 +{
1191      replyServer_->setReplyContent(value);
1192  }
1193  
1194 -bool O2::ignoreSslErrors() {
1195 +bool O2::ignoreSslErrors()
1196 +{
1197      return timedReplies_.ignoreSslErrors();
1198  }
1199  
1200 -void O2::setIgnoreSslErrors(bool ignoreSslErrors) {
1201 +void O2::setIgnoreSslErrors(bool ignoreSslErrors)
1202 +{
1203      timedReplies_.setIgnoreSslErrors(ignoreSslErrors);
1204  }
1205 diff --git a/src/o2.h b/src/o2.h
1206 index 250ea50..3f7591b 100644
1207 --- a/src/o2.h
1208 +++ b/src/o2.h
1209 @@ -13,7 +13,8 @@
1210  class O2ReplyServer;
1211  
1212  /// Simple OAuth2 authenticator.
1213 -class O2: public O0BaseAuth {
1214 +class O2: public O0BaseAuth
1215 +{
1216      Q_OBJECT
1217      Q_ENUMS(GrantFlow)
1218  
1219 diff --git a/src/o2reply.cpp b/src/o2reply.cpp
1220 index 4e03172..db8517a 100644
1221 --- a/src/o2reply.cpp
1222 +++ b/src/o2reply.cpp
1223 @@ -1,36 +1,43 @@
1224  #include <QTimer>
1225  #include <QNetworkReply>
1226  
1227 -#include "o2reply.h"
1228 +#include "o2/o2reply.h"
1229  
1230 -O2Reply::O2Reply(QNetworkReply *r, int timeOut, QObject *parent): QTimer(parent), reply(r) {
1231 +O2Reply::O2Reply(QNetworkReply *r, int timeOut, QObject *parent): QTimer(parent), reply(r)
1232 +{
1233      setSingleShot(true);
1234      connect(this, SIGNAL(error(QNetworkReply::NetworkError)), reply, SIGNAL(error(QNetworkReply::NetworkError)), Qt::QueuedConnection);
1235      connect(this, SIGNAL(timeout()), this, SLOT(onTimeOut()), Qt::QueuedConnection);
1236      start(timeOut);
1237  }
1238  
1239 -void O2Reply::onTimeOut() {
1240 +void O2Reply::onTimeOut()
1241 +{
1242      Q_EMIT error(QNetworkReply::TimeoutError);
1243  }
1244  
1245 -O2ReplyList::~O2ReplyList() {
1246 +O2ReplyList::~O2ReplyList()
1247 +{
1248      foreach (O2Reply *timedReply, replies_) {
1249          delete timedReply;
1250      }
1251  }
1252  
1253 -void O2ReplyList::add(QNetworkReply *reply) {
1254 -    if (reply && ignoreSslErrors())
1255 -            reply->ignoreSslErrors();
1256 +void O2ReplyList::add(QNetworkReply *reply)
1257 +{
1258 +    if (reply && ignoreSslErrors()) {
1259 +        reply->ignoreSslErrors();
1260 +    }
1261      add(new O2Reply(reply));
1262  }
1263  
1264 -void O2ReplyList::add(O2Reply *reply) {
1265 +void O2ReplyList::add(O2Reply *reply)
1266 +{
1267      replies_.append(reply);
1268  }
1269  
1270 -void O2ReplyList::remove(QNetworkReply *reply) {
1271 +void O2ReplyList::remove(QNetworkReply *reply)
1272 +{
1273      O2Reply *o2Reply = find(reply);
1274      if (o2Reply) {
1275          o2Reply->stop();
1276 @@ -38,7 +45,8 @@ void O2ReplyList::remove(QNetworkReply *reply) {
1277      }
1278  }
1279  
1280 -O2Reply *O2ReplyList::find(QNetworkReply *reply) {
1281 +O2Reply *O2ReplyList::find(QNetworkReply *reply)
1282 +{
1283      foreach (O2Reply *timedReply, replies_) {
1284          if (timedReply->reply == reply) {
1285              return timedReply;
1286 diff --git a/src/o2reply.h b/src/o2reply.h
1287 index 15f1571..4bfcd51 100644
1288 --- a/src/o2reply.h
1289 +++ b/src/o2reply.h
1290 @@ -9,7 +9,8 @@
1291  #include <QByteArray>
1292  
1293  /// A network request/reply pair that can time out.
1294 -class O2Reply: public QTimer {
1295 +class O2Reply: public QTimer
1296 +{
1297      Q_OBJECT
1298  
1299  public:
1300 @@ -27,9 +28,13 @@ public:
1301  };
1302  
1303  /// List of O2Replies.
1304 -class O2ReplyList {
1305 +class O2ReplyList
1306 +{
1307  public:
1308 -    O2ReplyList() { ignoreSslErrors_ = false; }
1309 +    O2ReplyList()
1310 +    {
1311 +        ignoreSslErrors_ = false;
1312 +    }
1313  
1314      /// Destructor.
1315      /// Deletes all O2Reply instances in the list.
1316 diff --git a/src/o2replyserver.cpp b/src/o2replyserver.cpp
1317 index 00dad96..b4c5da7 100644
1318 --- a/src/o2replyserver.cpp
1319 +++ b/src/o2replyserver.cpp
1320 @@ -11,20 +11,23 @@
1321  #include <QUrlQuery>
1322  #endif
1323  
1324 -#include "o2replyserver.h"
1325 +#include "o2/o2replyserver.h"
1326  
1327 -O2ReplyServer::O2ReplyServer(QObject *parent): QTcpServer(parent) {
1328 +O2ReplyServer::O2ReplyServer(QObject *parent): QTcpServer(parent)
1329 +{
1330      connect(this, SIGNAL(newConnection()), this, SLOT(onIncomingConnection()));
1331      replyContent_ = "<HTML></HTML>";
1332  }
1333  
1334 -void O2ReplyServer::onIncomingConnection() {
1335 +void O2ReplyServer::onIncomingConnection()
1336 +{
1337      QTcpSocket *socket = nextPendingConnection();
1338      connect(socket, SIGNAL(readyRead()), this, SLOT(onBytesReady()), Qt::UniqueConnection);
1339      connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
1340  }
1341  
1342 -void O2ReplyServer::onBytesReady() {
1343 +void O2ReplyServer::onBytesReady()
1344 +{
1345      qDebug() << "O2ReplyServer::onBytesReady";
1346      QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
1347      if (!socket) {
1348 @@ -44,7 +47,8 @@ void O2ReplyServer::onBytesReady() {
1349      Q_EMIT verificationReceived(queryParams);
1350  }
1351  
1352 -QMap<QString, QString> O2ReplyServer::parseQueryParams(QByteArray *data) {
1353 +QMap<QString, QString> O2ReplyServer::parseQueryParams(QByteArray *data)
1354 +{
1355      qDebug() << "O2ReplyServer::parseQueryParams";
1356  
1357      QString splitGetLine = QString(*data).split("\r\n").first();
1358 @@ -72,10 +76,12 @@ QMap<QString, QString> O2ReplyServer::parseQueryParams(QByteArray *data) {
1359      return queryParams;
1360  }
1361  
1362 -QByteArray O2ReplyServer::replyContent() {
1363 +QByteArray O2ReplyServer::replyContent()
1364 +{
1365      return replyContent_;
1366  }
1367  
1368 -void O2ReplyServer::setReplyContent(const QByteArray &value) {
1369 +void O2ReplyServer::setReplyContent(const QByteArray &value)
1370 +{
1371      replyContent_ = value;
1372  }
1373 diff --git a/src/o2replyserver.h b/src/o2replyserver.h
1374 index 5a9d2f2..f464126 100644
1375 --- a/src/o2replyserver.h
1376 +++ b/src/o2replyserver.h
1377 @@ -7,7 +7,8 @@
1378  #include <QString>
1379  
1380  /// HTTP server to process authentication response.
1381 -class O2ReplyServer: public QTcpServer {
1382 +class O2ReplyServer: public QTcpServer
1383 +{
1384      Q_OBJECT
1385  
1386  public:
1387 diff --git a/src/o2requestor.cpp b/src/o2requestor.cpp
1388 index d737d35..89248a5 100644
1389 --- a/src/o2requestor.cpp
1390 +++ b/src/o2requestor.cpp
1391 @@ -4,11 +4,12 @@
1392  #include <QUrlQuery>
1393  #endif
1394  
1395 -#include "o2requestor.h"
1396 -#include "o2.h"
1397 -#include "o0globals.h"
1398 +#include "o2/o2requestor.h"
1399 +#include "o2/o2.h"
1400 +#include "o2/o0globals.h"
1401  
1402 -O2Requestor::O2Requestor(QNetworkAccessManager *manager, O2 *authenticator, QObject *parent): QObject(parent), reply_(NULL), status_(Idle) {
1403 +O2Requestor::O2Requestor(QNetworkAccessManager *manager, O2 *authenticator, QObject *parent): QObject(parent), reply_(NULL), status_(Idle)
1404 +{
1405      manager_ = manager;
1406      authenticator_ = authenticator;
1407      if (authenticator) {
1408 @@ -18,10 +19,12 @@ O2Requestor::O2Requestor(QNetworkAccessManager *manager, O2 *authenticator, QObj
1409      connect(authenticator, SIGNAL(refreshFinished(QNetworkReply::NetworkError)), this, SLOT(onRefreshFinished(QNetworkReply::NetworkError)), Qt::QueuedConnection);
1410  }
1411  
1412 -O2Requestor::~O2Requestor() {
1413 +O2Requestor::~O2Requestor()
1414 +{
1415  }
1416  
1417 -int O2Requestor::get(const QNetworkRequest &req) {
1418 +int O2Requestor::get(const QNetworkRequest &req)
1419 +{
1420      if (-1 == setup(req, QNetworkAccessManager::GetOperation)) {
1421          return -1;
1422      }
1423 @@ -32,7 +35,8 @@ int O2Requestor::get(const QNetworkRequest &req) {
1424      return id_;
1425  }
1426  
1427 -int O2Requestor::post(const QNetworkRequest &req, const QByteArray &data) {
1428 +int O2Requestor::post(const QNetworkRequest &req, const QByteArray &data)
1429 +{
1430      if (-1 == setup(req, QNetworkAccessManager::PostOperation)) {
1431          return -1;
1432      }
1433 @@ -45,7 +49,8 @@ int O2Requestor::post(const QNetworkRequest &req, const QByteArray &data) {
1434      return id_;
1435  }
1436  
1437 -int O2Requestor::put(const QNetworkRequest &req, const QByteArray &data) {
1438 +int O2Requestor::put(const QNetworkRequest &req, const QByteArray &data)
1439 +{
1440      if (-1 == setup(req, QNetworkAccessManager::PutOperation)) {
1441          return -1;
1442      }
1443 @@ -58,7 +63,8 @@ int O2Requestor::put(const QNetworkRequest &req, const QByteArray &data) {
1444      return id_;
1445  }
1446  
1447 -void O2Requestor::onRefreshFinished(QNetworkReply::NetworkError error) {
1448 +void O2Requestor::onRefreshFinished(QNetworkReply::NetworkError error)
1449 +{
1450      if (status_ != Requesting) {
1451          qWarning() << "O2Requestor::onRefreshFinished: No pending request";
1452          return;
1453 @@ -71,7 +77,8 @@ void O2Requestor::onRefreshFinished(QNetworkReply::NetworkError error) {
1454      }
1455  }
1456  
1457 -void O2Requestor::onRequestFinished() {
1458 +void O2Requestor::onRequestFinished()
1459 +{
1460      QNetworkReply *senderReply = qobject_cast<QNetworkReply *>(sender());
1461      QNetworkReply::NetworkError error = senderReply->error();
1462      if (status_ == Idle) {
1463 @@ -85,7 +92,8 @@ void O2Requestor::onRequestFinished() {
1464      }
1465  }
1466  
1467 -void O2Requestor::onRequestError(QNetworkReply::NetworkError error) {
1468 +void O2Requestor::onRequestError(QNetworkReply::NetworkError error)
1469 +{
1470      qWarning() << "O2Requestor::onRequestError: Error" << (int)error;
1471      if (status_ == Idle) {
1472          return;
1473 @@ -107,7 +115,8 @@ void O2Requestor::onRequestError(QNetworkReply::NetworkError error) {
1474      QTimer::singleShot(10, this, SLOT(finish()));
1475  }
1476  
1477 -void O2Requestor::onUploadProgress(qint64 uploaded, qint64 total) {
1478 +void O2Requestor::onUploadProgress(qint64 uploaded, qint64 total)
1479 +{
1480      if (status_ == Idle) {
1481          qWarning() << "O2Requestor::onUploadProgress: No pending request";
1482          return;
1483 @@ -118,7 +127,8 @@ void O2Requestor::onUploadProgress(qint64 uploaded, qint64 total) {
1484      Q_EMIT uploadProgress(id_, uploaded, total);
1485  }
1486  
1487 -int O2Requestor::setup(const QNetworkRequest &req, QNetworkAccessManager::Operation operation) {
1488 +int O2Requestor::setup(const QNetworkRequest &req, QNetworkAccessManager::Operation operation)
1489 +{
1490      static int currentId;
1491      QUrl url;
1492  
1493 @@ -144,7 +154,8 @@ int O2Requestor::setup(const QNetworkRequest &req, QNetworkAccessManager::Operat
1494      return id_;
1495  }
1496  
1497 -void O2Requestor::finish() {
1498 +void O2Requestor::finish()
1499 +{
1500      QByteArray data;
1501      if (status_ == Idle) {
1502          qWarning() << "O2Requestor::finish: No pending request";
1503 @@ -158,7 +169,8 @@ void O2Requestor::finish() {
1504      Q_EMIT finished(id_, error_, data);
1505  }
1506  
1507 -void O2Requestor::retry() {
1508 +void O2Requestor::retry()
1509 +{
1510      if (status_ != Requesting) {
1511          qWarning() << "O2Requestor::retry: No pending request";
1512          return;
1513 diff --git a/src/o2requestor.h b/src/o2requestor.h
1514 index 939e598..fef7fc0 100644
1515 --- a/src/o2requestor.h
1516 +++ b/src/o2requestor.h
1517 @@ -8,12 +8,13 @@
1518  #include <QUrl>
1519  #include <QByteArray>
1520  
1521 -#include "o2reply.h"
1522 +#include "o2/o2reply.h"
1523  
1524  class O2;
1525  
1526  /// Makes authenticated requests.
1527 -class O2Requestor: public QObject {
1528 +class O2Requestor: public QObject
1529 +{
1530      Q_OBJECT
1531  
1532  public:
1533 diff --git a/src/o2simplecrypt.cpp b/src/o2simplecrypt.cpp
1534 index 210ae12..4a8584c 100644
1535 --- a/src/o2simplecrypt.cpp
1536 +++ b/src/o2simplecrypt.cpp
1537 @@ -24,7 +24,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1538  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1539  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1540  */
1541 -#include "o0simplecrypt.h"
1542 +#include "o2/o0simplecrypt.h"
1543  #include <QByteArray>
1544   @@ -61,16 +61,17 @@ void O0SimpleCrypt::splitKey()
1545  {
1546      m_keyParts.clear();
1547      m_keyParts.resize(8);
1548 -    for (int i=0;i<8;i++) {
1549 +    for (int i = 0; i < 8; i++) {
1550          quint64 part = m_key;
1551 -        for (int j=i; j>0; j--)
1552 +        for (int j = i; j > 0; j--) {
1553              part = part >> 8;
1554 +        }
1555          part = part & 0xff;
1556          m_keyParts[i] = static_cast<char>(part);
1557      }
1558  }
1559  
1560 -QByteArray O0SimpleCrypt::encryptToByteArray(const QString& plaintext)
1561 +QByteArray O0SimpleCrypt::encryptToByteArray(const QString &plaintext)
1562  {
1563      QByteArray plaintextArray = plaintext.toUtf8();
1564      return encryptToByteArray(plaintextArray);
1565 @@ -84,7 +85,6 @@ QByteArray O0SimpleCrypt::encryptToByteArray(QByteArray plaintext)
1566          return QByteArray();
1567      }
1568  
1569 -
1570      QByteArray ba = plaintext;
1571  
1572      CryptoFlags flags = CryptoFlagNone;
1573 @@ -136,7 +136,7 @@ QByteArray O0SimpleCrypt::encryptToByteArray(QByteArray plaintext)
1574      return resultArray;
1575  }
1576  
1577 -QString O0SimpleCrypt::encryptToString(const QString& plaintext)
1578 +QString O0SimpleCrypt::encryptToString(const QString &plaintext)
1579  {
1580      QByteArray plaintextArray = plaintext.toUtf8();
1581      QByteArray cypher = encryptToByteArray(plaintextArray);
1582 @@ -168,7 +168,7 @@ QString O0SimpleCrypt::decryptToString(QByteArray cypher)
1583      return plaintext;
1584  }
1585  
1586 -QByteArray O0SimpleCrypt::decryptToByteArray(const QString& cyphertext)
1587 +QByteArray O0SimpleCrypt::decryptToByteArray(const QString &cyphertext)
1588  {
1589      QByteArray cyphertextArray = QByteArray::fromBase64(cyphertext.toLatin1());
1590      QByteArray ba = decryptToByteArray(cyphertextArray);
1591 @@ -193,7 +193,7 @@ QByteArray O0SimpleCrypt::decryptToByteArray(QByteArray cypher)
1592  
1593      char version = ba.at(0);
1594  
1595 -    if (version !=3) {  //we only work with version 3
1596 +    if (version != 3) { //we only work with version 3
1597          m_lastError = ErrorUnknownVersion;
1598          qWarning() << "Invalid version or not a cyphertext.";
1599          return QByteArray();
1600 @@ -246,8 +246,9 @@ QByteArray O0SimpleCrypt::decryptToByteArray(QByteArray cypher)
1601          return QByteArray();
1602      }
1603  
1604 -    if (flags.testFlag(CryptoFlagCompression))
1605 +    if (flags.testFlag(CryptoFlagCompression)) {
1606          ba = qUncompress(ba);
1607 +    }
1608  
1609      m_lastError = ErrorNoError;
1610      return ba;