|
@@ -0,0 +1,116 @@
|
|
|
+using Gtk;
|
|
|
+using Adw;
|
|
|
+
|
|
|
+namespace Publicate.Wizards {
|
|
|
+
|
|
|
+ public class StandardWizard : Box, Wizard {
|
|
|
+
|
|
|
+ private EntryRow title;
|
|
|
+ private EntryRow author;
|
|
|
+ private EntryRow author_email;
|
|
|
+
|
|
|
+ private ViewerWindow window;
|
|
|
+
|
|
|
+ public StandardWizard(ViewerWindow win) {
|
|
|
+ window = win;
|
|
|
+ orientation = Orientation.VERTICAL;
|
|
|
+ spacing = 18;
|
|
|
+ valign = Align.CENTER;
|
|
|
+ halign = Align.CENTER;
|
|
|
+ vexpand = true;
|
|
|
+ margin_bottom = 40;
|
|
|
+
|
|
|
+
|
|
|
+ var group = new PreferencesGroup();
|
|
|
+ group.width_request = 300;
|
|
|
+ group.title = "Publication Details";
|
|
|
+ group.description = "These can be changed later";
|
|
|
+
|
|
|
+ title = new EntryRow ();
|
|
|
+ title.title = "Title";
|
|
|
+ group.add(title);
|
|
|
+
|
|
|
+ author = new EntryRow ();
|
|
|
+ author.title = "Author";
|
|
|
+ group.add(author);
|
|
|
+
|
|
|
+ author_email = new EntryRow ();
|
|
|
+ author_email.title = "Author Email";
|
|
|
+ group.add(author_email);
|
|
|
+
|
|
|
+ append(group);
|
|
|
+
|
|
|
+
|
|
|
+ var back_button = new Button.with_label ("Cancel");
|
|
|
+ back_button.hexpand = true;
|
|
|
+ back_button.clicked.connect (() => cancelled());
|
|
|
+
|
|
|
+ var next_button = new Button.with_label ("Create");
|
|
|
+ next_button.hexpand = true;
|
|
|
+ next_button.add_css_class ("suggested-action");
|
|
|
+ next_button.clicked.connect (() => create_ppub());
|
|
|
+
|
|
|
+ var button_box = new Box(Orientation.HORIZONTAL, 0);
|
|
|
+ button_box.add_css_class ("linked");
|
|
|
+
|
|
|
+ button_box.append (back_button);
|
|
|
+ button_box.append (next_button);
|
|
|
+ button_box.vexpand = true;
|
|
|
+ append(button_box);
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void create_ppub() {
|
|
|
+
|
|
|
+ var dialog = new FileDialog();
|
|
|
+ var filter = new FileFilter();
|
|
|
+ var filters = new GLib.ListStore(Type.OBJECT);
|
|
|
+ filters.append(filter);
|
|
|
+ filter.add_pattern("*.ppub");
|
|
|
+ filter.name = "Portable Publications";
|
|
|
+ dialog.filters = filters;
|
|
|
+ var file = yield dialog.save(window, null);
|
|
|
+
|
|
|
+ if(file == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var metadata = new Ppub.Metadata();
|
|
|
+ var email = author_email.text.chomp().chug();
|
|
|
+ if(email != "") {
|
|
|
+ metadata.author = @"$(author.text) <$email>";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ metadata.author = author.text;
|
|
|
+ }
|
|
|
+
|
|
|
+ metadata.title = title.text;
|
|
|
+
|
|
|
+ print(metadata.to_string());
|
|
|
+
|
|
|
+ var builder = new Ppub.Builder();
|
|
|
+ builder.add_metadata(metadata);
|
|
|
+
|
|
|
+ var article_data = @"# $(title.text)\n\n".to_utf8();
|
|
|
+ var article_stream = new MemoryInputStream.from_data((uint8[])article_data);
|
|
|
+ var compression_info = new Ppub.CompressionInfo(article_stream);
|
|
|
+ article_stream.seek(0, SeekType.SET);
|
|
|
+
|
|
|
+ builder.add_asset("article.md", "text/markdown", article_stream, Invercargill.empty<string>(), compression_info);
|
|
|
+
|
|
|
+ var output_stream = file.replace(null, false, FileCreateFlags.REPLACE_DESTINATION);
|
|
|
+ builder.write(output_stream);
|
|
|
+
|
|
|
+ output_stream.close();
|
|
|
+
|
|
|
+ open(file);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void reset() {
|
|
|
+ title.text = "";
|
|
|
+ author.text = "";
|
|
|
+ author_email.text = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|