RigsofRods
Soft-body Physics Simulation
GUI_RepositorySelector.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2021 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
26 
27 #pragma once
28 
29 #include "Application.h"
30 #include "OgreImGui.h" // ImVec4
31 
32 #include <future>
33 #include <memory>
34 #include <thread>
35 #include <vector>
36 #ifdef USE_CURL
37 # include <curl/curl.h>
38 #endif //USE_CURL
39 
40 namespace RoR {
41 namespace GUI {
42 
44 {
46  std::string title;
47  std::string description;
50 };
51 
53 {
55  std::string title;
56  std::string tag_line;
57  std::string icon_url;
58  std::string authors;
59  std::string version;
63  float rating_avg;
65  std::string view_url;
68  Ogre::TexturePtr preview_tex;
69  bool thumbnail_dl_queued = false;
70 };
71 
73 {
74  int id;
75  std::string filename;
76  int size;
77 };
78 
80 {
81  std::vector<ResourceItem> items;
82  std::vector<ResourceCategories> categories;
83  std::vector<ResourceFiles> files;
84 };
85 
87  public Ogre::WorkQueue::RequestHandler, // Processes tasks on background thread
88  public Ogre::WorkQueue::ResponseHandler // Processes task results on rendering thread
89 {
90 public:
91  const Ogre::uint16 WORKQUEUE_ROR_REPO_THUMBNAIL = 1; // Work queue request type, named by OGRE convention.
92 
95 
96  void SetVisible(bool visible);
97  bool IsVisible() const { return m_is_visible; }
98  void Draw();
99  void OpenResource(int resource_id);
100  void Download(int resource_id, std::string filename, int id);
101  void DownloadFinished();
102  void Refresh();
104  void UpdateFiles(ResourcesCollection* data);
105  void ShowError(CurlFailInfo* failinfo);
106  void DrawThumbnail(int resource_item_idx);
107 
109  virtual Ogre::WorkQueue::Response* handleRequest(const Ogre::WorkQueue::Request *req, const Ogre::WorkQueue *srcQ) override;
110  virtual void handleResponse(const Ogre::WorkQueue::Response *req, const Ogre::WorkQueue *srcQ) override;
111 
112 private:
113  bool m_is_visible = false;
114  bool m_draw = false;
117  std::string m_current_category;
119  std::string m_all_category_label;
121  bool m_update_cache = false;
122  bool m_show_spinner = false;
123  std::string m_current_sort = "Last Update";
124  std::string m_view_mode = "List";
125  bool m_resource_view = false;
127  Ogre::uint16 m_ogre_workqueue_channel = 0;
128  Ogre::TexturePtr m_fallback_thumbnail;
129 #ifdef USE_CURL
130  CURL *curl_th = curl_easy_init(); // One connection for fetching thumbnails using connection reuse
131 #endif
132 
133  // status or error messages
134  std::string m_repofiles_msg;
135  std::string m_repolist_msg;
137  std::string m_repolist_curlmsg;
138  std::string m_repolist_httpmsg;
139 };
140 
141 }// namespace GUI
142 }// namespace RoR
RoR::GUI::RepositorySelector::m_fallback_thumbnail
Ogre::TexturePtr m_fallback_thumbnail
Definition: GUI_RepositorySelector.h:128
RoR::GUI::ResourceCategories::display_order
int display_order
Definition: GUI_RepositorySelector.h:49
RoR::GUI::RepositorySelector::Draw
void Draw()
Definition: GUI_RepositorySelector.cpp:387
RoR::GUI::ResourceItem::rating_count
int rating_count
Definition: GUI_RepositorySelector.h:64
RoR::GUI::ResourceItem::view_url
std::string view_url
Definition: GUI_RepositorySelector.h:65
RoR::GUI::RepositorySelector::m_current_category
std::string m_current_category
Definition: GUI_RepositorySelector.h:117
RoR::GUI::RepositorySelector::RepositorySelector
RepositorySelector()
Definition: GUI_RepositorySelector.cpp:374
RoR::GUI::ResourceItem::authors
std::string authors
Definition: GUI_RepositorySelector.h:58
RoR::GUI::RepositorySelector::m_resource_view
bool m_resource_view
Definition: GUI_RepositorySelector.h:125
RoR::GUI::ResourceItem::tag_line
std::string tag_line
Definition: GUI_RepositorySelector.h:56
RoR::GUI::RepositorySelector::m_show_spinner
bool m_show_spinner
Definition: GUI_RepositorySelector.h:122
RoR::GUI::ResourceItem::thumbnail_dl_queued
bool thumbnail_dl_queued
Definition: GUI_RepositorySelector.h:69
RoR::GUI::RepositorySelector::handleRequest
virtual Ogre::WorkQueue::Response * handleRequest(const Ogre::WorkQueue::Request *req, const Ogre::WorkQueue *srcQ) override
Ogre::WorkQueue API.
Definition: GUI_RepositorySelector.cpp:1326
RoR::GUI::RepositorySelector::handleResponse
virtual void handleResponse(const Ogre::WorkQueue::Response *req, const Ogre::WorkQueue *srcQ) override
Processes task results on main thread.
Definition: GUI_RepositorySelector.cpp:1382
RoR::GUI::RepositorySelector::m_is_visible
bool m_is_visible
Definition: GUI_RepositorySelector.h:113
RoR::GUI::RepositorySelector::DrawThumbnail
void DrawThumbnail(int resource_item_idx)
Definition: GUI_RepositorySelector.cpp:1260
RoR::GUI::ResourceItem::download_count
int download_count
Definition: GUI_RepositorySelector.h:60
RoR::GUI::RepositorySelector::UpdateFiles
void UpdateFiles(ResourcesCollection *data)
Definition: GUI_RepositorySelector.cpp:1187
RoR::CurlFailInfo
Definition: Network.h:47
RoR::GUI::ResourceFiles
Definition: GUI_RepositorySelector.h:72
OgreImGui.h
RoR::GUI::ResourceCategories::resource_count
int resource_count
Definition: GUI_RepositorySelector.h:48
RoR::GUI::RepositorySelector::~RepositorySelector
~RepositorySelector()
Definition: GUI_RepositorySelector.cpp:384
RoR::GUI::ResourceItem::resource_id
int resource_id
Definition: GUI_RepositorySelector.h:54
RoR::GUI::RepositorySelector::OpenResource
void OpenResource(int resource_id)
Definition: GUI_RepositorySelector.cpp:1201
RoR::GUI::ResourcesCollection::items
std::vector< ResourceItem > items
Definition: GUI_RepositorySelector.h:81
RoR::GUI::RepositorySelector::m_repolist_msg
std::string m_repolist_msg
Definition: GUI_RepositorySelector.h:135
RoR::Str< 500 >
RoR::GUI::RepositorySelector::m_ogre_workqueue_channel
Ogre::uint16 m_ogre_workqueue_channel
Definition: GUI_RepositorySelector.h:127
RoR::GUI::RepositorySelector::SetVisible
void SetVisible(bool visible)
Definition: GUI_RepositorySelector.cpp:1238
RoR::GUI::RepositorySelector::m_selected_item
ResourceItem m_selected_item
Definition: GUI_RepositorySelector.h:126
RoR::GUI::RepositorySelector::Refresh
void Refresh()
Definition: GUI_RepositorySelector.cpp:1154
RoR::GUI::ResourceItem::resource_date
int resource_date
Definition: GUI_RepositorySelector.h:66
RoR::GUI::ResourceItem::resource_category_id
int resource_category_id
Definition: GUI_RepositorySelector.h:62
RoR::GUI::RepositorySelector::IsVisible
bool IsVisible() const
Definition: GUI_RepositorySelector.h:97
RoR::GUI::ResourceFiles::size
int size
Definition: GUI_RepositorySelector.h:76
RoR::GUI::RepositorySelector::m_repolist_httpmsg
std::string m_repolist_httpmsg
Displayed as dimmed text.
Definition: GUI_RepositorySelector.h:138
RoR::GUI::ResourceItem::preview_tex
Ogre::TexturePtr preview_tex
Definition: GUI_RepositorySelector.h:68
RoR::GUI::RepositorySelector::DownloadFinished
void DownloadFinished()
Definition: GUI_RepositorySelector.cpp:1221
RoR::GUI::ResourcesCollection
Definition: GUI_RepositorySelector.h:79
RoR::GUI::ResourceFiles::filename
std::string filename
Definition: GUI_RepositorySelector.h:75
RoR::GUI::ResourceCategories::description
std::string description
Definition: GUI_RepositorySelector.h:47
RoR::GUI::ResourceItem::icon_url
std::string icon_url
Definition: GUI_RepositorySelector.h:57
RoR::GUI::RepositorySelector::Download
void Download(int resource_id, std::string filename, int id)
Definition: GUI_RepositorySelector.cpp:1211
RoR::GUI::RepositorySelector::m_all_category_label
std::string m_all_category_label
Definition: GUI_RepositorySelector.h:119
Application.h
Central state/object manager and communications hub.
RoR::GUI::RepositorySelector::UpdateResources
void UpdateResources(ResourcesCollection *data)
Definition: GUI_RepositorySelector.cpp:1166
RoR::GUI::RepositorySelector::m_repolist_msg_color
ImVec4 m_repolist_msg_color
Definition: GUI_RepositorySelector.h:136
RoR::GUI::RepositorySelector::m_update_cache
bool m_update_cache
Definition: GUI_RepositorySelector.h:121
RoR::GUI::ResourcesCollection::categories
std::vector< ResourceCategories > categories
Definition: GUI_RepositorySelector.h:82
RoR::GUI::RepositorySelector::m_search_input
Str< 500 > m_search_input
Definition: GUI_RepositorySelector.h:116
RoR::GUI::RepositorySelector::m_current_category_id
int m_current_category_id
Definition: GUI_RepositorySelector.h:118
RoR::GUI::ResourceFiles::id
int id
Definition: GUI_RepositorySelector.h:74
RoR::GUI::RepositorySelector::m_current_category_label
std::string m_current_category_label
Definition: GUI_RepositorySelector.h:120
RoR::GUI::RepositorySelector::m_data
ResourcesCollection m_data
Definition: GUI_RepositorySelector.h:115
RoR::GUI::ResourceItem
Definition: GUI_RepositorySelector.h:52
RoR::GUI::RepositorySelector::m_view_mode
std::string m_view_mode
Definition: GUI_RepositorySelector.h:124
RoR::GUI::RepositorySelector::m_current_sort
std::string m_current_sort
Definition: GUI_RepositorySelector.h:123
RoR::GUI::ResourceItem::title
std::string title
Definition: GUI_RepositorySelector.h:55
RoR::GUI::RepositorySelector
Definition: GUI_RepositorySelector.h:86
RoR::GUI::ResourceCategories::title
std::string title
Definition: GUI_RepositorySelector.h:46
RoR::GUI::ResourceCategories::resource_category_id
int resource_category_id
Definition: GUI_RepositorySelector.h:45
RoR::GUI::RepositorySelector::m_draw
bool m_draw
Definition: GUI_RepositorySelector.h:114
RoR::GUI::ResourceItem::last_update
int last_update
Definition: GUI_RepositorySelector.h:61
RoR::GUI::ResourceItem::view_count
int view_count
Definition: GUI_RepositorySelector.h:67
RoR::GUI::ResourceCategories
Definition: GUI_RepositorySelector.h:43
RoR::GUI::ResourcesCollection::files
std::vector< ResourceFiles > files
Definition: GUI_RepositorySelector.h:83
RoR::GUI::RepositorySelector::WORKQUEUE_ROR_REPO_THUMBNAIL
const Ogre::uint16 WORKQUEUE_ROR_REPO_THUMBNAIL
Definition: GUI_RepositorySelector.h:91
RoR::GUI::RepositorySelector::m_repolist_curlmsg
std::string m_repolist_curlmsg
Displayed as dimmed text.
Definition: GUI_RepositorySelector.h:137
RoR::GUI::RepositorySelector::m_repofiles_msg
std::string m_repofiles_msg
Definition: GUI_RepositorySelector.h:134
RoR::GUI::RepositorySelector::ShowError
void ShowError(CurlFailInfo *failinfo)
Definition: GUI_RepositorySelector.cpp:1226
RoR
Definition: AppContext.h:36
RoR::GUI::ResourceItem::rating_avg
float rating_avg
Definition: GUI_RepositorySelector.h:63
RoR::GUI::RepositorySelector::curl_th
CURL * curl_th
Definition: GUI_RepositorySelector.h:130
RoR::GUI::ResourceItem::version
std::string version
Definition: GUI_RepositorySelector.h:59