Location selector and edit window finished nikos-branch
authorNiko Böckerman <niko.bockerman@gmail.com>
Thu, 14 Oct 2010 17:58:20 +0000 (20:58 +0300)
committerNiko Böckerman <niko.bockerman@gmail.com>
Thu, 14 Oct 2010 17:59:26 +0000 (20:59 +0300)
32 files changed:
zouba/build-stamp [deleted file]
zouba/configure-stamp [deleted file]
zouba/src/addressdialog.cpp [new file with mode: 0644]
zouba/src/addressdialog.h [new file with mode: 0644]
zouba/src/gpscontroller.cpp
zouba/src/gpscontroller.h
zouba/src/gpscontroller_p.cpp [deleted file]
zouba/src/gpscontroller_p.h [deleted file]
zouba/src/location.cpp
zouba/src/location.h
zouba/src/location_p.cpp [deleted file]
zouba/src/location_p.h [deleted file]
zouba/src/locationbutton.cpp [new file with mode: 0644]
zouba/src/locationbutton.h [new file with mode: 0644]
zouba/src/locations.cpp
zouba/src/locations.h
zouba/src/locationsdisplay.cpp [new file with mode: 0644]
zouba/src/locationsdisplay.h [new file with mode: 0644]
zouba/src/locationsdisplaywindow.cpp [new file with mode: 0644]
zouba/src/locationsdisplaywindow.h [new file with mode: 0644]
zouba/src/locationsdisplaywindow.ui [new file with mode: 0644]
zouba/src/main.cpp
zouba/src/route.cpp
zouba/src/route.h
zouba/src/route_p.cpp
zouba/src/ui.cpp
zouba/src/ui.h
zouba/src/uicontroller.cpp
zouba/src/uicontroller.h
zouba/src/ytv.cpp [new file with mode: 0644]
zouba/src/ytv.h
zouba/zouba.pro

diff --git a/zouba/build-stamp b/zouba/build-stamp
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/zouba/configure-stamp b/zouba/configure-stamp
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/zouba/src/addressdialog.cpp b/zouba/src/addressdialog.cpp
new file mode 100644 (file)
index 0000000..eba193d
--- /dev/null
@@ -0,0 +1,279 @@
+#include "addressdialog.h"\r
+#include "location.h"\r
+#include "ytv.h"\r
+#include "locations.h"\r
+\r
+#include <QWidget>\r
+#include <QDialog>\r
+#include <QHBoxLayout>\r
+#include <QVBoxLayout>\r
+#include <QFormLayout>\r
+#include <QLineEdit>\r
+#include <QPushButton>\r
+#include <QXmlStreamReader>\r
+#include <QListWidget>\r
+#include <QDebug>\r
+#ifdef Q_WS_MAEMO_5\r
+#include <QMaemo5InformationBox>\r
+#endif\r
+\r
+AddressDialog::AddressDialog(QWidget *parent, const Location *location) :\r
+    QDialog(parent), m_reply(0), m_current(0)\r
+{\r
+    QHBoxLayout *layout = new QHBoxLayout();\r
+    this->setLayout(layout);\r
+    QFormLayout *editLayout = new QFormLayout();\r
+    layout->addLayout(editLayout);\r
+    QVBoxLayout *buttonLayout = new QVBoxLayout();\r
+    layout->addLayout(buttonLayout);\r
+\r
+    this->m_label = new QLineEdit();\r
+    this->m_address = new QLineEdit();\r
+    connect(this->m_address, SIGNAL(textEdited(const QString&)), this, SLOT(typedInAddress()));\r
+\r
+    editLayout->addRow("Name", this->m_label);\r
+    editLayout->addRow("Address", this->m_address);\r
+\r
+    this->m_addButton = new QPushButton("Add", this);\r
+    buttonLayout->addWidget(this->m_addButton);\r
+    connect(this->m_addButton, SIGNAL(clicked()), this, SLOT(addLocation()));\r
+    QPushButton *searchButton = new QPushButton("Search", this);\r
+    buttonLayout->addWidget(searchButton);\r
+    connect(searchButton, SIGNAL(clicked()), this, SLOT(searchAddress()));\r
+\r
+    // Set dialog as edit dialog if given location is not null.\r
+    if (location)\r
+    {\r
+        this->m_label->setText(location->label());\r
+        this->m_label->setEnabled(false);\r
+        this->m_address->setText(location->address());\r
+        //this->m_current = location;\r
+        this->m_addButton->setText("Edit");\r
+    }\r
+    \r
+    // Always set add button to disabled when creating new layout.\r
+    this->m_addButton->setEnabled(false);\r
+}\r
+\r
+void AddressDialog::searchAddress()\r
+{\r
+    emit(busy(true));\r
+    this->m_reply = Ytv::searchAddress(m_address->text());\r
+    connect(m_reply, SIGNAL(finished()), this, SLOT(searchFinished()));\r
+}\r
+\r
+void AddressDialog::searchFinished()\r
+{\r
+    qDebug() << "Parsing following xml:";\r
+    QXmlStreamReader xml(this->m_reply->readAll());\r
+    //Remove the reply. Hopefully also removes the connection.\r
+    //delete this->m_reply;\r
+    this->m_reply = 0;\r
+    \r
+    bool responseHasError = false;\r
+    this->m_places = QList<Location*>();\r
+    this->m_roadNames = QList<Location*>();\r
+    this->m_stops = QList<Location*>();\r
+\r
+    while (!xml.atEnd())\r
+    {\r
+        qDebug() << "Reading next element";\r
+        xml.readNext();\r
+\r
+        if (xml.isStartElement())\r
+        {\r
+            QString xmlName(xml.name().toString());\r
+\r
+            if (xmlName == "LOC")\r
+            {\r
+                QXmlStreamAttributes attributes(xml.attributes());\r
+                QStringRef xAttribute( attributes.value("x") );\r
+                QStringRef yAttribute( attributes.value("y") );\r
+                QString newX( xAttribute.toString() );\r
+                QString newY( yAttribute.toString() );\r
+                QString category(attributes.value("category").toString());\r
+                QString name(attributes.value("name1").toString());\r
+                QString number(attributes.value("number").toString());\r
+                if (!number.isEmpty())\r
+                {\r
+                    name.append(" ");\r
+                    name.append(number);\r
+                }\r
+                name.append(", ");\r
+                name.append(attributes.value("city").toString());\r
+\r
+                if (category == "poi")\r
+                {\r
+                    m_places.append(new Location(newX, newY, name));\r
+                }\r
+                else if (category == "street")\r
+                {\r
+                    m_roadNames.append(new Location(newX, newY, name));\r
+                }\r
+                else if (category == "stop")\r
+                {\r
+                    m_stops.append(new Location(newX, newY, name));\r
+                }\r
+                else\r
+                {\r
+                    QString errorMessage("Unknown category: ");\r
+                    errorMessage.append(category);\r
+                    qDebug() << errorMessage;\r
+#ifdef Q_WS_MAEMO_5\r
+                    QMaemo5InformationBox::information(this, errorMessage);\r
+#endif\r
+                }\r
+            }\r
+\r
+            if (xmlName == "ERROR") {\r
+                responseHasError = true;\r
+            }\r
+\r
+        }\r
+    }\r
+\r
+    emit(busy(false));\r
+\r
+    qDebug() << xml.errorString();\r
+    if ( xml.hasError() || responseHasError ) {\r
+#ifdef Q_WS_MAEMO_5\r
+        QMaemo5InformationBox::information(this, "Invalid response received from Ytv.");\r
+#endif\r
+        qDebug() << "Invalid response received from Ytv";\r
+    } else {\r
+        // Case where no addresses are found.\r
+        if (m_places.size() + m_roadNames.size() + m_stops.size() == 0)\r
+        {\r
+#ifdef Q_WS_MAEMO_5\r
+            QMaemo5InformationBox::information(this, "No addresses were found with the given address.");\r
+#endif\r
+        }\r
+        // Case where addresses are found.\r
+        else        {\r
+            qDebug() << "Starting selection dialog";\r
+            AddressDialogSelection *selection = new AddressDialogSelection(this->m_places, this->m_roadNames, this->m_stops, this);\r
+            connect(selection, SIGNAL(locationSelected(Location*)), this, SLOT(locationSelected(Location*)));\r
+            selection->show();\r
+        }\r
+    }\r
+    //delete m_reply;\r
+    qDebug() << "Exiting xml parsing.";\r
+}\r
+\r
+void AddressDialog::typedInAddress()\r
+{\r
+    qDebug() << "Typed in address field signal detected.";\r
+    if (this->m_current != 0)\r
+    {\r
+        qDebug() << "Setting add button disabled and deleting current location.";\r
+        this->m_addButton->setEnabled(false);\r
+        delete this->m_current;\r
+        this->m_current = 0;\r
+    }\r
+}\r
+\r
+void AddressDialog::addLocation()\r
+{\r
+    this->m_current->setAddress(this->m_current->label());\r
+    this->m_current->setLabel(this->m_label->text());\r
+    Locations::GetInstance()->addEditLocation(this->m_current);\r
+    this->close();\r
+}\r
+\r
+void AddressDialog::locationSelected(Location* location)\r
+{\r
+    qDebug() << "Location selected and signal received. Setting add button enabled and correct text.";\r
+    if (location == 0)\r
+        qDebug() << "Null pointer received.";\r
+    this->m_current = location;\r
+    this->m_address->setText(this->m_current->label());\r
+    this->m_addButton->setEnabled(true);\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+void populateList(QListWidget *widget, const QList<Location*>& list);\r
+\r
+AddressDialogSelection::AddressDialogSelection(const QList<Location*> &places, const QList<Location*> &roads, const QList<Location*> &stops, QWidget *parent) :\r
+        QDialog(parent),\r
+        m_places(places),\r
+        m_roads(roads),\r
+        m_stops(stops)\r
+{\r
+    QVBoxLayout *layout = new QVBoxLayout();\r
+    this->setLayout(layout);\r
+    QListWidget *list = new QListWidget(this);\r
+    layout->addWidget(list);\r
+    connect(list, SIGNAL(itemClicked(QListWidgetItem*)),\r
+            this, SLOT(itemSelected(QListWidgetItem*)));\r
+    if (this->m_places.size() > 0)\r
+    {\r
+        QListWidgetItem *item = new QListWidgetItem("Places", list);\r
+        item->setFlags(item->flags() & (~Qt::ItemIsEnabled));\r
+        populateList(list, m_places);\r
+    }\r
+\r
+    if (m_roads.size() > 0)\r
+    {\r
+        QListWidgetItem *item = new QListWidgetItem("Street names", list);\r
+        item->setFlags(item->flags() & (~Qt::ItemIsEnabled));\r
+        populateList(list, m_roads);\r
+    }\r
+\r
+    if (m_stops.size() > 0)\r
+    {\r
+        QListWidgetItem *item = new QListWidgetItem("Stops", list);\r
+        item->setFlags(item->flags() & (~Qt::ItemIsEnabled));\r
+        populateList(list, m_stops);\r
+    }\r
+\r
+}\r
+\r
+void populateList(QListWidget *widget, const QList<Location*>& list)\r
+{\r
+    QList<Location*>::const_iterator it, ite;\r
+    for (it = list.constBegin(), ite = list.constEnd(); it != ite; ++it)\r
+    {\r
+        new QListWidgetItem((*it)->label(), widget);\r
+    }\r
+}\r
+\r
+\r
+Location* foundFromList(const QString address, const QList<Location*>& list);\r
+\r
+void AddressDialogSelection::itemSelected(QListWidgetItem *item)\r
+{\r
+    qDebug() << "Item selected";\r
+    QString address = item->text();\r
+    Location *location = 0;\r
+    location = foundFromList(address, this->m_places);\r
+    if (!location)\r
+        location = foundFromList(address, this->m_roads);\r
+    if (!location)\r
+        location = foundFromList(address, this->m_stops);\r
+    if (location)\r
+    {\r
+        qDebug() << "Found location pointer: " << location;\r
+        emit(locationSelected(location));\r
+        this->close();\r
+    }\r
+}\r
+\r
+Location* foundFromList(const QString address, const QList<Location*>& list)\r
+{\r
+    Location* ret = 0;\r
+    QList<Location*>::const_iterator it, ite;\r
+    for (it = list.constBegin(), ite = list.constEnd(); it != ite && !ret; ++it)\r
+    {\r
+        if (address == (*it)->label())\r
+        {\r
+            qDebug() << "Found item from list: " << *it;\r
+            ret = new Location(*it);\r
+            qDebug() << "After assignment: " << ret;\r
+        }\r
+    }\r
+    return ret;\r
+}\r
diff --git a/zouba/src/addressdialog.h b/zouba/src/addressdialog.h
new file mode 100644 (file)
index 0000000..dfe6a01
--- /dev/null
@@ -0,0 +1,83 @@
+#ifndef ADDRESSDIALOG_H
+#define ADDRESSDIALOG_H
+
+#include <QDialog>
+#include <QList>
+
+class Location;
+class QString;
+class QWidget;
+class QLineEdit;
+class QNetworkReply;
+class QListWidget;
+class QListWidgetItem;
+
+/* TODO: Layout
+ * - Name and andress text input fields in a form layout on the left
+ *   - Name text input field not enabled if editing an existing location
+ * - Buttons on the right
+ *   - Add button
+ *     - Enabled if search once and no typing has been done to address
+ *   - Search
+ *     - Searches for the address in the address text input field
+ */
+class AddressDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    explicit AddressDialog(QWidget *parent = 0, const Location *location = 0);
+
+signals:
+    void busy(bool busy);
+
+public slots:
+    void searchFinished();
+    void locationSelected(Location* location);
+
+private slots:
+    void searchAddress();
+    void addLocation();
+    void typedInAddress();
+
+private:
+    QLineEdit *m_label;
+    QLineEdit *m_address;
+    QPushButton *m_addButton;
+
+    QNetworkReply *m_reply;
+
+    QList<Location*> m_places;
+    QList<Location*> m_roadNames;
+    QList<Location*> m_stops;
+    
+    Location* m_current;
+};
+
+
+
+/* TODO: Layout
+ * - One list of found locations
+ * - Clicking one selects the location
+ * - If the clicked one is disabled, nothing happens (clicked signal might not be enabled so this needs to implemented only if selecting a heading line emits clicked signal
+ * - When selected emits locationSelected(Location *location) signal with the selected locations copy.
+ * - When selected calls close
+ */
+class AddressDialogSelection : public QDialog
+{
+    Q_OBJECT
+public:
+    explicit AddressDialogSelection(const QList<Location*> &places, const QList<Location*> &roads, const QList<Location*> &stops, QWidget *parent = 0);
+
+signals:
+    void locationSelected(Location* location);
+    
+private slots:
+    void itemSelected(QListWidgetItem *item);
+
+private:
+  const QList<Location*>& m_places;
+  const QList<Location*>& m_roads;
+  const QList<Location*>& m_stops;
+};
+
+#endif // ADDRESSDIALOGNEW_H
index d924564..aab676d 100644 (file)
@@ -1,65 +1,66 @@
 #include "gpscontroller.h"
-#include "gpscontroller_p.h"
+#include "locations.h"
 
 #include <QObject>
 #include <QGeoPositionInfo>
 #include <QGeoPositionInfoSource>
 #include <QDebug>
 
