indicator-china-weather/fix-auto-get-location.patch

113 lines
4.6 KiB
Diff
Raw Normal View History

2022-01-10 15:21:36 +08:00
diff -Naur indicator-china-weather-3.1.0/src/geoipworker.cpp indicator-china-weather-3.1.0~/src/geoipworker.cpp
--- indicator-china-weather-3.1.0/src/geoipworker.cpp 2021-11-27 03:59:19.000000000 +0800
+++ indicator-china-weather-3.1.0~/src/geoipworker.cpp 2022-01-10 14:49:04.598862385 +0800
@@ -264,29 +264,33 @@
const QString automaicCity()
{
- QString ip;
- QString city;
+// QString ip;
+// QString city;
- getIpAndCityByUbuntu(UbuntuUrl, ip, city);
- if (ip.isEmpty() || ip == "0.0.0.0") {
- ip = getIpByPconline(PconlineUrl);
- }
-
-// qDebug() << "ip:" << ip;
-
- if (city.isEmpty()) {
- city = getCityFromIPAddr(ip);//根据ip从geoip库定位城市
- if (city.isEmpty()) {
- city = getCityFromIpByAmap(ip);//根据ip从高德API定位城市该方式使用高德key访问次数有限
- }
- if (city.isEmpty()) {
- city = getCityFromIpByTaobao(ip);//根据ip从淘宝service定位城市该方式访问速度慢可能访问失败
- }
- }
-
-// qDebug() << "city:" << city;
-
- return city;
+// getIpAndCityByUbuntu(UbuntuUrl, ip, city);
+// if (ip.isEmpty() || ip == "0.0.0.0") {
+// ip = getIpByPconline(PconlineUrl);
+// }
+// if (city.isEmpty()) {
+// city = getCityFromIPAddr(ip);//根据ip从geoip库定位城市
+// if (city.isEmpty()) {
+// city = getCityFromIpByAmap(ip);//根据ip从高德API定位城市该方式使用高德key访问次数有限
+// }
+// if (city.isEmpty()) {
+// city = getCityFromIpByTaobao(ip);//根据ip从淘宝service定位城市该方式访问速度慢可能访问失败
+// }
+// }
+// return city;
+ QNetworkAccessManager *manager = new QNetworkAccessManager();
+ QNetworkReply *reply = manager->get(QNetworkRequest(QUrl("http://myip.ipip.net")));
+ QByteArray responseData ;
+ QEventLoop eventLoop;
+ QObject::connect(manager,&QNetworkAccessManager::finished,&eventLoop,&QEventLoop::quit);
+ eventLoop.exec();
+ responseData = reply->readAll();
+ QString str = responseData;
+ QStringList respList = str.split(' ');
+ return respList[5];
}
} // namespace
diff -Naur indicator-china-weather-3.1.0/src/geoipworker.h indicator-china-weather-3.1.0~/src/geoipworker.h
--- indicator-china-weather-3.1.0/src/geoipworker.h 2021-11-27 03:59:19.000000000 +0800
+++ indicator-china-weather-3.1.0~/src/geoipworker.h 2022-01-10 14:49:04.574862040 +0800
@@ -21,6 +21,10 @@
#define GEOIP_WORKER_H
#include <QObject>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+#include <QEventLoop>
class QNetworkAccessManager;
class QNetworkReply;
diff -Naur indicator-china-weather-3.1.0/src/mainwindow.cpp indicator-china-weather-3.1.0~/src/mainwindow.cpp
--- indicator-china-weather-3.1.0/src/mainwindow.cpp 2021-11-27 03:59:19.000000000 +0800
+++ indicator-china-weather-3.1.0~/src/mainwindow.cpp 2022-01-10 14:49:04.606862500 +0800
@@ -361,11 +361,12 @@
//根据获取到网络探测的结果分别处理
connect(m_weatherManager, &WeatherManager::nofityNetworkStatus, this, [=] (const QString &status) {
if (status == "OK") {
- //m_weatherManager->startAutoLocationTask();//开始自动定位城市
+ m_weatherManager->startAutoLocationTask();//开始自动定位城市
//CN101010100,beijing,北京,CN,China,中国
- // m_weatherManager->startGetTheWeatherData("101010100");
+// m_weatherManager->startGetTheWeatherData("101010100");
QStringList listCityId = getCityList().split(",");
+ qDebug()<<"listCityId:"<<listCityId;
m_weatherManager->startGetTheWeatherData(listCityId.at(0));
} else {
if (status == "Fail") {
@@ -381,6 +382,9 @@
connect(m_weatherManager, &WeatherManager::requestAutoLocationData, this, [=] (const CitySettingData &info, bool success) {
if (success) {
//自动定位城市成功后更新各个ui然后获取天气数据
+ m_weatherManager->startGetTheWeatherData(info.id);
+
+
} else {
//自动定位城市失败后,获取天气数据
}
diff -Naur indicator-china-weather-3.1.0/src/weathermanager.cpp indicator-china-weather-3.1.0~/src/weathermanager.cpp
--- indicator-china-weather-3.1.0/src/weathermanager.cpp 2021-11-27 03:59:19.000000000 +0800
+++ indicator-china-weather-3.1.0~/src/weathermanager.cpp 2022-01-10 14:49:04.559861824 +0800
@@ -165,7 +165,6 @@
}
file.close();
}
-
if (autoSuccess) {
emit this->requestAutoLocationData(info, true);
} else {