~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-updates

« back to all changes in this revision

Viewing changes to shortcuts/src/applet-load-icons.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
#include <string.h>
 
29
#include <math.h>
 
30
 
 
31
#include <cairo-dock.h>
 
32
 
 
33
#include "applet-struct.h"
 
34
#include "applet-bookmarks.h"
 
35
#include "applet-disk-usage.h"
 
36
#include "applet-load-icons.h"
 
37
 
 
38
 
 
39
static void cd_shortcuts_on_change_drives (CairoDockFMEventType iEventType, const gchar *cURI, CairoDockModuleInstance *myApplet)
 
40
{
 
41
        cd_shortcuts_stop_disk_periodic_task (myApplet);
 
42
        
 
43
        cairo_dock_fm_manage_event_on_file (iEventType, cURI, myIcon, 6);
 
44
        
 
45
        //\________________ On met a jour les signets qui pointeraient sur un repertoire du point de montage nouvellement (de)monte.
 
46
        GList *ic;
 
47
        Icon *icon;
 
48
        gboolean bIsMounted;
 
49
        gchar *cTargetURI = cairo_dock_fm_is_mounted (cURI, &bIsMounted);
 
50
        if (cTargetURI == NULL)  // version bourrinne.
 
51
        {
 
52
                cd_shortcuts_on_change_bookmarks (CAIRO_DOCK_FILE_MODIFIED, NULL, myApplet);  // NULL <=> on recharge tout.
 
53
        }
 
54
        else  // version optimisee.
 
55
        {
 
56
                for (ic = (myDock ? myIcon->pSubDock->icons : myDesklet->icons); ic != NULL; ic = ic->next)
 
57
                {
 
58
                        icon = ic->data;
 
59
                        if (icon->iType == 10)
 
60
                        {
 
61
                                if (strncmp (cTargetURI, icon->cBaseURI, strlen (cTargetURI)) == 0)
 
62
                                {
 
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;
 
65
                                        int iVolumeID = 0;
 
66
                                        gboolean bIsDirectory = FALSE;
 
67
                                        double fOrder;
 
68
                                        if (cairo_dock_fm_get_file_info (icon->cBaseURI, &cName, &cRealURI, &cIconName, &bIsDirectory, &iVolumeID, &fOrder, mySystem.iFileSortType))
 
69
                                        {
 
70
                                                g_print (" -> %s (%d)\n", cIconName, bIsMounted);
 
71
                                                g_free (icon->acName);
 
72
                                                if (bIsMounted || cIconName == NULL)
 
73
                                                        icon->acName = cName;
 
74
                                                else
 
75
                                                {
 
76
                                                        icon->acName = g_strdup_printf ("%s\n[%s]", cName, D_("Unmounted"));
 
77
                                                        g_free (cName);
 
78
                                                }
 
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));
 
85
                                        }
 
86
                                }
 
87
                        }
 
88
                }
 
89
                g_free (cTargetURI);
 
90
        }
 
91
        
 
92
        cd_shortcuts_launch_disk_periodic_task (myApplet);
 
93
}
 
94
static void cd_shortcuts_on_change_network (CairoDockFMEventType iEventType, const gchar *cURI, CairoDockModuleInstance *myApplet)
 
95
{
 
96
        cairo_dock_fm_manage_event_on_file (iEventType, cURI, myIcon, 8);
 
97
}
 
98
 
 
99
 
 
100
static GList * _load_icons (CairoDockModuleInstance *myApplet)
 
101
{
 
102
        GList *pIconList = NULL;
 
103
        gchar *cFullURI = NULL;
 
104
        
 
105
        if (myConfig.bListDrives)
 
106
        {
 
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)
 
110
                {
 
111
                        cd_warning ("couldn't detect any drives");  // on decide de poursuivre malgre tout, pour les signets.
 
112
                }
 
113
                
 
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;
 
117
        }
 
118
        
 
119
        if (myConfig.bListNetwork)
 
120
        {
 
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);
 
123
                
 
124
                if (myConfig.bUseSeparator && pIconList2 != NULL && pIconList != NULL)
 
125
                {
 
126
                        Icon *pSeparatorIcon = g_new0 (Icon, 1);
 
127
                        pSeparatorIcon->iType = 7;
 
128
                        pIconList = g_list_append (pIconList, pSeparatorIcon);
 
129
                }
 
130
                
 
131
                pIconList = g_list_concat (pIconList, pIconList2);
 
132
                
 
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;
 
136
        }
 
137
                
 
138
        if (myConfig.bListBookmarks)
 
139
        {
 
140
                gchar *cBookmarkFilePath = g_strdup_printf ("%s/.gtk-bookmarks", g_getenv ("HOME"));
 
141
                if (! g_file_test (cBookmarkFilePath, G_FILE_TEST_EXISTS))
 
142
                {
 
143
                        FILE *f = fopen (cBookmarkFilePath, "a");
 
144
                        fclose (f);
 
145
                }
 
146
                
 
147
                GList *pIconList2 = cd_shortcuts_list_bookmarks (cBookmarkFilePath);
 
148
                
 
149
                if (myConfig.bUseSeparator && pIconList2 != NULL && pIconList != NULL)
 
150
                {
 
151
                        Icon *pSeparatorIcon = g_new0 (Icon, 1);
 
152
                        pSeparatorIcon->iType = 9;
 
153
                        pIconList = g_list_append (pIconList, pSeparatorIcon);
 
154
                }
 
155
                
 
156
                pIconList = g_list_concat (pIconList, pIconList2);
 
157
                
 
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");
 
160
                
 
161
                myData.cBookmarksURI = cBookmarkFilePath;
 
162
        }
 
163
        
 
164
        return pIconList;
 
165
}
 
166
 
 
167
 
 
168
void cd_shortcuts_get_shortcuts_data (CairoDockModuleInstance *myApplet)
 
169
{
 
170
        myData.pIconList = _load_icons (myApplet);
 
171
}
 
172
 
 
173
 
 
174
gboolean cd_shortcuts_build_shortcuts_from_data (CairoDockModuleInstance *myApplet)
 
175
{
 
176
        g_return_val_if_fail (myIcon != NULL, FALSE);  // paranoia
 
177
        /*if (myIcon == NULL)
 
178
        {
 
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;
 
183
                return FALSE;
 
184
        }*/
 
185
        
 
186
        //\_______________________ On efface l'ancienne liste.
 
187
        CD_APPLET_DELETE_MY_ICONS_LIST;
 
188
        
 
189
        //\_______________________ On charge la nouvelle liste.
 
190
        CD_APPLET_LOAD_MY_ICONS_LIST (myData.pIconList, myConfig.cRenderer, "Tree", NULL);
 
191
        myData.pIconList = NULL;
 
192
        
 
193
        //\_______________________ On lance la tache de mesure des disques.
 
194
        cd_shortcuts_launch_disk_periodic_task (myApplet);
 
195
        
 
196
        return TRUE;
 
197
}
 
198