Fixed issues with special characters and adding contact to address book. Small fix...
[jenirok] / src / gui / detailwindow.cpp
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);
 }