diff --git a/daemon/src/account.cpp b/daemon/src/account.cpp index af0b0689d7505b4b951704dce1c1919a00c85029..094eb1afc20d46ecf743ebf1df6c43599a40181b 100644 --- a/daemon/src/account.cpp +++ b/daemon/src/account.cpp @@ -32,8 +32,9 @@ #include "account.h" #include "manager.h" +#include "dbus/configurationmanager.h" -Account::Account(const std::string& accountID, const std::string &type) : +Account::Account(const std::string &accountID, const std::string &type) : accountID_(accountID) , username_() , hostname_() @@ -54,8 +55,7 @@ Account::Account(const std::string& accountID, const std::string &type) : } Account::~Account() -{ -} +{} void Account::setRegistrationState(const RegistrationState &state) { @@ -63,7 +63,8 @@ void Account::setRegistrationState(const RegistrationState &state) registrationState_ = state; // Notify the client - Manager::instance().connectionStatusNotification(); + ConfigurationManager *c(Manager::instance().getDbusManager()->getConfigurationManager()); + c->registrationStateChanged(accountID_, registrationState_); } } diff --git a/daemon/src/dbus/configurationmanager-introspec.xml b/daemon/src/dbus/configurationmanager-introspec.xml index 6c8f27da36474bb1c61bd1e1c9fadf826e7131b7..a990a0be463994ea5c61a68778e615f23be1c61c 100644 --- a/daemon/src/dbus/configurationmanager-introspec.xml +++ b/daemon/src/dbus/configurationmanager-introspec.xml @@ -447,6 +447,11 @@ <signal name="accountsChanged" tp:name-for-bindings="accountsChanged"> </signal> + <signal name="registrationStateChanged" tp:name-for-bindings="registrationStateChanged"> + <arg type="s" name="accountID"/> + <arg type="i" name="registration_state"/> + </signal> + <signal name="stunStatusFailure" tp:name-for_bindings="stunStatusFailure"> <arg type="s" name="reason"> </arg> diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index a22b5c698923376a7a8c2a7cad2a3641a8e25b2d..04428236e551c2c7741daee7509bd4fd264b5533 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -1628,11 +1628,6 @@ void ManagerImpl::startVoiceMessageNotification(const std::string& accountId, dbus_.getCallManager()->voiceMailNotify(accountId, nb_msg); } -void ManagerImpl::connectionStatusNotification() -{ - dbus_.getConfigurationManager()->accountsChanged(); -} - /** * Multi Thread */ diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index 432f65adb2abcd74733c01632dfb8669529b5571..6c7768c18cc27e9286bf98112a0b881cf1812e02 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -399,11 +399,6 @@ class ManagerImpl { */ void startVoiceMessageNotification(const std::string& accountId, int nb_msg); - /** - * Notify the client through DBus that registration state has been updated - */ - void connectionStatusNotification(); - /** * ConfigurationManager - Send registration request * @param accountId The account to register/unregister diff --git a/gnome/src/accountlist.c b/gnome/src/accountlist.c index e9c1aa440ccefd6256f51f15b21e07756ca5d25f..1742c6e0922325dc02e491d53777ddbd93d27769 100644 --- a/gnome/src/accountlist.c +++ b/gnome/src/accountlist.c @@ -127,9 +127,7 @@ account_list_get_current() // if we are here, it means that we have at least one registered account in the list // So we get the first one - account_t *current = account_list_get_by_state(ACCOUNT_STATE_REGISTERED); - - return current; + return account_list_get_by_state(ACCOUNT_STATE_REGISTERED); } void account_list_set_current(account_t *current) @@ -148,45 +146,28 @@ void account_list_set_current(account_t *current) const gchar * account_state_name(account_state_t s) { - gchar * state; - switch (s) { case ACCOUNT_STATE_REGISTERED: - state = _("Registered"); - break; + return _("Registered"); case ACCOUNT_STATE_UNREGISTERED: - state = _("Not Registered"); - break; + return _("Not Registered"); case ACCOUNT_STATE_TRYING: - state = _("Trying..."); - break; + return _("Trying..."); case ACCOUNT_STATE_ERROR: - state = _("Error"); - break; + return _("Error"); case ACCOUNT_STATE_ERROR_AUTH: - state = _("Authentication Failed"); - break; + return _("Authentication Failed"); case ACCOUNT_STATE_ERROR_NETWORK: - state = _("Network unreachable"); - break; + return _("Network unreachable"); case ACCOUNT_STATE_ERROR_HOST: - state = _("Host unreachable"); - break; + return _("Host unreachable"); case ACCOUNT_STATE_ERROR_CONF_STUN: - state = _("Stun configuration error"); - break; + return _("Stun configuration error"); case ACCOUNT_STATE_ERROR_EXIST_STUN: - state = _("Stun server invalid"); - break; - case IP2IP_PROFILE_STATUS: - state = _("Ready"); - break; + return _("Stun server invalid"); default: - state = _("Invalid"); - break; + return _("Invalid"); } - - return state; } void account_list_free_elm(gpointer elm, gpointer data UNUSED) diff --git a/gnome/src/accountlist.h b/gnome/src/accountlist.h index 2bddde48b12f0df35c9787cec4ebe199fe2986e7..85903ce5969a5b3913d379e63a45dab3253dc8b2 100644 --- a/gnome/src/accountlist.h +++ b/gnome/src/accountlist.h @@ -41,14 +41,12 @@ * This enum have all the states an account can take. */ typedef enum { - /** Invalid state */ - ACCOUNT_STATE_INVALID = 0, - /** The account is registered */ - ACCOUNT_STATE_REGISTERED, /** The account is not registered */ ACCOUNT_STATE_UNREGISTERED, /** The account is trying to register */ ACCOUNT_STATE_TRYING, + /** The account is registered */ + ACCOUNT_STATE_REGISTERED, /** Error state. The account is not registered */ ACCOUNT_STATE_ERROR, /** An authentification error occured. Wrong password or wrong username. The account is not registered */ @@ -57,12 +55,12 @@ typedef enum { ACCOUNT_STATE_ERROR_NETWORK, /** Host is unreachable. The account is not registered */ ACCOUNT_STATE_ERROR_HOST, - /** Stun server configuration error. The account is not registered */ - ACCOUNT_STATE_ERROR_CONF_STUN, /** Stun server is not existing. The account is not registered */ ACCOUNT_STATE_ERROR_EXIST_STUN, - /** IP profile status **/ - IP2IP_PROFILE_STATUS + /** Stun server configuration error. The account is not registered */ + ACCOUNT_STATE_ERROR_CONF_STUN, + /** Invalid state */ + ACCOUNT_STATE_INVALID } account_state_t; /** @struct account_t diff --git a/gnome/src/actions.c b/gnome/src/actions.c index d7cea96c44cd8cf4c5b44f336a17d58ade90b8f5..ad1ab48106eb1e7b2f184fc4b1074c2263634782 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -237,8 +237,6 @@ void sflphone_fill_account_list(void) acc->state = ACCOUNT_STATE_ERROR_CONF_STUN; else if (g_strcmp0(status , "ERROR_EXIST_STUN") == 0) acc->state = ACCOUNT_STATE_ERROR_EXIST_STUN; - else if (g_strcmp0(status, "READY") == 0) - acc->state = IP2IP_PROFILE_STATUS; else acc->state = ACCOUNT_STATE_INVALID; diff --git a/gnome/src/config/accountconfigdialog.c b/gnome/src/config/accountconfigdialog.c index 919bd2b178b789c98746a39c823667bb6bb5fffd..bc77854f1d66d1a529faf0e172929e7d20f2637b 100644 --- a/gnome/src/config/accountconfigdialog.c +++ b/gnome/src/config/accountconfigdialog.c @@ -1250,23 +1250,19 @@ void update_account_from_dialog(GtkWidget *dialog, account_t *account) else current_protocol = g_strdup("SIP"); - if (g_strcmp0(current_protocol, "SIP") == 0) { - if (!IS_IP2IP) { - DEBUG("Config: Get new credentials"); - account->credential_information = get_new_credential(); - - if (account->credential_information) - dbus_set_credentials(account); - } - } + if (!IS_IP2IP && g_strcmp0(current_protocol, "SIP") == 0) + account->credential_information = get_new_credential(); /** @todo Verify if it's the best condition to check */ if (g_strcmp0(account->accountID, "new") == 0) dbus_add_account(account); else dbus_set_account_details(account); + // propagate changes to the daemon codec_list_update_to_daemon(account); + if (account->credential_information) + dbus_set_credentials(account); g_free(current_protocol); gtk_widget_destroy(dialog); diff --git a/gnome/src/config/accountlistconfigdialog.c b/gnome/src/config/accountlistconfigdialog.c index 3557491ce85ddb5909cd1c5d270683f1dbfba625..27f7b86b9142f1bc45e265eef8d1db524e645efb 100644 --- a/gnome/src/config/accountlistconfigdialog.c +++ b/gnome/src/config/accountlistconfigdialog.c @@ -94,9 +94,9 @@ static void delete_account_cb(gpointer data) static void run_account_dialog(const gchar *selected_accountID) { - account_t *selected_account = account_list_get_by_id(selected_accountID); - GtkWidget *dialog = show_account_window(selected_account); - update_account_from_dialog(dialog, selected_account); + account_t *account = account_list_get_by_id(selected_accountID); + GtkWidget *dialog = show_account_window(account); + update_account_from_dialog(dialog, account); } static void row_activated_cb(GtkTreeView *view, @@ -189,7 +189,7 @@ select_account_cb(GtkTreeSelection *selection, GtkTreeModel *model) memset(&val, 0, sizeof(val)); gtk_tree_model_get_value(model, &iter, COLUMN_ACCOUNT_ID, &val); - gchar *selected_accountID = g_strdup(g_value_get_string(&val)); + gchar *selected_accountID = g_value_dup_string(&val); g_value_unset(&val); DEBUG("Selected account has accountID %s", selected_accountID); @@ -208,7 +208,7 @@ select_account_cb(GtkTreeSelection *selection, GtkTreeModel *model) const gchar *state_name = account_state_name(selected_account->state); if (selected_account->protocol_state_description != NULL - && selected_account->protocol_state_code != 0) { + && selected_account->protocol_state_code != 0) { gchar * response = g_strdup_printf( _("Server returned \"%s\" (%d)"), @@ -260,10 +260,10 @@ enable_account_cb(GtkCellRendererToggle *rend UNUSED, gchar* path, enable, -1); // Modify account state - const gchar * registration_state = enable ? "true" : "false"; - DEBUG("Account is enabled: %s", registration_state); + const gchar * enabled_str = enable ? "true" : "false"; + DEBUG("Account is enabled: %s", enabled_str); - account_replace(account, ACCOUNT_ENABLED, registration_state); + account_replace(account, ACCOUNT_ENABLED, enabled_str); dbus_send_register(account->accountID, enable); } diff --git a/gnome/src/dbus/configurationmanager-introspec.xml b/gnome/src/dbus/configurationmanager-introspec.xml index f22a7ead0c531f917e37e800d4c46fc56f2314da..a990a0be463994ea5c61a68778e615f23be1c61c 100644 --- a/gnome/src/dbus/configurationmanager-introspec.xml +++ b/gnome/src/dbus/configurationmanager-introspec.xml @@ -21,6 +21,7 @@ The available keys / parameters are: <ul> <li>CONFIG_ACCOUNT_ENABLE: True or False (Default: True)</li> + <li>CONFIG_ACCOUNT_RESOLVE_ONCE</li> <li>CONFIG_ACCOUNT_TYPE: SIP or IAX2 (Default: SIP)</li> <li>HOSTNAME: The IP adress or hostname of the registrar</li> <li>USERNAME: The username (or extension) of the account</li> @@ -446,6 +447,11 @@ <signal name="accountsChanged" tp:name-for-bindings="accountsChanged"> </signal> + <signal name="registrationStateChanged" tp:name-for-bindings="registrationStateChanged"> + <arg type="s" name="accountID"/> + <arg type="i" name="registration_state"/> + </signal> + <signal name="stunStatusFailure" tp:name-for_bindings="stunStatusFailure"> <arg type="s" name="reason"> </arg> diff --git a/gnome/src/dbus/dbus.c b/gnome/src/dbus/dbus.c index c3ee84d693a3230224215d6b1d6efa6c7269f600..98bae46fd92695bfe1577015b9a3bc0cbec985f2 100644 --- a/gnome/src/dbus/dbus.c +++ b/gnome/src/dbus/dbus.c @@ -421,6 +421,17 @@ record_playback_stopped_cb(DBusGProxy *proxy UNUSED, const gchar *filepath) update_actions(); } +static void +registration_state_changed_cb(DBusGProxy *proxy UNUSED, const gchar *accountID, + guint state, void *foo UNUSED) +{ + DEBUG("DBus: Registration state changed to %s for account %s", + account_state_name(state), accountID); + account_t *acc = account_list_get_by_id(accountID); + if (acc) + acc->state = state; +} + static void accounts_changed_cb(DBusGProxy *proxy UNUSED, void *foo UNUSED) { @@ -733,6 +744,11 @@ gboolean dbus_connect(GError **error) dbus_g_proxy_connect_signal(call_proxy, "voiceMailNotify", G_CALLBACK(voice_mail_cb), NULL, NULL); + dbus_g_proxy_add_signal(config_proxy, "registrationStateChanged", G_TYPE_STRING, + G_TYPE_INT, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(config_proxy, "registrationStateChanged", + G_CALLBACK(registration_state_changed_cb), NULL, NULL); + dbus_g_proxy_add_signal(call_proxy, "incomingMessage", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal(call_proxy, "incomingMessage", @@ -1091,11 +1107,10 @@ void dbus_add_account(account_t *a) { g_assert(a); + g_assert(a->accountID); g_assert(a->properties); - DEBUG("Adding %s account", a->accountID); + g_free(a->accountID); GError *error = NULL; - if (a->accountID) - g_free(a->accountID); a->accountID = NULL; org_sflphone_SFLphone_ConfigurationManager_add_account(config_proxy, a->properties, &a->accountID, &error);