-GpsController::GpsController() :
-  q( new GpsControllerPrivate() )
-{
-  q->init();
-  q->startGps();
+GpsController::GpsController(bool started) :
+        m_gps(QGeoPositionInfoSource::createDefaultSource(this)),
+        m_started(started)
+{   
+    m_gps->setUpdateInterval(20000);
+    connect(m_gps, SIGNAL(positionUpdated(QGeoPositionInfo)),
+            this, SLOT(updateLocation(QGeoPositionInfo)));
+    connect(m_gps, SIGNAL(updateTimeout()),
+            this, SLOT(timeoutRequested()));
+    if (m_started) m_gps->startUpdates();
 }
 
-GpsController::GpsController( GpsControllerPrivate *gpsControllerPrivate ) :
-  q( gpsControllerPrivate )
+GpsController::~GpsController()
 {
-  q->init();
-  q->startGps();
+    delete m_gps;
 }
 
-GpsController::~GpsController()
+void GpsController::useGPS( bool use)
 {
-  delete q;
+    if (use) m_gps->startUpdates();
+    else m_gps->stopUpdates();
 }
 
-void GpsController::getGps()
+bool GpsController::isStarted() const
 {
-  Location *location;
-  Location *previousLocation = q->mostRecentlyReportedLocation();
-
-  if ( q->useFakeLocation() ) {
-    location = q->fakeLocation();
-  } else {
-    location = q->liveLocation();
-  }
-
-  if ( location != previousLocation ) {
-    emit locationChanged( location );
-  }
+    return m_started;
 }
 
-void GpsController::useLiveGps()
+QGeoPositionInfoSource *GpsController::gps() const
 {
-  q->setUseFakeLocation( false );
-  q->startGps();
-  emit locationChanged( q->liveLocation() );
+    return m_gps;
 }
 
-void GpsController::useFakeGps( const QString &fakeLocationLabel )
+void GpsController::updateLocation( QGeoPositionInfo positionInfo )
 {
-  qDebug() << "using fake gps (" << fakeLocationLabel << ")";
+    qDebug() << "GPS location update received";
+    Locations *locations = Locations::GetInstance();
+
+    //DEBUG
+    /*if (locations == 0)
+        qDebug() << "Null locations received from getInstance";
+    else
+        qDebug() << "Locations is not null";
+    Location* gpsLoc = locations->getGpsLocation();
+    if (gpsLoc == 0)
+        qDebug() << "Null gpsLocation received from locations";
+    else
+        qDebug() << "GPS location is not null.";*/
+    //DEBUG ENDED
 
-  q->setFakeLocationLabel( fakeLocationLabel );
-  Location  *fakeLocation = q->fakeLocation();
+    locations->getGpsLocation()->setLocation(positionInfo);
+    //emit(gpsLocationChanged(m_location));
+}
 
-  if ( fakeLocation == 0 ) {
-    qDebug() << "invalid fake location label; cannot use fake location";
-  } else {
-    q->stopGps();
-    q->setUseFakeLocation( true );
-    emit locationChanged( fakeLocation );
-  }
+void GpsController::timeoutRequested()
+{
+    qDebug() << "GPS sent timeout requested.";
 }
index 438b3f8..7433c6b 100644 (file)
@@ -3,34 +3,39 @@
 
 #include "location.h"
 
-#include "gpscontroller_p.h"
-
 #include <QObject>
 #include <QGeoPositionInfo>
 #include <QGeoPositionInfoSource>
 
-QTM_USE_NAMESPACE
+QTM_USE_NAMESPACE;
+
+class Location;
 
 class GpsController : public QObject
 {
-  Q_OBJECT
+    Q_OBJECT
 
 public:
-  GpsController();
-  GpsController( GpsControllerPrivate *gpsControllerPrivate );
+    GpsController(bool started = true);
 
-  ~GpsController();
+    ~GpsController();
+
+    QGeoPositionInfoSource *gps() const;
+    bool                    isStarted() const;
 
 public Q_SLOTS:
-  void getGps();
-  void useFakeGps( const QString &fakeLocationLabel );
-  void useLiveGps();
+    void useGPS( bool );
 
 Q_SIGNALS:
-  void locationChanged( Location *newLocation );
+    void gpsLocationChanged( Location *newLocation );
+
+private Q_SLOTS:
+    void updateLocation( QGeoPositionInfo positionInfo );
+    void timeoutRequested();
 
 private:
-    GpsControllerPrivate *q;
+    QGeoPositionInfoSource *m_gps;
+    bool                    m_started;
 };
 
 #endif // GPSCONTROLLER_H
diff --git a/zouba/src/gpscontroller_p.cpp b/zouba/src/gpscontroller_p.cpp
deleted file mode 100644 (file)
index 41086b0..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-#include "gpscontroller_p.h"
-
-#include "location.h"
-#include "locations.h"
-
-#include <QObject>
-#include <QGeoPositionInfo>
-#include <QGeoPositionInfoSource>
-#include <QDebug>
-
-QTM_USE_NAMESPACE
-
-GpsControllerPrivate::GpsControllerPrivate() :
-  m_gps(0),
-  m_liveLocation( new Location( "livegps" ) ),
-  m_fakeLocationLabel(),
-  m_useFakeLocation(false)
-{
-}
-
-GpsControllerPrivate::~GpsControllerPrivate()
-{
-  delete m_gps;
-  m_gps = 0;
-  delete m_liveLocation;
-  m_liveLocation = 0;
-}
-
-void GpsControllerPrivate::init()
-{
-  m_gps = QGeoPositionInfoSource::createDefaultSource(this);
-  connect(
-      m_gps, SIGNAL( positionUpdated( QGeoPositionInfo ) ),
-      this, SLOT( updateLocation( QGeoPositionInfo ) )
-  );
-}
-
-void GpsControllerPrivate::startGps()
-{
-  m_gps->startUpdates();
-}
-
-void GpsControllerPrivate::stopGps()
-{
-  m_gps->stopUpdates();
-}
-
-QGeoPositionInfoSource *GpsControllerPrivate::gps()
-{
-  return m_gps;
-}
-
-void GpsControllerPrivate::setGps( QGeoPositionInfoSource *gps )
-{
-  m_gps = gps;
-}
-
-Location *GpsControllerPrivate::liveLocation()
-{
-  m_mostRecentlyReportedLocation = m_liveLocation;
-  return m_liveLocation;
-}
-
-Location *GpsControllerPrivate::fakeLocation()
-{
-  Locations locations;
-  Location  *location = locations.location( fakeLocationLabel() );
-  m_mostRecentlyReportedLocation = location;
-  return location;
-}
-
-QString GpsControllerPrivate::fakeLocationLabel()
-{
-  return m_fakeLocationLabel;
-}
-
-void GpsControllerPrivate::setFakeLocationLabel( const QString &label )
-{
-  m_fakeLocationLabel = label;
-}
-
-bool GpsControllerPrivate::useFakeLocation()
-{
-  return m_useFakeLocation;
-}
-
-void GpsControllerPrivate::setUseFakeLocation( bool useFake )
-{
-  m_useFakeLocation = useFake;
-}
-
-void GpsControllerPrivate::updateLocation( QGeoPositionInfo positionInfo )
-{
-  m_liveLocation->setLocation( positionInfo );
-}
-
-Location *GpsControllerPrivate::mostRecentlyReportedLocation()
-{
-  return m_mostRecentlyReportedLocation;
-}
diff --git a/zouba/src/gpscontroller_p.h b/zouba/src/gpscontroller_p.h
deleted file mode 100644 (file)
index a101ffe..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef GPSCONTROLLER_P_H
-#define GPSCONTROLLER_P_H
-
-#include <QGeoPositionInfo>
-#include <QGeoPositionInfoSource>
-
-QTM_USE_NAMESPACE
-
-class Location;
-
-class GpsControllerPrivate : public QObject
-{
-    Q_OBJECT
-
-public:
-    GpsControllerPrivate();
-    ~GpsControllerPrivate();
-
-    virtual void init();
-    virtual void startGps();
-    virtual void stopGps();
-
-    virtual void setGps( QGeoPositionInfoSource *gps );
-    virtual void setFakeLocationLabel( const QString &label );
-    virtual void setUseFakeLocation( bool useFake );
-
-    virtual QGeoPositionInfoSource *gps();
-    virtual Location               *liveLocation();
-    virtual Location               *fakeLocation();
-    virtual Location               *mostRecentlyReportedLocation();
-    virtual QString                 fakeLocationLabel();
-    virtual bool                    useFakeLocation();
-
-private Q_SLOTS:
-    virtual void updateLocation( QGeoPositionInfo positionInfo );
-
-private:
-    QGeoPositionInfoSource *m_gps;
-    Location               *m_liveLocation;
-    QString                 m_fakeLocationLabel;
-    bool                    m_useFakeLocation;
-    Location               *m_mostRecentlyReportedLocation;
-};
-
-#endif //GPSCONTROLLER_P_H
index c54f65c..d799a82 100644 (file)
@@ -1,7 +1,5 @@
 #include "location.h"
 
-#include "location_p.h"
-
 #include "ytv.h"
 
 #include <QString>
 
 #include <math.h>
 
-const double Location::KkjZoneInfo[6][2] = {
-  {18.0,  500000.0},
-  {21.0, 1500000.0},
-  {24.0, 2500000.0},
-  {27.0, 3500000.0},
-  {30.0, 4500000.0},
-  {33.0, 5500000.0}
+const double KkjZoneInfo[6][2] = {
+    {18.0,  500000.0},
+    {21.0, 1500000.0},
+    {24.0, 2500000.0},
+    {27.0, 3500000.0},
+    {30.0, 4500000.0},
+    {33.0, 5500000.0}
 };
 
+#ifdef Q_WS_MAEMO_5
 QTM_USE_NAMESPACE
-
-Location::Location( const QString &x, const QString &y, const QString &label ) :
-  q( new LocationPrivate( x, y, label ) ),
-  manager( new QNetworkAccessManager(this) )
-{
-  connect(
-      manager, SIGNAL( finished(QNetworkReply*) ),
-      this, SLOT( replyFinished(QNetworkReply*) )
-      );
-}
-
-Location::Location( const QGeoPositionInfo &positionInfo, const QString &label ) :
-  q( new LocationPrivate( label ) ),
-  manager(0)
-{
-  setLocation( positionInfo );
-}
-
-void Location::setLocation( const QGeoPositionInfo &positionInfo )
-{
-  qreal latitude = positionInfo.coordinate().latitude();
-  qreal longitude = positionInfo.coordinate().longitude();
-
-  KKJ outX(0);
-  KKJ outY(0);
-
-  WGS84lola_to_KKJxy( longitude, latitude, &outX, &outY);
-
-  q->setX( outX );
-  q->setY( outY );
-  q->setValid( true );
-}
-
-Location::Location( const Location &from ) :
-  QObject(0),
-  q( new LocationPrivate( from.label() ) ),
-  manager(0)
+#endif
+
+        Location::Location( const QString &x, const QString &y, const QString &label ) :
+        m_label(label),
+        m_address(QString()),
+        m_x(x),
+        m_y(y),
+        m_valid(true)
 {
-  q->setAddress( from.address() );
-  q->setX( from.x() );
-  q->setY( from.y() );
-  q->setValid( from.isValid() );
-  if ( from.manager != 0 ) {
-    manager = new QNetworkAccessManager(this);
-    connect( manager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( replyFinished(QNetworkReply*) ) );
-  }
 }
-
-Location::Location( const QString &label ) :
-  q( new LocationPrivate( label ) ),
-  manager( new QNetworkAccessManager(this) )
+#ifdef Q_WS_MAEMO_5
+Location::Location(const QGeoPositionInfo &positionInfo, const QString &label) :
+        m_label(label),
+        m_address(QString()),
+        m_x("0"),
+        m_y("0"),
+        m_valid(false)
 {
-  connect( manager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( replyFinished(QNetworkReply*) ) );
+    setLocation(positionInfo);
 }
 
-Location::~Location()
+void Location::setLocation(const QGeoPositionInfo &positionInfo)
 {
-  delete q;
-  q=0;
-  delete manager;
-  manager=0;
+    qDebug() << "Setting new location based on GeoPositionInfo";
+    qreal latitude = positionInfo.coordinate().latitude();
+    qreal longitude = positionInfo.coordinate().longitude();
+
+    //qDebug() << "Calculating new values";
+
+    KKJ outX(0);
+    KKJ outY(0);
+
+    WGS84lola_to_KKJxy( longitude, latitude, &outX, &outY);
+
+    /*qDebug() << "Storing new values";
+    qDebug() << "x";
+    qDebug() << outX;
+    qDebug() << "y";
+    qDebug() << outY;*/
+
+    //qDebug() << "Setting x";
+    //this->m_x = QString("%1").arg(outX);
+    this->m_x.setNum(outX);
+    //qDebug() << "Setting y";
+    //this->m_y = QString("%1").arg(outY);
+    this->m_y.setNum(outY);
+    //qDebug() << "Setting as valid";
+    this->m_valid = true;
+    emit(becomeValid());
+    //qDebug() << "Location set";
 }
+#endif
 
-Location &Location::operator=( const Location &from )
+void Location::setPosition(const QString &x, const QString &y)
 {
-  q = new LocationPrivate( from.label() );
-  q->setAddress( from.address() );
-  q->setX( from.x() );
-  q->setY( from.y() );
-  q->setValid( from.isValid() );
-
-  if ( from.manager != 0 ) {
-    manager = new QNetworkAccessManager(this);
-    connect( manager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( replyFinished(QNetworkReply*) ) );
-  } else {
-    manager = 0;
-  }
-
-  return *this;
+    this->m_x = x;
+    this->m_y = y;
+    this->m_valid = true;
 }
 
-void Location::resolveAddress( const QString &address )
+Location::Location(const QString &label) :
+        m_label(label),
+        m_address(QString()),
+        m_x("0"),
+        m_y("0"),
+        m_valid(false)
 {
-  qDebug() << "resolving address (" << address << ")";
-
-  q->setAddress( address );
-  q->setValid( false );
-
-  QUrl fullUrl( Ytv::Url );
-
-  fullUrl.addEncodedQueryItem( "key", address.toAscii().toPercentEncoding() );
-  fullUrl.addQueryItem( "user", Ytv::Username );
-  fullUrl.addQueryItem( "pass", Ytv::Password );
-
-  manager->get( QNetworkRequest( fullUrl ) );
-  qDebug() << "waiting for reply from Ytv";
-  emit( busy( true ) );
 }
 
-void Location::replyFinished( QNetworkReply * reply )
+Location::Location(const Location *location) :
+        m_label(location->m_label),
+        m_address(location->m_address),
+        m_x(location->m_x),
+        m_y(location->m_y),
+        m_valid(location->m_valid)
 {
-  qDebug() << "address resolved";
-  q->parseReply( reply->readAll() );
-
-  if ( isValid() ) {
-    qDebug() << label() << "becomeValid";
-    emit( becomeValid() );
-  } else {
-    qDebug() << label() << "not valid";
-    emit( becomeInValid() );
-  }
-
-  emit( busy( false ) );
 }
 
 QString Location::x() const
 {
-  return q->x();
+    return m_x;
 }
 
 QString Location::y() const
 {
-  return q->y();
+    return m_y;
 }
 
-void Location::setLabel( const QString &label ) const
+void Location::setLabel(const QString &label)
 {
-  q->setLabel( label );
+    m_label = label;
 }
 
 QString Location::label() const
 {
-  return q->label();
+    return m_label;
 }
 
-void Location::setAddress( const QString &address ) const
+void Location::setAddress(const QString &address)
 {
-  qDebug() << "setting address to" << address;
-  q->setAddress( address );
+    m_address = address;
 }
 
 QString Location::address() const
 {
-  return q->address();
+    return m_address;
 }
 
 bool Location::isValid() const
 {
-  return q->isValid();
+    return m_valid;
 }
 
 // Degrees to radians
-double Location::radians(double deg)
+double radians(double deg)
 {
-  return deg * M_PI / 180.0;
+    return deg * M_PI / 180.0;
 }
 
 // Radians to degrees
-double Location::degrees(double rad)
+double degrees(double rad)
 {
-  return rad * 180.0 / M_PI;
+    return rad * 180.0 / M_PI;
 }
 
 // Function:  KKJ_Zone_I
-int Location::KKJ_Zone_I(KKJ easting)
+int KKJ_Zone_I(KKJ easting)
 {
-  int zoneNumber = floor(easting / 1000000.0);
-  if (zoneNumber < 0 || zoneNumber > 5) {
-    zoneNumber = -1;
-  }
+    int zoneNumber = floor(easting / 1000000.0);
+    if (zoneNumber < 0 || zoneNumber > 5) {
+        zoneNumber = -1;
+    }
 
-  return zoneNumber;
+    return zoneNumber;
 }
 
 // Function:  KKJ_Zone_Lo
-int Location::KKJ_Zone_Lo(double kkjlo)
+int KKJ_Zone_Lo(double kkjlo)
 {
-  // determine the zonenumber from KKJ easting
-  // takes KKJ zone which has center meridian
-  // longitude nearest (in math value) to
-  // the given KKJ longitude
-  int zoneNumber = 5;
-  while (zoneNumber >= 0) {
-    if (fabs(kkjlo - KkjZoneInfo[zoneNumber][0]) <= 1.5) {
-      break;
+    // determine the zonenumber from KKJ easting
+    // takes KKJ zone which has center meridian
+    // longitude nearest (in math value) to
+    // the given KKJ longitude
+    int zoneNumber = 5;
+    while (zoneNumber >= 0) {
+        if (fabs(kkjlo - KkjZoneInfo[zoneNumber][0]) <= 1.5) {
+            break;
+        }
+        zoneNumber--;
     }
-    zoneNumber--;
-  }
 
-  return zoneNumber;
+    return zoneNumber;
 }
 
 
 // Function:  KKJlalo_to_WGS84lalo
-void Location::KKJlola_to_WGS84lola(double kkjlo, double kkjla, double *outLongitude, double *outLatitude)
+void KKJlola_to_WGS84lola(double kkjlo, double kkjla, double *outLongitude, double *outLatitude)
 {
-  double dLa = radians(0.124867E+01 + -0.269982E+00 * kkjla + 0.191330E+00 * kkjlo + 0.356119E-02 * kkjla * kkjla + -0.122312E-02 * kkjla * kkjlo + -0.335514E-03 * kkjlo * kkjlo) / 3600.0;
-  double dLo = radians(-0.286111E+02 + 0.114183E+01 * kkjla + -0.581428E+00 * kkjlo + -0.152421E-01 * kkjla * kkjla + 0.118177E-01 * kkjla * kkjlo + 0.826646E-03 * kkjlo * kkjlo) / 3600.0;
+    double dLa = radians(0.124867E+01 + -0.269982E+00 * kkjla + 0.191330E+00 * kkjlo + 0.356119E-02 * kkjla * kkjla + -0.122312E-02 * kkjla * kkjlo + -0.335514E-03 * kkjlo * kkjlo) / 3600.0;
+    double dLo = radians(-0.286111E+02 + 0.114183E+01 * kkjla + -0.581428E+00 * kkjlo + -0.152421E-01 * kkjla * kkjla + 0.118177E-01 * kkjla * kkjlo + 0.826646E-03 * kkjlo * kkjlo) / 3600.0;
 
-  *outLatitude = degrees(radians(kkjla) + dLa);
-  *outLongitude = degrees(radians(kkjlo) + dLo);
+    *outLatitude = degrees(radians(kkjla) + dLa);
+    *outLongitude = degrees(radians(kkjlo) + dLo);
 }
 
 
 // Function:  WGS84lalo_to_KKJlalo
-void Location::WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude)
+void WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude)
 {
-  double dLa = radians(-0.124766E+01 + 0.269941E+00 * latitude + -0.191342E+00 * longitude + -0.356086E-02 * latitude * latitude + 0.122353E-02 * latitude * longitude + 0.335456E-03 * longitude * longitude) / 3600.0;
-  double dLo = radians(0.286008E+02 + -0.114139E+01 * latitude + 0.581329E+00 * longitude + 0.152376E-01 * latitude * latitude + -0.118166E-01 * latitude * longitude + -0.826201E-03 * longitude * longitude) / 3600.0;
+    double dLa = radians(-0.124766E+01 + 0.269941E+00 * latitude + -0.191342E+00 * longitude + -0.356086E-02 * latitude * latitude + 0.122353E-02 * latitude * longitude + 0.335456E-03 * longitude * longitude) / 3600.0;
+    double dLo = radians(0.286008E+02 + -0.114139E+01 * latitude + 0.581329E+00 * longitude + 0.152376E-01 * latitude * latitude + -0.118166E-01 * latitude * longitude + -0.826201E-03 * longitude * longitude) / 3600.0;
 
-  *outLatitude = degrees(radians(latitude) + dLa);
-  *outLongitude = degrees(radians(longitude) + dLo);
+    *outLatitude = degrees(radians(latitude) + dLa);
+    *outLongitude = degrees(radians(longitude) + dLo);
 }
 
 
 // Function:  KKJlalo_to_KKJxy
-void Location::KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY)
+void KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY)
 {
-  // Hayford ellipsoid
-  double a = 6378388.0;
-  double f  = 1.0 / 297.0;
-  double b  = (1.0 - f) * a;
-  double bb = b * b;
-  double c  = (a / b) * a;
-  double ee = (a * a - bb) / bb;
-  double n = (a - b) / (a + b);
-  double nn = n * n;
-
-  double Lo = radians(lon) - radians(KkjZoneInfo[zoneNumber][0]);
-  double cosLa = cos(radians(lat));
-  double NN = ee * cosLa * cosLa;
-  double LaF = atan(tan(radians(lat)) / cos(Lo * sqrt(1.0 + NN)));
-  double cosLaF = cos(LaF);
-  double t = (tan(Lo) * cosLaF) / sqrt(1.0 + ee * cosLaF * cosLaF);
-  double A = a / (1.0 + n);
-  double A1 = A * (1.0 + nn / 4.0 + nn * nn / 64.0);
-  double A2 = A * 1.5 * n * (1.0 - nn / 8.0);
-  double A3 = A * 0.9375 * nn * (1.0 - nn / 4.0);
-  double A4 = A * 35.0 / 48.0 * nn * n;
-
-  *outY = A1 * LaF - A2 * sin(2.0 * LaF) + A3 * sin(4.0 * LaF) - A4 * sin(6.0 * LaF);
-  *outX = c * log(t + sqrt(1.0 + t * t)) + 500000.0 + zoneNumber * 1000000.0;
+    // Hayford ellipsoid
+    double a = 6378388.0;
+    double f  = 1.0 / 297.0;
+    double b  = (1.0 - f) * a;
+    double bb = b * b;
+    double c  = (a / b) * a;
+    double ee = (a * a - bb) / bb;
+    double n = (a - b) / (a + b);
+    double nn = n * n;
+
+    double Lo = radians(lon) - radians(KkjZoneInfo[zoneNumber][0]);
+    double cosLa = cos(radians(lat));
+    double NN = ee * cosLa * cosLa;
+    double LaF = atan(tan(radians(lat)) / cos(Lo * sqrt(1.0 + NN)));
+    double cosLaF = cos(LaF);
+    double t = (tan(Lo) * cosLaF) / sqrt(1.0 + ee * cosLaF * cosLaF);
+    double A = a / (1.0 + n);
+    double A1 = A * (1.0 + nn / 4.0 + nn * nn / 64.0);
+    double A2 = A * 1.5 * n * (1.0 - nn / 8.0);
+    double A3 = A * 0.9375 * nn * (1.0 - nn / 4.0);
+    double A4 = A * 35.0 / 48.0 * nn * n;
+
+    *outY = A1 * LaF - A2 * sin(2.0 * LaF) + A3 * sin(4.0 * LaF) - A4 * sin(6.0 * LaF);
+    *outX = c * log(t + sqrt(1.0 + t * t)) + 500000.0 + zoneNumber * 1000000.0;
 }
 
 // Function:  KKJxy_to_KKJlalo
