summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivemount/drive-button.c107
-rw-r--r--drivemount/drive-list.c148
-rw-r--r--drivemount/drive-list.h2
3 files changed, 166 insertions, 91 deletions
diff --git a/drivemount/drive-button.c b/drivemount/drive-button.c
index 2408eec7..b4fc6dc3 100644
--- a/drivemount/drive-button.c
+++ b/drivemount/drive-button.c
@@ -121,11 +121,12 @@ drive_button_new (GVolume *volume)
DriveButton *self;
self = g_object_new (DRIVE_TYPE_BUTTON, NULL);
- drive_button_set_volume (self, volume);
-
- g_signal_connect (gtk_icon_theme_get_default (),
- "changed", G_CALLBACK (drive_button_theme_change),
- self);
+ if (volume != NULL) {
+ drive_button_set_volume (self, volume);
+ g_signal_connect (gtk_icon_theme_get_default (),
+ "changed", G_CALLBACK (drive_button_theme_change),
+ self);
+ }
return (GtkWidget *)self;
}
@@ -137,10 +138,10 @@ drive_button_new_from_mount (GMount *mount)
self = g_object_new (DRIVE_TYPE_BUTTON, NULL);
drive_button_set_mount (self, mount);
-
+
g_signal_connect (gtk_icon_theme_get_default (),
"changed", G_CALLBACK (drive_button_theme_change),
- self);
+ self);
return (GtkWidget *)self;
}
@@ -336,48 +337,68 @@ drive_button_update (gpointer user_data)
self = DRIVE_BUTTON (user_data);
self->update_tag = 0;
+ /* base the icon size on the desired button size */
drive_button_reset_popup (self);
+ gtk_widget_get_preferred_size (GTK_WIDGET (self), NULL, &button_req);
+ gtk_widget_get_preferred_size (gtk_bin_get_child (GTK_BIN (self)), NULL, &image_req);
+ width = self->icon_size - (button_req.width - image_req.width);
+ height = self->icon_size - (button_req.height - image_req.height);
- /* if no volume or mount, unset image */
- if (!self->volume && !self->mount) {
- if (gtk_bin_get_child (GTK_BIN (self)) != NULL)
- gtk_image_set_from_pixbuf (GTK_IMAGE (gtk_bin_get_child (GTK_BIN (self))), NULL);
- return FALSE;
+ /* if no volume or mount, display general image */
+ if (!self->volume && !self->mount)
+ {
+ gtk_widget_set_tooltip_text (GTK_WIDGET (self), "nothing to mount");
+ screen = gtk_widget_get_screen (GTK_WIDGET (self));
+ icon_theme = gtk_icon_theme_get_for_screen (screen); //m
+ // note - other good icon would be emblem-unreadable
+ icon_info = gtk_icon_theme_lookup_icon (icon_theme, "media-floppy",
+ MIN (width, height),
+ GTK_ICON_LOOKUP_USE_BUILTIN);
+ if (icon_info) {
+ pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
+ g_object_unref (icon_info);
+ }
+
+ if (!pixbuf)
+ return FALSE;
+ scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
+ if (scaled) {
+ g_object_unref (pixbuf);
+ pixbuf = scaled;
+ }
+ if (gtk_bin_get_child (GTK_BIN (self)) != NULL)
+ gtk_image_set_from_pixbuf (GTK_IMAGE (gtk_bin_get_child (GTK_BIN (self))), pixbuf);
+ return FALSE;
}
if (self->volume) {
- GMount *mount;
+ GMount *mount;
- display_name = g_volume_get_name (self->volume);
- mount = g_volume_get_mount (self->volume);
+ display_name = g_volume_get_name (self->volume);
+ mount = g_volume_get_mount (self->volume);
- if (mount)
- tip = g_strdup_printf ("%s\n%s", display_name, _("(mounted)"));
- else
- tip = g_strdup_printf ("%s\n%s", display_name, _("(not mounted)"));
+ if (mount)
+ tip = g_strdup_printf ("%s\n%s", display_name, _("(mounted)"));
+ else
+ tip = g_strdup_printf ("%s\n%s", display_name, _("(not mounted)"));
- if (mount)
- icon = g_mount_get_icon (mount);
- else
- icon = g_volume_get_icon (self->volume);
+ if (mount)
+ icon = g_mount_get_icon (mount);
+ else
+ icon = g_volume_get_icon (self->volume);
- if (mount)
- g_object_unref (mount);
+ if (mount)
+ g_object_unref (mount);
} else {
- display_name = g_mount_get_name (self->mount);
- tip = g_strdup_printf ("%s\n%s", display_name, _("(mounted)"));
- icon = g_mount_get_icon (self->mount);
+ display_name = g_mount_get_name (self->mount);
+ tip = g_strdup_printf ("%s\n%s", display_name, _("(mounted)"));
+ icon = g_mount_get_icon (self->mount);
}
gtk_widget_set_tooltip_text (GTK_WIDGET (self), tip);
g_free (tip);
g_free (display_name);
- /* base the icon size on the desired button size */
- gtk_widget_get_preferred_size (GTK_WIDGET (self), NULL, &button_req);
- gtk_widget_get_preferred_size (gtk_bin_get_child (GTK_BIN (self)), NULL, &image_req);
- width = self->icon_size - (button_req.width - image_req.width);
- height = self->icon_size - (button_req.height - image_req.height);
screen = gtk_widget_get_screen (GTK_WIDGET (self));
icon_theme = gtk_icon_theme_get_for_screen (screen);
@@ -386,19 +407,19 @@ drive_button_update (gpointer user_data)
GTK_ICON_LOOKUP_USE_BUILTIN);
if (icon_info)
{
- pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
- g_object_unref (icon_info);
+ pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
+ g_object_unref (icon_info);
}
g_object_unref (icon);
if (!pixbuf)
- return FALSE;
+ return FALSE;
scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
if (scaled) {
- g_object_unref (pixbuf);
- pixbuf = scaled;
+ g_object_unref (pixbuf);
+ pixbuf = scaled;
}
gtk_image_set_from_pixbuf (GTK_IMAGE (gtk_bin_get_child (GTK_BIN (self))), pixbuf);
@@ -657,11 +678,11 @@ gvm_check_dvd_only (const char *udi, const char *device, const char *mount_point
{
char *path;
gboolean retval;
-
+
path = g_build_path (G_DIR_SEPARATOR_S, mount_point, "video_ts", NULL);
retval = g_file_test (path, G_FILE_TEST_IS_DIR);
g_free (path);
-
+
/* try the other name, if needed */
if (retval == FALSE) {
path = g_build_path (G_DIR_SEPARATOR_S, mount_point,
@@ -669,7 +690,7 @@ gvm_check_dvd_only (const char *udi, const char *device, const char *mount_point
retval = g_file_test (path, G_FILE_TEST_IS_DIR);
g_free (path);
}
-
+
return retval;
}
/* END copied from mate-volume-manager/src/manager.c */
@@ -691,7 +712,7 @@ check_dvd_video (DriveButton *self)
file = g_mount_get_root (mount);
g_object_unref (mount);
-
+
if (!file)
return FALSE;
@@ -880,6 +901,8 @@ drive_button_ensure_popup (DriveButton *self)
g_object_unref (mount);
}
} else {
+ if (!G_IS_MOUNT(self->volume))
+ return;
display_name = g_mount_get_name (self->mount);
ejectable = g_mount_can_eject (self->mount);
mounted = TRUE;
diff --git a/drivemount/drive-list.c b/drivemount/drive-list.c
index 78dd2e66..1ebe20fc 100644
--- a/drivemount/drive-list.c
+++ b/drivemount/drive-list.c
@@ -65,7 +65,7 @@ static void add_mount (DriveList *self,
GMount *mount);
static void remove_mount (DriveList *self,
GMount *mount);
-
+static void queue_relayout (DriveList *self);
static void
drive_list_class_init (DriveListClass *class)
{
@@ -92,8 +92,9 @@ drive_list_init (DriveList *self)
/* listen for drive connects/disconnects, and add
* currently connected drives. */
- if (!volume_monitor)
- volume_monitor = g_volume_monitor_get ();
+ self->count = 0;
+ if (!volume_monitor)
+ volume_monitor = g_volume_monitor_get ();
g_signal_connect_object (volume_monitor, "mount_added",
G_CALLBACK (mount_added), self, 0);
@@ -107,22 +108,34 @@ drive_list_init (DriveList *self)
G_CALLBACK (volume_changed), self, 0);
g_signal_connect_object (volume_monitor, "volume_removed",
G_CALLBACK (volume_removed), self, 0);
- volumes = g_volume_monitor_get_volumes (volume_monitor);
- for (tmp = volumes; tmp != NULL; tmp = tmp->next) {
- GVolume *volume = tmp->data;
-
- add_volume (self, volume);
- g_object_unref (volume);
- }
- g_list_free (volumes);
-
- mounts = g_volume_monitor_get_mounts (volume_monitor);
- for (tmp = mounts; tmp != NULL; tmp = tmp->next) {
- GMount *mount = tmp->data;
-
- add_mount (self, mount);
- g_object_unref (mount);
- }
+ volumes = g_volume_monitor_get_volumes (volume_monitor);
+ for (tmp = volumes; tmp != NULL; tmp = tmp->next)
+ {
+ GVolume *volume = tmp->data;
+ add_volume (self, volume);
+ g_object_unref (volume);
+ self->count++;
+ }
+ g_list_free (volumes);
+
+ mounts = g_volume_monitor_get_mounts (volume_monitor);
+ for (tmp = mounts; tmp != NULL; tmp = tmp->next)
+ {
+ GMount *mount = tmp->data;
+ add_mount (self, mount);
+ g_object_unref (mount);
+ self->count++;
+ }
+ self->dummy = drive_button_new (NULL);
+ gtk_button_set_relief (GTK_BUTTON (self->dummy), self->relief);
+ drive_button_set_size (DRIVE_BUTTON (self->dummy), self->icon_size);
+
+ if (self->count == 0)
+ {
+ gtk_container_add (GTK_CONTAINER (self), self->dummy);
+ queue_relayout (self);
+ drive_button_queue_update (self->dummy);
+ }
g_list_free (mounts);
}
@@ -163,7 +176,7 @@ drive_list_dispose (GObject *object)
G_CALLBACK (volume_removed), self);
if (self->layout_tag)
- g_source_remove (self->layout_tag);
+ g_source_remove (self->layout_tag);
self->layout_tag = 0;
if (G_OBJECT_CLASS (drive_list_parent_class)->dispose)
@@ -225,33 +238,56 @@ list_buttons (gpointer key, gpointer value, gpointer user_data)
static gboolean
relayout_buttons (gpointer data)
{
- DriveList *self = DRIVE_LIST (data);
- GList *sorted_buttons = NULL, *tmp;
- int i;
-
-
- self->layout_tag = 0;
- g_hash_table_foreach (self->volumes, list_buttons, &sorted_buttons);
- g_hash_table_foreach (self->mounts, list_buttons, &sorted_buttons);
-
- /* position buttons in the table according to their sorted order */
- for (tmp = sorted_buttons, i = 0; tmp != NULL; tmp = tmp->next, i++) {
- GtkWidget *button = tmp->data;
-
- if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
- gtk_container_child_set (GTK_CONTAINER (self), button,
- "left-attach", i + 1, "top-attach", 0,
- "width", 1, "height", 1,
- NULL);
- } else {
- gtk_container_child_set (GTK_CONTAINER (self), button,
- "left-attach", 0, "top-attach", i + 1,
- "width", 1, "height", 1,
- NULL);
+ DriveList *self = DRIVE_LIST (data);
+ GList *sorted_buttons = NULL, *tmp;
+ int i;
+
+
+ self->layout_tag = 0;
+ if ( self->count > 0 )
+ {
+ g_hash_table_foreach (self->volumes, list_buttons, &sorted_buttons);
+ g_hash_table_foreach (self->mounts, list_buttons, &sorted_buttons);
+
+ /* position buttons in the table according to their sorted order */
+ for (tmp = sorted_buttons, i = 0; tmp != NULL; tmp = tmp->next, i++)
+ {
+ GtkWidget *button = tmp->data;
+
+ if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
+ gtk_container_child_set (GTK_CONTAINER (self), button,
+ "left-attach", i + 1, "top-attach", 0,
+ "width", 1, "height", 1,
+ NULL);
+ }
+ else
+ {
+ gtk_container_child_set (GTK_CONTAINER (self), button,
+ "left-attach", 0, "top-attach", i + 1,
+ "width", 1, "height", 1,
+ NULL);
+ }
+ }
}
- }
-
- return FALSE;
+ else
+ {
+ gtk_widget_show (self->dummy);
+ if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gtk_container_child_set (GTK_CONTAINER (self), self->dummy,
+ "left-attach", i + 1, "top-attach", 0,
+ "width", 1, "height", 1,
+ NULL);
+ }
+ else
+ {
+ gtk_container_child_set (GTK_CONTAINER (self), self->dummy,
+ "left-attach", 0, "top-attach", i + 1,
+ "width", 1, "height", 1,
+ NULL);
+ }
+ }
+ return FALSE;
}
static void
@@ -268,7 +304,9 @@ mount_added (GVolumeMonitor *monitor,
DriveList *self)
{
add_mount (self, mount);
-
+ self->count++;
+ if (self->count == 1)
+ gtk_container_remove (GTK_CONTAINER (self), g_object_ref(self->dummy));
mount_changed (monitor, mount, self);
}
@@ -297,8 +335,12 @@ mount_removed (GVolumeMonitor *monitor,
DriveList *self)
{
remove_mount (self, mount);
-
mount_changed (monitor, mount, self);
+ self->count--;
+ if (self->count == 0) {
+ gtk_container_add (GTK_CONTAINER (self), self->dummy);
+ queue_relayout(self);
+ }
}
static void
@@ -307,6 +349,9 @@ volume_added (GVolumeMonitor *monitor,
DriveList *self)
{
add_volume (self, volume);
+ self->count++;
+ if (self->count == 1)
+ gtk_container_remove (GTK_CONTAINER (self), g_object_ref(self->dummy));
}
static void
@@ -327,6 +372,11 @@ volume_removed (GVolumeMonitor *monitor,
DriveList *self)
{
remove_volume (self, volume);
+ self->count--;
+ if (self->count == 0) {
+ gtk_container_add (GTK_CONTAINER (self), self->dummy);
+ queue_relayout(self);
+ }
}
static void
@@ -449,7 +499,7 @@ void
drive_list_set_transparent (DriveList *self, gboolean transparent)
{
GtkReliefStyle relief;
-
+
relief = transparent ? GTK_RELIEF_NONE : GTK_RELIEF_NORMAL;
if (relief == self->relief)
diff --git a/drivemount/drive-list.h b/drivemount/drive-list.h
index 690e0c4b..283aeb6d 100644
--- a/drivemount/drive-list.h
+++ b/drivemount/drive-list.h
@@ -46,6 +46,8 @@ struct _DriveList
GtkOrientation orientation;
guint layout_tag;
GtkReliefStyle relief;
+ GtkWidget *dummy;
+ gint count;
int icon_size;
};