~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to weather/src/applet-notifications.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
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.
 
11
*
 
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/>.
 
18
*/
 
19
 
 
20
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program,
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
#include <stdlib.h>
 
29
#include <string.h>
 
30
#include <glib/gstdio.h>
 
31
 
 
32
#include "applet-struct.h"
 
33
#include "applet-load-icons.h"
 
34
#include "applet-read-data.h"
 
35
#include "applet-notifications.h"
 
36
 
 
37
 
 
38
CD_APPLET_ON_CLICK_BEGIN
 
39
        if (myDock)
 
40
        {
 
41
                if (pClickedContainer == CAIRO_CONTAINER (myIcon->pSubDock) && pClickedIcon != NULL)  // on a clique sur une icone du sous-dock.
 
42
                {
 
43
                        cd_debug (" clic sur %s", pClickedIcon->acName);
 
44
                        cd_weather_show_forecast_dialog (myApplet, pClickedIcon);
 
45
                }
 
46
        }
 
47
        else if (myDesklet)  // on a clique sur une icone du desklet.
 
48
        {
 
49
                if (pClickedIcon != NULL)
 
50
                {
 
51
                        if (pClickedIcon == myIcon)
 
52
                                cd_weather_show_current_conditions_dialog (myApplet);
 
53
                        else
 
54
                                cd_weather_show_forecast_dialog (myApplet, pClickedIcon);
 
55
                }
 
56
        }
 
57
        else
 
58
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
59
CD_APPLET_ON_CLICK_END
 
60
 
 
61
 
 
62
static void _cd_weather_reload (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
63
{
 
64
        cairo_dock_stop_task (myData.pTask);
 
65
        
 
66
        cairo_dock_launch_task (myData.pTask);
 
67
}
 
68
CD_APPLET_ON_BUILD_MENU_BEGIN
 
69
        GtkWidget *pSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
 
70
                CD_APPLET_ADD_IN_MENU (D_("Reload now"), _cd_weather_reload, pSubMenu);
 
71
                CD_APPLET_ADD_ABOUT_IN_MENU (pSubMenu);
 
72
CD_APPLET_ON_BUILD_MENU_END
 
73
 
 
74
 
 
75
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
 
76
        if (pClickedIcon == myIcon)
 
77
        {
 
78
                cd_weather_show_current_conditions_dialog (myApplet);
 
79
        }
 
80
        else
 
81
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
82
CD_APPLET_ON_MIDDLE_CLICK_END
 
83
 
 
84
 
 
85
CairoDialog *cd_weather_show_forecast_dialog (CairoDockModuleInstance *myApplet, Icon *pIcon)
 
86
{
 
87
        if (myDock != NULL)
 
88
                g_list_foreach (myIcon->pSubDock->icons, (GFunc) cairo_dock_remove_dialog_if_any, NULL);
 
89
        else
 
90
                cairo_dock_remove_dialog_if_any (myIcon);
 
91
        
 
92
        if (myData.bErrorRetrievingData)
 
93
        {
 
94
                cairo_dock_show_temporary_dialog_with_icon (D_("No data were available\n is connection alive ?"), 
 
95
                        (myDock ? pIcon : myIcon),
 
96
                        (myDock ? CAIRO_CONTAINER (myIcon->pSubDock) : myContainer),
 
97
                        myConfig.cDialogDuration,
 
98
                        pIcon->acFileName);
 
99
                return NULL;
 
100
        }
 
101
        
 
102
        int iNumDay = ((int) pIcon->fOrder) / 2, iPart = ((int) pIcon->fOrder) - 2 * iNumDay;
 
103
        g_return_val_if_fail (iNumDay < myConfig.iNbDays && iPart < 2, NULL);
 
104
        
 
105
        Day *day = &myData.days[iNumDay];
 
106
        DayPart *part = &day->part[iPart];
 
107
        cairo_dock_show_temporary_dialog_with_icon ("%s (%s) : %s\n %s : %s%s -> %s%s\n %s : %s%%\n %s : %s%s (%s)\n %s : %s\n %s : %s  %s %s",
 
108
                (myDock ? pIcon : myIcon), (myDock ? CAIRO_CONTAINER (myIcon->pSubDock) : myContainer), myConfig.cDialogDuration, pIcon->acFileName,
 
109
                day->cName, day->cDate, part->cWeatherDescription,
 
110
                D_("Temperature"), _display (day->cTempMin), myData.units.cTemp, _display (day->cTempMax), myData.units.cTemp,
 
111
                D_("Precipitation Probability"), _display (part->cPrecipitationProba),
 
112
                D_("Wind"), _display (part->cWindSpeed), myData.units.cSpeed, _display (part->cWindDirection),
 
113
                D_("Humidity"), _display (part->cHumidity),  // unite ?...
 
114
                D_("SunRise"), _display (day->cSunRise), _("SunSet"), _display (day->cSunSet));
 
115
}
 
116
 
 
117
CairoDialog *cd_weather_show_current_conditions_dialog (CairoDockModuleInstance *myApplet)
 
118
{
 
119
        cairo_dock_remove_dialog_if_any (myIcon);
 
120
        if (cairo_dock_task_is_running (myData.pTask))
 
121
        {
 
122
                cairo_dock_show_temporary_dialog_with_icon (D_("Data are being fetched, please re-try in a few seconds."), 
 
123
                        myIcon,
 
124
                        myContainer,
 
125
                        3000,
 
126
                        myIcon->acFileName);
 
127
                
 
128
                return NULL;
 
129
        }
 
130
        if (myData.bErrorRetrievingData)
 
131
        {
 
132
                cairo_dock_show_temporary_dialog_with_icon (D_("No data were available\nRe-trying now ..."), 
 
133
                        myIcon,
 
134
                        myContainer,
 
135
                        3000,
 
136
                        myIcon->acFileName);
 
137
                _cd_weather_reload (NULL, myApplet);
 
138
                
 
139
                return NULL;
 
140
        }
 
141
        
 
142
        CurrentContitions *cc = &myData.currentConditions;
 
143
        cairo_dock_show_temporary_dialog_with_icon ("%s (%s, %s)\n %s : %s%s (%s : %s%s)\n %s : %s%s (%s)\n %s : %s - %s : %s%s\n %s : %s  %s %s",
 
144
                myIcon, myContainer, myConfig.cDialogDuration, myIcon->acFileName,
 
145
                cc->cWeatherDescription, cc->cDataAcquisitionDate, cc->cObservatory,
 
146
                D_("Temperature"), _display (cc->cTemp), myData.units.cTemp, D_("feeled"), _display (cc->cFeeledTemp), myData.units.cTemp,
 
147
                D_("Wind"), _display (cc->cWindSpeed), myData.units.cSpeed, _display (cc->cWindDirection),
 
148
                D_("Humidity"), _display (cc->cHumidity), D_("Pressure"), _display (cc->cPressure), myData.units.cPressure,  // unite ?...
 
149
                D_("SunRise"), _display (cc->cSunRise), D_("SunSet"), _display (cc->cSunSet));
 
150
}