Merge lp:~shnatsel/noise/ditch-existence-checking-copypasta into lp:~elementary-apps/noise/trunk

Proposed by Sergey "Shnatsel" Davidoff
Status: Merged
Approved by: Corentin Noël
Approved revision: 1538
Merged at revision: 1539
Proposed branch: lp:~shnatsel/noise/ditch-existence-checking-copypasta
Merge into: lp:~elementary-apps/noise/trunk
Diff against target: 84 lines (+4/-26)
5 files modified
core/GStreamer/Playback.vala (+0/-1)
plugins/Devices/CDRom/CDPlayer.vala (+1/-8)
plugins/Devices/iPod/iPodStreamer.vala (+1/-8)
src/GStreamer/Streamer.vala (+1/-8)
src/PlaybackManager.vala (+1/-1)
To merge this branch: bzr merge lp:~shnatsel/noise/ditch-existence-checking-copypasta
Reviewer Review Type Date Requested Status
Victor Martinez (community) Approve
Review via email: mp+190634@code.launchpad.net

Commit message

ditch the superfluous existence-checking function copypasted all over the place

Description of the change

Ditch some useless copypasta from Noise codebase.

Player.check_existence (string uri) method as well as its copies in other classes is only used in once place and even there it's not needed at all.

Instead of "player.check_existance (m.uri)" which creates a new Glib.File out of the URI you can just use the already-in-place Glib.File associated with the media and do the job using well-known library functions only: "m.file.query_exists ()"
This simplifies the code and makes it a bit more readable.

If the need to check abstracted media existence ever arises (i.e. if we encounter a media without a valid file property), a similar function can be re-introduced, although I expect it to be a method of the Noise.Media class in that case.

To post a comment you must log in.
Revision history for this message
Victor Martinez (victored) wrote :

Good catch. Please correct the coding style in diff line 81 and it's done:

"if ( ! m.file.query_exists ()) {"

Should be:

"if (!m.file.query_exists ()) {"

It may seem harder to read but it's more consistent.

review: Needs Fixing
1538. By Sergey "Shnatsel" Davidoff

coding style tweak

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

<shnatsel> "if (!m.file.query_exists ()) {" vs "if ( ! m.file.query_exists ()) {"
<shnatsel> which one should be used in elementary?
<Munchor> the first one, we never put a space after opening parentheses. "if (! m.file.query_exists ()) {" is also acceptable I guess.

Fixed.

Revision history for this message
Victor Martinez (victored) wrote :

Hey, thanks for applying the correction. I'm not sure we really use "if (! condition) {" style from C++ over "if (!condition) {", but I guess it's OK, just not that common in Vala code.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'core/GStreamer/Playback.vala'
2--- core/GStreamer/Playback.vala 2013-02-26 21:56:08 +0000
3+++ core/GStreamer/Playback.vala 2013-10-13 16:08:51 +0000
4@@ -49,7 +49,6 @@
5 public abstract void pause ();
6 public abstract void set_state (Gst.State s);
7 public abstract void set_media (Media media);
8- public abstract bool check_existance (string uri);
9 public abstract void set_position (int64 pos);
10 public abstract int64 get_position ();
11 public abstract int64 get_duration ();
12
13=== modified file 'plugins/Devices/CDRom/CDPlayer.vala'
14--- plugins/Devices/CDRom/CDPlayer.vala 2013-06-17 12:58:33 +0000
15+++ plugins/Devices/CDRom/CDPlayer.vala 2013-10-13 16:08:51 +0000
16@@ -67,14 +67,7 @@
17 uris.add ("cdda://");
18 return uris;
19 }
20-
21- public bool check_existance (string uri) {
22- if (!GLib.File.new_for_uri (uri).query_exists ()) {
23- return false;
24- }
25- return true;
26- }
27-
28+
29 public bool update_position () {
30 if (first_start || (App.player.media_info != null && App.player.media_info.media != null && get_position() >= (int64)(App.player.media_info.media.resume_pos - 1) * 1000000000)) {
31 first_start = false;
32
33=== modified file 'plugins/Devices/iPod/iPodStreamer.vala'
34--- plugins/Devices/iPod/iPodStreamer.vala 2013-06-17 12:58:33 +0000
35+++ plugins/Devices/iPod/iPodStreamer.vala 2013-10-13 16:08:51 +0000
36@@ -54,14 +54,7 @@
37 uris.add ("afc://");
38 return uris;
39 }
40-
41- public bool check_existance (string uri) {
42- if (!GLib.File.new_for_uri (uri).query_exists ()) {
43- return false;
44- }
45- return true;
46- }
47-
48+
49 public bool update_position () {
50 if(set_resume_pos || (App.player.media_info != null && App.player.media_info.media != null && get_position() >= (int64)(App.player.media_info.media.resume_pos - 1) * 1000000000)) {
51 set_resume_pos = true;
52
53=== modified file 'src/GStreamer/Streamer.vala'
54--- src/GStreamer/Streamer.vala 2013-06-12 18:04:28 +0000
55+++ src/GStreamer/Streamer.vala 2013-10-13 16:08:51 +0000
56@@ -53,14 +53,7 @@
57 uris.add ("http://");
58 return uris;
59 }
60-
61- public bool check_existance (string uri) {
62- if (!GLib.File.new_for_uri (uri).query_exists ()) {
63- return false;
64- }
65- return true;
66- }
67-
68+
69 public bool update_position () {
70 if(set_resume_pos || (App.player.media_info != null && App.player.media_info.media != null && get_position() >= (int64)(App.player.media_info.media.resume_pos - 1) * 1000000000)) {
71 set_resume_pos = true;
72
73=== modified file 'src/PlaybackManager.vala'
74--- src/PlaybackManager.vala 2013-06-17 12:58:33 +0000
75+++ src/PlaybackManager.vala 2013-10-13 16:08:51 +0000
76@@ -532,7 +532,7 @@
77 }
78
79 // check that the file exists
80- if (!player.check_existance (m.uri)) {
81+ if (! m.file.query_exists ()) {
82 m.unique_status_image = Icons.PROCESS_ERROR.render(Gtk.IconSize.MENU);
83 m.location_unknown = true;
84 //App.main_window.media_not_found(id);

Subscribers

People subscribed via source and target branches