-void Location::KKJxy_to_KKJlola(KKJ x, KKJ y, double *outLongitude, double *outLatitude)
+void KKJxy_to_KKJlola(KKJ x, KKJ y, double *outLongitude, double *outLatitude)
 {
-  // Scan iteratively the target area, until find matching
-  // KKJ coordinate value.  Area is defined with Hayford Ellipsoid.
-  int zoneNumber = KKJ_Zone_I(x);
-  double minLo = radians(18.5);
-  double maxLo = radians(32.0);
-  double minLa = radians(59.0);
-  double maxLa = radians(70.5);
-
-  int i = 1;
-  KKJ tmpX, tmpY;
-
-  while (i < 35) {
-    double deltaLo = maxLo - minLo;
-    double deltaLa = maxLa - minLa;
-    *outLongitude = degrees(minLo + 0.5 * deltaLo);
-    *outLatitude = degrees(minLa + 0.5 * deltaLa);
-    KKJlola_to_KKJxy(*outLongitude, *outLatitude, zoneNumber, &tmpX, &tmpY);
-    if (tmpY < y) {
-      minLa = minLa + 0.45 * deltaLa;
-    } else {
-      maxLa = minLa + 0.55 * deltaLa;
-    }
-
-    if (tmpX < x) {
-      minLo = minLo + 0.45 * deltaLo;
-    } else {
-      maxLo = minLo + 0.55 * deltaLo;
+    // Scan iteratively the target area, until find matching
+    // KKJ coordinate value.  Area is defined with Hayford Ellipsoid.
+    int zoneNumber = KKJ_Zone_I(x);
+    double minLo = radians(18.5);
+    double maxLo = radians(32.0);
+    double minLa = radians(59.0);
+    double maxLa = radians(70.5);
+
+    int i = 1;
+    KKJ tmpX, tmpY;
+
+    while (i < 35) {
+        double deltaLo = maxLo - minLo;
+        double deltaLa = maxLa - minLa;
+        *outLongitude = degrees(minLo + 0.5 * deltaLo);
+        *outLatitude = degrees(minLa + 0.5 * deltaLa);
+        KKJlola_to_KKJxy(*outLongitude, *outLatitude, zoneNumber, &tmpX, &tmpY);
+        if (tmpY < y) {
+            minLa = minLa + 0.45 * deltaLa;
+        } else {
+            maxLa = minLa + 0.55 * deltaLa;
+        }
+
+        if (tmpX < x) {
+            minLo = minLo + 0.45 * deltaLo;
+        } else {
+            maxLo = minLo + 0.55 * deltaLo;
+        }
+
+        i++;
     }
-
-    i++;
-  }
 }
 
-void Location::WGS84lola_to_KKJxy(double longitude, double latitude, KKJ *outX, KKJ *outY)
+void WGS84lola_to_KKJxy(double longitude, double latitude, KKJ *outX, KKJ *outY)
 {
-  double kkjlo, kkjla;
+    double kkjlo, kkjla;
 
-  WGS84lola_to_KKJlola(longitude, latitude, &kkjlo, &kkjla);
-  int zoneNumber = KKJ_Zone_Lo(kkjlo);
-  KKJlola_to_KKJxy(kkjlo, kkjla, zoneNumber, outX, outY);
+    WGS84lola_to_KKJlola(longitude, latitude, &kkjlo, &kkjla);
+    int zoneNumber = KKJ_Zone_Lo(kkjlo);
+    KKJlola_to_KKJxy(kkjlo, kkjla, zoneNumber, outX, outY);
 }
 
-void Location::KKJxy_to_WGS84lola(KKJ x, KKJ y, double *outLongitude, double *outLatitude)
+void KKJxy_to_WGS84lola(KKJ x, KKJ y, double *outLongitude, double *outLatitude)
 {
-  double kkjlo, kkjla;
+    double kkjlo, kkjla;
 
-  KKJxy_to_KKJlola(x, y, &kkjlo, &kkjla);
-  KKJlola_to_WGS84lola(kkjlo, kkjla, outLongitude, outLatitude);
+    KKJxy_to_KKJlola(x, y, &kkjlo, &kkjla);
+    KKJlola_to_WGS84lola(kkjlo, kkjla, outLongitude, outLatitude);
 
 }
-
index dfb5d00..3f009b4 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef LOCATION_H
 #define LOCATION_H
 
-#include "location_p.h"
-
 #include <QString>
 #include <QObject>
 #include <QNetworkAccessManager>
 #include <QGeoPositionInfo>
 #include <math.h>
 
-QTM_USE_NAMESPACE
+QTM_USE_NAMESPACE;
 
 class Location : public QObject
 {
-Q_OBJECT
+    Q_OBJECT
 
 public:
-  Location( const QString &x, const QString &y, const QString &label=QString() );
-  Location( const QGeoPositionInfo &positionInfo, const QString &label=QString() );
-  Location( const Location &from );
-  Location &operator=( const Location &from );
-  Location( const QString &label=QString() );
-
-  ~Location();
+    Location( const QString &x, const QString &y, const QString &label=QString() );
+    Location( const QGeoPositionInfo &positionInfo, const QString &label=QString() );
+    Location( const QString &label=QString() );
+    Location(const Location* location);
 
-  QString x() const;
+    QString x() const;
 
-  QString y() const;
+    QString y() const;
 
-  void setLocation( const QGeoPositionInfo &positionInfo );
+    void setLocation( const QGeoPositionInfo &positionInfo );
 
-  void setAddress( const QString &address ) const;
-  QString address() const;
+    void setPosition(const QString &x, const QString &y);
 
-  void setLabel( const QString &label ) const;
-  QString label() const;
+    void setAddress( const QString &address );
+    QString address() const;
 
-  bool isValid() const;
+    void setLabel( const QString &label );
+    QString label() const;
 
-public Q_SLOTS:
-  void resolveAddress( const QString &address );
+    bool isValid() const;
 
 Q_SIGNALS:
-  void becomeValid();
-  void becomeInValid();
-  void busy( bool busy );
-
-private Q_SLOTS:
-  void replyFinished( QNetworkReply * reply );
+    void becomeValid();
+    void becomeInValid();
+    void busy( bool busy );
 
 private:
+    QString m_label;
+    QString m_address;
+    QString m_x;
+    QString m_y;
+    bool m_valid;
+};
 
-  LocationPrivate *q;
-  QNetworkAccessManager *manager;
 
-  typedef uint KKJ;
+typedef uint KKJ;
 
-  /**
+/**
    * Transformes WGS84 longitude/latitude coordinates to KKJ x/y coordinates.
    * @param longitude the input longitude in degrees
    * @param latitude the input latitude in degrees
    * @param outX the result x (easting)
    * @param outY the result y (northing)
    */
-  void WGS84lola_to_KKJxy(double longitude, double latitude, KKJ *outX, KKJ *outY);
+void WGS84lola_to_KKJxy(double longitude, double latitude, KKJ *outX, KKJ *outY);
 
-  /**
+/**
    * Transformes KKJ x/y coordinates to WGS84 longitude/latitude coordinates.
    * @param x the input x (easting)
    * @param y the input y (northing)
    * @param outLongitude the result longitude in degrees
    * @param outLatitude the result latitude in degrees
    */
-  void KKJxy_to_WGS84lola(KKJ x, KKJ y, double *outLongitude, double *outLatitude);
+void KKJxy_to_WGS84lola(KKJ x, KKJ y, double *outLongitude, double *outLatitude);
 
-  // Degrees to radians
-  double radians(double deg);
+// Degrees to radians
+double radians(double deg);
 
-  // Radians to degrees
-  double degrees(double rad);
+// Radians to degrees
+double degrees(double rad);
 
-  // Constants
-  // Longitude0 and Center meridian of KKJ bands
-  static const double KkjZoneInfo[][2];
+// Constants
+// Longitude0 and Center meridian of KKJ bands
+//static const double KkjZoneInfo[][2];
 
-  // Function:  KKJ_Zone_I
-  int KKJ_Zone_I(KKJ easting);
+// Function:  KKJ_Zone_I
+int KKJ_Zone_I(KKJ easting);
 
-  // Function:  KKJ_Zone_Lo
-  int KKJ_Zone_Lo(double kkjlo);
+// Function:  KKJ_Zone_Lo
+int KKJ_Zone_Lo(double kkjlo);
 
-  // Function:  KKJlalo_to_WGS84lalo
-  void KKJlola_to_WGS84lola(double kkjlo, double kkjla, double *outLongitude, double *outLatitude);
+// Function:  KKJlalo_to_WGS84lalo
+void KKJlola_to_WGS84lola(double kkjlo, double kkjla, double *outLongitude, double *outLatitude);
 
-  // Function:  WGS84lalo_to_KKJlalo
-  void WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude);
+// Function:  WGS84lalo_to_KKJlalo
+void WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude);
 
-  // Function:  KKJlalo_to_KKJxy
-  void KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY);
+// Function:  KKJlalo_to_KKJxy
+void KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY);
 
-  // Function:  KKJxy_to_KKJlalo
-  void KKJxy_to_KKJlola(KKJ x, KKJ y, double *outLongitude, double *outLatitude);
+// Function:  KKJxy_to_KKJlalo
+void KKJxy_to_KKJlola(KKJ x, KKJ y, double *outLongitude, double *outLatitude);
 
