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
|
|
|
|
* 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 ACCOUNTINFO_H
|
|
|
|
#define ACCOUNTINFO_H
|
|
|
|
|
|
|
|
#include <QByteArray>
|
2015-05-15 13:26:23 +03:00
|
|
|
#include <QPointer>
|
2014-12-17 16:09:57 +03:00
|
|
|
#include "utility.h"
|
|
|
|
#include "connectionvalidator.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;
|
|
|
|
class AbstractCredentials;
|
|
|
|
|
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
|
|
|
*/
|
2015-01-12 11:40:11 +03:00
|
|
|
class AccountState : public QObject {
|
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
|
|
|
|
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,
|
|
|
|
|
|
|
|
/// An error like invalid credentials where retrying won't help.
|
|
|
|
ConfigurationError
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The actual current connectivity status.
|
|
|
|
typedef ConnectionValidator::Status ConnectionStatus;
|
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
/// Use the account as parent
|
|
|
|
AccountState(AccountPtr account);
|
2014-12-17 16:09:57 +03:00
|
|
|
~AccountState();
|
|
|
|
|
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;
|
|
|
|
void setSignedOut(bool signedOut);
|
|
|
|
|
|
|
|
bool isConnected() const;
|
2015-04-24 12:32:47 +03:00
|
|
|
bool isConnectedOrTemporarilyUnavailable() const;
|
2014-12-17 16:09:57 +03:00
|
|
|
|
|
|
|
/// Triggers a ping to the server to update state and
|
|
|
|
/// connection status and errors.
|
|
|
|
void checkConnectivity();
|
|
|
|
|
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
|
|
|
|
2014-12-17 16:09:57 +03:00
|
|
|
private:
|
|
|
|
void setState(State state);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void stateChanged(int state);
|
|
|
|
|
|
|
|
protected Q_SLOTS:
|
|
|
|
void slotConnectionValidatorResult(ConnectionValidator::Status status, const QStringList& errors);
|
|
|
|
void slotInvalidCredentials();
|
|
|
|
void slotCredentialsFetched(AbstractCredentials* creds);
|
|
|
|
|
|
|
|
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-05-15 13:26:23 +03:00
|
|
|
QPointer<ConnectionValidator> _connectionValidator;
|
2014-12-17 16:09:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(OCC::AccountState*)
|
2015-07-06 12:04:17 +03:00
|
|
|
Q_DECLARE_METATYPE(QSharedPointer<OCC::AccountState>)
|
2014-12-17 16:09:57 +03:00
|
|
|
|
|
|
|
#endif //ACCOUNTINFO_H
|