diff options
author | ioannis <ioannis.e@gmail.com> | 2016-02-14 05:53:37 +0300 |
---|---|---|
committer | Kacper Michajłow <kasper93@gmail.com> | 2016-03-14 00:23:19 +0300 |
commit | e84d4bfb4c8cb6b527d3a3824a660354982b754f (patch) | |
tree | 6cb39867a049fa3d262d9590fb5944f5b385cce5 /src | |
parent | 3255040865be30d3743b905d53a31bd0035d6043 (diff) |
Fixes #5761, Append language code when saving subtitles file
Diffstat (limited to 'src')
-rw-r--r-- | src/Subtitles/PGSSub.cpp | 5 | ||||
-rw-r--r-- | src/Subtitles/RLECodedSubtitle.cpp | 3 | ||||
-rw-r--r-- | src/Subtitles/RLECodedSubtitle.h | 4 | ||||
-rw-r--r-- | src/Subtitles/RTS.cpp | 2 | ||||
-rw-r--r-- | src/Subtitles/STS.cpp | 7 | ||||
-rw-r--r-- | src/Subtitles/STS.h | 10 | ||||
-rw-r--r-- | src/Subtitles/SubtitleHelpers.cpp | 41 | ||||
-rw-r--r-- | src/Subtitles/SubtitleHelpers.h | 8 | ||||
-rw-r--r-- | src/mpc-hc/MainFrm.cpp | 16 | ||||
-rw-r--r-- | src/mpc-hc/SubtitlesProviders.h | 2 |
10 files changed, 67 insertions, 31 deletions
diff --git a/src/Subtitles/PGSSub.cpp b/src/Subtitles/PGSSub.cpp index d2abfd0f2..06afb887c 100644 --- a/src/Subtitles/PGSSub.cpp +++ b/src/Subtitles/PGSSub.cpp @@ -1,5 +1,5 @@ /*
- * (C) 2006-2015 see Authors.txt
+ * (C) 2006-2016 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -496,8 +496,9 @@ bool CPGSSubFile::Open(CString fn, CString name /*= _T("")*/, CString videoName {
bool bOpened = false;
+ CString guessed = Subtitle::GuessSubtitleName(fn, videoName, m_lcid, m_eHearingImpaired);
if (name.IsEmpty()) {
- m_name = Subtitle::GuessSubtitleName(fn, videoName);
+ m_name = guessed;
} else {
m_name = name;
}
diff --git a/src/Subtitles/RLECodedSubtitle.cpp b/src/Subtitles/RLECodedSubtitle.cpp index 328f07b32..b130b0de9 100644 --- a/src/Subtitles/RLECodedSubtitle.cpp +++ b/src/Subtitles/RLECodedSubtitle.cpp @@ -1,5 +1,5 @@ /* - * (C) 2008-2015 see Authors.txt + * (C) 2008-2016 see Authors.txt * * This file is part of MPC-HC. * @@ -27,6 +27,7 @@ CRLECodedSubtitle::CRLECodedSubtitle(CCritSec* pLock, const CString& name, LCID : CSubPicProviderImpl(pLock) , m_name(name) , m_lcid(lcid) + , m_eHearingImpaired(Subtitle::HI_UNKNOWN) { } diff --git a/src/Subtitles/RLECodedSubtitle.h b/src/Subtitles/RLECodedSubtitle.h index 7f5d31e6a..b71e8538c 100644 --- a/src/Subtitles/RLECodedSubtitle.h +++ b/src/Subtitles/RLECodedSubtitle.h @@ -1,5 +1,5 @@ /* - * (C) 2008-2015 see Authors.txt + * (C) 2008-2016 see Authors.txt * * This file is part of MPC-HC. * @@ -22,6 +22,7 @@ #include "../SubPic/SubPicProviderImpl.h" #include "ColorConvTable.h" +#include "SubtitleHelpers.h" class __declspec(uuid("FCA68599-C83E-4ea5-94A3-C2E1B0E326B9")) @@ -60,6 +61,7 @@ protected: CString m_name; LCID m_lcid; + Subtitle::HearingImpairedType m_eHearingImpaired; ColorConvTable::YuvMatrixType m_eSourceMatrix = ColorConvTable::NONE; }; diff --git a/src/Subtitles/RTS.cpp b/src/Subtitles/RTS.cpp index a3714bfb8..89f0ed5c6 100644 --- a/src/Subtitles/RTS.cpp +++ b/src/Subtitles/RTS.cpp @@ -3231,7 +3231,7 @@ STDMETHODIMP CRenderedTextSubtitle::GetStreamInfo(int iStream, WCHAR** ppName, L strLanguage.ReleaseBufferSetLength(std::max(len - 1, 0));
}
- if (!strLanguage.IsEmpty() && m_eHearingImpaired == HI_YES) {
+ if (!strLanguage.IsEmpty() && m_eHearingImpaired == Subtitle::HI_YES) {
strLanguage = '[' + strLanguage + ']';
}
CStringW strName;
diff --git a/src/Subtitles/STS.cpp b/src/Subtitles/STS.cpp index a9072dd5a..e7174c49e 100644 --- a/src/Subtitles/STS.cpp +++ b/src/Subtitles/STS.cpp @@ -1823,7 +1823,7 @@ CSimpleTextSubtitle::CSimpleTextSubtitle() , m_ePARCompensationType(EPCTDisabled)
, m_dPARCompensation(1.0)
, m_provider(_T("Local"))
- , m_eHearingImpaired(HI_UNKNOWN)
+ , m_eHearingImpaired(Subtitle::HI_UNKNOWN)
{
}
@@ -2613,8 +2613,9 @@ bool CSimpleTextSubtitle::Open(CString fn, int CharSet, CString name, CString vi return false;
}
+ CString guessed = Subtitle::GuessSubtitleName(fn, videoName, m_lcid, m_eHearingImpaired);
if (name.IsEmpty()) {
- name = Subtitle::GuessSubtitleName(fn, videoName);
+ name = guessed;
}
return Open(&f, CharSet, name);
@@ -2680,7 +2681,7 @@ bool CSimpleTextSubtitle::Open(CTextFile* f, int CharSet, CString name) return false;
}
-bool CSimpleTextSubtitle::Open(CString provider, BYTE* data, int len, int CharSet, CString name, HearingImpairedType eHearingImpaired, LCID lcid)
+bool CSimpleTextSubtitle::Open(CString provider, BYTE* data, int len, int CharSet, CString name, Subtitle::HearingImpairedType eHearingImpaired, LCID lcid)
{
bool fRet = Open(data, len, CharSet, name);
diff --git a/src/Subtitles/STS.h b/src/Subtitles/STS.h index e7193accc..7ac8b9994 100644 --- a/src/Subtitles/STS.h +++ b/src/Subtitles/STS.h @@ -123,12 +123,6 @@ public: }
};
-enum HearingImpairedType {
- HI_UNKNOWN = -1,
- HI_NO = 0,
- HI_YES = 1
-};
-
class CSimpleTextSubtitle : public CAtlArray<STSEntry>
{
friend class CSubtitleEditorDlg;
@@ -148,7 +142,7 @@ public: CString m_provider;
- HearingImpairedType m_eHearingImpaired;
+ Subtitle::HearingImpairedType m_eHearingImpaired;
CSize m_dstScreenSize;
int m_defaultWrapStyle;
@@ -186,7 +180,7 @@ public: bool Open(CString fn, int CharSet, CString name = _T(""), CString videoName = _T(""));
bool Open(CTextFile* f, int CharSet, CString name);
bool Open(BYTE* data, int len, int CharSet, CString name);
- bool Open(CString provider, BYTE* data, int len, int CharSet, CString name, HearingImpairedType eHearingImpaired, LCID lcid);
+ bool Open(CString provider, BYTE* data, int len, int CharSet, CString name, Subtitle::HearingImpairedType eHearingImpaired, LCID lcid);
bool SaveAs(CString fn, Subtitle::SubType type, double fps = -1, LONGLONG delay = 0, CTextFile::enc e = CTextFile::DEFAULT_ENCODING, bool bCreateExternalStyleFile = true);
void Add(CStringW str, bool fUnicode, REFERENCE_TIME start, REFERENCE_TIME end, CString style = _T("Default"), CString actor = _T(""), CString effect = _T(""), const CRect& marginRect = CRect(0, 0, 0, 0), int layer = 0, int readorder = -1);
diff --git a/src/Subtitles/SubtitleHelpers.cpp b/src/Subtitles/SubtitleHelpers.cpp index 020614187..7e1a6d0a9 100644 --- a/src/Subtitles/SubtitleHelpers.cpp +++ b/src/Subtitles/SubtitleHelpers.cpp @@ -171,10 +171,9 @@ void Subtitle::GetSubFileNames(CString fn, const CAtlArray<CString>& paths, CAtl qsort(ret.GetData(), ret.GetCount(), sizeof(SubFile), SubFileCompare); } -CString Subtitle::GuessSubtitleName(CString fn, CString videoName) +CString Subtitle::GuessSubtitleName(const CString& fn, CString videoName, LCID& lcid, HearingImpairedType& hi) { CString name, lang; - bool bHearingImpaired = false; // The filename of the subtitle file int iExtStart = fn.ReverseFind('.'); @@ -212,8 +211,18 @@ CString Subtitle::GuessSubtitleName(CString fn, CString videoName) ASSERT(mc[1].matched); lang = ISO639XToLanguage(CStringA(mc[1].str().c_str()), true); - if (!lang.IsEmpty() && mc[2].matched) { - bHearingImpaired = (CString(mc[2].str().c_str()).CompareNoCase(_T("hi")) == 0); + if (!lang.IsEmpty()) { + size_t len = mc[1].str().size(); + if (len == 3) { + lcid = ISO6392ToLcid(CStringA(mc[1].str().c_str())); + } else if (len == 2) { + lcid = ISO6391ToLcid(CStringA(mc[1].str().c_str())); + } + if (mc[2].matched) { + if (CString(mc[2].str().c_str()).CompareNoCase(_T("hi")) == 0) { + hi = HI_YES; + } + } } } } @@ -227,6 +236,14 @@ CString Subtitle::GuessSubtitleName(CString fn, CString videoName) ASSERT(mc.size() == 3); ASSERT(mc[1].matched); lang = ISO639XToLanguage(CStringA(mc[1].str().c_str()), true); + if (!lang.IsEmpty()) { + size_t len = mc[1].str().size(); + if (len == 3) { + lcid = ISO6392ToLcid(CStringA(mc[1].str().c_str())); + } else if (len == 2) { + lcid = ISO6391ToLcid(CStringA(mc[1].str().c_str())); + } + } CStringA str; if (mc[2].matched) { @@ -234,9 +251,17 @@ CString Subtitle::GuessSubtitleName(CString fn, CString videoName) } if (!lang.IsEmpty() && str.CompareNoCase("hi") == 0) { - bHearingImpaired = true; + hi = HI_YES; } else { lang = ISO639XToLanguage(str, true); + if (!lang.IsEmpty()) { + size_t len = str.GetLength(); + if (len == 3) { + lcid = ISO6392ToLcid(str.GetString()); + } else if (len == 2) { + lcid = ISO6391ToLcid(str.GetString()); + } + } } } } @@ -245,12 +270,6 @@ CString Subtitle::GuessSubtitleName(CString fn, CString videoName) if (name.GetLength() > 100) { // Cut some part of the filename if it's too long name.Format(_T("%s...%s"), name.Left(50).TrimRight(_T(".-_ ")), name.Right(50).TrimLeft(_T(".-_ "))); } - if (!lang.IsEmpty()) { - name.AppendFormat(_T(" [%s]"), lang); - if (bHearingImpaired) { - name.Append(_T(" [hearing impaired]")); - } - } return name; } diff --git a/src/Subtitles/SubtitleHelpers.h b/src/Subtitles/SubtitleHelpers.h index 82ec95286..95b9beec0 100644 --- a/src/Subtitles/SubtitleHelpers.h +++ b/src/Subtitles/SubtitleHelpers.h @@ -45,6 +45,12 @@ namespace Subtitle SUP }; + enum HearingImpairedType { + HI_UNKNOWN = -1, + HI_NO = 0, + HI_YES = 1 + }; + LPCTSTR GetSubtitleFileExt(SubType type); bool IsTextSubtitleFileName(CString filename); @@ -54,5 +60,5 @@ namespace Subtitle void GetSubFileNames(CString fn, const CAtlArray<CString>& paths, CAtlArray<SubFile>& ret); - CString GuessSubtitleName(CString fn, CString videoName); + CString GuessSubtitleName(const CString& fn, CString videoName, LCID& lcid, HearingImpairedType& hi); }; diff --git a/src/mpc-hc/MainFrm.cpp b/src/mpc-hc/MainFrm.cpp index ba99cb2a4..e3616c06d 100644 --- a/src/mpc-hc/MainFrm.cpp +++ b/src/mpc-hc/MainFrm.cpp @@ -101,6 +101,7 @@ #include "../Subtitles/STS.h"
#include "../Subtitles/RLECodedSubtitle.h"
#include "../Subtitles/PGSSub.h"
+#include "../Subtitles/SubtitleHelpers.h"
#include <mvrInterfaces.h>
#include <SubRenderIntf.h>
@@ -5117,6 +5118,17 @@ void CMainFrame::OnFileSubtitlesSave() CAppSettings& s = AfxGetAppSettings();
+ if (pRTS->m_lcid && pRTS->m_lcid != LCID(-1)) {
+ CString str;
+ int len = GetLocaleInfo(pRTS->m_lcid, LOCALE_SISO639LANGNAME, str.GetBuffer(64), 64);
+ str.ReleaseBufferSetLength(std::max(len - 1, 0));
+ suggestedFileName += "." + str;
+
+ if (pRTS->m_eHearingImpaired == Subtitle::HI_YES) {
+ suggestedFileName += ".hi";
+ }
+ }
+
// same thing as in the case of CVobSubFile above for lpszDefExt
CSaveSubtitlesFileDialog fd(pRTS->m_encoding, m_pCAP->GetSubtitleDelay(), s.bSubSaveExternalStyleFile,
_T("srt"), suggestedFileName, filter, types, GetModalParent());
@@ -16758,7 +16770,7 @@ LRESULT CMainFrame::OnLoadSubtitles(WPARAM wParam, LPARAM lParam) CAutoPtr<CRenderedTextSubtitle> pRTS(DEBUG_NEW CRenderedTextSubtitle(&m_csSubLock));
if (pRTS && pRTS->Open(CString(data.pSubtitlesInfo->Provider()->Name().c_str()),
(BYTE*)(LPCSTR)data.fileContents.c_str(), (int)data.fileContents.length(), DEFAULT_CHARSET,
- UTF8To16(data.fileName.c_str()), HearingImpairedType(data.pSubtitlesInfo->hearingImpaired),
+ UTF8To16(data.fileName.c_str()), Subtitle::HearingImpairedType(data.pSubtitlesInfo->hearingImpaired),
ISO6391ToLcid(data.pSubtitlesInfo->languageCode.c_str())) && pRTS->GetStreamCount() > 0) {
m_wndSubtitlesDownloadDialog.DoDownloaded(*data.pSubtitlesInfo);
@@ -16796,7 +16808,7 @@ LRESULT CMainFrame::OnGetSubtitles(WPARAM, LPARAM lParam) pSubtitlesInfo->GetFileInfo();
pSubtitlesInfo->releaseName = UTF16To8(pRTS->m_name);
- if (pSubtitlesInfo->hearingImpaired == HI_UNKNOWN) {
+ if (pSubtitlesInfo->hearingImpaired == Subtitle::HI_UNKNOWN) {
pSubtitlesInfo->hearingImpaired = pRTS->m_eHearingImpaired;
}
diff --git a/src/mpc-hc/SubtitlesProviders.h b/src/mpc-hc/SubtitlesProviders.h index f05958205..9493c2281 100644 --- a/src/mpc-hc/SubtitlesProviders.h +++ b/src/mpc-hc/SubtitlesProviders.h @@ -75,7 +75,7 @@ struct SubtitlesInfo { , seasonNumber(INT_ERROR) , episodeNumber(INT_ERROR) , discNumber(INT_ERROR) - , hearingImpaired(HI_UNKNOWN) + , hearingImpaired(Subtitle::HI_UNKNOWN) , discCount(INT_ERROR) , downloadCount(INT_ERROR) , corrected(0) |