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()
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();
{
QString street = streetButton_->valueText();
QString city = cityButton_->valueText();
- QString number;
- QString zip;
if(street.isEmpty() && city.isEmpty())
{
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)))
{
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);
}