Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
008404ffb3 | ||
|
|
2b6cca6bab | ||
|
|
fe968e19c0 | ||
|
|
479498d8be | ||
|
|
af9669acd0 | ||
|
|
d2eb98f859 | ||
|
|
ae11084f48 | ||
|
|
b02b554105 | ||
|
|
2d66ba918a | ||
|
|
400c0f35f0 | ||
|
|
5b8b265371 | ||
|
|
f3fb27005a | ||
|
|
79bb9bdde8 | ||
|
|
4b983e401d | ||
|
|
5f2f0a9a57 | ||
|
|
8b2ae6d464 | ||
|
|
91aae6a9f5 | ||
|
|
b0fc9ef05e | ||
|
|
5d6fbb6f04 | ||
|
|
301ebdbcd8 | ||
|
|
49bcf46b4f | ||
|
|
f7263c8ab8 | ||
|
|
c69772131a | ||
|
|
e8c025b898 | ||
|
|
8fb5c16bce | ||
|
|
f4551ddf3a | ||
|
|
f337488951 | ||
|
|
f104f11613 | ||
|
|
32e8f952fd | ||
|
|
c7cfc81c6f | ||
|
|
faeafc329c | ||
|
|
eeef0d13ff | ||
|
|
0686fca3b0 | ||
|
|
79b425326b | ||
|
|
2d879b9604 | ||
|
|
38eb14b013 | ||
|
|
ff2f43766e | ||
|
|
593d66ea54 | ||
|
|
ee8cbbf7ef | ||
|
|
474cb49d2c | ||
|
|
590f815dc0 | ||
|
|
a93d5246d2 | ||
|
|
3e2ab8e7ee | ||
|
|
a83270699f | ||
|
|
745afb32a3 | ||
|
|
2fcb8d915d | ||
|
|
a596b62a5f | ||
|
|
55b1504aab | ||
|
|
c42822669b | ||
|
|
b58d28c723 | ||
|
|
a6a34d8246 | ||
|
|
0080399db2 | ||
|
|
50b480ee23 | ||
|
|
da467b7837 | ||
|
|
70914b6c3e | ||
|
|
6c3fbfe0ca | ||
|
|
8e4b705e60 | ||
|
|
48d80d3194 | ||
|
|
38768c777d | ||
|
|
1daa841f31 | ||
|
|
a9f81d0ad3 | ||
|
|
76720424ab | ||
|
|
a7b639a66b | ||
|
|
1b78d221b6 | ||
|
|
ac7b1a3c66 | ||
|
|
039c3182aa | ||
|
|
55d94b1844 | ||
|
|
3baa69b43b | ||
|
|
5f92df97e6 | ||
|
|
47f297c495 | ||
|
|
58f09ba150 | ||
|
|
1142948945 | ||
|
|
9528160b03 | ||
|
|
4afdc54914 | ||
|
|
09973a6a56 | ||
|
|
f56bf3afef | ||
|
|
c4c7bbf46b | ||
|
|
7fdd374911 | ||
|
|
fb9ad9870d | ||
|
|
bbabc6f5e9 | ||
|
|
2060579bb4 | ||
|
|
b0f0940605 | ||
|
|
ee23df176d | ||
|
|
d53865d81b | ||
|
|
7becfd8adb | ||
|
|
a9feed56fe | ||
|
|
dea517c17c | ||
|
|
6d93ceb910 | ||
|
|
9b0ac5b83d | ||
|
|
acabb40171 | ||
|
|
04cd56ca16 | ||
|
|
4371512ba2 | ||
|
|
ced686e1cd | ||
|
|
272aab2397 | ||
|
|
a7f87f2ac8 | ||
|
|
f9e85155a8 | ||
|
|
d281c18951 | ||
|
|
04e7f4f8a7 | ||
|
|
a090c11f4a | ||
|
|
c303c697a9 | ||
|
|
9466c5ea10 | ||
|
|
1268fcf1cc | ||
|
|
86d06fa879 | ||
|
|
cfe79a73d6 | ||
|
|
d7a9d9ddc8 | ||
|
|
b3d45384e1 | ||
|
|
64099e37e5 | ||
|
|
2fe612d392 | ||
|
|
14d72b92cb | ||
|
|
8c0055723c | ||
|
|
bb9e368b2d | ||
|
|
2c203acbd2 | ||
|
|
7115eb573c | ||
|
|
e626c6f286 | ||
|
|
24058f9534 | ||
|
|
a8d47e9a72 | ||
|
|
9a2f51b48d | ||
|
|
667deef5f2 | ||
|
|
aa349aa935 | ||
|
|
666ab01d03 | ||
|
|
ffbab0136f | ||
|
|
b5f7399b2c | ||
|
|
f1892eeba2 | ||
|
|
e7128a57db | ||
|
|
793cafd294 | ||
|
|
9b1097effe | ||
|
|
079ae0e1f3 | ||
|
|
e181a9837a | ||
|
|
ca5c7022ef | ||
|
|
75c50392cb | ||
|
|
74f8e744ac | ||
|
|
1c657036da | ||
|
|
2869bb3ef3 | ||
|
|
784e117a8a | ||
|
|
8c2ea052de | ||
|
|
0b6bbf6733 | ||
|
|
2312df3718 | ||
|
|
095dd73c52 | ||
|
|
ac6ac42860 | ||
|
|
c6ce888cc7 |
@@ -7,3 +7,4 @@ resources.gresource
|
||||
_build
|
||||
vendor/
|
||||
.criterion
|
||||
org.gnome.*.json~
|
||||
|
||||
+8
-7
@@ -25,7 +25,7 @@ variables:
|
||||
|
||||
before_script:
|
||||
- apt-get update -yqq
|
||||
- apt-get install -yqq --no-install-recommends build-essential libgtk-3-dev meson
|
||||
- apt-get install -yqq --no-install-recommends build-essential libgtk-3-dev meson libgstreamer1.0-dev
|
||||
|
||||
- mkdir -p .cargo_cache
|
||||
# Only stuff inside the repo directory can be cached
|
||||
@@ -41,12 +41,12 @@ variables:
|
||||
- cargo test -- --test-threads=1 --ignored
|
||||
<<: *cargo_cache
|
||||
|
||||
rust:stable:
|
||||
.rust:stable:
|
||||
# https://hub.docker.com/_/rust/
|
||||
image: "rust"
|
||||
<<: *cargo_test
|
||||
|
||||
rust:nightly:
|
||||
.rust:nightly:
|
||||
# https://hub.docker.com/r/rustlang/rust/
|
||||
image: "rustlang/rust:nightly"
|
||||
<<: *cargo_test
|
||||
@@ -55,7 +55,7 @@ rust:nightly:
|
||||
- web
|
||||
|
||||
flatpak:
|
||||
image: registry.gitlab.com/alatiera/gnome-nightly-oci/rust-bundle:latest
|
||||
image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/rust_bundle:3.28
|
||||
stage: test
|
||||
script:
|
||||
- flatpak-builder --stop-at=hammond app org.gnome.Hammond.json
|
||||
@@ -125,19 +125,20 @@ rustfmt:
|
||||
script:
|
||||
- rustc -Vv && cargo -Vv
|
||||
- cargo fmt --version
|
||||
- cargo fmt --all -- --write-mode=diff
|
||||
- cargo fmt --all -- --check
|
||||
|
||||
# Configure and run clippy on nightly
|
||||
# Only fails on errors atm.
|
||||
clippy:
|
||||
.clippy:
|
||||
image: "registry.gitlab.gnome.org/alatiera/hammond-container-images/clippy:nightly"
|
||||
stage: lint
|
||||
variables:
|
||||
RUSTFLAGS: "--cfg rayon_unstable"
|
||||
CARGO_HOME: ".cargo_cache"
|
||||
script:
|
||||
- rustc --version && cargo --version
|
||||
- cargo clippy --version
|
||||
# Force regeneration of gresources regardless of artifacts chage
|
||||
- cd hammond-gtk/resources/ && glib-compile-resources --generate resources.xml && cd ../../
|
||||
- cargo clippy --all
|
||||
<<: *cargo_cache
|
||||
<<: *cargo_cache
|
||||
|
||||
@@ -1,9 +1,42 @@
|
||||
Detailed description of the issue. Put as much information as you can, potentially
|
||||
with images showing the issue.
|
||||
# Steps to reproduce
|
||||
<!--
|
||||
Explain in detail the steps on how the issue can be reproduced.
|
||||
-->
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
Steps to reproduce:
|
||||
Reproducible in:
|
||||
<!--
|
||||
Please test if the issue was already fixed in the unstable version of the app.
|
||||
For that, follow these steps:
|
||||
1. Make sure Flatpak is installed or install it following these steps https://flatpak.org/setup
|
||||
2. Install the unstable version of the app following this link
|
||||
https://gitlab.gnome.org/GNOME/gnome-apps-nightly/raw/master/nautilus.flatpakref and save
|
||||
it as a ".flatpakref" file
|
||||
|
||||
1. Open Hammond
|
||||
2. Do an action
|
||||
3. ...
|
||||
If these steps failed, write in 'Other' the distribution you’re using and
|
||||
the version of the app.
|
||||
-->
|
||||
- Flatpak unstable: (yes or no) <!-- Write "yes" or "no" after the semicolon. -->
|
||||
- Other:
|
||||
|
||||
# Current behavior
|
||||
<!-- Describe the current behavior. -->
|
||||
|
||||
|
||||
# Expected behavior
|
||||
<!-- Describe the expected behavior. -->
|
||||
|
||||
|
||||
# Additional information
|
||||
<!--
|
||||
Provide more information that could be relevant.
|
||||
|
||||
If the issue is a crash, provide a stack trace following the steps in:
|
||||
https://wiki.gnome.org/Community/GettingInTouch/Bugzilla/GettingTraces
|
||||
-->
|
||||
|
||||
|
||||
<!-- Ignore the text under this line. -->
|
||||
/label ~"Bug"
|
||||
|
||||
@@ -1,42 +1,41 @@
|
||||
Current problems
|
||||
<!--
|
||||
What are the problems that the current project has?
|
||||
# Current problems
|
||||
<!--
|
||||
What are the problems that the current project has?
|
||||
|
||||
For example:
|
||||
* User cannot use the keyboard to perform most common actions
|
||||
or
|
||||
* User cannot see documents from cloud services
|
||||
-->
|
||||
For example:
|
||||
* User cannot use the keyboard to perform most common actions
|
||||
or
|
||||
* User cannot see documents from cloud services
|
||||
-->
|
||||
|
||||
# Goals & use cases
|
||||
<!--
|
||||
What are the use cases that this proposal will cover? What are the end goals?
|
||||
# Goals & use cases
|
||||
<!--
|
||||
What are the use cases that this proposal will cover? What are the end goals?
|
||||
|
||||
For example:
|
||||
* User needs to share a file with their friends.
|
||||
or
|
||||
* It should be easy to edit a picture within the app.
|
||||
-->
|
||||
For example:
|
||||
* User needs to share a file with their friends.
|
||||
or
|
||||
* It should be easy to edit a picture within the app.
|
||||
-->
|
||||
|
||||
# Requirements
|
||||
<!--
|
||||
What does the solution needs to ensure for being succesful?
|
||||
# Requirements
|
||||
<!--
|
||||
What does the solution needs to ensure for being succesful?
|
||||
|
||||
For example:
|
||||
* Work on small form factors and touch
|
||||
or
|
||||
* Use the Meson build system and integrate with it
|
||||
-->
|
||||
For example:
|
||||
* Work on small form factors and touch
|
||||
or
|
||||
* Use the Meson build system and integrate with it
|
||||
-->
|
||||
|
||||
# Relevant art
|
||||
<!--
|
||||
Is there any product that has implemented something similar? Put links to other
|
||||
projects, pictures, links to other code, etc.
|
||||
-->
|
||||
# Relevant art
|
||||
<!--
|
||||
Is there any product that has implemented something similar? Put links to other
|
||||
projects, pictures, links to other code, etc.
|
||||
-->
|
||||
|
||||
# Proposal & plan
|
||||
<!-- What's the solution and how should be achieved? It can be split in smaller
|
||||
tasks of minimum change, so they can be delivered across several releases. -->
|
||||
|
||||
/label ~"Epic"
|
||||
# Proposal & plan
|
||||
<!-- What's the solution and how should be achieved? It can be split in smaller
|
||||
tasks of minimum change, so they can be delivered across several releases. -->
|
||||
|
||||
/label ~"Epic"
|
||||
@@ -1,17 +1,24 @@
|
||||
Detailed description of the feature. Put as much information as you can.
|
||||
### Use cases
|
||||
<!--
|
||||
Describe what problem(s) the user is experiencing and that this request
|
||||
is trying to solve.
|
||||
-->
|
||||
|
||||
Proposed Mockups:
|
||||
|
||||
(Add mockups of the proposed feature)
|
||||
### Desired behavior
|
||||
<!-- Describe the desired functionality. -->
|
||||
|
||||
## Design Tasks
|
||||
|
||||
* [ ] design tasks
|
||||
### Benefits of the solution
|
||||
<!-- List the possible benefits of the solution and how it fits in the project. -->
|
||||
|
||||
## Development Tasks
|
||||
|
||||
* [ ] development tasks
|
||||
### Possible drawbacks
|
||||
<!--
|
||||
Describe possible drawbacks of the feature and list how it could affect
|
||||
the project i.e. UI discoverability, complexity, impact in more or less
|
||||
number of users, etc.
|
||||
-->
|
||||
|
||||
## QA Tasks
|
||||
|
||||
* [ ] qa (quality assurance) tasks
|
||||
<!-- Ignore the text under this line. -->
|
||||
/label ~"Feature"
|
||||
|
||||
@@ -6,10 +6,37 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
## [Unreleased]
|
||||
### Added:
|
||||
|
||||
### Changed:
|
||||
|
||||
### Fixed:
|
||||
|
||||
### Removed:
|
||||
|
||||
## [0.4.0] - 2018-07-04
|
||||
### Added:
|
||||
- Keyboard Shortcuts and a Shortcuts dialog were implemented. (ZanderBrown)
|
||||
[!33](https://gitlab.gnome.org/World/hammond/merge_requests/33)
|
||||
|
||||
### Changed:
|
||||
- The `FileChooser` of the OPML import was changed to use the `FileChooserNative` widget/API. (ZanderBrown)
|
||||
[!33](https://gitlab.gnome.org/World/hammond/merge_requests/33)
|
||||
- The `EpisdeWidget` was refactored.
|
||||
[!38](https://gitlab.gnome.org/World/hammond/merge_requests/38)
|
||||
- `EpisdeWidget`'s progressbar was changed to be non-blocking and should feel way more responsive now. 9b0ac5b83dadecdff51cd398293afdf0d5276012
|
||||
- An embeded audio player was implemented!
|
||||
[!40](https://gitlab.gnome.org/World/hammond/merge_requests/40)
|
||||
- Various Database changes.
|
||||
[!41](https://gitlab.gnome.org/World/hammond/merge_requests/41)
|
||||
|
||||
### Fixed:
|
||||
- Fixed a bug whre the about dialog would be unclosable. (ZanderBrown) [!37](https://gitlab.gnome.org/World/hammond/merge_requests/37)
|
||||
|
||||
## [0.3.4] - 2018-05-20
|
||||
### Fixed:
|
||||
- Flatpak can now access the Home folder. This fixes the OPML import feature from
|
||||
not being able to access any file.
|
||||
|
||||
## [0.3.3] - 2018-05-19
|
||||
### Added:
|
||||
- Initial functionality for importing shows from an OPML file was implemented.
|
||||
|
||||
Generated
+724
-360
File diff suppressed because it is too large
Load Diff
@@ -68,8 +68,9 @@ sudo ninja -C build install
|
||||
|
||||
#### Dependencies
|
||||
|
||||
* Rust stable 1.26 or later along with cargo.
|
||||
* Rust stable 1.27 or later along with cargo.
|
||||
* Gtk+ 3.22 or later
|
||||
* Gstreamer 1.12 or later
|
||||
* Meson
|
||||
* A network connection
|
||||
|
||||
@@ -78,15 +79,23 @@ Offline build are possible too, but [`cargo-vendor`][vendor] would have to be se
|
||||
**Debian/Ubuntu**
|
||||
|
||||
```sh
|
||||
apt-get update -yqq
|
||||
apt-get install -yqq --no-install-recommends build-essential
|
||||
apt-get install -yqq --no-install-recommends rustc cargo libgtk-3-dev meson
|
||||
apt-get install -yqq cargo rustc libsqlite3-dev libssl-dev libgtk-3-dev meson \
|
||||
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
|
||||
gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
|
||||
gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
|
||||
gstreamer1.0-libav libgstrtspserver-1.0-dev ibgstreamer-plugins-bad1.0-dev
|
||||
```
|
||||
|
||||
**Fedora**
|
||||
|
||||
```sh
|
||||
dnf install -y rust cargo gtk3-devel glib2-devel openssl-devel sqlite-devel meson
|
||||
dnf install -y rust cargo gtk3-devel glib2-devel openssl-devel sqlite-devel meson \
|
||||
gstreamer1-devel gstreamer1-plugins-base-tools gstreamer1-devel-docs \
|
||||
gstreamer1-plugins-base-devel gstreamer1-plugins-base-devel-docs \
|
||||
gstreamer1-plugins-good gstreamer1-plugins-good-extras \
|
||||
gstreamer1-plugins-bad-free gstreamer1-plugins-bad-free-devel \
|
||||
gstreamer1-plugins-bad-free-extras
|
||||
|
||||
```
|
||||
|
||||
If you happen to build it on other distributions please let me know the names
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
|
||||
## Priorities
|
||||
|
||||
- [ ] Unplayed Only and Downloaded only view.
|
||||
- [ ] OPML import/export // Probably need to create a crate.
|
||||
|
||||
## Second
|
||||
|
||||
- [ ] Make use of file metadas, [This](https://github.com/GuillaumeGomez/audio-video-metadata) might be helpfull.
|
||||
- [ ] Make use of file metadas?, [This](https://github.com/GuillaumeGomez/audio-video-metadata) might be helpfull.
|
||||
- [ ] Episode queue
|
||||
- [ ] Embedded player
|
||||
- [ ] MPRIS integration
|
||||
@@ -19,14 +18,8 @@
|
||||
|
||||
- [ ] Download Queue
|
||||
- [ ] Ability to Stream content on demand
|
||||
- [ ] soundcloud and itunes feeds // [This](http://getrssfeed.com) seems intresting.
|
||||
- [ ] rss feeds from soundcloud urls? // [This](http://getrssfeed.com) seems intresting.
|
||||
- [ ] Integrate with Itunes API for various crap?
|
||||
- [ ] YoutubeFeeds?
|
||||
|
||||
## Rest Tasks
|
||||
|
||||
**Would be nice:**
|
||||
|
||||
- [ ] Make Podcast cover fetchng and loading not block the execution of the program at startup.
|
||||
- [ ] Lazy evaluate episode loading based on the show_widget's scrolling.
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ workspace = "../"
|
||||
|
||||
[dependencies]
|
||||
ammonia = "1.1.0"
|
||||
chrono = "0.4.2"
|
||||
chrono = "0.4.4"
|
||||
derive_builder = "0.5.1"
|
||||
lazy_static = "1.0.0"
|
||||
log = "0.4.1"
|
||||
lazy_static = "1.0.1"
|
||||
log = "0.4.2"
|
||||
rayon = "1.0.1"
|
||||
rayon-futures = "0.1.0"
|
||||
rfc822_sanitizer = "0.3.3"
|
||||
@@ -28,14 +28,14 @@ failure_derive = "0.1.1"
|
||||
|
||||
[dependencies.diesel]
|
||||
features = ["sqlite", "r2d2"]
|
||||
version = "1.2.2"
|
||||
version = "1.3.2"
|
||||
|
||||
[dependencies.diesel_migrations]
|
||||
features = ["sqlite"]
|
||||
version = "1.2.0"
|
||||
version = "1.3.0"
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.4.2"
|
||||
rand = "0.5.2"
|
||||
tempdir = "0.3.7"
|
||||
criterion = "0.2.3"
|
||||
pretty_assertions = "0.5.1"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# For documentation on how to configure this file,
|
||||
# see diesel.rs/guides/configuring-diesel-cli
|
||||
|
||||
[print_schema]
|
||||
file = "src/schema.rs"
|
||||
patch_file = "src/schema.patch"
|
||||
@@ -0,0 +1,53 @@
|
||||
ALTER TABLE episode RENAME TO old_table;
|
||||
|
||||
CREATE TABLE episode (
|
||||
title TEXT NOT NULL,
|
||||
uri TEXT,
|
||||
local_uri TEXT,
|
||||
description TEXT,
|
||||
epoch INTEGER NOT NULL DEFAULT 0,
|
||||
length INTEGER,
|
||||
duration INTEGER,
|
||||
guid TEXT,
|
||||
played INTEGER,
|
||||
podcast_id INTEGER NOT NULL,
|
||||
favorite INTEGER DEFAULT 0,
|
||||
archive INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (title, podcast_id)
|
||||
);
|
||||
|
||||
INSERT INTO episode (title, uri, local_uri, description, epoch, length, duration, guid, played, podcast_id, favorite, archive)
|
||||
SELECT title, uri, local_uri, description, epoch, length, duration, guid, played, podcast_id, 0, 0
|
||||
FROM old_table;
|
||||
|
||||
Drop table old_table;
|
||||
|
||||
ALTER TABLE podcast RENAME TO old_table;
|
||||
CREATE TABLE `podcast` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
`title` TEXT NOT NULL,
|
||||
`link` TEXT NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
`image_uri` TEXT,
|
||||
`source_id` INTEGER NOT NULL UNIQUE,
|
||||
`favorite` INTEGER NOT NULL DEFAULT 0,
|
||||
`archive` INTEGER NOT NULL DEFAULT 0,
|
||||
`always_dl` INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
INSERT INTO podcast (
|
||||
id,
|
||||
title,
|
||||
link,
|
||||
description,
|
||||
image_uri,
|
||||
source_id
|
||||
) SELECT id,
|
||||
title,
|
||||
link,
|
||||
description,
|
||||
image_uri,
|
||||
source_id
|
||||
FROM old_table;
|
||||
|
||||
Drop table old_table;
|
||||
@@ -0,0 +1,66 @@
|
||||
ALTER TABLE episode RENAME TO old_table;
|
||||
|
||||
CREATE TABLE episode (
|
||||
title TEXT NOT NULL,
|
||||
uri TEXT,
|
||||
local_uri TEXT,
|
||||
description TEXT,
|
||||
epoch INTEGER NOT NULL DEFAULT 0,
|
||||
length INTEGER,
|
||||
duration INTEGER,
|
||||
guid TEXT,
|
||||
played INTEGER,
|
||||
podcast_id INTEGER NOT NULL,
|
||||
PRIMARY KEY (title, podcast_id)
|
||||
);
|
||||
|
||||
INSERT INTO episode (
|
||||
title,
|
||||
uri,
|
||||
local_uri,
|
||||
description,
|
||||
epoch,
|
||||
length,
|
||||
duration,
|
||||
guid,
|
||||
played,
|
||||
podcast_id
|
||||
) SELECT title,
|
||||
uri,
|
||||
local_uri,
|
||||
description,
|
||||
epoch, length,
|
||||
duration,
|
||||
guid,
|
||||
played,
|
||||
podcast_id
|
||||
FROM old_table;
|
||||
|
||||
Drop table old_table;
|
||||
|
||||
ALTER TABLE podcast RENAME TO old_table;
|
||||
CREATE TABLE `podcast` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
`title` TEXT NOT NULL,
|
||||
`link` TEXT NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
`image_uri` TEXT,
|
||||
`source_id` INTEGER NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
INSERT INTO podcast (
|
||||
id,
|
||||
title,
|
||||
link,
|
||||
description,
|
||||
image_uri,
|
||||
source_id
|
||||
) SELECT id,
|
||||
title,
|
||||
link,
|
||||
description,
|
||||
image_uri,
|
||||
source_id
|
||||
FROM old_table;
|
||||
|
||||
Drop table old_table;
|
||||
@@ -0,0 +1,40 @@
|
||||
ALTER TABLE episodes RENAME TO old_table;
|
||||
ALTER TABLE shows RENAME TO podcast;
|
||||
|
||||
CREATE TABLE episode (
|
||||
title TEXT NOT NULL,
|
||||
uri TEXT,
|
||||
local_uri TEXT,
|
||||
description TEXT,
|
||||
epoch INTEGER NOT NULL DEFAULT 0,
|
||||
length INTEGER,
|
||||
duration INTEGER,
|
||||
guid TEXT,
|
||||
played INTEGER,
|
||||
podcast_id INTEGER NOT NULL,
|
||||
PRIMARY KEY (title, podcast_id)
|
||||
);
|
||||
|
||||
INSERT INTO episode (
|
||||
title,
|
||||
uri,
|
||||
local_uri,
|
||||
description,
|
||||
epoch,
|
||||
length,
|
||||
duration,
|
||||
guid,
|
||||
played,
|
||||
podcast_id
|
||||
) SELECT title,
|
||||
uri,
|
||||
local_uri,
|
||||
description,
|
||||
epoch, length,
|
||||
duration,
|
||||
guid,
|
||||
played,
|
||||
show_id
|
||||
FROM old_table;
|
||||
|
||||
Drop table old_table;
|
||||
@@ -0,0 +1,40 @@
|
||||
ALTER TABLE episode RENAME TO old_table;
|
||||
ALTER TABLE podcast RENAME TO shows;
|
||||
|
||||
CREATE TABLE episodes (
|
||||
title TEXT NOT NULL,
|
||||
uri TEXT,
|
||||
local_uri TEXT,
|
||||
description TEXT,
|
||||
epoch INTEGER NOT NULL DEFAULT 0,
|
||||
length INTEGER,
|
||||
duration INTEGER,
|
||||
guid TEXT,
|
||||
played INTEGER,
|
||||
show_id INTEGER NOT NULL,
|
||||
PRIMARY KEY (title, show_id)
|
||||
);
|
||||
|
||||
INSERT INTO episodes (
|
||||
title,
|
||||
uri,
|
||||
local_uri,
|
||||
description,
|
||||
epoch,
|
||||
length,
|
||||
duration,
|
||||
guid,
|
||||
played,
|
||||
show_id
|
||||
) SELECT title,
|
||||
uri,
|
||||
local_uri,
|
||||
description,
|
||||
epoch, length,
|
||||
duration,
|
||||
guid,
|
||||
played,
|
||||
podcast_id
|
||||
FROM old_table;
|
||||
|
||||
Drop table old_table;
|
||||
@@ -1,4 +1,6 @@
|
||||
//! Database Setup. This is only public to help with some unit tests.
|
||||
// Diesel embed_migrations! triggers the lint
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use diesel::prelude::*;
|
||||
use diesel::r2d2;
|
||||
@@ -66,8 +68,8 @@ fn run_migration_on(connection: &SqliteConnection) -> Result<(), DataError> {
|
||||
pub fn truncate_db() -> Result<(), DataError> {
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
con.execute("DELETE FROM episode")?;
|
||||
con.execute("DELETE FROM podcast")?;
|
||||
con.execute("DELETE FROM episodes")?;
|
||||
con.execute("DELETE FROM shows")?;
|
||||
con.execute("DELETE FROM source")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -23,106 +23,106 @@ pub fn get_sources() -> Result<Vec<Source>, DataError> {
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_podcasts() -> Result<Vec<Podcast>, DataError> {
|
||||
use schema::podcast::dsl::*;
|
||||
pub fn get_podcasts() -> Result<Vec<Show>, DataError> {
|
||||
use schema::shows::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
podcast
|
||||
shows
|
||||
.order(title.asc())
|
||||
.load::<Podcast>(&con)
|
||||
.load::<Show>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_podcasts_filter(filter_ids: &[i32]) -> Result<Vec<Podcast>, DataError> {
|
||||
use schema::podcast::dsl::*;
|
||||
pub fn get_podcasts_filter(filter_ids: &[i32]) -> Result<Vec<Show>, DataError> {
|
||||
use schema::shows::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
podcast
|
||||
shows
|
||||
.order(title.asc())
|
||||
.filter(id.ne_all(filter_ids))
|
||||
.load::<Podcast>(&con)
|
||||
.load::<Show>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_episodes() -> Result<Vec<Episode>, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
episode
|
||||
episodes
|
||||
.order(epoch.desc())
|
||||
.load::<Episode>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub(crate) fn get_downloaded_episodes() -> Result<Vec<EpisodeCleanerQuery>, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
pub(crate) fn get_downloaded_episodes() -> Result<Vec<EpisodeCleanerModel>, DataError> {
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
episode
|
||||
episodes
|
||||
.select((rowid, local_uri, played))
|
||||
.filter(local_uri.is_not_null())
|
||||
.load::<EpisodeCleanerQuery>(&con)
|
||||
.load::<EpisodeCleanerModel>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
// pub(crate) fn get_played_episodes() -> Result<Vec<Episode>, DataError> {
|
||||
// use schema::episode::dsl::*;
|
||||
// use schema::episodes::dsl::*;
|
||||
|
||||
// let db = connection();
|
||||
// let con = db.get()?;
|
||||
// episode
|
||||
// episodes
|
||||
// .filter(played.is_not_null())
|
||||
// .load::<Episode>(&con)
|
||||
// .map_err(From::from)
|
||||
// }
|
||||
|
||||
pub(crate) fn get_played_cleaner_episodes() -> Result<Vec<EpisodeCleanerQuery>, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
pub(crate) fn get_played_cleaner_episodes() -> Result<Vec<EpisodeCleanerModel>, DataError> {
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
episode
|
||||
episodes
|
||||
.select((rowid, local_uri, played))
|
||||
.filter(played.is_not_null())
|
||||
.load::<EpisodeCleanerQuery>(&con)
|
||||
.load::<EpisodeCleanerModel>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_episode_from_rowid(ep_id: i32) -> Result<Episode, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
episode
|
||||
episodes
|
||||
.filter(rowid.eq(ep_id))
|
||||
.get_result::<Episode>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_episode_widget_from_rowid(ep_id: i32) -> Result<EpisodeWidgetQuery, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
pub fn get_episode_widget_from_rowid(ep_id: i32) -> Result<EpisodeWidgetModel, DataError> {
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
episode
|
||||
episodes
|
||||
.select((
|
||||
rowid, title, uri, local_uri, epoch, length, duration, played, podcast_id,
|
||||
rowid, title, uri, local_uri, epoch, length, duration, played, show_id,
|
||||
))
|
||||
.filter(rowid.eq(ep_id))
|
||||
.get_result::<EpisodeWidgetQuery>(&con)
|
||||
.get_result::<EpisodeWidgetModel>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_episode_local_uri_from_id(ep_id: i32) -> Result<Option<String>, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
episode
|
||||
episodes
|
||||
.filter(rowid.eq(ep_id))
|
||||
.select(local_uri)
|
||||
.get_result::<Option<String>>(&con)
|
||||
@@ -132,48 +132,48 @@ pub fn get_episode_local_uri_from_id(ep_id: i32) -> Result<Option<String>, DataE
|
||||
pub fn get_episodes_widgets_filter_limit(
|
||||
filter_ids: &[i32],
|
||||
limit: u32,
|
||||
) -> Result<Vec<EpisodeWidgetQuery>, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
) -> Result<Vec<EpisodeWidgetModel>, DataError> {
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
let columns = (
|
||||
rowid, title, uri, local_uri, epoch, length, duration, played, podcast_id,
|
||||
rowid, title, uri, local_uri, epoch, length, duration, played, show_id,
|
||||
);
|
||||
|
||||
episode
|
||||
episodes
|
||||
.select(columns)
|
||||
.order(epoch.desc())
|
||||
.filter(podcast_id.ne_all(filter_ids))
|
||||
.filter(show_id.ne_all(filter_ids))
|
||||
.limit(i64::from(limit))
|
||||
.load::<EpisodeWidgetQuery>(&con)
|
||||
.load::<EpisodeWidgetModel>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_podcast_from_id(pid: i32) -> Result<Podcast, DataError> {
|
||||
use schema::podcast::dsl::*;
|
||||
pub fn get_podcast_from_id(pid: i32) -> Result<Show, DataError> {
|
||||
use schema::shows::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
podcast
|
||||
shows
|
||||
.filter(id.eq(pid))
|
||||
.get_result::<Podcast>(&con)
|
||||
.get_result::<Show>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_podcast_cover_from_id(pid: i32) -> Result<PodcastCoverQuery, DataError> {
|
||||
use schema::podcast::dsl::*;
|
||||
pub fn get_podcast_cover_from_id(pid: i32) -> Result<ShowCoverModel, DataError> {
|
||||
use schema::shows::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
podcast
|
||||
shows
|
||||
.select((id, title, image_uri))
|
||||
.filter(id.eq(pid))
|
||||
.get_result::<PodcastCoverQuery>(&con)
|
||||
.get_result::<ShowCoverModel>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_pd_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
pub fn get_pd_episodes(parent: &Show) -> Result<Vec<Episode>, DataError> {
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
@@ -183,7 +183,7 @@ pub fn get_pd_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataError> {
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_pd_episodes_count(parent: &Podcast) -> Result<i64, DataError> {
|
||||
pub fn get_pd_episodes_count(parent: &Show) -> Result<i64, DataError> {
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
@@ -193,24 +193,24 @@ pub fn get_pd_episodes_count(parent: &Podcast) -> Result<i64, DataError> {
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_pd_episodeswidgets(parent: &Podcast) -> Result<Vec<EpisodeWidgetQuery>, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
pub fn get_pd_episodeswidgets(parent: &Show) -> Result<Vec<EpisodeWidgetModel>, DataError> {
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
let columns = (
|
||||
rowid, title, uri, local_uri, epoch, length, duration, played, podcast_id,
|
||||
rowid, title, uri, local_uri, epoch, length, duration, played, show_id,
|
||||
);
|
||||
|
||||
episode
|
||||
episodes
|
||||
.select(columns)
|
||||
.filter(podcast_id.eq(parent.id()))
|
||||
.filter(show_id.eq(parent.id()))
|
||||
.order(epoch.desc())
|
||||
.load::<EpisodeWidgetQuery>(&con)
|
||||
.load::<EpisodeWidgetModel>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_pd_unplayed_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
pub fn get_pd_unplayed_episodes(parent: &Show) -> Result<Vec<Episode>, DataError> {
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
@@ -221,8 +221,8 @@ pub fn get_pd_unplayed_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataEr
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
// pub(crate) fn get_pd_episodes_limit(parent: &Podcast, limit: u32) ->
|
||||
// Result<Vec<Episode>, DataError> { use schema::episode::dsl::*;
|
||||
// pub(crate) fn get_pd_episodes_limit(parent: &Show, limit: u32) ->
|
||||
// Result<Vec<Episode>, DataError> { use schema::episodes::dsl::*;
|
||||
|
||||
// let db = connection();
|
||||
// let con = db.get()?;
|
||||
@@ -256,25 +256,25 @@ pub fn get_source_from_id(id_: i32) -> Result<Source, DataError> {
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_podcast_from_source_id(sid: i32) -> Result<Podcast, DataError> {
|
||||
use schema::podcast::dsl::*;
|
||||
pub fn get_podcast_from_source_id(sid: i32) -> Result<Show, DataError> {
|
||||
use schema::shows::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
podcast
|
||||
shows
|
||||
.filter(source_id.eq(sid))
|
||||
.get_result::<Podcast>(&con)
|
||||
.get_result::<Show>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_episode_from_pk(title_: &str, pid: i32) -> Result<Episode, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
episode
|
||||
episodes
|
||||
.filter(title.eq(title_))
|
||||
.filter(podcast_id.eq(pid))
|
||||
.filter(show_id.eq(pid))
|
||||
.get_result::<Episode>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
@@ -283,19 +283,19 @@ pub(crate) fn get_episode_minimal_from_pk(
|
||||
title_: &str,
|
||||
pid: i32,
|
||||
) -> Result<EpisodeMinimal, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
episode
|
||||
.select((rowid, title, uri, epoch, duration, guid, podcast_id))
|
||||
episodes
|
||||
.select((rowid, title, uri, epoch, length, duration, guid, show_id))
|
||||
.filter(title.eq(title_))
|
||||
.filter(podcast_id.eq(pid))
|
||||
.filter(show_id.eq(pid))
|
||||
.get_result::<EpisodeMinimal>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub(crate) fn remove_feed(pd: &Podcast) -> Result<(), DataError> {
|
||||
pub(crate) fn remove_feed(pd: &Show) -> Result<(), DataError> {
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
@@ -314,16 +314,16 @@ fn delete_source(con: &SqliteConnection, source_id: i32) -> QueryResult<usize> {
|
||||
diesel::delete(source.filter(id.eq(source_id))).execute(con)
|
||||
}
|
||||
|
||||
fn delete_podcast(con: &SqliteConnection, podcast_id: i32) -> QueryResult<usize> {
|
||||
use schema::podcast::dsl::*;
|
||||
fn delete_podcast(con: &SqliteConnection, show_id: i32) -> QueryResult<usize> {
|
||||
use schema::shows::dsl::*;
|
||||
|
||||
diesel::delete(podcast.filter(id.eq(podcast_id))).execute(con)
|
||||
diesel::delete(shows.filter(id.eq(show_id))).execute(con)
|
||||
}
|
||||
|
||||
fn delete_podcast_episodes(con: &SqliteConnection, parent_id: i32) -> QueryResult<usize> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
|
||||
diesel::delete(episode.filter(podcast_id.eq(parent_id))).execute(con)
|
||||
diesel::delete(episodes.filter(show_id.eq(parent_id))).execute(con)
|
||||
}
|
||||
|
||||
pub fn source_exists(url: &str) -> Result<bool, DataError> {
|
||||
@@ -338,70 +338,70 @@ pub fn source_exists(url: &str) -> Result<bool, DataError> {
|
||||
}
|
||||
|
||||
pub(crate) fn podcast_exists(source_id_: i32) -> Result<bool, DataError> {
|
||||
use schema::podcast::dsl::*;
|
||||
use schema::shows::dsl::*;
|
||||
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
select(exists(podcast.filter(source_id.eq(source_id_))))
|
||||
select(exists(shows.filter(source_id.eq(source_id_))))
|
||||
.get_result(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
pub(crate) fn episode_exists(title_: &str, podcast_id_: i32) -> Result<bool, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
pub(crate) fn episode_exists(title_: &str, show_id_: i32) -> Result<bool, DataError> {
|
||||
use schema::episodes::dsl::*;
|
||||
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
select(exists(episode.filter(podcast_id.eq(podcast_id_)).filter(title.eq(title_))))
|
||||
select(exists(episodes.filter(show_id.eq(show_id_)).filter(title.eq(title_))))
|
||||
.get_result(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
/// Check if the `episode table contains any rows
|
||||
/// Check if the `episodes table contains any rows
|
||||
///
|
||||
/// Return true if `episode` table is populated.
|
||||
/// Return true if `episodes` table is populated.
|
||||
pub fn is_episodes_populated() -> Result<bool, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
select(exists(episode.as_query()))
|
||||
select(exists(episodes.as_query()))
|
||||
.get_result(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
/// Check if the `podcast` table contains any rows
|
||||
/// Check if the `shows` table contains any rows
|
||||
///
|
||||
/// Return true if `podcast table is populated.
|
||||
/// Return true if `shows table is populated.
|
||||
pub fn is_podcasts_populated(filter_ids: &[i32]) -> Result<bool, DataError> {
|
||||
use schema::podcast::dsl::*;
|
||||
use schema::shows::dsl::*;
|
||||
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
select(exists(podcast.filter(id.ne_all(filter_ids))))
|
||||
select(exists(shows.filter(id.ne_all(filter_ids))))
|
||||
.get_result(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub(crate) fn index_new_episodes(eps: &[NewEpisode]) -> Result<(), DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
diesel::insert_into(episode)
|
||||
diesel::insert_into(episodes)
|
||||
.values(eps)
|
||||
.execute(&*con)
|
||||
.map_err(From::from)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
pub fn update_none_to_played_now(parent: &Podcast) -> Result<usize, DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
pub fn update_none_to_played_now(parent: &Show) -> Result<usize, DataError> {
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use rss;
|
||||
use dbqueries;
|
||||
use errors::DataError;
|
||||
use models::{Index, IndexState, Update};
|
||||
use models::{NewEpisode, NewEpisodeMinimal, NewPodcast, Podcast};
|
||||
use models::{NewEpisode, NewEpisodeMinimal, NewShow, Show};
|
||||
|
||||
/// Wrapper struct that hold a `Source` id and the `rss::Channel`
|
||||
/// that corresponds to the `Source.uri` field.
|
||||
@@ -31,15 +31,15 @@ impl Feed {
|
||||
.and_then(move |pd| self.index_channel_items(pd))
|
||||
}
|
||||
|
||||
fn parse_podcast(&self) -> NewPodcast {
|
||||
NewPodcast::new(&self.channel, self.source_id)
|
||||
fn parse_podcast(&self) -> NewShow {
|
||||
NewShow::new(&self.channel, self.source_id)
|
||||
}
|
||||
|
||||
fn parse_podcast_async(&self) -> impl Future<Item = NewPodcast, Error = DataError> + Send {
|
||||
fn parse_podcast_async(&self) -> impl Future<Item = NewShow, Error = DataError> + Send {
|
||||
ok(self.parse_podcast())
|
||||
}
|
||||
|
||||
fn index_channel_items(self, pd: Podcast) -> impl Future<Item = (), Error = DataError> + Send {
|
||||
fn index_channel_items(self, pd: Show) -> impl Future<Item = (), Error = DataError> + Send {
|
||||
let stream = stream::iter_ok::<_, DataError>(self.channel.into_items());
|
||||
|
||||
// Parse the episodes
|
||||
@@ -65,12 +65,12 @@ fn determine_ep_state(
|
||||
item: &rss::Item,
|
||||
) -> Result<IndexState<NewEpisode>, DataError> {
|
||||
// Check if feed exists
|
||||
let exists = dbqueries::episode_exists(ep.title(), ep.podcast_id())?;
|
||||
let exists = dbqueries::episode_exists(ep.title(), ep.show_id())?;
|
||||
|
||||
if !exists {
|
||||
Ok(IndexState::Index(ep.into_new_episode(item)))
|
||||
} else {
|
||||
let old = dbqueries::get_episode_minimal_from_pk(ep.title(), ep.podcast_id())?;
|
||||
let old = dbqueries::get_episode_minimal_from_pk(ep.title(), ep.show_id())?;
|
||||
let rowid = old.rowid();
|
||||
|
||||
if ep != old {
|
||||
@@ -174,7 +174,8 @@ mod tests {
|
||||
fn test_complete_index() {
|
||||
truncate_db().unwrap();
|
||||
|
||||
let feeds: Vec<_> = URLS.iter()
|
||||
let feeds: Vec<_> = URLS
|
||||
.iter()
|
||||
.map(|&(path, url)| {
|
||||
// Create and insert a Source into db
|
||||
let s = Source::from_url(url).unwrap();
|
||||
@@ -203,7 +204,7 @@ mod tests {
|
||||
let file = fs::File::open(path).unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let pd = NewPodcast::new(&channel, 42);
|
||||
let pd = NewShow::new(&channel, 42);
|
||||
assert_eq!(feed.parse_podcast(), pd);
|
||||
}
|
||||
|
||||
|
||||
+15
-9
@@ -10,17 +10,21 @@
|
||||
items_after_statements, used_underscore_binding
|
||||
)
|
||||
)]
|
||||
// Enable lint group collections
|
||||
#![warn(nonstandard_style, edition_2018, rust_2018_idioms, bad_style, unused)]
|
||||
// standalone lints
|
||||
#![warn(
|
||||
bad_style, const_err, dead_code, improper_ctypes, legacy_directory_ownership,
|
||||
non_shorthand_field_patterns, no_mangle_generic_items, overflowing_literals, path_statements,
|
||||
patterns_in_fns_without_body, plugin_as_library, private_in_public, private_no_mangle_fns,
|
||||
private_no_mangle_statics, safe_extern_statics, unconditional_recursion,
|
||||
unions_with_drop_fields, unused_allocation, unused_comparisons, unused_parens, while_true,
|
||||
missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts,
|
||||
unused_extern_crates, unused
|
||||
const_err, improper_ctypes, non_shorthand_field_patterns, no_mangle_generic_items,
|
||||
overflowing_literals, plugin_as_library, private_no_mangle_fns, private_no_mangle_statics,
|
||||
unconditional_recursion, unions_with_drop_fields, while_true, missing_debug_implementations,
|
||||
missing_docs, trivial_casts, trivial_numeric_casts, elided_lifetime_in_paths,
|
||||
missing_copy_implementations
|
||||
)]
|
||||
#![deny(warnings)]
|
||||
|
||||
// warn when code is not using dyn Trait syntax. req rustc 1.27
|
||||
// #![deny(bare_trait_object)]
|
||||
|
||||
//! FIXME: Docs
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -77,11 +81,13 @@ pub mod utils;
|
||||
|
||||
pub use feed::{Feed, FeedBuilder};
|
||||
pub use models::Save;
|
||||
pub use models::{Episode, EpisodeWidgetQuery, Podcast, PodcastCoverQuery, Source};
|
||||
pub use models::{Episode, EpisodeWidgetModel, Show, ShowCoverModel, Source};
|
||||
|
||||
// Set the user agent, See #53 for more
|
||||
// Keep this in sync with Tor-browser releases
|
||||
const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0";
|
||||
/// The user-agent to be used for all the requests.
|
||||
/// It originates from the Tor-browser UA.
|
||||
pub const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0";
|
||||
|
||||
/// [XDG Base Direcotory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) Paths.
|
||||
#[allow(missing_debug_implementations)]
|
||||
|
||||
@@ -5,14 +5,14 @@ use diesel::SaveChangesDsl;
|
||||
|
||||
use database::connection;
|
||||
use errors::DataError;
|
||||
use models::{Podcast, Save};
|
||||
use schema::episode;
|
||||
use models::{Save, Show};
|
||||
use schema::episodes;
|
||||
|
||||
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
|
||||
#[table_name = "episode"]
|
||||
#[table_name = "episodes"]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[primary_key(title, podcast_id)]
|
||||
#[belongs_to(Podcast, foreign_key = "podcast_id")]
|
||||
#[primary_key(title, show_id)]
|
||||
#[belongs_to(Show, foreign_key = "show_id")]
|
||||
#[derive(Debug, Clone)]
|
||||
/// Diesel Model of the episode table.
|
||||
pub struct Episode {
|
||||
@@ -26,9 +26,7 @@ pub struct Episode {
|
||||
duration: Option<i32>,
|
||||
guid: Option<String>,
|
||||
played: Option<i32>,
|
||||
favorite: bool,
|
||||
archive: bool,
|
||||
podcast_id: i32,
|
||||
show_id: i32,
|
||||
}
|
||||
|
||||
impl Save<Episode> for Episode {
|
||||
@@ -154,32 +152,9 @@ impl Episode {
|
||||
self.played = value;
|
||||
}
|
||||
|
||||
/// Represents the archiving policy for the episode.
|
||||
pub fn archive(&self) -> bool {
|
||||
self.archive
|
||||
}
|
||||
|
||||
/// Set the `archive` policy.
|
||||
///
|
||||
/// If true, the download cleanr will ignore the episode
|
||||
/// and the corresponding media value will never be automaticly deleted.
|
||||
pub fn set_archive(&mut self, b: bool) {
|
||||
self.archive = b
|
||||
}
|
||||
|
||||
/// Get the `favorite` status of the `Episode`.
|
||||
pub fn favorite(&self) -> bool {
|
||||
self.favorite
|
||||
}
|
||||
|
||||
/// Set `favorite` status.
|
||||
pub fn set_favorite(&mut self, b: bool) {
|
||||
self.favorite = b
|
||||
}
|
||||
|
||||
/// `Podcast` table foreign key.
|
||||
pub fn podcast_id(&self) -> i32 {
|
||||
self.podcast_id
|
||||
/// `Show` table foreign key.
|
||||
pub fn show_id(&self) -> i32 {
|
||||
self.show_id
|
||||
}
|
||||
|
||||
/// Sets the `played` value with the current `epoch` timestap and save it.
|
||||
@@ -191,12 +166,12 @@ impl Episode {
|
||||
}
|
||||
|
||||
#[derive(Queryable, AsChangeset, PartialEq)]
|
||||
#[table_name = "episode"]
|
||||
#[table_name = "episodes"]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[primary_key(title, podcast_id)]
|
||||
#[primary_key(title, show_id)]
|
||||
#[derive(Debug, Clone)]
|
||||
/// Diesel Model to be used for constructing `EpisodeWidgets`.
|
||||
pub struct EpisodeWidgetQuery {
|
||||
pub struct EpisodeWidgetModel {
|
||||
rowid: i32,
|
||||
title: String,
|
||||
uri: Option<String>,
|
||||
@@ -205,14 +180,12 @@ pub struct EpisodeWidgetQuery {
|
||||
length: Option<i32>,
|
||||
duration: Option<i32>,
|
||||
played: Option<i32>,
|
||||
// favorite: bool,
|
||||
// archive: bool,
|
||||
podcast_id: i32,
|
||||
show_id: i32,
|
||||
}
|
||||
|
||||
impl From<Episode> for EpisodeWidgetQuery {
|
||||
fn from(e: Episode) -> EpisodeWidgetQuery {
|
||||
EpisodeWidgetQuery {
|
||||
impl From<Episode> for EpisodeWidgetModel {
|
||||
fn from(e: Episode) -> EpisodeWidgetModel {
|
||||
EpisodeWidgetModel {
|
||||
rowid: e.rowid,
|
||||
title: e.title,
|
||||
uri: e.uri,
|
||||
@@ -221,30 +194,30 @@ impl From<Episode> for EpisodeWidgetQuery {
|
||||
length: e.length,
|
||||
duration: e.duration,
|
||||
played: e.played,
|
||||
podcast_id: e.podcast_id,
|
||||
show_id: e.show_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Save<usize> for EpisodeWidgetQuery {
|
||||
impl Save<usize> for EpisodeWidgetModel {
|
||||
type Error = DataError;
|
||||
|
||||
/// Helper method to easily save/"sync" current state of self to the
|
||||
/// Database.
|
||||
fn save(&self) -> Result<usize, Self::Error> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
|
||||
let db = connection();
|
||||
let tempdb = db.get()?;
|
||||
|
||||
diesel::update(episode.filter(rowid.eq(self.rowid)))
|
||||
diesel::update(episodes.filter(rowid.eq(self.rowid)))
|
||||
.set(self)
|
||||
.execute(&*tempdb)
|
||||
.map_err(From::from)
|
||||
}
|
||||
}
|
||||
|
||||
impl EpisodeWidgetQuery {
|
||||
impl EpisodeWidgetModel {
|
||||
/// Get the value of the sqlite's `ROW_ID`
|
||||
pub fn rowid(&self) -> i32 {
|
||||
self.rowid
|
||||
@@ -319,32 +292,9 @@ impl EpisodeWidgetQuery {
|
||||
self.played = value;
|
||||
}
|
||||
|
||||
// /// Represents the archiving policy for the episode.
|
||||
// pub fn archive(&self) -> bool {
|
||||
// self.archive
|
||||
// }
|
||||
|
||||
// /// Set the `archive` policy.
|
||||
// ///
|
||||
// /// If true, the download cleanr will ignore the episode
|
||||
// /// and the corresponding media value will never be automaticly deleted.
|
||||
// pub fn set_archive(&mut self, b: bool) {
|
||||
// self.archive = b
|
||||
// }
|
||||
|
||||
// /// Get the `favorite` status of the `Episode`.
|
||||
// pub fn favorite(&self) -> bool {
|
||||
// self.favorite
|
||||
// }
|
||||
|
||||
// /// Set `favorite` status.
|
||||
// pub fn set_favorite(&mut self, b: bool) {
|
||||
// self.favorite = b
|
||||
// }
|
||||
|
||||
/// `Podcast` table foreign key.
|
||||
pub fn podcast_id(&self) -> i32 {
|
||||
self.podcast_id
|
||||
/// `Show` table foreign key.
|
||||
pub fn show_id(&self) -> i32 {
|
||||
self.show_id
|
||||
}
|
||||
|
||||
/// Sets the `played` value with the current `epoch` timestap and save it.
|
||||
@@ -356,38 +306,38 @@ impl EpisodeWidgetQuery {
|
||||
}
|
||||
|
||||
#[derive(Queryable, AsChangeset, PartialEq)]
|
||||
#[table_name = "episode"]
|
||||
#[table_name = "episodes"]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[primary_key(title, podcast_id)]
|
||||
#[primary_key(title, show_id)]
|
||||
#[derive(Debug, Clone)]
|
||||
/// Diesel Model to be used internal with the `utils::checkup` function.
|
||||
pub struct EpisodeCleanerQuery {
|
||||
pub struct EpisodeCleanerModel {
|
||||
rowid: i32,
|
||||
local_uri: Option<String>,
|
||||
played: Option<i32>,
|
||||
}
|
||||
|
||||
impl Save<usize> for EpisodeCleanerQuery {
|
||||
impl Save<usize> for EpisodeCleanerModel {
|
||||
type Error = DataError;
|
||||
|
||||
/// Helper method to easily save/"sync" current state of self to the
|
||||
/// Database.
|
||||
fn save(&self) -> Result<usize, Self::Error> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
|
||||
let db = connection();
|
||||
let tempdb = db.get()?;
|
||||
|
||||
diesel::update(episode.filter(rowid.eq(self.rowid)))
|
||||
diesel::update(episodes.filter(rowid.eq(self.rowid)))
|
||||
.set(self)
|
||||
.execute(&*tempdb)
|
||||
.map_err(From::from)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Episode> for EpisodeCleanerQuery {
|
||||
fn from(e: Episode) -> EpisodeCleanerQuery {
|
||||
EpisodeCleanerQuery {
|
||||
impl From<Episode> for EpisodeCleanerModel {
|
||||
fn from(e: Episode) -> EpisodeCleanerModel {
|
||||
EpisodeCleanerModel {
|
||||
rowid: e.rowid(),
|
||||
local_uri: e.local_uri,
|
||||
played: e.played,
|
||||
@@ -395,7 +345,7 @@ impl From<Episode> for EpisodeCleanerQuery {
|
||||
}
|
||||
}
|
||||
|
||||
impl EpisodeCleanerQuery {
|
||||
impl EpisodeCleanerModel {
|
||||
/// Get the value of the sqlite's `ROW_ID`
|
||||
pub fn rowid(&self) -> i32 {
|
||||
self.rowid
|
||||
@@ -428,9 +378,9 @@ impl EpisodeCleanerQuery {
|
||||
}
|
||||
|
||||
#[derive(Queryable, AsChangeset, PartialEq)]
|
||||
#[table_name = "episode"]
|
||||
#[table_name = "episodes"]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[primary_key(title, podcast_id)]
|
||||
#[primary_key(title, show_id)]
|
||||
#[derive(Debug, Clone)]
|
||||
/// Diesel Model to be used for FIXME.
|
||||
pub struct EpisodeMinimal {
|
||||
@@ -438,9 +388,10 @@ pub struct EpisodeMinimal {
|
||||
title: String,
|
||||
uri: Option<String>,
|
||||
epoch: i32,
|
||||
length: Option<i32>,
|
||||
duration: Option<i32>,
|
||||
guid: Option<String>,
|
||||
podcast_id: i32,
|
||||
show_id: i32,
|
||||
}
|
||||
|
||||
impl From<Episode> for EpisodeMinimal {
|
||||
@@ -449,10 +400,11 @@ impl From<Episode> for EpisodeMinimal {
|
||||
rowid: e.rowid,
|
||||
title: e.title,
|
||||
uri: e.uri,
|
||||
length: e.length,
|
||||
guid: e.guid,
|
||||
epoch: e.epoch,
|
||||
duration: e.duration,
|
||||
podcast_id: e.podcast_id,
|
||||
show_id: e.show_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,6 +440,18 @@ impl EpisodeMinimal {
|
||||
self.epoch
|
||||
}
|
||||
|
||||
/// Get the `length`.
|
||||
///
|
||||
/// The number represents the size of the file in bytes.
|
||||
pub fn length(&self) -> Option<i32> {
|
||||
self.length
|
||||
}
|
||||
|
||||
/// Set the `length`.
|
||||
pub fn set_length(&mut self, value: Option<i32>) {
|
||||
self.length = value;
|
||||
}
|
||||
|
||||
/// Get the `duration` value.
|
||||
///
|
||||
/// The number represents the duration of the item/episode in seconds.
|
||||
@@ -495,8 +459,8 @@ impl EpisodeMinimal {
|
||||
self.duration
|
||||
}
|
||||
|
||||
/// `Podcast` table foreign key.
|
||||
pub fn podcast_id(&self) -> i32 {
|
||||
self.podcast_id
|
||||
/// `Show` table foreign key.
|
||||
pub fn show_id(&self) -> i32 {
|
||||
self.show_id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
mod new_episode;
|
||||
mod new_podcast;
|
||||
mod new_show;
|
||||
mod new_source;
|
||||
|
||||
mod episode;
|
||||
mod podcast;
|
||||
mod show;
|
||||
mod source;
|
||||
|
||||
// use futures::prelude::*;
|
||||
// use futures::future::*;
|
||||
|
||||
pub(crate) use self::episode::EpisodeCleanerQuery;
|
||||
pub(crate) use self::episode::EpisodeCleanerModel;
|
||||
pub(crate) use self::new_episode::{NewEpisode, NewEpisodeMinimal};
|
||||
pub(crate) use self::new_podcast::NewPodcast;
|
||||
pub(crate) use self::new_show::NewShow;
|
||||
pub(crate) use self::new_source::NewSource;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) use self::new_episode::NewEpisodeBuilder;
|
||||
#[cfg(test)]
|
||||
pub(crate) use self::new_podcast::NewPodcastBuilder;
|
||||
pub(crate) use self::new_show::NewShowBuilder;
|
||||
|
||||
pub use self::episode::{Episode, EpisodeMinimal, EpisodeWidgetQuery};
|
||||
pub use self::podcast::{Podcast, PodcastCoverQuery};
|
||||
pub use self::episode::{Episode, EpisodeMinimal, EpisodeWidgetModel};
|
||||
pub use self::show::{Show, ShowCoverModel};
|
||||
pub use self::source::Source;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
||||
@@ -9,11 +9,11 @@ use dbqueries;
|
||||
use errors::DataError;
|
||||
use models::{Episode, EpisodeMinimal, Index, Insert, Update};
|
||||
use parser;
|
||||
use schema::episode;
|
||||
use schema::episodes;
|
||||
use utils::url_cleaner;
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "episode"]
|
||||
#[table_name = "episodes"]
|
||||
#[derive(Debug, Clone, Default, Builder, PartialEq)]
|
||||
#[builder(default)]
|
||||
#[builder(derive(Debug))]
|
||||
@@ -26,7 +26,7 @@ pub(crate) struct NewEpisode {
|
||||
duration: Option<i32>,
|
||||
guid: Option<String>,
|
||||
epoch: i32,
|
||||
podcast_id: i32,
|
||||
show_id: i32,
|
||||
}
|
||||
|
||||
impl From<NewEpisodeMinimal> for NewEpisode {
|
||||
@@ -36,7 +36,7 @@ impl From<NewEpisodeMinimal> for NewEpisode {
|
||||
.uri(e.uri)
|
||||
.duration(e.duration)
|
||||
.epoch(e.epoch)
|
||||
.podcast_id(e.podcast_id)
|
||||
.show_id(e.show_id)
|
||||
.guid(e.guid)
|
||||
.build()
|
||||
.unwrap()
|
||||
@@ -47,12 +47,12 @@ impl Insert<()> for NewEpisode {
|
||||
type Error = DataError;
|
||||
|
||||
fn insert(&self) -> Result<(), DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
info!("Inserting {:?}", self.title);
|
||||
diesel::insert_into(episode)
|
||||
diesel::insert_into(episodes)
|
||||
.values(self)
|
||||
.execute(&con)
|
||||
.map_err(From::from)
|
||||
@@ -64,12 +64,12 @@ impl Update<()> for NewEpisode {
|
||||
type Error = DataError;
|
||||
|
||||
fn update(&self, episode_id: i32) -> Result<(), DataError> {
|
||||
use schema::episode::dsl::*;
|
||||
use schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
info!("Updating {:?}", self.title);
|
||||
diesel::update(episode.filter(rowid.eq(episode_id)))
|
||||
diesel::update(episodes.filter(rowid.eq(episode_id)))
|
||||
.set(self)
|
||||
.execute(&con)
|
||||
.map_err(From::from)
|
||||
@@ -83,10 +83,10 @@ impl Index<()> for NewEpisode {
|
||||
// Does not update the episode description if it's the only thing that has
|
||||
// changed.
|
||||
fn index(&self) -> Result<(), DataError> {
|
||||
let exists = dbqueries::episode_exists(self.title(), self.podcast_id())?;
|
||||
let exists = dbqueries::episode_exists(self.title(), self.show_id())?;
|
||||
|
||||
if exists {
|
||||
let other = dbqueries::get_episode_minimal_from_pk(self.title(), self.podcast_id())?;
|
||||
let other = dbqueries::get_episode_minimal_from_pk(self.title(), self.show_id())?;
|
||||
|
||||
if self != &other {
|
||||
self.update(other.rowid())
|
||||
@@ -101,17 +101,23 @@ impl Index<()> for NewEpisode {
|
||||
|
||||
impl PartialEq<EpisodeMinimal> for NewEpisode {
|
||||
fn eq(&self, other: &EpisodeMinimal) -> bool {
|
||||
(self.title() == other.title()) && (self.uri() == other.uri())
|
||||
&& (self.duration() == other.duration()) && (self.epoch() == other.epoch())
|
||||
&& (self.guid() == other.guid()) && (self.podcast_id() == other.podcast_id())
|
||||
(self.title() == other.title())
|
||||
&& (self.uri() == other.uri())
|
||||
&& (self.duration() == other.duration())
|
||||
&& (self.epoch() == other.epoch())
|
||||
&& (self.guid() == other.guid())
|
||||
&& (self.show_id() == other.show_id())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<Episode> for NewEpisode {
|
||||
fn eq(&self, other: &Episode) -> bool {
|
||||
(self.title() == other.title()) && (self.uri() == other.uri())
|
||||
&& (self.duration() == other.duration()) && (self.epoch() == other.epoch())
|
||||
&& (self.guid() == other.guid()) && (self.podcast_id() == other.podcast_id())
|
||||
(self.title() == other.title())
|
||||
&& (self.uri() == other.uri())
|
||||
&& (self.duration() == other.duration())
|
||||
&& (self.epoch() == other.epoch())
|
||||
&& (self.guid() == other.guid())
|
||||
&& (self.show_id() == other.show_id())
|
||||
&& (self.description() == other.description())
|
||||
&& (self.length() == other.length())
|
||||
}
|
||||
@@ -120,14 +126,14 @@ impl PartialEq<Episode> for NewEpisode {
|
||||
impl NewEpisode {
|
||||
/// Parses an `rss::Item` into a `NewEpisode` Struct.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn new(item: &rss::Item, podcast_id: i32) -> Result<Self, DataError> {
|
||||
NewEpisodeMinimal::new(item, podcast_id).map(|ep| ep.into_new_episode(item))
|
||||
pub(crate) fn new(item: &rss::Item, show_id: i32) -> Result<Self, DataError> {
|
||||
NewEpisodeMinimal::new(item, show_id).map(|ep| ep.into_new_episode(item))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn to_episode(&self) -> Result<Episode, DataError> {
|
||||
self.index()?;
|
||||
dbqueries::get_episode_from_pk(&self.title, self.podcast_id).map_err(From::from)
|
||||
dbqueries::get_episode_from_pk(&self.title, self.show_id).map_err(From::from)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,30 +167,34 @@ impl NewEpisode {
|
||||
self.length
|
||||
}
|
||||
|
||||
pub(crate) fn podcast_id(&self) -> i32 {
|
||||
self.podcast_id
|
||||
pub(crate) fn show_id(&self) -> i32 {
|
||||
self.show_id
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "episode"]
|
||||
#[table_name = "episodes"]
|
||||
#[derive(Debug, Clone, Builder, PartialEq)]
|
||||
#[builder(derive(Debug))]
|
||||
#[builder(setter(into))]
|
||||
pub(crate) struct NewEpisodeMinimal {
|
||||
title: String,
|
||||
uri: Option<String>,
|
||||
length: Option<i32>,
|
||||
duration: Option<i32>,
|
||||
epoch: i32,
|
||||
guid: Option<String>,
|
||||
podcast_id: i32,
|
||||
show_id: i32,
|
||||
}
|
||||
|
||||
impl PartialEq<EpisodeMinimal> for NewEpisodeMinimal {
|
||||
fn eq(&self, other: &EpisodeMinimal) -> bool {
|
||||
(self.title() == other.title()) && (self.uri() == other.uri())
|
||||
&& (self.duration() == other.duration()) && (self.epoch() == other.epoch())
|
||||
&& (self.guid() == other.guid()) && (self.podcast_id() == other.podcast_id())
|
||||
(self.title() == other.title())
|
||||
&& (self.uri() == other.uri())
|
||||
&& (self.duration() == other.duration())
|
||||
&& (self.epoch() == other.epoch())
|
||||
&& (self.guid() == other.guid())
|
||||
&& (self.show_id() == other.show_id())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,12 +212,19 @@ impl NewEpisodeMinimal {
|
||||
let title = item.title().unwrap().trim().to_owned();
|
||||
let guid = item.guid().map(|s| s.value().trim().to_owned());
|
||||
|
||||
let uri = item.enclosure()
|
||||
.map(|s| url_cleaner(s.url().trim()))
|
||||
// Get the mime type, the `http` url and the length from the enclosure
|
||||
// http://www.rssboard.org/rss-specification#ltenclosuregtSubelementOfLtitemgt
|
||||
let enc = item.enclosure();
|
||||
|
||||
// Get the url
|
||||
let uri = enc.map(|s| url_cleaner(s.url().trim()))
|
||||
// Fallback to Rss.Item.link if enclosure is None.
|
||||
.or_else(|| item.link().map(|s| url_cleaner(s.trim())));
|
||||
|
||||
// If url is still None return an Error as this behaviour is
|
||||
// Get the size of the content, it should be in bytes
|
||||
let length = enc.and_then(|x| x.length().parse().ok());
|
||||
|
||||
// If url is still None return an Error as this behaviour is not
|
||||
// compliant with the RSS Spec.
|
||||
if uri.is_none() {
|
||||
let err = DataError::ParseEpisodeError {
|
||||
@@ -229,17 +246,18 @@ impl NewEpisodeMinimal {
|
||||
NewEpisodeMinimalBuilder::default()
|
||||
.title(title)
|
||||
.uri(uri)
|
||||
.length(length)
|
||||
.duration(duration)
|
||||
.epoch(epoch)
|
||||
.guid(guid)
|
||||
.podcast_id(parent_id)
|
||||
.show_id(parent_id)
|
||||
.build()
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
// TODO: TryInto is stabilizing in rustc v1.26!
|
||||
// ^ Jokes on you past self!
|
||||
pub(crate) fn into_new_episode(self, item: &rss::Item) -> NewEpisode {
|
||||
let length = item.enclosure().and_then(|x| x.length().parse().ok());
|
||||
let description = item.description().and_then(|s| {
|
||||
let sanitized_html = ammonia::Builder::new()
|
||||
// Remove `rel` attributes from `<a>` tags
|
||||
@@ -254,9 +272,9 @@ impl NewEpisodeMinimal {
|
||||
.uri(self.uri)
|
||||
.duration(self.duration)
|
||||
.epoch(self.epoch)
|
||||
.podcast_id(self.podcast_id)
|
||||
.show_id(self.show_id)
|
||||
.guid(self.guid)
|
||||
.length(length)
|
||||
.length(self.length)
|
||||
.description(description)
|
||||
.build()
|
||||
.unwrap()
|
||||
@@ -285,10 +303,11 @@ impl NewEpisodeMinimal {
|
||||
self.epoch
|
||||
}
|
||||
|
||||
pub(crate) fn podcast_id(&self) -> i32 {
|
||||
self.podcast_id
|
||||
pub(crate) fn show_id(&self) -> i32 {
|
||||
self.show_id
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use database::truncate_db;
|
||||
@@ -314,8 +333,9 @@ mod tests {
|
||||
)))
|
||||
.guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24")))
|
||||
.epoch(1505296800)
|
||||
.length(Some(66738886))
|
||||
.duration(Some(4171))
|
||||
.podcast_id(42)
|
||||
.show_id(42)
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
@@ -327,8 +347,9 @@ mod tests {
|
||||
)))
|
||||
.guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d")))
|
||||
.epoch(1502272800)
|
||||
.length(Some(67527575))
|
||||
.duration(Some(4415))
|
||||
.podcast_id(42)
|
||||
.show_id(42)
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
@@ -349,7 +370,7 @@ mod tests {
|
||||
.length(Some(66738886))
|
||||
.epoch(1505296800)
|
||||
.duration(Some(4171))
|
||||
.podcast_id(42)
|
||||
.show_id(42)
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
@@ -373,7 +394,7 @@ mod tests {
|
||||
.length(Some(67527575))
|
||||
.epoch(1502272800)
|
||||
.duration(Some(4415))
|
||||
.podcast_id(42)
|
||||
.show_id(42)
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
@@ -388,7 +409,7 @@ mod tests {
|
||||
.length(Some(66738886))
|
||||
.epoch(1505296800)
|
||||
.duration(Some(424242))
|
||||
.podcast_id(42)
|
||||
.show_id(42)
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
@@ -399,9 +420,10 @@ mod tests {
|
||||
"http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3",
|
||||
)))
|
||||
.guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D")))
|
||||
.length(Some(46479789))
|
||||
.epoch(1505280282)
|
||||
.duration(Some(5733))
|
||||
.podcast_id(42)
|
||||
.show_id(42)
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
@@ -413,8 +435,9 @@ mod tests {
|
||||
)))
|
||||
.guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B")))
|
||||
.epoch(1504670247)
|
||||
.length(Some(36544272))
|
||||
.duration(Some(4491))
|
||||
.podcast_id(42)
|
||||
.show_id(42)
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
@@ -434,7 +457,7 @@ mod tests {
|
||||
.length(Some(46479789))
|
||||
.epoch(1505280282)
|
||||
.duration(Some(5733))
|
||||
.podcast_id(42)
|
||||
.show_id(42)
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
@@ -456,7 +479,7 @@ mod tests {
|
||||
.length(Some(36544272))
|
||||
.epoch(1504670247)
|
||||
.duration(Some(4491))
|
||||
.podcast_id(42)
|
||||
.show_id(42)
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
@@ -530,6 +553,10 @@ mod tests {
|
||||
let ep = EXPECTED_MINIMAL_INTERCEPTED_1
|
||||
.clone()
|
||||
.into_new_episode(&item);
|
||||
println!(
|
||||
"EPISODE: {:#?}\nEXPECTED: {:#?}",
|
||||
ep, *EXPECTED_INTERCEPTED_1
|
||||
);
|
||||
assert_eq!(ep, *EXPECTED_INTERCEPTED_1);
|
||||
|
||||
let item = channel.items().iter().nth(15).unwrap();
|
||||
@@ -549,7 +576,7 @@ mod tests {
|
||||
let episode = channel.items().iter().nth(14).unwrap();
|
||||
let new_ep = NewEpisode::new(&episode, 42).unwrap();
|
||||
new_ep.insert().unwrap();
|
||||
let ep = dbqueries::get_episode_from_pk(new_ep.title(), new_ep.podcast_id()).unwrap();
|
||||
let ep = dbqueries::get_episode_from_pk(new_ep.title(), new_ep.show_id()).unwrap();
|
||||
|
||||
assert_eq!(new_ep, ep);
|
||||
assert_eq!(&new_ep, &*EXPECTED_INTERCEPTED_1);
|
||||
@@ -558,7 +585,7 @@ mod tests {
|
||||
let episode = channel.items().iter().nth(15).unwrap();
|
||||
let new_ep = NewEpisode::new(&episode, 42).unwrap();
|
||||
new_ep.insert().unwrap();
|
||||
let ep = dbqueries::get_episode_from_pk(new_ep.title(), new_ep.podcast_id()).unwrap();
|
||||
let ep = dbqueries::get_episode_from_pk(new_ep.title(), new_ep.show_id()).unwrap();
|
||||
|
||||
assert_eq!(new_ep, ep);
|
||||
assert_eq!(&new_ep, &*EXPECTED_INTERCEPTED_2);
|
||||
@@ -572,21 +599,15 @@ mod tests {
|
||||
|
||||
let updated = &*UPDATED_DURATION_INTERCEPTED_1;
|
||||
updated.update(old.rowid()).unwrap();
|
||||
let mut new = dbqueries::get_episode_from_pk(old.title(), old.podcast_id()).unwrap();
|
||||
let new = dbqueries::get_episode_from_pk(old.title(), old.show_id()).unwrap();
|
||||
|
||||
// Assert that updating does not change the rowid and podcast_id
|
||||
// Assert that updating does not change the rowid and show_id
|
||||
assert_ne!(old, new);
|
||||
assert_eq!(old.rowid(), new.rowid());
|
||||
assert_eq!(old.podcast_id(), new.podcast_id());
|
||||
assert_eq!(old.show_id(), new.show_id());
|
||||
|
||||
assert_eq!(updated, &new);
|
||||
assert_ne!(updated, &old);
|
||||
|
||||
new.set_archive(true);
|
||||
new.save().unwrap();
|
||||
|
||||
let new2 = dbqueries::get_episode_from_pk(old.title(), old.podcast_id()).unwrap();
|
||||
assert_eq!(true, new2.archive());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -599,7 +620,7 @@ mod tests {
|
||||
// Second identical, This should take the early return path
|
||||
assert!(expected.index().is_ok());
|
||||
// Get the episode
|
||||
let old = dbqueries::get_episode_from_pk(expected.title(), expected.podcast_id()).unwrap();
|
||||
let old = dbqueries::get_episode_from_pk(expected.title(), expected.show_id()).unwrap();
|
||||
// Assert that NewPodcast is equal to the Indexed one
|
||||
assert_eq!(*expected, old);
|
||||
|
||||
@@ -608,23 +629,22 @@ mod tests {
|
||||
// Update the podcast
|
||||
assert!(updated.index().is_ok());
|
||||
// Get the new Podcast
|
||||
let new = dbqueries::get_episode_from_pk(expected.title(), expected.podcast_id()).unwrap();
|
||||
let new = dbqueries::get_episode_from_pk(expected.title(), expected.show_id()).unwrap();
|
||||
// Assert it's diff from the old one.
|
||||
assert_ne!(new, old);
|
||||
assert_eq!(*updated, new);
|
||||
assert_eq!(new.rowid(), old.rowid());
|
||||
assert_eq!(new.podcast_id(), old.podcast_id());
|
||||
assert_eq!(new.show_id(), old.show_id());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_episode_to_episode() {
|
||||
let expected = &*EXPECTED_INTERCEPTED_1;
|
||||
let updated = &*UPDATED_DURATION_INTERCEPTED_1;
|
||||
|
||||
// Assert insert() produces the same result that you would get with to_podcast()
|
||||
truncate_db().unwrap();
|
||||
expected.insert().unwrap();
|
||||
let old = dbqueries::get_episode_from_pk(expected.title(), expected.podcast_id()).unwrap();
|
||||
let old = dbqueries::get_episode_from_pk(expected.title(), expected.show_id()).unwrap();
|
||||
let ep = expected.to_episode().unwrap();
|
||||
assert_eq!(old, ep);
|
||||
|
||||
@@ -633,17 +653,7 @@ mod tests {
|
||||
let ep = expected.to_episode().unwrap();
|
||||
// This should error as a unique constrain violation
|
||||
assert!(expected.insert().is_err());
|
||||
let mut old =
|
||||
dbqueries::get_episode_from_pk(expected.title(), expected.podcast_id()).unwrap();
|
||||
let old = dbqueries::get_episode_from_pk(expected.title(), expected.show_id()).unwrap();
|
||||
assert_eq!(old, ep);
|
||||
|
||||
old.set_archive(true);
|
||||
old.save().unwrap();
|
||||
|
||||
// Assert that it does not mess with user preferences
|
||||
let ep = updated.to_episode().unwrap();
|
||||
let old = dbqueries::get_episode_from_pk(expected.title(), expected.podcast_id()).unwrap();
|
||||
assert_eq!(old, ep);
|
||||
assert_eq!(old.archive(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,21 +4,21 @@ use diesel::prelude::*;
|
||||
use rss;
|
||||
|
||||
use errors::DataError;
|
||||
use models::Podcast;
|
||||
use models::Show;
|
||||
use models::{Index, Insert, Update};
|
||||
use schema::podcast;
|
||||
use schema::shows;
|
||||
|
||||
use database::connection;
|
||||
use dbqueries;
|
||||
use utils::url_cleaner;
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "podcast"]
|
||||
#[table_name = "shows"]
|
||||
#[derive(Debug, Clone, Default, Builder, PartialEq)]
|
||||
#[builder(default)]
|
||||
#[builder(derive(Debug))]
|
||||
#[builder(setter(into))]
|
||||
pub(crate) struct NewPodcast {
|
||||
pub(crate) struct NewShow {
|
||||
title: String,
|
||||
link: String,
|
||||
description: String,
|
||||
@@ -26,15 +26,15 @@ pub(crate) struct NewPodcast {
|
||||
source_id: i32,
|
||||
}
|
||||
|
||||
impl Insert<()> for NewPodcast {
|
||||
impl Insert<()> for NewShow {
|
||||
type Error = DataError;
|
||||
|
||||
fn insert(&self) -> Result<(), Self::Error> {
|
||||
use schema::podcast::dsl::*;
|
||||
use schema::shows::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
diesel::insert_into(podcast)
|
||||
diesel::insert_into(shows)
|
||||
.values(self)
|
||||
.execute(&con)
|
||||
.map(|_| ())
|
||||
@@ -42,16 +42,16 @@ impl Insert<()> for NewPodcast {
|
||||
}
|
||||
}
|
||||
|
||||
impl Update<()> for NewPodcast {
|
||||
impl Update<()> for NewShow {
|
||||
type Error = DataError;
|
||||
|
||||
fn update(&self, podcast_id: i32) -> Result<(), Self::Error> {
|
||||
use schema::podcast::dsl::*;
|
||||
fn update(&self, show_id: i32) -> Result<(), Self::Error> {
|
||||
use schema::shows::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
info!("Updating {}", self.title);
|
||||
diesel::update(podcast.filter(id.eq(podcast_id)))
|
||||
diesel::update(shows.filter(id.eq(show_id)))
|
||||
.set(self)
|
||||
.execute(&con)
|
||||
.map(|_| ())
|
||||
@@ -61,7 +61,7 @@ impl Update<()> for NewPodcast {
|
||||
|
||||
// TODO: Maybe return an Enum<Action(Resut)> Instead.
|
||||
// It would make unti testing better too.
|
||||
impl Index<()> for NewPodcast {
|
||||
impl Index<()> for NewShow {
|
||||
type Error = DataError;
|
||||
|
||||
fn index(&self) -> Result<(), DataError> {
|
||||
@@ -81,18 +81,19 @@ impl Index<()> for NewPodcast {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<Podcast> for NewPodcast {
|
||||
fn eq(&self, other: &Podcast) -> bool {
|
||||
(self.link() == other.link()) && (self.title() == other.title())
|
||||
impl PartialEq<Show> for NewShow {
|
||||
fn eq(&self, other: &Show) -> bool {
|
||||
(self.link() == other.link())
|
||||
&& (self.title() == other.title())
|
||||
&& (self.image_uri() == other.image_uri())
|
||||
&& (self.description() == other.description())
|
||||
&& (self.source_id() == other.source_id())
|
||||
}
|
||||
}
|
||||
|
||||
impl NewPodcast {
|
||||
/// Parses a `rss::Channel` into a `NewPodcast` Struct.
|
||||
pub(crate) fn new(chan: &rss::Channel, source_id: i32) -> NewPodcast {
|
||||
impl NewShow {
|
||||
/// Parses a `rss::Channel` into a `NewShow` Struct.
|
||||
pub(crate) fn new(chan: &rss::Channel, source_id: i32) -> NewShow {
|
||||
let title = chan.title().trim();
|
||||
let link = url_cleaner(chan.link().trim());
|
||||
|
||||
@@ -103,13 +104,14 @@ impl NewPodcast {
|
||||
.to_string();
|
||||
|
||||
// Try to get the itunes img first
|
||||
let itunes_img = chan.itunes_ext()
|
||||
let itunes_img = chan
|
||||
.itunes_ext()
|
||||
.and_then(|s| s.image().map(|url| url.trim()))
|
||||
.map(|s| s.to_owned());
|
||||
// If itunes is None, try to get the channel.image from the rss spec
|
||||
let image_uri = itunes_img.or_else(|| chan.image().map(|s| s.url().trim().to_owned()));
|
||||
|
||||
NewPodcastBuilder::default()
|
||||
NewShowBuilder::default()
|
||||
.title(title)
|
||||
.description(description)
|
||||
.link(link)
|
||||
@@ -120,14 +122,14 @@ impl NewPodcast {
|
||||
}
|
||||
|
||||
// Look out for when tryinto lands into stable.
|
||||
pub(crate) fn to_podcast(&self) -> Result<Podcast, DataError> {
|
||||
pub(crate) fn to_podcast(&self) -> Result<Show, DataError> {
|
||||
self.index()?;
|
||||
dbqueries::get_podcast_from_source_id(self.source_id).map_err(From::from)
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore the following geters. They are used in unit tests mainly.
|
||||
impl NewPodcast {
|
||||
impl NewShow {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn source_id(&self) -> i32 {
|
||||
self.source_id
|
||||
@@ -158,14 +160,14 @@ mod tests {
|
||||
use rss::Channel;
|
||||
|
||||
use database::truncate_db;
|
||||
use models::{NewPodcastBuilder, Save};
|
||||
use models::NewShowBuilder;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
|
||||
// Pre-built expected NewPodcast structs.
|
||||
// Pre-built expected NewShow structs.
|
||||
lazy_static! {
|
||||
static ref EXPECTED_INTERCEPTED: NewPodcast = {
|
||||
static ref EXPECTED_INTERCEPTED: NewShow = {
|
||||
let descr = "The people behind The Intercept’s fearless reporting and incisive \
|
||||
commentary—Jeremy Scahill, Glenn Greenwald, Betsy Reed and \
|
||||
others—discuss the crucial issues of our time: national security, civil \
|
||||
@@ -173,7 +175,7 @@ mod tests {
|
||||
artists, thinkers, and newsmakers who challenge our preconceptions about \
|
||||
the world we live in.";
|
||||
|
||||
NewPodcastBuilder::default()
|
||||
NewShowBuilder::default()
|
||||
.title("Intercepted with Jeremy Scahill")
|
||||
.link("https://theintercept.com/podcasts")
|
||||
.description(descr)
|
||||
@@ -186,12 +188,12 @@ mod tests {
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
static ref EXPECTED_LUP: NewPodcast = {
|
||||
static ref EXPECTED_LUP: NewShow = {
|
||||
let descr = "An open show powered by community LINUX Unplugged takes the best \
|
||||
attributes of open collaboration and focuses them into a weekly \
|
||||
lifestyle show about Linux.";
|
||||
|
||||
NewPodcastBuilder::default()
|
||||
NewShowBuilder::default()
|
||||
.title("LINUX Unplugged Podcast")
|
||||
.link("http://www.jupiterbroadcasting.com/")
|
||||
.description(descr)
|
||||
@@ -202,7 +204,7 @@ mod tests {
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
static ref EXPECTED_TIPOFF: NewPodcast = {
|
||||
static ref EXPECTED_TIPOFF: NewShow = {
|
||||
let desc = "<p>Welcome to The Tip Off- the podcast where we take you behind the \
|
||||
scenes of some of the best investigative journalism from recent years. \
|
||||
Each episode we’ll be digging into an investigative scoop- hearing from \
|
||||
@@ -213,7 +215,7 @@ mod tests {
|
||||
complicated detective work that goes into doing great investigative \
|
||||
journalism- then this is the podcast for you.</p>";
|
||||
|
||||
NewPodcastBuilder::default()
|
||||
NewShowBuilder::default()
|
||||
.title("The Tip Off")
|
||||
.link("http://www.acast.com/thetipoff")
|
||||
.description(desc)
|
||||
@@ -225,7 +227,7 @@ mod tests {
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
static ref EXPECTED_STARS: NewPodcast = {
|
||||
static ref EXPECTED_STARS: NewShow = {
|
||||
let descr = "<p>The first audio drama from Tor Labs and Gideon Media, Steal the Stars \
|
||||
is a gripping noir science fiction thriller in 14 episodes: Forbidden \
|
||||
love, a crashed UFO, an alien body, and an impossible heist unlike any \
|
||||
@@ -235,7 +237,7 @@ mod tests {
|
||||
b183-7311d2e436c3/b3a4aa57a576bb662191f2a6bc2a436c8c4ae256ecffaff5c4c54fd42e\
|
||||
923914941c264d01efb1833234b52c9530e67d28a8cebbe3d11a4bc0fbbdf13ecdf1c3.jpeg";
|
||||
|
||||
NewPodcastBuilder::default()
|
||||
NewShowBuilder::default()
|
||||
.title("Steal the Stars")
|
||||
.link("http://tor-labs.com/")
|
||||
.description(descr)
|
||||
@@ -244,12 +246,12 @@ mod tests {
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
static ref EXPECTED_CODE: NewPodcast = {
|
||||
static ref EXPECTED_CODE: NewShow = {
|
||||
let descr = "A podcast about humans and technology. Panelists: Coraline Ada Ehmke, \
|
||||
David Brady, Jessica Kerr, Jay Bobo, Astrid Countee and Sam \
|
||||
Livingston-Gray. Brought to you by @therubyrep.";
|
||||
|
||||
NewPodcastBuilder::default()
|
||||
NewShowBuilder::default()
|
||||
.title("Greater Than Code")
|
||||
.link("https://www.greaterthancode.com/")
|
||||
.description(descr)
|
||||
@@ -260,8 +262,8 @@ mod tests {
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
static ref EXPECTED_ELLINOFRENEIA: NewPodcast = {
|
||||
NewPodcastBuilder::default()
|
||||
static ref EXPECTED_ELLINOFRENEIA: NewShow = {
|
||||
NewShowBuilder::default()
|
||||
.title("Ελληνοφρένεια")
|
||||
.link("https://ellinofreneia.sealabs.net/feed.rss")
|
||||
.description("Ανεπίσημο feed της Ελληνοφρένειας")
|
||||
@@ -270,8 +272,8 @@ mod tests {
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
static ref UPDATED_DESC_INTERCEPTED: NewPodcast = {
|
||||
NewPodcastBuilder::default()
|
||||
static ref UPDATED_DESC_INTERCEPTED: NewShow = {
|
||||
NewShowBuilder::default()
|
||||
.title("Intercepted with Jeremy Scahill")
|
||||
.link("https://theintercept.com/podcasts")
|
||||
.description("New Description")
|
||||
@@ -291,7 +293,7 @@ mod tests {
|
||||
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let pd = NewPodcast::new(&channel, 42);
|
||||
let pd = NewShow::new(&channel, 42);
|
||||
assert_eq!(*EXPECTED_INTERCEPTED, pd);
|
||||
}
|
||||
|
||||
@@ -300,7 +302,7 @@ mod tests {
|
||||
let file = File::open("tests/feeds/2018-01-20-LinuxUnplugged.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let pd = NewPodcast::new(&channel, 42);
|
||||
let pd = NewShow::new(&channel, 42);
|
||||
assert_eq!(*EXPECTED_LUP, pd);
|
||||
}
|
||||
|
||||
@@ -309,7 +311,7 @@ mod tests {
|
||||
let file = File::open("tests/feeds/2018-01-20-TheTipOff.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let pd = NewPodcast::new(&channel, 42);
|
||||
let pd = NewShow::new(&channel, 42);
|
||||
assert_eq!(*EXPECTED_TIPOFF, pd);
|
||||
}
|
||||
|
||||
@@ -318,7 +320,7 @@ mod tests {
|
||||
let file = File::open("tests/feeds/2018-01-20-StealTheStars.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let pd = NewPodcast::new(&channel, 42);
|
||||
let pd = NewShow::new(&channel, 42);
|
||||
assert_eq!(*EXPECTED_STARS, pd);
|
||||
}
|
||||
|
||||
@@ -327,7 +329,7 @@ mod tests {
|
||||
let file = File::open("tests/feeds/2018-01-20-GreaterThanCode.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let pd = NewPodcast::new(&channel, 42);
|
||||
let pd = NewShow::new(&channel, 42);
|
||||
assert_eq!(*EXPECTED_CODE, pd);
|
||||
}
|
||||
|
||||
@@ -336,7 +338,7 @@ mod tests {
|
||||
let file = File::open("tests/feeds/2018-03-28-Ellinofreneia.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let pd = NewPodcast::new(&channel, 42);
|
||||
let pd = NewShow::new(&channel, 42);
|
||||
assert_eq!(*EXPECTED_ELLINOFRENEIA, pd);
|
||||
}
|
||||
|
||||
@@ -347,7 +349,7 @@ mod tests {
|
||||
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let npd = NewPodcast::new(&channel, 42);
|
||||
let npd = NewShow::new(&channel, 42);
|
||||
npd.insert().unwrap();
|
||||
let pd = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||
|
||||
@@ -367,20 +369,13 @@ mod tests {
|
||||
|
||||
let updated = &*UPDATED_DESC_INTERCEPTED;
|
||||
updated.update(old.id()).unwrap();
|
||||
let mut new = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||
let new = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||
|
||||
assert_ne!(old, new);
|
||||
assert_eq!(old.id(), new.id());
|
||||
assert_eq!(old.source_id(), new.source_id());
|
||||
assert_eq!(updated, &new);
|
||||
assert_ne!(updated, &old);
|
||||
|
||||
// Chech that the update does not override user preferences.
|
||||
new.set_archive(true);
|
||||
new.save().unwrap();
|
||||
|
||||
let new2 = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||
assert_eq!(true, new2.archive());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -393,14 +388,14 @@ mod tests {
|
||||
assert!(EXPECTED_INTERCEPTED.index().is_ok());
|
||||
// Get the podcast
|
||||
let old = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||
// Assert that NewPodcast is equal to the Indexed one
|
||||
// Assert that NewShow is equal to the Indexed one
|
||||
assert_eq!(&*EXPECTED_INTERCEPTED, &old);
|
||||
|
||||
let updated = &*UPDATED_DESC_INTERCEPTED;
|
||||
|
||||
// Update the podcast
|
||||
assert!(updated.index().is_ok());
|
||||
// Get the new Podcast
|
||||
// Get the new Show
|
||||
let new = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||
// Assert it's diff from the old one.
|
||||
assert_ne!(new, old);
|
||||
@@ -422,16 +417,7 @@ mod tests {
|
||||
let pd = EXPECTED_INTERCEPTED.to_podcast().unwrap();
|
||||
// This should error as a unique constrain violation
|
||||
assert!(EXPECTED_INTERCEPTED.insert().is_err());
|
||||
let mut old = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||
assert_eq!(old, pd);
|
||||
|
||||
old.set_archive(true);
|
||||
old.save().unwrap();
|
||||
|
||||
// Assert that it does not mess with user preferences
|
||||
let pd = UPDATED_DESC_INTERCEPTED.to_podcast().unwrap();
|
||||
let old = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||
assert_eq!(old, pd);
|
||||
assert_eq!(old.archive(), true);
|
||||
}
|
||||
}
|
||||
@@ -3,42 +3,37 @@ use diesel::SaveChangesDsl;
|
||||
use database::connection;
|
||||
use errors::DataError;
|
||||
use models::{Save, Source};
|
||||
use schema::podcast;
|
||||
|
||||
use std::sync::Arc;
|
||||
use schema::shows;
|
||||
|
||||
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
|
||||
#[belongs_to(Source, foreign_key = "source_id")]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[table_name = "podcast"]
|
||||
#[table_name = "shows"]
|
||||
#[derive(Debug, Clone)]
|
||||
/// Diesel Model of the podcast table.
|
||||
pub struct Podcast {
|
||||
/// Diesel Model of the shows table.
|
||||
pub struct Show {
|
||||
id: i32,
|
||||
title: String,
|
||||
link: String,
|
||||
description: String,
|
||||
image_uri: Option<String>,
|
||||
favorite: bool,
|
||||
archive: bool,
|
||||
always_dl: bool,
|
||||
source_id: i32,
|
||||
}
|
||||
|
||||
impl Save<Podcast> for Podcast {
|
||||
impl Save<Show> for Show {
|
||||
type Error = DataError;
|
||||
|
||||
/// Helper method to easily save/"sync" current state of self to the
|
||||
/// Database.
|
||||
fn save(&self) -> Result<Podcast, Self::Error> {
|
||||
fn save(&self) -> Result<Show, Self::Error> {
|
||||
let db = connection();
|
||||
let tempdb = db.get()?;
|
||||
|
||||
self.save_changes::<Podcast>(&*tempdb).map_err(From::from)
|
||||
self.save_changes::<Show>(&*tempdb).map_err(From::from)
|
||||
}
|
||||
}
|
||||
|
||||
impl Podcast {
|
||||
impl Show {
|
||||
/// Get the Feed `id`.
|
||||
pub fn id(&self) -> i32 {
|
||||
self.id
|
||||
@@ -56,7 +51,7 @@ impl Podcast {
|
||||
&self.link
|
||||
}
|
||||
|
||||
/// Set the Podcast/Feed `link`.
|
||||
/// Set the Show/Feed `link`.
|
||||
pub fn set_link(&mut self, value: &str) {
|
||||
self.link = value.to_string();
|
||||
}
|
||||
@@ -83,41 +78,6 @@ impl Podcast {
|
||||
self.image_uri = value.map(|x| x.to_string());
|
||||
}
|
||||
|
||||
/// Represents the archiving policy for the episode.
|
||||
pub fn archive(&self) -> bool {
|
||||
self.archive
|
||||
}
|
||||
|
||||
/// Set the `archive` policy.
|
||||
pub fn set_archive(&mut self, b: bool) {
|
||||
self.archive = b
|
||||
}
|
||||
|
||||
/// Get the `favorite` status of the `Podcast` Feed.
|
||||
pub fn favorite(&self) -> bool {
|
||||
self.favorite
|
||||
}
|
||||
|
||||
/// Set `favorite` status.
|
||||
pub fn set_favorite(&mut self, b: bool) {
|
||||
self.favorite = b
|
||||
}
|
||||
|
||||
/// Represents the download policy for the `Podcast` Feed.
|
||||
///
|
||||
/// Reserved for the use with a Download manager, yet to be implemented.
|
||||
///
|
||||
/// If true Podcast Episode should be downloaded automaticly/skipping
|
||||
/// the selection queue.
|
||||
pub fn always_download(&self) -> bool {
|
||||
self.always_dl
|
||||
}
|
||||
|
||||
/// Set the download policy.
|
||||
pub fn set_always_download(&mut self, b: bool) {
|
||||
self.always_dl = b
|
||||
}
|
||||
|
||||
/// `Source` table foreign key.
|
||||
pub fn source_id(&self) -> i32 {
|
||||
self.source_id
|
||||
@@ -125,17 +85,17 @@ impl Podcast {
|
||||
}
|
||||
|
||||
#[derive(Queryable, Debug, Clone)]
|
||||
/// Diesel Model of the podcast cover query.
|
||||
/// Used for fetching information about a Podcast's cover.
|
||||
pub struct PodcastCoverQuery {
|
||||
/// Diesel Model of the Show cover query.
|
||||
/// Used for fetching information about a Show's cover.
|
||||
pub struct ShowCoverModel {
|
||||
id: i32,
|
||||
title: String,
|
||||
image_uri: Option<String>,
|
||||
}
|
||||
|
||||
impl From<Podcast> for PodcastCoverQuery {
|
||||
fn from(p: Podcast) -> PodcastCoverQuery {
|
||||
PodcastCoverQuery {
|
||||
impl From<Show> for ShowCoverModel {
|
||||
fn from(p: Show) -> ShowCoverModel {
|
||||
ShowCoverModel {
|
||||
id: p.id(),
|
||||
title: p.title,
|
||||
image_uri: p.image_uri,
|
||||
@@ -143,17 +103,7 @@ impl From<Podcast> for PodcastCoverQuery {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Arc<Podcast>> for PodcastCoverQuery {
|
||||
fn from(p: Arc<Podcast>) -> PodcastCoverQuery {
|
||||
PodcastCoverQuery {
|
||||
id: p.id(),
|
||||
title: p.title.clone(),
|
||||
image_uri: p.image_uri.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PodcastCoverQuery {
|
||||
impl ShowCoverModel {
|
||||
/// Get the Feed `id`.
|
||||
pub fn id(&self) -> i32 {
|
||||
self.id
|
||||
@@ -0,0 +1,29 @@
|
||||
diff --git a/hammond-data/src/schema.rs b/hammond-data/src/schema.rs
|
||||
index 03cbed0..88f1622 100644
|
||||
--- a/hammond-data/src/schema.rs
|
||||
+++ b/hammond-data/src/schema.rs
|
||||
@@ -1,8 +1,11 @@
|
||||
+#![allow(warnings)]
|
||||
+
|
||||
table! {
|
||||
episodes (title, show_id) {
|
||||
+ rowid -> Integer,
|
||||
title -> Text,
|
||||
uri -> Nullable<Text>,
|
||||
local_uri -> Nullable<Text>,
|
||||
description -> Nullable<Text>,
|
||||
epoch -> Integer,
|
||||
length -> Nullable<Integer>,
|
||||
@@ -30,11 +33,7 @@ table! {
|
||||
uri -> Text,
|
||||
last_modified -> Nullable<Text>,
|
||||
http_etag -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
-allow_tables_to_appear_in_same_query!(
|
||||
- episodes,
|
||||
- shows,
|
||||
- source,
|
||||
-);
|
||||
+allow_tables_to_appear_in_same_query!(episodes, shows, source);
|
||||
@@ -1,5 +1,7 @@
|
||||
#![allow(warnings)]
|
||||
|
||||
table! {
|
||||
episode (title, podcast_id) {
|
||||
episodes (title, show_id) {
|
||||
rowid -> Integer,
|
||||
title -> Text,
|
||||
uri -> Nullable<Text>,
|
||||
@@ -10,22 +12,17 @@ table! {
|
||||
duration -> Nullable<Integer>,
|
||||
guid -> Nullable<Text>,
|
||||
played -> Nullable<Integer>,
|
||||
favorite -> Bool,
|
||||
archive -> Bool,
|
||||
podcast_id -> Integer,
|
||||
show_id -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
podcast (id) {
|
||||
shows (id) {
|
||||
id -> Integer,
|
||||
title -> Text,
|
||||
link -> Text,
|
||||
description -> Text,
|
||||
image_uri -> Nullable<Text>,
|
||||
favorite -> Bool,
|
||||
archive -> Bool,
|
||||
always_dl -> Bool,
|
||||
source_id -> Integer,
|
||||
}
|
||||
}
|
||||
@@ -39,4 +36,4 @@ table! {
|
||||
}
|
||||
}
|
||||
|
||||
allow_tables_to_appear_in_same_query!(episode, podcast, source,);
|
||||
allow_tables_to_appear_in_same_query!(episodes, shows, source);
|
||||
|
||||
+10
-10
@@ -7,7 +7,7 @@ use url::{Position, Url};
|
||||
|
||||
use dbqueries;
|
||||
use errors::DataError;
|
||||
use models::{EpisodeCleanerQuery, Podcast, Save};
|
||||
use models::{EpisodeCleanerModel, Save, Show};
|
||||
use xdg_dirs::DL_DIR;
|
||||
|
||||
use std::fs;
|
||||
@@ -59,7 +59,7 @@ fn played_cleaner(cleanup_date: DateTime<Utc>) -> Result<(), DataError> {
|
||||
}
|
||||
|
||||
/// Check `ep.local_uri` field and delete the file it points to.
|
||||
fn delete_local_content(ep: &mut EpisodeCleanerQuery) -> Result<(), DataError> {
|
||||
fn delete_local_content(ep: &mut EpisodeCleanerModel) -> Result<(), DataError> {
|
||||
if ep.local_uri().is_some() {
|
||||
let uri = ep.local_uri().unwrap().to_owned();
|
||||
if Path::new(&uri).exists() {
|
||||
@@ -108,9 +108,9 @@ pub fn url_cleaner(s: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the URI of a Podcast Downloads given it's title.
|
||||
/// Returns the URI of a Show Downloads given it's title.
|
||||
pub fn get_download_folder(pd_title: &str) -> Result<String, DataError> {
|
||||
// It might be better to make it a hash of the title or the podcast rowid
|
||||
// It might be better to make it a hash of the title or the Show rowid
|
||||
let download_fold = format!("{}/{}", DL_DIR.to_str().unwrap(), pd_title);
|
||||
|
||||
// Create the folder
|
||||
@@ -123,7 +123,7 @@ pub fn get_download_folder(pd_title: &str) -> Result<String, DataError> {
|
||||
/// Removes all the entries associated with the given show from the database,
|
||||
/// and deletes all of the downloaded content.
|
||||
// TODO: Write Tests
|
||||
pub fn delete_show(pd: &Podcast) -> Result<(), DataError> {
|
||||
pub fn delete_show(pd: &Show) -> Result<(), DataError> {
|
||||
dbqueries::remove_feed(pd)?;
|
||||
info!("{} was removed succesfully.", pd.title());
|
||||
|
||||
@@ -183,7 +183,7 @@ mod tests {
|
||||
// Setup episodes
|
||||
let n1 = NewEpisodeBuilder::default()
|
||||
.title("foo_bar".to_string())
|
||||
.podcast_id(0)
|
||||
.show_id(0)
|
||||
.build()
|
||||
.unwrap()
|
||||
.to_episode()
|
||||
@@ -191,14 +191,14 @@ mod tests {
|
||||
|
||||
let n2 = NewEpisodeBuilder::default()
|
||||
.title("bar_baz".to_string())
|
||||
.podcast_id(1)
|
||||
.show_id(1)
|
||||
.build()
|
||||
.unwrap()
|
||||
.to_episode()
|
||||
.unwrap();
|
||||
|
||||
let mut ep1 = dbqueries::get_episode_from_pk(n1.title(), n1.podcast_id()).unwrap();
|
||||
let mut ep2 = dbqueries::get_episode_from_pk(n2.title(), n2.podcast_id()).unwrap();
|
||||
let mut ep1 = dbqueries::get_episode_from_pk(n1.title(), n1.show_id()).unwrap();
|
||||
let mut ep2 = dbqueries::get_episode_from_pk(n2.title(), n2.show_id()).unwrap();
|
||||
ep1.set_local_uri(Some(valid_path.to_str().unwrap()));
|
||||
ep2.set_local_uri(Some(bad_path.to_str().unwrap()));
|
||||
|
||||
@@ -230,7 +230,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_download_cleaner() {
|
||||
let _tmp_dir = helper_db();
|
||||
let mut episode: EpisodeCleanerQuery =
|
||||
let mut episode: EpisodeCleanerModel =
|
||||
dbqueries::get_episode_from_pk("foo_bar", 0).unwrap().into();
|
||||
|
||||
let valid_path = episode.local_uri().unwrap().to_owned();
|
||||
|
||||
@@ -5,11 +5,11 @@ version = "0.1.0"
|
||||
workspace = "../"
|
||||
|
||||
[dependencies]
|
||||
error-chain = "0.11.0"
|
||||
error-chain = "0.12.0"
|
||||
hyper = "0.11.27"
|
||||
log = "0.4.1"
|
||||
log = "0.4.2"
|
||||
mime_guess = "1.8.4"
|
||||
reqwest = "0.8.5"
|
||||
reqwest = "0.8.6"
|
||||
tempdir = "0.3.7"
|
||||
glob = "0.2.11"
|
||||
failure = "0.1.1"
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use hammond_data::xdg_dirs::HAMMOND_CACHE;
|
||||
use hammond_data::{EpisodeWidgetQuery, PodcastCoverQuery, Save};
|
||||
use hammond_data::{EpisodeWidgetModel, Save, ShowCoverModel};
|
||||
|
||||
// use failure::Error;
|
||||
use errors::DownloadError;
|
||||
@@ -127,7 +127,7 @@ fn save_io(
|
||||
info!("Downloading into: {}", file);
|
||||
let chunk_size = match content_lenght {
|
||||
Some(x) => x as usize / 99,
|
||||
None => 1024 as usize, // default chunk size
|
||||
None => 1024, // default chunk size
|
||||
};
|
||||
|
||||
let mut writer = BufWriter::new(File::create(&file)?);
|
||||
@@ -161,7 +161,7 @@ fn save_io(
|
||||
|
||||
// TODO: Refactor
|
||||
pub fn get_episode(
|
||||
ep: &mut EpisodeWidgetQuery,
|
||||
ep: &mut EpisodeWidgetModel,
|
||||
download_folder: &str,
|
||||
progress: Option<Arc<Mutex<DownloadProgress>>>,
|
||||
) -> Result<(), DownloadError> {
|
||||
@@ -196,8 +196,9 @@ pub fn get_episode(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cache_image(pd: &PodcastCoverQuery) -> Result<String, DownloadError> {
|
||||
let url = pd.image_uri()
|
||||
pub fn cache_image(pd: &ShowCoverModel) -> Result<String, DownloadError> {
|
||||
let url = pd
|
||||
.image_uri()
|
||||
.ok_or_else(|| DownloadError::NoImageLocation)?
|
||||
.to_owned();
|
||||
|
||||
@@ -215,7 +216,8 @@ pub fn cache_image(pd: &PodcastCoverQuery) -> Result<String, DownloadError> {
|
||||
// For some reason there is no .first() method so nth(0) is used
|
||||
let path = foo.nth(0).and_then(|x| x.ok());
|
||||
if let Some(p) = path {
|
||||
return Ok(p.to_str()
|
||||
return Ok(p
|
||||
.to_str()
|
||||
.ok_or_else(|| DownloadError::InvalidCachedImageLocation)?
|
||||
.into());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
#![recursion_limit = "1024"]
|
||||
#![warn(unused_extern_crates, unused)]
|
||||
#![allow(unknown_lints)]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(blacklisted_name, option_map_unit_fn))]
|
||||
// Enable lint group collections
|
||||
#![warn(nonstandard_style, edition_2018, rust_2018_idioms, bad_style, unused)]
|
||||
// standalone lints
|
||||
#![warn(
|
||||
const_err, improper_ctypes, non_shorthand_field_patterns, no_mangle_generic_items,
|
||||
overflowing_literals, plugin_as_library, private_no_mangle_fns, private_no_mangle_statics,
|
||||
unconditional_recursion, unions_with_drop_fields, while_true, missing_debug_implementations,
|
||||
trivial_casts, trivial_numeric_casts, elided_lifetime_in_paths, missing_copy_implementations
|
||||
)]
|
||||
#![deny(warnings)]
|
||||
|
||||
extern crate failure;
|
||||
|
||||
+11
-10
@@ -6,14 +6,16 @@ version = "0.1.0"
|
||||
workspace = "../"
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.2"
|
||||
crossbeam-channel = "0.1.2"
|
||||
chrono = "0.4.4"
|
||||
crossbeam-channel = "0.2.1"
|
||||
gdk = "0.8.0"
|
||||
gdk-pixbuf = "0.4.0"
|
||||
glib = "0.5.0"
|
||||
gstreamer = "0.11.3"
|
||||
gstreamer-player = "0.11.3"
|
||||
humansize = "1.1.0"
|
||||
lazy_static = "1.0.0"
|
||||
log = "0.4.1"
|
||||
lazy_static = "1.0.1"
|
||||
log = "0.4.2"
|
||||
loggerv = "0.7.1"
|
||||
open = "1.2.1"
|
||||
rayon = "1.0.1"
|
||||
@@ -21,11 +23,10 @@ send-cell = "0.1.3"
|
||||
url = "1.7.0"
|
||||
failure = "0.1.1"
|
||||
failure_derive = "0.1.1"
|
||||
take_mut = "0.2.2"
|
||||
regex = "1.0.0"
|
||||
reqwest = "0.8.5"
|
||||
serde_json = "1.0.17"
|
||||
html2pango = { git = "https://gitlab.gnome.org/World/html2pango" }
|
||||
regex = "1.0.1"
|
||||
reqwest = "0.8.6"
|
||||
serde_json = "1.0.22"
|
||||
html2text = "0.1.7"
|
||||
|
||||
[dependencies.gtk]
|
||||
features = ["v3_22"]
|
||||
@@ -33,7 +34,7 @@ version = "0.4.1"
|
||||
|
||||
[dependencies.gio]
|
||||
features = ["v2_50"]
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
|
||||
[dependencies.hammond-data]
|
||||
path = "../hammond-data"
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
// Rerun the build script when files in the resources folder are changed.
|
||||
println!("cargo:rerun-if-changed=resources");
|
||||
println!("cargo:rerun-if-changed=resources/*");
|
||||
|
||||
Command::new("glib-compile-resources")
|
||||
.args(&["--generate", "resources.xml"])
|
||||
.current_dir("resources")
|
||||
|
||||
@@ -41,37 +41,26 @@ Tobias Bernard
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkBox" id="info_container">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkLabel" id="title_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="title_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Episode Title</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="width_chars">55</property>
|
||||
<property name="single_line_mode">True</property>
|
||||
<property name="track_visited_links">False</property>
|
||||
<property name="lines">1</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<property name="label" translatable="yes">Episode Title</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="width_chars">55</property>
|
||||
<property name="single_line_mode">True</property>
|
||||
<property name="track_visited_links">False</property>
|
||||
<property name="lines">1</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
@@ -213,16 +202,16 @@ Tobias Bernard
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkButtonBox" id="button_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="layout_style">center</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="cancel_button">
|
||||
<property name="label" translatable="yes">Cancel</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
</object>
|
||||
<packing>
|
||||
@@ -237,8 +226,8 @@ Tobias Bernard
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Download this episode</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<child>
|
||||
@@ -252,8 +241,8 @@ Tobias Bernard
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">2</property>
|
||||
<property name="position">1</property>
|
||||
<property name="non_homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -262,6 +251,7 @@ Tobias Bernard
|
||||
<property name="receives_default">True</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Play this episode</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
@@ -274,15 +264,14 @@ Tobias Bernard
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">3</property>
|
||||
<property name="position">2</property>
|
||||
<property name="non_homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="padding">6</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
|
||||
@@ -151,9 +151,10 @@ Tobias Bernard
|
||||
<object class="GtkMenuButton" id="add_toggle">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Add a new feed</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="popover">add_popover</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="add-button-image2">
|
||||
<property name="visible">True</property>
|
||||
@@ -257,12 +258,11 @@ Tobias Bernard
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuButton" id="menu_toggle">
|
||||
<object class="GtkMenuButton" id="menu_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="popover">menu_popover</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
@@ -281,125 +281,4 @@ Tobias Bernard
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkPopover" id="menu_popover">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="relative_to">menu_toggle</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_right">10</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkModelButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="text" translatable="yes">Preferences</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkModelButton" id="update_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="text" translatable="yes">Check for new episodes</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkModelButton" id="import">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="text" translatable="yes">Import Shows</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkModelButton" id="export">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="text" translatable="yes">Export Shows</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparator">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkModelButton" id="about">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="text" translatable="yes">About</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkModelButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="text" translatable="yes">Help</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">7</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkModelButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="text" translatable="yes">Keyboard Shortcuts</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">8</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkShortcutsWindow" id="help_overlay">
|
||||
<property name="modal">True</property>
|
||||
<child>
|
||||
<object class="GtkShortcutsSection">
|
||||
<property name="section-name">shortcuts</property>
|
||||
<property name="max-height">12</property>
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<object class="GtkShortcutsGroup">
|
||||
<property name="title" translatable="yes">General</property>
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut">
|
||||
<property name="visible">True</property>
|
||||
<property name="accelerator"><primary>r</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Check for new episodes</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut">
|
||||
<property name="visible">True</property>
|
||||
<property name="accelerator"><primary>q</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Quit the application</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0"?>
|
||||
<interface>
|
||||
<!-- interface-requires gtk+ 3.0 -->
|
||||
<menu id="menu">
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Check for new episodes</attribute>
|
||||
<attribute name="action">win.refresh</attribute>
|
||||
<attribute name="accel"><primary>r</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Import Shows</attribute>
|
||||
<attribute name="action">win.import</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Export Shows</attribute>
|
||||
<attribute name="action">win.export</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Preferences</attribute>
|
||||
<attribute name="action">win.preferences</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
|
||||
<attribute name="action">win.show-help-overlay</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Help</attribute>
|
||||
<attribute name="action">win.help</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_About</attribute>
|
||||
<attribute name="action">win.about</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
</interface>
|
||||
@@ -0,0 +1,372 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.0 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkImage" id="ff_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">1</property>
|
||||
<property name="icon_name">media-seek-forward-symbolic</property>
|
||||
<property name="icon_size">1</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="pause_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">1</property>
|
||||
<property name="icon_name">media-playback-pause-symbolic</property>
|
||||
<property name="icon_size">1</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="play_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">1</property>
|
||||
<property name="icon_name">media-playback-start-symbolic</property>
|
||||
<property name="icon_size">1</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="previous_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">1</property>
|
||||
<property name="icon_name">media-seek-backward-symbolic</property>
|
||||
<property name="icon_size">1</property>
|
||||
</object>
|
||||
<object class="GtkActionBar" id="action_bar">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="valign">center</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="buttons">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">center</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="rewind_button">
|
||||
<property name="width_request">42</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Previous</property>
|
||||
<property name="image">previous_image</property>
|
||||
<property name="always_show_image">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="play_button">
|
||||
<property name="width_request">60</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Play</property>
|
||||
<property name="image">play_image</property>
|
||||
<property name="always_show_image">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="pause_button">
|
||||
<property name="width_request">60</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Play</property>
|
||||
<property name="image">pause_image</property>
|
||||
<property name="always_show_image">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="ff_button">
|
||||
<property name="width_request">42</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Next</property>
|
||||
<property name="image">ff_image</property>
|
||||
<property name="always_show_image">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<style>
|
||||
<class name="linked"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="info">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="show_cover">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="pixel_size">34</property>
|
||||
<property name="icon_name">image-x-generic-symbolic</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="show_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">Show Title</property>
|
||||
<property name="wrap">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="max_width_chars">20</property>
|
||||
<style>
|
||||
<class name="player-show-label"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="episode_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">Episode Title</property>
|
||||
<property name="wrap">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="max_width_chars">20</property>
|
||||
<style>
|
||||
<class name="player-episode-label"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScale" id="seek">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="round_digits">1</property>
|
||||
<property name="draw_value">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="timer">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="progress_time_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="label">0:00</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="separator">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="label">/</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="total_duration_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="label">0:00</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuButton" id="rate_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin_left">6</property>
|
||||
<property name="direction">up</property>
|
||||
<property name="popover">rate_popover</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="rate_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">1.00x</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">go-down-symbolic</property>
|
||||
<property name="icon_size">1</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkPopover" id="rate_popover">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="relative_to">rate_button</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">6</property>
|
||||
<property name="margin_right">6</property>
|
||||
<property name="margin_top">6</property>
|
||||
<property name="margin_bottom">6</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">3</property>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="rate_1_50">
|
||||
<property name="label" translatable="yes">1.50x</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">normal_rate</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="rate_1_25">
|
||||
<property name="label" translatable="yes">1.25x</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">normal_rate</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="normal_rate">
|
||||
<property name="label" translatable="yes">1.00x</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
@@ -9,3 +9,12 @@ row:last-child {
|
||||
list, border {
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.player-episode-label {
|
||||
font-weight: bold;
|
||||
font-size: smaller;
|
||||
}
|
||||
|
||||
.player-show-label {
|
||||
font-size: smaller;
|
||||
}
|
||||
@@ -5,10 +5,10 @@
|
||||
<project_license>GPL-3.0</project_license>
|
||||
<metadata_license>CC0-1.0</metadata_license>
|
||||
<developer_name>Jordan Petridis</developer_name>
|
||||
<summary>Modern Podcast Client for the GNOME desktop</summary>
|
||||
<summary>Modern Podcast application for the GNOME desktop</summary>
|
||||
<description xml:lang="en">
|
||||
<p>
|
||||
Hammond is a modern, reliable, and fast Podcast Client for the GNOME
|
||||
Hammond is a modern, reliable, and fast Podcast application for the GNOME
|
||||
desktop written in Rust.
|
||||
</p>
|
||||
</description>
|
||||
@@ -28,7 +28,7 @@
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
<releases>
|
||||
<release version="0.3.3" date="2018-05-19"/>
|
||||
<release version="0.4.0" date="2018-07-04"/>
|
||||
</releases>
|
||||
<url type="homepage">https://gitlab.gnome.org/World/hammond</url>
|
||||
<update_contact>jpetridis@gnome.org</update_contact>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/org/gnome/hammond/">
|
||||
<gresource prefix="/org/gnome/Hammond/">
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/episode_widget.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/show_widget.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/empty_view.ui</file>
|
||||
@@ -11,6 +11,9 @@
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/shows_child.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/headerbar.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/inapp_notif.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/menus.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/player_toolbar.ui</file>
|
||||
<file compressed="true">gtk/style.css</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
||||
+170
-97
@@ -1,31 +1,49 @@
|
||||
#![allow(new_without_default)]
|
||||
|
||||
use gio::{ApplicationExt, ApplicationExtManual, ApplicationFlags, Settings, SettingsExt};
|
||||
use gio::{
|
||||
self, ActionMapExt, ApplicationExt, ApplicationExtManual, ApplicationFlags, SettingsExt,
|
||||
SimpleAction, SimpleActionExt,
|
||||
};
|
||||
use glib;
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
use gtk::SettingsExt as GtkSettingsExt;
|
||||
|
||||
use hammond_data::Podcast;
|
||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||
use hammond_data::Show;
|
||||
|
||||
use appnotif::{InAppNotification, UndoState};
|
||||
use headerbar::Header;
|
||||
use settings::{self, WindowGeometry};
|
||||
use stacks::{Content, PopulatedState};
|
||||
use utils;
|
||||
use widgets::{mark_all_notif, remove_show_notif};
|
||||
use widgets::appnotif::{InAppNotification, UndoState};
|
||||
use widgets::player;
|
||||
use widgets::{about_dialog, mark_all_notif, remove_show_notif};
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Creates an action named $called in the action map $on with the handler $handle
|
||||
macro_rules! action {
|
||||
($on:expr, $called:expr, $handle:expr) => {{
|
||||
// Create a stateless, parameterless action
|
||||
let act = SimpleAction::new($called, None);
|
||||
// Connect the handler
|
||||
act.connect_activate($handle);
|
||||
// Add it to the map
|
||||
$on.add_action(&act);
|
||||
// Return the action
|
||||
act
|
||||
}};
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Action {
|
||||
RefreshAllViews,
|
||||
RefreshEpisodesView,
|
||||
RefreshEpisodesViewBGR,
|
||||
RefreshShowsView,
|
||||
ReplaceWidget(Arc<Podcast>),
|
||||
ReplaceWidget(Arc<Show>),
|
||||
RefreshWidgetIfSame(i32),
|
||||
ShowWidgetAnimated,
|
||||
ShowShowsAnimated,
|
||||
@@ -33,72 +51,91 @@ pub enum Action {
|
||||
HeaderBarNormal,
|
||||
HeaderBarShowUpdateIndicator,
|
||||
HeaderBarHideUpdateIndicator,
|
||||
MarkAllPlayerNotification(Arc<Podcast>),
|
||||
RemoveShow(Arc<Podcast>),
|
||||
MarkAllPlayerNotification(Arc<Show>),
|
||||
RemoveShow(Arc<Show>),
|
||||
ErrorNotification(String),
|
||||
InitEpisode(i32),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct App {
|
||||
app_instance: gtk::Application,
|
||||
window: gtk::Window,
|
||||
instance: gtk::Application,
|
||||
window: gtk::ApplicationWindow,
|
||||
overlay: gtk::Overlay,
|
||||
header: Rc<Header>,
|
||||
settings: gio::Settings,
|
||||
content: Rc<Content>,
|
||||
receiver: Receiver<Action>,
|
||||
headerbar: Rc<Header>,
|
||||
player: Rc<player::PlayerWidget>,
|
||||
sender: Sender<Action>,
|
||||
settings: Settings,
|
||||
receiver: Receiver<Action>,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> App {
|
||||
let settings = Settings::new("org.gnome.Hammond");
|
||||
let application = gtk::Application::new("org.gnome.Hammond", ApplicationFlags::empty())
|
||||
.expect("Application Initialization failed...");
|
||||
pub fn new(application: >k::Application) -> Rc<Self> {
|
||||
let settings = gio::Settings::new("org.gnome.Hammond");
|
||||
|
||||
// Weird magic I copy-pasted that sets the Application Name in the Shell.
|
||||
glib::set_application_name("Hammond");
|
||||
glib::set_prgname(Some("Hammond"));
|
||||
let (sender, receiver) = unbounded();
|
||||
|
||||
let cleanup_date = settings::get_cleanup_date(&settings);
|
||||
utils::cleanup(cleanup_date);
|
||||
|
||||
// Create the main window
|
||||
let window = gtk::Window::new(gtk::WindowType::Toplevel);
|
||||
let window = gtk::ApplicationWindow::new(application);
|
||||
window.set_title("Hammond");
|
||||
|
||||
window.connect_delete_event(clone!(application, settings, window => move |_, _| {
|
||||
window.connect_delete_event(clone!(application, settings => move |window, _| {
|
||||
WindowGeometry::from_window(&window).write(&settings);
|
||||
application.quit();
|
||||
Inhibit(false)
|
||||
}));
|
||||
|
||||
let (sender, receiver) = channel();
|
||||
|
||||
// Create a content instance
|
||||
let content =
|
||||
Rc::new(Content::new(sender.clone()).expect("Content Initialization failed."));
|
||||
let content = Content::new(&sender).expect("Content Initialization failed.");
|
||||
|
||||
// Create the headerbar
|
||||
let header = Rc::new(Header::new(&content, &window, &sender));
|
||||
let header = Header::new(&content, &sender);
|
||||
// Add the Headerbar to the window.
|
||||
window.set_titlebar(&header.container);
|
||||
|
||||
// Add the content main stack to the overlay.
|
||||
let overlay = gtk::Overlay::new();
|
||||
overlay.add(&content.get_stack());
|
||||
|
||||
// Add the overlay to the main window
|
||||
window.add(&overlay);
|
||||
let wrap = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||
// Add the overlay to the main Box
|
||||
wrap.add(&overlay);
|
||||
|
||||
App {
|
||||
app_instance: application,
|
||||
let player = player::PlayerWidget::new(&sender);
|
||||
// Add the player to the main Box
|
||||
wrap.add(&player.action_bar);
|
||||
|
||||
window.add(&wrap);
|
||||
|
||||
let app = App {
|
||||
instance: application.clone(),
|
||||
window,
|
||||
overlay,
|
||||
header,
|
||||
content,
|
||||
receiver,
|
||||
sender,
|
||||
settings,
|
||||
}
|
||||
overlay,
|
||||
headerbar: header,
|
||||
content,
|
||||
player,
|
||||
sender,
|
||||
receiver,
|
||||
};
|
||||
|
||||
Rc::new(app)
|
||||
}
|
||||
|
||||
fn init(app: &Rc<Self>) {
|
||||
let cleanup_date = settings::get_cleanup_date(&app.settings);
|
||||
// Garbage collect watched episodes from the disk
|
||||
utils::cleanup(cleanup_date);
|
||||
|
||||
app.setup_gactions();
|
||||
app.setup_timed_callbacks();
|
||||
|
||||
app.instance.connect_activate(move |_| ());
|
||||
|
||||
// Retrieve the previous window position and size.
|
||||
WindowGeometry::from_settings(&app.settings).apply(&app.window);
|
||||
|
||||
// Setup the Action channel
|
||||
gtk::timeout_add(25, clone!(app => move || app.setup_action_channel()));
|
||||
}
|
||||
|
||||
fn setup_timed_callbacks(&self) {
|
||||
@@ -108,17 +145,16 @@ impl App {
|
||||
}
|
||||
|
||||
fn setup_dark_theme(&self) {
|
||||
let settings = gtk::Settings::get_default().unwrap();
|
||||
let gtk_settings = gtk::Settings::get_default().unwrap();
|
||||
let enabled = self.settings.get_boolean("dark-theme");
|
||||
|
||||
settings.set_property_gtk_application_prefer_dark_theme(enabled);
|
||||
gtk_settings.set_property_gtk_application_prefer_dark_theme(enabled);
|
||||
}
|
||||
|
||||
fn setup_refresh_on_startup(&self) {
|
||||
// Update the feeds right after the Application is initialized.
|
||||
let sender = self.sender.clone();
|
||||
if self.settings.get_boolean("refresh-on-startup") {
|
||||
let sender = self.sender.clone();
|
||||
|
||||
info!("Refresh on startup.");
|
||||
// The ui loads async, after initialization
|
||||
// so we need to delay this a bit so it won't block
|
||||
@@ -133,10 +169,9 @@ impl App {
|
||||
|
||||
fn setup_auto_refresh(&self) {
|
||||
let refresh_interval = settings::get_refresh_interval(&self.settings).num_seconds() as u32;
|
||||
let sender = self.sender.clone();
|
||||
|
||||
info!("Auto-refresh every {:?} seconds.", refresh_interval);
|
||||
|
||||
let sender = self.sender.clone();
|
||||
gtk::timeout_add_seconds(refresh_interval, move || {
|
||||
let s: Option<Vec<_>> = None;
|
||||
utils::refresh(s, sender.clone());
|
||||
@@ -145,30 +180,57 @@ impl App {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn run(self) {
|
||||
WindowGeometry::from_settings(&self.settings).apply(&self.window);
|
||||
/// Define the `GAction`s.
|
||||
///
|
||||
/// Used in menus and the keyboard shortcuts dialog.
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn setup_gactions(&self) {
|
||||
let sender = &self.sender;
|
||||
let win = &self.window;
|
||||
let instance = &self.instance;
|
||||
let header = &self.headerbar;
|
||||
|
||||
let window = self.window.clone();
|
||||
self.app_instance.connect_startup(move |app| {
|
||||
build_ui(&window, app);
|
||||
});
|
||||
// Create the `refresh` action.
|
||||
//
|
||||
// This will trigger a refresh of all the shows in the database.
|
||||
action!(win, "refresh", clone!(sender => move |_, _| {
|
||||
gtk::idle_add(clone!(sender => move || {
|
||||
let s: Option<Vec<_>> = None;
|
||||
utils::refresh(s, sender.clone());
|
||||
glib::Continue(false)
|
||||
}));
|
||||
}));
|
||||
self.instance.set_accels_for_action("win.refresh", &["<primary>r"]);
|
||||
|
||||
self.setup_timed_callbacks();
|
||||
// Create the `OPML` import action
|
||||
action!(win, "import", clone!(sender, win => move |_, _| {
|
||||
utils::on_import_clicked(&win, &sender)
|
||||
}));
|
||||
|
||||
let content = self.content;
|
||||
let headerbar = self.header;
|
||||
let sender = self.sender;
|
||||
let overlay = self.overlay;
|
||||
let receiver = self.receiver;
|
||||
gtk::timeout_add(50, move || {
|
||||
match receiver.try_recv() {
|
||||
Ok(Action::RefreshAllViews) => content.update(),
|
||||
Ok(Action::RefreshShowsView) => content.update_shows_view(),
|
||||
Ok(Action::RefreshWidgetIfSame(id)) => content.update_widget_if_same(id),
|
||||
Ok(Action::RefreshEpisodesView) => content.update_home(),
|
||||
Ok(Action::RefreshEpisodesViewBGR) => content.update_home_if_background(),
|
||||
Ok(Action::ReplaceWidget(pd)) => {
|
||||
let shows = content.get_shows();
|
||||
// Create the action that shows a `gtk::AboutDialog`
|
||||
action!(win, "about", clone!(win => move |_, _| about_dialog(&win)));
|
||||
|
||||
// Create the quit action
|
||||
action!(win, "quit", clone!(instance => move |_, _| instance.quit()));
|
||||
self.instance.set_accels_for_action("win.quit", &["<primary>q"]);
|
||||
|
||||
// Create the menu action
|
||||
action!(win, "menu",clone!(header => move |_, _| header.open_menu()));
|
||||
// Bind the hamburger menu button to `F10`
|
||||
self.instance.set_accels_for_action("win.menu", &["F10"]);
|
||||
}
|
||||
|
||||
fn setup_action_channel(&self) -> glib::Continue {
|
||||
if let Some(action) = self.receiver.try_recv() {
|
||||
trace!("Incoming channel action: {:?}", action);
|
||||
match action {
|
||||
Action::RefreshAllViews => self.content.update(),
|
||||
Action::RefreshShowsView => self.content.update_shows_view(),
|
||||
Action::RefreshWidgetIfSame(id) => self.content.update_widget_if_same(id),
|
||||
Action::RefreshEpisodesView => self.content.update_home(),
|
||||
Action::RefreshEpisodesViewBGR => self.content.update_home_if_background(),
|
||||
Action::ReplaceWidget(pd) => {
|
||||
let shows = self.content.get_shows();
|
||||
let mut pop = shows.borrow().populated();
|
||||
pop.borrow_mut()
|
||||
.replace_widget(pd.clone())
|
||||
@@ -176,51 +238,62 @@ impl App {
|
||||
.map_err(|_| error!("Failed ot update ShowWidget {}", pd.title()))
|
||||
.ok();
|
||||
}
|
||||
Ok(Action::ShowWidgetAnimated) => {
|
||||
let shows = content.get_shows();
|
||||
Action::ShowWidgetAnimated => {
|
||||
let shows = self.content.get_shows();
|
||||
let mut pop = shows.borrow().populated();
|
||||
pop.borrow_mut().switch_visible(
|
||||
PopulatedState::Widget,
|
||||
gtk::StackTransitionType::SlideLeft,
|
||||
);
|
||||
}
|
||||
Ok(Action::ShowShowsAnimated) => {
|
||||
let shows = content.get_shows();
|
||||
Action::ShowShowsAnimated => {
|
||||
let shows = self.content.get_shows();
|
||||
let mut pop = shows.borrow().populated();
|
||||
pop.borrow_mut()
|
||||
.switch_visible(PopulatedState::View, gtk::StackTransitionType::SlideRight);
|
||||
}
|
||||
Ok(Action::HeaderBarShowTile(title)) => headerbar.switch_to_back(&title),
|
||||
Ok(Action::HeaderBarNormal) => headerbar.switch_to_normal(),
|
||||
Ok(Action::HeaderBarShowUpdateIndicator) => headerbar.show_update_notification(),
|
||||
Ok(Action::HeaderBarHideUpdateIndicator) => headerbar.hide_update_notification(),
|
||||
Ok(Action::MarkAllPlayerNotification(pd)) => {
|
||||
let notif = mark_all_notif(pd, &sender);
|
||||
notif.show(&overlay);
|
||||
Action::HeaderBarShowTile(title) => self.headerbar.switch_to_back(&title),
|
||||
Action::HeaderBarNormal => self.headerbar.switch_to_normal(),
|
||||
Action::HeaderBarShowUpdateIndicator => self.headerbar.show_update_notification(),
|
||||
Action::HeaderBarHideUpdateIndicator => self.headerbar.hide_update_notification(),
|
||||
Action::MarkAllPlayerNotification(pd) => {
|
||||
let notif = mark_all_notif(pd, &self.sender);
|
||||
notif.show(&self.overlay);
|
||||
}
|
||||
Ok(Action::RemoveShow(pd)) => {
|
||||
let notif = remove_show_notif(pd, sender.clone());
|
||||
notif.show(&overlay);
|
||||
Action::RemoveShow(pd) => {
|
||||
let notif = remove_show_notif(pd, self.sender.clone());
|
||||
notif.show(&self.overlay);
|
||||
}
|
||||
Ok(Action::ErrorNotification(err)) => {
|
||||
Action::ErrorNotification(err) => {
|
||||
error!("An error notification was triggered: {}", err);
|
||||
let callback = || glib::Continue(false);
|
||||
let notif = InAppNotification::new(&err, callback, || {}, UndoState::Hidden);
|
||||
notif.show(&overlay);
|
||||
notif.show(&self.overlay);
|
||||
}
|
||||
Err(_) => (),
|
||||
Action::InitEpisode(rowid) => self.player.initialize_episode(rowid).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
Continue(true)
|
||||
});
|
||||
glib::Continue(true)
|
||||
}
|
||||
|
||||
ApplicationExtManual::run(&self.app_instance, &[]);
|
||||
pub fn run() {
|
||||
let application = gtk::Application::new("org.gnome.Hammond", ApplicationFlags::empty())
|
||||
.expect("Application Initialization failed...");
|
||||
|
||||
application.connect_startup(clone!(application => move |_| {
|
||||
info!("CONNECT STARTUP RUN");
|
||||
let app = Self::new(&application);
|
||||
Self::init(&app);
|
||||
app.window.show_all();
|
||||
app.window.activate();
|
||||
}));
|
||||
|
||||
// Weird magic I copy-pasted that sets the Application Name in the Shell.
|
||||
glib::set_application_name("Hammond");
|
||||
glib::set_prgname(Some("Hammond"));
|
||||
// We need out own org.gnome.Hammon icon
|
||||
gtk::Window::set_default_icon_name("multimedia-player");
|
||||
ApplicationExtManual::run(&application, &[]);
|
||||
}
|
||||
}
|
||||
|
||||
fn build_ui(window: >k::Window, app: >k::Application) {
|
||||
window.set_application(app);
|
||||
window.show_all();
|
||||
window.activate();
|
||||
app.connect_activate(move |_| ());
|
||||
}
|
||||
|
||||
+193
-261
@@ -1,151 +1,243 @@
|
||||
use glib;
|
||||
use gio::MenuModel;
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use failure::Error;
|
||||
use failure::ResultExt;
|
||||
use rayon;
|
||||
use url::Url;
|
||||
|
||||
use hammond_data::{dbqueries, opml, Source};
|
||||
|
||||
use std::sync::mpsc::Sender;
|
||||
use hammond_data::{dbqueries, Source};
|
||||
|
||||
use app::Action;
|
||||
use stacks::Content;
|
||||
use utils::{self, itunes_to_rss, refresh};
|
||||
use utils::{itunes_to_rss, refresh};
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
// TODO: split this into smaller
|
||||
// TODO: Factor out the hamburger menu
|
||||
// TODO: Make a proper state machine for the headerbar states
|
||||
pub struct Header {
|
||||
container: gtk::HeaderBar,
|
||||
add_toggle: gtk::MenuButton,
|
||||
pub container: gtk::HeaderBar,
|
||||
switch: gtk::StackSwitcher,
|
||||
back: gtk::Button,
|
||||
show_title: gtk::Label,
|
||||
about: gtk::ModelButton,
|
||||
import: gtk::ModelButton,
|
||||
export: gtk::ModelButton,
|
||||
update_button: gtk::ModelButton,
|
||||
update_box: gtk::Box,
|
||||
update_label: gtk::Label,
|
||||
update_spinner: gtk::Spinner,
|
||||
menu_button: gtk::MenuButton,
|
||||
app_menu: MenuModel,
|
||||
updater: UpdateIndicator,
|
||||
add: AddPopover,
|
||||
}
|
||||
|
||||
impl Default for Header {
|
||||
fn default() -> Header {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/headerbar.ui");
|
||||
#[derive(Debug, Clone)]
|
||||
struct UpdateIndicator {
|
||||
container: gtk::Box,
|
||||
text: gtk::Label,
|
||||
spinner: gtk::Spinner,
|
||||
}
|
||||
|
||||
let header = builder.get_object("headerbar").unwrap();
|
||||
let add_toggle = builder.get_object("add_toggle").unwrap();
|
||||
let switch = builder.get_object("switch").unwrap();
|
||||
let back = builder.get_object("back").unwrap();
|
||||
let show_title = builder.get_object("show_title").unwrap();
|
||||
let import = builder.get_object("import").unwrap();
|
||||
let export = builder.get_object("export").unwrap();
|
||||
let update_button = builder.get_object("update_button").unwrap();
|
||||
let update_box = builder.get_object("update_notification").unwrap();
|
||||
let update_label = builder.get_object("update_label").unwrap();
|
||||
let update_spinner = builder.get_object("update_spinner").unwrap();
|
||||
let about = builder.get_object("about").unwrap();
|
||||
impl UpdateIndicator {
|
||||
fn show(&self) {
|
||||
self.spinner.start();
|
||||
self.spinner.show();
|
||||
self.container.show();
|
||||
self.text.show();
|
||||
}
|
||||
|
||||
Header {
|
||||
container: header,
|
||||
add_toggle,
|
||||
switch,
|
||||
back,
|
||||
show_title,
|
||||
about,
|
||||
import,
|
||||
export,
|
||||
update_button,
|
||||
update_box,
|
||||
update_label,
|
||||
update_spinner,
|
||||
fn hide(&self) {
|
||||
self.spinner.stop();
|
||||
self.spinner.hide();
|
||||
self.container.hide();
|
||||
self.text.hide();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct AddPopover {
|
||||
container: gtk::Popover,
|
||||
result: gtk::Label,
|
||||
entry: gtk::Entry,
|
||||
add: gtk::Button,
|
||||
toggle: gtk::MenuButton,
|
||||
}
|
||||
|
||||
impl AddPopover {
|
||||
// FIXME: THIS ALSO SUCKS!
|
||||
fn on_add_clicked(&self, sender: &Sender<Action>) -> Result<(), Error> {
|
||||
let url = self
|
||||
.entry
|
||||
.get_text()
|
||||
.ok_or_else(|| format_err!("GtkEntry blew up somehow."))?;
|
||||
|
||||
debug!("Url: {}", url);
|
||||
let url = if url.contains("itunes.com") || url.contains("apple.com") {
|
||||
info!("Detected itunes url.");
|
||||
let foo = itunes_to_rss(&url)?;
|
||||
info!("Resolved to {}", foo);
|
||||
foo
|
||||
} else {
|
||||
url.to_owned()
|
||||
};
|
||||
|
||||
self.entry.set_text("");
|
||||
|
||||
rayon::spawn(clone!(sender => move || {
|
||||
if let Ok(source) = Source::from_url(&url) {
|
||||
refresh(Some(vec![source]), sender.clone());
|
||||
} else {
|
||||
error!("Failed to convert, url: {}, to a source entry", url);
|
||||
}
|
||||
}));
|
||||
|
||||
self.container.hide();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// FIXME: THIS SUCKS! REFACTOR ME.
|
||||
fn on_entry_changed(&self) -> Result<(), Error> {
|
||||
let uri = self
|
||||
.entry
|
||||
.get_text()
|
||||
.ok_or_else(|| format_err!("GtkEntry blew up somehow."))?;
|
||||
debug!("Url: {}", uri);
|
||||
|
||||
let url = Url::parse(&uri);
|
||||
// TODO: refactor to avoid duplication
|
||||
match url {
|
||||
Ok(u) => {
|
||||
if !dbqueries::source_exists(u.as_str())? {
|
||||
self.add.set_sensitive(true);
|
||||
self.result.hide();
|
||||
self.result.set_label("");
|
||||
} else {
|
||||
self.add.set_sensitive(false);
|
||||
self.result.set_label("Show already exists.");
|
||||
self.result.show();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
self.add.set_sensitive(false);
|
||||
if !uri.is_empty() {
|
||||
self.result.set_label("Invalid url.");
|
||||
self.result.show();
|
||||
error!("Error: {}", err);
|
||||
} else {
|
||||
self.result.hide();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Refactor components into smaller state machines
|
||||
impl Default for Header {
|
||||
fn default() -> Header {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/headerbar.ui");
|
||||
let menus = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/menus.ui");
|
||||
|
||||
let header = builder.get_object("headerbar").unwrap();
|
||||
let switch = builder.get_object("switch").unwrap();
|
||||
let back = builder.get_object("back").unwrap();
|
||||
let show_title = builder.get_object("show_title").unwrap();
|
||||
let menu_button = builder.get_object("menu_button").unwrap();
|
||||
let app_menu = menus.get_object("menu").unwrap();
|
||||
|
||||
let update_box = builder.get_object("update_notification").unwrap();
|
||||
let update_label = builder.get_object("update_label").unwrap();
|
||||
let update_spinner = builder.get_object("update_spinner").unwrap();
|
||||
|
||||
let updater = UpdateIndicator {
|
||||
container: update_box,
|
||||
text: update_label,
|
||||
spinner: update_spinner,
|
||||
};
|
||||
|
||||
let add_toggle = builder.get_object("add_toggle").unwrap();
|
||||
let add_popover = builder.get_object("add_popover").unwrap();
|
||||
let new_url = builder.get_object("new_url").unwrap();
|
||||
let add_button = builder.get_object("add_button").unwrap();
|
||||
let result = builder.get_object("result_label").unwrap();
|
||||
let add = AddPopover {
|
||||
container: add_popover,
|
||||
entry: new_url,
|
||||
toggle: add_toggle,
|
||||
add: add_button,
|
||||
result,
|
||||
};
|
||||
|
||||
Header {
|
||||
container: header,
|
||||
switch,
|
||||
back,
|
||||
show_title,
|
||||
menu_button,
|
||||
app_menu,
|
||||
updater,
|
||||
add,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Factor out the hamburger menu
|
||||
// TODO: Make a proper state machine for the headerbar states
|
||||
impl Header {
|
||||
pub fn new(content: &Content, window: >k::Window, sender: &Sender<Action>) -> Header {
|
||||
let h = Header::default();
|
||||
h.init(content, window, &sender);
|
||||
pub fn new(content: &Content, sender: &Sender<Action>) -> Rc<Self> {
|
||||
let h = Rc::new(Header::default());
|
||||
Self::init(&h, content, &sender);
|
||||
h
|
||||
}
|
||||
|
||||
pub fn init(&self, content: &Content, window: >k::Window, sender: &Sender<Action>) {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/headerbar.ui");
|
||||
pub fn init(s: &Rc<Self>, content: &Content, sender: &Sender<Action>) {
|
||||
let weak = Rc::downgrade(s);
|
||||
|
||||
let add_popover: gtk::Popover = builder.get_object("add_popover").unwrap();
|
||||
let new_url: gtk::Entry = builder.get_object("new_url").unwrap();
|
||||
let add_button: gtk::Button = builder.get_object("add_button").unwrap();
|
||||
let result_label: gtk::Label = builder.get_object("result_label").unwrap();
|
||||
self.switch.set_stack(&content.get_stack());
|
||||
s.switch.set_stack(&content.get_stack());
|
||||
|
||||
new_url.connect_changed(clone!(add_button => move |url| {
|
||||
on_url_change(url, &result_label, &add_button)
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
s.add.entry.connect_changed(clone!(weak => move |_| {
|
||||
weak.upgrade().map(|h| {
|
||||
h.add.on_entry_changed()
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
});
|
||||
}));
|
||||
|
||||
add_button.connect_clicked(clone!(add_popover, new_url, sender => move |_| {
|
||||
on_add_bttn_clicked(&new_url, sender.clone())
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
add_popover.hide();
|
||||
s.add.add.connect_clicked(clone!(weak, sender => move |_| {
|
||||
weak.upgrade().map(|h| h.add.on_add_clicked(&sender));
|
||||
}));
|
||||
|
||||
self.add_toggle.set_popover(&add_popover);
|
||||
|
||||
self.update_button
|
||||
.connect_clicked(clone!(sender => move |_| {
|
||||
gtk::idle_add(clone!(sender => move || {
|
||||
let s: Option<Vec<_>> = None;
|
||||
refresh(s, sender.clone());
|
||||
glib::Continue(false)
|
||||
}));
|
||||
}));
|
||||
|
||||
self.about
|
||||
.connect_clicked(clone!(window => move |_| about_dialog(&window)));
|
||||
|
||||
self.import.connect_clicked(
|
||||
clone!(window, sender => move |_| on_import_clicked(&window, &sender)),
|
||||
);
|
||||
|
||||
// Add the Headerbar to the window.
|
||||
window.set_titlebar(&self.container);
|
||||
|
||||
let switch = &self.switch;
|
||||
let add_toggle = &self.add_toggle;
|
||||
let show_title = &self.show_title;
|
||||
self.back.connect_clicked(
|
||||
clone!(switch, add_toggle, show_title, sender => move |back| {
|
||||
let switch = &s.switch;
|
||||
let add_toggle = &s.add.toggle;
|
||||
let show_title = &s.show_title;
|
||||
let menu = &s.menu_button;
|
||||
s.back.connect_clicked(
|
||||
clone!(switch, add_toggle, show_title, sender, menu => move |back| {
|
||||
switch.show();
|
||||
add_toggle.show();
|
||||
back.hide();
|
||||
show_title.hide();
|
||||
sender.send(Action::ShowShowsAnimated)
|
||||
.map_err(|err| error!("Action Sender: {}", err))
|
||||
.ok();
|
||||
menu.show();
|
||||
sender.send(Action::ShowShowsAnimated);
|
||||
}),
|
||||
);
|
||||
|
||||
s.menu_button.set_menu_model(Some(&s.app_menu));
|
||||
}
|
||||
|
||||
pub fn switch_to_back(&self, title: &str) {
|
||||
self.switch.hide();
|
||||
self.add_toggle.hide();
|
||||
self.add.toggle.hide();
|
||||
self.back.show();
|
||||
self.set_show_title(title);
|
||||
self.show_title.show();
|
||||
self.menu_button.hide();
|
||||
}
|
||||
|
||||
pub fn switch_to_normal(&self) {
|
||||
self.switch.show();
|
||||
self.add_toggle.show();
|
||||
self.add.toggle.show();
|
||||
self.back.hide();
|
||||
self.show_title.hide();
|
||||
self.menu_button.show();
|
||||
}
|
||||
|
||||
pub fn set_show_title(&self, title: &str) {
|
||||
@@ -153,174 +245,14 @@ impl Header {
|
||||
}
|
||||
|
||||
pub fn show_update_notification(&self) {
|
||||
self.update_spinner.start();
|
||||
self.update_box.show();
|
||||
self.update_spinner.show();
|
||||
self.update_label.show();
|
||||
self.updater.show();
|
||||
}
|
||||
|
||||
pub fn hide_update_notification(&self) {
|
||||
self.update_spinner.stop();
|
||||
self.update_box.hide();
|
||||
self.update_spinner.hide();
|
||||
self.update_label.hide();
|
||||
self.updater.hide();
|
||||
}
|
||||
|
||||
pub fn open_menu(&self) {
|
||||
self.menu_button.clicked();
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: THIS ALSO SUCKS!
|
||||
fn on_add_bttn_clicked(entry: >k::Entry, sender: Sender<Action>) -> Result<(), Error> {
|
||||
let url = entry.get_text().unwrap_or_default();
|
||||
let url = if url.contains("itunes.com") || url.contains("apple.com") {
|
||||
info!("Detected itunes url.");
|
||||
let foo = itunes_to_rss(&url)?;
|
||||
info!("Resolved to {}", foo);
|
||||
foo
|
||||
} else {
|
||||
url.to_owned()
|
||||
};
|
||||
|
||||
let source = Source::from_url(&url).context("Failed to convert url to a Source entry.")?;
|
||||
entry.set_text("");
|
||||
|
||||
gtk::idle_add(move || {
|
||||
refresh(Some(vec![source.clone()]), sender.clone());
|
||||
glib::Continue(false)
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// FIXME: THIS SUCKS!
|
||||
fn on_url_change(
|
||||
entry: >k::Entry,
|
||||
result: >k::Label,
|
||||
add_button: >k::Button,
|
||||
) -> Result<(), Error> {
|
||||
let uri = entry
|
||||
.get_text()
|
||||
.ok_or_else(|| format_err!("GtkEntry blew up somehow."))?;
|
||||
debug!("Url: {}", uri);
|
||||
|
||||
let url = Url::parse(&uri);
|
||||
// TODO: refactor to avoid duplication
|
||||
match url {
|
||||
Ok(u) => {
|
||||
if !dbqueries::source_exists(u.as_str())? {
|
||||
add_button.set_sensitive(true);
|
||||
result.hide();
|
||||
result.set_label("");
|
||||
} else {
|
||||
add_button.set_sensitive(false);
|
||||
result.set_label("Show already exists.");
|
||||
result.show();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
add_button.set_sensitive(false);
|
||||
if !uri.is_empty() {
|
||||
result.set_label("Invalid url.");
|
||||
result.show();
|
||||
error!("Error: {}", err);
|
||||
} else {
|
||||
result.hide();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn on_import_clicked(window: >k::Window, sender: &Sender<Action>) {
|
||||
use glib::translate::ToGlib;
|
||||
use gtk::{FileChooserAction, FileChooserDialog, FileFilter, ResponseType};
|
||||
|
||||
// let dialog = FileChooserDialog::new(title, Some(&window), FileChooserAction::Open);
|
||||
// TODO: It might be better to use a FileChooserNative widget.
|
||||
// Create the FileChooser Dialog
|
||||
let dialog = FileChooserDialog::with_buttons(
|
||||
Some("Select the file from which to you want to Import Shows."),
|
||||
Some(window),
|
||||
FileChooserAction::Open,
|
||||
&[
|
||||
("_Cancel", ResponseType::Cancel),
|
||||
("_Open", ResponseType::Accept),
|
||||
],
|
||||
);
|
||||
|
||||
// Do not show hidden(.thing) files
|
||||
dialog.set_show_hidden(false);
|
||||
|
||||
// Set a filter to show only xml files
|
||||
let filter = FileFilter::new();
|
||||
FileFilterExt::set_name(&filter, Some("OPML file"));
|
||||
filter.add_mime_type("application/xml");
|
||||
filter.add_mime_type("text/xml");
|
||||
dialog.add_filter(&filter);
|
||||
|
||||
dialog.connect_response(clone!(sender => move |dialog, resp| {
|
||||
debug!("Dialong Response {}", resp);
|
||||
if resp == ResponseType::Accept.to_glib() {
|
||||
// TODO: Show an in-app notifictaion if the file can not be accessed
|
||||
if let Some(filename) = dialog.get_filename() {
|
||||
debug!("File selected: {:?}", filename);
|
||||
|
||||
rayon::spawn(clone!(sender => move || {
|
||||
// Parse the file and import the feeds
|
||||
if let Ok(sources) = opml::import_from_file(filename) {
|
||||
// Refresh the succesfully parsed feeds to index them
|
||||
utils::refresh(Some(sources), sender)
|
||||
} else {
|
||||
let text = String::from("Failed to parse the Imported file");
|
||||
sender.send(Action::ErrorNotification(text))
|
||||
.map_err(|err| error!("Action Sender: {}", err))
|
||||
.ok();
|
||||
}
|
||||
}))
|
||||
} else {
|
||||
let text = String::from("Selected File could not be accessed.");
|
||||
sender.send(Action::ErrorNotification(text))
|
||||
.map_err(|err| error!("Action Sender: {}", err))
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
dialog.destroy();
|
||||
}));
|
||||
|
||||
dialog.run();
|
||||
}
|
||||
|
||||
// Totally copied it from fractal.
|
||||
// https://gitlab.gnome.org/danigm/fractal/blob/503e311e22b9d7540089d735b92af8e8f93560c5/fractal-gtk/src/app.rs#L1883-1912
|
||||
fn about_dialog(window: >k::Window) {
|
||||
// Feel free to add yourself if you contribured.
|
||||
let authors = &[
|
||||
"Constantin Nickel",
|
||||
"Gabriele Musco",
|
||||
"James Wykeham-Martin",
|
||||
"Jordan Petridis",
|
||||
"Julian Sparber",
|
||||
"Rowan Lewis",
|
||||
];
|
||||
|
||||
let dialog = gtk::AboutDialog::new();
|
||||
// Waiting for a logo.
|
||||
// dialog.set_logo_icon_name("org.gnome.Hammond");
|
||||
dialog.set_logo_icon_name("multimedia-player");
|
||||
dialog.set_comments("Podcast Client for the GNOME Desktop.");
|
||||
dialog.set_copyright("© 2017, 2018 Jordan Petridis");
|
||||
dialog.set_license_type(gtk::License::Gpl30);
|
||||
dialog.set_modal(true);
|
||||
// TODO: make it show it fetches the commit hash from which it was built
|
||||
// and the version number is kept in sync automaticly
|
||||
dialog.set_version("0.3.3");
|
||||
dialog.set_program_name("Hammond");
|
||||
// TODO: Need a wiki page first.
|
||||
// dialog.set_website("https://wiki.gnome.org/Design/Apps/Potential/Podcasts");
|
||||
// dialog.set_website_label("Learn more about Hammond");
|
||||
dialog.set_transient_for(window);
|
||||
|
||||
dialog.set_artists(&["Tobias Bernard"]);
|
||||
dialog.set_authors(authors);
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
+15
-6
@@ -3,13 +3,23 @@
|
||||
allow(clone_on_ref_ptr, blacklisted_name, match_same_arms, option_map_unit_fn)
|
||||
)]
|
||||
#![allow(unknown_lints)]
|
||||
#![warn(unused_extern_crates, unused)]
|
||||
// Enable lint group collections
|
||||
#![warn(nonstandard_style, edition_2018, rust_2018_idioms, bad_style, unused)]
|
||||
// standalone lints
|
||||
#![warn(
|
||||
const_err, improper_ctypes, non_shorthand_field_patterns, no_mangle_generic_items,
|
||||
overflowing_literals, plugin_as_library, private_no_mangle_fns, private_no_mangle_statics,
|
||||
unconditional_recursion, unions_with_drop_fields, while_true, missing_debug_implementations,
|
||||
trivial_casts, trivial_numeric_casts, elided_lifetime_in_paths, missing_copy_implementations
|
||||
)]
|
||||
#![deny(warnings)]
|
||||
|
||||
extern crate gdk;
|
||||
extern crate gdk_pixbuf;
|
||||
extern crate gio;
|
||||
extern crate glib;
|
||||
extern crate gstreamer as gst;
|
||||
extern crate gstreamer_player as gst_player;
|
||||
extern crate gtk;
|
||||
|
||||
#[macro_use]
|
||||
@@ -29,7 +39,7 @@ extern crate chrono;
|
||||
extern crate crossbeam_channel;
|
||||
extern crate hammond_data;
|
||||
extern crate hammond_downloader;
|
||||
extern crate html2pango;
|
||||
extern crate html2text;
|
||||
extern crate humansize;
|
||||
extern crate loggerv;
|
||||
extern crate open;
|
||||
@@ -38,7 +48,6 @@ extern crate regex;
|
||||
extern crate reqwest;
|
||||
extern crate send_cell;
|
||||
extern crate serde_json;
|
||||
extern crate take_mut;
|
||||
extern crate url;
|
||||
|
||||
use log::Level;
|
||||
@@ -70,7 +79,6 @@ mod widgets;
|
||||
mod app;
|
||||
mod headerbar;
|
||||
|
||||
mod appnotif;
|
||||
mod manager;
|
||||
mod settings;
|
||||
mod static_resource;
|
||||
@@ -82,16 +90,17 @@ fn main() {
|
||||
// TODO: make the the logger a cli -vv option
|
||||
loggerv::init_with_level(Level::Info).expect("Error initializing loggerv.");
|
||||
gtk::init().expect("Error initializing gtk.");
|
||||
gst::init().expect("Error initializing gstreamer");
|
||||
static_resource::init().expect("Something went wrong with the resource file initialization.");
|
||||
|
||||
// Add custom style
|
||||
let provider = gtk::CssProvider::new();
|
||||
gtk::CssProvider::load_from_resource(&provider, "/org/gnome/hammond/gtk/style.css");
|
||||
gtk::CssProvider::load_from_resource(&provider, "/org/gnome/Hammond/gtk/style.css");
|
||||
gtk::StyleContext::add_provider_for_screen(
|
||||
&gdk::Screen::get_default().expect("Error initializing gtk css provider."),
|
||||
&provider,
|
||||
600,
|
||||
);
|
||||
|
||||
App::new().run();
|
||||
App::run();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pub struct WindowGeometry {
|
||||
}
|
||||
|
||||
impl WindowGeometry {
|
||||
pub fn from_window(window: >k::Window) -> WindowGeometry {
|
||||
pub fn from_window(window: >k::ApplicationWindow) -> WindowGeometry {
|
||||
let position = window.get_position();
|
||||
let size = window.get_size();
|
||||
let left = position.0;
|
||||
@@ -49,7 +49,7 @@ impl WindowGeometry {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply(&self, window: >k::Window) {
|
||||
pub fn apply(&self, window: >k::ApplicationWindow) {
|
||||
if self.width > 0 && self.height > 0 {
|
||||
window.resize(self.width, self.height);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use failure::Error;
|
||||
|
||||
use app::Action;
|
||||
@@ -8,7 +9,6 @@ use stacks::{HomeStack, ShowStack};
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Content {
|
||||
@@ -19,20 +19,21 @@ pub struct Content {
|
||||
}
|
||||
|
||||
impl Content {
|
||||
pub fn new(sender: Sender<Action>) -> Result<Content, Error> {
|
||||
pub fn new(sender: &Sender<Action>) -> Result<Rc<Content>, Error> {
|
||||
let stack = gtk::Stack::new();
|
||||
let home = Rc::new(RefCell::new(HomeStack::new(sender.clone())?));
|
||||
let shows = Rc::new(RefCell::new(ShowStack::new(sender.clone())?));
|
||||
|
||||
stack.add_titled(&home.borrow().get_stack(), "home", "Recent");
|
||||
stack.add_titled(&home.borrow().get_stack(), "home", "New");
|
||||
stack.add_titled(&shows.borrow().get_stack(), "shows", "Shows");
|
||||
|
||||
Ok(Content {
|
||||
let con = Content {
|
||||
stack,
|
||||
shows,
|
||||
home,
|
||||
sender,
|
||||
})
|
||||
sender: sender.clone(),
|
||||
};
|
||||
Ok(Rc::new(con))
|
||||
}
|
||||
|
||||
pub fn update(&self) {
|
||||
|
||||
@@ -2,6 +2,7 @@ use gtk;
|
||||
use gtk::prelude::*;
|
||||
use gtk::StackTransitionType;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use failure::Error;
|
||||
use hammond_data::dbqueries::is_episodes_populated;
|
||||
use hammond_data::errors::DataError;
|
||||
@@ -10,7 +11,6 @@ use app::Action;
|
||||
use widgets::{EmptyView, HomeView};
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum State {
|
||||
|
||||
@@ -2,16 +2,16 @@ use gtk;
|
||||
use gtk::prelude::*;
|
||||
use gtk::StackTransitionType;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use failure::Error;
|
||||
|
||||
use hammond_data::dbqueries;
|
||||
use hammond_data::Podcast;
|
||||
use hammond_data::Show;
|
||||
|
||||
use app::Action;
|
||||
use widgets::{ShowWidget, ShowsView};
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -89,13 +89,11 @@ impl PopulatedStack {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn replace_widget(&mut self, pd: Arc<Podcast>) -> Result<(), Error> {
|
||||
pub fn replace_widget(&mut self, pd: Arc<Show>) -> Result<(), Error> {
|
||||
let old = self.show.container.clone();
|
||||
|
||||
// save the ShowWidget vertical scrollabar alignment
|
||||
self.show
|
||||
.podcast_id()
|
||||
.map(|id| self.show.save_vadjustment(id));
|
||||
self.show.show_id().map(|id| self.show.save_vadjustment(id));
|
||||
|
||||
let new = ShowWidget::new(pd, self.sender.clone());
|
||||
self.show = new;
|
||||
@@ -113,7 +111,7 @@ impl PopulatedStack {
|
||||
|
||||
pub fn update_widget(&mut self) -> Result<(), Error> {
|
||||
let old = self.show.container.clone();
|
||||
let id = self.show.podcast_id();
|
||||
let id = self.show.show_id();
|
||||
if id.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -131,9 +129,9 @@ impl PopulatedStack {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Only update widget if its podcast_id is equal to pid.
|
||||
// Only update widget if its show_id is equal to pid.
|
||||
pub fn update_widget_if_same(&mut self, pid: i32) -> Result<(), Error> {
|
||||
if self.show.podcast_id() != Some(pid) {
|
||||
if self.show.show_id() != Some(pid) {
|
||||
debug!("Different widget. Early return");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use failure::Error;
|
||||
use hammond_data::dbqueries::is_podcasts_populated;
|
||||
|
||||
@@ -11,7 +12,6 @@ use widgets::EmptyView;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ShowState {
|
||||
|
||||
+73
-35
@@ -8,6 +8,7 @@ use gtk::prelude::*;
|
||||
use gtk::{IsA, Widget};
|
||||
|
||||
use chrono::prelude::*;
|
||||
use crossbeam_channel::{unbounded, Sender};
|
||||
use failure::Error;
|
||||
use rayon;
|
||||
use regex::Regex;
|
||||
@@ -17,15 +18,14 @@ use serde_json::Value;
|
||||
|
||||
// use hammond_data::feed;
|
||||
use hammond_data::dbqueries;
|
||||
use hammond_data::opml;
|
||||
use hammond_data::pipeline;
|
||||
use hammond_data::utils::checkup;
|
||||
use hammond_data::Source;
|
||||
use hammond_downloader::downloader;
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::mpsc::*;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Mutex, RwLock};
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
|
||||
use app::Action;
|
||||
|
||||
@@ -48,7 +48,7 @@ use app::Action;
|
||||
///
|
||||
/// let messages: Vec<Message> = Vec::new();
|
||||
/// let list = gtk::ListBox::new();
|
||||
/// let constructor = |m| { MessageWidget::new(m).0};
|
||||
/// let constructor = |m| MessageWidget::new(m).0;
|
||||
/// lazy_load(messages, list, constructor, || {});
|
||||
/// ```
|
||||
///
|
||||
@@ -188,10 +188,7 @@ fn refresh_feed<S>(source: Option<S>, sender: Sender<Action>) -> Result<(), Erro
|
||||
where
|
||||
S: IntoIterator<Item = Source> + Send + 'static,
|
||||
{
|
||||
sender
|
||||
.send(Action::HeaderBarShowUpdateIndicator)
|
||||
.map_err(|err| error!("Action Sender: {}", err))
|
||||
.ok();
|
||||
sender.send(Action::HeaderBarShowUpdateIndicator);
|
||||
|
||||
rayon::spawn(move || {
|
||||
if let Some(s) = source {
|
||||
@@ -209,14 +206,8 @@ where
|
||||
.ok();
|
||||
};
|
||||
|
||||
sender
|
||||
.send(Action::HeaderBarHideUpdateIndicator)
|
||||
.map_err(|err| error!("Action Sender: {}", err))
|
||||
.ok();
|
||||
sender
|
||||
.send(Action::RefreshAllViews)
|
||||
.map_err(|err| error!("Action Sender: {}", err))
|
||||
.ok();
|
||||
sender.send(Action::HeaderBarHideUpdateIndicator);
|
||||
sender.send(Action::RefreshAllViews);
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
@@ -235,15 +226,15 @@ lazy_static! {
|
||||
// GObjects do not implement Send trait, so SendCell is a way around that.
|
||||
// Also lazy_static requires Sync trait, so that's what the mutexes are.
|
||||
// TODO: maybe use something that would just scale to requested size?
|
||||
pub fn set_image_from_path(image: >k::Image, podcast_id: i32, size: u32) -> Result<(), Error> {
|
||||
pub fn set_image_from_path(image: >k::Image, show_id: i32, size: u32) -> Result<(), Error> {
|
||||
// Check if there's an active download about this show cover.
|
||||
// If there is, a callback will be set so this function will be called again.
|
||||
// If the download succedes, there should be a quick return from the pixbuf cache_image
|
||||
// If it fails another download will be scheduled.
|
||||
if let Ok(guard) = COVER_DL_REGISTRY.read() {
|
||||
if guard.contains(&podcast_id) {
|
||||
if guard.contains(&show_id) {
|
||||
let callback = clone!(image => move || {
|
||||
let _ = set_image_from_path(&image, podcast_id, size);
|
||||
let _ = set_image_from_path(&image, show_id, size);
|
||||
glib::Continue(false)
|
||||
});
|
||||
gtk::timeout_add(250, callback);
|
||||
@@ -254,7 +245,7 @@ pub fn set_image_from_path(image: >k::Image, podcast_id: i32, size: u32) -> Re
|
||||
if let Ok(hashmap) = CACHED_PIXBUFS.read() {
|
||||
// Check if the requested (cover + size) is already in the chache
|
||||
// and if so do an early return after that.
|
||||
if let Some(guard) = hashmap.get(&(podcast_id, size)) {
|
||||
if let Some(guard) = hashmap.get(&(show_id, size)) {
|
||||
guard
|
||||
.lock()
|
||||
.map_err(|err| format_err!("SendCell Mutex: {}", err))
|
||||
@@ -269,32 +260,25 @@ pub fn set_image_from_path(image: >k::Image, podcast_id: i32, size: u32) -> Re
|
||||
}
|
||||
}
|
||||
|
||||
let (sender, receiver) = channel();
|
||||
let (sender, receiver) = unbounded();
|
||||
THREADPOOL.spawn(move || {
|
||||
if let Ok(mut guard) = COVER_DL_REGISTRY.write() {
|
||||
guard.insert(podcast_id);
|
||||
}
|
||||
|
||||
if let Ok(pd) = dbqueries::get_podcast_cover_from_id(podcast_id) {
|
||||
sender
|
||||
.send(downloader::cache_image(&pd))
|
||||
.map_err(|err| error!("Action Sender: {}", err))
|
||||
.ok();
|
||||
}
|
||||
|
||||
if let Ok(mut guard) = COVER_DL_REGISTRY.write() {
|
||||
guard.remove(&podcast_id);
|
||||
guard.insert(show_id);
|
||||
if let Ok(pd) = dbqueries::get_podcast_cover_from_id(show_id) {
|
||||
sender.send(downloader::cache_image(&pd));
|
||||
}
|
||||
guard.remove(&show_id);
|
||||
}
|
||||
});
|
||||
|
||||
let image = image.clone();
|
||||
let s = size as i32;
|
||||
gtk::timeout_add(25, move || {
|
||||
if let Ok(path) = receiver.try_recv() {
|
||||
if let Some(path) = receiver.try_recv() {
|
||||
if let Ok(path) = path {
|
||||
if let Ok(px) = Pixbuf::new_from_file_at_scale(&path, s, s, true) {
|
||||
if let Ok(mut hashmap) = CACHED_PIXBUFS.write() {
|
||||
hashmap.insert((podcast_id, size), Mutex::new(SendCell::new(px.clone())));
|
||||
hashmap.insert((show_id, size), Mutex::new(SendCell::new(px.clone())));
|
||||
image.set_from_pixbuf(&px);
|
||||
}
|
||||
}
|
||||
@@ -333,6 +317,60 @@ fn lookup_id(id: u32) -> Result<String, Error> {
|
||||
.ok_or_else(|| format_err!("Failed to get url from itunes response"))
|
||||
}
|
||||
|
||||
pub fn on_import_clicked(window: >k::ApplicationWindow, sender: &Sender<Action>) {
|
||||
use glib::translate::ToGlib;
|
||||
use gtk::{FileChooserAction, FileChooserNative, FileFilter, ResponseType};
|
||||
|
||||
// let dialog = FileChooserDialog::new(title, Some(&window), FileChooserAction::Open);
|
||||
// TODO: It might be better to use a FileChooserNative widget.
|
||||
// Create the FileChooser Dialog
|
||||
let dialog = FileChooserNative::new(
|
||||
Some("Select the file from which to you want to Import Shows."),
|
||||
Some(window),
|
||||
FileChooserAction::Open,
|
||||
Some("_Import"),
|
||||
None,
|
||||
);
|
||||
|
||||
// Do not show hidden(.thing) files
|
||||
dialog.set_show_hidden(false);
|
||||
|
||||
// Set a filter to show only xml files
|
||||
let filter = FileFilter::new();
|
||||
FileFilterExt::set_name(&filter, Some("OPML file"));
|
||||
filter.add_mime_type("application/xml");
|
||||
filter.add_mime_type("text/xml");
|
||||
dialog.add_filter(&filter);
|
||||
|
||||
dialog.connect_response(clone!(sender => move |dialog, resp| {
|
||||
debug!("Dialong Response {}", resp);
|
||||
if resp == ResponseType::Accept.to_glib() {
|
||||
// TODO: Show an in-app notifictaion if the file can not be accessed
|
||||
if let Some(filename) = dialog.get_filename() {
|
||||
debug!("File selected: {:?}", filename);
|
||||
|
||||
rayon::spawn(clone!(sender => move || {
|
||||
// Parse the file and import the feeds
|
||||
if let Ok(sources) = opml::import_from_file(filename) {
|
||||
// Refresh the succesfully parsed feeds to index them
|
||||
refresh(Some(sources), sender)
|
||||
} else {
|
||||
let text = String::from("Failed to parse the Imported file");
|
||||
sender.send(Action::ErrorNotification(text));
|
||||
}
|
||||
}))
|
||||
} else {
|
||||
let text = String::from("Selected File could not be accessed.");
|
||||
sender.send(Action::ErrorNotification(text));
|
||||
}
|
||||
}
|
||||
|
||||
dialog.destroy();
|
||||
}));
|
||||
|
||||
dialog.run();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
// Totally copied it from fractal.
|
||||
// https://gitlab.gnome.org/danigm/fractal/blob/503e311e22b9d7540089d735b92af8e8f93560c5/fractal-gtk/src/app.rs#L1883-1912
|
||||
/// Given a `window` create and attach an `gtk::AboutDialog` to it.
|
||||
pub fn about_dialog(window: >k::ApplicationWindow) {
|
||||
// Feel free to add yourself if you contribured.
|
||||
let authors = &[
|
||||
"Constantin Nickel",
|
||||
"Gabriele Musco",
|
||||
"James Wykeham-Martin",
|
||||
"Jordan Petridis",
|
||||
"Julian Sparber",
|
||||
"Rowan Lewis",
|
||||
"Zander Brown",
|
||||
];
|
||||
|
||||
let dialog = gtk::AboutDialog::new();
|
||||
// Waiting for a logo.
|
||||
// dialog.set_logo_icon_name("org.gnome.Hammond");
|
||||
dialog.set_logo_icon_name("multimedia-player");
|
||||
dialog.set_comments("Podcast Client for the GNOME Desktop.");
|
||||
dialog.set_copyright("© 2017, 2018 Jordan Petridis");
|
||||
dialog.set_license_type(gtk::License::Gpl30);
|
||||
dialog.set_modal(true);
|
||||
// TODO: make it show it fetches the commit hash from which it was built
|
||||
// and the version number is kept in sync automaticly
|
||||
dialog.set_version("0.4.0");
|
||||
dialog.set_program_name("Hammond");
|
||||
// TODO: Need a wiki page first.
|
||||
// dialog.set_website("https://wiki.gnome.org/Design/Apps/Potential/Podcasts");
|
||||
// dialog.set_website_label("Learn more about Hammond");
|
||||
dialog.set_transient_for(window);
|
||||
|
||||
dialog.set_artists(&["Tobias Bernard"]);
|
||||
dialog.set_authors(authors);
|
||||
|
||||
dialog.connect_response(|dlg, _| dlg.destroy());
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
@@ -21,7 +21,7 @@ pub struct InAppNotification {
|
||||
|
||||
impl Default for InAppNotification {
|
||||
fn default() -> Self {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/inapp_notif.ui");
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/inapp_notif.ui");
|
||||
|
||||
let revealer: gtk::Revealer = builder.get_object("revealer").unwrap();
|
||||
let text: gtk::Label = builder.get_object("text").unwrap();
|
||||
@@ -7,7 +7,7 @@ pub struct EmptyView {
|
||||
|
||||
impl Default for EmptyView {
|
||||
fn default() -> Self {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/empty_view.ui");
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/empty_view.ui");
|
||||
let view: gtk::Box = builder.get_object("empty_view").unwrap();
|
||||
|
||||
EmptyView { container: view }
|
||||
|
||||
+405
-236
@@ -2,278 +2,458 @@ use glib;
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use chrono;
|
||||
use chrono::prelude::*;
|
||||
use crossbeam_channel::Sender;
|
||||
use failure::Error;
|
||||
use humansize::FileSize;
|
||||
use humansize::{file_size_opts as size_opts, FileSize};
|
||||
#[allow(unused_imports)]
|
||||
use open;
|
||||
use take_mut;
|
||||
|
||||
use hammond_data::dbqueries;
|
||||
use hammond_data::utils::get_download_folder;
|
||||
use hammond_data::EpisodeWidgetQuery;
|
||||
use hammond_data::EpisodeWidgetModel;
|
||||
|
||||
use app::Action;
|
||||
use manager;
|
||||
use widgets::episode_states::*;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::ops::DerefMut;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex, TryLockError};
|
||||
|
||||
#[derive(Debug)]
|
||||
lazy_static! {
|
||||
static ref SIZE_OPTS: Arc<size_opts::FileSizeOpts> = {
|
||||
// Declare a custom humansize option struct
|
||||
// See: https://docs.rs/humansize/1.0.2/humansize/file_size_opts/struct.FileSizeOpts.html
|
||||
Arc::new(size_opts::FileSizeOpts {
|
||||
divider: size_opts::Kilo::Binary,
|
||||
units: size_opts::Kilo::Decimal,
|
||||
decimal_places: 0,
|
||||
decimal_zeroes: 0,
|
||||
fixed_at: size_opts::FixedAt::No,
|
||||
long_units: false,
|
||||
space: true,
|
||||
suffix: "",
|
||||
allow_negative: false,
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct EpisodeWidget {
|
||||
pub container: gtk::Box,
|
||||
date: DateMachine,
|
||||
duration: DurationMachine,
|
||||
title: Rc<RefCell<TitleMachine>>,
|
||||
media: Rc<RefCell<MediaMachine>>,
|
||||
info: InfoLabels,
|
||||
buttons: Buttons,
|
||||
progressbar: gtk::ProgressBar,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct InfoLabels {
|
||||
container: gtk::Box,
|
||||
title: gtk::Label,
|
||||
date: gtk::Label,
|
||||
separator1: gtk::Label,
|
||||
duration: gtk::Label,
|
||||
separator2: gtk::Label,
|
||||
local_size: gtk::Label,
|
||||
size_separator: gtk::Label,
|
||||
total_size: gtk::Label,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Buttons {
|
||||
container: gtk::ButtonBox,
|
||||
play: gtk::Button,
|
||||
download: gtk::Button,
|
||||
cancel: gtk::Button,
|
||||
}
|
||||
|
||||
impl InfoLabels {
|
||||
fn init(&self, episode: &EpisodeWidgetModel) {
|
||||
// Set the title label state.
|
||||
self.set_title(episode);
|
||||
|
||||
// Set the date label.
|
||||
self.set_date(episode.epoch());
|
||||
|
||||
// Set the duaration label.
|
||||
self.set_duration(episode.duration());
|
||||
|
||||
// Set the total_size label.
|
||||
self.set_size(episode.length())
|
||||
}
|
||||
|
||||
fn set_title(&self, episode: &EpisodeWidgetModel) {
|
||||
self.title.set_text(episode.title());
|
||||
|
||||
if episode.played().is_some() {
|
||||
self.title
|
||||
.get_style_context()
|
||||
.map(|c| c.add_class("dim-label"));
|
||||
} else {
|
||||
self.title
|
||||
.get_style_context()
|
||||
.map(|c| c.remove_class("dim-label"));
|
||||
}
|
||||
}
|
||||
|
||||
// Set the date label of the episode widget.
|
||||
fn set_date(&self, epoch: i32) {
|
||||
lazy_static! {
|
||||
static ref NOW: DateTime<Utc> = Utc::now();
|
||||
};
|
||||
|
||||
let ts = Utc.timestamp(i64::from(epoch), 0);
|
||||
|
||||
// If the episode is from a different year, print year as well
|
||||
if NOW.year() != ts.year() {
|
||||
self.date.set_text(ts.format("%e %b %Y").to_string().trim());
|
||||
// Else omit the year from the label
|
||||
} else {
|
||||
self.date.set_text(ts.format("%e %b").to_string().trim());
|
||||
}
|
||||
}
|
||||
|
||||
// Set the duration label of the episode widget.
|
||||
fn set_duration(&self, seconds: Option<i32>) {
|
||||
// If lenght is provided
|
||||
if let Some(s) = seconds {
|
||||
// Convert seconds to minutes
|
||||
let minutes = chrono::Duration::seconds(s.into()).num_minutes();
|
||||
// If the lenght is 1 or more minutes
|
||||
if minutes != 0 {
|
||||
// Set the label and show them.
|
||||
self.duration.set_text(&format!("{} min", minutes));
|
||||
self.duration.show();
|
||||
self.separator1.show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Else hide the labels
|
||||
self.separator1.hide();
|
||||
self.duration.hide();
|
||||
}
|
||||
|
||||
// Set the size label of the episode widget.
|
||||
fn set_size(&self, bytes: Option<i32>) {
|
||||
// Convert the bytes to a String label
|
||||
let size = || -> Option<String> {
|
||||
let s = bytes?;
|
||||
if s == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
s.file_size(SIZE_OPTS.clone()).ok()
|
||||
};
|
||||
|
||||
if let Some(s) = size() {
|
||||
self.total_size.set_text(&s);
|
||||
self.total_size.show();
|
||||
self.separator2.show();
|
||||
} else {
|
||||
self.total_size.hide();
|
||||
self.separator2.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EpisodeWidget {
|
||||
fn default() -> Self {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episode_widget.ui");
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/episode_widget.ui");
|
||||
|
||||
let container: gtk::Box = builder.get_object("episode_container").unwrap();
|
||||
let progress: gtk::ProgressBar = builder.get_object("progress_bar").unwrap();
|
||||
let container = builder.get_object("episode_container").unwrap();
|
||||
let progressbar = builder.get_object("progress_bar").unwrap();
|
||||
|
||||
let download: gtk::Button = builder.get_object("download_button").unwrap();
|
||||
let play: gtk::Button = builder.get_object("play_button").unwrap();
|
||||
let cancel: gtk::Button = builder.get_object("cancel_button").unwrap();
|
||||
let buttons_container = builder.get_object("button_box").unwrap();
|
||||
let download = builder.get_object("download_button").unwrap();
|
||||
let play = builder.get_object("play_button").unwrap();
|
||||
let cancel = builder.get_object("cancel_button").unwrap();
|
||||
|
||||
let title: gtk::Label = builder.get_object("title_label").unwrap();
|
||||
let date: gtk::Label = builder.get_object("date_label").unwrap();
|
||||
let duration: gtk::Label = builder.get_object("duration_label").unwrap();
|
||||
let local_size: gtk::Label = builder.get_object("local_size").unwrap();
|
||||
let total_size: gtk::Label = builder.get_object("total_size").unwrap();
|
||||
let info_container = builder.get_object("info_container").unwrap();
|
||||
let title = builder.get_object("title_label").unwrap();
|
||||
let date = builder.get_object("date_label").unwrap();
|
||||
let duration = builder.get_object("duration_label").unwrap();
|
||||
let local_size = builder.get_object("local_size").unwrap();
|
||||
let total_size = builder.get_object("total_size").unwrap();
|
||||
|
||||
let separator1: gtk::Label = builder.get_object("separator1").unwrap();
|
||||
let separator2: gtk::Label = builder.get_object("separator2").unwrap();
|
||||
let prog_separator: gtk::Label = builder.get_object("prog_separator").unwrap();
|
||||
let separator1 = builder.get_object("separator1").unwrap();
|
||||
let separator2 = builder.get_object("separator2").unwrap();
|
||||
|
||||
let date_machine = DateMachine::new(date, 0);
|
||||
let dur_machine = DurationMachine::new(duration, separator1, None);
|
||||
let title_machine = Rc::new(RefCell::new(TitleMachine::new(title, false)));
|
||||
let media = MediaMachine::new(
|
||||
play,
|
||||
download,
|
||||
progress,
|
||||
cancel,
|
||||
total_size,
|
||||
local_size,
|
||||
separator2,
|
||||
prog_separator,
|
||||
);
|
||||
let media_machine = Rc::new(RefCell::new(media));
|
||||
let size_separator = builder.get_object("prog_separator").unwrap();
|
||||
|
||||
EpisodeWidget {
|
||||
info: InfoLabels {
|
||||
container: info_container,
|
||||
title,
|
||||
date,
|
||||
separator1,
|
||||
duration,
|
||||
separator2,
|
||||
local_size,
|
||||
total_size,
|
||||
size_separator,
|
||||
},
|
||||
buttons: Buttons {
|
||||
container: buttons_container,
|
||||
play,
|
||||
download,
|
||||
cancel,
|
||||
},
|
||||
progressbar,
|
||||
container,
|
||||
title: title_machine,
|
||||
duration: dur_machine,
|
||||
date: date_machine,
|
||||
media: media_machine,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EpisodeWidget {
|
||||
pub fn new(episode: EpisodeWidgetQuery, sender: &Sender<Action>) -> EpisodeWidget {
|
||||
let mut widget = EpisodeWidget::default();
|
||||
widget.init(episode, sender);
|
||||
pub fn new(episode: &EpisodeWidgetModel, sender: &Sender<Action>) -> Rc<Self> {
|
||||
let widget = Rc::new(Self::default());
|
||||
widget.info.init(episode);
|
||||
Self::determine_buttons_state(&widget, episode, sender)
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
widget
|
||||
}
|
||||
|
||||
fn init(&mut self, episode: EpisodeWidgetQuery, sender: &Sender<Action>) {
|
||||
// Set the date label.
|
||||
self.set_date(episode.epoch());
|
||||
// fn init(widget: Rc<Self>, sender: &Sender<Action>) {}
|
||||
|
||||
// Set the title label state.
|
||||
self.set_title(&episode);
|
||||
// InProgress State:
|
||||
// * Show ProgressBar and Cancel Button.
|
||||
// * Show `total_size`, `local_size` labels and `size_separator`.
|
||||
// * Hide Download and Play Buttons
|
||||
fn state_prog(&self) {
|
||||
self.progressbar.show();
|
||||
self.buttons.cancel.show();
|
||||
|
||||
// Set the duaration label.
|
||||
self.set_duration(episode.duration());
|
||||
self.info.total_size.show();
|
||||
self.info.local_size.show();
|
||||
self.info.size_separator.show();
|
||||
|
||||
// Determine what the state of the media widgets should be.
|
||||
determine_media_state(&self.media, &episode)
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.map_err(|_| error!("Could not determine Media State"))
|
||||
.ok();
|
||||
|
||||
let episode = Arc::new(Mutex::new(episode));
|
||||
self.connect_buttons(&episode, sender);
|
||||
self.buttons.play.hide();
|
||||
self.buttons.download.hide();
|
||||
}
|
||||
|
||||
fn connect_buttons(&self, episode: &Arc<Mutex<EpisodeWidgetQuery>>, sender: &Sender<Action>) {
|
||||
let title = self.title.clone();
|
||||
if let Ok(media) = self.media.try_borrow_mut() {
|
||||
media.play_connect_clicked(clone!(episode, sender => move |_| {
|
||||
if let Ok(mut ep) = episode.lock() {
|
||||
on_play_bttn_clicked(&mut ep, &title, &sender)
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
// Playable State:
|
||||
// * Hide ProgressBar and Cancel, Download Buttons.
|
||||
// * Hide `local_size` labels and `size_separator`.
|
||||
// * Show Play Button and `total_size` label
|
||||
fn state_playable(&self) {
|
||||
self.progressbar.hide();
|
||||
self.buttons.cancel.hide();
|
||||
self.buttons.download.hide();
|
||||
self.info.local_size.hide();
|
||||
self.info.size_separator.hide();
|
||||
|
||||
self.info.total_size.show();
|
||||
self.buttons.play.show();
|
||||
}
|
||||
|
||||
// ToDownload State:
|
||||
// * Hide ProgressBar and Cancel, Play Buttons.
|
||||
// * Hide `local_size` labels and `size_separator`.
|
||||
// * Show Download Button
|
||||
// * Determine `total_size` label state (Comes from `episode.lenght`).
|
||||
fn state_download(&self) {
|
||||
self.progressbar.hide();
|
||||
self.buttons.cancel.hide();
|
||||
self.buttons.play.hide();
|
||||
|
||||
self.info.local_size.hide();
|
||||
self.info.size_separator.hide();
|
||||
|
||||
self.buttons.download.show();
|
||||
}
|
||||
|
||||
fn update_progress(&self, local_size: &str, fraction: f64) {
|
||||
self.info.local_size.set_text(local_size);
|
||||
self.progressbar.set_fraction(fraction);
|
||||
}
|
||||
|
||||
/// Change the state of the `EpisodeWidget`.
|
||||
///
|
||||
/// Function Flowchart:
|
||||
///
|
||||
/// ------------------- --------------
|
||||
/// | Is the Episode | YES | State: |
|
||||
/// | currently being | ----> | InProgress |
|
||||
/// | downloaded? | | |
|
||||
/// ------------------- --------------
|
||||
/// |
|
||||
/// | NO
|
||||
/// |
|
||||
/// \_/
|
||||
/// ------------------- --------------
|
||||
/// | is the episode | YES | State: |
|
||||
/// | downloaded | ----> | Playable |
|
||||
/// | already? | | |
|
||||
/// ------------------- --------------
|
||||
/// |
|
||||
/// | NO
|
||||
/// |
|
||||
/// \_/
|
||||
/// -------------------
|
||||
/// | State: |
|
||||
/// | ToDownload |
|
||||
/// -------------------
|
||||
fn determine_buttons_state(
|
||||
widget: &Rc<Self>,
|
||||
episode: &EpisodeWidgetModel,
|
||||
sender: &Sender<Action>,
|
||||
) -> Result<(), Error> {
|
||||
// Reset the buttons state no matter the glade file.
|
||||
// This is just to make it easier to port to relm in the future.
|
||||
widget.buttons.cancel.hide();
|
||||
widget.buttons.play.hide();
|
||||
widget.buttons.download.hide();
|
||||
|
||||
// Check if the episode is being downloaded
|
||||
let id = episode.rowid();
|
||||
let active_dl = move || -> Result<Option<_>, Error> {
|
||||
let m = manager::ACTIVE_DOWNLOADS
|
||||
.read()
|
||||
.map_err(|_| format_err!("Failed to get a lock on the mutex."))?;
|
||||
|
||||
Ok(m.get(&id).cloned())
|
||||
};
|
||||
|
||||
// State: InProggress
|
||||
if let Some(prog) = active_dl()? {
|
||||
// set a callback that will update the state when the download finishes
|
||||
let callback = clone!(widget, sender => move || {
|
||||
if let Ok(guard) = manager::ACTIVE_DOWNLOADS.read() {
|
||||
if !guard.contains_key(&id) {
|
||||
if let Ok(ep) = dbqueries::get_episode_widget_from_rowid(id) {
|
||||
Self::determine_buttons_state(&widget, &ep, &sender)
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
|
||||
return glib::Continue(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glib::Continue(true)
|
||||
});
|
||||
gtk::timeout_add(250, callback);
|
||||
|
||||
// Wire the cancel button
|
||||
widget
|
||||
.buttons
|
||||
.cancel
|
||||
.connect_clicked(clone!(prog, widget, sender => move |_| {
|
||||
// Cancel the download
|
||||
if let Ok(mut m) = prog.lock() {
|
||||
m.cancel();
|
||||
}
|
||||
|
||||
// Cancel is not instant so we have to wait a bit
|
||||
timeout_add(50, clone!(widget, sender => move || {
|
||||
if let Ok(thing) = active_dl() {
|
||||
if thing.is_none() {
|
||||
// Recalculate the widget state
|
||||
dbqueries::get_episode_widget_from_rowid(id)
|
||||
.map_err(From::from)
|
||||
.and_then(|ep| Self::determine_buttons_state(&widget, &ep, &sender))
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
|
||||
return glib::Continue(false)
|
||||
}
|
||||
}
|
||||
|
||||
glib::Continue(true)
|
||||
}));
|
||||
}));
|
||||
|
||||
let media_machine = self.media.clone();
|
||||
media.download_connect_clicked(clone!(media_machine, episode, sender => move |dl| {
|
||||
// Setup a callback that will update the total_size label
|
||||
// with the http ContentLength header number rather than
|
||||
// relying to the RSS feed.
|
||||
update_total_size_callback(&widget, &prog);
|
||||
|
||||
// Setup a callback that will update the progress bar.
|
||||
update_progressbar_callback(&widget, &prog, id);
|
||||
|
||||
// Change the widget layout/state
|
||||
widget.state_prog();
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// State: Playable
|
||||
if episode.local_uri().is_some() {
|
||||
// Change the widget layout/state
|
||||
widget.state_playable();
|
||||
|
||||
// Wire the play button
|
||||
widget
|
||||
.buttons
|
||||
.play
|
||||
.connect_clicked(clone!(widget, sender => move |_| {
|
||||
if let Ok(mut ep) = dbqueries::get_episode_widget_from_rowid(id) {
|
||||
on_play_bttn_clicked(&widget, &mut ep, &sender)
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
}
|
||||
}));
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// State: ToDownload
|
||||
// Wire the download button
|
||||
widget
|
||||
.buttons
|
||||
.download
|
||||
.connect_clicked(clone!(widget, sender => move |dl| {
|
||||
// Make the button insensitive so it won't be pressed twice
|
||||
dl.set_sensitive(false);
|
||||
if let Ok(ep) = episode.lock() {
|
||||
if let Ok(ep) = dbqueries::get_episode_widget_from_rowid(id) {
|
||||
on_download_clicked(&ep, &sender)
|
||||
.and_then(|_| {
|
||||
info!("Donwload started succesfully.");
|
||||
determine_media_state(&media_machine, &ep)
|
||||
})
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.map_err(|_| error!("Could not determine Media State"))
|
||||
.ok();
|
||||
Self::determine_buttons_state(&widget, &ep, &sender)
|
||||
})
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
}
|
||||
|
||||
// Restore sensitivity after operations above complete
|
||||
dl.set_sensitive(true);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
/// Determine the title state.
|
||||
fn set_title(&mut self, episode: &EpisodeWidgetQuery) {
|
||||
let mut machine = self.title.borrow_mut();
|
||||
machine.set_title(episode.title());
|
||||
take_mut::take(machine.deref_mut(), |title| {
|
||||
title.determine_state(episode.played().is_some())
|
||||
});
|
||||
}
|
||||
// Change the widget state into `ToDownload`
|
||||
widget.state_download();
|
||||
|
||||
/// Set the date label depending on the current time.
|
||||
fn set_date(&mut self, epoch: i32) {
|
||||
let machine = &mut self.date;
|
||||
take_mut::take(machine, |date| date.determine_state(i64::from(epoch)));
|
||||
}
|
||||
|
||||
/// Set the duration label.
|
||||
fn set_duration(&mut self, seconds: Option<i32>) {
|
||||
let machine = &mut self.duration;
|
||||
take_mut::take(machine, |duration| duration.determine_state(seconds));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn determine_media_state(
|
||||
media_machine: &Rc<RefCell<MediaMachine>>,
|
||||
episode: &EpisodeWidgetQuery,
|
||||
) -> Result<(), Error> {
|
||||
let id = episode.rowid();
|
||||
let active_dl = || -> Result<Option<_>, Error> {
|
||||
let m = manager::ACTIVE_DOWNLOADS
|
||||
.read()
|
||||
.map_err(|_| format_err!("Failed to get a lock on the mutex."))?;
|
||||
|
||||
Ok(m.get(&id).cloned())
|
||||
}()?;
|
||||
|
||||
let mut lock = media_machine.try_borrow_mut()?;
|
||||
take_mut::take(lock.deref_mut(), |media| {
|
||||
media.determine_state(
|
||||
episode.length(),
|
||||
active_dl.is_some(),
|
||||
episode.local_uri().is_some(),
|
||||
)
|
||||
});
|
||||
|
||||
// Show or hide the play/delete/download buttons upon widget initialization.
|
||||
if let Some(prog) = active_dl {
|
||||
// set a callback that will update the state when the download finishes
|
||||
let id = episode.rowid();
|
||||
let callback = clone!(media_machine => move || {
|
||||
if let Ok(guard) = manager::ACTIVE_DOWNLOADS.read() {
|
||||
if !guard.contains_key(&id) {
|
||||
if let Ok(ep) = dbqueries::get_episode_widget_from_rowid(id) {
|
||||
determine_media_state(&media_machine, &ep)
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.map_err(|_| error!("Could not determine Media State"))
|
||||
.ok();
|
||||
|
||||
return glib::Continue(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glib::Continue(true)
|
||||
});
|
||||
gtk::timeout_add(250, callback);
|
||||
|
||||
lock.cancel_connect_clicked(clone!(prog, media_machine => move |_| {
|
||||
if let Ok(mut m) = prog.lock() {
|
||||
m.cancel();
|
||||
}
|
||||
|
||||
if let Ok(mut lock) = media_machine.try_borrow_mut() {
|
||||
if let Ok(episode) = dbqueries::get_episode_widget_from_rowid(id) {
|
||||
take_mut::take(lock.deref_mut(), |media| {
|
||||
media.determine_state(
|
||||
episode.length(),
|
||||
false,
|
||||
episode.local_uri().is_some(),
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
}));
|
||||
drop(lock);
|
||||
|
||||
// Setup a callback that will update the progress bar.
|
||||
update_progressbar_callback(&prog, &media_machine, id);
|
||||
|
||||
// Setup a callback that will update the total_size label
|
||||
// with the http ContentLength header number rather than
|
||||
// relying to the RSS feed.
|
||||
update_total_size_callback(&prog, &media_machine);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_download_clicked(ep: &EpisodeWidgetQuery, sender: &Sender<Action>) -> Result<(), Error> {
|
||||
let pd = dbqueries::get_podcast_from_id(ep.podcast_id())?;
|
||||
fn on_download_clicked(ep: &EpisodeWidgetModel, sender: &Sender<Action>) -> Result<(), Error> {
|
||||
let pd = dbqueries::get_podcast_from_id(ep.show_id())?;
|
||||
let download_fold = get_download_folder(&pd.title())?;
|
||||
|
||||
// Start a new download.
|
||||
manager::add(ep.rowid(), download_fold)?;
|
||||
|
||||
// Update Views
|
||||
sender.send(Action::RefreshEpisodesViewBGR)?;
|
||||
|
||||
sender.send(Action::RefreshEpisodesViewBGR);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_play_bttn_clicked(
|
||||
episode: &mut EpisodeWidgetQuery,
|
||||
title: &Rc<RefCell<TitleMachine>>,
|
||||
widget: &Rc<EpisodeWidget>,
|
||||
episode: &mut EpisodeWidgetModel,
|
||||
sender: &Sender<Action>,
|
||||
) -> Result<(), Error> {
|
||||
open_uri(episode.rowid())?;
|
||||
// Mark played
|
||||
episode.set_played_now()?;
|
||||
// Grey out the title
|
||||
widget.info.set_title(&episode);
|
||||
|
||||
let mut machine = title.try_borrow_mut()?;
|
||||
take_mut::take(machine.deref_mut(), |title| {
|
||||
title.determine_state(episode.played().is_some())
|
||||
});
|
||||
|
||||
sender.send(Action::RefreshEpisodesViewBGR)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn open_uri(rowid: i32) -> Result<(), Error> {
|
||||
let uri = dbqueries::get_episode_local_uri_from_id(rowid)?
|
||||
.ok_or_else(|| format_err!("Expected Some found None."))?;
|
||||
|
||||
if Path::new(&uri).exists() {
|
||||
info!("Opening {}", uri);
|
||||
open::that(&uri)?;
|
||||
} else {
|
||||
bail!("File \"{}\" does not exist.", uri);
|
||||
}
|
||||
|
||||
// Play the episode
|
||||
sender.send(Action::InitEpisode(episode.rowid()));
|
||||
// Refresh background views to match the normal/greyout title state
|
||||
sender.send(Action::RefreshEpisodesViewBGR);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -281,27 +461,27 @@ fn open_uri(rowid: i32) -> Result<(), Error> {
|
||||
#[inline]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
|
||||
fn update_progressbar_callback(
|
||||
widget: &Rc<EpisodeWidget>,
|
||||
prog: &Arc<Mutex<manager::Progress>>,
|
||||
media: &Rc<RefCell<MediaMachine>>,
|
||||
episode_rowid: i32,
|
||||
) {
|
||||
let callback = clone!(prog, media => move || {
|
||||
progress_bar_helper(&prog, &media, episode_rowid)
|
||||
let callback = clone!(widget, prog => move || {
|
||||
progress_bar_helper(&widget, &prog, episode_rowid)
|
||||
.unwrap_or(glib::Continue(false))
|
||||
});
|
||||
timeout_add(300, callback);
|
||||
timeout_add(100, callback);
|
||||
}
|
||||
|
||||
#[allow(if_same_then_else)]
|
||||
fn progress_bar_helper(
|
||||
widget: &Rc<EpisodeWidget>,
|
||||
prog: &Arc<Mutex<manager::Progress>>,
|
||||
media: &Rc<RefCell<MediaMachine>>,
|
||||
episode_rowid: i32,
|
||||
) -> Result<glib::Continue, Error> {
|
||||
let (fraction, downloaded) = {
|
||||
let m = prog.lock()
|
||||
.map_err(|_| format_err!("Failed to get a lock on the mutex."))?;
|
||||
(m.get_fraction(), m.get_downloaded())
|
||||
let (fraction, downloaded) = match prog.try_lock() {
|
||||
Ok(guard) => (guard.get_fraction(), guard.get_downloaded()),
|
||||
Err(TryLockError::WouldBlock) => return Ok(glib::Continue(true)),
|
||||
Err(TryLockError::Poisoned(_)) => return Err(format_err!("Progress Mutex is poisoned")),
|
||||
};
|
||||
|
||||
// I hate floating points.
|
||||
@@ -312,20 +492,16 @@ fn progress_bar_helper(
|
||||
.file_size(SIZE_OPTS.clone())
|
||||
.map_err(|err| format_err!("{}", err))?;
|
||||
|
||||
if let Ok(mut m) = media.try_borrow_mut() {
|
||||
m.update_progress(&size, fraction);
|
||||
}
|
||||
widget.update_progress(&size, fraction);
|
||||
}
|
||||
|
||||
// info!("Fraction: {}", progress_bar.get_fraction());
|
||||
// info!("Fraction: {}", fraction);
|
||||
|
||||
// Check if the download is still active
|
||||
let active = {
|
||||
let m = manager::ACTIVE_DOWNLOADS
|
||||
.read()
|
||||
.map_err(|_| format_err!("Failed to get a lock on the mutex."))?;
|
||||
m.contains_key(&episode_rowid)
|
||||
let active = match manager::ACTIVE_DOWNLOADS.read() {
|
||||
Ok(guard) => guard.contains_key(&episode_rowid),
|
||||
Err(_) => return Err(format_err!("Failed to get a lock on the mutex.")),
|
||||
};
|
||||
|
||||
if (fraction >= 1.0) && (!fraction.is_nan()) {
|
||||
@@ -341,35 +517,28 @@ fn progress_bar_helper(
|
||||
// with the http ContentLength header number rather than
|
||||
// relying to the RSS feed.
|
||||
#[inline]
|
||||
fn update_total_size_callback(
|
||||
prog: &Arc<Mutex<manager::Progress>>,
|
||||
media: &Rc<RefCell<MediaMachine>>,
|
||||
) {
|
||||
let callback = clone!(prog, media => move || {
|
||||
total_size_helper(&prog, &media).unwrap_or(glib::Continue(true))
|
||||
fn update_total_size_callback(widget: &Rc<EpisodeWidget>, prog: &Arc<Mutex<manager::Progress>>) {
|
||||
let callback = clone!(prog, widget => move || {
|
||||
total_size_helper(&widget, &prog).unwrap_or(glib::Continue(true))
|
||||
});
|
||||
timeout_add(500, callback);
|
||||
timeout_add(100, callback);
|
||||
}
|
||||
|
||||
fn total_size_helper(
|
||||
widget: &Rc<EpisodeWidget>,
|
||||
prog: &Arc<Mutex<manager::Progress>>,
|
||||
media: &Rc<RefCell<MediaMachine>>,
|
||||
) -> Result<glib::Continue, Error> {
|
||||
// Get the total_bytes.
|
||||
let total_bytes = {
|
||||
let m = prog.lock()
|
||||
.map_err(|_| format_err!("Failed to get a lock on the mutex."))?;
|
||||
m.get_total_size()
|
||||
let total_bytes = match prog.try_lock() {
|
||||
Ok(guard) => guard.get_total_size(),
|
||||
Err(TryLockError::WouldBlock) => return Ok(glib::Continue(true)),
|
||||
Err(TryLockError::Poisoned(_)) => return Err(format_err!("Progress Mutex is poisoned")),
|
||||
};
|
||||
|
||||
debug!("Total Size: {}", total_bytes);
|
||||
if total_bytes != 0 {
|
||||
// Update the total_size label
|
||||
if let Ok(mut m) = media.try_borrow_mut() {
|
||||
take_mut::take(m.deref_mut(), |machine| {
|
||||
machine.set_size(Some(total_bytes as i32))
|
||||
});
|
||||
}
|
||||
widget.info.set_size(Some(total_bytes as i32));
|
||||
|
||||
// Do not call again the callback
|
||||
Ok(glib::Continue(false))
|
||||
|
||||
@@ -1,879 +0,0 @@
|
||||
// TODO: Things that should be done.
|
||||
//
|
||||
// * Wherever there's a function that take 2 or more arguments of the same type,
|
||||
// eg: fn new(total_size: gtk::Label, local_size: gtk::Label ..)
|
||||
// Wrap the types into Struct-tuples and imple deref so it won't be possible to pass
|
||||
// the wrong argument to the wrong position.
|
||||
|
||||
use chrono;
|
||||
use glib;
|
||||
use gtk;
|
||||
|
||||
use chrono::prelude::*;
|
||||
use gtk::prelude::*;
|
||||
use humansize::{file_size_opts as size_opts, FileSize};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref SIZE_OPTS: Arc<size_opts::FileSizeOpts> = {
|
||||
// Declare a custom humansize option struct
|
||||
// See: https://docs.rs/humansize/1.0.2/humansize/file_size_opts/struct.FileSizeOpts.html
|
||||
Arc::new(size_opts::FileSizeOpts {
|
||||
divider: size_opts::Kilo::Binary,
|
||||
units: size_opts::Kilo::Decimal,
|
||||
decimal_places: 0,
|
||||
decimal_zeroes: 0,
|
||||
fixed_at: size_opts::FixedAt::No,
|
||||
long_units: false,
|
||||
space: true,
|
||||
suffix: "",
|
||||
allow_negative: false,
|
||||
})
|
||||
};
|
||||
|
||||
static ref NOW: DateTime<Utc> = Utc::now();
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UnInitialized;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Shown;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Hidden;
|
||||
|
||||
pub trait Visibility {}
|
||||
|
||||
impl Visibility for Shown {}
|
||||
impl Visibility for Hidden {}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Normal;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GreyedOut;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Title<S> {
|
||||
title: gtk::Label,
|
||||
state: S,
|
||||
}
|
||||
|
||||
impl<S> Title<S> {
|
||||
#[allow(unused_must_use)]
|
||||
// This does not need to be &mut since gtk-rs does not model ownership
|
||||
// But I think it wouldn't hurt if we treat it as a Rust api.
|
||||
fn set_title(&mut self, s: &str) {
|
||||
self.title.set_text(s);
|
||||
}
|
||||
}
|
||||
|
||||
impl Title<Normal> {
|
||||
fn new(title: gtk::Label) -> Self {
|
||||
Title {
|
||||
title,
|
||||
state: Normal {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Title<Normal>> for Title<GreyedOut> {
|
||||
fn from(f: Title<Normal>) -> Self {
|
||||
f.title
|
||||
.get_style_context()
|
||||
.map(|c| c.add_class("dim-label"));
|
||||
|
||||
Title {
|
||||
title: f.title,
|
||||
state: GreyedOut {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Title<GreyedOut>> for Title<Normal> {
|
||||
fn from(f: Title<GreyedOut>) -> Self {
|
||||
f.title
|
||||
.get_style_context()
|
||||
.map(|c| c.remove_class("dim-label"));
|
||||
|
||||
Title {
|
||||
title: f.title,
|
||||
state: Normal {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TitleMachine {
|
||||
Normal(Title<Normal>),
|
||||
GreyedOut(Title<GreyedOut>),
|
||||
}
|
||||
|
||||
impl TitleMachine {
|
||||
pub fn new(label: gtk::Label, is_played: bool) -> Self {
|
||||
let m = TitleMachine::Normal(Title::<Normal>::new(label));
|
||||
m.determine_state(is_played)
|
||||
}
|
||||
|
||||
pub fn determine_state(self, is_played: bool) -> Self {
|
||||
use self::TitleMachine::*;
|
||||
|
||||
match (self, is_played) {
|
||||
(title @ Normal(_), false) => title,
|
||||
(title @ GreyedOut(_), true) => title,
|
||||
(Normal(val), true) => GreyedOut(val.into()),
|
||||
(GreyedOut(val), false) => Normal(val.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_title(&mut self, s: &str) {
|
||||
use self::TitleMachine::*;
|
||||
|
||||
match *self {
|
||||
Normal(ref mut val) => val.set_title(s),
|
||||
GreyedOut(ref mut val) => val.set_title(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Usual;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct YearShown;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Date<S> {
|
||||
date: gtk::Label,
|
||||
epoch: i64,
|
||||
state: S,
|
||||
}
|
||||
|
||||
impl<S> Date<S> {
|
||||
fn into_usual(self, epoch: i64) -> Date<Usual> {
|
||||
let ts = Utc.timestamp(epoch, 0);
|
||||
self.date.set_text(ts.format("%e %b").to_string().trim());
|
||||
|
||||
Date {
|
||||
date: self.date,
|
||||
epoch: self.epoch,
|
||||
state: Usual {},
|
||||
}
|
||||
}
|
||||
|
||||
fn into_year_shown(self, epoch: i64) -> Date<YearShown> {
|
||||
let ts = Utc.timestamp(epoch, 0);
|
||||
self.date.set_text(ts.format("%e %b %Y").to_string().trim());
|
||||
|
||||
Date {
|
||||
date: self.date,
|
||||
epoch: self.epoch,
|
||||
state: YearShown {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Date<UnInitialized> {
|
||||
fn new(date: gtk::Label, epoch: i64) -> Self {
|
||||
let ts = Utc.timestamp(epoch, 0);
|
||||
date.set_text(ts.format("%e %b %Y").to_string().trim());
|
||||
|
||||
Date {
|
||||
date,
|
||||
epoch,
|
||||
state: UnInitialized {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum DateMachine {
|
||||
UnInitialized(Date<UnInitialized>),
|
||||
Usual(Date<Usual>),
|
||||
WithYear(Date<YearShown>),
|
||||
}
|
||||
|
||||
impl DateMachine {
|
||||
pub fn new(label: gtk::Label, epoch: i64) -> Self {
|
||||
let m = DateMachine::UnInitialized(Date::<UnInitialized>::new(label, epoch));
|
||||
m.determine_state(epoch)
|
||||
}
|
||||
|
||||
pub fn determine_state(self, epoch: i64) -> Self {
|
||||
use self::DateMachine::*;
|
||||
|
||||
let ts = Utc.timestamp(epoch, 0);
|
||||
let is_old = NOW.year() != ts.year();
|
||||
|
||||
match (self, is_old) {
|
||||
// Into Usual
|
||||
(Usual(val), false) => Usual(val.into_usual(epoch)),
|
||||
(WithYear(val), false) => Usual(val.into_usual(epoch)),
|
||||
(UnInitialized(val), false) => Usual(val.into_usual(epoch)),
|
||||
|
||||
// Into Year Shown
|
||||
(Usual(val), true) => WithYear(val.into_year_shown(epoch)),
|
||||
(WithYear(val), true) => WithYear(val.into_year_shown(epoch)),
|
||||
(UnInitialized(val), true) => WithYear(val.into_year_shown(epoch)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Duration<S: Visibility> {
|
||||
// TODO: make duration and separator diff types
|
||||
duration: gtk::Label,
|
||||
separator: gtk::Label,
|
||||
state: S,
|
||||
}
|
||||
|
||||
impl<S: Visibility> Duration<S> {
|
||||
// This needs a better name.
|
||||
// TODO: make me mut
|
||||
fn set_duration(&self, minutes: i64) {
|
||||
self.duration.set_text(&format!("{} min", minutes));
|
||||
}
|
||||
}
|
||||
|
||||
impl Duration<Hidden> {
|
||||
fn new(duration: gtk::Label, separator: gtk::Label) -> Self {
|
||||
duration.hide();
|
||||
separator.hide();
|
||||
|
||||
Duration {
|
||||
duration,
|
||||
separator,
|
||||
state: Hidden {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Duration<Hidden>> for Duration<Shown> {
|
||||
fn from(f: Duration<Hidden>) -> Self {
|
||||
f.duration.show();
|
||||
f.separator.show();
|
||||
|
||||
Duration {
|
||||
duration: f.duration,
|
||||
separator: f.separator,
|
||||
state: Shown {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Duration<Shown>> for Duration<Hidden> {
|
||||
fn from(f: Duration<Shown>) -> Self {
|
||||
f.duration.hide();
|
||||
f.separator.hide();
|
||||
|
||||
Duration {
|
||||
duration: f.duration,
|
||||
separator: f.separator,
|
||||
state: Hidden {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum DurationMachine {
|
||||
Hidden(Duration<Hidden>),
|
||||
Shown(Duration<Shown>),
|
||||
}
|
||||
|
||||
impl DurationMachine {
|
||||
pub fn new(duration: gtk::Label, separator: gtk::Label, seconds: Option<i32>) -> Self {
|
||||
let m = DurationMachine::Hidden(Duration::<Hidden>::new(duration, separator));
|
||||
m.determine_state(seconds)
|
||||
}
|
||||
|
||||
pub fn determine_state(self, seconds: Option<i32>) -> Self {
|
||||
match (self, seconds) {
|
||||
(d @ DurationMachine::Hidden(_), None) => d,
|
||||
(DurationMachine::Shown(val), None) => DurationMachine::Hidden(val.into()),
|
||||
(DurationMachine::Hidden(val), Some(s)) => {
|
||||
let minutes = chrono::Duration::seconds(s.into()).num_minutes();
|
||||
if minutes == 0 {
|
||||
DurationMachine::Hidden(val)
|
||||
} else {
|
||||
val.set_duration(minutes);
|
||||
DurationMachine::Shown(val.into())
|
||||
}
|
||||
}
|
||||
(DurationMachine::Shown(val), Some(s)) => {
|
||||
let minutes = chrono::Duration::seconds(s.into()).num_minutes();
|
||||
if minutes == 0 {
|
||||
DurationMachine::Hidden(val.into())
|
||||
} else {
|
||||
val.set_duration(minutes);
|
||||
DurationMachine::Shown(val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Size<S> {
|
||||
size: gtk::Label,
|
||||
separator: gtk::Label,
|
||||
state: S,
|
||||
}
|
||||
|
||||
impl<S> Size<S> {
|
||||
fn set_size(self, s: &str) -> Size<Shown> {
|
||||
self.size.set_text(s);
|
||||
self.size.show();
|
||||
self.separator.show();
|
||||
Size {
|
||||
size: self.size,
|
||||
separator: self.separator,
|
||||
state: Shown {},
|
||||
}
|
||||
}
|
||||
|
||||
// https://play.rust-lang.org/?gist=1acffaf62743eeb85be1ae6ecf474784&version=stable
|
||||
// It might be possible to make a generic definition with Specialization.
|
||||
// https://github.com/rust-lang/rust/issues/31844
|
||||
fn into_shown(self) -> Size<Shown> {
|
||||
self.size.show();
|
||||
self.separator.show();
|
||||
|
||||
Size {
|
||||
size: self.size,
|
||||
separator: self.separator,
|
||||
state: Shown {},
|
||||
}
|
||||
}
|
||||
|
||||
fn into_hidden(self) -> Size<Hidden> {
|
||||
self.size.hide();
|
||||
self.separator.hide();
|
||||
|
||||
Size {
|
||||
size: self.size,
|
||||
separator: self.separator,
|
||||
state: Hidden {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Size<UnInitialized> {
|
||||
fn new(size: gtk::Label, separator: gtk::Label) -> Self {
|
||||
size.hide();
|
||||
separator.hide();
|
||||
|
||||
Size {
|
||||
size,
|
||||
separator,
|
||||
state: UnInitialized {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pub trait Playable {}
|
||||
|
||||
// impl Playable for Download {}
|
||||
// impl Playable for Play {}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Download;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Play;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
// FIXME: Needs better name.
|
||||
// Should each button also has it's own type and machine?
|
||||
pub struct DownloadPlay<S> {
|
||||
play: gtk::Button,
|
||||
download: gtk::Button,
|
||||
state: S,
|
||||
}
|
||||
|
||||
impl<S> DownloadPlay<S> {
|
||||
// https://play.rust-lang.org/?gist=1acffaf62743eeb85be1ae6ecf474784&version=stable
|
||||
// It might be possible to make a generic definition with Specialization.
|
||||
// https://github.com/rust-lang/rust/issues/31844
|
||||
fn into_playable(self) -> DownloadPlay<Play> {
|
||||
self.play.show();
|
||||
self.download.hide();
|
||||
|
||||
DownloadPlay {
|
||||
play: self.play,
|
||||
download: self.download,
|
||||
state: Play {},
|
||||
}
|
||||
}
|
||||
|
||||
fn into_fetchable(self) -> DownloadPlay<Download> {
|
||||
self.play.hide();
|
||||
self.download.show();
|
||||
|
||||
DownloadPlay {
|
||||
play: self.play,
|
||||
download: self.download,
|
||||
state: Download {},
|
||||
}
|
||||
}
|
||||
|
||||
fn into_hidden(self) -> DownloadPlay<Hidden> {
|
||||
self.play.hide();
|
||||
self.download.hide();
|
||||
|
||||
DownloadPlay {
|
||||
play: self.play,
|
||||
download: self.download,
|
||||
state: Hidden {},
|
||||
}
|
||||
}
|
||||
|
||||
fn download_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> glib::SignalHandlerId {
|
||||
self.download.connect_clicked(f)
|
||||
}
|
||||
|
||||
fn play_connect_clicked<F: Fn(>k::Button) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||
self.play.connect_clicked(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl DownloadPlay<UnInitialized> {
|
||||
fn new(play: gtk::Button, download: gtk::Button) -> Self {
|
||||
play.hide();
|
||||
download.hide();
|
||||
|
||||
DownloadPlay {
|
||||
play,
|
||||
download,
|
||||
state: UnInitialized {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Progress<S> {
|
||||
bar: gtk::ProgressBar,
|
||||
cancel: gtk::Button,
|
||||
local_size: gtk::Label,
|
||||
prog_separator: gtk::Label,
|
||||
state: S,
|
||||
}
|
||||
|
||||
impl<S> Progress<S> {
|
||||
fn into_shown(self) -> Progress<Shown> {
|
||||
self.bar.show();
|
||||
self.cancel.show();
|
||||
self.local_size.show();
|
||||
self.prog_separator.show();
|
||||
|
||||
Progress {
|
||||
bar: self.bar,
|
||||
cancel: self.cancel,
|
||||
local_size: self.local_size,
|
||||
prog_separator: self.prog_separator,
|
||||
state: Shown {},
|
||||
}
|
||||
}
|
||||
|
||||
fn into_hidden(self) -> Progress<Hidden> {
|
||||
self.bar.hide();
|
||||
self.cancel.hide();
|
||||
self.local_size.hide();
|
||||
self.prog_separator.hide();
|
||||
|
||||
Progress {
|
||||
bar: self.bar,
|
||||
cancel: self.cancel,
|
||||
local_size: self.local_size,
|
||||
prog_separator: self.prog_separator,
|
||||
state: Hidden {},
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
// This does not need to be &mut since gtk-rs does not model ownership
|
||||
// But I think it wouldn't hurt if we treat it as a Rust api.
|
||||
fn update_progress(&mut self, local_size: &str, fraction: f64) {
|
||||
self.local_size.set_text(local_size);
|
||||
self.bar.set_fraction(fraction);
|
||||
}
|
||||
|
||||
fn cancel_connect_clicked<F: Fn(>k::Button) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||
self.cancel.connect_clicked(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Progress<UnInitialized> {
|
||||
fn new(
|
||||
bar: gtk::ProgressBar,
|
||||
cancel: gtk::Button,
|
||||
local_size: gtk::Label,
|
||||
prog_separator: gtk::Label,
|
||||
) -> Self {
|
||||
bar.hide();
|
||||
cancel.hide();
|
||||
local_size.hide();
|
||||
prog_separator.hide();
|
||||
|
||||
Progress {
|
||||
bar,
|
||||
cancel,
|
||||
local_size,
|
||||
prog_separator,
|
||||
state: UnInitialized {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Media<X, Y, Z> {
|
||||
dl: DownloadPlay<X>,
|
||||
size: Size<Y>,
|
||||
progress: Progress<Z>,
|
||||
}
|
||||
|
||||
type New<Y> = Media<Download, Y, Hidden>;
|
||||
type Playable<Y> = Media<Play, Y, Hidden>;
|
||||
type InProgress = Media<Hidden, Shown, Shown>;
|
||||
|
||||
impl<X, Y, Z> Media<X, Y, Z> {
|
||||
fn set_size(self, s: &str) -> Media<X, Shown, Z> {
|
||||
Media {
|
||||
dl: self.dl,
|
||||
size: self.size.set_size(s),
|
||||
progress: self.progress,
|
||||
}
|
||||
}
|
||||
|
||||
fn hide_size(self) -> Media<X, Hidden, Z> {
|
||||
Media {
|
||||
dl: self.dl,
|
||||
size: self.size.into_hidden(),
|
||||
progress: self.progress,
|
||||
}
|
||||
}
|
||||
|
||||
fn into_new(self, size: &str) -> New<Shown> {
|
||||
Media {
|
||||
dl: self.dl.into_fetchable(),
|
||||
size: self.size.set_size(size),
|
||||
progress: self.progress.into_hidden(),
|
||||
}
|
||||
}
|
||||
|
||||
fn into_new_without(self) -> New<Hidden> {
|
||||
Media {
|
||||
dl: self.dl.into_fetchable(),
|
||||
size: self.size.into_hidden(),
|
||||
progress: self.progress.into_hidden(),
|
||||
}
|
||||
}
|
||||
|
||||
fn into_playable(self, size: &str) -> Playable<Shown> {
|
||||
Media {
|
||||
dl: self.dl.into_playable(),
|
||||
size: self.size.set_size(size),
|
||||
progress: self.progress.into_hidden(),
|
||||
}
|
||||
}
|
||||
|
||||
fn into_playable_without(self) -> Playable<Hidden> {
|
||||
Media {
|
||||
dl: self.dl.into_playable(),
|
||||
size: self.size.into_hidden(),
|
||||
progress: self.progress.into_hidden(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<X, Z> Media<X, Shown, Z> {
|
||||
fn into_progress(self) -> InProgress {
|
||||
Media {
|
||||
dl: self.dl.into_hidden(),
|
||||
size: self.size.into_shown(),
|
||||
progress: self.progress.into_shown(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<X, Z> Media<X, Hidden, Z> {
|
||||
fn into_progress(self) -> InProgress {
|
||||
Media {
|
||||
dl: self.dl.into_hidden(),
|
||||
size: self.size.set_size("Unkown"),
|
||||
progress: self.progress.into_shown(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<X, Z> Media<X, UnInitialized, Z> {
|
||||
fn into_progress(self, size: Option<String>) -> InProgress {
|
||||
if let Some(s) = size {
|
||||
Media {
|
||||
dl: self.dl.into_hidden(),
|
||||
size: self.size.set_size(&s),
|
||||
progress: self.progress.into_shown(),
|
||||
}
|
||||
} else {
|
||||
Media {
|
||||
dl: self.dl.into_hidden(),
|
||||
size: self.size.set_size("Unkown"),
|
||||
progress: self.progress.into_shown(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InProgress {
|
||||
#[allow(unused_must_use)]
|
||||
// This does not need to be &mut since gtk-rs does not model ownership
|
||||
// But I think it wouldn't hurt if we treat it as a Rust api.
|
||||
fn update_progress(&mut self, local_size: &str, fraction: f64) {
|
||||
self.progress.update_progress(local_size, fraction)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ButtonsState {
|
||||
New(Media<Download, Shown, Hidden>),
|
||||
NewWithoutSize(Media<Download, Hidden, Hidden>),
|
||||
Playable(Media<Play, Shown, Hidden>),
|
||||
PlayableWithoutSize(Media<Play, Hidden, Hidden>),
|
||||
}
|
||||
|
||||
impl ButtonsState {
|
||||
pub fn determine_state(self, size: Option<String>, is_downloaded: bool) -> Self {
|
||||
use self::ButtonsState::*;
|
||||
|
||||
match (self, size, is_downloaded) {
|
||||
// From whatever to New
|
||||
(New(m), Some(s), false) => New(m.into_new(&s)),
|
||||
(Playable(m), Some(s), false) => New(m.into_new(&s)),
|
||||
|
||||
(NewWithoutSize(m), Some(s), false) => New(m.into_new(&s)),
|
||||
(PlayableWithoutSize(m), Some(s), false) => New(m.into_new(&s)),
|
||||
|
||||
// From whatever to Playable
|
||||
(New(m), Some(s), true) => Playable(m.into_playable(&s)),
|
||||
(Playable(m), Some(s), true) => Playable(m.into_playable(&s)),
|
||||
|
||||
(NewWithoutSize(m), Some(s), true) => Playable(m.into_playable(&s)),
|
||||
(PlayableWithoutSize(m), Some(s), true) => Playable(m.into_playable(&s)),
|
||||
|
||||
// From whatever to NewWithoutSize
|
||||
(New(m), None, false) => NewWithoutSize(m.hide_size()),
|
||||
(Playable(m), None, false) => NewWithoutSize(m.into_new_without()),
|
||||
|
||||
(b @ NewWithoutSize(_), None, false) => b,
|
||||
(PlayableWithoutSize(m), None, false) => NewWithoutSize(m.into_new_without()),
|
||||
|
||||
// From whatever to PlayableWithoutSize
|
||||
(New(m), None, true) => PlayableWithoutSize(m.into_playable_without()),
|
||||
(Playable(m), None, true) => PlayableWithoutSize(m.hide_size()),
|
||||
|
||||
(NewWithoutSize(val), None, true) => PlayableWithoutSize(val.into_playable_without()),
|
||||
(b @ PlayableWithoutSize(_), None, true) => b,
|
||||
}
|
||||
}
|
||||
|
||||
fn into_progress(self) -> InProgress {
|
||||
use self::ButtonsState::*;
|
||||
|
||||
match self {
|
||||
New(m) => m.into_progress(),
|
||||
Playable(m) => m.into_progress(),
|
||||
NewWithoutSize(m) => m.into_progress(),
|
||||
PlayableWithoutSize(m) => m.into_progress(),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_size(self, size: Option<String>) -> Self {
|
||||
use self::ButtonsState::*;
|
||||
|
||||
match (self, size) {
|
||||
(New(m), Some(s)) => New(m.set_size(&s)),
|
||||
(New(m), None) => NewWithoutSize(m.hide_size()),
|
||||
(Playable(m), Some(s)) => Playable(m.set_size(&s)),
|
||||
(Playable(m), None) => PlayableWithoutSize(m.hide_size()),
|
||||
(bttn @ NewWithoutSize(_), None) => bttn,
|
||||
(bttn @ PlayableWithoutSize(_), None) => bttn,
|
||||
(NewWithoutSize(m), Some(s)) => New(m.into_new(&s)),
|
||||
(PlayableWithoutSize(m), Some(s)) => Playable(m.into_playable(&s)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn download_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> glib::SignalHandlerId {
|
||||
use self::ButtonsState::*;
|
||||
|
||||
match *self {
|
||||
New(ref val) => val.dl.download_connect_clicked(f),
|
||||
NewWithoutSize(ref val) => val.dl.download_connect_clicked(f),
|
||||
Playable(ref val) => val.dl.download_connect_clicked(f),
|
||||
PlayableWithoutSize(ref val) => val.dl.download_connect_clicked(f),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn play_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> glib::SignalHandlerId {
|
||||
use self::ButtonsState::*;
|
||||
|
||||
match *self {
|
||||
New(ref val) => val.dl.play_connect_clicked(f),
|
||||
NewWithoutSize(ref val) => val.dl.play_connect_clicked(f),
|
||||
Playable(ref val) => val.dl.play_connect_clicked(f),
|
||||
PlayableWithoutSize(ref val) => val.dl.play_connect_clicked(f),
|
||||
}
|
||||
}
|
||||
|
||||
fn cancel_connect_clicked<F: Fn(>k::Button) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||
use self::ButtonsState::*;
|
||||
|
||||
match *self {
|
||||
New(ref val) => val.progress.cancel_connect_clicked(f),
|
||||
NewWithoutSize(ref val) => val.progress.cancel_connect_clicked(f),
|
||||
Playable(ref val) => val.progress.cancel_connect_clicked(f),
|
||||
PlayableWithoutSize(ref val) => val.progress.cancel_connect_clicked(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum MediaMachine {
|
||||
UnInitialized(Media<UnInitialized, UnInitialized, UnInitialized>),
|
||||
Initialized(ButtonsState),
|
||||
InProgress(Media<Hidden, Shown, Shown>),
|
||||
}
|
||||
|
||||
impl MediaMachine {
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
|
||||
pub fn new(
|
||||
play: gtk::Button,
|
||||
download: gtk::Button,
|
||||
bar: gtk::ProgressBar,
|
||||
cancel: gtk::Button,
|
||||
total_size: gtk::Label,
|
||||
local_size: gtk::Label,
|
||||
separator: gtk::Label,
|
||||
prog_separator: gtk::Label,
|
||||
) -> Self {
|
||||
let dl = DownloadPlay::<UnInitialized>::new(play, download);
|
||||
let progress = Progress::<UnInitialized>::new(bar, cancel, local_size, prog_separator);
|
||||
let size = Size::<UnInitialized>::new(total_size, separator);
|
||||
|
||||
MediaMachine::UnInitialized(Media { dl, progress, size })
|
||||
}
|
||||
|
||||
pub fn download_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> glib::SignalHandlerId {
|
||||
use self::MediaMachine::*;
|
||||
|
||||
match *self {
|
||||
UnInitialized(ref val) => val.dl.download_connect_clicked(f),
|
||||
Initialized(ref val) => val.download_connect_clicked(f),
|
||||
InProgress(ref val) => val.dl.download_connect_clicked(f),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn play_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> glib::SignalHandlerId {
|
||||
use self::MediaMachine::*;
|
||||
|
||||
match *self {
|
||||
UnInitialized(ref val) => val.dl.play_connect_clicked(f),
|
||||
Initialized(ref val) => val.play_connect_clicked(f),
|
||||
InProgress(ref val) => val.dl.play_connect_clicked(f),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cancel_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> glib::SignalHandlerId {
|
||||
use self::MediaMachine::*;
|
||||
|
||||
match *self {
|
||||
UnInitialized(ref val) => val.progress.cancel_connect_clicked(f),
|
||||
Initialized(ref val) => val.cancel_connect_clicked(f),
|
||||
InProgress(ref val) => val.progress.cancel_connect_clicked(f),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn determine_state(self, bytes: Option<i32>, is_active: bool, is_downloaded: bool) -> Self {
|
||||
use self::ButtonsState::*;
|
||||
use self::MediaMachine::*;
|
||||
|
||||
match (self, size_helper(bytes), is_downloaded, is_active) {
|
||||
(UnInitialized(m), s, _, true) => InProgress(m.into_progress(s)),
|
||||
|
||||
// Into New
|
||||
(UnInitialized(m), Some(s), false, false) => Initialized(New(m.into_new(&s))),
|
||||
(UnInitialized(m), None, false, false) => {
|
||||
Initialized(NewWithoutSize(m.into_new_without()))
|
||||
}
|
||||
|
||||
// Into Playable
|
||||
(UnInitialized(m), Some(s), true, false) => Initialized(Playable(m.into_playable(&s))),
|
||||
(UnInitialized(m), None, true, false) => {
|
||||
Initialized(PlayableWithoutSize(m.into_playable_without()))
|
||||
}
|
||||
|
||||
(Initialized(bttn), s, dl, false) => Initialized(bttn.determine_state(s, dl)),
|
||||
(Initialized(bttn), _, _, true) => InProgress(bttn.into_progress()),
|
||||
|
||||
// Into New
|
||||
(InProgress(m), Some(s), false, false) => Initialized(New(m.into_new(&s))),
|
||||
(InProgress(m), None, false, false) => {
|
||||
Initialized(NewWithoutSize(m.into_new_without()))
|
||||
}
|
||||
|
||||
// Into Playable
|
||||
(InProgress(m), Some(s), true, false) => Initialized(Playable(m.into_playable(&s))),
|
||||
(InProgress(m), None, true, false) => {
|
||||
Initialized(PlayableWithoutSize(m.into_playable_without()))
|
||||
}
|
||||
|
||||
(i @ InProgress(_), _, _, _) => i,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_size(self, bytes: Option<i32>) -> Self {
|
||||
use self::MediaMachine::*;
|
||||
let size = size_helper(bytes);
|
||||
|
||||
match (self, size) {
|
||||
(Initialized(bttn), s) => Initialized(bttn.set_size(s)),
|
||||
(InProgress(val), Some(s)) => InProgress(val.set_size(&s)),
|
||||
(n @ InProgress(_), None) => n,
|
||||
(n @ UnInitialized(_), _) => n,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_progress(&mut self, local_size: &str, fraction: f64) {
|
||||
use self::MediaMachine::*;
|
||||
|
||||
match *self {
|
||||
Initialized(_) => (),
|
||||
UnInitialized(_) => (),
|
||||
InProgress(ref mut val) => val.update_progress(local_size, fraction),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn size_helper(bytes: Option<i32>) -> Option<String> {
|
||||
let s = bytes?;
|
||||
if s == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
s.file_size(SIZE_OPTS.clone()).ok()
|
||||
}
|
||||
@@ -4,8 +4,9 @@ use failure::Error;
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use hammond_data::dbqueries;
|
||||
use hammond_data::EpisodeWidgetQuery;
|
||||
use hammond_data::EpisodeWidgetModel;
|
||||
use send_cell::SendCell;
|
||||
|
||||
use app::Action;
|
||||
@@ -13,7 +14,6 @@ use utils::{self, lazy_load_full};
|
||||
use widgets::EpisodeWidget;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static! {
|
||||
@@ -49,7 +49,7 @@ pub struct HomeView {
|
||||
|
||||
impl Default for HomeView {
|
||||
fn default() -> Self {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view.ui");
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/episodes_view.ui");
|
||||
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||
let scrolled_window: gtk::ScrolledWindow = builder.get_object("scrolled_window").unwrap();
|
||||
let frame_parent: gtk::Box = builder.get_object("frame_parent").unwrap();
|
||||
@@ -93,9 +93,9 @@ impl HomeView {
|
||||
let now_utc = Utc::now();
|
||||
|
||||
let view_ = view.clone();
|
||||
let func = move |ep: EpisodeWidgetQuery| {
|
||||
let func = move |ep: EpisodeWidgetModel| {
|
||||
let epoch = ep.epoch();
|
||||
let widget = HomeEpisode::new(ep, &sender);
|
||||
let widget = HomeEpisode::new(&ep, &sender);
|
||||
|
||||
match split(&now_utc, i64::from(epoch)) {
|
||||
Today => add_to_box(&widget, &view_.today_list, &view_.today_box),
|
||||
@@ -138,7 +138,8 @@ impl HomeView {
|
||||
/// Save the vertical scrollbar position.
|
||||
pub fn save_alignment(&self) -> Result<(), Error> {
|
||||
if let Ok(mut guard) = EPISODES_VIEW_VALIGNMENT.lock() {
|
||||
let adj = self.scrolled_window
|
||||
let adj = self
|
||||
.scrolled_window
|
||||
.get_vadjustment()
|
||||
.ok_or_else(|| format_err!("Could not get the adjustment"))?;
|
||||
*guard = Some(SendCell::new(adj));
|
||||
@@ -174,13 +175,14 @@ fn split(now: &DateTime<Utc>, epoch: i64) -> ListSplit {
|
||||
struct HomeEpisode {
|
||||
container: gtk::Box,
|
||||
image: gtk::Image,
|
||||
// FIXME: Change it to `EpisodeWidget` instead of a `Box`?
|
||||
episode: gtk::Box,
|
||||
}
|
||||
|
||||
impl Default for HomeEpisode {
|
||||
fn default() -> Self {
|
||||
let builder =
|
||||
gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view_widget.ui");
|
||||
gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/episodes_view_widget.ui");
|
||||
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||
let image: gtk::Image = builder.get_object("cover").unwrap();
|
||||
let ep = EpisodeWidget::default();
|
||||
@@ -195,33 +197,33 @@ impl Default for HomeEpisode {
|
||||
}
|
||||
|
||||
impl HomeEpisode {
|
||||
fn new(episode: EpisodeWidgetQuery, sender: &Sender<Action>) -> HomeEpisode {
|
||||
fn new(episode: &EpisodeWidgetModel, sender: &Sender<Action>) -> HomeEpisode {
|
||||
let builder =
|
||||
gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view_widget.ui");
|
||||
gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/episodes_view_widget.ui");
|
||||
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||
let image: gtk::Image = builder.get_object("cover").unwrap();
|
||||
let pid = episode.podcast_id();
|
||||
let pid = episode.show_id();
|
||||
let ep = EpisodeWidget::new(episode, sender);
|
||||
|
||||
let view = HomeEpisode {
|
||||
container,
|
||||
image,
|
||||
episode: ep.container,
|
||||
episode: ep.container.clone(),
|
||||
};
|
||||
|
||||
view.init(pid);
|
||||
view
|
||||
}
|
||||
|
||||
fn init(&self, podcast_id: i32) {
|
||||
self.set_cover(podcast_id)
|
||||
fn init(&self, show_id: i32) {
|
||||
self.set_cover(show_id)
|
||||
.map_err(|err| error!("Failed to set a cover: {}", err))
|
||||
.ok();
|
||||
|
||||
self.container.pack_start(&self.episode, true, true, 6);
|
||||
}
|
||||
|
||||
fn set_cover(&self, podcast_id: i32) -> Result<(), Error> {
|
||||
utils::set_image_from_path(&self.image, podcast_id, 64)
|
||||
fn set_cover(&self, show_id: i32) -> Result<(), Error> {
|
||||
utils::set_image_from_path(&self.image, show_id, 64)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
mod aboutdialog;
|
||||
pub mod appnotif;
|
||||
mod empty;
|
||||
mod episode;
|
||||
mod episode_states;
|
||||
mod home_view;
|
||||
pub mod player;
|
||||
mod show;
|
||||
mod shows_view;
|
||||
|
||||
pub use self::aboutdialog::about_dialog;
|
||||
pub use self::empty::EmptyView;
|
||||
pub use self::episode::EpisodeWidget;
|
||||
pub use self::home_view::HomeView;
|
||||
|
||||
@@ -0,0 +1,460 @@
|
||||
use gst::prelude::*;
|
||||
use gst::ClockTime;
|
||||
use gst_player;
|
||||
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use gio::{File, FileExt};
|
||||
use glib::SignalHandlerId;
|
||||
|
||||
use chrono::NaiveTime;
|
||||
use crossbeam_channel::Sender;
|
||||
use failure::Error;
|
||||
use send_cell::SendCell;
|
||||
|
||||
use hammond_data::{dbqueries, USER_AGENT};
|
||||
use hammond_data::{EpisodeWidgetModel, ShowCoverModel};
|
||||
|
||||
use app::Action;
|
||||
use utils::set_image_from_path;
|
||||
|
||||
use std::ops::Deref;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum SeekDirection {
|
||||
Backwards,
|
||||
Forward,
|
||||
}
|
||||
|
||||
trait PlayerExt {
|
||||
fn play(&self);
|
||||
fn pause(&self);
|
||||
fn stop(&self);
|
||||
fn seek(&self, offset: ClockTime, direction: SeekDirection);
|
||||
fn fast_forward(&self);
|
||||
fn rewind(&self);
|
||||
fn set_playback_rate(&self, f64);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct PlayerInfo {
|
||||
container: gtk::Box,
|
||||
show: gtk::Label,
|
||||
episode: gtk::Label,
|
||||
cover: gtk::Image,
|
||||
}
|
||||
|
||||
impl PlayerInfo {
|
||||
// FIXME: create a Diesel Model of the joined episode and podcast query instead
|
||||
fn init(&self, episode: &EpisodeWidgetModel, podcast: &ShowCoverModel) {
|
||||
self.set_cover_image(podcast);
|
||||
self.set_show_title(podcast);
|
||||
self.set_episode_title(episode);
|
||||
}
|
||||
|
||||
fn set_episode_title(&self, episode: &EpisodeWidgetModel) {
|
||||
self.episode.set_text(episode.title());
|
||||
self.episode.set_tooltip_text(episode.title());
|
||||
}
|
||||
|
||||
fn set_show_title(&self, show: &ShowCoverModel) {
|
||||
self.show.set_text(show.title());
|
||||
self.show.set_tooltip_text(show.title());
|
||||
}
|
||||
|
||||
fn set_cover_image(&self, show: &ShowCoverModel) {
|
||||
set_image_from_path(&self.cover, show.id(), 34)
|
||||
.map_err(|err| error!("Player Cover: {}", err))
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct PlayerTimes {
|
||||
container: gtk::Box,
|
||||
progressed: gtk::Label,
|
||||
duration: gtk::Label,
|
||||
separator: gtk::Label,
|
||||
slider: gtk::Scale,
|
||||
slider_update: Rc<SignalHandlerId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
struct Duration(ClockTime);
|
||||
|
||||
impl Deref for Duration {
|
||||
type Target = ClockTime;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
struct Position(ClockTime);
|
||||
|
||||
impl Deref for Position {
|
||||
type Target = ClockTime;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl PlayerTimes {
|
||||
/// Update the duration `gtk::Label` and the max range of the `gtk::SclaeBar`.
|
||||
pub fn on_duration_changed(&self, duration: Duration) {
|
||||
let seconds = duration.seconds().map(|v| v as f64).unwrap_or(0.0);
|
||||
|
||||
self.slider.block_signal(&self.slider_update);
|
||||
self.slider.set_range(0.0, seconds);
|
||||
self.slider.unblock_signal(&self.slider_update);
|
||||
|
||||
self.duration.set_text(&format_duration(seconds as u32));
|
||||
}
|
||||
|
||||
/// Update the `gtk::SclaeBar` when the pipeline position is changed.
|
||||
pub fn on_position_updated(&self, position: Position) {
|
||||
let seconds = position.seconds().map(|v| v as f64).unwrap_or(0.0);
|
||||
|
||||
self.slider.block_signal(&self.slider_update);
|
||||
self.slider.set_value(seconds);
|
||||
self.slider.unblock_signal(&self.slider_update);
|
||||
|
||||
self.progressed.set_text(&format_duration(seconds as u32));
|
||||
}
|
||||
}
|
||||
|
||||
fn format_duration(seconds: u32) -> String {
|
||||
let time = NaiveTime::from_num_seconds_from_midnight(seconds, 0);
|
||||
|
||||
if seconds >= 3600 {
|
||||
time.format("%T").to_string()
|
||||
} else {
|
||||
time.format("%M:%S").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct PlayerRate {
|
||||
radio150: gtk::RadioButton,
|
||||
radio125: gtk::RadioButton,
|
||||
radio_normal: gtk::RadioButton,
|
||||
popover: gtk::Popover,
|
||||
btn: gtk::MenuButton,
|
||||
label: gtk::Label,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct PlayerControls {
|
||||
container: gtk::Box,
|
||||
play: gtk::Button,
|
||||
pause: gtk::Button,
|
||||
forward: gtk::Button,
|
||||
rewind: gtk::Button,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PlayerWidget {
|
||||
pub action_bar: gtk::ActionBar,
|
||||
player: gst_player::Player,
|
||||
controls: PlayerControls,
|
||||
timer: PlayerTimes,
|
||||
info: PlayerInfo,
|
||||
rate: PlayerRate,
|
||||
}
|
||||
|
||||
impl Default for PlayerWidget {
|
||||
fn default() -> Self {
|
||||
let dispatcher = gst_player::PlayerGMainContextSignalDispatcher::new(None);
|
||||
let player = gst_player::Player::new(
|
||||
None,
|
||||
// Use the gtk main thread
|
||||
Some(&dispatcher.upcast::<gst_player::PlayerSignalDispatcher>()),
|
||||
);
|
||||
|
||||
let mut config = player.get_config();
|
||||
config.set_user_agent(USER_AGENT);
|
||||
config.set_position_update_interval(250);
|
||||
player.set_config(config).unwrap();
|
||||
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/player_toolbar.ui");
|
||||
let action_bar = builder.get_object("action_bar").unwrap();
|
||||
|
||||
let buttons = builder.get_object("buttons").unwrap();
|
||||
let play = builder.get_object("play_button").unwrap();
|
||||
let pause = builder.get_object("pause_button").unwrap();
|
||||
let forward = builder.get_object("ff_button").unwrap();
|
||||
let rewind = builder.get_object("rewind_button").unwrap();
|
||||
|
||||
let controls = PlayerControls {
|
||||
container: buttons,
|
||||
play,
|
||||
pause,
|
||||
forward,
|
||||
rewind,
|
||||
};
|
||||
|
||||
let timer_container = builder.get_object("timer").unwrap();
|
||||
let progressed = builder.get_object("progress_time_label").unwrap();
|
||||
let duration = builder.get_object("total_duration_label").unwrap();
|
||||
let separator = builder.get_object("separator").unwrap();
|
||||
let slider: gtk::Scale = builder.get_object("seek").unwrap();
|
||||
slider.set_range(0.0, 1.0);
|
||||
let slider_update = Rc::new(Self::connect_update_slider(&slider, &player));
|
||||
let timer = PlayerTimes {
|
||||
container: timer_container,
|
||||
progressed,
|
||||
duration,
|
||||
separator,
|
||||
slider,
|
||||
slider_update,
|
||||
};
|
||||
|
||||
let labels = builder.get_object("info").unwrap();
|
||||
let show = builder.get_object("show_label").unwrap();
|
||||
let episode = builder.get_object("episode_label").unwrap();
|
||||
let cover = builder.get_object("show_cover").unwrap();
|
||||
let info = PlayerInfo {
|
||||
container: labels,
|
||||
show,
|
||||
episode,
|
||||
cover,
|
||||
};
|
||||
|
||||
let radio150 = builder.get_object("rate_1_50").unwrap();
|
||||
let radio125 = builder.get_object("rate_1_25").unwrap();
|
||||
let radio_normal = builder.get_object("normal_rate").unwrap();
|
||||
let popover = builder.get_object("rate_popover").unwrap();
|
||||
let btn = builder.get_object("rate_button").unwrap();
|
||||
let label = builder.get_object("rate_label").unwrap();
|
||||
let rate = PlayerRate {
|
||||
radio150,
|
||||
radio125,
|
||||
radio_normal,
|
||||
popover,
|
||||
label,
|
||||
btn,
|
||||
};
|
||||
|
||||
PlayerWidget {
|
||||
player,
|
||||
action_bar,
|
||||
controls,
|
||||
timer,
|
||||
info,
|
||||
rate,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PlayerWidget {
|
||||
pub fn new(sender: &Sender<Action>) -> Rc<Self> {
|
||||
let w = Rc::new(Self::default());
|
||||
Self::init(&w, sender);
|
||||
w
|
||||
}
|
||||
|
||||
fn init(s: &Rc<Self>, sender: &Sender<Action>) {
|
||||
Self::connect_control_buttons(s);
|
||||
Self::connect_rate_buttons(s);
|
||||
Self::connect_gst_signals(s, sender);
|
||||
}
|
||||
|
||||
/// Connect the `PlayerControls` buttons to the `PlayerExt` methods.
|
||||
fn connect_control_buttons(s: &Rc<Self>) {
|
||||
let weak = Rc::downgrade(s);
|
||||
|
||||
// Connect the play button to the gst Player.
|
||||
s.controls.play.connect_clicked(clone!(weak => move |_| {
|
||||
weak.upgrade().map(|p| p.play());
|
||||
}));
|
||||
|
||||
// Connect the pause button to the gst Player.
|
||||
s.controls.pause.connect_clicked(clone!(weak => move |_| {
|
||||
weak.upgrade().map(|p| p.pause());
|
||||
}));
|
||||
|
||||
// Connect the rewind button to the gst Player.
|
||||
s.controls.rewind.connect_clicked(clone!(weak => move |_| {
|
||||
weak.upgrade().map(|p| p.rewind());
|
||||
}));
|
||||
|
||||
// Connect the fast-forward button to the gst Player.
|
||||
s.controls.forward.connect_clicked(clone!(weak => move |_| {
|
||||
weak.upgrade().map(|p| p.fast_forward());
|
||||
}));
|
||||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn connect_gst_signals(s: &Rc<Self>, sender: &Sender<Action>) {
|
||||
// Log gst warnings.
|
||||
s.player.connect_warning(move |_, warn| warn!("gst warning: {}", warn));
|
||||
|
||||
// Log gst errors.
|
||||
s.player.connect_error(clone!(sender => move |_, error| {
|
||||
// FIXME: should never occur and should not be user facing.
|
||||
sender.send(Action::ErrorNotification(format!("Player Error: {}", error)));
|
||||
}));
|
||||
|
||||
// The followign callbacks require `Send` but are handled by the gtk main loop
|
||||
let weak = SendCell::new(Rc::downgrade(s));
|
||||
|
||||
// Update the duration label and the slider
|
||||
s.player.connect_duration_changed(clone!(weak => move |_, clock| {
|
||||
weak.borrow()
|
||||
.upgrade()
|
||||
.map(|p| p.timer.on_duration_changed(Duration(clock)));
|
||||
}));
|
||||
|
||||
// Update the position label and the slider
|
||||
s.player.connect_position_updated(clone!(weak => move |_, clock| {
|
||||
weak.borrow()
|
||||
.upgrade()
|
||||
.map(|p| p.timer.on_position_updated(Position(clock)));
|
||||
}));
|
||||
|
||||
// Reset the slider to 0 and show a play button
|
||||
s.player.connect_end_of_stream(clone!(weak => move |_| {
|
||||
weak.borrow()
|
||||
.upgrade()
|
||||
.map(|p| p.stop());
|
||||
}));
|
||||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn connect_rate_buttons(s: &Rc<Self>) {
|
||||
let weak = Rc::downgrade(s);
|
||||
|
||||
s.rate
|
||||
.radio_normal
|
||||
.connect_toggled(clone!(weak => move |_| {
|
||||
weak.upgrade().map(|p| p.on_rate_changed(1.00));
|
||||
}));
|
||||
|
||||
s.rate
|
||||
.radio125
|
||||
.connect_toggled(clone!(weak => move |_| {
|
||||
weak.upgrade().map(|p| p.on_rate_changed(1.25));
|
||||
}));
|
||||
|
||||
s.rate
|
||||
.radio150
|
||||
.connect_toggled(clone!(weak => move |_| {
|
||||
weak.upgrade().map(|p| p.on_rate_changed(1.50));
|
||||
}));
|
||||
}
|
||||
|
||||
fn on_rate_changed(&self, rate: f64) {
|
||||
self.set_playback_rate(rate);
|
||||
self.rate.label.set_text(&format!("{:.2}x", rate));
|
||||
}
|
||||
|
||||
fn reveal(&self) {
|
||||
self.action_bar.show();
|
||||
}
|
||||
|
||||
pub fn initialize_episode(&self, rowid: i32) -> Result<(), Error> {
|
||||
let ep = dbqueries::get_episode_widget_from_rowid(rowid)?;
|
||||
let pd = dbqueries::get_podcast_cover_from_id(ep.show_id())?;
|
||||
|
||||
self.info.init(&ep, &pd);
|
||||
// Currently that will always be the case since the play button is
|
||||
// only shown if the file is downloaded
|
||||
if let Some(ref path) = ep.local_uri() {
|
||||
if Path::new(path).exists() {
|
||||
// path is an absolute fs path ex. "foo/bar/baz".
|
||||
// Convert it so it will have a "file:///"
|
||||
// FIXME: convert it properly
|
||||
if let Some(uri) = File::new_for_path(path).get_uri() {
|
||||
// play the file
|
||||
self.player.set_uri(&uri);
|
||||
self.play();
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
// TODO: log an error
|
||||
}
|
||||
|
||||
// FIXME: Stream stuff
|
||||
// unimplemented!()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn connect_update_slider(slider: >k::Scale, player: &gst_player::Player) -> SignalHandlerId {
|
||||
slider.connect_value_changed(clone!(player => move |slider| {
|
||||
let value = slider.get_value() as u64;
|
||||
player.seek(ClockTime::from_seconds(value));
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl PlayerExt for PlayerWidget {
|
||||
fn play(&self) {
|
||||
self.reveal();
|
||||
|
||||
self.controls.pause.show();
|
||||
self.controls.play.hide();
|
||||
|
||||
self.player.play();
|
||||
}
|
||||
|
||||
fn pause(&self) {
|
||||
self.controls.pause.hide();
|
||||
self.controls.play.show();
|
||||
|
||||
self.player.pause();
|
||||
|
||||
// Only rewind on pause if the stream position is passed a certain point.
|
||||
if let Some(sec) = self.player.get_position().seconds() {
|
||||
if sec >= 90 {
|
||||
self.seek(ClockTime::from_seconds(5), SeekDirection::Backwards);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn stop(&self) {
|
||||
self.controls.pause.hide();
|
||||
self.controls.play.show();
|
||||
|
||||
self.player.stop();
|
||||
|
||||
// Reset the slider bar to the start
|
||||
self.timer.on_position_updated(Position(ClockTime::from_seconds(0)));
|
||||
}
|
||||
|
||||
// Adapted from https://github.com/philn/glide/blob/b52a65d99daeab0b487f79a0e1ccfad0cd433e22/src/player_context.rs#L219-L245
|
||||
fn seek(&self, offset: ClockTime, direction: SeekDirection) {
|
||||
let position = self.player.get_position();
|
||||
if position.is_none() || offset.is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
let duration = self.player.get_duration();
|
||||
let destination = match direction {
|
||||
SeekDirection::Backwards if position >= offset => Some(position - offset),
|
||||
SeekDirection::Forward if !duration.is_none() && position + offset <= duration => {
|
||||
Some(position + offset)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
destination.map(|d| self.player.seek(d));
|
||||
}
|
||||
|
||||
// FIXME: make the interval a GSetting
|
||||
fn rewind(&self) {
|
||||
self.seek(ClockTime::from_seconds(10), SeekDirection::Backwards)
|
||||
}
|
||||
|
||||
// FIXME: make the interval a GSetting
|
||||
fn fast_forward(&self) {
|
||||
self.seek(ClockTime::from_seconds(10), SeekDirection::Forward)
|
||||
}
|
||||
|
||||
fn set_playback_rate(&self, rate: f64) {
|
||||
self.player.set_rate(rate);
|
||||
}
|
||||
}
|
||||
@@ -2,23 +2,23 @@ use glib;
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use failure::Error;
|
||||
use html2pango::markup_from_raw;
|
||||
use html2text;
|
||||
use open;
|
||||
use rayon;
|
||||
use send_cell::SendCell;
|
||||
|
||||
use hammond_data::dbqueries;
|
||||
use hammond_data::utils::delete_show;
|
||||
use hammond_data::Podcast;
|
||||
use hammond_data::Show;
|
||||
|
||||
use app::Action;
|
||||
use appnotif::{InAppNotification, UndoState};
|
||||
use utils::{self, lazy_load};
|
||||
use widgets::appnotif::{InAppNotification, UndoState};
|
||||
use widgets::EpisodeWidget;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::{SendError, Sender};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
lazy_static! {
|
||||
@@ -36,12 +36,12 @@ pub struct ShowWidget {
|
||||
settings: gtk::MenuButton,
|
||||
unsub: gtk::Button,
|
||||
episodes: gtk::ListBox,
|
||||
podcast_id: Option<i32>,
|
||||
show_id: Option<i32>,
|
||||
}
|
||||
|
||||
impl Default for ShowWidget {
|
||||
fn default() -> Self {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/show_widget.ui");
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/show_widget.ui");
|
||||
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||
let scrolled_window: gtk::ScrolledWindow = builder.get_object("scrolled_window").unwrap();
|
||||
let episodes = builder.get_object("episodes").unwrap();
|
||||
@@ -61,13 +61,13 @@ impl Default for ShowWidget {
|
||||
link,
|
||||
settings,
|
||||
episodes,
|
||||
podcast_id: None,
|
||||
show_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ShowWidget {
|
||||
pub fn new(pd: Arc<Podcast>, sender: Sender<Action>) -> Rc<ShowWidget> {
|
||||
pub fn new(pd: Arc<Show>, sender: Sender<Action>) -> Rc<ShowWidget> {
|
||||
let mut pdw = ShowWidget::default();
|
||||
pdw.init(&pd, &sender);
|
||||
let pdw = Rc::new(pdw);
|
||||
@@ -78,8 +78,8 @@ impl ShowWidget {
|
||||
pdw
|
||||
}
|
||||
|
||||
pub fn init(&mut self, pd: &Arc<Podcast>, sender: &Sender<Action>) {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/show_widget.ui");
|
||||
pub fn init(&mut self, pd: &Arc<Show>, sender: &Sender<Action>) {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/show_widget.ui");
|
||||
|
||||
self.unsub
|
||||
.connect_clicked(clone!(pd, sender => move |bttn| {
|
||||
@@ -87,7 +87,7 @@ impl ShowWidget {
|
||||
}));
|
||||
|
||||
self.set_description(pd.description());
|
||||
self.podcast_id = Some(pd.id());
|
||||
self.show_id = Some(pd.id());
|
||||
|
||||
self.set_cover(&pd)
|
||||
.map_err(|err| error!("Failed to set a cover: {}", err))
|
||||
@@ -118,19 +118,21 @@ impl ShowWidget {
|
||||
}
|
||||
|
||||
/// Set the show cover.
|
||||
fn set_cover(&self, pd: &Arc<Podcast>) -> Result<(), Error> {
|
||||
fn set_cover(&self, pd: &Arc<Show>) -> Result<(), Error> {
|
||||
utils::set_image_from_path(&self.cover, pd.id(), 256)
|
||||
}
|
||||
|
||||
/// Set the descripton text.
|
||||
fn set_description(&self, text: &str) {
|
||||
self.description.set_markup(&markup_from_raw(text));
|
||||
self.description
|
||||
.set_markup(&html2text::from_read(text.as_bytes(), 70));
|
||||
}
|
||||
|
||||
/// Save the scrollabar vajustment to the cache.
|
||||
pub fn save_vadjustment(&self, oldid: i32) -> Result<(), Error> {
|
||||
if let Ok(mut guard) = SHOW_WIDGET_VALIGNMENT.lock() {
|
||||
let adj = self.scrolled_window
|
||||
let adj = self
|
||||
.scrolled_window
|
||||
.get_vadjustment()
|
||||
.ok_or_else(|| format_err!("Could not get the adjustment"))?;
|
||||
*guard = Some((oldid, SendCell::new(adj)));
|
||||
@@ -141,7 +143,7 @@ impl ShowWidget {
|
||||
}
|
||||
|
||||
/// Set scrolled window vertical adjustment.
|
||||
fn set_vadjustment(&self, pd: &Arc<Podcast>) -> Result<(), Error> {
|
||||
fn set_vadjustment(&self, pd: &Arc<Show>) -> Result<(), Error> {
|
||||
let guard = SHOW_WIDGET_VALIGNMENT
|
||||
.lock()
|
||||
.map_err(|err| format_err!("Failed to lock widget align mutex: {}", err))?;
|
||||
@@ -164,19 +166,18 @@ impl ShowWidget {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn podcast_id(&self) -> Option<i32> {
|
||||
self.podcast_id
|
||||
pub fn show_id(&self) -> Option<i32> {
|
||||
self.show_id
|
||||
}
|
||||
}
|
||||
|
||||
/// Populate the listbox with the shows episodes.
|
||||
fn populate_listbox(
|
||||
show: &Rc<ShowWidget>,
|
||||
pd: Arc<Podcast>,
|
||||
pd: Arc<Show>,
|
||||
sender: Sender<Action>,
|
||||
) -> Result<(), Error> {
|
||||
use crossbeam_channel::bounded;
|
||||
use crossbeam_channel::TryRecvError::*;
|
||||
|
||||
let count = dbqueries::get_pd_episodes_count(&pd)?;
|
||||
|
||||
@@ -185,11 +186,11 @@ fn populate_listbox(
|
||||
let episodes = dbqueries::get_pd_episodeswidgets(&pd).unwrap();
|
||||
// The receiver can be dropped if there's an early return
|
||||
// like on show without episodes for example.
|
||||
sender_.send(episodes).ok();
|
||||
sender_.send(episodes);
|
||||
}));
|
||||
|
||||
if count == 0 {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/empty_show.ui");
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/empty_show.ui");
|
||||
let container: gtk::Box = builder.get_object("empty_show").unwrap();
|
||||
show.episodes.add(&container);
|
||||
return Ok(());
|
||||
@@ -198,15 +199,14 @@ fn populate_listbox(
|
||||
let show_ = show.clone();
|
||||
gtk::idle_add(move || {
|
||||
let episodes = match receiver.try_recv() {
|
||||
Ok(e) => e,
|
||||
Err(Empty) => return glib::Continue(true),
|
||||
Err(Disconnected) => return glib::Continue(false),
|
||||
Some(e) => e,
|
||||
None => return glib::Continue(true),
|
||||
};
|
||||
|
||||
let list = show_.episodes.clone();
|
||||
|
||||
let constructor = clone!(sender => move |ep| {
|
||||
EpisodeWidget::new(ep, &sender).container
|
||||
EpisodeWidget::new(&ep, &sender).container.clone()
|
||||
});
|
||||
|
||||
let callback = clone!(pd, show_ => move || {
|
||||
@@ -223,47 +223,41 @@ fn populate_listbox(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_unsub_button_clicked(pd: Arc<Podcast>, unsub_button: >k::Button, sender: &Sender<Action>) {
|
||||
fn on_unsub_button_clicked(pd: Arc<Show>, unsub_button: >k::Button, sender: &Sender<Action>) {
|
||||
// hack to get away without properly checking for none.
|
||||
// if pressed twice would panic.
|
||||
unsub_button.set_sensitive(false);
|
||||
|
||||
let wrap = || -> Result<(), SendError<_>> {
|
||||
sender.send(Action::RemoveShow(pd))?;
|
||||
sender.send(Action::RemoveShow(pd));
|
||||
|
||||
sender.send(Action::HeaderBarNormal)?;
|
||||
sender.send(Action::ShowShowsAnimated)?;
|
||||
// Queue a refresh after the switch to avoid blocking the db.
|
||||
sender.send(Action::RefreshShowsView)?;
|
||||
sender.send(Action::RefreshEpisodesView)?;
|
||||
Ok(())
|
||||
};
|
||||
sender.send(Action::HeaderBarNormal);
|
||||
sender.send(Action::ShowShowsAnimated);
|
||||
// Queue a refresh after the switch to avoid blocking the db.
|
||||
sender.send(Action::RefreshShowsView);
|
||||
sender.send(Action::RefreshEpisodesView);
|
||||
|
||||
wrap().map_err(|err| error!("Action Sender: {}", err)).ok();
|
||||
unsub_button.set_sensitive(true);
|
||||
}
|
||||
|
||||
fn on_played_button_clicked(pd: Arc<Podcast>, episodes: >k::ListBox, sender: &Sender<Action>) {
|
||||
fn on_played_button_clicked(pd: Arc<Show>, episodes: >k::ListBox, sender: &Sender<Action>) {
|
||||
if dim_titles(episodes).is_none() {
|
||||
error!("Something went horribly wrong when dimming the titles.");
|
||||
warn!("RUN WHILE YOU STILL CAN!");
|
||||
}
|
||||
|
||||
sender
|
||||
.send(Action::MarkAllPlayerNotification(pd))
|
||||
.map_err(|err| error!("Action Sender: {}", err))
|
||||
.ok();
|
||||
sender.send(Action::MarkAllPlayerNotification(pd))
|
||||
}
|
||||
|
||||
fn mark_all_watched(pd: &Podcast, sender: &Sender<Action>) -> Result<(), Error> {
|
||||
fn mark_all_watched(pd: &Show, sender: &Sender<Action>) -> Result<(), Error> {
|
||||
dbqueries::update_none_to_played_now(pd)?;
|
||||
// Not all widgets migth have been loaded when the mark_all is hit
|
||||
// So we will need to refresh again after it's done.
|
||||
sender.send(Action::RefreshWidgetIfSame(pd.id()))?;
|
||||
sender.send(Action::RefreshEpisodesView).map_err(From::from)
|
||||
sender.send(Action::RefreshWidgetIfSame(pd.id()));
|
||||
sender.send(Action::RefreshEpisodesView);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn mark_all_notif(pd: Arc<Podcast>, sender: &Sender<Action>) -> InAppNotification {
|
||||
pub fn mark_all_notif(pd: Arc<Show>, sender: &Sender<Action>) -> InAppNotification {
|
||||
let id = pd.id();
|
||||
let callback = clone!(sender => move || {
|
||||
mark_all_watched(&pd, &sender)
|
||||
@@ -272,17 +266,12 @@ pub fn mark_all_notif(pd: Arc<Podcast>, sender: &Sender<Action>) -> InAppNotific
|
||||
glib::Continue(false)
|
||||
});
|
||||
|
||||
let undo_callback = clone!(sender => move || {
|
||||
sender.send(Action::RefreshWidgetIfSame(id))
|
||||
.map_err(|err| error!("Action Sender: {}", err))
|
||||
.ok();
|
||||
});
|
||||
|
||||
let undo_callback = clone!(sender => move || sender.send(Action::RefreshWidgetIfSame(id)));
|
||||
let text = "Marked all episodes as listened";
|
||||
InAppNotification::new(text, callback, undo_callback, UndoState::Shown)
|
||||
}
|
||||
|
||||
pub fn remove_show_notif(pd: Arc<Podcast>, sender: Sender<Action>) -> InAppNotification {
|
||||
pub fn remove_show_notif(pd: Arc<Show>, sender: Sender<Action>) -> InAppNotification {
|
||||
let text = format!("Unsubscribed from {}", pd.title());
|
||||
|
||||
utils::ignore_show(pd.id())
|
||||
@@ -303,20 +292,17 @@ pub fn remove_show_notif(pd: Arc<Podcast>, sender: Sender<Action>) -> InAppNotif
|
||||
.map_err(|_| error!("Failed to delete {}", pd.title()))
|
||||
.ok();
|
||||
|
||||
sender.send(Action::RefreshEpisodesView).ok();
|
||||
sender.send(Action::RefreshEpisodesView);
|
||||
}));
|
||||
glib::Continue(false)
|
||||
});
|
||||
|
||||
let undo_wrap = move || -> Result<(), Error> {
|
||||
utils::uningore_show(pd.id())?;
|
||||
sender.send(Action::RefreshShowsView)?;
|
||||
sender.send(Action::RefreshEpisodesView)?;
|
||||
Ok(())
|
||||
};
|
||||
|
||||
let undo_callback = move || {
|
||||
undo_wrap().map_err(|err| error!("{}", err)).ok();
|
||||
utils::uningore_show(pd.id())
|
||||
.map_err(|err| error!("{}", err))
|
||||
.ok();
|
||||
sender.send(Action::RefreshShowsView);
|
||||
sender.send(Action::RefreshEpisodesView);
|
||||
};
|
||||
|
||||
InAppNotification::new(&text, callback, undo_callback, UndoState::Shown)
|
||||
@@ -338,8 +324,7 @@ fn dim_titles(episodes: >k::ListBox) -> Option<()> {
|
||||
.downcast::<gtk::Box>()
|
||||
.ok()?;
|
||||
let bar = foo.get_children().remove(0).downcast::<gtk::Box>().ok()?;
|
||||
let baz = bar.get_children().remove(0).downcast::<gtk::Box>().ok()?;
|
||||
let title = baz.get_children().remove(0).downcast::<gtk::Label>().ok()?;
|
||||
let title = bar.get_children().remove(0).downcast::<gtk::Label>().ok()?;
|
||||
|
||||
title.get_style_context().map(|c| c.add_class("dim-label"));
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use failure::Error;
|
||||
use send_cell::SendCell;
|
||||
|
||||
use hammond_data::dbqueries;
|
||||
use hammond_data::Podcast;
|
||||
use hammond_data::Show;
|
||||
|
||||
use app::Action;
|
||||
use utils::{self, get_ignored_shows, lazy_load, set_image_from_path};
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
@@ -28,7 +28,7 @@ pub struct ShowsView {
|
||||
|
||||
impl Default for ShowsView {
|
||||
fn default() -> Self {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_view.ui");
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/shows_view.ui");
|
||||
let container: gtk::Box = builder.get_object("fb_parent").unwrap();
|
||||
let scrolled_window: gtk::ScrolledWindow = builder.get_object("scrolled_window").unwrap();
|
||||
let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap();
|
||||
@@ -45,7 +45,7 @@ impl ShowsView {
|
||||
pub fn new(sender: Sender<Action>) -> Result<Rc<Self>, Error> {
|
||||
let pop = Rc::new(ShowsView::default());
|
||||
pop.init(sender);
|
||||
// Populate the flowbox with the Podcasts.
|
||||
// Populate the flowbox with the Shows.
|
||||
populate_flowbox(&pop)?;
|
||||
Ok(pop)
|
||||
}
|
||||
@@ -78,7 +78,8 @@ impl ShowsView {
|
||||
/// Save the vertical scrollbar position.
|
||||
pub fn save_alignment(&self) -> Result<(), Error> {
|
||||
if let Ok(mut guard) = SHOWS_VIEW_VALIGNMENT.lock() {
|
||||
let adj = self.scrolled_window
|
||||
let adj = self
|
||||
.scrolled_window
|
||||
.get_vadjustment()
|
||||
.ok_or_else(|| format_err!("Could not get the adjustment"))?;
|
||||
*guard = Some(SendCell::new(adj));
|
||||
@@ -114,9 +115,9 @@ fn on_child_activate(child: >k::FlowBoxChild, sender: &Sender<Action>) -> Resu
|
||||
.parse::<i32>()?;
|
||||
let pd = Arc::new(dbqueries::get_podcast_from_id(id)?);
|
||||
|
||||
sender.send(Action::HeaderBarShowTile(pd.title().into()))?;
|
||||
sender.send(Action::ReplaceWidget(pd))?;
|
||||
sender.send(Action::ShowWidgetAnimated)?;
|
||||
sender.send(Action::HeaderBarShowTile(pd.title().into()));
|
||||
sender.send(Action::ReplaceWidget(pd));
|
||||
sender.send(Action::ShowWidgetAnimated);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -129,7 +130,7 @@ struct ShowsChild {
|
||||
|
||||
impl Default for ShowsChild {
|
||||
fn default() -> Self {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_child.ui");
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/shows_child.ui");
|
||||
|
||||
let container: gtk::Box = builder.get_object("fb_child").unwrap();
|
||||
let cover: gtk::Image = builder.get_object("pd_cover").unwrap();
|
||||
@@ -146,13 +147,13 @@ impl Default for ShowsChild {
|
||||
}
|
||||
|
||||
impl ShowsChild {
|
||||
pub fn new(pd: &Podcast) -> ShowsChild {
|
||||
pub fn new(pd: &Show) -> ShowsChild {
|
||||
let child = ShowsChild::default();
|
||||
child.init(pd);
|
||||
child
|
||||
}
|
||||
|
||||
fn init(&self, pd: &Podcast) {
|
||||
fn init(&self, pd: &Show) {
|
||||
self.container.set_tooltip_text(pd.title());
|
||||
WidgetExt::set_name(&self.child, &pd.id().to_string());
|
||||
|
||||
@@ -161,7 +162,7 @@ impl ShowsChild {
|
||||
.ok();
|
||||
}
|
||||
|
||||
fn set_cover(&self, podcast_id: i32) -> Result<(), Error> {
|
||||
set_image_from_path(&self.cover, podcast_id, 256)
|
||||
fn set_cover(&self, show_id: i32) -> Result<(), Error> {
|
||||
set_image_from_path(&self.cover, show_id, 256)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
project(
|
||||
'hammond', 'rust',
|
||||
version: '0.3.3',
|
||||
version: '0.4.0',
|
||||
license: 'GPLv3',
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"app-id" : "org.gnome.Hammond",
|
||||
"runtime" : "org.gnome.Platform",
|
||||
"runtime-version" : "master",
|
||||
"runtime-version" : "3.28",
|
||||
"sdk" : "org.gnome.Sdk",
|
||||
"sdk-extensions" : [
|
||||
"org.freedesktop.Sdk.Extension.rust-stable"
|
||||
@@ -20,6 +20,7 @@
|
||||
"--share=ipc",
|
||||
"--socket=x11",
|
||||
"--socket=wayland",
|
||||
"--socket=pulseaudio",
|
||||
"--talk-name=org.freedesktop.Desktop"
|
||||
],
|
||||
"build-options" : {
|
||||
@@ -30,7 +31,7 @@
|
||||
"env" : {
|
||||
"CARGO_HOME" : "/run/build/Hammond/cargo",
|
||||
"RUST_BACKTRACE" : "1",
|
||||
"RUSTFLAGS" : "--cfg rayon_unstable"
|
||||
"DEBUG" : "true"
|
||||
}
|
||||
},
|
||||
"modules" : [
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
unstable_features = true
|
||||
verbose = false
|
||||
max_width = 100
|
||||
comment_width = 100
|
||||
wrap_comments = true
|
||||
tab_spaces = 4
|
||||
hard_tabs = false
|
||||
newline_style = "Unix"
|
||||
write_mode = "Overwrite"
|
||||
condense_wildcard_suffixes = false
|
||||
format_strings = true
|
||||
normalize_comments = true
|
||||
|
||||
+8
-1
@@ -3,4 +3,11 @@
|
||||
export CARGO_HOME=$1/target/cargo-home
|
||||
export RUSTFLAGS="--cfg rayon_unstable"
|
||||
|
||||
cargo build --release -p hammond-gtk && cp $1/target/release/hammond-gtk $2
|
||||
if [[ $DEBUG = true ]]
|
||||
then
|
||||
echo "DEBUG MODE"
|
||||
cargo build -p hammond-gtk && cp $1/target/debug/hammond-gtk $2
|
||||
else
|
||||
echo "RELEASE MODE"
|
||||
cargo build --release -p hammond-gtk && cp $1/target/release/hammond-gtk $2
|
||||
fi
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/sh
|
||||
|
||||
file="/.flatpak-info"
|
||||
if [ -f "$file" ]
|
||||
then
|
||||
# If you open a build terminal with gnome-builder
|
||||
source /usr/lib/sdk/rust-stable/enable.sh
|
||||
export CARGO_HOME=target/cargo-home/
|
||||
fi
|
||||
|
||||
export RUSTFLAGS="--cfg rayon_unstable"
|
||||
export RUSTBACKTRACE="1"
|
||||
|
||||
rustc --version
|
||||
cargo --version
|
||||
# cargo fmt --version
|
||||
|
||||
cargo build --all && \
|
||||
cargo test -- --test-threads=1 && \
|
||||
cargo test -- --test-threads=1 --ignored
|
||||
|
||||
# Rustfmt from the flatpak bundle tends to be outdated,
|
||||
# will probably get better when rustfmt stabilizes
|
||||
# cargo fmt --all -- --write-mode=diff
|
||||
|
||||
# cargo bench large
|
||||
Reference in New Issue
Block a user