Headerbar: Do not allow insertion of invalid urls.
This commit is contained in:
parent
d14973cf0d
commit
18e55e23ee
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -671,6 +671,7 @@ dependencies = [
|
|||||||
"open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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]]
|
[[package]]
|
||||||
|
|||||||
@ -1,14 +1,13 @@
|
|||||||
#![recursion_limit = "1024"]
|
#![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 = "cargo-clippy", allow(blacklisted_name))]
|
||||||
#![cfg_attr(feature = "clippy",
|
#![cfg_attr(feature = "clippy",
|
||||||
warn(option_unwrap_used, result_unwrap_used, print_stdout,
|
warn(option_unwrap_used, result_unwrap_used, print_stdout,
|
||||||
wrong_pub_self_convention, mut_mut, non_ascii_literal, similar_names,
|
wrong_pub_self_convention, mut_mut, non_ascii_literal, similar_names,
|
||||||
unicode_not_nfc, enum_glob_use, if_not_else, items_after_statements,
|
unicode_not_nfc, enum_glob_use, if_not_else, items_after_statements,
|
||||||
used_underscore_binding))]
|
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,
|
//! FIXME: Docs
|
||||||
//! into and from a Database.
|
|
||||||
|
|
||||||
#![allow(unknown_lints)]
|
#![allow(unknown_lints)]
|
||||||
#![deny(bad_style, const_err, dead_code, improper_ctypes, legacy_directory_ownership,
|
#![deny(bad_style, const_err, dead_code, improper_ctypes, legacy_directory_ownership,
|
||||||
@ -19,7 +18,6 @@
|
|||||||
unused_parens, while_true)]
|
unused_parens, while_true)]
|
||||||
#![deny(missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts)]
|
#![deny(missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts)]
|
||||||
#![deny(unused_extern_crates, unused)]
|
#![deny(unused_extern_crates, unused)]
|
||||||
#![deny(unused_extern_crates, unused)]
|
|
||||||
|
|
||||||
// #![feature(conservative_impl_trait)]
|
// #![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`.
|
/// Scan downloaded `episode` entries that might have broken `local_uri`s and set them to `None`.
|
||||||
fn download_checker() -> Result<()> {
|
fn download_checker() -> Result<()> {
|
||||||
let episodes = dbqueries::get_downloaded_episodes()?;
|
let mut episodes = dbqueries::get_downloaded_episodes()?;
|
||||||
|
|
||||||
episodes
|
episodes
|
||||||
.into_par_iter()
|
.par_iter_mut()
|
||||||
.filter(|ep| !Path::new(ep.local_uri().unwrap()).exists())
|
.filter(|ep| !Path::new(ep.local_uri().unwrap()).exists())
|
||||||
.for_each(|mut ep| {
|
.for_each(|ep| {
|
||||||
ep.set_local_uri(None);
|
ep.set_local_uri(None);
|
||||||
if let Err(err) = ep.save() {
|
if let Err(err) = ep.save() {
|
||||||
error!("Error while trying to update episode: {:#?}", ep);
|
error!("Error while trying to update episode: {:#?}", ep);
|
||||||
|
|||||||
@ -19,6 +19,7 @@ loggerv = "0.7.0"
|
|||||||
open = "1.2.1"
|
open = "1.2.1"
|
||||||
rayon = "0.9.0"
|
rayon = "0.9.0"
|
||||||
send-cell = "0.1.2"
|
send-cell = "0.1.2"
|
||||||
|
url = "1.6.0"
|
||||||
|
|
||||||
[dependencies.gtk]
|
[dependencies.gtk]
|
||||||
features = ["v3_22"]
|
features = ["v3_22"]
|
||||||
|
|||||||
@ -129,7 +129,7 @@ Tobias Bernard
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="already_subscribed_label">
|
<object class="GtkLabel" id="result_label">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="halign">start</property>
|
<property name="halign">start</property>
|
||||||
<property name="label" translatable="yes">You are already subscribed to that feed!</property>
|
<property name="label" translatable="yes">You are already subscribed to that feed!</property>
|
||||||
|
|||||||
@ -2,6 +2,7 @@ use gtk;
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
use hammond_data::Source;
|
use hammond_data::Source;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
@ -63,11 +64,12 @@ impl Header {
|
|||||||
let add_popover: gtk::Popover = builder.get_object("add_popover").unwrap();
|
let add_popover: gtk::Popover = builder.get_object("add_popover").unwrap();
|
||||||
let new_url: gtk::Entry = builder.get_object("new_url").unwrap();
|
let new_url: gtk::Entry = builder.get_object("new_url").unwrap();
|
||||||
let add_button: gtk::Button = builder.get_object("add_button").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());
|
self.switch.set_stack(&content.get_stack());
|
||||||
|
|
||||||
new_url.connect_changed(move |url| {
|
new_url.connect_changed(clone!(add_button => move |url| {
|
||||||
println!("{:?}", url.get_text());
|
on_url_change(url, &result_label, &add_button);
|
||||||
});
|
}));
|
||||||
|
|
||||||
add_button.connect_clicked(clone!(add_popover, new_url, sender => move |_| {
|
add_button.connect_clicked(clone!(add_popover, new_url, sender => move |_| {
|
||||||
on_add_bttn_clicked(&new_url, sender.clone());
|
on_add_bttn_clicked(&new_url, sender.clone());
|
||||||
@ -139,3 +141,24 @@ fn on_add_bttn_clicked(entry: >k::Entry, sender: Sender<Action>) {
|
|||||||
error!("Error: {:?}", source.unwrap_err());
|
error!("Error: {:?}", source.unwrap_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_url_change(entry: >k::Entry, result: >k::Label, add_button: >k::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 loggerv;
|
||||||
extern crate open;
|
extern crate open;
|
||||||
extern crate send_cell;
|
extern crate send_cell;
|
||||||
|
extern crate url;
|
||||||
// extern crate rayon;
|
// extern crate rayon;
|
||||||
|
|
||||||
// use rayon::prelude::*;
|
// use rayon::prelude::*;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user