Locations selectors and edit window implemented.
authorNiko Böckerman <niko@nikosdesktopFedora.Murmeli>
Wed, 13 Oct 2010 15:42:08 +0000 (18:42 +0300)
committerNiko Böckerman <niko@nikosdesktopFedora.Murmeli>
Wed, 13 Oct 2010 15:42:08 +0000 (18:42 +0300)
18 files changed:
zouba/src/addressdialog.cpp
zouba/src/location.cpp
zouba/src/locations.cpp
zouba/src/locations.h
zouba/src/locationsdisplay.cpp
zouba/src/locationsdisplay.h
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_p.cpp
zouba/src/ui.cpp
zouba/src/ui.h
zouba/src/uicontroller.cpp
zouba/src/uicontroller.h
zouba/src/ytv.h
zouba/zouba.pro

index a5d7bd8..eba193d 100644 (file)
 #include <QLineEdit>\r
 #include <QPushButton>\r
 #include <QXmlStreamReader>\r
-#include <QMaemo5InformationBox>\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
@@ -117,7 +119,9 @@ void AddressDialog::searchFinished()
                     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
@@ -132,13 +136,17 @@ void AddressDialog::searchFinished()
 \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
index 8ba54cf..d799a82 100644 (file)
@@ -25,7 +25,9 @@ const double KkjZoneInfo[6][2] = {
     {33.0, 5500000.0}
 };
 
+#ifdef Q_WS_MAEMO_5
 QTM_USE_NAMESPACE
+#endif
 
         Location::Location( const QString &x, const QString &y, const QString &label ) :
         m_label(label),
@@ -35,12 +37,12 @@ QTM_USE_NAMESPACE
         m_valid(true)
 {
 }
-
+#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_x("0"),
+        m_y("0"),
         m_valid(false)
 {
     setLocation(positionInfo);
@@ -76,6 +78,7 @@ void Location::setLocation(const QGeoPositionInfo &positionInfo)
     emit(becomeValid());
     //qDebug() << "Location set";
 }
+#endif
 
 void Location::setPosition(const QString &x, const QString &y)
 {
@@ -87,8 +90,8 @@ void Location::setPosition(const QString &x, const QString &y)
 Location::Location(const QString &label) :
         m_label(label),
         m_address(QString()),
-        m_x(0),
-        m_y(0),
+        m_x("0"),
+        m_y("0"),
         m_valid(false)
 {
 }
index 9b1f45b..c4bbddb 100644 (file)
@@ -7,6 +7,9 @@
 #include <QString>
 #include <QStringList>
 #include <QCoreApplication>
+#include <QMap>
+#include <QMapIterator>
+#include <QList>
 
 Locations* Locations::m_instance = 0;
 
@@ -25,7 +28,7 @@ Locations* Locations::GetInstance()
 
 Locations::Locations() :
         m_locationStorage(QHash<QString,Location *>()),
-        m_indexStorage(QHash<QString, int>()),
+        m_indexStorage(QList<QString>()),
         m_gpsLocation(new Location("GPS"))
 {
     this->restoreLocations();
@@ -53,21 +56,19 @@ bool Locations::addEditLocation(Location *location)
         qDebug() << "Index storage:";
         qDebug() << this->m_indexStorage;
         qDebug() << "Size of index storage:" << this->m_indexStorage.size();
-        this->m_indexStorage.insert(location->label(), this->m_indexStorage.size() + 1);
+        this->m_indexStorage.append(location->label());
         qDebug() << "Index storage after inserting location:";
         qDebug() << this->m_indexStorage;
         addedNew = true;
-        emit(locationsChanged());
     } 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 it's valid now, save the setting
-    if ( location->isValid() ) {
-        this->saveLocation(location, this->m_indexStorage.value(location->label()));
-    }
+    // save the location to settings
+    this->saveLocation(location);
 
     return addedNew;
 }
@@ -79,38 +80,91 @@ void Locations::restoreLocations()
     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 x       = settings.value( "x" ).toString();
-        QString y       = settings.value( "y" ).toString();
-        QString address = settings.value( "address" ).toString();
+        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 = new Location( x, y, label );
-        location->setAddress(address);
+        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.insert(label,this->m_indexStorage.size() + 1);
+        this->m_indexStorage.append(label);
         if (index != 0)
