d2c1c710e93be9ca86d3b6668b5010d06776f6b1
[ptas] / zouba / uicontroller.cpp
1 #include "uicontroller.h"
2 #include "route.h"
3 #include "ui.h"
4 #include "ytv.h"
5 #include "location.h"
6
7 #include <QObject>
8 #include <QTableWidgetItem>
9 #include <QPushButton>
10 #include <QDebug>
11 #include <QButtonGroup>
12
13 UiController::UiController( Ui *ui ) :
14   ui(ui)
15 {
16   Location *homeLocation = new Location();
17   Location *workLocation = new Location();
18
19   connect(
20       homeLocation, SIGNAL( becomeValid() ),
21       this, SLOT( setHomeButtonValid() )
22   );
23   connect(
24       workLocation, SIGNAL( becomeValid() ),
25       this, SLOT( setWorkButtonValid() )
26   );
27
28   homeLocation->resolveAddress( home );
29   workLocation->resolveAddress( work );
30
31   destination.append( homeLocation );
32   destination.append( workLocation );
33
34   connect(
35       ui->destinationButtons, SIGNAL( buttonClicked( int ) ),
36       this, SLOT( changeDestination( int ) )
37   );
38
39 }
40
41 UiController::~UiController()
42 {
43 }
44
45 void UiController::setHomeButtonValid()
46 {
47   setButtonValid( Ui::HomeButtonId );
48 }
49
50 void UiController::setWorkButtonValid()
51 {
52   setButtonValid( Ui::WorkButtonId );
53 }
54
55 void UiController::setButtonValid( int id )
56 {
57   ui->destinationButtons->button( id )->setEnabled(true);
58 }
59
60 void UiController::changeDestination( int id )
61 {
62   bool destinationHasChanged = ( currentDestination != id );
63   if ( destinationHasChanged ) {
64     emit destinationChanged( *(destination[id]) );
65   }
66
67   // always want to emit this so that the gps position is update
68   // and the user gets new information
69   emit buttonClicked();
70 }
71
72 void UiController::displayRoute( const RouteData &routeData )
73 {
74   qDebug() << __PRETTY_FUNCTION__;
75   qDebug() << "routeData.arrivalTime" << routeData.arrivalTime;
76   qDebug() << "routeData.lineCode" << routeData.lineCode;
77
78   QTableWidgetItem *timeItem = new QTableWidgetItem( routeData.arrivalTime );
79   ui->table->setItem( 0, 0, timeItem );
80
81   QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.lineCode );
82   ui->table->setItem( 0, 1, lineItem );
83 }