~elementary-apps/snap-elementary/snap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Copyright (c) 2011-2016 Snap Developers (http://launchpad.net/snap-elementary)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Authored by: Marcus Wichelmann <marcus.wichelmann@hotmail.de>
 */

public class Snap.Widgets.CameraView : ClutterGst.Camera {
    public signal void initialized ();

    public CameraView () {
        new Thread<int> (null, () => {
            debug ("Initializing camera view...");

            initialize_view ();

            return 0;
        });
    }

    public new bool take_photo () {
        if (!this.is_ready_for_capture () || this.is_recording_video ()) {
            warning ("Device isn't ready for taking photos.");

            return false;
        }

        base.take_photo (Utils.get_new_media_filename (Utils.ActionType.PHOTO));

        return true;
    }

    public bool start_recording () {
        if (!this.is_ready_for_capture () || this.is_recording_video ()) {
            warning ("Device isn't ready for recording videos.");

            return false;
        }

        this.start_video_recording (Utils.get_new_media_filename (Utils.ActionType.VIDEO));

        return true;
    }

    public void stop_recording () {
        if (!this.is_recording_video ()) {
            warning ("Cannot stop recording because no record is running.");

            return;
        }

        this.stop_video_recording ();
    }

    private void initialize_view () {
        Gst.Element flip_filter = Gst.ElementFactory.make ("videoflip", "videoflip");
        flip_filter.set_property ("method", 4);

        this.set_filter (flip_filter);
        this.set_playing (true);

        if (this.is_ready_for_capture ()) {
            debug ("Camera view initalized.");

            Idle.add (() => {
                initialized ();

                return false;
            });
        } else {
            warning ("Initializing camera view failed.");
        }
    }
}