Account server version: Helper to create versions
authorChristian Kamm <mail@ckamm.de>
Tue, 14 Mar 2017 14:57:57 +0000 (15:57 +0100)
committerMarkus Goetz <markus@woboq.com>
Wed, 15 Mar 2017 15:30:08 +0000 (16:30 +0100)
Hex literals don't work well with version 10: 0x100000 doesn't do
the right thing.

src/gui/creds/httpcredentialsgui.cpp
src/gui/sharedialog.cpp
src/gui/sharemanager.cpp
src/gui/shareusergroupwidget.cpp
src/gui/socketapi.cpp
src/libsync/account.cpp
src/libsync/account.h
src/libsync/propagatedownload.cpp
src/libsync/propagateuploadv1.cpp
src/libsync/syncengine.cpp

index 6f84f4bf576df2827095737a204acc4d8d43be23..26ad6ec8b67958f1f8dfea415d4561210c182f49 100644 (file)
@@ -70,13 +70,14 @@ void HttpCredentialsGui::askFromUserAsync()
 
 QString HttpCredentialsGui::requestAppPasswordText(const Account* account)
 {
-    if (account->serverVersionInt() < 0x090100) {
-        // Older server than 9.1 does not have trhe feature to request App Password
+    if (account->serverVersionInt() < Account::makeServerVersion(9, 1, 0)) {
+        // Older server than 9.1 does not have the feature to request App Password
         return QString();
     }
 
+    QString path = QLatin1String("/index.php/settings/personal?section=apppasswords");
     return tr("<a href=\"%1\">Click here</a> to request an app password from the web interface.")
-        .arg(account->url().toString() + QLatin1String("/index.php/settings/personal?section=apppasswords"));
+        .arg(account->url().toString() + path);
 }
 
 
index 831807da81ef39e6b1fa439f914ebda3fc56ce99..7506e4f920873ae9c16796c488a5219049dadefc 100644 (file)
@@ -176,7 +176,7 @@ void ShareDialog::showSharingUi()
     // We only do user/group sharing from 8.2.0
     bool userGroupSharing =
             theme->userGroupSharing()
-            && _accountState->account()->serverVersionInt() >= ((8 << 16) + (2 << 8));
+            && _accountState->account()->serverVersionInt() >= Account::makeServerVersion(8, 2, 0);
 
     bool autoShare = !userGroupSharing;
 
index 08f2092d5bdc02b2251ad0f0d71ccc84eb9c5378..7b6032bbb2a70efdb2b25fcdeb3c07c51e3e377c 100644 (file)
@@ -343,7 +343,7 @@ QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QVariantMap &data)
     // From ownCloud server 8.2 the url field is always set for public shares
     if (data.contains("url")) {
         url = QUrl(data.value("url").toString());
-    } else if (_account->serverVersionInt() >= (8 << 16)) {
+    } else if (_account->serverVersionInt() >= Account::makeServerVersion(8, 0, 0)) {
         // From ownCloud server version 8 on, a different share link scheme is used.
         url = QUrl(Utility::concatUrlPath(_account->url(), QLatin1String("index.php/s/") + data.value("token").toString())).toString();
     } else {
index c1b798e5b35efad54a121e4bff19473780446316..e339d6a1c374fb71abc0e0a446fcaa75cfa6df4b 100644 (file)
@@ -254,7 +254,7 @@ void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex & index)
      * https://github.com/owncloud/client/issues/4996
      */
     if (sharee->type() == Sharee::Federated
-            && _account->serverVersionInt() < 0x090100) {
+            && _account->serverVersionInt() < Account::makeServerVersion(9, 1, 0)) {
         int permissions = SharePermissionRead | SharePermissionUpdate;
         if (!_isFile) {
             permissions |= SharePermissionCreate | SharePermissionDelete;
@@ -343,7 +343,7 @@ ShareWidget::ShareWidget(QSharedPointer<Share> share,
      * https://github.com/owncloud/client/issues/4996
      */
     if (share->getShareType() == Share::TypeRemote
-            && share->account()->serverVersionInt() < 0x090100) {
+            && share->account()->serverVersionInt() < Account::makeServerVersion(9, 1, 0)) {
         _ui->permissionShare->setVisible(false);
         _ui->permissionToolButton->setVisible(false);
     }
index dac1e0f6d46a625da25df922c2b88aa445b79dd8..361c7a34f53477bf5405b1fb069dbda76e7728ad 100644 (file)
@@ -404,7 +404,7 @@ void SocketApi::command_SHARE(const QString& localFile, SocketListener* listener
         listener->sendMessage(message);
     } else if (!theme->linkSharing() && (
                  !theme->userGroupSharing() ||
-                 shareFolder->accountState()->account()->serverVersionInt() < ((8 << 16) + (2 << 8)))) {
+                 shareFolder->accountState()->account()->serverVersionInt() < Account::makeServerVersion(8, 2, 0))) {
         const QString message = QLatin1String("SHARE:NOP:")+QDir::toNativeSeparators(localFile);
         listener->sendMessage(message);
     } else {
index 2918d2a39200c3670262d2b1511d1d4bab3b0bdc..b926094598ee08ea68e51c6ad9d461ed06474bdd 100644 (file)
@@ -396,9 +396,14 @@ int Account::serverVersionInt() const
 {
     // FIXME: Use Qt 5.5 QVersionNumber
     auto components = serverVersion().split('.');
-    return  (components.value(0).toInt() << 16)
-                   + (components.value(1).toInt() << 8)
-            + components.value(2).toInt();
+    return makeServerVersion(components.value(0).toInt(),
+                             components.value(1).toInt(),
+                             components.value(2).toInt());
+}
+
+int Account::makeServerVersion(int majorVersion, int minorVersion, int patchVersion)
+{
+    return (majorVersion << 16) + (minorVersion << 8) + patchVersion;
 }
 
 bool Account::serverVersionUnsupported() const
@@ -407,7 +412,7 @@ bool Account::serverVersionUnsupported() const
         // not detected yet, assume it is fine.
         return false;
     }
-    return serverVersionInt() < 0x070000;
+    return serverVersionInt() < makeServerVersion(7, 0, 0);
 }
 
 void Account::setServerVersion(const QString& version)
@@ -423,7 +428,7 @@ void Account::setServerVersion(const QString& version)
 
 bool Account::rootEtagChangesNotOnlySubFolderEtags()
 {
-    return (serverVersionInt() >= 0x080100);
+    return (serverVersionInt() >= makeServerVersion(8, 1, 0));
 }
 
 void Account::setNonShib(bool nonShib)
index 5e5ab4944391ea21a80074c2571701b2801a480b..e081121b3f6bbe37f99a4ef0331f5d0ecd75fca7 100644 (file)
@@ -148,6 +148,7 @@ public:
     /** Access the server version */
     QString serverVersion() const;
     int serverVersionInt() const;
+    static int makeServerVersion(int majorVersion, int minorVersion, int patchVersion);
     void setServerVersion(const QString &version);
 
     /** Whether the server is too old.
index 51a3ab319eac19268f79e8f17f84403d709dba00..f5bc11f5e98501b590bda5273fa437cf3b2c480a 100644 (file)
@@ -767,7 +767,7 @@ void PropagateDownloadFile::downloadFinished()
     // Apply the remote permissions
     // Older server versions sometimes provide empty remote permissions
     // see #4450 - don't adjust the write permissions there.
-    const int serverVersionGoodRemotePerm = 0x070000; // 7.0.0
+    const int serverVersionGoodRemotePerm = Account::makeServerVersion(7, 0, 0);
     if (propagator()->account()->serverVersionInt() >= serverVersionGoodRemotePerm) {
         FileSystem::setFileReadOnlyWeak(_tmpFile.fileName(),
                                         !_item->_remotePerm.contains('W'));
index 916dcdcf9e6cd1b648d1263bd718f9cea8364f21..612aab004c57be057fa846aec0f167df5f29a925 100644 (file)
@@ -145,7 +145,7 @@ void PropagateUploadFileV1::startNextChunk()
             parallelChunkUpload = env != "false" && env != "0";
         } else {
             int versionNum = propagator()->account()->serverVersionInt();
-            if (versionNum < 0x080003) {
+            if (versionNum < Account::makeServerVersion(8, 0, 3)) {
                 // Disable parallel chunk upload severs older than 8.0.3 to avoid too many
                 // internal sever errors (#2743, #2938)
                 parallelChunkUpload = false;
index 333fdd9e7f9b8e1bd3ef5fbcde9bd7a3b49ae00f..047732d485a6af8f05a008496c4f9ac4b500672a 100644 (file)
@@ -930,7 +930,7 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
     }
 
     // Check for invalid character in old server version
-    if (_account->serverVersionInt() < 0x080100) {
+    if (_account->serverVersionInt() < Account::makeServerVersion(8, 1, 0)) {
         // Server version older than 8.1 don't support these character in filename.
         static const QRegExp invalidCharRx("[\\\\:?*\"<>|]");
         for (auto it = syncItems.begin(); it != syncItems.end(); ++it) {
@@ -961,7 +961,8 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
             && _discoveryMainThread->_dataFingerprint != databaseFingerprint) {
         qDebug() << "data fingerprint changed, assume restore from backup" << databaseFingerprint << _discoveryMainThread->_dataFingerprint;
         restoreOldFiles(syncItems);
-    } else if (!_hasForwardInTimeFiles && _backInTimeFiles >= 2 && _account->serverVersionInt() < 0x090100) {
+    } else if (!_hasForwardInTimeFiles && _backInTimeFiles >= 2
+               && _account->serverVersionInt() < Account::makeServerVersion(9, 1, 0)) {
         // The server before ownCloud 9.1 did not have the data-fingerprint property. So in that
         // case we use heuristics to detect restored backup.  This is disabled with newer version
         // because this causes troubles to the user and is not as reliable as the data-fingerprint.