00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Library.h"
00025 #include "SharedFile.h"
00026 #include "PageFileSharing.h"
00027
00028 #include "Transfers.h"
00029 #include "UploadQueue.h"
00030 #include "UploadQueues.h"
00031
00032 #ifdef _DEBUG
00033 #define new DEBUG_NEW
00034 #undef THIS_FILE
00035 static char THIS_FILE[] = __FILE__;
00036 #endif
00037
00038 IMPLEMENT_DYNCREATE(CFileSharingPage, CFilePropertiesPage)
00039
00040 BEGIN_MESSAGE_MAP(CFileSharingPage, CFilePropertiesPage)
00041
00042 ON_BN_CLICKED(IDC_SHARE_OVERRIDE_0, OnShareOverride0)
00043 ON_BN_CLICKED(IDC_SHARE_OVERRIDE_1, OnShareOverride1)
00044
00045 END_MESSAGE_MAP()
00046
00047
00049
00050
00051 CFileSharingPage::CFileSharingPage() : CFilePropertiesPage(CFileSharingPage::IDD)
00052 {
00053
00054 m_bOverride = -1;
00055 m_bShare = FALSE;
00056 m_sTags = _T("");
00057
00058 }
00059
00060 CFileSharingPage::~CFileSharingPage()
00061 {
00062 }
00063
00064 void CFileSharingPage::DoDataExchange(CDataExchange* pDX)
00065 {
00066 CFilePropertiesPage::DoDataExchange(pDX);
00067
00068 DDX_Control(pDX, IDC_FILE_TAGS, m_wndTags);
00069 DDX_Control(pDX, IDC_FILE_SHARE, m_wndShare);
00070 DDX_Control(pDX, IDC_FILE_NETWORKS, m_wndNetworks);
00071 DDX_Radio(pDX, IDC_SHARE_OVERRIDE_0, m_bOverride);
00072 DDX_Check(pDX, IDC_FILE_SHARE, m_bShare);
00073 DDX_CBString(pDX, IDC_FILE_TAGS, m_sTags);
00074
00075 }
00076
00078
00079
00080 BOOL CFileSharingPage::OnInitDialog()
00081 {
00082 CFilePropertiesPage::OnInitDialog();
00083
00084 m_wndTags.AddString( _T("") );
00085
00086 if ( UploadQueues.m_pSection.Lock() )
00087 {
00088 CStringList pAdded;
00089
00090 for ( POSITION pos = UploadQueues.GetIterator() ; pos ; )
00091 {
00092 CUploadQueue* pQueue = UploadQueues.GetNext( pos );
00093
00094 if ( pQueue->m_sShareTag.GetLength() )
00095 {
00096 if ( pAdded.Find( pQueue->m_sShareTag ) == NULL )
00097 {
00098 pAdded.AddTail( pQueue->m_sShareTag );
00099 m_wndTags.AddString( pQueue->m_sShareTag );
00100 }
00101 }
00102 }
00103
00104 UploadQueues.m_pSection.Unlock();
00105
00106 if ( pAdded.IsEmpty() )
00107 {
00108 m_wndTags.AddString( _T("Release") );
00109 m_wndTags.AddString( _T("Popular") );
00110 }
00111 }
00112
00113 {
00114 CQuickLock oLock( Library.m_pSection );
00115
00116 if ( CLibraryFile* pFile = GetFile() )
00117 {
00118 m_bOverride = pFile->m_bShared != TS_UNKNOWN;
00119 m_bShare = pFile->IsShared();
00120 m_sTags = pFile->m_sShareTags;
00121 }
00122 else if ( CLibraryList* pList = GetList() )
00123 {
00124 for ( POSITION pos = pList->GetIterator() ; pos ; )
00125 {
00126 if ( CLibraryFile* pFile = pList->GetNextFile( pos ) )
00127 {
00128 m_bOverride = pFile->m_bShared != TS_UNKNOWN;
00129 m_bShare = pFile->IsShared();
00130 m_sTags = pFile->m_sShareTags;
00131 }
00132 }
00133
00134 }
00135 }
00136
00137 UpdateData( FALSE );
00138 m_wndShare.EnableWindow( m_bOverride );
00139
00140 return TRUE;
00141 }
00142
00143 void CFileSharingPage::OnShareOverride0()
00144 {
00145 UpdateData();
00146
00147 m_wndShare.EnableWindow( m_bOverride );
00148
00149 if ( ! m_bOverride )
00150 {
00151 CSingleLock oLock( &Library.m_pSection, TRUE );
00152 if ( CLibraryFile* pFile = GetFile() )
00153 {
00154 TRISTATE bSave = pFile->m_bShared;
00155 pFile->m_bShared = TS_UNKNOWN;
00156 m_bShare = pFile->IsShared();
00157 pFile->m_bShared = bSave;
00158
00159 oLock.Unlock();
00160 UpdateData( FALSE );
00161 }
00162 }
00163 }
00164
00165 void CFileSharingPage::OnShareOverride1()
00166 {
00167 OnShareOverride0();
00168 }
00169
00170 void CFileSharingPage::OnOK()
00171 {
00172 UpdateData();
00173
00174 if ( CLibraryList* pList = GetList() )
00175 {
00176 CQuickLock oLock( Library.m_pSection );
00177
00178 for ( POSITION pos = pList->GetIterator() ; pos ; )
00179 {
00180 if ( CLibraryFile* pFile = pList->GetNextFile( pos ) )
00181 {
00182 if ( m_bOverride )
00183 {
00184 pFile->m_bShared = m_bShare ? TS_TRUE : TS_FALSE;
00185 }
00186 else
00187 {
00188 pFile->m_bShared = TS_UNKNOWN;
00189 }
00190
00191 pFile->m_sShareTags = m_sTags;
00192 }
00193 }
00194
00195 }
00196
00197 CFilePropertiesPage::OnOK();
00198 }