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

« back to all changes in this revision

Viewing changes to Cairo-Penguin/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
 
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
 
 
32
#include "applet-struct.h"
 
33
#include "applet-animation.h"
 
34
#include "applet-notifications.h"
 
35
 
 
36
 
 
37
#define PENGUIN_NB_MESSAGES 13
 
38
static gchar *s_pMessage[PENGUIN_NB_MESSAGES] = {
 
39
        N_("Hey, I'm here !"),
 
40
        N_("Sorry but I'm busy right now."),
 
41
        N_("I don't have time to play with you, I have to dig and mine all these icons."),
 
42
        N_("Your dock is so messy ! Let me clean it."),
 
43
        N_("Admit my superiority on you as a penguin !"),
 
44
        N_("Wait, do you want to kill me ?!"),
 
45
        N_("Do you know how much painful it is to be clicked on ??"),
 
46
        N_("It's my dock now, mwahahaha !"),
 
47
        N_("I want to be a pirate !"),
 
48
        N_("You shall not pass !"),
 
49
        N_("I'm your father !"),
 
50
        N_("- What will we do tonight Cortex ?\n- The same thing as every nights, Minus. Try to take over the Dock !"),
 
51
        N_("For Aiur !")};
 
52
 
 
53
 
 
54
 
 
55
 
 
56
CD_APPLET_ON_CLICK_PROTO
 
