[Goodies-commits] r2786 - in xfce4-places-plugin/branches/umount: . panel-plugin
Diego Ongaro
ongardie at xfce.org
Sun May 27 10:44:44 CEST 2007
Author: ongardie
Date: 2007-05-27 08:44:44 +0000 (Sun, 27 May 2007)
New Revision: 2786
Modified:
xfce4-places-plugin/branches/umount/ChangeLog
xfce4-places-plugin/branches/umount/panel-plugin/model.h
xfce4-places-plugin/branches/umount/panel-plugin/model_system.c
xfce4-places-plugin/branches/umount/panel-plugin/model_user.c
xfce4-places-plugin/branches/umount/panel-plugin/model_volumes.c
xfce4-places-plugin/branches/umount/panel-plugin/view.c
Log:
2007-05-27 Diego Ongaro <ongardie at gmail.com>
* unmount branch: added "actions" to bookmarks.
added unmount/mount actions to volumes.
Modified: xfce4-places-plugin/branches/umount/ChangeLog
===================================================================
--- xfce4-places-plugin/branches/umount/ChangeLog 2007-05-27 05:11:25 UTC (rev 2785)
+++ xfce4-places-plugin/branches/umount/ChangeLog 2007-05-27 08:44:44 UTC (rev 2786)
@@ -1,3 +1,8 @@
+2007-05-27 Diego Ongaro <ongardie at gmail.com>
+
+ * unmount branch: added "actions" to bookmarks.
+ added unmount/mount actions to volumes.
+
2007-05-22 Diego Ongaro <ongardie at gmail.com>
* Changed to lazily adding menu separators to avoid extra
Modified: xfce4-places-plugin/branches/umount/panel-plugin/model.h
===================================================================
--- xfce4-places-plugin/branches/umount/panel-plugin/model.h 2007-05-27 05:11:25 UTC (rev 2785)
+++ xfce4-places-plugin/branches/umount/panel-plugin/model.h 2007-05-27 08:44:44 UTC (rev 2786)
@@ -33,8 +33,16 @@
typedef struct
{
+ gchar *label;
+ gpointer pass_thru;
+ void (*action) (gpointer);
+} BookmarkAction;
+#define places_bookmark_action_call(act) (act->action(act->pass_thru))
+
+typedef struct
+{
gpointer pass_thru;
- void (*item) (gpointer, const gchar*, const gchar*, const gchar*);
+ void (*item) (gpointer, const gchar*, const gchar*, const gchar*, GSList *actions);
void (*separator) (gpointer);
} BookmarksVisitor;
Modified: xfce4-places-plugin/branches/umount/panel-plugin/model_system.c
===================================================================
--- xfce4-places-plugin/branches/umount/panel-plugin/model_system.c 2007-05-27 05:11:25 UTC (rev 2785)
+++ xfce4-places-plugin/branches/umount/panel-plugin/model_system.c 2007-05-27 08:44:44 UTC (rev 2786)
@@ -113,7 +113,7 @@
for(k=0; k < b->bookmarks->len; k++){
bi = g_ptr_array_index(b->bookmarks, k);
if(bi->show)
- visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon);
+ visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon, NULL);
}
}
Modified: xfce4-places-plugin/branches/umount/panel-plugin/model_user.c
===================================================================
--- xfce4-places-plugin/branches/umount/panel-plugin/model_user.c 2007-05-27 05:11:25 UTC (rev 2785)
+++ xfce4-places-plugin/branches/umount/panel-plugin/model_user.c 2007-05-27 08:44:44 UTC (rev 2786)
@@ -175,7 +175,7 @@
for(k=0; k < b->bookmarks->len; k++){
bi = g_ptr_array_index(b->bookmarks, k);
if(bi->show)
- visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon);
+ visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon, NULL);
}
}
Modified: xfce4-places-plugin/branches/umount/panel-plugin/model_volumes.c
===================================================================
--- xfce4-places-plugin/branches/umount/panel-plugin/model_volumes.c 2007-05-27 05:11:25 UTC (rev 2785)
+++ xfce4-places-plugin/branches/umount/panel-plugin/model_volumes.c 2007-05-27 08:44:44 UTC (rev 2786)
@@ -55,6 +55,7 @@
BookmarkInfo *bi;
GList *volumes;
guint k;
+ b->changed = TRUE;
if(places_bookmarks_volumes_show_volume(volume)){
@@ -71,7 +72,6 @@
volumes = g_list_prepend(NULL, volume);
places_bookmarks_volumes_add(b, volumes);
g_list_free(volumes);
- b->changed = TRUE;
}else{
DBG("volume already in array");
}
@@ -87,8 +87,6 @@
g_object_unref(bi->data);
bi->data = NULL;
g_free(bi);
-
- b->changed = TRUE;
}
}
}
@@ -152,8 +150,7 @@
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) &&
+ return thunar_vfs_volume_is_removable(volume) &&
thunar_vfs_volume_is_present(volume);
}
@@ -252,14 +249,61 @@
}
void
+places_bookmarks_volumes_unmount(gpointer _volume)
+{
+ ThunarVfsVolume *volume = THUNAR_VFS_VOLUME(_volume);
+ if(thunar_vfs_volume_is_mounted(volume))
+ thunar_vfs_volume_unmount(volume, NULL, NULL);
+}
+
+void
+places_bookmarks_volumes_mount(gpointer _volume)
+{
+ ThunarVfsVolume *volume = THUNAR_VFS_VOLUME(_volume);
+ if(!thunar_vfs_volume_is_mounted(volume))
+ thunar_vfs_volume_mount(volume, NULL, NULL);
+}
+
+
+void
places_bookmarks_volumes_visit(BookmarksVolumes *b, BookmarksVisitor *visitor)
{
guint k;
BookmarkInfo *bi;
-
+ GSList *actions;
+ ThunarVfsVolume *volume;
+ gchar *uri;
+
for(k=0; k < b->bookmarks->len; k++){
bi = g_ptr_array_index(b->bookmarks, k);
- visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon);
+ volume = THUNAR_VFS_VOLUME(bi->data);
+ actions = NULL;
+
+ if(thunar_vfs_volume_is_mounted(volume)){
+
+ BookmarkAction *unmount = g_new0(BookmarkAction, 1);
+ if(thunar_vfs_volume_is_disc(volume))
+ unmount->label = _("Eject Volume");
+ else
+ unmount->label = _("Unmount Volume");
+ unmount->action = places_bookmarks_volumes_unmount;
+ unmount->pass_thru = volume;
+ actions = g_slist_prepend(actions, unmount);
+
+ uri = bi->uri;
+ }else{
+
+ BookmarkAction *mount = g_new0(BookmarkAction, 1);
+ mount->label = _("Mount Volume");
+ mount->action = places_bookmarks_volumes_mount;
+ mount->pass_thru = volume;
+ actions = g_slist_prepend(actions, mount);
+
+ uri = NULL;
+ }
+
+ visitor->item(visitor->pass_thru, bi->label, uri, bi->icon, actions);
+ // visitor is in charge of freeing actions if not NULL
}
}
Modified: xfce4-places-plugin/branches/umount/panel-plugin/view.c
===================================================================
--- xfce4-places-plugin/branches/umount/panel-plugin/view.c 2007-05-27 05:11:25 UTC (rev 2785)
+++ xfce4-places-plugin/branches/umount/panel-plugin/view.c 2007-05-27 08:44:44 UTC (rev 2786)
@@ -63,7 +63,6 @@
gboolean *push_in,
PlacesData*);
static void places_view_cb_menu_deact(PlacesData*, GtkWidget *menu);
-static void places_view_cb_menu_item_open(GtkWidget *item, const gchar *uri);
// - Button
static gboolean places_view_cb_button_pressed(PlacesData*, GdkEventButton *);
@@ -76,7 +75,7 @@
// Model Visitor Callbacks
static void places_view_add_menu_item(gpointer _places_data,
- const gchar *label, const gchar *uri, const gchar *icon);
+ const gchar *label, const gchar *uri, const gchar *icon, GSList *actions);
static void places_view_lazy_add_menu_sep(gpointer _places_data);
@@ -482,12 +481,6 @@
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pd->view_button), FALSE);
}
-static void
-places_view_cb_menu_item_open(GtkWidget *widget, const gchar* uri)
-{
- places_load_thunar(uri);
-}
-
// Button
static gboolean
places_view_cb_button_pressed(PlacesData *pd, GdkEventButton *evt)
@@ -526,12 +519,65 @@
/********** Model Visitor Callbacks **********/
+void
+places_view_cb_menu_item_context_act(GtkWidget *item, PlacesData *pd)
+{ // TODO: move this
+ // we want the menu gone - now - since it prevents mouse grabs
+ places_view_destroy_menu(pd);
+ g_main_context_iteration(NULL, FALSE);
+
+ BookmarkAction *action = (BookmarkAction*) g_object_get_data(G_OBJECT(item), "action");
+ places_bookmark_action_call(action);
+}
+
+gboolean
+places_view_cb_menu_item_press(GtkWidget *menu_item, GdkEventButton *event, PlacesData *pd)
+{ // TODO: move this
+
+ if(event->button == 1){
+ const gchar *uri = (const gchar*) g_object_get_data(G_OBJECT(menu_item), "uri");
+ if(uri != NULL){
+ places_load_thunar(uri);
+ }
+
+ return TRUE;
+ }
+
+ if(event->button == 3){
+
+ DBG("menu item pressed");
+ GSList *actions = (GSList*) g_object_get_data(G_OBJECT(menu_item), "actions");
+ if(actions != NULL){
+
+ GtkWidget *context = gtk_menu_new();
+ gtk_widget_show(context);
+ while(actions != NULL){
+ BookmarkAction *action = (BookmarkAction*) actions->data;
+ GtkWidget *context_item = gtk_menu_item_new_with_label(action->label);
+ g_object_set_data(G_OBJECT(context_item), "action", action);
+ gtk_widget_show(context_item);
+ g_signal_connect(context_item, "activate",
+ G_CALLBACK(places_view_cb_menu_item_context_act), pd);
+ gtk_menu_shell_append(GTK_MENU_SHELL(context), context_item);
+ actions = actions->next;
+ }
+ gtk_menu_popup(GTK_MENU(context), NULL, NULL,
+ NULL, NULL,
+ event->button, event->time);
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
static void
-places_view_add_menu_item(gpointer _pd, const gchar *label, const gchar *uri, const gchar *icon)
+places_view_add_menu_item(gpointer _pd, const gchar *label, const gchar *uri, const gchar *icon, GSList *actions)
{
g_assert(_pd != NULL);
g_return_if_fail(label != NULL && label != "");
- g_return_if_fail(uri != NULL && uri != "");
PlacesData *pd = (PlacesData*) _pd;
@@ -553,8 +599,18 @@
}
}
- g_signal_connect(item, "activate",
- G_CALLBACK(places_view_cb_menu_item_open), (gchar*) uri);
+ if(uri != NULL)
+ g_object_set_data(G_OBJECT(item), "uri", (gchar*) uri);
+ else
+ gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(item)), FALSE);
+
+ if(actions != NULL)
+ g_object_set_data_full(G_OBJECT(item), "actions", actions, (GDestroyNotify) g_slist_free);
+
+ // TODO: click on button and release on menu item to open thunar no longer works (this is strictly button PRESS)
+ g_signal_connect(item, "button-press-event",
+ G_CALLBACK(places_view_cb_menu_item_press), pd);
+
gtk_menu_shell_append(GTK_MENU_SHELL(pd->view_menu), item);
}
More information about the Goodies-commits
mailing list