2014-12-17 16:09:57 +03: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
|
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.
|
2014-12-17 16:09:57 +03: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ACCOUNTINFO_H
|
|
|
|
#define ACCOUNTINFO_H
|
|
|
|
|
|
|
|
#include <QByteArray>
|
2017-08-16 09:36:52 +03:00
|
|
|
#include <QElapsedTimer>
|
2015-05-15 13:26:23 +03:00
|
|
|
#include <QPointer>
|
2014-12-17 16:09:57 +03:00
|
|
|
#include "connectionvalidator.h"
|
2015-09-05 16:39:22 +03:00
|
|
|
#include "creds/abstractcredentials.h"
|
2015-06-15 16:04:39 +03:00
|
|
|
#include <memory>
|
2014-12-17 16:09:57 +03:00
|
|
|
|
2015-06-15 16:04:39 +03:00
|
|
|
class QSettings;
|
2014-12-17 16:09:57 +03:00
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
|
|
|
class AccountState;
|
|
|
|
class Account;
|
|
|
|
|
2016-03-16 21:07:40 +03:00
|
|
|
typedef QExplicitlySharedDataPointer<AccountState> AccountStatePtr;
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief Extra info about an ownCloud server account.
|
|
|
|
* @ingroup gui
|
2014-12-17 16:09:57 +03:00
|
|
|
*/
|
2016-03-16 21:07:40 +03:00
|
|
|
class AccountState : public QObject, public QSharedData
|
|
|
|
{
|
2014-12-17 16:09:57 +03:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum State {
|
|
|
|
/// Not even attempting to connect, most likely because the
|
|
|
|
/// user explicitly signed out or cancelled a credential dialog.
|
|
|
|
SignedOut,
|
|
|
|
|
|
|
|
/// Account would like to be connected but hasn't heard back yet.
|
|
|
|
Disconnected,
|
|
|
|
|
|
|
|
/// The account is successfully talking to the server.
|
|
|
|
Connected,
|
|
|
|
|
2015-04-24 12:32:47 +03:00
|
|
|
/// There's a temporary problem with talking to the server,
|
|
|
|
/// don't bother the user too much and try again.
|
|
|
|
ServiceUnavailable,
|
2015-02-25 11:49:39 +03:00
|
|
|
|
2017-05-08 13:39:08 +03:00
|
|
|
/// Similar to ServiceUnavailable, but we know the server is down
|
|
|
|
/// for maintenance
|
|
|
|
MaintenanceMode,
|
|
|
|
|
2014-12-17 16:09:57 +03:00
|
|
|
/// Could not communicate with the server for some reason.
|
|
|
|
/// We assume this may resolve itself over time and will try
|
|
|
|
/// again automatically.
|
|
|
|
NetworkError,
|
|
|
|
|
2017-07-13 12:27:02 +03:00
|
|
|
/// Server configuration error. (For example: unsupported version)
|
|
|
|
ConfigurationError,
|
|
|
|
|
|
|
|
/// We are currently asking the user for credentials
|
|
|
|
AskingCredentials
|
2014-12-17 16:09:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// The actual current connectivity status.
|
|
|
|
typedef ConnectionValidator::Status ConnectionStatus;
|
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
/// Use the account as parent
|
2016-03-01 18:08:23 +03:00
|
|
|
explicit AccountState(AccountPtr account);
|
2014-12-17 16:09:57 +03:00
|
|
|
~AccountState();
|
|
|
|
|
2016-03-01 18:08:23 +03:00
|
|
|
/** Creates an account state from settings and an Account object.
|
|
|
|
*
|
|
|
|
* Use from AccountManager with a prepared QSettings object only.
|
|
|
|
*/
|
|
|
|
static AccountState *loadFromSettings(AccountPtr account, QSettings &settings);
|
|
|
|
|
|
|
|
/** Writes account state information to settings.
|
|
|
|
*
|
|
|
|
* It does not write the Account data.
|
|
|
|
*/
|
|
|
|
void writeToSettings(QSettings &settings);
|
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
AccountPtr account() const;
|
2014-12-17 16:09:57 +03:00
|
|
|
|
|
|
|
ConnectionStatus connectionStatus() const;
|
|
|
|
QStringList connectionErrors() const;
|
|
|
|
static QString connectionStatusString(ConnectionStatus status);
|
|
|
|
|
|
|
|
State state() const;
|
2015-07-01 13:30:18 +03:00
|
|
|
static QString stateString(State state);
|
2014-12-17 16:09:57 +03:00
|
|
|
|
|
|
|
bool isSignedOut() const;
|
2015-12-09 13:06:28 +03:00
|
|
|
|
|
|
|
/** A user-triggered sign out which disconnects, stops syncs
|
|
|
|
* for the account and forgets the password. */
|
|
|
|
void signOutByUi();
|
|
|
|
|
2017-11-05 21:50:09 +03:00
|
|
|
/** Tries to connect from scratch.
|
|
|
|
*
|
|
|
|
* Does nothing for signed out accounts.
|
|
|
|
* Connected accounts will be disconnected and try anew.
|
|
|
|
* Disconnected accounts will go to checkConnectivity().
|
|
|
|
*
|
|
|
|
* Useful for when network settings (proxy) change.
|
|
|
|
*/
|
|
|
|
void freshConnectionAttempt();
|
|
|
|
|
2015-12-09 13:06:28 +03:00
|
|
|
/// Move from SignedOut state to Disconnected (attempting to connect)
|
|
|
|
void signIn();
|
2014-12-17 16:09:57 +03:00
|
|
|
|
|
|
|
bool isConnected() const;
|
|
|
|
|
2015-06-15 16:04:39 +03:00
|
|
|
/** Returns a new settings object for this account, already in the right groups. */
|
2015-07-02 14:31:42 +03:00
|
|
|
std::unique_ptr<QSettings> settings();
|
2015-06-15 16:04:39 +03:00
|
|
|
|
2015-10-19 12:50:26 +03:00
|
|
|
/** Mark the timestamp when the last successful ETag check happened for
|
|
|
|
* this account.
|
|
|
|
* The checkConnectivity() method uses the timestamp to save a call to
|
|
|
|
* the server to validate the connection if the last successful etag job
|
2015-11-19 08:17:15 +03:00
|
|
|
* was not so long ago.
|
2015-10-19 12:50:26 +03:00
|
|
|
*/
|
|
|
|
void tagLastSuccessfullETagRequest();
|
|
|
|
|
2018-03-02 00:19:04 +03:00
|
|
|
/** Saves the ETag Response header from the last Notifications api
|
|
|
|
* request with statusCode 200.
|
|
|
|
*/
|
|
|
|
QByteArray notificationsEtagResponseHeader() const;
|
|
|
|
|
|
|
|
/** Returns the ETag Response header from the last Notifications api
|
|
|
|
* request with statusCode 200.
|
|
|
|
*/
|
|
|
|
void setNotificationsEtagResponseHeader(const QByteArray &value);
|
|
|
|
|
2017-07-04 13:23:23 +03:00
|
|
|
public slots:
|
|
|
|
/// Triggers a ping to the server to update state and
|
|
|
|
/// connection status and errors.
|
|
|
|
void checkConnectivity();
|
|
|
|
|
2014-12-17 16:09:57 +03:00
|
|
|
private:
|
|
|
|
void setState(State state);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void stateChanged(int state);
|
2016-04-28 23:43:53 +03:00
|
|
|
void isConnectedChanged();
|
2014-12-17 16:09:57 +03:00
|
|
|
|
|
|
|
protected Q_SLOTS:
|
|
|
|
void slotConnectionValidatorResult(ConnectionValidator::Status status, const QStringList &errors);
|
|
|
|
void slotInvalidCredentials();
|
|
|
|
void slotCredentialsFetched(AbstractCredentials *creds);
|
2015-09-05 16:39:22 +03:00
|
|
|
void slotCredentialsAsked(AbstractCredentials *creds);
|
2014-12-17 16:09:57 +03:00
|
|
|
|
|
|
|
private:
|
2015-04-17 18:56:17 +03:00
|
|
|
AccountPtr _account;
|
2014-12-17 16:09:57 +03:00
|
|
|
State _state;
|
|
|
|
ConnectionStatus _connectionStatus;
|
|
|
|
QStringList _connectionErrors;
|
|
|
|
bool _waitingForNewCredentials;
|
2015-10-19 12:50:26 +03:00
|
|
|
QElapsedTimer _timeSinceLastETagCheck;
|
2015-05-15 13:26:23 +03:00
|
|
|
QPointer<ConnectionValidator> _connectionValidator;
|
2018-03-02 00:19:04 +03:00
|
|
|
QByteArray _notificationsEtagResponseHeader;
|
2017-07-04 13:23:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts counting when the server starts being back up after 503 or
|
|
|
|
* maintenance mode. The account will only become connected once this
|
|
|
|
* timer exceeds the _maintenanceToConnectedDelay value.
|
|
|
|
*/
|
|
|
|
QElapsedTimer _timeSinceMaintenanceOver;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Milliseconds for which to delay reconnection after 503/maintenance.
|
|
|
|
*/
|
|
|
|
int _maintenanceToConnectedDelay;
|
2014-12-17 16:09:57 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(OCC::AccountState *)
|
2016-03-16 21:07:40 +03:00
|
|
|
Q_DECLARE_METATYPE(OCC::AccountStatePtr)
|
2014-12-17 16:09:57 +03:00
|
|
|
|
|
|
|
#endif //ACCOUNTINFO_H
|