Skip to content

Commit

Permalink
BottomBar.vala: Code cleanups (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Scott authored and codygarver committed Oct 10, 2017
1 parent 4e732e9 commit aa9ab20
Showing 1 changed file with 89 additions and 56 deletions.
145 changes: 89 additions & 56 deletions src/Widgets/Player/BottomBar.vala
Expand Up @@ -27,9 +27,6 @@ public class Audience.Widgets.BottomBar : Gtk.Revealer {
public signal void unfullscreen ();
public signal void seeked (double val);

public bool playing { get; set; default=false; }
public bool hovered { get; set; default=false; }
public bool fullscreen { get; set; default=false; }
public SettingsPopover preferences_popover;
public PlaylistPopover playlist_popover;
public TimeWidget time_widget;
Expand All @@ -41,6 +38,58 @@ public class Audience.Widgets.BottomBar : Gtk.Revealer {
private uint hiding_timer = 0;
private bool playlist_glowing = false;

private bool _fullscreen = false;
public bool fullscreen {
get {
return _fullscreen;
}
set {
_fullscreen = value;
if (value && child_revealed) {
unfullscreen_revealer.reveal_child = true;
} else if (!value && child_revealed) {
unfullscreen_revealer.reveal_child = false;
}
}
}

private bool _hovered = false;
private bool hovered {
get {
return _hovered;
}
set {
_hovered = value;
if (value) {
if (hiding_timer != 0) {
Source.remove (hiding_timer);
hiding_timer = 0;
}
} else {
reveal_control ();
}
}
}

private bool _playing = false;
public bool playing {
get {
return _playing;
}
set {
_playing = value;
if (value) {
((Gtk.Image) play_button.image).icon_name = "media-playback-pause-symbolic";
play_button.tooltip_text = _("Pause");
reveal_control ();
} else {
((Gtk.Image) play_button.image).icon_name = "media-playback-start-symbolic";
play_button.tooltip_text = _("Play");
set_reveal_child (true);
}
}
}

public bool repeat {
get {
return playlist_popover.rep.active;
Expand All @@ -55,26 +104,39 @@ public class Audience.Widgets.BottomBar : Gtk.Revealer {
this.events |= Gdk.EventMask.LEAVE_NOTIFY_MASK;
this.events |= Gdk.EventMask.ENTER_NOTIFY_MASK;

this.enter_notify_event.connect ((event) => { this.hovered = true; return false; });
this.leave_notify_event.connect ((event) => { this.hovered = false; return false; });
this.enter_notify_event.connect ((event) => {
this.hovered = true;
return false;
});

this.leave_notify_event.connect ((event) => {
this.hovered = false;
return false;
});

this.transition_type = Gtk.RevealerTransitionType.SLIDE_UP;

var main_actionbar = new Gtk.ActionBar ();

play_button = new Gtk.Button.from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.BUTTON);
play_button.tooltip_text = _("Play");
play_button.clicked.connect (() => {play_toggled ();});
play_button.clicked.connect (() => {
playing = !playing;
play_toggled ();
});

playlist_button = new Gtk.Button.from_icon_name ("view-list-symbolic", Gtk.IconSize.BUTTON);
playlist_button.tooltip_text = _("Playlist");
playlist_button.clicked.connect (() => {playlist_popover.show_all (); playlist_popover.queue_resize ();});
playlist_button.clicked.connect (() => {
playlist_popover.show_all ();
playlist_popover.queue_resize ();
});

preferences_button = new Gtk.Button.from_icon_name ("open-menu-symbolic", Gtk.IconSize.BUTTON);
preferences_button.tooltip_text = _("Settings");
preferences_button.clicked.connect (() => {
preferences_popover.setup ();
preferences_popover.show_all ();
preferences_popover.show_all ();
preferences_popover.queue_resize ();
});

Expand All @@ -95,40 +157,16 @@ public class Audience.Widgets.BottomBar : Gtk.Revealer {
playlist_item_added ();
});

notify["hovered"].connect (() => {
if (hovered == false) {
reveal_control ();
} else {
if (hiding_timer != 0) {
Source.remove (hiding_timer);
hiding_timer = 0;
}
}
});

notify["fullscreen"].connect (() => {
if (fullscreen == true && child_revealed == true) {
unfullscreen_revealer.set_reveal_child (true);
} else if (fullscreen == false && child_revealed == true) {
unfullscreen_revealer.set_reveal_child (false);
}
});

play_button.clicked.connect (() => {
playing = !playing;
var unfullscreen_button = new Gtk.Button.from_icon_name ("view-restore-symbolic", Gtk.IconSize.BUTTON);
unfullscreen_button.tooltip_text = _("Unfullscreen");
unfullscreen_button.clicked.connect (() => {
unfullscreen ();
});

notify["playing"].connect (() => {
if (playing == true) {
((Gtk.Image) play_button.image).icon_name = "media-playback-pause-symbolic";
play_button.tooltip_text = _("Pause");
reveal_control ();
} else {
((Gtk.Image) play_button.image).icon_name = "media-playback-start-symbolic";
play_button.tooltip_text = _("Play");
set_reveal_child (true);
}
});
unfullscreen_revealer = new Gtk.Revealer ();
unfullscreen_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
unfullscreen_revealer.add (unfullscreen_button);
unfullscreen_revealer.show_all ();

show_all ();
}
Expand All @@ -138,7 +176,7 @@ public class Audience.Widgets.BottomBar : Gtk.Revealer {
playlist_glowing = true;
playlist_button.get_child ().get_style_context ().add_class (PULSE_CLASS);
playlist_button.get_child ().get_style_context ().add_class (PULSE_TYPE);

Timeout.add (6000, () => {
playlist_button.get_child ().get_style_context ().remove_class (PULSE_CLASS);
playlist_button.get_child ().get_style_context ().remove_class (PULSE_TYPE);
Expand All @@ -149,30 +187,23 @@ public class Audience.Widgets.BottomBar : Gtk.Revealer {
}

public Gtk.Revealer get_unfullscreen_button () {
unfullscreen_revealer = new Gtk.Revealer ();
unfullscreen_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;

var unfullscreen_button = new Gtk.Button.from_icon_name ("view-restore-symbolic", Gtk.IconSize.BUTTON);
unfullscreen_button.tooltip_text = _("Unfullscreen");
unfullscreen_button.clicked.connect (() => {unfullscreen ();});
unfullscreen_revealer.add (unfullscreen_button);
unfullscreen_revealer.show_all ();
return unfullscreen_revealer;
}

private new void set_reveal_child (bool reveal) {
base.set_reveal_child (reveal);
if (reveal == true && fullscreen == true) {
unfullscreen_revealer.set_reveal_child (reveal);
unfullscreen_revealer.reveal_child = reveal;
} else if (reveal == false) {
unfullscreen_revealer.set_reveal_child (reveal);
unfullscreen_revealer.reveal_child = reveal;
}
}

public override void get_preferred_width (out int minimum_width, out int natural_width) {
base.get_preferred_width (out minimum_width, out natural_width);
if (parent.get_window () == null)
if (parent.get_window () == null) {
return;
}

var width = parent.get_window ().get_width ();
if (width > 0 && width >= minimum_width) {
Expand All @@ -181,19 +212,21 @@ public class Audience.Widgets.BottomBar : Gtk.Revealer {
}

public void reveal_control () {
if (child_revealed == false)
if (child_revealed == false) {
set_reveal_child (true);
}

if (hiding_timer != 0)
if (hiding_timer != 0) {
Source.remove (hiding_timer);
}

hiding_timer = GLib.Timeout.add (2000, () => {
if (hovered == true || preferences_popover.visible == true || playlist_popover.visible == true || playing == false) {
if (hovered || preferences_popover.visible || playlist_popover.visible || !playing) {
hiding_timer = 0;
return false;
}
set_reveal_child (false);
unfullscreen_revealer.set_reveal_child (false);
unfullscreen_revealer.reveal_child = false;
hiding_timer = 0;
return false;
});
Expand Down

0 comments on commit aa9ab20

Please sign in to comment.