From f75323a5abfbb0ab7a5523948834cf6b7b712cbb Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Fri, 26 Aug 2011 13:35:54 -0400
Subject: [PATCH] * #6737: cleanup in accountlist

---
 gnome/src/accountlist.c | 147 +++++++++++++---------------------------
 gnome/src/accountlist.h |  20 ------
 gnome/src/actions.c     |  13 ++--
 3 files changed, 50 insertions(+), 130 deletions(-)

diff --git a/gnome/src/accountlist.c b/gnome/src/accountlist.c
index 8f19ae3510..d8dceb006e 100644
--- a/gnome/src/accountlist.c
+++ b/gnome/src/accountlist.c
@@ -31,34 +31,43 @@
 
 #include <accountlist.h>
 #include <actions.h>
-#include <string.h>
 
 static GQueue * accountQueue;
 
+static guint account_list_get_position (account_t *account)
+{
+    guint size = account_list_get_size ();
+
+    for (guint i = 0; i < size; i++) {
+        account_t *tmp = account_list_get_nth (i);
+
+        if (g_strcasecmp (tmp->accountID, account->accountID) == 0)
+            return i;
+    }
+
+    // Not found
+    return -1;
+}
+
+
 /* GCompareFunc to compare a accountID (gchar* and a account_t) */
-gint is_accountID_struct (gconstpointer a, gconstpointer b)
+static gint is_accountID_struct (gconstpointer a, gconstpointer b)
 {
     if (!a || !b)
         return 1;
 
     account_t * c = (account_t*) a;
 
-    if (g_strcmp0 (c->accountID, (gchar*) b) == 0)
-        return 0;
-    else
-        return 1;
+    /* We only want it to return 0 or 1 */
+    return !!(g_strcmp0 (c->accountID, (gchar*) b));
 }
 
 /* GCompareFunc to get current call (gchar* and a account_t) */
-gint get_state_struct (gconstpointer a, gconstpointer b)
+static gint get_state_struct (gconstpointer a, gconstpointer b)
 {
-
     account_t * c = (account_t*) a;
 
-    if (c->state == * ( (account_state_t*) b))
-        return 0;
-    else
-        return 1;
+    return !(c->state == *((account_state_t*) b));
 }
 
 void account_list_init ()
@@ -66,37 +75,12 @@ void account_list_init ()
     accountQueue = g_queue_new ();
 }
 
-void
-account_list_clean ()
-{
-    g_queue_free (accountQueue);
-}
-
 void
 account_list_add (account_t * c)
 {
     g_queue_push_tail (accountQueue, (gpointer) c);
 }
 
