Changes: changed UI, walking speed, time format
authorMax Waterman <davidmaxwaterman+maemogit@fastmail.co.uk>
Tue, 16 Mar 2010 19:31:34 +0000 (21:31 +0200)
committerMax Waterman <davidmaxwaterman+maemogit@fastmail.co.uk>
Tue, 16 Mar 2010 19:31:34 +0000 (21:31 +0200)
zouba/gpscontroller.cpp
zouba/gpscontroller.h
zouba/main.cpp
zouba/route.cpp
zouba/route_p.cpp
zouba/ui.cpp [new file with mode: 0644]
zouba/ui.h [new file with mode: 0644]
zouba/uicontroller.cpp
zouba/uicontroller.h
zouba/zouba.pro

index 932c0cf..618746a 100644 (file)
@@ -34,6 +34,7 @@ void GpsController::updateLocation( QGeoPositionInfo positionInfo )
   Location newLocation( positionInfo );
 
   emit locationChanged( newLocation );
+  m_location->stopUpdates();
 }
 
 void GpsController::startGps()
index e68bcb6..8628828 100644 (file)
@@ -14,15 +14,15 @@ class GpsController : public QObject
   Q_OBJECT
 
 public:
-    GpsController();
+  GpsController();
 
-    ~GpsController();
+  ~GpsController();
 
-    void startGps();
-    void stopGps();
+  void stopGps();
 
 public Q_SLOTS:
   void updateLocation( QGeoPositionInfo positionInfo );
+  void startGps();
 
 Q_SIGNALS:
   void locationChanged( const Location &newLocation );
index 182e723..761cfcb 100644 (file)
@@ -1,6 +1,6 @@
 #include "routedata.h"
 #include "route.h"
-#include "ui_zouba.h"
+#include "ui.h"
 #include "uicontroller.h"
 #include "location.h"
 #include "gpscontroller.h"
@@ -9,46 +9,44 @@
 
 #include <QDebug>
 #include <QObject>
+#include <QApplication>
+#include <QMainWindow>
 
 int main(int argc, char *argv[] )
 {
   QApplication app(argc, argv);
-  QMainWindow *widget = new QMainWindow;
-  Ui::MainWindow ui;
-  ui.setupUi(widget);
+  QMainWindow *mainWindow = new QMainWindow;
+  Ui ui;
+  ui.setupUi(mainWindow);
 
-  UiController *uiController = new UiController( &ui );
-
-  Route *route = new Route();
+  UiController  *uiController  = new UiController( &ui );
+  Route         *route         = new Route();
+  GpsController *gpsController = new GpsController();
+  Location      *to            = new Location();
 
   QObject::connect(
       route, SIGNAL( routeReady( RouteData ) ),
       uiController, SLOT( displayRoute( RouteData ) )
       );
 
-  GpsController *gpsController = new GpsController();
-  Location *to   = new Location();
-
   QObject::connect(
       gpsController, SIGNAL( locationChanged( Location ) ),
       route, SLOT( setFromLocation( Location ) )
       );
+
   QObject::connect(
       to, SIGNAL( becomeValid() ),
       route, SLOT( setToLocation() )
       );
 
-  ui.homeaddress->setText( "GPS" );
-  ui.workaddress->setText( work );
-
-  gpsController->startGps();
-  to->resolveAddress( work );
-
   QObject::connect(
-      uiController, SIGNAL( workAddressChanged( QString ) ),
-      to, SLOT( resolveAddress( QString ) )
+      uiController, SIGNAL( homePressed() ),
+      gpsController, SLOT( startGps() )
     );
 
-  widget->show();
+  mainWindow->show();
+
+  to->resolveAddress( work );
+
   return app.exec();
 }
