summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Fedoskin <afedoskin3@gmail.com>2016-11-01 17:44:38 (GMT)
committerArtem Fedoskin <afedoskin3@gmail.com>2016-11-01 17:44:38 (GMT)
commit6b9087d736598f4df5fef18fc5338cc431896119 (patch)
tree8b79cec53657beb021680366d7eade892de93603
parent8450f009c2976ca7df915414855cd74eec172bb6 (diff)
KStars Lite - Location name can be now automatically retrieved from internet while setting coordinates from GPS
-rw-r--r--cmake/modules/FindCFitsio.cmake17
-rw-r--r--cmake/modules/FindINDI.cmake2
-rw-r--r--cmake/modules/FindNova.cmake4
-rw-r--r--kstars/CMakeLists.txt21
-rw-r--r--kstars/kstarslite/dialogs/locationdialoglite.cpp80
-rw-r--r--kstars/kstarslite/dialogs/locationdialoglite.h26
-rw-r--r--kstars/kstarslite/qml/dialogs/LocationDialog.qml12
-rw-r--r--kstars/kstarslite/qml/dialogs/helpers/LocationEdit.qml124
-rw-r--r--kstars/kstarslite/qml/dialogs/helpers/LocationLoading.qml2
-rw-r--r--kstars/kstarslite/qml/main.qml1
10 files changed, 237 insertions, 52 deletions
diff --git a/cmake/modules/FindCFitsio.cmake b/cmake/modules/FindCFitsio.cmake
index 3b3edee..9cefba3 100644
--- a/cmake/modules/FindCFitsio.cmake
+++ b/cmake/modules/FindCFitsio.cmake
@@ -27,20 +27,23 @@ else (CFITSIO_INCLUDE_DIR AND CFITSIO_LIBRARIES)
endif (PKG_CONFIG_FOUND)
endif (NOT WIN32)
- find_path(CFITSIO_INCLUDE_DIR fitsio.h
if(ANDROID)
- ${CMAKE_SOURCE_DIR}/build_kstarslite/include
+ find_path(CFITSIO_INCLUDE_DIR fitsio.h
+ ${BUILD_KSTARSLITE_DIR}/include
+ NO_DEFAULT_PATH
+ )
else(ANDROID)
- ${PC_CFITSIO_INCLUDE_DIRS}
- ${_obIncDir}
- ${GNUWIN32_DIR}/include
+ find_path(CFITSIO_INCLUDE_DIR fitsio.h
+ ${PC_CFITSIO_INCLUDE_DIRS}
+ ${_obIncDir}
+ ${GNUWIN32_DIR}/include
+ )
endif(ANDROID)
- )
find_library(CFITSIO_LIBRARIES NAMES cfitsio libcfitsio
PATHS
if(ANDROID)
- ${CMAKE_SOURCE_DIR}/build_kstarslite/android_libs/${ANDROID_ARCHITECTURE}
+ ${BUILD_KSTARSLITE_DIR}/android_libs/${ANDROID_ARCHITECTURE}
else(ANDROID)
${PC_CFITSIO_LIBRARY_DIRS}
${_obIncDir}
diff --git a/cmake/modules/FindINDI.cmake b/cmake/modules/FindINDI.cmake
index dd4a267..2cb83a1 100644
--- a/cmake/modules/FindINDI.cmake
+++ b/cmake/modules/FindINDI.cmake
@@ -79,7 +79,7 @@ if (INDI_INCLUDE_DIR)
if(ANDROID)
find_library(INDI_CLIENT_ANDROID_LIBRARIES NAMES indiclientandroid
PATHS
- ${CMAKE_SOURCE_DIR}/build_kstarslite/android_libs/${ANDROID_ARCHITECTURE}/
+ ${BUILD_KSTARSLITE_DIR}/android_libs/${ANDROID_ARCHITECTURE}/
)
else(ANDROID)
find_library(INDI_LIBRARIES NAMES indi
diff --git a/cmake/modules/FindNova.cmake b/cmake/modules/FindNova.cmake
index c66d14e..6cb942a 100644
--- a/cmake/modules/FindNova.cmake
+++ b/cmake/modules/FindNova.cmake
@@ -21,7 +21,7 @@ else (NOVA_INCLUDE_DIR AND NOVA_LIBRARIES)
find_path(NOVA_INCLUDE_DIR libnova.h
if(ANDROID)
- ${CMAKE_SOURCE_DIR}/build_kstarslite/include
+ ${BUILD_KSTARSLITE_DIR}/include
endif(ANDROID)
PATH_SUFFIXES libnova
${_obIncDir}
@@ -31,7 +31,7 @@ else (NOVA_INCLUDE_DIR AND NOVA_LIBRARIES)
find_library(NOVA_LIBRARIES NAMES nova libnova
PATHS
if(ANDROID)
- ${CMAKE_SOURCE_DIR}/build_kstarslite/android_libs/${ANDROID_ARCHITECTURE}/
+ ${BUILD_KSTARSLITE_DIR}/android_libs/${ANDROID_ARCHITECTURE}/
else(ANDROID)
${_obLinkDir}
${GNUWIN32_DIR}/lib
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index d590d38..b58ad36 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -65,12 +65,8 @@ if (INDI_FOUND)
fitsviewer/fitsviewlite.cpp
fitsviewer/bayer.c
)
- if(ANDROID)
- include_directories(${kstars_SOURCE_DIR}/build_kstarslite/include)
- else()
- #if it is not Android we need only CFITSIO
include_directories(${CFITSIO_INCLUDE_DIR})
- endif()
+ include_directories(${NOVA_INCLUDE_DIR})
set (indi_SRCS
indi/clientmanagerlite.cpp
@@ -890,7 +886,8 @@ if(BUILD_KSTARS_LITE)
if(ANDROID)
#RAWExtractor is needed for converting RAW photos to JPEG in INDI Lite
add_library(RAWExtractor SHARED IMPORTED)
- set_property(TARGET RAWExtractor PROPERTY IMPORTED_LOCATION ${kstars_SOURCE_DIR}/build_kstarslite/android_libs/${ANDROID_ARCHITECTURE}/libRAWExtractor.so)
+ include_directories(${BUILD_KSTARSLITE_DIR}/include/libraw)
+ set_property(TARGET RAWExtractor PROPERTY IMPORTED_LOCATION ${BUILD_KSTARSLITE_DIR}/android_libs/${ANDROID_ARCHITECTURE}/libRAWExtractor.so)
target_link_libraries(KStarsLib RAWExtractor)
endif(ANDROID)
endif(INDI_FOUND)
@@ -944,13 +941,13 @@ if(INDI_FOUND)
endif(ANDROID)
else(WIN32 OR ANDROID)
# If INDI Qt5 Client is found, use it.
- # Do not use Qt5 client on Linux for now
- #if (INDI_CLIENT_QT_LIBRARIES)
- #add_definitions(-DUSE_QT5_INDI)
- #target_link_libraries(KStarsLib ${INDI_LIBRARIES} ${INDI_CLIENT_QT_LIBRARIES} z)
- #else(INDI_CLIENT_QT_LIBRARIES)
+ # Do not use Qt5 client on Linux for now (But KStars Lite needs it - polaris 31.10.2016)
+ if(BUILD_KSTARS_LITE)
+ add_definitions(-DUSE_QT5_INDI)
+ target_link_libraries(KStarsLib ${INDI_LIBRARIES} ${INDI_CLIENT_QT_LIBRARIES} z)
+ else(BUILD_KSTARS_LITE)
target_link_libraries(KStarsLib ${INDI_LIBRARIES} ${INDI_CLIENT_LIBRARIES} z)
- #endif(INDI_CLIENT_QT_LIBRARIES)
+ endif(BUILD_KSTARS_LITE)
endif(WIN32 OR ANDROID)
endif(INDI_FOUND)
diff --git a/kstars/kstarslite/dialogs/locationdialoglite.cpp b/kstars/kstarslite/dialogs/locationdialoglite.cpp
index 3794151..f2aaa71 100644
--- a/kstars/kstarslite/dialogs/locationdialoglite.cpp
+++ b/kstars/kstarslite/dialogs/locationdialoglite.cpp
@@ -21,6 +21,16 @@
#include "kspaths.h"
#include <QGeoPositionInfoSource>
#include "Options.h"
+#include <QNetworkAccessManager>
+#include <QNetworkSession>
+#include <QNetworkConfigurationManager>
+#include <QUrlQuery>
+#include <QNetworkReply>
+
+#include <QJsonDocument>
+#include <QJsonValue>
+#include <QJsonObject>
+#include <QJsonArray>
LocationDialogLite::LocationDialogLite()
:SelectedCity(nullptr), currentGeo(nullptr){
@@ -32,23 +42,52 @@ LocationDialogLite::LocationDialogLite()
KStarsData* data = KStarsData::Instance();
connect(data, SIGNAL(geoChanged()), this, SLOT(updateCurrentLocation()));
- setupGPS();
+ nam = new QNetworkAccessManager(this);
+ connect(nam, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(processLocationNameData(QNetworkReply*)));
}
-void LocationDialogLite::setupGPS() {
- m_geoSrc = QGeoPositionInfoSource::createDefaultSource(this);
+void LocationDialogLite::getNameFromCoordinates(double latitude, double longitude) {
+ QString lat = QString::number(latitude);
+ QString lon = QString::number(longitude);
+ QString latlng (lat + ", " + lon);
- connect(m_geoSrc, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(processNewCoordinates(QGeoPositionInfo)));
- connect(m_geoSrc, SIGNAL(updateTimeout()), this, SIGNAL(updateTimeoutGPS()));
-}
+ QUrl url("http://maps.googleapis.com/maps/api/geocode/json");
+ QUrlQuery query;
+ query.addQueryItem("latlng", latlng);
+ url.setQuery(query);
+ qDebug() << "submitting request";
-void LocationDialogLite::processNewCoordinates(QGeoPositionInfo position) {
-// m_geoSrc->stopUpdates();
- emit coordinatesChangedGPS(position);
+ nam->get(QNetworkRequest(url));
+ connect(nam, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(processLocationNameData(QNetworkReply*)));
}
-void LocationDialogLite::getCoordinatesFromGPS() {
- m_geoSrc->startUpdates();
+void LocationDialogLite::processLocationNameData(QNetworkReply *networkReply) {
+ if (!networkReply)
+ return;
+
+ if (!networkReply->error()) {
+ QJsonDocument document = QJsonDocument::fromJson(networkReply->readAll());
+
+ if (document.isObject()) {
+ QJsonObject obj = document.object();
+ QJsonValue val;
+
+ if (obj.contains(QStringLiteral("results"))) {
+ val = obj["results"];
+
+ QString city = val.toArray()[0].toObject()["address_components"].toArray()[2].toObject()["long_name"].toString();
+ QString region = val.toArray()[0].toObject()["address_components"].toArray()[3].toObject()["long_name"].toString();
+ QString country = val.toArray()[0].toObject()["address_components"].toArray()[4].toObject()["long_name"].toString();
+
+ emit newNameFromCoordinates(city, region, country);
+ } else {
+
+ }
+ }
+ }
+ networkReply->deleteLater();
}
void LocationDialogLite::initCityList() {
@@ -102,6 +141,7 @@ void LocationDialogLite::filterCity(QString city, QString province, QString coun
}
m_cityList.setStringList(cities);
m_cityList.sort(0);
+
setProperty("currLocIndex", m_cityList.stringList().indexOf(m_currentLocation));
}
@@ -109,6 +149,23 @@ bool LocationDialogLite::addCity(QString city, QString province, QString country
QSqlDatabase mycitydb = getDB();
if( mycitydb.isValid() ) {
+ QString fullName;
+ if(!city.isEmpty()) {
+ fullName += city;
+ }
+
+ if(!province.isEmpty()) {
+ fullName += ", " + province;
+ }
+
+ if(!country.isEmpty()) {
+ fullName += ", " + country;
+ }
+
+ if(m_cityList.stringList().contains(fullName)) {
+ return editCity(fullName, city, province, country, latitude, longitude, TimeZoneString, TZRule);
+ }
+
bool latOk(false), lngOk(false), tzOk(false);
dms lat = createDms( latitude, true, &latOk );
dms lng = createDms( longitude, true, &lngOk );
@@ -366,6 +423,7 @@ bool LocationDialogLite::checkLongLat(QString longitude, QString latitude) {
bool LocationDialogLite::setLocation(QString fullName) {
KStarsData *data = KStarsData::Instance();
+
GeoLocation *geo = filteredCityList.value(fullName);
if(!geo) {
foreach ( GeoLocation *loc, data->getGeoList() )
diff --git a/kstars/kstarslite/dialogs/locationdialoglite.h b/kstars/kstarslite/dialogs/locationdialoglite.h
index ab6b300..7e91d30 100644
--- a/kstars/kstarslite/dialogs/locationdialoglite.h
+++ b/kstars/kstarslite/dialogs/locationdialoglite.h
@@ -34,6 +34,10 @@
class GeoLocation;
class QGeoPositionInfoSource;
+class QNetworkAccessManager;
+class QNetworkSession;
+class QNetworkReply;
+
class LocationDialogLite : public QObject {
Q_OBJECT
Q_PROPERTY(QString currentLocation READ getCurrentLocation WRITE setCurrentLocation NOTIFY currentLocationChanged)
@@ -82,33 +86,23 @@ public:
dms createDms ( QString degree, bool deg, bool *ok );
/**
- * @short setup everything needed to use GPS
+ * @short retrieve name of location by latitude and longitude. Name will be sent with sendNameFromCoordinates signal
*/
- void setupGPS();
+ Q_INVOKABLE void getNameFromCoordinates(double latitude, double longitude);
- /**
- * Starts setting GPS fix. GPSCoordinatesChanged() signal will be emitted once coordinates are
- * fetched.
- */
- Q_INVOKABLE void getCoordinatesFromGPS();
public slots:
void initCityList();
void updateCurrentLocation();
- void processNewCoordinates(QGeoPositionInfo position);
+ void processLocationNameData(QNetworkReply *rep);
signals:
void currentLocationChanged(QString);
void TZListChanged(QStringList);
void DSTRulesChanged(QStringList);
void currLocIndexChanged(int);
-
- /** Emitted when GPS coordinates were successfully updated **/
- void coordinatesChangedGPS(QGeoPositionInfo newPos);
- /** Emitted when coordinates couldn't be fetched during 10 seconds **/
- void updateTimeoutGPS();
-
+ void newNameFromCoordinates(QString city, QString region, QString country);
private:
/**
* @short checks whether database with cities is already created. Creates a new otherwise
@@ -125,7 +119,9 @@ private:
QStringList m_TZList;
QStringList m_DSTRules;
- QGeoPositionInfoSource *m_geoSrc;
+
+ //Retrieve the name of city
+ QNetworkAccessManager *nam;
};
#endif
diff --git a/kstars/kstarslite/qml/dialogs/LocationDialog.qml b/kstars/kstarslite/qml/dialogs/LocationDialog.qml
index 7b9d694..119f141 100644
--- a/kstars/kstarslite/qml/dialogs/LocationDialog.qml
+++ b/kstars/kstarslite/qml/dialogs/LocationDialog.qml
@@ -137,5 +137,17 @@ KSPage {
locationEdit.openAdd()
}
}
+
+ Button {
+ anchors {
+ bottom: parent.bottom
+ right: parent.right
+ }
+
+ text: "Set from GPS"
+ onClicked: {
+ locationEdit.setAutomaticallyFromGPS()
+ }
+ }
}
}
diff --git a/kstars/kstarslite/qml/dialogs/helpers/LocationEdit.qml b/kstars/kstarslite/qml/dialogs/helpers/LocationEdit.qml
index 7da6315..a2225f1 100644
--- a/kstars/kstarslite/qml/dialogs/helpers/LocationEdit.qml
+++ b/kstars/kstarslite/qml/dialogs/helpers/LocationEdit.qml
@@ -23,6 +23,94 @@ KSPage {
property bool isReadOnly: false
property string geoName
property bool fieldsChanged: false //true whenever either city, province or country fields are changed. Turned to false every time this page is opened
+ property string loadingText //Text used in location loading popup
+ property string fetchingCoordinatesLoading: xi18n("Please, wait while we are fetching coordinates")
+
+ property bool fetchingName: false // true when we are fetchingN name of location
+ property bool addAutomatically: false //true if user wants add location automatically without manually editing the fields
+
+ signal locationFetched(var _lat, var _lng) //emitted when location is fetched in auto mode
+ signal locNameFetched(var _city, var _region, var _country) //emitted when location nane is fetched or was failed to fetch in auto mode
+
+ /*This function sets coordinates from GPS automatically, without asking user to fill information
+ about location */
+ function setAutomaticallyFromGPS() {
+ addAutomatically = true
+ positionSource.stop()
+ positionSource.start()
+ loadingText = fetchingCoordinatesLoading
+ if(!positionSource.valid) {
+ positionSource.stop()
+ notification.showNotification(xi18("Positioning is not available on your device"))
+ }
+ }
+
+ property double lat
+ property double lng
+ property string city
+ property string region
+ property string country
+ property int tz
+
+ onLocationFetched: {
+ lat = _lat
+ lng = _lng
+ }
+
+ Timer {
+ id: nameFetchTimeout
+ interval: 20000;
+ onTriggered: {
+ locationLoading.close()
+ var city = xi18n("Default city")
+ var province = xi18n("Default province")
+ var country = xi18n("Default country")
+ if(addAutomatically) {
+ notification.showNotification(xi18n("Couldn't fetch location name (check your internet connection). Added with default name"))
+ if(!LocationDialogLite.addCity(city, province, country,
+ lat, lng, tz,
+ "--")) {
+ notification.showNotification(xi18n("Failed to set location"))
+ return
+ }
+
+ if(LocationDialogLite.setLocation(city + ", " + province + ", " + country)) {
+ notification.showNotification(xi18n("Successfully set your location"))
+ } else {
+ notification.showNotification(xi18n("Couldn't set your location"))
+ }
+ } else {
+ notification.showNotification(xi18n("Couldn't fetch location name (check your internet connection). Set default name"))
+ cityField.text = city
+ provinceField.text = province
+ countryField.text = country
+ comboBoxTZ.currentIndex = comboBoxTZ.find(tz)
+ }
+ fetchingName = false
+ addAutomatically = false
+ }
+ }
+
+ onLocNameFetched: {
+ nameFetchTimeout.running = false
+ city = _city
+ region = _region
+ country = _country
+
+ if(!LocationDialogLite.addCity(city, region, country,
+ lat, lng, tz,
+ "--")) {
+ notification.showNotification(xi18n("Failed to set location"))
+ }
+
+ if(LocationDialogLite.setLocation(city + ", " + region + ", " + country)) {
+ notification.showNotification(xi18n("Successfully set your location"))
+ } else {
+ notification.showNotification(xi18n("Couldn't set your location"))
+ }
+
+ addAutomatically = false
+ }
function openAdd() {
editMode = false
@@ -70,6 +158,7 @@ KSPage {
notification.showNotification(errorDesc)
active = false
sourceError = positionSource.NoError
+ locationLoading.close()
}
onUpdateTimeout: {
@@ -80,7 +169,7 @@ KSPage {
onActiveChanged: {
if(positionSource.active) {
locationLoading.open()
- } else {
+ } else if (!fetchingName) {
locationLoading.close()
}
}
@@ -92,12 +181,42 @@ KSPage {
var lng = positionSource.position.coordinate.longitude
latField.text = lat
longField.text = lng
- locationLoading.close()
+ if(addAutomatically) {
+ locationFetched(lat, lng)
+ }
+
+ tz = new Date().getTimezoneOffset()/60
+ loadingText = xi18n("Please, wait while we are retrieving location name")
+ fetchingName = true // must be set to true before we are stopping positioning service
+ positionSource.stop()
+ LocationDialogLite.getNameFromCoordinates(lat, lng)
+ nameFetchTimeout.running = true
+ setTZComboBox(new Date().getTimezoneOffset())
}
}
preferredPositioningMethods: PositionSource.AllPositioningMethods
}
+ function setTZComboBox(TZMinutes) {
+ var TZ = TZMinutes/60
+ comboBoxTZ.currentIndex = comboBoxTZ.find(TZ)
+ }
+
+ Connections {
+ target: LocationDialogLite
+ onNewNameFromCoordinates: {
+ if(addAutomatically) {
+ locNameFetched(city, region, country)
+ }
+ cityField.text = city
+ provinceField.text = region
+ countryField.text = country
+ fetchingName = false
+ locationLoading.close()
+ addAutomatically = false
+ }
+ }
+
//close the popup and clears all text fields
onVisibleChanged: {
if(!visible) {
@@ -239,6 +358,7 @@ KSPage {
onClicked: {
positionSource.stop()
positionSource.start()
+ loadingText = fetchingCoordinatesLoading
if(!positionSource.valid) {
positionSource.stop()
notification.showNotification(xi18("Positioning is not available on your device"))
diff --git a/kstars/kstarslite/qml/dialogs/helpers/LocationLoading.qml b/kstars/kstarslite/qml/dialogs/helpers/LocationLoading.qml
index 41d6162..1dd8f31 100644
--- a/kstars/kstarslite/qml/dialogs/helpers/LocationLoading.qml
+++ b/kstars/kstarslite/qml/dialogs/helpers/LocationLoading.qml
@@ -44,7 +44,7 @@ Popup {
width: parent.width
wrapMode: Label.Wrap
horizontalAlignment: Label.AlignHCenter
- text: xi18n("Please, wait while we are fetching coordinates")
+ text: locationEdit.loadingText
}
Button {
diff --git a/kstars/kstarslite/qml/main.qml b/kstars/kstarslite/qml/main.qml
index 38cbc4a..9c80e79 100644
--- a/kstars/kstarslite/qml/main.qml
+++ b/kstars/kstarslite/qml/main.qml
@@ -517,7 +517,6 @@ ApplicationWindow {
onValueChanged: {
SkyMapLite.magLim = value
- console.log(colorSchemePopup.currentCScheme)
}
}
}