123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #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
- }
- //---------------------------------------------------------------------------
|