Skip to content

Commit df704dd

Browse files
committed
gtk: connect playlist api calls to playlist edit dialogs
gtk: connect playlist api calls to playlist edit dialogs
1 parent bc3edc7 commit df704dd

20 files changed

+525
-60
lines changed

cli/src/api/rockbox.v1alpha1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,6 +4338,8 @@ pub struct CreatePlaylistRequest {
43384338
pub name: ::core::option::Option<::prost::alloc::string::String>,
43394339
#[prost(string, repeated, tag = "2")]
43404340
pub tracks: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
4341+
#[prost(string, optional, tag = "3")]
4342+
pub folder_id: ::core::option::Option<::prost::alloc::string::String>,
43414343
}
43424344
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
43434345
pub struct CreatePlaylistResponse {

cli/src/api/rockbox_descriptor.bin

91 Bytes
Binary file not shown.

gtk/data/gtk/window.blp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ template $RbApplicationWindow : Adw.ApplicationWindow {
419419
Adw.ViewStackPage playlist_details_page {
420420
name: "playlist-details-page";
421421
title: _("Playlist");
422-
child: ScrolledWindow {
422+
child: ScrolledWindow playlist_details_scrolled_window {
423423
$PlaylistDetails playlist_details {}
424424
};
425425
}

gtk/proto/rockbox/v1alpha1/playlist.proto

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ message GetDisplayIndexResponse {}
3535

3636
message AmountRequest {}
3737

38-
message AmountResponse {
39-
int32 amount = 1;
40-
}
38+
message AmountResponse { int32 amount = 1; }
4139

4240
message PlaylistResumeRequest {}
4341

44-
message PlaylistResumeResponse {
45-
int32 code = 1;
46-
}
42+
message PlaylistResumeResponse { int32 code = 1; }
4743

4844
message ResumeTrackRequest {
4945
int32 start_index = 1;
@@ -70,9 +66,7 @@ message SyncRequest {}
7066

7167
message SyncResponse {}
7268

73-
message RemoveAllTracksRequest {
74-
optional string playlist_id = 1;
75-
}
69+
message RemoveAllTracksRequest { optional string playlist_id = 1; }
7670

7771
message RemoveAllTracksResponse {}
7872

@@ -86,11 +80,10 @@ message RemoveTracksResponse {}
8680
message CreatePlaylistRequest {
8781
optional string name = 1;
8882
repeated string tracks = 2;
83+
optional string folder_id = 3;
8984
}
9085

91-
message CreatePlaylistResponse {
92-
int32 start_index = 1;
93-
}
86+
message CreatePlaylistResponse { int32 start_index = 1; }
9487

9588
message InsertTracksRequest {
9689
optional string playlist_id = 1;
@@ -138,15 +131,11 @@ message InsertArtistTracksRequest {
138131

139132
message InsertArtistTracksResponse {}
140133

141-
message ShufflePlaylistRequest {
142-
int32 start_index = 1;
143-
}
134+
message ShufflePlaylistRequest { int32 start_index = 1; }
144135

145136
message ShufflePlaylistResponse {}
146137

147-
message GetPlaylistRequest {
148-
string playlist_id = 1;
149-
}
138+
message GetPlaylistRequest { string playlist_id = 1; }
150139

151140
message GetPlaylistResponse {
152141
string id = 1;
@@ -165,37 +154,27 @@ message CreateFolderRequest {
165154
optional string parent_id = 2;
166155
}
167156

168-
message CreateFolderResponse {
169-
string folder_id = 1;
170-
}
157+
message CreateFolderResponse { string folder_id = 1; }
171158

172-
message GetFolderRequest {
173-
string id = 1;
174-
}
159+
message GetFolderRequest { string id = 1; }
175160

176161
message GetFolderResponse {
177162
string id = 1;
178163
string name = 2;
179164
optional string parent_id = 3;
180165
}
181166

182-
message GetFoldersRequest {
183-
optional string parent_id = 1;
184-
}
167+
message GetFoldersRequest { optional string parent_id = 1; }
185168

186169
message GetFoldersResponse {
187170
repeated rockbox.v1alpha1.GetFolderResponse folders = 1;
188171
}
189172

190-
message RemoveFolderRequest {
191-
string id = 1;
192-
}
173+
message RemoveFolderRequest { string id = 1; }
193174

194175
message RemoveFolderResponse {}
195176

196-
message RemovePlaylistRequest {
197-
string id = 1;
198-
}
177+
message RemovePlaylistRequest { string id = 1; }
199178

200179
message RemovePlaylistResponse {}
201180

@@ -227,9 +206,7 @@ message MoveFolderRequest {
227206

228207
message MoveFolderResponse {}
229208

230-
message GetPlaylistsRequest {
231-
optional string folder_id = 1;
232-
}
209+
message GetPlaylistsRequest { optional string folder_id = 1; }
233210

234211
message GetPlaylistsResponse {
235212
repeated rockbox.v1alpha1.GetPlaylistResponse playlists = 1;
@@ -240,22 +217,27 @@ service PlaylistService {
240217
rpc GetResumeInfo(GetResumeInfoRequest) returns (GetResumeInfoResponse) {}
241218
rpc GetTrackInfo(GetTrackInfoRequest) returns (GetTrackInfoResponse) {}
242219
rpc GetFirstIndex(GetFirstIndexRequest) returns (GetFirstIndexResponse) {}
243-
rpc GetDisplayIndex(GetDisplayIndexRequest) returns (GetDisplayIndexResponse) {}
220+
rpc GetDisplayIndex(GetDisplayIndexRequest)
221+
returns (GetDisplayIndexResponse) {}
244222
rpc Amount(AmountRequest) returns (AmountResponse) {}
245223
rpc PlaylistResume(PlaylistResumeRequest) returns (PlaylistResumeResponse) {}
246224
rpc ResumeTrack(ResumeTrackRequest) returns (ResumeTrackResponse) {}
247225
rpc SetModified(SetModifiedRequest) returns (SetModifiedResponse) {}
248226
rpc Start(StartRequest) returns (StartResponse) {}
249227
rpc Sync(SyncRequest) returns (SyncResponse) {}
250-
rpc RemoveAllTracks(RemoveAllTracksRequest) returns (RemoveAllTracksResponse) {}
228+
rpc RemoveAllTracks(RemoveAllTracksRequest)
229+
returns (RemoveAllTracksResponse) {}
251230
rpc RemoveTracks(RemoveTracksRequest) returns (RemoveTracksResponse) {}
252231
rpc CreatePlaylist(CreatePlaylistRequest) returns (CreatePlaylistResponse) {}
253232
rpc InsertTracks(InsertTracksRequest) returns (InsertTracksResponse) {}
254-
rpc InsertDirectory(InsertDirectoryRequest) returns (InsertDirectoryResponse) {}
233+
rpc InsertDirectory(InsertDirectoryRequest)
234+
returns (InsertDirectoryResponse) {}
255235
rpc InsertPlaylist(InsertPlaylistRequest) returns (InsertPlaylistResponse) {}
256236
rpc InsertAlbum(InsertAlbumRequest) returns (InsertAlbumResponse) {}
257-
rpc InsertArtistTracks(InsertArtistTracksRequest) returns (InsertArtistTracksResponse) {}
258-
rpc ShufflePlaylist(ShufflePlaylistRequest) returns (ShufflePlaylistResponse) {}
237+
rpc InsertArtistTracks(InsertArtistTracksRequest)
238+
returns (InsertArtistTracksResponse) {}
239+
rpc ShufflePlaylist(ShufflePlaylistRequest)
240+
returns (ShufflePlaylistResponse) {}
259241
rpc GetPlaylist(GetPlaylistRequest) returns (GetPlaylistResponse) {}
260242
rpc GetPlaylists(GetPlaylistsRequest) returns (GetPlaylistsResponse) {}
261243
rpc CreateFolder(CreateFolderRequest) returns (CreateFolderResponse) {}

gtk/src/api/rockbox.v1alpha1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,6 +4338,8 @@ pub struct CreatePlaylistRequest {
43384338
pub name: ::core::option::Option<::prost::alloc::string::String>,
43394339
#[prost(string, repeated, tag = "2")]
43404340
pub tracks: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
4341+
#[prost(string, optional, tag = "3")]
4342+
pub folder_id: ::core::option::Option<::prost::alloc::string::String>,
43414343
}
43424344
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
43434345
pub struct CreatePlaylistResponse {

gtk/src/api/rockbox_descriptor.bin

91 Bytes
Binary file not shown.

gtk/src/state.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ mod imp {
2929
pub artists: RefCell<Vec<RockboxArtist>>,
3030
pub current_playlist_folder: RefCell<Option<String>>,
3131
pub parent_playlist_folder: RefCell<Option<String>>,
32+
pub selected_playlist: RefCell<Option<String>>,
33+
pub selected_playlist_folder: RefCell<Option<String>>,
3234
}
3335

3436
#[glib::object_subclass]
@@ -65,6 +67,8 @@ impl AppState {
6567
obj.imp().tracks.replace(Vec::new());
6668
obj.imp().current_playlist_folder.replace(None);
6769
obj.imp().parent_playlist_folder.replace(None);
70+
obj.imp().selected_playlist.replace(None);
71+
obj.imp().selected_playlist_folder.replace(None);
6872
obj
6973
}
7074

@@ -124,6 +128,16 @@ impl AppState {
124128
self_.parent_playlist_folder.borrow().clone()
125129
}
126130

131+
pub fn selected_playlist_folder(&self) -> Option<String> {
132+
let self_ = imp::AppState::from_obj(self);
133+
self_.selected_playlist_folder.borrow().clone()
134+
}
135+
136+
pub fn selected_playlist(&self) -> Option<String> {
137+
let self_ = imp::AppState::from_obj(self);
138+
self_.selected_playlist.borrow().clone()
139+
}
140+
127141
pub fn music_directory(&self) -> Option<String> {
128142
let self_ = imp::AppState::from_obj(self);
129143
self_.music_directory.borrow().clone()
@@ -144,6 +158,16 @@ impl AppState {
144158
*self_.parent_playlist_folder.borrow_mut() = folder_id;
145159
}
146160

161+
pub fn set_selected_playlist(&self, playlist_id: Option<String>) {
162+
let self_ = imp::AppState::from_obj(self);
163+
*self_.selected_playlist.borrow_mut() = playlist_id;
164+
}
165+
166+
pub fn set_selected_playlist_folder(&self, folder_id: Option<String>) {
167+
let self_ = imp::AppState::from_obj(self);
168+
*self_.selected_playlist_folder.borrow_mut() = folder_id;
169+
}
170+
147171
pub fn set_music_directory(&self, path: &str) {
148172
let self_ = imp::AppState::from_obj(self);
149173
*self_.music_directory.borrow_mut() = Some(path.to_string());

gtk/src/ui/delete_playlist.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1+
use crate::api::rockbox::v1alpha1::playlist_service_client::PlaylistServiceClient;
2+
use crate::api::rockbox::v1alpha1::RemovePlaylistRequest;
3+
use crate::state::AppState;
14
use adw::prelude::*;
25
use adw::subclass::prelude::*;
6+
use anyhow::Error;
37
use glib::subclass;
48
use gtk::{glib, CompositeTemplate};
59
use std::env;
10+
use std::thread;
611

712
mod imp {
813
use super::*;
914

1015
#[derive(Debug, Default, CompositeTemplate)]
1116
#[template(resource = "/io/github/tsirysndr/Rockbox/gtk/delete_playlist.ui")]
12-
pub struct DeletePlaylistDialog {}
17+
pub struct DeletePlaylistDialog {
18+
pub state: glib::WeakRef<AppState>,
19+
}
1320

1421
#[glib::object_subclass]
1522
impl ObjectSubclass for DeletePlaylistDialog {
@@ -24,6 +31,7 @@ mod imp {
2431
"app.delete_playlist_dialog.delete",
2532
None,
2633
move |dialog, _action, _target| {
34+
dialog.delete_playlist();
2735
dialog.close();
2836
},
2937
);
@@ -56,6 +64,23 @@ impl Default for DeletePlaylistDialog {
5664
}
5765
}
5866

67+
#[gtk::template_callbacks]
68+
impl DeletePlaylistDialog {
69+
fn delete_playlist(&self) {
70+
let state = self.imp().state.upgrade().unwrap();
71+
let id = state.selected_playlist().unwrap();
72+
thread::spawn(move || {
73+
let rt = tokio::runtime::Runtime::new().unwrap();
74+
let url = build_url();
75+
let result = rt.block_on(async {
76+
let mut client = PlaylistServiceClient::connect(url).await?;
77+
client.remove_playlist(RemovePlaylistRequest { id }).await?;
78+
Ok::<_, Error>(())
79+
});
80+
});
81+
}
82+
}
83+
5984
fn build_url() -> String {
6085
let host = env::var("ROCKBOX_HOST").unwrap_or_else(|_| "localhost".to_string());
6186
let port = env::var("ROCKBOX_PORT").unwrap_or_else(|_| "6061".to_string());

gtk/src/ui/delete_playlist_folder.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1+
use crate::api::rockbox::v1alpha1::playlist_service_client::PlaylistServiceClient;
2+
use crate::api::rockbox::v1alpha1::RemoveFolderRequest;
3+
use crate::state::AppState;
14
use adw::prelude::*;
25
use adw::subclass::prelude::*;
6+
use anyhow::Error;
37
use glib::subclass;
48
use gtk::{glib, CompositeTemplate};
59
use std::env;
10+
use std::thread;
611

712
mod imp {
813

914
use super::*;
1015

1116
#[derive(Debug, Default, CompositeTemplate)]
1217
#[template(resource = "/io/github/tsirysndr/Rockbox/gtk/delete_playlist_folder.ui")]
13-
pub struct DeletePlaylistFolderDialog {}
18+
pub struct DeletePlaylistFolderDialog {
19+
pub state: glib::WeakRef<AppState>,
20+
}
1421

1522
#[glib::object_subclass]
1623
impl ObjectSubclass for DeletePlaylistFolderDialog {
@@ -25,6 +32,7 @@ mod imp {
2532
"app.delete_playlist_folder_dialog.delete",
2633
None,
2734
move |dialog, _action, _target| {
35+
dialog.delete_folder();
2836
dialog.close();
2937
},
3038
);
@@ -57,6 +65,23 @@ impl Default for DeletePlaylistFolderDialog {
5765
}
5866
}
5967

68+
#[gtk::template_callbacks]
69+
impl DeletePlaylistFolderDialog {
70+
fn delete_folder(&self) {
71+
let state = self.imp().state.upgrade().unwrap();
72+
let id = state.selected_playlist_folder().unwrap();
73+
thread::spawn(move || {
74+
let rt = tokio::runtime::Runtime::new().unwrap();
75+
let url = build_url();
76+
let result = rt.block_on(async {
77+
let mut client = PlaylistServiceClient::connect(url).await?;
78+
client.remove_folder(RemoveFolderRequest { id }).await?;
79+
Ok::<_, Error>(())
80+
});
81+
});
82+
}
83+
}
84+
6085
fn build_url() -> String {
6186
let host = env::var("ROCKBOX_HOST").unwrap_or_else(|_| "localhost".to_string());
6287
let port = env::var("ROCKBOX_PORT").unwrap_or_else(|_| "6061".to_string());

0 commit comments

Comments
 (0)