File indexing completed on 2024-04-21 16:30:38

0001 // SPDX-License-Identifier: GPL-3.0-or-later
0002 /*
0003   Copyright 2017 Martin Koller, kollix@aon.at
0004 
0005   This file is part of liquidshell.
0006 
0007   liquidshell is free software: you can redistribute it and/or modify
0008   it under the terms of the GNU General Public License as published by
0009   the Free Software Foundation, either version 3 of the License, or
0010   (at your option) any later version.
0011 
0012   liquidshell is distributed in the hope that it will be useful,
0013   but WITHOUT ANY WARRANTY; without even the implied warranty of
0014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015   GNU General Public License for more details.
0016 
0017   You should have received a copy of the GNU General Public License
0018   along with liquidshell.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 
0021 #ifndef _WeatherApplet_H_
0022 #define _WeatherApplet_H_
0023 
0024 #include <DesktopApplet.hxx>
0025 #include <WeatherAppletConfigureDialog.hxx>
0026 
0027 #include <QTimer>
0028 #include <QLabel>
0029 #include <QPointer>
0030 
0031 #include <KIO/StoredTransferJob>
0032 
0033 // applet using data from http://api.openweathermap.org
0034 
0035 class WeatherApplet : public DesktopApplet
0036 {
0037   Q_OBJECT
0038 
0039   public:
0040     WeatherApplet(QWidget *parent, const QString &theId);
0041 
0042     void loadConfig() override;
0043     QSize sizeHint() const override;
0044 
0045   public Q_SLOTS:
0046     void configure() override;
0047 
0048   protected:
0049     void showEvent(QShowEvent *event) override;
0050 
0051   private Q_SLOTS:
0052     void fetchData();
0053     void gotData(KJob *job);
0054 
0055   private:  // methods
0056     void setIcon(QLabel *label, const QString &icon);
0057 
0058   private:  // members
0059     static QString apiKey; // see http://openweathermap.org/api
0060     QString cityId, units;
0061     QTimer timer;
0062     QPixmap moon;
0063     QLabel *cityLabel = nullptr;
0064     QLabel *moonLabel = nullptr;
0065     QLabel *tempLabel = nullptr;
0066     QLabel *pressureLabel = nullptr;
0067     QLabel *humidityLabel = nullptr;
0068     QLabel *windSpeedLabel = nullptr;
0069     QLabel *windDirectionLabel = nullptr;
0070 
0071     class ForecastWidget *shortForecast[4] = { nullptr };
0072     class ForecastWidget *forecast[5] = { nullptr };
0073 
0074     QPointer<WeatherAppletConfigureDialog> dialog;
0075 
0076     friend WeatherAppletConfigureDialog;
0077 };
0078 
0079 //--------------------------------------------------------------------------------
0080 
0081 class ForecastWidget : public QWidget
0082 {
0083   Q_OBJECT
0084 
0085   public:
0086     ForecastWidget(QWidget *parent, bool showMinMax = true);
0087 
0088     QLabel *min = nullptr;
0089     QLabel *max = nullptr;
0090     QLabel *day = nullptr;
0091     QLabel *icon = nullptr;
0092 };
0093 
0094 #endif