Fixed issues with special characters and adding contact to address book. Small fix...
authoreshe <jessehakanen@gmail.com>
Fri, 6 Aug 2010 11:27:05 +0000 (12:27 +0100)
committereshe <jessehakanen@gmail.com>
Fri, 6 Aug 2010 11:27:05 +0000 (12:27 +0100)
src/common/contactmanager.cpp
src/common/contactmanager.h
src/common/translations/fi_FI.qm
src/common/translations/fi_FI.ts
src/gui/detailwindow.cpp
src/gui/detailwindow.h

index 974c7a5..67cd7ca 100644 (file)
@@ -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()
index b719700..0c42e6b 100644 (file)
@@ -33,7 +33,10 @@ public:
         QString name;
         QString number;
         QString street;
+        QString streetNumber;
+        QString zipCode;
         QString city;
+        QString country;
     };
 
     ContactManager();
index 6440136..65758e6 100644 (file)
Binary files a/src/common/translations/fi_FI.qm and b/src/common/translations/fi_FI.qm differ
index c17a08b..a9b093f 100644 (file)
     <message>
         <location filename="../../gui/detailwindow.cpp" line="160"/>
         <source>Unable to add contact.</source>
-        <translation>Yhteystiedon lisääminen epäonnistui,</translation>
+        <translation>Yhteystiedon lisääminen epäonnistui.</translation>
     </message>
     <message>
         <location filename="../../gui/detailwindow.cpp" line="170"/>
index 92a6d73..f7088c2 100644 (file)
@@ -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);
 }
index 97fe4f0..a2831c4 100644 (file)
@@ -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_;