Merge lp:~artem-anufrij/snap-elementary/Bugfix-1365978 into lp:snap-elementary

Proposed by Artem Anufrij
Status: Merged
Approved by: Cody Garver
Approved revision: 263
Merged at revision: 262
Proposed branch: lp:~artem-anufrij/snap-elementary/Bugfix-1365978
Merge into: lp:snap-elementary
Diff against target: 216 lines (+90/-13)
4 files modified
src/CMakeLists.txt (+1/-0)
src/SnapWindow.vala (+52/-11)
src/Widgets/Camera.vala (+4/-2)
src/Widgets/NoCamera.vala (+33/-0)
To merge this branch: bzr merge lp:~artem-anufrij/snap-elementary/Bugfix-1365978
Reviewer Review Type Date Requested Status
Cody Garver (community) Approve
Corentin Noël Needs Fixing
Review via email: mp+235849@code.launchpad.net

Commit message

Show a message when no camera detected

To post a comment you must log in.
Revision history for this message
Cody Garver (codygarver) wrote :

Does not compile

review: Needs Fixing
Revision history for this message
Cody Garver (codygarver) wrote :

Also some code style violations, function() should be function ()

Revision history for this message
Cody Garver (codygarver) wrote :
260. By artem-anufrij

NoCamera.vala added

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

Hey Gody,

sorry, I forgot to add "NoCamera.vala".

Revision history for this message
Corentin Noël (tintou) wrote :

You don't need to translate the second argument in stack.add_named, the name is internal to Gtk and is used to identify the widget

review: Needs Fixing
Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

Hey Cody,
"Gallery" and "Camera" are translated, too. Should I fixed them?

"
78. this.stack.add_named (this.gallery, _("Gallery"));
79. this.stack.add_named (this.camera, _("Camera"));
"

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

Sorry. I mean Corentin.

Revision history for this message
Corentin Noël (tintou) wrote :

Yes, please fix it
Le 1 oct. 2014 14:07, "Artem Anufrij" <email address hidden> a écrit :

> Sorry. I mean Corentin.
> --
>
> https://code.launchpad.net/~artem-anufrij/snap-elementary/Bugfix-1365978/+merge/235849
> You are reviewing the proposed merge of
> lp:~artem-anufrij/snap-elementary/Bugfix-1365978 into lp:snap-elementary.
>

261. By artem-anufrij

Second argument in 'stack.add_named' will not be translated.

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

done

Revision history for this message
Cody Garver (codygarver) wrote :

Code style is still wrong

Also the copyright should be attributed to something like "elementary Developers", not Mario

review: Needs Fixing
262. By artem-anufrij

License text was changed. Code style was corrected.

263. By artem-anufrij

Code style was corrected.

Revision history for this message
Cody Garver (codygarver) wrote :

The warning could look better but design team can deal with that later

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2014-05-16 16:15:44 +0000
3+++ src/CMakeLists.txt 2014-10-03 08:46:09 +0000
4@@ -8,6 +8,7 @@
5 ######
6 Widgets/Camera.vala
7 Widgets/Gallery.vala
8+ Widgets/NoCamera.vala
9 ######
10 config.vala
11 PACKAGES
12
13=== modified file 'src/SnapWindow.vala'
14--- src/SnapWindow.vala 2014-10-03 01:33:47 +0000
15+++ src/SnapWindow.vala 2014-10-03 08:46:09 +0000
16@@ -21,11 +21,12 @@
17 namespace Snap {
18
19 public class SnapWindow : Gtk.Window {
20-
21+
22 private Snap.SnapApp snap_app;
23
24 private Snap.Widgets.Camera camera;
25 private Snap.Widgets.Gallery gallery;
26+ private Snap.Widgets.NoCamera no_camera;
27 private Gtk.HeaderBar toolbar;
28 private Gtk.Stack stack;
29 private Granite.Widgets.ModeButton mode_button;
30@@ -36,6 +37,8 @@
31 private File photo_path;
32 private File video_path;
33
34+ private bool camera_detected;
35+
36 public SnapWindow (Snap.SnapApp snap_app) {
37
38 this.snap_app = snap_app;
39@@ -53,6 +56,9 @@
40 Resources.photo_thumb_provider = new Services.ThumbnailProvider (photo_path);
41 Resources.video_thumb_provider = new Services.ThumbnailProvider (video_path);
42
43+ // camera
44+ camera_detected = this.detect_camera ();
45+
46 // Setup UI
47 setup_window ();
48 }
49@@ -74,7 +80,7 @@
50 gallery_button = new Gtk.ToggleButton.with_label (_("Gallery"));
51 gallery_button.sensitive = gallery_files_exists ();
52 gallery_button.toggled.connect (() => {
53- if (this.stack.get_visible_child () == this.camera) {
54+ if (this.stack.get_visible_child () != this.gallery) {
55 this.show_gallery ();
56 this.load_thumbnails ();
57 }
58@@ -119,6 +125,7 @@
59 this.camera.take_stop ();
60 }
61 });
62+ take_button.set_sensitive (camera_detected);
63
64 var take_button_box = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
65 take_button_box.set_spacing (4);
66@@ -130,6 +137,9 @@
67
68 toolbar.set_custom_title (take_button_box);
69
70+ // Setup NoCamera widget
71+ this.no_camera = new Snap.Widgets.NoCamera ();
72+
73 // Setup gallery widget
74 this.gallery = new Snap.Widgets.Gallery ();
75
76@@ -151,10 +161,14 @@
77 // Setup window main content area
78 this.stack = new Gtk.Stack ();
79 this.stack.transition_type = Gtk.StackTransitionType.SLIDE_UP_DOWN;
80- this.stack.add_named (this.gallery, _("Gallery"));
81- this.stack.add_named (this.camera, _("Camera"));
82- this.stack.set_visible_child (this.camera); // Show camera on launch
83-
84+ this.stack.add_named (this.gallery, "Gallery");
85+ this.stack.add_named (this.camera, "Camera");
86+ this.stack.add_named (this.no_camera, "NoCamera");
87+ if (camera_detected)
88+ this.stack.set_visible_child (this.camera); // Show camera on launch
89+ else
90+ this.stack.set_visible_child (this.no_camera); // Show no_camera on launch
91+
92 // Statusbar
93 statusbar = new Gtk.Statusbar ();
94
95@@ -169,6 +183,25 @@
96
97 }
98
99+ private bool detect_camera () {
100+ try {
101+ var video_devices = File.new_for_path ("/dev/.");
102+ FileEnumerator enumerator = video_devices.enumerate_children (FileAttribute.STANDARD_NAME, 0);
103+ FileInfo info;
104+ while ((info = enumerator.next_file (null)) != null) {
105+ if (info.get_name ().has_prefix ("video")){
106+ debug ("camera found: %s", info.get_name ());
107+ return true;
108+ }
109+ }
110+ } catch (Error err) {
111+ debug ("camera detection failed: %s", err.message);
112+ }
113+
114+ debug ("no camera");
115+ return false;
116+ }
117+
118 protected override bool delete_event (Gdk.EventAny event) {
119 Resources.photo_thumb_provider.clear_cache ();
120 Resources.video_thumb_provider.clear_cache ();
121@@ -226,15 +259,23 @@
122 }
123
124 private void show_gallery () {
125- this.camera.stop ();
126+ if (camera_detected) {
127+ this.camera.stop ();
128+ }
129 this.lock_camera_actions ();
130 this.stack.set_visible_child (this.gallery);
131 }
132
133 private void show_camera () {
134- this.camera.play ();
135- this.unlock_camera_actions ();
136- this.stack.set_visible_child (this.camera);
137+
138+ if (camera_detected) {
139+ this.stack.set_visible_child (this.camera); // Show camera on launch
140+ this.camera.play ();
141+ this.unlock_camera_actions ();
142+ }
143+ else {
144+ this.stack.set_visible_child (this.no_camera); // Show no_camera on launch
145+ }
146 }
147
148 private bool gallery_files_exists () {
149@@ -257,4 +298,4 @@
150 return false;
151 }
152 }
153-}
154+}
155\ No newline at end of file
156
157=== modified file 'src/Widgets/Camera.vala'
158--- src/Widgets/Camera.vala 2014-05-27 11:23:34 +0000
159+++ src/Widgets/Camera.vala 2014-10-03 08:46:09 +0000
160@@ -41,13 +41,15 @@
161 public signal void capture_stop ();
162
163 public class Camera () {
164+
165 this.set_size_request (WIDTH, HEIGHT); // FIXME
166
167- this.videoflip = Gst.ElementFactory.make ("videoflip", "videoflip");
168+ this.videoflip = Gst.ElementFactory.make ("videoflip", "videoflip");
169 this.videoflip.set_property ("method", 4);
170-
171+
172 this.camerabin = Gst.ElementFactory.make ("camerabin","camera");
173 this.camerabin.set_property ("viewfinder-filter", videoflip);
174+
175 this.camerabin.bus.add_watch (0,(bus,message) => {
176 if (Gst.Video.is_video_overlay_prepare_window_handle_message (message))
177 (message.src as Gst.Video.Overlay).set_window_handle ((uint*) Gdk.X11Window.get_xid (this.get_window()));
178
179=== added file 'src/Widgets/NoCamera.vala'
180--- src/Widgets/NoCamera.vala 1970-01-01 00:00:00 +0000
181+++ src/Widgets/NoCamera.vala 2014-10-03 08:46:09 +0000
182@@ -0,0 +1,33 @@
183+// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
184+/***
185+Copyright (C) 2014 elementary Developers and Artem Anufrij
186+
187+This program is free software: you can redistribute it and/or modify it
188+under the terms of the GNU Lesser General Public License version 3, as published
189+by the Free Software Foundation.
190+
191+This program is distributed in the hope that it will be useful, but
192+WITHOUT ANY WARRANTY; without even the implied warranties of
193+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
194+PURPOSE. See the GNU General Public License for more details.
195+
196+You should have received a copy of the GNU General Public License along
197+with this program. If not, see <http://www.gnu.org/licenses/>.
198+
199+Authors : Artem Anufrij <artem.anufrij@live.de>
200+***/
201+
202+namespace Snap.Widgets {
203+
204+ public class NoCamera : Gtk.ScrolledWindow {
205+
206+ Gtk.Label no_camera_label;
207+
208+ public class NoCamera () {
209+ no_camera_label = new Gtk.Label ("");
210+ no_camera_label.set_markup ("<span color='gray'>%s</span>".printf(_("Your webcam has not been detected. Please be sure you plugged it in.")));
211+ this.add (no_camera_label);
212+ this.show_all ();
213+ }
214+ }
215+}
216\ No newline at end of file

Subscribers

People subscribed via source and target branches