Works now without any existing location settings, enabling a new user to start using it.
authorMax Waterman <davidmaxwaterman+maemogit@fastmail.co.uk>
Tue, 23 Mar 2010 15:41:24 +0000 (17:41 +0200)
committerMax Waterman <davidmaxwaterman+maemogit@fastmail.co.uk>
Tue, 23 Mar 2010 15:41:24 +0000 (17:41 +0200)
zouba/location.cpp
zouba/location_p.cpp
zouba/locations.cpp
zouba/main.cpp
zouba/ui.cpp
zouba/uicontroller.cpp
zouba/ytv.h

index 3b289ca..4a4a1a7 100644 (file)
@@ -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)
 {
index fd32e12..b915be2 100644 (file)
@@ -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;
+    }
   }
 }
 
index ed818c9..04cf6ab 100644 (file)
@@ -57,16 +57,17 @@ void Locations::restoreLocations()
 
   for( int i=0; i<labels.size(); ++i ) {
     QString label = labels[i];
-    qDebug() << "restoring" << label;
     settings.beginGroup( label );
-    QString x = settings.value( "x" ).toString();
-    QString y = settings.value( "y" ).toString();
+    QString x       = settings.value( "x" ).toString();
+    QString y       = settings.value( "y" ).toString();
+    QString address = settings.value( "address" ).toString();
     settings.endGroup();
 
+    qDebug() << "restoring" << label;
     Location *location = new Location( x, y, label );
-    location->setAddress( settings.value( "address" ).toString() );
+    location->setAddress( address );
 
-    locationHash[ location->label() ] = location;
+    locationHash[ label ] = location;
   }
 
   settings.endGroup();
index 47402c8..7a0020e 100644 (file)
@@ -15,7 +15,7 @@
 
 int main(int argc, char *argv[] )
 {
-  qInstallMsgHandler( messageHandler );
+  //qInstallMsgHandler( messageHandler );
   QApplication app(argc, argv);
 
   QMainWindow *mainWindow = new QMainWindow;
index 330b71e..33319f0 100644 (file)
@@ -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 );
index f1a32cf..2f823d2 100644 (file)
@@ -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 );
 
index 430e3cb..ee867a5 100644 (file)
@@ -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,