From 71ac726571baae82abd4a8411f3f9e8f85dcfb0e Mon Sep 17 00:00:00 2001 From: eshe Date: Fri, 6 Aug 2010 12:27:05 +0100 Subject: [PATCH] Fixed issues with special characters and adding contact to address book. Small fix to Finnish translation. --- src/common/contactmanager.cpp | 41 ++++++++++++++++--------- src/common/contactmanager.h | 3 ++ src/common/translations/fi_FI.qm | Bin 9190 -> 9190 bytes src/common/translations/fi_FI.ts | 2 +- src/gui/detailwindow.cpp | 62 ++++++++++++++++++++------------------ src/gui/detailwindow.h | 2 ++ 6 files changed, 66 insertions(+), 44 deletions(-) diff --git a/src/common/contactmanager.cpp b/src/common/contactmanager.cpp index 974c7a5..67cd7ca 100644 --- a/src/common/contactmanager.cpp +++ b/src/common/contactmanager.cpp @@ -73,36 +73,49 @@ bool ContactManager::addContact(Contact const& contact) EContact* newContact = e_contact_new(); GError* error = NULL; - //EContactAddress* addr = new EContactAddress; + EContactAddress* addr = NULL; if(!contact.name.isEmpty()) { - char* name = contact.name.toLatin1().data(); + char* name = contact.name.toUtf8().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.city.isEmpty() || !contact.street.isEmpty()) + { + addr = g_new0 (EContactAddress, 1); + addr->address_format = g_strdup(""); + addr->po = g_strdup(contact.streetNumber.toUtf8().data()); + addr->ext = g_strdup(""); + addr->region = g_strdup(""); + addr->code = g_strdup(contact.zipCode.toUtf8().data()); + addr->country = g_strdup(contact.country.toUtf8().data()); + addr->street = g_strdup(contact.street.toUtf8().data()); + addr->locality = g_strdup(contact.city.toUtf8().data()); + e_contact_set(newContact, E_CONTACT_ADDRESS_OTHER, (gpointer)addr); + } if(!contact.number.isEmpty()) { - char* number = contact.number.toLatin1().data(); - e_contact_set(newContact, E_CONTACT_PHONE_HOME, (gpointer)number); + char* number = contact.number.toUtf8().data(); + e_contact_set(newContact, E_CONTACT_PHONE_OTHER, (gpointer)number); } + bool ret = true; + if(!e_book_add_contact(book_, newContact, &error)) { - qDebug() << "Couldn't add contact: %s" << error->message; + qDebug() << "Couldn't add contact: " << error->message; g_error_free(error); - return false; + ret = false; } - return true; + if(addr) + { + e_contact_address_free(addr); + } + + return ret; } bool ContactManager::load() diff --git a/src/common/contactmanager.h b/src/common/contactmanager.h index b719700..0c42e6b 100644 --- a/src/common/contactmanager.h +++ b/src/common/contactmanager.h @@ -33,7 +33,10 @@ public: QString name; QString number; QString street; + QString streetNumber; + QString zipCode; QString city; + QString country; }; ContactManager(); diff --git a/src/common/translations/fi_FI.qm b/src/common/translations/fi_FI.qm index 644013640d24b3d7804f5c84d985c301d091bfe4..65758e6d4c95384e9e7cb1c03436eb58207e0ac5 100644 GIT binary patch delta 16 XcmaFn{>*&?7w_bF3DM2+yvM}=I|l{* delta 18 ZcmaFn{>*&?7cZmE Unable to add contact. - Yhteystiedon lisääminen epäonnistui, + Yhteystiedon lisääminen epäonnistui. diff --git a/src/gui/detailwindow.cpp b/src/gui/detailwindow.cpp index 92a6d73..f7088c2 100644 --- a/src/gui/detailwindow.cpp +++ b/src/gui/detailwindow.cpp @@ -154,8 +154,11 @@ void DetailWindow::addToContacts() ContactManager cm; ContactManager::Contact contact; + getDetails(contact.street, contact.streetNumber, + contact.zipCode, contact.city); contact.name = addContactInput_->text(); contact.number = numberButton_->valueText(); + contact.country = country_; addDialog_->hide(); @@ -208,8 +211,6 @@ void DetailWindow::openMaps() { QString street = streetButton_->valueText(); QString city = cityButton_->valueText(); - QString number; - QString zip; if(street.isEmpty() && city.isEmpty()) { @@ -218,18 +219,36 @@ void DetailWindow::openMaps() setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); + OviMaps maps; + + OviMaps::Address addr; + getDetails(addr.street, addr.number, + addr.zipCode, addr.city); + addr.country = country_; + + if(!maps.openMaps(addr)) + { + QMaemo5InformationBox::information(this, tr("Unable to find coordinates for address.")); + } + + setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); +} + +void DetailWindow::getDetails(QString& street, QString& streetNumber, + QString& zip, QString& city) +{ int pos = 0; - QStringList words = street.split(" ", QString::SkipEmptyParts); + QString streetVal = streetButton_->valueText(); + QString cityVal = cityButton_->valueText(); + + QStringList words = streetVal.split(" ", QString::SkipEmptyParts); static QRegExp numberCheck("([0-9-]+)"); bool numberFound = false; bool numberSet = false; - QString streetStr; - QString numberStr; - for(int i = 0; i < words.size(); i++) { if(i > 0 && numberCheck.exactMatch(words.at(i))) @@ -241,41 +260,26 @@ void DetailWindow::openMaps() { if(!numberSet) { - numberStr = words.at(i); + streetNumber = words.at(i); numberSet = true; } } else { - streetStr += words.at(i) + " "; + street += words.at(i) + " "; } } - number = numberStr.trimmed(); - street = streetStr.trimmed(); + streetNumber = streetNumber.trimmed(); + street = street.trimmed(); - if((pos = city.indexOf(" ")) > 0) + if((pos = cityVal.indexOf(" ")) > 0) { - if(numberCheck.exactMatch(city.left(pos))) + if(numberCheck.exactMatch(cityVal.left(pos))) { - zip = city.left(pos); - city = city.mid(pos + 1); + zip = cityVal.left(pos); + city = cityVal.mid(pos + 1); } } - OviMaps maps; - - OviMaps::Address addr; - addr.street = street; - addr.number = number; - addr.zipCode = zip; - addr.city = city; - addr.country = country_; - - if(!maps.openMaps(addr)) - { - QMaemo5InformationBox::information(this, tr("Unable to find coordinates for address.")); - } - - setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); } diff --git a/src/gui/detailwindow.h b/src/gui/detailwindow.h index 97fe4f0..a2831c4 100644 --- a/src/gui/detailwindow.h +++ b/src/gui/detailwindow.h @@ -48,6 +48,8 @@ private slots: void openMaps(); private: + void getDetails(QString& street, QString& streetNumber, + QString& zip, QString& city); QWidget* area_; QVBoxLayout* layout_; QMaemo5ValueButton* nameButton_; -- 1.7.9.5