-            this->changeIndex(label, index, false);
+            tempIndex.insert(label, index);
     }
 
     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, int index)
+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() );
-    settings.setValue( "address", location->address() );
-    settings.setValue( "x", location->x() );
-    settings.setValue( "y", location->y() );
-    settings.setValue("index", index);
+    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();
 }
@@ -126,7 +180,6 @@ bool Locations::removeLocation(Location *location)
         qDebug() << "Given location exists in settings -> removing it";
         settings.remove(location->label());
         succeeded = true;
-        emit(locationsChanged());
     }
     settings.endGroup();
 
@@ -134,14 +187,16 @@ bool Locations::removeLocation(Location *location)
     {
         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.remove(location->label());
-        QHash<QString, int>::iterator it, ite;
-        for (it = this->m_indexStorage.begin(), ite = this->m_indexStorage.end(); it != ite; ++it)
+        //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 (it.value() > remIndex)
+            if (this->m_indexStorage.value(this->m_indexStorage > remIndex)
+            {
                 it.value() -= 1;
-        }
+                this->saveLocation(this->getLocation(it.key()), it.value());
+            }
+        }*/
         emit(locationsChanged());
     }
     return succeeded;
@@ -162,7 +217,7 @@ Location *Locations::getLocation(const QString &label) const
     return retVal;
 }
 
-void Locations::changeIndex(const QString &label, const int &index, bool signal)
+/*void Locations::changeIndex(const QString &label, const int &index, bool signal)
 {
     int oldIndex = this->m_indexStorage.value(label);
     if (index == oldIndex)
@@ -193,23 +248,28 @@ void Locations::changeIndex(const QString &label, const int &index, bool signal)
     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;
+    /*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;
 }
 
-bool Locations::findLabel(const int &index, QString &label) const
+/*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";
@@ -233,7 +293,7 @@ bool Locations::findLabel(const int &index, QString &label) const
     }
     qDebug() << "Returning from label search.";
     return found;
-}
+}*/
 
 /*const QHash<QString, Location *>& Locations::getLocations() const
 {
@@ -249,19 +309,29 @@ Location *Locations::getGpsLocation() const
 bool Locations::increaseLocationIndex(const QString &label)
 {
     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;
-    bool done = false;
-    int oldIndex = this->m_indexStorage.value(label);
-    QString otherLabel;
+    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 done;
+    }*/
+    return true;
 }
 
 bool Locations::lowerLocationIndex(const QString &label)
@@ -269,17 +339,23 @@ bool Locations::lowerLocationIndex(const QString &label)
     if (!this->m_indexStorage.contains(label))
         return false;
     qDebug() << "Lowering index by one for label" << label;
-    bool done = false;
-    int oldIndex = this->m_indexStorage[label];
-    QString otherLabel;
+    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 done;
+    }*/
+    return true;
 }
 
 int Locations::size() const
index 9324d3d..0ed119c 100644 (file)
@@ -4,6 +4,7 @@
 #include "location.h"
 
 #include <QHash>
+#include <QList>
 #include <QString>
 #include <QObject>
 
@@ -38,12 +39,12 @@ private:
     void operator=(const Locations&);
 
     void restoreLocations();
-    void saveLocation(Location *location, int index);
+    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;
-    QHash<QString, int> m_indexStorage;
+    QList<QString> m_indexStorage;
     Location* m_gpsLocation;
 
     static Locations *m_instance;
index a603f98..9a4b1fd 100644 (file)
@@ -1,30 +1,43 @@
 #include <QPushButton>
 #include <QVBoxLayout>
-#include <QMaemo5EditBar>
 #include <QListWidget>
 #include <QHash>
 #include <QDebug>
 #include <QListWidgetItem>
 #include <QPoint>
 #include <QMenu>
-#include <QMaemo5EditBar>
 #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);
+    //this->setWindowFlags(this->windowFlags() | Qt::Window);
+#endif
 
     QMenuBar *menu = this->menuBar();
-    QAction *editListAction = new QAction("Edit list", menu);
+    QAction *editListAction = new QAction(editText, menu);
     menu->addAction(editListAction);
     connect(editListAction, SIGNAL(triggered()), this, SLOT(showEditOptions()));
 
