~tombeckmann/+junk/presentator

« back to all changes in this revision

Viewing changes to src/Widgets/CameraViewer.vala

  • Committer: Tom Beckmann
  • Date: 2012-04-06 16:32:49 UTC
  • Revision ID: tombeckmann@online.de-20120406163249-a103nbdkkwhlif4i
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
namespace Presentator.Widgets {
 
4
    
 
5
    public enum RecordMode {
 
6
        VIDEO,
 
7
        IMAGE
 
8
    }
 
9
    
 
10
    public class CameraViewer : InlineWindowActor {
 
11
        
 
12
        public signal void finished (string file);
 
13
        
 
14
        public CameraViewer (string title, int width, int height, RecordMode mode, PresentatorApp app){
 
15
            base (title, width, height);
 
16
            
 
17
            var box  = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
 
18
            var rec  = new Gtk.Button ();
 
19
            
 
20
            var draw = new Gtk.DrawingArea ();
 
21
            draw.halign = draw.valign = Gtk.Align.CENTER;
 
22
            draw.set_size_request (350, 270);
 
23
            
 
24
            app.overlay.add_overlay (draw);
 
25
            
 
26
            dynamic Gst.Element pipe = Gst.ElementFactory.make ("camerabin", "pipe");
 
27
            pipe.get_bus ().set_sync_handler ( (bus, message) => {
 
28
                if (message.get_structure () != null && 
 
29
                    message.get_structure().has_name ("prepare-xwindow-id")) {
 
30
                    var xoverlay = message.src as Gst.XOverlay;
 
31
                    xoverlay.set_xwindow_id (Gdk.X11Window.get_xid (draw.get_window ()));
 
32
                    return Gst.BusSyncReply.DROP;
 
33
                }
 
34
                return Gst.BusSyncReply.PASS;
 
35
            });
 
36
            
 
37
            draw.map.connect ( () => {
 
38
                pipe.set_state (Gst.State.PLAYING);
 
39
            });
 
40
            
 
41
            rec.get_style_context ().add_class ("noundo");
 
42
            rec.halign = Gtk.Align.CENTER;
 
43
            if (mode == RecordMode.IMAGE)
 
44
                rec.image = new Gtk.Image.from_icon_name ("view-list-images-symbolic", Gtk.IconSize.BUTTON);
 
45
            else
 
46
                rec.image = new Gtk.Image.from_icon_name ("view-list-video-symbolic", Gtk.IconSize.BUTTON);
 
47
            
 
48
            box.pack_start (rec, false, false);
 
49
            
 
50
            window.add (box);
 
51
            window.show_all ();
 
52
            draw.show ();
 
53
            
 
54
            rec.clicked.connect ( () => {
 
55
                if (mode == RecordMode.IMAGE){
 
56
                    pipe.set_property ("mode", 0);
 
57
                    pipe.set_property ("filename", 
 
58
                        Presentation.data_dir.get_path ()+"/image"+
 
59
                        new DateTime.now_local ().to_unix ().to_string ()+".jpg");
 
60
                    print ("Test\n");
 
61
                    GLib.Signal.emit_by_name (pipe, "capture-start");
 
62
                }else{
 
63
                    pipe.set_property ("mode", 1);
 
64
                    pipe.set_property ("filename", 
 
65
                        Presentation.data_dir.get_path ()+"/video"+
 
66
                        new DateTime.now_local ().to_unix ().to_string ()+".webm");
 
67
                    GLib.Signal.emit_by_name (pipe, "capture-start");
 
68
                }
 
69
            });
 
70
            
 
71
            this.window.closed.connect ( () => {
 
72
                pipe.set_state (Gst.State.NULL);
 
73
                app.overlay.remove (draw);
 
74
            });
 
75
        }
 
76
        
 
77
    }
 
78
    
 
79
    
 
80
}
 
81