Development: route load/save.
authorToni Jussila <toni.jussila@gmail.com>
Wed, 19 May 2010 11:37:25 +0000 (14:37 +0300)
committerToni Jussila <toni.jussila@gmail.com>
Wed, 19 May 2010 11:37:25 +0000 (14:37 +0300)
Client/gpsdata.cpp
Client/httpclient.cpp
Client/httpclient.h
Client/maemo5locationprivate.h
Client/mainwindow.cpp
Client/mainwindow.h
Client/profiledialog.cpp
Client/routedialog.cpp
Client/routedialog.h
Client/routesavedialog.cpp
Client/routesavedialog.h

index 3879b54..250728a 100644 (file)
@@ -107,7 +107,7 @@ void GPSData::agnss()
         speed       = location->getSpeed();     //Returns current speed in km/h.
         track = location->getTrack(); //Returns direction of motion in degrees(0-359).
 
-        QFile routeTempFile(".//speedfreak_route/routetemp.xml");//Temp xml.
+        QFile routeTempFile("/home/user/MyDocs/speedfreak/route/routetemp.xml");//Temp xml.
 
         //If GPS find 4 or more satellite and signal stregth is 30 or more.
         if (location->getSatellitesInUse() >= 4 && location->getSignalStrength() >= 30)
@@ -232,7 +232,7 @@ void GPSData::stopRouteRecording()
         recordingStatus = false;
 
         //Write final xml.
-        QFile file(".//speedfreak_route/route.xml");
+        QFile file("/home/user/MyDocs/speedfreak/route/route.xml");
         if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
             return;
         writeRouteXml(&file, 1);