index 6206492..e8a2790 100644 (file)
@@ -30,6 +30,7 @@ Route::~Route()
 
 void Route::getRoute()
 {
+  qDebug() << __PRETTY_FUNCTION__;
   QUrl fullUrl( ytv );
 
   QStringList a;
@@ -39,6 +40,8 @@ void Route::getRoute()
 
   fullUrl.addQueryItem( "a", a.join(",") );
   fullUrl.addQueryItem( "b", b.join(",") );
+  fullUrl.addQueryItem( "show", "1" );
+  fullUrl.addQueryItem( "walkspeed", "3" );
   fullUrl.addQueryItem( "user", username );
   fullUrl.addQueryItem( "pass", password );
 
@@ -47,6 +50,7 @@ void Route::getRoute()
 
 void Route::replyFinished( QNetworkReply * reply )
 {
+  qDebug() << __PRETTY_FUNCTION__;
   RouteData routeData = q->parseReply( reply->readAll() );
 
   emit( routeReady( routeData ) );
index f2cb747..9e91620 100644 (file)
@@ -19,28 +19,36 @@ RoutePrivate::~RoutePrivate()
 
 RouteData RoutePrivate::parseReply( const QByteArray &reply )
 {
+  qDebug() << __PRETTY_FUNCTION__;
   RouteData retVal;
 
   QXmlStreamReader xml( reply );
 
+  bool haveLine = false;
+  bool haveTime = false;
+
   bool inLine = false;
   bool inStop = false;
-  while ( !xml.atEnd() ) {
+  while ( !(haveLine && haveTime) && !xml.atEnd() ) {
     xml.readNext();
-    if ( xml.isStartElement() && xml.name() == "LINE" ) {
+    if ( !haveLine && xml.isStartElement() && xml.name() == "LINE" ) {
       QString lineCode( xml.attributes().value("code").toString() );
+      qDebug() << "lineCode" << lineCode;
 
       retVal.lineCode = parseJORECode( lineCode );
+      haveLine = true;
 
       inLine = true;
     } else
     if ( inLine && xml.name() == "STOP" ) {
       inStop = true;
     } else
-    if ( inLine && inStop && xml.name() == "ARRIVAL" ) {
+    if ( !haveTime && inLine && inStop && xml.name() == "ARRIVAL" ) {
       QString arrivalTime( xml.attributes().value("time").toString() );
+      qDebug() << "arrivalTime" << arrivalTime;
 
-      retVal.arrivalTime = arrivalTime;
+      retVal.arrivalTime = arrivalTime.rightJustified(4).insert(2,":");
+      haveTime = true;
 
       inLine = false;
     } else
diff --git a/zouba/ui.cpp b/zouba/ui.cpp
new file mode 100644 (file)
index 0000000..d36baab
--- /dev/null
@@ -0,0 +1,35 @@
+#include "ui.h"
+
+#include <QMainWindow>
+#include <QPushButton>
+#include <QTableWidget>
+#include <QString>
+#include <QRect>
+
+Ui::Ui() :
+  centralWidget(0),
+  trigger(0),
+  table(0)
+{
+}
+
+Ui::~Ui()
+{
+}
+
+void Ui::setupUi( QMainWindow *mainWindow )
+{
+  mainWindow->resize(800,480);
+
+  centralWidget = new QWidget( mainWindow );
+  mainWindow->setCentralWidget(centralWidget);
+
+  trigger = new QPushButton( centralWidget );
+  trigger->setObjectName( QString::fromUtf8("trigger") );
+  trigger->setText( "HOME" );
+  trigger->setGeometry( QRect( 0, 0, 150, 40 ) );
+
+  table = new QTableWidget( 1, 2, centralWidget );
+  table->setObjectName( QString::fromUtf8("table") );
+  table->setGeometry( QRect( 151, 0, 650, 480 ) );
+}
diff --git a/zouba/ui.h b/zouba/ui.h
new file mode 100644 (file)
index 0000000..a232ad9
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef UI_H
+#define UI_H
+
+class QMainWindow;
+class QWidget;
+class QPushButton;
+class QTableWidget;
+
+class Ui
+{
+public:
+  Ui();
+  ~Ui();
+  void setupUi( QMainWindow *mainWindow );
+
+  QWidget *centralWidget;
+  QPushButton *trigger;
+  QTableWidget *table;
+};
+#endif //UI_H
index 3a0fd65..9df97b2 100644 (file)
@@ -1,48 +1,32 @@
 #include "uicontroller.h"
 #include "route.h"
-#include "ui_zouba.h"
+#include "ui.h"
 
-UiController::UiController( Ui::MainWindow *ui ) :
-  ui(ui),
-  route( HomeToWork )
-{
-  connect( ui->sethomeaddress, SIGNAL( pressed() ), this, SLOT( setHomeAddress() ) );
-  connect( ui->setworkaddress, SIGNAL( pressed() ), this, SLOT( setWorkAddress() ) );
-  connect( ui->route, SIGNAL( pressed() ), this, SLOT( toggleRoute() ) );
-}
-
-UiController::~UiController()
-{
-}
+#include <QObject>
+#include <QTableWidgetItem>
+#include <QPushButton>
+#include <QDebug>
 
-void UiController::setHomeAddress()
+UiController::UiController( Ui *ui ) :
+  ui(ui)
 {
-  emit homeAddressChanged( ui->homeaddress->text() );
+  connect( ui->trigger, SIGNAL( pressed() ), this, SIGNAL( homePressed() ) );
 }
 
-void UiController::setWorkAddress()
+UiController::~UiController()
 {
-  emit workAddressChanged( ui->workaddress->text() );
 }
 
-void UiController::toggleRoute()
+void UiController::displayRoute( const RouteData &routeData )
 {
-  if ( route == HomeToWork ) {
-    route = WorkToHome;
-    ui->route->setText( "Home<-Work" );
-  } else {
-    route = HomeToWork;
-    ui->route->setText( "Home->Work" );
-  }
+  qDebug() << __PRETTY_FUNCTION__;
+  qDebug() << "routeData.arrivalTime" << routeData.arrivalTime;
+  qDebug() << "routeData.lineCode" << routeData.lineCode;
 
-  ui->busnodisplay->setText( "working" );
-  ui->timedisplay->setText( "working" );
+  QTableWidgetItem *timeItem = new QTableWidgetItem( routeData.arrivalTime );
+  ui->table->setItem( 0, 0, timeItem );
 
-  emit directionChanged();
-}
+  QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.lineCode );
+  ui->table->setItem( 0, 1, lineItem );
 
-void UiController::displayRoute( const RouteData &routeData )
-{
-  ui->busnodisplay->setText( routeData.lineCode );
-  ui->timedisplay->setText( routeData.arrivalTime );
 }
index 392962d..f524a42 100644 (file)
@@ -1,40 +1,28 @@
 #ifndef UICONTROLLER_H
 #define UICONTROLLER_H
 
-#include "ui_zouba.h"
 #include "routedata.h"
 
 #include <QObject>
 
+class Ui;
+
 class UiController : public QObject
 {
   Q_OBJECT
 
 public:
-  UiController( Ui::MainWindow *ui );
+  UiController( Ui *ui );
   ~UiController();
 
 public Q_SLOTS:
   void displayRoute( const RouteData &routeData );
 
 Q_SIGNALS:
-  void homeAddressChanged( QString );
-  void workAddressChanged( QString );
-  void directionChanged();
-
-private Q_SLOTS:
-  void setHomeAddress();
-  void setWorkAddress();
-  void toggleRoute();
+  void homePressed();
 
 private:
-  Ui::MainWindow *ui;
-  enum Direction {
-    WorkToHome,
-    HomeToWork
-  };
-
-  Direction route;
+  Ui *ui;
 };
 #endif // UICONTROLLER_H
 
index 68580cf..571eca3 100644 (file)
@@ -17,7 +17,7 @@ QT += \
 
 TEMPLATE = app
 
-FORMS = zouba.ui
+#FORMS = zouba.ui
 
 SOURCES += \
     main.cpp \
@@ -27,6 +27,7 @@ SOURCES += \
     location.cpp \
     location_p.cpp \
     gpscontroller.cpp \
+    ui.cpp \
 
 HEADERS += \
     route.h \
@@ -36,4 +37,5 @@ HEADERS += \
     location_p.h \
     ytv.h \
     gpscontroller.h \
+    ui.h \