Added meta information in session file XML, for quick access to file

info (SessionCreator::info), displayed in the user interface (list of
sessions in quick access).
This commit is contained in:
brunoherbelin
2020-07-04 10:18:26 +02:00
parent 3f0def5c26
commit 84cd772644
8 changed files with 72 additions and 16 deletions

View File

@@ -187,7 +187,6 @@ bool ImGuiToolkit::IconToggle(int i, int j, int i_toggle, int j_toggle, bool* to
if (tooltips != nullptr && tooltips[tooltipid] != nullptr && ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
// ImGui::Text("%s-clic on source to show pannel", Settings::application.pannel_stick?"Single":"Double");
ImGui::Text("%s", tooltips[tooltipid]);
ImGui::EndTooltip();
}

View File

@@ -89,6 +89,8 @@ static void saveSession(const std::string& filename, Session *session)
XMLElement *version = xmlDoc.NewElement(APP_NAME);
version->SetAttribute("major", XML_VERSION_MAJOR);
version->SetAttribute("minor", XML_VERSION_MINOR);
version->SetAttribute("size", session->numSource());
version->SetAttribute("date", SystemToolkit::date_time_string().c_str());
xmlDoc.InsertEndChild(version);
// 1. list of sources
@@ -123,6 +125,7 @@ static void saveSession(const std::string& filename, Session *session)
views->InsertEndChild(render);
}
// save file to disk
if ( XMLSaveDoc(&xmlDoc, filename) ) {
// all ok

View File

@@ -17,6 +17,27 @@
using namespace tinyxml2;
std::string SessionCreator::info(const std::string& filename)
{
std::string ret = "";
XMLDocument doc;
XMLError eResult = doc.LoadFile(filename.c_str());
if ( XMLResultError(eResult))
return ret;
XMLElement *header = doc.FirstChildElement(APP_NAME);
if (header != nullptr && header->Attribute("date") != 0) {
int s = header->IntAttribute("size");
ret = std::to_string( s ) + " source" + ( s > 1 ? "s\n" : "\n");
std::string date( header->Attribute("date") );
ret += date.substr(6,2) + "/" + date.substr(4,2) + "/" + date.substr(0,4) + " ";
ret += date.substr(8,2) + ":" + date.substr(10,2) + "\n";
}
return ret;
}
SessionCreator::SessionCreator(Session *session): Visitor(), session_(session)
{
xmlDoc_ = new XMLDocument;
@@ -29,15 +50,15 @@ bool SessionCreator::load(const std::string& filename)
if ( XMLResultError(eResult))
return false;
XMLElement *version = xmlDoc_->FirstChildElement(APP_NAME);
if (version == nullptr) {
XMLElement *header = xmlDoc_->FirstChildElement(APP_NAME);
if (header == nullptr) {
Log::Warning("%s is not a %s session file.", filename.c_str(), APP_NAME);
return false;
}
int version_major = -1, version_minor = -1;
version->QueryIntAttribute("major", &version_major); // TODO incompatible if major is different?
version->QueryIntAttribute("minor", &version_minor);
header->QueryIntAttribute("major", &version_major); // TODO incompatible if major is different?
header->QueryIntAttribute("minor", &version_minor);
if (version_major != XML_VERSION_MAJOR || version_minor != XML_VERSION_MINOR){
Log::Warning("%s is in a different versions of session file. Loading might fail.", filename.c_str());
return false;

View File

@@ -15,6 +15,7 @@ class SessionCreator : public Visitor {
void loadSession(tinyxml2::XMLElement *sessionNode);
void loadConfig(tinyxml2::XMLElement *viewsNode);
public:
SessionCreator(Session *session = nullptr);
@@ -47,6 +48,7 @@ public:
void visit (MediaSource& s) override;
void visit (SessionSource& s) override;
static std::string info(const std::string& filename);
static void XMLToNode(tinyxml2::XMLElement *xml, Node &n);
};

View File

@@ -98,17 +98,30 @@ std::string SystemToolkit::home_path()
char *mHomePath;
// try the system user info
struct passwd* pwd = getpwuid(getuid());
if (pwd) {
if (pwd)
mHomePath = pwd->pw_dir;
}
else {
else
// try the $HOME environment variable
mHomePath = getenv("HOME");
}
return string(mHomePath) + PATH_SEP;
}
std::string SystemToolkit::username()
{
// 1. find home
char *user;
// try the system user info
struct passwd* pwd = getpwuid(getuid());
if (pwd)
user = pwd->pw_name;
else
// try the $USER environment variable
user = getenv("USER");
return string(user);
}
bool create_directory(const string& path)
{
return !mkdir(path.c_str(), 0755) || errno == EEXIST;
@@ -140,7 +153,6 @@ string SystemToolkit::settings_path()
// fallback to home if settings path does not exists
return home;
}
}
string SystemToolkit::full_filename(const std::string& path, const string &filename)

View File

@@ -15,13 +15,16 @@ namespace SystemToolkit
// get fixed length string (17 chars) YYYYMMDDHHmmssiii
std::string date_time_string();
// get the OS dependent username
std::string username();
// get the OS dependent home path
std::string home_path();
// get the OS dependent path where to store settings
std::string settings_path();
// builds the OS dependent complete file name for a settings file
// builds the OS dependent complete file name
std::string full_filename(const std::string& path, const std::string& filename);
// extract the filename from a full path / URI (e.g. file:://home/me/toto.mpg -> toto.mpg)

View File

@@ -38,6 +38,7 @@
#include "Resource.h"
#include "FileDialog.h"
#include "Settings.h"
#include "SessionCreator.h"
#include "ImGuiToolkit.h"
#include "ImGuiVisitor.h"
#include "GstToolkit.h"
@@ -1620,15 +1621,30 @@ void Navigator::RenderMainPannel()
bool session_selected = false;
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
ImGui::ListBoxHeader("##Sessions", 7);
static std::string file_info = "";
static std::list<std::string>::iterator file_selected = sessions_list.end();
for(auto filename = sessions_list.begin(); filename != sessions_list.end(); filename++) {
if (ImGui::Selectable( SystemToolkit::filename(*filename).c_str(), false, ImGuiSelectableFlags_AllowDoubleClick )) {
if (ImGui::IsMouseDoubleClicked(0)) {
Mixer::manager().open( *filename );
session_selected = true;
}
if (ImGui::IsMouseDoubleClicked(0)) {
Mixer::manager().open( *filename );
session_selected = true;
}
else {
file_info = SessionCreator::info(*filename);
file_selected = filename;
}
}
if (ImGui::IsItemHovered() && file_selected != filename) {
file_info.clear();
file_selected = sessions_list.end();
}
}
ImGui::ListBoxFooter();
if (!file_info.empty()) {
ImGui::BeginTooltip();
ImGui::Text("%s", file_info.c_str());
ImGui::EndTooltip();
}
pos = ImGui::GetCursorPos();
ImGui::SameLine();

View File

@@ -86,7 +86,7 @@ bool tinyxml2::XMLSaveDoc(XMLDocument * const doc, std::string filename)
XMLDeclaration *pDec = doc->NewDeclaration();
doc->InsertFirstChild(pDec);
std::string s = "Save time " + SystemToolkit::date_time_string();
std::string s = "Originally saved as " + filename + " by " + SystemToolkit::username();
XMLComment *pComment = doc->NewComment(s.c_str());
doc->InsertEndChild(pComment);