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:
@@ -55,11 +55,11 @@ namespace Song {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Config() {
|
private Config() {
|
||||||
playlists = new List<PlaylistObject>();
|
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void load() {
|
private async void load() {
|
||||||
|
playlists = new List<PlaylistObject>();
|
||||||
print("load");
|
print("load");
|
||||||
File config_file = File.new_for_path(config_file_path);
|
File config_file = File.new_for_path(config_file_path);
|
||||||
if (config_file.query_exists(null)) {
|
if (config_file.query_exists(null)) {
|
||||||
@@ -117,6 +117,11 @@ namespace Song {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*public List<PlaylistObject> get_playlists() {
|
||||||
|
|
||||||
|
return playlists.;
|
||||||
|
}*/
|
||||||
|
|
||||||
// Save configuration to file
|
// Save configuration to file
|
||||||
public async void save() {
|
public async void save() {
|
||||||
print("save");
|
print("save");
|
||||||
@@ -214,7 +219,7 @@ namespace Song {
|
|||||||
File config_file = File.new_for_path(config_file_path);
|
File config_file = File.new_for_path(config_file_path);
|
||||||
if (!config_file.query_exists(null)) {
|
if (!config_file.query_exists(null)) {
|
||||||
print("file never existed");
|
print("file never existed");
|
||||||
Config.get_instance().save(); // Create the file with default values
|
Config.get_instance().save.begin(); // Create the file with default values
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-23
@@ -1,23 +1,3 @@
|
|||||||
/* main.vala
|
|
||||||
*
|
|
||||||
* Copyright 2024 Leo Wen
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main (string[] args) {
|
int main (string[] args) {
|
||||||
Gst.init(ref args);
|
Gst.init(ref args);
|
||||||
|
|
||||||
@@ -26,11 +6,9 @@ int main (string[] args) {
|
|||||||
|
|
||||||
Song.PlaylistObject playlist = new Song.PlaylistObject();
|
Song.PlaylistObject playlist = new Song.PlaylistObject();
|
||||||
playlist.name = "QQ";
|
playlist.name = "QQ";
|
||||||
playlist.add_item(Song.PlaylistItem.load_item(Song.ItemType.AUDIO, "aaa", "eee"));
|
|
||||||
|
|
||||||
config.playlists.append(playlist);
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
var app = new Song.Application ();
|
var app = new Song.Application ();
|
||||||
|
|
||||||
return app.run (args);
|
return app.run (args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,14 +281,14 @@ namespace Song {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (file_valid) {
|
if (file_valid) {
|
||||||
if (SongController.main_view_content == null) return;
|
/*if (SongController.main_view_content == null) return;
|
||||||
var main_content = SongController.main_view_content;
|
var main_content = SongController.main_view_content;
|
||||||
string[] _string_array = _list.get_strv(main_content.current_playlist);
|
string[] _string_array = _list.get_strv(main_content.current_playlist.name);
|
||||||
_string_array += song_title;
|
_string_array += song_title;
|
||||||
_list.set_strv(main_content.current_playlist, _string_array);
|
_list.set_strv(main_content.current_playlist, _string_array);
|
||||||
foreach(string str in _list.get_strv(main_content.current_playlist)) {
|
foreach(string str in _list.get_strv(main_content.current_playlist)) {
|
||||||
print("this playlist has \n" + str);
|
print("this playlist has \n" + str);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO implement error page
|
//TODO implement error page
|
||||||
|
|||||||
+23
-25
@@ -69,7 +69,7 @@ namespace Song {
|
|||||||
|
|
||||||
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
|
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
|
||||||
private Adw.NavigationView navigation_view;
|
private Adw.NavigationView navigation_view;
|
||||||
public string current_playlist;
|
public PlaylistObject current_playlist;
|
||||||
|
|
||||||
public MainViewContent() {
|
public MainViewContent() {
|
||||||
vexpand = true;
|
vexpand = true;
|
||||||
@@ -86,24 +86,12 @@ namespace Song {
|
|||||||
SongController.main_view_content = this;
|
SongController.main_view_content = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void change_page(string playlist_name) {
|
public void change_page(PlaylistObject playlist) {
|
||||||
print("change page called");
|
print("change page called");
|
||||||
|
|
||||||
bool isKeyValid = false;
|
current_playlist = playlist;
|
||||||
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_name;
|
/*string[] songs = settings.get_strv(playlist_name);
|
||||||
|
|
||||||
string[] songs = settings.get_strv(playlist_name);
|
|
||||||
print("\n playlist contains: \n" + songs[1]);
|
print("\n playlist contains: \n" + songs[1]);
|
||||||
if (songs.length == 1) {
|
if (songs.length == 1) {
|
||||||
if (songs[0] == "") {empty_playlist_ui(playlist_name); return;}
|
if (songs[0] == "") {empty_playlist_ui(playlist_name); return;}
|
||||||
@@ -115,39 +103,49 @@ namespace Song {
|
|||||||
print("making a page with actual content");
|
print("making a page with actual content");
|
||||||
playlist_ui(playlist_name);
|
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 empty_page = new Adw.StatusPage();
|
||||||
var parent_page = new Adw.NavigationPage(empty_page,"no songs added");
|
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_icon_name("edit-find-symbolic");
|
||||||
empty_page.set_description("Click the button on the top left to add songs in this playlist.");
|
empty_page.set_description("Click the button on the top left to add songs in this playlist.");
|
||||||
navigation_view.push(parent_page);
|
navigation_view.push(parent_page);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void playlist_ui(string playlist_name) {
|
private void playlist_ui(PlaylistObject playlist) {
|
||||||
var playlist_page = new Adw.StatusPage();
|
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");
|
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);
|
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();
|
Adw.Clamp clamp = new Adw.Clamp();
|
||||||
Gtk.ListBox content = new Gtk.ListBox();
|
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 != "") {
|
if (i != "") {
|
||||||
content.append(new MusicListRow(i));
|
content.append(new MusicListRow(i));
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
playlist.items.foreach((item) => {
|
||||||
|
content.append(new MusicListRow(item));
|
||||||
|
});
|
||||||
clamp.child = content;
|
clamp.child = content;
|
||||||
page.child = clamp;
|
page.child = clamp;
|
||||||
content.hexpand = true;
|
content.hexpand = true;
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ namespace Song {
|
|||||||
public class MusicListRow : Gtk.Box {
|
public class MusicListRow : Gtk.Box {
|
||||||
|
|
||||||
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
|
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
|
||||||
public string song_name;
|
public PlaylistItem item;
|
||||||
|
|
||||||
public MusicListRow (string _song_name) {
|
public MusicListRow (PlaylistItem _item) {
|
||||||
this.song_name = _song_name;
|
this.item = _item;
|
||||||
build_ui();
|
build_ui();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,8 +23,8 @@ namespace Song {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void build_ui() {
|
private void build_ui() {
|
||||||
var label = new Gtk.Label (song_name);
|
var label = new Gtk.Label (item.name);
|
||||||
print(song_name + "making playlists song button");
|
print(item.name + "making playlists song button");
|
||||||
label.hexpand = true;
|
label.hexpand = true;
|
||||||
append(label);
|
append(label);
|
||||||
|
|
||||||
@@ -33,11 +33,11 @@ namespace Song {
|
|||||||
play_button.add_css_class("flat");
|
play_button.add_css_class("flat");
|
||||||
|
|
||||||
play_button.clicked.connect(() => {
|
play_button.clicked.connect(() => {
|
||||||
if (SongController.song_controls.current_song != song_name) {
|
if (SongController.song_controls.current_item != item) {
|
||||||
SongController.song_controls.change_song(song_name);
|
SongController.song_controls.change_item(item);
|
||||||
play_button.icon_name = "media-playback-pause-symbolic";
|
play_button.icon_name = "media-playback-pause-symbolic";
|
||||||
Timeout.add(1, () => {
|
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
|
// when another song is called to play, reset the button state
|
||||||
play_button.icon_name = "media-playback-start-symbolic";
|
play_button.icon_name = "media-playback-start-symbolic";
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
namespace Song {
|
namespace Song {
|
||||||
public class Playlist : Gtk.Button {
|
public class PlaylistButton : Gtk.Button {
|
||||||
|
|
||||||
private Settings settings = new Settings ("com.liyaowhen.Song");
|
private Settings settings = new Settings ("com.liyaowhen.Song");
|
||||||
|
|
||||||
public signal void removal_mode();
|
public signal void removal_mode();
|
||||||
public signal void exit_removal_mode();
|
public signal void exit_removal_mode();
|
||||||
|
|
||||||
private string playlist_name;
|
private PlaylistObject playlist;
|
||||||
|
|
||||||
public Playlist (string _playlist_name) {
|
public PlaylistButton (PlaylistObject _playlist) {
|
||||||
this.playlist_name = _playlist_name;
|
this.playlist = _playlist;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
@@ -19,12 +19,12 @@ namespace Song {
|
|||||||
|
|
||||||
clicked.connect(() => {
|
clicked.connect(() => {
|
||||||
//assumes that main_view is already instanciated
|
//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() {
|
public void initialize() {
|
||||||
set_label(playlist_name);
|
set_label(playlist.name);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace Song {
|
|||||||
public class SideBarContent : Gtk.Box {
|
public class SideBarContent : Gtk.Box {
|
||||||
|
|
||||||
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
|
private Settings settings = new Settings("com.liyaowhen.Song.playlists");
|
||||||
public List<Playlist> playlists;
|
public List<PlaylistButton> playlist_buttons;
|
||||||
private MainView main_view;
|
private MainView main_view;
|
||||||
|
|
||||||
public SideBarContent() {
|
public SideBarContent() {
|
||||||
@@ -60,22 +60,34 @@ namespace Song {
|
|||||||
vexpand_set = true;
|
vexpand_set = true;
|
||||||
hexpand_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) {
|
foreach (string _name in playlist_names) {
|
||||||
var playlist = new Playlist(_name);
|
var playlist = new PlaylistButton(_name);
|
||||||
if (_name == playlist_names[0]) {
|
if (_name == playlist_names[0]) {
|
||||||
initial_playlist = playlist;
|
initial_playlist = playlist;
|
||||||
}
|
}
|
||||||
playlists.append(playlist);
|
playlists.append(playlist);
|
||||||
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, () => {
|
Timeout.add(1, () => {
|
||||||
if (SongController.main_view_content != null) {
|
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;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Song {
|
|||||||
private Gtk.Button progress_bar_controller;
|
private Gtk.Button progress_bar_controller;
|
||||||
|
|
||||||
public bool isPlaying;
|
public bool isPlaying;
|
||||||
public string current_song;
|
public PlaylistItem current_item;
|
||||||
|
|
||||||
|
|
||||||
public Gst.Element playbin;
|
public Gst.Element playbin;
|
||||||
@@ -123,7 +123,7 @@ namespace Song {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void play_music() {
|
private void play_music() {
|
||||||
if (current_song != null) {
|
if (current_item != null) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,15 +138,15 @@ namespace Song {
|
|||||||
isPlaying = false;
|
isPlaying = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void change_song(string song) {
|
public void change_item(PlaylistItem item) {
|
||||||
print("song is now " + song + "\n");
|
print("song is now " + item.name + "\n");
|
||||||
current_song = song;
|
current_item = item;
|
||||||
string file_path = "file://" + settings.get_string("song-folder") + "/" + current_song + ".mp3";
|
string file_path = item.file;
|
||||||
print("song full path is " + file_path);
|
print("song full path is " + file_path);
|
||||||
playbin.set_state(Gst.State.NULL);
|
playbin.set_state(Gst.State.NULL);
|
||||||
playbin.set_property("uri", file_path);
|
playbin.set_property("uri", file_path);
|
||||||
playbin.set_state(Gst.State.PLAYING);
|
//playbin.set_state(Gst.State.PLAYING);
|
||||||
isPlaying = true;
|
//isPlaying = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user