From e6710aea822f6fe413bfcac9a489a9407c01087d Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 18 Dec 2020 21:18:37 +0100 Subject: [PATCH] update per latest gtk-rs updates mostly simplifies imports, renamed macros, simplifed gobject instance creation --- Cargo.lock | 89 +++++++++++------------- Cargo.toml | 25 +------ src/application.rs | 25 +++---- src/backup/andotp.rs | 13 ++-- src/backup/bitwarden.rs | 2 +- src/backup/freeotp.rs | 12 ++-- src/backup/legacy.rs | 6 +- src/backup/mod.rs | 4 +- src/helpers/qrcode.rs | 2 +- src/main.rs | 4 +- src/models/account.rs | 30 ++++---- src/models/account_sorter.rs | 12 ++-- src/models/accounts.rs | 14 ++-- src/models/algorithm.rs | 2 +- src/models/database.rs | 2 +- src/models/favicon.rs | 6 +- src/models/provider.rs | 38 +++++----- src/models/provider_sorter.rs | 12 ++-- src/models/providers.rs | 15 ++-- src/static_resources.rs.in | 4 +- src/widgets/accounts/add.rs | 15 ++-- src/widgets/accounts/qrcode_page.rs | 14 ++-- src/widgets/accounts/row.rs | 15 ++-- src/widgets/preferences/password_page.rs | 15 ++-- src/widgets/preferences/window.rs | 15 ++-- src/widgets/providers/dialog.rs | 25 +++---- src/widgets/providers/image.rs | 13 ++-- src/widgets/providers/list.rs | 13 ++-- src/widgets/providers/page.rs | 13 ++-- src/widgets/providers/row.rs | 19 ++--- src/widgets/url_row.rs | 15 ++-- src/widgets/window.rs | 15 ++-- src/window_state.rs | 5 +- 33 files changed, 210 insertions(+), 299 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f03947..6065b85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -239,11 +239,7 @@ dependencies = [ "diesel", "diesel_migrations", "futures", - "gdk-pixbuf", - "gdk4", "gettext-rs", - "gio", - "glib", "gtk-macros", "gtk4", "hex", @@ -374,7 +370,7 @@ checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" [[package]] name = "cairo-rs" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "bitflags", "cairo-sys-rs", @@ -387,7 +383,7 @@ dependencies = [ [[package]] name = "cairo-sys-rs" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "glib-sys", "libc", @@ -875,16 +871,16 @@ checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" [[package]] name = "futures-lite" -version = "1.11.2" +version = "1.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6c079abfac3ab269e2927ec048dabc89d009ebfdda6b8ee86624f30c689658" +checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" dependencies = [ "fastrand", "futures-core", "futures-io", "memchr", "parking", - "pin-project-lite 0.1.11", + "pin-project-lite 0.2.0", "waker-fn", ] @@ -938,7 +934,7 @@ dependencies = [ [[package]] name = "gdk-pixbuf" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "gdk-pixbuf-sys", "gio", @@ -949,7 +945,7 @@ dependencies = [ [[package]] name = "gdk-pixbuf-sys" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "gio-sys", "glib-sys", @@ -961,7 +957,7 @@ dependencies = [ [[package]] name = "gdk4" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "bitflags", "cairo-rs", @@ -976,7 +972,7 @@ dependencies = [ [[package]] name = "gdk4-sys" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "cairo-sys-rs", "gdk-pixbuf-sys", @@ -991,7 +987,7 @@ dependencies = [ [[package]] name = "gdk4-wayland" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "gdk4", "gdk4-wayland-sys", @@ -1004,7 +1000,7 @@ dependencies = [ [[package]] name = "gdk4-wayland-sys" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "glib-sys", "libc", @@ -1014,7 +1010,7 @@ dependencies = [ [[package]] name = "gdk4-x11" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "gdk4", "gdk4-x11-sys", @@ -1027,7 +1023,7 @@ dependencies = [ [[package]] name = "gdk4-x11-sys" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "gdk4-sys", "glib-sys", @@ -1098,7 +1094,7 @@ dependencies = [ [[package]] name = "gio" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "bitflags", "futures", @@ -1116,7 +1112,7 @@ dependencies = [ [[package]] name = "gio-sys" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "glib-sys", "gobject-sys", @@ -1128,7 +1124,7 @@ dependencies = [ [[package]] name = "glib" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "bitflags", "futures-channel", @@ -1147,7 +1143,7 @@ dependencies = [ [[package]] name = "glib-macros" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "anyhow", "heck", @@ -1162,7 +1158,7 @@ dependencies = [ [[package]] name = "glib-sys" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "libc", "system-deps", @@ -1184,7 +1180,7 @@ dependencies = [ [[package]] name = "gobject-sys" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "glib-sys", "libc", @@ -1194,7 +1190,7 @@ dependencies = [ [[package]] name = "graphene-rs" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "glib", "graphene-sys", @@ -1204,7 +1200,7 @@ dependencies = [ [[package]] name = "graphene-sys" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "glib-sys", "libc", @@ -1215,7 +1211,7 @@ dependencies = [ [[package]] name = "gsk4" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "bitflags", "cairo-rs", @@ -1230,7 +1226,7 @@ dependencies = [ [[package]] name = "gsk4-sys" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "cairo-sys-rs", "gdk4-sys", @@ -1251,7 +1247,7 @@ checksum = "1874c48e670519ce192093ac906c08a6dde7cb2d18b28722ef237726a39c3a63" [[package]] name = "gtk4" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "bitflags", "cairo-rs", @@ -1272,7 +1268,7 @@ dependencies = [ [[package]] name = "gtk4-macros" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "anyhow", "heck", @@ -1287,7 +1283,7 @@ dependencies = [ [[package]] name = "gtk4-sys" version = "0.1.0" -source = "git+https://github.com/gtk-rs/gtk4-rs#e643e460730f486b819aaa0213b984f96f38e406" +source = "git+https://github.com/gtk-rs/gtk4-rs#d393f59dbf97518add962d250de9e3b69339f251" dependencies = [ "cairo-sys-rs", "gdk-pixbuf-sys", @@ -1348,9 +1344,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" +checksum = "84129d298a6d57d246960ff8eb831ca4af3f96d29e2e28848dae275408658e26" dependencies = [ "bytes", "fnv", @@ -1527,7 +1523,7 @@ checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" [[package]] name = "libhandy4" version = "0.1.0" -source = "git+https://gitlab.gnome.org/bilelmoussaoui/libhandy4-rs#d9f277bd4612b1040830b36beb8a5ccf01e3d2dc" +source = "git+https://gitlab.gnome.org/bilelmoussaoui/libhandy4-rs#511b3e4a398aacb9ffa30ccff9926955e135b7bc" dependencies = [ "bitflags", "gdk-pixbuf", @@ -1544,7 +1540,7 @@ dependencies = [ [[package]] name = "libhandy4-sys" version = "0.1.0" -source = "git+https://gitlab.gnome.org/bilelmoussaoui/libhandy4-rs#d9f277bd4612b1040830b36beb8a5ccf01e3d2dc" +source = "git+https://gitlab.gnome.org/bilelmoussaoui/libhandy4-rs#511b3e4a398aacb9ffa30ccff9926955e135b7bc" dependencies = [ "gdk-pixbuf-sys", "gdk4-sys", @@ -1909,7 +1905,7 @@ dependencies = [ [[package]] name = "pango" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "bitflags", "glib", @@ -1921,7 +1917,7 @@ dependencies = [ [[package]] name = "pango-sys" version = "0.13.0" -source = "git+https://github.com/gtk-rs/gtk-rs#f316f4025cde40953f2e47bcd58c8f400ca92bc7" +source = "git+https://github.com/gtk-rs/gtk-rs#f9714995940f334a712f5bfcccd558f600007e9f" dependencies = [ "glib-sys", "gobject-sys", @@ -2478,13 +2474,12 @@ checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" [[package]] name = "socket2" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c29947abdee2a218277abeca306f25789c938e500ea5a9d4b12a5a504466902" +checksum = "97e0e9fd577458a4f61fb91fcb559ea2afecc54c934119421f9f5d3d5b1a1057" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", "winapi", ] @@ -2581,9 +2576,9 @@ dependencies = [ [[package]] name = "subtle" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "surf" @@ -2737,9 +2732,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "toml" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75cf45bb0bef80604d001caaec0d09da99611b3c0fd39d3080468875cdb65645" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ "serde", ] @@ -3134,9 +3129,9 @@ dependencies = [ [[package]] name = "zvariant" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc8bb578d9efd69a950d6061d12a9359ea5b2e961ad4dee10f25ccd4bc2201a4" +checksum = "4bfdc513511335faee7b18d6e8b6086de555d6e8b0a598415571bb0f0b446519" dependencies = [ "byteorder", "enumflags2", @@ -3146,9 +3141,9 @@ dependencies = [ [[package]] name = "zvariant_derive" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f327c66f7a22695719b1cf26ae671081a9c47f1c7fa6d79209039f6ad0f6acd" +checksum = "6651d08772eefc17d36ef4da3a521b2e5f87c10ef730125b83eb500512073c92" dependencies = [ "proc-macro-crate", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index b67c17a..56ad5b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,27 +29,6 @@ ring = "0.16" serde = "1.0" serde_json = "1.0" qrcode = {version ="0.12",features=["image"]} +gtk = { git = "https://github.com/gtk-rs/gtk4-rs", package = "gtk4"} +libhandy = { git = "https://gitlab.gnome.org/bilelmoussaoui/libhandy4-rs", package = "libhandy4"} -[dependencies.gtk] -git = "https://github.com/gtk-rs/gtk4-rs" -package = "gtk4" - -[dependencies.glib] -git = "https://github.com/gtk-rs/gtk-rs" -features = ["v2_66"] - -[dependencies.gio] -git = "https://github.com/gtk-rs/gtk-rs" -features = ["v2_66"] - -[dependencies.gdk] -git = "https://github.com/gtk-rs/gtk4-rs" -package = "gdk4" - -[dependencies.libhandy] -git = "https://gitlab.gnome.org/bilelmoussaoui/libhandy4-rs" -package = "libhandy4" - -[dependencies.gdk-pixbuf] -git = "https://github.com/gtk-rs/gtk-rs" -features = ["v2_32"] diff --git a/src/application.rs b/src/application.rs index 43982cc..4f40f09 100644 --- a/src/application.rs +++ b/src/application.rs @@ -5,9 +5,9 @@ use crate::{ widgets::{PreferencesWindow, ProvidersDialog, Window}, }; use gettextrs::gettext; -use gio::{prelude::*, subclass::ObjectSubclass}; -use glib::{clone, glib_object_subclass, glib_wrapper}; -use gtk::prelude::*; +use gio::subclass::ObjectSubclass; +use glib::clone; +use gtk::{gio, glib, prelude::*}; use gtk_macros::{action, get_action}; use std::env; @@ -45,7 +45,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn class_init(klass: &mut Self::Class) { klass.install_properties(&PROPERTIES); @@ -105,7 +105,7 @@ mod imp { libhandy::functions::init(); let app = app.downcast_ref::().unwrap(); - if let Some(ref display) = gdk::Display::get_default() { + if let Some(ref display) = gtk::gdk::Display::get_default() { let p = gtk::CssProvider::new(); gtk::CssProvider::load_from_resource( &p, @@ -220,7 +220,7 @@ mod imp { } } -glib_wrapper! { +glib::wrapper! { pub struct Application(ObjectSubclass) @extends gio::Application, gtk::Application, gio::ActionMap; } @@ -231,15 +231,10 @@ impl Application { info!("Version: {} ({})", config::VERSION, config::PROFILE); info!("Datadir: {}", config::PKGDATADIR); - let app = glib::Object::new( - Application::static_type(), - &[ - ("application-id", &Some(config::APP_ID)), - ("flags", &gio::ApplicationFlags::empty()), - ], - ) - .unwrap() - .downcast::() + let app = glib::Object::new::(&[ + ("application-id", &Some(config::APP_ID)), + ("flags", &gio::ApplicationFlags::empty()), + ]) .unwrap(); let args: Vec = env::args().collect(); diff --git a/src/backup/andotp.rs b/src/backup/andotp.rs index 0a1dcb5..6a682c4 100644 --- a/src/backup/andotp.rs +++ b/src/backup/andotp.rs @@ -2,8 +2,7 @@ use super::{Backupable, Restorable}; use crate::models::{Account, Algorithm, OTPMethod, Provider, ProvidersModel}; use anyhow::Result; use gettextrs::gettext; -use gio::prelude::*; -use glib::Cast; +use gtk::{glib::Cast, prelude::*}; use serde::{Deserialize, Serialize}; #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -36,7 +35,7 @@ impl Backupable for AndOTP { gettext("Into a plain-text JSON file") } - fn backup(model: ProvidersModel, into: gio::File) -> Result<()> { + fn backup(model: ProvidersModel, into: gtk::gio::File) -> Result<()> { let mut items = Vec::new(); for i in 0..model.get_n_items() { @@ -74,8 +73,8 @@ impl Backupable for AndOTP { content.as_bytes(), None, false, - gio::FileCreateFlags::REPLACE_DESTINATION, - gio::NONE_CANCELLABLE, + gtk::gio::FileCreateFlags::REPLACE_DESTINATION, + gtk::gio::NONE_CANCELLABLE, )?; Ok(()) @@ -95,8 +94,8 @@ impl Restorable for AndOTP { gettext("From a plain-text JSON file") } - fn restore(model: ProvidersModel, from: gio::File) -> Result<()> { - let (data, _) = from.load_contents(gio::NONE_CANCELLABLE)?; + fn restore(model: ProvidersModel, from: gtk::gio::File) -> Result<()> { + let (data, _) = from.load_contents(gtk::gio::NONE_CANCELLABLE)?; let items: Vec = serde_json::de::from_slice(&data)?; items.iter().try_for_each(|item| -> anyhow::Result<()> { diff --git a/src/backup/bitwarden.rs b/src/backup/bitwarden.rs index aa99bb6..e0c9ec6 100644 --- a/src/backup/bitwarden.rs +++ b/src/backup/bitwarden.rs @@ -20,7 +20,7 @@ impl Restorable for Bitwarden { gettext("From a plain-text JSON file") } - fn restore(model: ProvidersModel, from: gio::File) -> Result<()> { + fn restore(model: ProvidersModel, from: gtk::gio::File) -> Result<()> { Ok(()) } } diff --git a/src/backup/freeotp.rs b/src/backup/freeotp.rs index e963416..5843e41 100644 --- a/src/backup/freeotp.rs +++ b/src/backup/freeotp.rs @@ -2,7 +2,7 @@ use super::{Backupable, Restorable}; use crate::models::{Account, OTPUri, Provider, ProvidersModel}; use anyhow::Result; use gettextrs::gettext; -use gio::prelude::*; +use gtk::prelude::*; use serde::{Deserialize, Serialize}; use std::str::FromStr; @@ -22,7 +22,7 @@ impl Backupable for FreeOTP { gettext("Into a plain-text file, compatible with FreeOTP+") } - fn backup(model: ProvidersModel, into: gio::File) -> Result<()> { + fn backup(model: ProvidersModel, into: gtk::gio::File) -> Result<()> { let mut items: Vec = Vec::new(); for i in 0..model.get_n_items() { @@ -46,8 +46,8 @@ impl Backupable for FreeOTP { content.as_bytes(), None, false, - gio::FileCreateFlags::REPLACE_DESTINATION, - gio::NONE_CANCELLABLE, + gtk::gio::FileCreateFlags::REPLACE_DESTINATION, + gtk::gio::NONE_CANCELLABLE, )?; Ok(()) @@ -67,8 +67,8 @@ impl Restorable for FreeOTP { gettext("From a plain-text file, compatible with FreeOTP+") } - fn restore(model: ProvidersModel, from: gio::File) -> Result<()> { - let (data, _) = from.load_contents(gio::NONE_CANCELLABLE)?; + fn restore(model: ProvidersModel, from: gtk::gio::File) -> Result<()> { + let (data, _) = from.load_contents(gtk::gio::NONE_CANCELLABLE)?; let uris = String::from_utf8(data)?; uris.split('\n') diff --git a/src/backup/legacy.rs b/src/backup/legacy.rs index 6367f77..c44d349 100644 --- a/src/backup/legacy.rs +++ b/src/backup/legacy.rs @@ -2,7 +2,7 @@ use super::Restorable; use crate::models::{Account, Algorithm, OTPMethod, ProvidersModel}; use anyhow::Result; use gettextrs::gettext; -use gio::prelude::*; +use gtk::prelude::*; use serde::{Deserialize, Serialize}; // Same as andOTP except uses the first tag for the issuer @@ -33,8 +33,8 @@ impl Restorable for LegacyAuthenticator { gettext("From a plain-text JSON file") } - fn restore(model: ProvidersModel, from: gio::File) -> Result<()> { - let (data, _) = from.load_contents(gio::NONE_CANCELLABLE)?; + fn restore(model: ProvidersModel, from: gtk::gio::File) -> Result<()> { + let (data, _) = from.load_contents(gtk::gio::NONE_CANCELLABLE)?; let items: Vec = serde_json::de::from_slice(&data)?; diff --git a/src/backup/mod.rs b/src/backup/mod.rs index a464c26..5f4f445 100644 --- a/src/backup/mod.rs +++ b/src/backup/mod.rs @@ -12,7 +12,7 @@ pub trait Restorable { fn subtitle() -> String; // Used to define the `restore.$identifier` action fn identifier() -> String; - fn restore(model: ProvidersModel, from: gio::File) -> Result<()>; + fn restore(model: ProvidersModel, from: gtk::gio::File) -> Result<()>; } pub trait Backupable { @@ -20,7 +20,7 @@ pub trait Backupable { fn subtitle() -> String; // Used to define the `backup.$identifier` action fn identifier() -> String; - fn backup(model: ProvidersModel, into: gio::File) -> Result<()>; + fn backup(model: ProvidersModel, into: gtk::gio::File) -> Result<()>; } mod andotp; diff --git a/src/helpers/qrcode.rs b/src/helpers/qrcode.rs index 32d03a7..c650afc 100644 --- a/src/helpers/qrcode.rs +++ b/src/helpers/qrcode.rs @@ -4,7 +4,7 @@ use ashpd::{ desktop::screenshot::{Screenshot, ScreenshotOptions, ScreenshotProxy}, zbus, RequestProxy, Response, WindowIdentifier, }; -use gio::FileExt; +use gtk::{gio, prelude::*}; use image::GenericImageView; use std::str::FromStr; use zbar_rust::ZBarImageScanner; diff --git a/src/main.rs b/src/main.rs index de30084..2d0c898 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,8 @@ fn main() { bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); textdomain(GETTEXT_PACKAGE); - glib::set_application_name("Authenticator"); - glib::set_prgname(Some(config::APP_ID)); + gtk::glib::set_application_name("Authenticator"); + gtk::glib::set_prgname(Some(config::APP_ID)); static_resources::init().expect("Failed to initialize the resource file."); diff --git a/src/models/account.rs b/src/models/account.rs index 50060fa..e93edc7 100644 --- a/src/models/account.rs +++ b/src/models/account.rs @@ -8,7 +8,8 @@ use byteorder::{BigEndian, ReadBytesExt}; use core::cmp::Ordering; use diesel::{BelongingToDsl, ExpressionMethods, QueryDsl, RunQueryDsl}; use gio::{subclass::ObjectSubclass, FileExt}; -use glib::{clone, glib_object_subclass, glib_wrapper, Cast, ObjectExt, StaticType, ToValue}; +use glib::{clone, Cast, ObjectExt, StaticType, ToValue}; +use gtk::{gio, glib}; use once_cell::sync::OnceCell; use qrcode::QrCode; use ring::hmac; @@ -114,7 +115,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn class_init(klass: &mut Self::Class) { klass.install_properties(&PROPERTIES); @@ -181,7 +182,7 @@ mod imp { } } } -glib_wrapper! { +glib::wrapper! { pub struct Account(ObjectSubclass); } @@ -246,19 +247,14 @@ impl Account { } pub fn new(id: i32, name: &str, token_id: &str, counter: i32, provider: Provider) -> Account { - let account = glib::Object::new( - Account::static_type(), - &[ - ("id", &id), - ("name", &name), - ("token-id", &token_id), - ("provider", &provider), - ("counter", &counter), - ], - ) - .expect("Failed to create account") - .downcast::() - .expect("Created account is of wrong type"); + let account = glib::Object::new(&[ + ("id", &id), + ("name", &name), + ("token-id", &token_id), + ("provider", &provider), + ("counter", &counter), + ]) + .expect("Failed to create account"); let token = Keyring::token(token_id).unwrap().unwrap(); let self_ = imp::Account::from_instance(&account); @@ -316,7 +312,7 @@ impl Account { } pub fn copy_otp(&self) { - let display = gdk::Display::get_default().unwrap(); + let display = gtk::gdk::Display::get_default().unwrap(); let clipboard = display.get_clipboard(); let self_ = imp::Account::from_instance(self); clipboard.set_text(&self_.otp.borrow()); diff --git a/src/models/account_sorter.rs b/src/models/account_sorter.rs index fd0b334..3d5ffb7 100644 --- a/src/models/account_sorter.rs +++ b/src/models/account_sorter.rs @@ -1,6 +1,5 @@ use super::account::Account; -use gio::{prelude::*, subclass::ObjectSubclass}; -use glib::{glib_object_subclass, glib_wrapper, StaticType}; +use gtk::glib; mod imp { use super::*; @@ -17,7 +16,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { Self {} @@ -40,16 +39,13 @@ mod imp { } } -glib_wrapper! { +glib::wrapper! { pub struct AccountSorter(ObjectSubclass) @extends gtk::Sorter; } impl AccountSorter { #[allow(clippy::new_without_default)] pub fn new() -> Self { - glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create AccountSorter") - .downcast() - .expect("Created AccountSorter is of wrong type") + glib::Object::new(&[]).expect("Failed to create AccountSorter") } } diff --git a/src/models/accounts.rs b/src/models/accounts.rs index 41809ce..5003cc9 100644 --- a/src/models/accounts.rs +++ b/src/models/accounts.rs @@ -1,6 +1,7 @@ use super::account::Account; -use gio::{prelude::*, subclass::ObjectSubclass}; -use glib::{glib_object_subclass, glib_wrapper, StaticType}; +use gio::subclass::ObjectSubclass; +use glib::StaticType; +use gtk::{gio, glib, prelude::*}; mod imp { use super::*; @@ -18,7 +19,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn type_init(type_: &mut subclass::InitializingType) { type_.add_interface::(); @@ -45,17 +46,14 @@ mod imp { } } -glib_wrapper! { +glib::wrapper! { pub struct AccountsModel(ObjectSubclass) @implements gio::ListModel; } impl AccountsModel { #[allow(clippy::new_without_default)] pub fn new() -> Self { - glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create AccountsModel") - .downcast() - .expect("Created AccountsModel is of wrong type") + glib::Object::new(&[]).expect("Failed to create AccountsModel") } pub fn insert(&self, account: &Account) { diff --git a/src/models/algorithm.rs b/src/models/algorithm.rs index 76388a1..6efa365 100644 --- a/src/models/algorithm.rs +++ b/src/models/algorithm.rs @@ -1,5 +1,5 @@ use gettextrs::gettext; -use glib::GEnum; +use gtk::{glib, glib::GEnum}; use ring::hmac; use serde::{de::Deserializer, ser::Serializer, Deserialize, Serialize}; use std::{str::FromStr, string::ToString}; diff --git a/src/models/database.rs b/src/models/database.rs index 47c8e60..09dec61 100644 --- a/src/models/database.rs +++ b/src/models/database.rs @@ -5,7 +5,7 @@ use std::{fs, fs::File, path::PathBuf}; type Pool = r2d2::Pool>; -static DB_PATH: Lazy = Lazy::new(|| glib::get_user_data_dir().join("authenticator")); +static DB_PATH: Lazy = Lazy::new(|| gtk::glib::get_user_data_dir().join("authenticator")); static POOL: Lazy = Lazy::new(|| init_pool().expect("Failed to create a pool")); embed_migrations!("migrations/"); diff --git a/src/models/favicon.rs b/src/models/favicon.rs index f38bd95..cf7c0d5 100644 --- a/src/models/favicon.rs +++ b/src/models/favicon.rs @@ -15,7 +15,7 @@ const SUPPORTED_RELS: [&[u8]; 7] = [ pub enum FaviconError { Surf(surf::Error), Url(url::ParseError), - GLib(glib::Error), + GLib(gtk::glib::Error), NoResults, } @@ -25,8 +25,8 @@ impl From for FaviconError { } } -impl From for FaviconError { - fn from(e: glib::Error) -> Self { +impl From for FaviconError { + fn from(e: gtk::glib::Error) -> Self { Self::GLib(e) } } diff --git a/src/models/provider.rs b/src/models/provider.rs index 07f9df1..3bf6844 100644 --- a/src/models/provider.rs +++ b/src/models/provider.rs @@ -6,8 +6,9 @@ use crate::{ use anyhow::Result; use core::cmp::Ordering; use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl}; -use gio::{prelude::*, subclass::ObjectSubclass}; -use glib::{glib_object_subclass, glib_wrapper, Cast, StaticType, ToValue}; +use gio::subclass::ObjectSubclass; +use glib::{Cast, StaticType, ToValue}; +use gtk::{gio, glib, prelude::*}; use std::{ cell::{Cell, RefCell}, str::FromStr, @@ -173,7 +174,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn class_init(klass: &mut Self::Class) { klass.install_properties(&PROPERTIES); @@ -268,7 +269,7 @@ mod imp { } } -glib_wrapper! { +glib::wrapper! { pub struct Provider(ObjectSubclass); } @@ -343,24 +344,19 @@ impl Provider { help_url: Option, image_uri: Option, ) -> Provider { - glib::Object::new( - Provider::static_type(), - &[ - ("id", &id), - ("name", &name), - ("website", &website), - ("help-url", &help_url), - ("image-uri", &image_uri), - ("period", &period), - ("method", &method.to_string()), - ("algorithm", &algorithm.to_string()), - ("digits", &digits), - ("default-counter", &default_counter), - ], - ) + glib::Object::new(&[ + ("id", &id), + ("name", &name), + ("website", &website), + ("help-url", &help_url), + ("image-uri", &image_uri), + ("period", &period), + ("method", &method.to_string()), + ("algorithm", &algorithm.to_string()), + ("digits", &digits), + ("default-counter", &default_counter), + ]) .expect("Failed to create provider") - .downcast() - .expect("Created provider is of wrong type") } pub async fn favicon(&self) -> Result { diff --git a/src/models/provider_sorter.rs b/src/models/provider_sorter.rs index 7b1f72a..65246cd 100644 --- a/src/models/provider_sorter.rs +++ b/src/models/provider_sorter.rs @@ -1,6 +1,5 @@ use super::provider::Provider; -use gio::{prelude::*, subclass::ObjectSubclass}; -use glib::{glib_object_subclass, glib_wrapper, StaticType}; +use gtk::glib; mod imp { use super::*; @@ -17,7 +16,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { Self {} @@ -40,16 +39,13 @@ mod imp { } } -glib_wrapper! { +glib::wrapper! { pub struct ProviderSorter(ObjectSubclass) @extends gtk::Sorter; } impl ProviderSorter { #[allow(clippy::new_without_default)] pub fn new() -> Self { - glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create ProviderSorter") - .downcast() - .expect("Created ProviderSorter is of wrong type") + glib::Object::new(&[]).expect("Failed to create ProviderSorter") } } diff --git a/src/models/providers.rs b/src/models/providers.rs index cc839cd..979ad14 100644 --- a/src/models/providers.rs +++ b/src/models/providers.rs @@ -1,8 +1,8 @@ use super::{Account, Algorithm, OTPMethod, Provider}; use anyhow::Result; -use gio::{prelude::*, subclass::ObjectSubclass}; -use glib::{glib_object_subclass, glib_wrapper, StaticType}; -use gtk::prelude::*; +use gio::subclass::ObjectSubclass; +use glib::StaticType; +use gtk::{gio, glib, prelude::*}; mod imp { use super::*; @@ -20,7 +20,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn type_init(type_: &mut subclass::InitializingType) { type_.add_interface::(); @@ -47,17 +47,14 @@ mod imp { } } -glib_wrapper! { +glib::wrapper! { pub struct ProvidersModel(ObjectSubclass) @implements gio::ListModel; } impl ProvidersModel { #[allow(clippy::new_without_default)] pub fn new() -> Self { - let model: ProvidersModel = glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create Model") - .downcast() - .expect("Created Model is of wrong type"); + let model: ProvidersModel = glib::Object::new(&[]).expect("Failed to create Model"); model.init(); model } diff --git a/src/static_resources.rs.in b/src/static_resources.rs.in index c619de5..6852ed1 100644 --- a/src/static_resources.rs.in +++ b/src/static_resources.rs.in @@ -1,7 +1,7 @@ // Source: https://gitlab.gnome.org/World/podcasts/blob/master/podcasts-gtk/src/static_resource.rs -use gio::{resources_register, Resource}; -use glib::{Bytes, Error}; +use gtk::gio::{resources_register, Resource}; +use gtk::glib::{Bytes, Error}; pub(crate) fn init() -> Result<(), Error> { // load the gresource binary at build time and include/link it into the final diff --git a/src/widgets/accounts/add.rs b/src/widgets/accounts/add.rs index cf49af1..5308f55 100644 --- a/src/widgets/accounts/add.rs +++ b/src/widgets/accounts/add.rs @@ -4,9 +4,9 @@ use crate::{ widgets::{ProviderImage, UrlRow}, }; use anyhow::Result; -use gio::{prelude::*, subclass::ObjectSubclass, ActionMapExt}; -use glib::{clone, glib_object_subclass, glib_wrapper, signal::Inhibit, subclass::prelude::*}; -use gtk::{prelude::*, CompositeTemplate}; +use gio::{subclass::ObjectSubclass, ActionMapExt}; +use glib::{clone, signal::Inhibit}; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; use gtk_macros::{action, get_action}; use once_cell::sync::OnceCell; @@ -58,7 +58,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { let actions = gio::SimpleActionGroup::new(); @@ -103,16 +103,13 @@ mod imp { impl WindowImpl for AccountAddDialog {} impl libhandy::subclass::window::WindowImpl for AccountAddDialog {} } -glib_wrapper! { +glib::wrapper! { pub struct AccountAddDialog(ObjectSubclass) @extends gtk::Widget, gtk::Window, libhandy::Window; } impl AccountAddDialog { pub fn new(model: ProvidersModel) -> Self { - let dialog = glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create AccountAddDialog") - .downcast::() - .expect("Created object is of wrong type"); + let dialog = glib::Object::new(&[]).expect("Failed to create AccountAddDialog"); let self_ = imp::AccountAddDialog::from_instance(&dialog); self_.model.set(model).unwrap(); diff --git a/src/widgets/accounts/qrcode_page.rs b/src/widgets/accounts/qrcode_page.rs index 2bc4c8f..132cadc 100644 --- a/src/widgets/accounts/qrcode_page.rs +++ b/src/widgets/accounts/qrcode_page.rs @@ -1,7 +1,6 @@ use crate::{models::Account, widgets::UrlRow}; use gio::{subclass::ObjectSubclass, FileExt}; -use glib::{glib_object_subclass, glib_wrapper, subclass::prelude::*}; -use gtk::{prelude::*, CompositeTemplate}; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; mod imp { use super::*; @@ -29,7 +28,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { Self { @@ -60,16 +59,13 @@ mod imp { impl BoxImpl for QRCodePage {} } -glib_wrapper! { +glib::wrapper! { pub struct QRCodePage(ObjectSubclass) @extends gtk::Widget, gtk::Box; } impl QRCodePage { #[allow(clippy::new_without_default)] pub fn new() -> Self { - glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create QRCodePage") - .downcast::() - .expect("Created object is of wrong type") + glib::Object::new(&[]).expect("Failed to create QRCodePage") } pub fn set_account(&self, account: &Account) { @@ -79,7 +75,7 @@ impl QRCodePage { .get_property_gtk_application_prefer_dark_theme(); let qr_code = account.qr_code(is_dark).unwrap(); - let pixbuf = gdk_pixbuf::Pixbuf::from_file(qr_code.get_path().unwrap()).unwrap(); + let pixbuf = gtk::gdk_pixbuf::Pixbuf::from_file(qr_code.get_path().unwrap()).unwrap(); self_.image.get().set_from_pixbuf(Some(&pixbuf)); self_.account_label.get().set_text(&account.name()); diff --git a/src/widgets/accounts/row.rs b/src/widgets/accounts/row.rs index a2b3536..0756db5 100644 --- a/src/widgets/accounts/row.rs +++ b/src/widgets/accounts/row.rs @@ -1,7 +1,7 @@ use crate::models::Account; -use gio::{prelude::*, subclass::ObjectSubclass, ActionMapExt}; -use glib::{clone, glib_object_subclass, glib_wrapper, subclass::prelude::*}; -use gtk::{prelude::*, CompositeTemplate}; +use gio::{subclass::ObjectSubclass, ActionMapExt}; +use glib::clone; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; use gtk_macros::{action, get_action}; use std::cell::RefCell; @@ -43,7 +43,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { let actions = gio::SimpleActionGroup::new(); @@ -100,16 +100,13 @@ mod imp { impl ListBoxRowImpl for AccountRow {} } -glib_wrapper! { +glib::wrapper! { pub struct AccountRow(ObjectSubclass) @extends gtk::Widget, gtk::ListBoxRow; } impl AccountRow { pub fn new(account: Account) -> Self { - glib::Object::new(Self::static_type(), &[("account", &account)]) - .expect("Failed to create AccountRow") - .downcast::() - .expect("Created object is of wrong type") + glib::Object::new(&[("account", &account)]).expect("Failed to create AccountRow") } fn account(&self) -> Account { diff --git a/src/widgets/preferences/password_page.rs b/src/widgets/preferences/password_page.rs index 5d58960..ed8755b 100644 --- a/src/widgets/preferences/password_page.rs +++ b/src/widgets/preferences/password_page.rs @@ -1,7 +1,7 @@ use crate::{config, helpers::Keyring}; -use gio::{prelude::*, subclass::ObjectSubclass}; -use glib::{clone, glib_object_subclass, glib_wrapper, subclass::prelude::*}; -use gtk::{prelude::*, CompositeTemplate}; +use gio::subclass::ObjectSubclass; +use glib::clone; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; use gtk_macros::{action, get_action}; use once_cell::sync::OnceCell; use std::cell::Cell; @@ -34,7 +34,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { let has_set_password = Keyring::has_set_password().unwrap_or(false); @@ -69,16 +69,13 @@ mod imp { impl BoxImpl for PasswordPage {} } -glib_wrapper! { +glib::wrapper! { pub struct PasswordPage(ObjectSubclass) @extends gtk::Widget, gtk::Box; } impl PasswordPage { pub fn new(actions: gio::SimpleActionGroup) -> Self { - let page = glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create PasswordPage") - .downcast::() - .expect("Created object is of wrong type"); + let page = glib::Object::new(&[]).expect("Failed to create PasswordPage"); let self_ = imp::PasswordPage::from_instance(&page); self_.actions.set(actions).unwrap(); page.setup_widgets(); diff --git a/src/widgets/preferences/window.rs b/src/widgets/preferences/window.rs index f8fec86..7150de4 100644 --- a/src/widgets/preferences/window.rs +++ b/src/widgets/preferences/window.rs @@ -5,9 +5,9 @@ use crate::{ models::ProvidersModel, }; use gettextrs::gettext; -use gio::{prelude::*, subclass::ObjectSubclass, ActionMapExt}; -use glib::{clone, glib_object_subclass, glib_wrapper, subclass::prelude::*}; -use gtk::{prelude::*, CompositeTemplate}; +use gio::{subclass::ObjectSubclass, ActionMapExt}; +use glib::clone; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; use libhandy::prelude::*; use once_cell::sync::OnceCell; @@ -48,7 +48,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { let settings = gio::Settings::new(config::APP_ID); @@ -95,17 +95,14 @@ mod imp { impl PreferencesWindowImpl for PreferencesWindow {} } -glib_wrapper! { +glib::wrapper! { pub struct PreferencesWindow(ObjectSubclass) @extends gtk::Widget, gtk::Window, libhandy::Window, libhandy::PreferencesWindow; } impl PreferencesWindow { pub fn new(model: ProvidersModel) -> Self { - let window = glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create PreferencesWindow") - .downcast::() - .expect("Created object is of wrong type"); + let window = glib::Object::new(&[]).expect("Failed to create PreferencesWindow"); let self_ = imp::PreferencesWindow::from_instance(&window); self_.model.set(model).unwrap(); window.setup_widgets(); diff --git a/src/widgets/providers/dialog.rs b/src/widgets/providers/dialog.rs index 0e16bdf..bc3b0d7 100644 --- a/src/widgets/providers/dialog.rs +++ b/src/widgets/providers/dialog.rs @@ -1,8 +1,8 @@ use super::{ProviderPage, ProviderPageMode}; use crate::models::{Provider, ProviderSorter, ProvidersModel}; -use gio::{prelude::*, subclass::ObjectSubclass, ListModelExt}; -use glib::{clone, glib_object_subclass, glib_wrapper, subclass::prelude::*}; -use gtk::{prelude::*, CompositeTemplate}; +use gio::{subclass::ObjectSubclass, ListModelExt}; +use glib::clone; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; use row::ProviderActionRow; mod imp { @@ -35,7 +35,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { let filter_model = gtk::FilterListModel::new(gio::NONE_LIST_MODEL, gtk::NONE_FILTER); @@ -67,16 +67,14 @@ mod imp { impl WindowImpl for ProvidersDialog {} impl HdyWindowImpl for ProvidersDialog {} } -glib_wrapper! { +glib::wrapper! { pub struct ProvidersDialog(ObjectSubclass) @extends gtk::Widget, gtk::Window, libhandy::Window; } impl ProvidersDialog { pub fn new(model: ProvidersModel) -> Self { - let dialog = glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create ProvidersDialog") - .downcast::() - .expect("Created object is of wrong type"); + let dialog = + glib::Object::new::(&[]).expect("Failed to create ProvidersDialog"); dialog.setup_widgets(model); dialog.setup_actions(); @@ -236,7 +234,7 @@ mod row { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { let actions = gio::SimpleActionGroup::new(); @@ -286,17 +284,14 @@ mod row { impl ListBoxRowImpl for ProviderActionRow {} } - glib_wrapper! { + glib::wrapper! { pub struct ProviderActionRow(ObjectSubclass) @extends gtk::Widget, gtk::ListBoxRow; } impl ProviderActionRow { #[allow(clippy::new_without_default)] pub fn new() -> Self { - glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create ProviderActionRow") - .downcast::() - .expect("Created object is of wrong type") + glib::Object::new(&[]).expect("Failed to create ProviderActionRow") } fn setup_widgets(&self) { diff --git a/src/widgets/providers/image.rs b/src/widgets/providers/image.rs index d154932..c79fc1f 100644 --- a/src/widgets/providers/image.rs +++ b/src/widgets/providers/image.rs @@ -1,7 +1,7 @@ use crate::models::Provider; use gio::{subclass::ObjectSubclass, FileExt}; -use glib::{clone, glib_object_subclass, glib_wrapper, subclass::prelude::*, Receiver, Sender}; -use gtk::{prelude::*, CompositeTemplate}; +use glib::{clone, Receiver, Sender}; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; pub enum ImageAction { Ready(gio::File), @@ -58,7 +58,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { let (sender, r) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); @@ -117,16 +117,13 @@ mod imp { impl BoxImpl for ProviderImage {} } -glib_wrapper! { +glib::wrapper! { pub struct ProviderImage(ObjectSubclass) @extends gtk::Widget, gtk::Box; } impl ProviderImage { #[allow(clippy::new_without_default)] pub fn new() -> Self { - glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create ProviderImage") - .downcast::() - .expect("Created ProviderImage is of wrong type") + glib::Object::new(&[]).expect("Failed to create ProviderImage") } pub fn set_provider(&self, provider: &Provider) { diff --git a/src/widgets/providers/list.rs b/src/widgets/providers/list.rs index 26e5d99..8c13db7 100644 --- a/src/widgets/providers/list.rs +++ b/src/widgets/providers/list.rs @@ -4,8 +4,8 @@ use crate::{ widgets::providers::ProviderRow, }; use gio::{subclass::ObjectSubclass, ListModelExt}; -use glib::{clone, glib_object_subclass, glib_wrapper, subclass::prelude::*}; -use gtk::{prelude::*, CompositeTemplate}; +use glib::clone; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; mod imp { use super::*; @@ -29,7 +29,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { let filter_model = gtk::FilterListModel::new(gio::NONE_LIST_MODEL, gtk::NONE_FILTER); @@ -64,16 +64,13 @@ mod imp { impl BoxImpl for ProvidersList {} } -glib_wrapper! { +glib::wrapper! { pub struct ProvidersList(ObjectSubclass) @extends gtk::Widget, gtk::Box; } impl ProvidersList { #[allow(clippy::new_without_default)] pub fn new() -> Self { - glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create ProvidersList") - .downcast::() - .expect("Created object is of wrong type") + glib::Object::new(&[]).expect("Failed to create ProvidersList") } pub fn set_model(&self, model: ProvidersModel) { diff --git a/src/widgets/providers/page.rs b/src/widgets/providers/page.rs index 4ba73d4..b917807 100644 --- a/src/widgets/providers/page.rs +++ b/src/widgets/providers/page.rs @@ -3,8 +3,8 @@ use crate::{ widgets::ProviderImage, }; use gio::subclass::ObjectSubclass; -use glib::{clone, glib_object_subclass, glib_wrapper, subclass::prelude::*, translate::ToGlib}; -use gtk::{prelude::*, CompositeTemplate}; +use glib::{clone, translate::ToGlib}; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; use libhandy::ComboRowExt; pub enum ProviderPageMode { @@ -58,7 +58,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { let methods_model = libhandy::EnumListModel::new(OTPMethod::static_type()); @@ -101,16 +101,13 @@ mod imp { impl BoxImpl for ProviderPage {} } -glib_wrapper! { +glib::wrapper! { pub struct ProviderPage(ObjectSubclass) @extends gtk::Widget, gtk::Box; } impl ProviderPage { #[allow(clippy::new_without_default)] pub fn new() -> Self { - glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create ProviderPage") - .downcast::() - .expect("Created object is of wrong type") + glib::Object::new(&[]).expect("Failed to create ProviderPage") } pub fn set_provider(&self, provider: Provider) { diff --git a/src/widgets/providers/row.rs b/src/widgets/providers/row.rs index 78c01c8..93adfb4 100644 --- a/src/widgets/providers/row.rs +++ b/src/widgets/providers/row.rs @@ -2,9 +2,13 @@ use crate::{ models::{Account, AccountSorter, OTPMethod, Provider}, widgets::{accounts::AccountRow, ProviderImage}, }; -use gio::{prelude::*, subclass::ObjectSubclass}; -use glib::{clone, glib_object_subclass, glib_wrapper, subclass::prelude::*}; -use gtk::{prelude::*, CompositeTemplate}; +use gio::subclass::ObjectSubclass; +use gtk::{ + gio, glib, + glib::{clone, subclass::prelude::*}, + prelude::*, + CompositeTemplate, +}; use std::time::{Duration, Instant}; mod imp { @@ -58,7 +62,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { Self { @@ -123,16 +127,13 @@ mod imp { impl ListBoxRowImpl for ProviderRow {} } -glib_wrapper! { +glib::wrapper! { pub struct ProviderRow(ObjectSubclass) @extends gtk::Widget, gtk::ListBoxRow; } impl ProviderRow { pub fn new(provider: Provider) -> Self { - glib::Object::new(Self::static_type(), &[("provider", &provider)]) - .expect("Failed to create ProviderRow") - .downcast::() - .expect("Created object is of wrong type") + glib::Object::new(&[("provider", &provider)]).expect("Failed to create ProviderRow") } fn provider(&self) -> Provider { diff --git a/src/widgets/url_row.rs b/src/widgets/url_row.rs index 507fbc1..23fd9b3 100644 --- a/src/widgets/url_row.rs +++ b/src/widgets/url_row.rs @@ -1,11 +1,11 @@ use gio::subclass::ObjectSubclass; -use glib::{clone, glib_wrapper, Cast, ObjectExt, StaticType, ToValue}; -use gtk::WidgetExt; +use glib::{clone, ObjectExt, ToValue}; +use gtk::{gio, glib, WidgetExt}; use libhandy::ActionRowExt; mod imp { use super::*; - use glib::{glib_object_subclass, subclass}; + use glib::subclass; use gtk::subclass::prelude::*; use libhandy::subclass::action_row::ActionRowImpl; use std::cell::RefCell; @@ -43,7 +43,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { Self { @@ -93,17 +93,14 @@ mod imp { impl ActionRowImpl for UrlRow {} } -glib_wrapper! { +glib::wrapper! { pub struct UrlRow(ObjectSubclass) @extends gtk::Widget, gtk::ListBoxRow, libhandy::ActionRow; } impl UrlRow { #[allow(clippy::new_without_default)] pub fn new() -> Self { - glib::Object::new(Self::static_type(), &[]) - .expect("Failed to create UrlRow") - .downcast::() - .expect("Created object is of wrong type") + glib::Object::new(&[]).expect("Failed to create UrlRow") } fn setup_widgets(&self) { diff --git a/src/widgets/window.rs b/src/widgets/window.rs index 72c81ca..04891b9 100644 --- a/src/widgets/window.rs +++ b/src/widgets/window.rs @@ -6,9 +6,9 @@ use crate::{ widgets::{accounts::QRCodePage, providers::ProvidersList, AccountAddDialog}, window_state, }; -use gio::{prelude::*, subclass::ObjectSubclass}; -use glib::{clone, glib_object_subclass, glib_wrapper, signal::Inhibit, subclass::prelude::*}; -use gtk::{prelude::*, CompositeTemplate}; +use gio::subclass::ObjectSubclass; +use glib::{clone, signal::Inhibit, subclass::prelude::*}; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; use gtk_macros::{action, get_action}; use once_cell::sync::OnceCell; @@ -54,7 +54,7 @@ mod imp { type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; - glib_object_subclass!(); + glib::object_subclass!(); fn new() -> Self { let settings = gio::Settings::new(config::APP_ID); @@ -92,17 +92,14 @@ mod imp { impl HdyApplicationWindowImpl for Window {} } -glib_wrapper! { +glib::wrapper! { pub struct Window(ObjectSubclass) @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, libhandy::ApplicationWindow, gio::ActionMap, gio::ActionGroup; } impl Window { pub fn new(model: ProvidersModel, app: &Application) -> Self { - let window = glib::Object::new(Window::static_type(), &[("application", app)]) - .unwrap() - .downcast::() - .unwrap(); + let window = glib::Object::new::(&[("application", app)]).unwrap(); app.add_window(&window); if config::PROFILE == "Devel" { diff --git a/src/window_state.rs b/src/window_state.rs index c724a96..fcdb373 100644 --- a/src/window_state.rs +++ b/src/window_state.rs @@ -1,9 +1,8 @@ use crate::widgets::Window; use anyhow::Result; -use gio::prelude::SettingsExt; use gtk::prelude::*; -pub fn load(window: &Window, settings: &gio::Settings) { +pub fn load(window: &Window, settings: >k::gio::Settings) { let width = settings.get_int("window-width"); let height = settings.get_int("window-height"); @@ -17,7 +16,7 @@ pub fn load(window: &Window, settings: &gio::Settings) { } } -pub fn save(window: &Window, settings: &gio::Settings) -> Result<()> { +pub fn save(window: &Window, settings: >k::gio::Settings) -> Result<()> { let size = window.get_default_size(); settings.set_int("window-width", size.0)?; settings.set_int("window-height", size.1)?;