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/>.
20
/*********************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
27
*********************************************************************************/
31
#include <cairo-dock.h>
33
#include "applet-struct.h"
34
#include "applet-bookmarks.h"
35
#include "applet-disk-usage.h"
36
#include "applet-load-icons.h"
39
static void cd_shortcuts_on_change_drives (CairoDockFMEventType iEventType, const gchar *cURI, CairoDockModuleInstance *myApplet)
41
cd_shortcuts_stop_disk_periodic_task (myApplet);
43
cairo_dock_fm_manage_event_on_file (iEventType, cURI, myIcon, 6);
45
//\________________ On met a jour les signets qui pointeraient sur un repertoire du point de montage nouvellement (de)monte.
49
gchar *cTargetURI = cairo_dock_fm_is_mounted (cURI, &bIsMounted);
50
if (cTargetURI == NULL) // version bourrinne.
52
cd_shortcuts_on_change_bookmarks (CAIRO_DOCK_FILE_MODIFIED, NULL, myApplet); // NULL <=> on recharge tout.
54
else // version optimisee.
56
for (ic = (myDock ? myIcon->pSubDock->icons : myDesklet->icons); ic != NULL; ic = ic->next)
59
if (icon->iType == 10)
61
if (strncmp (cTargetURI, icon->cBaseURI, strlen (cTargetURI)) == 0)
63
cd_message ("le signet %s est situe sur un point de montage ayant change (%s)", icon->cBaseURI, cTargetURI);
64
gchar *cName = NULL, *cRealURI = NULL, *cIconName = NULL, *cUserName = NULL;
66
gboolean bIsDirectory = FALSE;
68
if (cairo_dock_fm_get_file_info (icon->cBaseURI, &cName, &cRealURI, &cIconName, &bIsDirectory, &iVolumeID, &fOrder, mySystem.iFileSortType))
70
g_print (" -> %s (%d)\n", cIconName, bIsMounted);
71
g_free (icon->acName);
72
if (bIsMounted || cIconName == NULL)
76
icon->acName = g_strdup_printf ("%s\n[%s]", cName, D_("Unmounted"));
79
g_free (icon->acCommand);
80
icon->acCommand = cRealURI;
81
g_free (icon->acFileName);
82
icon->acFileName = cIconName;
83
icon->iVolumeID = iVolumeID;
84
cairo_dock_load_one_icon_from_scratch (icon, (myDock ? CAIRO_CONTAINER (myIcon->pSubDock) : myContainer));
92
cd_shortcuts_launch_disk_periodic_task (myApplet);
94
static void cd_shortcuts_on_change_network (CairoDockFMEventType iEventType, const gchar *cURI, CairoDockModuleInstance *myApplet)
96
cairo_dock_fm_manage_event_on_file (iEventType, cURI, myIcon, 8);
100
static GList * _load_icons (CairoDockModuleInstance *myApplet)
102
GList *pIconList = NULL;
103
gchar *cFullURI = NULL;
105
if (myConfig.bListDrives)
107
pIconList = cairo_dock_fm_list_directory (CAIRO_DOCK_FM_VFS_ROOT, CAIRO_DOCK_FM_SORT_BY_NAME, 6, FALSE, &cFullURI);
108
cd_message (" cFullURI : %s", cFullURI);
109
if (pIconList == NULL)
111
cd_warning ("couldn't detect any drives"); // on decide de poursuivre malgre tout, pour les signets.
114
if (! cairo_dock_fm_add_monitor_full (cFullURI, TRUE, NULL, (CairoDockFMMonitorCallback) cd_shortcuts_on_change_drives, myApplet))
115
cd_warning ("Shortcuts : can't monitor drives");
116
myData.cDisksURI = cFullURI;
119
if (myConfig.bListNetwork)
121
GList *pIconList2 = cairo_dock_fm_list_directory (CAIRO_DOCK_FM_NETWORK, CAIRO_DOCK_FM_SORT_BY_NAME, 8, FALSE, &cFullURI);
122
cd_message (" cFullURI : %s", cFullURI);
124
if (myConfig.bUseSeparator && pIconList2 != NULL && pIconList != NULL)
126
Icon *pSeparatorIcon = g_new0 (Icon, 1);
127
pSeparatorIcon->iType = 7;
128
pIconList = g_list_append (pIconList, pSeparatorIcon);
131
pIconList = g_list_concat (pIconList, pIconList2);
133
if (! cairo_dock_fm_add_monitor_full (cFullURI, TRUE, NULL, (CairoDockFMMonitorCallback) cd_shortcuts_on_change_network, myApplet))
134
cd_warning ("Shortcuts : can't monitor network");
135
myData.cNetworkURI = cFullURI;
138
if (myConfig.bListBookmarks)
140
gchar *cBookmarkFilePath = g_strdup_printf ("%s/.gtk-bookmarks", g_getenv ("HOME"));
141
if (! g_file_test (cBookmarkFilePath, G_FILE_TEST_EXISTS))
143
FILE *f = fopen (cBookmarkFilePath, "a");
147
GList *pIconList2 = cd_shortcuts_list_bookmarks (cBookmarkFilePath);
149
if (myConfig.bUseSeparator && pIconList2 != NULL && pIconList != NULL)
151
Icon *pSeparatorIcon = g_new0 (Icon, 1);
152
pSeparatorIcon->iType = 9;
153
pIconList = g_list_append (pIconList, pSeparatorIcon);
156
pIconList = g_list_concat (pIconList, pIconList2);
158
if (! cairo_dock_fm_add_monitor_full (cBookmarkFilePath, FALSE, NULL, (CairoDockFMMonitorCallback) cd_shortcuts_on_change_bookmarks, myApplet))
159
cd_warning ("Shortcuts : can't monitor bookmarks");
161
myData.cBookmarksURI = cBookmarkFilePath;
168
void cd_shortcuts_get_shortcuts_data (CairoDockModuleInstance *myApplet)
170
myData.pIconList = _load_icons (myApplet);
174
gboolean cd_shortcuts_build_shortcuts_from_data (CairoDockModuleInstance *myApplet)
176
g_return_val_if_fail (myIcon != NULL, FALSE); // paranoia
177
/*if (myIcon == NULL)
179
g_print ("annulation du chargement des raccourcis\n");
180
g_list_foreach (myData.pIconList, (GFunc) cairo_dock_free_icon, NULL);
181
g_list_free (myData.pIconList);
182
myData.pIconList = NULL;
186
//\_______________________ On efface l'ancienne liste.
187
CD_APPLET_DELETE_MY_ICONS_LIST;
189
//\_______________________ On charge la nouvelle liste.
190
CD_APPLET_LOAD_MY_ICONS_LIST (myData.pIconList, myConfig.cRenderer, "Tree", NULL);
191
myData.pIconList = NULL;
193
//\_______________________ On lance la tache de mesure des disques.
194
cd_shortcuts_launch_disk_periodic_task (myApplet);