Route save/open development.
authoroppilas <oppilas@oppilas-laptop.(none)>
Wed, 12 May 2010 06:09:20 +0000 (09:09 +0300)
committeroppilas <oppilas@oppilas-laptop.(none)>
Wed, 12 May 2010 06:09:20 +0000 (09:09 +0300)
Client/gpsdata.cpp
Client/httpclient.cpp
Client/httpclient.h
Client/mainwindow.cpp
Client/mainwindow.h
Client/routedialog.cpp
Client/routedialog.h
Client/routesavedialog.cpp
Client/routesavedialog.h

index 1fa4983..3879b54 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("routetemp.xml");//Temp xml.
+        QFile routeTempFile(".//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("route.xml");
+        QFile file(".//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 (routetemp.xml).
+    //Write temp xml (.//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 (route.xml).
+    //Write final xml (.//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("routetemp.xml");
+        QFile tempFile(".//speedfreak_route/routetemp.xml");
         if (!tempFile.open(QIODevice::ReadOnly | QIODevice::Text))
             return;
         QTextStream readRoute(&tempFile);
index 944749f..933de3d 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <QString>
 #include <QMessageBox>
+#include <QDir>
 #include "httpclient.h"
 #include "mainwindow.h"
 
@@ -107,39 +108,55 @@ void HttpClient::sendResultXml(QString category, double result)
 }
 
 /**
-  *@brief Sends route to the server in xml format.
-  *Send authentication information in the header.
-  *@todo Check destination URL.
+  * @brief Sends route to the server in xml format.
+  * Send authentication information in the header.
+  * @param QString filename
+  * @param int 1(send to server) or 0(no send)
+  * @todo Check destination URL.
   */
-void HttpClient::sendRouteXml()
+void HttpClient::sendRouteXml(QString s, int i)
 {
     qDebug() << "_sendRouteXml";
 
-    QString filename = "route.xml";
-    QFile file(filename);
-    if (!file.open(QFile::ReadOnly)) {
-        qDebug() << "_sendRouteXml file.open() fail";
-        return;
+    QString filename = ".//speedfreak_route/route.xml";
+
+    if(s != "")
+    {
+        qDebug() << "_rename xml";
+        filename = s + ".xml";
+        QDir dir(filename);
+        qDebug() << dir.rename(".//speedfreak_route/route.xml", filename);
     }
 
-    QUrl qurl("http://api.speedfreak-app.com/api/update/route");
-    qDebug() << qurl.toString();
-    QNetworkRequest request(qurl);
-    QNetworkReply *currentDownload;
+    if(i == 1)
+    {
+        qDebug() << "_send route";
+        QFile file(filename);
+        if (!file.open(QFile::ReadOnly))
+        {
+            qDebug() << "_sendRouteXml file.open() fail";
+            return;
+        }
 
-    QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
-    credentials = "Basic " + credentials.toAscii().toBase64();
-    request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
+        QUrl qurl("http://api.speedfreak-app.com/api/update/route");
+        qDebug() << qurl.toString();
+        QNetworkRequest request(qurl);
+        QNetworkReply *currentDownload;
 
-    currentDownload = netManager->post(request, ("xml=" + file.readAll()));
-    connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRoute()));
-    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+        QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
+        credentials = "Basic " + credentials.toAscii().toBase64();
+        request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
 
-    //Indicating user
-    if(myMainw->routeSaveDialog->routeDialog)
-        myMainw->routeSaveDialog->routeDialog->setLabelInfoToUser("Sending route to server");
+        currentDownload = netManager->post(request, ("xml=" + file.readAll()));
+        connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRoute()));
+        //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
 
-    file.close();
+        //Indicating user
+        if(myMainw->routeSaveDialog->routeDialog)
+            myMainw->routeSaveDialog->routeDialog->setLabelInfoToUser("Sending route to server");
+
+        file.close();
+    }
 }
 
 /**
index 2c4bd84..f8a7b99 100644 (file)
@@ -39,7 +39,7 @@ public slots:
     void requestRegistration();
     void checkLogin();
     void sendResultXml(QString category, double result);
-    void sendRouteXml();
+    void sendRouteXml(QString, int);
     void requestTopList(QString category, QString limit);
     void requestCategories();
     void ackOfResult();
index 6eb8757..7c27b22 100644 (file)
@@ -180,7 +180,6 @@ MainWindow::~MainWindow()
         delete customButtonHelp;
 }
 
-
 /**
   *
   */
