use adw::Application

This commit is contained in:
Bilal Elmoussaoui 2021-11-14 18:16:46 +01:00
parent eaba3f0d97
commit 1635e15050
10 changed files with 22 additions and 47 deletions

View file

@ -22,7 +22,7 @@
<file compressed="true" preprocess="xml-stripblanks" alias="camera.ui">resources/ui/camera.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="error_revealer.ui">resources/ui/error_revealer.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="shortcuts.ui">resources/ui/shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">resources/ui/shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="window.ui">resources/ui/window.ui</file>
</gresource>

View file

@ -156,7 +156,7 @@
</object>
</child>
<style>
<class name="content"/>
<class name="boxed-list"/>
</style>
</object>
</child>
@ -227,7 +227,7 @@
</object>
</child>
<style>
<class name="content"/>
<class name="boxed-list"/>
</style>
</object>
</child>

View file

@ -64,7 +64,7 @@
</object>
</child>
<style>
<class name="content"/>
<class name="boxed-list"/>
</style>
</object>
</child>

View file

@ -88,7 +88,7 @@
</object>
</child>
<style>
<class name="content" />
<class name="boxed-list" />
</style>
</object>
</child>

View file

@ -163,7 +163,7 @@
<object class="AdwComboRow" id="method_comborow">
<property name="title" translatable="yes">Computing Method</property>
<property name="expression">
<lookup type="AdwEnumValueObject" name="name"/>
<lookup type="OTPMethod" name="name"/>
</property>
</object>
</child>
@ -171,12 +171,12 @@
<object class="AdwComboRow" id="algorithm_comborow">
<property name="title" translatable="yes">Algorithm</property>
<property name="expression">
<lookup type="AdwEnumValueObject" name="name"/>
<lookup type="Algorithm" name="name"/>
</property>
</object>
</child>
<style>
<class name="content"/>
<class name="boxed-list"/>
</style>
<child>
<object class="AdwActionRow" id="period_row">

View file

@ -38,7 +38,7 @@
<object class="GtkListBox" id="accounts_list">
<property name="vexpand">True</property>
<style>
<class name="content" />
<class name="boxed-list" />
</style>
</object>
</child>

View file

@ -89,7 +89,7 @@
<property name="vexpand">true</property>
<property name="single-click-activate">True</property>
<style>
<class name="content" />
<class name="boxed-list" />
</style>
</object>
</child>

View file

@ -10,6 +10,7 @@ use gtk_macros::{action, get_action};
mod imp {
use super::*;
use adw::subclass::prelude::*;
use glib::{ParamSpec, WeakRef};
use std::cell::{Cell, RefCell};
@ -28,7 +29,7 @@ mod imp {
#[glib::object_subclass]
impl ObjectSubclass for Application {
const NAME: &'static str = "Application";
type ParentType = gtk::Application;
type ParentType = adw::Application;
type Type = super::Application;
// Initialize with default values
@ -100,39 +101,11 @@ mod imp {
}
}
// This is empty, but we still need to provide an
// empty implementation for each type we subclass.
impl GtkApplicationImpl for Application {}
// Overrides GApplication vfuncs
impl ApplicationImpl for Application {
fn startup(&self, app: &Self::Type) {
self.parent_startup(app);
adw::functions::init();
let app = app.downcast_ref::<super::Application>().unwrap();
if let Some(ref display) = gtk::gdk::Display::default() {
let p = gtk::CssProvider::new();
gtk::CssProvider::load_from_resource(
&p,
"/com/belmoussaoui/Authenticator/style.css",
);
gtk::StyleContext::add_provider_for_display(display, &p, 500);
let theme = gtk::IconTheme::for_display(display).unwrap();
theme.add_resource_path("/com/belmoussaoui/Authenticator/icons/");
}
// - action! is a macro from gtk_macros
// that creates a GSimpleAction with a callback.
//
// - clone! is a macro from glib-rs that allows
// you to easily handle references in callbacks
// without refcycles or leaks.
// When you don't want the callback to keep the
// Object alive, pass as @weak. Otherwise, pass
// as @strong. Most of the time you will want
// to use @weak.
action!(app, "quit", clone!(@weak app => move |_, _| app.quit()));
action!(
@ -243,14 +216,11 @@ mod imp {
return;
}
let app = app.downcast_ref::<super::Application>().unwrap();
let window = app.create_window();
window.present();
self.window.replace(Some(window.downgrade()));
let has_set_password = Keyring::has_set_password().unwrap_or(false);
app.set_resource_base_path(Some("/com/belmoussaoui/Authenticator"));
app.set_accels_for_action("app.quit", &["<primary>q"]);
app.set_accels_for_action("app.lock", &["<primary>l"]);
app.set_accels_for_action("app.providers", &["<primary>p"]);
@ -267,6 +237,11 @@ mod imp {
app.restart_lock_timeout();
}
}
// This is empty, but we still need to provide an
// empty implementation for each type we subclass.
impl GtkApplicationImpl for Application {}
impl AdwApplicationImpl for Application {}
}
// Creates a wrapper struct that inherits the functions
@ -275,7 +250,8 @@ mod imp {
// Application without casting.
glib::wrapper! {
pub struct Application(ObjectSubclass<imp::Application>)
@extends gio::Application, gtk::Application, gio::ActionMap;
@extends gio::Application, gtk::Application, adw::Application,
@implements gio::ActionMap;
}
impl Application {
@ -291,6 +267,7 @@ impl Application {
let app = glib::Object::new::<Application>(&[
("application-id", &Some(config::APP_ID)),
("flags", &gio::ApplicationFlags::empty()),
("resource-base-path", &"/com/belmoussaoui/Authenticator"),
])
.unwrap();

View file

@ -92,6 +92,8 @@ mod imp {
}
fn class_init(klass: &mut Self::Class) {
OTPMethod::static_type();
Algorithm::static_type();
Self::bind_template(klass);
}

View file

@ -225,10 +225,6 @@ impl Window {
Inhibit(false)
}));
let builder = gtk::Builder::from_resource("/com/belmoussaoui/Authenticator/shortcuts.ui");
gtk_macros::get_widget!(builder, gtk::ShortcutsWindow, shortcuts);
self.set_help_overlay(Some(&shortcuts));
let search_entry = &*self_.search_entry;
let search_btn = &*self_.search_btn;
let providers = &*self_.providers;