[Goodies-commits] r2661 - in xfce4-places-plugin/branches/volumes: . panel-plugin
Diego Ongaro
ongardie at xfce.org
Wed Apr 4 18:19:28 CEST 2007
Author: ongardie
Date: 2007-04-04 16:19:28 +0000 (Wed, 04 Apr 2007)
New Revision: 2661
Modified:
xfce4-places-plugin/branches/volumes/ChangeLog
xfce4-places-plugin/branches/volumes/panel-plugin/places.c
xfce4-places-plugin/branches/volumes/panel-plugin/places.h
Log:
2007-04-03 Diego Ongaro ongardie at gmail.com
* Improved managing volumes when a signal comes in
Modified: xfce4-places-plugin/branches/volumes/ChangeLog
===================================================================
--- xfce4-places-plugin/branches/volumes/ChangeLog 2007-04-03 21:52:28 UTC (rev 2660)
+++ xfce4-places-plugin/branches/volumes/ChangeLog 2007-04-04 16:19:28 UTC (rev 2661)
@@ -1,3 +1,7 @@
+2007-04-03 Diego Ongaro ongardie at gmail.com
+
+ * Improved managing volumes when a signal comes in
+
2007-04-02 Diego Ongaro ongardie at gmail.com
* Added volumes as items in menu
Modified: xfce4-places-plugin/branches/volumes/panel-plugin/places.c
===================================================================
--- xfce4-places-plugin/branches/volumes/panel-plugin/places.c 2007-04-03 21:52:28 UTC (rev 2660)
+++ xfce4-places-plugin/branches/volumes/panel-plugin/places.c 2007-04-04 16:19:28 UTC (rev 2661)
@@ -39,12 +39,13 @@
/********** Structs **********/
static BookmarkInfo*
-places_construct_BookmarkInfo(gchar* label, gchar* uri, gchar* icon)
+places_construct_BookmarkInfo(gchar *label, gchar *uri, gchar *icon)
{
BookmarkInfo *info = g_new(BookmarkInfo, 1);
info->label = label;
info->uri = uri;
info->icon = icon;
+ info->volume = NULL;
return info;
}
@@ -67,10 +68,10 @@
//xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
g_signal_connect (pd->bookmarks_volumes_manager, "volumes-added",
- G_CALLBACK (places_cb_volumes_changed), pd);
+ G_CALLBACK (places_cb_volumes_added), pd);
g_signal_connect (pd->bookmarks_volumes_manager, "volumes-removed",
- G_CALLBACK (places_cb_volumes_changed), pd);
+ G_CALLBACK (places_cb_volumes_removed), pd);
g_signal_connect (pd->panel_button, "button-release-event",
G_CALLBACK (places_cb_button_act), NULL);
@@ -94,7 +95,7 @@
{
DBG("initializing");
- pd->bookmarks_system = g_ptr_array_new();
+ pd->bookmarks_system = g_ptr_array_sized_new(4);
places_init_bookmarks_system(pd);
pd->bookmarks_volumes = g_ptr_array_new();
@@ -135,33 +136,59 @@
"/", "gnome-dev-harddisk"));
}
+static gboolean
+places_show_volume(ThunarVfsVolume *volume){
+
+ DBG("Volume: %s [mounted=%x removable=%x present=%x]", thunar_vfs_volume_get_name(volume),
+ thunar_vfs_volume_is_mounted(volume),
+ thunar_vfs_volume_is_removable(volume),
+ thunar_vfs_volume_is_present(volume));
+
+ return thunar_vfs_volume_is_mounted(volume) &&
+ thunar_vfs_volume_is_removable(volume) &&
+ thunar_vfs_volume_is_present(volume);
+}
+
+
static void
-places_init_bookmarks_volumes(PlacesData *pd)
+places_bookmarks_volumes_add(PlacesData *pd, const GList *volumes)
{
- DBG("initializing");
+ ThunarVfsVolume *volume;
- ThunarVfsVolume* volume;
- const GList* volumes = thunar_vfs_volume_manager_get_volumes(pd->bookmarks_volumes_manager);
-
while(volumes){
volume = THUNAR_VFS_VOLUME(volumes->data);
g_signal_connect (volume, "changed",
G_CALLBACK (places_cb_volume_changed), pd);
- if(thunar_vfs_volume_is_mounted(volume)){ // is this the criteria Thunar uses?
- g_ptr_array_add(pd->bookmarks_volumes, places_construct_BookmarkInfo(
- g_strdup(thunar_vfs_volume_get_name(volume)),
- thunar_vfs_path_dup_uri(thunar_vfs_volume_get_mount_point(volume)),
- g_strdup(thunar_vfs_volume_lookup_icon_name(volume, gtk_icon_theme_get_default()))));
+ if(places_show_volume(volume)){
+
+ g_object_ref(volume);
+
+ BookmarkInfo *bi = places_construct_BookmarkInfo(
+ g_strdup(thunar_vfs_volume_get_name(volume)),
+ thunar_vfs_path_dup_uri(thunar_vfs_volume_get_mount_point(volume)),
+ g_strdup(thunar_vfs_volume_lookup_icon_name(volume, gtk_icon_theme_get_default())));
+ bi->volume = volume;
+
+ g_ptr_array_add(pd->bookmarks_volumes, bi);
}
volumes = volumes->next;
}
-
+
}
+static void
+places_init_bookmarks_volumes(PlacesData *pd)
+{
+ DBG("initializing");
+ places_bookmarks_volumes_add(pd, thunar_vfs_volume_manager_get_volumes(pd->bookmarks_volumes_manager));
+
+}
+
+
static void
places_init_bookmarks_user(PlacesData *pd)
{
@@ -326,9 +353,9 @@
/********** Library **********/
static void
-places_load_thunar(const gchar * path)
+places_load_thunar(const gchar *path)
{
- gchar * cmd = g_strconcat("thunar ", path, NULL);
+ gchar *cmd = g_strconcat("thunar ", path, NULL);
xfce_exec(cmd, FALSE, FALSE, NULL);
g_free(cmd);
}
@@ -425,14 +452,85 @@
static void
places_cb_volume_changed(ThunarVfsVolume *volume, PlacesData *pd){
- pd->bookmarks_volumes_changed = TRUE;
+ DBG("volume changed");
+ // unfortunately there tends to be like 3 of these in a row
+
+ guint k;
+
+ if(places_show_volume(volume)){
+
+ // make sure it's in the array
+ for(k = 0; k < pd->bookmarks_volumes->len; k++){
+ BookmarkInfo *bi = g_ptr_array_index(pd->bookmarks_volumes, k);
+ if(bi->volume == volume)
+ break;
+ }
+
+ if(k == pd->bookmarks_volumes->len){ // it's not there
+ DBG("adding volume to array");
+
+ places_bookmarks_volumes_add(pd, g_list_prepend(NULL, volume));
+ pd->bookmarks_volumes_changed = TRUE;
+ }else{
+ DBG("volume already in array");
+ }
+
+ }else{
+ // make sure it's not in the array
+ for(k = 0; k < pd->bookmarks_volumes->len; k++){
+ BookmarkInfo *bi = g_ptr_array_index(pd->bookmarks_volumes, k);
+ if(bi->volume == volume){ // it is there
+ DBG("dropping volume from array");
+
+ bi = g_ptr_array_remove_index(pd->bookmarks_volumes, k);
+ g_object_unref(bi->volume);
+ g_free(bi);
+
+ pd->bookmarks_volumes_changed = TRUE;
+ }
+ }
+ }
}
static void
-places_cb_volumes_changed(ThunarVfsVolumeManager *volume_manager, ThunarVfsVolume *volume, PlacesData *pd){
+places_cb_volumes_added(ThunarVfsVolumeManager *volume_manager, const GList *volumes, PlacesData *pd){
+ DBG("volumes added");
+ places_bookmarks_volumes_add(pd, volumes);
pd->bookmarks_volumes_changed = TRUE;
}
+static void
+places_cb_volumes_removed(ThunarVfsVolumeManager *volume_manager, const GList *volumes, PlacesData *pd){
+ DBG("volumes removed");
+ GList *vol_iter;
+ guint k;
+
+ // step through existing bookmarks
+ for(k = 0; k < pd->bookmarks_volumes->len; k++){
+ BookmarkInfo *bi = g_ptr_array_index(pd->bookmarks_volumes, k);
+
+ // step through removals
+ vol_iter = (GList*) volumes;
+ while(vol_iter){
+ if(bi->volume == vol_iter->data){ // it is there
+
+ // delete the bookmark
+ bi = g_ptr_array_remove_index(pd->bookmarks_volumes, k);
+ DBG("Removing bookmark %s", bi->label);
+
+ if(bi->volume)
+ g_object_unref(bi->volume);
+ g_free(bi);
+
+ pd->bookmarks_volumes_changed = TRUE;
+ }
+
+ vol_iter = vol_iter->next;
+ }
+ }
+}
+
+
/********** Gtk Callbacks **********/
static gboolean
@@ -541,9 +639,6 @@
if(volumes_changed){
DBG("volumes changed");
- g_ptr_array_free(pd->bookmarks_volumes, TRUE);
- pd->bookmarks_volumes = g_ptr_array_new();
- places_init_bookmarks_volumes(pd);
pd->bookmarks_volumes_changed = FALSE;
}
@@ -598,10 +693,17 @@
{
DBG ("Free data: %s", PLUGIN_NAME);
g_assert(pd != NULL);
+ guint k;
thunar_vfs_shutdown();
g_object_unref(pd->bookmarks_volumes_manager);
+ for(k = 0; k < pd->bookmarks_volumes->len; k++){
+ BookmarkInfo *bi = g_ptr_array_remove_index(pd->bookmarks_volumes, k);
+ if(bi->volume)
+ g_object_unref(bi->volume);
+ }
+
g_ptr_array_free(pd->bookmarks_system, TRUE);
g_ptr_array_free(pd->bookmarks_volumes, TRUE);
g_ptr_array_free(pd->bookmarks_user, TRUE);
Modified: xfce4-places-plugin/branches/volumes/panel-plugin/places.h
===================================================================
--- xfce4-places-plugin/branches/volumes/panel-plugin/places.h 2007-04-03 21:52:28 UTC (rev 2660)
+++ xfce4-places-plugin/branches/volumes/panel-plugin/places.h 2007-04-04 16:19:28 UTC (rev 2661)
@@ -37,7 +37,7 @@
GPtrArray *bookmarks_system;
GPtrArray *bookmarks_volumes;
gboolean bookmarks_volumes_changed;
- ThunarVfsVolumeManager* bookmarks_volumes_manager;
+ ThunarVfsVolumeManager *bookmarks_volumes_manager;
GPtrArray *bookmarks_user;
gchar *bookmarks_user_filename;
time_t bookmarks_user_loaded;
@@ -47,12 +47,14 @@
typedef struct
{
- gchar *label;
- gchar *uri;
- gchar *icon;
+ gchar *label;
+ gchar *uri;
+ gchar *icon;
+ ThunarVfsVolume *volume;
} BookmarkInfo;
-static BookmarkInfo* places_construct_BookmarkInfo(gchar* label, gchar* uri, gchar* icon);
+static BookmarkInfo* places_construct_BookmarkInfo(gchar *label, gchar *uri, gchar *icon);
+
// Init
static void places_construct(XfcePanelPlugin*);
static void places_init_bookmarks(PlacesData*);
@@ -77,7 +79,8 @@
// ThunarVFS Callbacks
static void places_cb_volume_changed(ThunarVfsVolume*, PlacesData*);
-static void places_cb_volumes_changed(ThunarVfsVolumeManager*, ThunarVfsVolume*, PlacesData*);
+static void places_cb_volumes_added(ThunarVfsVolumeManager*, const GList*, PlacesData*);
+static void places_cb_volumes_removed(ThunarVfsVolumeManager*, const GList*, PlacesData*);
// GTK Callbacks
static gboolean places_cb_size_changed(XfcePanelPlugin*, int, PlacesData*);
More information about the Goodies-commits
mailing list