Prettify code
Signed-off-by: Vasiliy Doylov <nekocwd@mainlining.org>
This commit is contained in:
parent
c37bd1caae
commit
562ec9e94d
6 changed files with 69 additions and 81 deletions
|
@ -6,7 +6,7 @@
|
|||
* Author: Vasiliy Doylov <nekocwd@mainlining.org>
|
||||
*/
|
||||
|
||||
namespace MediaPlayer {
|
||||
namespace MediaPlayer {
|
||||
Gtk.CssProvider css;
|
||||
[ModuleInit]
|
||||
[CCode (cname = "g_io_phosh_plugin_media_player_load")]
|
||||
|
|
|
@ -25,6 +25,7 @@ sources = files(
|
|||
'extension.vala',
|
||||
'player.vala',
|
||||
'qs.vala',
|
||||
'utils.vala',
|
||||
)
|
||||
|
||||
shared_module(
|
||||
|
|
|
@ -32,6 +32,7 @@ public class MediaPlayer.Player : Gtk.Box {
|
|||
}
|
||||
|
||||
~Player () {
|
||||
warning ("Destructor");
|
||||
Gtk.StyleContext.remove_provider_for_screen (Gdk.Screen.get_default (), css_provider);
|
||||
}
|
||||
|
||||
|
@ -151,15 +152,16 @@ public class MediaPlayer.Player : Gtk.Box {
|
|||
switch (child.get_name ()) {
|
||||
case "img_art" :
|
||||
child.notify["gicon"].connect (() => process_icon.begin (((Gtk.Image) child).gicon));
|
||||
child.notify_property ("gicon");
|
||||
break;
|
||||
default :
|
||||
foreach (var child2 in ((Gtk.Box) child).get_children ()) {
|
||||
switch (child2.get_name ()) {
|
||||
case "lbl_artist" :
|
||||
child2.bind_property ("label", artist, "label");
|
||||
child2.bind_property ("label", artist, "label", BindingFlags.SYNC_CREATE);
|
||||
break;
|
||||
case "lbl_title":
|
||||
child2.bind_property ("label", title, "label");
|
||||
child2.bind_property ("label", title, "label", BindingFlags.SYNC_CREATE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
95
src/qs.vala
95
src/qs.vala
|
@ -14,93 +14,32 @@ using GLib;
|
|||
|
||||
public class MediaPlayer.QuickSetting : Phosh.QuickSetting {
|
||||
private Player player = new Player () { margin_top = 24 };
|
||||
private Gtk.Widget? hiden_player = null;
|
||||
private Gtk.Widget? old_player = null;
|
||||
|
||||
construct {
|
||||
parent_set.connect (() => replace_player (Stage.QickSettings_Box));
|
||||
visible = false;
|
||||
var ts = new TimeoutSource (500);
|
||||
ts.set_callback (() => try_replace_player ());
|
||||
ts.attach ();
|
||||
}
|
||||
|
||||
enum Stage {
|
||||
QickSettings_Box = 0,
|
||||
QickSettings,
|
||||
BoxSettings;
|
||||
|
||||
public string to_string () {
|
||||
return ((EnumClass) typeof (Stage).class_ref ()).get_value (this).value_nick.up ();
|
||||
}
|
||||
~QuickSetting () {
|
||||
if (old_player != null)
|
||||
Utils.replace_widget (player, old_player);
|
||||
}
|
||||
|
||||
void replace_player (Stage stage) {
|
||||
if (parent == null) {
|
||||
if (stage == Stage.QickSettings_Box)
|
||||
clean_up ();
|
||||
return;
|
||||
}
|
||||
if (hiden_player != null)
|
||||
return;
|
||||
message ("Replace player: Stage %d %s", stage, stage.to_string ());
|
||||
if (stage != Stage.BoxSettings) {
|
||||
var _p = parent;
|
||||
for (uint i = 0; i < stage; i++)
|
||||
_p = _p.parent;
|
||||
if (_p.parent != null)
|
||||
replace_player (stage + 1);
|
||||
_p.parent_set.connect (() => replace_player (stage + 1));
|
||||
return;
|
||||
}
|
||||
Gtk.Box box = (Gtk.Box) parent.parent.parent;
|
||||
foreach (var child in box.get_children ())
|
||||
on_something_added (child);
|
||||
box.add.connect ((w) => on_something_added (w));
|
||||
}
|
||||
bool try_replace_player () {
|
||||
var anc = get_ancestor (Type.from_name ("PhoshSettings"));
|
||||
if (anc == null)
|
||||
return true;
|
||||
|
||||
void on_something_added (Gtk.Widget widget) {
|
||||
if (hiden_player != null)
|
||||
return;
|
||||
old_player = Utils.find_widget_by_name (anc, "PhoshDefaultMediaPlayer");
|
||||
if (old_player == null)
|
||||
return true;
|
||||
|
||||
if (widget.get_type ().is_a (typeof (Gtk.Container))) {
|
||||
((Gtk.Container) widget).add.connect ((w) => on_something_added (w));
|
||||
}
|
||||
Utils.replace_widget (old_player, player);
|
||||
player.bind_to_player ((Gtk.Box) old_player);
|
||||
|
||||
Gtk.Box box = (Gtk.Box) parent.parent.parent;
|
||||
find_player (box);
|
||||
}
|
||||
|
||||
void find_player (Gtk.Container container) {
|
||||
if (hiden_player != null)
|
||||
return;
|
||||
var i = 0;
|
||||
foreach (var child in container.get_children ()) {
|
||||
if (child.name == "PhoshDefaultMediaPlayer") {
|
||||
message ("Player found");
|
||||
player.bind_to_player ((Gtk.Box) child);
|
||||
container.add (player);
|
||||
var b = (Gtk.Box) container;
|
||||
b.reorder_child (player, i);
|
||||
hiden_player = child;
|
||||
container.remove (hiden_player);
|
||||
}
|
||||
if (child.get_type ().is_a (typeof (Gtk.Container))) {
|
||||
find_player ((Gtk.Container) child);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void clean_up () {
|
||||
player.dispose ();
|
||||
if (player.parent != null) {
|
||||
var i = 0;
|
||||
foreach (var child in player.parent.get_children ()) {
|
||||
if (child == player) {
|
||||
parent.add (hiden_player);
|
||||
((Gtk.Box) parent).reorder_child (hiden_player, i);
|
||||
player.parent.remove (player);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
hiden_player = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,3 +21,8 @@
|
|||
.nekoplayer image {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#top-bar-bin {
|
||||
background-color: rgba(255, 0, 0, 0.5);
|
||||
padding-top: 100px;
|
||||
}
|
||||
|
|
41
src/utils.vala
Normal file
41
src/utils.vala
Normal file
|
@ -0,0 +1,41 @@
|
|||
namespace Utils {
|
||||
public delegate bool FindDelegate (Gtk.Widget widget);
|
||||
|
||||
public Gtk.Widget ? find_widget (Gtk.Widget widget, FindDelegate find_func) {
|
||||
if (find_func (widget)) {
|
||||
return widget;
|
||||
}
|
||||
if (widget is Gtk.Container) {
|
||||
foreach (var child in ((Gtk.Container) widget).get_children ()) {
|
||||
var found = find_widget (child, find_func);
|
||||
if (found != null)
|
||||
return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Gtk.Widget ? find_widget_by_name (Gtk.Widget widget, string name) {
|
||||
return find_widget (widget, (w) => w.name == name);
|
||||
}
|
||||
|
||||
public int get_box_position (Gtk.Box box, Gtk.Widget child) {
|
||||
var i = 0;
|
||||
foreach (var _child in box.get_children ()) {
|
||||
if (_child == child)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void replace_widget (Gtk.Widget old, Gtk.Widget replacement) {
|
||||
var container = old.parent;
|
||||
container.add (replacement);
|
||||
if (container is Gtk.Box) {
|
||||
var box = (Gtk.Box) container;
|
||||
var position = get_box_position (box, old);
|
||||
box.reorder_child (replacement, position);
|
||||
}
|
||||
container.remove (old);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue