From: Max Waterman Date: Tue, 23 Mar 2010 15:41:24 +0000 (+0200) Subject: Works now without any existing location settings, enabling a new user to start using it. X-Git-Url: http://vcs.maemo.org/git/?p=ptas;a=commitdiff_plain;h=4397917b7035735b4e9adf5df1a8e79ccf5e9ab9 Works now without any existing location settings, enabling a new user to start using it. --- diff --git a/zouba/location.cpp b/zouba/location.cpp index 3b289ca..4a4a1a7 100644 --- a/zouba/location.cpp +++ b/zouba/location.cpp @@ -33,6 +33,7 @@ Location::Location( const QString &x, const QString &y, const QString &label ) : q( new LocationPrivate( x, y, label ) ), manager( new QNetworkAccessManager(this) ) { + qDebug() << "Location::Location(" << x << "," << y << "," << label <<")"; connect( manager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( replyFinished(QNetworkReply*) ) @@ -109,6 +110,7 @@ void Location::resolveAddress( const QString &address ) qDebug() << address; q->setAddress( address ); + q->setValid( false ); QUrl fullUrl( Ytv::Url ); @@ -126,7 +128,7 @@ void Location::replyFinished( QNetworkReply * reply ) q->parseReply( reply->readAll() ); if ( isValid() ) { - qDebug() << label() << "becomeValid" << this; + qDebug() << label() << "becomeValid"; emit( becomeValid() ); } } @@ -153,6 +155,7 @@ QString Location::label() const void Location::setAddress( const QString &address ) const { + qDebug() << "setting address to" << address; q->setAddress( address ); } @@ -166,7 +169,6 @@ bool Location::isValid() const return q->isValid(); } - // Degrees to radians double Location::radians(double deg) { diff --git a/zouba/location_p.cpp b/zouba/location_p.cpp index fd32e12..b915be2 100644 --- a/zouba/location_p.cpp +++ b/zouba/location_p.cpp @@ -51,8 +51,13 @@ void LocationPrivate::parseReply( const QByteArray &reply ) m_valid = false; } else { qDebug() << "(" << m_x << "," << m_y << ")"; - qDebug() << "is now valid"; - m_valid = true; + if ( m_x.isEmpty() || m_y.isEmpty() ) { + qDebug() << "is NOT valid"; + m_valid = false; + } else { + qDebug() << "is now valid"; + m_valid = true; + } } } diff --git a/zouba/locations.cpp b/zouba/locations.cpp index ed818c9..04cf6ab 100644 --- a/zouba/locations.cpp +++ b/zouba/locations.cpp @@ -57,16 +57,17 @@ void Locations::restoreLocations() for( int i=0; isetAddress( settings.value( "address" ).toString() ); + location->setAddress( address ); - locationHash[ location->label() ] = location; + locationHash[ label ] = location; } settings.endGroup(); diff --git a/zouba/main.cpp b/zouba/main.cpp index 47402c8..7a0020e 100644 --- a/zouba/main.cpp +++ b/zouba/main.cpp @@ -15,7 +15,7 @@ int main(int argc, char *argv[] ) { - qInstallMsgHandler( messageHandler ); + //qInstallMsgHandler( messageHandler ); QApplication app(argc, argv); QMainWindow *mainWindow = new QMainWindow; diff --git a/zouba/ui.cpp b/zouba/ui.cpp index 330b71e..33319f0 100644 --- a/zouba/ui.cpp +++ b/zouba/ui.cpp @@ -123,8 +123,8 @@ void Ui::setAddress( const QString &label ) if ( ok ) { qDebug() << "new address" << address; - Locations *locations=Locations::instance(); - Location *location = locations->location( label ); + Locations *locations = Locations::instance(); + Location *location = locations->location( label ); qDebug() << "location" << location; if ( location ) { location->resolveAddress( address ); diff --git a/zouba/uicontroller.cpp b/zouba/uicontroller.cpp index f1a32cf..2f823d2 100644 --- a/zouba/uicontroller.cpp +++ b/zouba/uicontroller.cpp @@ -19,6 +19,20 @@ UiController::UiController( Ui *ui ) : Location *homeLocation = locations->location( "home" ); Location *workLocation = locations->location( "work" ); + if ( homeLocation==0 ) { + homeLocation = new Location( "home" ); + locations->addLocation( homeLocation ); + } else if ( homeLocation->isValid() ) { + setHomeButtonValid(); + } + + if ( workLocation==0 ) { + workLocation = new Location( "work" ); + locations->addLocation( workLocation ); + } else if ( workLocation->isValid() ) { + setWorkButtonValid(); + } + connect( homeLocation, SIGNAL( becomeValid() ), this, SLOT( setHomeButtonValid() ) @@ -37,9 +51,6 @@ UiController::UiController( Ui *ui ) : locations, SLOT( saveLocation() ) ); - homeLocation->resolveAddress( Ytv::Home ); - workLocation->resolveAddress( Ytv::Work ); - destination.append( homeLocation ); destination.append( workLocation ); diff --git a/zouba/ytv.h b/zouba/ytv.h index 430e3cb..ee867a5 100644 --- a/zouba/ytv.h +++ b/zouba/ytv.h @@ -6,8 +6,8 @@ namespace Ytv { const QString Username( "zouba" ); const QString Password( "caf9r3ee" ); - const QString Home( QByteArray::fromPercentEncoding( "Taivaanvuohentie%207%2CHelsinki" ) ); - const QString Work( QByteArray::fromPercentEncoding( "It%E4merenkatu%2011%2CHelsinki" ) ); + //const QString Home( QByteArray::fromPercentEncoding( "Taivaanvuohentie%207%2CHelsinki" ) ); + //const QString Work( QByteArray::fromPercentEncoding( "It%E4merenkatu%2011%2CHelsinki" ) ); enum { Slow=1,