2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
26
Fabrice Rey (fabounet@users.berlios.de)
28
******************************************************************************/
30
#include <glib/gstdio.h>
32
#include "applet-struct.h"
33
#include "applet-read-data.h"
34
#include "applet-config.h"
36
GList *s_pLocationsList = NULL;
38
CD_APPLET_GET_CONFIG_BEGIN
39
//\_________________ On recupere toutes les valeurs de notre fichier de conf.
40
myConfig.cLocationCode = CD_CONFIG_GET_STRING_WITH_DEFAULT ("Configuration", "location code", "FRXX0076");
41
myConfig.bISUnits = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Configuration", "IS units", TRUE);
42
myConfig.bCurrentConditions = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Configuration", "display cc", TRUE);
43
myConfig.bDisplayNights = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Configuration", "display nights", FALSE);
44
myConfig.iNbDays = MIN (CD_CONFIG_GET_INTEGER_WITH_DEFAULT ("Configuration", "nb days", WEATHER_NB_DAYS_MAX), WEATHER_NB_DAYS_MAX);
45
myConfig.bDisplayTemperature = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Configuration", "display temperature", FALSE);
46
myConfig.cDialogDuration = 1000 * CD_CONFIG_GET_INTEGER_WITH_DEFAULT ("Configuration", "dialog duration", 5);
47
myConfig.iCheckInterval = 60 * MAX (CD_CONFIG_GET_INTEGER_WITH_DEFAULT ("Configuration", "check interval", 15), 1);
49
myConfig.cThemePath = CD_CONFIG_GET_THEME_PATH ("Configuration", "theme", "themes", "Classic");
51
myConfig.bDesklet3D = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Configuration", "3D desket", FALSE);
53
myConfig.cRenderer = CD_CONFIG_GET_STRING ("Configuration", "renderer");
55
gchar *cName = CD_CONFIG_GET_STRING ("Icon", "name");
56
myConfig.bSetName = (cName == NULL);
58
///myConfig.iDeskletRenderer = CD_CONFIG_GET_INTEGER_WITH_DEFAULT ("Configuration", "current desklet", 0);
59
CD_APPLET_GET_CONFIG_END
62
static void _reset_units (Unit *pUnits)
64
g_free (pUnits->cTemp);
65
g_free (pUnits->cDistance);
66
g_free (pUnits->cSpeed);
67
g_free (pUnits->cPressure);
70
static void _reset_current_conditions (CurrentContitions *pCurrentContitions)
72
g_free (pCurrentContitions->cSunRise);
73
g_free (pCurrentContitions->cSunSet);
74
g_free (pCurrentContitions->cDataAcquisitionDate);
75
g_free (pCurrentContitions->cObservatory);
76
g_free (pCurrentContitions->cTemp);
77
g_free (pCurrentContitions->cFeeledTemp);
78
g_free (pCurrentContitions->cWeatherDescription);
79
g_free (pCurrentContitions->cIconNumber);
80
g_free (pCurrentContitions->cWindSpeed);
81
g_free (pCurrentContitions->cWindDirection);
82
g_free (pCurrentContitions->cPressure);
83
g_free (pCurrentContitions->cHumidity);
84
g_free (pCurrentContitions->cMoonIconNumber);
87
static void _reset_current_one_day (Day *pDay)
91
g_free (pDay->cTempMax);
92
g_free (pDay->cTempMin);
93
g_free (pDay->cSunRise);
94
g_free (pDay->cSunSet);
96
for (j = 0; j < 2; j ++)
98
g_free (pDay->part[j].cIconNumber);
99
g_free (pDay->part[j].cWeatherDescription);
100
g_free (pDay->part[j].cWindSpeed);
101
g_free (pDay->part[j].cWindDirection);
102
g_free (pDay->part[j].cHumidity);
103
g_free (pDay->part[j].cPrecipitationProba);
107
CD_APPLET_RESET_CONFIG_BEGIN
108
g_free (myConfig.cLocationCode);
109
g_free (myConfig.cRenderer);
110
g_free (myConfig.cThemePath);
111
CD_APPLET_RESET_CONFIG_END
114
void cd_weather_reset_all_datas (CairoDockModuleInstance *myApplet)
116
cairo_dock_free_task (myData.pTask);
118
g_free (myData.cLon);
119
g_free (myData.cLat);
120
_reset_units (&myData.units);
121
_reset_current_conditions (&myData.currentConditions);
123
for (i = 0; i < myConfig.iNbDays; i ++)
125
_reset_current_one_day (&myData.days[i]);
128
cd_weather_free_location_list ();
130
CD_APPLET_DELETE_MY_ICONS_LIST;
132
memset (myDataPtr, 0, sizeof (AppletData));
135
CD_APPLET_RESET_DATA_BEGIN
136
cd_weather_reset_all_datas (myApplet);
137
CD_APPLET_RESET_DATA_END
140
/////////////////////
141
/// CUSTOM WIDGET ///
142
/////////////////////
143
void cd_weather_free_location_list (void)
145
if (s_pLocationsList == NULL)
147
g_list_foreach (s_pLocationsList, (GFunc) g_free, NULL);
148
g_list_free (s_pLocationsList);
149
s_pLocationsList = NULL;
152
static void _cd_weather_location_choosed (GtkMenuItem *pMenuItem, gchar *cLocationCode)
154
g_return_if_fail (cLocationCode != NULL);
156
//\____________________ On met a jour le panneau de conf.
157
GtkWidget *pCodeEntry = cairo_dock_get_widget_from_name ("Configuration", "location code");
158
gtk_entry_set_text (GTK_ENTRY (pCodeEntry), cLocationCode);
159
cd_weather_free_location_list ();
161
static void _cd_weather_search_for_location (GtkEntry *pEntry, CairoDockModuleInstance *myApplet)
163
const gchar *cLocationName = gtk_entry_get_text (pEntry);
164
if (cLocationName == NULL || *cLocationName == '\0')
167
gchar *cFilePath = cd_weather_get_location_data (cLocationName);
169
GError *erreur = NULL;
170
cd_weather_free_location_list ();
171
s_pLocationsList = cd_weather_parse_location_data (cFilePath, &erreur);
174
gchar *cIconPath = g_strdup_printf ("%s/broken.png", MY_APPLET_SHARE_DATA_DIR);
175
cairo_dock_show_temporary_dialog_with_icon (D_("I couldn't get the info\n Is connexion alive ?"),
182
g_error_free (erreur);
183
erreur = NULL; // on ne garde pas trace de l'erreur, c'est deja fait au (re)chargement.
185
else if (s_pLocationsList == NULL)
187
gchar *cIconPath = g_strdup_printf ("%s/broken.png", MY_APPLET_SHARE_DATA_DIR);
188
cairo_dock_show_temporary_dialog_with_icon (D_("I couldn't find this location"),
195
g_error_free (erreur);
200
GtkWidget *pMenu = gtk_menu_new ();
201
GString *sOneLocation = g_string_new ("");
202
GtkWidget *pMenuItem;
203
gchar *cLocationName, *cLocationCode;
205
for (list = s_pLocationsList; list != NULL; list = list->next)
208
cLocationCode = list->data;
210
cLocationName = list->data;
212
g_string_printf (sOneLocation, "%s : %s", cLocationName, cLocationCode);
213
pMenuItem = gtk_menu_item_new_with_label (sOneLocation->str);
214
gtk_menu_shell_append (GTK_MENU_SHELL (pMenu), pMenuItem);
215
g_signal_connect (G_OBJECT (pMenuItem), "activate", G_CALLBACK(_cd_weather_location_choosed), cLocationCode);
217
g_string_free (sOneLocation, TRUE);
219
gtk_widget_show_all (pMenu);
221
gtk_menu_popup (GTK_MENU (pMenu),
227
gtk_get_current_event_time ());
230
g_remove (cFilePath);
233
void cd_weather_load_custom_widget (CairoDockModuleInstance *myApplet, GKeyFile* pKeyFile)
235
g_print ("%s (%s)\n", __func__, myIcon->acName);
236
//\____________ On recupere le widget.
237
GtkWidget *pCodeEntry = cairo_dock_get_widget_from_name ("Configuration", "location code");
238
g_return_if_fail (pCodeEntry != NULL);
240
GtkWidget *pWidgetBox = gtk_widget_get_parent (pCodeEntry);
242
GtkWidget *pLabel = gtk_label_new (D_("Search for your location :"));
243
gtk_box_pack_start (GTK_BOX (pWidgetBox), pLabel, FALSE, FALSE, 0);
245
GtkWidget *pLocationEntry = gtk_entry_new ();
246
gtk_widget_set_tooltip_text (pLocationEntry, D_("Enter the name of your location and press Enter to choose amongst results."));
247
if (myData.cLocation != NULL)
248
gtk_entry_set_text (GTK_ENTRY (pLocationEntry), myData.cLocation);
249
gtk_box_pack_start (GTK_BOX (pWidgetBox), pLocationEntry, FALSE, FALSE, 0);
250
g_signal_connect (pLocationEntry, "activate", G_CALLBACK (_cd_weather_search_for_location), myApplet);