nextcloud-desktop/src/gui/quotainfo.h

83 lines
2.6 KiB
C
Raw Normal View History

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.
*/
#ifndef QUOTAINFO_H
#define QUOTAINFO_H
2013-11-07 13:14:38 +04:00
#include <QObject>
#include <QPointer>
#include <QVariant>
#include <QTimer>
#include <QDateTime>
2013-11-07 13:14:38 +04:00
2014-11-10 00:34:07 +03:00
namespace OCC {
class AccountState;
class PropfindJob;
2013-11-07 13:14:38 +04:00
/**
* This class handle the getting the quota to display in the UI
* It is typically owned by the AccountSetting page.
*
* The quota is requested if those 3 conditions are met:
* - 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.
*/
2013-11-07 13:14:38 +04:00
class QuotaInfo : public QObject {
Q_OBJECT
public:
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; }
/**
* When the quotainfo is active, it requests the quota at regular interval.
* When setting it to active it will request the quota imediatly if the last time
* 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:
void slotUpdateLastQuota(const QVariantMap &);
void slotAccountStateChanged();
void slotRequestFailed();
2013-11-07 13:14:38 +04:00
Q_SIGNALS:
void quotaUpdated(qint64 total, qint64 used);
private:
bool canGetQuota() const;
QPointer<AccountState> _accountState;
2013-11-07 13:14:38 +04:00
qint64 _lastQuotaTotalBytes;
qint64 _lastQuotaUsedBytes;
QTimer _jobRestartTimer;
QDateTime _lastQuotaRecieved; // the time at which de quota was recieved last
bool _active; // if we should check at regular interval (when the UI is visible)
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
#endif //QUOTAINFO_H