From 0595f7ed48e5601f9e98fd99dcee31ac10698a5d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niko=20B=C3=B6ckerman?= Date: Wed, 13 Oct 2010 18:42:08 +0300 Subject: [PATCH] Locations selectors and edit window implemented. --- zouba/src/addressdialog.cpp | 10 +- zouba/src/location.cpp | 13 ++- zouba/src/locations.cpp | 160 +++++++++++++++++++++++--------- zouba/src/locations.h | 5 +- zouba/src/locationsdisplay.cpp | 106 ++++++++++++++++++---- zouba/src/locationsdisplay.h | 6 +- zouba/src/locationsdisplaywindow.cpp | 166 ++++++++++++++++++++++++++++++++++ zouba/src/locationsdisplaywindow.h | 36 ++++++++ zouba/src/locationsdisplaywindow.ui | 91 +++++++++++++++++++ zouba/src/main.cpp | 6 +- zouba/src/route.cpp | 2 +- zouba/src/route_p.cpp | 4 + zouba/src/ui.cpp | 41 ++++++--- zouba/src/ui.h | 14 ++- zouba/src/uicontroller.cpp | 44 +++++++-- zouba/src/uicontroller.h | 6 +- zouba/src/ytv.h | 4 +- zouba/zouba.pro | 32 ++++--- 18 files changed, 635 insertions(+), 111 deletions(-) create mode 100644 zouba/src/locationsdisplaywindow.cpp create mode 100644 zouba/src/locationsdisplaywindow.h create mode 100644 zouba/src/locationsdisplaywindow.ui diff --git a/zouba/src/addressdialog.cpp b/zouba/src/addressdialog.cpp index a5d7bd8..eba193d 100644 --- a/zouba/src/addressdialog.cpp +++ b/zouba/src/addressdialog.cpp @@ -11,9 +11,11 @@ #include #include #include -#include #include #include +#ifdef Q_WS_MAEMO_5 +#include +#endif AddressDialog::AddressDialog(QWidget *parent, const Location *location) : QDialog(parent), m_reply(0), m_current(0) @@ -117,7 +119,9 @@ void AddressDialog::searchFinished() QString errorMessage("Unknown category: "); errorMessage.append(category); qDebug() << errorMessage; +#ifdef Q_WS_MAEMO_5 QMaemo5InformationBox::information(this, errorMessage); +#endif } } @@ -132,13 +136,17 @@ void AddressDialog::searchFinished() qDebug() << xml.errorString(); if ( xml.hasError() || responseHasError ) { +#ifdef Q_WS_MAEMO_5 QMaemo5InformationBox::information(this, "Invalid response received from Ytv."); +#endif qDebug() << "Invalid response received from Ytv"; } else { // Case where no addresses are found. if (m_places.size() + m_roadNames.size() + m_stops.size() == 0) { +#ifdef Q_WS_MAEMO_5 QMaemo5InformationBox::information(this, "No addresses were found with the given address."); +#endif } // Case where addresses are found. else { diff --git a/zouba/src/location.cpp b/zouba/src/location.cpp index 8ba54cf..d799a82 100644 --- a/zouba/src/location.cpp +++ b/zouba/src/location.cpp @@ -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) { } diff --git a/zouba/src/locations.cpp b/zouba/src/locations.cpp index 9b1f45b..c4bbddb 100644 --- a/zouba/src/locations.cpp +++ b/zouba/src/locations.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include Locations* Locations::m_instance = 0; @@ -25,7 +28,7 @@ Locations* Locations::GetInstance() Locations::Locations() : m_locationStorage(QHash()), - m_indexStorage(QHash()), + m_indexStorage(QList()), 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 tempIndex = QMap(); + for( int i=0; isetAddress(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::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::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& 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 diff --git a/zouba/src/locations.h b/zouba/src/locations.h index 9324d3d..0ed119c 100644 --- a/zouba/src/locations.h +++ b/zouba/src/locations.h @@ -4,6 +4,7 @@ #include "location.h" #include +#include #include #include @@ -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 m_locationStorage; - QHash m_indexStorage; + QList m_indexStorage; Location* m_gpsLocation; static Locations *m_instance; diff --git a/zouba/src/locationsdisplay.cpp b/zouba/src/locationsdisplay.cpp index a603f98..9a4b1fd 100644 --- a/zouba/src/locationsdisplay.cpp +++ b/zouba/src/locationsdisplay.cpp @@ -1,30 +1,43 @@ #include #include -#include #include #include #include #include #include #include -#include #include #include #include +#ifdef Q_WS_MAEMO_5 +#include +#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 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 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 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() diff --git a/zouba/src/locationsdisplay.h b/zouba/src/locationsdisplay.h index 101e5f2..445de8f 100644 --- a/zouba/src/locationsdisplay.h +++ b/zouba/src/locationsdisplay.h @@ -2,7 +2,9 @@ #define LOCATIONSDISPLAY_H #include +#ifdef Q_WS_MAEMO_5 #include +#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 index 0000000..ddb8f9b --- /dev/null +++ b/zouba/src/locationsdisplaywindow.cpp @@ -0,0 +1,166 @@ +#include "locationsdisplaywindow.h" +#include "ui_locationsdisplaywindow.h" +#include "locations.h" +#include "addressdialog.h" + +#include +#include +#include +#include + +const QString invalidPostText = " - Invalid address"; +const QString editText = "Edit list"; + +QString getLocName(const QListWidgetItem *item); +Location* getSelectedLocation(QList list); +/*QString getLocName(const QListWidgetItem *item); +Location* getSelectedLocation(QList 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 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 index 0000000..bae7211 --- /dev/null +++ b/zouba/src/locationsdisplaywindow.h @@ -0,0 +1,36 @@ +#ifndef LOCATIONSDISPLAYWINDOW_H +#define LOCATIONSDISPLAYWINDOW_H + +#include + +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 index 0000000..82f6cb2 --- /dev/null +++ b/zouba/src/locationsdisplaywindow.ui @@ -0,0 +1,91 @@ + + + LocationsDisplayWindow + + + + 0 + 0 + 480 + 640 + + + + MainWindow + + + + + + + + + + Add new location + + + + + + + + + + true + + + + + + Up + + + + + + + Down + + + + + + + Delete + + + + + + + Done + + + + + + + + + + + + + + + 0 + 0 + 480 + 21 + + + + + + sdfasf + + + + + + diff --git a/zouba/src/main.cpp b/zouba/src/main.cpp index 96c2a6b..471e8c1 100644 --- a/zouba/src/main.cpp +++ b/zouba/src/main.cpp @@ -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 ) ), @@ -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(); diff --git a/zouba/src/route.cpp b/zouba/src/route.cpp index 7fe3391..2022850 100644 --- a/zouba/src/route.cpp +++ b/zouba/src/route.cpp @@ -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 ); diff --git a/zouba/src/route_p.cpp b/zouba/src/route_p.cpp index d2125da..7c44ec9 100644 --- a/zouba/src/route_p.cpp +++ b/zouba/src/route_p.cpp @@ -6,7 +6,9 @@ #include #include #include +#ifdef Q_WS_MAEMO_5 #include +#endif RoutePrivate::RoutePrivate( QObject *parent ) : m_fromValid(false), @@ -170,7 +172,9 @@ QList 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; diff --git a/zouba/src/ui.cpp b/zouba/src/ui.cpp index 3c75406..e645c6a 100644 --- a/zouba/src/ui.cpp +++ b/zouba/src/ui.cpp @@ -20,29 +20,33 @@ #include #include #include +#ifdef Q_WS_MAEMO_5 #include #include +#endif #include -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 } diff --git a/zouba/src/ui.h b/zouba/src/ui.h index 1a48503..5f315bf 100644 --- a/zouba/src/ui.h +++ b/zouba/src/ui.h @@ -13,10 +13,12 @@ #include #include #include +#ifdef Q_WS_MAEMO_5 #include +#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(); diff --git a/zouba/src/uicontroller.cpp b/zouba/src/uicontroller.cpp index 671d68e..ba6c122 100644 --- a/zouba/src/uicontroller.cpp +++ b/zouba/src/uicontroller.cpp @@ -13,10 +13,12 @@ #include #include #include +#ifdef Q_WS_MAEMO_5 #include #include +#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)); + } } diff --git a/zouba/src/uicontroller.h b/zouba/src/uicontroller.h index 4d40e12..51eb736 100644 --- a/zouba/src/uicontroller.h +++ b/zouba/src/uicontroller.h @@ -6,14 +6,14 @@ #include -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 m_routeData; - Ui *m_ui; + UiClass *m_ui; int m_currentRoute; }; #endif // UICONTROLLER_H diff --git a/zouba/src/ytv.h b/zouba/src/ytv.h index b3c3462..f9f8035 100644 --- a/zouba/src/ytv.h +++ b/zouba/src/ytv.h @@ -16,8 +16,8 @@ namespace Ytv { enum { WalkSpeedSlow=1, - WalkSpeedFast=2, - WalkSpeedNormal=3, + WalkSpeedNormal=2, + WalkSpeedFast=3, WalkSpeedRunning=4, WalkSpeedCycling=5, NoWalkSpeeds=5 diff --git a/zouba/zouba.pro b/zouba/zouba.pro index 27defdf..edf7d94 100644 --- a/zouba/zouba.pro +++ b/zouba/zouba.pro @@ -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/ -- 1.7.9.5