Commit Graph

154 Commits

Author SHA1 Message Date
Jordan Petridis
854581f0bf
Lazy_load: Use IntoIterator for T, instead of Iterator. 2018-04-06 22:56:44 +03:00
Jordan Petridis
c79a92f3b2
Lazy_load: accept an iterator instead a Vec<_> over T. 2018-04-06 22:37:40 +03:00
Jordan Petridis
4d6c3a67b1
Lazy_load: Avoid manually indexing.
make the data: Vec<T> mutable, then reverse the vector
so it can be used as a stack, and then use the ::pop()
method to retrieve the item.

This also avoid the constrain for Clone on T.
2018-04-06 22:37:36 +03:00
Jordan Petridis
83abb5a825
Move the lazy_load logic to a Generic function. 2018-04-06 22:37:33 +03:00
Jordan Petridis
d618771125 EpisodesListBox: Do not block while fetching episode backlog. 2018-04-06 17:06:14 +00:00
Jordan Petridis
45c9fd308d EpisodesListBox: Add each widget lazyly. 2018-04-06 17:06:14 +00:00
Jordan Petridis
0c00ee1320 ShowWidget: Initial Lazier evaluation of the widgets. 2018-04-06 17:06:13 +00:00
Jordan Petridis
370ba2d461
dlmanager: minor cleanup. 2018-04-04 21:36:23 +03:00
Jordan Petridis
f693c986ec
Add an empty_show if Show has no episodes. 2018-03-28 13:24:26 +03:00
Jordan Petridis
9f3a5a13b3
EpisodeWidget: Some RefCell are not really necessary. 2018-03-16 20:11:17 +02:00
Jordan Petridis
030fed6d12
EpisodeWidget: Just in case there was a deadlock. 2018-03-13 04:57:11 +02:00
Jordan Petridis
fc9579cd51
EpisodeWidget: Replace some Mutexs with RefCells.
The state machines are not send and the code is sequnecial.
We only need `&mut machine` refference to pass to `take_mut::take`
to change the state of the machine. In 2/3 cases we can even use
`.get_mut()` method and even avoid the dynamic borrow checks at
runtime. For the `TitleMachine` The only thing that will hold
a refference to it after initialization will be the play_button
callback. So it's justifiable to use `RefCell` insetead of a `Mutex`.
2018-03-13 04:44:06 +02:00
Jordan Petridis
74712b5410
EpisodeWidget: Remove unnecessary Arcs.
`DateMachine` and `DurationMachine` are only mutated during initialization
and thus do not need shared ownership.
`TitleMachine` is only mutated during initialization and after that only
the callback will keep holding a referrence to it. The `EpisodeWidget`s
get dropped after initialization. So it's justifiable to use `Rc<Mutex<T>>`
instead of `Arc`.
2018-03-13 03:47:46 +02:00
Jordan Petridis
2a6e0b0e07
Merge branch 'master' into state-machines-experiements 2018-02-22 12:14:55 +00:00
Jordan Petridis
c856b88008
EpisodeWidget: Add a Date state machine. 2018-02-19 18:14:34 +00:00
Jordan Petridis
ae25dd65bf
Cargo clippy and fmt. 2018-02-19 09:58:47 +00:00
Jordan Petridis
a88a1c5f1f
MediaMachine: Expose an interface to update the ProgressBar and local_size. 2018-02-17 19:49:43 +02:00
Jordan Petridis
0cd678cc1d
MediaMachine: Expose an interface to update total_size label. 2018-02-16 17:18:02 +02:00
Jordan Petridis
c9bf58af66
EpisodeWidget: Expose cancel button from the state machine. 2018-02-16 16:05:48 +02:00
Jordan Petridis
ed87a00225
EpisodeWidget: Cleanup parts of the state machine. 2018-02-16 14:43:16 +02:00
Jordan Petridis
bcc3608c04
EpisodeWidget: Split ButtonState enum from the MediaMachine.
Add a ButtonState Machine which represents the state of total_size
label, play button, and download button. Also implemented the
update/determine_state function for ButtonState.

