| 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 |
#include <stdlib.h> |
| 21 |
#include <string.h> |
| 22 |
#include <cairo-dock.h> |
| 23 |
#include <glib/gi18n.h> |
| 24 |
#include <glib/gstdio.h> |
| 25 |
|
| 26 |
#include "applet-struct.h" |
| 27 |
#include "applet-notifications.h" |
| 28 |
#include "applet-transitions.h" |
| 29 |
#include "applet-slider.h" |
| 30 |
|
| 31 |
static inline void _toggle_pause (GldiModuleInstance *myApplet) |
| 32 |
{ |
| 33 |
if (!myData.bPause) { |
| 34 |
myData.bPause = TRUE; // will stop the slider. |
| 35 |
} |
| 36 |
else { |
| 37 |
myData.bPause = FALSE; |
| 38 |
cd_slider_jump_to_next_slide (myApplet); // restart the slider |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
//\___________ Define here the action to be taken when the user left-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons. |
| 43 |
static void _open_current_slide (GldiModuleInstance *myApplet) |
| 44 |
{ |
| 45 |
if (myData.pElement != NULL && myData.pElement->data != NULL) |
| 46 |
{ |
| 47 |
SliderImage *pImage = myData.pElement->data; |
| 48 |
gchar *cImagePath = pImage->cPath; |
| 49 |
cd_debug ("opening %s ...", cImagePath); |
| 50 |
cairo_dock_fm_launch_uri (cImagePath); |
| 51 |
} |
| 52 |
} |
| 53 |
static void _open_current_folder (GldiModuleInstance *myApplet) |
| 54 |
{ |
| 55 |
if (myData.pElement != NULL && myData.pElement->data != NULL) |
| 56 |
{ |
| 57 |
SliderImage *pImage = myData.pElement->data; |
| 58 |
gchar *cDirPath = g_path_get_dirname (pImage->cPath); |
| 59 |
cd_debug ("opening folder %s ...", cDirPath); |
| 60 |
cairo_dock_fm_launch_uri (cDirPath); |
| 61 |
g_free (cDirPath); |
| 62 |
} |
| 63 |
} |
| 64 |
static void _cd_slider_action (SliderClickOption iAction, GldiModuleInstance *myApplet) |
| 65 |
{ |
| 66 |
if (myConfig.cDirectory == NULL) |
| 67 |
{ |
| 68 |
gldi_dialog_show_temporary_with_icon (D_("You need to define the images folder first."), myIcon, myContainer, 8000, MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE); |
| 69 |
return; |
| 70 |
} |
| 71 |
switch (iAction) |
| 72 |
{ |
| 73 |
case SLIDER_PAUSE: |
| 74 |
default: |
| 75 |
_toggle_pause (myApplet); |
| 76 |
break; |
| 77 |
case SLIDER_OPEN_IMAGE: |
| 78 |
_open_current_slide (myApplet); |
| 79 |
break; |
| 80 |
case SLIDER_OPEN_FOLDER: |
| 81 |
_open_current_folder (myApplet); |
| 82 |
break; |
| 83 |
} |
| 84 |
} |
| 85 |
CD_APPLET_ON_CLICK_BEGIN |
| 86 |
_cd_slider_action (myConfig.iClickOption, myApplet); |
| 87 |
CD_APPLET_ON_CLICK_END |
| 88 |
|
| 89 |
|
| 90 |
CD_APPLET_ON_MIDDLE_CLICK_BEGIN |
| 91 |
_cd_slider_action (myConfig.iMiddleClickOption, myApplet); |
| 92 |
CD_APPLET_ON_MIDDLE_CLICK_END |
| 93 |
|
| 94 |
|
| 95 |
static gboolean _cd_slider_scroll_delayed (GldiModuleInstance *myApplet) |
| 96 |
{ |
| 97 |
CD_APPLET_ENTER; |
| 98 |
if (myData.iNbScroll == 0) |
| 99 |
{ |
| 100 |
myData.iScrollID = 0; |
| 101 |
CD_APPLET_LEAVE (FALSE); |
| 102 |
} |
| 103 |
|
| 104 |
int i; |
| 105 |
if (myData.iNbScroll > 0) |
| 106 |
{ |
| 107 |
for (i = 0; i < myData.iNbScroll-1; i ++) // N-1 because we'll jump to next slide. |
| 108 |
{ |
| 109 |
if (myData.pElement == NULL) // debut |
| 110 |
myData.pElement = myData.pList; |
| 111 |
else |
| 112 |
myData.pElement = cairo_dock_get_next_element (myData.pElement, myData.pList); |
| 113 |
} |
| 114 |
} |
| 115 |
else if (myData.iNbScroll < 0) |
| 116 |
{ |
| 117 |
for (i = 0; i <= -myData.iNbScroll; i ++) // N+1 because we'll jump to next slide. |
| 118 |
{ |
| 119 |
if (myData.pElement == NULL) // debut |
| 120 |
myData.pElement = myData.pList; |
| 121 |
else |
| 122 |
myData.pElement = cairo_dock_get_previous_element (myData.pElement, myData.pList); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
myData.iNbScroll = 0; |
| 127 |
myData.iScrollID = 0; |
| 128 |
cd_slider_jump_to_next_slide (myApplet); |
| 129 |
CD_APPLET_LEAVE (FALSE); |
| 130 |
} |
| 131 |
CD_APPLET_ON_SCROLL_BEGIN |
| 132 |
if (myData.iScrollID != 0) |
| 133 |
g_source_remove (myData.iScrollID); |
| 134 |
|
| 135 |
if (CD_APPLET_SCROLL_DOWN) |
| 136 |
{ |
| 137 |
myData.iNbScroll ++; |
| 138 |
} |
| 139 |
else if (CD_APPLET_SCROLL_UP) |
| 140 |
{ |
| 141 |
myData.iNbScroll --; |
| 142 |
} |
| 143 |
|
| 144 |
myData.iScrollID = g_timeout_add (100, (GSourceFunc) _cd_slider_scroll_delayed, myApplet); |
| 145 |
CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS); |
| 146 |
CD_APPLET_ON_SCROLL_END |
| 147 |
|
| 148 |
|
| 149 |
//\___________ Define here the entries you want to add to the menu when the user right-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons. The menu where you can add your entries is available throught the macro CD_APPLET_MY_MENU; you can add sub-menu to it if you want. |
| 150 |
static void _free_app (gpointer *app) |
| 151 |
{ |
| 152 |
g_free (app[1]); |
| 153 |
g_free (app); |
| 154 |
} |
| 155 |
void cd_slider_free_apps_list (GldiModuleInstance *myApplet) |
| 156 |
{ |
| 157 |
if (myData.pAppList != NULL) |
| 158 |
{ |
| 159 |
g_list_foreach (myData.pAppList, (GFunc) _free_app, NULL); |
| 160 |
g_list_free (myData.pAppList); |
| 161 |
myData.pAppList = NULL; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
static void _cd_slider_toogle_pause (GtkMenuItem *menu_item, GldiModuleInstance *myApplet) |
| 166 |
{ |
| 167 |
CD_APPLET_ENTER; |
| 168 |
_toggle_pause (myApplet); |
| 169 |
CD_APPLET_LEAVE(); |
| 170 |
} |
| 171 |
static void _cd_slider_open_selected (GtkMenuItem *menu_item, GldiModuleInstance *myApplet) |
| 172 |
{ |
| 173 |
CD_APPLET_ENTER; |
| 174 |
cairo_dock_fm_launch_uri (myData.cSelectedImagePath); |
| 175 |
CD_APPLET_LEAVE(); |
| 176 |
} |
| 177 |
static void _cd_slider_launch_with (GtkMenuItem *pMenuItem, gpointer *app) |
| 178 |
{ |
| 179 |
GldiModuleInstance *myApplet = app[0]; |
| 180 |
gchar *cExec = app[1]; |
| 181 |
cairo_dock_launch_command_printf ("%s \"%s\"", NULL, cExec, myData.cSelectedImagePath); // en esperant que l'appli gere les URI. |
| 182 |
} |
| 183 |
static void _cd_slider_run_dir (GtkMenuItem *menu_item, GldiModuleInstance *myApplet) |
| 184 |
{ |
| 185 |
CD_APPLET_ENTER; |
| 186 |
if (myData.cSelectedImagePath == NULL) |
| 187 |
{ |
| 188 |
cairo_dock_fm_launch_uri (myConfig.cDirectory); |
| 189 |
} |
| 190 |
else |
| 191 |
{ |
| 192 |
gchar *cDirPath = g_path_get_dirname (myData.cSelectedImagePath); |
| 193 |
cairo_dock_fm_launch_uri (cDirPath); |
| 194 |
g_free (cDirPath); |
| 195 |
} |
| 196 |
CD_APPLET_LEAVE(); |
| 197 |
} |
| 198 |
static void _cd_slider_refresh_images_list (GtkMenuItem *menu_item, GldiModuleInstance *myApplet) |
| 199 |
{ |
| 200 |
CD_APPLET_ENTER; |
| 201 |
cd_slider_stop (myApplet); |
| 202 |
|
| 203 |
cd_slider_start (myApplet, FALSE); // FALSE <=> immediately |
| 204 |
CD_APPLET_LEAVE(); |
| 205 |
} |
| 206 |
CD_APPLET_ON_BUILD_MENU_BEGIN |
| 207 |
// get the current image selected at the moment of the click. |
| 208 |
g_free (myData.cSelectedImagePath); |
| 209 |
if (myData.pElement != NULL && myData.pElement->data != NULL) |
| 210 |
{ |
| 211 |
SliderImage *pImage = myData.pElement->data; |
| 212 |
myData.cSelectedImagePath = g_strdup (pImage->cPath); |
| 213 |
} |
| 214 |
else |
| 215 |
myData.cSelectedImagePath = NULL; |
| 216 |
|
| 217 |
gchar *cLabel; |
| 218 |
if (myConfig.iClickOption != SLIDER_PAUSE) |
| 219 |
{ |
| 220 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK (myData.bPause ? D_("Play") : D_("Pause"), myData.bPause ? GLDI_ICON_NAME_MEDIA_PLAY : GLDI_ICON_NAME_MEDIA_PAUSE, _cd_slider_toogle_pause, CD_APPLET_MY_MENU); |
| 221 |
} |
| 222 |
|
| 223 |
if (myData.cSelectedImagePath != NULL) |
| 224 |
{ |
| 225 |
if (myConfig.iClickOption != SLIDER_OPEN_IMAGE) |
| 226 |
{ |
| 227 |
if (myConfig.iMiddleClickOption == SLIDER_OPEN_IMAGE) |
| 228 |
cLabel = g_strdup_printf ("%s (%s)", D_("Open current image"), D_("middle-click")); |
| 229 |
else |
| 230 |
cLabel = g_strdup (D_("Open current image")); |
| 231 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, GLDI_ICON_NAME_OPEN, _cd_slider_open_selected, CD_APPLET_MY_MENU); |
| 232 |
g_free (cLabel); |
| 233 |
} |
| 234 |
|
| 235 |
GList *pApps = cairo_dock_fm_list_apps_for_file (myData.cSelectedImagePath); |
| 236 |
if (pApps != NULL) |
| 237 |
{ |
| 238 |
GtkWidget *pSubMenu = CD_APPLET_ADD_SUB_MENU_WITH_IMAGE (D_("Open with"), CD_APPLET_MY_MENU, GLDI_ICON_NAME_OPEN); |
| 239 |
|
| 240 |
cd_slider_free_apps_list (myApplet); |
| 241 |
|
| 242 |
gint iDesiredIconSize = cairo_dock_search_icon_size (GTK_ICON_SIZE_LARGE_TOOLBAR); // 24px |
| 243 |
GList *a; |
| 244 |
gchar **pAppInfo; |
| 245 |
gchar *cIconPath; |
| 246 |
gpointer *app; |
| 247 |
for (a = pApps; a != NULL; a = a->next) |
| 248 |
{ |
| 249 |
pAppInfo = a->data; |
| 250 |
|
| 251 |
app = g_new0 (gpointer, 2); |
| 252 |
app[0] = myApplet; |
| 253 |
app[1] = g_strdup (pAppInfo[1]); |
| 254 |
//g_print (" + %s (%s ; %s)\n", pAppInfo[0], pAppInfo[1], pAppInfo[2]); |
| 255 |
myData.pAppList = g_list_prepend (myData.pAppList, app); |
| 256 |
|
| 257 |
if (pAppInfo[2] != NULL) |
| 258 |
cIconPath = cairo_dock_search_icon_s_path (pAppInfo[2], iDesiredIconSize); |
| 259 |
else |
| 260 |
cIconPath = NULL; |
| 261 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (pAppInfo[0], cIconPath, _cd_slider_launch_with, pSubMenu, app); |
| 262 |
g_free (cIconPath); |
| 263 |
g_strfreev (pAppInfo); |
| 264 |
} |
| 265 |
g_list_free (pApps); |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
if (myConfig.iMiddleClickOption == SLIDER_OPEN_FOLDER) |
| 270 |
cLabel = g_strdup_printf ("%s (%s)", D_("Browse images folder"), D_("middle-click")); |
| 271 |
else |
| 272 |
cLabel = g_strdup (D_("Browse images folder")); |
| 273 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, GLDI_ICON_NAME_DIRECTORY, _cd_slider_run_dir, CD_APPLET_MY_MENU); |
| 274 |
|
| 275 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Refresh images list"), GLDI_ICON_NAME_REFRESH, _cd_slider_refresh_images_list, CD_APPLET_MY_MENU); |
| 276 |
|
| 277 |
g_free (cLabel); |
| 278 |
CD_APPLET_ON_BUILD_MENU_END |
| 279 |
|
| 280 |
|
| 281 |
CD_APPLET_ON_UPDATE_ICON_BEGIN |
| 282 |
if (cd_slider_next_slide_is_scheduled (myApplet) || gldi_task_is_running (myData.pMeasureImage)) // on est en attente d'une image, on quitte la boucle tout de suite. |
| 283 |
CD_APPLET_STOP_UPDATE_ICON; |
| 284 |
|
| 285 |
gboolean bContinueTransition = FALSE; |
| 286 |
switch (myData.iAnimation) |
| 287 |
{ |
| 288 |
case SLIDER_FADE : |
| 289 |
bContinueTransition = cd_slider_fade (myApplet); |
| 290 |
break ; |
| 291 |
case SLIDER_BLANK_FADE : |
| 292 |
bContinueTransition = cd_slider_blank_fade (myApplet); |
| 293 |
break ; |
| 294 |
case SLIDER_FADE_IN_OUT : |
| 295 |
bContinueTransition = cd_slider_fade_in_out (myApplet); |
| 296 |
break ; |
| 297 |
case SLIDER_SIDE_KICK : |
| 298 |
bContinueTransition = cd_slider_side_kick (myApplet); |
| 299 |
break ; |
| 300 |
case SLIDER_DIAPORAMA : |
| 301 |
bContinueTransition = cd_slider_diaporama (myApplet); |
| 302 |
break ; |
| 303 |
case SLIDER_GROW_UP : |
| 304 |
bContinueTransition = cd_slider_grow_up (myApplet); |
| 305 |
break ; |
| 306 |
case SLIDER_SHRINK_DOWN : |
| 307 |
bContinueTransition = cd_slider_shrink_down (myApplet); |
| 308 |
break ; |
| 309 |
case SLIDER_CUBE : |
| 310 |
bContinueTransition = cd_slider_cube (myApplet); |
| 311 |
break ; |
| 312 |
default : |
| 313 |
CD_APPLET_STOP_UPDATE_ICON; |
| 314 |
} |
| 315 |
|
| 316 |
if (! bContinueTransition) // la transition est finie, on dessine une derniere fois, on se place en attente de l'image suivante et on quitte la boucle. |
| 317 |
{ |
| 318 |
cd_slider_schedule_next_slide (myApplet); |
| 319 |
CD_APPLET_PAUSE_UPDATE_ICON; |
| 320 |
} |
| 321 |
CD_APPLET_ON_UPDATE_ICON_END |