@@ -248,7 +248,7 @@ void GPSData::writeRouteXml(QIODevice *device, int round)
 {
     xmlwriter.setDevice(device);
 
-    //Write temp xml (.//speedfreak_route/routetemp.xml).
+    //Write temp xml (/home/user/MyDocs/speedfreak/route/routetemp.xml).
     if ( round == 0 )
     {
         xmlwriter.writeStartElement("Point");
@@ -259,7 +259,7 @@ void GPSData::writeRouteXml(QIODevice *device, int round)
         xmlwriter.writeEndElement();//Point
     }
 
-    //Write final xml (.//speedfreak_route/route.xml).
+    //Write final xml (/home/user/MyDocs/speedfreak/route/route.xml).
     else if ( round == 1 )
     {
         xmlwriter.writeStartDocument();
@@ -269,7 +269,7 @@ void GPSData::writeRouteXml(QIODevice *device, int round)
         xmlwriter.writeAttribute("Points", QString::number(roundCounter));
 
         //Open temp xml and read points
-        QFile tempFile(".//speedfreak_route/routetemp.xml");
+        QFile tempFile("/home/user/MyDocs/speedfreak/route/routetemp.xml");
         if (!tempFile.open(QIODevice::ReadOnly | QIODevice::Text))
             return;
         QTextStream readRoute(&tempFile);
index 933de3d..fe73799 100644 (file)
@@ -114,18 +114,20 @@ void HttpClient::sendResultXml(QString category, double result)
   * @param int 1(send to server) or 0(no send)
   * @todo Check destination URL.
   */
-void HttpClient::sendRouteXml(QString s, int i)
+void HttpClient::sendRouteXml(QString oldName, QString newName, int i)
 {
     qDebug() << "_sendRouteXml";
 
-    QString filename = ".//speedfreak_route/route.xml";
+    //QString filename = "/home/user/MyDocs/speedfreak/route/route.xml";
+    qDebug() << "__old:" + oldName;
+    QString filename = newName; //+ ".xml";
 
-    if(s != "")
+    if(newName != "")
     {
         qDebug() << "_rename xml";
-        filename = s + ".xml";
         QDir dir(filename);
-        qDebug() << dir.rename(".//speedfreak_route/route.xml", filename);
+        qDebug() << "__new:" + filename;
+        qDebug() << dir.rename(oldName, filename);
     }
 
     if(i == 1)
index f8a7b99..457f7b7 100644 (file)
@@ -39,7 +39,7 @@ public slots:
     void requestRegistration();
     void checkLogin();
     void sendResultXml(QString category, double result);
-    void sendRouteXml(QString, int);
+    void sendRouteXml(QString oldName, QString newName, int i);
     void requestTopList(QString category, QString limit);
     void requestCategories();
     void ackOfResult();
index c61d041..4817e1b 100755 (executable)
@@ -14,7 +14,7 @@ extern "C"
 {
 #include <location/location-gps-device.h>
 #include <location/location-gpsd-control.h>
-#include <location/location-distance-utils.h>
+#include <location/location-distance-utils.h>    
 }
 
 #include <QObject>
index 7c27b22..04aeb97 100644 (file)
@@ -283,11 +283,14 @@ void MainWindow::clientUserLogin()
 
 /**
   * This function send route data to server.
+  * @param QString oldName, old file name
+  * @param QString newName, new file name
+  * @param int i
   */
-void MainWindow::clientSendRoute(QString s,int i)
+void MainWindow::clientSendRoute(QString oldName, QString newName, int i)
 {
     if(httpClient)
-        httpClient->sendRouteXml(s,i);
+        httpClient->sendRouteXml(oldName, newName, i);
 }
 
 /**
@@ -374,7 +377,7 @@ void MainWindow::OpenRouteDialog()
     if(!routeSaveDialog)
         routeSaveDialog = new RouteSaveDialog;
 
-    connect(routeSaveDialog, SIGNAL(sendroute(QString,int)), this, SLOT(clientSendRoute(QString,int)));
+    connect(routeSaveDialog, SIGNAL(sendroute(QString,QString,int)), this, SLOT(clientSendRoute(QString,QString,int)));
     connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
     routeSaveDialog->show();
 }
index e0685d4..509809d 100644 (file)
@@ -66,7 +66,7 @@ private:
 private slots:
     void clientRequestCategoryList();
     void clientRequestTopList(int index);
-    void clientSendRoute(QString,int);
+    void clientSendRoute(QString,QString,int);
     void clientRegUserToServer();
     void clientUserLogin();
     void clientSendResult(QString category, double result);
index 4870b8a..82707cd 100644 (file)
@@ -51,7 +51,7 @@ ProfileDialog::ProfileDialog(SettingsDialog *parent) : QDialog(parent), ui(new U
     picture="";
 
     // Read user profile xml
-    QString filename = parent->getUserName() + "_profile.xml";
+    QString filename = "/home/user/MyDocs/speedfreak/profile/" + parent->getUserName() + "_profile.xml";
     QFile file(filename);
 
     if (!file.open(QFile::ReadOnly))
index e73e872..12064bc 100644 (file)
@@ -93,7 +93,8 @@ public:
     void setEye()
     {
         double amarkmag, tempmag;
-        Vector temp, dist;
+        Vector temp;
+        Vector dist;
 
         dval = cos(angle/2.0)/sin(angle/2.0);
         dist = atPoint-fromPoint;
@@ -335,13 +336,17 @@ void RouteDialog::paintEvent(QPaintEvent *)
     checkLogin();
 
     int type = 0; //  0 for 2d, 1 for 3d
-    int startx, starty; // Starting point of the route
-    int i, maxi;
+    int startx = 0; // Starting x point of the route
+    int starty = 0; // Starting y point of the route
+    int i = 0;
+    int maxi = 0;
     qreal x1, y1, x2, y2;
-    int x1Screen, y1Screen, x2Screen, y2Screen;
+    int x1Screen = 0;
+    int y1Screen = 0;
+    int x2Screen = 0;
+    int y2Screen = 0;
     Vector v1, v2;
     QPainter painter(this);
-    int startStop = 0;
 
     painter.setRenderHint(QPainter::Antialiasing, true);
     painter.setPen(QPen((Qt::white),2));
@@ -395,8 +400,9 @@ void RouteDialog::paintEvent(QPaintEvent *)
     }
 
     {
-        qreal maxvx, maxvy; // max speed point coordinates
-        qreal maxv;         // max speed
+        qreal maxvx = 0; // max speed x point
+        qreal maxvy = 0; // max speed y point
+        qreal maxv = 0;  // max speed
         Vector v;
 
         maxv = 0.0;
@@ -427,27 +433,29 @@ void RouteDialog::paintEvent(QPaintEvent *)
 
 /**
   *
+  * @param QString route file
   */
 bool RouteDialog::readRouteFromFile( QString &routeFile )
 {
     QString rFile = routeFile;
+    fileName = routeFile;
     Vector temp;
     QString rivi;
     QFile file;
+    int progressbarInt = 5;
+    int count;
 
-    file.setFileName( rFile);//"routetemp.xml");
-    //file.setFileName( ".//speedfreak_route/routetemp.xml");
+    file.setFileName( rFile);
     if (!file.open(QIODevice::ReadOnly))
     {
-        QMessageBox::about(0, "Error", "File not found");
+        QMessageBox::about(0, "Error", "Empty file");
         return false;
     }
-    emit progressbar(5);
+    emit progressbar(progressbarInt);
     vertexList.clear();
-    emit progressbar(50);
+
     while(!file.atEnd())
     {
-        int count;
         bool allRead;
         QString astr1, astr2, astr3, astr4;
         QString str1, str2, str3, str4;
@@ -487,40 +495,58 @@ bool RouteDialog::readRouteFromFile( QString &routeFile )
                     allRead = true;
                 }
             }
+            if(progressbarInt < 50)
+                progressbarInt++;
+            emit progressbar(progressbarInt);
         }
     }
-
     file.close();
 
-     /********  in 3d use only */
-     a = 400/2.;
-     b = 1 - a*(-1);
-     c = -300/2.;
-     d = 300 - c*(-1);
-     //angle = toradians(60);
-
-     view3d.setUp( 1.0, 0.0, 0.0);
-     view3d.setAngle(toradians(60));
-     setAtPoint( &view3d);
-     xmin = objxmin; xmax = objxmax; ymin = objymin; ymax = objymax; // 2d viewing needs this !!!!
-     setFromPoint( &view3d);
-     view3d.setEye();
-     /****** end of 3d *****/
-
-     /*
-     //Testing distance counting
-     Vector a1, a2;
-     qreal dist;
-     //a1.setX( xmin); a1.setY( ymin);
-     //a2.setX( xmax); a2.setY( ymax);
-     a1.setX( 25.483); a1.setY( 65.017); // Oulu
-     a2.setX( 27.767); a2.setY( 64.283); // Kajaani
-     dist = countDistance( &a1, &a2);
-     QString str = QString("Min & Max datan v√§limatka %1").arg(dist);
-     QMessageBox::about( 0, "Testi", str);
-     */
-    emit progressbar(100);
-    return true;
+    if(count == 1) // Check is file empty.
+    {
+        progressbarInt = 50;
+        emit progressbar(progressbarInt);
+        qDebug() << "count: " + QString::number(count);
+         /********  in 3d use only */
+         a = 400/2.;
+         b = 1 - a*(-1);
+         c = -300/2.;
+         d = 300 - c*(-1);
+         emit progressbar(60);
+         //angle = toradians(60);
+         view3d.setUp( 1.0, 0.0, 0.0);
+         emit progressbar(70);
+         view3d.setAngle(toradians(60));
+         emit progressbar(80);
+         setAtPoint( &view3d); // If file is empty software crash here.
+         emit progressbar(90);
+         xmin = objxmin; xmax = objxmax; ymin = objymin; ymax = objymax; // 2d viewing needs this !!!!
+         emit progressbar(95);
+         setFromPoint( &view3d);
+         emit progressbar(98);
+         view3d.setEye();
+         emit progressbar(99);
+         /****** end of 3d *****/
+         /*
+         //Testing distance counting
+         Vector a1, a2;
+         qreal dist;
+         //a1.setX( xmin); a1.setY( ymin);
+         //a2.setX( xmax); a2.setY( ymax);
+         a1.setX( 25.483); a1.setY( 65.017); // Oulu
+         a2.setX( 27.767); a2.setY( 64.283); // Kajaani
+         dist = countDistance( &a1, &a2);
+         QString str = QString("Min & Max datan v√§limatka %1").arg(dist);
+         QMessageBox::about( 0, "Testi", str);
+         */
+        emit progressbar(100);
+        return true;
+    }
+    else // Probably file is empty.
+    {
+        QMessageBox::about(0, "Error", "Empty file");
+        return false;
+    }
 }
 
 /**
@@ -668,8 +694,13 @@ void WORLDtoSCREEN( qreal xWorld, qreal yWorld, int *xScreen, int *yScreen)
   */
 void clip3d( qreal x1, qreal y1, qreal z1, qreal x2, qreal y2, qreal z2, int *xscreen1, int *yscreen1, int *xscreen2, int *yscreen2)
 {
-    int c,c1,c2;
-    qreal x,y,z,t;
+    int c = 0;
+    int c1 = 0;
+    int c2 = 0;
+    qreal x = 0;
+    qreal y = 0;
+    qreal z = 0;
+    qreal t = 0;
 
     c1 = code(x1,y1,z1);
     c2 = code(x2,y2,z2);
@@ -769,30 +800,34 @@ void RouteDialog::on_sendPushButton_clicked()
 {
     ui->sendPushButton->setEnabled(false);
 
-
-    QString folder = "speedfreak_route";
-
-    if(!QDir(folder).exists())
+    // Check default file dir.
+    if(!QDir("/home/user/MyDocs/speedfreak/route").exists())
     {
-        QDir().mkdir(folder);
+        QDir().mkdir("/home/user/MyDocs/speedfreak/route");
     }
 
-    QString fileName = QFileDialog::getSaveFileName(this, tr("Save Route"),
-                                ".//" + folder);//, tr("Route files  (*.xml)"));
-    qDebug() << fileName;
+    // If file name is empty set it to default.
+    if(fileName == "")
+        fileName = "/home/user/MyDocs/speedfreak/route/";
+
+    if(fileName == "/home/user/MyDocs/speedfreak/route/routetemp.xml")
+        fileName = "/home/user/MyDocs/speedfreak/route/route.xml";
 
+    qDebug() << "__FileName: " + fileName;
+    QString newFileName = QFileDialog::getSaveFileName(this, tr("Save Route"), fileName);
     int server = QMessageBox::question(this, "Save route to server?", "", 4,3);
+
     if(server == 3) // Yes button
     {
-        qDebug() << "__save to server";
-        emit sendroute(fileName,1); // Save route.
+        qDebug() << "__Save to server: yes";
+        emit sendroute(newFileName,1); // Save route to server and phone.
     }
     else if(server == 4) // No button
     {
-        qDebug() << "__no save";
+        qDebug() << "__Save to server: no";
 
         if(fileName != "")
-            emit sendroute(fileName,0); // Save route.
+            emit sendroute(newFileName,0); // Save route to phone.
     }
 }
 
index 24ff58e..a82dbd1 100644 (file)
@@ -45,6 +45,7 @@ private:
     Ui::RouteDialog *ui;
     int left, top, right, bottom;       // Limits in screen coordinates in route dialog
     void checkLogin();
+    QString fileName;
 
 private slots:
     void on_pushButtonInfo_clicked();
index 53175f4..acbe051 100644 (file)
@@ -91,11 +91,15 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) :
     connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus()));
 
     // Route folder
