Removed the .service file, and removed the service line from the .desktop file.
[ptas] / zouba / src / uicontroller.cpp
1 #include "uicontroller.h"
2 #include "route.h"
3 #include "ui.h"
4 #include "ytv.h"
5 #include "location.h"
6 #include "messagetable.h"
7 #include "locations.h"
8
9 #include <QObject>
10 #include <QTableWidgetItem>
11 #include <QPushButton>
12 #include <QDebug>
13 #include <QButtonGroup>
14
15 UiController::UiController( Ui *ui ) :
16   ui(ui)
17 {
18   Locations *locations = Locations::instance();
19   Location *homeLocation = locations->location( "home" );
20   Location *workLocation = locations->location( "work" );
21
22   if ( homeLocation==0 ) {
23     homeLocation = new Location( "home" );
24     locations->addLocation( homeLocation );
25   } else if ( homeLocation->isValid() ) {
26     setHomeButtonValid();
27   }
28
29   if ( workLocation==0 ) {
30     workLocation = new Location( "work" );
31     locations->addLocation( workLocation );
32   } else if ( workLocation->isValid() ) {
33     setWorkButtonValid();
34   }
35
36   connect(
37       homeLocation, SIGNAL( becomeValid() ),
38       this, SLOT( setHomeButtonValid() )
39   );
40   connect(
41       homeLocation, SIGNAL( becomeValid() ),
42       locations, SLOT( saveLocation() )
43       );
44
45   connect(
46       workLocation, SIGNAL( becomeValid() ),
47       this, SLOT( setWorkButtonValid() )
48   );
49   connect(
50       workLocation, SIGNAL( becomeValid() ),
51       locations, SLOT( saveLocation() )
52       );
53
54   destination.append( homeLocation );
55   destination.append( workLocation );
56
57   connect(
58       ui->destinationButtons, SIGNAL( buttonClicked( int ) ),
59       this, SLOT( changeDestination( int ) )
60   );
61 }
62
63 UiController::~UiController()
64 {
65 }
66
67 void UiController::setHomeButtonValid()
68 {
69   qDebug() << "setting home button valid";
70   setButtonValid( Ui::HomeButtonId );
71 }
72
73 void UiController::setWorkButtonValid()
74 {
75   qDebug() << "setting work button valid";
76   setButtonValid( Ui::WorkButtonId );
77 }
78
79 void UiController::setButtonValid( int id )
80 {
81   ui->destinationButtons->button( id )->setEnabled(true);
82 }
83
84 void UiController::changeDestination( int id )
85 {
86   qDebug() << "Button "+QString::number(id)+" clicked";
87
88   bool destinationHasChanged = ( currentDestination != id );
89   if ( destinationHasChanged ) {
90     emit destinationChanged( destination[id] );
91   }
92
93   // always want to emit this so that the gps position is update
94   // and the user gets new information
95   emit buttonClicked();
96 }
97
98 void UiController::displayRoute( const QList<RouteData> &routeData )
99 {
100   qDebug() << "displaying route";
101
102   ui->routeTable->setRowCount( routeData.count() );
103
104   for ( int i=0; i<routeData.count(); i++ ) {
105     QTableWidgetItem *timeItem = new QTableWidgetItem( routeData.at(i).arrivalTime );
106     ui->routeTable->setItem( i, 0, timeItem );
107
108     QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.at(i).lineCode );
109     ui->routeTable->setItem( i, 1, lineItem );
110   }
111 }