diff options
Diffstat (limited to 'src/apps/mplayerc/SubtitleDlDlg.cpp')
-rw-r--r-- | src/apps/mplayerc/SubtitleDlDlg.cpp | 200 |
1 files changed, 127 insertions, 73 deletions
diff --git a/src/apps/mplayerc/SubtitleDlDlg.cpp b/src/apps/mplayerc/SubtitleDlDlg.cpp index 8f63b8296..576c34db7 100644 --- a/src/apps/mplayerc/SubtitleDlDlg.cpp +++ b/src/apps/mplayerc/SubtitleDlDlg.cpp @@ -2,7 +2,7 @@ * $Id$
*
* (C) 2003-2006 Gabest
- * (C) 2006-2010 see AUTHORS
+ * (C) 2006-2011 see AUTHORS
*
* This file is part of mplayerc.
*
@@ -24,39 +24,47 @@ #include "stdafx.h"
#include "mplayerc.h"
#include "SubtitleDlDlg.h"
+#include <algorithm> // For std::sort
// CSubtitleDlDlg dialog
//IMPLEMENT_DYNAMIC(CSubtitleDlDlg, CResizableDialog)
CSubtitleDlDlg::CSubtitleDlDlg(CList<isdb_movie>& movies, CWnd* pParent /*=NULL*/)
- : CResizableDialog(CSubtitleDlDlg::IDD, pParent)
+ : CResizableDialog(CSubtitleDlDlg::IDD, pParent),
+ iColumn(-1),
+ bSortDirection(false)
{
m_movies.AddTail(&movies);
-}
-CSubtitleDlDlg::~CSubtitleDlDlg()
-{
-}
+ // Parse
+ POSITION pos = m_movies.GetHeadPosition();
+ while (pos)
+ {
+ isdb_movie& m = m_movies.GetNext(pos);
+ isdb_movie_Parsed p;
-int CSubtitleDlDlg::GetChecked(int iItem)
-{
- LVITEM lvi;
- lvi.iItem = iItem;
- lvi.iSubItem = 0;
- lvi.mask = LVIF_IMAGE;
- m_list.GetItem(&lvi);
- return(lvi.iImage);
+ CStringA titlesA = Implode(m.titles, '|');
+ titlesA.Replace("|", ", ");
+ p.titles = UTF8To16(titlesA);
+ p.checked = false;
+
+ POSITION pos2 = m.subs.GetHeadPosition();
+ while (pos2) {
+ isdb_subtitle& s = m.subs.GetNext(pos2);
+ p.name = UTF8To16(s.name);
+ p.language = s.language;
+ p.format = s.format;
+ p.disc.Format(_T("%d/%d"), s.disc_no, s.discs);
+ p.ptr = (DWORD_PTR)&s;
+
+ m_moviesParsed.Add(p);
+ }
+ }
}
-void CSubtitleDlDlg::SetChecked(int iItem, int iChecked)
+CSubtitleDlDlg::~CSubtitleDlDlg()
{
- LVITEM lvi;
- lvi.iItem = iItem;
- lvi.iSubItem = 0;
- lvi.mask = LVIF_IMAGE;
- lvi.iImage = iChecked;
- m_list.SetItem(&lvi);
}
void CSubtitleDlDlg::DoDataExchange(CDataExchange* pDX)
@@ -67,8 +75,8 @@ void CSubtitleDlDlg::DoDataExchange(CDataExchange* pDX) BEGIN_MESSAGE_MAP(CSubtitleDlDlg, CResizableDialog)
- ON_NOTIFY(NM_CLICK, IDC_LIST1, OnNMClickList1)
ON_UPDATE_COMMAND_UI(IDOK, OnUpdateOk)
+ ON_NOTIFY(HDN_ITEMCLICK, 0, &CSubtitleDlDlg::OnHdnItemclickList1)
END_MESSAGE_MAP()
// CSubtitleDlDlg message handlers
@@ -77,7 +85,6 @@ BOOL CSubtitleDlDlg::OnInitDialog() {
__super::OnInitDialog();
-
AddAnchor(IDC_LIST1, TOP_LEFT, BOTTOM_RIGHT);
AddAnchor(IDC_CHECK1, BOTTOM_LEFT);
AddAnchor(IDOK, BOTTOM_RIGHT);
@@ -85,8 +92,7 @@ BOOL CSubtitleDlDlg::OnInitDialog() CSize s(200, 150);
SetMinTrackSize(s);
-
- m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT);
+ m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
m_list.InsertColumn(COL_FILENAME, _T("File"), LVCFMT_LEFT, 160);
m_list.InsertColumn(COL_LANGUAGE, _T("Language"), LVCFMT_CENTER, 80);
@@ -94,38 +100,7 @@ BOOL CSubtitleDlDlg::OnInitDialog() m_list.InsertColumn(COL_DISC, _T("Disc"), LVCFMT_CENTER, 50);
m_list.InsertColumn(COL_TITLES, _T("Title(s)"), LVCFMT_LEFT, 300);
- m_onoff.Create(IDB_ONOFF, 12, 3, 0xffffff);
- m_list.SetImageList(&m_onoff, LVSIL_SMALL);
-
-
- int i = 0;
-
- POSITION pos = m_movies.GetHeadPosition();
- while(pos) {
- isdb_movie& m = m_movies.GetNext(pos);
-
- CStringA titlesA = Implode(m.titles, '|');
- titlesA.Replace("|", ", ");
- CString titles = UTF8To16(titlesA);
-
- POSITION pos2 = m.subs.GetHeadPosition();
- while(pos2) {
- isdb_subtitle& s = m.subs.GetNext(pos2);
- CString name = UTF8To16(s.name);
- CString language = s.language;
- CString format = s.format;
- CString disc;
- disc.Format(_T("%d/%d"), s.disc_no, s.discs);
-
- int iItem = m_list.InsertItem(i++, _T(""));
- m_list.SetItemData(iItem, (DWORD_PTR)&s);
- m_list.SetItemText(iItem, COL_FILENAME, name);
- m_list.SetItemText(iItem, COL_LANGUAGE, language);
- m_list.SetItemText(iItem, COL_FORMAT, format);
- m_list.SetItemText(iItem, COL_DISC, disc);
- m_list.SetItemText(iItem, COL_TITLES, titles);
- }
- }
+ BuildList();
m_selsubs.RemoveAll();
@@ -135,37 +110,116 @@ BOOL CSubtitleDlDlg::OnInitDialog() void CSubtitleDlDlg::OnOK()
{
- for(int i = 0; i < m_list.GetItemCount(); i++)
- if(GetChecked(i)) {
+ for (int i = 0; i < m_list.GetItemCount(); ++i)
+ {
+ if (m_list.GetCheck(i)) {
m_selsubs.AddTail(*(isdb_subtitle*)m_list.GetItemData(i));
}
+ }
m_fReplaceSubs = IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED;
__super::OnOK();
}
-void CSubtitleDlDlg::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
+void CSubtitleDlDlg::OnUpdateOk(CCmdUI* pCmdUI)
{
- LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR;
-
- if(lpnmlv->iItem >= 0) {
- CRect r;
- m_list.GetItemRect(lpnmlv->iItem, r, LVIR_ICON);
- if(r.PtInRect(lpnmlv->ptAction)) {
- SetChecked(lpnmlv->iItem, (GetChecked(lpnmlv->iItem)&1) == 0 ? 1 : 0);
- }
+ bool fEnable = false;
+ for (int i = 0; !fEnable && i < m_list.GetItemCount(); ++i) {
+ fEnable = !!m_list.GetCheck(i);
}
+ pCmdUI->Enable(fEnable);
+}
+
+
+void CSubtitleDlDlg::OnHdnItemclickList1(NMHDR *pNMHDR, LRESULT *pResult)
+{
+ LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
*pResult = 0;
+
+ if ( phdr->iItem != iColumn )
+ {
+ iColumn = phdr->iItem;
+ bSortDirection = false;
+ }
+ else
+ {
+ bSortDirection = !bSortDirection;
+ }
+
+ SortList();
}
-void CSubtitleDlDlg::OnUpdateOk(CCmdUI* pCmdUI)
+void CSubtitleDlDlg::BuildList( void )
{
- bool fEnable = false;
- for(int i = 0; !fEnable && i < m_list.GetItemCount(); i++) {
- fEnable = !!GetChecked(i);
+ for (INT_PTR i = 0; i < m_moviesParsed.GetCount(); ++i)
+ {
+ isdb_movie_Parsed& m = m_moviesParsed[i];
+
+ int iItem = m_list.InsertItem(i, _T(""));
+ m_list.SetItemData(iItem, (DWORD_PTR)m.ptr);
+ m_list.SetItemText(iItem, COL_FILENAME, m.name);
+ m_list.SetItemText(iItem, COL_LANGUAGE, m.language);
+ m_list.SetItemText(iItem, COL_FORMAT, m.format);
+ m_list.SetItemText(iItem, COL_DISC, m.disc);
+ m_list.SetItemText(iItem, COL_TITLES, m.titles);
+ m_list.SetCheck(iItem, m.checked);
}
+}
- pCmdUI->Enable(fEnable);
+struct sort_cmp {
+ sort_cmp(int col, bool dir) : iColumn(col), bSortDirection(dir) {}
+
+ bool operator()(const CSubtitleDlDlg::isdb_movie_Parsed& a, const CSubtitleDlDlg::isdb_movie_Parsed& b) const
+ {
+ bool result = false;
+
+ // Should this macro be a function instead ?
+ #define dir_cmp(l, r) bSortDirection ? (r) < (l) : (l) < (r)
+
+ switch (iColumn)
+ {
+ case CSubtitleDlDlg::COL_FILENAME:
+ result = dir_cmp(a.name, b.name);
+ break;
+ case CSubtitleDlDlg::COL_LANGUAGE:
+ result = dir_cmp(a.language, b.language);
+ break;
+ case CSubtitleDlDlg::COL_FORMAT:
+ result = dir_cmp(a.format, b.format);
+ break;
+ case CSubtitleDlDlg::COL_DISC:
+ result = dir_cmp(a.disc, b.disc);
+ break;
+ case CSubtitleDlDlg::COL_TITLES:
+ result = dir_cmp(a.titles, b.titles);
+ break;
+ }
+
+ #undef dir_cmp
+
+ return result;
+ }
+
+ const int iColumn;
+ const bool bSortDirection;
+};
+
+void CSubtitleDlDlg::SortList( void )
+{
+ // Save checked state
+ for (INT_PTR i = 0; i < m_moviesParsed.GetCount(); ++i)
+ {
+ m_moviesParsed[i].checked = m_list.GetCheck(i);
+ }
+
+ // Sort list
+ // qsort doesn't support functors
+ //qsort(m_moviesParsed.GetData(), m_moviesParsed.GetCount(), sizeof(m_moviesParsed[0]), sort_cmp_c(iColumn, bSortDirection));
+ std::sort(m_moviesParsed.GetData(), m_moviesParsed.GetData() + m_moviesParsed.GetCount(), sort_cmp(iColumn, bSortDirection));
+
+ m_list.DeleteAllItems();
+
+ BuildList();
}
|