Verified Commit 18e55e23 authored by Jordan Petridis's avatar Jordan Petridis 🌱

Headerbar: Do not allow insertion of invalid urls.

parent d14973cf
......@@ -671,6 +671,7 @@ dependencies = [
"open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"send-cell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......
#![recursion_limit = "1024"]
#![cfg_attr(all(test, feature = "clippy"), allow(option_unwrap_used, result_unwrap_used))]
#![cfg_attr(feature = "cargo-clippy", allow(blacklisted_name))]
#![cfg_attr(feature = "clippy",
warn(option_unwrap_used, result_unwrap_used, print_stdout,
wrong_pub_self_convention, mut_mut, non_ascii_literal, similar_names,
unicode_not_nfc, enum_glob_use, if_not_else, items_after_statements,
used_underscore_binding))]
#![cfg_attr(all(test, feature = "clippy"), allow(option_unwrap_used, result_unwrap_used))]
//! A libraty for parsing, indexing and retrieving podcast Feeds,
//! into and from a Database.
//! FIXME: Docs
#![allow(unknown_lints)]
#![deny(bad_style, const_err, dead_code, improper_ctypes, legacy_directory_ownership,
......@@ -19,7 +18,6 @@
unused_parens, while_true)]
#![deny(missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts)]
#![deny(unused_extern_crates, unused)]
#![deny(unused_extern_crates, unused)]
// #![feature(conservative_impl_trait)]
......
......@@ -16,12 +16,12 @@ use std::path::Path;
/// Scan downloaded `episode` entries that might have broken `local_uri`s and set them to `None`.
fn download_checker() -> Result<()> {
let episodes = dbqueries::get_downloaded_episodes()?;
let mut episodes = dbqueries::get_downloaded_episodes()?;
episodes
.into_par_iter()
.par_iter_mut()
.filter(|ep| !Path::new(ep.local_uri().unwrap()).exists())
.for_each(|mut ep| {
.for_each(|ep| {
ep.set_local_uri(None);
if let Err(err) = ep.save() {
error!("Error while trying to update episode: {:#?}", ep);
......
......@@ -19,6 +19,7 @@ loggerv = "0.7.0"
open = "1.2.1"
rayon = "0.9.0"
send-cell = "0.1.2"
url = "1.6.0"
[dependencies.gtk]
features = ["v3_22"]
......
......@@ -129,7 +129,7 @@ Tobias Bernard
</packing>
</child>
<child>
<object class="GtkLabel" id="already_subscribed_label">
<object class="GtkLabel" id="result_label">
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">You are already subscribed to that feed!</property>
......
......@@ -2,6 +2,7 @@ use gtk;
use gtk::prelude::*;
use hammond_data::Source;
use url::Url;
use std::sync::Arc;
use std::sync::mpsc::Sender;
......@@ -63,11 +64,12 @@ impl Header {
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());
new_url.connect_changed(move |url| {
println!("{:?}", url.get_text());
});
new_url.connect_changed(clone!(add_button => move |url| {
on_url_change(url, &result_label, &add_button);
}));
add_button.connect_clicked(clone!(add_popover, new_url, sender => move |_| {
on_add_bttn_clicked(&new_url, sender.clone());
......@@ -139,3 +141,24 @@ fn on_add_bttn_clicked(entry: &gtk::Entry, sender: Sender<Action>) {
error!("Error: {:?}", source.unwrap_err());
}
}
fn on_url_change(entry: &gtk::Entry, result: &gtk::Label, add_button: &gtk::Button) {
let uri = entry.get_text().unwrap();
debug!("Url: {}", uri);
let url = Url::parse(&uri);
match url {
// TODO: Check if the url exists
Ok(_u) => {
add_button.set_sensitive(true);
result.hide();
}
// TODO: refactor to avoid duplication
Err(err) => {
add_button.set_sensitive(false);
result.set_label("Invalid url.");
result.show();
error!("Error: {}", err);
}
}
}
......@@ -19,6 +19,7 @@ extern crate log;
extern crate loggerv;
extern crate open;
extern crate send_cell;
extern crate url;
// extern crate rayon;
// use rayon::prelude::*;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment