bunch of small fixes

This commit is contained in:
Bilal Elmoussaoui 2020-11-08 19:05:00 +01:00
parent 5dbda93bb0
commit b9fa684e75
16 changed files with 56 additions and 102 deletions

View file

@ -19,7 +19,7 @@ endforeach
resources = gnome.compile_resources(
application_id,
'com.belmoussaoui.Authenticator.gresource.xml',
'resources.gresource.xml',
gresource_bundle: true,
dependencies: ui_dependencies
)

View file

@ -4,7 +4,9 @@
<file alias="style.css">resources/style.css</file>
<!-- Accounts -->
<file compressed="true" preprocess="xml-stripblanks" alias="add_account.ui">resources/ui/add_account.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="account_add.ui">resources/ui/account_add.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="account_edit.ui">resources/ui/account_edit.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="account_row.ui">resources/ui/account_row.ui</file>
<!-- Providers -->
<file compressed="true" preprocess="xml-stripblanks" alias="provider_row.ui">resources/ui/provider_row.ui</file>
@ -13,14 +15,11 @@
<!-- UI Files -->
<file compressed="true" preprocess="xml-stripblanks" alias="shortcuts.ui">resources/ui/shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="about_dialog.ui">about_dialog.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="account_edit.ui">resources/ui/account_edit.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="account_row.ui">resources/ui/account_row.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="accounts_widget.ui">resources/ui/accounts_widget.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="provider_image.ui">resources/ui/provider_image.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="password_widget.ui">resources/ui/password_widget.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="window.ui">window.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="settings.ui">settings.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="provider_image.ui">resources/ui/provider_image.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="password_widget.ui">resources/ui/password_widget.ui</file>
</gresource>
<gresource prefix="/com/belmoussaoui/Authenticator/icons/16x16/actions">
<file alias="qrscanner-symbolic.svg">resources/icons/qrscanner-symbolic.svg</file>

View file

