json works, minor animations

This commit is contained in:
liyaowhen
2024-07-23 10:51:51 -07:00
parent 8b7d3d0c2e
commit c09d61bcdd
11 changed files with 271 additions and 129 deletions
+11 -2
View File
@@ -4,7 +4,7 @@ namespace Song {
public Settings settings = new Settings("com.liyaowhen.Song.playlists");
public MainViewContent main_content;
public string current_playlist;
public PlaylistObject current_playlist;
public MainView(Window _window) {
this.window = _window;
@@ -67,7 +67,6 @@ namespace Song {
public class MainViewContent : Gtk.Box {
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
private Adw.NavigationView navigation_view;
public PlaylistObject current_playlist;
@@ -84,6 +83,16 @@ namespace Song {
construct {
SongController.main_view_content = this;
var config = Config.get_instance();
config.config_changed.connect(() => {
if (config.playlists.length() == 1) {
config.playlists.foreach((i) => {
change_page(i);
return;
});
}
});
}
public void change_page(PlaylistObject playlist) {
+93
View File
@@ -0,0 +1,93 @@
namespace Song {
public class NewPlaylistPopover : Adw.Dialog {
private bool valid_entry = false;
private bool _isBoth_ = true;
construct {
valid_entry = false;
Gtk.Button cancel = new Gtk.Button.with_label ("Cancel");
cancel.clicked.connect(() => {
close();
});
Gtk.Button confirm = new Gtk.Button.with_label ("Confirm");
confirm.sensitive = false;
var header = new Adw.HeaderBar ();
header.show_end_title_buttons = false;
header.show_start_title_buttons = false;
header.pack_end (confirm);
header.pack_start (cancel);
Gtk.Entry entry = new Gtk.Entry();
set_focus(entry);
List<weak PlaylistObject> already_existing_playlists = Config.get_instance().playlists.copy();
Gee.HashSet<string> already_existing_playlists_string;
already_existing_playlists.foreach ((i) => {
already_existing_playlists_string.add(i.name);
});
entry.changed.connect(() => {
if (entry.get_buffer ().length == 0) {
valid_entry = false;
confirm.sensitive = false;
} else {
if (!already_existing_playlists_string.contains(entry.text)) {
valid_entry = true;
confirm.sensitive = true;
} else {
valid_entry = false;
confirm.sensitive = false;
}
}
});
confirm.clicked.connect(() => {
if (valid_entry) {
var config = Config.get_instance ();
var playlist = new PlaylistObject();
playlist.name = entry.text;
config.playlists.append(playlist);
config.save();
}
});
var is_song = new Gtk.CheckButton.with_label ("song");
var is_video = new Gtk.CheckButton.with_label("video");
var is_both = new Gtk.CheckButton.with_label ("both");
is_both.activate.connect(() => {
_isBoth_ = true;
is_song.sensitive = false;
is_video.sensitive = false;
});
var check_box_row = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 5);
check_box_row.vexpand = true;
check_box_row.hexpand = true;
check_box_row.halign = Gtk.Align.CENTER;
check_box_row.append(is_song);
check_box_row.append(is_video);
check_box_row.append(is_both);
// use settings to determine this later
is_both.set_active(true);
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 5);
box.append(entry);
box.append(check_box_row);
var content = new Adw.ToolbarView ();
content.add_top_bar (header);
content.set_content(box);
set_child(content);
set_title("Playlist Name");
}
}
}
+43 -10
View File
@@ -1,31 +1,64 @@
namespace Song {
public class PlaylistButton : Gtk.Button {
public class PlaylistButton : Gtk.Box {
private Settings settings = new Settings ("com.liyaowhen.Song");
public signal void removal_mode();
public signal void exit_removal_mode();
private PlaylistObject playlist;
private Gtk.Button remove_button;
private Gtk.Revealer remove_button_revealer;
public PlaylistButton (PlaylistObject _playlist) {
this.playlist = _playlist;
initialize();
}
construct {
orientation = Gtk.Orientation.HORIZONTAL;
add_css_class("toolbar");
remove_button = new Gtk.Button.from_icon_name("app-remove-symbolic");
remove_button_revealer = new Gtk.Revealer();
remove_button_revealer.set_child(remove_button);
remove_button_revealer.transition_type = Gtk.RevealerTransitionType.SWING_LEFT;
remove_button_revealer.set_reveal_child(false);
var main_button = new Gtk.Button();
main_button.hexpand = true;
append(main_button);
append(remove_button_revealer);
hexpand = true;
clicked.connect(() => {
main_button.clicked.connect(() => {
//assumes that main_view is already instanciated
SongController.main_view_content.change_page(playlist);
});
Timeout.add(1, () => {
if (playlist.name != null) {
main_button.label = playlist.name;
}
});
Config.get_instance().loaded.connect(() => {
if (playlist.name != null) {
main_button.label = playlist.name;
}
});
Config.get_instance().config_changed.connect(() => {
if (playlist.name != null) {
main_button.label = playlist.name;
}
});
}
public void initialize() {
set_label(playlist.name);
public void enter_removal_mode() {
remove_button_revealer.set_reveal_child(true);
}
public void exit_removal_mode() {
remove_button_revealer.set_reveal_child(false);
}
}
}
+40 -13
View File
@@ -38,7 +38,7 @@ namespace Song {
public class SideBarContent : Gtk.Box {
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
public List<PlaylistButton> playlist_buttons;
public Gee.HashSet<PlaylistButton> playlist_buttons = new Gee.HashSet<PlaylistButton>();
private MainView main_view;
public SideBarContent() {
@@ -79,10 +79,28 @@ namespace Song {
var button = new PlaylistButton(_playlist);
if (!firstDeclared) {initial_playlist = _playlist; firstDeclared = true;}
playlist_buttons.append(button);
playlist_buttons.add(button);
append(button);
});
config.config_changed.connect(() => {
playlist_buttons.clear();
config.playlists.foreach((_playlist) => {
var button = new PlaylistButton(_playlist);
playlist_buttons.add(button);
append(button);
});
});
Timeout.add(1000, () => {
if (playlist_buttons == null) {
print("\n playlist buttons empty");
} else {
print("\n playlist not empty");
}
});
//print("sidbar requesting main_view_content switch to playlist of name:\n" + playlists.nth_data(0).name);
Timeout.add(1, () => {
@@ -99,16 +117,6 @@ namespace Song {
}
/*private void reconfigure_playlist_button_group() {
foreach (Playlist i in playlists) {
foreach (Playlist j in playlists) {
if (i != j) {
i.set_group(j);
}
}
}
}*/
}
@@ -120,7 +128,7 @@ namespace Song {
public SideBarControls(SideBarContent _sidebar_content) {
this.sidebar_content = _sidebar_content;
}
construct {
@@ -147,6 +155,25 @@ namespace Song {
action_bar.pack_start(select_button);
//action_bar.set_center_widget(empty_spacer());
action_bar.pack_end(options_button);
select_button.toggled.connect((i) => {
if (sidebar_content == null) {
print("\n sidebar is null");
} else if (sidebar_content.playlist_buttons == null) {
print("\n sidebar buttons are null");
}
if (i.get_active()) {
sidebar_content.playlist_buttons.foreach((e) => {
e.enter_removal_mode();
print(e.name);
});
} else {
sidebar_content.playlist_buttons.foreach((e) => {
e.exit_removal_mode();
print(e.name);
});
}
});
// signals
+6 -8
View File
@@ -12,10 +12,11 @@ namespace Song {
private bool isDragging;
private Gtk.Button progress_bar_controller;
private string item_directory = Path.build_path("/", Environment.get_user_config_dir(), "com.liyaowhen.Song");
public bool isPlaying;
public PlaylistItem current_item;
public Gst.Element playbin;
public SongControls() {
@@ -52,12 +53,9 @@ namespace Song {
}
print(position.to_string() + "\n" + duration.to_string() + "\n");
} else {
if (isDragging) print("stillDragging");
if (playbin == null) print("playbinnull");
print("what went wrong");
}
print("working");
return true;
});
@@ -144,9 +142,9 @@ namespace Song {
string file_path = item.file;
print("song full path is " + file_path);
playbin.set_state(Gst.State.NULL);
playbin.set_property("uri", file_path);
//playbin.set_state(Gst.State.PLAYING);
//isPlaying = true;
playbin.set_property("uri", File.new_for_path(file_path).get_uri());
playbin.set_state(Gst.State.PLAYING);
isPlaying = true;
}