Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI: reference and description from filename #320

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 84 additions & 1 deletion Source/GUI/Qt/GUI_Main_xxxx_EditMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void GUI_Main_xxxx_EditMenu::updateEditMenu( QList<QPair<string, string> > forI
//History data
ZtringList History; History.Write(Ztring().From_UTF8(C->History(FileName, Field)));

//Data data
//Date data
string Date;
if (Field=="OriginationDate" || Field=="OriginationTime" || Field=="ICRD")
{
Expand All @@ -75,6 +75,27 @@ void GUI_Main_xxxx_EditMenu::updateEditMenu( QList<QPair<string, string> > forI
Date.clear();
}

//FileTitle data
string FileTitle;
string FileTitle32;
string FileTitle256;
if (Field=="OriginatorReference" || Field=="Description")
{
FileTitle=FileName;
#ifdef _WIN32
size_t SeparatorPos=FileTitle.find_last_of('\\');
#else
size_t SeparatorPos=FileTitle.find_last_of('/');
#endif
if (SeparatorPos!=string::npos && SeparatorPos+1<FileTitle.size())
FileTitle=FileTitle.substr(SeparatorPos+1);
FileTitle=FileTitle.substr(0, FileTitle.find_last_of('.'));
if (Field=="OriginatorReference")
FileTitle32=FileTitle.size()>32?FileTitle.erase(32):FileTitle;
else
FileTitle256=FileTitle.size()>256?FileTitle.erase(256):FileTitle;
}

//Copy
if (!C->Get(FileName, Field).empty())
{
Expand Down Expand Up @@ -115,6 +136,31 @@ void GUI_Main_xxxx_EditMenu::updateEditMenu( QList<QPair<string, string> > forI
connect(Action, SIGNAL(triggered(bool)), this, SLOT(onActionTriggered()));
}

//Handling filename display
if (!FileTitle32.empty())
{
string Text;
Text="&Set OriginatorReference to file name ("+FileTitle32+")";

QAction* Action=new QAction(QString::fromUtf8(Text.c_str()));
Action->setProperty("Action", "Name");
Main->Menu_Edit->addAction(Action);
Main->Menu_Edit->addSeparator();
connect(Action, SIGNAL(triggered(bool)), this, SLOT(onActionTriggered()));
}

if (!FileTitle256.empty())
{
string Text;
Text="&Set BEXT description to file name ("+FileTitle256+")";

QAction* Action=new QAction(QString::fromUtf8(Text.c_str()));
Action->setProperty("Action", "Name");
Main->Menu_Edit->addAction(Action);
Main->Menu_Edit->addSeparator();
connect(Action, SIGNAL(triggered(bool)), this, SLOT(onActionTriggered()));
}

//Handling date display
if (!Date.empty())
{
Expand Down Expand Up @@ -147,6 +193,8 @@ void GUI_Main_xxxx_EditMenu::updateEditMenu( QList<QPair<string, string> > forI
else if (Items.count()>1)
{
//Clear data
bool ShowOriginatorReference=true;
bool ShowBextDescription=true;
bool ShowOriginationDate=true;
bool ShowICRDDate=true;
bool ShowClear=false;
Expand All @@ -161,6 +209,12 @@ void GUI_Main_xxxx_EditMenu::updateEditMenu( QList<QPair<string, string> > forI
if (Field!="OriginationDate" && Field!="OriginationTime")
ShowOriginationDate=false;

if (Field!="OriginatorReference")
ShowOriginatorReference=false;

if (Field!="Description")
ShowBextDescription=false;

if (Field!="ICRD")
ShowICRDDate=false;

Expand Down Expand Up @@ -192,6 +246,25 @@ void GUI_Main_xxxx_EditMenu::updateEditMenu( QList<QPair<string, string> > forI
connect(Action, SIGNAL(triggered(bool)), this, SLOT(onActionTriggered()));
}

//Handling originator reference display
if (ShowOriginatorReference)
{
QAction* Action=new QAction("Set OriginatorReference to files names");
Action->setProperty("Action", "Name");
Main->Menu_Edit->addSeparator();
Main->Menu_Edit->addAction(Action);
connect(Action, SIGNAL(triggered(bool)), this, SLOT(onActionTriggered()));
}

//Handling BEXT description display
if (ShowBextDescription)
{
QAction* Action=new QAction("Set BEXT description to files names");
Action->setProperty("Action", "Name");
Main->Menu_Edit->addAction(Action);
connect(Action, SIGNAL(triggered(bool)), this, SLOT(onActionTriggered()));
}

//Handling origination date display
if (ShowOriginationDate)
{
Expand Down Expand Up @@ -274,6 +347,16 @@ void GUI_Main_xxxx_EditMenu::onActionTriggered()
}
Q_EMIT valuesChanged(false);
}
else if (Action->property("Action")=="Name")
{
for (int Pos=0; Pos<Items.size(); Pos++)
{
string FileName=Items.at(Pos).first;
string Field=Items.at(Pos).second;
C->Set(FileName, Field, "FILENAME");
}
Q_EMIT valuesChanged(true);
}
else if (Action->property("Action")=="Date")
{
for (int Pos=0; Pos<Items.size(); Pos++)
Expand Down
4 changes: 4 additions & 0 deletions Source/Riff/Riff_Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ class Riff_Base
bool IsRF64;
bool Trace_UseDec;
bool Read_Only;
bool BextDescriptionFromFileName;
bool OriginatorReferenceFromFileName;

CriticalSection CS;
float Progress;
Expand Down Expand Up @@ -450,6 +452,8 @@ class Riff_Base
IsRF64=false;
Trace_UseDec=false;
Read_Only=false;
BextDescriptionFromFileName=false;
OriginatorReferenceFromFileName=false;
Progress=0;
Canceling=false;
}
Expand Down
60 changes: 60 additions & 0 deletions Source/Riff/Riff_Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,24 @@ void AdaptEOL(string& Value, adapteol Adapt=adapt_platform)
Value=Value2;
}

//---------------------------------------------------------------------------
inline string BaseFileName(const string& FileName)
{
if (FileName.empty())
return FileName;

string ToReturn=FileName;
#ifdef _WIN32
size_t Pos=ToReturn.find_last_of("\\");
#else
size_t Pos=ToReturn.find_last_of("/");
#endif
if (Pos!=string::npos && Pos+1<ToReturn.size())
ToReturn=ToReturn.substr(Pos+1);

return ToReturn.substr(0, ToReturn.find_last_of('.'));
}

//***************************************************************************
// Constructor/Destructor
//***************************************************************************
Expand Down Expand Up @@ -1429,6 +1447,36 @@ bool Riff_Handler::Set_Internal(const string &Field_, const string &Value_, rule
}
}

// Use file name
if (Field=="originatorreference" || Field=="description")
{
if (Value=="FILENAME")
{
if (Chunks->Global)
{
Value=BaseFileName(Chunks->Global->File_Name.To_UTF8());
if (Field=="originatorreference" && Value.size()>32)
Value=Value.erase(32);
else if (Field=="description" && Value.size()>256)
Value=Value.erase(256);
}
else
Value=string();

if (Field=="originatorreference")
Chunks->Global->OriginatorReferenceFromFileName=true;
else
Chunks->Global->BextDescriptionFromFileName=true;
}
else
{
if (Field=="originatorreference" && Chunks->Global->OriginatorReferenceFromFileName && Value!=Get_Internal(Field))
Chunks->Global->OriginatorReferenceFromFileName=false;
else if (Field=="description" && Chunks->Global->BextDescriptionFromFileName && Value!=Get_Internal(Field))
Chunks->Global->BextDescriptionFromFileName=false;
}
}

// EBU ISRC recommandations, link aXML ISRC and INFO ISRC
string FieldToFill, ValueToFill;
if (Rules.EBU_ISRC_Rec)
Expand Down Expand Up @@ -1990,6 +2038,12 @@ bool Riff_Handler::IsValid_Internal(const string &Field_, const string &Value_,
//If error
if (!Message.empty())
IsValid_Errors<<"malformed input, Description "<<Message;

if (Chunks && Chunks->Global && Chunks->Global->BextDescriptionFromFileName)
{
if (Value.size()<BaseFileName(Chunks->Global->File_Name.To_UTF8()).size())
IsValid_Warnings<<"full file name does not fit in Description field";
}
}

//Originator
Expand Down Expand Up @@ -2078,6 +2132,12 @@ bool Riff_Handler::IsValid_Internal(const string &Field_, const string &Value_,
//If error
if (!Message.empty())
IsValid_Errors<<"malformed input, OriginatorReference "<<Message;

if (Chunks && Chunks->Global && Chunks->Global->OriginatorReferenceFromFileName)
{
if (Value.size()<BaseFileName(Chunks->Global->File_Name.To_UTF8()).size())
IsValid_Warnings<<"full file name does not fit in OriginatorReference field";
}
}

//OriginationDate
Expand Down