Browse Source

Actually install

Billy Barrow 2 years ago
parent
commit
1dbfd23804
3 changed files with 139 additions and 1 deletions
  1. 21 0
      src/FileCreationPopover.vala
  2. 116 0
      src/Wizards/Video.vala
  3. 2 1
      src/meson.build

+ 21 - 0
src/FileCreationPopover.vala

@@ -0,0 +1,21 @@
+using Adw;
+using Gtk;
+
+namespace Publicate {
+
+    public class FileCreat8ionPopover : Popover {
+
+        private ViewerWindow toplevel;
+
+        public FileCreat8ionPopover(ViewerWindow window) {
+
+            toplevel = window;
+            var box = new Box(Orientation.VERTICAL, 8);
+            child = box;
+
+            
+        }
+
+    }
+
+}

+ 116 - 0
src/Wizards/Video.vala

@@ -0,0 +1,116 @@
+using Gtk;
+using Adw;
+
+namespace Publicate.Wizards {
+
+    public class VideoWizard : Box, Wizard {
+
+        private EntryRow title;
+        private EntryRow author;
+        private EntryRow author_email;
+
+        private ViewerWindow window;
+
+        public VideoWizard(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 = "";
+        }
+
+    }
+
+}

+ 2 - 1
src/meson.build

@@ -10,6 +10,7 @@ sources += files('FileExplorer.vala')
 sources += files('Editor.vala')
 sources += files('Savable.vala')
 sources += files('FileChooser.vala')
+sources += files('FileCreationPopover.vala')
 sources += files('Editors/EditorWidget.vala')
 sources += files('Editors/MarkdownEditor.vala')
 sources += files('Editors/PlainTextEditor.vala')
@@ -32,4 +33,4 @@ dependencies = [
     dependency('gtksourceview-5'),
 ]
 
-executable('publicate', sources, dependencies: dependencies)
+executable('publicate', sources, dependencies: dependencies, install: true)