//--------------------------------------------------------------------------- #include #pragma hdrstop #include "FrmIcsCameraF.h" #include "AppGlobalF.h" //#include "UJSExec.hpp" //using namespace Ujsexec; //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "cxContainer" #pragma link "cxControls" #pragma link "cxEdit" #pragma link "cxGraphics" #pragma link "cxLabel" #pragma link "cxLookAndFeelPainters" #pragma link "cxLookAndFeels" #pragma link "dxSkinsCore" #pragma link "dxSkinBlack" #pragma link "dxSkinBlue" #pragma resource "*.dfm" TFrmIcsCamera *FrmIcsCamera = NULL; //--------------------------------------------------------------------------- __fastcall TFrmIcsCamera::TFrmIcsCamera(TComponent* Owner, TXCctv *ACctv, bool AAutoPlay) : TForm(Owner) { ::CoInitialize(NULL); FPlay = false; FAutoPlay = AAutoPlay; FConHandle = 0; FInstalled = false; FCamUrl = ""; FHtmlCompleted = false; fJSExec = NULL; #if 0 TJSExec *pfJSExec = new TJSExec(WebBrowser1); fJSExec = (void*)pfJSExec; try { String sUrlName = ExtractFilePath(Application->ExeName) + "VMS\\icsview.html"; WebBrowser1->Stop(); WebBrowser1->Navigate(sUrlName.c_str()); } catch(Exception &exception) { } #endif PnlCamera->ParentColor = false; PnlCamera->Color = clBlack; PnlCamera->Font->Color = clWhite; //WebBrowser1->Parent = PnlCamera; //WebBrowser1->Align = alClient; //WebBrowser1->Visible = false; BrowserShow(false); InitCamera(ACctv, FAutoPlay); } //--------------------------------------------------------------------------- bool __fastcall TFrmIcsCamera::ExecScript(String AScript) { #if 0 if (FHtmlCompleted == false) return false; try { if (fJSExec) ((TJSExec*)fJSExec)->RunJSFn(AScript); } catch(Exception &exception) { return false; } #endif return true; } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::MnuConnectClick(TObject *Sender) { FAutoPlay = true; Connect(); } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::MnuDisconnectClick(TObject *Sender) { FAutoPlay = false; Disconnect(); } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::MnuReleaseClick(TObject *Sender) { CameraRelease(); } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::Connect() { Disconnect(); if (FId.IsEmpty()) return; if (FViewAddress.IsEmpty()) return; PnlCamera->Caption = "¿¬°áÁß..."; BrowserShow(true); //if (WebBrowser1) WebBrowser1->Visible = true; try { if (WebBrowser1) { OpenUrl(true); #if 0 String sJs; String sId = FWebCamUser; String sPswd = FWebCamPswd; String sHost = FWebCamIp; sJs.printf(L"CamOpen('%s', '%s', '%s')", sId.c_str(), sPswd.c_str(), sHost.c_str()); ExecScript(sJs); #endif } } catch(...) { } FConHandle = 1; FPlay = true; } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::Disconnect() { if (!FPlay) return; try { if (FConHandle) { if (WebBrowser1) { OpenUrl(false); //ExecScript("CamClose()"); } } FConHandle = 0; } catch(...) { } PnlCamera->Caption = "Disconnected"; //if (WebBrowser1) WebBrowser1->Visible = false; FConHandle = 0; FPlay = false; } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::CameraRelease() { Disconnect(); PnlCamera->Caption = ""; //if (WebBrowser1) WebBrowser1->Visible = false; } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::InitCamera(TXCctv *ACctv, bool AAutoPlay/*=true*/) { FAutoPlay = AAutoPlay; PopupMenu = NULL; FCamUrl = ""; if (!ACctv) { FId = ""; FGroup = ""; FName = ""; FStreamingType = ""; FViewAddress = ""; FFullAddress = ""; FWebCamIp = ""; FWebCamUser = ""; FWebCamPswd = ""; PnlCamera->Caption = "-Empty-"; DisplayName(" "); FInstalled = false; //WebBrowser1->Visible = false; BrowserShow(false); try { String sImageFile = ExtractFilePath(Application->ExeName) + "\\image\\vmscam.bmp"; ImgNoData->Picture->LoadFromFile(sImageFile); ImgNoData->Align = alClient; ImgNoData->Visible = true; PnlName->Visible = false; } catch(Exception &e) { ImgNoData->Visible = false; } } else { FId = ACctv->Id; FGroup = ACctv->Group; FName = ACctv->Name; FStreamingType = ACctv->StreamingType; FViewAddress = ACctv->ViewAddress; FFullAddress = ACctv->FullAddress; FWebCamIp = ACctv->WebCamIp; FWebCamUser = ACctv->WebCamUser; FWebCamPswd = ACctv->WebCamPswd; PnlCamera->Caption = "Disconnected"; DisplayName(FName); FInstalled = true; if (FWebCamIp.IsEmpty()) { //WebBrowser1->Visible = false; BrowserShow(false); PnlCamera->Caption = "½ºÆ®¸®¹ÖÁÖ¼Ò ¿À·ù"; } else { PopupMenu = PopupMenu1; FCamUrl = ExtractFilePath(Application->ExeName) + "VMS\\" + FId + ".html"; } } } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::DisplayName(String AName) { // PnlName->Visible = false; PnlName->Caption = " " + FName; PnlName->Visible = true; PnlName->Refresh(); } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::TmrPlayTimer(TObject *Sender) { TmrStop->Enabled = false; TmrPlay->Enabled = false; #if 0 if (FHtmlCompleted == false) { TmrPlay->Enabled = true; return; } #endif Connect(); } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::TmrStopTimer(TObject *Sender) { TmrPlay->Enabled = false; TmrStop->Enabled = false; Disconnect(); } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::FormDestroy(TObject *Sender) { ::CoUninitialize(); #if 0 try { if (fJSExec) { ((TJSExec*)fJSExec)->Free(); } } catch(Exception &e) { } #endif } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::WebBrowser1BeforeNavigate2(TObject *ASender, const IDispatch *pDisp, OleVariant &URL, OleVariant &Flags, OleVariant &TargetFrameName, OleVariant &PostData, OleVariant &Headers, WordBool &Cancel) { #if 0 char szUrl[2048]; char szMsg[256]; char szTmp[256]; String sMsgType, sUrl, sTargetFrameName, sPostData, sHeaders; sUrl = URL.operator UnicodeString(); bool bCancel = false; if (sUrl.Pos("webcamready:") > 0) { FHtmlCompleted = true; bCancel = true; } else if (sUrl.Pos("webcamplayed:") > 0) { bCancel = true; } else if (sUrl.Pos("webcamstopped:") > 0) { bCancel = true; } Cancel = bCancel; #endif } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::OpenUrl(bool AOpen) { bool bShow = AOpen; try { String sUrlName = "About:Blank"; WebBrowser1->Stop(); if (AOpen) { if (FCamUrl != "") { sUrlName = FCamUrl; } else bShow = false; } WebBrowser1->Navigate(sUrlName.c_str()); if (bShow) { //if (WebBrowser1->Visible == false) WebBrowser1->Visible = true; BrowserShow(true); } else { //if (WebBrowser1->Visible == true) WebBrowser1->Visible = false; BrowserShow(false); } } catch(Exception &exception) { } } //--------------------------------------------------------------------------- void __fastcall TFrmIcsCamera::BrowserShow(bool AShow) { #if 0 if (AShow) { WebBrowser1->Align = alClient; WebBrowser1->Tag = 1; } else { WebBrowser1->Align = alNone; WebBrowser1->Left = -WebBrowser1->Width - 1; WebBrowser1->Top = -WebBrowser1->Height - 1; //WebBrowser1->OnDocumentComplete = WebBrowser1DocumentComplete; WebBrowser1->Tag = 0; } #endif } //---------------------------------------------------------------------------