@ -1,12 +1,12 @@
.providers-list {
background-color: @theme_base_bg;
margin-top: 20px;
}
.provider-row {
margin-top: 12px;
margin-bottom: 12px;
}
.provider-row:hover {
background-color: @theme_base_bg;
}
@ -17,6 +17,7 @@
}
.provider-row .title-2 {
margin-bottom: 8px;
margin-left: 2px;
}
.account-row {

View file

@ -2,8 +2,8 @@
<interface>
<object class="HdyWindow" id="add_dialog">
<property name="modal">True</property>
<property name="default_width">560</property>
<property name="default_height">720</property>
<property name="default_width">360</property>
<property name="default_height">600</property>
<property name="title">Add a new account</property>
<property name="destroy_with_parent">True</property>
<child>
@ -57,6 +57,8 @@
<object class="GtkBox" id="main_container">
<property name="orientation">vertical</property>
<property name="spacing">42</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<child>
<object class="GtkStack" id="image_stack">
<property name="transition-type">crossfade</property>

View file

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkBox" id="providers_list">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
<child>
<object class="GtkViewport">
<child>
<object class="HdyColumn">
<property name="maximum_width">600</property>
<property name="linear_growth_width">600</property>
<child>
<object class="GtkBox" id="providers_container">
<property name="valign">start</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<style>
<class name="accounts-widget"/>
</style>
</object>
</interface>

View file

@ -14,6 +14,8 @@
<object class="GtkListBox" id="providers_list">
<property name="selection-mode">none</property>
<property name="margin-start">6</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="margin-end">6</property>
<child type="placeholder">
<object class="GtkBox">

View file

@ -22,7 +22,7 @@
<property name="can-unfold">False</property>
<child>
<object class="HdyLeafletPage">
<property name="name">empty</property>
<property name="name">accounts</property>
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
@ -49,6 +49,9 @@
<property name="icon-name">system-search-symbolic</property>
</object>
</child>
<style>
<class name="titlebar"/>
</style>
</object>
</child>
<child>

View file

@ -1,6 +1,6 @@
use crate::config;
use crate::models::{Account, Provider, ProvidersModel};
use crate::widgets::{AddAccountDialog, View, Window};
use crate::widgets::{AddAccountDialog, Window};
use gio::prelude::*;
use glib::subclass;
use glib::subclass::prelude::*;
@ -12,7 +12,6 @@ use std::{cell::RefCell, rc::Rc};
use glib::{Receiver, Sender};
pub enum Action {
ViewAccounts,
AccountCreated(Account, Provider),
OpenAddAccountDialog,
}
@ -81,10 +80,6 @@ impl ApplicationImpl for ApplicationPrivate {
about_dialog.show();
})
);
app_.set_accels_for_action("app.quit", &["<primary>q"]);
app_.set_accels_for_action("win.show-help-overlay", &["<primary>question"]);
app_.set_accels_for_action("win.search", &["<primary>f"]);
app_.set_accels_for_action("win.add-account", &["<primary>n"]);
}
fn activate(&self, _app: &gio::Application) {
@ -100,6 +95,11 @@ impl ApplicationImpl for ApplicationPrivate {
window.present();
self.window.replace(Some(window));
app.set_accels_for_action("app.quit", &["<primary>q"]);
app.set_accels_for_action("win.show-help-overlay", &["<primary>question"]);
app.set_accels_for_action("win.search", &["<primary>f"]);
app.set_accels_for_action("win.add-account", &["<primary>n"]);
let receiver = self.receiver.borrow_mut().take().unwrap();
receiver.attach(None, move |action| app.do_action(action));
}
@ -146,16 +146,15 @@ impl Application {
fn do_action(&self, action: Action) -> glib::Continue {
let self_ = ApplicationPrivate::from_instance(self);
let active_window = self.get_active_window().unwrap();
match action {
Action::OpenAddAccountDialog => {
let dialog = AddAccountDialog::new(self_.model.clone(), self_.sender.clone());
//dialog.widget.set_transient_for(Some(&self_.window));
dialog.widget.set_transient_for(Some(&active_window));
dialog.widget.show();
}
Action::ViewAccounts => (), //self.set_view(View::Accounts),
Action::AccountCreated(account, provider) => {
self_.model.add_account(&account, &provider);
println!("{:#?}", account);
}
};

View file

@ -2,13 +2,10 @@ use super::provider::{DiProvider, Provider};
use crate::models::database;
use crate::schema::accounts;
use anyhow::Result;
use diesel::RunQueryDsl;
use diesel::{ExpressionMethods, QueryDsl};
use glib::subclass;
use glib::subclass::prelude::*;
use diesel::{BelongingToDsl, ExpressionMethods, QueryDsl, RunQueryDsl};
use glib::subclass::{self, prelude::*};
use glib::translate::*;
use glib::Cast;
use glib::{StaticType, ToValue};
use glib::{Cast, StaticType, ToValue};
use std::cell::{Cell, RefCell};
#[derive(Insertable)]
@ -165,13 +162,11 @@ impl Account {
}
pub fn load(p: &Provider) -> Result<Vec<Self>> {
use crate::schema::accounts::dsl::accounts;
use crate::schema::accounts::provider_id;
let db = database::connection();
let conn = db.get()?;
let results = accounts
.filter(provider_id.eq(p.id()))
let dip: DiProvider = p.into();
let results = DiAccount::belonging_to(&dip)
.load::<DiAccount>(&conn)?
.into_iter()
.map(From::from)

View file

@ -40,23 +40,3 @@ fn init_pool() -> Result<Pool> {
info!("Database pool initialized.");
Ok(pool)
}
/*
pub fn get_accounts_by_provider(provider_model: Provider) -> Result<Vec<Account>> {
use crate::schema::accounts::dsl::*;
let db = connection();
let conn = db.get()?;
accounts
.filter(provider_id.eq(provider_model.id()))
.load::<Account>(&conn)
.map_err(From::from)
}
pub fn get_accounts() -> Result<Vec<Account>> {
use crate::schema::accounts::dsl::*;
let db = connection();
let conn = db.get()?;
accounts.load::<Account>(&conn).map_err(From::from)
}
*/

View file

@ -196,13 +196,6 @@ impl ObjectImpl for ProviderPriv {
.expect("type conformity checked by `Object::set_property`");
self.image_uri.replace(image_uri);
}
/*subclass::Property("accounts", ..) => {
let accounts = value
.get()
.expect("type conformity checked by `Object::set_property`")
.unwrap();
self.accounts.replace(accounts);
}*/
_ => unimplemented!(),
}
}
@ -218,7 +211,6 @@ impl ObjectImpl for ProviderPriv {
subclass::Property("website", ..) => Ok(self.website.borrow().to_value()),
subclass::Property("help-url", ..) => Ok(self.help_url.borrow().to_value()),
subclass::Property("image-uri", ..) => Ok(self.image_uri.borrow().to_value()),
//subclass::Property("accounts", ..) => Ok(self.accounts.borrow().to_value()),
_ => unimplemented!(),
}
}
@ -412,3 +404,17 @@ impl From<DiProvider> for Provider {
)
}
}
impl From<&Provider> for DiProvider {
fn from(p: &Provider) -> Self {
Self {
id: p.id(),
name: p.name(),
period: p.period(),
algorithm: p.algorithm().to_string(),
website: p.website(),
help_url: p.help_url(),
image_uri: p.image_uri(),
}
}
}

