PPageFormats.cpp

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 // PPageFormats.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "PPageFormats.h"
00028 
00029 // CPPageFormats dialog
00030 
00031 IMPLEMENT_DYNAMIC(CPPageFormats, CPPageBase)
00032 CPPageFormats::CPPageFormats()
00033         : CPPageBase(CPPageFormats::IDD, CPPageFormats::IDD)
00034         , m_list(0)
00035         , m_exts(_T(""))
00036         , m_iRtspHandler(0)
00037         , m_fRtspFileExtFirst(FALSE)
00038 {
00039 }
00040 
00041 CPPageFormats::~CPPageFormats()
00042 {
00043 }
00044 
00045 void CPPageFormats::DoDataExchange(CDataExchange* pDX)
00046 {
00047         __super::DoDataExchange(pDX);
00048         DDX_Control(pDX, IDC_LIST1, m_list);
00049         DDX_Text(pDX, IDC_EDIT1, m_exts);
00050         DDX_Control(pDX, IDC_STATIC1, m_autoplay);
00051         DDX_Control(pDX, IDC_CHECK1, m_apvideo);
00052         DDX_Control(pDX, IDC_CHECK2, m_apmusic);
00053         DDX_Control(pDX, IDC_CHECK3, m_apaudiocd);
00054         DDX_Control(pDX, IDC_CHECK4, m_apdvd);
00055         DDX_Radio(pDX, IDC_RADIO4, m_iRtspHandler);
00056         DDX_Check(pDX, IDC_CHECK5, m_fRtspFileExtFirst);
00057 }
00058 
00059 int CPPageFormats::GetChecked(int iItem)
00060 {
00061         LVITEM lvi;
00062         lvi.iItem = iItem;
00063         lvi.iSubItem = 0;
00064         lvi.mask = LVIF_IMAGE;
00065         m_list.GetItem(&lvi);
00066         return(lvi.iImage);
00067 }
00068 
00069 void CPPageFormats::SetChecked(int iItem, int iChecked)
00070 {
00071         LVITEM lvi;
00072         lvi.iItem = iItem;
00073         lvi.iSubItem = 0;
00074         lvi.mask = LVIF_IMAGE;
00075         lvi.iImage = iChecked;
00076         m_list.SetItem(&lvi);
00077 }
00078 
00079 static bool MakeRegParams(CString ext, CString& path, CString& fn, CString& extfile, CString& cmd)
00080 {
00081         if(ext.GetLength() == 0)
00082                 return(false);
00083 
00084         TCHAR buff[MAX_PATH];
00085         if(::GetModuleFileName(AfxGetInstanceHandle(), buff, MAX_PATH) == 0)
00086                 return(false);
00087 
00088         path = buff;
00089 
00090         fn = path.Mid(path.ReverseFind('\\')+1).MakeLower();
00091         if(fn.IsEmpty())
00092                 return(false);
00093 
00094         extfile = ext.TrimLeft('.')+_T("file");
00095 
00096         cmd = _T("\"") + path + _T("\" \"%1\"");
00097 
00098         return(true);
00099 }
00100 
00101 bool CPPageFormats::IsRegistered(CString ext)
00102 {
00103         CString path, fn, extfile, cmd;
00104         if(!MakeRegParams(ext, path, fn, extfile, cmd))
00105                 return(false);
00106 
00107         TCHAR buff[256];
00108         ULONG len = sizeof(buff);
00109         memset(buff, 0, len);
00110 
00111         CRegKey key;
00112 
00113         CString ExplExt = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\") + ext;
00114         if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, ExplExt, KEY_READ))
00115         {
00116                 len = sizeof(buff);
00117                 memset(buff, 0, len);
00118                 if(ERROR_SUCCESS == key.QueryStringValue(_T("Application"), buff, &len))
00119                         return(CString(buff).Trim() == cmd);
00120         }
00121 
00122         if(ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, ext, KEY_READ))
00123                 return(false);
00124 
00125         len = sizeof(buff);
00126         memset(buff, 0, len);
00127         if(ERROR_SUCCESS != key.QueryStringValue(NULL, buff, &len) || (extfile = buff).Trim().IsEmpty())
00128                 return(false);
00129 
00130         if(ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, extfile + _T("\\shell\\open\\command"), KEY_READ))
00131                 return(false);
00132 
00133         len = sizeof(buff);
00134         memset(buff, 0, len);
00135 
00136         CRegKey key2;
00137         if(ERROR_SUCCESS == key2.Open(HKEY_CLASSES_ROOT, extfile + _T("\\shell\\open"), KEY_READ)
00138         && ERROR_SUCCESS == key2.QueryStringValue(_T("LegacyDisable"), buff, &len))
00139                 return(false);
00140 
00141         len = sizeof(buff);
00142         memset(buff, 0, len);
00143 
00144         if(ERROR_SUCCESS == key2.Open(HKEY_CLASSES_ROOT, extfile + _T("\\shell\\open\\DropTarget"), KEY_READ))
00145                 return(false);
00146 
00147         len = sizeof(buff);
00148         memset(buff, 0, len);
00149 
00150         return(ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) 
00151                 && !CString(buff).CompareNoCase(cmd));
00152 }
00153 
00154 bool CPPageFormats::RegisterExt(CString ext, bool fRegister)
00155 {
00156         if(fRegister == IsRegistered(ext))
00157                 return(true);
00158 
00159         CString path, fn, extfile, cmd;
00160         if(!MakeRegParams(ext, path, fn, extfile, cmd))
00161                 return(false);
00162 
00163         TCHAR buff[256];
00164         ULONG len = sizeof(buff);
00165         memset(buff, 0, len);
00166 
00167         CRegKey key;
00168 
00169         if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, ext))
00170                 return(false);
00171 
00172         len = sizeof(buff);
00173         memset(buff, 0, len);
00174 
00175         if(ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && !CString(buff).Trim().IsEmpty())
00176         {
00177                 extfile = buff;
00178         }
00179         else
00180         {
00181                 if(!fRegister) return(true);
00182                 else if(ERROR_SUCCESS != key.SetStringValue(NULL, extfile)) return(false);
00183         }
00184 
00185         if(fRegister)
00186         {
00187                 if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, extfile + _T("\\shell")))
00188                         return(false);
00189 
00190                 len = sizeof(buff);
00191                 memset(buff, 0, len);
00192 
00193                 key.QueryStringValue(NULL, buff, &len);
00194 
00195                 if(ERROR_SUCCESS != key.SetStringValue(fn + _T(".bak"), buff))
00196                         return(false);
00197 
00198                 if(ERROR_SUCCESS != key.SetStringValue(NULL, _T("open")))
00199                 {
00200                         key.SetStringValue(NULL, buff);
00201                         key.DeleteValue(fn + _T(".bak"));
00202                         return(false);
00203                 }
00204 
00205                 if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, extfile + _T("\\shell\\open")))
00206                         return(false);
00207 
00208                 len = sizeof(buff);
00209                 memset(buff, 0, len);
00210 
00211                 if(ERROR_SUCCESS != key.SetStringValue(NULL, _T("&Open")))
00212                         return(false);
00213 
00214                 if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, extfile + _T("\\shell\\open\\command")))
00215                         return(false);
00216 
00217                 len = sizeof(buff);
00218                 memset(buff, 0, len);
00219 
00220                 key.QueryStringValue(NULL, buff, &len);
00221 
00222                 if(CString(buff).MakeLower() == cmd)
00223                         return(true);
00224 
00225                 if(ERROR_SUCCESS != key.SetStringValue(fn + _T(".bak"), buff))
00226                         return(false);
00227 
00228                 if(ERROR_SUCCESS != key.SetStringValue(NULL, cmd))
00229                 {
00230                         key.SetStringValue(NULL, buff);
00231                         key.DeleteValue(fn + _T(".bak"));
00232                         return(false);
00233                 }
00234 
00235                 len = sizeof(buff);
00236                 memset(buff, 0, len);
00237 
00238                 if(ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, extfile + _T("\\shell\\open")))
00239                 {
00240                         if(ERROR_SUCCESS == key.QueryStringValue(_T("LegacyDisable"), buff, &len))
00241                         {
00242                                 key.DeleteValue(_T("LegacyDisable"));
00243                                 key.SetStringValue(_T("LegacyDisable.bak"), _T(""));
00244                         }
00245 
00246                         key.RecurseDeleteKey(_T("ddeexec"));
00247                         key.RecurseDeleteKey(_T("DropTarget"));
00248                 }
00249 
00250                 if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\") + ext))
00251                 {
00252                         key.DeleteValue(_T("Application"));
00253                 }
00254         }
00255         else
00256         {
00257                 if(ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, extfile + _T("\\shell\\open\\command")))
00258                         return(true);
00259 
00260                 len = sizeof(buff);
00261                 memset(buff, 0, len);
00262 
00263                 if(ERROR_SUCCESS != key.QueryStringValue(fn + _T(".bak"), buff, &len))
00264                         buff[0] = 0; //return(true);
00265 
00266                 if(CString(buff).Trim().IsEmpty())
00267                 {
00268                         if(ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, extfile + _T("\\shell\\open"))
00269                         || ERROR_SUCCESS != key.RecurseDeleteKey(_T("command")))
00270                                 return(false);
00271                 }
00272                 else
00273                 {
00274                         if(ERROR_SUCCESS != key.SetStringValue(NULL, buff)
00275                         || ERROR_SUCCESS != key.DeleteValue(fn + _T(".bak")))
00276                                 return(false);
00277 
00278                         len = sizeof(buff);
00279                         memset(buff, 0, len);
00280 
00281                         if(ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, extfile + _T("\\shell\\open"))
00282                         && ERROR_SUCCESS == key.QueryStringValue(_T("LegacyDisable.bak"), buff, &len))
00283                         {
00284                                 key.DeleteValue(_T("LegacyDisable.bak"));
00285                                 key.SetStringValue(_T("LegacyDisable"), _T(""));
00286                         }
00287                 }
00288 
00289                 if(ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, extfile + _T("\\shell")))
00290                         return(true);
00291 
00292                 len = sizeof(buff);
00293                 memset(buff, 0, len);
00294 
00295                 if(ERROR_SUCCESS != key.QueryStringValue(fn + _T(".bak"), buff, &len))
00296                         return(true);
00297 
00298                 if(CString(buff).Trim().IsEmpty())
00299                 {
00300                         if(ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, extfile)
00301                         || ERROR_SUCCESS != key.RecurseDeleteKey(_T("shell")))
00302                                 return(false);
00303                 }
00304                 else
00305                 {
00306                         if(ERROR_SUCCESS != key.SetStringValue(NULL, buff)
00307                         || ERROR_SUCCESS != key.DeleteValue(fn + _T(".bak")))
00308                                 return(false);
00309                 }
00310         }
00311 
00312         return(true);
00313 }
00314 
00315 static struct {TCHAR verb[20], cmd[20], action[100];} handlers[] =
00316 {
00317         {_T("VideoFiles"), _T(" %1"), _T("Play Video")},
00318         {_T("MusicFiles"), _T(" %1"), _T("Play Music")},
00319         {_T("CDAudio"), _T(" %1 /cd"), _T("Play Audio CD")},
00320         {_T("DVDMovie"), _T(" %1 /dvd"), _T("Play DVD Movie")},
00321 };
00322 
00323 void CPPageFormats::AddAutoPlayToRegistry(autoplay_t ap, bool fRegister)
00324 {
00325         if(!AfxGetAppSettings().fXpOrBetter) return;
00326 
00327         TCHAR buff[MAX_PATH];
00328         if(::GetModuleFileName(AfxGetInstanceHandle(), buff, MAX_PATH) == 0) return;
00329         CString exe = buff;
00330 
00331         int i = (int)ap;
00332         if(i < 0 || i >= countof(handlers)) return;
00333 
00334         CRegKey key;
00335 
00336         if(fRegister)
00337         {
00338                 if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, _T("MediaPlayerClassic.Autorun"))) return;
00339                 key.Close();
00340 
00341                 if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, 
00342                         CString(_T("MediaPlayerClassic.Autorun\\Shell\\Play")) + handlers[i].verb + _T("\\Command"))) return;
00343                 key.SetStringValue(NULL, exe + handlers[i].cmd);
00344                 key.Close();
00345 
00346                 if(ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, 
00347                         CString(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AutoplayHandlers\\Handlers\\MPCPlay")) + handlers[i].verb + _T("OnArrival"))) return;
00348                 key.SetStringValue(_T("Action"), handlers[i].action);
00349                 key.SetStringValue(_T("Provider"), _T("Media Player Classic"));
00350                 key.SetStringValue(_T("InvokeProgID"), _T("MediaPlayerClassic.Autorun"));
00351                 key.SetStringValue(_T("InvokeVerb"), CString(_T("Play")) + handlers[i].verb);
00352                 key.SetStringValue(_T("DefaultIcon"), exe + _T(",0"));
00353                 key.Close();
00354 
00355                 if(ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, 
00356                         CString(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AutoplayHandlers\\EventHandlers\\Play")) + handlers[i].verb + _T("OnArrival"))) return;
00357                 key.SetStringValue(CString(_T("MPCPlay")) + handlers[i].verb + _T("OnArrival"), _T(""));
00358                 key.Close();
00359         }
00360         else
00361         {
00362                 if(ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, 
00363                         CString(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AutoplayHandlers\\EventHandlers\\Play")) + handlers[i].verb + _T("OnArrival"))) return;
00364                 key.DeleteValue(CString(_T("MPCPlay")) + handlers[i].verb + _T("OnArrival"));
00365                 key.Close();
00366         }
00367 }
00368 
00369 bool CPPageFormats::IsAutoPlayRegistered(autoplay_t ap)
00370 {
00371         ULONG len;
00372         TCHAR buff[MAX_PATH];
00373         if(::GetModuleFileName(AfxGetInstanceHandle(), buff, MAX_PATH) == 0) return(false);
00374         CString exe = buff;
00375 
00376         int i = (int)ap;
00377         if(i < 0 || i >= countof(handlers)) return(false);
00378 
00379         CRegKey key;
00380 
00381         if(ERROR_SUCCESS != key.Open(HKEY_LOCAL_MACHINE, 
00382                 CString(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AutoplayHandlers\\EventHandlers\\Play")) + handlers[i].verb + _T("OnArrival"),
00383                 KEY_READ)) return(false);
00384         len = countof(buff);
00385         if(ERROR_SUCCESS != key.QueryStringValue(
00386                 CString(_T("MPCPlay")) + handlers[i].verb + _T("OnArrival"), 
00387                 buff, &len)) return(false);
00388         key.Close();
00389 
00390         if(ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, 
00391                 CString(_T("MediaPlayerClassic.Autorun\\Shell\\Play")) + handlers[i].verb + _T("\\Command"),
00392                 KEY_READ)) return(false);
00393         len = countof(buff);
00394         if(ERROR_SUCCESS != key.QueryStringValue(NULL, buff, &len))
00395                 return(false);
00396         if(_tcsnicmp(exe, buff, exe.GetLength()))
00397                 return(false);
00398         key.Close();
00399 
00400         return(true);
00401 }
00402 
00403 void CPPageFormats::SetListItemState(int nItem)
00404 {
00405         if(nItem < 0) return;
00406 
00407         CString str = AfxGetAppSettings().Formats[(int)m_list.GetItemData(nItem)].GetExtsWithPeriod();
00408 
00409         CList<CString> exts;
00410         ExplodeMin(str, exts, ' ');
00411 
00412         int cnt = 0;
00413 
00414         POSITION pos = exts.GetHeadPosition();
00415         while(pos) if(IsRegistered(exts.GetNext(pos))) cnt++;
00416 
00417         SetChecked(nItem, cnt == 0 ? 0 : cnt == exts.GetCount() ? 1 : 2);
00418 }
00419 
00420 BEGIN_MESSAGE_MAP(CPPageFormats, CPPageBase)
00421         ON_NOTIFY(NM_CLICK, IDC_LIST1, OnNMClickList1)
00422         ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnLvnItemchangedList1)
00423         ON_NOTIFY(LVN_BEGINLABELEDIT, IDC_LIST1, OnBeginlabeleditList)
00424         ON_NOTIFY(LVN_DOLABELEDIT, IDC_LIST1, OnDolabeleditList)
00425         ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LIST1, OnEndlabeleditList)
00426         ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
00427         ON_BN_CLICKED(IDC_BUTTON12, OnBnClickedButton12)
00428         ON_BN_CLICKED(IDC_BUTTON11, OnBnClickedButton11)
00429         ON_BN_CLICKED(IDC_BUTTON14, OnBnClickedButton14)
00430         ON_BN_CLICKED(IDC_BUTTON13, OnBnClickedButton13)
00431         ON_UPDATE_COMMAND_UI(IDC_BUTTON12, OnUpdateButtonDefault)
00432         ON_UPDATE_COMMAND_UI(IDC_BUTTON11, OnUpdateButtonSet)
00433 END_MESSAGE_MAP()
00434 
00435 // CPPageFormats message handlers
00436 
00437 BOOL CPPageFormats::OnInitDialog()
00438 {
00439         __super::OnInitDialog();
00440 
00441         m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT);
00442 
00443         m_list.InsertColumn(COL_CATEGORY, _T("Category"), LVCFMT_LEFT, 300);
00444         m_list.InsertColumn(COL_ENGINE, _T("Engine"), LVCFMT_RIGHT, 60);
00445 
00446         m_onoff.Create(IDB_ONOFF, 12, 3, 0xffffff);
00447         m_list.SetImageList(&m_onoff, LVSIL_SMALL);
00448 
00449         CMediaFormats& mf = AfxGetAppSettings().Formats;
00450         for(int i = 0; i < mf.GetCount(); i++)
00451         {
00452                 CString label = mf[i].GetLabel();
00453                 // HACK: sorry, mpc is just not an image viewer :)
00454                 if(!label.CompareNoCase(_T("Image file"))) continue;
00455                 int iItem = m_list.InsertItem(i, label);
00456                 m_list.SetItemData(iItem, i);
00457                 engine_t e = mf[i].GetEngineType();
00458                 m_list.SetItemText(iItem, COL_ENGINE, 
00459                         e == DirectShow ? _T("DirectShow") : 
00460                         e == RealMedia ? _T("RealMedia") : 
00461                         e == QuickTime ? _T("QuickTime") : 
00462                         e == ShockWave ? _T("ShockWave") : _T("-"));
00463         }
00464 
00465 //      m_list.SetColumnWidth(COL_CATEGORY, LVSCW_AUTOSIZE);
00466         m_list.SetColumnWidth(COL_ENGINE, LVSCW_AUTOSIZE_USEHEADER);
00467 
00468         m_list.SetSelectionMark(0);
00469         m_list.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
00470         m_exts = mf[(int)m_list.GetItemData(0)].GetExtsWithPeriod();
00471 
00472         AppSettings& s = AfxGetAppSettings();
00473         bool fRtspFileExtFirst;
00474         engine_t e = s.Formats.GetRtspHandler(fRtspFileExtFirst);
00475         m_iRtspHandler = (e==RealMedia?0:e==QuickTime?1:2);
00476         m_fRtspFileExtFirst = fRtspFileExtFirst;
00477 
00478         UpdateData(FALSE);
00479 
00480         for(int i = 0; i < m_list.GetItemCount(); i++)
00481         {
00482                 SetListItemState(i);
00483         }
00484 
00485         if(AfxGetAppSettings().fXpOrBetter)
00486         {
00487                 m_apvideo.SetCheck(IsAutoPlayRegistered(AP_VIDEO));
00488                 m_apmusic.SetCheck(IsAutoPlayRegistered(AP_MUSIC));
00489                 m_apaudiocd.SetCheck(IsAutoPlayRegistered(AP_AUDIOCD));
00490                 m_apdvd.SetCheck(IsAutoPlayRegistered(AP_DVDMOVIE));
00491         }
00492         else
00493         {
00494                 m_autoplay.ShowWindow(SW_HIDE);
00495                 m_apvideo.ShowWindow(SW_HIDE);
00496                 m_apmusic.ShowWindow(SW_HIDE);
00497                 m_apaudiocd.ShowWindow(SW_HIDE);
00498                 m_apdvd.ShowWindow(SW_HIDE);
00499         }
00500 
00501         return TRUE;  // return TRUE unless you set the focus to a control
00502         // EXCEPTION: OCX Property Pages should return FALSE
00503 }
00504 
00505 BOOL CPPageFormats::OnApply()
00506 {
00507         UpdateData();
00508 
00509         {
00510                 int i = m_list.GetSelectionMark();
00511                 if(i >= 0) i = (int)m_list.GetItemData(i);
00512                 if(i >= 0)
00513                 {
00514                         CMediaFormats& mf = AfxGetAppSettings().Formats;
00515                         mf[i].SetExts(m_exts);
00516                         m_exts = mf[i].GetExtsWithPeriod();
00517                         UpdateData(FALSE);
00518                 }
00519         }
00520 
00521         CMediaFormats& mf = AfxGetAppSettings().Formats;
00522 
00523         for(int i = 0; i < m_list.GetItemCount(); i++)
00524         {
00525                 int iChecked = GetChecked(i);
00526                 if(iChecked == 2) continue;
00527 
00528                 CList<CString> exts;
00529                 Explode(mf[(int)m_list.GetItemData(i)].GetExtsWithPeriod(), exts, ' ');
00530 
00531                 POSITION pos = exts.GetHeadPosition();
00532                 while(pos) RegisterExt(exts.GetNext(pos), !!iChecked);
00533         }
00534 
00535         {
00536                 SetListItemState(m_list.GetSelectionMark());
00537         }
00538 
00539         AddAutoPlayToRegistry(AP_VIDEO, !!m_apvideo.GetCheck());
00540         AddAutoPlayToRegistry(AP_MUSIC, !!m_apmusic.GetCheck());
00541         AddAutoPlayToRegistry(AP_AUDIOCD, !!m_apaudiocd.GetCheck());
00542         AddAutoPlayToRegistry(AP_DVDMOVIE, !!m_apdvd.GetCheck());
00543 
00544 //      SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
00545 
00546         AppSettings& s = AfxGetAppSettings();
00547         s.Formats.SetRtspHandler(m_iRtspHandler==0?RealMedia:m_iRtspHandler==1?QuickTime:DirectShow, !!m_fRtspFileExtFirst);
00548 
00549         return __super::OnApply();
00550 }
00551 
00552 void CPPageFormats::OnNMClickList1(NMHDR* pNMHDR, LRESULT* pResult)
00553 {
00554         LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR;
00555 
00556         if(lpnmlv->iItem >= 0 && lpnmlv->iSubItem == COL_CATEGORY)
00557         {
00558                 CRect r;
00559                 m_list.GetItemRect(lpnmlv->iItem, r, LVIR_ICON);
00560                 if(r.PtInRect(lpnmlv->ptAction))
00561                 {
00562                         SetChecked(lpnmlv->iItem, (GetChecked(lpnmlv->iItem)&1) == 0 ? 1 : 0);
00563                         SetModified();
00564                 }
00565         }
00566 
00567         *pResult = 0;
00568 }
00569 
00570 void CPPageFormats::OnLvnItemchangedList1(NMHDR *pNMHDR, LRESULT *pResult)
00571 {
00572         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
00573 
00574         if(pNMLV->iItem >= 0 && pNMLV->iSubItem == COL_CATEGORY
00575         && (pNMLV->uChanged&LVIF_STATE) && (pNMLV->uNewState&LVIS_SELECTED))
00576         {
00577                 m_exts = AfxGetAppSettings().Formats[(int)m_list.GetItemData(pNMLV->iItem)].GetExtsWithPeriod();
00578                 UpdateData(FALSE);
00579         }
00580 
00581         *pResult = 0;
00582 }
00583 
00584 void CPPageFormats::OnBeginlabeleditList(NMHDR* pNMHDR, LRESULT* pResult) 
00585 {
00586         LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
00587         LV_ITEM* pItem = &pDispInfo->item;
00588 
00589         *pResult = FALSE;
00590 
00591         if(pItem->iItem < 0) 
00592                 return;
00593 
00594         if(pItem->iSubItem == COL_ENGINE)
00595         {
00596                 *pResult = TRUE;
00597         }
00598 }
00599 
00600 void CPPageFormats::OnDolabeleditList(NMHDR* pNMHDR, LRESULT* pResult) 
00601 {
00602         LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
00603         LV_ITEM* pItem = &pDispInfo->item;
00604 
00605         *pResult = FALSE;
00606 
00607         if(pItem->iItem < 0) 
00608                 return;
00609 
00610         CMediaFormatCategory& mfc = AfxGetAppSettings().Formats[m_list.GetItemData(pItem->iItem)];
00611 
00612         CList<CString> sl;
00613         int nSel = -1;
00614 
00615         if(pItem->iSubItem == COL_ENGINE)
00616         {
00617                 sl.AddTail(_T("DirectShow"));
00618                 sl.AddTail(_T("RealMedia"));
00619                 sl.AddTail(_T("QuickTime"));
00620                 sl.AddTail(_T("ShockWave"));
00621 
00622                 nSel = (int)mfc.GetEngineType();
00623 
00624                 m_list.ShowInPlaceComboBox(pItem->iItem, pItem->iSubItem, sl, nSel);
00625 
00626                 *pResult = TRUE;
00627         }
00628 }
00629 
00630 void CPPageFormats::OnEndlabeleditList(NMHDR* pNMHDR, LRESULT* pResult) 
00631 {
00632         LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
00633         LV_ITEM* pItem = &pDispInfo->item;
00634 
00635         *pResult = FALSE;
00636 
00637         if(!m_list.m_fInPlaceDirty)
00638                 return;
00639 
00640         if(pItem->iItem < 0) 
00641                 return;
00642 
00643         CMediaFormatCategory& mfc = AfxGetAppSettings().Formats[m_list.GetItemData(pItem->iItem)];
00644 
00645         if(pItem->iSubItem == COL_ENGINE && pItem->lParam >= 0)
00646         {
00647                 mfc.SetEngineType((engine_t)pItem->lParam);
00648                 m_list.SetItemText(pItem->iItem, pItem->iSubItem, pItem->pszText);
00649                 *pResult = TRUE;
00650         }
00651 
00652         if(*pResult)
00653                 SetModified();
00654 }
00655 
00656 void CPPageFormats::OnBnClickedButton1()
00657 {
00658         for(int i = 0, j = m_list.GetItemCount(); i < j; i++)
00659         {
00660                 SetChecked(i, 1);
00661         }
00662 
00663         m_apvideo.SetCheck(1);
00664         m_apmusic.SetCheck(1);
00665         m_apaudiocd.SetCheck(1);
00666         m_apdvd.SetCheck(1);
00667     
00668         SetModified();
00669 }
00670 
00671 void CPPageFormats::OnBnClickedButton14()
00672 {
00673         CMediaFormats& mf = AfxGetAppSettings().Formats;
00674 
00675         for(int i = 0, j = m_list.GetItemCount(); i < j; i++)
00676         {
00677                 SetChecked(i, mf[(int)m_list.GetItemData(i)].IsAudioOnly()?0:1);
00678         }
00679 
00680         m_apvideo.SetCheck(1);
00681         m_apmusic.SetCheck(0);
00682         m_apaudiocd.SetCheck(0);
00683         m_apdvd.SetCheck(1);
00684     
00685         SetModified();
00686 }
00687 
00688 void CPPageFormats::OnBnClickedButton13()
00689 {
00690         CMediaFormats& mf = AfxGetAppSettings().Formats;
00691 
00692         for(int i = 0, j = m_list.GetItemCount(); i < j; i++)
00693         {
00694                 SetChecked(i, mf[(int)m_list.GetItemData(i)].IsAudioOnly()?1:0);
00695         }
00696 
00697         m_apvideo.SetCheck(0);
00698         m_apmusic.SetCheck(1);
00699         m_apaudiocd.SetCheck(1);
00700         m_apdvd.SetCheck(0);
00701     
00702         SetModified();
00703 }
00704 
00705 void CPPageFormats::OnBnClickedButton12()
00706 {
00707         int i = m_list.GetSelectionMark();
00708         if(i < 0) return;
00709         i = (int)m_list.GetItemData(i);
00710         CMediaFormats& mf = AfxGetAppSettings().Formats;
00711         mf[i].RestoreDefaultExts();
00712         m_exts = mf[i].GetExtsWithPeriod();
00713         SetListItemState(m_list.GetSelectionMark());
00714         UpdateData(FALSE);
00715     
00716         SetModified();
00717 }
00718 
00719 void CPPageFormats::OnBnClickedButton11()
00720 {
00721         UpdateData();
00722         int i = m_list.GetSelectionMark();
00723         if(i < 0) return;
00724         i = (int)m_list.GetItemData(i);
00725         CMediaFormats& mf = AfxGetAppSettings().Formats;
00726         mf[i].SetExts(m_exts);
00727         m_exts = mf[i].GetExtsWithPeriod();
00728         SetListItemState(m_list.GetSelectionMark());
00729         UpdateData(FALSE);
00730     
00731         SetModified();
00732 }
00733 
00734 void CPPageFormats::OnUpdateButtonDefault(CCmdUI* pCmdUI)
00735 {
00736         int i = m_list.GetSelectionMark();
00737         if(i < 0) {pCmdUI->Enable(FALSE); return;}
00738         i = (int)m_list.GetItemData(i);
00739 
00740         CString orgexts, newexts;
00741         GetDlgItem(IDC_EDIT1)->GetWindowText(newexts);
00742         newexts.Trim();
00743         orgexts = AfxGetAppSettings().Formats[i].GetBackupExtsWithPeriod();
00744 
00745         pCmdUI->Enable(!!newexts.CompareNoCase(orgexts));
00746 }
00747 
00748 void CPPageFormats::OnUpdateButtonSet(CCmdUI* pCmdUI)
00749 {
00750         int i = m_list.GetSelectionMark();
00751         if(i < 0) {pCmdUI->Enable(FALSE); return;}
00752         i = (int)m_list.GetItemData(i);
00753 
00754         CString orgexts, newexts;
00755         GetDlgItem(IDC_EDIT1)->GetWindowText(newexts);
00756         newexts.Trim();
00757         orgexts = AfxGetAppSettings().Formats[i].GetExtsWithPeriod();
00758 
00759         pCmdUI->Enable(!!newexts.CompareNoCase(orgexts));
00760 }

Generated on Tue Dec 13 14:47:01 2005 for guliverkli by  doxygen 1.4.5