2013-11-07 13:14:38 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
2020-10-15 03:15:42 +03:00
|
|
|
* Copyright (C) by Michael Schuster <michael@schuster.ms>
|
2013-11-07 13:14:38 +04:00
|
|
|
*
|
|
|
|
* 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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-11-07 13:14:38 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2020-02-14 04:10:01 +03:00
|
|
|
#ifndef USERINFO_H
|
|
|
|
#define USERINFO_H
|
2014-02-20 20:00:45 +04:00
|
|
|
|
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;
|
2020-02-14 04:10:01 +03:00
|
|
|
class JsonApiJob;
|
2013-11-07 13:14:38 +04:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
2020-02-14 04:10:01 +03:00
|
|
|
* @brief handles getting the user info and 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.
|
|
|
|
*
|
2020-02-14 04:10:01 +03:00
|
|
|
* The user info and 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)
|
|
|
|
*
|
2020-02-14 04:10:01 +03:00
|
|
|
* We only request the info when the UI is visible otherwise this might slow down the server with
|
2015-06-26 16:40:34 +03:00
|
|
|
* 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
|
|
|
*
|
2020-02-14 04:10:01 +03:00
|
|
|
* If the fetch job is not finished within 30 seconds, it is cancelled and another one is started
|
|
|
|
*
|
|
|
|
* Constructor notes:
|
|
|
|
* - allowDisconnectedAccountState: set to true if you want to ignore AccountState's isConnected() state,
|
|
|
|
* this is used by ConnectionValidator (prior having a valid AccountState).
|
|
|
|
* - fetchAvatarImage: set to false if you don't want to fetch the avatar image
|
2015-06-29 19:45:55 +03:00
|
|
|
*
|
2015-06-29 19:56:09 +03:00
|
|
|
* @ingroup gui
|
2020-02-14 04:10:01 +03:00
|
|
|
*
|
|
|
|
* Here follows the state machine
|
|
|
|
|
|
|
|
\code{.unparsed}
|
|
|
|
*---> slotFetchInfo
|
|
|
|
JsonApiJob (ocs/v1.php/cloud/user)
|
|
|
|
|
|
|
|
|
+-> slotUpdateLastInfo
|
|
|
|
AvatarJob (if _fetchAvatarImage is true)
|
|
|
|
|
|
|
|
|
+-> slotAvatarImage -->
|
|
|
|
+-----------------------------------+
|
|
|
|
|
|
|
|
|
+-> Client Side Encryption Checks --+ --reportResult()
|
|
|
|
\endcode
|
|
|
|
*/
|
|
|
|
class UserInfo : public QObject
|
2013-11-07 13:14:38 +04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-02-14 04:10:01 +03:00
|
|
|
explicit UserInfo(OCC::AccountState *accountState, bool allowDisconnectedAccountState, bool fetchAvatarImage, QObject *parent = nullptr);
|
2013-11-07 13:14:38 +04:00
|
|
|
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] qint64 lastQuotaTotalBytes() const { return _lastQuotaTotalBytes; }
|
|
|
|
[[nodiscard]] qint64 lastQuotaUsedBytes() const { return _lastQuotaUsedBytes; }
|
2013-11-07 13:14:38 +04:00
|
|
|
|
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:
|
2020-02-14 04:10:01 +03:00
|
|
|
void slotFetchInfo();
|
2013-11-07 13:14:38 +04:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
2020-02-14 04:10:01 +03:00
|
|
|
void slotUpdateLastInfo(const QJsonDocument &json);
|
2015-06-26 16:40:34 +03:00
|
|
|
void slotAccountStateChanged();
|
2013-12-12 13:53:51 +04:00
|
|
|
void slotRequestFailed();
|
2020-02-14 04:10:01 +03:00
|
|
|
void slotAvatarImage(const QImage &img);
|
2013-11-07 13:14:38 +04:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void quotaUpdated(qint64 total, qint64 used);
|
2022-10-24 17:00:50 +03:00
|
|
|
void fetchedLastInfo(OCC::UserInfo *userInfo);
|
2013-11-07 13:14:38 +04:00
|
|
|
|
|
|
|
private:
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] bool canGetInfo() const;
|
2016-03-17 17:33:37 +03:00
|
|
|
|
2014-12-17 16:09:57 +03:00
|
|
|
QPointer<AccountState> _accountState;
|
2020-02-14 04:10:01 +03:00
|
|
|
bool _allowDisconnectedAccountState;
|
|
|
|
bool _fetchAvatarImage;
|
|
|
|
|
2023-02-06 12:38:59 +03:00
|
|
|
qint64 _lastQuotaTotalBytes = 0;
|
|
|
|
qint64 _lastQuotaUsedBytes = 0;
|
2015-06-26 16:40:34 +03:00
|
|
|
QTimer _jobRestartTimer;
|
2020-02-14 04:10:01 +03:00
|
|
|
QDateTime _lastInfoReceived; // the time at which the user info and quota was received last
|
2023-02-06 12:38:59 +03:00
|
|
|
bool _active = false; // if we should check at regular interval (when the UI is visible)
|
2020-02-14 04:10:01 +03:00
|
|
|
QPointer<JsonApiJob> _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
|
|
|
|
2020-02-14 04:10:01 +03:00
|
|
|
#endif //USERINFO_H
|