Added dialogs to change home and work locations.
[ptas] / zouba / uicontroller.cpp
index 9df97b2..891886a 100644 (file)
@@ -1,32 +1,92 @@
 #include "uicontroller.h"
 #include "route.h"
 #include "ui.h"
+#include "ytv.h"
+#include "location.h"
+#include "messagetable.h"
+#include "locations.h"
 
 #include <QObject>
 #include <QTableWidgetItem>
 #include <QPushButton>
 #include <QDebug>
+#include <QButtonGroup>
 
 UiController::UiController( Ui *ui ) :
   ui(ui)
 {
-  connect( ui->trigger, SIGNAL( pressed() ), this, SIGNAL( homePressed() ) );
+  Location *homeLocation = new Location( "home" );
+  Location *workLocation = new Location( "work" );
+
+  Locations locations;
+  locations.addLocation( homeLocation );
+  locations.addLocation( workLocation );
+
+  connect(
+      homeLocation, SIGNAL( becomeValid() ),
+      this, SLOT( setHomeButtonValid() )
+  );
+  connect(
+      workLocation, SIGNAL( becomeValid() ),
+      this, SLOT( setWorkButtonValid() )
+  );
+
+  homeLocation->resolveAddress( Ytv::Home );
+  workLocation->resolveAddress( Ytv::Work );
+
+  destination.append( homeLocation );
+  destination.append( workLocation );
+
+  connect(
+      ui->destinationButtons, SIGNAL( buttonClicked( int ) ),
+      this, SLOT( changeDestination( int ) )
+  );
 }
 
 UiController::~UiController()
 {
 }
 
-void UiController::displayRoute( const RouteData &routeData )
+void UiController::setHomeButtonValid()
+{
+  setButtonValid( Ui::HomeButtonId );
+}
+
+void UiController::setWorkButtonValid()
+{
+  setButtonValid( Ui::WorkButtonId );
+}
+
+void UiController::setButtonValid( int id )
+{
+  ui->destinationButtons->button( id )->setEnabled(true);
+}
+
+void UiController::changeDestination( int id )
+{
+  qDebug() << "Button "+QString::number(id)+" clicked";
+
+  bool destinationHasChanged = ( currentDestination != id );
+  if ( destinationHasChanged ) {
+    emit destinationChanged( destination[id] );
+  }
+
+  // always want to emit this so that the gps position is update
+  // and the user gets new information
+  emit buttonClicked();
+}
+
+void UiController::displayRoute( const QList<RouteData> &routeData )
 {
-  qDebug() << __PRETTY_FUNCTION__;
-  qDebug() << "routeData.arrivalTime" << routeData.arrivalTime;
-  qDebug() << "routeData.lineCode" << routeData.lineCode;
+  qDebug() << "displaying route";
 
-  QTableWidgetItem *timeItem = new QTableWidgetItem( routeData.arrivalTime );
-  ui->table->setItem( 0, 0, timeItem );
+  ui->routeTable->setRowCount( routeData.count() );
 
-  QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.lineCode );
-  ui->table->setItem( 0, 1, lineItem );
+  for ( int i=0; i<routeData.count(); i++ ) {
+    QTableWidgetItem *timeItem = new QTableWidgetItem( routeData.at(i).arrivalTime );
+    ui->routeTable->setItem( i, 0, timeItem );
 
+    QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.at(i).lineCode );
+    ui->routeTable->setItem( i, 1, lineItem );
+  }
 }