-};
 
 #endif // LOCATION_H
diff --git a/zouba/src/location_p.cpp b/zouba/src/location_p.cpp
deleted file mode 100644 (file)
index fe9d555..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-#include <stdio.h>
-#include "location_p.h"
-
-#include <QXmlStreamReader>
-#include <QByteArray>
-#include <QDebug>
-#include <QMaemo5InformationBox>
-
-LocationPrivate::LocationPrivate( const QString &x, const QString &y, const QString &label ) :
-  m_label(label),
-  m_address(),
-  m_x(x),
-  m_y(y),
-  m_valid(true)
-{
-}
-
-LocationPrivate::LocationPrivate( const QString &label ) :
-  m_label(label),
-  m_address(),
-  m_x(0),
-  m_y(0),
-  m_valid(false)
-{
-}
-
-LocationPrivate::~LocationPrivate()
-{
-  m_label="deleted";
-  m_address="";
-  m_x="";
-  m_y="";
-  m_valid=false;
-}
-
-void LocationPrivate::parseReply( const QByteArray &reply )
-{
-  qDebug() << "parsing";
-  QXmlStreamReader xml( reply );
-  bool responseHasError = false;
-
-  while ( !xml.atEnd() ) {
-    xml.readNext();
-
-    if ( xml.isStartElement() ) {
-      QString xmlName( xml.name().toString() );
-
-      if ( xmlName == "LOC" ) {
-        QXmlStreamAttributes attributes( xml.attributes() );
-        QStringRef xAttribute( attributes.value("x") );
-        QStringRef yAttribute( attributes.value("y") );
-        QString newX( xAttribute.toString() );
-        QString newY( yAttribute.toString() );
-
-        m_x = newX;
-        m_y = newY;
-      }
-
-      if ( xmlName == "ERROR" ) {
-        responseHasError = true;
-      }
-
-    }
-  }
-
-  if ( xml.hasError() || responseHasError ) {
-    QMaemo5InformationBox::information( 0, "address resolution error - please check address" );
-    qDebug() << "xml error";
-    m_valid = false;
-  } else {
-    qDebug() << "(" << m_x << "," << m_y << ")";
-    if ( m_x.isEmpty() ||  m_y.isEmpty() ) {
-      qDebug() << "is NOT valid";
-      m_valid = false;
-    } else {
-      qDebug() << "is now valid";
-      m_valid = true;
-    }
-  }
-}
-
-void LocationPrivate::setLabel( const QString &label)
-{
-  m_label = label;
-}
-
-QString LocationPrivate::label() const
-{
-  return m_label;
-}
-
-void LocationPrivate::setAddress( const QString &address)
-{
-  m_address = address;
-}
-
-QString LocationPrivate::address() const
-{
-  return m_address;
-}
-
-void LocationPrivate::setX( uint x )
-{
-  m_x = QString( "%1" ).arg( x );
-}
-
-void LocationPrivate::setX( const QString &x )
-{
-  m_x = x;
-}
-
-QString LocationPrivate::x() const
-{
-  return m_x;
-}
-
-void LocationPrivate::setY( uint y )
-{
-  m_y = QString( "%1" ).arg( y );
-}
-
-void LocationPrivate::setY( const QString &y )
-{
-  m_y = y;
-}
-
-QString LocationPrivate::y() const
-{
-  return m_y;
-}
-
-void LocationPrivate::setValid( bool valid )
-{
-  m_valid = valid;
-}
-
-bool LocationPrivate::isValid() const
-{
-  return m_valid;
-}
diff --git a/zouba/src/location_p.h b/zouba/src/location_p.h
deleted file mode 100644 (file)
index e32b267..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-#ifndef LOCATION_P_H
-#define LOCATION_P_H
-
-#include <QObject>
-#include <QString>
-#include <QByteArray>
-
-class LocationPrivate : public QObject
-{
-    Q_OBJECT
-
-public:
-  LocationPrivate( const QString &x, const QString &y, const QString &label );
-  LocationPrivate( const QString &label );
-  virtual ~LocationPrivate();
-
-  void setX( uint x );
-  void setX( const QString &x );
-  QString x() const;
-
-  void setY( uint y );
-  void setY( const QString &y );
-  QString y() const;
-
-  void setAddress( const QString &address );
-  QString address() const;
-
-  void setLabel( const QString &label );
-  QString label() const;
-
-  void setValid( bool valid );
-  bool isValid() const;
-
-  void parseReply( const QByteArray &reply );
-
-  QString m_label;
-  QString m_address;
-  QString m_x;
-  QString m_y;
-  bool    m_valid;
-};
-
-#endif // LOCATION_P_H
-
diff --git a/zouba/src/locationbutton.cpp b/zouba/src/locationbutton.cpp
new file mode 100644 (file)
index 0000000..528dc64
--- /dev/null
@@ -0,0 +1,20 @@
+/*#include "locationbutton.h"
+
+locationButton::locationButton(Locations& locations, QObject *parent) :
+        m_locations(locations), QValueButton(parent)
+{
+    QStandardItemModel model(0,1);
+
+}
+
+
+locationButton::Location* getSelected()
+{
+    //return this.
+}
+
+void locationButton::updateLocations() {
+
+}
+
+*/
diff --git a/zouba/src/locationbutton.h b/zouba/src/locationbutton.h
new file mode 100644 (file)
index 0000000..3db2393
--- /dev/null
@@ -0,0 +1,25 @@
+/*#ifndef LOCATIONBUTTON_H
+#define LOCATIONBUTTON_H
+
+#include <QMaemo5ValueButton>
+
+class locationButton : public QValueButton
+{
+    Q_OBJECT
+    //Locations& m_locations;
+    //QStandartItemModel
+
+public:
+    //explicit locationButton(Locations& locations, QObject *parent = 0);
+
+    //Location* getSelected();
+
+signals:
+
+public slots:
+    void updateLocations();
+
+};
+
+#endif // LOCATIONBUTTON_H
+*/
index 358a2cc..c4bbddb 100644 (file)
@@ -1,4 +1,5 @@
 #include "locations.h"
+#include "location.h"
 
 #include <QDebug>
 #include <QHash>
 #include <QString>
 #include <QStringList>
 #include <QCoreApplication>
+#include <QMap>
+#include <QMapIterator>
+#include <QList>
 
-QHash<QString,Location *> Locations::locationHash;
-bool Locations::initialised = false;
+Locations* Locations::m_instance = 0;
 
-Locations::Locations()
+Locations* Locations::GetInstance()
 {
-    if ( !initialised ) {
-        QCoreApplication::setOrganizationName("ZouBa");
-        QCoreApplication::setOrganizationDomain("zouba.yi.org");
-        QCoreApplication::setOrganizationName("ZouBa");
+    if (m_instance == 0)
+        m_instance = new Locations();
 
-        restoreLocations();
-        initialised = true;
-    }
+    return m_instance;
 }
 
-Locations::~Locations()
+/*void Locations::destroyLocations()
+{
+    delete m_instance;
+}*/
+
+Locations::Locations() :
+        m_locationStorage(QHash<QString,Location *>()),
+        m_indexStorage(QList<QString>()),
+        m_gpsLocation(new Location("GPS"))
 {
+    this->restoreLocations();
+    qDebug() << "Size of index storage:" << this->m_indexStorage.size();
 }
 
-bool Locations::addLocation( Location *location )
+/*Locations::~Locations()
 {
-  bool succeeded=false;
+    QHash<QString,Location*>::iterator it, ite;
+    for (it = this->m_locationStorage.begin(), ite = this->m_locationStorage.end(); it != ite; ++it)
+    {
+        delete it.value();
+    }
+    this->m_locationStorage.empty();
+    delete m_gpsLocation;
+}*/
 
-  // if it's valid now, save the setting
-  if ( location->isValid() ) {
-    saveLocation( location );
-  }
+bool Locations::addEditLocation(Location *location)
+{
+    bool addedNew=false;
+
+    if ( !this->m_locationStorage.contains(location->label())) {
+        qDebug() << "Adding location" << location->label();
+        this->m_locationStorage[location->label()] = location;
+        qDebug() << "Index storage:";
+        qDebug() << this->m_indexStorage;
+        qDebug() << "Size of index storage:" << this->m_indexStorage.size();
+        this->m_indexStorage.append(location->label());
+        qDebug() << "Index storage after inserting location:";
+        qDebug() << this->m_indexStorage;
+        addedNew = true;
+    } else {
+        qDebug() << "A location with the same label (" << location->label() << ") already exists.";
+        this->m_locationStorage.remove(location->label());
+        this->m_locationStorage[location->label()] = location;
+    }
+    emit(locationsChanged());
 
-  if ( !locationHash.contains( location->label() ) ) {
-    qDebug() << "Adding location" << location->label();
-    locationHash[ location->label() ] = location;
-    succeeded = true;
-  } else {
-    qDebug() << "FAILED to add location" << location->label();
-  }
+    // save the location to settings
+    this->saveLocation(location);
 
-  return succeeded;
+    return addedNew;
 }
 
 void Locations::restoreLocations()
 {
-  QSettings settings;
+    QSettings settings;
+
+    settings.beginGroup("Locations");
+    QStringList labels = settings.childGroups();
+
+    QMap<QString, int> tempIndex = QMap<QString, int>();
+
+    for( int i=0; i<labels.size(); ++i ) {
+        QString label = labels[i];
+        settings.beginGroup(label);
+        QString address, x, y;
+        bool valid = false;
+        if (settings.contains("address")) {
+            address = settings.value( "address" ).toString();
+            if (settings.contains("x")) {
+                x = settings.value( "x" ).toString();
+                if (settings.contains("y")) {
+                    y = settings.value( "y" ).toString();
+                    valid = true;
+                }
+            }
+        }
+        int index = settings.value("index").toInt();
+        settings.endGroup();
+
+        qDebug() << "Restoring " << label;
+        Location *location;
+        if (valid) {
+            location = new Location( x, y, label );
+            location->setAddress(address);
+        }
+        else
+            location = new Location(label);
+
+        this->m_locationStorage[label] = location;
+        this->m_indexStorage.append(label);
+        if (index != 0)
+            tempIndex.insert(label, index);
+    }
 
-  settings.beginGroup( "Locations" );
-  QStringList labels = settings.childGroups();
+    settings.endGroup();
+
+    qDebug() << "Locations indexes before restoring positions";
+    qDebug() << this->m_indexStorage;
+    qDebug() << "Restoring these locations positions.";
+    qDebug() << tempIndex;
+
+    // Swap locations to correct indexes.
+    QMap<QString, int>::iterator it, ite;
+    for (it = tempIndex.begin(), ite = tempIndex.end(); it != ite; ++it)
+    {
+        int oldIndex = this->m_indexStorage.indexOf(it.key());
+        // Only operate on this item if current index is not the same as specified
+        if (it.value() != oldIndex + 1)
+        {
+            // Move to last if requested index is greater than the number of items.
+            if (it.value() >= this->m_indexStorage.size()) {
+                this->m_indexStorage.swap(oldIndex, this->m_indexStorage.size() - 1);
+            }
+            else {
+                this->m_indexStorage.swap(oldIndex, it.value() - 1);
+            }
+        }
+    }
+
+    qDebug() << "Locations indexes after positions are restored.";
+    qDebug() << this->m_indexStorage;
+}
+
+void Locations::saveLocation(Location *location)
+{
+    if (!location) {
+        qDebug() << "Null location given to saveLocation. Aborting";
+        return;
+    }
+    qDebug() << "Saving location " << location->label();
+    QSettings settings;
+    settings.beginGroup("Locations");
+    settings.beginGroup(location->label() );
+    if (location->isValid()) {
+        settings.setValue( "address", location->address() );
+        settings.setValue( "x", location->x() );
+        settings.setValue( "y", location->y() );
+    }
+    else {
+        if (settings.contains("address")) settings.remove("address");
+        if (settings.contains("x")) settings.remove("x");
+        if (settings.contains("y")) settings.remove("y");
+    }
+    settings.setValue("index", this->m_indexStorage.indexOf(location->label()) + 1);
+    settings.endGroup();
+    settings.endGroup();
+}
 
-  for( int i=0; i<labels.size(); ++i ) {
-    QString label = labels[i];
-    settings.beginGroup( label );
-    QString x       = settings.value( "x" ).toString();
-    QString y       = settings.value( "y" ).toString();
-    QString address = settings.value( "address" ).toString();
+bool Locations::removeLocation(Location *location)
+{
+    bool succeeded = false;
+    qDebug() << "Trying to remove location " << location->label();
+    QSettings settings;
+    settings.beginGroup("Locations");
+    if (settings.contains(location->label()))
+    {
+        qDebug() << "Given location exists in settings -> removing it";
+        settings.remove(location->label());
+        succeeded = true;
+    }
     settings.endGroup();
 
-    qDebug() << "restoring" << label;
-    Location *location = new Location( x, y, label );
-    location->setAddress( address );
+    if (this->m_locationStorage.contains(location->label()))
+    {
+        qDebug() << "Given location exists in locations list -> removing it";
+        this->m_locationStorage.remove(location->label());
+        //int remIndex = this->m_indexStorage.value(location->label());
+        this->m_indexStorage.removeOne(location->label());
+        /*for (int ind = 0; ind < this->m_indexStorage.size(); ++ind)
+        {
+            if (this->m_indexStorage.value(this->m_indexStorage > remIndex)
+            {
+                it.value() -= 1;
+                this->saveLocation(this->getLocation(it.key()), it.value());
+            }
+        }*/
+        emit(locationsChanged());
+    }
+    return succeeded;
+}
 
-    locationHash[ label ] = location;
-  }
+Location *Locations::getLocation(const QString &label) const
+{
+    qDebug() << "requesting location " << label;
+    Location *retVal = 0;
 
-  settings.endGroup();
+    if (this->m_locationStorage.contains(label)) {
+        qDebug() << "found location " << label;
+        retVal = this->m_locationStorage[label];
+    } else {
+        qDebug() << "didn't find location " << label;
+    }
+
+    return retVal;
 }
 
