mirror of
https://github.com/arabine/open-story-teller.git
synced 2025-12-06 17:09:06 +01:00
librarymanager: (wip) selection and copy to device
This commit is contained in:
parent
bd59867bc3
commit
4fc34d5521
5 changed files with 107 additions and 40 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#include "library_manager.h"
|
#include "library_manager.h"
|
||||||
#include "tlv.h"
|
#include "tlv.h"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
#include "story_project.h"
|
#include "story_project.h"
|
||||||
|
|
@ -102,13 +103,16 @@ void LibraryManager::Save()
|
||||||
tlv.add_array(m_projectsList.size());
|
tlv.add_array(m_projectsList.size());
|
||||||
for (auto &p : m_projectsList)
|
for (auto &p : m_projectsList)
|
||||||
{
|
{
|
||||||
tlv.add_object(6);
|
if (p->IsSelected())
|
||||||
tlv.add_string(p->GetUuid());
|
{
|
||||||
tlv.add_string(p->GetTitleImage());
|
tlv.add_object(6);
|
||||||
tlv.add_string(p->GetTitleSound());
|
tlv.add_string(p->GetUuid());
|
||||||
tlv.add_string(p->GetName());
|
tlv.add_string(p->GetTitleImage());
|
||||||
tlv.add_string(p->GetDescription());
|
tlv.add_string(p->GetTitleSound());
|
||||||
tlv.add_integer(p->GetVersion());
|
tlv.add_string(p->GetName());
|
||||||
|
tlv.add_string(p->GetDescription());
|
||||||
|
tlv.add_integer(p->GetVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -123,6 +127,14 @@ void LibraryManager::Save()
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LibraryManager::CopyToDevice(const std::string &outputDir)
|
||||||
|
{
|
||||||
|
std::thread myThread([&]() {
|
||||||
|
myThread.detach();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool LibraryManager::IsInitialized() const
|
bool LibraryManager::IsInitialized() const
|
||||||
{
|
{
|
||||||
return m_library_path.size() > 0;
|
return m_library_path.size() > 0;
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,15 @@ public:
|
||||||
std::vector<std::shared_ptr<StoryProject>>::const_iterator begin() const { return m_projectsList.begin(); }
|
std::vector<std::shared_ptr<StoryProject>>::const_iterator begin() const { return m_projectsList.begin(); }
|
||||||
std::vector<std::shared_ptr<StoryProject>>::const_iterator end() const { return m_projectsList.end(); }
|
std::vector<std::shared_ptr<StoryProject>>::const_iterator end() const { return m_projectsList.end(); }
|
||||||
|
|
||||||
|
uint32_t ProjectsCount() const { return m_projectsList.size(); };
|
||||||
|
|
||||||
void Save();
|
void Save();
|
||||||
void Scan();
|
void Scan();
|
||||||
|
|
||||||
|
// Copie toutes les histoires sélectionnées vers un répertoire
|
||||||
|
// On va ne copier que les fichiers de sortie au format désiré
|
||||||
|
void CopyToDevice(const std::string &outputDir);
|
||||||
|
|
||||||
std::shared_ptr<StoryProject> NewProject();
|
std::shared_ptr<StoryProject> NewProject();
|
||||||
void CheckDirectories();
|
void CheckDirectories();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,9 @@ public:
|
||||||
void CreateTree();
|
void CreateTree();
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
void Select(bool selected) { m_selected = selected; }
|
||||||
|
bool IsSelected() const { return m_selected; }
|
||||||
|
|
||||||
void SetImageFormat(ImageFormat format);
|
void SetImageFormat(ImageFormat format);
|
||||||
void SetSoundFormat(SoundFormat format);
|
void SetSoundFormat(SoundFormat format);
|
||||||
void SetDisplayFormat(int w, int h);
|
void SetDisplayFormat(int w, int h);
|
||||||
|
|
@ -105,8 +108,6 @@ public:
|
||||||
static void EraseString(std::string &theString, const std::string &toErase);
|
static void EraseString(std::string &theString, const std::string &toErase);
|
||||||
static std::string ToUpper(const std::string &input);
|
static std::string ToUpper(const std::string &input);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ParseStoryInformation(nlohmann::json &j);
|
bool ParseStoryInformation(nlohmann::json &j);
|
||||||
private:
|
private:
|
||||||
// Project properties and location
|
// Project properties and location
|
||||||
|
|
@ -116,6 +117,7 @@ private:
|
||||||
std::string m_titleSound;
|
std::string m_titleSound;
|
||||||
std::string m_description;
|
std::string m_description;
|
||||||
int m_version;
|
int m_version;
|
||||||
|
bool m_selected{false};
|
||||||
|
|
||||||
std::filesystem::path m_assetsPath;
|
std::filesystem::path m_assetsPath;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,7 @@ if(UNIX)
|
||||||
SDL3::SDL3
|
SDL3::SDL3
|
||||||
SDL3_image::SDL3_image
|
SDL3_image::SDL3_image
|
||||||
libcurl_static
|
libcurl_static
|
||||||
OpenSSL::SSL OpenSSL::Crypto
|
# OpenSSL::SSL OpenSSL::Crypto
|
||||||
)
|
)
|
||||||
elseif(WIN32)
|
elseif(WIN32)
|
||||||
target_link_libraries(${STORY_EDITOR_PROJECT}
|
target_link_libraries(${STORY_EDITOR_PROJECT}
|
||||||
|
|
|
||||||
|
|
@ -17,27 +17,30 @@ void download_file(CURL *curl,
|
||||||
std::function<void(bool, const std::string &filename)> finished_callback)
|
std::function<void(bool, const std::string &filename)> finished_callback)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
CURLcode res;
|
CURLcode res = CURLE_FAILED_INIT;
|
||||||
|
|
||||||
if (curl)
|
if (curl)
|
||||||
{
|
{
|
||||||
//SetConsoleTextAttribute(hConsole, 11);
|
//SetConsoleTextAttribute(hConsole, 11);
|
||||||
fp = fopen(output_file.c_str(),"wb");
|
fp = fopen(output_file.c_str(),"wb");
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
if (fp)
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
|
||||||
std::cout<<" Start download"<<std::endl<<std::endl;
|
|
||||||
|
|
||||||
res = curl_easy_perform(curl);
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
if(res == CURLE_OK)
|
|
||||||
{
|
{
|
||||||
std::cout<< "\r\n The file was download with success\r\n"<< std::endl;
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
}
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||||
else
|
std::cout<<" Start download"<<std::endl<<std::endl;
|
||||||
{
|
|
||||||
std::cout<< "\r\n Error \r\n"<< std::endl;
|
res = curl_easy_perform(curl);
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
if(res == CURLE_OK)
|
||||||
|
{
|
||||||
|
std::cout<< "\r\n The file was download with success\r\n"<< std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout<< "\r\n Error \r\n"<< std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finished_callback(res == CURLE_OK, output_file);
|
finished_callback(res == CURLE_OK, output_file);
|
||||||
|
|
@ -375,6 +378,16 @@ void LibraryWindow::Draw()
|
||||||
ImGuiFileDialog::Instance()->OpenDialog("ChooseLibraryDirDialog", "Choose a library directory", nullptr, config);
|
ImGuiFileDialog::Instance()->OpenDialog("ChooseLibraryDirDialog", "Choose a library directory", nullptr, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::Button(ICON_MDI_FOLDER " Export to device"))
|
||||||
|
{
|
||||||
|
IGFD::FileDialogConfig config;
|
||||||
|
config.path = ".";
|
||||||
|
config.countSelectionMax = 1;
|
||||||
|
config.flags = ImGuiFileDialogFlags_Modal;
|
||||||
|
|
||||||
|
ImGuiFileDialog::Instance()->OpenDialog("ChooseOutputDirDialog", "Choose an output directory", nullptr, config);
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_libraryManager.IsInitialized())
|
if (!m_libraryManager.IsInitialized())
|
||||||
{
|
{
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
@ -425,38 +438,40 @@ void LibraryWindow::Draw()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ImGui::BeginTable("library_table", 3, tableFlags))
|
if (ImGui::BeginTable("library_table", 3, tableFlags))
|
||||||
{
|
{
|
||||||
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed);
|
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed);
|
||||||
ImGui::TableSetupColumn("Select", ImGuiTableColumnFlags_WidthFixed);
|
ImGui::TableSetupColumn("Select", ImGuiTableColumnFlags_WidthFixed);
|
||||||
ImGui::TableSetupColumn("Actions", ImGuiTableColumnFlags_WidthFixed);
|
ImGui::TableSetupColumn("Actions", ImGuiTableColumnFlags_WidthFixed);
|
||||||
|
|
||||||
|
|
||||||
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(0);
|
ImGui::TableSetColumnIndex(0);
|
||||||
ImGui::TableHeader(ImGui::TableGetColumnName(0));
|
ImGui::TableHeader(ImGui::TableGetColumnName(0));
|
||||||
|
|
||||||
|
static bool select_all = false;
|
||||||
static bool column_selected = false;
|
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(1);
|
ImGui::TableSetColumnIndex(1);
|
||||||
const char* column_name = ImGui::TableGetColumnName(1); // Retrieve name passed to TableSetupColumn()
|
const char* column_name = ImGui::TableGetColumnName(1); // Retrieve name passed to TableSetupColumn()
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
||||||
ImGui::Checkbox("##checkall", &column_selected);
|
if (ImGui::Checkbox("##checkall", &select_all))
|
||||||
|
{
|
||||||
|
// Mettre à jour tous les checkboxes des lignes en fonction de l'état du checkbox de l'en-tête
|
||||||
|
for (auto &p : m_libraryManager)
|
||||||
|
{
|
||||||
|
p->Select(select_all);
|
||||||
|
}
|
||||||
|
}
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
|
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
|
||||||
ImGui::TableHeader(column_name);
|
ImGui::TableHeader(column_name);
|
||||||
|
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(2);
|
ImGui::TableSetColumnIndex(2);
|
||||||
ImGui::TableHeader(ImGui::TableGetColumnName(2));
|
ImGui::TableHeader(ImGui::TableGetColumnName(2));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int internal_id = 1;
|
int internal_id = 1;
|
||||||
|
uint32_t row = 0;
|
||||||
for (auto &p : m_libraryManager)
|
for (auto &p : m_libraryManager)
|
||||||
{
|
{
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
|
|
@ -465,9 +480,17 @@ void LibraryWindow::Draw()
|
||||||
ImGui::PushID(internal_id++);
|
ImGui::PushID(internal_id++);
|
||||||
|
|
||||||
// Select
|
// Select
|
||||||
ImGui::TableNextColumn();
|
|
||||||
ImGui::Checkbox("", &column_selected);
|
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
bool state = p->IsSelected();
|
||||||
|
ImGui::Checkbox("", &state);
|
||||||
|
|
||||||
|
if (!state && select_all)
|
||||||
|
{
|
||||||
|
select_all = false; // Désélectionner "Select All" si un des items est désélectionné
|
||||||
|
}
|
||||||
|
|
||||||
|
row++;
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
|
|
||||||
if (ImGui::SmallButton("Load"))
|
if (ImGui::SmallButton("Load"))
|
||||||
|
|
@ -475,7 +498,6 @@ void LibraryWindow::Draw()
|
||||||
m_storyManager.OpenProject(p->GetUuid());
|
m_storyManager.OpenProject(p->GetUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::SmallButton("Remove"))
|
if (ImGui::SmallButton("Remove"))
|
||||||
{
|
{
|
||||||
|
|
@ -599,7 +621,8 @@ void LibraryWindow::Draw()
|
||||||
|
|
||||||
|
|
||||||
// ---------------- CHOOSE LIBRARY DIR
|
// ---------------- CHOOSE LIBRARY DIR
|
||||||
if (ImGuiFileDialog::Instance()->Display("ChooseLibraryDirDialog"))
|
static ImGuiWindowFlags window_flags = 0;
|
||||||
|
if (ImGuiFileDialog::Instance()->Display("ChooseLibraryDirDialog", window_flags, ImVec2(300, 200)))
|
||||||
{
|
{
|
||||||
// action if OK
|
// action if OK
|
||||||
if (ImGuiFileDialog::Instance()->IsOk())
|
if (ImGuiFileDialog::Instance()->IsOk())
|
||||||
|
|
@ -617,6 +640,30 @@ void LibraryWindow::Draw()
|
||||||
ImGuiFileDialog::Instance()->Close();
|
ImGuiFileDialog::Instance()->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------- EXPORT SELECTED STORIES TO SPECIFIED DIRECTORY
|
||||||
|
static ImGuiWindowFlags choose_output_window_flags = 0;
|
||||||
|
if (ImGuiFileDialog::Instance()->Display("ChooseOutputDirDialog", choose_output_window_flags, ImVec2(300, 200)))
|
||||||
|
{
|
||||||
|
// action if OK
|
||||||
|
if (ImGuiFileDialog::Instance()->IsOk())
|
||||||
|
{
|
||||||
|
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
||||||
|
std::string outputDir = ImGuiFileDialog::Instance()->GetCurrentPath();
|
||||||
|
|
||||||
|
if (std::filesystem::is_directory(outputDir))
|
||||||
|
{
|
||||||
|
// Generate TLV file (index of all stories)
|
||||||
|
m_libraryManager.Save();
|
||||||
|
|
||||||
|
// Copy all files to device
|
||||||
|
m_libraryManager.CopyToDevice(outputDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// close
|
||||||
|
ImGuiFileDialog::Instance()->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
WindowBase::EndDraw();
|
WindowBase::EndDraw();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue