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

« back to all changes in this revision

Viewing changes to mail/src/cd-mail-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
 
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
#include <glib/gi18n.h>
 
32
#include <time.h>
 
33
#include <math.h>
 
34
 
 
35
#include "cd-mail-applet-struct.h"
 
36
#include "cd-mail-applet-etpan.h"
 
37
#include "cd-mail-applet-notifications.h"
 
38
 
 
39
 
 
40
CD_APPLET_ON_CLICK_BEGIN
 
41
 
 
42
        if( myConfig.cMailApplication )
 
43
        {
 
44
                if (myIcon->Xid != 0)
 
45
                {
 
46
                        if (cairo_dock_get_current_active_window () == myIcon->Xid && myTaskBar.bMinimizeOnClick)
 
47
                                cairo_dock_minimize_xwindow (myIcon->Xid);
 
48
                        else
 
49
                                cairo_dock_show_xwindow (myIcon->Xid);
 
50
                }
 
51
                else
 
52
                {
 
53
                        gboolean r = cairo_dock_launch_command (myConfig.cMailApplication);
 
54
                        
 
55
                        if (!r)
 
56
                        {
 
57
                                cd_warning ("when couldn't execute '%s'", myConfig.cMailApplication);
 
58
                                cairo_dock_show_temporary_dialog (D_("A problem occured\nIf '%s' is not your usual mail application,\nyou can change it in the conf panel of this module"), myIcon, myContainer, 5000, myConfig.cMailApplication);
 
59
                        }
 
60
                }
 
61
        }
 
62
 
 
63
CD_APPLET_ON_CLICK_END
 
64
 
 
65
 
 
66
static void _cd_mail_force_update(CairoDockModuleInstance *myApplet)
 
67
{
 
68
        guint i;
 
69
        if (myData.pMailAccounts != NULL)
 
70
        {
 
71
                for (i = 0; i < myData.pMailAccounts->len; i ++)
 
72
                {
 
73
                        CDMailAccount *pMailAccount = g_ptr_array_index (myData.pMailAccounts, i);
 
74
                        if( pMailAccount )
 
75
                        {
 
76
                                cairo_dock_launch_task(pMailAccount->pAccountMailTimer);
 
77
                        }
 
78
                }
 
79
        }
 
80
}
 
81
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
 
82
 
 
83
    _cd_mail_force_update(myApplet);
 
84
 
 
85
CD_APPLET_ON_MIDDLE_CLICK_END
 
86
 
 
87
 
 
88
static void _cd_mail_update_account (GtkMenuItem *menu_item, CDMailAccount *pMailAccount)
 
89
{
 
90
        if( pMailAccount )
 
91
        {
 
92
                CairoDockModuleInstance *myApplet = pMailAccount->pAppletInstance;
 
93
                Icon *pIcon = (pMailAccount->icon ? pMailAccount->icon : myIcon);
 
94
                CairoContainer *pContainer = (pMailAccount->icon ? CD_APPLET_MY_ICONS_LIST_CONTAINER : myContainer);
 
95
                cairo_dock_set_quick_info (myDrawContext, "...", pIcon, cairo_dock_get_max_scale (pContainer));
 
96
                
 
97
                cairo_dock_launch_task(pMailAccount->pAccountMailTimer);
 
98
        }
 
99
}
 
100
static void _cd_mail_launch_mail_appli (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
101
{
 
102
        cairo_dock_launch_command (myConfig.cMailApplication);
 
103
}
 
104
CD_APPLET_ON_BUILD_MENU_BEGIN
 
105
        
 
106
        GtkWidget *pSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
 
107
    if(myData.pMailAccounts && myData.pMailAccounts->len > 0)
 
108
    {
 
109
        /* add a "update account" item for each mailbox */
 
110
        GtkWidget *pRefreshAccountSubMenu = CD_APPLET_ADD_SUB_MENU (D_("Refresh a mail account"), pSubMenu);
 
111
        
 
112
        guint i;
 
113
        for (i = 0; i < myData.pMailAccounts->len; i ++)
 
114
        {
 
115
                        CDMailAccount *pMailAccount = g_ptr_array_index (myData.pMailAccounts, i);
 
116
                        CD_APPLET_ADD_IN_MENU_WITH_DATA (pMailAccount->name, _cd_mail_update_account, pRefreshAccountSubMenu, pMailAccount);
 
117
        }
 
118
    }
 
119
        if (myConfig.cMailApplication)
 
120
        {
 
121
                gchar *cLabel = g_strdup_printf (D_("Launch %s"), myConfig.cMailApplication);
 
122
                CD_APPLET_ADD_IN_MENU (cLabel, _cd_mail_launch_mail_appli, pSubMenu);
 
123
                g_free (cLabel);
 
124
        }
 
125
        CD_APPLET_ADD_ABOUT_IN_MENU (pSubMenu);
 
126
 
 
127
CD_APPLET_ON_BUILD_MENU_END
 
128
 
 
129
 
 
130
CD_APPLET_ON_SCROLL_BEGIN
 
131
        if (myData.pMailAccounts == NULL)
 
132
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
133
 
 
134
        CDMailAccount *pMailAccount;
 
135
        guint i;
 
136
        for (i = 0; i < myData.pMailAccounts->len; i++)
 
137
        {
 
138
                pMailAccount = g_ptr_array_index (myData.pMailAccounts, i);
 
139
                if (pMailAccount->name && (myData.pMailAccounts->len == 1 || strcmp (pMailAccount->name, CD_APPLET_CLICKED_ICON->acName) == 0))
 
140
                        break ;
 
141
        }
 
142
        if (i == myData.pMailAccounts->len || pMailAccount == NULL)
 
143
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
144
        
 
145
        if (cairo_dock_task_is_running (pMailAccount->pAccountMailTimer))
 
146
        {
 
147
                g_print ("account is being checked, wait a second\n");
 
148
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
149
        }
 
150
        
 
151
        struct mail_flags *pFlags = NULL;
 
152
        mailmessage *pMessage = NULL;
 
153
        int r;
 
154
        GList *l;
 
155
        gchar *cMessage;
 
156
        for (l = pMailAccount->pUnseenMessageList; l != NULL; l = l->next)
 
157
        {
 
158
                cMessage = l->data;
 
159
                cairo_dock_remove_dialog_if_any (CD_APPLET_CLICKED_ICON);
 
160
                cairo_dock_show_temporary_dialog_with_icon (cMessage, CD_APPLET_CLICKED_ICON, CD_APPLET_CLICKED_CONTAINER, 10e3, "same icon");
 
161
                
 
162
                // on marque le message comme lu.
 
163
                ///r = mailmessage_get_flags (pMessage, &pFlags);
 
164
        }
 
165
        
 
166
CD_APPLET_ON_SCROLL_END
 
167
 
 
168
 
 
169
CD_APPLET_ON_UPDATE_ICON_BEGIN
 
170
        double fSpeedX, fSpeedY;
 
171
        if (myData.iNbUnreadMails == 0)
 
172
        {
 
173
                fSpeedX = 2.;
 
174
                fSpeedY = 2.;
 
175
        }
 
176
        else
 
177
        {
 
178
                fSpeedX = 2 * MIN (5., sqrt (myData.iNbUnreadMails));
 
179
                fSpeedY = fSpeedX/2;
 
180
        }
 
181
        if( myData.iNbUnreadMails > 0 || myData.current_rotX != 0 )  // mails non lus ou on finit la rotation en cours.
 
182
        {
 
183
                myData.current_rotX += fSpeedX;
 
184
        }
 
185
        if( myData.iNbUnreadMails > 0 || myData.current_rotY != 0 )  // mails non lus ou on finit la rotation en cours.
 
186
        {
 
187
                myData.current_rotY += fSpeedY;
 
188
        }
 
189
 
 
190
        if( myData.current_rotX>=360.f )
 
191
        {
 
192
                if (myData.iNbUnreadMails > 0)
 
193
                        myData.current_rotX -= 360.f;  // on se ramene juste dans [0;360[
 
194
                else
 
195
                        myData.current_rotX = 0;  // on s'arrete la.
 
196
        }
 
197
        if( myData.current_rotY>=360.f )
 
198
        {
 
199
                if (myData.iNbUnreadMails > 0)
 
200
                        myData.current_rotY -= 360.f;
 
201
                else
 
202
                        myData.current_rotY = 0;
 
203
        }
 
204
        
 
205
        cd_mail_render_3D_to_texture (myApplet);
 
206
 
 
207
        if( myData.iNbUnreadMails <= 0 && myData.current_rotX == 0 && myData.current_rotY == 0 )
 
208
        {
 
209
                CD_APPLET_STOP_UPDATE_ICON;
 
210
        }
 
211
CD_APPLET_ON_UPDATE_ICON_END