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

PageSettingsLibrary.cpp

Go to the documentation of this file.
00001 //
00002 // PageSettingsLibrary.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 "Library.h"
00026 #include "LibraryHistory.h"
00027 #include "LibraryBuilder.h"
00028 #include "PageSettingsLibrary.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_DYNCREATE(CLibrarySettingsPage, CSettingsPage)
00037 
00038 BEGIN_MESSAGE_MAP(CLibrarySettingsPage, CSettingsPage)
00039         //{{AFX_MSG_MAP(CLibrarySettingsPage)
00040         ON_CBN_SELCHANGE(IDC_SAFE_TYPES, OnSelChangeSafeTypes)
00041         ON_CBN_EDITCHANGE(IDC_SAFE_TYPES, OnEditChangeSafeTypes)
00042         ON_BN_CLICKED(IDC_SAFE_ADD, OnSafeAdd)
00043         ON_BN_CLICKED(IDC_SAFE_REMOVE, OnSafeRemove)
00044         ON_CBN_SELCHANGE(IDC_PRIVATE_TYPES, OnSelChangePrivateTypes)
00045         ON_CBN_EDITCHANGE(IDC_PRIVATE_TYPES, OnEditChangePrivateTypes)
00046         ON_BN_CLICKED(IDC_PRIVATE_ADD, OnPrivateAdd)
00047         ON_BN_CLICKED(IDC_PRIVATE_REMOVE, OnPrivateRemove)
00048         ON_BN_CLICKED(IDC_RECENT_CLEAR, OnRecentClear)
00049         ON_BN_CLICKED(IDC_COLLECTIONS_BROWSE, OnCollectionsBrowse)
00050         //}}AFX_MSG_MAP
00051 END_MESSAGE_MAP()
00052 
00053 
00055 // CLibrarySettingsPage property page
00056 
00057 CLibrarySettingsPage::CLibrarySettingsPage() : CSettingsPage(CLibrarySettingsPage::IDD)
00058 {
00059         //{{AFX_DATA_INIT(CLibrarySettingsPage)
00060         m_bWatchFolders = FALSE;
00061         m_nRecentDays = 0;
00062         m_nRecentTotal = 0;
00063         m_bStoreViews = FALSE;
00064         m_bBrowseFiles = FALSE;
00065         m_bHighPriorityHash = FALSE;
00066         m_sCollectionPath = _T("");
00067         //}}AFX_DATA_INIT
00068 }
00069 
00070 CLibrarySettingsPage::~CLibrarySettingsPage()
00071 {
00072 }
00073 
00074 void CLibrarySettingsPage::DoDataExchange(CDataExchange* pDX)
00075 {
00076         CSettingsPage::DoDataExchange(pDX);
00077         //{{AFX_DATA_MAP(CLibrarySettingsPage)
00078         DDX_Control(pDX, IDC_RECENT_TOTAL_SPIN, m_wndRecentTotal);
00079         DDX_Control(pDX, IDC_RECENT_DAYS_SPIN, m_wndRecentDays);
00080         DDX_Control(pDX, IDC_SAFE_REMOVE, m_wndSafeRemove);
00081         DDX_Control(pDX, IDC_SAFE_ADD, m_wndSafeAdd);
00082         DDX_Control(pDX, IDC_SAFE_TYPES, m_wndSafeList);
00083         DDX_Control(pDX, IDC_PRIVATE_REMOVE, m_wndPrivateRemove);
00084         DDX_Control(pDX, IDC_PRIVATE_ADD, m_wndPrivateAdd);
00085         DDX_Control(pDX, IDC_PRIVATE_TYPES, m_wndPrivateList);
00086         DDX_Check(pDX, IDC_WATCH_FOLDERS, m_bWatchFolders);
00087         DDX_Text(pDX, IDC_RECENT_DAYS, m_nRecentDays);
00088         DDX_Text(pDX, IDC_RECENT_TOTAL, m_nRecentTotal);
00089         DDX_Check(pDX, IDC_STORE_VIEWS, m_bStoreViews);
00090         DDX_Check(pDX, IDC_BROWSE_FILES, m_bBrowseFiles);
00091         DDX_Check(pDX, IDC_HIGH_HASH, m_bHighPriorityHash);
00092         DDX_Control(pDX, IDC_COLLECTIONS_BROWSE, m_wndCollectionPath);
00093         DDX_Text(pDX, IDC_COLLECTIONS_FOLDER, m_sCollectionPath);
00094         //}}AFX_DATA_MAP
00095 }
00096 
00098 // CLibrarySettingsPage message handlers
00099 
00100 BOOL CLibrarySettingsPage::OnInitDialog() 
00101 {
00102         CSettingsPage::OnInitDialog();
00103         
00104         m_bStoreViews           = Settings.Library.StoreViews;
00105         m_bWatchFolders         = Settings.Library.WatchFolders;
00106         m_bBrowseFiles          = Settings.Community.ServeFiles;
00107         m_bHighPriorityHash = Settings.Library.HighPriorityHash;
00108 
00109         m_nRecentTotal          = Settings.Library.HistoryTotal;
00110         m_nRecentDays           = Settings.Library.HistoryDays;
00111 
00112         m_sCollectionPath       = Settings.Downloads.CollectionPath;
00113 
00114         
00115 
00116         CString strList;
00117         
00118         for ( strList = Settings.Library.SafeExecute + '|' ; strList.GetLength() ; )
00119         {
00120                 CString strType = strList.SpanExcluding( _T(" |") );
00121                 strList = strList.Mid( strType.GetLength() + 1 );
00122                 strType.TrimLeft();
00123                 strType.TrimRight();
00124                 if ( strType.GetLength() ) m_wndSafeList.AddString( strType );
00125         }
00126         
00127         for ( strList = Settings.Library.PrivateTypes + '|' ; strList.GetLength() ; )
00128         {
00129                 CString strType = strList.SpanExcluding( _T(" |") );
00130                 strList = strList.Mid( strType.GetLength() + 1 );
00131                 strType.TrimLeft();
00132                 strType.TrimRight();
00133                 if ( strType.GetLength() ) m_wndPrivateList.AddString( strType );
00134         }
00135 
00136         m_wndCollectionPath.SetIcon( IDI_BROWSE );
00137 
00138         UpdateData( FALSE );
00139 
00140         m_wndRecentTotal.SetRange( 0, 100 );
00141         m_wndRecentDays.SetRange( 0, 365 );
00142 
00143         m_wndSafeAdd.EnableWindow( m_wndSafeList.GetWindowTextLength() > 0 );
00144         m_wndSafeRemove.EnableWindow( m_wndSafeList.GetCurSel() >= 0 );
00145         m_wndPrivateAdd.EnableWindow( m_wndPrivateList.GetWindowTextLength() > 0 );
00146         m_wndPrivateRemove.EnableWindow( m_wndPrivateList.GetCurSel() >= 0 );
00147 
00148         return TRUE;
00149 }
00150 
00151 void CLibrarySettingsPage::OnSelChangeSafeTypes() 
00152 {
00153         m_wndSafeRemove.EnableWindow( m_wndSafeList.GetCurSel() >= 0 );
00154 }
00155 
00156 void CLibrarySettingsPage::OnEditChangeSafeTypes() 
00157 {
00158         m_wndSafeAdd.EnableWindow( m_wndSafeList.GetWindowTextLength() > 0 );
00159 }
00160 
00161 void CLibrarySettingsPage::OnSafeAdd() 
00162 {
00163         CString strType;
00164         m_wndSafeList.GetWindowText( strType );
00165 
00166         CharLower( strType.GetBuffer() );
00167         strType.ReleaseBuffer();
00168         strType.TrimLeft(); strType.TrimRight();
00169         if ( strType.IsEmpty() ) return;
00170 
00171         if ( m_wndSafeList.FindStringExact( -1, strType ) >= 0 ) return;
00172 
00173         m_wndSafeList.AddString( strType );
00174         m_wndSafeList.SetWindowText( _T("") );
00175 }
00176 
00177 void CLibrarySettingsPage::OnSafeRemove() 
00178 {
00179         int nItem = m_wndSafeList.GetCurSel();
00180         if ( nItem >= 0 ) m_wndSafeList.DeleteString( nItem );
00181         m_wndSafeRemove.EnableWindow( FALSE );
00182 }
00183 
00184 void CLibrarySettingsPage::OnSelChangePrivateTypes() 
00185 {
00186         m_wndPrivateRemove.EnableWindow( m_wndPrivateList.GetCurSel() >= 0 );
00187 }
00188 
00189 void CLibrarySettingsPage::OnEditChangePrivateTypes() 
00190 {
00191         m_wndPrivateAdd.EnableWindow( m_wndPrivateList.GetWindowTextLength() > 0 );
00192 }
00193 
00194 void CLibrarySettingsPage::OnPrivateAdd() 
00195 {
00196         CString strType;
00197         m_wndPrivateList.GetWindowText( strType );
00198 
00199         CharLower( strType.GetBuffer() );
00200         strType.ReleaseBuffer();
00201         strType.TrimLeft(); strType.TrimRight();
00202         if ( strType.IsEmpty() ) return;
00203 
00204         if ( m_wndPrivateList.FindStringExact( -1, strType ) >= 0 ) return;
00205 
00206         m_wndPrivateList.AddString( strType );
00207         m_wndPrivateList.SetWindowText( _T("") );
00208 }
00209 
00210 void CLibrarySettingsPage::OnPrivateRemove() 
00211 {
00212         int nItem = m_wndPrivateList.GetCurSel();
00213         if ( nItem >= 0 ) m_wndPrivateList.DeleteString( nItem );
00214         m_wndPrivateRemove.EnableWindow( FALSE );
00215 }
00216 
00217 void CLibrarySettingsPage::OnRecentClear() 
00218 {
00219         CQuickLock oLock( Library.m_pSection );
00220         LibraryHistory.Clear();
00221         Library.Update();
00222 }
00223 
00224 void CLibrarySettingsPage::OnCollectionsBrowse() 
00225 {
00226         TCHAR szPath[MAX_PATH];
00227         LPITEMIDLIST pPath;
00228         LPMALLOC pMalloc;
00229         BROWSEINFO pBI;
00230                 
00231         ZeroMemory( &pBI, sizeof(pBI) );
00232         pBI.hwndOwner           = AfxGetMainWnd()->GetSafeHwnd();
00233         pBI.pszDisplayName      = szPath;
00234         pBI.lpszTitle           = _T("Select folder for collections:");
00235         pBI.ulFlags                     = BIF_RETURNONLYFSDIRS;
00236         
00237         pPath = SHBrowseForFolder( &pBI );
00238 
00239         if ( pPath == NULL ) return;
00240 
00241         SHGetPathFromIDList( pPath, szPath );
00242         SHGetMalloc( &pMalloc );
00243         pMalloc->Free( pPath );
00244         pMalloc->Release();
00245         
00246         UpdateData( TRUE );
00247         m_sCollectionPath = szPath;
00248         //m_bCollectionsChanged = TRUE;
00249         UpdateData( FALSE );
00250 }
00251 
00252 void CLibrarySettingsPage::OnOK() 
00253 {
00254         UpdateData();
00255 
00256         Settings.Library.StoreViews             = m_bStoreViews;
00257         Settings.Library.WatchFolders   = m_bWatchFolders;
00258         Settings.Community.ServeFiles   = m_bBrowseFiles;
00259         Settings.Library.HighPriorityHash=m_bHighPriorityHash;
00260 
00261         Settings.Library.HistoryTotal   = m_nRecentTotal;
00262         Settings.Library.HistoryDays    = m_nRecentDays;
00263 
00264         Settings.Downloads.CollectionPath = m_sCollectionPath;
00265 
00266         //Set current hashing speed to requested
00267         LibraryBuilder.BoostPriority( m_bHighPriorityHash );
00268 
00269         Settings.Library.SafeExecute.Empty();
00270 
00271         for ( int nItem = 0 ; nItem < m_wndSafeList.GetCount() ; nItem++ )
00272         {
00273                 CString str;
00274                 m_wndSafeList.GetLBText( nItem, str );
00275 
00276                 if ( str.GetLength() )
00277                 {
00278                         if ( Settings.Library.SafeExecute.IsEmpty() )
00279                                 Settings.Library.SafeExecute += '|';
00280                         Settings.Library.SafeExecute += str;
00281                         Settings.Library.SafeExecute += '|';
00282                 }
00283         }
00284         
00285         Settings.Library.PrivateTypes.Empty();
00286 
00287         for ( int nItem = 0 ; nItem < m_wndPrivateList.GetCount() ; nItem++ )
00288         {
00289                 CString str;
00290                 m_wndPrivateList.GetLBText( nItem, str );
00291 
00292                 if ( str.GetLength() )
00293                 {
00294                         if ( Settings.Library.PrivateTypes.IsEmpty() )
00295                                 Settings.Library.PrivateTypes += '|';
00296                         Settings.Library.PrivateTypes += str;
00297                         Settings.Library.PrivateTypes += '|';
00298                 }
00299         }
00300 
00301         CSettingsPage::OnOK();
00302 }
00303 

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