-void Locations::saveLocation( Location *location )
-{
-  qDebug() << "Saving location" << location->label();
-  QSettings settings;
-  settings.beginGroup( "Locations" );
-  settings.beginGroup( location->label() );
-  settings.setValue( "address", location->address() );
-  settings.setValue( "x", location->x() );
-  settings.setValue( "y", location->y() );
-  settings.endGroup();
-  settings.endGroup();
+/*void Locations::changeIndex(const QString &label, const int &index, bool signal)
+{
+    int oldIndex = this->m_indexStorage.value(label);
+    if (index == oldIndex)
+        return;
+
+    qDebug() << "Index map before moving " << label << " from index " << oldIndex << " to index " << index;
+    qDebug() << this->m_indexStorage;
+    QHash<QString, int>::iterator it, ite;
+    if (index < oldIndex)
+    {
+        for (it = this->m_indexStorage.begin(), ite = this->m_indexStorage.end(); it != ite; ++it)
+        {
+            if (it.value() >= index && it.value() < oldIndex)
+            {
+                this->saveLocation(this->getLocation(label), ++(it.value()));
+            }
+        }
+    }
+    else
+        for (it = this->m_indexStorage.begin(), ite = this->m_indexStorage.end(); it != ite; ++it)
+            if (it.value() <= index && it.value() > oldIndex)
+                this->saveLocation(this->getLocation(label), --(it.value()));
+
+    this->m_indexStorage[label] = index;
+    this->saveLocation(this->getLocation(label), index);
+
+    qDebug() << "Index map after move";
+    qDebug() << this->m_indexStorage;
+    if (signal)
+        emit(locationsChanged());
+}*/
+
+Location *Locations::getLocation(const int &index) const
+{
+    qDebug() << "Getting location for index" << index;
+    Location *loc = 0;
+    /*QString label;
+    if (this->findLabel(index, label))
+    {
+        qDebug() << "Found a label with given index " << index;
+        qDebug() << "Found label is " << label;
+        loc = this->getLocation(label);
+    }*/
+    if (index <= 0 || index > this->m_indexStorage.size())
+        return loc;
+
+    QString label = this->m_indexStorage.at(index - 1);
+    loc = this->m_locationStorage.value(label);
+    return loc;
 }
 
-void Locations::saveLocation()
+/*bool Locations::findLabel(const int &index, QString &label) const
+{
+    qDebug() << "Finding label for index" << index << ". Number of items in indexStorage:" << this->m_indexStorage.size() << ". Number of items in locationStorage:" << this->m_locationStorage.size();
+    qDebug() << "Location storage";
+    qDebug() << this->m_locationStorage;
+    qDebug() << "Index storage";
+    qDebug() << this->m_indexStorage;
+
+    if (index > this->m_indexStorage.size() || index < 1)
+        return false;
+    bool found = false;
+    QHash<QString, int>::const_iterator it, ite;
+    for (it = this->m_indexStorage.constBegin(), ite = this->m_indexStorage.constEnd(); it != ite; ++it)
+    {
+        if (it.value() == index)
+        {
+            label = it.key();
+            qDebug() << "Found label is " << label;
+            found = true;
+            break;
+        }
+    }
+    qDebug() << "Returning from label search.";
+    return found;
+}*/
+
+/*const QHash<QString, Location *>& Locations::getLocations() const
 {
-  Location *location = qobject_cast<Location*>(sender());
+    return this->m_locationStorage;
+}*/
 
-  saveLocation( location );
+Location *Locations::getGpsLocation() const
+{
+    qDebug() << "GPS location requested.";
+    return this->m_gpsLocation;
 }
 
-Location *Locations::location( const QString &label )
+bool Locations::increaseLocationIndex(const QString &label)
 {
-  qDebug() << "requesting location" << label;
-  Location *retVal = 0;
+    if (!this->m_indexStorage.contains(label))
+    {
+        qDebug() << "Given label \"" << label << "\" does not exist in indexStorage.";
+        qDebug() << "Contents of indexStorage: " << this->m_indexStorage;
+        return false;
+    }
+    qDebug() << "Increasing index by one for label" << label;
+    int oldIndex = this->m_indexStorage.indexOf(label);
+    if (oldIndex == -1)
+        return false;
+    if (oldIndex == this->m_indexStorage.size() - 1)
+        return false;
+    this->m_indexStorage.move(oldIndex, oldIndex + 1);
+    this->saveLocation(this->m_locationStorage.value(label));
+    emit(locationsChanged());
+    /*QString otherLabel;
+    if (this->findLabel(oldIndex + 1, otherLabel))
+    {
+        this->m_indexStorage[label] = oldIndex + 1;
+        this->m_indexStorage[otherLabel] = oldIndex;
+        done = true;
+        emit(locationsChanged());
+    }*/
+    return true;
+}
 
-  if ( locationHash.contains( label ) ) {
-    qDebug() << "found location" << label;
-    retVal = locationHash[ label ];
-  } else {
-    qDebug() << "didn't find location" << label;
-  }
+bool Locations::lowerLocationIndex(const QString &label)
+{
+    if (!this->m_indexStorage.contains(label))
+        return false;
+    qDebug() << "Lowering index by one for label" << label;
+    int oldIndex = this->m_indexStorage.indexOf(label);
+    if (oldIndex == -1) //Not found
+        return false;
+    if (oldIndex == 0) // Already first
+        return false;
+    this->m_indexStorage.move(oldIndex, oldIndex - 1);
+    this->saveLocation(this->m_locationStorage.value(label));
+    emit(locationsChanged());
+    /*QString otherLabel;
+    if (this->findLabel(oldIndex - 1, otherLabel))
+    {
+        this->m_indexStorage[label] = oldIndex - 1;
+        this->m_indexStorage[otherLabel] = oldIndex;
+        done = true;
+        emit(locationsChanged());
+    }*/
+    return true;
+}
 
-  return retVal;
+int Locations::size() const
+{
+    return this->m_locationStorage.size();
 }
index fa74faa..0ed119c 100644 (file)
@@ -4,30 +4,49 @@
 #include "location.h"
 
 #include <QHash>
+#include <QList>
 #include <QString>
 #include <QObject>
 
 class Locations: public QObject
 {
-  Q_OBJECT
+    Q_OBJECT
 
 public:
-  Locations();
-  ~Locations();
+    static Locations *GetInstance();
+    //static void destroyLocations();
 
-  static Locations *instance();
-  bool addLocation( Location *location );
+    bool addEditLocation(Location *location);
+    bool removeLocation(Location *location);
 
-  Location *location( const QString &label );
+    bool increaseLocationIndex(const QString &label);
+    bool lowerLocationIndex(const QString &label);
 
-public Q_SLOTS:
-  void saveLocation();
+    Location *getLocation(const QString &label) const;
+    Location *getLocation(const int&) const;
+    Location *getGpsLocation() const;
+    int size() const;
+
+    //const QHash<QString, Location *>& getLocations() const;
+
+signals:
+    void locationsChanged();
 
 private:
-  void restoreLocations();
-  static QHash<QString,Location *> locationHash;
-  static bool initialised;
+    Locations();
+    //~Locations();
+    Locations(const Locations&);
+    void operator=(const Locations&);
+
+    void restoreLocations();
+    void saveLocation(Location *location);
+    bool findLabel(const int &index, QString &label) const;
+    void changeIndex(const QString &label, const int &index, bool signal = true);
+
+    QHash<QString, Location*> m_locationStorage;
+    QList<QString> m_indexStorage;
+    Location* m_gpsLocation;
 
-  void saveLocation( Location *location );
+    static Locations *m_instance;
 };
 #endif // LOCATIONS_H
diff --git a/zouba/src/locationsdisplay.cpp b/zouba/src/locationsdisplay.cpp
new file mode 100644 (file)
index 0000000..9a4b1fd
--- /dev/null
@@ -0,0 +1,212 @@
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QListWidget>
+#include <QHash>
+#include <QDebug>
+#include <QListWidgetItem>
+#include <QPoint>
+#include <QMenu>
+#include <QMenuBar>
+#include <QAction>
+#include <QWidget>
+#ifdef Q_WS_MAEMO_5
+#include <QMaemo5EditBar>
+#endif
+
+#include "locationsdisplay.h"
+#include "locations.h"
+#include "addressdialog.h"
+
+const QString invalidPostText = " - Invalid address";
+const QString editText = "Edit list";
+const QString newLocText = "Add new location";
+const QString removeText = "Remove";
+const QString doneText = "Done";
+const QString moveUpText = "Move up";
+const QString moveDownText = "Move down";
+
+QString getLocName(const QListWidgetItem *item);
+Location* getSelectedLocation(QList<QListWidgetItem*> list);
+
+LocationsDisplay::LocationsDisplay(QWidget *parent) :
+        QMainWindow(parent)
+{
+#ifdef Q_WS_MAEMO_5
+    this->setAttribute(Qt::WA_Maemo5StackedWindow);
+    //this->setWindowFlags(this->windowFlags() | Qt::Window);
+#endif
+
+    QMenuBar *menu = this->menuBar();
+    QAction *editListAction = new QAction(editText, menu);
+    menu->addAction(editListAction);
+    connect(editListAction, SIGNAL(triggered()), this, SLOT(showEditOptions()));
+
+    this->m_centralWidget = new QWidget(this);
+    this->setCentralWidget(this->m_centralWidget);
+
+    QVBoxLayout *layout = new QVBoxLayout(this->m_centralWidget);
+    this->m_centralWidget->setLayout(layout);
+
+    this->m_topWidget = new QWidget(this->m_centralWidget);
+    layout->addWidget(this->m_topWidget);
+    QVBoxLayout *topLayout = new QVBoxLayout(this->m_topWidget);
+    this->m_topWidget->setLayout(topLayout);
+    this->m_addButton = new QPushButton(newLocText, this->m_topWidget);
+    connect(this->m_addButton, SIGNAL(clicked()), this, SLOT(addAddress()));
+    topLayout->addWidget(this->m_addButton);
+
+    this->m_list = new QListWidget(this->m_centralWidget);
+    connect(this->m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(editLocation(QListWidgetItem*)));
+    //this->m_list->setContextMenuPolicy(Qt::CustomContextMenu);
+    //connect(this->m_list, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(const QPoint&)));
+    layout->addWidget(this->m_list);
+
+    this->populateLocations();
+
+    this->m_bottomWidget = new QWidget(this->m_centralWidget);
+    layout->addWidget(this->m_bottomWidget);
+    QHBoxLayout *bottomLayout = new QHBoxLayout(this->m_bottomWidget);
+    this->m_bottomWidget->setLayout(bottomLayout);
+    QPushButton *removeButton = new QPushButton(removeText, this->m_bottomWidget);
+    connect(removeButton, SIGNAL(clicked()), this, SLOT(remove()));
+    bottomLayout->addWidget(removeButton);
+    QPushButton *moveUpButton = new QPushButton(moveUpText, this->m_bottomWidget);
+    connect(moveUpButton, SIGNAL(clicked()), this, SLOT(moveUp()));
+    bottomLayout->addWidget(moveUpButton);
+    QPushButton *moveDownButton = new QPushButton(moveDownText, this->m_bottomWidget);
+    connect(moveDownButton, SIGNAL(clicked()), this, SLOT(moveDown()));
+    bottomLayout->addWidget(moveDownButton);
+
+    QPushButton *doneButton = new QPushButton(doneText, this->m_bottomWidget);
+    connect(doneButton, SIGNAL(clicked()), this, SLOT(closeEditOptions()));
+    bottomLayout->addWidget(doneButton);
+    this->m_bottomWidget->hide();
+
+    Locations *locations = Locations::GetInstance();
+    connect(locations, SIGNAL(locationsChanged()), this, SLOT(populateLocations()));
+}
+
+void LocationsDisplay::populateLocations()
+{
+    m_list->clear();
+    qDebug() << "Populating locations";
+    Locations *locations = Locations::GetInstance();
+
+    for (int index = 1; index <= locations->size(); ++index)
+    {
+        qDebug() << "Adding location: " << locations->getLocation(index)->label();
+        Location* loc = locations->getLocation(index);
+        QString dispName = loc->label();
+        if (!loc->isValid())
+            dispName.append(invalidPostText);
+        new QListWidgetItem(dispName, m_list);
+    }
+    qDebug() << "Locations populated";
+}
+
+void LocationsDisplay::addAddress()
+{
+    AddressDialog *dialog = new AddressDialog(this);
+    dialog->show();
+}
+
+void LocationsDisplay::editLocation(QListWidgetItem *item)
+{
+    if (!item) return;
+
+    Locations *locations = Locations::GetInstance();
+    QString findText = getLocName(item);
+    Location *loc = locations->getLocation(findText);
+    if (!loc)
+        qDebug() << "No location with label " << findText << " was found from locations.";
+    else
+    {
+        AddressDialog *dialog = new AddressDialog(this, loc);
+        dialog->show();
+    }
+}
+
+QString getLocNameold(const QListWidgetItem *item)
+{
+    if (!item) return 0;
+    QString retText = item->text();
+    if (retText.contains(" - Invalid address", Qt::CaseSensitive))
+        retText.chop(18);
+    return retText;
+}
+
+/*void LocationsDisplay::contextMenu(const QPoint &point)
+{
+    qDebug() << "ContextMenu requested";
+    this->m_point = point;
+    QMenu *menu = new QMenu(this->m_list);
+    menu->addAction("Delete", this, SLOT(remove()));
+    menu->exec(this->mapToGlobal(point));
+}*/
+
+void LocationsDisplay::remove()
+{
+    qDebug() << "Remove called";
+    Location* loc = getSelectedLocation(this->m_list->selectedItems());
+    if (!loc)
+        qDebug() << "No location with selected label was found from locations.";
+    else
+    {
+        Locations *locations = Locations::GetInstance();
+        locations->removeLocation(loc);
+    }
+}
+
+Location* getSelectedLocationold(QList<QListWidgetItem*> list)
+{
+    if (list.size() == 0)
+    {
+        qDebug() << "No item is selected";
+        return 0;
+    }
+    QListWidgetItem *item = list.at(0);
+    QString name = getLocName(item);
+    qDebug() << "Selected item is" << name;
+    Locations *locations = Locations::GetInstance();
+    return locations->getLocation(name);
+}
+
+void LocationsDisplay::moveUp()
+{
+    qDebug() << "Move up called";
+    Location* loc = getSelectedLocation(this->m_list->selectedItems());
+    if (!loc)
+        qDebug() << "No location with selected label was found from locations.";
+    else
+    {
+        Locations *locations = Locations::GetInstance();
+        locations->lowerLocationIndex(loc->label());
+    }
+}
+
+void LocationsDisplay::moveDown()
+{
+    qDebug() << "Move down called";
+    Location* loc = getSelectedLocation(this->m_list->selectedItems());
+    if (!loc)
+        qDebug() << "No location with selected label was found from locations.";
+    else
+    {
+        Locations *locations = Locations::GetInstance();
+        locations->increaseLocationIndex(loc->label());
+    }
+}
+
+void LocationsDisplay::showEditOptions()
+{
+    disconnect(this->m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(editLocation(QListWidgetItem*)));
+    this->m_topWidget->hide();
+    this->m_bottomWidget->show();
+}
+
+void LocationsDisplay::closeEditOptions()
+{
+    connect(this->m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(editLocation(QListWidgetItem*)));
+    this->m_topWidget->show();
+    this->m_bottomWidget->hide();
+}
diff --git a/zouba/src/locationsdisplay.h b/zouba/src/locationsdisplay.h
new file mode 100644 (file)
index 0000000..445de8f
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef LOCATIONSDISPLAY_H
+#define LOCATIONSDISPLAY_H
+
+#include <QMainWindow>
+#ifdef Q_WS_MAEMO_5
+#include <QMaemo5EditBar>
+#endif
+
+class QVBoxLayout;
+class QWidget;
+class QListView;
+class QListWidget;
+class QPoint;
+class QListWidgetItem;
+class QPushButton;
+class LocationsEditBar;
+
+
+/* TODO: Redesign locations list:
+ * - Add button to top
+ * - List all locations below that
+ * - Short press selects to edit
+ * - Long press shows options:
+ *   - Delete
+ *   - Move up
+ *   - Move down
+ */
+class LocationsDisplay : public QMainWindow
+{
+    Q_OBJECT
+public:
+    explicit LocationsDisplay(QWidget *parent = 0);
+
+signals:
+
+public slots:
+    void populateLocations();
+
+private slots:
+    void addAddress();
+    void editLocation(QListWidgetItem*);
+    //void contextMenu(const QPoint&);
+    void remove();
+    void moveUp();
+    void moveDown();
+    void showEditOptions();
+    void closeEditOptions();
+
+private:
+    QPushButton *m_addButton;
+    QListWidget *m_list;
+    QPoint m_point;
+    QWidget *m_centralWidget;
+    QWidget *m_topWidget;
+    QWidget *m_bottomWidget;
+};
+
+#endif // LOCATIONSDISPLAY_H
diff --git a/zouba/src/locationsdisplaywindow.cpp b/zouba/src/locationsdisplaywindow.cpp
new file mode 100644 (file)
index 0000000..ddb8f9b
--- /dev/null
@@ -0,0 +1,166 @@
+#include "locationsdisplaywindow.h"
+#include "ui_locationsdisplaywindow.h"
+#include "locations.h"
+#include "addressdialog.h"
+
+#include <QDebug>
+#include <QListWidgetItem>
+#include <QListWidget>
+#include <QList>
+
+const QString invalidPostText = " - Invalid address";
+const QString editText = "Edit list";
+
+QString getLocName(const QListWidgetItem *item);
+Location* getSelectedLocation(QList<QListWidgetItem*> list);
+/*QString getLocName(const QListWidgetItem *item);
+Location* getSelectedLocation(QList<QListWidgetItem*> list);*/
+
+LocationsDisplayWindow::LocationsDisplayWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::LocationsDisplayWindow)
+{
+    ui->setupUi(this);
+#ifdef Q_WS_MAEMO_5
+    this->setAttribute(Qt::WA_Maemo5StackedWindow);
+#endif
+    QAction *editListAction = new QAction(editText, this->ui->menuBar);
+    this->ui->menuBar->addAction(editListAction);
+    connect(editListAction, SIGNAL(triggered()), this, SLOT(showEditOptions()));
+//#endif
+    this->ui->editViewWidget->hide();
+
+    connect(this->ui->newLocButton, SIGNAL(clicked()), this, SLOT(addAddress()));
+    connect(this->ui->locationsWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(editLocation(QListWidgetItem*)));
+    connect(this->ui->deleteButton, SIGNAL(clicked()), this, SLOT(remove()));
+    connect(this->ui->upButton, SIGNAL(clicked()), this, SLOT(moveUp()));
+    connect(this->ui->downButton, SIGNAL(clicked()), this, SLOT(moveDown()));
+    connect(this->ui->doneButton, SIGNAL(clicked()), this, SLOT(closeEditOptions()));
+
+    this->populateLocations();
+
+    Locations *locations = Locations::GetInstance();
+    connect(locations, SIGNAL(locationsChanged()), this, SLOT(populateLocations()));
+}
+
+LocationsDisplayWindow::~LocationsDisplayWindow()
+{
+    delete ui;
+}
+
+void LocationsDisplayWindow::showEditOptions()
+{
+    disconnect(this->ui->locationsWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(editLocation(QListWidgetItem*)));
+    this->ui->defaultViewWidget->hide();
+    this->ui->editViewWidget->show();
+}
+
+void LocationsDisplayWindow::closeEditOptions()
+{
+    connect(this->ui->locationsWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(editLocation(QListWidgetItem*)));
+    this->ui->defaultViewWidget->show();
+    this->ui->editViewWidget->hide();
+}
+
+void LocationsDisplayWindow::populateLocations()
+{
+    this->ui->locationsWidget->clear();
+    qDebug() << "Populating locations";
+    Locations *locations = Locations::GetInstance();
+
+    for (int index = 1; index <= locations->size(); ++index)
+    {
+        qDebug() << "Adding location: " << locations->getLocation(index)->label();
+        Location* loc = locations->getLocation(index);
+        QString dispName = loc->label();
+        if (!loc->isValid())
+            dispName.append(invalidPostText);
+        new QListWidgetItem(dispName, this->ui->locationsWidget);
+    }
+    qDebug() << "Locations populated";
+}
+
+void LocationsDisplayWindow::addAddress()
+{
+    AddressDialog *dialog = new AddressDialog(this);
+    dialog->show();
+}
+
+void LocationsDisplayWindow::editLocation(QListWidgetItem *item)
+{
+    if (!item) return;
+
+    Locations *locations = Locations::GetInstance();
+    QString findText = getLocName(item);
+    Location *loc = locations->getLocation(findText);
+    if (!loc)
+        qDebug() << "No location with label " << findText << " was found from locations.";
+    else
+    {
+        AddressDialog *dialog = new AddressDialog(this, loc);
+        dialog->show();
+    }
+}
+
+QString getLocName(const QListWidgetItem *item)
+{
+    if (!item) return 0;
+    QString retText = item->text();
+    if (retText.contains(" - Invalid address", Qt::CaseSensitive))
+        retText.chop(18);
+    return retText;
+}
+
+void LocationsDisplayWindow::remove()
+{
+    qDebug() << "Remove called";
+    Location* loc = getSelectedLocation(this->ui->locationsWidget->selectedItems());
+    if (!loc)
+        qDebug() << "No location with selected label was found from locations.";
+    else
+    {
+        Locations *locations = Locations::GetInstance();
+        locations->removeLocation(loc);
+    }
+}
+
+Location* getSelectedLocation(QList<QListWidgetItem*> list)
+{
+    if (list.size() == 0)
+    {
+        qDebug() << "No item is selected";
+        return 0;
+    }
+    QListWidgetItem *item = list.at(0);
+    QString name = getLocName(item);
+    qDebug() << "Selected item is" << name;
+    Locations *locations = Locations::GetInstance();
+    return locations->getLocation(name);
+}
+
+void LocationsDisplayWindow::moveUp()
+{
+    qDebug() << "Move up called";
+    Location* loc = getSelectedLocation(this->ui->locationsWidget->selectedItems());
+    if (!loc)
+        qDebug() << "No location with selected label was found from locations.";
+    else
+    {
+        Locations *locations = Locations::GetInstance();
+        locations->lowerLocationIndex(loc->label());
+    }
+}
+
+void LocationsDisplayWindow::moveDown()
+{
+    qDebug() << "Move down called";
+    Location* loc = getSelectedLocation(this->ui->locationsWidget->selectedItems());
+    if (!loc)
+        qDebug() << "No location with selected label was found from locations.";
+    else
+    {
+        Locations *locations = Locations::GetInstance();
+        locations->increaseLocationIndex(loc->label());
+    }
+}
+
diff --git a/zouba/src/locationsdisplaywindow.h b/zouba/src/locationsdisplaywindow.h
new file mode 100644 (file)
index 0000000..bae7211
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef LOCATIONSDISPLAYWINDOW_H
+#define LOCATIONSDISPLAYWINDOW_H
+
+#include <QMainWindow>
+
+class QListWidgetItem;
+
+namespace Ui {
+    class LocationsDisplayWindow;
+}
+
+class LocationsDisplayWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit LocationsDisplayWindow(QWidget *parent = 0);
+    ~LocationsDisplayWindow();
+
+public slots:
+    void populateLocations();
+
+private slots:
+    void showEditOptions();
+    void editLocation(QListWidgetItem*);
+    void closeEditOptions();
+    void remove();
+    void moveUp();
+    void moveDown();
+    void addAddress();
+
+private:
+    Ui::LocationsDisplayWindow *ui;
+};
+
+#endif // LOCATIONSDISPLAYWINDOW_H
diff --git a/zouba/src/locationsdisplaywindow.ui b/zouba/src/locationsdisplaywindow.ui
new file mode 100644 (file)
index 0000000..82f6cb2
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LocationsDisplayWindow</class>
+ <widget class="QMainWindow" name="LocationsDisplayWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>480</width>
+    <height>640</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <layout class="QVBoxLayout" name="verticalLayout">
+    <item>
+     <widget class="QWidget" name="defaultViewWidget" native="true">
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <item>
+        <widget class="QPushButton" name="newLocButton">
+         <property name="text">
+          <string>Add new location</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </item>
+    <item>
+     <widget class="QWidget" name="editViewWidget" native="true">
+      <property name="enabled">
+       <bool>true</bool>
+      </property>
+      <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <item>
+        <widget class="QPushButton" name="upButton">
+         <property name="text">
+          <string>Up</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="downButton">
+         <property name="text">
+          <string>Down</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="deleteButton">
+         <property name="text">
+          <string>Delete</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="doneButton">
+         <property name="text">
+          <string>Done</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </item>
+    <item>
+     <widget class="QListWidget" name="locationsWidget"/>
+    </item>
+   </layout>
+  </widget>
+  <widget class="QMenuBar" name="menuBar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>480</width>
+     <height>21</height>
+    </rect>
+   </property>
+  </widget>
+  <action name="actionSdfasf">
+   <property name="text">
+    <string>sdfasf</string>
+   </property>
+  </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
index bd3898b..471e8c1 100644 (file)
@@ -5,6 +5,7 @@
 #include "location.h"
 #include "gpscontroller.h"
 #include "ytv.h"