57
{
 
58
        PenguinAnimation *pAnimation = penguin_get_current_animation ();
 
59
        if (penguin_is_resting (pAnimation))
 
60
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
61
        
 
62
        if ((myConfig.bFree && pClickedContainer == myContainer && myDock->iMouseX >  (myDock->iCurrentWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->iMouseX < (myDock->iCurrentWidth - myDock->fFlatDockWidth) / 2 +  myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon))
 
63
        {
 
64
                myData.iCurrentPositionY = (myConfig.bFree ? g_iDockLineWidth : 0);
 
65
                PenguinAnimation *pAnimation = penguin_get_current_animation ();
 
66
                int iNewAnimation;
 
67
                int iRandom = g_random_int_range (0, 4);
 
68
                if (iRandom == 0)  // 1 chance sur 4.
 
69
                        iNewAnimation = penguin_choose_go_up_animation (myApplet);
 
70
                else
 
71
                        iNewAnimation = penguin_choose_next_animation (myApplet, pAnimation);
 
72
                penguin_set_new_animation (myApplet, iNewAnimation);
 
73
                
 
74
                cairo_dock_stop_icon_animation (pClickedIcon);
 
75
CD_APPLET_ON_CLICK_END
 
76
 
 
77
 
 
78
static void _start_xpenguins (GtkMenuItem *menu_item, gpointer *data)
 
79
{
 
80
        cairo_dock_launch_command ("xpenguins");
 
81
}
 
82
static void _stop_xpenguins (GtkMenuItem *menu_item, gpointer *data)
 
83
{
 
84
        cairo_dock_launch_command ("xpenguins-stop");
 
85
}
 
86
static void _keep_quiet (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
87
{
 
88
        //\_______________ On arrete tout.
 
89
        if (myData.iSidRestartDelayed != 0)
 
90
        {
 
91
                g_source_remove (myData.iSidRestartDelayed);
 
92
                myData.iSidRestartDelayed = 0;
 
93
        }
 
94
        cairo_dock_remove_notification_func (CAIRO_DOCK_UPDATE_DOCK_SLOW, (CairoDockNotificationFunc) penguin_update_container, myApplet);
 
95
        cairo_dock_remove_notification_func (CAIRO_DOCK_UPDATE_ICON_SLOW, (CairoDockNotificationFunc) penguin_update_icon, myApplet);
 
96
        
 
97
        //\_______________ On met l'animation de repos et on la dessine.
 
98
        int iNewAnimation = penguin_choose_resting_animation (myApplet);
 
99
        penguin_set_new_animation (myApplet, iNewAnimation);
 
100
        myData.iCurrentPositionY = (myConfig.bFree ? g_iDockLineWidth : 0);
 
101
        if (myConfig.bFree)
 
102
        {
 
103
                penguin_move_in_dock (myApplet);
 
104
        }
 
105
        else
 
106
        {
 
107
                penguin_move_in_icon (myApplet);
 
108
        }
 
109
}
 
110
static void _wake_up (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
111
{
 
112
        penguin_start_animating (myApplet);
 
113
}
 
114
CD_APPLET_ON_BUILD_MENU_PROTO
 
115
{
 
116
        PenguinAnimation *pAnimation = penguin_get_current_animation ();
 
117
        if(pAnimation == NULL)
 
118
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
119
        
 
120
        if ((myConfig.bFree && pClickedContainer == myContainer && myDock->iMouseX >  (myDock->iCurrentWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->iMouseX < (myDock->iCurrentWidth - myDock->fFlatDockWidth) / 2 +  myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon))
 
121
        {
 
122
                if (pClickedIcon != myIcon && ! (CAIRO_DOCK_IS_APPLET (pClickedIcon) && pClickedIcon->pModuleInstance->pModule == myIcon->pModuleInstance->pModule))
 
123
                {
 
124
                        g_print ("%s\n", myApplet->cConfFilePath);
 
125
                        cairo_dock_notify (CAIRO_DOCK_BUILD_MENU, myIcon, myContainer, CD_APPLET_MY_MENU);
 
126
                        return CAIRO_DOCK_INTERCEPT_NOTIFICATION;
 
127
                }
 
128
                
 
129
                GtkWidget *pMenuItem, *image;
 
130
                
 
131
                CD_APPLET_ADD_SEPARATOR_IN_MENU (CD_APPLET_MY_MENU);
 
132
                
 
133
                GtkWidget *pModuleSubMenu = CD_APPLET_ADD_SUB_MENU (D_("Hey, you there !"), CD_APPLET_MY_MENU);
 
134
                //GtkWidget *pModuleSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
 
135
                if (penguin_is_resting (pAnimation))
 
136
                {
 
137
                        CD_APPLET_ADD_IN_MENU(D_("Wake up"), _wake_up, pModuleSubMenu);
 
138
                }
 
139
                else
 
140
                {
 
141
                        CD_APPLET_ADD_IN_MENU(D_("Keep quiet"), _keep_quiet, pModuleSubMenu);
 
142
                }
 
143
                
 
144
                CD_APPLET_ADD_IN_MENU(D_("Start XPenguins"), _start_xpenguins, pModuleSubMenu);
 
145
                CD_APPLET_ADD_IN_MENU(D_("Stop XPenguins"), _stop_xpenguins, pModuleSubMenu);
 
146
                CD_APPLET_ADD_ABOUT_IN_MENU (pModuleSubMenu);
 
147
CD_APPLET_ON_BUILD_MENU_END
 
148
 
 
149
 
 
150
gboolean CD_APPLET_ON_MIDDLE_CLICK_FUNC (CairoDockModuleInstance *myApplet, Icon *pClickedIcon, CairoContainer *pClickedContainer)
 
151
{
 
152
        PenguinAnimation *pAnimation = penguin_get_current_animation ();
 
153
        if(pAnimation == NULL)
 
154
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
155
        
 
156
        if ((myConfig.bFree && pClickedContainer == myContainer && myDock->iMouseX >  (myDock->iCurrentWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->iMouseX < (myDock->iCurrentWidth - myDock->fFlatDockWidth) / 2 +  myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon))
 
157
        {
 
158
                if (myData.pDialog != NULL)
 
159
                {
 
160
                        cairo_dock_dialog_unreference (myData.pDialog);
 
161
                        myData.pDialog = NULL;
 
162
                }
 
163
                PenguinAnimation *pAnimation = penguin_get_current_animation ();
 
164
                if (penguin_is_resting (pAnimation))
 
165
                {
 
166
                        Icon *pIcon = cairo_dock_get_pointed_icon (myDock->icons);
 
167
                        if (pIcon != NULL)
 
168
                                myData.pDialog = cairo_dock_show_temporary_dialog (D_("Zzzzz"), pIcon, myContainer, 2000);
 
169
                        else
 
170
                                myData.pDialog = cairo_dock_show_general_message (D_("Zzzzz"), 2000);
 
171
                }
 
172
                else if (! pAnimation->bEnding && myData.iSidRestartDelayed == 0)
 
173
                {
 
174
                        int iRandom = g_random_int_range (0, 5);  // [a;b[
 
175
                        if (iRandom == 0)  // 1 chance sur 5.
 
176
                        {
 
177
                                int iNewAnimation = penguin_choose_ending_animation (myApplet);
 
178
                                penguin_set_new_animation (myApplet, iNewAnimation);
 
179
                        }
 
180
                        else if (iRandom == 1 && ! myConfig.bFree)
 
181
                        {
 
182
                                CD_APPLET_ANIMATE_MY_ICON ("bounce", 3);
 
183
                                myData.pDialog = cairo_dock_show_temporary_dialog ("Olllééééé !", myIcon, myContainer, 2500);
 
184
                        }
 
185
                        else
 
186
                        {
 
187
                                iRandom = g_random_int_range (0, PENGUIN_NB_MESSAGES);  // [a;b[
 
188
                                Icon *pIcon = cairo_dock_get_pointed_icon (myDock->icons);
 
189
                                const gchar *cMessage = D_(s_pMessage[iRandom]);
 
190
                                int iDuration = 1000 + 25 * g_utf8_strlen (cMessage, -1);
 
191
                                if (pIcon != NULL)
 
192
                                        myData.pDialog = cairo_dock_show_temporary_dialog (cMessage, pIcon, myContainer, iDuration);
 
193
                                else
 
194
                                        myData.pDialog = cairo_dock_show_general_message (cMessage, iDuration);
 
195
                        }
 
196
                }
 
197
CD_APPLET_ON_MIDDLE_CLICK_END