[Goodies-commits] r2865 - xfce4-cddrive-plugin/trunk/panel-plugin
Sylvain Reynal
syl at xfce.org
Wed Jun 27 05:00:30 CEST 2007
Author: syl
Date: 2007-06-27 03:00:29 +0000 (Wed, 27 Jun 2007)
New Revision: 2865
Modified:
xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor-private.h
xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor.c
xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor.h
xfce4-cddrive-plugin/trunk/panel-plugin/cddrive.c
Log:
remove monitor callback enabling functions (used to avoid spurious clicks)
simply use gtk_widget_set_sensitive instead
Modified: xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor-private.h
===================================================================
--- xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor-private.h 2007-06-27 02:57:14 UTC (rev 2864)
+++ xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor-private.h 2007-06-27 03:00:29 UTC (rev 2865)
@@ -35,7 +35,6 @@
gpointer on_disc_inserted;
gpointer on_disc_removed;
gpointer on_disc_modified;
- gboolean callbacks_enabled;
gchar *dev; /* CD-ROM drive's device path */
gchar *udi; /* CD-ROM disc's UDI (NULL if none) */
Modified: xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor.c
===================================================================
--- xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor.c 2007-06-27 02:57:14 UTC (rev 2864)
+++ xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor.c 2007-06-27 03:00:29 UTC (rev 2865)
@@ -492,99 +492,34 @@
-gboolean
-cddrive_monitor_enable_callbacks (CddriveMonitor *monitor,
- gboolean enable,
- GError **error)
+static gboolean
+cddrive_monitor_enable_callbacks (CddriveMonitor *monitor, GError **error)
{
- DBusError derr;
-
g_assert (monitor != NULL);
- if (monitor->callbacks_enabled == enable)
- return TRUE;
-
- if (enable)
+ if (G_UNLIKELY (! libhal_ctx_set_device_added (monitor->ctx,
+ cddrive_monitor_hal_callback_device_added)))
{
- /*enable callbacks */
-
- if (G_UNLIKELY (! libhal_ctx_set_device_added (monitor->ctx,
- cddrive_monitor_hal_callback_device_added)))
- {
- cddrive_set_error (error,
- CDDRIVE_ERROR_FAILED,
- _("Failed to register drive addition callback."));
- return FALSE;
- }
-
- if (G_UNLIKELY (! libhal_ctx_set_device_removed (monitor->ctx,
- cddrive_monitor_hal_callback_device_removed)))
- {
- cddrive_set_error (error,
- CDDRIVE_ERROR_FAILED,
- _("Failed to register drive removal callback."));
- return FALSE;
- }
-
- if (monitor->udi != NULL)
- {
- dbus_error_init (&derr);
- if (! libhal_device_remove_property_watch (monitor->ctx, monitor->udi, &derr))
- {
- cddrive_store_dbus_error (error, CDDRIVE_ERROR_FAILED, &derr);
- dbus_error_free (&derr);
- return FALSE;
- }
- }
+ cddrive_set_error (error,
+ CDDRIVE_ERROR_FAILED,
+ _("Failed to register drive addition callback."));
+ return FALSE;
}
- else
- {
- /* disable callbacks */
-
- if (G_UNLIKELY (! libhal_ctx_set_device_added (monitor->ctx, NULL)))
- {
- cddrive_set_error (error,
- CDDRIVE_ERROR_FAILED,
- _("Failed to unregister drive addition callback."));
- return FALSE;
- }
- if (G_UNLIKELY (! libhal_ctx_set_device_removed (monitor->ctx, NULL)))
- {
- cddrive_set_error (error,
- CDDRIVE_ERROR_FAILED,
- _("Failed to unregister drive removal callback."));
- return FALSE;
- }
-
- if (monitor->udi != NULL)
- {
- dbus_error_init (&derr);
- if (! libhal_device_remove_property_watch (monitor->ctx, monitor->udi, &derr))
- {
- cddrive_store_dbus_error (error, CDDRIVE_ERROR_FAILED, &derr);
- dbus_error_free (&derr);
- return FALSE;
- }
- }
+ if (G_UNLIKELY (! libhal_ctx_set_device_removed (monitor->ctx,
+ cddrive_monitor_hal_callback_device_removed)))
+ {
+ cddrive_set_error (error,
+ CDDRIVE_ERROR_FAILED,
+ _("Failed to register drive removal callback."));
+ return FALSE;
}
-
- monitor->callbacks_enabled = enable;
+
return TRUE;
}
-gboolean
-cddrive_monitor_callbacks_enabled (CddriveMonitor *monitor)
-{
- g_assert (monitor != NULL);
-
- return monitor->callbacks_enabled;
-}
-
-
-
static void
cddrive_monitor_set_is_ejectable (CddriveMonitor *monitor, GError **error)
{
@@ -665,7 +600,6 @@
res->on_disc_inserted = on_disc_inserted_callback;
res->on_disc_removed = on_disc_removed_callback;
res->on_disc_modified = on_disc_modified_callback;
- res->callbacks_enabled = FALSE; /* set to FALSE to enable callbacks effectively below */
res->udi = NULL;
res->is_ejectable = FALSE;
res->audio_title = NULL;
@@ -692,7 +626,7 @@
return NULL;
}
- if (G_UNLIKELY (! cddrive_monitor_enable_callbacks (res, TRUE, error)))
+ if (G_UNLIKELY (! cddrive_monitor_enable_callbacks (res, error)))
{
cddrive_monitor_free (res);
return NULL;
Modified: xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor.h
===================================================================
--- xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor.h 2007-06-27 02:57:14 UTC (rev 2864)
+++ xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-monitor.h 2007-06-27 03:00:29 UTC (rev 2865)
@@ -84,21 +84,6 @@
-/* Enable/disable callbacks on changes of drive state.
- Return FALSE if the operation failed, TRUE otherwise. */
-gboolean
-cddrive_monitor_enable_callbacks (CddriveMonitor *monitor,
- gboolean enable,
- GError **error);
-
-
-
-/* Are the callbacks enabled ? */
-gboolean
-cddrive_monitor_callbacks_enabled (CddriveMonitor *monitor);
-
-
-
/* Open the tray of the CD-ROM drive */
void
cddrive_monitor_eject (CddriveMonitor *monitor, GError **error);
Modified: xfce4-cddrive-plugin/trunk/panel-plugin/cddrive.c
===================================================================
--- xfce4-cddrive-plugin/trunk/panel-plugin/cddrive.c 2007-06-27 02:57:14 UTC (rev 2864)
+++ xfce4-cddrive-plugin/trunk/panel-plugin/cddrive.c 2007-06-27 03:00:29 UTC (rev 2865)
@@ -921,55 +921,51 @@
{
CddriveStatus *s;
GError *err = NULL;
- gboolean cb_enabled, update_mon;
- if (G_UNLIKELY (cddrive->monitor == NULL))
- return;
-
- /* We will force the status update. It doesn't need to be done a second time
- upon a state drive change event, so we deactivate the callbacks. */
- cb_enabled = cddrive_monitor_callbacks_enabled (cddrive->monitor);
- update_mon = cddrive_monitor_enable_callbacks (cddrive->monitor, FALSE, NULL);
-
- s = cddrive_status_new (cddrive->monitor, &err);
- if (G_LIKELY (s != NULL ))
+ /* to avoid spurious clicks while waiting the completion of the operation. */
+ gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
+
+ if (G_LIKELY (cddrive->monitor != NULL))
{
- if (cddrive_status_is_open (s))
- /* close the tray */
- cddrive_monitor_close (cddrive->monitor, &err);
- else
+ s = cddrive_status_new (cddrive->monitor, &err);
+ if (G_LIKELY (s != NULL ))
{
- if (cddrive_status_is_mounted (s))
- /* try to unmount the disc */
- cddrive_monitor_unmount (cddrive->monitor, &err);
+ if (cddrive_status_is_open (s))
+ /* close the tray */
+ cddrive_monitor_close (cddrive->monitor, &err);
+ else
+ {
+ if (cddrive_status_is_mounted (s))
+ /* try to unmount the disc */
+ cddrive_monitor_unmount (cddrive->monitor, &err);
- if (G_LIKELY (err == NULL))
- /* open the tray */
- cddrive_monitor_eject (cddrive->monitor, &err);
- }
+ if (G_LIKELY (err == NULL))
+ /* open the tray */
+ cddrive_monitor_eject (cddrive->monitor, &err);
+ }
- cddrive_status_free (s);
+ cddrive_status_free (s);
- if (G_LIKELY (err == NULL && update_mon))
- {
- /* update the monitor, to keep the button pushed down
- while waiting for HAL response. */
- cddrive_update_monitor (cddrive);
- gtk_widget_show_all (cddrive->ebox);
+ if (G_LIKELY (err == NULL))
+ {
+ /* force update, to keep the button pushed down while waiting for
+ HAL response. */
+ cddrive_update_monitor (cddrive);
+
+ /* show the new status after HAL response. */
+ gtk_widget_show_all (cddrive->ebox);
+ }
}
- }
- if (update_mon)
- {
- /* Forced status update done, restore callbacks activation. */
- cddrive_monitor_enable_callbacks (cddrive->monitor, cb_enabled, NULL);
+ if (G_UNLIKELY (err != NULL))
+ {
+ cddrive_show_error (err);
+ cddrive_clear_error (&err);
+ }
}
- if (G_UNLIKELY (err != NULL))
- {
- cddrive_show_error (err);
- cddrive_clear_error (&err);
- }
+ /* re-enable the button disabled at the beginning. */
+ gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
}
More information about the Goodies-commits
mailing list