Skip to content

Commit

Permalink
Merge pull request MediaArea#491 from g-maxime/sponsors
Browse files Browse the repository at this point in the history
Translatable sponsor message
  • Loading branch information
JeromeMartinez authored Oct 7, 2020
2 parents 00ff6d2 + 61cf385 commit 687f4b5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 38 deletions.
66 changes: 51 additions & 15 deletions Source/Common/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,17 @@ int Preferences::Config_Load()
Donate_Display=false;

// Sponsor
if (Config(__T("Sponsored"))==__T("1") && Config(__T("SponsorMessage"))!=__T("") && Config(__T("SponsorUrl"))!=__T(""))
if (Config(__T("Sponsored"))==__T("1"))
{
Sponsored=true;
SponsorMessage=Config(__T("SponsorMessage"));
SponsorUrl=Config(__T("SponsorUrl"));

Ztring Saved=Config(__T("SponsorMessage"));
Saved.FindAndReplace(__T("\\r\\n"), __T("\r\n"));
SponsorMessage.Write(Saved);

Saved=Config(__T("SponsorUrl"));
Saved.FindAndReplace(__T("\\r\\n"), __T("\r\n"));
SponsorUrl.Write(Saved);
}

delete Reg_User; Reg_User=NULL;
Expand Down Expand Up @@ -464,21 +470,30 @@ void __fastcall ThreadInternetCheck::Execute()
}

//Sponsored
ZtringList Sponsor=Download.SubSheet(__T("ShowSponsor"))[0];
if (Sponsor(1)==__T("1") && Sponsor(2)!=__T("") && Sponsor(3)!=__T(""))
Prefs->Config(__T("Sponsored"))=__T("0");
Prefs->Config(__T("SponsorMessage"))=__T("");
Prefs->Config(__T("SponsorUrl"))=__T("");

ZtringListList Sponsor=Download.SubSheet(__T("ShowSponsor"));
if (int En=Sponsor.Find(__T("en"), 1)!=-1 && Sponsor[En](2)!=__T("") && Sponsor[En](3)!=__T(""))
{
Prefs->Config(__T("Sponsored"))=__T("1");
Prefs->Config(__T("SponsorMessage"))=Sponsor(2);
Prefs->Config(__T("SponsorUrl"))=Sponsor(3);
Prefs->Config_Save();
}
else
{
Prefs->Config(__T("Sponsored"))=__T("0");
Prefs->Config(__T("SponsorMessage"))=__T("");
Prefs->Config(__T("SponsorUrl"))=__T("");
Prefs->Config_Save();
Ztring Message;
Ztring Url;
for (size_t Pos=0; Pos<Sponsor.size(); Pos++)
{
if (Sponsor[Pos](1)!=__T(""))
{
if (Sponsor[Pos](2)!=__T(""))
Message+=(Message.empty()?__T(""):__T("\\r\\n"))+Sponsor[Pos](1)+__T(";")+Sponsor[Pos](2);
if (Sponsor[Pos](3)!=__T(""))
Url+=(Url.empty()?__T(""):__T("\\r\\n"))+Sponsor[Pos](1)+__T(";")+Sponsor[Pos](3);
}
}
Prefs->Config(__T("SponsorMessage"))=Message.Quote();
Prefs->Config(__T("SponsorUrl"))=Url.Quote();
}
Prefs->Config_Save();

//Chargement de pages
ZtringListList Pages=Download.SubSheet(__T("Url"));
Expand Down Expand Up @@ -1399,6 +1414,27 @@ int Preferences::ShellToolTip()
//---------------------------------------------------------------------------
ZenLib::Ztring &Preferences::Translate(ZenLib::Ztring Name)
{
if (Name==__T("SponsorMessage") || Name==__T("SponsorUrl"))
{
Ztring Language=Translate(__T(" Language_ISO639"));
if (Name==__T("SponsorMessage"))
{
int Index=SponsorMessage.Find(Language, 0);
if (Index==-1 || SponsorMessage(Index)(1)==__T(""))
Index=SponsorMessage.Find(__T("en"), 0);

return SponsorMessage(Index)(1);
}
else if (Name==__T("SponsorUrl"))
{
int Index=SponsorUrl.Find(Language, 0);
if (Index==-1 || SponsorUrl(Index)(1)==__T(""))
Index=SponsorUrl.Find(__T("en"), 0);

return SponsorUrl(Index)(1);
}
}

size_t Pos=Details[Prefs_Language].Find(Name, 0, 0, __T("=="), Ztring_CaseSensitive);

//If not in the language, search for English language
Expand Down
4 changes: 2 additions & 2 deletions Source/Common/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Preferences
ZenLib::ZtringListListF Config; //Configuration file
ZenLib::ZtringList FilesList[Prefs_Max]; //List of available files for an Item
ZenLib::ZtringListListF Details[Prefs_Max];
ZenLib::ZtringListList SponsorMessage;
ZenLib::ZtringListList SponsorUrl;

//Useful functions about preferences
int Config_Create ();
Expand Down Expand Up @@ -90,8 +92,6 @@ class Preferences

//Sponsor
bool Sponsored;
ZenLib::Ztring SponsorMessage;
ZenLib::Ztring SponsorUrl;
};

