Fixed some inconsistencies in code indentation
[jenirok] / src / common / contactmanager.cpp
index 3f8affe..1289f1a 100644 (file)
@@ -21,8 +21,8 @@
 
 namespace
 {
-       const int COUNTRY_CODES[] = {358, 45, 46, 47};
-       const int NUM_OF_CODES = 4;
+    const int COUNTRY_CODES[] = {358, 45, 46, 47};
+    const int NUM_OF_CODES = 4;
 }
 
 ContactManager::ContactManager(): book_(0)
@@ -35,142 +35,142 @@ ContactManager::~ContactManager()
 
 bool ContactManager::numberExists(QString const& number)
 {
-       if(!load())
-       {
-               return false;
-       }
+    if(!load())
+    {
+        return false;
+    }
 
-       EBookQuery* query;
-       GList *g_contacts;
+    EBookQuery* query;
+    GList *g_contacts;
 
-       QString copy(number);
-       QString clean = removeCountryCode(copy);
+    QString copy(number);
+    QString clean = removeCountryCode(copy);
 
-       query = e_book_query_any_field_contains(clean.toLatin1());
+    query = e_book_query_any_field_contains(clean.toLatin1());
 
-       if (!e_book_get_contacts (book_, query, &g_contacts, NULL))
-       {
-               qDebug() << "Couldn't get query results.\n";
-               return false;
-       }
+    if (!e_book_get_contacts (book_, query, &g_contacts, NULL))
+    {
+        qDebug() << "Couldn't get query results.\n";
+        return false;
+    }
 
-       if (g_contacts == 0)
-       {
-               qDebug() << "no contacts";
-               return false;
-       }
+    if (g_contacts == 0)
+    {
+        qDebug() << "no contacts";
+        return false;
+    }
 
-       return true;
+    return true;
 
 }
 
 bool ContactManager::addContact(Contact const& contact)
 {
-       if(!load())
-       {
-               return false;
-       }
-
-       EContact* newContact = e_contact_new();
-       GError* error = NULL;
-       //EContactAddress* addr = new EContactAddress;
-
-       if(!contact.name.isEmpty())
-       {
-               char* name = contact.name.toLatin1().data();
-               e_contact_set(newContact, E_CONTACT_FULL_NAME, (gpointer)name);
-       }
-
-       // Doesn't work for some reason
-       /*if(!contact.city.isEmpty() || !contact.street.isEmpty())
+    if(!load())
+    {
+        return false;
+    }
+
+    EContact* newContact = e_contact_new();
+    GError* error = NULL;
+    //EContactAddress* addr = new EContactAddress;
+
+    if(!contact.name.isEmpty())
+    {
+        char* name = contact.name.toLatin1().data();
+        e_contact_set(newContact, E_CONTACT_FULL_NAME, (gpointer)name);
+    }
+
+    // Doesn't work for some reason
+    /*if(!contact.city.isEmpty() || !contact.street.isEmpty())
        {
                addr->street = contact.street.toLatin1().data();
                addr->locality = contact.city.toLatin1().data();
                e_contact_set(newContact, E_CONTACT_ADDRESS_HOME, (gpointer)addr);
        }*/
 
-       if(!contact.number.isEmpty())
-       {
-               char* number = contact.number.toLatin1().data();
-               e_contact_set(newContact, E_CONTACT_PHONE_HOME, (gpointer)number);
-       }
+    if(!contact.number.isEmpty())
+    {
+        char* number = contact.number.toLatin1().data();
+        e_contact_set(newContact, E_CONTACT_PHONE_HOME, (gpointer)number);
+    }
 
-       if(!e_book_add_contact(book_, newContact, &error))
-       {
-               qDebug() << "Couldn't add contact: %s" <<  error->message;
-               g_error_free(error);
-               return false;
-       }
+    if(!e_book_add_contact(book_, newContact, &error))
+    {
+        qDebug() << "Couldn't add contact: %s" <<  error->message;
+        g_error_free(error);
+        return false;
+    }
 
-       return true;
+    return true;
 }
 
 bool ContactManager::load()
 {
-       if(book_)
-       {
-               return true;
-       }
-
-       GError* error = NULL;
-       book_ = e_book_new_system_addressbook(&error);
-
-       if (!book_)
-       {
-               qDebug() << "Couldn't open addressbook: %s" <<  error->message;
-               g_error_free(error);
-               return false;
-       }
-
-       /* Open connection to the address book */
-       if (!e_book_open(book_, FALSE, &error))
-       {
-               qDebug() << "Couldn't open addressbook: %s" << error->message;
-               g_error_free(error);
-               return false;
-       }
-
-       return true;
+    if(book_)
+    {
+        return true;
+    }
+
+    GError* error = NULL;
+    book_ = e_book_new_system_addressbook(&error);
+
+    if (!book_)
+    {
+        qDebug() << "Couldn't open addressbook: %s" <<  error->message;
+        g_error_free(error);
+        return false;
+    }
+
+    /* Open connection to the address book */
+    if (!e_book_open(book_, FALSE, &error))
+    {
+        qDebug() << "Couldn't open addressbook: %s" << error->message;
+        g_error_free(error);
+        return false;
+    }
+
+    return true;
 
 }
 
 QString& ContactManager::removeCountryCode(QString& number)
 {
-       if(number.isEmpty())
-       {
-               return number;
-       }
-
-       if(number.at(0) == '0')
-       {
-               return number.remove(0, 1);
-       }
-       else if(number.at(0) != '+')
-       {
-               return number;
-       }
-
-       static QRegExp countryCodeCleaner;
-       static bool countryCodeCleanerLoaded = false;
-
-       if(!countryCodeCleanerLoaded)
-       {
-               QString match = "";
-
-               for(int i = 0; i < NUM_OF_CODES; i++)
-               {
-                       if(i > 0)
-                       {
-                               match += "|";
-                       }
-
-                       match += "\\+" + QString::number(COUNTRY_CODES[i]);
-               }
-
-               countryCodeCleaner = QRegExp("^(" + match + ")");
-               countryCodeCleanerLoaded = true;
-       }
-
-       return number.replace(countryCodeCleaner, "");
+    if(number.isEmpty())
+    {
+        return number;
+    }
+
+    if(number.at(0) == '0')
+    {
+        return number.remove(0, 1);
+    }
+    else if(number.at(0) != '+')
+    {
+        return number;
+    }
+
+    static QRegExp countryCodeCleaner;
+    static bool countryCodeCleanerLoaded = false;
+
+    if(!countryCodeCleanerLoaded)
+    {
+        QString match = "";
+
+        for(int i = 0; i < NUM_OF_CODES; i++)
+        {
+            if(i > 0)
+            {
+                match += "|";
+            }
+
+            match += "\\+" + QString::number(COUNTRY_CODES[i]);
+        }
+
+        countryCodeCleaner = QRegExp("^(" + match + ")");
+        countryCodeCleanerLoaded = true;
+    }
+
+    return number.replace(countryCodeCleaner, "");
 }