66
69
settings = new Settings ();
67
70
mainwindow = new Gtk.Window ();
68
71
video_player = new Widgets.VideoPlayer ();
72
video_player.notify["playing"].connect (() => {bottom_bar.toggle_play_pause ();});
69
74
tagview = new Widgets.TagView (this);
71
75
tagview.select_external_subtitle.connect (video_player.set_subtitle_uri);
73
var mainbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
74
77
clutter = new GtkClutter.Embed ();
76
79
//prepare last played videos
99
102
welcome.append ("media-cdrom", _("Play from Disc"), _("Watch a DVD or open a file from disc"));
100
103
welcome.set_item_visible (2, has_dvd);
102
var stage = clutter.get_stage ();
105
stage = (Clutter.Stage)clutter.get_stage ();
104
107
video_player.add_constraint (new Clutter.BindConstraint (stage, Clutter.BindCoordinate.WIDTH, 0));
105
108
video_player.add_constraint (new Clutter.BindConstraint (stage, Clutter.BindCoordinate.HEIGHT, 0));
107
110
stage.add_child (video_player);
108
111
stage.add_child (tagview);
109
stage.background_color = {0, 0, 0};
112
stage.background_color = {0, 0, 0, 0};
113
stage.use_alpha = true;
111
115
this.tagview.y = -10;
112
116
this.tagview.x = stage.width;
113
117
this.tagview.add_constraint (new Clutter.BindConstraint (stage, Clutter.BindCoordinate.HEIGHT, -20));
119
bottom_bar = new Widgets.BottomBar ();
120
bottom_bar.set_valign (Gtk.Align.END);
121
bottom_bar.run_open.connect ((type) => {run_open (type);});
122
bottom_bar.play_toggled.connect (() => {video_player.playing = !video_player.playing;});
124
overlay = new Gtk.Overlay ();
125
overlay.add (clutter);
126
overlay.add_overlay (bottom_bar);
128
var mainbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
129
mainbox.pack_start (overlay);
115
130
mainbox.pack_start (welcome);
116
mainbox.pack_start (clutter);
118
132
this.mainwindow.title = program_name;
119
133
this.mainwindow.window_position = Gtk.WindowPosition.CENTER;
124
138
if (!settings.show_window_decoration)
125
139
this.mainwindow.decorated = false;
130
144
video_player.text_tags_changed.connect (tagview.setup_text_setup);
131
145
video_player.audio_tags_changed.connect (tagview.setup_audio_setup);
146
video_player.progression_changed.connect ((current_time, total_time) => {
147
bottom_bar.set_progression_time (current_time, total_time);
134
151
this.monitor = GLib.VolumeMonitor.get ();
376
video_player.configure_window.connect ((video_w, video_h) => {
378
Gdk.Rectangle monitor;
379
var screen = Gdk.Screen.get_default ();
380
screen.get_monitor_geometry (
381
screen.get_monitor_at_window (mainwindow.get_window ()),
384
int width = 0, height = 0;
385
if (monitor.width > video_w && monitor.height > video_h) {
386
width = (int)video_w;
387
height = (int)video_h;
389
width = (int)(monitor.width * 0.9);
390
height = (int)((double)video_h / video_w * width);
393
var geom = Gdk.Geometry ();
394
if (settings.keep_aspect) {
395
geom.min_aspect = geom.max_aspect = video_w / (double)video_h;
397
geom.min_aspect = 0.0;
398
geom.max_aspect = 99999999.0;
401
mainwindow.get_window ().move_resize (monitor.width / 2 - width / 2 + monitor.x,
402
monitor.height / 2 - height / 2 + monitor.y,
405
if (settings.keep_aspect) {
406
mainwindow.get_window ().set_geometry_hints (geom, Gdk.WindowHints.ASPECT);
393
setup_drag_n_drop ();
394
video_player.configure_window.connect ((video_w, video_h) => {on_configure_window (video_w, video_h);});
411
396
//fullscreen on maximize
412
mainwindow.window_state_event.connect ( (e) => {
413
if (!((e.window.get_state () & Gdk.WindowState.MAXIMIZED) == 0) && !video_player.fullscreened){
414
mainwindow.fullscreen ();
415
video_player.fullscreened = true;
425
mainwindow.size_allocate.connect ( (alloc) => {
426
if (alloc.width != old_w ||
427
alloc.height != old_h) {
428
if (video_player.relayout ()) {
430
old_h = alloc.height;
434
tagview.x = tagview.expanded ? stage.width - tagview.width + 10 : stage.width;
397
mainwindow.window_state_event.connect ((e) => {on_window_state_changed (e.window.get_state ()); return false;});
437
399
/*moving the window by drag, fullscreen for dbl-click*/
438
400
bool down = false;
437
mainwindow.events |= Gdk.EventMask.POINTER_MOTION_MASK;
438
mainwindow.events |= Gdk.EventMask.LEAVE_NOTIFY_MASK;
439
mainwindow.size_allocate.connect ((alloc) => {on_size_allocate (alloc);});
440
mainwindow.motion_notify_event.connect ((event) => {return update_pointer_position (event.y, event.window.get_height ());});
441
mainwindow.leave_notify_event.connect ((event) => {
442
if (event.x == event.window.get_width ())
443
return update_pointer_position (event.window.get_height (), event.window.get_height ());
445
return update_pointer_position (event.window.get_height (), event.window.get_height ());
446
return update_pointer_position (event.y, event.window.get_height ());
448
//save position in video when not finished playing
449
mainwindow.destroy.connect (() => {on_destroy ();});
452
private void on_configure_window (uint video_w, uint video_h) {
453
Gdk.Rectangle monitor;
454
var screen = Gdk.Screen.get_default ();
455
screen.get_monitor_geometry (
456
screen.get_monitor_at_window (mainwindow.get_window ()),
459
int width = 0, height = 0;
460
if (monitor.width > video_w && monitor.height > video_h) {
461
width = (int)video_w;
462
height = (int)video_h;
464
width = (int)(monitor.width * 0.9);
465
height = (int)((double)video_h / video_w * width);
468
var geom = Gdk.Geometry ();
469
if (settings.keep_aspect) {
470
geom.min_aspect = geom.max_aspect = video_w / (double)video_h;
472
geom.min_aspect = 0.0;
473
geom.max_aspect = 99999999.0;
476
mainwindow.get_window ().move_resize (monitor.width / 2 - width / 2 + monitor.x,
477
monitor.height / 2 - height / 2 + monitor.y,
480
if (settings.keep_aspect) {
481
mainwindow.get_window ().set_geometry_hints (geom, Gdk.WindowHints.ASPECT);
485
private void on_window_state_changed (Gdk.WindowState window_state) {
486
if (!((window_state & Gdk.WindowState.MAXIMIZED) == 0) && !video_player.fullscreened){
487
mainwindow.fullscreen ();
488
video_player.fullscreened = true;
492
private void setup_drag_n_drop () {
476
494
Gtk.TargetEntry uris = {"text/uri-list", 0, 0};
477
495
Gtk.drag_dest_set (mainwindow, Gtk.DestDefaults.ALL, {uris}, Gdk.DragAction.MOVE);
481
499
open_file (sel.get_uris ()[0]);
487
//save position in video when not finished playing
488
mainwindow.destroy.connect ( () => {
489
if (video_player.uri == null || video_player.uri == "" || video_player.uri.has_prefix ("dvd://"))
491
if (!video_player.at_end) {
492
for (var i = 0; i < last_played_videos.length (); i += 2){
493
if (video_player.uri == last_played_videos.nth_data (i)){
494
last_played_videos.nth (i+1).data = video_player.progress.to_string ();
495
save_last_played_videos ();
500
//not in list yet, insert at start
501
last_played_videos.insert (video_player.uri, 0);
502
last_played_videos.insert (video_player.progress.to_string (), 1);
503
if (last_played_videos.length () > 10) {
504
last_played_videos.delete_link (last_played_videos.nth (10));
505
last_played_videos.delete_link (last_played_videos.nth (11));
507
save_last_played_videos ();
506
private void on_destroy () {
507
if (video_player.uri == null || video_player.uri == "" || video_player.uri.has_prefix ("dvd://"))
509
if (!video_player.at_end) {
510
for (var i = 0; i < last_played_videos.length (); i += 2){
511
if (video_player.uri == last_played_videos.nth_data (i)){
512
last_played_videos.nth (i+1).data = video_player.progress.to_string ();
513
save_last_played_videos ();
518
//not in list yet, insert at start
519
last_played_videos.insert (video_player.uri, 0);
520
last_played_videos.insert (video_player.progress.to_string (), 1);
521
if (last_played_videos.length () > 10) {
522
last_played_videos.delete_link (last_played_videos.nth (10));
523
last_played_videos.delete_link (last_played_videos.nth (11));
525
save_last_played_videos ();
529
private int old_h = - 1;
530
private int old_w = - 1;
531
private void on_size_allocate (Gtk.Allocation alloc) {
532
if (alloc.width != old_w ||
533
alloc.height != old_h) {
534
if (video_player.relayout ()) {
536
old_h = alloc.height;
540
tagview.x = tagview.expanded ? stage.width - tagview.width + 10 : stage.width;
543
private bool update_pointer_position (double y, int window_height) {
544
int bottom_bar_size = 0;
546
bottom_bar.get_preferred_height (out minimum, out bottom_bar_size);
548
if (bottom_bar.child_revealed == false)
549
bottom_bar.set_reveal_child (true);
550
if (y >= window_height - bottom_bar_size && y < window_height) {
551
bottom_bar.hovered = true;
553
bottom_bar.hovered = false;
512
558
public void next_audio () {