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

DlgShareManager.cpp

Go to the documentation of this file.
00001 //
00002 // DlgShareManager.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 "LibraryFolders.h"
00027 #include "SharedFolder.h"
00028 #include "ShellIcons.h"
00029 #include "DlgShareManager.h"
00030 #include "DlgFolderScan.h"
00031 #include "LiveList.h"
00032 #include "Skin.h"
00033 #include "DlgHelp.h"
00034 
00035 #ifdef _DEBUG
00036 #define new DEBUG_NEW
00037 #undef THIS_FILE
00038 static char THIS_FILE[] = __FILE__;
00039 #endif
00040 
00041 IMPLEMENT_DYNAMIC(CShareManagerDlg, CSkinDialog)
00042 
00043 BEGIN_MESSAGE_MAP(CShareManagerDlg, CSkinDialog)
00044         //{{AFX_MSG_MAP(CShareManagerDlg)
00045         ON_BN_CLICKED(IDC_SHARE_ADD, OnShareAdd)
00046         ON_BN_CLICKED(IDC_SHARE_REMOVE, OnShareRemove)
00047         ON_NOTIFY(LVN_ITEMCHANGED, IDC_SHARE_FOLDERS, OnItemChangedShareFolders)
00048         //}}AFX_MSG_MAP
00049 END_MESSAGE_MAP()
00050 
00051 
00053 // CShareManagerDlg dialog
00054 
00055 CShareManagerDlg::CShareManagerDlg(CWnd* pParent) : CSkinDialog( CShareManagerDlg::IDD, pParent )
00056 {
00057         //{{AFX_DATA_INIT(CShareManagerDlg)
00058         //}}AFX_DATA_INIT
00059 }
00060 
00061 void CShareManagerDlg::DoDataExchange(CDataExchange* pDX)
00062 {
00063         CDialog::DoDataExchange(pDX);
00064         //{{AFX_DATA_MAP(CShareManagerDlg)
00065         DDX_Control(pDX, IDC_SHARE_REMOVE, m_wndRemove);
00066         DDX_Control(pDX, IDC_SHARE_FOLDERS, m_wndList);
00067         //}}AFX_DATA_MAP
00068 }
00069 
00071 // CShareManagerDlg message handlers
00072 
00073 BOOL CShareManagerDlg::OnInitDialog()
00074 {
00075         CSkinDialog::OnInitDialog();
00076 
00077         SkinMe( NULL, IDR_LIBRARYFRAME );
00078 
00079         CRect rc;
00080         m_wndList.GetClientRect( &rc );
00081         m_wndList.InsertColumn( 0, _T("Folder"), LVCFMT_LEFT, rc.Width() - GetSystemMetrics( SM_CXVSCROLL ) );
00082         m_wndList.SetImageList( ShellIcons.GetObject( 16 ), LVSIL_SMALL );
00083         m_wndList.EnableToolTips( TRUE );
00084         m_wndList.SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE,
00085                 LVS_EX_FULLROWSELECT|LVS_EX_LABELTIP,
00086                 LVS_EX_FULLROWSELECT|LVS_EX_LABELTIP );
00087 
00088         {
00089                 CQuickLock oLock( Library.m_pSection );
00090 
00091                 for ( POSITION pos = LibraryFolders.GetFolderIterator() ; pos ; )
00092                 {
00093                         CLibraryFolder* pFolder = LibraryFolders.GetNextFolder( pos );
00094 
00095                         m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE, m_wndList.GetItemCount(),
00096                                 pFolder->m_sPath, 0, 0, SHI_FOLDER_OPEN, 0 );
00097                 }
00098         }
00099 
00100         m_wndRemove.EnableWindow( FALSE );
00101 
00102         return TRUE;
00103 }
00104 
00105 void CShareManagerDlg::OnItemChangedShareFolders(NMHDR* pNMHDR, LRESULT* pResult)
00106 {
00107         *pResult = 0;
00108         m_wndRemove.EnableWindow( m_wndList.GetSelectedCount() > 0 );
00109 }
00110 
00111 void CShareManagerDlg::OnShareAdd()
00112 {
00113         //Let user select path to share
00114         TCHAR szPath[MAX_PATH];
00115         LPITEMIDLIST pPath;
00116         LPMALLOC pMalloc;
00117         BROWSEINFO pBI;
00118 
00119         ZeroMemory( &pBI, sizeof(pBI) );
00120         pBI.hwndOwner           = AfxGetMainWnd()->GetSafeHwnd();
00121         pBI.pszDisplayName      = szPath;
00122         pBI.lpszTitle           = _T("Select folder to share:");
00123         pBI.ulFlags                     = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
00124 
00125         pPath = SHBrowseForFolder( &pBI );
00126 
00127         if ( pPath == NULL ) return;
00128 
00129         SHGetPathFromIDList( pPath, szPath );
00130         SHGetMalloc( &pMalloc );
00131         pMalloc->Free( pPath );
00132 
00133         CString strPathLC( szPath );
00134         CharLower( strPathLC.GetBuffer() );
00135         strPathLC.ReleaseBuffer();
00136 
00137         //Check shared path isn't invalid
00138         if ( !LibraryFolders.IsShareable( strPathLC ) )
00139         {
00140                 CHelpDlg::Show( _T("ShareHelp.BadShare") );
00141                 return;
00142         }
00143 
00144         BOOL bForceAdd = FALSE;
00145         //Check shared path isn't already shared
00146         for ( int nItem = 0 ; nItem < m_wndList.GetItemCount() ; nItem++ )
00147         {
00148                 BOOL bSubFolder = FALSE;
00149                 CString strOldLC( m_wndList.GetItemText( nItem, 0 ) );
00150                 CharLower( strOldLC.GetBuffer() );
00151                 strOldLC.ReleaseBuffer();
00152 
00153                 if ( strPathLC == strOldLC )
00154                 {
00155                         // Matches exactly
00156                 }
00157                 else if ( strPathLC.GetLength() > strOldLC.GetLength() )
00158                 {
00159                         if ( strPathLC.Left( strOldLC.GetLength() + 1 ) != strOldLC + '\\' )
00160                                 continue;
00161                 }
00162                 else if ( strPathLC.GetLength() < strOldLC.GetLength() )
00163                 {
00164                         bSubFolder = TRUE;
00165                         if ( strOldLC.Left( strPathLC.GetLength() + 1 ) != strPathLC + '\\' )
00166                                 continue;
00167                 }
00168                 else
00169                 {
00170                         continue;
00171                 }
00172 
00173                 if ( bSubFolder )
00174                 {
00175                         CString strFormat, strMessage;
00176                         LoadString( strFormat, IDS_LIBRARY_SUBFOLDER_IN_LIBRARY );
00177                         strMessage.Format( strFormat, (LPCTSTR)szPath );
00178 
00179                         if ( bForceAdd || AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDYES )
00180                         {
00181                                 // Don't bother asking again- remove all sub-folders
00182                                 bForceAdd = TRUE;
00183                                 // Remove the sub-folder
00184                                 m_wndList.DeleteItem( nItem );
00185                                 nItem--;
00186                         }
00187                         else
00188                         {
00189                                 return;
00190                         }
00191                 }
00192                 else
00193                 {
00194                         CString strFormat, strMessage;
00195                         Skin.LoadString( strFormat, IDS_WIZARD_SHARE_ALREADY );
00196                         strMessage.Format( strFormat, (LPCTSTR)strOldLC );
00197                         AfxMessageBox( strMessage, MB_ICONINFORMATION );
00198                         //CHelpDlg::Show(  _T( "ShareHelp.AlreadyShared" ) );
00199                         return;
00200                 }
00201         }
00202 
00203         //Add path to shared list
00204         m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE, m_wndList.GetItemCount(),
00205                 szPath, 0, 0, SHI_FOLDER_OPEN, 0 );
00206 }
00207 
00208 void CShareManagerDlg::OnShareRemove()
00209 {
00210         for ( int nItem = 0 ; nItem < m_wndList.GetItemCount() ; nItem++ )
00211         {
00212                 if ( m_wndList.GetItemState( nItem, LVIS_SELECTED ) )
00213                 {
00214                         m_wndList.DeleteItem( nItem-- );
00215                 }
00216         }
00217 }
00218 
00219 void CShareManagerDlg::OnOK()
00220 {
00221         {
00222                 CQuickLock oLock( Library.m_pSection );
00223 
00224                 for ( POSITION pos = LibraryFolders.GetFolderIterator() ; pos ; )
00225                 {
00226                         CLibraryFolder* pFolder = LibraryFolders.GetNextFolder( pos );
00227 
00228                         int nItem = 0;
00229                         for ( ; nItem < m_wndList.GetItemCount() ; nItem++ )
00230                         {
00231                                 CString strFolder = m_wndList.GetItemText( nItem, 0 );
00232                                 if ( strFolder.CompareNoCase( pFolder->m_sPath ) == 0 ) break;
00233                         }
00234 
00235                         if ( nItem >= m_wndList.GetItemCount() )
00236                         {
00237                                 LibraryFolders.RemoveFolder( pFolder );
00238                         }
00239                 }
00240 
00241                 for ( int nItem = 0 ; nItem < m_wndList.GetItemCount() ; nItem++ )
00242                 {
00243                         LibraryFolders.AddFolder( m_wndList.GetItemText( nItem, 0 ) );
00244                 }
00245         }
00246 
00247         CFolderScanDlg dlgScan;
00248         dlgScan.DoModal();
00249 
00250         CDialog::OnOK();
00251 }

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