account: Rework account states
Introduce a state-changed signal which also gives a reason for why the state changed. This will allow the UI to give some meaningful feedback to the user. Additionally we can get rid of a number of things that were not really states, but rather reasons for why a state changed (f.e. authentication failures).
This commit is contained in:
@@ -74,7 +74,7 @@ on_account_state_changed (CallsAccountRow *self)
|
||||
{
|
||||
CallsAccountState state = calls_account_get_state (self->account);
|
||||
|
||||
gtk_switch_set_active (self->online_switch, state == CALLS_ACCOUNT_ONLINE);
|
||||
gtk_switch_set_active (self->online_switch, state == CALLS_ACCOUNT_STATE_ONLINE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -35,6 +35,12 @@
|
||||
|
||||
G_DEFINE_INTERFACE (CallsAccount, calls_account, CALLS_TYPE_ORIGIN)
|
||||
|
||||
enum {
|
||||
SIGNAL_STATE_CHANGED,
|
||||
SIGNAL_LAST_SIGNAL,
|
||||
};
|
||||
static guint signals [SIGNAL_LAST_SIGNAL];
|
||||
|
||||
|
||||
static void
|
||||
calls_account_default_init (CallsAccountInterface *iface)
|
||||
@@ -44,7 +50,7 @@ calls_account_default_init (CallsAccountInterface *iface)
|
||||
"Account state",
|
||||
"The state of the account",
|
||||
CALLS_TYPE_ACCOUNT_STATE,
|
||||
CALLS_ACCOUNT_NULL,
|
||||
CALLS_ACCOUNT_STATE_UNKNOWN,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_EXPLICIT_NOTIFY));
|
||||
@@ -57,6 +63,24 @@ calls_account_default_init (CallsAccountInterface *iface)
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_EXPLICIT_NOTIFY));
|
||||
|
||||
/**
|
||||
* CallsAccount::account-state-changed:
|
||||
* @self: The #CallsAccount
|
||||
* @new_state: The new #CALLS_ACCOUNT_STATE of the account
|
||||
* @old_state: The old #CALLS_ACCOUNT_STATE of the account
|
||||
* @reason: The #CALLS_ACCOUNT_STATE_REASON for the change
|
||||
*/
|
||||
signals[SIGNAL_STATE_CHANGED] =
|
||||
g_signal_new ("account-state-changed",
|
||||
G_TYPE_FROM_INTERFACE (iface),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0, NULL, NULL, NULL,
|
||||
G_TYPE_NONE,
|
||||
3,
|
||||
CALLS_TYPE_ACCOUNT_STATE,
|
||||
CALLS_TYPE_ACCOUNT_STATE,
|
||||
CALLS_TYPE_ACCOUNT_STATE_REASON);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +115,7 @@ calls_account_get_state (CallsAccount *self)
|
||||
{
|
||||
CallsAccountState state;
|
||||
|
||||
g_return_val_if_fail (CALLS_IS_ACCOUNT (self), CALLS_ACCOUNT_NULL);
|
||||
g_return_val_if_fail (CALLS_IS_ACCOUNT (self), CALLS_ACCOUNT_STATE_UNKNOWN);
|
||||
|
||||
g_object_get (self, "account-state", &state, NULL);
|
||||
|
||||
|
||||
@@ -33,7 +33,62 @@ G_BEGIN_DECLS
|
||||
|
||||
#define CALLS_TYPE_ACCOUNT (calls_account_get_type ())
|
||||
|
||||
G_DECLARE_INTERFACE (CallsAccount, calls_account, CALLS, ACCOUNT, CallsOrigin);
|
||||
G_DECLARE_INTERFACE (CallsAccount, calls_account, CALLS, ACCOUNT, CallsOrigin)
|
||||
|
||||
/**
|
||||
* CallsAccountState:
|
||||
* @CALLS_ACCOUNT_STATE_UNKNOWN: Default state for new accounts
|
||||
* @CALLS_ACCOUNT_STATE_INITIALIZING: Account is initializing
|
||||
* @CALLS_ACCOUNT_STATE_DEINITIALIZING: Account is being shutdown
|
||||
* @CALLS_ACCOUNT_STATE_CONNECTING: Connecting to server
|
||||
* @CALLS_ACCOUNT_STATE_ONLINE: Account is online
|
||||
* @CALLS_ACCOUNT_STATE_DISCONNECTING: Disconnecting from server
|
||||
* @CALLS_ACCOUNT_STATE_OFFLINE: Account is offline
|
||||
* @CALLS_ACCOUNT_STATE_ERROR: Account is in an error state
|
||||
*/
|
||||
typedef enum {
|
||||
CALLS_ACCOUNT_STATE_UNKNOWN = 0,
|
||||
CALLS_ACCOUNT_STATE_INITIALIZING,
|
||||
CALLS_ACCOUNT_STATE_DEINITIALIZING,
|
||||
CALLS_ACCOUNT_STATE_CONNECTING,
|
||||
CALLS_ACCOUNT_STATE_ONLINE,
|
||||
CALLS_ACCOUNT_STATE_DISCONNECTING,
|
||||
CALLS_ACCOUNT_STATE_OFFLINE,
|
||||
CALLS_ACCOUNT_STATE_ERROR,
|
||||
} CallsAccountState;
|
||||
|
||||
/**
|
||||
* CallsAccountStateReason:
|
||||
* @CALLS_ACCOUNT_STATE_REASON_UNKNOWN: Default unspecified reason
|
||||
* @CALLS_ACCOUNT_STATE_REASON_INITIALIZATION_STARTED: Initialization started
|
||||
* @CALLS_ACCOUNT_STATE_REASON_INITIALIZED: Initialization done
|
||||
* @CALLS_ACCOUNT_STATE_REASON_DEINITIALIZATION_STARTED: Deinitialization started
|
||||
* @CALLS_ACCOUNT_STATE_REASON_DEINITIALIZED: Deinitialization done
|
||||
* @CALLS_ACCOUNT_STATE_REASON_NO_CREDENTIALS: No credentials were set
|
||||
* @CALLS_ACCOUNT_STATE_REASON_CONNECT_STARTED: Starting to connect
|
||||
* @CALLS_ACCOUNT_STATE_REASON_CONNECTION_TIMEOUT: A connection has timed out
|
||||
* @CALLS_ACCOUNT_STATE_REASON_CONNECTION_DNS_ERROR: A domain name could not be resolved
|
||||
* @CALLS_ACCOUNT_STATE_REASON_AUTHENTICATION_FAILURE: Could not authenticate, possibly wrong credentials
|
||||
* @CALLS_ACCOUNT_STATE_REASON_CONNECTED: Connected successfully
|
||||
* @CALLS_ACCOUNT_STATE_REASON_DISCONNECTED: Disconnected successfully
|
||||
* @CALLS_ACCOUNT_STATE_REASON_INTERNAL_ERROR: An internal error has occurred
|
||||
*/
|
||||
typedef enum {
|
||||
CALLS_ACCOUNT_STATE_REASON_UNKNOWN = 0,
|
||||
CALLS_ACCOUNT_STATE_REASON_INITIALIZATION_STARTED,
|
||||
CALLS_ACCOUNT_STATE_REASON_INITIALIZED,
|
||||
CALLS_ACCOUNT_STATE_REASON_DEINITIALIZATION_STARTED,
|
||||
CALLS_ACCOUNT_STATE_REASON_DEINITIALIZED,
|
||||
CALLS_ACCOUNT_STATE_REASON_NO_CREDENTIALS,
|
||||
CALLS_ACCOUNT_STATE_REASON_CONNECT_STARTED,
|
||||
CALLS_ACCOUNT_STATE_REASON_CONNECTION_TIMEOUT,
|
||||
CALLS_ACCOUNT_STATE_REASON_CONNECTION_DNS_ERROR,
|
||||
CALLS_ACCOUNT_STATE_REASON_AUTHENTICATION_FAILURE,
|
||||
CALLS_ACCOUNT_STATE_REASON_CONNECTED,
|
||||
CALLS_ACCOUNT_STATE_REASON_DISCONNECT_STARTED,
|
||||
CALLS_ACCOUNT_STATE_REASON_DISCONNECTED,
|
||||
CALLS_ACCOUNT_STATE_REASON_INTERNAL_ERROR,
|
||||
} CallsAccountStateReason;
|
||||
|
||||
|
||||
struct _CallsAccountInterface
|
||||
@@ -44,33 +99,13 @@ struct _CallsAccountInterface
|
||||
gboolean online);
|
||||
const char *(*get_address) (CallsAccount *self);
|
||||
};
|
||||
/**
|
||||
* CallsAccountState:
|
||||
* @CALLS_ACCOUNT_NULL: Not initialized or error
|
||||
* @CALLS_ACCOUNT_OFFLINE: Account considered offline (not ready for placing or receiving calls)
|
||||
* @CALLS_ACCOUNT_CONNECTING: Trying to connect to server
|
||||
* @CALLS_ACCOUNT_CONNECTION_FAILURE: Could not connect to server (f.e. DNS error, unreachable)
|
||||
* @CALLS_ACCOUNT_AUTHENTICATING: Authenticating using web-auth/proxy-auth
|
||||
* @CALLS_ACCOUNT_AUTHENTICATION_FAILURE: Could not authenticate to server (f.e. wrong credentials)
|
||||
* @CALLS_ACCOUNT_NO_CREDENTIALS: Credentials are missing
|
||||
* @CALLS_ACCOUNT_ONLINE: Account considered online (can place and receive calls)
|
||||
*/
|
||||
typedef enum {
|
||||
CALLS_ACCOUNT_NULL = 0,
|
||||
CALLS_ACCOUNT_OFFLINE,
|
||||
CALLS_ACCOUNT_CONNECTING,
|
||||
CALLS_ACCOUNT_CONNECTION_FAILURE,
|
||||
CALLS_ACCOUNT_AUTHENTICATING,
|
||||
CALLS_ACCOUNT_AUTHENTICATION_FAILURE,
|
||||
CALLS_ACCOUNT_NO_CREDENTIALS,
|
||||
CALLS_ACCOUNT_UNKNOWN_ERROR,
|
||||
CALLS_ACCOUNT_ONLINE
|
||||
} CallsAccountState;
|
||||
|
||||
|
||||
void calls_account_go_online (CallsAccount *self,
|
||||
gboolean online);
|
||||
const char *calls_account_get_address (CallsAccount *self);
|
||||
CallsAccountState calls_account_get_state (CallsAccount *self);
|
||||
void calls_account_go_online (CallsAccount *self,
|
||||
gboolean online);
|
||||
const char *calls_account_get_address (CallsAccount *self);
|
||||
CallsAccountState calls_account_get_state (CallsAccount *self);
|
||||
const char *calls_account_state_to_string (CallsAccountState *state);
|
||||
const char *calls_account_state_reason_to_string (CallsAccountStateReason *reason);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
Reference in New Issue
Block a user