Quota: handle special negative value for the quota #3940
authorOlivier Goffart <ogoffart@woboq.com>
Thu, 29 Oct 2015 13:33:29 +0000 (14:33 +0100)
committerOlivier Goffart <ogoffart@woboq.com>
Thu, 29 Oct 2015 13:33:29 +0000 (14:33 +0100)
Don't show a progress bar if there is an unkown or unlimited total

src/gui/accountsettings.cpp
src/gui/quotainfo.cpp

index 962cddda7834f3cf64be84007ae4e41853534949..fa3d7ae88e3703fb82cdc14ccebacf3530e0ed57 100644 (file)
@@ -455,7 +455,15 @@ void AccountSettings::slotUpdateQuota(qint64 total, qint64 used)
         ui->quotaProgressBar->setToolTip(toolTip);
     } else {
         ui->quotaProgressBar->setVisible(false);
-        ui->quotaInfoLabel->setText(tr("Currently there is no storage usage information available."));
+        ui->quotaInfoLabel->setToolTip(QString());
+
+        /* -1 means not computed; -2 means unknown; -3 means unlimited  (#3940)*/
+        if (total == 0 || total == -1) {
+            ui->quotaInfoLabel->setText(tr("Currently there is no storage usage information available."));
+        } else {
+            QString usedStr = Utility::octetsToString(used);
+            ui->quotaInfoLabel->setText(tr("%1 in use").arg(usedStr));
+        }
     }
 }
 
index 49c188bdd8ba3fe40b647970f7195b038db19f8b..02d5dfdc4b28755b40b3ef4b944c17568371af91 100644 (file)
@@ -102,9 +102,10 @@ void QuotaInfo::slotUpdateLastQuota(const QVariantMap &result)
 {
     // The server can return fractional bytes (#1374)
     // <d:quota-available-bytes>1374532061.2</d:quota-available-bytes>
-    quint64 avail = result["quota-available-bytes"].toDouble();
+    qint64 avail = result["quota-available-bytes"].toDouble();
     _lastQuotaUsedBytes = result["quota-used-bytes"].toDouble();
-    _lastQuotaTotalBytes = _lastQuotaUsedBytes + avail;
+    // negative value of the available quota have special meaning (#3940)
+    _lastQuotaTotalBytes = avail >= 0 ? _lastQuotaUsedBytes + avail : avail;
     emit quotaUpdated(_lastQuotaTotalBytes, _lastQuotaUsedBytes);
     _jobRestartTimer.start(defaultIntervalT);
     _lastQuotaRecieved = QDateTime::currentDateTime();