diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-12-09 19:45:19 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2019-12-09 19:45:19 +0100 |
commit | 5ef35784af24e5fcaa0f8570c23299d01b46412a (patch) | |
tree | 5c0a6c11743990975360518ebec32e8788e8edcc /src | |
parent | 5e29715201f3b67648728a0cd048fd1b3e1dbcf7 (diff) |
Show title of posts on 4chan
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 6 | ||||
-rw-r--r-- | src/SearchBar.cpp | 5 | ||||
-rw-r--r-- | src/plugins/Fourchan.cpp | 60 |
3 files changed, 66 insertions, 5 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 059cecf..5fcfc73 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -235,7 +235,7 @@ namespace QuickMedia { return 0; } - void Program::base_event_handler(sf::Event &event, Page previous_page, bool handle_keypress, bool clear_on_escape) { + void Program::base_event_handler(sf::Event &event, Page previous_page, bool handle_keypress, bool clear_on_escape, bool handle_searchbar) { if (event.type == sf::Event::Closed) { current_page = Page::EXIT; } else if(event.type == sf::Event::Resized) { @@ -256,7 +256,7 @@ namespace QuickMedia { search_bar->clear(); } } - } else if(event.type == sf::Event::TextEntered) { + } else if(handle_searchbar && event.type == sf::Event::TextEntered) { search_bar->onTextEntered(event.text.unicode); } } @@ -767,7 +767,7 @@ namespace QuickMedia { while (current_page == Page::VIDEO_CONTENT) { while (window.pollEvent(event)) { - base_event_handler(event, previous_page, true, false); + base_event_handler(event, previous_page, true, false, false); if(event.type == sf::Event::Resized) { if(video_player_ui_window) ui_resize = true; diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index 985f931..2008447 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -67,14 +67,15 @@ namespace QuickMedia { draw_logo = false; } - float font_height = text.getLocalBounds().height + 8.0f; + float font_height = text.getLocalBounds().height + 12.0f; float rect_height = std::floor(font_height + background_margin_vertical * 2.0f); float offset_x = padding_horizontal; if(draw_logo) { + float one_line_height = std::floor(text.getCharacterSize() + 8.0f + background_margin_vertical * 2.0f); auto texture_size = plugin_logo_sprite.getTexture()->getSize(); sf::Vector2f texture_size_f(texture_size.x, texture_size.y); - sf::Vector2f new_size = wrap_to_size(texture_size_f, sf::Vector2f(200.0f, text.getCharacterSize() + 8.0f)); + sf::Vector2f new_size = wrap_to_size(texture_size_f, sf::Vector2f(200.0f, one_line_height)); plugin_logo_sprite.setScale(get_ratio(texture_size_f, new_size)); plugin_logo_sprite.setPosition(25.0f, padding_vertical); offset_x = 25.0f + new_size.x + 25.0f; diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index 88bcafa..c571ef8 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -178,6 +178,11 @@ namespace QuickMedia { if(!thread.isObject()) continue; + const Json::Value &sub = thread["sub"]; + const char *sub_begin = ""; + const char *sub_end = sub_begin; + sub.getString(&sub_begin, &sub_end); + const Json::Value &com = thread["com"]; const char *comment_begin = ""; const char *comment_end = comment_begin; @@ -188,6 +193,30 @@ namespace QuickMedia { continue; std::string comment_text; + extract_comment_pieces(sub_begin, sub_end - sub_begin, + [&comment_text](const CommentPiece &cp) { + switch(cp.type) { + case CommentPiece::Type::TEXT: + comment_text.append(cp.text.data, cp.text.size); + break; + case CommentPiece::Type::QUOTE: + comment_text += '>'; + comment_text.append(cp.text.data, cp.text.size); + //comment_text += '\n'; + break; + case CommentPiece::Type::QUOTELINK: { + comment_text.append(cp.text.data, cp.text.size); + break; + } + case CommentPiece::Type::LINE_CONTINUE: { + if(!comment_text.empty() && comment_text.back() == '\n') { + comment_text.pop_back(); + } + break; + } + } + } + ); extract_comment_pieces(comment_begin, comment_end - comment_begin, [&comment_text](const CommentPiece &cp) { switch(cp.type) { @@ -289,6 +318,11 @@ namespace QuickMedia { if(!post.isObject()) continue; + const Json::Value &sub = post["sub"]; + const char *sub_begin = ""; + const char *sub_end = sub_begin; + sub.getString(&sub_begin, &sub_end); + const Json::Value &com = post["com"]; const char *comment_begin = ""; const char *comment_end = comment_begin; @@ -304,6 +338,32 @@ namespace QuickMedia { author_str = author.asString(); std::string comment_text; + extract_comment_pieces(sub_begin, sub_end - sub_begin, + [&comment_text](const CommentPiece &cp) { + switch(cp.type) { + case CommentPiece::Type::TEXT: + comment_text.append(cp.text.data, cp.text.size); + break; + case CommentPiece::Type::QUOTE: + comment_text += '>'; + comment_text.append(cp.text.data, cp.text.size); + //comment_text += '\n'; + break; + case CommentPiece::Type::QUOTELINK: { + comment_text.append(cp.text.data, cp.text.size); + break; + } + case CommentPiece::Type::LINE_CONTINUE: { + if(!comment_text.empty() && comment_text.back() == '\n') { + comment_text.pop_back(); + } + break; + } + } + } + ); + if(!comment_text.empty()) + comment_text += '\n'; extract_comment_pieces(comment_begin, comment_end - comment_begin, [&comment_text, &comment_by_postno, &result_items, body_item_index](const CommentPiece &cp) { switch(cp.type) { |