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 std::iter::Enumerate;
|
||||||
|
|
||||||
use egui::{widgets, TextStyle};
|
use egui::{widgets, TextStyle};
|
||||||
use metadata::{AgeRating, LanguageISO, Metadata};
|
use crate::metadata::{AgeRating, LanguageISO, Metadata};
|
||||||
|
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use parsers::Parsers;
|
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
use crate::parsers::{MetadataSource, Parser};
|
||||||
|
|
||||||
mod metadata;
|
mod metadata;
|
||||||
mod parsers;
|
mod parsers;
|
||||||
|
@ -33,8 +34,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||||
struct Generator<'a> {
|
struct Generator<'a> {
|
||||||
show_all: bool,
|
show_all: bool,
|
||||||
metadata: Vec<Metadata<'a>>,
|
metadata: Vec<Metadata<'a>>,
|
||||||
selected_parser: Parsers,
|
selected_parser: Box<dyn Parser>,
|
||||||
use_file: bool,
|
|
||||||
meta_path: Option<String>,
|
meta_path: Option<String>,
|
||||||
bundle: bool,
|
bundle: bool,
|
||||||
bundle_source: Option<String>,
|
bundle_source: Option<String>,
|
||||||
|
@ -47,8 +47,7 @@ impl Default for Generator<'_> {
|
||||||
Self {
|
Self {
|
||||||
show_all: false,
|
show_all: false,
|
||||||
metadata: vec![Metadata::default()],
|
metadata: vec![Metadata::default()],
|
||||||
selected_parser: Parsers::JNovel,
|
selected_parser: Box::new(parsers::file::File::new()),
|
||||||
use_file: true,
|
|
||||||
meta_path: None,
|
meta_path: None,
|
||||||
bundle: false,
|
bundle: false,
|
||||||
bundle_source: None,
|
bundle_source: None,
|
||||||
|
@ -60,6 +59,13 @@ impl Default for Generator<'_> {
|
||||||
|
|
||||||
impl eframe::App for Generator<'_> {
|
impl eframe::App for Generator<'_> {
|
||||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
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
|
// Non-Metadata Options
|
||||||
egui::SidePanel::right("Options")
|
egui::SidePanel::right("Options")
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
|
@ -70,51 +76,24 @@ impl eframe::App for Generator<'_> {
|
||||||
panel.horizontal(|row| {
|
panel.horizontal(|row| {
|
||||||
row.label("Parser: ");
|
row.label("Parser: ");
|
||||||
egui::containers::ComboBox::from_label("")
|
egui::containers::ComboBox::from_label("")
|
||||||
.selected_text(self.selected_parser.to_string())
|
.selected_text(self.selected_parser.get_display_string())
|
||||||
.show_ui(row, |ui| {
|
.show_ui(row, |ui| {
|
||||||
for rating in Parsers::iter() {
|
for parser in ParserList {
|
||||||
let text = rating.to_string().clone();
|
let text = parser.get_display_string().clone();
|
||||||
if ui
|
if ui.selectable_value(&mut self.selected_parser.get_display_string(), parser.get_display_string(), text).clicked() {
|
||||||
.selectable_value(&mut self.selected_parser, rating, text)
|
self.selected_parser = parser;
|
||||||
.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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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;
|
let file_label;
|
||||||
if self.use_file {
|
if self.selected_parser.source_is_file() {
|
||||||
file_label = "File Path";
|
file_label = "File Path";
|
||||||
} else {
|
} else {
|
||||||
file_label = "URL";
|
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
|
// TODO this feels wrong, there must be a better way
|
||||||
panel.add_space(self.footer_height * 0.1);
|
panel.add_space(self.footer_height * 0.1);
|
||||||
|
@ -215,11 +194,11 @@ impl eframe::App for Generator<'_> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO Multiline Summary
|
ui.label("Summary Edit:");
|
||||||
ui.label("TODO: Summary Edit");
|
let mut summary = self.metadata[0].summary.clone().unwrap_or("".to_string());
|
||||||
if let Some(summary) = &self.metadata[0].summary {
|
if ui.add(egui::TextEdit::multiline(&mut summary)).changed() {
|
||||||
ui.label(summary);
|
self.metadata[0].summary = Some(summary);
|
||||||
}
|
};
|
||||||
|
|
||||||
// Date Inputs
|
// Date Inputs
|
||||||
let glyph_width = ctx
|
let glyph_width = ctx
|
||||||
|
@ -349,7 +328,7 @@ impl eframe::App for Generator<'_> {
|
||||||
if centered.button("Save Metadata").clicked() {
|
if centered.button("Save Metadata").clicked() {
|
||||||
// Run Metadata Generation
|
// Run Metadata Generation
|
||||||
// DO NOT SAVE RESULTS YET ONLY POPULATE DATA
|
// 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) mod file;
|
||||||
pub(crate) enum Parsers {
|
pub(crate) mod jnovel;
|
||||||
#[strum(serialize="Irodori Comics")]
|
pub(crate) mod fakku;
|
||||||
Irodori,
|
pub(crate) mod irodori;
|
||||||
Fakku,
|
|
||||||
#[strum(serialize="J-Novel Club")]
|
pub(crate) trait Parser {
|
||||||
JNovel
|
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