X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fcommon%2Fcontactmanager.cpp;h=974c7a5304f73a3b92fb8e5b8e6c07e62d2e92c2;hb=71122b1057b6c12b250b37f6693ed8259f20b34c;hp=0a49a7c4dcff7638006e12616b424388bf9e5d44;hpb=f47fcb3ca78e8b27cace31fb18becd9dfa35d3d8;p=jenirok diff --git a/src/common/contactmanager.cpp b/src/common/contactmanager.cpp index 0a49a7c..974c7a5 100644 --- a/src/common/contactmanager.cpp +++ b/src/common/contactmanager.cpp @@ -16,14 +16,9 @@ * */ -#include +#include #include "contactmanager.h" -namespace -{ - const int COUNTRY_CODES[] = {358, 45, 46, 47}; - const int NUM_OF_CODES = 4; -} ContactManager::ContactManager(): book_(0) { @@ -31,6 +26,10 @@ ContactManager::ContactManager(): book_(0) ContactManager::~ContactManager() { + if(book_) + { + g_object_unref(book_); + } } bool ContactManager::numberExists(QString const& number) @@ -43,8 +42,8 @@ bool ContactManager::numberExists(QString const& number) EBookQuery* query; GList *g_contacts; - QString copy(number); - QString clean = removeCountryCode(copy); + // Just check the last 7 digits + QString clean = number.right(7); query = e_book_query_any_field_contains(clean.toLatin1()); @@ -54,9 +53,10 @@ bool ContactManager::numberExists(QString const& number) return false; } + e_book_query_unref(query); + if (g_contacts == 0) { - qDebug() << "no contacts"; return false; } @@ -112,23 +112,17 @@ bool ContactManager::load() return true; } - qDebug() << "Loading addressbook"; - GError *error; error = 0; book_ = e_book_new_system_addressbook(&error); - qDebug() << "Loaded almost"; - if (!book_) { - qDebug() << "Couldn't open addressbook: %s" << error->message; + qDebug() << "Couldn't open addressbook: %s" << error->message; g_error_free(error); return false; } - qDebug() << "Addressbook loaded"; - /* Open connection to the address book */ if (!e_book_open(book_, FALSE, &error)) { @@ -137,49 +131,7 @@ bool ContactManager::load() return false; } - qDebug() << "Addressbook opened"; - 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, ""); -} -