Skip to content

Commit

Permalink
Added more info view for #51
Browse files Browse the repository at this point in the history
  • Loading branch information
k-donn committed May 24, 2024
1 parent 82d2960 commit 41deb39
Show file tree
Hide file tree
Showing 87 changed files with 143 additions and 22 deletions.
47 changes: 30 additions & 17 deletions plasmoid/contents/code/pws-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,31 @@ function getCurrentData() {

var res = JSON.parse(req.responseText);

// The nested section name returned in JSON is the units type
// So res cannot be directly assigned to weatherData
var tmp = {};
var tmp = res["observations"][0];
var obs = res["observations"][0];

var details = res["observations"][0][sectionName];
tmp["details"] = details;
var details = obs[sectionName];

// The properties are assigned to weatherData explicitly to preserve
// its structure instead of assigning obs completely and breaking it
weatherData["details"] = details;

weatherData["stationID"] = obs["stationID"];
weatherData["uv"] = obs["uv"];
weatherData["obsTimeLocal"] = obs["obsTimeLocal"];
weatherData["winddir"] = obs["winddir"];
weatherData["lat"] = obs["lat"];
weatherData["lon"] = obs["lon"];

weatherData = tmp;

plasmoid.configuration.latitude = weatherData["lat"];
plasmoid.configuration.longitude = weatherData["lon"];

printDebug("[pws-api.js] Got new current data");

findIconCode();
// Force QML to update text depending on weatherData
weatherData = weatherData;

getExtendedConditions();

appState = showDATA;
} else {
Expand Down Expand Up @@ -462,7 +471,7 @@ function getExtendedConditions() {
url += "?geocodes=" + lat + "," + long;
url += "&apiKey=" + API_KEY;
url += "&language=" + Qt.locale().name.replace("_","-");
url += "&scale=EPA"
url += "&scale=EPA";

if (unitsChoice === UNITS_SYSTEM.METRIC) {
url += "&units=m";
Expand Down Expand Up @@ -492,11 +501,11 @@ function getExtendedConditions() {
if (req.status == 200) {
var res = JSON.parse(req.responseText);

var combinedVars = res[0]
var combinedVars = res[0];

var condVars = combinedVars["v3-wx-observations-current"]
var alertsVars = combinedVars["v3alertsHeadlines"]
var airQualVars = combinedVars["v3-wx-globalAirQuality"]["globalairquality"]
var condVars = combinedVars["v3-wx-observations-current"];
var alertsVars = combinedVars["v3alertsHeadlines"];
var airQualVars = combinedVars["v3-wx-globalAirQuality"]["globalairquality"];

iconCode = iconThemeMap[condVars["iconCode"]];
conditionNarrative = condVars["wxPhraseLong"];
Expand All @@ -520,10 +529,14 @@ function getExtendedConditions() {
// parse and show weather alerts
}

weatherData["aq"]["aqi"] = airQualVars["airQualityIndex"]
weatherData["aq"]["aqhi"] = airQualVars["airQualityCategoryIndex"]
weatherData["aq"]["aqDesc"] = airQualVars["airQualityCategory"]
weatherData["aq"]["aqColor"] = airQualVars["airQualityCategoryIndexColor"]
weatherData["aq"]["aqi"] = airQualVars["airQualityIndex"];
weatherData["aq"]["aqhi"] = airQualVars["airQualityCategoryIndex"];
weatherData["aq"]["aqDesc"] = airQualVars["airQualityCategory"];
weatherData["aq"]["aqColor"] = airQualVars["airQualityCategoryIndexColor"];
weatherData["aq"]["aqPrimary"] = airQualVars["primaryPollutant"];

// Force QML to update text depending on weatherData
weatherData = weatherData;

}
}
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
89 changes: 89 additions & 0 deletions plasmoid/contents/ui/MoreInfoItem.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2024 Kevin Donnelly
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http: //www.gnu.org/licenses/>.
*/

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import org.kde.plasma.plasmoid
import org.kde.ksvg as KSvg
import org.kde.kirigami as Kirigami
import org.kde.plasma.core as PlasmaCore
import org.kde.plasma.components as PlasmaComponents
import "../code/utils.js" as Utils


ColumnLayout {
id: moreInfoRoot
PlasmaComponents.Label {
id: heading

font {
bold: true
pointSize: 20
}

text: i18n("Air quality")
}

GridLayout {
id: aqGrid

columns: 2
rows: 2

columnSpacing: parent.width * 0.25

Layout.alignment: Qt.AlignTop | Qt.AlignHCenter

PlasmaComponents.Label {
id: aqIndex

Layout.alignment: Qt.AlignHCenter

text: i18n("AQI: %1",weatherData["aq"]["aqi"])
}
PlasmaComponents.Label {
id: aqhi
Layout.alignment: Qt.AlignHCenter

text: i18n("AQHI: %1",weatherData["aq"]["aqhi"])
}
PlasmaComponents.Label {
id: aqIndexColor
Layout.alignment: Qt.AlignHCenter

color: "#" + weatherData["aq"]["aqColor"]

text: i18n("Status Color")
}
PlasmaComponents.Label {
id: aqPrimary
Layout.alignment: Qt.AlignHCenter

text: i18n("Primary pollutant: %1",weatherData["aq"]["aqPrimary"])
}
}

PlasmaComponents.Label {
Layout.alignment: Qt.AlignTop | Qt.AlignHCenter

id: aqDesc

text: i18n("Air quality message: %1", weatherData["aq"]["aqDesc"])
}

}
16 changes: 16 additions & 0 deletions plasmoid/contents/ui/SwitchPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ ColumnLayout {

text: i18n("Forecast")
}

PlasmaComponents.TabButton {
id: moreInfoTabButton

text: i18n("More Info")
}

}

SwipeView {
Expand Down Expand Up @@ -72,6 +79,15 @@ ColumnLayout {
Layout.alignment: Qt.AlignTop
}

MoreInfoItem {
id: moreInfoItem

Layout.preferredWidth: parent.width
Layout.preferredHeight: parent.height * 0.75

Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
}

onCurrentIndexChanged: {
tabBar.setCurrentIndex(currentIndex);
}
Expand Down
2 changes: 1 addition & 1 deletion plasmoid/contents/ui/config/ConfigAppearance.qml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ KCM.SimpleKCM {
ComboBox {
id: defaultLoadPage

model: ["Details","Forecast"]
model: ["Details","Forecast","More Info"]

Kirigami.FormData.label: i18n("Default page shown:")
}
Expand Down
11 changes: 7 additions & 4 deletions plasmoid/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ PlasmoidItem {
"uv": 0,
"obsTimeLocal": "",
"winddir": 0,
"lat": 0,
"lon": 0,
"details": {
"temp": 0,
"windSpeed": 0,
Expand All @@ -43,10 +45,11 @@ PlasmoidItem {
"elev": 0
},
"aq": {
"aqi": "",
"aqhi": "",
"aqi": 0,
"aqhi": 0,
"aqDesc": "",
"aqColor": ""
"aqColor": "FFFFFF",
"aqPrimary": "PM2.5"
},
"alerts": []
}
Expand All @@ -61,7 +64,7 @@ PlasmoidItem {
property int showERROR: 4
property int showDATA: 8

property int appState: showCONFIG
property int appState: showDATA

// QML does not let you property bind items part of ListModels.
// The TopPanel shows the high/low values which are items part of forecastModel
Expand Down

0 comments on commit 41deb39

Please sign in to comment.