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/>.
23
#include "applet-struct.h"
24
#include "applet-animation.h"
25
#include "applet-notifications.h"
27
#define PENGUIN_NB_MESSAGES 13
28
static const gchar *s_pMessage[PENGUIN_NB_MESSAGES] = {
30
N_("Sorry but I'm busy right now."),
31
N_("I don't have time to play with you, I have to dig and mine all these icons."),
32
N_("Your dock is so messy! Let me clean it."),
33
N_("Admit my superiority on you as a penguin!"),
34
N_("Wait, do you want to kill me?!"),
35
N_("Do you know how painful it is to be clicked on??"),
36
N_("It's my dock now, mwahahaha!"),
37
N_("I want to be a pirate!"),
38
N_("You shall not pass!"),
39
N_("I'm your father!"),
40
N_("- Gee, Brain, what do you want to do tonight?\n- The same thing we do every night, Pinky : try to take over the Dock!"),
44
CD_APPLET_ON_CLICK_PROTO
46
PenguinAnimation *pAnimation = penguin_get_current_animation ();
47
if (penguin_is_resting (pAnimation))
48
return GLDI_NOTIFICATION_LET_PASS;
50
if ((myConfig.bFree && pClickedContainer == myContainer && myDock->container.iMouseX > (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->container.iMouseX < (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->container.iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->container.iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon))
52
myData.iCurrentPositionY = (myConfig.bFree ? myDocksParam.iDockLineWidth : 0);
53
PenguinAnimation *pAnimation = penguin_get_current_animation ();
55
int iRandom = g_random_int_range (0, 4);
56
if (iRandom == 0) // 1 chance sur 4.
57
iNewAnimation = penguin_choose_go_up_animation (myApplet);
59
iNewAnimation = penguin_choose_next_animation (myApplet, pAnimation);
60
penguin_set_new_animation (myApplet, iNewAnimation);
62
cairo_dock_redraw_container (myContainer); // si l'animation etait down, la nouvelle a pu nous placer ailleurs.
64
gldi_icon_stop_animation (pClickedIcon);
65
CD_APPLET_ON_CLICK_END
68
static void _start_xpenguins (GtkMenuItem *menu_item, gpointer *data)
70
cairo_dock_launch_command ("xpenguins");
72
static void _stop_xpenguins (GtkMenuItem *menu_item, gpointer *data)
74
cairo_dock_launch_command ("xpenguins-stop");
76
static void _keep_quiet (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
78
//\_______________ On arrete tout.
79
if (myData.iSidRestartDelayed != 0)
81
g_source_remove (myData.iSidRestartDelayed);
82
myData.iSidRestartDelayed = 0;
84
gldi_object_remove_notification (myContainer, NOTIFICATION_UPDATE_SLOW, (GldiNotificationFunc) penguin_update_container, myApplet);
85
gldi_object_remove_notification (myIcon, NOTIFICATION_UPDATE_ICON_SLOW, (GldiNotificationFunc) penguin_update_icon, myApplet);
87
//\_______________ On met l'animation de repos et on la dessine.
88
int iNewAnimation = penguin_choose_resting_animation (myApplet);
89
penguin_set_new_animation (myApplet, iNewAnimation);
90
myData.iCurrentPositionY = (myConfig.bFree ? myDocksParam.iDockLineWidth : 0);
93
penguin_move_in_dock (myApplet);
97
penguin_move_in_icon (myApplet);
100
static void _wake_up (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
102
penguin_start_animating (myApplet);
104
gboolean on_build_container_menu (GldiModuleInstance *myApplet, Icon *pClickedIcon, GldiContainer *pClickedContainer, GtkWidget *pAppletMenu, gboolean *bDiscardMenu)
106
PenguinAnimation *pAnimation = penguin_get_current_animation ();
107
if(pAnimation == NULL)
108
CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS);
110
if ((myConfig.bFree && pClickedContainer == myContainer && myDock->container.iMouseX > (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->container.iMouseX < (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->container.iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->container.iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon))
112
if (pClickedIcon != myIcon)
114
gldi_object_notify (myContainer, NOTIFICATION_BUILD_CONTAINER_MENU, myIcon, myContainer, pAppletMenu, bDiscardMenu);
115
gldi_object_notify (myContainer, NOTIFICATION_BUILD_ICON_MENU, myIcon, myContainer, pAppletMenu);
116
return GLDI_NOTIFICATION_INTERCEPT;
119
return GLDI_NOTIFICATION_LET_PASS;
122
static gboolean s_bXPenguinsChecked = FALSE, s_bHasXPenguins = FALSE;
124
CD_APPLET_ON_BUILD_MENU_BEGIN
125
PenguinAnimation *pAnimation = penguin_get_current_animation ();
126
if(pAnimation == NULL)
127
CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS);
129
if ((myConfig.bFree && pClickedContainer == myContainer && myDock->container.iMouseX > (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->container.iMouseX < (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->container.iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->container.iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon))
131
if (pClickedIcon != myIcon)
133
return GLDI_NOTIFICATION_INTERCEPT;
137
if (penguin_is_resting (pAnimation))
139
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Wake up"), MY_APPLET_SHARE_DATA_DIR"/icon.png", _wake_up, CD_APPLET_MY_MENU);
143
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Keep quiet"), MY_APPLET_SHARE_DATA_DIR"/icon.png",_keep_quiet, CD_APPLET_MY_MENU);
146
if (! s_bXPenguinsChecked)
148
s_bXPenguinsChecked = TRUE;
149
gchar *cResult = cairo_dock_launch_command_sync ("which xpenguins");
150
if (cResult != NULL && *cResult == '/')
151
s_bHasXPenguins = TRUE;
158
CD_APPLET_ADD_IN_MENU(D_("Start XPenguins"), _start_xpenguins, CD_APPLET_MY_MENU);
159
CD_APPLET_ADD_IN_MENU(D_("Stop XPenguins"), _stop_xpenguins, CD_APPLET_MY_MENU);
161
CD_APPLET_ON_BUILD_MENU_END
164
gboolean CD_APPLET_ON_MIDDLE_CLICK_FUNC (GldiModuleInstance *myApplet, Icon *pClickedIcon, GldiContainer *pClickedContainer)
166
PenguinAnimation *pAnimation = penguin_get_current_animation ();
167
if(pAnimation == NULL)
168
return GLDI_NOTIFICATION_LET_PASS;
170
if ((myConfig.bFree && pClickedContainer == myContainer && myDock->container.iMouseX > (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->container.iMouseX < (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->container.iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->container.iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon))
172
if (myData.pDialog != NULL)
174
gldi_object_unref (GLDI_OBJECT(myData.pDialog));
175
myData.pDialog = NULL;
177
PenguinAnimation *pAnimation = penguin_get_current_animation ();
178
if (penguin_is_resting (pAnimation))
180
Icon *pIcon = cairo_dock_get_pointed_icon (myDock->icons);
182
myData.pDialog = gldi_dialog_show_temporary (D_("Zzzzz"), pIcon, myContainer, 2000);
184
myData.pDialog = gldi_dialog_show_general_message (D_("Zzzzz"), 2000);
186
else if (! pAnimation->bEnding && myData.iSidRestartDelayed == 0)
188
int iRandom = g_random_int_range (0, 5); // [a;b[
189
if (iRandom == 0) // 1 chance sur 5.
191
int iNewAnimation = penguin_choose_ending_animation (myApplet);
192
penguin_set_new_animation (myApplet, iNewAnimation);
194
else if (iRandom == 1 && ! myConfig.bFree)
196
CD_APPLET_ANIMATE_MY_ICON ("bounce", 3);
197
myData.pDialog = gldi_dialog_show_temporary ("Olll����� !", myIcon, myContainer, 2500);
201
iRandom = g_random_int_range (0, PENGUIN_NB_MESSAGES); // [a;b[
202
Icon *pIcon = cairo_dock_get_pointed_icon (myDock->icons);
203
const gchar *cMessage = D_(s_pMessage[iRandom]);
204
int iDuration = 2000 + 25 * g_utf8_strlen (cMessage, -1);
206
myData.pDialog = gldi_dialog_show_temporary (cMessage, pIcon, myContainer, iDuration);
208
myData.pDialog = gldi_dialog_show_general_message (cMessage, iDuration);
211
CD_APPLET_ON_MIDDLE_CLICK_END
214
gboolean cd_on_dock_destroyed (GldiModuleInstance *myApplet, CairoDock *pDock)
216
gldi_object_delete (GLDI_OBJECT(myApplet));
217
return GLDI_NOTIFICATION_LET_PASS;