Also implemented required generic functions for MediaMachine<X,Y,Z>
that convert it to the desired state.
2018-02-16 13:32:13 +02:00
Jordan Petridis
973d47ee05
EpisodeWidget: Expose the connect_clicked callbacks from the statemachine enum. 2018-02-15 18:07:21 +02:00
Jordan Petridis
f50c990d93
Yay, finally something that works. 2018-02-15 11:33:56 +02:00
Jordan Petridis
72eef6f104
Running in circles. 2018-02-15 11:08:21 +02:00
Jordan Petridis
4b8fceaa7d
Nothing makes sense. 2018-02-15 05:15:25 +02:00
Jordan Petridis
138cfdb68c
EpisodeWidget: use debug! instead of error! to avoid spamming stderr with *not actuall* errors. 2018-02-10 05:45:50 +02:00
Jordan Petridis
fc48ce9c47
EpisodeWidget: Migrate Duration Machine to use take mut too, and revert the api to require just &mut self. 2018-02-10 03:33:39 +02:00
Jordan Petridis
3a9a2f4033
EpisdoeWidget: Use take_mut crate to allow for a better api.
Currently it's required that you take mut self in order to manipulate
the internal state machines. This would not allow passing an Arc/Rc to
a callback since A/Rc<T> only derefs to &T and not T.

The take_mut crate allows the retrieval of ownership if you have a &mut refference
and as long you return T again. So Arc<Mutex<Machine> could work with
callbacks and embed Nested state machies without copying.
2018-02-10 03:15:12 +02:00
Jordan Petridis
f0ce0eb653
EpisodeWidget: Implement a state machine for duration label. 2018-02-09 10:12:37 +02:00
Jordan Petridis
23979b8f22
EpisodeWidget: Move state machine implementations into a separate module. 2018-02-09 09:13:41 +02:00
Jordan Petridis
e22a78fac6
EpisodeWidget: Re-enable on_play_bttn_clicked callback.
Before we were avoiding reloading the widget in view by
directly dimming the title label. Now instead we reload
the whole widget since I can't figure out a way to have
multiple Owneded refferences of the same state machine.
2018-02-09 08:59:50 +02:00
Jordan Petridis
7690cb1356
Remove code duplication using generics. 2018-02-09 08:43:47 +02:00
Jordan Petridis
a96f4c57c9
Probably the worst state machine implementation that was ever written. 2018-02-09 08:43:43 +02:00
Jordan Petridis
1135d77147
EpisodeWidget: Remove unwrap on that could occur if an invalid path was passed. 2018-02-08 21:10:36 +02:00
Jordan Petridis
9dfb18a487
EpisodeWidget: Minor refactor of set_total_size method. 2018-02-08 21:02:16 +02:00
Jordan Petridis
fbfa0de17e
EpisodeWidget: Fix minutes label parsing.
Before if a feed had reported a number between 1 and 60, a label 0 min
would be set.

This fixes that, while also using chrono::Duration for parsing minutes.
2018-02-08 20:39:37 +02:00
Jordan Petridis
4ba82c1515
EpisodeWidget: Set title alignment from glade. 2018-02-08 05:29:47 +02:00
Jordan Petridis
b172aa7aa3
Remove forgotten unwrap(). 2018-02-08 04:39:51 +02:00
Jordan Petridis
e2a1762af4
EpisodeWidget: Use refference counting intead of unnecessary clones.
Pass owenership of EpisodeWidgetQuery and use Atomic Ref counting
to pass to the callbacks. This should avoid extra allocations.
2018-02-07 18:40:22 +02:00
Jordan Petridis
1c84f0d721
hammond-gtk::manager: Switch the add function to return a Result<(), Error>. 2018-02-06 22:03:17 +02:00
Jordan Petridis
0dc16dab9a
EpisodeWidget: Refactor to return Result<T, Error> wherever possible. 2018-02-06 02:31:53 +02:00
Jordan Petridis
de43cae015
Switch rest stuff of data/downloader to Failure Crate. 2018-02-04 17:36:27 +02:00
Jordan Petridis
2f062afb07
Clippy suggestions 2018-01-29 19:09:53 +02:00
Jordan Petridis
a7e3b1b99e
GtkApplication: Headbar and Content constructors now return Self instead of Arc<Self>. 2018-01-26 19:05:19 +02:00
Jordan Petridis
574cfae5c6
rustfmt: enable reorder imports. 2018-01-17 08:57:02 +02:00
Jordan Petridis
8e367b7e86
Dont ask me how this is working. 2018-01-12 08:50:16 +02:00
Jordan Petridis
8a90de3c0e
Implement download cancel action. #24 2018-01-10 09:43:38 +02:00
Jordan Petridis
955845110b
Merge branch 'master' into 33-downloader-re-work 2018-01-09 12:06:38 +02:00
Jordan Petridis
0ba5e14d7f
EpisodeWidget: Only update if it's visible. 2018-01-09 10:10:54 +02:00
Jordan Petridis
ea70addbc6
Removed some unwrap()s. 2018-01-09 09:21:07 +02:00