Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

DlgMediaVis.cpp

Go to the documentation of this file.
00001 //
00002 // DlgMediaVis.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "Plugins.h"
00026 #include "CoolInterface.h"
00027 #include "DlgMediaVis.h"
00028 #include "CtrlMediaFrame.h"
00029 
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035 
00036 IMPLEMENT_DYNAMIC(CMediaVisDlg, CSkinDialog)
00037 
00038 BEGIN_MESSAGE_MAP(CMediaVisDlg, CSkinDialog)
00039         //{{AFX_MSG_MAP(CMediaVisDlg)
00040         ON_NOTIFY(NM_DBLCLK, IDC_PLUGINS, OnDblClkPlugins)
00041         ON_NOTIFY(LVN_ITEMCHANGED, IDC_PLUGINS, OnItemChangedPlugins)
00042         ON_BN_CLICKED(IDC_SETUP, OnSetup)
00043         //}}AFX_MSG_MAP
00044 END_MESSAGE_MAP()
00045 
00046 
00048 // CMediaVisDlg dialog
00049 
00050 CMediaVisDlg::CMediaVisDlg(CMediaFrame* pFrame) : CSkinDialog( CMediaVisDlg::IDD, NULL )
00051 {
00052         //{{AFX_DATA_INIT(CMediaVisDlg)
00053         m_nSize = -1;
00054         //}}AFX_DATA_INIT
00055         m_pFrame        = pFrame;
00056         m_hIcon         = NULL;
00057 }
00058 
00059 CMediaVisDlg::~CMediaVisDlg()
00060 {
00061         if ( m_hIcon ) DestroyIcon( m_hIcon );
00062 }
00063 
00064 void CMediaVisDlg::DoDataExchange(CDataExchange* pDX)
00065 {
00066         CSkinDialog::DoDataExchange(pDX);
00067         //{{AFX_DATA_MAP(CMediaVisDlg)
00068         DDX_Control(pDX, IDC_SETUP, m_wndSetup);
00069         DDX_Control(pDX, IDC_PLUGINS, m_wndList);
00070         DDX_CBIndex(pDX, IDC_VIS_SIZE, m_nSize);
00071         //}}AFX_DATA_MAP
00072 }
00073 
00075 // CMediaVisDlg message handlers
00076 
00077 BOOL CMediaVisDlg::OnInitDialog()
00078 {
00079         CString strMessage;
00080 
00081         CSkinDialog::OnInitDialog();
00082 
00083         SkinMe( NULL, ID_MEDIA_VIS );
00084 
00085         CRect rc;
00086         m_wndList.GetClientRect( &rc );
00087         rc.right -= GetSystemMetrics( SM_CXVSCROLL ) + 1;
00088 
00089         m_wndList.SetImageList( &CoolInterface.m_pImages, LVSIL_SMALL );
00090         m_wndList.InsertColumn( 0, _T("Description"), LVCFMT_LEFT, rc.right, -1 );
00091         m_wndList.InsertColumn( 1, _T("CLSID"), LVCFMT_LEFT, 0, 0 );
00092         m_wndList.InsertColumn( 2, _T("Subpath"), LVCFMT_LEFT, 0, 1 );
00093 
00094         m_wndList.SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE,
00095                 LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT );
00096 
00097         m_nIcon = CoolInterface.ImageForID( ID_MEDIA_VIS );
00098         m_hIcon = CoolInterface.ExtractIcon( ID_MEDIA_VIS );
00099         SetIcon( m_hIcon, FALSE );
00100 
00101         LoadString( strMessage, IDS_MEDIAVIS_NOVIS );
00102         AddPlugin( strMessage, NULL, NULL );
00103         Enumerate();
00104 
00105         m_nSize = Settings.MediaPlayer.VisSize + 1;
00106         UpdateData( FALSE );
00107 
00108         m_wndSetup.EnableWindow( m_wndList.GetSelectedCount() == 1 );
00109 
00110         return TRUE;
00111 }
00112 
00113 void CMediaVisDlg::Enumerate()
00114 {
00115         CWaitCursor pCursor;
00116         HKEY hKey;
00117 
00118         if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
00119                 _T("Software\\Shareaza\\Shareaza\\Plugins\\AudioVis"),
00120                 NULL, KEY_READ, &hKey ) != ERROR_SUCCESS ) return;
00121 
00122         for ( DWORD nKey = 0 ; ; nKey++ )
00123         {
00124                 DWORD dwType, dwName = sizeof(TCHAR) * 128, dwCLSID = 64 * sizeof(TCHAR);
00125                 TCHAR szName[128], szCLSID[64];
00126 
00127                 if ( RegEnumValue( hKey, nKey, szName, &dwName, NULL, &dwType, (LPBYTE)szCLSID, &dwCLSID )
00128                          != ERROR_SUCCESS ) break;
00129 
00130                 if ( dwType != REG_SZ || dwCLSID / sizeof(TCHAR) != 39 || szCLSID[0] != '{' || szName[0] == '{' ) continue;
00131                 szCLSID[ 38 ] = 0;
00132 
00133                 CLSID pCLSID;
00134                 if ( ! GUIDX::Decode( szCLSID, &pCLSID ) ) continue;
00135                 if ( ! Plugins.LookupEnable( pCLSID, TRUE ) ) continue;
00136 
00137                 if ( _tcsistr( szName, _T("wrap") ) )
00138                 {
00139                         if ( ! EnumerateWrapped( szName, pCLSID, szCLSID ) )
00140                         {
00141                                 AddPlugin( szName, szCLSID, NULL );
00142                         }
00143                 }
00144                 else
00145                 {
00146                         AddPlugin( szName, szCLSID, NULL );
00147                 }
00148         }
00149 
00150         RegCloseKey( hKey );
00151 }
00152 
00153 void CMediaVisDlg::AddPlugin(LPCTSTR pszName, LPCTSTR pszCLSID, LPCTSTR pszPath)
00154 {
00155         int nItem = m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE, -1, pszName, 0, 0, m_nIcon, 0 );
00156 
00157         if ( pszCLSID ) m_wndList.SetItemText( nItem, 1, pszCLSID );
00158         if ( pszPath ) m_wndList.SetItemText( nItem, 2, pszPath );
00159 
00160         if ( ( pszCLSID == NULL && Settings.MediaPlayer.VisCLSID.IsEmpty() ) ||
00161                  ( pszCLSID != NULL && Settings.MediaPlayer.VisCLSID.CompareNoCase( pszCLSID ) == 0 ) )
00162         {
00163                 if ( ( pszPath == NULL && Settings.MediaPlayer.VisPath.IsEmpty() ) ||
00164                          ( pszPath != NULL && Settings.MediaPlayer.VisPath.CompareNoCase( pszPath ) == 0 ) )
00165                 {
00166                         m_wndList.SetItemState( nItem, LVIS_SELECTED, LVIS_SELECTED );
00167                 }
00168         }
00169 }
00170 
00171 BOOL CMediaVisDlg::EnumerateWrapped(LPCTSTR pszName, REFCLSID pCLSID, LPCTSTR pszCLSID)
00172 {
00173         IWrappedPluginControl* pPlugin = NULL;
00174 
00175         HINSTANCE hRes = AfxGetResourceHandle();
00176 
00177         HRESULT hr = CoCreateInstance( pCLSID, NULL, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER,
00178                 IID_IWrappedPluginControl, (void**)&pPlugin );
00179 
00180         AfxSetResourceHandle( hRes );
00181 
00182         if ( FAILED(hr) || pPlugin == NULL ) return FALSE;
00183 
00184         LPSAFEARRAY pArray = NULL;
00185         hr = pPlugin->Enumerate( &pArray );
00186 
00187         pPlugin->Release();
00188 
00189         if ( FAILED(hr) || pArray == NULL ) return FALSE;
00190 
00191         LONG pIndex[2] = { 0, 0 };
00192         SafeArrayGetUBound( pArray, 2, &pIndex[1] );
00193 
00194         if ( pIndex[1] < 0 )
00195         {
00196                 SafeArrayDestroy( pArray );
00197                 return TRUE;
00198         }
00199 
00200         for ( ; pIndex[1] >= 0 ; pIndex[1] -- )
00201         {
00202                 CString strName, strPath;
00203                 BSTR bsValue = NULL;
00204 
00205                 strName = pszName;
00206                 strName += _T(": ");
00207 
00208                 pIndex[0] = 0;
00209                 SafeArrayGetElement( pArray, pIndex, &bsValue );
00210                 strName += bsValue;
00211                 SysFreeString( bsValue );
00212                 bsValue = NULL;
00213 
00214                 pIndex[0] = 1;
00215                 SafeArrayGetElement( pArray, pIndex, &bsValue );
00216                 strPath = bsValue;
00217                 SysFreeString( bsValue );
00218                 bsValue = NULL;
00219 
00220                 AddPlugin( strName, pszCLSID, strPath );
00221         }
00222 
00223         SafeArrayDestroy( pArray );
00224 
00225         return TRUE;
00226 }
00227 
00228 void CMediaVisDlg::OnDblClkPlugins(NMHDR* pNMHDR, LRESULT* pResult)
00229 {
00230         PostMessage( WM_COMMAND, IDOK );
00231         *pResult = 0;
00232 }
00233 
00234 void CMediaVisDlg::OnItemChangedPlugins(NMHDR* pNMHDR, LRESULT* pResult)
00235 {
00236         m_wndSetup.EnableWindow( m_wndList.GetSelectedCount() == 1 );
00237         *pResult = 0;
00238 }
00239 
00240 void CMediaVisDlg::OnSetup()
00241 {
00242         int nItem = m_wndList.GetNextItem( -1, LVIS_SELECTED );
00243         if ( nItem < 0 ) return;
00244 
00245         CString strCLSID        = m_wndList.GetItemText( nItem, 1 );
00246         CString strPath         = m_wndList.GetItemText( nItem, 2 );
00247 
00248         CLSID pCLSID;
00249         if ( ! GUIDX::Decode( strCLSID, &pCLSID ) ) return;
00250         if ( ! Plugins.LookupEnable( pCLSID, TRUE ) ) return;
00251 
00252         IAudioVisPlugin* pPlugin = NULL;
00253 
00254         if ( Settings.MediaPlayer.VisCLSID == strCLSID &&
00255                  Settings.MediaPlayer.VisPath == strPath )
00256         {
00257                 IMediaPlayer* pPlayer = ( m_pFrame != NULL ) ? m_pFrame->GetPlayer() : NULL;
00258 
00259                 if ( pPlayer != NULL )
00260                 {
00261                         pPlayer->GetPlugin( &pPlugin );
00262 
00263                         if ( pPlugin != NULL )
00264                         {
00265                                 pPlugin->Configure();
00266                                 pPlugin->Release();
00267                                 return;
00268                         }
00269                 }
00270         }
00271 
00272         HINSTANCE hRes = AfxGetResourceHandle();
00273 
00274         HRESULT hr = CoCreateInstance( pCLSID, NULL, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER,
00275                 IID_IAudioVisPlugin, (void**)&pPlugin );
00276 
00277         AfxSetResourceHandle( hRes );
00278 
00279         if ( FAILED(hr) || pPlugin == NULL ) return;
00280 
00281         if ( strPath.GetLength() )
00282         {
00283                 IWrappedPluginControl* pWrap = NULL;
00284                 hr = pPlugin->QueryInterface( IID_IWrappedPluginControl, (void**)&pWrap );
00285                 if ( SUCCEEDED(hr) && pWrap != NULL )
00286                 {
00287                         BSTR bsPath = strPath.AllocSysString();
00288                         pWrap->Load( bsPath, 0 );
00289                         pWrap->Release();
00290                         SysFreeString( bsPath );
00291                 }
00292         }
00293 
00294         pPlugin->Configure();
00295         pPlugin->Release();
00296 }
00297 
00298 void CMediaVisDlg::OnOK()
00299 {
00300         int nItem = m_wndList.GetNextItem( -1, LVIS_SELECTED );
00301         CString strCLSID, strPath;
00302 
00303         UpdateData( TRUE );
00304 
00305         if ( nItem >= 0 )
00306         {
00307                 strCLSID        = m_wndList.GetItemText( nItem, 1 );
00308                 strPath         = m_wndList.GetItemText( nItem, 2 );
00309         }
00310 
00311         if ( Settings.MediaPlayer.VisCLSID != strCLSID ||
00312                  Settings.MediaPlayer.VisPath != strPath ||
00313                  Settings.MediaPlayer.VisSize != m_nSize - 1 )
00314         {
00315                 Settings.MediaPlayer.VisCLSID   = strCLSID;
00316                 Settings.MediaPlayer.VisPath    = strPath;
00317                 Settings.MediaPlayer.VisSize    = m_nSize - 1;
00318 
00319                 Settings.Save();
00320                 CSkinDialog::OnOK();
00321         }
00322         else
00323         {
00324                 CSkinDialog::OnCancel();
00325         }
00326 }
00327 

Generated on Thu Dec 15 10:39:39 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2