| 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 |
|
| 23 |
#include "applet-config.h" |
| 24 |
#include "applet-notifications.h" |
| 25 |
#include "applet-trashes-manager.h" |
| 26 |
#include "applet-struct.h" |
| 27 |
#include "applet-init.h" |
| 28 |
|
| 29 |
|
| 30 |
CD_APPLET_DEFINITION (N_("dustbin"), |
| 31 |
2, 2, 0, |
| 32 |
CAIRO_DOCK_CATEGORY_APPLET_FILES, |
| 33 |
N_("This applet manages the dustbin\n" |
| 34 |
"You can threw files and unmount disks by drag-and-dropping them on the icon.\n" |
| 35 |
"Middle-click on the icon will empty the dustbin."), |
| 36 |
"Fabounet (Fabrice Rey)") |
| 37 |
|
| 38 |
static void _get_theme (void) |
| 39 |
{ |
| 40 |
// get the user images first, as they overwrite the theme. |
| 41 |
if (myConfig.cEmptyUserImage != NULL) |
| 42 |
{ |
| 43 |
gchar *cPath = cairo_dock_search_icon_s_path (myConfig.cEmptyUserImage, CAIRO_DOCK_DEFAULT_ICON_SIZE); |
| 44 |
if (! g_file_test (cPath, G_FILE_TEST_EXISTS)) |
| 45 |
{ |
| 46 |
g_free (myConfig.cEmptyUserImage); |
| 47 |
myConfig.cEmptyUserImage = NULL; |
| 48 |
} |
| 49 |
g_free (cPath); |
| 50 |
} |
| 51 |
if (myConfig.cFullUserImage != NULL) |
| 52 |
{ |
| 53 |
gchar *cPath = cairo_dock_search_icon_s_path (myConfig.cFullUserImage, CAIRO_DOCK_DEFAULT_ICON_SIZE); |
| 54 |
if (! g_file_test (cPath, G_FILE_TEST_EXISTS)) |
| 55 |
{ |
| 56 |
g_free (myConfig.cFullUserImage); |
| 57 |
myConfig.cFullUserImage = NULL; |
| 58 |
} |
| 59 |
g_free (cPath); |
| 60 |
} |
| 61 |
// if a theme is defined, and user images are not defined, use the theme. |
| 62 |
if (myConfig.cThemePath != NULL) |
| 63 |
{ |
| 64 |
if (myConfig.cEmptyUserImage == NULL) |
| 65 |
{ |
| 66 |
myConfig.cEmptyUserImage = g_strdup_printf ("%s/%s", myConfig.cThemePath, "trashcan_empty.svg"); |
| 67 |
if (! g_file_test (myConfig.cEmptyUserImage, G_FILE_TEST_EXISTS)) |
| 68 |
{ |
| 69 |
g_free (myConfig.cEmptyUserImage); |
| 70 |
myConfig.cEmptyUserImage = g_strdup_printf ("%s/%s", myConfig.cThemePath, "trashcan_empty.png"); |
| 71 |
if (! g_file_test (myConfig.cEmptyUserImage, G_FILE_TEST_EXISTS)) // no svg nor png, use the default theme. |
| 72 |
{ |
| 73 |
g_free (myConfig.cEmptyUserImage); |
| 74 |
myConfig.cEmptyUserImage = g_strdup (MY_APPLET_SHARE_DATA_DIR"/themes/default/trashcan_empty.svg"); |
| 75 |
cd_warning ("using the default theme for Dustbin, as neither the user image (%s) nor the theme (%s) are valid", myConfig.cEmptyUserImage, myConfig.cThemePath); |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
if (myConfig.cFullUserImage == NULL) |
| 80 |
{ |
| 81 |
myConfig.cFullUserImage = g_strdup_printf ("%s/%s", myConfig.cThemePath, "trashcan_full.svg"); |
| 82 |
if (! g_file_test (myConfig.cFullUserImage, G_FILE_TEST_EXISTS)) |
| 83 |
{ |
| 84 |
g_free (myConfig.cFullUserImage); |
| 85 |
myConfig.cFullUserImage = g_strdup_printf ("%s/%s", myConfig.cThemePath, "trashcan_full.png"); |
| 86 |
if (! g_file_test (myConfig.cFullUserImage, G_FILE_TEST_EXISTS)) |
| 87 |
{ |
| 88 |
g_free (myConfig.cFullUserImage); |
| 89 |
myConfig.cFullUserImage = g_strdup (MY_APPLET_SHARE_DATA_DIR"/themes/default/trashcan_full.svg"); |
| 90 |
cd_warning ("using the default theme for Dustbin, as neither the user image (%s) nor the theme (%s) are valid", myConfig.cFullUserImage, myConfig.cThemePath); |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
CD_APPLET_INIT_BEGIN |
| 98 |
if (myDesklet) |
| 99 |
{ |
| 100 |
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); |
| 101 |
} |
| 102 |
|
| 103 |
//\_______________ On recupere les images du theme choisi. |
| 104 |
_get_theme (); |
| 105 |
|
| 106 |
//\_______________ On enregistre nos notifications. |
| 107 |
CD_APPLET_REGISTER_FOR_CLICK_EVENT; |
| 108 |
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT; |
| 109 |
CD_APPLET_REGISTER_FOR_DROP_DATA_EVENT; |
| 110 |
CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT; |
| 111 |
|
| 112 |
//\_______________ On demarre la surveillance de la poubelle. |
| 113 |
cd_dustbin_start (myApplet); |
| 114 |
CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cEmptyUserImage); |
| 115 |
|
| 116 |
CD_APPLET_INIT_END |
| 117 |
|
| 118 |
|
| 119 |
CD_APPLET_STOP_BEGIN |
| 120 |
//\_______________ On se desabonne de nos notifications. |
| 121 |
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT; |
| 122 |
CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT; |
| 123 |
CD_APPLET_UNREGISTER_FOR_DROP_DATA_EVENT; |
| 124 |
CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT; |
| 125 |
|
| 126 |
//\_______________ On stoppe la surveillance. |
| 127 |
cd_dustbin_stop (myApplet); |
| 128 |
|
| 129 |
CD_APPLET_STOP_END |
| 130 |
|
| 131 |
|
| 132 |
CD_APPLET_RELOAD_BEGIN |
| 133 |
//\_______________ On recharge les donnees qui ont pu changer. |
| 134 |
if (CD_APPLET_MY_CONFIG_CHANGED) |
| 135 |
{ |
| 136 |
if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED) // we are now in a desklet, set a renderer. |
| 137 |
{ |
| 138 |
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); |
| 139 |
} |
| 140 |
|
| 141 |
//\_______________ On stoppe la surveillance. |
| 142 |
cd_dustbin_stop (myApplet); |
| 143 |
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL); |
| 144 |
|
| 145 |
//\_______________ On la redemarre. |
| 146 |
_get_theme (); |
| 147 |
cd_dustbin_start (myApplet); |
| 148 |
|
| 149 |
CD_APPLET_SET_IMAGE_ON_MY_ICON (myData.bDisplayFullIcon ? myConfig.cFullUserImage: myConfig.cEmptyUserImage); |
| 150 |
} |
| 151 |
CD_APPLET_RELOAD_END |