Commit 1916d1db authored by Luís Gabriel Lima's avatar Luís Gabriel Lima
Browse files

Add NoticesView


Signed-off-by: default avatarLuís Gabriel Lima <lampih@gmail.com>
parent 99907e70
/*
* Copyright 2012 Luís Gabriel Lima <lampih@gmail.com>
*
* 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 1.1
Column {
property alias model: repeater.model
property alias title: title.text
anchors.left: parent.left
anchors.right: parent.right
Text {
id: title
font.bold: true
color: theme.textColor
}
Repeater {
id: repeater
Text {
font.underline: true
color: theme.linkColor
text: modelData.description
MouseArea {
anchors.fill: parent
onClicked: weatherApplet.invokeBrowser(modelData.info);
}
}
}
}
/*
* Copyright 2012 Luís Gabriel Lima <lampih@gmail.com>
*
* 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 1.1
Column {
id: root
property variant model
spacing: 10
visible: model.length > 0 && model[0].length > 0 && model[1].length > 0
clip: true
Notice {
title: i18nc("weather warnings", "Warnings Issued:")
model: root.model[0]
}
Notice {
title: i18nc("weather watches" ,"Watches Issued:")
model: root.model[1]
}
}
......@@ -50,7 +50,7 @@ Item {
topMargin: 5
horizontalCenter: parent.horizontalCenter
}
width: 160
width: noticesView.visible ? 240 : 160
height: 30
visible: detailsView.model.length > 0
......@@ -62,6 +62,11 @@ Item {
text: i18n("Details")
onClicked: root.state = "details";
}
PlasmaComponents.TabButton {
text: i18n("Notices")
visible: noticesView.visible
onClicked: root.state = "notices";
}
}
FiveDaysView {
......@@ -86,6 +91,16 @@ Item {
model: weatherApplet.detailsModel
}
NoticesView {
id: noticesView
anchors {
top: fiveDaysView.top
bottom: fiveDaysView.bottom
}
width: parent.width
model: weatherApplet.noticesModel
}
Text {
id: courtesyLabel
anchors {
......@@ -112,19 +127,26 @@ Item {
name: "fiveDays"
PropertyChanges { target: fiveDaysView; x: 0 }
PropertyChanges { target: detailsView; x: root.width + 10 }
PropertyChanges { target: noticesView; x: 2*root.width + 10 }
},
State {
name: "details"
PropertyChanges { target: fiveDaysView; x: -root.width - 10 }
PropertyChanges { target: detailsView; x: 0 }
PropertyChanges { target: noticesView; x: root.width + 10 }
},
State {
name: "notices"
PropertyChanges { target: fiveDaysView; x: -2*root.width - 10 }
PropertyChanges { target: detailsView; x: -root.width - 10 }
PropertyChanges { target: noticesView; x: 0 }
}
]
transitions: Transition {
from: "fiveDays"
to: "details"
reversible: true
to: "*"
PropertyAnimation { target: fiveDaysView; property: "x"; easing.type: Easing.InQuad; duration: 250 }
PropertyAnimation { target: detailsView; property: "x"; easing.type: Easing.InQuad; duration: 250 }
PropertyAnimation { target: noticesView; property: "x"; easing.type: Easing.InQuad; duration: 250 }
}
}
......@@ -134,9 +134,12 @@ void WeatherApplet::constraintsEvent(Plasma::Constraints constraints)
}
}
void WeatherApplet::invokeBrowser() const
void WeatherApplet::invokeBrowser(const QString &url) const
{
KToolInvocation::invokeBrowser(m_creditUrl);
if (url.isEmpty())
KToolInvocation::invokeBrowser(m_creditUrl);
else
KToolInvocation::invokeBrowser(url);
}
QString WeatherApplet::convertTemperature(KUnitConversion::UnitPtr format, QString value,
......@@ -415,6 +418,29 @@ void WeatherApplet::updateDetailsModel(const Plasma::DataEngine::Data &data)
}
}
void WeatherApplet::updateNoticesModel(const Plasma::DataEngine::Data &data)
{
m_noticesModel.clear();
QVariantList warnings;
for (int i = 0; i < data["Total Warnings Issued"].toInt(); i++) {
QVariantMap warning;
warning["description"] = data[QString("Warning Description %1").arg(i)];
warning["info"] = data[QString("Warning Info %1").arg(i)];
warnings << warning;
}
m_noticesModel << QVariant(warnings);
QVariantList watches;
for (int i = 0; i < data["Total Watches Issued"].toInt(); i++) {
QVariantMap watch;
watch["description"] = data[QString("Watch Description %1").arg(i)];
watch["info"] = data[QString("Watch Info %1").arg(i)];
watches << watch;
}
m_noticesModel << QVariant(watches);
}
void WeatherApplet::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
{
if (data.isEmpty()) {
......@@ -424,6 +450,7 @@ void WeatherApplet::dataUpdated(const QString &source, const Plasma::DataEngine:
updatePanelModel(data);
updateFiveDaysModel(data);
updateDetailsModel(data);
updateNoticesModel(data);
WeatherPopupApplet::dataUpdated(source, data);
emit dataUpdated();
......
......@@ -34,6 +34,7 @@ class WeatherApplet : public WeatherPopupApplet
Q_PROPERTY(QVariantMap panelModel READ panelModel NOTIFY dataUpdated)
Q_PROPERTY(QVariantList fiveDaysModel READ fiveDaysModel NOTIFY dataUpdated)
Q_PROPERTY(QVariantList detailsModel READ detailsModel NOTIFY dataUpdated)
Q_PROPERTY(QVariantList noticesModel READ noticesModel NOTIFY dataUpdated)
public:
WeatherApplet(QObject *parent, const QVariantList &args);
~WeatherApplet();
......@@ -43,13 +44,14 @@ public:
QVariantMap panelModel() const { return m_panelModel; }
QVariantList fiveDaysModel() const { return m_fiveDaysModel; }
QVariantList detailsModel() const { return m_detailsModel; }
QVariantList noticesModel() const { return m_noticesModel; }
signals:
void dataUpdated();
public Q_SLOTS:
void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data);
void invokeBrowser() const;
void invokeBrowser(const QString &url = QString()) const;
protected Q_SLOTS:
void configAccepted();
......@@ -59,13 +61,13 @@ protected Q_SLOTS:
protected:
void constraintsEvent(Plasma::Constraints constraints);
private:
bool isValidData(const QVariant &data) const;
void resetPanelModel();
void updatePanelModel(const Plasma::DataEngine::Data &data);
void updateFiveDaysModel(const Plasma::DataEngine::Data &data);
void updateDetailsModel(const Plasma::DataEngine::Data &data);
void updateNoticesModel(const Plasma::DataEngine::Data &data);
QString convertTemperature(KUnitConversion::UnitPtr format, QString value,
int type, bool rounded = false, bool degreesOnly = false);
......@@ -76,6 +78,7 @@ private:
QVariantMap m_panelModel;
QVariantList m_fiveDaysModel;
QVariantList m_detailsModel;
QVariantList m_noticesModel;
};
K_EXPORT_PLASMA_APPLET(weather, WeatherApplet)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment