2013-11-07 13:14:38 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2014-02-20 20:00:45 +04:00
|
|
|
#ifndef QUOTAINFO_H
|
|
|
|
#define QUOTAINFO_H
|
|
|
|
|
2013-11-07 13:14:38 +04:00
|
|
|
#include <QObject>
|
|
|
|
#include <QPointer>
|
2015-06-25 15:28:15 +03:00
|
|
|
#include <QVariant>
|
2015-06-26 16:40:34 +03:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QDateTime>
|
2013-11-07 13:14:38 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2014-12-17 16:09:57 +03:00
|
|
|
class AccountState;
|
2015-06-26 17:58:34 +03:00
|
|
|
class PropfindJob;
|
2013-11-07 13:14:38 +04:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief handles getting the quota to display in the UI
|
2015-06-29 19:45:55 +03:00
|
|
|
*
|
2015-06-26 16:40:34 +03:00
|
|
|
* It is typically owned by the AccountSetting page.
|
|
|
|
*
|
2015-10-05 07:21:19 +03:00
|
|
|
* The quota is requested if these 3 conditions are met:
|
2015-06-26 16:40:34 +03:00
|
|
|
* - This object is active via setActive() (typically if the settings page is visible.)
|
|
|
|
* - The account is connected.
|
|
|
|
* - Every 30 seconds (defaultIntervalT) or 5 seconds in case of failure (failIntervalT)
|
|
|
|
*
|
|
|
|
* We only request the quota when the UI is visible otherwise this might slow down the server with
|
|
|
|
* too many requests. But we still need to do it every 30 seconds otherwise user complains that the
|
|
|
|
* quota is not updated fast enough when changed on the server.
|
2015-06-29 11:57:32 +03:00
|
|
|
*
|
|
|
|
* If the quota job is not finished within 30 seconds, it is cancelled and another one is started
|
2015-06-29 19:45:55 +03:00
|
|
|
*
|
2015-06-29 19:56:09 +03:00
|
|
|
* @ingroup gui
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2013-11-07 13:14:38 +04:00
|
|
|
class QuotaInfo : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-06-26 16:40:34 +03:00
|
|
|
explicit QuotaInfo(OCC::AccountState* accountState, QObject* parent = 0);
|
2013-11-07 13:14:38 +04:00
|
|
|
|
|
|
|
qint64 lastQuotaTotalBytes() const { return _lastQuotaTotalBytes; }
|
|
|
|
qint64 lastQuotaUsedBytes() const { return _lastQuotaUsedBytes; }
|
|
|
|
|
2015-06-26 16:40:34 +03:00
|
|
|
/**
|
|
|
|
* When the quotainfo is active, it requests the quota at regular interval.
|
2015-10-05 07:21:19 +03:00
|
|
|
* When setting it to active it will request the quota immediately if the last time
|
2015-06-26 16:40:34 +03:00
|
|
|
* the quota was requested was more than the interval
|
|
|
|
*/
|
|
|
|
void setActive(bool active);
|
|
|
|
|
2013-11-07 13:14:38 +04:00
|
|
|
public Q_SLOTS:
|
|
|
|
void slotCheckQuota();
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2015-06-25 15:28:15 +03:00
|
|
|
void slotUpdateLastQuota(const QVariantMap &);
|
2015-06-26 16:40:34 +03:00
|
|
|
void slotAccountStateChanged();
|
2013-12-12 13:53:51 +04:00
|
|
|
void slotRequestFailed();
|
2013-11-07 13:14:38 +04:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void quotaUpdated(qint64 total, qint64 used);
|
|
|
|
|
|
|
|
private:
|
2015-02-12 17:16:10 +03:00
|
|
|
bool canGetQuota() const;
|
|
|
|
|
2016-03-17 17:33:37 +03:00
|
|
|
/// Returns the folder that quota shall be retrieved for
|
|
|
|
QString quotaBaseFolder() const;
|
|
|
|
|
2014-12-17 16:09:57 +03:00
|
|
|
QPointer<AccountState> _accountState;
|
2013-11-07 13:14:38 +04:00
|
|
|
qint64 _lastQuotaTotalBytes;
|
|
|
|
qint64 _lastQuotaUsedBytes;
|
2015-06-26 16:40:34 +03:00
|
|
|
QTimer _jobRestartTimer;
|
2015-10-05 07:21:19 +03:00
|
|
|
QDateTime _lastQuotaRecieved; // the time at which the quota was received last
|
2015-06-26 16:40:34 +03:00
|
|
|
bool _active; // if we should check at regular interval (when the UI is visible)
|
2015-06-26 17:58:34 +03:00
|
|
|
QPointer<PropfindJob> _job; // the currently running job
|
2013-11-07 13:14:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|
2014-02-20 20:00:45 +04:00
|
|
|
|
|
|
|
#endif //QUOTAINFO_H
|