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

DlgDownloadGroup.cpp

Go to the documentation of this file.
00001 //
00002 // DlgDownloadGroup.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 "DownloadGroup.h"
00029 #include "DownloadGroups.h"
00030 #include "DlgDownloadGroup.h"
00031 #include "DlgHelp.h"
00032 
00033 #include "Schema.h"
00034 #include "SchemaCache.h"
00035 #include "ShellIcons.h"
00036 
00037 #ifdef _DEBUG
00038 #define new DEBUG_NEW
00039 #undef THIS_FILE
00040 static char THIS_FILE[] = __FILE__;
00041 #endif
00042 
00043 BEGIN_MESSAGE_MAP(CDownloadGroupDlg, CSkinDialog)
00044         //{{AFX_MSG_MAP(CDownloadGroupDlg)
00045         ON_BN_CLICKED(IDC_FILTER_ADD, OnFilterAdd)
00046         ON_BN_CLICKED(IDC_FILTER_REMOVE, OnFilterRemove)
00047         ON_CBN_EDITCHANGE(IDC_FILTER_LIST, OnEditChangeFilterList)
00048         ON_CBN_SELCHANGE(IDC_FILTER_LIST, OnSelChangeFilterList)
00049         ON_BN_CLICKED(IDC_DOWNLOADS_BROWSE, OnBrowse)
00050         //}}AFX_MSG_MAP
00051 END_MESSAGE_MAP()
00052 
00053 
00055 // CDownloadGroupDlg dialog
00056 
00057 CDownloadGroupDlg::CDownloadGroupDlg(CDownloadGroup* pGroup, CWnd* pParent) : CSkinDialog(CDownloadGroupDlg::IDD, pParent)
00058 {
00059         //{{AFX_DATA_INIT(CDownloadGroupDlg)
00060         m_sName = _T("");
00061         m_sFolder = _T("");
00062         //}}AFX_DATA_INIT
00063         m_pGroup = pGroup;
00064 }
00065 
00066 void CDownloadGroupDlg::DoDataExchange(CDataExchange* pDX)
00067 {
00068         CSkinDialog::DoDataExchange(pDX);
00069         //{{AFX_DATA_MAP(CDownloadGroupDlg)
00070         DDX_Control(pDX, IDC_DOWNLOADS_BROWSE, m_wndBrowse);
00071         DDX_Control(pDX, IDC_ICON_LIST, m_wndImages);
00072         DDX_Control(pDX, IDC_FOLDER, m_wndFolder);
00073         DDX_Control(pDX, IDC_FILTER_ADD, m_wndFilterAdd);
00074         DDX_Control(pDX, IDC_FILTER_REMOVE, m_wndFilterRemove);
00075         DDX_Control(pDX, IDC_FILTER_LIST, m_wndFilterList);
00076         DDX_Text(pDX, IDC_NAME, m_sName);
00077         DDX_Text(pDX, IDC_FOLDER, m_sFolder);
00078         //}}AFX_DATA_MAP
00079 }
00080 
00082 // CDownloadGroupDlg message handlers
00083 
00084 BOOL CDownloadGroupDlg::OnInitDialog()
00085 {
00086         CSkinDialog::OnInitDialog();
00087 
00088         SkinMe( _T("CDownloadGroupDlg") );
00089 
00090         m_wndImages.SetImageList( ShellIcons.GetObject( 16 ), LVSIL_SMALL );
00091         m_wndBrowse.SetIcon( IDI_BROWSE );
00092 
00093         CSingleLock pLock( &DownloadGroups.m_pSection, TRUE );
00094 
00095         if ( ! DownloadGroups.Check( m_pGroup ) )
00096         {
00097                 EndDialog( IDCANCEL );
00098                 return TRUE;
00099         }
00100 
00101         m_sName         = m_pGroup->m_sName;
00102         m_sFolder       = m_pGroup->m_sFolder;
00103 
00104         for ( POSITION pos = m_pGroup->m_pFilters.GetHeadPosition() ; pos ; )
00105         {
00106                 m_wndFilterList.AddString( m_pGroup->m_pFilters.GetNext( pos ) );
00107         }
00108 
00109         for ( POSITION pos = SchemaCache.GetIterator() ; pos ; )
00110         {
00111                 CSchema* pSchema = SchemaCache.GetNext( pos );
00112 
00113                 int nIndex = m_wndImages.InsertItem( LVIF_IMAGE|LVIF_PARAM|LVIF_TEXT,
00114                         m_wndImages.GetItemCount(), _T("Icon"), 0, 0, pSchema->m_nIcon16,
00115                         (LPARAM)pSchema );
00116 
00117                 if ( pSchema->m_sURI == m_pGroup->m_sSchemaURI )
00118                 {
00119                         m_wndImages.SetItemState( nIndex, LVIS_SELECTED, LVIS_SELECTED );
00120                 }
00121         }
00122 
00123         UpdateData( FALSE );
00124 
00125         BOOL bSuper = DownloadGroups.GetSuperGroup() == m_pGroup;
00126 
00127         m_wndFolder.EnableWindow( ! bSuper );
00128         m_wndFilterList.EnableWindow( ! bSuper );
00129         m_wndFilterAdd.EnableWindow( m_wndFilterList.GetWindowTextLength() > 0 );
00130         m_wndFilterRemove.EnableWindow( m_wndFilterList.GetCurSel() >= 0 );
00131 
00132         return TRUE;
00133 }
00134 
00135 void CDownloadGroupDlg::OnEditChangeFilterList()
00136 {
00137         m_wndFilterAdd.EnableWindow( m_wndFilterList.GetWindowTextLength() > 0 );
00138 }
00139 
00140 void CDownloadGroupDlg::OnSelChangeFilterList()
00141 {
00142         m_wndFilterRemove.EnableWindow( m_wndFilterList.GetCurSel() >= 0 );
00143 }
00144 
00145 void CDownloadGroupDlg::OnFilterAdd()
00146 {
00147         CString strType;
00148         m_wndFilterList.GetWindowText( strType );
00149 
00150         strType.TrimLeft(); strType.TrimRight();
00151         if ( strType.IsEmpty() ) return;
00152 
00153         if ( m_wndFilterList.FindString( -1, strType ) >= 0 ) return;
00154 
00155         m_wndFilterList.AddString( strType );
00156         m_wndFilterList.SetWindowText( _T("") );
00157 }
00158 
00159 void CDownloadGroupDlg::OnFilterRemove()
00160 {
00161         int nItem = m_wndFilterList.GetCurSel();
00162         if ( nItem >= 0 ) m_wndFilterList.DeleteString( nItem );
00163         m_wndFilterRemove.EnableWindow( FALSE );
00164 }
00165 
00166 void CDownloadGroupDlg::OnOK()
00167 {
00168         UpdateData();
00169 
00170         CSingleLock pLock( &DownloadGroups.m_pSection, TRUE );
00171 
00172         if ( DownloadGroups.Check( m_pGroup ) )
00173         {
00174                 m_pGroup->m_sName       = m_sName;
00175                 m_pGroup->m_sFolder     = m_sFolder;
00176 
00177                 m_pGroup->m_pFilters.RemoveAll();
00178 
00179                 for ( int nItem = 0 ; nItem < m_wndFilterList.GetCount() ; nItem++ )
00180                 {
00181                         CString str;
00182                         m_wndFilterList.GetLBText( nItem, str );
00183                         if ( str.GetLength() ) m_pGroup->m_pFilters.AddTail( str );
00184                 }
00185 
00186                 int nIndex = m_wndImages.GetNextItem( -1, LVNI_SELECTED );
00187 
00188                 if ( nIndex >= 0 )
00189                 {
00190                         CSchema* pSchema = (CSchema*)m_wndImages.GetItemData( nIndex );
00191                         m_pGroup->SetSchema( pSchema->m_sURI );
00192                 }
00193                 else
00194                 {
00195                         m_pGroup->SetSchema( _T("") );
00196                 }
00197         }
00198 
00199         if ( m_sFolder.GetLength() && ! LibraryFolders.IsFolderShared( m_sFolder ) )
00200         {
00201                 CString strFormat, strMessage;
00202 
00203                 LoadString( strFormat, IDS_LIBRARY_DOWNLOADS_ADD );
00204                 strMessage.Format( strFormat, (LPCTSTR)m_sFolder );
00205 
00206                 BOOL bAdd = ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDYES );
00207                 if ( bAdd )
00208                 {
00209                         if ( LibraryFolders.IsSubFolderShared( m_sFolder ) )
00210                         {
00211                                 CString strFormat, strMessage;
00212                                 LoadString( strFormat, IDS_LIBRARY_SUBFOLDER_IN_LIBRARY );
00213                                 strMessage.Format( strFormat, (LPCTSTR)m_sFolder );
00214 
00215                                 bAdd = ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDYES );
00216                                 if ( bAdd )
00217                                 {
00218                                         CLibraryFolder* pFolder;
00219                                         while ( ( pFolder = LibraryFolders.IsSubFolderShared( m_sFolder ) ) != NULL )
00220                                         {
00221                                                 LibraryFolders.RemoveFolder( pFolder );
00222                                         }
00223                                 }
00224                         }
00225                         if ( bAdd )
00226                         {
00227                                 if ( !LibraryFolders.IsShareable( m_sFolder ) )
00228                                 {
00229                                         CHelpDlg::Show( _T("ShareHelp.BadShare") );
00230                                         bAdd = FALSE;
00231                                 }
00232                         }
00233                         if ( bAdd )
00234                         {
00235                                 if ( CLibraryFolder* pFolder = LibraryFolders.AddFolder( m_sFolder ) )
00236                                 {
00237                                         LoadString( strMessage, IDS_LIBRARY_DOWNLOADS_SHARE );
00238 
00239                                         BOOL bShare = AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDYES;
00240 
00241                                         CQuickLock oLock( Library.m_pSection );
00242                                         if ( LibraryFolders.CheckFolder( pFolder, TRUE ) )
00243                                                 pFolder->m_bShared = bShare ? TS_TRUE : TS_FALSE;
00244                                         Library.Update();
00245                                 }
00246                         }
00247                 }
00248         }
00249 
00250         CSkinDialog::OnOK();
00251 }
00252 
00253 void CDownloadGroupDlg::OnBrowse()
00254 {
00255         TCHAR szPath[MAX_PATH];
00256         LPITEMIDLIST pPath;
00257         LPMALLOC pMalloc;
00258         BROWSEINFO pBI;
00259 
00260         ZeroMemory( &pBI, sizeof(pBI) );
00261         pBI.hwndOwner           = AfxGetMainWnd()->GetSafeHwnd();
00262         pBI.pszDisplayName      = szPath;
00263         pBI.lpszTitle           = _T("Select folder for downloads:");
00264         pBI.ulFlags                     = BIF_RETURNONLYFSDIRS;
00265 
00266         pPath = SHBrowseForFolder( &pBI );
00267 
00268         if ( pPath == NULL ) return;
00269 
00270         SHGetPathFromIDList( pPath, szPath );
00271         SHGetMalloc( &pMalloc );
00272         pMalloc->Free( pPath );
00273         pMalloc->Release();
00274 
00275 
00276         // Make sure download/incomplete folders aren't the same
00277         if ( _tcsicmp( szPath, Settings.Downloads.IncompletePath ) == 0 )
00278         {
00279                 CString strMessage;
00280                 LoadString( strMessage, IDS_SETTINGS_FILEPATH_NOT_SAME );
00281                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00282                 return;
00283         }
00284 
00285         // If the group folder and download folders are the same, use the default download folder
00286         if ( _tcsicmp( szPath, Settings.Downloads.CompletePath ) == 0 )
00287         {
00288                 UpdateData( TRUE );
00289                 m_sFolder.Empty();
00290                 UpdateData( FALSE );
00291                 return;
00292         }
00293 
00294         UpdateData( TRUE );
00295         m_sFolder = szPath;
00296         UpdateData( FALSE );
00297 }

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