Merge lp:~vikoadi/audience/restore-progress into lp:~audience-members/audience/trunk

Proposed by Viko Adi Rahmawan
Status: Merged
Approved by: Cody Garver
Approved revision: 368
Merged at revision: 363
Proposed branch: lp:~vikoadi/audience/restore-progress
Merge into: lp:~audience-members/audience/trunk
Diff against target: 242 lines (+65/-31)
3 files modified
src/Audience.vala (+31/-17)
src/Utils.vala (+5/-0)
src/Widgets/Playlist.vala (+29/-14)
To merge this branch: bzr merge lp:~vikoadi/audience/restore-progress
Reviewer Review Type Date Requested Status
Audience Members Pending
Review via email: mp+229738@code.launchpad.net

Commit message

* Fix restoring video progress if open audience.
* Restore playlist and progress from welcome screen on Resume
* Use current-video key instead of last-played-videos
* Don't restore video if they don't exist anymore
* Update playlist play icon properly

Description of the change

-fix restoring video progress if open audience.
-restore playlist and progress from welcome screen
-use current-video key instead of last-played-videos
-dont restore video if they are moved
-update playlist play icon properly

To post a comment you must log in.
367. By Viko Adi Rahmawan

dont play queued video

368. By Viko Adi Rahmawan

dont play when adding file from FileChooserDialog

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Audience.vala'
2--- src/Audience.vala 2014-08-05 13:37:45 +0000
3+++ src/Audience.vala 2014-08-10 16:22:47 +0000
4@@ -318,10 +318,10 @@
5 welcome.append ("document-open", _("Open file"), _("Open a saved file."));
6
7 //welcome.append ("internet-web-browser", _("Open a location"), _("Watch something from the infinity of the internet"));
8- var filename = settings.last_played_videos.length > 0 ? settings.last_played_videos[0] : "";
9- var last_file = File.new_for_path (filename);
10+ var filename = settings.current_video;
11+ var last_file = File.new_for_uri (filename);
12 welcome.append ("media-playback-start", _("Resume last video"), get_title (last_file.get_basename ()));
13- bool show_last_file = settings.last_played_videos.length > 0;
14+ bool show_last_file = settings.current_video != "";
15 if (last_file.query_exists () == false) {
16 show_last_file = false;
17 }
18@@ -355,9 +355,10 @@
19 case 1:
20 welcome.hide ();
21 clutter.show_all ();
22+ restore_playlist ();
23 open_file (filename);
24 video_player.playing = false;
25- video_player.progress = settings.last_stopped;
26+ Idle.add (() => {video_player.progress = settings.last_stopped; return false;});
27 video_player.playing = true;
28 break;
29 case 2:
30@@ -486,9 +487,9 @@
31 Gtk.drag_dest_set (mainwindow, Gtk.DestDefaults.ALL, {uris}, Gdk.DragAction.MOVE);
32 mainwindow.drag_data_received.connect ( (ctx, x, y, sel, info, time) => {
33 foreach (var uri in sel.get_uris ()) {
34- playlist.add_item (File.new_for_uri (uri));
35+ open_file (uri);
36 }
37- open_file (sel.get_uris ()[0]);
38+
39 welcome.hide ();
40 clutter.show_all ();
41 });
42@@ -536,12 +537,18 @@
43 private inline void save_last_played_videos () {
44 playlist.save_playlist_config ();
45
46- if (settings.last_played_videos.length > 0)
47+ if (settings.current_video != "")
48 settings.last_stopped = video_player.progress;
49 else
50 settings.last_stopped = 0;
51 }
52
53+ private void restore_playlist () {
54+ foreach (var filename in settings.last_played_videos) {
55+ playlist.add_item (File.new_for_uri (filename));
56+ }
57+ }
58+
59 public void run_open_file () {
60 var file = new Gtk.FileChooserDialog (_("Open"), mainwindow, Gtk.FileChooserAction.OPEN,
61 _("_Cancel"), Gtk.ResponseType.CANCEL, _("_Open"), Gtk.ResponseType.ACCEPT);
62@@ -562,7 +569,11 @@
63 if (file.run () == Gtk.ResponseType.ACCEPT) {
64 welcome.hide ();
65 clutter.show_all ();
66- open_file (file.get_uri ());
67+
68+ playlist.add_item (file.get_file ());
69+ if (video_player.uri == null)
70+ open_file (file.get_uri ());
71+
72 settings.last_folder = file.get_current_folder ();
73 }
74
75@@ -614,10 +625,9 @@
76 });
77
78 file = playlist.get_first_item ();
79+ play_file (file.get_uri ());
80 } else if (is_subtitle (filename) && video_player.playing) {
81 video_player.set_subtitle_uri (filename);
82- } else if (video_player.playing == true) {
83- playlist.add_item (file);
84 } else {
85 playlist.add_item (file);
86 play_file (file.get_uri ());
87@@ -657,6 +667,7 @@
88 public void play_file (string uri) {
89 debug ("Opening %s", uri);
90 video_player.uri = uri;
91+ playlist.set_current (uri);
92 bottom_bar.set_preview_uri (uri);
93
94 string? sub_uri = get_subtitle_for_uri (uri);
95@@ -678,16 +689,16 @@
96 //the application started
97 public override void activate () {
98 build ();
99- if (settings.resume_videos == true && settings.last_played_videos.length > 0) {
100+ if (settings.resume_videos == true
101+ && settings.last_played_videos.length > 0
102+ && settings.current_video != ""
103+ && file_exists (settings.current_video)) {
104 welcome.hide ();
105 clutter.show_all ();
106- foreach (var filename in settings.last_played_videos) {
107- playlist.add_item (File.new_for_path (filename));
108- }
109+ restore_playlist ();
110 open_file (settings.current_video);
111-
112 video_player.playing = false;
113- video_player.progress = settings.last_stopped;
114+ Idle.add (() => {video_player.progress = settings.last_stopped; return false;});
115 video_player.playing = true;
116 }
117 }
118@@ -700,8 +711,11 @@
119 welcome.hide ();
120 clutter.show_all ();
121 foreach (var file in files) {
122- open_file (file.get_path ());
123+ playlist.add_item (file);
124 }
125+
126+ if (video_player.uri == null)
127+ open_file(files[0].get_uri ());
128 }
129 }
130 }
131
132=== modified file 'src/Utils.vala'
133--- src/Utils.vala 2014-06-30 14:54:30 +0000
134+++ src/Utils.vala 2014-08-10 16:22:47 +0000
135@@ -106,4 +106,9 @@
136 var disk_manager = DiskManager.get_default ();
137 return disk_manager.get_volumes ().length () > 0;
138 }
139+
140+ public static bool file_exists (string uri) {
141+ var file = File.new_for_uri (uri);
142+ return file.query_exists ();
143+ }
144 }
145\ No newline at end of file
146
147=== modified file 'src/Widgets/Playlist.vala'
148--- src/Widgets/Playlist.vala 2014-08-05 13:37:45 +0000
149+++ src/Widgets/Playlist.vala 2014-08-10 16:22:47 +0000
150@@ -54,8 +54,6 @@
151 string filename;
152 playlist.get (iter, Columns.FILENAME, out filename);
153 play (File.new_for_commandline_arg (filename));
154- change_current_symbol (iter);
155- this.current = int.parse (path.to_string ());
156 });
157
158 this.reorderable = true;
159@@ -69,19 +67,11 @@
160 });
161 }
162
163- private inline void change_current_symbol (Gtk.TreeIter new_item) {
164- Gtk.TreeIter old_item;
165- playlist.get_iter_from_string (out old_item, this.current.to_string ());
166- playlist.set (old_item, Columns.PLAYING, null);
167- playlist.set (new_item, Columns.PLAYING, new ThemedIcon ("media-playback-start-symbolic"));
168- }
169-
170 public void next () {
171 Gtk.TreeIter iter;
172 if (playlist.get_iter_from_string (out iter, (this.current + 1).to_string ())){
173 string filename;
174 playlist.get (iter, Columns.FILENAME, out filename);
175- change_current_symbol (iter);
176 current++;
177 play (File.new_for_commandline_arg (filename));
178 }
179@@ -92,7 +82,6 @@
180 if (playlist.get_iter_from_string (out iter, (this.current - 1).to_string ())){
181 string filename;
182 playlist.get (iter, Columns.FILENAME, out filename);
183- change_current_symbol (iter);
184 current--;
185 play (File.new_for_commandline_arg (filename));
186 }
187@@ -101,7 +90,7 @@
188 public void add_item (File path) {
189 if (!path.query_exists ())
190 return;
191- var file_name = path.get_path ();
192+ var file_name = path.get_uri ();
193 bool exist = false;
194 Gtk.TreeIter iter;
195
196@@ -127,11 +116,11 @@
197 playlist.append (out iter);
198 playlist.set (iter, Columns.PLAYING, playing,
199 Columns.TITLE, Audience.get_title (path.get_basename ()),
200- Columns.FILENAME, path.get_path ());
201+ Columns.FILENAME, path.get_uri ());
202 }
203
204 public void remove_item (File path) {
205- var file_name = path.get_path ();
206+ var file_name = path.get_uri ();
207
208 playlist.foreach ((model, path, iter) => {
209 Value filename;
210@@ -153,6 +142,32 @@
211 return null;
212 }
213
214+ public int get_current () {
215+ return current;
216+ }
217+
218+ public void set_current (string current_file) {
219+ int count = 0;
220+ int current_played = 0;
221+ playlist.foreach ((model, path, iter) => {
222+ playlist.set (iter, Columns.PLAYING, null);
223+ Value filename;
224+ playlist.get_value (iter, Columns.FILENAME, out filename);
225+ string name = filename.get_string ();
226+ if (name == current_file)
227+ current_played = count;
228+ count++;
229+ return false;
230+ });
231+
232+ Gtk.TreeIter new_iter;
233+ playlist.get_iter_from_string (out new_iter, current_played.to_string ());
234+ playlist.set (new_iter, Columns.PLAYING, new ThemedIcon ("media-playback-start-symbolic"));
235+
236+ this.current = current_played;
237+
238+ }
239+
240 public List<string> get_all_items () {
241 var list = new List<string> ();
242 playlist.foreach ((model, path, iter) => {

Subscribers

People subscribed via source and target branches