X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=zouba%2Fsrc%2Fuicontroller.cpp;h=836537842e5a9afb36726d8a66cdf304030a24cb;hb=5789808b3e0c9a6a1d779270ecfbf0854f4d1b1e;hp=31d2b9f6fc38839c55cd573465c9dc8ef70087dc;hpb=7a612dc57f023d1b4ad931692efc4f52822abf4b;p=ptas diff --git a/zouba/src/uicontroller.cpp b/zouba/src/uicontroller.cpp index 31d2b9f..8365378 100644 --- a/zouba/src/uicontroller.cpp +++ b/zouba/src/uicontroller.cpp @@ -3,32 +3,37 @@ #include "ui.h" #include "ytv.h" #include "location.h" -#include "messagetable.h" #include "locations.h" #include -#include #include #include #include +#include +#include +#include UiController::UiController( Ui *ui ) : - ui(ui) + m_routeData(), + m_destination(), + m_ui(ui), + m_currentDestination(-1), + m_currentRoute(-1) { - Locations *locations = Locations::instance(); - Location *homeLocation = locations->location( "home" ); - Location *workLocation = locations->location( "work" ); + Locations locations; + Location *homeLocation = locations.location( "home" ); + Location *workLocation = locations.location( "work" ); if ( homeLocation==0 ) { homeLocation = new Location( "home" ); - locations->addLocation( homeLocation ); + locations.addLocation( homeLocation ); } else if ( homeLocation->isValid() ) { setHomeButtonValid(); } if ( workLocation==0 ) { workLocation = new Location( "work" ); - locations->addLocation( workLocation ); + locations.addLocation( workLocation ); } else if ( workLocation->isValid() ) { setWorkButtonValid(); } @@ -38,8 +43,16 @@ UiController::UiController( Ui *ui ) : this, SLOT( setHomeButtonValid() ) ); connect( + homeLocation, SIGNAL( becomeInValid() ), + this, SLOT( setHomeButtonInValid() ) + ); + connect( homeLocation, SIGNAL( becomeValid() ), - locations, SLOT( saveLocation() ) + &locations, SLOT( saveLocation() ) + ); + connect( + homeLocation, SIGNAL( busy( bool ) ), + ui, SLOT( setBusy( bool ) ) ); connect( @@ -47,65 +60,160 @@ UiController::UiController( Ui *ui ) : this, SLOT( setWorkButtonValid() ) ); connect( + workLocation, SIGNAL( becomeInValid() ), + this, SLOT( setWorkButtonInValid() ) + ); + connect( workLocation, SIGNAL( becomeValid() ), - locations, SLOT( saveLocation() ) + &locations, SLOT( saveLocation() ) + ); + connect( + workLocation, SIGNAL( busy( bool ) ), + ui, SLOT( setBusy( bool ) ) ); - destination.append( homeLocation ); - destination.append( workLocation ); + m_destination.append( homeLocation ); + m_destination.append( workLocation ); connect( - ui->destinationButtons, SIGNAL( buttonClicked( int ) ), + m_ui->m_destinationButtons, SIGNAL( buttonClicked( int ) ), this, SLOT( changeDestination( int ) ) ); + + connect( + m_ui->m_routeButtons, SIGNAL( buttonClicked( int ) ), + this, SLOT( changeRoute( int ) ) + ); } UiController::~UiController() { } +void UiController::setHomeButtonInValid() +{ + qDebug() << "setting home button invalid"; + setButtonValid( Ui::HomeButtonId, false ); +} + void UiController::setHomeButtonValid() { qDebug() << "setting home button valid"; - setButtonValid( Ui::HomeButtonId ); + setButtonValid( Ui::HomeButtonId, true ); +} + +void UiController::setWorkButtonInValid() +{ + qDebug() << "setting work button invalid"; + setButtonValid( Ui::WorkButtonId, false ); } void UiController::setWorkButtonValid() { qDebug() << "setting work button valid"; - setButtonValid( Ui::WorkButtonId ); + setButtonValid( Ui::WorkButtonId, true ); } -void UiController::setButtonValid( int id ) +void UiController::setButtonValid( int id, bool isValid ) { - ui->destinationButtons->button( id )->setEnabled(true); + m_ui->m_destinationButtons->button( id )->setEnabled( isValid ); } void UiController::changeDestination( int id ) { - qDebug() << "Button "+QString::number(id)+" clicked"; - - bool destinationHasChanged = ( currentDestination != id ); + bool destinationHasChanged = ( m_currentDestination != id ); + qDebug() << "Destination has changed=" << destinationHasChanged; if ( destinationHasChanged ) { - emit destinationChanged( destination[id] ); + qDebug() << "Emitting destination changed (" << m_destination[id]->label() << ")"; + emit destinationChanged( m_destination[id] ); + m_currentDestination = id; } - // always want to emit this so that the gps position is update + // always want to emit this so that the gps position is updated // and the user gets new information emit buttonClicked(); } -void UiController::displayRoute( const QList &routeData ) +void UiController::changeRoute( int id ) { - qDebug() << "displaying route"; + bool routeHasChanged = ( m_currentRoute != id ); + if ( routeHasChanged ) { + displayRouteDetail( id ); + } +} + +void UiController::displayRouteDetail( int id ) +{ + QTableWidget *table = m_ui->m_routeDetailTable; + + if ( id < m_routeData.count() ) { + QList &legDataList = m_routeData[ id ].m_legData; + table->setRowCount( legDataList.count() ); + + int row=0; + foreach( LegData thisLegData, legDataList ) { + QString thisHow = thisLegData.m_how; + + bool thisIsLine = ( thisHow == "LINE" ); + if ( thisIsLine ) { + thisHow = thisLegData.m_lineCode; + } + + QStringList tableStrings; + tableStrings + << thisHow + << thisLegData.m_tripTime + << thisLegData.m_tripDistance + << thisLegData.m_departureTime + << thisLegData.m_arrivalTime; + + int col=0; + foreach( QString thisString, tableStrings ) { + QTableWidgetItem *newItem = new QTableWidgetItem(); + newItem->setText( thisString ); + table->setItem( row,col, newItem ); + ++col; + } + + ++row; + } + } else { + table->setRowCount( 0 ); + } + + table->resizeColumnsToContents(); +} - ui->routeTable->setRowCount( routeData.count() ); +void UiController::displayRoute( const QList &routeData ) +{ + m_routeData = routeData; - for ( int i=0; irouteTable->setItem( i, 0, timeItem ); + qDebug() << "displaying route"; - QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.at(i).lineCode ); - ui->routeTable->setItem( i, 1, lineItem ); + for ( int i=0; im_routeStack->itemAt( i )->widget(); + QRadioButton *button = qobject_cast(widget); + + if ( isetEnabled( true ); + } else { + button->setEnabled( false ); + } + + if ( i==0 ) { + button->setChecked( true ); + } else { + button->setChecked( false ); + } + + button->setText( label ); } + + displayRouteDetail( 0 ); }