aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-06 07:55:13 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-06 07:55:16 +0200
commitd399e7ec86a91dd14a7c0deedaaec70ae46cef1d (patch)
tree85b8598274f3dc9ca921c47aaaf7640400543168 /src
parent953fa85fb67f1f59a2612754b13f2c4a00b93866 (diff)
Add cli arg to choose plugin, fix crash
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp21
-rw-r--r--src/QuickMedia.cpp30
-rw-r--r--src/main.cpp5
3 files changed, 39 insertions, 17 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 68acaad..9f27ed2 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -116,7 +116,6 @@ namespace QuickMedia {
// TODO: Show chapters (rows) that have been read differently to make it easier to see what
// needs hasn't been read yet.
void Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress) {
- assert(content_progress.isObject());
const float font_height = title_text.getCharacterSize() + 8.0f;
const float image_height = 100.0f;
@@ -127,8 +126,8 @@ namespace QuickMedia {
sf::RectangleShape item_background;
item_background.setFillColor(front_color);
- //item_background.setOutlineThickness(1.0f);
- //item_background.setOutlineColor(sf::Color(63, 65, 67));
+ item_background.setOutlineThickness(1.0f);
+ item_background.setOutlineColor(sf::Color(63, 65, 67));
sf::RectangleShape selected_border;
selected_border.setFillColor(sf::Color::Red);
@@ -201,13 +200,15 @@ namespace QuickMedia {
// TODO: Do the same for non-manga content
const Json::Value &item_progress = content_progress[item->title];
- const Json::Value &current_json = item_progress["current"];
- const Json::Value &total_json = item_progress["total"];
- if(current_json.isNumeric() && total_json.isNumeric()) {
- progress_text.setString(std::string("Progress: ") + std::to_string(current_json.asInt()) + "/" + std::to_string(total_json.asInt()));
- auto bounds = progress_text.getLocalBounds();
- progress_text.setPosition(std::floor(item_pos.x + size.x - bounds.width - 10.0f), std::floor(item_pos.y));
- window.draw(progress_text);
+ if(item_progress.isObject()) {
+ const Json::Value &current_json = item_progress["current"];
+ const Json::Value &total_json = item_progress["total"];
+ if(current_json.isNumeric() && total_json.isNumeric()) {
+ progress_text.setString(std::string("Progress: ") + std::to_string(current_json.asInt()) + "/" + std::to_string(total_json.asInt()));
+ auto bounds = progress_text.getLocalBounds();
+ progress_text.setPosition(std::floor(item_pos.x + size.x - bounds.width - 10.0f), std::floor(item_pos.y));
+ window.draw(progress_text);
+ }
}
pos.y += row_height + 10.0f;
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 <json/writer.h>
#include <assert.h>
#include <cmath>
+#include <string.h>
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<SearchBar>(font);
}
@@ -63,7 +62,27 @@ namespace QuickMedia {
body->clamp_selection();
}
- void Program::run() {
+ static void usage() {
+ fprintf(stderr, "usage: QuickMedia <plugin>\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) {
diff --git a/src/main.cpp b/src/main.cpp
index 2dc50ee..1b85cbf 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,9 +1,8 @@
#include "../include/QuickMedia.hpp"
#include <X11/Xlib.h>
-int main() {
+int main(int argc, char **argv) {
XInitThreads();
QuickMedia::Program program;
- program.run();
- return 0;
+ return program.run(argc, argv);
}