mirror of
https://gitlab.com/liyaowhen/youtubecollector-git.git
synced 2026-10-01 01:12:59 +00:00
fixed bug that made window crash when there were no playlists
This commit is contained in:
@@ -15,7 +15,9 @@ namespace Song {
|
|||||||
|
|
||||||
public static SongControls song_controls;
|
public static SongControls song_controls;
|
||||||
|
|
||||||
public static Adw.ApplicationWindow window;
|
public static Song.Window window;
|
||||||
|
|
||||||
|
public static Adw.ToastOverlay toast_overlay = new Adw.ToastOverlay();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-28
@@ -87,37 +87,47 @@ namespace Song {
|
|||||||
// Parse settings from JSON
|
// Parse settings from JSON
|
||||||
if (json_config.has_member("playlists")) {
|
if (json_config.has_member("playlists")) {
|
||||||
Json.Object _playlists = json_config.get_object_member("playlists");
|
Json.Object _playlists = json_config.get_object_member("playlists");
|
||||||
print("\n." + _playlists.get_members().data + ".\n");
|
|
||||||
// invalid methoud down below
|
|
||||||
|
|
||||||
var members = _playlists.get_members();
|
var members = _playlists.get_members();
|
||||||
members.foreach((member_name) => {
|
|
||||||
PlaylistObject _playList = new PlaylistObject();
|
if (members != null) {
|
||||||
var object = _playlists.get_member(member_name).get_object();
|
members.foreach((member_name) => {
|
||||||
_playList.name = member_name;
|
PlaylistObject? _playList = new PlaylistObject();
|
||||||
// TODO: ADD PROPERTIES _playList.properties = whatever
|
var object = _playlists.get_member(member_name).get_object();
|
||||||
// TODO: fix item iterator, it is invalid as it calls on each member, not each "object"
|
|
||||||
var items_object = object.get_object_member("items");
|
|
||||||
var items_list = items_object.get_members();
|
|
||||||
items_list.foreach((item) => {
|
|
||||||
PlaylistItem _item = new PlaylistItem();
|
|
||||||
var _item_object = items_object.get_object_member(item);
|
|
||||||
_item.item_type = _item_object.get_int_member("item_type");
|
|
||||||
_item.name = _item_object.get_string_member("name");
|
|
||||||
_item.file = _item_object.get_string_member("file");
|
|
||||||
if (_item_object.has_member("picture")) {
|
|
||||||
_item.picture = _item_object.get_string_member("picture");
|
|
||||||
}
|
|
||||||
if (_item_object.has_member("source")) {
|
|
||||||
_item.picture = _item_object.get_string_member("source");
|
|
||||||
}
|
|
||||||
_playList.items.append(_item);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
playlists.append(_playList);
|
if (object != null) {
|
||||||
});
|
|
||||||
}
|
_playList.name = member_name;
|
||||||
|
// TODO: ADD PROPERTIES _playList.properties = whatever
|
||||||
|
// TODO: fix item iterator, it is invalid as it calls on each member, not each "object"
|
||||||
|
Json.Object? items_object = null;
|
||||||
|
if (object.has_member("items")) {
|
||||||
|
items_object = object.get_object_member("items");
|
||||||
|
}
|
||||||
|
if (items_object != null) {
|
||||||
|
var items_list = items_object.get_members();
|
||||||
|
items_list.foreach((item) => {
|
||||||
|
PlaylistItem _item = new PlaylistItem();
|
||||||
|
var _item_object = items_object.get_object_member(item);
|
||||||
|
_item.item_type = _item_object.get_int_member("item_type");
|
||||||
|
_item.name = _item_object.get_string_member("name");
|
||||||
|
_item.file = _item_object.get_string_member("file");
|
||||||
|
if (_item_object.has_member("picture")) {
|
||||||
|
_item.picture = _item_object.get_string_member("picture");
|
||||||
|
}
|
||||||
|
if (_item_object.has_member("source")) {
|
||||||
|
_item.picture = _item_object.get_string_member("source");
|
||||||
|
}
|
||||||
|
_playList.items.append(_item);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
playlists.append(_playList);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
loaded();
|
loaded();
|
||||||
|
|
||||||
|
|||||||
@@ -86,11 +86,13 @@ namespace Song {
|
|||||||
|
|
||||||
var config = Config.get_instance();
|
var config = Config.get_instance();
|
||||||
config.config_changed.connect(() => {
|
config.config_changed.connect(() => {
|
||||||
if (config.playlists.length() == 1) {
|
if (config.playlists != null) {
|
||||||
config.playlists.foreach((i) => {
|
if (config.playlists.length() == 1) {
|
||||||
change_page(i);
|
config.playlists.foreach((i) => {
|
||||||
return;
|
change_page(i);
|
||||||
});
|
return;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ namespace Song {
|
|||||||
|
|
||||||
private Settings settings = new Settings ("com.liyaowhen.Song");
|
private Settings settings = new Settings ("com.liyaowhen.Song");
|
||||||
|
|
||||||
private PlaylistObject playlist;
|
public PlaylistObject playlist;
|
||||||
private Gtk.Button remove_button;
|
private Gtk.Button remove_button;
|
||||||
private Gtk.Revealer remove_button_revealer;
|
private Gtk.Revealer remove_button_revealer;
|
||||||
|
|
||||||
@@ -13,10 +13,17 @@ namespace Song {
|
|||||||
}
|
}
|
||||||
|
|
||||||
construct {
|
construct {
|
||||||
|
|
||||||
|
|
||||||
orientation = Gtk.Orientation.HORIZONTAL;
|
orientation = Gtk.Orientation.HORIZONTAL;
|
||||||
add_css_class("toolbar");
|
add_css_class("toolbar");
|
||||||
remove_button = new Gtk.Button.from_icon_name("app-remove-symbolic");
|
remove_button = new Gtk.Button.from_icon_name("app-remove-symbolic");
|
||||||
|
|
||||||
|
remove_button.clicked.connect(() => {
|
||||||
|
print("clicked");
|
||||||
|
confirm_delete_popup();
|
||||||
|
});
|
||||||
|
|
||||||
remove_button_revealer = new Gtk.Revealer();
|
remove_button_revealer = new Gtk.Revealer();
|
||||||
remove_button_revealer.set_child(remove_button);
|
remove_button_revealer.set_child(remove_button);
|
||||||
remove_button_revealer.transition_type = Gtk.RevealerTransitionType.SWING_LEFT;
|
remove_button_revealer.transition_type = Gtk.RevealerTransitionType.SWING_LEFT;
|
||||||
@@ -39,6 +46,7 @@ namespace Song {
|
|||||||
if (playlist.name != null) {
|
if (playlist.name != null) {
|
||||||
main_button.label = playlist.name;
|
main_button.label = playlist.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Config.get_instance().loaded.connect(() => {
|
Config.get_instance().loaded.connect(() => {
|
||||||
@@ -60,5 +68,29 @@ namespace Song {
|
|||||||
public void exit_removal_mode() {
|
public void exit_removal_mode() {
|
||||||
remove_button_revealer.set_reveal_child(false);
|
remove_button_revealer.set_reveal_child(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void confirm_delete_popup() {
|
||||||
|
|
||||||
|
|
||||||
|
var alert_dialog = new Adw.AlertDialog("Remove Playlist?",
|
||||||
|
"Deleting a playlist is a non-reversable action,
|
||||||
|
however the playlist's items will remain intact in the configuration folder");
|
||||||
|
|
||||||
|
alert_dialog.add_response("Cancel", "Cancel");
|
||||||
|
alert_dialog.add_response("Confirm", "Confirm");
|
||||||
|
alert_dialog.set_response_appearance("Confirm", Adw.ResponseAppearance.DESTRUCTIVE);
|
||||||
|
|
||||||
|
alert_dialog.present(this);
|
||||||
|
|
||||||
|
|
||||||
|
alert_dialog.response.connect((i, e) => {
|
||||||
|
if (e == "Confirm") {
|
||||||
|
Config.get_instance().playlists.remove(playlist);
|
||||||
|
Config.get_instance().save.begin();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+35
-23
@@ -60,7 +60,7 @@ namespace Song {
|
|||||||
vexpand_set = true;
|
vexpand_set = true;
|
||||||
hexpand_set = true;
|
hexpand_set = true;
|
||||||
|
|
||||||
PlaylistObject initial_playlist;
|
PlaylistObject? initial_playlist = null;
|
||||||
|
|
||||||
/*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) {
|
||||||
@@ -75,23 +75,33 @@ namespace Song {
|
|||||||
Config config = Config.get_instance();
|
Config config = Config.get_instance();
|
||||||
|
|
||||||
bool firstDeclared = false;
|
bool firstDeclared = false;
|
||||||
config.playlists.foreach((_playlist) => {
|
if (config.playlists != null) {
|
||||||
var button = new PlaylistButton(_playlist);
|
foreach (PlaylistObject _playlist in config.playlists) {
|
||||||
if (!firstDeclared) {initial_playlist = _playlist; firstDeclared = true;}
|
|
||||||
|
|
||||||
playlist_buttons.add(button);
|
|
||||||
append(button);
|
|
||||||
});
|
|
||||||
|
|
||||||
config.config_changed.connect(() => {
|
|
||||||
playlist_buttons.clear();
|
|
||||||
config.playlists.foreach((_playlist) => {
|
|
||||||
var button = new PlaylistButton(_playlist);
|
var button = new PlaylistButton(_playlist);
|
||||||
|
if (!firstDeclared) {initial_playlist = _playlist; firstDeclared = true;}
|
||||||
|
|
||||||
playlist_buttons.add(button);
|
playlist_buttons.add(button);
|
||||||
append(button);
|
append(button);
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print("\n aaaaaa" + playlist_buttons.size.to_string() + "\n");
|
||||||
|
|
||||||
|
config.config_changed.connect(() => {
|
||||||
|
foreach (PlaylistButton e in playlist_buttons) {
|
||||||
|
print("\n" + e.playlist.name + "eee");
|
||||||
|
e.destroy();
|
||||||
|
}
|
||||||
|
if (config.playlists != null) {
|
||||||
|
config.playlists.foreach((_playlist) => {
|
||||||
|
var button = new PlaylistButton(_playlist);
|
||||||
|
|
||||||
|
playlist_buttons.add(button);
|
||||||
|
append(button);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Timeout.add(1000, () => {
|
Timeout.add(1000, () => {
|
||||||
if (playlist_buttons == null) {
|
if (playlist_buttons == null) {
|
||||||
@@ -105,9 +115,10 @@ namespace Song {
|
|||||||
//print("sidbar requesting main_view_content switch to playlist of name:\n" + playlists.nth_data(0).name);
|
//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(initial_playlist);
|
if (initial_playlist != null) {
|
||||||
return false;
|
SongController.main_view_content.change_page(initial_playlist);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, 1);
|
}, 1);
|
||||||
@@ -163,16 +174,17 @@ namespace Song {
|
|||||||
print("\n sidebar buttons are null");
|
print("\n sidebar buttons are null");
|
||||||
}
|
}
|
||||||
if (i.get_active()) {
|
if (i.get_active()) {
|
||||||
sidebar_content.playlist_buttons.foreach((e) => {
|
foreach (PlaylistButton e in sidebar_content.playlist_buttons) {
|
||||||
e.enter_removal_mode();
|
e.enter_removal_mode();
|
||||||
print(e.name);
|
print(e.playlist.name);
|
||||||
});
|
}
|
||||||
} else {
|
} else {
|
||||||
sidebar_content.playlist_buttons.foreach((e) => {
|
foreach (PlaylistButton e in sidebar_content.playlist_buttons) {
|
||||||
e.exit_removal_mode();
|
e.exit_removal_mode();
|
||||||
print(e.name);
|
print(e.playlist.name);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
print("\n" + sidebar_content.playlist_buttons.size.to_string() + "\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace Song {
|
|||||||
private Settings settings = new Settings ("com.liyaowhen.Song");
|
private Settings settings = new Settings ("com.liyaowhen.Song");
|
||||||
public SideBar sidebar;
|
public SideBar sidebar;
|
||||||
public MainView main_view;
|
public MainView main_view;
|
||||||
|
public Gtk.ShortcutAction ctrl_z = new Gtk.SignalAction("ctrl_z");
|
||||||
|
|
||||||
public Window (Gtk.Application app) {
|
public Window (Gtk.Application app) {
|
||||||
Object (application: app);
|
Object (application: app);
|
||||||
@@ -69,6 +70,11 @@ namespace Song {
|
|||||||
var _content = new Adw.ToolbarView ();
|
var _content = new Adw.ToolbarView ();
|
||||||
_content.add_top_bar (title_bar);
|
_content.add_top_bar (title_bar);
|
||||||
_content.set_content (split_view);
|
_content.set_content (split_view);
|
||||||
|
|
||||||
|
var controller = new Gtk.ShortcutController();
|
||||||
|
Gtk.ShortcutTrigger trigger = Gtk.ShortcutTrigger.parse_string("<Control>Z");
|
||||||
|
controller.add_shortcut(new Gtk.Shortcut(trigger, ctrl_z));
|
||||||
|
add_controller(new Gtk.ShortcutController());
|
||||||
|
|
||||||
|
|
||||||
collapse_button.clicked.connect(() => {
|
collapse_button.clicked.connect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user