-    QString folder = "speedfreak_route";
+    QString folder = "/home/user/MyDocs/speedfreak";
     if(!QDir(folder).exists())
     {
         QDir().mkdir(folder);
     }
+    if(!QDir(folder + "/route").exists())
+    {
+        QDir().mkdir(folder + "/route");
+    }
 }
 
 /**
@@ -271,42 +275,6 @@ void RouteSaveDialog::on_buttonRouteStartStop_clicked()
         ui->labelRoutePicture->setVisible(0);
         timerRoutePicture->stop();
         location->stopPollingGPS();
-/*
-        // Progress bar
-        if(!calibrateDialog)
-        {
-            calibrateDialog = new CalibrateDialog();
-        }
-
-        progressbarPoints = 100;
-        progressbarIteration = 0;
-        calibrateDialog->resetProgressValue();
-        calibrateDialog->setMaxValue( progressbarPoints );
-        calibrateDialog->setTitle("Calculating route...");
-        calibrateDialog->show();
-
-
-        if(!routeDialog)
-        {
-            routeDialog = new RouteDialog(this);
-        }
-
-        connect(routeDialog, SIGNAL(sendroute(QString,int)),      this, SLOT(sendRoute(QString,int)));
-        connect(routeDialog, SIGNAL(progressbar(int)), this, SLOT(setProgressbar(int)));
-        connect(routeDialog, SIGNAL(rejected()),       this, SLOT(killRouteDialog()));
-        //connect(routeDialog, SIGNAL(killRoute()),      this, SLOT(killRouteDialog()));
-
-        QString routeFile = QString(".//speedfreak_route/routetemp.xml");
-        if (routeDialog->readRouteFromFile( routeFile ) == true)
-        {
-            //calibrateDialog->close();
-            routeDialog->show();
-        }
-        else
-        {
-            //calibrateDialog->close();
-        }
-calibrateDialog->close();*/
 
         //Set GPS speed labels in visible
         ui->labelGpsSpeed->setVisible(0);
