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

PageSettingsWeb.cpp

Go to the documentation of this file.
00001 //
00002 // PageSettingsWeb.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 "ShareazaURL.h"
00026 #include "PageSettingsWeb.h"
00027 
00028 #ifdef _DEBUG
00029 #define new DEBUG_NEW
00030 #undef THIS_FILE
00031 static char THIS_FILE[] = __FILE__;
00032 #endif
00033 
00034 IMPLEMENT_DYNCREATE(CWebSettingsPage, CSettingsPage)
00035 
00036 BEGIN_MESSAGE_MAP(CWebSettingsPage, CSettingsPage)
00037         //{{AFX_MSG_MAP(CWebSettingsPage)
00038         ON_CBN_EDITCHANGE(IDC_EXT_LIST, OnEditChangeExtList)
00039         ON_CBN_SELCHANGE(IDC_EXT_LIST, OnSelChangeExtList)
00040         ON_BN_CLICKED(IDC_EXT_ADD, OnExtAdd)
00041         ON_BN_CLICKED(IDC_EXT_REMOVE, OnExtRemove)
00042         ON_BN_CLICKED(IDC_WEB_HOOK, OnWebHook)
00043         //}}AFX_MSG_MAP
00044 END_MESSAGE_MAP()
00045 
00046 
00048 // CWebSettingsPage property page
00049 
00050 CWebSettingsPage::CWebSettingsPage() : CSettingsPage( CWebSettingsPage::IDD )
00051 {
00052         //{{AFX_DATA_INIT(CWebSettingsPage)
00053         m_bUriMagnet = FALSE;
00054         m_bUriGnutella = FALSE;
00055         m_bUriED2K = FALSE;
00056         m_bWebHook = FALSE;
00057         m_bUriPiolet = FALSE;
00058         m_bUriTorrent = FALSE;
00059         //}}AFX_DATA_INIT
00060 }
00061 
00062 CWebSettingsPage::~CWebSettingsPage()
00063 {
00064 }
00065 
00066 void CWebSettingsPage::DoDataExchange(CDataExchange* pDX)
00067 {
00068         CSettingsPage::DoDataExchange(pDX);
00069         //{{AFX_DATA_MAP(CWebSettingsPage)
00070         DDX_Control(pDX, IDC_EXT_REMOVE, m_wndExtRemove);
00071         DDX_Control(pDX, IDC_EXT_ADD, m_wndExtAdd);
00072         DDX_Control(pDX, IDC_EXT_LIST, m_wndExtensions);
00073         DDX_Check(pDX, IDC_URI_MAGNET, m_bUriMagnet);
00074         DDX_Check(pDX, IDC_URI_GNUTELLA, m_bUriGnutella);
00075         DDX_Check(pDX, IDC_URI_ED2K, m_bUriED2K);
00076         DDX_Check(pDX, IDC_WEB_HOOK, m_bWebHook);
00077         DDX_Check(pDX, IDC_URI_PIOLET, m_bUriPiolet);
00078         DDX_Check(pDX, IDC_URI_TORRENT, m_bUriTorrent);
00079         //}}AFX_DATA_MAP
00080 }
00081 
00083 // CWebSettingsPage message handlers
00084 
00085 BOOL CWebSettingsPage::OnInitDialog() 
00086 {
00087         CSettingsPage::OnInitDialog();
00088         
00089         m_bUriMagnet    = Settings.Web.Magnet;
00090         m_bUriGnutella  = Settings.Web.Gnutella;
00091         m_bUriED2K              = Settings.Web.ED2K;
00092         m_bUriPiolet    = Settings.Web.Piolet;
00093         m_bUriTorrent   = Settings.Web.Torrent;
00094         
00095         HKEY hKey;
00096         if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects\\{0EEDB912-C5FA-486F-8334-57288578C627}"), 0, KEY_READ, &hKey ) == ERROR_SUCCESS )
00097         {
00098                 RegCloseKey( hKey );
00099                 m_bWebHook = TRUE;
00100         }
00101         
00102         CString strList = theApp.GetProfileString( _T("Downloads"), _T("WebHookExtensions"),
00103                 _T("|zip|exe|bin|gz|z|tar|arj|lzh|sit|hqx|fml|tgz|grs|mp3|rar|r0|ace|iso|msi|") );
00104         
00105         for ( strList += '|' ; strList.GetLength() ; )
00106         {
00107                 CString strType = strList.SpanExcluding( _T(" |") );
00108                 strList = strList.Mid( strType.GetLength() + 1 );
00109                 strType.TrimLeft();
00110                 strType.TrimRight();
00111                 if ( strType.GetLength() ) m_wndExtensions.AddString( strType );
00112         }
00113         
00114         UpdateData( FALSE );
00115         OnWebHook();
00116         
00117         return TRUE;
00118 }
00119 
00120 void CWebSettingsPage::OnWebHook() 
00121 {
00122         UpdateData( TRUE );
00123         m_wndExtensions.EnableWindow( m_bWebHook );
00124         OnEditChangeExtList();
00125         OnSelChangeExtList();
00126 }
00127 
00128 void CWebSettingsPage::OnEditChangeExtList() 
00129 {
00130         m_wndExtAdd.EnableWindow( m_bWebHook && m_wndExtensions.GetWindowTextLength() > 0 );
00131 }
00132 
00133 void CWebSettingsPage::OnSelChangeExtList() 
00134 {
00135         m_wndExtRemove.EnableWindow( m_bWebHook && m_wndExtensions.GetCurSel() >= 0 );
00136 }
00137 
00138 void CWebSettingsPage::OnExtAdd() 
00139 {
00140         CString strType;
00141         m_wndExtensions.GetWindowText( strType );
00142 
00143         CharLower( strType.GetBuffer() );
00144         strType.ReleaseBuffer();
00145         strType.TrimLeft(); strType.TrimRight();
00146         if ( strType.IsEmpty() ) return;
00147 
00148         if ( m_wndExtensions.FindString( -1, strType ) >= 0 ) return;
00149 
00150         m_wndExtensions.AddString( strType );
00151         m_wndExtensions.SetWindowText( _T("") );
00152 }
00153 
00154 void CWebSettingsPage::OnExtRemove() 
00155 {
00156         int nItem = m_wndExtensions.GetCurSel();
00157         if ( nItem >= 0 ) m_wndExtensions.DeleteString( nItem );
00158         m_wndExtRemove.EnableWindow( FALSE );
00159 }
00160 
00161 void CWebSettingsPage::OnOK()
00162 {
00163         UpdateData();
00164         
00165         Settings.Web.Magnet             = m_bUriMagnet;
00166         Settings.Web.Gnutella   = m_bUriGnutella;
00167         Settings.Web.ED2K               = m_bUriED2K;
00168         Settings.Web.Piolet             = m_bUriPiolet;
00169         Settings.Web.Torrent    = m_bUriTorrent;
00170         
00171         CShareazaURL::Register();
00172         
00173         if ( HINSTANCE hInstance = LoadLibrary( Settings.General.Path + _T("\\Plugins\\RazaWebHook.dll") ) )
00174         {
00175                 HRESULT (WINAPI *pfnRegister)();
00176                 (FARPROC&)pfnRegister = GetProcAddress( hInstance, m_bWebHook ? "DllRegisterServer" : "DllUnregisterServer" );
00177                 if ( pfnRegister != NULL ) (*pfnRegister)();
00178                 FreeLibrary( hInstance );
00179         }
00180         
00181         HKEY hKey;
00182         
00183         if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects"), 0, KEY_READ, &hKey ) == ERROR_SUCCESS )
00184         {
00185                 if ( m_bWebHook )
00186                 {
00187                         DWORD dwDisposition;
00188                         HKEY hCLSID = NULL;
00189                         
00190                         RegCreateKeyEx( hKey, _T("{0EEDB912-C5FA-486F-8334-57288578C627}"), 0, NULL,
00191                                 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hCLSID, &dwDisposition );
00192                         
00193                         if ( hCLSID ) RegCloseKey( hCLSID );
00194                 }
00195                 else
00196                 {
00197                         RegDeleteKey( hKey, _T("{0EEDB912-C5FA-486F-8334-57288578C627}") );
00198                 }
00199                 
00200                 RegCloseKey( hKey );
00201         }
00202         
00203         CString strExtensions;
00204         
00205         for ( int nItem = 0 ; nItem < m_wndExtensions.GetCount() ; nItem++ )
00206         {
00207                 CString str;
00208                 m_wndExtensions.GetLBText( nItem, str );
00209                 
00210                 if ( str.GetLength() )
00211                 {
00212                         if ( strExtensions.IsEmpty() ) strExtensions += '|';
00213                         strExtensions += str;
00214                         strExtensions += '|';
00215                 }
00216         }
00217         
00218         theApp.WriteProfileInt( _T("Downloads"), _T("WebHookEnable"), m_bWebHook );
00219         theApp.WriteProfileString( _T("Downloads"), _T("WebHookExtensions"), strExtensions );
00220         
00221         CSettingsPage::OnOK();
00222 }
00223 

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