3
* Copyright (c) 2007 Diego Ongaro <ongardie@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Library General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
#include "model_volumes.h"
26
#include <thunar-vfs/thunar-vfs.h>
27
#include <libxfce4util/libxfce4util.h>
29
struct _BookmarksVolumes
33
ThunarVfsVolumeManager *volume_manager;
37
places_bookmarks_volumes_show_volume(ThunarVfsVolume *volume);
40
places_bookmarks_volumes_add(BookmarksVolumes *b, const GList *volumes);
43
/********** ThunarVFS Callbacks **********/
46
places_bookmarks_volumes_cb_changed(ThunarVfsVolume *volume,
49
DBG("volume changed");
50
// unfortunately there tends to be like 3 of these in a row
56
if(places_bookmarks_volumes_show_volume(volume)){
58
// make sure it's in the array
59
for(k = 0; k < b->bookmarks->len; k++){
60
bi = g_ptr_array_index(b->bookmarks, k);
61
if(THUNAR_VFS_VOLUME(bi->data) == volume)
65
if(k == b->bookmarks->len){ // it's not there
66
DBG("adding volume to array");
68
volumes = g_list_prepend(NULL, volume);
69
places_bookmarks_volumes_add(b, volumes);
73
DBG("volume already in array");
77
// make sure it's not in the array
78
for(k = 0; k < b->bookmarks->len; k++){
79
bi = g_ptr_array_index(b->bookmarks, k);
80
if(THUNAR_VFS_VOLUME(bi->data) == volume){ // it is there
81
DBG("dropping volume from array");
83
bi = g_ptr_array_remove_index(b->bookmarks, k);
84
g_object_unref(bi->data);
95
places_bookmarks_volumes_cb_added(ThunarVfsVolumeManager *volume_manager,
100
places_bookmarks_volumes_add(b, volumes);
105
places_bookmarks_volumes_cb_removed(ThunarVfsVolumeManager *volume_manager,
106
const GList *volumes,
109
DBG("volumes removed");
115
// step through existing bookmarks
116
for(k = 0; k < b->bookmarks->len; k++){
117
bi = g_ptr_array_index(b->bookmarks, k);
119
// step through removals
120
vol_iter = (GList*) volumes;
122
if(bi->data == vol_iter->data){ // it is there
124
// delete the bookmark
125
bi = g_ptr_array_remove_index(b->bookmarks, k);
126
DBG("Removing bookmark %s", bi->label);
128
if(bi->data != NULL){
129
g_object_unref(bi->data);
138
vol_iter = vol_iter->next;
145
places_bookmarks_volumes_show_volume(ThunarVfsVolume *volume){
147
DBG("Volume: %s [mounted=%x removable=%x present=%x]", thunar_vfs_volume_get_name(volume),
148
thunar_vfs_volume_is_mounted(volume),
149
thunar_vfs_volume_is_removable(volume),
150
thunar_vfs_volume_is_present(volume));
152
return thunar_vfs_volume_is_mounted(volume) &&
153
thunar_vfs_volume_is_removable(volume) &&
154
thunar_vfs_volume_is_present(volume);
159
places_bookmarks_volumes_add(BookmarksVolumes *b, const GList *volumes)
161
ThunarVfsVolume *volume;
163
GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
166
volume = THUNAR_VFS_VOLUME(volumes->data);
168
g_signal_connect (volume, "changed",
169
G_CALLBACK(places_bookmarks_volumes_cb_changed), b);
171
if(places_bookmarks_volumes_show_volume(volume)){
173
g_object_ref(volume);
175
bi = g_new0(BookmarkInfo, 1);
176
bi->label = g_strdup( thunar_vfs_volume_get_name(volume) );
177
bi->uri = thunar_vfs_path_dup_uri( thunar_vfs_volume_get_mount_point(volume) );
178
bi->icon = g_strdup( thunar_vfs_volume_lookup_icon_name(volume, icon_theme) );
179
bi->data = (gpointer) volume;
181
g_ptr_array_add(b->bookmarks, bi);
184
volumes = volumes->next;
191
places_bookmarks_volumes_init()
194
BookmarksVolumes *b = g_new0(BookmarksVolumes, 1);
198
b->bookmarks = g_ptr_array_new();
200
b->volume_manager = thunar_vfs_volume_manager_get_default();
202
places_bookmarks_volumes_add(b, thunar_vfs_volume_manager_get_volumes(b->volume_manager));
204
g_signal_connect (b->volume_manager, "volumes-added",
205
G_CALLBACK (places_bookmarks_volumes_cb_added), b);
207
g_signal_connect (b->volume_manager, "volumes-removed",
208
G_CALLBACK (places_bookmarks_volumes_cb_removed), b);
216
places_bookmarks_volumes_finalize(BookmarksVolumes *b)
221
for(k = 0; k < b->bookmarks->len; k++){
222
bi = g_ptr_array_remove_index(b->bookmarks, k);
223
if(bi->data != NULL){
224
g_object_unref(bi->data);
230
g_object_unref(b->volume_manager);
231
b->volume_manager = NULL;
232
thunar_vfs_shutdown();
234
g_ptr_array_free(b->bookmarks, TRUE);
241
places_bookmarks_volumes_changed(BookmarksVolumes *b)
252
places_bookmarks_volumes_visit(BookmarksVolumes *b, BookmarksVisitor *visitor)
257
for(k=0; k < b->bookmarks->len; k++){
258
bi = g_ptr_array_index(b->bookmarks, k);
259
visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon);
264
// vim: ai et tabstop=4