2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // PPageFileInfoDetails.cpp : implementation file
27 #include "PPageFileInfoDetails.h"
29 #include "..\..\DSUtil\DSUtil.h"
32 #include "..\..\..\include\moreuuids.h"
34 // CPPageFileInfoDetails dialog
36 IMPLEMENT_DYNAMIC(CPPageFileInfoDetails
, CPropertyPage
)
37 CPPageFileInfoDetails::CPPageFileInfoDetails(CString fn
, IFilterGraph
* pFG
, ISubPicAllocatorPresenter
* pCAP
)
38 : CPropertyPage(CPPageFileInfoDetails::IDD
, CPPageFileInfoDetails::IDD
)
43 , m_type(_T("Not known"))
44 , m_size(_T("Not known"))
45 , m_time(_T("Not known"))
46 , m_res(_T("Not known"))
47 , m_created(_T("Not known"))
51 CPPageFileInfoDetails::~CPPageFileInfoDetails()
53 if(m_hIcon
) DestroyIcon(m_hIcon
);
56 void CPPageFileInfoDetails::DoDataExchange(CDataExchange
* pDX
)
58 __super::DoDataExchange(pDX
);
59 DDX_Control(pDX
, IDC_DEFAULTICON
, m_icon
);
60 DDX_Text(pDX
, IDC_EDIT1
, m_fn
);
61 DDX_Text(pDX
, IDC_EDIT4
, m_type
);
62 DDX_Text(pDX
, IDC_EDIT3
, m_size
);
63 DDX_Text(pDX
, IDC_EDIT2
, m_time
);
64 DDX_Text(pDX
, IDC_EDIT5
, m_res
);
65 DDX_Text(pDX
, IDC_EDIT6
, m_created
);
66 DDX_Control(pDX
, IDC_EDIT7
, m_encoding
);
69 BEGIN_MESSAGE_MAP(CPPageFileInfoDetails
, CPropertyPage
)
72 inline int LNKO(int a
, int b
)
80 else if(a
> b
) a
-= b
;
86 // CPPageFileInfoDetails message handlers
88 static bool GetProperty(IFilterGraph
* pFG
, LPCOLESTR propName
, VARIANT
* vt
)
90 BeginEnumFilters(pFG
, pEF
, pBF
)
92 if(CComQIPtr
<IPropertyBag
> pPB
= pBF
)
93 if(SUCCEEDED(pPB
->Read(propName
, vt
, NULL
)))
101 static CString
FormatDateTime(FILETIME tm
)
104 FileTimeToSystemTime(&tm
, &t
);
106 GetDateFormat(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &t
, NULL
, buff
, 256);
109 GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &t
, NULL
, buff
, 256);
114 BOOL
CPPageFileInfoDetails::OnInitDialog()
116 __super::OnInitDialog();
118 CString ext
= m_fn
.Left(m_fn
.Find(_T("://"))+1).TrimRight(':');
119 if(ext
.IsEmpty() || !ext
.CompareNoCase(_T("file")))
120 ext
= _T(".") + m_fn
.Mid(m_fn
.ReverseFind('.')+1);
122 if(m_hIcon
= LoadIcon(m_fn
, false))
123 m_icon
.SetIcon(m_hIcon
);
125 if(!LoadType(ext
, m_type
))
126 m_type
= _T("Not known");
129 if(::GetProperty(m_pFG
, L
"CurFile.TimeCreated", &vt
))
131 if(V_VT(&vt
) == VT_UI8
)
134 uli
.QuadPart
= V_UI8(&vt
);
137 ft
.dwLowDateTime
= uli
.LowPart
;
138 ft
.dwHighDateTime
= uli
.HighPart
;
140 m_created
= FormatDateTime(ft
);
145 HANDLE hFind
= FindFirstFile(m_fn
, &wfd
);
146 if(hFind
!= INVALID_HANDLE_VALUE
)
150 __int64 size
= (__int64(wfd
.nFileSizeHigh
)<<32)|wfd
.nFileSizeLow
;
151 __int64 shortsize
= size
;
152 CString measure
= _T("B");
153 if(shortsize
> 10240) shortsize
/= 1024, measure
= _T("KB");
154 if(shortsize
> 10240) shortsize
/= 1024, measure
= _T("MB");
155 if(shortsize
> 10240) shortsize
/= 1024, measure
= _T("GB");
156 m_size
.Format(_T("%I64d%s (%I64d bytes)"), shortsize
, measure
, size
);
158 if(m_created
.IsEmpty())
160 m_created
= FormatDateTime(wfd
.ftCreationTime
);
164 REFERENCE_TIME rtDur
= 0;
165 CComQIPtr
<IMediaSeeking
> pMS
= m_pFG
;
166 if(pMS
&& SUCCEEDED(pMS
->GetDuration(&rtDur
)) && rtDur
> 0)
168 m_time
.Format(_T("%02d:%02d:%02d"),
169 int(rtDur
/10000000/60/60),
170 int((rtDur
/10000000/60)%60),
171 int((rtDur
/10000000)%60));
174 CSize
wh(0, 0), arxy(0, 0);
179 wh
= m_pCAP
->GetVideoSize(false);
180 arxy
= m_pCAP
->GetVideoSize(true);
184 if(CComQIPtr
<IBasicVideo
> pBV
= m_pFG
)
186 if(SUCCEEDED(pBV
->GetVideoSize(&wh
.cx
, &wh
.cy
)))
188 if(CComQIPtr
<IBasicVideo2
> pBV2
= m_pFG
)
189 pBV2
->GetPreferredAspectRatio(&arxy
.cx
, &arxy
.cy
);
197 if(wh
.cx
== 0 && wh
.cy
== 0)
199 BeginEnumFilters(m_pFG
, pEF
, pBF
)
201 if(CComQIPtr
<IBasicVideo
> pBV
= pBF
)
203 pBV
->GetVideoSize(&wh
.cx
, &wh
.cy
);
204 if(CComQIPtr
<IBasicVideo2
> pBV2
= pBF
)
205 pBV2
->GetPreferredAspectRatio(&arxy
.cx
, &arxy
.cy
);
208 else if(CComQIPtr
<IVMRWindowlessControl
> pWC
= pBF
)
210 pWC
->GetNativeVideoSize(&wh
.cx
, &wh
.cy
, &arxy
.cx
, &arxy
.cy
);
213 else if(CComQIPtr
<IVMRWindowlessControl9
> pWC
= pBF
)
215 pWC
->GetNativeVideoSize(&wh
.cx
, &wh
.cy
, &arxy
.cx
, &arxy
.cy
);
223 if(wh
.cx
> 0 && wh
.cy
> 0)
225 m_res
.Format(_T("%d x %d"), wh
.cx
, wh
.cy
);
230 lnko
= LNKO(arxy
.cx
, arxy
.cy
);
231 if(lnko
> 1) arxy
.cx
/= lnko
, arxy
.cy
/= lnko
;
235 if(arxy
.cx
> 0 && arxy
.cy
> 0 && arxy
.cx
*wh
.cy
!= arxy
.cy
*wh
.cx
)
238 ar
.Format(_T(" (AR %d:%d)"), arxy
.cx
, arxy
.cy
);
244 m_fn
.Replace('\\', '/');
245 m_fn
= m_fn
.Mid(m_fn
.ReverseFind('/')+1);
254 return TRUE
; // return TRUE unless you set the focus to a control
255 // EXCEPTION: OCX Property Pages should return FALSE
258 void CPPageFileInfoDetails::InitEncoding()
260 CAtlList
<CString
> sl
;
262 BeginEnumFilters(m_pFG
, pEF
, pBF
)
264 CComPtr
<IBaseFilter
> pUSBF
= GetUpStreamFilter(pBF
);
266 if(GetCLSID(pBF
) == CLSID_NetShowSource
)
270 else if(GetCLSID(pUSBF
) != CLSID_NetShowSource
)
272 if(IPin
* pPin
= GetFirstPin(pBF
, PINDIR_INPUT
))
275 if(FAILED(pPin
->ConnectionMediaType(&mt
)) || mt
.majortype
!= MEDIATYPE_Stream
)
279 if(IPin
* pPin
= GetFirstPin(pBF
, PINDIR_OUTPUT
))
282 if(SUCCEEDED(pPin
->ConnectionMediaType(&mt
)) && mt
.majortype
== MEDIATYPE_Stream
)
287 BeginEnumPins(pBF
, pEP
, pPin
)
291 if(FAILED(pPin
->QueryDirection(&dir
)) || dir
!= PINDIR_OUTPUT
292 || FAILED(pPin
->ConnectionMediaType(&mt
)))
295 CString str
= mt
.ToString();
299 sl
.AddTail(mt
.ToString() + CString(L
" [" + GetPinName(pPin
) + L
"]"));
306 CString text
= Implode(sl
, '\n');
307 text
.Replace(_T("\n"), _T("\r\n"));
308 m_encoding
.SetWindowText(text
);