Merge branch 'url-parsing' into 'master'
headerbar: Refactor 'add' styling after url parsing See merge request World/podcasts!119
This commit is contained in:
commit
c3351f01e4
@ -104,58 +104,63 @@ impl AddPopover {
|
|||||||
};
|
};
|
||||||
|
|
||||||
debug!("Url: {}", url);
|
debug!("Url: {}", url);
|
||||||
// TODO: refactor to avoid duplication
|
|
||||||
match Url::parse(&url) {
|
match Url::parse(&url) {
|
||||||
Ok(u) => {
|
Ok(u) => {
|
||||||
if !dbqueries::source_exists(u.as_str())? {
|
if !dbqueries::source_exists(u.as_str())? {
|
||||||
self.entry
|
self.style_neutral(true);
|
||||||
.get_style_context()
|
|
||||||
.remove_class(>k::STYLE_CLASS_ERROR);
|
|
||||||
self.entry
|
|
||||||
.set_icon_from_icon_name(gtk::EntryIconPosition::Secondary, None);
|
|
||||||
self.add.set_sensitive(true);
|
|
||||||
} else {
|
} else {
|
||||||
self.entry
|
self.style_error("You are already subscribed to this show");
|
||||||
.get_style_context()
|
|
||||||
.add_class(>k::STYLE_CLASS_ERROR);
|
|
||||||
self.entry.set_icon_from_icon_name(
|
|
||||||
gtk::EntryIconPosition::Secondary,
|
|
||||||
Some("dialog-error-symbolic"),
|
|
||||||
);
|
|
||||||
self.entry.set_icon_tooltip_text(
|
|
||||||
gtk::EntryIconPosition::Secondary,
|
|
||||||
Some(i18n("You are already subscribed to this show").as_str()),
|
|
||||||
);
|
|
||||||
self.add.set_sensitive(false);
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.add.set_sensitive(false);
|
|
||||||
if !is_input_url_empty {
|
if !is_input_url_empty {
|
||||||
self.entry
|
self.style_error("Invalid URL");
|
||||||
.get_style_context()
|
|
||||||
.add_class(>k::STYLE_CLASS_ERROR);
|
|
||||||
self.entry.set_icon_from_icon_name(
|
|
||||||
gtk::EntryIconPosition::Secondary,
|
|
||||||
Some("dialog-error-symbolic"),
|
|
||||||
);
|
|
||||||
self.entry.set_icon_tooltip_text(
|
|
||||||
gtk::EntryIconPosition::Secondary,
|
|
||||||
Some(i18n("Invalid URL").as_str()),
|
|
||||||
);
|
|
||||||
error!("Error: {}", err);
|
error!("Error: {}", err);
|
||||||
} else {
|
} else {
|
||||||
self.entry
|
self.style_neutral(false);
|
||||||
.get_style_context()
|
|
||||||
.remove_class(>k::STYLE_CLASS_ERROR);
|
|
||||||
self.entry
|
|
||||||
.set_icon_from_icon_name(gtk::EntryIconPosition::Secondary, None);
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn style_error(&self, icon_tooltip: &str) {
|
||||||
|
self.style(
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
Some("dialog-error-symbolic"),
|
||||||
|
Some(icon_tooltip),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn style_neutral(&self, sensitive: bool) {
|
||||||
|
self.style(false, sensitive, None, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn style(
|
||||||
|
&self,
|
||||||
|
error: bool,
|
||||||
|
sensitive: bool,
|
||||||
|
icon_name: Option<&str>,
|
||||||
|
icon_tooltip: Option<&str>,
|
||||||
|
) {
|
||||||
|
let entry = &self.entry;
|
||||||
|
let icon_position = gtk::EntryIconPosition::Secondary;
|
||||||
|
entry.set_icon_from_icon_name(icon_position, icon_name);
|
||||||
|
if let Some(icon_tooltip_text) = icon_tooltip {
|
||||||
|
entry.set_icon_tooltip_text(icon_position, Some(i18n(icon_tooltip_text).as_str()));
|
||||||
|
}
|
||||||
|
self.add.set_sensitive(sensitive);
|
||||||
|
|
||||||
|
let error_style_class = >k::STYLE_CLASS_ERROR;
|
||||||
|
let style_context = entry.get_style_context();
|
||||||
|
if error {
|
||||||
|
style_context.add_class(error_style_class);
|
||||||
|
} else {
|
||||||
|
style_context.remove_class(error_style_class);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Header {
|
impl Default for Header {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user