Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Update GTK #153

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 163 additions & 76 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
gtk = { version = "0.4.9", package = "gtk4" }
gdk-pixbuf = "0.15.11"
gdk = { version = "0.4.8", package = "gdk4" }
gtk = { version = "0.6.6", package = "gtk4" }
gdk-pixbuf = "0.17.10"
gdk = { version = "0.6.3", package = "gdk4" }
pango = "0.15.10"
libadwaita = { version = "0.2.0-alpha.3", features = ["v1_2"]}
libadwaita = { version = "0.4.4", features = ["v1_2"]}

tokio = {version = "1.29.1", features = ["full"]}
futures = "0.3.28"
Expand Down
20 changes: 6 additions & 14 deletions src/gui/feed/error_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub mod imp {

use gdk::glib::clone;
use gdk::glib::MainContext;
use gdk::glib::ParamFlags;
use gdk::glib::ParamSpec;
use gdk::glib::ParamSpecString;
use gdk::glib::Sender;
Expand Down Expand Up @@ -136,24 +135,17 @@ pub mod imp {
}

impl ObjectImpl for ErrorLabel {
fn constructed(&self, obj: &Self::Type) {
self.parent_constructed(obj);
fn constructed(&self) {
self.parent_constructed();
}

fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
vec![ParamSpecString::new(
"error",
"error",
"error",
None,
ParamFlags::READWRITE,
)]
});
static PROPERTIES: Lazy<Vec<ParamSpec>> =
Lazy::new(|| vec![ParamSpecString::builder("error").build()]);
PROPERTIES.as_ref()
}

fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
fn set_property(&self, _id: usize, value: &Value, pspec: &ParamSpec) {
match pspec.name() {
"error" => {
let value: Option<String> =
Expand All @@ -164,7 +156,7 @@ pub mod imp {
}
}

fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
fn property(&self, _id: usize, pspec: &ParamSpec) -> Value {
match pspec.name() {
"error" => self.error.borrow().to_value(),
_ => unimplemented!(),
Expand Down
24 changes: 8 additions & 16 deletions src/gui/feed/feed_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gtk::glib::wrapper! {

impl FeedItem {
pub fn new(playlist_manager: PlaylistManager<String, AnyVideo>) -> Self {
let s: Self = Object::new(&[]).expect("Failed to create FeedItem");
let s: Self = Object::builder::<Self>().build();
s.imp().playlist_manager.replace(Some(playlist_manager));
s
}
Expand All @@ -47,7 +47,6 @@ pub mod imp {
use gdk::glib::ParamSpecObject;
use gdk::glib::Value;
use glib::subclass::InitializingObject;
use glib::ParamFlags;
use glib::ParamSpec;
use gtk::glib;
use gtk::prelude::*;
Expand Down Expand Up @@ -134,37 +133,30 @@ pub mod imp {
}

impl ObjectImpl for FeedItem {
fn constructed(&self, obj: &Self::Type) {
self.parent_constructed(obj);
fn constructed(&self) {
self.parent_constructed();
}

fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
vec![ParamSpecObject::new(
"video",
"video",
"video",
VideoObject::static_type(),
ParamFlags::READWRITE,
)]
});
static PROPERTIES: Lazy<Vec<ParamSpec>> =
Lazy::new(|| vec![ParamSpecObject::builder::<VideoObject>("video").build()]);
PROPERTIES.as_ref()
}

fn set_property(&self, obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
fn set_property(&self, _id: usize, value: &Value, pspec: &ParamSpec) {
match pspec.name() {
"video" => {
let value: Option<VideoObject> =
value.get().expect("Property video of incorrect type");
self.video.replace(value);
self.bind_watch_later();
self.setup_actions(obj);
self.setup_actions(&self.obj());
}
_ => unimplemented!(),
}
}

fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
fn property(&self, _id: usize, pspec: &ParamSpec) -> Value {
match pspec.name() {
"video" => self.video.borrow().to_value(),
_ => unimplemented!(),
Expand Down
58 changes: 20 additions & 38 deletions src/gui/feed/feed_item_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::player::play;

macro_rules! str_prop {
( $x:expr ) => {
ParamSpecString::new($x, $x, $x, None, ParamFlags::READWRITE)
ParamSpecString::builder($x).build()
};
}

Expand Down Expand Up @@ -75,22 +75,21 @@ gtk::glib::wrapper! {

impl VideoObject {
pub fn new(video: AnyVideo) -> Self {
let s: Self = Object::new(&[
("title", &video.title()),
("url", &video.url()),
("thumbnail-url", &video.thumbnail_url()),
("author", &video.subscription().to_string()),
("platform", &video.platform().to_string()),
(
let s: Self = Object::builder::<Self>()
.property("title", &video.title())
.property("url", &video.url())
.property("thumbnail-url", &video.thumbnail_url())
.property("author", &video.subscription().to_string())
.property("platform", &video.platform().to_string())
.property(
"date",
&video
.uploaded()
.format(&gettextrs::gettext("%F %T"))
.to_string(),
),
("playing", &false),
])
.expect("Failed to create `VideoObject`.");
)
.property("playing", &false)
.build();
s.imp().video.swap(&RefCell::new(Some(video)));
s
}
Expand Down Expand Up @@ -144,18 +143,18 @@ impl VideoObject {
}

mod imp {
use gtk::glib;
use gtk::glib::{self, Object};
use std::cell::{Cell, RefCell};
use tf_join::AnyVideo;

use gdk::{
glib::{ParamFlags, ParamSpec, ParamSpecBoolean, ParamSpecString, Value},
glib::{ParamSpec, ParamSpecBoolean, ParamSpecString, Value},
prelude::ToValue,
subclass::prelude::{ObjectImpl, ObjectSubclass},
};
use once_cell::sync::Lazy;

#[derive(Default, Clone)]
#[derive(Default)]
pub struct VideoObject {
title: RefCell<Option<String>>,
author: RefCell<Option<String>>,
Expand All @@ -175,6 +174,7 @@ mod imp {
impl ObjectSubclass for VideoObject {
const NAME: &'static str = "TFVideoObject";
type Type = super::VideoObject;
type ParentType = Object;
}

impl ObjectImpl for VideoObject {
Expand All @@ -188,33 +188,15 @@ mod imp {
str_prop!("platform"),
str_prop!("date"),
str_prop!("local-path"),
ParamSpecBoolean::new(
"playing",
"playing",
"playing",
false,
ParamFlags::READWRITE,
),
ParamSpecBoolean::new(
"downloading",
"downloading",
"downloading",
false,
ParamFlags::READWRITE,
),
ParamSpecBoolean::new(
"is-local",
"is-local",
"is-local",
false,
ParamFlags::READABLE,
),
ParamSpecBoolean::builder("playing").build(),
ParamSpecBoolean::builder("downloading").build(),
ParamSpecBoolean::builder("is-local").build(),
]
});
PROPERTIES.as_ref()
}

fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
fn set_property(&self, _id: usize, value: &Value, pspec: &ParamSpec) {
if pspec.name() == "playing" {
self.playing
.set(value.get().expect("Expect 'playing' to be a boolean."));
Expand Down Expand Up @@ -245,7 +227,7 @@ mod imp {
);
}

fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
fn property(&self, _id: usize, pspec: &ParamSpec) -> Value {
if pspec.name() == "playing" {
return self.playing.get().to_value();
}
Expand Down
37 changes: 14 additions & 23 deletions src/gui/feed/feed_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ pub mod imp {
use std::cell::{Cell, RefCell};

use gdk::gio::ListStore;
use gdk::glib::ParamFlags;
use gdk::glib::ParamSpec;
use gdk::glib::ParamSpecBoolean;
use gdk::glib::Value;
Expand Down Expand Up @@ -192,7 +191,7 @@ pub mod imp {
impl FeedList {
pub(super) fn setup(&self) {
let model = gtk::gio::ListStore::new(VideoObject::static_type());
let selection_model = gtk::NoSelection::new(Some(&model));
let selection_model = gtk::NoSelection::new(Some(model.clone()));
self.feed_list.get().set_model(Some(&selection_model));

self.model.replace(model);
Expand Down Expand Up @@ -225,7 +224,7 @@ pub mod imp {
video_object.play();
});

self.instance().setup_autoload();
self.obj().setup_autoload();
}
}

Expand All @@ -234,7 +233,11 @@ pub mod imp {
#[template_callback]
fn edge_reached(&self, pos: PositionType) {
if pos == PositionType::Bottom {
let _ = WidgetExt::activate_action(&self.instance(), "feed.more", None);
let _ = gtk::prelude::WidgetExt::activate_action(
self.obj().as_ref(),
"feed.more",
None,
);
}
}
}
Expand All @@ -256,34 +259,22 @@ pub mod imp {
}

impl ObjectImpl for FeedList {
fn constructed(&self, obj: &Self::Type) {
self.parent_constructed(obj);
obj.add_actions();
fn constructed(&self) {
self.parent_constructed();
self.obj().add_actions();
}

fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
vec![
ParamSpecBoolean::new(
"more-available",
"more-available",
"more-available",
false,
ParamFlags::READWRITE,
),
ParamSpecBoolean::new(
"is-empty",
"is-empty",
"is-empty",
false,
ParamFlags::READABLE,
),
ParamSpecBoolean::builder("more-available").build(),
ParamSpecBoolean::builder("is-empty").build(),
]
});
PROPERTIES.as_ref()
}

fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
fn set_property(&self, _id: usize, value: &Value, pspec: &ParamSpec) {
match pspec.name() {
"more-available" => {
let value: bool = value
Expand All @@ -295,7 +286,7 @@ pub mod imp {
}
}

fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
fn property(&self, _id: usize, pspec: &ParamSpec) -> Value {
match pspec.name() {
"more-available" => self.more_available.get().to_value(),
"is-empty" => (self.model.borrow().n_items() == 0).to_value(),
Expand Down
Loading
Loading