@@ -220,7 +219,7 @@ void MainWindow::clientRequestTopList(int index)
 }
 
 /**
-  *This function is used to set items to category combobox. Top-tab view.
+  *This function is used to set items to category combobox.
   *@param
   */
 void MainWindow::setCategoryCompoBox()
@@ -285,10 +284,10 @@ void MainWindow::clientUserLogin()
 /**
   * This function send route data to server.
   */
-void MainWindow::clientSendRoute()
+void MainWindow::clientSendRoute(QString s,int i)
 {
     if(httpClient)
-        httpClient->sendRouteXml();
+        httpClient->sendRouteXml(s,i);
 }
 
 /**
@@ -375,7 +374,7 @@ void MainWindow::OpenRouteDialog()
     if(!routeSaveDialog)
         routeSaveDialog = new RouteSaveDialog;
 
-    connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
+    connect(routeSaveDialog, SIGNAL(sendroute(QString,int)), this, SLOT(clientSendRoute(QString,int)));
     connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
     routeSaveDialog->show();
 }
index fb115ae..e0685d4 100644 (file)
@@ -66,7 +66,7 @@ private:
 private slots:
     void clientRequestCategoryList();
     void clientRequestTopList(int index);
-    void clientSendRoute();
+    void clientSendRoute(QString,int);
     void clientRegUserToServer();
     void clientUserLogin();
     void clientSendResult(QString category, double result);
index 8a77167..e73e872 100644 (file)
@@ -436,12 +436,13 @@ bool RouteDialog::readRouteFromFile( QString &routeFile )
     QFile file;
 
     file.setFileName( rFile);//"routetemp.xml");
+    //file.setFileName( ".//speedfreak_route/routetemp.xml");
     if (!file.open(QIODevice::ReadOnly))
     {
         QMessageBox::about(0, "Error", "File not found");
         return false;
     }
-emit progressbar(5);
+    emit progressbar(5);
     vertexList.clear();
     emit progressbar(50);
     while(!file.atEnd())
@@ -767,7 +768,32 @@ void transformseg( Viewing *v, Vector *v1, Vector *v2, int *xscreen1, int *yscre
 void RouteDialog::on_sendPushButton_clicked()
 {
     ui->sendPushButton->setEnabled(false);
-    emit sendroute();
+
+
+    QString folder = "speedfreak_route";
+
+    if(!QDir(folder).exists())
+    {
+        QDir().mkdir(folder);
+    }
+
+    QString fileName = QFileDialog::getSaveFileName(this, tr("Save Route"),
+                                ".//" + folder);//, tr("Route files  (*.xml)"));
+    qDebug() << 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.
+    }
+    else if(server == 4) // No button
+    {
+        qDebug() << "__no save";
+
+        if(fileName != "")
+            emit sendroute(fileName,0); // Save route.
+    }
 }
 
 /**
index 9f68617..24ff58e 100644 (file)
@@ -34,7 +34,7 @@ public:
     HelpRoutingDialog *helpRoutingDialog;
 
 signals:
-    void sendroute();
+    void sendroute(QString,int);
     void progressbar(int);
 
 protected:
index 0813f56..53175f4 100644 (file)
@@ -11,6 +11,7 @@
 #include <QDebug>
 #include <QPainter>
 #include <QFileDialog>
+#include <QDir>
 
 const QPoint arrowStartEast(100, 100);
 const QPoint arrowEndEast(140, 100);
@@ -88,6 +89,13 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) :
     location = new Maemo5Location(this);
     gpsData = new GPSData(location);
     connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus()));
+
+    // Route folder
+    QString folder = "speedfreak_route";
+    if(!QDir(folder).exists())
+    {
+        QDir().mkdir(folder);
+    }
 }
 
 /**
@@ -263,6 +271,42 @@ 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);
@@ -421,9 +465,9 @@ void RouteSaveDialog::gpsStatus()
 /**
   * This slot function is called when routeDialog emit sendroute (sendPushButton).
   */
-void RouteSaveDialog::sendRoute()
+void RouteSaveDialog::sendRoute(QString s,int i)
 {
-    emit sendroute(); //Emit mainwindow clientSendRoute
+    emit sendroute(s,i); //Emit mainwindow clientSendRoute
 }
 
 /**
index 7fe157e..2c06aa3 100644 (file)
@@ -68,13 +68,13 @@ private slots:
     void timerSatellitePictureTimeout();
     void timerRoutePictureTimeout();
     void gpsStatus();
-    void sendRoute();
+    void sendRoute(QString,int);
     void killHelpDialog();
     void killRouteDialog();
     void setProgressbar(int i);
 
 signals:
-    void sendroute();
+    void sendroute(QString,int);
 
 };