mirror of
https://gitlab.gnome.org/World/Authenticator.git
synced 2025-03-04 16:54:45 +01:00
adapt per latest gtk-rs api changes
This commit is contained in:
parent
b867c5c19b
commit
9e78e50a09
19 changed files with 183 additions and 302 deletions
|
@ -11,7 +11,7 @@ use gtk_macros::{action, get_action};
|
|||
mod imp {
|
||||
use super::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use glib::{ParamSpec, WeakRef};
|
||||
use glib::{ParamSpec, ParamSpecBoolean, Value, WeakRef};
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
||||
// The basic struct that holds our state and widgets
|
||||
|
@ -54,14 +54,14 @@ mod imp {
|
|||
use once_cell::sync::Lazy;
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![
|
||||
ParamSpec::new_boolean(
|
||||
ParamSpecBoolean::new(
|
||||
"locked",
|
||||
"locked",
|
||||
"locked",
|
||||
false,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_boolean(
|
||||
ParamSpecBoolean::new(
|
||||
"can-be-locked",
|
||||
"can_be_locked",
|
||||
"can be locked",
|
||||
|
@ -72,13 +72,7 @@ mod imp {
|
|||
});
|
||||
PROPERTIES.as_ref()
|
||||
}
|
||||
fn set_property(
|
||||
&self,
|
||||
_obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"locked" => {
|
||||
let locked = value.get().unwrap();
|
||||
|
@ -92,7 +86,7 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> glib::Value {
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"locked" => self.locked.get().to_value(),
|
||||
"can-be-locked" => self.can_be_locked.get().to_value(),
|
||||
|
@ -136,7 +130,7 @@ mod imp {
|
|||
"about",
|
||||
clone!(@weak app => move |_, _| {
|
||||
let window = app.active_window().unwrap();
|
||||
let about_dialog = gtk::AboutDialogBuilder::new()
|
||||
gtk::AboutDialog::builder()
|
||||
.program_name(&gettext("Authenticator"))
|
||||
.modal(true)
|
||||
.version(config::VERSION)
|
||||
|
@ -148,9 +142,8 @@ mod imp {
|
|||
.logo_icon_name(config::APP_ID)
|
||||
.license_type(gtk::License::Gpl30)
|
||||
.transient_for(&window)
|
||||
.build();
|
||||
|
||||
about_dialog.show();
|
||||
.build()
|
||||
.show();
|
||||
})
|
||||
);
|
||||
action!(
|
||||
|
|
|
@ -39,7 +39,7 @@ pub struct DiAccount {
|
|||
#[doc(hidden)]
|
||||
mod imp {
|
||||
use super::*;
|
||||
use glib::ParamSpec;
|
||||
use glib::{ParamSpec, ParamSpecObject, ParamSpecString, ParamSpecUInt, Value};
|
||||
|
||||
pub struct Account {
|
||||
pub id: Cell<u32>,
|
||||
|
@ -75,7 +75,7 @@ mod imp {
|
|||
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![
|
||||
ParamSpec::new_uint(
|
||||
ParamSpecUInt::new(
|
||||
"id",
|
||||
"id",
|
||||
"Id",
|
||||
|
@ -84,7 +84,7 @@ mod imp {
|
|||
0,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_uint(
|
||||
ParamSpecUInt::new(
|
||||
"counter",
|
||||
"counter",
|
||||
"Counter",
|
||||
|
@ -93,28 +93,22 @@ mod imp {
|
|||
otp::HOTP_DEFAULT_COUNTER,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_string(
|
||||
"name",
|
||||
"name",
|
||||
"Name",
|
||||
None,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_string(
|
||||
ParamSpecString::new("name", "name", "Name", None, glib::ParamFlags::READWRITE),
|
||||
ParamSpecString::new(
|
||||
"token-id",
|
||||
"token-id",
|
||||
"token id",
|
||||
None,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_string(
|
||||
ParamSpecString::new(
|
||||
"otp",
|
||||
"otp",
|
||||
"The One Time Password",
|
||||
None,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_object(
|
||||
ParamSpecObject::new(
|
||||
"provider",
|
||||
"provider",
|
||||
"The account provider",
|
||||
|
@ -126,13 +120,7 @@ mod imp {
|
|||
PROPERTIES.as_ref()
|
||||
}
|
||||
|
||||
fn set_property(
|
||||
&self,
|
||||
_obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"id" => {
|
||||
let id = value.get().unwrap();
|
||||
|
@ -162,7 +150,7 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> glib::Value {
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"id" => self.id.get().to_value(),
|
||||
"name" => self.name.borrow().to_value(),
|
||||
|
@ -250,7 +238,7 @@ impl Account {
|
|||
provider: Provider,
|
||||
token: Option<&str>,
|
||||
) -> Result<Account> {
|
||||
let account = glib::Object::new(&[
|
||||
let account = glib::Object::new::<Self>(&[
|
||||
("id", &id),
|
||||
("name", &name),
|
||||
("token-id", &token_id),
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
use gettextrs::gettext;
|
||||
use gtk::{glib, glib::GEnum};
|
||||
use gtk::glib;
|
||||
use ring::hmac;
|
||||
use serde::{de::Deserializer, ser::Serializer, Deserialize, Serialize};
|
||||
use std::{str::FromStr, string::ToString};
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy, GEnum)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy, glib::Enum)]
|
||||
#[repr(u32)]
|
||||
#[genum(type_name = "OTPMethod")]
|
||||
#[enum_type(name = "OTPMethod")]
|
||||
pub enum OTPMethod {
|
||||
#[genum(name = "TOTP")]
|
||||
#[enum_value(name = "TOTP")]
|
||||
TOTP = 0,
|
||||
#[genum(name = "HOTP")]
|
||||
#[enum_value(name = "HOTP")]
|
||||
HOTP = 1,
|
||||
Steam = 2,
|
||||
}
|
||||
|
@ -85,15 +85,15 @@ impl ToString for OTPMethod {
|
|||
}
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy, GEnum)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy, glib::Enum)]
|
||||
#[repr(u32)]
|
||||
#[genum(type_name = "Algorithm")]
|
||||
#[enum_type(name = "Algorithm")]
|
||||
pub enum Algorithm {
|
||||
#[genum(name = "SHA1")]
|
||||
#[enum_value(name = "SHA1")]
|
||||
SHA1 = 0,
|
||||
#[genum(name = "SHA256")]
|
||||
#[enum_value(name = "SHA256")]
|
||||
SHA256 = 1,
|
||||
#[genum(name = "SHA512")]
|
||||
#[enum_value(name = "SHA512")]
|
||||
SHA512 = 2,
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ pub struct DiProvider {
|
|||
}
|
||||
mod imp {
|
||||
use super::*;
|
||||
use glib::ParamSpec;
|
||||
use glib::{ParamSpec, ParamSpecObject, ParamSpecString, ParamSpecUInt, Value};
|
||||
|
||||
pub struct Provider {
|
||||
pub id: Cell<u32>,
|
||||
|
@ -109,7 +109,7 @@ mod imp {
|
|||
use once_cell::sync::Lazy;
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![
|
||||
ParamSpec::new_uint(
|
||||
ParamSpecUInt::new(
|
||||
"id",
|
||||
"id",
|
||||
"Id",
|
||||
|
@ -118,21 +118,15 @@ mod imp {
|
|||
0,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_string(
|
||||
"name",
|
||||
"name",
|
||||
"Name",
|
||||
None,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_object(
|
||||
ParamSpecString::new("name", "name", "Name", None, glib::ParamFlags::READWRITE),
|
||||
ParamSpecObject::new(
|
||||
"accounts",
|
||||
"accounts",
|
||||
"accounts",
|
||||
AccountsModel::static_type(),
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_uint(
|
||||
ParamSpecUInt::new(
|
||||
"period",
|
||||
"period",
|
||||
"Period",
|
||||
|
@ -141,7 +135,7 @@ mod imp {
|
|||
otp::TOTP_DEFAULT_PERIOD,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_uint(
|
||||
ParamSpecUInt::new(
|
||||
"digits",
|
||||
"digits",
|
||||
"Digits",
|
||||
|
@ -150,7 +144,7 @@ mod imp {
|
|||
otp::DEFAULT_DIGITS,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_uint(
|
||||
ParamSpecUInt::new(
|
||||
"default-counter",
|
||||
"default_counter",
|
||||
"default_counter",
|
||||
|
@ -159,35 +153,35 @@ mod imp {
|
|||
otp::HOTP_DEFAULT_COUNTER,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_string(
|
||||
ParamSpecString::new(
|
||||
"algorithm",
|
||||
"algorithm",
|
||||
"Algorithm",
|
||||
Some(&Algorithm::default().to_string()),
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_string(
|
||||
ParamSpecString::new(
|
||||
"method",
|
||||
"method",
|
||||
"Method",
|
||||
Some(&OTPMethod::default().to_string()),
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_string(
|
||||
ParamSpecString::new(
|
||||
"website",
|
||||
"website",
|
||||
"Website",
|
||||
None,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_string(
|
||||
ParamSpecString::new(
|
||||
"help-url",
|
||||
"help url",
|
||||
"Help URL",
|
||||
None,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_string(
|
||||
ParamSpecString::new(
|
||||
"image-uri",
|
||||
"image uri",
|
||||
"Image URI",
|
||||
|
@ -199,13 +193,7 @@ mod imp {
|
|||
PROPERTIES.as_ref()
|
||||
}
|
||||
|
||||
fn set_property(
|
||||
&self,
|
||||
_obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"id" => {
|
||||
let id = value.get().unwrap();
|
||||
|
@ -251,7 +239,7 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> glib::Value {
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"id" => self.id.get().to_value(),
|
||||
"name" => self.name.borrow().to_value(),
|
||||
|
|
|
@ -120,7 +120,7 @@ glib::wrapper! {
|
|||
|
||||
impl AccountAddDialog {
|
||||
pub fn new(model: ProvidersModel) -> Self {
|
||||
let dialog = glib::Object::new(&[]).expect("Failed to create AccountAddDialog");
|
||||
let dialog = glib::Object::new::<Self>(&[]).expect("Failed to create AccountAddDialog");
|
||||
|
||||
dialog.imp().model.set(model).unwrap();
|
||||
dialog.setup_actions();
|
||||
|
@ -141,11 +141,9 @@ impl AccountAddDialog {
|
|||
fn setup_signals(&self) {
|
||||
let imp = self.imp();
|
||||
|
||||
imp
|
||||
.username_entry
|
||||
imp.username_entry
|
||||
.connect_changed(clone!(@weak self as win => move |_| win.validate()));
|
||||
imp
|
||||
.token_entry
|
||||
imp.token_entry
|
||||
.connect_changed(clone!(@weak self as win => move |_| win.validate()));
|
||||
}
|
||||
|
||||
|
@ -201,7 +199,7 @@ impl AccountAddDialog {
|
|||
let account = Account::create(&username, &token, provider)?;
|
||||
|
||||
imp.model.get().unwrap().add_account(&account, &provider);
|
||||
self.emit_by_name("added", &[]);
|
||||
self.emit_by_name::<()>("added", &[]);
|
||||
// TODO: display an error message saying there was an error form keyring
|
||||
} else {
|
||||
anyhow::bail!("Could not find provider");
|
||||
|
@ -218,12 +216,10 @@ impl AccountAddDialog {
|
|||
|
||||
imp.image.set_provider(Some(&provider));
|
||||
|
||||
imp
|
||||
.method_label
|
||||
imp.method_label
|
||||
.set_text(&provider.method().to_locale_string());
|
||||
|
||||
imp
|
||||
.algorithm_label
|
||||
imp.algorithm_label
|
||||
.set_text(&provider.algorithm().to_locale_string());
|
||||
|
||||
imp.digits_label.set_text(&provider.digits().to_string());
|
||||
|
@ -297,8 +293,7 @@ impl AccountAddDialog {
|
|||
|
||||
fn setup_widgets(&self) {
|
||||
let imp = self.imp();
|
||||
imp
|
||||
.provider_completion
|
||||
imp.provider_completion
|
||||
.set_model(Some(&imp.model.get().unwrap().completion_model()));
|
||||
|
||||
imp.provider_completion.connect_match_selected(
|
||||
|
|
|
@ -69,8 +69,7 @@ impl AccountDetailsPage {
|
|||
|
||||
fn init_widgets(&self) {
|
||||
let imp = self.imp();
|
||||
imp
|
||||
.qrcode_picture
|
||||
imp.qrcode_picture
|
||||
.set_paintable(Some(&imp.qrcode_paintable));
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ mod imp {
|
|||
use super::*;
|
||||
use glib::{
|
||||
subclass::{self, Signal},
|
||||
ParamSpec,
|
||||
ParamSpec, ParamSpecObject, Value,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
|
@ -59,7 +59,7 @@ mod imp {
|
|||
|
||||
fn properties() -> &'static [ParamSpec] {
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![ParamSpec::new_object(
|
||||
vec![ParamSpecObject::new(
|
||||
"account",
|
||||
"Account",
|
||||
"The account",
|
||||
|
@ -69,13 +69,7 @@ mod imp {
|
|||
});
|
||||
PROPERTIES.as_ref()
|
||||
}
|
||||
fn set_property(
|
||||
&self,
|
||||
_obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"account" => {
|
||||
let account = value.get().unwrap();
|
||||
|
@ -85,7 +79,7 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> glib::Value {
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"account" => self.account.borrow().to_value(),
|
||||
_ => unimplemented!(),
|
||||
|
@ -118,7 +112,7 @@ impl AccountRow {
|
|||
fn setup_widgets(&self) {
|
||||
let imp = self.imp();
|
||||
self.connect_activate(move |row| {
|
||||
row.activate_action("account.details", None);
|
||||
row.activate_action("account.details", None).unwrap();
|
||||
});
|
||||
|
||||
self.account()
|
||||
|
@ -141,14 +135,12 @@ impl AccountRow {
|
|||
.flags(glib::BindingFlags::DEFAULT | glib::BindingFlags::SYNC_CREATE)
|
||||
.build();
|
||||
|
||||
imp
|
||||
.name_entry
|
||||
imp.name_entry
|
||||
.connect_changed(clone!(@weak imp.actions as actions => move |entry| {
|
||||
let name = entry.text();
|
||||
get_action!(actions, @save).set_enabled(!name.is_empty());
|
||||
}));
|
||||
imp
|
||||
.name_entry
|
||||
imp.name_entry
|
||||
.connect_activate(clone!(@weak imp.actions as actions => move |_| {
|
||||
actions.activate_action("save", None);
|
||||
}));
|
||||
|
@ -169,7 +161,7 @@ impl AccountRow {
|
|||
imp.actions,
|
||||
"details",
|
||||
clone!(@weak self as row => move |_, _| {
|
||||
row.emit_by_name("shared", &[]);
|
||||
row.emit_by_name::<()>("shared", &[]);
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -177,7 +169,7 @@ impl AccountRow {
|
|||
imp.actions,
|
||||
"delete",
|
||||
clone!(@weak self as row => move |_, _| {
|
||||
row.emit_by_name("removed", &[]);
|
||||
row.emit_by_name::<()>("removed", &[]);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
@ -212,8 +212,7 @@ impl Camera {
|
|||
let glsinkbin = gst::ElementFactory::make("glsinkbin", None).unwrap();
|
||||
glsinkbin.set_property("sink", &imp.sink);
|
||||
|
||||
imp
|
||||
.pipeline
|
||||
imp.pipeline
|
||||
.add_many(&[
|
||||
&source_element,
|
||||
&tee,
|
||||
|
@ -298,7 +297,7 @@ impl Camera {
|
|||
let imp = self.imp();
|
||||
match event {
|
||||
CameraEvent::CodeDetected(code) => {
|
||||
self.emit_by_name("code-detected", &[&code]);
|
||||
self.emit_by_name::<()>("code-detected", &[&code]);
|
||||
}
|
||||
CameraEvent::DeviceAdded(device) => {
|
||||
info!("Camera source added: {}", device.display_name());
|
||||
|
|
|
@ -2,18 +2,18 @@ mod accounts;
|
|||
mod camera;
|
||||
mod error_revealer;
|
||||
mod preferences;
|
||||
mod progress_icon;
|
||||
mod providers;
|
||||
mod url_row;
|
||||
mod window;
|
||||
mod progress_icon;
|
||||
|
||||
pub use self::{
|
||||
accounts::{AccountAddDialog, QRCodeData},
|
||||
camera::Camera,
|
||||
error_revealer::ErrorRevealer,
|
||||
preferences::PreferencesWindow,
|
||||
progress_icon::{ProgressIcon, ProgressIconExt},
|
||||
providers::{ProviderImage, ProvidersDialog, ProvidersList},
|
||||
url_row::UrlRow,
|
||||
progress_icon::{ProgressIcon, ProgressIconExt},
|
||||
window::{View, Window},
|
||||
};
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::cell::Cell;
|
|||
|
||||
mod imp {
|
||||
use super::*;
|
||||
use glib::{subclass, ParamSpec};
|
||||
use glib::{subclass, ParamSpec, ParamSpecBoolean, Value};
|
||||
use gtk::subclass::widget::WidgetImplExt;
|
||||
use std::cell::RefCell;
|
||||
|
||||
|
@ -65,7 +65,7 @@ mod imp {
|
|||
fn properties() -> &'static [ParamSpec] {
|
||||
use once_cell::sync::Lazy;
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![ParamSpec::new_boolean(
|
||||
vec![ParamSpecBoolean::new(
|
||||
"has-set-password",
|
||||
"has set password",
|
||||
"Has Set Password",
|
||||
|
@ -75,13 +75,7 @@ mod imp {
|
|||
});
|
||||
PROPERTIES.as_ref()
|
||||
}
|
||||
fn set_property(
|
||||
&self,
|
||||
_obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"has-set-password" => {
|
||||
let has_set_password = value.get().unwrap();
|
||||
|
@ -91,7 +85,7 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> glib::Value {
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"has-set-password" => self.has_set_password.get().to_value(),
|
||||
_ => unimplemented!(),
|
||||
|
@ -113,7 +107,7 @@ glib::wrapper! {
|
|||
|
||||
impl PasswordPage {
|
||||
pub fn new(actions: gio::SimpleActionGroup) -> Self {
|
||||
let page = glib::Object::new(&[]).expect("Failed to create PasswordPage");
|
||||
let page = glib::Object::new::<Self>(&[]).expect("Failed to create PasswordPage");
|
||||
page.imp().actions.set(actions).unwrap();
|
||||
page.setup_widgets();
|
||||
page.setup_actions();
|
||||
|
@ -149,11 +143,9 @@ impl PasswordPage {
|
|||
|
||||
imp.status_page.set_icon_name(Some(config::APP_ID));
|
||||
|
||||
imp
|
||||
.password_entry
|
||||
imp.password_entry
|
||||
.connect_changed(clone!(@weak self as page=> move |_| page.validate()));
|
||||
imp
|
||||
.confirm_password_entry
|
||||
imp.confirm_password_entry
|
||||
.connect_changed(clone!(@weak self as page => move |_| page.validate()));
|
||||
|
||||
self.reset_validation();
|
||||
|
@ -171,8 +163,7 @@ impl PasswordPage {
|
|||
fn reset_validation(&self) {
|
||||
let imp = self.imp();
|
||||
if self.has_set_password() {
|
||||
imp
|
||||
.current_password_entry
|
||||
imp.current_password_entry
|
||||
.connect_changed(clone!(@weak self as page => move |_| page.validate()));
|
||||
} else if let Some(handler_id) = imp.default_password_signal.borrow_mut().take() {
|
||||
imp.current_password_entry.disconnect(handler_id);
|
||||
|
|
|
@ -20,7 +20,7 @@ mod imp {
|
|||
use adw::subclass::{preferences_window::PreferencesWindowImpl, window::AdwWindowImpl};
|
||||
use glib::{
|
||||
subclass::{self, Signal},
|
||||
ParamSpec,
|
||||
ParamSpec, ParamSpecBoolean, Value,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
@ -87,7 +87,7 @@ mod imp {
|
|||
impl ObjectImpl for PreferencesWindow {
|
||||
fn properties() -> &'static [ParamSpec] {
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![ParamSpec::new_boolean(
|
||||
vec![ParamSpecBoolean::new(
|
||||
"has-set-password",
|
||||
"has set password",
|
||||
"Has Set Password",
|
||||
|
@ -109,13 +109,7 @@ mod imp {
|
|||
SIGNALS.as_ref()
|
||||
}
|
||||
|
||||
fn set_property(
|
||||
&self,
|
||||
_obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"has-set-password" => {
|
||||
let has_set_password = value.get().unwrap();
|
||||
|
@ -125,7 +119,7 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> glib::Value {
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"has-set-password" => self.has_set_password.get().to_value(),
|
||||
_ => unimplemented!(),
|
||||
|
@ -150,7 +144,7 @@ glib::wrapper! {
|
|||
|
||||
impl PreferencesWindow {
|
||||
pub fn new(model: ProvidersModel) -> Self {
|
||||
let window = glib::Object::new(&[]).expect("Failed to create PreferencesWindow");
|
||||
let window = glib::Object::new::<Self>(&[]).expect("Failed to create PreferencesWindow");
|
||||
window.imp().model.set(model).unwrap();
|
||||
window.setup_widgets();
|
||||
window
|
||||
|
@ -167,21 +161,17 @@ impl PreferencesWindow {
|
|||
fn setup_widgets(&self) {
|
||||
let imp = self.imp();
|
||||
|
||||
imp
|
||||
.settings
|
||||
imp.settings
|
||||
.bind("dark-theme", &*imp.dark_theme, "active")
|
||||
.build();
|
||||
imp
|
||||
.settings
|
||||
imp.settings
|
||||
.bind("auto-lock", &*imp.auto_lock, "active")
|
||||
.build();
|
||||
imp
|
||||
.settings
|
||||
imp.settings
|
||||
.bind("auto-lock-timeout", &*imp.lock_timeout, "value")
|
||||
.build();
|
||||
|
||||
imp
|
||||
.password_page
|
||||
imp.password_page
|
||||
.bind_property("has-set-password", self, "has-set-password")
|
||||
.flags(glib::BindingFlags::BIDIRECTIONAL | glib::BindingFlags::SYNC_CREATE)
|
||||
.build();
|
||||
|
@ -198,7 +188,7 @@ impl PreferencesWindow {
|
|||
fn register_backup<T: Backupable>(&self, filters: &'static [&str]) {
|
||||
let imp = self.imp();
|
||||
|
||||
let row = adw::ActionRowBuilder::new()
|
||||
let row = adw::ActionRow::builder()
|
||||
.title(&T::title())
|
||||
.subtitle(&T::subtitle())
|
||||
.activatable(true)
|
||||
|
@ -229,7 +219,7 @@ impl PreferencesWindow {
|
|||
fn register_restore<T: Restorable>(&self, filters: &'static [&str]) {
|
||||
let imp = self.imp();
|
||||
|
||||
let row = adw::ActionRowBuilder::new()
|
||||
let row = adw::ActionRow::builder()
|
||||
.title(&T::title())
|
||||
.subtitle(&T::subtitle())
|
||||
.activatable(true)
|
||||
|
@ -272,7 +262,7 @@ impl PreferencesWindow {
|
|||
warn!("Failed to restore item {}", err);
|
||||
}
|
||||
});
|
||||
self.emit_by_name("restore-completed", &[]);
|
||||
self.emit_by_name::<()>("restore-completed", &[]);
|
||||
}
|
||||
|
||||
fn select_file(
|
||||
|
@ -316,14 +306,12 @@ impl PreferencesWindow {
|
|||
fn setup_actions(&self) {
|
||||
let imp = self.imp();
|
||||
|
||||
imp
|
||||
.password_page
|
||||
imp.password_page
|
||||
.connect_map(clone!(@weak self as win => move |_| {
|
||||
win.set_search_enabled(false);
|
||||
}));
|
||||
|
||||
imp
|
||||
.password_page
|
||||
imp.password_page
|
||||
.connect_unmap(clone!(@weak self as win => move |_| {
|
||||
win.set_search_enabled(true);
|
||||
}));
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
use gtk::{glib, gdk};
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{gdk, glib};
|
||||
|
||||
pub(crate) mod imp {
|
||||
use super::*;
|
||||
use glib::{ParamSpec, ParamSpecBoolean, ParamSpecFloat, Value};
|
||||
use gtk::{graphene, gsk};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use std::cell::RefCell;
|
||||
use std::cell::Cell;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ProgressIcon {
|
||||
pub progress: RefCell<f32>,
|
||||
pub inverted: RefCell<bool>,
|
||||
pub clockwise: RefCell<bool>,
|
||||
pub progress: Cell<f32>,
|
||||
pub inverted: Cell<bool>,
|
||||
pub clockwise: Cell<bool>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
@ -24,18 +24,18 @@ pub(crate) mod imp {
|
|||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
progress: RefCell::new(0.0),
|
||||
inverted: RefCell::new(false),
|
||||
clockwise: RefCell::new(true),
|
||||
progress: Cell::new(0.0),
|
||||
inverted: Cell::new(false),
|
||||
clockwise: Cell::new(true),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for ProgressIcon {
|
||||
fn properties() -> &'static [glib::ParamSpec] {
|
||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
||||
fn properties() -> &'static [ParamSpec] {
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![
|
||||
glib::ParamSpec::new_float(
|
||||
ParamSpecFloat::new(
|
||||
"progress",
|
||||
"Progress",
|
||||
"Progress of the icon",
|
||||
|
@ -44,14 +44,14 @@ pub(crate) mod imp {
|
|||
0.0,
|
||||
glib::ParamFlags::READWRITE | glib::ParamFlags::EXPLICIT_NOTIFY,
|
||||
),
|
||||
glib::ParamSpec::new_boolean(
|
||||
ParamSpecBoolean::new(
|
||||
"inverted",
|
||||
"Inverted",
|
||||
"Invert icon colors",
|
||||
false,
|
||||
glib::ParamFlags::READWRITE | glib::ParamFlags::EXPLICIT_NOTIFY,
|
||||
),
|
||||
glib::ParamSpec::new_boolean(
|
||||
ParamSpecBoolean::new(
|
||||
"clockwise",
|
||||
"Clockwise",
|
||||
"Direction of the icon",
|
||||
|
@ -63,7 +63,7 @@ pub(crate) mod imp {
|
|||
PROPERTIES.as_ref()
|
||||
}
|
||||
|
||||
fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
||||
fn property(&self, obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"progress" => obj.progress().to_value(),
|
||||
"inverted" => obj.inverted().to_value(),
|
||||
|
@ -72,13 +72,7 @@ pub(crate) mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn set_property(
|
||||
&self,
|
||||
obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &glib::ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"progress" => obj.set_progress(value.get().unwrap()),
|
||||
"inverted" => obj.set_inverted(value.get().unwrap()),
|
||||
|
@ -161,7 +155,6 @@ impl Default for ProgressIcon {
|
|||
}
|
||||
|
||||
impl ProgressIcon {
|
||||
|
||||
/// Creates a new [`ProgressIcon`].
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
|
@ -203,7 +196,7 @@ pub trait ProgressIconExt {
|
|||
|
||||
impl<W: IsA<ProgressIcon>> ProgressIconExt for W {
|
||||
fn progress(&self) -> f32 {
|
||||
*self.as_ref().imp().progress.borrow()
|
||||
self.as_ref().imp().progress.get()
|
||||
}
|
||||
fn set_progress(&self, progress: f32) {
|
||||
if (progress - self.progress()).abs() < f32::EPSILON {
|
||||
|
@ -216,7 +209,7 @@ impl<W: IsA<ProgressIcon>> ProgressIconExt for W {
|
|||
}
|
||||
|
||||
fn inverted(&self) -> bool {
|
||||
*self.as_ref().imp().inverted.borrow()
|
||||
self.as_ref().imp().inverted.get()
|
||||
}
|
||||
fn set_inverted(&self, inverted: bool) {
|
||||
if inverted == self.inverted() {
|
||||
|
@ -228,7 +221,7 @@ impl<W: IsA<ProgressIcon>> ProgressIconExt for W {
|
|||
}
|
||||
|
||||
fn clockwise(&self) -> bool {
|
||||
*self.as_ref().imp().clockwise.borrow()
|
||||
self.as_ref().imp().clockwise.get()
|
||||
}
|
||||
|
||||
fn set_clockwise(&self, clockwise: bool) {
|
||||
|
@ -256,4 +249,3 @@ impl<W: IsA<ProgressIcon>> ProgressIconExt for W {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,8 +103,7 @@ impl ProvidersDialog {
|
|||
imp.filter_model.set_model(Some(&model));
|
||||
|
||||
let stack = &*imp.stack;
|
||||
imp
|
||||
.filter_model
|
||||
imp.filter_model
|
||||
.connect_items_changed(clone!(@weak stack => move |model, _, _, _| {
|
||||
if model.n_items() == 0 {
|
||||
stack.set_visible_child_name("no-results");
|
||||
|
@ -161,8 +160,8 @@ impl ProvidersDialog {
|
|||
let selection_model = gtk::NoSelection::new(Some(&sort_model));
|
||||
imp.providers_list.set_model(Some(&selection_model));
|
||||
|
||||
imp.providers_list.connect_activate(
|
||||
clone!(@weak self as dialog => move |listview, pos| {
|
||||
imp.providers_list
|
||||
.connect_activate(clone!(@weak self as dialog => move |listview, pos| {
|
||||
let model = listview.model().unwrap();
|
||||
let provider = model
|
||||
.item(pos)
|
||||
|
@ -170,8 +169,7 @@ impl ProvidersDialog {
|
|||
.downcast::<Provider>()
|
||||
.unwrap();
|
||||
dialog.edit_provider(provider);
|
||||
}),
|
||||
);
|
||||
}));
|
||||
|
||||
imp.page.connect_local(
|
||||
"created",
|
||||
|
@ -180,7 +178,7 @@ impl ProvidersDialog {
|
|||
let provider = args.get(1).unwrap().get::<Provider>().unwrap();
|
||||
model.add_provider(&provider);
|
||||
dialog.set_view(View::List);
|
||||
dialog.emit_by_name("changed", &[]);
|
||||
dialog.emit_by_name::<()>("changed", &[]);
|
||||
None
|
||||
}),
|
||||
);
|
||||
|
@ -190,7 +188,7 @@ impl ProvidersDialog {
|
|||
false,
|
||||
clone!(@weak self as dialog => @default-return None, move |_| {
|
||||
dialog.set_view(View::List);
|
||||
dialog.emit_by_name("changed", &[]);
|
||||
dialog.emit_by_name::<()>("changed", &[]);
|
||||
None
|
||||
}),
|
||||
);
|
||||
|
@ -202,11 +200,11 @@ impl ProvidersDialog {
|
|||
let provider = args.get(1).unwrap().get::<Provider>().unwrap();
|
||||
model.delete_provider(&provider);
|
||||
dialog.set_view(View::List);
|
||||
dialog.emit_by_name("changed", &[]);
|
||||
dialog.emit_by_name::<()>("changed", &[]);
|
||||
None
|
||||
}),
|
||||
);
|
||||
let deck_page = imp.deck.append(&imp.page).unwrap();
|
||||
let deck_page = imp.deck.append(&imp.page);
|
||||
deck_page.set_name(Some("provider"));
|
||||
self.set_view(View::List);
|
||||
}
|
||||
|
@ -284,7 +282,7 @@ mod row {
|
|||
use super::*;
|
||||
mod imp {
|
||||
use super::*;
|
||||
use glib::ParamSpec;
|
||||
use glib::{ParamSpec, ParamSpecObject, Value};
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub struct ProviderActionRow {
|
||||
|
@ -315,7 +313,7 @@ mod row {
|
|||
fn properties() -> &'static [ParamSpec] {
|
||||
use once_cell::sync::Lazy;
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![ParamSpec::new_object(
|
||||
vec![ParamSpecObject::new(
|
||||
"provider",
|
||||
"Provider",
|
||||
"The Provider",
|
||||
|
@ -330,7 +328,7 @@ mod row {
|
|||
&self,
|
||||
_obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
value: &Value,
|
||||
pspec: &ParamSpec,
|
||||
) {
|
||||
match pspec.name() {
|
||||
|
@ -342,7 +340,7 @@ mod row {
|
|||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> glib::Value {
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"provider" => self.provider.borrow().to_value(),
|
||||
_ => unimplemented!(),
|
||||
|
@ -370,7 +368,7 @@ mod row {
|
|||
|
||||
fn setup_widgets(&self) {
|
||||
let imp = self.imp();
|
||||
let hbox = gtk::BoxBuilder::new()
|
||||
let hbox = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.margin_bottom(16)
|
||||
.margin_end(16)
|
||||
|
|
|
@ -10,7 +10,7 @@ pub enum ImageAction {
|
|||
|
||||
mod imp {
|
||||
use super::*;
|
||||
use glib::{subclass, ParamSpec};
|
||||
use glib::{subclass, ParamSpec, ParamSpecObject, ParamSpecUInt, Value};
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
||||
#[derive(Debug, CompositeTemplate)]
|
||||
|
@ -67,14 +67,14 @@ mod imp {
|
|||
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![
|
||||
ParamSpec::new_object(
|
||||
ParamSpecObject::new(
|
||||
"provider",
|
||||
"provider",
|
||||
"Provider",
|
||||
Provider::static_type(),
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_uint(
|
||||
ParamSpecUInt::new(
|
||||
"size",
|
||||
"size",
|
||||
"Image size",
|
||||
|
@ -87,13 +87,7 @@ mod imp {
|
|||
});
|
||||
PROPERTIES.as_ref()
|
||||
}
|
||||
fn set_property(
|
||||
&self,
|
||||
_obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"provider" => {
|
||||
let provider = value.get().unwrap();
|
||||
|
@ -107,7 +101,7 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> glib::Value {
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"provider" => self.provider.borrow().to_value(),
|
||||
"size" => self.size.get().to_value(),
|
||||
|
@ -190,7 +184,9 @@ impl ProviderImage {
|
|||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
self.imp().image.set_from_icon_name(Some("provider-fallback"));
|
||||
self.imp()
|
||||
.image
|
||||
.set_from_icon_name(Some("provider-fallback"));
|
||||
self.fetch();
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ impl ProvidersList {
|
|||
row.connect_local("shared", false, clone!(@weak list => @default-return None, move |args| {
|
||||
let account = args.get(1).unwrap().get::<Account>().unwrap();
|
||||
|
||||
list.emit_by_name("shared", &[&account]);
|
||||
list.emit_by_name::<()>("shared", &[&account]);
|
||||
None
|
||||
}));
|
||||
|
||||
|
|
|
@ -165,51 +165,41 @@ impl ProviderPage {
|
|||
}
|
||||
|
||||
imp.algorithm_comborow.set_selected(
|
||||
imp
|
||||
.algorithms_model
|
||||
imp.algorithms_model
|
||||
.find_position(provider.algorithm().into_glib()),
|
||||
);
|
||||
|
||||
imp
|
||||
.default_counter_spinbutton
|
||||
imp.default_counter_spinbutton
|
||||
.set_value(provider.default_counter() as f64);
|
||||
imp.digits_spinbutton.set_value(provider.digits() as f64);
|
||||
|
||||
imp.method_comborow.set_selected(
|
||||
imp
|
||||
.methods_model
|
||||
imp.methods_model
|
||||
.find_position(provider.method().into_glib()),
|
||||
);
|
||||
imp.image.set_provider(Some(&provider));
|
||||
imp
|
||||
.title
|
||||
imp.title
|
||||
.set_text(&i18n::i18n_f("Editing Provider: {}", &[&provider.name()]));
|
||||
imp.selected_provider.replace(Some(provider));
|
||||
} else {
|
||||
imp.name_entry.set_text("");
|
||||
imp.delete_button.hide();
|
||||
imp
|
||||
.period_spinbutton
|
||||
imp.period_spinbutton
|
||||
.set_value(otp::TOTP_DEFAULT_PERIOD as f64);
|
||||
imp.provider_website_entry.set_text("");
|
||||
imp.provider_help_entry.set_text("");
|
||||
|
||||
imp.algorithm_comborow.set_selected(
|
||||
imp
|
||||
.algorithms_model
|
||||
imp.algorithms_model
|
||||
.find_position(Algorithm::default().into_glib()),
|
||||
);
|
||||
|
||||
imp
|
||||
.default_counter_spinbutton
|
||||
imp.default_counter_spinbutton
|
||||
.set_value(otp::HOTP_DEFAULT_COUNTER as f64);
|
||||
imp
|
||||
.digits_spinbutton
|
||||
.set_value(otp::DEFAULT_DIGITS as f64);
|
||||
imp.digits_spinbutton.set_value(otp::DEFAULT_DIGITS as f64);
|
||||
|
||||
imp.method_comborow.set_selected(
|
||||
imp
|
||||
.methods_model
|
||||
imp.methods_model
|
||||
.find_position(OTPMethod::default().into_glib()),
|
||||
);
|
||||
imp.image.set_provider(None);
|
||||
|
@ -296,7 +286,7 @@ impl ProviderPage {
|
|||
algorithm: algorithm.to_string(),
|
||||
method: method.to_string(),
|
||||
})?;
|
||||
self.emit_by_name("updated", &[&provider]);
|
||||
self.emit_by_name::<()>("updated", &[&provider]);
|
||||
} else {
|
||||
let provider = Provider::create(
|
||||
&name,
|
||||
|
@ -309,7 +299,7 @@ impl ProviderPage {
|
|||
Some(help_url),
|
||||
image_uri,
|
||||
)?;
|
||||
self.emit_by_name("created", &[&provider]);
|
||||
self.emit_by_name::<()>("created", &[&provider]);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -318,7 +308,7 @@ impl ProviderPage {
|
|||
let imp = self.imp();
|
||||
let parent = self.root().unwrap().downcast::<gtk::Window>().unwrap();
|
||||
|
||||
let file_chooser = gtk::FileChooserNativeBuilder::new()
|
||||
let file_chooser = gtk::FileChooserNative::builder()
|
||||
.accept_label(&gettext("Select"))
|
||||
.cancel_label(&gettext("Cancel"))
|
||||
.modal(true)
|
||||
|
@ -365,7 +355,7 @@ impl ProviderPage {
|
|||
"The provider has accounts assigned to it, please remove them first",
|
||||
));
|
||||
} else if provider.delete().is_ok() {
|
||||
self.emit_by_name("deleted", &[&provider]);
|
||||
self.emit_by_name::<()>("deleted", &[&provider]);
|
||||
}
|
||||
} else {
|
||||
anyhow::bail!("Can't remove a provider as none are selected");
|
||||
|
@ -413,12 +403,10 @@ impl ProviderPage {
|
|||
|
||||
fn setup_widgets(&self) {
|
||||
let imp = self.imp();
|
||||
imp
|
||||
.algorithm_comborow
|
||||
imp.algorithm_comborow
|
||||
.set_model(Some(&imp.algorithms_model));
|
||||
|
||||
imp
|
||||
.method_comborow
|
||||
imp.method_comborow
|
||||
.connect_selected_item_notify(clone!(@weak self as page => move |_| {
|
||||
page.on_method_changed();
|
||||
}));
|
||||
|
@ -428,8 +416,7 @@ impl ProviderPage {
|
|||
});
|
||||
|
||||
imp.name_entry.connect_changed(validate_cb.clone());
|
||||
imp
|
||||
.provider_website_entry
|
||||
imp.provider_website_entry
|
||||
.connect_changed(validate_cb.clone());
|
||||
imp.provider_help_entry.connect_changed(validate_cb);
|
||||
|
||||
|
@ -444,40 +431,30 @@ impl ProviderPage {
|
|||
OTPMethod::TOTP => {
|
||||
imp.default_counter_row.hide();
|
||||
imp.period_row.show();
|
||||
imp
|
||||
.digits_spinbutton
|
||||
.set_value(otp::DEFAULT_DIGITS as f64);
|
||||
imp
|
||||
.period_spinbutton
|
||||
imp.digits_spinbutton.set_value(otp::DEFAULT_DIGITS as f64);
|
||||
imp.period_spinbutton
|
||||
.set_value(otp::TOTP_DEFAULT_PERIOD as f64);
|
||||
}
|
||||
OTPMethod::HOTP => {
|
||||
imp.default_counter_row.show();
|
||||
imp.period_row.hide();
|
||||
imp
|
||||
.default_counter_spinbutton
|
||||
imp.default_counter_spinbutton
|
||||
.set_value(otp::HOTP_DEFAULT_COUNTER as f64);
|
||||
imp
|
||||
.digits_spinbutton
|
||||
.set_value(otp::DEFAULT_DIGITS as f64);
|
||||
imp.digits_spinbutton.set_value(otp::DEFAULT_DIGITS as f64);
|
||||
}
|
||||
OTPMethod::Steam => {
|
||||
imp.default_counter_row.hide();
|
||||
imp.period_row.show();
|
||||
imp
|
||||
.digits_spinbutton
|
||||
imp.digits_spinbutton
|
||||
.set_value(otp::STEAM_DEFAULT_DIGITS as f64);
|
||||
imp
|
||||
.period_spinbutton
|
||||
imp.period_spinbutton
|
||||
.set_value(otp::STEAM_DEFAULT_PERIOD as f64);
|
||||
imp
|
||||
.algorithm_comborow
|
||||
imp.algorithm_comborow
|
||||
.set_selected(Algorithm::default().into_glib() as u32);
|
||||
}
|
||||
}
|
||||
|
||||
imp
|
||||
.algorithm_comborow
|
||||
imp.algorithm_comborow
|
||||
.set_sensitive(selected != OTPMethod::Steam);
|
||||
imp.period_row.set_sensitive(selected != OTPMethod::Steam);
|
||||
imp.digits_row.set_sensitive(selected != OTPMethod::Steam);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
models::{Account, AccountSorter, OTPMethod, Provider},
|
||||
widgets::{accounts::AccountRow, ProviderImage, ProgressIcon, ProgressIconExt},
|
||||
widgets::{accounts::AccountRow, ProgressIcon, ProgressIconExt, ProviderImage},
|
||||
};
|
||||
use gtk::{glib, glib::clone, prelude::*, subclass::prelude::*, CompositeTemplate};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
@ -9,7 +9,7 @@ mod imp {
|
|||
use super::*;
|
||||
use glib::{
|
||||
subclass::{self, Signal},
|
||||
ParamSpec,
|
||||
ParamSpec, ParamSpecObject, ParamSpecUInt64, Value,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
@ -63,14 +63,14 @@ mod imp {
|
|||
fn properties() -> &'static [ParamSpec] {
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![
|
||||
ParamSpec::new_object(
|
||||
ParamSpecObject::new(
|
||||
"provider",
|
||||
"Provider",
|
||||
"The accounts provider",
|
||||
Provider::static_type(),
|
||||
glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT_ONLY,
|
||||
),
|
||||
ParamSpec::new_uint64(
|
||||
ParamSpecUInt64::new(
|
||||
"remaining-time",
|
||||
"remaining time",
|
||||
"the remaining time",
|
||||
|
@ -102,13 +102,7 @@ mod imp {
|
|||
SIGNALS.as_ref()
|
||||
}
|
||||
|
||||
fn set_property(
|
||||
&self,
|
||||
_obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"provider" => {
|
||||
let provider = value.get().unwrap();
|
||||
|
@ -122,7 +116,7 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> glib::Value {
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"provider" => self.provider.borrow().to_value(),
|
||||
"remaining-time" => self.remaining_time.get().to_value(),
|
||||
|
@ -235,8 +229,7 @@ impl ProviderRow {
|
|||
}),
|
||||
);
|
||||
|
||||
imp
|
||||
.callback_id
|
||||
imp.callback_id
|
||||
.replace(Some(self.add_tick_callback(|row, _| {
|
||||
row.tick_progressbar();
|
||||
glib::Continue(true)
|
||||
|
@ -264,7 +257,7 @@ impl ProviderRow {
|
|||
clone!(@weak provider, @weak account, @weak provider_row => @default-return None, move |_| {
|
||||
account.delete().unwrap();
|
||||
provider.remove_account(account);
|
||||
provider_row.emit_by_name("changed", &[]);
|
||||
provider_row.emit_by_name::<()>("changed", &[]);
|
||||
None
|
||||
}),
|
||||
);
|
||||
|
@ -273,7 +266,7 @@ impl ProviderRow {
|
|||
"shared",
|
||||
false,
|
||||
clone!(@weak account, @weak provider_row => @default-return None, move |_| {
|
||||
provider_row.emit_by_name("shared", &[&account]);
|
||||
provider_row.emit_by_name::<()>("shared", &[&account]);
|
||||
None
|
||||
}),
|
||||
);
|
||||
|
@ -283,15 +276,14 @@ impl ProviderRow {
|
|||
clone!(@weak provider_row, @weak sorter => @default-return None, move |_| {
|
||||
// Re-sort in case the name was updated
|
||||
sorter.changed(gtk::SorterChange::Different);
|
||||
provider_row.emit_by_name("changed", &[]);
|
||||
provider_row.emit_by_name::<()>("changed", &[]);
|
||||
None
|
||||
}),
|
||||
);
|
||||
row.upcast::<gtk::Widget>()
|
||||
});
|
||||
|
||||
imp
|
||||
.accounts_list
|
||||
imp.accounts_list
|
||||
.bind_model(Some(&sort_model), create_callback);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use gtk::{glib, subclass::prelude::*};
|
|||
mod imp {
|
||||
use super::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use glib::ParamSpec;
|
||||
use glib::{ParamSpec, ParamSpecString, Value};
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
@ -26,14 +26,14 @@ mod imp {
|
|||
use once_cell::sync::Lazy;
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![
|
||||
ParamSpec::new_string(
|
||||
ParamSpecString::new(
|
||||
"uri",
|
||||
"uri",
|
||||
"The Row URI",
|
||||
None,
|
||||
glib::ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpec::new_string(
|
||||
ParamSpecString::new(
|
||||
"icon-name",
|
||||
"icon name",
|
||||
"The Icon Name",
|
||||
|
@ -45,13 +45,7 @@ mod imp {
|
|||
PROPERTIES.as_ref()
|
||||
}
|
||||
|
||||
fn set_property(
|
||||
&self,
|
||||
_obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"uri" => {
|
||||
let uri = value.get().unwrap();
|
||||
|
@ -65,7 +59,7 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> glib::Value {
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"uri" => self.uri.borrow().to_value(),
|
||||
"icon-name" => self.icon_name.borrow().to_value(),
|
||||
|
@ -102,13 +96,13 @@ impl UrlRow {
|
|||
|
||||
self.add_controller(&gesture);
|
||||
|
||||
let image_prefix = gtk::Image::from_icon_name(Some("image-missing-symbolic"));
|
||||
let image_prefix = gtk::Image::from_icon_name("image-missing-symbolic");
|
||||
self.bind_property("icon-name", &image_prefix, "icon-name")
|
||||
.flags(glib::BindingFlags::DEFAULT | glib::BindingFlags::SYNC_CREATE)
|
||||
.build();
|
||||
self.add_prefix(&image_prefix);
|
||||
|
||||
let image_suffix = gtk::Image::from_icon_name(Some("link-symbolic"));
|
||||
let image_suffix = gtk::Image::from_icon_name("link-symbolic");
|
||||
image_suffix.add_css_class("dim-label");
|
||||
self.add_suffix(&image_suffix);
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ impl Window {
|
|||
}
|
||||
|
||||
fn init(&self, model: ProvidersModel, app: &Application) {
|
||||
let imp =self.imp();
|
||||
let imp = self.imp();
|
||||
imp.model.set(model.clone()).unwrap();
|
||||
imp.providers.set_model(model);
|
||||
imp.providers.connect_local(
|
||||
|
@ -217,12 +217,14 @@ impl Window {
|
|||
// load latest window state
|
||||
window_state::load(&self, &imp.settings);
|
||||
// save window state on delete event
|
||||
self.connect_close_request(clone!(@weak imp.settings as settings => @default-return Inhibit(false), move |window| {
|
||||
self.connect_close_request(
|
||||
clone!(@weak imp.settings as settings => @default-return Inhibit(false), move |window| {
|
||||
if let Err(err) = window_state::save(&window, &settings) {
|
||||
warn!("Failed to save window state {:#?}", err);
|
||||
}
|
||||
Inhibit(false)
|
||||
}));
|
||||
}),
|
||||
);
|
||||
|
||||
let search_entry = &*imp.search_entry;
|
||||
let search_btn = &*imp.search_btn;
|
||||
|
@ -250,8 +252,7 @@ impl Window {
|
|||
}));
|
||||
|
||||
let gtk_settings = gtk::Settings::default().unwrap();
|
||||
imp
|
||||
.settings
|
||||
imp.settings
|
||||
.bind(
|
||||
"dark-theme",
|
||||
>k_settings,
|
||||
|
@ -261,7 +262,7 @@ impl Window {
|
|||
}
|
||||
|
||||
fn setup_actions(&self, app: &Application) {
|
||||
let imp =self.imp();
|
||||
let imp = self.imp();
|
||||
let search_btn = &*imp.search_btn;
|
||||
action!(
|
||||
self,
|
||||
|
@ -327,17 +328,15 @@ impl Window {
|
|||
}),
|
||||
);
|
||||
|
||||
let imp =self.imp();
|
||||
let imp = self.imp();
|
||||
|
||||
imp
|
||||
.password_entry
|
||||
imp.password_entry
|
||||
.connect_activate(clone!(@weak self as win => move |_| {
|
||||
WidgetExt::activate_action(&win, "win.unlock", None);
|
||||
WidgetExt::activate_action(&win, "win.unlock", None).unwrap();
|
||||
}));
|
||||
|
||||
// On each click or key pressed we restart the timeout.
|
||||
imp
|
||||
.click_gesture
|
||||
imp.click_gesture
|
||||
.connect_pressed(clone!(@weak app => move |_, _, _, _| {
|
||||
app.restart_lock_timeout();
|
||||
}));
|
||||
|
|
Loading…
Add table
Reference in a new issue