+#include "locations.h"
 
 #include <QDebug>
 #include <QObject>
 
 int main(int argc, char *argv[] )
 {
-  QApplication app(argc, argv);
-
-  QMainWindow *mainWindow = new QMainWindow;
-  Ui *ui = new Ui;;
-  ui->setupUi(mainWindow);
-
-  UiController  *uiController  = new UiController( ui );
-  Route         *route         = new Route();
-  GpsController *gpsController = new GpsController();
-
-  QObject::connect(
-      route, SIGNAL( routeReady( QList<RouteData> ) ),
-      uiController, SLOT( displayRoute( QList<RouteData> ) )
-      );
-
-  QObject::connect(
-      gpsController, SIGNAL( locationChanged( Location* ) ),
-      route, SLOT( setFromLocation( Location* ) )
-      );
-
-  QObject::connect(
-      uiController, SIGNAL( destinationChanged( Location* ) ),
-      route, SLOT( setToLocation( Location* ) )
-    );
-
-  QObject::connect(
-      uiController, SIGNAL( buttonClicked() ),
-      gpsController, SLOT( getGps() )
-    );
-
-  QObject::connect(
-      ui, SIGNAL( fakeGpsPressed( const QString & ) ),
-      gpsController, SLOT( useFakeGps( const QString & ) )
-    );
-
-  QObject::connect(
-      ui, SIGNAL( liveGpsPressed() ),
-      gpsController, SLOT( useLiveGps() )
-    );
-
-  QObject::connect(
-      route, SIGNAL( busy( bool ) ),
-      ui, SLOT( setBusy( bool ) )
-    );
-
-  mainWindow->show();
-
-  return app.exec();
+    QApplication app(argc, argv);
+
+    QCoreApplication::setOrganizationName("ZouBa");
+    QCoreApplication::setOrganizationDomain("zouba.yi.org");
+    QCoreApplication::setApplicationName("ZouBa");
+
+    Locations* locations = Locations::GetInstance();
+    Locations *other_locations = Locations::GetInstance();
+    if (locations == other_locations)
+        qDebug() << "Same instance";
+    else
+        qDebug() << "!!NOT SAME INSTANCE!!";
+
+    QMainWindow *mainWindow = new QMainWindow;
+    UiClass *ui = new UiClass;;
+    ui->setupUi(mainWindow);
+
+    UiController  *uiController  = new UiController( ui );
+    Route         *route         = new Route();
+#ifdef Q_WS_MAEMO_5
+    GpsController *gpsController = new GpsController();
+#endif
+
+    QObject::connect(
+            route, SIGNAL( routeReady( QList<RouteData> ) ),
+            uiController, SLOT( displayRoute( QList<RouteData> ) )
+            );
+
+    /*QObject::connect(
+      gpsController, SIGNAL( gpsLocationChanged( Location* ) ),
+      uiController, SLOT()
+      );*/
+
+    QObject::connect(
+            uiController, SIGNAL(fromChanged(Location*)),
+            route, SLOT(setFromLocation(Location*)));
+
+    QObject::connect(
+            uiController, SIGNAL(toChanged(Location*)),
+            route, SLOT(setToLocation(Location*)));
+
+    QObject::connect(
+            uiController, SIGNAL(routeSearchRequested()),
+            route, SLOT(searchRoute()));
+
+    QObject::connect(
+            route, SIGNAL(busy(bool)),
+            ui, SLOT(setBusy(bool)));
+
+#ifdef Q_WS_MAEMO_5
+    QObject::connect(
+            ui->m_UseGpsAction, SIGNAL(toggled(bool)), gpsController, SLOT(useGPS(bool)));
+#endif
+
+    mainWindow->show();
+
+    //Locations::destroyLocations();
+
+    return app.exec();
 }
index 5d5e794..2022850 100644 (file)
@@ -44,7 +44,7 @@ void Route::getRoute()
   fullUrl.addQueryItem( "b", b.join(",") );
   fullUrl.addQueryItem( "show", QString::number(Ytv::ShowFiveResults) );
   fullUrl.addQueryItem( "walkspeed", QString::number(Ytv::WalkSpeedFast) );
-  fullUrl.addQueryItem( "optimize", QString::number(Ytv::OptimizeLeastWalking) );
+  fullUrl.addQueryItem( "optimize", QString::number(Ytv::OptimizeDefault) );
   fullUrl.addQueryItem( "user", Ytv::Username );
   fullUrl.addQueryItem( "pass", Ytv::Password );
 
@@ -66,23 +66,16 @@ void Route::replyFinished( QNetworkReply * reply )
 void Route::setFromLocation( Location *location )
 {
   qDebug() << "setting new From location (" << location->label() << ")";
+  this->setLocation(location, true);
+}
 
-  if ( location && location->isValid() ) {
-    qDebug() << "From is valid";
-    q->setFromLocation( location );
-    if ( q->toValid() ) {
-      qDebug() << "To is also valid";
-      getRoute();
-    } else {
-      qDebug() << "To not valid - waiting";
-    }
-  } else {
-    qDebug() << "ERROR:From is not valid";
-    qDebug() << "location=" << location;
-    if ( location ) {
-      qDebug() << "location->isValid()=" << location->isValid();
+void Route::searchRoute()
+{
+    if (q->fromValid() && q->toValid())
+    {
+        qDebug() << "From and To addresses are valid.";
+        getRoute();
     }
-  }
 }
 
 Location *Route::fromLocation() const
@@ -90,28 +83,31 @@ Location *Route::fromLocation() const
   return q->fromLocation();
 }
 
-void Route::setToLocation( Location *location )
+void Route::setLocation(Location *location, bool from)
 {
-  qDebug() << "setting new To location (" << location->label() << ")";
-
-  if ( location && location->isValid() ) {
-    qDebug() << "To is valid";
-    q->setToLocation( location );
-    if ( q->fromValid() ) {
-      qDebug() << "From is also valid";
-      getRoute();
+  if (location != 0)
+  {
+    if (location->isValid())
+    {
+      qDebug() << "Location is valid";
+      if (from) q->setFromLocation( location );
+      else q->setToLocation(location);
     } else {
-      qDebug() << "From not valid - waiting";
+      qDebug() << "Location is not valid. Try again or fix address";
+      qDebug() << "Location = " << location;
+      //location->resolveAddress(location->address());
     }
   } else {
-    qDebug() << "ERROR:From is not valid";
-    qDebug() << "location=" << location;
-    if ( location ) {
-      qDebug() << "location->isValid()=" << location->isValid();
-    }
+    qDebug() << "ERROR:Null location pointer given.";
   }
 }
 
+void Route::setToLocation( Location *location )
+{
+  qDebug() << "setting new To location (" << location->label() << ")";
+  this->setLocation(location, false);
+}
+
 Location *Route::toLocation() const
 {
   return q->toLocation();
index 9a311b5..87d41bb 100644 (file)
@@ -49,6 +49,8 @@ public Q_SLOTS:
     */
   void setToLocation( Location *location=0 );
 
+  void searchRoute();
+
 Q_SIGNALS:
   void routeReady( QList<RouteData> );
   void busy( bool busy );
@@ -57,6 +59,8 @@ private Q_SLOTS:
   void replyFinished( QNetworkReply* );
 
 private:
+  void setLocation(Location*, bool from);
+private:
   RoutePrivate *q;
   QNetworkAccessManager *manager;
 };
index d2125da..7c44ec9 100644 (file)
@@ -6,7 +6,9 @@
 #include <QList>
 #include <QFile>
 #include <QStringList>
+#ifdef Q_WS_MAEMO_5
 #include <QMaemo5InformationBox>
+#endif
 
 RoutePrivate::RoutePrivate( QObject *parent ) :
     m_fromValid(false),
@@ -170,7 +172,9 @@ QList<RouteData> RoutePrivate::parseReply( const QByteArray &reply )
 
   if ( retVal.isEmpty() ) {
     qDebug() << "no routes found";
+#ifdef Q_WS_MAEMO_5
     QMaemo5InformationBox::information( 0, "no routes found" );
+#endif
   }
 
   return retVal;
index ee18f3a..e645c6a 100644 (file)
 #include <QSizePolicy>
 #include <QInputDialog>
 #include <QDebug>
-
-Ui::Ui() :
-  m_centralWidget(0),
-  m_destinationButtons(0),
-  m_routeStack(0),
-  m_usingFakeGps( false ),
-  m_fakeLocationLabel( "work" )
+#include <QMenu>
+#include <QPushButton>
+#ifdef Q_WS_MAEMO_5
+#include <QMaemo5ValueButton>
+#include <QMaemo5ListPickSelector>
+#endif
+#include <QStandardItemModel>
+
+UiClass::UiClass() :
+        m_centralWidget(NULL),
+        m_routeStack(NULL),
+        m_locDisp(NULL)
 {
 }
 
-Ui::~Ui()
+UiClass::~UiClass()
 {
+    delete m_locDisp;
 }
 
-void Ui::setupUi( QMainWindow *mainWindow )
+void UiClass::setupUi( QMainWindow *mainWindow )
 {
-  m_mainWindow = mainWindow;
-  m_mainWindow->resize(800,480);
-
-  m_menu = mainWindow->menuBar()->addMenu("Settings");
-
-  QAction *setHomeAddressAction = new QAction("Set home address", this);
-  QAction *setWorkAddressAction = new QAction("Set work address", this);
-  m_toggleFakeGpsAction  = new QAction("Use fake GPS", this);
-  m_menu->addAction(setHomeAddressAction);
-  m_menu->addAction(setWorkAddressAction);
-  m_menu->addAction(m_toggleFakeGpsAction);
-
-  connect(
-      setHomeAddressAction, SIGNAL(triggered()),
-      this, SLOT(setHomeAddress())
-      );
-  connect(
-      setWorkAddressAction, SIGNAL(triggered()),
-      this, SLOT(setWorkAddress())
-      );
-  connect(
-      m_toggleFakeGpsAction, SIGNAL(triggered()),
-      this, SLOT(toggleFakeGps())
-      );
-
-  m_centralWidget = new QWidget( m_mainWindow );
-  m_mainWindow->setCentralWidget( m_centralWidget);
-
-  QRadioButton *homeButton = new QRadioButton();
-  homeButton->setObjectName( QString::fromUtf8("homeButton") );
-  homeButton->setText( "GPS->HOME" );
-  homeButton->setEnabled(false);
-
-  QRadioButton *workButton = new QRadioButton();
-  workButton->setObjectName( QString::fromUtf8("workButton") );
-  workButton->setText( "GPS->WORK" );
-  workButton->setEnabled(false);
-
-  m_destinationButtons = new QButtonGroup();
-  m_destinationButtons->addButton( homeButton, HomeButtonId );
-  m_destinationButtons->addButton( workButton, WorkButtonId );
-  m_destinationButtons->setExclusive( true );
-
-  m_routeButtons = new QButtonGroup();
-  m_routeButtons->setExclusive( true );
-  m_routeStack = new QVBoxLayout();
-  for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
-    QRadioButton *button = new QRadioButton();
-    button->setObjectName( "routeButton"+i );
-    button->setEnabled( false );
-
-    m_routeStack->addWidget( button, i );
-    m_routeButtons->addButton( button, i );
-  }
-  m_routeStack->addStretch();
-
-  QStringList headers( QStringList() << "How" << "Time" << "Dist" << "Dep" << "Arr" );
-  m_routeDetailTable = new QTableWidget();
-  m_routeDetailTable->setColumnCount( headers.count() );
-  m_routeDetailTable->setHorizontalHeaderLabels( headers );
-  m_routeDetailTable->resizeColumnsToContents();
-  m_routeDetailTable->setSelectionMode( QAbstractItemView::NoSelection );
-
-  QHBoxLayout *topLayout = new QHBoxLayout();
-  topLayout->addLayout( m_routeStack );
-  topLayout->addWidget( m_routeDetailTable );
-
-  m_buttonLayout = new QGridLayout();
-  m_buttonLayout->addWidget( homeButton, 0, 0 );
-  m_buttonLayout->addWidget( workButton, 0, 1 );
-
-  m_mainLayout = new QVBoxLayout();
-  m_mainLayout->addLayout( topLayout );
-  m_mainLayout->addLayout( m_buttonLayout );
-
-  m_centralWidget->setLayout( m_mainLayout );
+    m_mainWindow = mainWindow;
+#ifdef Q_WS_MAEMO_5
+    m_mainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
+#endif
+    //m_mainWindow->resize(800,480);
+
+    m_locDisp = new LocationsDisplayWindow(mainWindow);
+
+    m_menu = mainWindow->menuBar();
+
+    /*QAction *setHomeAddressAction = new QAction("Set home address", this);
+    QAction *setWorkAddressAction = new QAction("Set work address", this);*/
+    QAction *modifyLocationsAction = new QAction("Modify locations", this);
+    m_UseGpsAction  = new QAction("Use GPS", this);
+    m_UseGpsAction->setCheckable(true);
+    m_UseGpsAction->setChecked(true);
+    connect(this->m_UseGpsAction, SIGNAL(toggled(bool)), this, SLOT(setLocations()));
+    /*m_menu->addAction(setHomeAddressAction);
+    m_menu->addAction(setWorkAddressAction);*/
+    m_menu->addAction(m_UseGpsAction);
+    m_menu->addAction(modifyLocationsAction);
+
+    /*connect(
+            setHomeAddressAction, SIGNAL(triggered()),
+            this, SLOT(setHomeAddress())
+            );
+    connect(
+            setWorkAddressAction, SIGNAL(triggered()),
+            this, SLOT(setWorkAddress())
+            );*/
+
+    connect(modifyLocationsAction, SIGNAL(triggered()), m_locDisp, SLOT(show()));
+
+    Locations* locations = Locations::GetInstance();
+    connect(locations, SIGNAL(locationsChanged()), this, SLOT(setLocations()));
+
+    m_centralWidget = new QWidget( m_mainWindow );
+    m_mainWindow->setCentralWidget( m_centralWidget);
+
+    m_locationsModel = new QStandardItemModel(0,1);
+    this->setLocations();
+
+#ifdef Q_WS_MAEMO_5
+    m_fromButton = new QMaemo5ValueButton(QString::fromUtf8("From"));
+    m_fromButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
+    QMaemo5ListPickSelector *fromSelector = new QMaemo5ListPickSelector();
+    fromSelector->setModel(m_locationsModel);
+    m_fromButton->setPickSelector(fromSelector);
+
+    m_toButton = new QMaemo5ValueButton(QString::fromUtf8("To"));
+    m_toButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
+    QMaemo5ListPickSelector *toSelector = new QMaemo5ListPickSelector();
+    toSelector->setModel(m_locationsModel);
+    m_toButton->setPickSelector(toSelector);
+#endif
+
+    m_routeButton = new QPushButton("Route");
+
+    m_routeButtons = new QButtonGroup();
+    m_routeButtons->setExclusive( true );
+    m_routeStack = new QVBoxLayout();
+    for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
+        QRadioButton *button = new QRadioButton();
+        button->setObjectName( "routeButton"+i );
+        button->setEnabled( false );
+
+        m_routeStack->addWidget( button, i );
+        m_routeButtons->addButton( button, i );
+    }
+    m_routeStack->addStretch();
+
+    QStringList headers( QStringList() << "How" << "Time" << "Dist" << "Dep" << "Arr" );
+    m_routeDetailTable = new QTableWidget();
+    m_routeDetailTable->setColumnCount( headers.count() );
+    m_routeDetailTable->setHorizontalHeaderLabels( headers );
+    m_routeDetailTable->resizeColumnsToContents();
+    m_routeDetailTable->setSelectionMode( QAbstractItemView::NoSelection );
+
+    QHBoxLayout *topLayout = new QHBoxLayout();
+    topLayout->addLayout( m_routeStack );
+    topLayout->addWidget( m_routeDetailTable );
+
+    m_buttonLayout = new QGridLayout();
+#ifdef Q_WS_MAEMO_5
+    m_buttonLayout->addWidget(m_fromButton, 0, 0);
+    m_buttonLayout->addWidget(m_toButton, 0, 1);
+#endif
+    m_buttonLayout->addWidget(m_routeButton, 0, 2);
+
+    m_mainLayout = new QVBoxLayout();
+    m_mainLayout->addLayout( topLayout );
+    m_mainLayout->addLayout( m_buttonLayout );
+
+    m_centralWidget->setLayout( m_mainLayout );
 }
 
-void Ui::setHomeAddress()
+void UiClass::setLocations()
 {
-  setAddress( "home" );
-}
+    qDebug() << "Setting locations for main menu selectors.";
+    Locations *locations = Locations::GetInstance();
+
+    m_locationsModel->clear();
+    QStandardItem *item;
+    if (this->m_UseGpsAction->isChecked())
+    {
+        item = new QStandardItem(QString("GPS"));
+        item->setTextAlignment(Qt::AlignCenter);
+        item->setEditable(false);
+        m_locationsModel->appendRow(item);
+    }
 
-void Ui::setWorkAddress()
-{
-  setAddress( "work" );
+    for (int index = 1; index <= locations->size(); ++index)
+    {
+        item = new QStandardItem(locations->getLocation(index)->label());
+        item->setTextAlignment(Qt::AlignCenter);
+        item->setEditable(false);
+        m_locationsModel->appendRow(item);
+    }
 }
 
-void Ui::toggleFakeGps()
+void UiClass::setHomeAddress()
 {
-  m_usingFakeGps = !m_usingFakeGps;
-
-  if ( m_usingFakeGps ) {
-    useFakeGps();
-  } else {
-    useLiveGps();
-  }
+    setAddress( "home" );
 }
 
-void Ui::useFakeGps()
+void UiClass::setWorkAddress()
 {
-  emit fakeGpsPressed( m_fakeLocationLabel );
-  m_toggleFakeGpsAction->setText( "Use Live GPS" );
+    setAddress( "work" );
 }
 
-void Ui::useLiveGps()
+void UiClass::setAddress( const QString &label )
 {
-  emit liveGpsPressed();
-  m_toggleFakeGpsAction->setText( "Use Fake GPS" );
+    /*Locations locations;
+    Location *location=locations.location( label );
+
+    bool ok;
+    QString address = QInputDialog::getText(
+            m_centralWidget,
+            tr("Enter address for \""+QString(label).toLatin1()+"\""),
+            tr("Address"),
+            QLineEdit::Normal,
+            location->address(),
+            &ok
+            );
+
+    if ( ok ) {
+        qDebug() << "new address" << address;
+        Locations locations;
+        Location  *location  = locations.location( label );
+        qDebug() << "location" << location;
+        if ( location ) {
+            //location->resolveAddress( address );
+        }
+    }*/
 }
 
-void Ui::setAddress( const QString &label )
+/*void Ui::modifyLocations()
 {
-  Locations locations;
-  Location *location=locations.location( label );
-
-  bool ok;
-  QString address = QInputDialog::getText(
-     m_centralWidget,
-     tr("Enter address for \""+QString(label).toLatin1()+"\""),
-     tr("Address"),
-     QLineEdit::Normal,
-     location->address(),
-     &ok
-     );
-
-  if ( ok ) {
-    qDebug() << "new address" << address;
-    Locations locations;
-    Location  *location  = locations.location( label );
-    qDebug() << "location" << location;
-    if ( location ) {
-      location->resolveAddress( address );
-    }
-  }
-}
+    LocationsDisplay
+}*/
 
-void Ui::setBusy( bool busy )
+void UiClass::setBusy( bool busy )
 {
-  m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
+#ifdef Q_WS_MAEMO_5
+    m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
+#endif
 }
index 94dc687..5f315bf 100644 (file)
@@ -2,8 +2,25 @@
 #define UI_H
 
 #include <QObject>
+#include <QStandardItemModel>
+#include <QPushButton>
+#include <QMenuBar>
+#include <QMainWindow>
+#include <QWidget>
+#include <QTableWidget>
+#include <QButtonGroup>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QGridLayout>
+#include <QAction>
+#ifdef Q_WS_MAEMO_5
+#include <QMaemo5ValueButton>
+#endif
 
-class QMainWindow;
+#include "location.h"
+#include "locationsdisplaywindow.h"
+
+/*class QMainWindow;
 class QWidget;
 class QTableWidget;
 class QButtonGroup;
@@ -12,20 +29,21 @@ class QVBoxLayout;
 class QGridLayout;
 class QMenu;
 class QAction;
-class Location;
+class Location;*/
 
-class Ui : public QObject
+class UiClass : public QObject
 {
   Q_OBJECT
 
 public:
-  Ui();
-  ~Ui();
+  UiClass();
+  ~UiClass();
   void setupUi( QMainWindow *mainWindow );
 
   enum {
-    HomeButtonId=0,
-    WorkButtonId=1
+    FromButtonId=0,
+    ToButtonId=1,
+    RouteButtonId=2
   };
 
   enum {
@@ -35,33 +53,36 @@ public:
 
   QMainWindow *m_mainWindow;
   QWidget *m_centralWidget;
-  QButtonGroup *m_destinationButtons;
+#ifdef Q_WS_MAEMO_5
+  QMaemo5ValueButton *m_fromButton;
+  QMaemo5ValueButton *m_toButton;
+#endif
   QButtonGroup *m_routeButtons;
   QVBoxLayout *m_routeStack;
   QTableWidget *m_routeDetailTable;
   QVBoxLayout *m_mainLayout;
   QGridLayout *m_buttonLayout;
-  QMenu       *m_menu;
-  QAction     *m_toggleFakeGpsAction;
-  QAction     *m_useLiveGpsAction;
-  bool        m_usingFakeGps;
-  QString     m_fakeLocationLabel;
+  QMenuBar       *m_menu;
+  QAction     *m_UseGpsAction;
+  QStandardItemModel *m_locationsModel;
+  QPushButton *m_routeButton;
+  LocationsDisplayWindow *m_locDisp;
+
+public slots:
+  void setLocations();
 
 Q_SIGNALS:
   void homeAddressChanged( QString address );
   void workAddressChanged( QString address );
-  void fakeGpsPressed( const QString &fakeLocationLabel );
-  void liveGpsPressed();
 
 private Q_SLOTS:
   void setHomeAddress();
   void setWorkAddress();
-  void toggleFakeGps();
   void setBusy( bool busy );
+  //void modifyLocations();
+
 
 private:
-  void useFakeGps();
-  void useLiveGps();
   void setAddress( const QString &label );
 };
 #endif //UI_H
index 8365378..ba6c122 100644 (file)
 #include <QRadioButton>
 #include <QVBoxLayout>
 #include <QTableWidgetItem>
-
-UiController::UiController( Ui *ui ) :
-  m_routeData(),
-  m_destination(),
-  m_ui(ui),
-  m_currentDestination(-1),
-  m_currentRoute(-1)
+#include <QString>
+#ifdef Q_WS_MAEMO_5
+#include <QMaemo5AbstractPickSelector>
+#include <QMaemo5InformationBox>
+#endif
+
+UiController::UiController( UiClass *ui ) :
+        m_routeData(),
+        m_ui(ui),
+        m_currentRoute(-1)
 {
-  Locations locations;
-  Location *homeLocation = locations.location( "home" );
-  Location *workLocation = locations.location( "work" );
-
-  if ( homeLocation==0 ) {
-    homeLocation = new Location( "home" );
-    locations.addLocation( homeLocation );
-  } else if ( homeLocation->isValid() ) {
-    setHomeButtonValid();
-  }
-
-  if ( workLocation==0 ) {
-    workLocation = new Location( "work" );
-    locations.addLocation( workLocation );
-  } else if ( workLocation->isValid() ) {
-    setWorkButtonValid();
-  }
-
-  connect(
-      homeLocation, SIGNAL( becomeValid() ),
-      this, SLOT( setHomeButtonValid() )
-  );
-  connect(
-      homeLocation, SIGNAL( becomeInValid() ),
-      this, SLOT( setHomeButtonInValid() )
-  );
-  connect(
-      homeLocation, SIGNAL( becomeValid() ),
-      &locations, SLOT( saveLocation() )
-      );
-  connect(
-      homeLocation, SIGNAL( busy( bool ) ),
-      ui, SLOT( setBusy( bool ) )
-      );
-
-  connect(
-      workLocation, SIGNAL( becomeValid() ),
-      this, SLOT( setWorkButtonValid() )
-  );
-  connect(
-      workLocation, SIGNAL( becomeInValid() ),
-      this, SLOT( setWorkButtonInValid() )
-  );
-  connect(
-      workLocation, SIGNAL( becomeValid() ),
-      &locations, SLOT( saveLocation() )
-      );
-  connect(
-      workLocation, SIGNAL( busy( bool ) ),
-      ui, SLOT( setBusy( bool ) )
-      );
-
-  m_destination.append( homeLocation );
-  m_destination.append( workLocation );
-
-  connect(
-      m_ui->m_destinationButtons, SIGNAL( buttonClicked( int ) ),
-      this, SLOT( changeDestination( int ) )
-  );
-
-  connect(
-      m_ui->m_routeButtons, SIGNAL( buttonClicked( int ) ),
-      this, SLOT( changeRoute( int ) )
-  );
+    Locations *locations = Locations::GetInstance();
+    if (locations->size() == 0)
+    {
+        locations->addEditLocation(new Location("Home"));
+        locations->addEditLocation(new Location("Work"));
+    }
+
+    QObject::connect(m_ui->m_routeButton, SIGNAL(clicked()), this, SLOT(findRoute()));
+#ifdef Q_WS_MAEMO_5
+    QObject::connect(this->m_ui->m_fromButton->pickSelector(), SIGNAL(selected(const QString &)), this, SLOT(changeFrom()));
+    connect(m_ui->m_toButton->pickSelector(), SIGNAL(selected(const QString &)), this, SLOT(changeTo()));
+#endif
+    connect(m_ui->m_routeButtons, SIGNAL(buttonClicked(int)), this, SLOT(displayRouteDetail(int)));
 }
 
 UiController::~UiController()
 {
 }
 
-void UiController::setHomeButtonInValid()
+void UiController::changeRoute( int id )
 {
-  qDebug() << "setting home button invalid";
-  setButtonValid( Ui::HomeButtonId, false );
+    bool routeHasChanged = ( m_currentRoute != id );
+    if ( routeHasChanged ) {
+        displayRouteDetail( id );
+    }
 }
 
-void UiController::setHomeButtonValid()
+void UiController::displayRouteDetail( int id )
 {
-  qDebug() << "setting home button valid";
-  setButtonValid( Ui::HomeButtonId, true );
-}
+    QTableWidget *table = m_ui->m_routeDetailTable;
+
+    if ( id < m_routeData.count() ) {
+        QList<LegData> &legDataList = m_routeData[ id ].m_legData;
+        table->setRowCount( legDataList.count() );
+
+        int row=0;
+        foreach( LegData thisLegData, legDataList ) {
+            QString thisHow = thisLegData.m_how;
+
+            bool thisIsLine = ( thisHow == "LINE" );
+            if ( thisIsLine ) {
+                thisHow = thisLegData.m_lineCode;
+            }
+
+            QStringList tableStrings;
+            tableStrings
+                    << thisHow
+                    << thisLegData.m_tripTime
+                    << thisLegData.m_tripDistance
+                    << thisLegData.m_departureTime
+                    << thisLegData.m_arrivalTime;
+
+            int col=0;
+            foreach( QString thisString, tableStrings ) {
+                QTableWidgetItem *newItem = new QTableWidgetItem();
+                newItem->setText( thisString );
+                table->setItem( row,col, newItem );
+                ++col;
+            }
+
+            ++row;
+        }
+    } else {
+        table->setRowCount( 0 );
+    }
 
-void UiController::setWorkButtonInValid()
-{
-  qDebug() << "setting work button invalid";
-  setButtonValid( Ui::WorkButtonId, false );
+    table->resizeColumnsToContents();
 }
 
-void UiController::setWorkButtonValid()
+void UiController::displayRoute( const QList<RouteData> &routeData )
 {
-  qDebug() << "setting work button valid";
-  setButtonValid( Ui::WorkButtonId, true );
-}
+    m_routeData = routeData;
 
-void UiController::setButtonValid( int id, bool isValid )
-{
-  m_ui->m_destinationButtons->button( id )->setEnabled( isValid );
+    qDebug() << "displaying route";
+
+    for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
+        QString label;
+
+        QWidget *widget = m_ui->m_routeStack->itemAt( i )->widget();
+        QRadioButton *button = qobject_cast<QRadioButton *>(widget);
+
+        if ( i<routeData.count() ) {
+            RouteData thisRouteData = routeData.at(i);
+            label = ( QStringList()
+                      << thisRouteData.m_departureTime
+                      << thisRouteData.m_lineCode ).join( "/" );
+            button->setEnabled( true );
+        } else {
+            button->setEnabled( false );
+        }
+
+        if ( i==0 ) {
+            button->setChecked( true );
+        } else {
+            button->setChecked( false );
+        }
+
+        button->setText( label );
+    }
+
+    displayRouteDetail( 0 );
 }
 
