fix get Weather error
This commit is contained in:
parent
f4cfd9a8b3
commit
d5c5ee0d20
@ -1,16 +1,15 @@
|
||||
From 4208da6c0f07a645b2cfe3b53c5ce28412639af9 Mon Sep 17 00:00:00 2001
|
||||
From 9b05757e476316786e21a902982ed3befb9de443 Mon Sep 17 00:00:00 2001
|
||||
From: peijiankang <peijiankang@kylinos.cn>
|
||||
Date: Fri, 13 Jan 2023 15:14:11 +0800
|
||||
Date: Tue, 17 Jan 2023 13:42:01 +0800
|
||||
Subject: [PATCH] fix get Weather error
|
||||
|
||||
---
|
||||
src/gsettingmanager.cpp | 6 +++---
|
||||
src/platforminfo.cpp | 21 +++++++++++++++++++++
|
||||
src/platforminfo.h | 6 ++++--
|
||||
3 files changed, 28 insertions(+), 5 deletions(-)
|
||||
src/gsettingmanager.cpp | 17 ++++++++++++++---
|
||||
src/gsettingmanager.h | 3 +++
|
||||
2 files changed, 17 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/gsettingmanager.cpp b/src/gsettingmanager.cpp
|
||||
index fad7961..5869fa2 100644
|
||||
index fad7961..ff8630d 100644
|
||||
--- a/src/gsettingmanager.cpp
|
||||
+++ b/src/gsettingmanager.cpp
|
||||
@@ -677,7 +677,7 @@ Q_GLOBAL_STATIC(WeatherGsetting, weatherGsetting)
|
||||
@ -18,7 +17,7 @@ index fad7961..5869fa2 100644
|
||||
{
|
||||
//获取系统
|
||||
- if (PLATFORM::Intel.compare(PLATFORM::g_platformType,Qt::CaseInsensitive) == 0) {
|
||||
+ if (PLATFORM::Weathername.compare(PLATFORM::g_weathername,Qt::CaseInsensitive) == 0) {
|
||||
+ if (isFileExist(WEATHER_DESKTOP_FILE)) {
|
||||
const QByteArray id(WEATHER_GSETTING_OLD);
|
||||
if (QGSettings::isSchemaInstalled(id)) {
|
||||
m_pWeatherSetting = new QGSettings(id);
|
||||
@ -27,7 +26,7 @@ index fad7961..5869fa2 100644
|
||||
{
|
||||
//获取系统
|
||||
- if (PLATFORM::Intel.compare(PLATFORM::g_platformType,Qt::CaseInsensitive) == 0) {
|
||||
+ if (PLATFORM::Weathername.compare(PLATFORM::g_weathername,Qt::CaseInsensitive) == 0) {
|
||||
+ if (isFileExist(WEATHER_DESKTOP_FILE)) {
|
||||
const QByteArray id(WEATHER_GSETTING_OLD);
|
||||
if (QGSettings::isSchemaInstalled(id) && m_pWeatherSetting != nullptr \
|
||||
&& m_pWeatherSetting->keys().contains(WEATHER_GSETTING_KEY)) {
|
||||
@ -36,59 +35,56 @@ index fad7961..5869fa2 100644
|
||||
{
|
||||
//获取系统
|
||||
- if (PLATFORM::Intel.compare(PLATFORM::g_platformType,Qt::CaseInsensitive) == 0) {
|
||||
+ if (PLATFORM::Weathername.compare(PLATFORM::g_weathername,Qt::CaseInsensitive) == 0) {
|
||||
+ if (isFileExist(WEATHER_DESKTOP_FILE)) {
|
||||
const QByteArray id(WEATHER_GSETTING_OLD);
|
||||
if (QGSettings::isSchemaInstalled(id) && m_pWeatherSetting != nullptr \
|
||||
&& m_pWeatherSetting->keys().contains(WEATHER_GSETTING_KEY)) {
|
||||
diff --git a/src/platforminfo.cpp b/src/platforminfo.cpp
|
||||
index 8a16c2b..58f0792 100644
|
||||
--- a/src/platforminfo.cpp
|
||||
+++ b/src/platforminfo.cpp
|
||||
@@ -1,5 +1,26 @@
|
||||
#include "platforminfo.h"
|
||||
@@ -765,6 +765,17 @@ QString WeatherGsetting::getIcon()
|
||||
}
|
||||
}
|
||||
|
||||
+QString getweathername() {
|
||||
+ FILE *pp = NULL;
|
||||
+ char *line = NULL;
|
||||
+ size_t len = 0;
|
||||
+ QString weathername = "none";
|
||||
+
|
||||
+ pp = popen("rpm -q indicator-china-weather", "r");
|
||||
+ if(NULL == pp)
|
||||
+ return weathername;
|
||||
+
|
||||
+ if(getline(&line, &len, pp) != -1){
|
||||
+ weathername = "indicator-china-weather";
|
||||
+bool WeatherGsetting::isFileExist(QString FullFileName)
|
||||
+{
|
||||
+ QFileInfo fileInfo(FullFileName);
|
||||
+ if(fileInfo.isFile())
|
||||
+ {
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ free(line);
|
||||
+ line = NULL;
|
||||
+ pclose(pp);
|
||||
+ return weathername;
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
namespace PLATFORM {
|
||||
QString g_platformType = KDKGetPrjCodeName().c_str();
|
||||
+ QString g_weathername = getweathername();
|
||||
}
|
||||
diff --git a/src/platforminfo.h b/src/platforminfo.h
|
||||
index 1e331d9..17e6ca2 100644
|
||||
--- a/src/platforminfo.h
|
||||
+++ b/src/platforminfo.h
|
||||
@@ -6,9 +6,11 @@
|
||||
#include <ukuisdk/kylin-com4cxx.h>
|
||||
+
|
||||
//! 护眼中心
|
||||
Q_GLOBAL_STATIC(EyeprotectionGsetting, eyeprotectionGsetting)
|
||||
|
||||
namespace PLATFORM {
|
||||
- const QString V101 = "V10SP1";
|
||||
- const QString Intel = "V10SP1-edu";
|
||||
+ const QString V101 = "V10SP1";
|
||||
+ const QString Intel = "V10SP1-edu";
|
||||
+ const QString Weathername = "indicator-china-weather";
|
||||
extern QString g_platformType ;
|
||||
+ extern QString g_weathername ;
|
||||
}
|
||||
diff --git a/src/gsettingmanager.h b/src/gsettingmanager.h
|
||||
index 7319a27..9440598 100644
|
||||
--- a/src/gsettingmanager.h
|
||||
+++ b/src/gsettingmanager.h
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QGSettings>
|
||||
#include <QGuiApplication>
|
||||
#include <QDebug>
|
||||
+#include <QFileInfo>
|
||||
#include "../platforminfo.h"
|
||||
|
||||
#endif // PLATFORMINFO_H
|
||||
//! 控制中心-个性化部分
|
||||
@@ -293,6 +294,7 @@ private:
|
||||
#define WEATHER_GSETTING_OLD "org.china-weather-data.settings"
|
||||
#define WEATHER_GSETTING_NEW "org.kylin-weather.settings"
|
||||
#define WEATHER_GSETTING_KEY "weather"
|
||||
+#define WEATHER_DESKTOP_FILE "/etc/xdg/autostart/indicator-china-weather.desktop"
|
||||
|
||||
class WeatherGsetting : public QObject
|
||||
{
|
||||
@@ -305,6 +307,7 @@ public:
|
||||
|
||||
QString getWeather();
|
||||
QString getIcon();
|
||||
+ bool isFileExist(QString FullFileName);
|
||||
|
||||
private:
|
||||
QGSettings *m_pWeatherSetting = nullptr;
|
||||
--
|
||||
2.33.0
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user