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
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-05-16 16:15:44 +0000
+++ src/CMakeLists.txt 2014-10-03 08:46:09 +0000
@@ -8,6 +8,7 @@
8 ######8 ######
9 Widgets/Camera.vala9 Widgets/Camera.vala
10 Widgets/Gallery.vala10 Widgets/Gallery.vala
11 Widgets/NoCamera.vala
11 ######12 ######
12 config.vala13 config.vala
13PACKAGES14PACKAGES
1415
=== modified file 'src/SnapWindow.vala'
--- src/SnapWindow.vala 2014-10-03 01:33:47 +0000
+++ src/SnapWindow.vala 2014-10-03 08:46:09 +0000
@@ -21,11 +21,12 @@
21namespace Snap {21namespace Snap {
2222
23 public class SnapWindow : Gtk.Window {23 public class SnapWindow : Gtk.Window {
2424
25 private Snap.SnapApp snap_app;25 private Snap.SnapApp snap_app;
26 26
27 private Snap.Widgets.Camera camera;27 private Snap.Widgets.Camera camera;
28 private Snap.Widgets.Gallery gallery;28 private Snap.Widgets.Gallery gallery;
29 private Snap.Widgets.NoCamera no_camera;
29 private Gtk.HeaderBar toolbar;30 private Gtk.HeaderBar toolbar;
30 private Gtk.Stack stack;31 private Gtk.Stack stack;
31 private Granite.Widgets.ModeButton mode_button;32 private Granite.Widgets.ModeButton mode_button;
@@ -36,6 +37,8 @@
36 private File photo_path;37 private File photo_path;
37 private File video_path;38 private File video_path;
3839
40 private bool camera_detected;
41
39 public SnapWindow (Snap.SnapApp snap_app) {42 public SnapWindow (Snap.SnapApp snap_app) {
4043
41 this.snap_app = snap_app;44 this.snap_app = snap_app;
@@ -53,6 +56,9 @@
53 Resources.photo_thumb_provider = new Services.ThumbnailProvider (photo_path);56 Resources.photo_thumb_provider = new Services.ThumbnailProvider (photo_path);
54 Resources.video_thumb_provider = new Services.ThumbnailProvider (video_path);57 Resources.video_thumb_provider = new Services.ThumbnailProvider (video_path);
5558
59 // camera
60 camera_detected = this.detect_camera ();
61
56 // Setup UI62 // Setup UI
57 setup_window ();63 setup_window ();
58 }64 }
@@ -74,7 +80,7 @@
74 gallery_button = new Gtk.ToggleButton.with_label (_("Gallery"));80 gallery_button = new Gtk.ToggleButton.with_label (_("Gallery"));
75 gallery_button.sensitive = gallery_files_exists ();81 gallery_button.sensitive = gallery_files_exists ();
76 gallery_button.toggled.connect (() => {82 gallery_button.toggled.connect (() => {
77 if (this.stack.get_visible_child () == this.camera) {83 if (this.stack.get_visible_child () != this.gallery) {
78 this.show_gallery ();84 this.show_gallery ();
79 this.load_thumbnails ();85 this.load_thumbnails ();
80 }86 }
@@ -119,6 +125,7 @@
119 this.camera.take_stop ();125 this.camera.take_stop ();
120 }126 }
121 });127 });
128 take_button.set_sensitive (camera_detected);
122 129
123 var take_button_box = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);130 var take_button_box = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
124 take_button_box.set_spacing (4);131 take_button_box.set_spacing (4);
@@ -130,6 +137,9 @@
130137
131 toolbar.set_custom_title (take_button_box);138 toolbar.set_custom_title (take_button_box);
132 139
140 // Setup NoCamera widget
141 this.no_camera = new Snap.Widgets.NoCamera ();
142
133 // Setup gallery widget143 // Setup gallery widget
134 this.gallery = new Snap.Widgets.Gallery ();144 this.gallery = new Snap.Widgets.Gallery ();
135 145
@@ -151,10 +161,14 @@
151 // Setup window main content area161 // Setup window main content area
152 this.stack = new Gtk.Stack ();162 this.stack = new Gtk.Stack ();
153 this.stack.transition_type = Gtk.StackTransitionType.SLIDE_UP_DOWN;163 this.stack.transition_type = Gtk.StackTransitionType.SLIDE_UP_DOWN;
154 this.stack.add_named (this.gallery, _("Gallery"));164 this.stack.add_named (this.gallery, "Gallery");
155 this.stack.add_named (this.camera, _("Camera"));165 this.stack.add_named (this.camera, "Camera");
156 this.stack.set_visible_child (this.camera); // Show camera on launch166 this.stack.add_named (this.no_camera, "NoCamera");
157167 if (camera_detected)
168 this.stack.set_visible_child (this.camera); // Show camera on launch
169 else
170 this.stack.set_visible_child (this.no_camera); // Show no_camera on launch
171
158 // Statusbar172 // Statusbar
159 statusbar = new Gtk.Statusbar ();173 statusbar = new Gtk.Statusbar ();
160174
@@ -169,6 +183,25 @@
169 183
170 }184 }
171 185
186 private bool detect_camera () {
187 try {
188 var video_devices = File.new_for_path ("/dev/.");
189 FileEnumerator enumerator = video_devices.enumerate_children (FileAttribute.STANDARD_NAME, 0);
190 FileInfo info;
191 while ((info = enumerator.next_file (null)) != null) {
192 if (info.get_name ().has_prefix ("video")){
193 debug ("camera found: %s", info.get_name ());
194 return true;
195 }
196 }
197 } catch (Error err) {
198 debug ("camera detection failed: %s", err.message);
199 }
200
201 debug ("no camera");
202 return false;
203 }
204
172 protected override bool delete_event (Gdk.EventAny event) {205 protected override bool delete_event (Gdk.EventAny event) {
173 Resources.photo_thumb_provider.clear_cache ();206 Resources.photo_thumb_provider.clear_cache ();
174 Resources.video_thumb_provider.clear_cache ();207 Resources.video_thumb_provider.clear_cache ();
@@ -226,15 +259,23 @@
226 }259 }
227 260
228 private void show_gallery () {261 private void show_gallery () {
229 this.camera.stop ();262 if (camera_detected) {
263 this.camera.stop ();
264 }
230 this.lock_camera_actions ();265 this.lock_camera_actions ();
231 this.stack.set_visible_child (this.gallery);266 this.stack.set_visible_child (this.gallery);
232 }267 }
233 268
234 private void show_camera () {269 private void show_camera () {
235 this.camera.play ();270
236 this.unlock_camera_actions ();271 if (camera_detected) {
237 this.stack.set_visible_child (this.camera);272 this.stack.set_visible_child (this.camera); // Show camera on launch
273 this.camera.play ();
274 this.unlock_camera_actions ();
275 }
276 else {
277 this.stack.set_visible_child (this.no_camera); // Show no_camera on launch
278 }
238 }279 }
239280
240 private bool gallery_files_exists () {281 private bool gallery_files_exists () {
@@ -257,4 +298,4 @@
257 return false;298 return false;
258 }299 }
259 }300 }
260}301}
261\ No newline at end of file302\ No newline at end of file
262303
=== modified file 'src/Widgets/Camera.vala'
--- src/Widgets/Camera.vala 2014-05-27 11:23:34 +0000
+++ src/Widgets/Camera.vala 2014-10-03 08:46:09 +0000
@@ -41,13 +41,15 @@
41 public signal void capture_stop ();41 public signal void capture_stop ();
42 42
43 public class Camera () {43 public class Camera () {
44
44 this.set_size_request (WIDTH, HEIGHT); // FIXME45 this.set_size_request (WIDTH, HEIGHT); // FIXME
4546
46 this.videoflip = Gst.ElementFactory.make ("videoflip", "videoflip");47 this.videoflip = Gst.ElementFactory.make ("videoflip", "videoflip");
47 this.videoflip.set_property ("method", 4);48 this.videoflip.set_property ("method", 4);
4849
49 this.camerabin = Gst.ElementFactory.make ("camerabin","camera");50 this.camerabin = Gst.ElementFactory.make ("camerabin","camera");
50 this.camerabin.set_property ("viewfinder-filter", videoflip);51 this.camerabin.set_property ("viewfinder-filter", videoflip);
52
51 this.camerabin.bus.add_watch (0,(bus,message) => {53 this.camerabin.bus.add_watch (0,(bus,message) => {
52 if (Gst.Video.is_video_overlay_prepare_window_handle_message (message))54 if (Gst.Video.is_video_overlay_prepare_window_handle_message (message))
53 (message.src as Gst.Video.Overlay).set_window_handle ((uint*) Gdk.X11Window.get_xid (this.get_window()));55 (message.src as Gst.Video.Overlay).set_window_handle ((uint*) Gdk.X11Window.get_xid (this.get_window()));
5456
=== added file 'src/Widgets/NoCamera.vala'
--- src/Widgets/NoCamera.vala 1970-01-01 00:00:00 +0000
+++ src/Widgets/NoCamera.vala 2014-10-03 08:46:09 +0000
@@ -0,0 +1,33 @@
1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
2/***
3Copyright (C) 2014 elementary Developers and Artem Anufrij
4
5This program is free software: you can redistribute it and/or modify it
6under the terms of the GNU Lesser General Public License version 3, as published
7by the Free Software Foundation.
8
9This program is distributed in the hope that it will be useful, but
10WITHOUT ANY WARRANTY; without even the implied warranties of
11MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12PURPOSE. See the GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License along
15with this program. If not, see <http://www.gnu.org/licenses/>.
16
17Authors : Artem Anufrij <artem.anufrij@live.de>
18***/
19
20namespace Snap.Widgets {
21
22 public class NoCamera : Gtk.ScrolledWindow {
23
24 Gtk.Label no_camera_label;
25
26 public class NoCamera () {
27 no_camera_label = new Gtk.Label ("");
28 no_camera_label.set_markup ("<span color='gray'>%s</span>".printf(_("Your webcam has not been detected. Please be sure you plugged it in.")));
29 this.add (no_camera_label);
30 this.show_all ();
31 }
32 }
33}
0\ No newline at end of file34\ No newline at end of file

Subscribers

People subscribed via source and target branches