mirror of
https://gitlab.com/liyaowhen/youtubecollector-git.git
synced 2026-10-01 01:12:59 +00:00
json works in essence
This commit is contained in:
+23
-25
@@ -69,7 +69,7 @@ namespace Song {
|
||||
|
||||
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
|
||||
private Adw.NavigationView navigation_view;
|
||||
public string current_playlist;
|
||||
public PlaylistObject current_playlist;
|
||||
|
||||
public MainViewContent() {
|
||||
vexpand = true;
|
||||
@@ -86,24 +86,12 @@ namespace Song {
|
||||
SongController.main_view_content = this;
|
||||
}
|
||||
|
||||
public void change_page(string playlist_name) {
|
||||
public void change_page(PlaylistObject playlist) {
|
||||
print("change page called");
|
||||
|
||||
bool isKeyValid = false;
|
||||
foreach (string key in settings.list_keys()){
|
||||
if (key == playlist_name) {
|
||||
print("valid playlist");
|
||||
isKeyValid = true;
|
||||
}
|
||||
}
|
||||
if (!isKeyValid) {
|
||||
print("invalid playlist_name");
|
||||
return;
|
||||
}
|
||||
current_playlist = playlist;
|
||||
|
||||
current_playlist = playlist_name;
|
||||
|
||||
string[] songs = settings.get_strv(playlist_name);
|
||||
/*string[] songs = settings.get_strv(playlist_name);
|
||||
print("\n playlist contains: \n" + songs[1]);
|
||||
if (songs.length == 1) {
|
||||
if (songs[0] == "") {empty_playlist_ui(playlist_name); return;}
|
||||
@@ -115,39 +103,49 @@ namespace Song {
|
||||
print("making a page with actual content");
|
||||
playlist_ui(playlist_name);
|
||||
}
|
||||
}*/
|
||||
|
||||
if (playlist.items.is_empty()) {
|
||||
empty_playlist_ui(playlist);
|
||||
return;
|
||||
} else {
|
||||
playlist_ui(playlist);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void empty_playlist_ui(string playlist_name) {
|
||||
private void empty_playlist_ui(PlaylistObject playlist) {
|
||||
var empty_page = new Adw.StatusPage();
|
||||
var parent_page = new Adw.NavigationPage(empty_page,"no songs added");
|
||||
empty_page.set_title("Empty Playlist " + playlist_name);
|
||||
empty_page.set_title("Empty Playlist " + playlist.name);
|
||||
empty_page.set_icon_name("edit-find-symbolic");
|
||||
empty_page.set_description("Click the button on the top left to add songs in this playlist.");
|
||||
navigation_view.push(parent_page);
|
||||
}
|
||||
|
||||
private void playlist_ui(string playlist_name) {
|
||||
private void playlist_ui(PlaylistObject playlist) {
|
||||
var playlist_page = new Adw.StatusPage();
|
||||
playlist_page.set_title(playlist_name);
|
||||
playlist_page.set_title(playlist.name);
|
||||
playlist_page.set_icon_name("emblem-music-symbolic");
|
||||
|
||||
load_music(playlist_page, playlist_name);
|
||||
load_music(playlist_page, playlist);
|
||||
|
||||
var parent_page = new Adw.NavigationPage(playlist_page, playlist_name);
|
||||
var parent_page = new Adw.NavigationPage(playlist_page, playlist.name);
|
||||
navigation_view.push(parent_page);
|
||||
}
|
||||
|
||||
private void load_music(Adw.StatusPage page, string playlist_name) {
|
||||
private void load_music(Adw.StatusPage page, PlaylistObject playlist) {
|
||||
Adw.Clamp clamp = new Adw.Clamp();
|
||||
Gtk.ListBox content = new Gtk.ListBox();
|
||||
foreach (string i in settings.get_strv(playlist_name)) {
|
||||
/*foreach (string i in settings.get_strv(playlist_name)) {
|
||||
if (i != "") {
|
||||
content.append(new MusicListRow(i));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
playlist.items.foreach((item) => {
|
||||
content.append(new MusicListRow(item));
|
||||
});
|
||||
clamp.child = content;
|
||||
page.child = clamp;
|
||||
content.hexpand = true;
|
||||
|
||||
@@ -2,10 +2,10 @@ namespace Song {
|
||||
public class MusicListRow : Gtk.Box {
|
||||
|
||||
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
|
||||
public string song_name;
|
||||
public PlaylistItem item;
|
||||
|
||||
public MusicListRow (string _song_name) {
|
||||
this.song_name = _song_name;
|
||||
public MusicListRow (PlaylistItem _item) {
|
||||
this.item = _item;
|
||||
build_ui();
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace Song {
|
||||
}
|
||||
|
||||
private void build_ui() {
|
||||
var label = new Gtk.Label (song_name);
|
||||
print(song_name + "making playlists song button");
|
||||
var label = new Gtk.Label (item.name);
|
||||
print(item.name + "making playlists song button");
|
||||
label.hexpand = true;
|
||||
append(label);
|
||||
|
||||
@@ -33,11 +33,11 @@ namespace Song {
|
||||
play_button.add_css_class("flat");
|
||||
|
||||
play_button.clicked.connect(() => {
|
||||
if (SongController.song_controls.current_song != song_name) {
|
||||
SongController.song_controls.change_song(song_name);
|
||||
if (SongController.song_controls.current_item != item) {
|
||||
SongController.song_controls.change_item(item);
|
||||
play_button.icon_name = "media-playback-pause-symbolic";
|
||||
Timeout.add(1, () => {
|
||||
if (SongController.song_controls.current_song != song_name) {
|
||||
if (SongController.song_controls.current_item != item) {
|
||||
// when another song is called to play, reset the button state
|
||||
play_button.icon_name = "media-playback-start-symbolic";
|
||||
return false;
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
namespace Song {
|
||||
public class Playlist : Gtk.Button {
|
||||
public class PlaylistButton : Gtk.Button {
|
||||
|
||||
private Settings settings = new Settings ("com.liyaowhen.Song");
|
||||
|
||||
public signal void removal_mode();
|
||||
public signal void exit_removal_mode();
|
||||
|
||||
private string playlist_name;
|
||||
private PlaylistObject playlist;
|
||||
|
||||
public Playlist (string _playlist_name) {
|
||||
this.playlist_name = _playlist_name;
|
||||
public PlaylistButton (PlaylistObject _playlist) {
|
||||
this.playlist = _playlist;
|
||||
|
||||
initialize();
|
||||
}
|
||||
@@ -19,12 +19,12 @@ namespace Song {
|
||||
|
||||
clicked.connect(() => {
|
||||
//assumes that main_view is already instanciated
|
||||
SongController.main_view_content.change_page(playlist_name);
|
||||
SongController.main_view_content.change_page(playlist);
|
||||
});
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
set_label(playlist_name);
|
||||
set_label(playlist.name);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Song {
|
||||
public class SideBarContent : Gtk.Box {
|
||||
|
||||
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
|
||||
public List<Playlist> playlists;
|
||||
public List<PlaylistButton> playlist_buttons;
|
||||
private MainView main_view;
|
||||
|
||||
public SideBarContent() {
|
||||
@@ -60,22 +60,34 @@ namespace Song {
|
||||
vexpand_set = true;
|
||||
hexpand_set = true;
|
||||
|
||||
Playlist initial_playlist;
|
||||
PlaylistObject initial_playlist;
|
||||
|
||||
var playlist_names = settings.get_strv("playlists");
|
||||
/*var playlist_names = settings.get_strv("playlists");
|
||||
foreach (string _name in playlist_names) {
|
||||
var playlist = new Playlist(_name);
|
||||
var playlist = new PlaylistButton(_name);
|
||||
if (_name == playlist_names[0]) {
|
||||
initial_playlist = playlist;
|
||||
}
|
||||
playlists.append(playlist);
|
||||
append(playlist);
|
||||
}
|
||||
}*/
|
||||
|
||||
print("sidbar requesting main_view_content switch to playlist of name:\n" + playlist_names[1]);
|
||||
Config config = Config.get_instance();
|
||||
|
||||
bool firstDeclared = false;
|
||||
config.playlists.foreach((_playlist) => {
|
||||
var button = new PlaylistButton(_playlist);
|
||||
if (!firstDeclared) {initial_playlist = _playlist; firstDeclared = true;}
|
||||
|
||||
playlist_buttons.append(button);
|
||||
append(button);
|
||||
});
|
||||
|
||||
|
||||
//print("sidbar requesting main_view_content switch to playlist of name:\n" + playlists.nth_data(0).name);
|
||||
Timeout.add(1, () => {
|
||||
if (SongController.main_view_content != null) {
|
||||
SongController.main_view_content.change_page(playlist_names[0]);
|
||||
SongController.main_view_content.change_page(initial_playlist);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Song {
|
||||
private Gtk.Button progress_bar_controller;
|
||||
|
||||
public bool isPlaying;
|
||||
public string current_song;
|
||||
public PlaylistItem current_item;
|
||||
|
||||
|
||||
public Gst.Element playbin;
|
||||
@@ -123,7 +123,7 @@ namespace Song {
|
||||
}
|
||||
|
||||
private void play_music() {
|
||||
if (current_song != null) {
|
||||
if (current_item != null) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -138,15 +138,15 @@ namespace Song {
|
||||
isPlaying = false;
|
||||
}
|
||||
|
||||
public void change_song(string song) {
|
||||
print("song is now " + song + "\n");
|
||||
current_song = song;
|
||||
string file_path = "file://" + settings.get_string("song-folder") + "/" + current_song + ".mp3";
|
||||
public void change_item(PlaylistItem item) {
|
||||
print("song is now " + item.name + "\n");
|
||||
current_item = item;
|
||||
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_state(Gst.State.PLAYING);
|
||||
//isPlaying = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user