Added some sort of Ovi Maps integration. All translations updated.
authoreshe <jessehakanen@gmail.com>
Fri, 23 Jul 2010 21:18:21 +0000 (22:18 +0100)
committereshe <jessehakanen@gmail.com>
Fri, 23 Jul 2010 21:18:21 +0000 (22:18 +0100)
23 files changed:
debian/changelog
src/common/cache.cpp
src/common/dastelefonbuch.cpp
src/common/db.cpp
src/common/eniro.cpp
src/common/mobil1881.cpp
src/common/source.h
src/common/translations/de_DE.qm
src/common/translations/de_DE.ts
src/common/translations/nb_NO.qm
src/common/translations/nb_NO.ts
src/common/translations/sv_SE.qm
src/common/translations/sv_SE.ts
src/daemon/main.cpp
src/gui/detailwindow.cpp
src/gui/detailwindow.h
src/gui/gui.pro
src/gui/listwidget.cpp
src/gui/logwindow.cpp
src/gui/main.cpp
src/gui/ovimaps.cpp [new file with mode: 0644]
src/gui/ovimaps.h [new file with mode: 0644]
src/gui/resultwindow.cpp

index edcec39..5834f13 100644 (file)
@@ -1,3 +1,11 @@
+jenirok (0.2-4) unstable; urgency=low
+
+  * German translation and German phone book (Das Telefonbuch) added.
+  * Added call log for missed and answered calls.
+  * Address item in detail view can now be clicked to open it in Ovi Maps.
+
+ -- Jesse Hakanen <jessehakanen@gmail.com>  Fri, 23 Jul 2010 22:08:38 +0100
+
 jenirok (0.2-3) unstable; urgency=low
 
   * Swedish translation added.
index b339d43..2e01f07 100644 (file)
@@ -170,11 +170,12 @@ bool Cache::logItem(Source::Result const& result, bool missed, unsigned int time
 
     QSqlQuery query;
 
-    query.prepare("INSERT INTO log(number, name, street, city, time, missed) VALUES(:number, :name, :street, :city, :time, :missed)");
+    query.prepare("INSERT INTO log(number, name, street, city, country, time, missed) VALUES(:number, :name, :street, :city, :country, :time, :missed)");
     query.bindValue(":number", result.number);
     query.bindValue(":name", result.name);
     query.bindValue(":street", result.street);
     query.bindValue(":city", result.city);
+    query.bindValue(":country", result.country);
     query.bindValue(":time", time);
     int misVal = missed ? 1 : 0;
 
@@ -233,7 +234,7 @@ void Cache::getLogItems(QList<Cache::LogDetails>& items, int limit)
         DB::connect();
     }
 
-    QSqlQuery query("SELECT number, name, street, city, time, missed FROM log ORDER BY time DESC LIMIT " + QString::number(limit));
+    QSqlQuery query("SELECT number, name, street, city, country, time, missed FROM log ORDER BY time DESC LIMIT " + QString::number(limit));
 
     while(query.next())
     {
@@ -242,9 +243,10 @@ void Cache::getLogItems(QList<Cache::LogDetails>& items, int limit)
         details.result.name = query.value(1).toString();
         details.result.street = query.value(2).toString();
         details.result.city = query.value(3).toString();
-        details.time = query.value(4).toInt();
+        details.result.country = query.value(4).toString();
+        details.time = query.value(5).toInt();
 
-        int missed = query.value(5).toInt();
+        int missed = query.value(6).toInt();
 
         details.missed = missed ? true : false;
 
index da890f8..7ab3ed4 100644 (file)
@@ -254,6 +254,7 @@ bool DasTelefonbuch::formatResult(QString& name, QString& number,
     city = htmlEntityDecode(city);
     result.street = street.trimmed();
     result.city = city.trimmed();
+    result.country = "Germany";
 
     if(!result.name.isEmpty() && (!getFindNumber() || !result.number.isEmpty()))
     {
index 4028a74..fd12f34 100644 (file)
@@ -113,7 +113,7 @@ bool DB::createTables(bool update)
 
     ret = ret && query.exec("CREATE TABLE IF NOT EXISTS cache (id INTEGER PRIMARY KEY, number VARCHAR(32) NOT NULL UNIQUE, name VARCHAR(255) NOT NULL, street VARCHAR(255) NOT NULL, city VARCHAR(255) NOT NULL)");
     ret = ret && query.exec("CREATE TABLE IF NOT EXISTS settings (name VARCHAR(255) NOT NULL PRIMARY KEY, value VARCHAR(255) NOT NULL)");
-    ret = ret && query.exec("CREATE TABLE IF NOT EXISTS log (id INTEGER PRIMARY KEY, number VARCHAR(32) NOT NULL, name VARCHAR(255), street VARCHAR(255), city VARCHAR(255), time INTEGER NOT NULL, missed INTEGER NOT NULL)");
+    ret = ret && query.exec("CREATE TABLE IF NOT EXISTS log (id INTEGER PRIMARY KEY, number VARCHAR(32) NOT NULL, name VARCHAR(255), street VARCHAR(255), city VARCHAR(255), country VARCHAR(255), time INTEGER NOT NULL, missed INTEGER NOT NULL)");
 
     if(update)
     {
index 8e2503a..77290e2 100644 (file)
@@ -304,6 +304,19 @@ void Eniro::loadResults(int id, QString const& httpData)
 
         Result result;
 
+        switch(site_)
+        {
+        case FI:
+            result.country = "Finland";
+            break;
+        case SE:
+            result.country = "Sweden";
+            break;
+        case DK:
+            result.country = "Denmark";
+            break;
+        }
+
         int size = rows.size();
 
         switch(size)
index 1bd0c3a..6bc9deb 100644 (file)
@@ -248,6 +248,7 @@ bool Mobil1881::formatResult(QString& name, QString& number,
     city = htmlEntityDecode(city);
     result.street = street.trimmed();
     result.city = city.trimmed();
+    result.country = "Norway";
 
     if(!result.name.isEmpty() && (!getFindNumber() || !result.number.isEmpty()))
     {
index 6af26b2..7ebe969 100644 (file)
@@ -39,6 +39,7 @@ public:
         QString street;
         QString city;
         QString number;
+        QString country;
     };
 
     enum SearchType {YELLOW_PAGES, PERSONS, BOTH};
index f9f2113..ad66694 100644 (file)
Binary files a/src/common/translations/de_DE.qm and b/src/common/translations/de_DE.qm differ
index 9dcef5d..0629ba2 100644 (file)
@@ -53,7 +53,7 @@
     <message>
         <location filename="../../gui/connectionselector.cpp" line="69"/>
         <source>Use global setting</source>
-        <translation>Globale Einstellung verwenden</translation>
+        <translation>Globale Einstellungen</translation>
     </message>
     <message>
         <location filename="../../gui/connectionselector.cpp" line="70"/>
     <message>
         <location filename="../../gui/emptyguiconfig.cpp" line="27"/>
         <source>Selected phonebook has no settings to configure.</source>
-        <translation>Kein Einstellungen für das gewählte Telefonbuch.</translation>
+        <translation>Keine Einstellungen für das gewählte Telefonbuch.</translation>
     </message>
 </context>
 <context>
     </message>
 </context>
 <context>
+    <name>LogWindow</name>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="30"/>
+        <source>Incoming call log</source>
+        <translation>Liste eingegangener Anrufe</translation>
+    </message>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="31"/>
+        <source>Clear log</source>
+        <translation>Liste leeren</translation>
+    </message>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="64"/>
+        <source>There are currently no logged calls</source>
+        <translation>Liste ist leer</translation>
+    </message>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="134"/>
+        <source>%1 (no search results)</source>
+        <translation>%1 (keine Ergebnisse)</translation>
+    </message>
+</context>
+<context>
     <name>MainWindow</name>
     <message>
         <location filename="../../gui/mainwindow.cpp" line="48"/>
         <translation>Suchen</translation>
     </message>
     <message>
+        <location filename="../../gui/mainwindow.cpp" line="76"/>
+        <source>Log</source>
+        <translation>Logbuch</translation>
+    </message>
+    <message>
         <location filename="../../gui/mainwindow.cpp" line="82"/>
         <source>Settings</source>
         <translation>Einstellungen</translation>
     <message>
         <location filename="../../gui/settingsdialog.cpp" line="58"/>
         <source>Cache size (numbers)</source>
-        <translation>Programmspeicherplatz (Nummern)</translation>
+        <translation>Speicherplatz (Nummern)</translation>
     </message>
     <message>
         <location filename="../../gui/settingsdialog.cpp" line="61"/>
     <message>
         <location filename="../../gui/settingsdialog.cpp" line="108"/>
         <source>Connect automatically on</source>
-        <translation>Automatisch verbinden bei</translation>
+        <translation>Automatisch verbinden:</translation>
     </message>
     <message>
         <location filename="../../gui/settingsdialog.cpp" line="112"/>
index e1dd43e..41e71f8 100644 (file)
Binary files a/src/common/translations/nb_NO.qm and b/src/common/translations/nb_NO.qm differ
index 4f5fd71..a2a405c 100644 (file)
     </message>
 </context>
 <context>
+    <name>LogWindow</name>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="30"/>
+        <source>Incoming call log</source>
+        <translation>Anropslogg</translation>
+    </message>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="31"/>
+        <source>Clear log</source>
+        <translation>Tøm Logg</translation>
+    </message>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="64"/>
+        <source>There are currently no logged calls</source>
+        <translation>Det er ingen mottatte anrop</translation>
+    </message>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="134"/>
+        <source>%1 (no search results)</source>
+        <translation>%1 (ble ikke funnet)</translation>
+    </message>
+</context>
+<context>
     <name>MainWindow</name>
     <message>
         <location filename="../../gui/mainwindow.cpp" line="48"/>
         <translation>Søk</translation>
     </message>
     <message>
+        <location filename="../../gui/mainwindow.cpp" line="76"/>
+        <source>Log</source>
+        <translation>Logg</translation>
+    </message>
+    <message>
         <location filename="../../gui/mainwindow.cpp" line="82"/>
         <source>Settings</source>
         <translation>Innstillinger</translation>
     <message>
         <location filename="../../gui/mainwindow.cpp" line="116"/>
         <source>Unable to stop daemon.</source>
-        <translation>Kan ikke stoppe Autosøk.</translation>
+        <translation>Kan ikke stoppe autosøk.</translation>
     </message>
     <message>
         <location filename="../../gui/mainwindow.cpp" line="127"/>
index a278fe0..24d9304 100644 (file)
Binary files a/src/common/translations/sv_SE.qm and b/src/common/translations/sv_SE.qm differ
index ebe1d2f..17f7022 100644 (file)
     </message>
 </context>
 <context>
+    <name>LogWindow</name>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="30"/>
+        <source>Incoming call log</source>
+        <translation>Samtalshistorik</translation>
+    </message>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="31"/>
+        <source>Clear log</source>
+        <translation>Nollställ samtalshistorik</translation>
+    </message>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="64"/>
+        <source>There are currently no logged calls</source>
+        <translation>Samtalshistoriken är tom</translation>
+    </message>
+    <message>
+        <location filename="../../gui/logwindow.cpp" line="134"/>
+        <source>%1 (no search results)</source>
+        <translation>%1 (inget sökresultat)</translation>
+    </message>
+</context>
+<context>
     <name>MainWindow</name>
     <message>
         <location filename="../../gui/mainwindow.cpp" line="48"/>
         <translation>Sök</translation>
     </message>
     <message>
+        <location filename="../../gui/mainwindow.cpp" line="76"/>
+        <source>Log</source>
+        <translation>Historik</translation>
+    </message>
+    <message>
         <location filename="../../gui/mainwindow.cpp" line="82"/>
         <source>Settings</source>
         <translation>Inställningar</translation>
     <message>
         <location filename="../settings.cpp" line="168"/>
         <source>fi</source>
-        <translation>fi</translation>
+        <translation>se</translation>
     </message>
 </context>
 <context>
index d3b73a4..f011649 100644 (file)
 #include "calllistener.h"
 #include "settings.h"
 
-#include "source.h"
-#include "cache.h"
-#include <QtCore/QList>
-#include <QtCore/QPair>
-#include <QtCore/QDebug>
-#include <QtCore/QDateTime>
-
-
 int main(int argc, char *argv[])
 {
     // If daemon was started on boot, the first parameter is set to "-boot"
index 1e5b6c4..92a6d73 100644 (file)
  */
 
 #include <QtCore/QDebug>
+#include <QtCore/QList>
 #include <QtDBus/QDBusConnection>
 #include <QtDBus/QDBusMessage>
+#include <QtDBus/QDBusReply>
+#include <QtDBus/QDBusArgument>
+#include <QtDBus/QDBusMetaType>
 #include <QtGui/QMessageBox>
 #include <QtGui/QLabel>
 #include <QtGui/QClipboard>
@@ -28,6 +32,7 @@
 #include <QMaemo5InformationBox>
 #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();
 }
 
@@ -195,3 +203,79 @@ void DetailWindow::sendSMS()
     }
 
 }
+
+void DetailWindow::openMaps()
+{
+    QString street = streetButton_->valueText();
+    QString city = cityButton_->valueText();
+    QString number;
+    QString zip;
+
+    if(street.isEmpty() && city.isEmpty())
+    {
+        return;
+    }
+
+    setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+
+    int pos = 0;
+
+    QStringList words = street.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)))
+        {
+            numberFound = true;
+        }
+
+        if(numberFound)
+        {
+            if(!numberSet)
+            {
+                numberStr = words.at(i);
+                numberSet = true;
+            }
+        }
+        else
+        {
+            streetStr += words.at(i) + " ";
+        }
+    }
+
+    number = numberStr.trimmed();
+    street = streetStr.trimmed();
+
+    if((pos = city.indexOf(" ")) > 0)
+    {
+        if(numberCheck.exactMatch(city.left(pos)))
+        {
+            zip = city.left(pos);
+            city = city.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 a267e6b..97fe4f0 100644 (file)
@@ -33,6 +33,7 @@ class DetailWindow : public QMainWindow
     Q_OBJECT
 
 public:
+
     DetailWindow(QWidget* parent = 0);
 
 public slots:
@@ -44,6 +45,7 @@ private slots:
     void addToContacts();
     void copyToClipboard();
     void sendSMS();
+    void openMaps();
 
 private:
     QWidget* area_;
@@ -54,6 +56,7 @@ private:
     QMaemo5ValueButton* numberButton_;
     QDialog* addDialog_;
     QLineEdit* addContactInput_;
+    QString country_;
 
 
 };
index ce51464..ae1659f 100644 (file)
@@ -27,7 +27,8 @@ SOURCES += main.cpp \
     ../common/cache.cpp \
     ../common/dastelefonbuch.cpp \
     logwindow.cpp \
-    listwidget.cpp
+    listwidget.cpp \
+    ovimaps.cpp
 HEADERS += mainwindow.h \
     searchdialog.h \
     resultwindow.h \
@@ -53,7 +54,8 @@ HEADERS += mainwindow.h \
     ../common/cache.h \
     ../common/dastelefonbuch.h \
     logwindow.h \
-    listwidget.h
+    listwidget.h \
+    ovimaps.h
 RESOURCES = icons.qrc ../common/translations.qrc
 TRANSLATIONS = ../common/translations/fi_FI.ts
 INCLUDEPATH += ../common
index 39a6519..66930fa 100644 (file)
@@ -16,6 +16,8 @@
  *
  */
 
+#include <QtGui/QApplication>
+#include <QtGui/QDesktopWidget>
 #include <QtGui/QHeaderView>
 #include <QtCore/QDebug>
 #include "listwidget.h"
@@ -26,7 +28,7 @@ ListWidget::ListWidget(QWidget* parent): QTableWidget(parent)
     setColumnCount(1);
     verticalHeader()->hide();
     horizontalHeader()->hide();
-    setColumnWidth(0, 800);
+    setColumnWidth(0, QApplication::desktop()->availableGeometry().width());
     setSelectionMode(QAbstractItemView::SingleSelection);
 }
 
index 1fb8484..4197111 100644 (file)
@@ -75,6 +75,7 @@ void LogWindow::loadLogItems()
             data["street"] = QVariant(logList.at(i).result.street);
             data["city"] = QVariant(logList.at(i).result.city);
             data["number"] = QVariant(logList.at(i).result.number);
+            data["country"] = QVariant(logList.at(i).result.country);
 
             list_->addWidget(createWidget(logList.at(i)), data);
         }
@@ -100,6 +101,7 @@ void LogWindow::itemClicked(int index)
     details.street = data["street"].toString();
     details.city = data["city"].toString();
     details.number = data["number"].toString();
+    details.country = data["country"].toString();
 
     emit logItemSelected(details);
 }
index e642575..56ea49c 100644 (file)
@@ -22,7 +22,7 @@
 #include "searchdialog.h"
 #include "resultwindow.h"
 #include "detailwindow.h"
-#include "eniro.h"
+#include "source.h"
 #include "settings.h"
 
 int main(int argc, char *argv[])
diff --git a/src/gui/ovimaps.cpp b/src/gui/ovimaps.cpp
new file mode 100644 (file)
index 0000000..5f76f22
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * This file is part of Jenirok.
+ *
+ * Jenirok is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Jenirok is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jenirok.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <QtCore/QDebug>
+#include <QtGui/QApplication>
+#include <QtDBus/QDBusConnection>
+#include <QtDBus/QDBusMessage>
+#include <QtDBus/QDBusReply>
+#include <QtDBus/QDBusArgument>
+#include <QtDBus/QDBusMetaType>
+#include "ovimaps.h"
+
+namespace
+{
+    QString const MAPS_SERVICE = "com.nokia.Navigation.NokiaMapsProvider";
+    QString const MAPS_PATH = "/Provider";
+    QString const MAPS_INTERFACE = "com.nokia.Navigation.MapProvider";
+    QString const MAPS_ADDRESS_TO_LOCATIONS = "AddressToLocations";
+    QString const MAPS_ADDRESS_TO_LOCATIONS_REPLY = "AddressToLocationsReply";
+    QString const MAPS_LOCATION_TO_ADDRESSES = "LocationToAddresses";
+    QString const MAPS_LOCATION_TO_ADDESSES_REPLY = "LocationToAddressReply";
+    QString const MAPS_START = "ShowPlaceGeo";
+
+}
+
+inline QDBusArgument& operator<<(QDBusArgument& argument,
+                                 const OviMaps::Location& location)
+{
+    argument.beginStructure();
+    argument << location.latitude << location.longitude;
+    argument.endStructure();
+    return argument;
+}
+
+inline const QDBusArgument& operator>>(const QDBusArgument& argument,
+                                       OviMaps::Location& location)
+{
+    argument.beginStructure();
+    argument >> location.latitude >> location.longitude;
+    argument.endStructure();
+    return argument;
+}
+
+Q_DECLARE_METATYPE(OviMaps::Location);
+Q_DECLARE_METATYPE(QList<OviMaps::Location>);
+Q_DECLARE_METATYPE(QList<QStringList>);
+
+OviMaps::OviMaps(QObject* parent): QObject(parent),
+locationsTarget_(0), addressesTarget_(0), ready_(false), timer_(0)
+{
+    qDBusRegisterMetaType<OviMaps::Location>();
+    qDBusRegisterMetaType< QList<OviMaps::Location> >();
+    qDBusRegisterMetaType< QList<QStringList> >();
+}
+
+bool OviMaps::addressToLocations(OviMaps::Address const& address,
+                                 QList<OviMaps::Location>& locations)
+{
+    QDBusMessage msg = QDBusMessage::createMethodCall(MAPS_SERVICE,
+                                                      MAPS_PATH,
+                                                      MAPS_INTERFACE,
+                                                      MAPS_ADDRESS_TO_LOCATIONS);
+
+    QList<QVariant> arguments;
+
+    QStringList data;
+
+    data << address.number << "" << address.street << ""
+         << address.city << "" << "" << address.zipCode << address.country
+         << "" << "" << "" << "" << "" << "";
+
+    arguments.append(QVariant(data));
+    arguments.append(QVariant(true));
+
+    msg.setArguments(arguments);
+
+    QDBusMessage rep = QDBusConnection::sessionBus().call(msg);
+
+    QDBusReply<QDBusObjectPath> reply(rep);
+
+    if(reply.isValid())
+    {
+        QDBusObjectPath path = reply.value();
+        locationsTarget_ = &locations;
+        QDBusConnection::sessionBus().connect(MAPS_SERVICE,
+                                              path.path(),
+                                              MAPS_INTERFACE,
+                                              MAPS_ADDRESS_TO_LOCATIONS_REPLY,
+                                              this,
+                                              SLOT(handleAddressToLocationsReply(QList<OviMaps::Location>)));
+
+        bool ret = waitSignal();
+        locationsTarget_ = 0;
+        return ret;
+    }
+
+    return false;
+
+}
+
+bool OviMaps::locationToAddresses(Location const& location, QList<Address>& address)
+{
+    QDBusMessage msg = QDBusMessage::createMethodCall(MAPS_SERVICE,
+                                                      MAPS_PATH,
+                                                      MAPS_INTERFACE,
+                                                      MAPS_LOCATION_TO_ADDRESSES);
+
+    QList<QVariant> arguments;
+
+    arguments.append(QVariant(location.latitude));
+    arguments.append(QVariant(location.longitude));
+    arguments.append(QVariant(false));
+
+    msg.setArguments(arguments);
+
+    QDBusMessage rep = QDBusConnection::sessionBus().call(msg);
+
+    QDBusReply<QDBusObjectPath> reply(rep);
+
+    if(reply.isValid())
+    {
+        QDBusObjectPath path = reply.value();
+        addressesTarget_ = &address;
+        QDBusConnection::sessionBus().connect(MAPS_SERVICE,
+                                              path.path(),
+                                              MAPS_INTERFACE,
+                                              MAPS_LOCATION_TO_ADDESSES_REPLY,
+                                              this,
+                                              SLOT(handleLocationToAddressesReply(QList<QStringList>)));
+
+        bool ret = waitSignal();
+        addressesTarget_ = 0;
+        return ret;
+    }
+
+    return false;
+}
+
+bool OviMaps::openMaps(Address const& address)
+{
+    QList<Location> locations;
+
+    if(!addressToLocations(address, locations) || locations.size() == 0)
+    {
+        return false;
+    }
+
+    return openMaps(locations.at(0));
+}
+
+bool OviMaps::openMaps(Location const& location)
+{
+    QDBusMessage msg = QDBusMessage::createMethodCall(MAPS_SERVICE,
+                                                      MAPS_PATH,
+                                                      MAPS_INTERFACE,
+                                                      MAPS_START);
+
+    QList<QVariant> arguments;
+
+    arguments.append(QVariant(location.latitude));
+    arguments.append(QVariant(location.longitude));
+
+    uint val = 0;
+
+    arguments.append(QVariant(val));
+
+    msg.setArguments(arguments);
+
+    QDBusMessage rep = QDBusConnection::sessionBus().call(msg);
+
+    if(rep.type() == QDBusMessage::ErrorMessage)
+    {
+        return false;
+    }
+
+    return true;
+}
+
+void OviMaps::timerEvent(QTimerEvent* event)
+{
+    Q_UNUSED(event);
+
+    if(timer_)
+    {
+        killTimer(timer_);
+        timer_ = 0;
+    }
+}
+
+void OviMaps::handleAddressToLocationsReply(QList<OviMaps::Location> locations)
+{
+    if(locationsTarget_)
+    {
+        *locationsTarget_ = locations;
+        ready_ = true;
+    }
+}
+
+void OviMaps::handleLocationToAddressesReply(QList<QStringList> addresses)
+{
+    if(addressesTarget_)
+    {
+        for(int i = 0; i < addresses.size(); i++)
+        {
+            Address addr;
+            addr.street = addresses.at(i).at(2);
+            addr.number = addresses.at(i).at(0);
+            addr.zipCode = addresses.at(i).at(7);
+            addr.city = addresses.at(i).at(4);
+            addr.country = addresses.at(i).at(8);
+
+            addressesTarget_->push_back(addr);
+        }
+
+        ready_ = true;
+    }
+}
+
+bool OviMaps::waitSignal()
+{
+    ready_ = false;
+    timer_ = startTimer(TIMEOUT);
+
+    while(!ready_ && timer_)
+    {
+        QApplication::processEvents(QEventLoop::WaitForMoreEvents);
+    }
+
+    if(!timer_)
+    {
+        return false;
+    }
+    else
+    {
+        killTimer(timer_);
+        timer_ = 0;
+    }
+
+    return true;
+}
diff --git a/src/gui/ovimaps.h b/src/gui/ovimaps.h
new file mode 100644 (file)
index 0000000..5063650
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * This file is part of Jenirok.
+ *
+ * Jenirok is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Jenirok is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jenirok.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef OVIMAPS_H
+#define OVIMAPS_H
+
+#include <QtCore/QObject>
+#include <QtCore/QString>
+#include <QtCore/QList>
+#include <QtCore/QStringList>
+
+class OviMaps : public QObject
+{
+    Q_OBJECT
+
+public:
+
+    struct Address
+    {
+        QString street;
+        QString number;
+        QString zipCode;
+        QString city;
+        QString country;
+    };
+
+    struct Location
+    {
+        double latitude;
+        double longitude;
+    };
+
+    static int const TIMEOUT = 10000;
+
+    OviMaps(QObject* parent = 0);
+    bool addressToLocations(Address const& address, QList<Location>& locations);
+    bool locationToAddresses(Location const& location, QList<Address>& address);
+    bool openMaps(Address const& address);
+    bool openMaps(Location const& location);
+
+protected:
+    virtual void timerEvent(QTimerEvent* event);
+
+private slots:
+    void handleAddressToLocationsReply(QList<OviMaps::Location>);
+    void handleLocationToAddressesReply(QList<QStringList> addresses);
+
+private:
+    bool waitSignal();
+    QList<Location>* locationsTarget_;
+    QList<Address>* addressesTarget_;
+    bool ready_;
+    int timer_;
+
+};
+
+#endif
index adbd404..e9da90a 100644 (file)
@@ -133,6 +133,7 @@ void ResultWindow::resultAvailable(Source::Result const& result,
     data["street"] = QVariant(result.street);
     data["city"] = QVariant(result.city);
     data["number"] = QVariant(result.number);
+    data["country"] = QVariant(result.country);
 
     item->setData(Qt::UserRole, QVariant(data));
 
@@ -189,6 +190,7 @@ void ResultWindow::itemClicked(QListWidgetItem* item)
     details.street = data["street"].toString();
     details.city = data["city"].toString();
     details.number = data["number"].toString();
+    details.country = data["country"].toString();
 
     emit itemSelected(details);
 }