Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

Commit

Permalink
added simple preferences window
Browse files Browse the repository at this point in the history
  • Loading branch information
adhadse committed Jun 5, 2023
1 parent 50342c2 commit 17e6933
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 126 deletions.
11 changes: 1 addition & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ authors = ["Anurag Dhadse <[email protected]>"]
edition = "2021"

[dependencies]
log = "0.4"
pretty_env_logger = "0.4"
once_cell = "1.9"
gtk-macros = "0.3.0"
strum = "0.24.1"
strum_macros = "0.24.3"
futures = "0.3.28"
anyhow = "1.0.70"
rust-crypto = "0.2.36"
tracing = "0.1"
tracker = "0.1"
tracing-subscriber = "0.3"
relm4-macros = "0.5.1"

Expand All @@ -39,6 +33,3 @@ version = "1.0.91"
package = "epub"
version = "2.0.0"

[build-dependencies]
relm4-macros = "0.5.1"

34 changes: 25 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ use relm4::{
use gtk::prelude::{ApplicationExt, ApplicationWindowExt, GtkWindowExt, SettingsExt, WidgetExt};
use gtk::{gio, glib};

use crate::components::{AboutDialog, MainContainer};
use crate::components::{AboutDialog, BookxMainContainer, BookxPreferences};
use crate::config::{APP_ID, PROFILE};

pub(super) struct App {
bookx_preferences: Controller<BookxPreferences>,
about_dialog: Controller<AboutDialog>,
main_container: Controller<MainContainer>,
bookx_main_container: Controller<BookxMainContainer>,
}

#[derive(Debug)]
pub(super) enum AppMsg {
pub(super) enum Event {
OpenPreferences,
Quit,
}

Expand All @@ -47,7 +49,7 @@ impl SimpleComponent for App {
/// The type of data with which this component will be initialized.
type Init = ();
/// The type of the messages that this component can receive.
type Input = AppMsg;
type Input = Event;
/// The type of the messages that this component can send.
type Output = ();
/// A data structure that contains the widgets that you will need to update.
Expand All @@ -66,7 +68,7 @@ impl SimpleComponent for App {
view! {
main_window = gtk::ApplicationWindow::new(&main_application()) {
connect_close_request[sender] => move |_| {
sender.input(AppMsg::Quit);
sender.input(Event::Quit);
gtk::Inhibit(true)
},

Expand Down Expand Up @@ -99,7 +101,7 @@ impl SimpleComponent for App {
set_margin_all: 5,
set_spacing: 5,

append: model.main_container.widget()
append: model.bookx_main_container.widget()
}
}
}
Expand All @@ -113,10 +115,15 @@ impl SimpleComponent for App {
.transient_for(root)
.launch(())
.detach();
let main_container = MainContainer::builder().launch(()).detach();
let bookx_preferences = BookxPreferences::builder()
.transient_for(root)
.launch(())
.detach();
let bookx_main_container = BookxMainContainer::builder().launch(()).detach();
let model = Self {
bookx_preferences,
about_dialog,
main_container,
bookx_main_container,
};

let mut actions = RelmActionGroup::<WindowActionGroup>::new();
Expand All @@ -136,8 +143,16 @@ impl SimpleComponent for App {
})
};

let preferences_action = {
let sender = sender.input_sender().clone();
RelmAction::<PreferencesAction>::new_stateless(move |_| {
sender.send(Event::OpenPreferences).unwrap();
})
};

actions.add_action(shortcuts_action);
actions.add_action(about_action);
actions.add_action(preferences_action);

widgets
.main_window
Expand All @@ -150,7 +165,8 @@ impl SimpleComponent for App {

fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
match message {
AppMsg::Quit => main_application().quit(),
Event::Quit => main_application().quit(),
Event::OpenPreferences => self.bookx_preferences.widget().present(),
}
}

Expand Down
95 changes: 0 additions & 95 deletions src/components/bookxbook.rs

This file was deleted.

10 changes: 5 additions & 5 deletions src/components/library/bookx_book.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Bookx - bookxbook.rs
// Bookx - bookx_book.rs
// Copyright (C) 2023 Anurag Dhadse <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -15,12 +15,11 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use epub::doc::{DocError, EpubDoc};
use log::debug;
use relm4::{
gtk::{self, gdk_pixbuf::Pixbuf, glib, prelude::*},
ComponentParts, ComponentSender, SimpleComponent,
};
use tracing::{error, info};
use tracing::error;

use std::fs;
use std::io::Write;
Expand Down Expand Up @@ -120,9 +119,10 @@ impl BookxBook {
Ok(()) => {
let mut f = fs::File::create(cover_path.clone()).unwrap();
let resp = f.write_all(&cover_data);
debug!(
tracing::debug!(
"Writing book cover for: {:?}; Response: {:?}",
book_path, resp
book_path,
resp
);
}
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/library/bookx_library.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Bookx - library.rs
// Bookx - bookx_library.rs
// Copyright (C) 2023 Anurag Dhadse <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
Expand Down
6 changes: 3 additions & 3 deletions src/components/main_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use tracing::error;

// serve as the main container for library, reader component
// status page of library, add Toast messages
pub struct MainContainer {
pub struct BookxMainContainer {
library: Controller<BookxLibrary>,
}

#[relm4_macros::component(pub)]
impl SimpleComponent for MainContainer {
impl SimpleComponent for BookxMainContainer {
type Init = ();
type Input = ();
type Output = ();
Expand All @@ -51,7 +51,7 @@ impl SimpleComponent for MainContainer {
let library = BookxLibrary::builder()
.launch(String::from("/home/adhadse/Documents/sample_dir"))
.detach();
let model = MainContainer { library };
let model = Self { library };
let widgets = view_output!();
ComponentParts { model, widgets }
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod about;
mod library;
mod main_container;
mod preferences;
mod utils;

pub use about::AboutDialog;
pub use main_container::MainContainer;
pub use main_container::BookxMainContainer;
pub use preferences::BookxPreferences;
64 changes: 64 additions & 0 deletions src/components/preferences.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Bookx - preferences.rs
// Copyright (C) 2023 Anurag Dhadse <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use gettextrs::gettext;
use relm4::{
adw::{self, prelude::*},
gtk, ComponentParts, ComponentSender, SimpleComponent,
};

pub struct BookxPreferences {}

#[relm4::component(pub)]
impl SimpleComponent for BookxPreferences {
type Init = ();
type Input = ();
type Output = ();

view! {
#[name = "preferences_window"]
adw::PreferencesWindow {
set_default_width: 480,
set_search_enabled: false,
set_modal: true,

add = &adw::PreferencesPage {
set_title: &gettext("General"),

add = &adw::PreferencesGroup {
set_title: &gettext("Books Location"),
adw::ActionRow {
set_title: &gettext("Load books from folder"),
#[wrap(Some)]
set_activatable_widget = &gtk::Button::builder().valign(gtk::Align::Center).build(),
}
}
}
}
}

fn init(
_: Self::Init,
root: &Self::Root,
_sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Self {};

let widgets = view_output!();

ComponentParts { model, widgets }
}
}
1 change: 0 additions & 1 deletion src/components/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use core::cmp::Ordering;
use relm4::gtk::{
gio::{self, prelude::*},
glib,
prelude::*,
};
use std::time::Instant;
use tracing::{debug, info};
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pub const LOCALEDIR: &str = "/app/share/locale";
pub const PKGDATADIR: &str = "/app/share/bookx";
pub const PROFILE: &str = "Devel";
pub const RESOURCES_FILE: &str = concat!("/app/share/bookx", "/resources.gresource");
pub const VERSION: &str = "0.1.0-9b34b1e";
pub const VERSION: &str = "0.1.0-50342c2";

0 comments on commit 17e6933

Please sign in to comment.