#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
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
\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
{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),
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);
emit(becomeValid());
//qDebug() << "Location set";
}
+#endif
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)
{
}
#include <QString>
#include <QStringList>
#include <QCoreApplication>
+#include <QMap>
+#include <QMapIterator>
+#include <QList>
Locations* Locations::m_instance = 0;
Locations::Locations() :
m_locationStorage(QHash<QString,Location *>()),
- m_indexStorage(QHash<QString, int>()),
+ m_indexStorage(QList<QString>()),
m_gpsLocation(new Location("GPS"))
{
this->restoreLocations();
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;
}
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();
}
qDebug() << "Given location exists in settings -> removing it";
settings.remove(location->label());
succeeded = true;
- emit(locationsChanged());
}
settings.endGroup();
{
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;
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)
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";
}
qDebug() << "Returning from label search.";
return found;
-}
+}*/
/*const QHash<QString, Location *>& Locations::getLocations() 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)
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
#include "location.h"
#include <QHash>
+#include <QList>
#include <QString>
#include <QObject>
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;
#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()));
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);
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();
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";
}
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);
}
}
-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()
#define LOCATIONSDISPLAY_H
#include <QMainWindow>
+#ifdef Q_WS_MAEMO_5
#include <QMaemo5EditBar>
+#endif
class QVBoxLayout;
class QWidget;
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();
--- /dev/null
+#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());
+ }
+}
+
--- /dev/null
+#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
--- /dev/null
+<?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>
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> ) ),
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();
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 );
#include <QList>
#include <QFile>
#include <QStringList>
+#ifdef Q_WS_MAEMO_5
#include <QMaemo5InformationBox>
+#endif
RoutePrivate::RoutePrivate( QObject *parent ) :
m_fromValid(false),
if ( retVal.isEmpty() ) {
qDebug() << "no routes found";
+#ifdef Q_WS_MAEMO_5
QMaemo5InformationBox::information( 0, "no routes found" );
+#endif
}
return retVal;
#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();
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_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();
QMaemo5ListPickSelector *toSelector = new QMaemo5ListPickSelector();
toSelector->setModel(m_locationsModel);
m_toButton->setPickSelector(toSelector);
+#endif
m_routeButton = new QPushButton("Route");
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_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)
{
}
}
-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 );
LocationsDisplay
}*/
-void Ui::setBusy( bool busy )
+void UiClass::setBusy( bool busy )
{
+#ifdef Q_WS_MAEMO_5
m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
+#endif
}
#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;
class QAction;
class Location;*/
-class Ui : public QObject
+class UiClass : public QObject
{
Q_OBJECT
public:
- Ui();
- ~Ui();
+ UiClass();
+ ~UiClass();
void setupUi( QMainWindow *mainWindow );
enum {
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;
QAction *m_UseGpsAction;
QStandardItemModel *m_locationsModel;
QPushButton *m_routeButton;
- LocationsDisplay *m_locDisp;
+ LocationsDisplayWindow *m_locDisp;
public slots:
void setLocations();
#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)
}
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)));
}
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();
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));
+ }
}
#include <QObject>
-class Ui;
+class UiClass;
class UiController : public QObject
{
Q_OBJECT
public:
- UiController( Ui *ui );
+ UiController( UiClass *ui );
~UiController();
public Q_SLOTS:
private:
QList<RouteData> m_routeData;
- Ui *m_ui;
+ UiClass *m_ui;
int m_currentRoute;
};
#endif // UICONTROLLER_H
enum {
WalkSpeedSlow=1,
- WalkSpeedFast=2,
- WalkSpeedNormal=3,
+ WalkSpeedNormal=2,
+ WalkSpeedFast=3,
WalkSpeedRunning=4,
WalkSpeedCycling=5,
NoWalkSpeeds=5
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 \
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#
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
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/