@@ -38,7 +51,7 @@ LocationsDisplay::LocationsDisplay(QWidget *parent) :
     layout->addWidget(this->m_topWidget);
     QVBoxLayout *topLayout = new QVBoxLayout(this->m_topWidget);
     this->m_topWidget->setLayout(topLayout);
-    this->m_addButton = new QPushButton("Add new location", this->m_topWidget);
+    this->m_addButton = new QPushButton(newLocText, this->m_topWidget);
     connect(this->m_addButton, SIGNAL(clicked()), this, SLOT(addAddress()));
     topLayout->addWidget(this->m_addButton);
 
@@ -54,10 +67,17 @@ LocationsDisplay::LocationsDisplay(QWidget *parent) :
     layout->addWidget(this->m_bottomWidget);
     QHBoxLayout *bottomLayout = new QHBoxLayout(this->m_bottomWidget);
     this->m_bottomWidget->setLayout(bottomLayout);
-    QPushButton *removeButton = new QPushButton("Remove", this->m_bottomWidget);
+    QPushButton *removeButton = new QPushButton(removeText, this->m_bottomWidget);
     connect(removeButton, SIGNAL(clicked()), this, SLOT(remove()));
     bottomLayout->addWidget(removeButton);
-    QPushButton *doneButton = new QPushButton("Done", this->m_bottomWidget);
+    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();
@@ -75,7 +95,11 @@ void LocationsDisplay::populateLocations()
     for (int index = 1; index <= locations->size(); ++index)
     {
         qDebug() << "Adding location: " << locations->getLocation(index)->label();
-        new QListWidgetItem(locations->getLocation(index)->label(), m_list);
+        Location* loc = locations->getLocation(index);
+        QString dispName = loc->label();
+        if (!loc->isValid())
+            dispName.append(invalidPostText);
+        new QListWidgetItem(dispName, m_list);
     }
     qDebug() << "Locations populated";
 }
@@ -88,10 +112,13 @@ void LocationsDisplay::addAddress()
 
 void LocationsDisplay::editLocation(QListWidgetItem *item)
 {
+    if (!item) return;
+
     Locations *locations = Locations::GetInstance();
-    Location *loc = locations->getLocation(item->text());
+    QString findText = getLocName(item);
+    Location *loc = locations->getLocation(findText);
     if (!loc)
-        qDebug() << "No location with label " << item->text() << " was found from locations.";
+        qDebug() << "No location with label " << findText << " was found from locations.";
     else
     {
         AddressDialog *dialog = new AddressDialog(this, loc);
@@ -99,28 +126,75 @@ void LocationsDisplay::editLocation(QListWidgetItem *item)
     }
 }
 
-void LocationsDisplay::contextMenu(const QPoint &point)
+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";
-    QList<QListWidgetItem*> list = this->m_list->selectedItems();
+    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;
+        return 0;
     }
     QListWidgetItem *item = list.at(0);
-    qDebug() << "Selected item is" << item->text();
+    QString name = getLocName(item);
+    qDebug() << "Selected item is" << name;
     Locations *locations = Locations::GetInstance();
-    locations->removeLocation(locations->getLocation(item->text()));
+    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()
index 101e5f2..445de8f 100644 (file)
@@ -2,7 +2,9 @@
 #define LOCATIONSDISPLAY_H
 
 #include <QMainWindow>
+#ifdef Q_WS_MAEMO_5
 #include <QMaemo5EditBar>
+#endif
 
 class QVBoxLayout;
 class QWidget;
@@ -37,8 +39,10 @@ public slots:
 private slots:
     void addAddress();
     void editLocation(QListWidgetItem*);
-    void contextMenu(const QPoint&);
+    //void contextMenu(const QPoint&);
     void remove();
+    void moveUp();
+    void moveDown();
     void showEditOptions();
     void closeEditOptions();
 
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 96c2a6b..471e8c1 100644 (file)
@@ -28,12 +28,14 @@ int main(int argc, char *argv[] )
         qDebug() << "!!NOT SAME INSTANCE!!";
 
     QMainWindow *mainWindow = new QMainWindow;