-void UiController::changeDestination( int id )
+void UiController::findRoute()
 {
-  bool destinationHasChanged = ( m_currentDestination != id );
-  qDebug() << "Destination has changed=" << destinationHasChanged;
-  if ( destinationHasChanged ) {
-    qDebug() << "Emitting destination changed (" << m_destination[id]->label() << ")";
-    emit destinationChanged( m_destination[id] );
-    m_currentDestination = id;
-  }
-
-  // always want to emit this so that the gps position is updated
-  // and the user gets new information
-  emit buttonClicked();
+    qDebug() << "Route search button clicked";
+    emit(routeSearchRequested());
 }
 
-void UiController::changeRoute( int id )
+/*void UiController::updateLocationSelectors()
 {
-  bool routeHasChanged = ( m_currentRoute != id );
-  if ( routeHasChanged ) {
-    displayRouteDetail( id );
-  }
-}
+    m_ui->setLocations();
+}*/
 
-void UiController::displayRouteDetail( int id )
+void UiController::changeFrom()
 {
-  QTableWidget *table = m_ui->m_routeDetailTable;
-
-  if ( id < m_routeData.count() ) {
-    QList<LegData> &legDataList = m_routeData[ id ].m_legData;
-    table->setRowCount( legDataList.count() );
-
-    int row=0;
-    foreach( LegData thisLegData, legDataList ) {
-      QString thisHow = thisLegData.m_how;
-
-      bool thisIsLine = ( thisHow == "LINE" );
-      if ( thisIsLine ) {
-        thisHow = thisLegData.m_lineCode;
-      }
-
-      QStringList tableStrings;
-      tableStrings
-        << thisHow
-        << thisLegData.m_tripTime
-        << thisLegData.m_tripDistance
-        << thisLegData.m_departureTime
-        << thisLegData.m_arrivalTime;
-
-      int col=0;
-      foreach( QString thisString, tableStrings ) {
-        QTableWidgetItem *newItem = new QTableWidgetItem();
-        newItem->setText( thisString );
-        table->setItem( row,col, newItem );
-        ++col;
-      }
-
-      ++row;
+    qDebug() << "From selection changed";
+    Locations *locations = Locations::GetInstance();
+    Location *from;
+
+#ifdef Q_WS_MAEMO_5
+    const QString newValue = m_ui->m_fromButton->valueText();
+#else
+    const QString newValue = "";
+#endif
+    if (newValue == "GPS")
+    {
+        from = locations->getGpsLocation();
+        if (!from->isValid())
+        {
+            qDebug() << "GPS location is not valid.";
+#ifdef Q_WS_MAEMO_5
+            QMaemo5InformationBox::information(this->m_ui->m_mainWindow, "GPS location has not been received yet. Wait a moment.");
+#endif
+            connect(from, SIGNAL(becomeValid()), this, SLOT(gpsBecameValid()));
+            return;
+        }
+    }
+    else
+    {
+        from = locations->getLocation(newValue);
+        if (!from)
+            qDebug() << "No location with label " << newValue << " was found.";
+    }
+    if (from)
+    {
+        qDebug() << "Emitting signal of new from selection";
+        emit(fromChanged(from));
     }
-  } else {
-    table->setRowCount( 0 );
-  }
-
-  table->resizeColumnsToContents();
 }
 
-void UiController::displayRoute( const QList<RouteData> &routeData )
+void UiController::gpsBecameValid()
 {
-  m_routeData = routeData;
-
-  qDebug() << "displaying route";
-
-  for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
-    QString label;
-
-    QWidget *widget = m_ui->m_routeStack->itemAt( i )->widget();
-    QRadioButton *button = qobject_cast<QRadioButton *>(widget);
+#ifdef Q_WS_MAEMO_5
+    QMaemo5InformationBox::information(this->m_ui->m_mainWindow, "GPS location received.");
+#endif
+    Location *gps = Locations::GetInstance()->getGpsLocation();
+    disconnect(gps, SIGNAL(becomeValid()), this, SLOT(gpsBecameValid()));
+    this->changeFrom();
+    this->changeTo();
+}
 
-    if ( i<routeData.count() ) {
-      RouteData thisRouteData = routeData.at(i);
-      label = ( QStringList()
-          << thisRouteData.m_departureTime
-          << thisRouteData.m_lineCode ).join( "/" );
-      button->setEnabled( true );
-    } else {
-      button->setEnabled( false );
+void UiController::changeTo()
+{
+    qDebug() << "To selection changed";
+    Locations *locations = Locations::GetInstance();
+    Location *to;
+
+#ifdef Q_WS_MAEMO_5
+    const QString newValue = m_ui->m_toButton->valueText();
+#else
+    const QString newValue = "";
+#endif
+    if (newValue == "GPS")
+    {
+        to = locations->getGpsLocation();
+        if (!to->isValid())
+        {
+            qDebug() << "GPS location is not valid.";
+#ifdef Q_WS_MAEMO_5
+            QMaemo5InformationBox::information(this->m_ui->m_mainWindow, "GPS location has not been received yet. Wait a moment.");
+#endif
+            connect(to, SIGNAL(becomeValid()), this, SLOT(gpsBecameValid()));
+            return;
+        }
     }
-
-    if ( i==0 ) {
-      button->setChecked( true );
-    } else {
-      button->setChecked( false );
+    else
+    {
+        to = locations->getLocation(newValue);
+        if (!to)
+            qDebug() << "No location with label " << newValue << " was found.";
+    }
+    if (to)
+    {
+        qDebug() << "Emitting signal of new to selection";
+        emit(toChanged(to));
     }
-
-    button->setText( label );
-  }
-
-  displayRouteDetail( 0 );
 }
index 7cbbbf5..51eb736 100644 (file)
@@ -6,40 +6,36 @@
 
 #include <QObject>
 
-class Ui;
+class UiClass;
 
 class UiController : public QObject
 {
   Q_OBJECT
 
 public:
-  UiController( Ui *ui );
+  UiController( UiClass *ui );
   ~UiController();
 
 public Q_SLOTS:
   void displayRoute( const QList<RouteData> &routeData );
+  //void updateLocationSelectors();
+  void changeFrom();
+  void changeTo();
+  void gpsBecameValid();
 
 Q_SIGNALS:
-  void buttonClicked();
-  void destinationChanged( Location *newDestination );
+  void routeSearchRequested();
+  void fromChanged(Location *newFromLocation);
+  void toChanged(Location *newToLocation);
 
 private Q_SLOTS:
-  void changeDestination( int id );
   void changeRoute( int id );
-  void setHomeButtonValid();
-  void setWorkButtonValid();
-  void setHomeButtonInValid();
-  void setWorkButtonInValid();
   void displayRouteDetail( int id );
-
-private:
-  void setButtonValid( int id, bool isValid );
+  void findRoute();
 
 private:
   QList<RouteData> m_routeData;
-  QList<Location*> m_destination;
-  Ui *m_ui;
-  int m_currentDestination;
+  UiClass *m_ui;
   int m_currentRoute;
 };
 #endif // UICONTROLLER_H
diff --git a/zouba/src/ytv.cpp b/zouba/src/ytv.cpp
new file mode 100644 (file)
index 0000000..a785fed
--- /dev/null
@@ -0,0 +1,23 @@
+#include "ytv.h"
+
+#include <QNetworkReply>
+#include <QNetworkAccessManager>
+#include <QDebug>
+#include <QUrl>
+#include <QString>
+#include <QNetworkRequest>
+
+QNetworkReply* Ytv::searchAddress(const QString &address)
+{
+    qDebug() << "Searching for address (" << address << ")";
+
+    QUrl fullUrl(Url);
+
+    fullUrl.addEncodedQueryItem( "key", address.toAscii().toPercentEncoding() );
+    fullUrl.addQueryItem( "user", Username );
+    fullUrl.addQueryItem( "pass", Password );
+
+    qDebug() << "The query url: " << fullUrl.toString();
+
+    return manager->get(QNetworkRequest(fullUrl));
+};
index 9e34102..f9f8035 100644 (file)
@@ -1,35 +1,45 @@
-#include <QUrl>
+#ifndef YTV_H
+#define YTV_H
+
 #include <QString>
+#include <QNetworkAccessManager>
+
+class QNetworkReply;
 
 namespace Ytv {
-  const QString Url( "http://api.reittiopas.fi/public-ytv/fi/api/" );
-  const QString Username( "zouba" );
-  const QString Password( "caf9r3ee" );
-
-  //const QString Home( QByteArray::fromPercentEncoding( "Taivaanvuohentie%207%2CHelsinki" ) );
-  //const QString Work( QByteArray::fromPercentEncoding( "It%E4merenkatu%2011%2CHelsinki" ) );
-
-  enum {
-    WalkSpeedSlow=1,
-    WalkSpeedFast=2,
-    WalkSpeedNormal=3,
-    WalkSpeedRunning=4,
-    WalkSpeedCycling=5,
-    NoWalkSpeeds=5
-  };
-
-  enum {
-    ShowOneResult=1,
-    ShowThreeResults=3,
-    ShowFiveResults=5
-  };
-
-  enum {
-    OptimizeDefault=1,
-    OptimizeFastest=2,
-    OptimizeLeastTransfers=3,
-    OptimizeLeastWalking=4
-  };
+    const QString Url("http://api.reittiopas.fi/public-ytv/fi/api/");
+    const QString Username("zouba");
+    const QString Password("caf9r3ee");
+
+    //const QString Home( QByteArray::fromPercentEncoding( "Taivaanvuohentie%207%2CHelsinki" ) );
+    //const QString Work( QByteArray::fromPercentEncoding( "It%E4merenkatu%2011%2CHelsinki" ) );
+
+    enum {
+        WalkSpeedSlow=1,
+        WalkSpeedNormal=2,
+        WalkSpeedFast=3,
+        WalkSpeedRunning=4,
+        WalkSpeedCycling=5,
+        NoWalkSpeeds=5
+                 };
+
+    enum {
+        ShowOneResult=1,
+        ShowThreeResults=3,
+        ShowFiveResults=5
+                    };
+
+    enum {
+        OptimizeDefault=1,
+        OptimizeFastest=2,
+        OptimizeLeastTransfers=3,
+        OptimizeLeastWalking=4
+                         };
+
+    static QNetworkAccessManager *manager = new QNetworkAccessManager();
+
+    QNetworkReply* searchAddress(const QString &address);
 
 };
 
+#endif // YTH_H
index d978a4c..edf7d94 100644 (file)
@@ -5,25 +5,27 @@ SOURCES += \
     route_p.cpp \
     uicontroller.cpp \
     location.cpp \
-    location_p.cpp \
     locations.cpp \
-    gpscontroller.cpp \
-    gpscontroller_p.cpp \
     ui.cpp \
+    locationbutton.cpp \
+    addressdialog.cpp \
+    ytv.cpp \
+    locationsdisplaywindow.cpp
 
 HEADERS += \
     route.h \
     route_p.h \
     uicontroller.h \
     location.h \
-    location_p.h \
     locations.h \
     ytv.h \
-    gpscontroller.h \
-    gpscontroller_p.h \
     ui.h \
+    locationbutton.h \
+    addressdialog.h \
+    locationsdisplaywindow.h
 
-FORMS       +=
+FORMS       += \
+    locationsdisplaywindow.ui
 LEXSOURCES  += #LEXS#
 YACCSOURCES += #YACCS#
 
@@ -31,8 +33,8 @@ INCLUDEPATH += include
 DEPENDSPATH += INCLUDEPATH
 #QMAKE_LIBDIR_QT = qt4-maemo5/lib
 #QMAKE_INCDIR_QT = qt4-maemo5/include
-LIBS        += -Llib -lQtBearer -lQtLocation
-DEFINES     += Q_WS_MAEMO_5
+LIBS        += -Llib
+#DEFINES     += Q_WS_MAEMO_5
 
 # All generated files goes same directory
 OBJECTS_DIR = build
@@ -44,9 +46,18 @@ TEMPLATE    = app
 DEPENDPATH  +=
 VPATH       += src uis
 CONFIG      -=
-CONFIG      += debug qt mobility
-MOBILITY    += location bearer
-QT=core gui network maemo5
+CONFIG      += debug qt
+#MOBILITY    += location bearer
+QT=core gui network
+
+linux-g++-maemo5 {
+SOURCES += gpscontroller.cpp
+HEADERS += gpscontroller.h
+QT += maemo5
+LIBS += -lQtBearer -lQtLocation
+MOBILITY += location bearer
+CONFIG += mobility
+}
 
 INSTALLS    += target
 target.path  = /usr/bin/