X-Git-Url: http://git.maemo.org/git/?p=jenirok;a=blobdiff_plain;f=src%2Fgui%2Fdetailwindow.cpp;h=4d6107d4faf55f083796692f7799353f7b8f27f1;hp=1e5b6c4d9acdf959664336abb134df86b5e0708e;hb=f99718e69b270a89094113a26b22c694b79382f0;hpb=d187495fd3566da1ee1eb94cc313c2f561a0fac5 diff --git a/src/gui/detailwindow.cpp b/src/gui/detailwindow.cpp index 1e5b6c4..4d6107d 100644 --- a/src/gui/detailwindow.cpp +++ b/src/gui/detailwindow.cpp @@ -17,8 +17,12 @@ */ #include +#include #include #include +#include +#include +#include #include #include #include @@ -28,6 +32,7 @@ #include #include "detailwindow.h" #include "contactmanager.h" +#include "ovimaps.h" DetailWindow::DetailWindow(QWidget* parent): QMainWindow(parent), addDialog_(0) { @@ -51,12 +56,14 @@ DetailWindow::DetailWindow(QWidget* parent): QMainWindow(parent), addDialog_(0) nameButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_default_avatar"), tr("Name"), this); - streetButton_ = new QMaemo5ValueButton(tr("Street"), this); + streetButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_map"), + tr("Street"), this); cityButton_ = new QMaemo5ValueButton(tr("City"), this); numberButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_call"), tr("Phone number"), this); connect(numberButton_, SIGNAL(pressed()), this, SLOT(makeCall())); + connect(streetButton_, SIGNAL(pressed()), this, SLOT(openMaps())); top->addWidget(nameButton_); bottom->addWidget(streetButton_); @@ -81,6 +88,7 @@ void DetailWindow::loadData(Source::Result const& details) streetButton_->setValueText(details.street); cityButton_->setValueText(details.city); numberButton_->setValueText(details.number); + country_ = details.country; show(); } @@ -146,8 +154,13 @@ void DetailWindow::addToContacts() ContactManager cm; ContactManager::Contact contact; - contact.name = addContactInput_->text(); + QString number; + QString street; + getDetails(street, number, + contact.zipCode, contact.city, contact.street); + ContactManager::stringToName(addContactInput_->text(), contact.name); contact.number = numberButton_->valueText(); + contact.country = country_; addDialog_->hide(); @@ -195,3 +208,98 @@ void DetailWindow::sendSMS() } } + +void DetailWindow::openMaps() +{ + QString street = streetButton_->valueText(); + QString city = cityButton_->valueText(); + + if(street.isEmpty() && city.isEmpty()) + { + return; + } + + setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); + + OviMaps maps; + + OviMaps::Address addr; + QString streetAndNumber; + getDetails(addr.street, addr.number, + addr.zipCode, addr.city, streetAndNumber); + addr.country = country_; + + //qDebug() << addr.street << addr.number << addr.zipCode << addr.city << addr.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, QString& streetAndNumber) +{ + int pos = 0; + + QString streetVal = streetButton_->valueText(); + streetVal = streetVal.replace("Str.", QString::fromUtf8("Straße")); + streetVal = streetVal.replace("str.", QString::fromUtf8("straße")); + streetAndNumber = streetVal; + QString cityVal = cityButton_->valueText(); + city = cityVal; + + QStringList words = streetVal.split(" ", QString::SkipEmptyParts); + + static QRegExp numberCheck("([0-9-]+)"); + + bool numberFound = false; + bool numberSet = false; + + for(int i = 0; i < words.size(); i++) + { + if(i > 0 && numberCheck.exactMatch(words.at(i))) + { + numberFound = true; + } + + if(numberFound) + { + if(!numberSet) + { + streetNumber = words.at(i); + numberSet = true; + } + } + else + { + street += words.at(i) + " "; + } + } + + if(streetNumber.isEmpty()) + { + static QRegExp addrCheck(" ([0-9]+)"); + + if((pos = addrCheck.indexIn(street)) != -1) + { + streetNumber = addrCheck.cap(1); + street = street.left(pos); + } + } + + streetNumber = streetNumber.trimmed(); + street = street.trimmed(); + + if((pos = cityVal.indexOf(" ")) > 0) + { + if(numberCheck.exactMatch(cityVal.left(pos))) + { + zip = cityVal.left(pos); + city = cityVal.mid(pos + 1); + } + } + +}