-    Ui *ui = new Ui;;
+    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> ) ),
@@ -61,8 +63,10 @@ int main(int argc, char *argv[] )
             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();
 
index 7fe3391..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 );
 
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 3c75406..e645c6a 100644 (file)
 #include <QDebug>
 #include <QMenu>
 #include <QPushButton>
+#ifdef Q_WS_MAEMO_5
 #include <QMaemo5ValueButton>
 #include <QMaemo5ListPickSelector>
+#endif
 #include <QStandardItemModel>
 
-Ui::Ui() :
+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;
+#ifdef Q_WS_MAEMO_5
     m_mainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
+#endif
     //m_mainWindow->resize(800,480);
 
-    m_locDisp = new LocationsDisplay(mainWindow);
+    m_locDisp = new LocationsDisplayWindow(mainWindow);
 
     m_menu = mainWindow->menuBar();
 
@@ -52,6 +56,7 @@ void Ui::setupUi( QMainWindow *mainWindow )
     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);
@@ -77,6 +82,7 @@ void Ui::setupUi( QMainWindow *mainWindow )
     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();
@@ -88,6 +94,7 @@ void Ui::setupUi( QMainWindow *mainWindow )
     QMaemo5ListPickSelector *toSelector = new QMaemo5ListPickSelector();
     toSelector->setModel(m_locationsModel);
     m_toButton->setPickSelector(toSelector);
+#endif
 
     m_routeButton = new QPushButton("Route");
 
@@ -116,8 +123,10 @@ void Ui::setupUi( QMainWindow *mainWindow )
     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();
@@ -127,16 +136,20 @@ void Ui::setupUi( QMainWindow *mainWindow )
     m_centralWidget->setLayout( m_mainLayout );
 }
 
-void Ui::setLocations()
+void UiClass::setLocations()
 {
     qDebug() << "Setting locations for main menu selectors.";
     Locations *locations = Locations::GetInstance();
 
     m_locationsModel->clear();
-    QStandardItem *item = new QStandardItem(QString("GPS"));
-    item->setTextAlignment(Qt::AlignCenter);
-    item->setEditable(false);
-    m_locationsModel->appendRow(item);
+    QStandardItem *item;
+    if (this->m_UseGpsAction->isChecked())
+    {
+        item = new QStandardItem(QString("GPS"));
+        item->setTextAlignment(Qt::AlignCenter);
+        item->setEditable(false);
+        m_locationsModel->appendRow(item);
+    }
 
     for (int index = 1; index <= locations->size(); ++index)
     {
@@ -147,17 +160,17 @@ void Ui::setLocations()
     }
 }
 
-void Ui::setHomeAddress()
+void UiClass::setHomeAddress()
 {
     setAddress( "home" );
 }
 
-void Ui::setWorkAddress()
+void UiClass::setWorkAddress()
 {
     setAddress( "work" );
 }
 
-void Ui::setAddress( const QString &label )
+void UiClass::setAddress( const QString &label )
 {
     /*Locations locations;
     Location *location=locations.location( label );
@@ -188,7 +201,9 @@ void Ui::setAddress( const QString &label )
     LocationsDisplay
 }*/
 
-void Ui::setBusy( bool busy )
+void UiClass::setBusy( bool busy )
 {
+#ifdef Q_WS_MAEMO_5
     m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
+#endif
 }
index 1a48503..5f315bf 100644 (file)
 #include <QVBoxLayout>
 #include <QGridLayout>
 #include <QAction>
+#ifdef Q_WS_MAEMO_5
 #include <QMaemo5ValueButton>
+#endif
 
 #include "location.h"
-#include "locationsdisplay.h"
+#include "locationsdisplaywindow.h"
 
 /*class QMainWindow;
 class QWidget;
@@ -29,13 +31,13 @@ class QMenu;
 class QAction;
 class Location;*/
 
-class Ui : public QObject
+class UiClass : public QObject
 {
   Q_OBJECT
 
 public:
-  Ui();
-  ~Ui();
+  UiClass();
+  ~UiClass();
   void setupUi( QMainWindow *mainWindow );
 
   enum {
@@ -51,8 +53,10 @@ public:
 
   QMainWindow *m_mainWindow;
   QWidget *m_centralWidget;
+#ifdef Q_WS_MAEMO_5
   QMaemo5ValueButton *m_fromButton;
   QMaemo5ValueButton *m_toButton;
+#endif
   QButtonGroup *m_routeButtons;
   QVBoxLayout *m_routeStack;
   QTableWidget *m_routeDetailTable;
@@ -62,7 +66,7 @@ public:
   QAction     *m_UseGpsAction;
   QStandardItemModel *m_locationsModel;
   QPushButton *m_routeButton;
-  LocationsDisplay *m_locDisp;
+  LocationsDisplayWindow *m_locDisp;
 
 public slots:
   void setLocations();
index 671d68e..ba6c122 100644 (file)
 #include <QVBoxLayout>
 #include <QTableWidgetItem>
 #include <QString>
+#ifdef Q_WS_MAEMO_5
 #include <QMaemo5AbstractPickSelector>
 #include <QMaemo5InformationBox>
+#endif
 
-UiController::UiController( Ui *ui ) :
+UiController::UiController( UiClass *ui ) :
         m_routeData(),
         m_ui(ui),
         m_currentRoute(-1)
@@ -29,8 +31,10 @@ UiController::UiController( Ui *ui ) :
     }
 
     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)));
 }
 