@@ -321,7 +289,8 @@ calibrateDialog->close();*/
         //User info label
         ui->labelUserInfo->setText("Push start button");
 
-        openRouteDialog("routetemp.xml");
+        fileName = "/home/user/MyDocs/speedfreak/route/routetemp.xml";
+        openRouteDialog();
     }
 }
 
@@ -465,9 +434,9 @@ void RouteSaveDialog::gpsStatus()
 /**
   * This slot function is called when routeDialog emit sendroute (sendPushButton).
   */
-void RouteSaveDialog::sendRoute(QString s,int i)
+void RouteSaveDialog::sendRoute(QString newName, int i)
 {
-    emit sendroute(s,i); //Emit mainwindow clientSendRoute
+    emit sendroute(fileName, newName, i); //Emit mainwindow clientSendRoute
 }
 
 /**
@@ -538,8 +507,8 @@ QString RouteSaveDialog::getDistanceTraveled()
   */
 void RouteSaveDialog::setProgressbar(int i)
 {
-    qDebug() << "__setProgressbar " ;
-    qDebug() << i;
+    qDebug() << "__setProgressbar: " + QString::number(i);
+    //qDebug() << i;
     calibrateDialog->setProgressValue(i);
     progressbarIteration++;
 }
@@ -549,46 +518,49 @@ void RouteSaveDialog::setProgressbar(int i)
   */
 void RouteSaveDialog::on_buttonLoadRoute_clicked()
 {
-    QString fileName = QFileDialog::getOpenFileName(this, tr("Open route"), QDir::currentPath());
+    fileName = QFileDialog::getOpenFileName(this, tr("Open route"), "/home/user/MyDocs/speedfreak/route", "XML (*.xml)");
     qDebug() << "__Opening: " + fileName;
-    openRouteDialog(fileName);
+    openRouteDialog();//fileName);
 }
 
 /**
-  * This function open route.
+  * This function open and show route.
   * @param QString file name
   */
-void RouteSaveDialog::openRouteDialog(QString fileName)
+void RouteSaveDialog::openRouteDialog()
 {
-    // Progress bar
-    if(!calibrateDialog)
+    if(fileName != "")
     {
-        calibrateDialog = new CalibrateDialog();
-    }
+        // Progress bar
+        if(!calibrateDialog)
+        {
+            calibrateDialog = new CalibrateDialog();
+        }
 
-    progressbarPoints = 100;
-    progressbarIteration = 0;
-    calibrateDialog->resetProgressValue();
-    calibrateDialog->setMaxValue( progressbarPoints );
-    calibrateDialog->setTitle("Calculating route...");
-    calibrateDialog->show();
+        progressbarPoints = 100;
+        progressbarIteration = 0;
+        calibrateDialog->resetProgressValue();
+        calibrateDialog->setMaxValue( progressbarPoints );
+        calibrateDialog->setTitle("Calculating route...");
+        calibrateDialog->show();
 
-    if(!routeDialog)
-    {
-        routeDialog = new RouteDialog(this);
-    }
+        if(!routeDialog)
+        {
+            routeDialog = new RouteDialog(this);
+        }
 
-    connect(routeDialog, SIGNAL(sendroute()),      this, SLOT(sendRoute()));
-    connect(routeDialog, SIGNAL(progressbar(int)), this, SLOT(setProgressbar(int)));
-    connect(routeDialog, SIGNAL(rejected()),       this, SLOT(killRouteDialog()));
+        connect(routeDialog, SIGNAL(sendroute(QString, int)), this, SLOT(sendRoute(QString, int)));
+        connect(routeDialog, SIGNAL(progressbar(int)), this, SLOT(setProgressbar(int)));
+        connect(routeDialog, SIGNAL(rejected()), this, SLOT(killRouteDialog()));
 
-    if (routeDialog->readRouteFromFile( fileName ) == true)
-    {
-        calibrateDialog->close();
-        routeDialog->show();
-    }
-    else
-    {
-        calibrateDialog->close();
+        if (routeDialog->readRouteFromFile( fileName ) == true)
+        {
+            calibrateDialog->close();
+            routeDialog->show();
+        }
+        else
+        {
+            calibrateDialog->close();
+        }
     }
 }
index 2c06aa3..50ddaff 100644 (file)
@@ -59,7 +59,8 @@ private:
     double direction;
     int progressbarIteration;
     int progressbarPoints;
-    void openRouteDialog(QString fileName);
+    void openRouteDialog();
+    QString fileName;
 
 private slots:
     void on_buttonLoadRoute_clicked();
@@ -74,7 +75,7 @@ private slots:
     void setProgressbar(int i);
 
 signals:
-    void sendroute(QString,int);
+    void sendroute(QString,QString,int);
 
 };