Skip to content

Commit

Permalink
feat: filter panel (#275)
Browse files Browse the repository at this point in the history
Signed-off-by: tsukinaha <sakuovds@gmail.com>
  • Loading branch information
tsukinaha committed Dec 22, 2024
1 parent 4fbf9b9 commit fc27c84
Show file tree
Hide file tree
Showing 17 changed files with 542 additions and 128 deletions.
27 changes: 14 additions & 13 deletions resources/ui/filter.ui
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
</object>
</child>
<child>
<object class="AdwActionRow" id="favourite_check">
<object class="AdwActionRow">
<property name="title">Favourite</property>
<property name="activatable-widget">check</property>
<property name="activatable-widget">favourite_check</property>
<child type="suffix">
<object class="GtkCheckButton" id="check">
<object class="GtkCheckButton" id="favourite_check">
<style>
<class name="accent" />
</style>
Expand All @@ -74,35 +74,35 @@
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="FiltersRow">
<object class="FiltersRow" id="genres_row">
<property name="title" translatable="yes">Genres</property>
<property name="icon-name">music-note-single-outline-symbolic</property>
<property name="filter-type">Genres</property>
</object>
</child>
<child>
<object class="FiltersRow">
<object class="FiltersRow" id="tags_row">
<property name="title" translatable="yes">Tags</property>
<property name="icon-name">tag-outline-symbolic</property>
<property name="filter-type">Tags</property>
</object>
</child>
<child>
<object class="FiltersRow">
<object class="FiltersRow" id="years_row">
<property name="title" translatable="yes">Years</property>
<property name="icon-name">month-symbolic</property>
<property name="filter-type">Years</property>
</object>
</child>
<child>
<object class="FiltersRow">
<object class="FiltersRow" id="ratings_row">
<property name="title" translatable="yes">Official Ratings</property>
<property name="icon-name">minus-circle-outline-symbolic</property>
<property name="filter-type">OfficialRatings</property>
</object>
</child>
<child>
<object class="FiltersRow">
<object class="FiltersRow" id="studios_row">
<property name="title" translatable="yes">Studios</property>
<property name="icon-name">sound-symbolic</property>
<property name="filter-type">Studios</property>
Expand All @@ -114,28 +114,28 @@
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Media Info</property>
<child>
<object class="FiltersRow">
<object class="FiltersRow" id="containers_row">
<property name="title" translatable="yes">Containers</property>
<property name="icon-name">display-projector-symbolic</property>
<property name="filter-type">Containers</property>
</object>
</child>
<child>
<object class="FiltersRow">
<object class="FiltersRow" id="encoders_row">
<property name="title" translatable="yes">Encoders</property>
<property name="icon-name">video-encoder-symbolic</property>
<property name="filter-type">VideoCodecs</property>
</object>
</child>
<child>
<object class="FiltersRow">
<object class="FiltersRow" id="video_types_row">
<property name="title" translatable="yes">Video Types</property>
<property name="icon-name">video-reel2-symbolic</property>
<property name="filter-type">ExtendedVideoTypes</property>
</object>
</child>
<child>
<object class="AdwComboRow">
<object class="AdwComboRow" id="resolution_combo">
<property name="title" translatable="yes">Resolution</property>
<property name="use-subtitle">True</property>
<child type="prefix">
Expand All @@ -161,9 +161,10 @@
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="AdwButtonRow" id="clear_button_row">
<object class="AdwButtonRow">
<property name="title" translatable="yes">Clear</property>
<property name="start-icon-name">large-brush-symbolic</property>
<signal name="activated" handler="on_clear_activated" swapped="yes"/>
<style>
<class name="raised" />
</style>
Expand Down
70 changes: 57 additions & 13 deletions src/client/emby_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ use crate::{
emby_cache_path,
SETTINGS,
},
widgets::single_grid::imp::ListType,
widgets::{
filter_panel::FiltersList,
single_grid::imp::ListType,
},
},
utils::spawn_tokio_without_await,
};
Expand Down Expand Up @@ -443,10 +446,12 @@ impl EmbyClient {
url.to_string()
}

pub async fn search(&self, query: &str, filter: &[&str], start_index: &str) -> Result<List> {
pub async fn search(
&self, query: &str, filter: &[&str], start_index: &str, filters_list: &FiltersList,
) -> Result<List> {
let filter_str = filter.join(",");
let path = format!("Users/{}/Items", self.user_id());
let params = [
let mut params = vec![
(
"Fields",
"BasicSyncInfo,CanDelete,PrimaryImageAspectRatio,ProductionYear,Status,EndDate,CommunityRating",
Expand All @@ -463,6 +468,12 @@ impl EmbyClient {
("GroupProgramsBySeries", "true"),
("Limit", "50"),
];

let kv = filters_list.to_kv();
kv.iter().for_each(|(k, v)| {
params.push((k.as_str(), v.as_str()));
});

self.request(&path, &params).await
}

Expand Down Expand Up @@ -797,9 +808,10 @@ impl EmbyClient {
url.join(path.trim_start_matches('/')).unwrap().to_string()
}

#[allow(clippy::too_many_arguments)]
pub async fn get_list(
&self, id: &str, start: u32, include_item_types: &str, list_type: ListType,
sort_order: &str, sortby: &str,
sort_order: &str, sortby: &str, filters_list: &FiltersList,
) -> Result<List> {
let user_id = &self.user_id();
let path = match list_type {
Expand All @@ -814,7 +826,7 @@ impl EmbyClient {
_ => include_item_types,
};
let start_string = start.to_string();
let params = match list_type {
let mut params = match list_type {
ListType::All | ListType::Liked | ListType::Tags | ListType::BoxSet => {
vec![
("Limit", "50"),
Expand Down Expand Up @@ -865,12 +877,17 @@ impl EmbyClient {
],
_ => vec![],
};
let kv = filters_list.to_kv();
kv.iter().for_each(|(k, v)| {
params.push((k.as_str(), v.as_str()));
});
self.request(&path, &params).await
}

#[allow(clippy::too_many_arguments)]
pub async fn get_inlist(
&self, id: Option<String>, start: u32, listtype: &str, parentid: &str, sort_order: &str,
sortby: &str,
sortby: &str, filters_list: &FiltersList,
) -> Result<List> {
let path = format!("Users/{}/Items", &self.user_id());
let start_string = start.to_string();
Expand Down Expand Up @@ -900,6 +917,11 @@ impl EmbyClient {
id_clone = id.clone();
params.push(("ParentId", &id_clone));
}

let kv = filters_list.to_kv();
kv.iter().for_each(|(k, v)| {
params.push((k.as_str(), v.as_str()));
});
self.request(&path, &params).await
}

Expand Down Expand Up @@ -986,10 +1008,11 @@ impl EmbyClient {

pub async fn get_person_large_list(
&self, id: &str, types: &str, sort_by: &str, sort_order: &str, start_index: u32,
filters_list: &FiltersList,
) -> Result<List> {
let start_string = start_index.to_string();
let path = format!("Users/{}/Items", &self.user_id());
let params = [
let mut params = vec![
(
"Fields",
"Overview,PrimaryImageAspectRatio,ProductionYear,CommunityRating",
Expand All @@ -1004,6 +1027,12 @@ impl EmbyClient {
("ImageTypeLimit", "1"),
("Limit", "50"),
];

let kv = filters_list.to_kv();
kv.iter().for_each(|(k, v)| {
params.push((k.as_str(), v.as_str()));
});

self.request(&path, &params).await
}

Expand Down Expand Up @@ -1051,6 +1080,7 @@ impl EmbyClient {

pub async fn get_favourite(
&self, types: &str, start: u32, limit: u32, sort_by: &str, sort_order: &str,
filters_list: &FiltersList,
) -> Result<List> {
let user_id = {
let user_id = self.user_id.lock().unwrap();
Expand All @@ -1061,7 +1091,9 @@ impl EmbyClient {
} else {
format!("Users/{}/Items", user_id)
};
let params = [
let limit_string = limit.to_string();
let start_string = start.to_string();
let mut params = vec![
(
"Fields",
"BasicSyncInfo,CanDelete,PrimaryImageAspectRatio,ProductionYear,CommunityRating",
Expand All @@ -1072,14 +1104,20 @@ impl EmbyClient {
("SortBy", sort_by),
("SortOrder", sort_order),
("IncludeItemTypes", types),
("Limit", &limit.to_string()),
("StartIndex", &start.to_string()),
("Limit", &limit_string),
("StartIndex", &start_string),
if types == "People" {
("UserId", &user_id)
} else {
("", "")
},
];

let kv = filters_list.to_kv();
kv.iter().for_each(|(k, v)| {
params.push((k.as_str(), v.as_str()));
});

self.request(&path, &params).await
}

Expand Down Expand Up @@ -1118,11 +1156,12 @@ impl EmbyClient {

pub async fn get_folder_include(
&self, parent_id: &str, sort_by: &str, sort_order: &str, start_index: u32,
filters_list: &FiltersList,
) -> Result<List> {
let path = format!("Users/{}/Items", &self.user_id());
let start_index_string = start_index.to_string();
let sort_by = format!("IsFolder,{}", sort_by);
let params = [
let mut params = vec![
(
"Fields",
"BasicSyncInfo,CanDelete,PrimaryImageAspectRatio,ProductionYear,Status,EndDate,CommunityRating",
Expand All @@ -1135,6 +1174,11 @@ impl EmbyClient {
("SortOrder", sort_order),
("EnableTotalRecordCount", "true"),
];

let kv = filters_list.to_kv();
kv.iter().for_each(|(k, v)| {
params.push((k.as_str(), v.as_str()));
});
self.request(&path, &params).await
}

Expand Down Expand Up @@ -1353,8 +1397,8 @@ mod tests {
eprintln!("{}", e.to_user_facing());
}
}

let result = EMBY_CLIENT.search("你的名字", &["Movie"], "0");
let filters_list = FiltersList::default();
let result = EMBY_CLIENT.search("你的名字", &["Movie"], "0", &filters_list);
match result.await {
Ok(items) => {
for item in items.items {
Expand Down
41 changes: 30 additions & 11 deletions src/client/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,26 +607,45 @@ impl SGTitem {
let page = SingleGrid::new();
let id = self.id.to_string();
let list_type_clone = list_type.clone();
page.connect_sort_changed_tokio(false, move |sort_by, sort_order| {
page.connect_sort_changed_tokio(false, move |sort_by, sort_order, filters_list| {
let id = id.clone();
let list_type_clone = list_type_clone.clone();
async move {
EMBY_CLIENT
.get_inlist(None, 0, &list_type_clone, &id, &sort_order, &sort_by)
.get_inlist(
None,
0,
&list_type_clone,
&id,
&sort_order,
&sort_by,
&filters_list,
)
.await
}
});
let id = self.id.to_string();
let list_type = list_type.clone();
page.connect_end_edge_overshot_tokio(false, move |sort_by, sort_order, n_items| {
let id = id.clone();
let list_type = list_type.clone();
async move {
EMBY_CLIENT
.get_inlist(None, n_items, &list_type, &id, &sort_order, &sort_by)
.await
}
});
page.connect_end_edge_overshot_tokio(
false,
move |sort_by, sort_order, n_items, filters_list| {
let id = id.clone();
let list_type = list_type.clone();
async move {
EMBY_CLIENT
.get_inlist(
None,
n_items,
&list_type,
&id,
&sort_order,
&sort_by,
&filters_list,
)
.await
}
},
);
push_page_with_tag(widget, page, &self.id.to_string(), &self.name.clone());
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/mpv/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ impl MPVPage {
Object::new()
}

#[allow(clippy::too_many_arguments)]
pub fn play(
&self, url: &str, suburi: Option<&str>, item: TuItem, episode_list: Vec<TuItem>,
back: Option<Back>, percentage: f64, matcher: Option<String>,
Expand Down
Loading

0 comments on commit fc27c84

Please sign in to comment.