Different Approach to Parser picking. Added Summary Edit
This commit is contained in:
parent
d8620b14c5
commit
4c5276738a
6 changed files with 152 additions and 53 deletions
71
src/main.rs
71
src/main.rs
|
@ -1,11 +1,12 @@
|
|||
use std::any::Any;
|
||||
use std::iter::Enumerate;
|
||||
|
||||
use egui::{widgets, TextStyle};
|
||||
use metadata::{AgeRating, LanguageISO, Metadata};
|
||||
use crate::metadata::{AgeRating, LanguageISO, Metadata};
|
||||
|
||||
use eframe::egui;
|
||||
use parsers::Parsers;
|
||||
use strum::IntoEnumIterator;
|
||||
use crate::parsers::{MetadataSource, Parser};
|
||||
|
||||
mod metadata;
|
||||
mod parsers;
|
||||
|
@ -33,8 +34,7 @@ fn main() -> Result<(), eframe::Error> {
|
|||
struct Generator<'a> {
|
||||
show_all: bool,
|
||||
metadata: Vec<Metadata<'a>>,
|
||||
selected_parser: Parsers,
|
||||
use_file: bool,
|
||||
selected_parser: Box<dyn Parser>,
|
||||
meta_path: Option<String>,
|
||||
bundle: bool,
|
||||
bundle_source: Option<String>,
|
||||
|
@ -47,8 +47,7 @@ impl Default for Generator<'_> {
|
|||
Self {
|
||||
show_all: false,
|
||||
metadata: vec![Metadata::default()],
|
||||
selected_parser: Parsers::JNovel,
|
||||
use_file: true,
|
||||
selected_parser: Box::new(parsers::file::File::new()),
|
||||
meta_path: None,
|
||||
bundle: false,
|
||||
bundle_source: None,
|
||||
|
@ -60,6 +59,13 @@ impl Default for Generator<'_> {
|
|||
|
||||
impl eframe::App for Generator<'_> {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
let ParserList: Vec<Box<dyn Parser>> = vec![
|
||||
Box::new(parsers::fakku::Fakku::new()),
|
||||
Box::new(parsers::file::File::new()),
|
||||
Box::new(parsers::irodori::Irodori::new()),
|
||||
Box::new(parsers::jnovel::JNovel::new()),
|
||||
];
|
||||
|
||||
// Non-Metadata Options
|
||||
egui::SidePanel::right("Options")
|
||||
.resizable(false)
|
||||
|
@ -70,51 +76,24 @@ impl eframe::App for Generator<'_> {
|
|||
panel.horizontal(|row| {
|
||||
row.label("Parser: ");
|
||||
egui::containers::ComboBox::from_label("")
|
||||
.selected_text(self.selected_parser.to_string())
|
||||
.selected_text(self.selected_parser.get_display_string())
|
||||
.show_ui(row, |ui| {
|
||||
for rating in Parsers::iter() {
|
||||
let text = rating.to_string().clone();
|
||||
if ui
|
||||
.selectable_value(&mut self.selected_parser, rating, text)
|
||||
.clicked()
|
||||
{
|
||||
match self.selected_parser {
|
||||
Parsers::Fakku | Parsers::Irodori => {
|
||||
self.use_file = false; // TODO change to use Parser default
|
||||
}
|
||||
Parsers::JNovel => {
|
||||
self.use_file = true; // TODO change to use Parser default
|
||||
}
|
||||
}
|
||||
for parser in ParserList {
|
||||
let text = parser.get_display_string().clone();
|
||||
if ui.selectable_value(&mut self.selected_parser.get_display_string(), parser.get_display_string(), text).clicked() {
|
||||
self.selected_parser = parser;
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
panel.horizontal(|row| {
|
||||
row.label("Parser Source: ");
|
||||
if row
|
||||
.add(widgets::SelectableLabel::new(self.use_file, "File"))
|
||||
.clicked()
|
||||
{
|
||||
self.use_file = true;
|
||||
}
|
||||
|
||||
if row
|
||||
.add(widgets::SelectableLabel::new(!self.use_file, "URL"))
|
||||
.clicked()
|
||||
{
|
||||
self.use_file = false;
|
||||
}
|
||||
});
|
||||
|
||||
let file_label;
|
||||
if self.use_file {
|
||||
if self.selected_parser.source_is_file() {
|
||||
file_label = "File Path";
|
||||
} else {
|
||||
file_label = "URL";
|
||||
}
|
||||
text_input_option(panel, &mut self.meta_path, file_label, self.use_file);
|
||||
text_input_option(panel, &mut self.meta_path, file_label, self.selected_parser.source_is_file());
|
||||
|
||||
// TODO this feels wrong, there must be a better way
|
||||
panel.add_space(self.footer_height * 0.1);
|
||||
|
@ -215,11 +194,11 @@ impl eframe::App for Generator<'_> {
|
|||
}
|
||||
});
|
||||
|
||||
// TODO Multiline Summary
|
||||
ui.label("TODO: Summary Edit");
|
||||
if let Some(summary) = &self.metadata[0].summary {
|
||||
ui.label(summary);
|
||||
}
|
||||
ui.label("Summary Edit:");
|
||||
let mut summary = self.metadata[0].summary.clone().unwrap_or("".to_string());
|
||||
if ui.add(egui::TextEdit::multiline(&mut summary)).changed() {
|
||||
self.metadata[0].summary = Some(summary);
|
||||
};
|
||||
|
||||
// Date Inputs
|
||||
let glyph_width = ctx
|
||||
|
@ -349,7 +328,7 @@ impl eframe::App for Generator<'_> {
|
|||
if centered.button("Save Metadata").clicked() {
|
||||
// Run Metadata Generation
|
||||
// DO NOT SAVE RESULTS YET ONLY POPULATE DATA
|
||||
self.metadata[0].save_to_xml("/home/neshura/Repositories/manga-hentai-metadata-generator/ComicInfo.xml")
|
||||
self.metadata[0].save_to_xml("/home/neshura/Repositories/comicinfo-editor/ComicInfo.xml")
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
26
src/parsers/fakku/mod.rs
Normal file
26
src/parsers/fakku/mod.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use crate::parsers::{self, MetadataSource, Parser, ParserConsts};
|
||||
|
||||
pub(crate) struct Fakku {
|
||||
|
||||
}
|
||||
|
||||
impl Parser for Fakku {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
fn get_uses_file(&self) -> MetadataSource {
|
||||
return MetadataSource::File;
|
||||
}
|
||||
|
||||
fn source_is_file(&self) -> bool {
|
||||
return Fakku::source == MetadataSource::File;
|
||||
}
|
||||
|
||||
fn get_display_string(&self) -> &str {
|
||||
return "Fakku";
|
||||
}
|
||||
}
|
||||
|
||||
impl ParserConsts for Fakku {
|
||||
const source: MetadataSource = MetadataSource::URL;
|
||||
}
|
26
src/parsers/file/mod.rs
Normal file
26
src/parsers/file/mod.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use crate::parsers::{self, MetadataSource, Parser, ParserConsts};
|
||||
|
||||
pub(crate) struct File {
|
||||
|
||||
}
|
||||
|
||||
impl Parser for File {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
fn get_uses_file(&self) -> MetadataSource {
|
||||
return MetadataSource::File;
|
||||
}
|
||||
|
||||
fn source_is_file(&self) -> bool {
|
||||
return File::source == MetadataSource::File;
|
||||
}
|
||||
|
||||
fn get_display_string(&self) -> &str {
|
||||
return "File";
|
||||
}
|
||||
}
|
||||
|
||||
impl ParserConsts for File {
|
||||
const source: MetadataSource = MetadataSource::File;
|
||||
}
|
26
src/parsers/irodori/mod.rs
Normal file
26
src/parsers/irodori/mod.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use crate::parsers::{self, MetadataSource, Parser, ParserConsts};
|
||||
|
||||
pub(crate) struct Irodori {
|
||||
|
||||
}
|
||||
|
||||
impl Parser for Irodori {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
fn get_uses_file(&self) -> MetadataSource {
|
||||
return MetadataSource::File;
|
||||
}
|
||||
|
||||
fn source_is_file(&self) -> bool {
|
||||
return Irodori::source == MetadataSource::File;
|
||||
}
|
||||
|
||||
fn get_display_string(&self) -> &str {
|
||||
return "Irodori Comics";
|
||||
}
|
||||
}
|
||||
|
||||
impl ParserConsts for Irodori {
|
||||
const source: MetadataSource = MetadataSource::URL;
|
||||
}
|
26
src/parsers/jnovel/mod.rs
Normal file
26
src/parsers/jnovel/mod.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use crate::parsers::{self, MetadataSource, Parser, ParserConsts};
|
||||
|
||||
pub(crate) struct JNovel {
|
||||
|
||||
}
|
||||
|
||||
impl Parser for JNovel {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
fn get_uses_file(&self) -> MetadataSource {
|
||||
return MetadataSource::File;
|
||||
}
|
||||
|
||||
fn source_is_file(&self) -> bool {
|
||||
return JNovel::source == MetadataSource::File;
|
||||
}
|
||||
|
||||
fn get_display_string(&self) -> &str {
|
||||
return "J-Novel Club";
|
||||
}
|
||||
}
|
||||
|
||||
impl ParserConsts for JNovel {
|
||||
const source: MetadataSource = MetadataSource::File;
|
||||
}
|
|
@ -1,8 +1,24 @@
|
|||
#[derive(strum_macros::Display, Debug, PartialEq, strum_macros::EnumIter)]
|
||||
pub(crate) enum Parsers {
|
||||
#[strum(serialize="Irodori Comics")]
|
||||
Irodori,
|
||||
Fakku,
|
||||
#[strum(serialize="J-Novel Club")]
|
||||
JNovel
|
||||
pub(crate) mod file;
|
||||
pub(crate) mod jnovel;
|
||||
pub(crate) mod fakku;
|
||||
pub(crate) mod irodori;
|
||||
|
||||
pub(crate) trait Parser {
|
||||
fn get_uses_file(&self) -> MetadataSource;
|
||||
|
||||
fn source_is_file(&self) -> bool;
|
||||
|
||||
fn get_display_string(&self) -> &str;
|
||||
|
||||
fn new() -> Self where Self: Sized;
|
||||
}
|
||||
|
||||
pub(crate) trait ParserConsts {
|
||||
const source: MetadataSource;
|
||||
}
|
||||
|
||||
#[derive(strum_macros::Display, Debug, PartialEq)]
|
||||
pub(crate) enum MetadataSource {
|
||||
File,
|
||||
URL
|
||||
}
|
Reference in a new issue