summaryrefslogtreecommitdiffstats
path: root/app/file_operation.cpp
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2018-11-07 11:06:42 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-02-13 11:00:20 +0900
commit0ed2885ececf079f16b42fec60a4dc86285b5101 (patch)
treeb07075ffbebf9680ad4d5d2d6a4fa99a4ceee06c /app/file_operation.cpp
parentae47635e56c4af4d816a76e5186e945768543679 (diff)
add tbtnavi source
Diffstat (limited to 'app/file_operation.cpp')
-rw-r--r--app/file_operation.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/app/file_operation.cpp b/app/file_operation.cpp
new file mode 100644
index 0000000..a191c76
--- /dev/null
+++ b/app/file_operation.cpp
@@ -0,0 +1,92 @@
+#include "file_operation.h"
+
+File_Operation::File_Operation(){
+ initFileOperation();
+}
+
+File_Operation::~File_Operation(){
+
+}
+
+void File_Operation::initFileOperation(){
+
+ m_mapAccessToken = "";
+ m_car_speed = 60; // set default Km/h
+ m_update_interval = 100; // set default millisecond
+ m_start_latitude = 35.692396; // set default coordinate Tokyo Hilton
+ m_start_longitute = 139.691102;
+
+ QFile file(NAVI_CONFIG_FILEPATH);
+ if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
+ fprintf(stderr,"Failed to open mapAccessToken file \"%s\": %m", qPrintable(NAVI_CONFIG_FILEPATH));
+ return;
+ }
+
+ QByteArray data = file.readAll();
+ QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
+ QJsonObject jsonObj(jsonDoc.object());
+
+ if(jsonObj.contains("mapAccessToken")){
+ m_mapAccessToken = jsonObj["mapAccessToken"].toString();
+ }else{
+ fprintf(stderr,"Failed to find mapAccessToken data \"%s\": %m", qPrintable(NAVI_CONFIG_FILEPATH));
+ return;
+ }
+ if(jsonObj.contains("mapStyle")){
+ m_mapStyle = jsonObj["mapStyle"].toString();
+ }else{
+ fprintf(stderr,"Failed to find mapStyle data \"%s\": %m", qPrintable(NAVI_CONFIG_FILEPATH));
+ return;
+ }
+
+ if(jsonObj.contains("speed")){
+ m_car_speed = jsonObj["speed"].toDouble();
+ }else{
+ fprintf(stderr,"Failed to find speed data \"%s\": %m", qPrintable(NAVI_CONFIG_FILEPATH));
+ return;
+ }
+
+ if(jsonObj.contains("interval")){
+ m_update_interval = jsonObj["interval"].toInt();
+ }else{
+ fprintf(stderr,"Failed to find interval data \"%s\": %m", qPrintable(NAVI_CONFIG_FILEPATH));
+ return;
+ }
+
+ if(jsonObj.contains("latitude")){
+ m_start_latitude = jsonObj["latitude"].toDouble();
+ }else{
+ fprintf(stderr,"Failed to find latitude data \"%s\": %m", qPrintable(NAVI_CONFIG_FILEPATH));
+ return;
+ }
+
+ if(jsonObj.contains("longitute")){
+ m_start_longitute = jsonObj["longitute"].toDouble();
+ }else{
+ fprintf(stderr,"Failed to find longitute data \"%s\": %m", qPrintable(NAVI_CONFIG_FILEPATH));
+ return;
+ }
+
+ file.close();
+
+ return;
+}
+
+QString File_Operation::getMapAccessToken() {
+ return m_mapAccessToken;
+}
+QString File_Operation::getMapStyle() {
+ return m_mapStyle;
+}
+double File_Operation::getCarSpeed(){
+ return m_car_speed;
+}
+int File_Operation::getUpdateInterval(){
+ return m_update_interval;
+}
+double File_Operation::getStartLatitude(){
+ return m_start_latitude;
+}
+double File_Operation::getStartLongitute(){
+ return m_start_longitute;
+}