View file

@ -19,7 +19,7 @@ impl ProvidersModel {
pub fn find_by_name(&self, name: &str) -> Option<Provider> {
for pos in 0..self.count() {
let obj = self.model.get_object(pos).unwrap();
let obj = self.model.get_object(pos)?;
let provider = obj.downcast::<Provider>().unwrap();
if provider.name() == name {
return Some(provider);
@ -30,7 +30,7 @@ impl ProvidersModel {
pub fn find_by_id(&self, id: i32) -> Option<Provider> {
for pos in 0..self.count() {
let obj = self.model.get_object(pos).unwrap();
let obj = self.model.get_object(pos)?;
let provider = obj.downcast::<Provider>().unwrap();
if provider.id() == id {
return Some(provider);

View file

@ -30,7 +30,7 @@ pub struct AddAccountDialog {
impl AddAccountDialog {
pub fn new(model: Rc<ProvidersModel>, global_sender: Sender<Action>) -> Rc<Self> {
let builder = gtk::Builder::from_resource("/com/belmoussaoui/Authenticator/add_account.ui");
let builder = gtk::Builder::from_resource("/com/belmoussaoui/Authenticator/account_add.ui");
get_widget!(builder, libhandy::Window, add_dialog);
let (sender, r) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);

View file

@ -1,6 +1,6 @@
use crate::application::Action;
use crate::models::{Account, Provider, ProvidersModel};
use crate::widgets::{accounts::AccountRow, providers::ProviderRow};
use crate::models::{Provider, ProvidersModel};
use crate::widgets::providers::ProviderRow;
use gio::ListModelExt;
use glib::Sender;
use gtk::prelude::*;

View file

@ -1,9 +1,8 @@
use crate::application::Action;
use crate::models::{Account, Provider, ProvidersModel};
use crate::models::{Account, Provider};
use crate::widgets::accounts::AccountRow;
use glib::Sender;
use gtk::prelude::*;
use std::rc::Rc;
pub struct ProviderRow<'a> {
pub widget: gtk::ListBoxRow,

View file

@ -97,7 +97,9 @@ impl Window {
window_state::load(&self, &self_.settings);
// save window state on delete event
self.connect_close_request(clone!(@strong self_.settings as settings => move |window| {
window_state::save(&window, &settings);
if let Err(err) = window_state::save(&window, &settings) {
warn!("Failed to save window state {:#?}", err);
}
Inhibit(false)
}));
@ -133,8 +135,8 @@ impl Window {
fn setup_actions(&self, sender: Sender<Action>) {
let self_ = WindowPrivate::from_instance(self);
action!(
self,
"search",
clone!(@strong self_.builder as builder => move |_,_| {
get_widget!(builder, gtk::ToggleButton, search_btn);