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>
|
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
|
Subject: [PATCH] fix get Weather error
|
||||||
|
|
||||||
---
|
---
|
||||||
src/gsettingmanager.cpp | 6 +++---
|
src/gsettingmanager.cpp | 17 ++++++++++++++---
|
||||||
src/platforminfo.cpp | 21 +++++++++++++++++++++
|
src/gsettingmanager.h | 3 +++
|
||||||
src/platforminfo.h | 6 ++++--
|
2 files changed, 17 insertions(+), 3 deletions(-)
|
||||||
3 files changed, 28 insertions(+), 5 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/src/gsettingmanager.cpp b/src/gsettingmanager.cpp
|
diff --git a/src/gsettingmanager.cpp b/src/gsettingmanager.cpp
|
||||||
index fad7961..5869fa2 100644
|
index fad7961..ff8630d 100644
|
||||||
--- a/src/gsettingmanager.cpp
|
--- a/src/gsettingmanager.cpp
|
||||||
+++ b/src/gsettingmanager.cpp
|
+++ b/src/gsettingmanager.cpp
|
||||||
@@ -677,7 +677,7 @@ Q_GLOBAL_STATIC(WeatherGsetting, weatherGsetting)
|
@@ -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::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);
|
const QByteArray id(WEATHER_GSETTING_OLD);
|
||||||
if (QGSettings::isSchemaInstalled(id)) {
|
if (QGSettings::isSchemaInstalled(id)) {
|
||||||
m_pWeatherSetting = new QGSettings(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::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);
|
const QByteArray id(WEATHER_GSETTING_OLD);
|
||||||
if (QGSettings::isSchemaInstalled(id) && m_pWeatherSetting != nullptr \
|
if (QGSettings::isSchemaInstalled(id) && m_pWeatherSetting != nullptr \
|
||||||
&& m_pWeatherSetting->keys().contains(WEATHER_GSETTING_KEY)) {
|
&& 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::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);
|
const QByteArray id(WEATHER_GSETTING_OLD);
|
||||||
if (QGSettings::isSchemaInstalled(id) && m_pWeatherSetting != nullptr \
|
if (QGSettings::isSchemaInstalled(id) && m_pWeatherSetting != nullptr \
|
||||||
&& m_pWeatherSetting->keys().contains(WEATHER_GSETTING_KEY)) {
|
&& m_pWeatherSetting->keys().contains(WEATHER_GSETTING_KEY)) {
|
||||||
diff --git a/src/platforminfo.cpp b/src/platforminfo.cpp
|
@@ -765,6 +765,17 @@ QString WeatherGsetting::getIcon()
|
||||||
index 8a16c2b..58f0792 100644
|
}
|
||||||
--- a/src/platforminfo.cpp
|
}
|
||||||
+++ b/src/platforminfo.cpp
|
|
||||||
@@ -1,5 +1,26 @@
|
|
||||||
#include "platforminfo.h"
|
|
||||||
|
|
||||||
+QString getweathername() {
|
+bool WeatherGsetting::isFileExist(QString FullFileName)
|
||||||
+ FILE *pp = NULL;
|
+{
|
||||||
+ char *line = NULL;
|
+ QFileInfo fileInfo(FullFileName);
|
||||||
+ size_t len = 0;
|
+ if(fileInfo.isFile())
|
||||||
+ QString weathername = "none";
|
+ {
|
||||||
+
|
+ return true;
|
||||||
+ pp = popen("rpm -q indicator-china-weather", "r");
|
|
||||||
+ if(NULL == pp)
|
|
||||||
+ return weathername;
|
|
||||||
+
|
|
||||||
+ if(getline(&line, &len, pp) != -1){
|
|
||||||
+ weathername = "indicator-china-weather";
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+ return false;
|
||||||
+ free(line);
|
|
||||||
+ line = NULL;
|
|
||||||
+ pclose(pp);
|
|
||||||
+ return weathername;
|
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
namespace PLATFORM {
|
+
|
||||||
QString g_platformType = KDKGetPrjCodeName().c_str();
|
//! 护眼中心
|
||||||
+ QString g_weathername = getweathername();
|
Q_GLOBAL_STATIC(EyeprotectionGsetting, eyeprotectionGsetting)
|
||||||
}
|
|
||||||
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>
|
|
||||||
|
|
||||||
namespace PLATFORM {
|
diff --git a/src/gsettingmanager.h b/src/gsettingmanager.h
|
||||||
- const QString V101 = "V10SP1";
|
index 7319a27..9440598 100644
|
||||||
- const QString Intel = "V10SP1-edu";
|
--- a/src/gsettingmanager.h
|
||||||
+ const QString V101 = "V10SP1";
|
+++ b/src/gsettingmanager.h
|
||||||
+ const QString Intel = "V10SP1-edu";
|
@@ -5,6 +5,7 @@
|
||||||
+ const QString Weathername = "indicator-china-weather";
|
#include <QGSettings>
|
||||||
extern QString g_platformType ;
|
#include <QGuiApplication>
|
||||||
+ extern QString g_weathername ;
|
#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
|
2.33.0
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user