//General preference for the whole program
Expand Down
23 changes: 9 additions & 14 deletions Source/GUI/VCL/GUI_About.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ void __fastcall TAboutF::FormShow(TObject *Sender)
WriteToTranslator->Caption=Prefs->Translate(__T("WriteToTranslator")).c_str();
WriteToTranslator->Visible=true;
}

Sponsor_Label->Caption = (__T("<a href=\"") + Prefs->SponsorUrl + __T("\">") + Prefs->SponsorMessage + __T("</a>")).c_str();

if (!Prefs->Sponsored || Prefs->Donated)
Sponsor_Label->Visible=false;
if (Prefs->Sponsored && !Prefs->Donated && !Prefs->Translate(__T("SponsorMessage")).empty() && !Prefs->Translate(__T("SponsorMessage")).empty())
{
//Sponsor->Visible=false;
Sponsor_Label->Visible=false;
Sponsor_Label->Caption = (__T("<a href=\"") + Prefs->Translate(__T("SponsorUrl")) + __T("\">") + Prefs->Translate(__T("SponsorMessage")) + __T("</a>")).c_str();
Sponsor_Label->Visible=true;
}
}

Expand Down Expand Up @@ -117,17 +115,14 @@ void __fastcall TAboutF::WebSiteClick(TObject *Sender)
ShellExecute(NULL, NULL, MEDIAINFO_URL, NULL, NULL, SW_SHOWNORMAL);
}

//---------------------------------------------------------------------------
void __fastcall TAboutF::SponsorClick(TObject *Sender, const UnicodeString Link, TSysLinkType LinkType)
{
ShellExecute(NULL, NULL, Link.c_str(), NULL, NULL, SW_SHOWNORMAL);
}

//***************************************************************************
// C++
//***************************************************************************

#endif //MEDIAINFOGUI_ABOUT_NO



void __fastcall TAboutF::SponsorClick(TObject *Sender, const UnicodeString Link,
TSysLinkType LinkType)
{
ShellExecute(NULL, NULL, Link.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
13 changes: 6 additions & 7 deletions Source/GUI/VCL/GUI_Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,11 @@ void __fastcall TMainF::Translate()
*/
}

M_Sponsor->Caption = Prefs->SponsorMessage.c_str();

if (!Prefs->Sponsored || Prefs->Donated)
M_Sponsor->Visible=false;
if (Prefs->Sponsored && !Prefs->Donated && !Prefs->Translate(__T("SponsorMessage")).empty() && !Prefs->Translate(__T("SponsorMessage")).empty())
{
M_Sponsor->Visible=false;
M_Sponsor->Caption = + Prefs->Translate(__T("SponsorMessage")).c_str();
M_Sponsor->Visible=true;
}
}

Expand Down Expand Up @@ -1800,9 +1800,8 @@ void __fastcall TMainF::M_NewVersionClick(TObject *Sender)
ShellExecute(NULL, NULL, (Ztring(__T("http://mediaarea.net/"))+Prefs->Translate(__T(" Language_ISO639"))+__T("/MediaInfo/?NewVersionRequested=true")).c_str(), NULL, NULL, SW_SHOWNORMAL);
}

//---------------------------------------------------------------------------
void __fastcall TMainF::M_SponsorClick(TObject *Sender)
{
ShellExecute(NULL, NULL, Prefs->SponsorUrl.c_str(), NULL, NULL, SW_SHOWNORMAL);
ShellExecute(NULL, NULL, Prefs->Translate(__T("SponsorUrl")).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

0 comments on commit 687f4b5

Please sign in to comment.