[accounts-dialog] Fix "Take a photograph" menu item sensitivity
- From: Bastien Nocera <hadess src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [accounts-dialog] Fix "Take a photograph" menu item sensitivity
- Date: Thu, 21 Jan 2010 14:29:58 +0000 (UTC)
commit 70fde5e92632148e0ab6e3037d667bb8d80ac8d5
Author: Bastien Nocera <hadess hadess net>
Date: Thu Jan 21 14:28:01 2010 +0000
Fix "Take a photograph" menu item sensitivity
Follow whether there are any webcams available before offering
it to users.
configure.ac | 2 +-
src/um-photo-dialog.c | 53 +++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 50 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c0dcfb5..521fa18 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,7 +38,7 @@ PKG_CHECK_MODULES(DBUS_GLIB, dbus-glib-1)
PKG_CHECK_MODULES(UNIQUE, unique-1.0)
PKG_CHECK_MODULES(POLKIT, polkit-gtk-1)
PKG_CHECK_MODULES(GCONF, gconf-2.0)
-PKG_CHECK_MODULES(CHEESE, cheese-gtk, have_cheese=yes, have_cheese=no)
+PKG_CHECK_MODULES(CHEESE, cheese-gtk > 2.29.6, have_cheese=yes, have_cheese=no)
if test x$have_cheese = xyes ; then
AC_DEFINE(HAVE_CHEESE, 1, [Define to 1 to enable cheese webcam support])
diff --git a/src/um-photo-dialog.c b/src/um-photo-dialog.c
index 5161ba8..bd67dd5 100644
--- a/src/um-photo-dialog.c
+++ b/src/um-photo-dialog.c
@@ -31,6 +31,7 @@
#ifdef HAVE_CHEESE
#include <cheese-avatar-chooser.h>
+#include <cheese-camera-device-monitor.h>
#endif /* HAVE_CHEESE */
#include "um-photo-dialog.h"
@@ -45,6 +46,12 @@ struct _UmPhotoDialog {
GtkWidget *popup_button;
GtkWidget *crop_area;
+#ifdef HAVE_CHEESE
+ CheeseCameraDeviceMonitor *monitor;
+ GtkWidget *take_photo_menuitem;
+ guint num_cameras;
+#endif /* HAVE_CHEESE */
+
GnomeDesktopThumbnailFactory *thumb_factory;
UmUser *user;
@@ -283,6 +290,34 @@ webcam_icon_selected (GtkMenuItem *menuitem,
G_CALLBACK (webcam_response_cb), um);
gtk_widget_show (window);
}
+
+static void
+update_photo_menu_status (UmPhotoDialog *um)
+{
+ if (um->num_cameras == 0)
+ gtk_widget_set_sensitive (um->take_photo_menuitem, FALSE);
+ else
+ gtk_widget_set_sensitive (um->take_photo_menuitem, TRUE);
+}
+
+static void
+device_added (CheeseCameraDeviceMonitor *monitor,
+ GObject *device,
+ UmPhotoDialog *um)
+{
+ um->num_cameras++;
+ update_photo_menu_status (um);
+}
+
+static void
+device_removed (CheeseCameraDeviceMonitor *monitor,
+ const char *id,
+ UmPhotoDialog *um)
+{
+ um->num_cameras--;
+ update_photo_menu_status (um);
+}
+
#endif /* HAVE_CHEESE */
static void
@@ -346,12 +381,20 @@ setup_photo_popup (UmPhotoDialog *um)
gtk_widget_show (menuitem);
#ifdef HAVE_CHEESE
- menuitem = gtk_menu_item_new_with_label (_("Take a photograph..."));
- gtk_menu_attach (GTK_MENU (menu), GTK_WIDGET (menuitem),
+ um->take_photo_menuitem = gtk_menu_item_new_with_label (_("Take a photograph..."));
+ gtk_menu_attach (GTK_MENU (menu), GTK_WIDGET (um->take_photo_menuitem),
0, ROW_SPAN - 1, 2, 3);
- g_signal_connect (G_OBJECT (menuitem), "activate",
+ g_signal_connect (G_OBJECT (um->take_photo_menuitem), "activate",
G_CALLBACK (webcam_icon_selected), um);
- gtk_widget_show (menuitem);
+ gtk_widget_set_sensitive (um->take_photo_menuitem, FALSE);
+ gtk_widget_show (um->take_photo_menuitem);
+
+ um->monitor = cheese_camera_device_monitor_new ();
+ g_signal_connect (G_OBJECT (um->monitor), "added",
+ G_CALLBACK (device_added), um);
+ g_signal_connect (G_OBJECT (um->monitor), "removed",
+ G_CALLBACK (device_removed), um);
+ cheese_camera_device_monitor_coldplug (um->monitor);
#endif /* HAVE_CHEESE */
/* Separator */
@@ -496,6 +539,8 @@ um_photo_dialog_free (UmPhotoDialog *um)
if (um->thumb_factory)
g_object_unref (um->thumb_factory);
+ if (um->monitor)
+ g_object_unref (um->monitor);
if (um->user)
g_object_unref (um->user);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]