[the-board/cheese] [things] Initial work on Cheese support in PhotoThing



commit fc0ef10bf2ed0ee8829ec001e2008b3de8be08e5
Author: Lucas Rocha <lucasr gnome org>
Date:   Wed Mar 30 01:48:52 2011 +0100

    [things] Initial work on Cheese support in PhotoThing

 configure.ac              |    3 +-
 src/js/ui/things/photo.js |   53 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 50 insertions(+), 6 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 187629a..13ff5bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -69,7 +69,8 @@ PKG_CHECK_MODULES(THE_BOARD,
                   mx-1.0 >= $MX_MIN_VERSION
                   gtk+-3.0 >= $GTK_MIN_VERSION
                   clutter-gtk-1.0 >= $CLUTTER_GTK_MIN_VERSION
-                  clutter-gst-1.0 >= $CLUTTER_GST_MIN_VERSION)
+                  clutter-gst-1.0 >= $CLUTTER_GST_MIN_VERSION,
+                  cheese >= 2.91.93)
 
 PKG_CHECK_MODULES(TB,
                   glib-2.0 >= $GLIB_MIN_VERSION
diff --git a/src/js/ui/things/photo.js b/src/js/ui/things/photo.js
index a73acb5..dd4a9c7 100644
--- a/src/js/ui/things/photo.js
+++ b/src/js/ui/things/photo.js
@@ -5,6 +5,7 @@ const Mainloop = imports.mainloop;
 const Tweener = imports.tweener.tweener;
 
 // gi imports
+const Cheese = imports.gi.Cheese;
 const Clutter = imports.gi.Clutter;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
@@ -260,6 +261,40 @@ PhotoThing.prototype = {
                                   false /* not from state*/);
     },
 
+    _updatePhotoWithWebcam : function() {
+        let camera = Cheese.Camera.new(this._photo,
+                                       null,
+                                       640, 480);
+
+        let fileUtil = new Cheese.FileUtil();
+
+        camera.setup(null);
+        camera.play();
+
+        this._updateInitialSize(640, 480);
+        this._onPhotoLoadFinished(this._photo, null, false);
+
+        let filename = fileUtil.get_photo_path() +
+                       fileUtil.get_new_media_filename(Cheese.MediaMode.PHOTO);
+
+        let onSaved = function() {
+            Mainloop.idle_add(function() {
+                                  camera.stop();
+                              });
+
+            this._updateImageFilename(filename,
+                                      false /* not from state*/);
+        }
+
+        camera.connect("photo-saved",
+                       Lang.bind(this, onSaved));
+
+        Mainloop.timeout_add_seconds(3,
+                                     function() {
+                                         camera.take_photo(filename);
+                                     });
+    },
+
     _onCaptionTextKeyPressEvent : function(o, event) {
         let key = event.get_key_symbol();
 
@@ -348,6 +383,8 @@ PhotoThing.prototype = {
     doAction : function(actionName, actionArgs) {
         if (actionName == "chooseFile") {
             this._updatePhotoWithFileChooser();
+        } else if (actionName == "takePhoto") {
+            this._updatePhotoWithWebcam();
         }
     },
 
@@ -404,13 +441,19 @@ function createToolbar(args) {
         new Toolbar.Toolbar({ title: NAME,
                               visible: false });
 
-    let toolBox =
-        new ToolBox.ToolBox({ title: Gettext.gettext("Load from") });
+    let toolBoxWebcam = new ToolBox.ToolBox();
+
+    toolBoxWebcam.addButton({ label: Gettext.gettext("Take photo"),
+                              actionName: "takePhoto" });
+
+    toolbar.addToolBox(toolBoxWebcam);
+
+    let toolBoxFile = new ToolBox.ToolBox();
 
-    toolBox.addButton({ label: Gettext.gettext("File"),
-                        actionName: "chooseFile" });
+    toolBoxFile.addButton({ label: Gettext.gettext("Load file"),
+                            actionName: "chooseFile" });
 
-    toolbar.addToolBox(toolBox);
+    toolbar.addToolBox(toolBoxFile);
 
     return toolbar;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]