//--------------------------------------------------------------------------- #include #include "UploadFormUnit.h" #pragma hdrstop #include "GlobalUnit.h" //--------------------------------------------------------------------------- #include "ImgCopperFormUnit.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "PNGButton" #pragma resource "*.dfm" TUploadForm *UploadForm; //--------------------------------------------------------------------------- __fastcall TUploadForm::TUploadForm(TComponent* Owner) : TForm(Owner) { m_iCheckCount = 0; } //--------------------------------------------------------------------------- __fastcall TUploadForm::~TUploadForm() { StopURLDownload(UrlDown_ImageCover); } //--------------------------------------------------------------------------- void __fastcall TUploadForm::WMNCHitTest(TWMNCHitTest &Msg) { TForm::Dispatch(&Msg); if( Msg.Result==HTCLIENT && Msg.YPosColor = RGB(60,43,23); m_radioOriginal->Font->Color = RGB(60,43,23); m_radioAmend->Font->Color = RGB(60,43,23); m_cbTypes[0] = m_checkPop; m_cbTypes[1] = m_checkFolk; m_cbTypes[2] = m_checkRock; m_cbTypes[3] = m_checkDance; m_cbTypes[4] = m_checkJazz; m_cbTypes[5] = m_checkBlues; m_cbTypes[6] = m_checkSamba; m_cbTypes[7] = m_checkClassic; m_cbTypes[8] = m_checkWaltz; m_cbTypes[9] = m_checkIndpent; m_cbTypes[10] = m_checkCountry; m_cbTypes[11] = m_checkOthers; //»æÖÆÔ²½Ç´°Ìå HRGN hRgn = CreateRoundRectRgn( 0, 0, Width+1, Height+1, 16, 16 ); SetWindowRgn( Handle, hRgn, false ); DeleteObject( hRgn ); if( strlen(g_infoSong.strSongName)==0 ) sprintf( g_infoSong.strSongName, "untitle-%s-%d", g_strTSName[g_iMelodyTimeSignature], g_nMelodyTempo ); m_editSongName->Text = g_infoSong.strSongName; if( strlen(g_infoSong.strSinger)==0 ) strcpy( g_infoSong.strSinger, g_infoUser.strNickName ); m_editSinger->Text = g_infoSong.strSinger; if( strlen(g_infoSong.strArranger)==0 ) strcpy( g_infoSong.strArranger, g_infoUser.strNickName ); m_editArranger->Text = g_infoSong.strArranger; if( strlen(g_infoSong.strLyricist)==0 ) strcpy( g_infoSong.strLyricist, g_infoUser.strNickName ); m_editLyricist->Text = g_infoSong.strLyricist; if( strlen(g_infoSong.strComposer)==0 ) strcpy( g_infoSong.strComposer, g_infoUser.strNickName ); m_editComposer->Text = g_infoSong.strComposer; m_editOriginal->Text = g_infoSong.strOriginal; m_memoDescription->Text = g_infoSong.strDescription; m_checkSubmit->Checked = g_infoSong.iSubmit; if( g_infoSong.iCreation==3 ){ m_radioAmend->Checked = true; } m_cbSex->ItemIndex = g_infoSong.iSingerType - 1; m_btnOk->Enabled = true; UINT aStyleIDs[32]; memset( aStyleIDs, 0, 32*sizeof(UINT) ); int count = 0; for( int i=0; iidStyle==aStyleIDs[j] ){ bFound = true; break; } } if( !bFound ){ aStyleIDs[count++] = pStage->idStyle; if( count>=32 ){ break; } } } if( memcmp( g_infoSong.aStyleIDs, aStyleIDs, 32*sizeof(UINT) ) ){ memcpy( g_infoSong.aStyleIDs, aStyleIDs, 32*sizeof(UINT) ); memset( g_infoSong.iMusicStyle, -1, 4 ); } if( g_infoSong.iMusicStyle[0]!=-1 ){ for( int i=0; i<4; i++ ){ int iCB = g_infoSong.iMusicStyle[i]; if( iCB==127 ) iCB = MUSIC_TYPE_NUM-1; if( iCB!=-1 ){ m_cbTypes[iCB]->Checked = true; } } } else{ TSTYLEINFO infoStyle; for( int i=0; i=0 ){ char iType = infoStyle.detail.type[j]; char iCB = iType; if( iType>=MUSIC_TYPE_NUM-1 ){ iCB = MUSIC_TYPE_NUM-1; iType = 127; } bool bFound = false; for( int k=0; kChecked = true; if( m_iCheckCount>=4 ){ break; } } } } } } m_editSongName->OnChange = EditNameChange; m_editOriginal->OnChange = EditNameChange; m_editSinger->OnChange = EditNameChange; m_editArranger->OnChange = EditNameChange; m_editLyricist->OnChange = EditNameChange; m_editComposer->OnChange = EditNameChange; if( g_infoSong.strLyric ) { m_memoLyrices->Text = g_infoSong.strLyric; } String strCoverPath = g_strUserPath.c_str(); strCoverPath += MUSIC_COVER_DIR; if( g_infoSong.strIconName ) { strCoverPath = g_infoSong.strIconName; }else{ strCoverPath += MUSIC_COVER_FILE; } if( SetMusicCover(strCoverPath) ) m_strMusicCoverPath = strCoverPath; if( NULL==g_infoSong.strIconName ) { bool bDownloadMusicCover = false; if( NULL==g_pTThreadMusciCover ) { bDownloadMusicCover = true; }else if( !g_pTThreadMusciCover->Started || (g_pTThreadMusciCover->Started && g_pTThreadMusciCover->Finished) ) { bDownloadMusicCover = true; } if( bDownloadMusicCover ){ SAFE_DELETE(g_pTThreadMusciCover) g_pTThreadMusciCover = new TThreadMusciCover(true, this); g_pTThreadMusciCover->Priority = tpIdle; g_pTThreadMusciCover->Start(); } } SetTransparent( this ); } //--------------------------------------------------------------------------- void __fastcall TUploadForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { switch( Key ){ case VK_RETURN: if( m_btnOk->Enabled && !m_memoDescription->Focused() && !m_memoLyrices->Focused() ){ OkClick( NULL ); ModalResult = mrOk; } break; case VK_ESCAPE: ModalResult = mrCancel; break; } } //--------------------------------------------------------------------------- void __fastcall TUploadForm::OkClick(TObject *Sender) { int nLength = 0; AnsiString strName = m_editSongName->Text.Trim(); strcpy( g_infoSong.strSongName, strName.c_str() ); strName = m_editSinger->Text.Trim(); strcpy( g_infoSong.strSinger, strName.c_str() ); strName = m_editOriginal->Text.Trim(); strcpy( g_infoSong.strOriginal, strName.c_str() ); strName = m_editArranger->Text.Trim(); strcpy( g_infoSong.strArranger, strName.c_str() ); strName = m_editLyricist->Text.Trim(); strcpy( g_infoSong.strLyricist, strName.c_str() ); strName = m_editComposer->Text.Trim(); strcpy( g_infoSong.strComposer, strName.c_str() ); strName = m_memoDescription->Text.Trim(); strcpy( g_infoSong.strDescription, strName.c_str() ); g_infoSong.iCreation = m_radioOriginal->Checked ? 1 : 3; g_infoSong.iSingerType = m_cbSex->ItemIndex + 1; g_infoSong.iSubmit = m_checkSubmit->Checked; g_infoSong.iTS = g_iMelodyTimeSignature; g_infoSong.iTempo = g_nMelodyTempo; memset( g_infoSong.iMusicStyle, -1, 4 ); int count = 0; for( int i=0; iChecked ){ g_infoSong.iMusicStyle[count++] = m_cbTypes[i]->Tag; } } m_strLyrices = m_memoLyrices->Text; SAFE_DELETE_ARRAY(g_infoSong.strLyric) if( m_strLyrices.Length() ) { nLength = strlen( wstr2str(m_strLyrices.c_str()).c_str() ); g_infoSong.strLyric = new char[nLength+1]; strcpy(g_infoSong.strLyric, wstr2str(m_strLyrices.c_str()).c_str()); g_infoSong.strLyric[nLength] = '\0'; } SAFE_DELETE_ARRAY(g_infoSong.strIconName) if( m_strCopperPath.Length() || m_strMusicCoverPath.Length() ) { if( m_strCopperPath.Length() ) { nLength = strlen( wstr2str(m_strCopperPath.c_str()).c_str() ); }else if( m_strMusicCoverPath.Length() ) { nLength = strlen( wstr2str(m_strMusicCoverPath.c_str()).c_str() ); } g_infoSong.strIconName = new char[nLength+1]; if( m_strCopperPath.Length() ) { strcpy(g_infoSong.strIconName, wstr2str(m_strCopperPath.c_str()).c_str()); }else if( m_strMusicCoverPath.Length() ) { strcpy(g_infoSong.strIconName, wstr2str(m_strMusicCoverPath.c_str()).c_str()); } g_infoSong.strIconName[nLength] = '\0'; } SAFE_DELETE_ARRAY(g_infoSong.strCpjName) if( m_checkProject->Checked ) { String strCPJ = g_strUserPath.c_str(); strCPJ += L"temp\\"; if(!DirectoryExists(strCPJ, false)) ForceDirectories(strCPJ); strCPJ += m_editSongName->Text + L".cpj"; wstring wStrCpjName = strCPJ.c_str(); if( wStrCpjName.size() ) { nLength = strlen( wstr2str(wStrCpjName).c_str() ); g_infoSong.strCpjName = new char[nLength+1]; strcpy(g_infoSong.strCpjName, wstr2str(wStrCpjName).c_str()); } if( m_editCpjPrice->Text.Length()==0 ) { g_infoSong.cpjPrice = 0; }else g_infoSong.cpjPrice = StrToInt((m_editCpjPrice->Text)); g_infoSong.cpjVersion = g_dwProjectVersion; }else { g_infoSong.strCpjName = NULL; } } //--------------------------------------------------------------------------- void __fastcall TUploadForm::EditNameChange(TObject *Sender) { TEdit* pEdit = ((TEdit*)Sender); AnsiString strName = pEdit->Text.Trim(); string strTmp = GBToUTF8(strName.c_str()); if( strTmp.length()>pEdit->MaxLength ){ pEdit->OnChange = NULL; pEdit->Text = pEdit->Text.SubString( 0, pEdit->Text.Length()-1 ); pEdit->SelStart = pEdit->Text.Length(); pEdit->OnChange = EditNameChange; } if( pEdit==m_editSongName ){ m_btnOk->Enabled = !pEdit->Text.Trim().IsEmpty(); } } //--------------------------------------------------------------------------- void __fastcall TUploadForm::CheckBoxClick(TObject *Sender) { int iType = ((TCheckBox*)Sender)->Tag; bool bChecked = ((TCheckBox*)Sender)->Checked; if( bChecked ){ if( m_iCheckCount==4 ){ ((TCheckBox*)Sender)->Checked = false; } else{ for( int k=0; k<4; k++ ){ if( g_infoSong.iMusicStyle[k]==-1 || g_infoSong.iMusicStyle[k]==iType){ g_infoSong.iMusicStyle[k] = iType; m_iCheckCount++; break; } } } } else{ for( int k=0; k<4; k++ ){ if( g_infoSong.iMusicStyle[k]==iType ){ g_infoSong.iMusicStyle[k] = -1; m_iCheckCount--; break; } } if( m_iCheckCount==0 ){ m_checkOthers->Checked = true; } } } //--------------------------------------------------------------------------- void __fastcall TUploadForm::RadioBoxClick(TObject *Sender) { if( Sender==m_radioAmend ){ m_editOriginal->Enabled = true; } else{ m_editOriginal->Enabled = false; m_editOriginal->Text = L""; } } //--------------------------------------------------------------------------- void __fastcall TUploadForm::m_memoLyricesChange(TObject *Sender) { if( m_memoLyrices->Lines->Count>8 ) { m_memoLyrices->ScrollBars = ssVertical; }else{ m_memoLyrices->ScrollBars = ssNone; } } //--------------------------------------------------------------------------- void __fastcall TUploadForm::m_ImgCoverClick(TObject *Sender) { TPicture *pPic = new TPicture(); TPicture *pPicDraw = new TPicture(); TBitmap *pBmp = new TBitmap(); pBmp->SetSize(260, 260); if( m_strCopperPath.Length() ){ pPicDraw->LoadFromFile( m_strCopperPath ); pBmp->Canvas->StretchDraw(TRect(0, 0, 260, 260), pPicDraw->Graphic); }else if( m_strMusicCoverPath.Length() ) { pPicDraw->LoadFromFile( m_strMusicCoverPath ); pBmp->Canvas->StretchDraw(TRect(0, 0, 260, 260), pPicDraw->Graphic); }else{ pBmp->LoadFromResourceName(int(HInstance), L"music_cover_default"); } pPic->Bitmap = pBmp; SAFE_DELETE(pBmp) TImgCopperForm *pTImgCopperForm = new TImgCopperForm(this, TRect(0, 0, 260, 260), pPic); pTImgCopperForm->Width = 340; pTImgCopperForm->Height = 420; if( mrOk==pTImgCopperForm->ShowModal() ) { m_strCopperPath = g_strUserPath.c_str(); m_strCopperPath += MUSIC_COVER_DIR; m_strCopperPath += MUSIC_COVER_COPPER; CopyFile(pTImgCopperForm->m_strCopperPath.c_str(), m_strCopperPath.c_str(), false); SetMusicCover(m_strCopperPath); } SAFE_DELETE(pTImgCopperForm) SAFE_DELETE(pPic) SAFE_DELETE(pPicDraw) } //--------------------------------------------------------------------------- bool __fastcall TUploadForm::SetMusicCover(String &strCoverPath) { bool bSucess = false; if( FileExists( strCoverPath ) ) { TMemoryStream *memoryStream = new TMemoryStream(); memoryStream->Position = 0; memoryStream->LoadFromFile(strCoverPath); if( !GetPicType(strCoverPath, memoryStream, true) ){ SAFE_DELETE(memoryStream) }else { TPicture *pTPicture = new TPicture(); try{ pTPicture->LoadFromFile(strCoverPath); }catch(Exception &e){ SAFE_DELETE(pTPicture) SAFE_DELETE(memoryStream) } if( pTPicture ) { m_ImgCover->Picture = pTPicture; SAFE_DELETE(pTPicture) bSucess = true; } } SAFE_DELETE(memoryStream) } return bSucess; } //--------------------------------------------------------------------------- void __fastcall TUploadForm::onUM_MUSICCOVER(TMessage & Msg) { if( !m_strCopperPath.Length() ) { String strCoverPath = g_strUserPath.c_str(); strCoverPath += MUSIC_COVER_DIR; strCoverPath += MUSIC_COVER_FILE; if( SetMusicCover(strCoverPath) ) m_strMusicCoverPath = strCoverPath; SAFE_DELETE(g_pTThreadMusciCover) } } //--------------------------------------------------------------------------- void __fastcall TUploadForm::CpjPriceChange(TObject *Sender) { int nLength = m_editCpjPrice->Text.Length(); if( nLength==0 ) { return; } for( int i=1; i<=nLength; i++ ) { int index = i; if( !TryStrToInt(m_editCpjPrice->Text, index) ) { m_editCpjPrice->Text = L"0"; m_btnOk->Enabled = true; return; } } int nPrice = StrToInt((m_editCpjPrice->Text)); if( nPrice==0 || (nPrice>=100 && nPrice<=9999) ) m_btnOk->Enabled = true; else m_btnOk->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TUploadForm::ProjectClick(TObject *Sender) { if( m_checkProject->Checked ) { m_editCpjPrice->Enabled = true; m_editCpjPrice->Color = clWindow; // m_editCpjPrice->Visible = true; // m_lbPrice->Visible = true; // m_lbSpriceDes->Visible = true; }else { m_editCpjPrice->Enabled = false; m_editCpjPrice->Color = clInactiveCaption; // m_editCpjPrice->Visible = false; // m_lbPrice->Visible = false; // m_lbSpriceDes->Visible = false; } } //---------------------------------------------------------------------------