From d399e7ec86a91dd14a7c0deedaaec70ae46cef1d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 6 Aug 2019 07:55:13 +0200 Subject: Add cli arg to choose plugin, fix crash --- src/QuickMedia.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 18324a9..88c74f9 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -12,6 +12,7 @@ #include #include #include +#include const sf::Color front_color(43, 45, 47); const sf::Color back_color(33, 35, 37); @@ -31,8 +32,6 @@ namespace QuickMedia { abort(); } body = new Body(font); - current_plugin = new Manganelo(); - //current_plugin = new Youtube(); search_bar = std::make_unique(font); } @@ -63,7 +62,27 @@ namespace QuickMedia { body->clamp_selection(); } - void Program::run() { + static void usage() { + fprintf(stderr, "usage: QuickMedia \n"); + fprintf(stderr, "OPTIONS:\n"); + fprintf(stderr, "plugin The plugin to use. Should be either manganelo or youtube\n"); + } + + int Program::run(int argc, char **argv) { + if(argc < 2) { + usage(); + return -1; + } + + if(strcmp(argv[1], "manganelo") == 0) + current_plugin = new Manganelo(); + else if(strcmp(argv[1], "youtube") == 0) + current_plugin = new Youtube(); + else { + usage(); + return -1; + } + while(window.isOpen()) { switch(current_page) { case Page::EXIT: @@ -88,9 +107,12 @@ namespace QuickMedia { break; } default: - return; + window.close(); + break; } } + + return 0; } void Program::base_event_handler(sf::Event &event, Page previous_page) { -- cgit v1.2.3