Headerbar: Do not allow insertion of duplicate urls.
This commit is contained in:
parent
77a52bdc8c
commit
a4660a0700
@ -91,6 +91,7 @@ Tobias Bernard
|
|||||||
<object class="GtkButton" id="add_button">
|
<object class="GtkButton" id="add_button">
|
||||||
<property name="label" translatable="yes">Add</property>
|
<property name="label" translatable="yes">Add</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="sensitive">False</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">False</property>
|
<property name="receives_default">False</property>
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@ -2,6 +2,7 @@ use gtk;
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
use hammond_data::Source;
|
use hammond_data::Source;
|
||||||
|
use hammond_data::dbqueries;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -135,6 +136,7 @@ fn on_add_bttn_clicked(entry: >k::Entry, sender: Sender<Action>) {
|
|||||||
let source = Source::from_url(&url);
|
let source = Source::from_url(&url);
|
||||||
|
|
||||||
if source.is_ok() {
|
if source.is_ok() {
|
||||||
|
entry.set_text("");
|
||||||
sender.send(Action::UpdateSources(source.ok())).unwrap();
|
sender.send(Action::UpdateSources(source.ok())).unwrap();
|
||||||
} else {
|
} else {
|
||||||
error!("Something went wrong.");
|
error!("Something went wrong.");
|
||||||
@ -147,18 +149,28 @@ fn on_url_change(entry: >k::Entry, result: >k::Label, add_button: >k::Butt
|
|||||||
debug!("Url: {}", uri);
|
debug!("Url: {}", uri);
|
||||||
|
|
||||||
let url = Url::parse(&uri);
|
let url = Url::parse(&uri);
|
||||||
|
// TODO: refactor to avoid duplication
|
||||||
match url {
|
match url {
|
||||||
// TODO: Check if the url exists
|
Ok(u) => {
|
||||||
Ok(_u) => {
|
if !dbqueries::source_exists(u.as_str()).unwrap() {
|
||||||
add_button.set_sensitive(true);
|
add_button.set_sensitive(true);
|
||||||
result.hide();
|
result.hide();
|
||||||
|
result.set_label("");
|
||||||
|
} else {
|
||||||
|
add_button.set_sensitive(false);
|
||||||
|
result.set_label("Show already exists.");
|
||||||
|
result.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// TODO: refactor to avoid duplication
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
add_button.set_sensitive(false);
|
add_button.set_sensitive(false);
|
||||||
result.set_label("Invalid url.");
|
if !uri.is_empty() {
|
||||||
result.show();
|
result.set_label("Invalid url.");
|
||||||
error!("Error: {}", err);
|
result.show();
|
||||||
|
error!("Error: {}", err);
|
||||||
|
} else {
|
||||||
|
result.hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user