1 /*  Copyright (c) 2003-2014 Xfce Development Team
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  * Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef __WEATHER_H__
20 #define __WEATHER_H__
21 
22 #include <libxfce4panel/libxfce4panel.h>
23 #include <libxfce4util/libxfce4util.h>
24 #include <xfconf/xfconf.h>
25 #include <libsoup/soup.h>
26 #ifdef HAVE_UPOWER_GLIB
27 #include <upower.h>
28 #endif
29 #include "weather-icon.h"
30 
31 #define PLUGIN_WEBSITE "https://docs.xfce.org/panel-plugins/xfce4-weather-plugin"
32 #define MAX_FORECAST_DAYS 10
33 #define DEFAULT_FORECAST_DAYS 5
34 #define MAX_SCROLLBOX_LINES 10
35 #define FORECAST_API "2.0"
36 
37 #define SETTING_LOCATION_NAME "/location/name"
38 #define SETTING_LATITUDE      "/location/latitude"
39 #define SETTING_LONGITUDE     "/location/longitude"
40 #define SETTING_MSL           "/msl"
41 #define SETTING_TIMEZONE      "/timezone"
42 #define SETTING_OFFSET        "/offset"
43 #define SETTING_GEONAMES      "/geonames-username"
44 #define SETTING_CACHE_MAX_AGE "/cache-max-age"
45 #define SETTING_POWER_SAVING  "/power-saving"
46 #define SETTING_TEMPERATURE   "/units/temperature"
47 #define SETTING_PRESSURE      "/units/pressure"
48 #define SETTING_WINDSPEED     "/units/windspeed"
49 #define SETTING_PRECIPITATION "/units/precipitation"
50 #define SETTING_ALTITUDE      "/units/altitude"
51 #define SETTING_APPARENT_TEMP "/units/apparent-temperature"
52 #define SETTING_ROUND         "/round"
53 #define SETTING_SINGLE_ROW    "/single-row"
54 #define SETTING_TOOLTIP_STYLE "/tooltip-style"
55 #define SETTING_FC_LAYOUT     "/forecast/layout"
56 #define SETTING_FC_DAYS       "/forecast/days"
57 #define SETTING_THEME_DIR     "/theme-dir"
58 #define SETTING_SB_SHOW       "/scrollbox/show"
59 #define SETTING_SB_ANIMATE    "/scrollbox/animate"
60 #define SETTING_SB_LINES      "/scrollbox/lines"
61 #define SETTING_SB_FONT       "/scrollbox/font"
62 #define SETTING_SB_COLOR      "/scrollbox/color"
63 #define SETTING_SB_USE_COLOR  "/scrollbox/use-color"
64 #define SETTING_LABELS        "/labels"
65 
66 G_BEGIN_DECLS
67 
68 typedef enum {
69     TOOLTIP_SIMPLE,
70     TOOLTIP_VERBOSE
71 } tooltip_styles;
72 
73 typedef enum {
74     FC_LAYOUT_CALENDAR,
75     FC_LAYOUT_LIST
76 } forecast_layouts;
77 
78 typedef struct {
79     GdkCursor *hand_cursor;
80     GdkCursor *text_cursor;
81     GtkWidget *icon_ebox;
82     GtkWidget *text_view;
83     gboolean on_icon;
84 } summary_details;
85 
86 typedef struct {
87     time_t last;
88     time_t next;
89     guint attempt;
90     guint check_interval;
91     gboolean started;
92     gboolean finished;
93     guint http_status_code;
94 } update_info;
95 
96 typedef struct {
97     XfcePanelPlugin *plugin;
98     XfconfChannel *channel;
99     const gchar *property_base;
100 
101 #ifdef HAVE_UPOWER_GLIB
102     UpClient *upower;
103     gboolean upower_on_battery;
104     gboolean upower_lid_closed;
105 #endif
106     gboolean power_saving;
107     SoupSession *session;
108     gchar *geonames_username;
109 
110     GtkWidget *button;
111     GtkWidget *alignbox;
112     GtkWidget *vbox_center_scrollbox;
113     GtkWidget *iconimage;
114     GdkPixbuf *tooltip_icon;
115     GtkWidget *summary_window;
116     GtkWidget *summary_subtitle;
117     summary_details *summary_details;
118     guint config_remember_tab;
119     guint summary_remember_tab;
120 
121     gint panel_size;
122     gint icon_size;
123     guint panel_rows;
124     XfcePanelPluginMode panel_orientation;
125     gboolean single_row;
126     xml_weather *weatherdata;
127     GArray *astrodata;
128     xml_astro *current_astro;
129 
130     update_info *astro_update;
131     update_info *weather_update;
132     update_info *conditions_update;
133     time_t next_wakeup;
134     gchar *next_wakeup_reason;
135     guint update_timer;
136     guint summary_update_timer;
137 
138     GtkWidget *scrollbox;
139     gboolean show_scrollbox;
140     guint scrollbox_lines;
141     gchar *scrollbox_font;
142     GdkRGBA scrollbox_color;
143     gboolean scrollbox_use_color;
144     gboolean scrollbox_animate;
145     GArray *labels;
146 
147     gchar *location_name;
148     gchar *lat;
149     gchar *lon;
150     gint msl;
151     gchar *timezone;
152     gchar *offset;
153     gchar *timezone_initial;
154     gint cache_file_max_age;
155     gboolean night_time;
156 
157     units_config *units;
158 
159     icon_theme *icon_theme;
160     tooltip_styles tooltip_style;
161     forecast_layouts forecast_layout;
162     guint forecast_days;
163     gboolean round;
164 } plugin_data;
165 
166 
167 extern gboolean debug_mode;
168 
169 void weather_http_queue_request(SoupSession *session,
170                                 const gchar *uri,
171                                 SoupSessionCallback callback_func,
172                                 gpointer user_data);
173 
174 void scrollbox_set_visible(plugin_data *data);
175 
176 void forecast_click(GtkWidget *widget,
177                     gpointer user_data);
178 
179 gchar *get_cache_directory(void);
180 
181 void update_timezone(plugin_data *data);
182 
183 void update_offset(plugin_data *data);
184 
185 void update_icon(plugin_data *data);
186 
187 void update_scrollbox(plugin_data *data,
188                       gboolean immediately);
189 
190 void update_weatherdata_with_reset(plugin_data *data);
191 
192 GArray *labels_clear(GArray *array);
193 
194 #if LIBXFCE4PANEL_CHECK_VERSION(4,9,0)
195 gboolean xfceweather_set_mode(XfcePanelPlugin *panel,
196                               XfcePanelPluginMode mode,
197                               plugin_data *data);
198 #endif
199 
200 G_END_DECLS
201 
202 #endif
203