podcasts-gtk: Use libdazzle to set CSS per-theme

Allows us to set custom CSS by theme. This means
we can special case for HighContrast, Adwaita-dark,
etc.

Fixes https://gitlab.gnome.org/World/podcasts/issues/69
This commit is contained in:
Christopher Davis 2019-04-25 22:34:38 -04:00
parent 53f29b57a5
commit 5595eef623
8 changed files with 127 additions and 1 deletions

46
Cargo.lock generated
View File

@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]] [[package]]
name = "MacTypes-sys" name = "MacTypes-sys"
version = "2.1.0" version = "2.1.0"
@ -1022,6 +1024,47 @@ name = "libc"
version = "0.2.51" version = "0.2.51"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libdazzle"
version = "0.1.0"
source = "git+https://gitlab.gnome.org/BrainBlasted/libdazzle-rs.git#34658913affed0e4610575f884ad7ab6357ef69b"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"cairo-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gtk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gtk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"libdazzle-sys 0.1.0 (git+https://gitlab.gnome.org/BrainBlasted/libdazzle-rs.git)",
"pango 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libdazzle-sys"
version = "0.1.0"
source = "git+https://gitlab.gnome.org/BrainBlasted/libdazzle-rs.git#34658913affed0e4610575f884ad7ab6357ef69b"
dependencies = [
"cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gtk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "libdbus-sys" name = "libdbus-sys"
version = "0.1.5" version = "0.1.5"
@ -1570,6 +1613,7 @@ dependencies = [
"html2text 0.1.8 (git+https://github.com/jugglerchris/rust-html2text)", "html2text 0.1.8 (git+https://github.com/jugglerchris/rust-html2text)",
"humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libdazzle 0.1.0 (git+https://gitlab.gnome.org/BrainBlasted/libdazzle-rs.git)",
"libhandy 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libhandy 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"loggerv 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "loggerv 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2652,6 +2696,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917"
"checksum libdazzle 0.1.0 (git+https://gitlab.gnome.org/BrainBlasted/libdazzle-rs.git)" = "<none>"
"checksum libdazzle-sys 0.1.0 (git+https://gitlab.gnome.org/BrainBlasted/libdazzle-rs.git)" = "<none>"
"checksum libdbus-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "18cb88963258d00f4962205dbb5933d82780d9962c8c8a064b651d2ad7189210" "checksum libdbus-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "18cb88963258d00f4962205dbb5933d82780d9962c8c8a064b651d2ad7189210"
"checksum libhandy 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9f1fd41f2216fc3894257f4b4405dec7255977ff3a292df1ec1a74bc1700178d" "checksum libhandy 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9f1fd41f2216fc3894257f4b4405dec7255977ff3a292df1ec1a74bc1700178d"
"checksum libhandy-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d1a46914f15afb94df8efddd8d451f60764da95a63dc4f7f3526ce71e1ef775" "checksum libhandy-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d1a46914f15afb94df8efddd8d451f60764da95a63dc4f7f3526ce71e1ef775"

View File

@ -60,6 +60,21 @@
} }
] ]
}, },
{
"name" : "libdazzle",
"buildsystem" : "meson",
"cleanup" : [
"/include",
"/lib/pkgconfig"
],
"sources" : [
{
"type" : "git",
"url" : "https://gitlab.gnome.org/GNOME/libdazzle.git",
"branch" : "libdazzle-3-32"
}
]
},
{ {
"name" : "gnome-podcasts", "name" : "gnome-podcasts",
"buildsystem" : "meson", "buildsystem" : "meson",

View File

@ -41,6 +41,11 @@ version = "0.6.0"
features = ["v2_50"] features = ["v2_50"]
version = "0.6.0" version = "0.6.0"
[dependencies.libdazzle]
version = "0.1.0"
git = "https://gitlab.gnome.org/BrainBlasted/libdazzle-rs.git"
features = ["v3_26"]
[dependencies.libhandy] [dependencies.libhandy]
version = "0.3.0" version = "0.3.0"
features = [ "v0_0_7"] features = [ "v0_0_7"]

View File

@ -16,5 +16,7 @@
<file compressed="true" preprocess="xml-stripblanks">icons/skip-forward-symbolic.svg</file> <file compressed="true" preprocess="xml-stripblanks">icons/skip-forward-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">gtk/prefs.ui</file> <file compressed="true" preprocess="xml-stripblanks">gtk/prefs.ui</file>
<file compressed="true">gtk/style.css</file> <file compressed="true">gtk/style.css</file>
<file compressed="true">themes/Adwaita.css</file>
<file compressed="true">themes/HighContrast.css</file>
</gresource> </gresource>
</gresources> </gresources>

View File

@ -0,0 +1,4 @@
.played {
/* Needed to reset the styling */
background: none;
}

View File

@ -0,0 +1,9 @@
.played {
background: repeating-linear-gradient(
-45deg,
mix(lightgrey, @theme_bg_color, 0.3),
mix(lightgrey, @theme_bg_color, 0.3) 10px,
@theme_bg_color 10px,
@theme_bg_color 20px
);
}

View File

@ -20,6 +20,8 @@
#![allow(new_without_default)] #![allow(new_without_default)]
use dazzle;
use dazzle::ThemeManagerExt;
use gio::{self, prelude::*, ActionMapExt, SettingsExt}; use gio::{self, prelude::*, ActionMapExt, SettingsExt};
use glib::{self, Variant}; use glib::{self, Variant};
use gtk; use gtk;
@ -96,6 +98,7 @@ pub(crate) struct App {
headerbar: Rc<Header>, headerbar: Rc<Header>,
player: player::PlayerWrapper, player: player::PlayerWrapper,
updater: RefCell<Option<InAppNotification>>, updater: RefCell<Option<InAppNotification>>,
theme_manager: dazzle::ThemeManager,
sender: Sender<Action>, sender: Sender<Action>,
receiver: Receiver<Action>, receiver: Receiver<Action>,
} }
@ -155,6 +158,11 @@ impl App {
let updater = RefCell::new(None); let updater = RefCell::new(None);
let theme_manager = dazzle::ThemeManager::new();
application.get_resource_base_path().map(|path| {
theme_manager.add_resources(&format!("resource://{}", path));
});
window.add(&wrap); window.add(&wrap);
let app = App { let app = App {
@ -166,6 +174,7 @@ impl App {
content, content,
player, player,
updater, updater,
theme_manager,
sender, sender,
receiver, receiver,
}; };

View File

@ -232,7 +232,10 @@ impl EpisodeWidget {
let weak = Rc::downgrade(&widget); let weak = Rc::downgrade(&widget);
widget.container.connect_draw(clone!(sender => move |_, _| { widget.container.connect_draw(clone!(sender => move |_, _| {
episode.borrow_mut().take().map(|ep| { episode.borrow_mut().take().map(|ep| {
weak.upgrade().map(|w| w.info.init(&ep)); weak.upgrade().map(|w| {
w.info.init(&ep);
w.set_styling(&ep);
});
Self::determine_buttons_state(&weak, &ep, &sender) Self::determine_buttons_state(&weak, &ep, &sender)
.map_err(|err| error!("Error: {}", err)) .map_err(|err| error!("Error: {}", err))
.ok(); .ok();
@ -474,6 +477,36 @@ impl EpisodeWidget {
Ok(()) Ok(())
} }
// Searches in the two levels above for a GtkListBoxRow
fn get_listbox_row(widget: &gtk::Box) -> Option<gtk::ListBoxRow> {
let mut row = None;
widget.get_parent().map(|first_parent| {
match first_parent.clone().downcast::<gtk::ListBoxRow>() {
Ok(r) => row = Some(r),
_ => {
first_parent.get_parent().map(|second_parent| {
second_parent
.clone()
.downcast::<gtk::ListBoxRow>()
.map(|r| row = Some(r))
});
}
}
});
row
}
fn set_styling(&self, episode: &EpisodeWidgetModel) {
if episode.played().is_some() {
Self::get_listbox_row(&self.container)
.map(|row| row.get_style_context().add_class("played"));
} else {
Self::get_listbox_row(&self.container)
.map(|row| row.get_style_context().remove_class("played"));
}
}
} }
fn on_download_clicked(ep: &EpisodeWidgetModel, sender: &Sender<Action>) -> Result<(), Error> { fn on_download_clicked(ep: &EpisodeWidgetModel, sender: &Sender<Action>) -> Result<(), Error> {
@ -504,6 +537,9 @@ fn on_play_bttn_clicked(
// Grey out the title // Grey out the title
widget.info.set_title(&episode); widget.info.set_title(&episode);
// Set the styling
widget.set_styling(&episode);
// Play the episode // Play the episode
sender sender
.send(Action::InitEpisode(episode.rowid())) .send(Action::InitEpisode(episode.rowid()))