~audience-members/audience/gtk-3.12

« back to all changes in this revision

Viewing changes to src/Audience.vala

  • Committer: Corentin Noël
  • Date: 2014-07-06 11:16:48 UTC
  • Revision ID: corentin@elementaryos.org-20140706111648-a72f9bvymwpnf3a6
Fixed saving videos when closing the application.

Show diffs side-by-side

added added

removed removed

Lines of Context:
238
238
                        (int)event.x_root, (int)event.y_root, event.time);
239
239
                }
240
240
 
241
 
                return update_pointer_position (event.y, event.window.get_height ());
 
241
                Gtk.Allocation allocation;
 
242
                clutter.get_allocation (out allocation);
 
243
                return update_pointer_position (event.y, allocation.height);
242
244
            });
243
245
 
244
246
            bottom_bar.time_widget.slider_motion_event.connect ((event) => {
245
247
                int x, y;
246
248
                bottom_bar.translate_coordinates (mainwindow, (int)event.x, (int)event.y, out x, out y);
247
 
                update_pointer_position (y, mainwindow.get_window ().get_height ());
 
249
                Gtk.Allocation allocation;
 
250
                clutter.get_allocation (out allocation);
 
251
                update_pointer_position (y, allocation.height);
248
252
            });
249
253
 
250
254
            mainwindow.button_press_event.connect ((event) => {
268
272
            mainwindow.leave_notify_event.connect ((event) => {
269
273
                if (event.window == null)
270
274
                    return false;
 
275
 
 
276
                Gtk.Allocation allocation;
 
277
                clutter.get_allocation (out allocation);
271
278
                if (event.x == event.window.get_width ())
272
 
                    return update_pointer_position (event.window.get_height (), event.window.get_height ());
 
279
                    return update_pointer_position (event.window.get_height (), allocation.height);
273
280
                else if (event.x == 0)
274
 
                    return update_pointer_position (event.window.get_height (), event.window.get_height ());
275
 
                return update_pointer_position (event.y, event.window.get_height ());
 
281
                    return update_pointer_position (event.window.get_height (), allocation.height);
 
282
                return update_pointer_position (event.y, allocation.height);
276
283
            });
277
284
            //shortcuts
278
 
            this.mainwindow.key_press_event.connect ( (e) => {
 
285
            this.mainwindow.key_press_event.connect ((e) => {
279
286
                return on_key_press_event (e);
280
287
            });
281
288
 
283
290
            mainwindow.destroy.connect (() => {on_destroy ();});
284
291
 
285
292
            //playlist wants us to open a file
286
 
            playlist.play.connect ( (file) => {
 
293
            playlist.play.connect ((file) => {
287
294
                this.play_file (file.get_uri ());
288
295
            });
289
296
 
295
302
                }
296
303
            });
297
304
 
298
 
            stage.notify["allocation"].connect (() => {
299
 
                bottom_actor.width = stage.get_width ();
300
 
                bottom_bar.queue_resize ();
301
 
                bottom_actor.y = stage.get_height () - bottom_bar_size;
302
 
                unfullscreen_actor.y = 6;
303
 
                unfullscreen_actor.x = stage.get_width () - bottom_bar_size - 6;
304
 
            });
 
305
            stage.notify["allocation"].connect (() => {allocate_bottombar ();});
305
306
 
306
 
            if (settings.resume_videos) {
 
307
            if (settings.resume_videos == true && settings.last_played_videos.length > 0) {
 
308
                welcome.hide ();
 
309
                clutter.show_all ();
307
310
                foreach (var filename in settings.last_played_videos) {
308
 
                    var file = File.new_for_commandline_arg (filename);
309
 
                    playlist.add_item (file);
 
311
                    open_file (filename);
310
312
                }
 
313
 
 
314
                video_player.playing = false;
 
315
                video_player.progress = settings.last_stopped;
 
316
                video_player.playing = true;
311
317
            }
312
318
        }
313
319
 
 
320
        private void allocate_bottombar () {
 
321
            bottom_actor.width = stage.get_width ();
 
322
            bottom_bar.queue_resize ();
 
323
            bottom_actor.y = stage.get_height () - bottom_bar_size;
 
324
            unfullscreen_actor.y = 6;
 
325
            unfullscreen_actor.x = stage.get_width () - bottom_bar_size - 6;
 
326
        }
 
327
 
314
328
        private void setup_welcome_screen () {
315
329
            welcome = new Granite.Widgets.Welcome (_("No Videos Open"), _("Select a source to begin playing."));
316
330
            welcome.append ("document-open", _("Open file"), _("Open a saved file."));
317
331
 
318
332
            //welcome.append ("internet-web-browser", _("Open a location"), _("Watch something from the infinity of the internet"));
319
333
            var filename = settings.last_played_videos.length > 0 ? settings.last_played_videos[0] : "";
320
 
            var last_file = File.new_for_uri (filename);
 
334
            var last_file = File.new_for_path (filename);
321
335
            welcome.append ("media-playback-start", _("Resume last video"), get_title (last_file.get_basename ()));
322
336
            bool show_last_file = settings.last_played_videos.length > 0;
323
337
            if (last_file.query_exists () == false) {
496
510
            if (video_player.uri == null || video_player.uri == "" || video_player.uri.has_prefix ("dvd://"))
497
511
                return;
498
512
            if (!video_player.at_end) {
499
 
                /*for (var i = 0; i < last_played_videos.length (); i += 2){
500
 
                    if (video_player.uri == last_played_videos.nth_data (i)){
501
 
                        last_played_videos.nth (i+1).data = video_player.progress.to_string ();
502
 
                        save_last_played_videos ();
503
 
 
504
 
                        return;
505
 
                    }
506
 
                }
507
 
                //not in list yet, insert at start
508
 
                last_played_videos.insert (video_player.uri, 0);
509
 
                last_played_videos.insert (video_player.progress.to_string (), 1);
510
 
                if (last_played_videos.length () > 10) {
511
 
                    last_played_videos.delete_link (last_played_videos.nth (10));
512
 
                    last_played_videos.delete_link (last_played_videos.nth (11));
513
 
                }*/
514
513
                save_last_played_videos ();
515
514
            }
516
515
        }
527
526
        }
528
527
 
529
528
        private bool update_pointer_position (double y, int window_height) {
 
529
            allocate_bottombar ();
530
530
            mainwindow.get_window ().set_cursor (null);
531
531
            if (bottom_bar_size == 0) {
532
532
                int minimum = 0;
536
536
            if (bottom_bar.child_revealed == false)
537
537
                bottom_bar.set_reveal_child (true);
538
538
 
539
 
            if (y >= window_height - bottom_bar_size && y < window_height) {
 
539
            if (y >= (window_height - bottom_bar_size) && y < window_height) {
540
540
                bottom_bar.hovered = true;
541
541
            } else {
542
542
                bottom_bar.hovered = false;
587
587
 
588
588
        private async void read_first_disk () {
589
589
            var disk_manager = DiskManager.get_default ();
 
590
            if (disk_manager.get_volumes ().length () <= 0)
 
591
                return;
590
592
            var volume = disk_manager.get_volumes ().nth_data (0);
591
593
            if (volume.can_mount () == true && volume.get_mount ().can_unmount () == false) {
592
594
                try {
595
597
                    critical (e.message);
596
598
                }
597
599
            }
 
600
 
598
601
            var root = volume.get_mount ().get_default_location ();
599
602
            open_file (root.get_uri (), true);
600
603
            video_player.playing = true;
621
624
                Audience.recurse_over_dir (file, (file_ret) => {
622
625
                    playlist.add_item (file_ret);
623
626
                });
 
627
 
624
628
                file = playlist.get_first_item ();
625
629
            } else if (is_subtitle (filename) && video_player.playing) {
626
630
                video_player.set_subtitle_uri (filename);
627
 
                return;
628
631
            } else if (video_player.playing == true) {
629
632
                playlist.add_item (file);
630
633
            } else {
672
675
            if (mainwindow == null)
673
676
                activate ();
674
677
 
675
 
            open_file (files[0].get_path ());
676
678
            welcome.hide ();
677
679
            clutter.show_all ();
 
680
            foreach (var file in files) {
 
681
                open_file (file.get_path ());
 
682
            }
678
683
        }
679
684
    }
680
685
}