-void
-account_list_add_at_nth (account_t * c, guint pos)
-{
-    g_queue_push_nth (accountQueue, (gpointer) c, pos);
-}
-
-
-void
-account_list_remove (const gchar * accountID)
-{
-    GList * c = g_queue_find_custom (accountQueue, accountID, is_accountID_struct);
-
-    DEBUG("Account List remove");
-
-    if (c)
-        g_queue_remove (accountQueue, c->data);
-}
-
-
 account_t *
 account_list_get_by_state (account_state_t state)
 {
@@ -113,10 +97,10 @@ account_list_get_by_id (gchar * accountID)
 {
     GList * c = g_queue_find_custom (accountQueue, accountID, is_accountID_struct);
 
-    if (c == NULL)
+    if (c)
+        return (account_t *) c->data;
+    else
         return NULL;
-
-    return (account_t *) c->data;
 }
 
 guint account_list_get_size (void)
@@ -132,34 +116,26 @@ account_t * account_list_get_nth (guint n)
 account_t*
 account_list_get_current()
 {
-    account_t *current;
-
     // No account registered
     if (account_list_get_registered_accounts () == 0)
         return NULL;
 
     // if we are here, it means that we have at least one registered account in the list
     // So we get the first one
-    current = account_list_get_by_state (ACCOUNT_STATE_REGISTERED);
-
-    if (!current)
-        return NULL;
+    account_t *current = account_list_get_by_state (ACCOUNT_STATE_REGISTERED);
 
     return current;
 }
 
 void account_list_set_current (account_t *current)
 {
-    gpointer acc;
-    guint pos;
-
     // 2 steps:
     // 1 - retrieve the index of the current account in the Queue
     // 2 - then set it as first
-    pos = account_list_get_position (current);
+    guint pos = account_list_get_position (current);
 
     if (pos > 0) {
-        acc = g_queue_pop_nth (accountQueue, pos);
+        gpointer acc = g_queue_pop_nth (accountQueue, pos);
         g_queue_push_nth (accountQueue, acc, 0);
     }
 }
@@ -171,37 +147,37 @@ const gchar * account_state_name (account_state_t s)
 
     switch (s) {
         case ACCOUNT_STATE_REGISTERED:
-            state = _ ("Registered");
+            state = _("Registered");
             break;
         case ACCOUNT_STATE_UNREGISTERED:
-            state = _ ("Not Registered");
+            state = _("Not Registered");
             break;
         case ACCOUNT_STATE_TRYING:
-            state = _ ("Trying...");
+            state = _("Trying...");
             break;
         case ACCOUNT_STATE_ERROR:
-            state = _ ("Error");
+            state = _("Error");
             break;
         case ACCOUNT_STATE_ERROR_AUTH:
-            state = _ ("Authentication Failed");
+            state = _("Authentication Failed");
             break;
         case ACCOUNT_STATE_ERROR_NETWORK:
-            state = _ ("Network unreachable");
+            state = _("Network unreachable");
             break;
         case ACCOUNT_STATE_ERROR_HOST:
-            state = _ ("Host unreachable");
+            state = _("Host unreachable");
             break;
         case ACCOUNT_STATE_ERROR_CONF_STUN:
-            state = _ ("Stun configuration error");
+            state = _("Stun configuration error");
             break;
         case ACCOUNT_STATE_ERROR_EXIST_STUN:
-            state = _ ("Stun server invalid");
+            state = _("Stun server invalid");
             break;
         case IP2IP_PROFILE_STATUS:
-            state = _ ("Ready");
+            state = _("Ready");
             break;
         default:
-            state = _ ("Invalid");
+            state = _("Invalid");
             break;
     }
 
@@ -239,12 +215,10 @@ guint
 account_list_get_registered_accounts (void)
 {
     guint res = 0;
-    unsigned int i;
 
-    for (i=0; i<account_list_get_size(); i++) {
+    for (guint i = 0; i < account_list_get_size(); i++)
         if (account_list_get_nth (i) -> state == (ACCOUNT_STATE_REGISTERED))
-            res ++;
-    }
+            res++;
 
     DEBUG ("Account: %d registered accounts" , res);
     return res;
@@ -265,9 +239,8 @@ gchar* account_list_get_current_id (void)
 gchar * account_list_get_ordered_list (void)
 {
     gchar *order = strdup("");
-    guint i;
 
-    for (i=0; i < account_list_get_size(); i++) {
+    for (guint i = 0; i < account_list_get_size(); i++) {
         account_t * account = NULL;
         account = account_list_get_nth (i);
 
@@ -282,37 +255,15 @@ gchar * account_list_get_ordered_list (void)
 }
 
 
-guint account_list_get_position (account_t *account)
-{
-    guint size, i;
-    account_t *tmp;
-
-    size = account_list_get_size ();
-
-    for (i=0; i<size; i++) {
-        tmp = account_list_get_nth (i);
-
-        if (g_strcasecmp (tmp->accountID, account->accountID) == 0)
-            return i;
-    }
-
-    // Not found
-    return -1;
-}
-
 gboolean current_account_has_mailbox (void)
 {
-
-    account_t *current;
-
     // Check if the current account has a voicemail number configured
-
-    current = account_list_get_current ();
+    account_t *current = account_list_get_current ();
 
     if (current) {
         gchar * account_mailbox = g_hash_table_lookup (current->properties, ACCOUNT_MAILBOX);
 
-        if (account_mailbox != NULL && g_strcasecmp (account_mailbox, "") != 0)
+        if (account_mailbox && g_strcasecmp (account_mailbox, "") != 0)
             return TRUE;
     }
 
@@ -321,9 +272,7 @@ gboolean current_account_has_mailbox (void)
 
 void current_account_set_message_number (guint nb)
 {
-    account_t *current;
-
-    current = account_list_get_current ();
+    account_t *current = account_list_get_current ();
 
     if (current)
         current->_messages_number = nb;
@@ -331,9 +280,7 @@ void current_account_set_message_number (guint nb)
 
 guint current_account_get_message_number (void)
 {
-    account_t *current;
-
-    current = account_list_get_current ();
+    account_t *current = account_list_get_current ();
 
     if (current)
         return current->_messages_number;
@@ -343,9 +290,7 @@ guint current_account_get_message_number (void)
 
 gboolean current_account_has_new_message (void)
 {
-    account_t *current;
-
-    current = account_list_get_current ();
+    account_t *current = account_list_get_current ();
 
     if (current)
         return (current->_messages_number > 0);
diff --git a/gnome/src/accountlist.h b/gnome/src/accountlist.h
index 155a415b18..f5c85673ca 100644
--- a/gnome/src/accountlist.h
+++ b/gnome/src/accountlist.h
@@ -93,30 +93,12 @@ typedef struct  {
  */
 void account_list_init ();
 
-/**
- * This function empty and free the account list.
- */
-void account_list_clean ();
-
 /**
  * This function append an account to list.
  * @param a The account you want to add
  */
 void account_list_add (account_t * a);
 
-/**
- * This function append an account to list at a given position.
- * @param a The account you want to add
- * @param pos THe position in the list to insert the account
- */
-void account_list_add_at_nth (account_t * a, guint pos);
-
-/**
- * This function remove an account from list.
- * @param accountID The accountID of the account you want to remove
- */
-void account_list_remove (const gchar * accountID);
-
 /**
  * Return the first account that corresponds to the state
  * @param state The state
@@ -193,8 +175,6 @@ gchar* account_list_get_current_id (void);
 
 gchar * account_list_get_ordered_list (void);
 
-guint account_list_get_position (account_t *account);
-
 gboolean current_account_has_mailbox (void);
 
 guint current_account_get_message_number (void);
diff --git a/gnome/src/actions.c b/gnome/src/actions.c
index 9898c6d58c..5ea37d4d0f 100644
--- a/gnome/src/actions.c
+++ b/gnome/src/actions.c
@@ -101,22 +101,18 @@ static gchar ** sflphone_order_history_hash_table(GHashTable *result)
 void
 sflphone_notify_voice_mail (const gchar* accountID , guint count)
 {
-    gchar *id;
-    gchar *current_id;
-    account_t *current;
-
     // We want to notify only the current account; ie the first in the list
-    id = g_strdup (accountID);
-    current_id = account_list_get_current_id ();
+    gchar *id = g_strdup (accountID);
+    const gchar * const current_id = account_list_get_current_id ();
 
     DEBUG ("sflphone_notify_voice_mail begin");
 
-    if (g_strcasecmp (id, current_id) != 0 || account_list_get_size() == 0)
+    if (g_ascii_strcasecmp (id, current_id) != 0 || account_list_get_size() == 0)
         return;
 
     // Set the number of voice messages for the current account
     current_account_set_message_number (count);
-    current = account_list_get_current ();
+    account_t *current = account_list_get_current ();
 
     // Update the voicemail tool button
     update_voicemail_status ();
@@ -187,7 +183,6 @@ sflphone_quit ()
         calllist_clean (current_calls);
         calllist_clean (contacts);
         calllist_clean (history);
-        //account_list_clean()
         gtk_main_quit ();
     }
 }
-- 
GitLab