@@ -139,28 +143,42 @@ void UiController::changeFrom()
     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);
-
-    qDebug() << "Emitting signal of new from selection";
-    emit(fromChanged(from));
+        if (!from)
+            qDebug() << "No location with label " << newValue << " was found.";
+    }
+    if (from)
+    {
+        qDebug() << "Emitting signal of new from selection";
+        emit(fromChanged(from));
+    }
 }
 
 void UiController::gpsBecameValid()
 {
+#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();
@@ -173,21 +191,33 @@ void UiController::changeTo()
     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;
         }
     }
     else
+    {
         to = locations->getLocation(newValue);
-
-    qDebug() << "Emitting signal of new to selection";
-    emit(toChanged(to));
+        if (!to)
+            qDebug() << "No location with label " << newValue << " was found.";
+    }
+    if (to)
+    {
+        qDebug() << "Emitting signal of new to selection";
+        emit(toChanged(to));
+    }
 }
index 4d40e12..51eb736 100644 (file)
@@ -6,14 +6,14 @@
 
 #include <QObject>
 
-class Ui;
+class UiClass;
 
 class UiController : public QObject
 {
   Q_OBJECT
 
 public:
-  UiController( Ui *ui );
+  UiController( UiClass *ui );
   ~UiController();
 
 public Q_SLOTS:
@@ -35,7 +35,7 @@ private Q_SLOTS:
 
 private:
   QList<RouteData> m_routeData;
-  Ui *m_ui;
+  UiClass *m_ui;
   int m_currentRoute;
 };
 #endif // UICONTROLLER_H
index b3c3462..f9f8035 100644 (file)
@@ -16,8 +16,8 @@ namespace Ytv {
 
     enum {
         WalkSpeedSlow=1,
-        WalkSpeedFast=2,
-        WalkSpeedNormal=3,
+        WalkSpeedNormal=2,
+        WalkSpeedFast=3,
         WalkSpeedRunning=4,
         WalkSpeedCycling=5,
         NoWalkSpeeds=5
index 27defdf..edf7d94 100644 (file)
@@ -6,12 +6,11 @@ SOURCES += \
     uicontroller.cpp \
     location.cpp \
     locations.cpp \
-    gpscontroller.cpp \
     ui.cpp \
     locationbutton.cpp \
-    locationsdisplay.cpp \
     addressdialog.cpp \
-    src/ytv.cpp
+    ytv.cpp \
+    locationsdisplaywindow.cpp
 
 HEADERS += \
     route.h \
@@ -20,13 +19,13 @@ HEADERS += \
     location.h \
     locations.h \
     ytv.h \
-    gpscontroller.h \
     ui.h \
     locationbutton.h \
-    locationsdisplay.h \
-    addressdialog.h
+    addressdialog.h \
+    locationsdisplaywindow.h
 
-FORMS       +=
+FORMS       += \
+    locationsdisplaywindow.ui
 LEXSOURCES  += #LEXS#
 YACCSOURCES += #YACCS#
 
@@ -34,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
@@ -47,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/