FrmIcsCameraF.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "FrmIcsCameraF.h"
  5. #include "AppGlobalF.h"
  6. //#include "UJSExec.hpp"
  7. //using namespace Ujsexec;
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma link "cxContainer"
  11. #pragma link "cxControls"
  12. #pragma link "cxEdit"
  13. #pragma link "cxGraphics"
  14. #pragma link "cxLabel"
  15. #pragma link "cxLookAndFeelPainters"
  16. #pragma link "cxLookAndFeels"
  17. #pragma link "dxSkinsCore"
  18. #pragma link "dxSkinBlack"
  19. #pragma link "dxSkinBlue"
  20. #pragma resource "*.dfm"
  21. TFrmIcsCamera *FrmIcsCamera = NULL;
  22. //---------------------------------------------------------------------------
  23. __fastcall TFrmIcsCamera::TFrmIcsCamera(TComponent* Owner, TXCctv *ACctv, bool AAutoPlay)
  24. : TForm(Owner)
  25. {
  26. ::CoInitialize(NULL);
  27. FPlay = false;
  28. FAutoPlay = AAutoPlay;
  29. FConHandle = 0;
  30. FInstalled = false;
  31. FCamUrl = "";
  32. FHtmlCompleted = false;
  33. fJSExec = NULL;
  34. #if 0
  35. TJSExec *pfJSExec = new TJSExec(WebBrowser1);
  36. fJSExec = (void*)pfJSExec;
  37. try
  38. {
  39. String sUrlName = ExtractFilePath(Application->ExeName) + "VMS\\icsview.html";
  40. WebBrowser1->Stop();
  41. WebBrowser1->Navigate(sUrlName.c_str());
  42. }
  43. catch(Exception &exception)
  44. {
  45. }
  46. #endif
  47. PnlCamera->ParentColor = false;
  48. PnlCamera->Color = clBlack;
  49. PnlCamera->Font->Color = clWhite;
  50. //WebBrowser1->Parent = PnlCamera;
  51. //WebBrowser1->Align = alClient;
  52. //WebBrowser1->Visible = false;
  53. BrowserShow(false);
  54. InitCamera(ACctv, FAutoPlay);
  55. }
  56. //---------------------------------------------------------------------------
  57. bool __fastcall TFrmIcsCamera::ExecScript(String AScript)
  58. {
  59. #if 0
  60. if (FHtmlCompleted == false) return false;
  61. try
  62. {
  63. if (fJSExec) ((TJSExec*)fJSExec)->RunJSFn(AScript);
  64. }
  65. catch(Exception &exception)
  66. {
  67. return false;
  68. }
  69. #endif
  70. return true;
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TFrmIcsCamera::MnuConnectClick(TObject *Sender)
  74. {
  75. FAutoPlay = true;
  76. Connect();
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TFrmIcsCamera::MnuDisconnectClick(TObject *Sender)
  80. {
  81. FAutoPlay = false;
  82. Disconnect();
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TFrmIcsCamera::MnuReleaseClick(TObject *Sender)
  86. {
  87. CameraRelease();
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TFrmIcsCamera::Connect()
  91. {
  92. Disconnect();
  93. if (FId.IsEmpty()) return;
  94. if (FViewAddress.IsEmpty()) return;
  95. PnlCamera->Caption = "연결중...";
  96. BrowserShow(true);
  97. //if (WebBrowser1) WebBrowser1->Visible = true;
  98. try
  99. {
  100. if (WebBrowser1)
  101. {
  102. OpenUrl(true);
  103. #if 0
  104. String sJs;
  105. String sId = FWebCamUser;
  106. String sPswd = FWebCamPswd;
  107. String sHost = FWebCamIp;
  108. sJs.printf(L"CamOpen('%s', '%s', '%s')", sId.c_str(), sPswd.c_str(), sHost.c_str());
  109. ExecScript(sJs);
  110. #endif
  111. }
  112. }
  113. catch(...)
  114. {
  115. }
  116. FConHandle = 1;
  117. FPlay = true;
  118. }
  119. //---------------------------------------------------------------------------
  120. void __fastcall TFrmIcsCamera::Disconnect()
  121. {
  122. if (!FPlay) return;
  123. try
  124. {
  125. if (FConHandle)
  126. {
  127. if (WebBrowser1)
  128. {
  129. OpenUrl(false);
  130. //ExecScript("CamClose()");
  131. }
  132. }
  133. FConHandle = 0;
  134. }
  135. catch(...)
  136. {
  137. }
  138. PnlCamera->Caption = "Disconnected";
  139. //if (WebBrowser1) WebBrowser1->Visible = false;
  140. FConHandle = 0;
  141. FPlay = false;
  142. }
  143. //---------------------------------------------------------------------------
  144. void __fastcall TFrmIcsCamera::CameraRelease()
  145. {
  146. Disconnect();
  147. PnlCamera->Caption = "";
  148. //if (WebBrowser1) WebBrowser1->Visible = false;
  149. }
  150. //---------------------------------------------------------------------------
  151. void __fastcall TFrmIcsCamera::InitCamera(TXCctv *ACctv, bool AAutoPlay/*=true*/)
  152. {
  153. FAutoPlay = AAutoPlay;
  154. PopupMenu = NULL;
  155. FCamUrl = "";
  156. if (!ACctv)
  157. {
  158. FId = "";
  159. FGroup = "";
  160. FName = "";
  161. FStreamingType = "";
  162. FViewAddress = "";
  163. FFullAddress = "";
  164. FWebCamIp = "";
  165. FWebCamUser = "";
  166. FWebCamPswd = "";
  167. PnlCamera->Caption = "-Empty-";
  168. DisplayName(" ");
  169. FInstalled = false;
  170. //WebBrowser1->Visible = false;
  171. BrowserShow(false);
  172. try
  173. {
  174. String sImageFile = ExtractFilePath(Application->ExeName) + "\\image\\vmscam.bmp";
  175. ImgNoData->Picture->LoadFromFile(sImageFile);
  176. ImgNoData->Align = alClient;
  177. ImgNoData->Visible = true;
  178. PnlName->Visible = false;
  179. }
  180. catch(Exception &e)
  181. {
  182. ImgNoData->Visible = false;
  183. }
  184. }
  185. else
  186. {
  187. FId = ACctv->Id;
  188. FGroup = ACctv->Group;
  189. FName = ACctv->Name;
  190. FStreamingType = ACctv->StreamingType;
  191. FViewAddress = ACctv->ViewAddress;
  192. FFullAddress = ACctv->FullAddress;
  193. FWebCamIp = ACctv->WebCamIp;
  194. FWebCamUser = ACctv->WebCamUser;
  195. FWebCamPswd = ACctv->WebCamPswd;
  196. PnlCamera->Caption = "Disconnected";
  197. DisplayName(FName);
  198. FInstalled = true;
  199. if (FWebCamIp.IsEmpty())
  200. {
  201. //WebBrowser1->Visible = false;
  202. BrowserShow(false);
  203. PnlCamera->Caption = "스트리밍주소 오류";
  204. }
  205. else
  206. {
  207. PopupMenu = PopupMenu1;
  208. FCamUrl = ExtractFilePath(Application->ExeName) + "VMS\\" + FId + ".html";
  209. }
  210. }
  211. }
  212. //---------------------------------------------------------------------------
  213. void __fastcall TFrmIcsCamera::DisplayName(String AName)
  214. {
  215. // PnlName->Visible = false;
  216. PnlName->Caption = " " + FName;
  217. PnlName->Visible = true;
  218. PnlName->Refresh();
  219. }
  220. //---------------------------------------------------------------------------
  221. void __fastcall TFrmIcsCamera::TmrPlayTimer(TObject *Sender)
  222. {
  223. TmrStop->Enabled = false;
  224. TmrPlay->Enabled = false;
  225. #if 0
  226. if (FHtmlCompleted == false)
  227. {
  228. TmrPlay->Enabled = true;
  229. return;
  230. }
  231. #endif
  232. Connect();
  233. }
  234. //---------------------------------------------------------------------------
  235. void __fastcall TFrmIcsCamera::TmrStopTimer(TObject *Sender)
  236. {
  237. TmrPlay->Enabled = false;
  238. TmrStop->Enabled = false;
  239. Disconnect();
  240. }
  241. //---------------------------------------------------------------------------
  242. void __fastcall TFrmIcsCamera::FormDestroy(TObject *Sender)
  243. {
  244. ::CoUninitialize();
  245. #if 0
  246. try
  247. {
  248. if (fJSExec)
  249. {
  250. ((TJSExec*)fJSExec)->Free();
  251. }
  252. }
  253. catch(Exception &e)
  254. {
  255. }
  256. #endif
  257. }
  258. //---------------------------------------------------------------------------
  259. void __fastcall TFrmIcsCamera::WebBrowser1BeforeNavigate2(TObject *ASender, const IDispatch *pDisp,
  260. OleVariant &URL, OleVariant &Flags, OleVariant &TargetFrameName,
  261. OleVariant &PostData, OleVariant &Headers, WordBool &Cancel)
  262. {
  263. #if 0
  264. char szUrl[2048];
  265. char szMsg[256];
  266. char szTmp[256];
  267. String sMsgType, sUrl, sTargetFrameName, sPostData, sHeaders;
  268. sUrl = URL.operator UnicodeString();
  269. bool bCancel = false;
  270. if (sUrl.Pos("webcamready:") > 0)
  271. {
  272. FHtmlCompleted = true;
  273. bCancel = true;
  274. }
  275. else
  276. if (sUrl.Pos("webcamplayed:") > 0)
  277. {
  278. bCancel = true;
  279. }
  280. else
  281. if (sUrl.Pos("webcamstopped:") > 0)
  282. {
  283. bCancel = true;
  284. }
  285. Cancel = bCancel;
  286. #endif
  287. }
  288. //---------------------------------------------------------------------------
  289. void __fastcall TFrmIcsCamera::OpenUrl(bool AOpen)
  290. {
  291. bool bShow = AOpen;
  292. try
  293. {
  294. String sUrlName = "About:Blank";
  295. WebBrowser1->Stop();
  296. if (AOpen)
  297. {
  298. if (FCamUrl != "")
  299. {
  300. sUrlName = FCamUrl;
  301. }
  302. else bShow = false;
  303. }
  304. WebBrowser1->Navigate(sUrlName.c_str());
  305. if (bShow)
  306. {
  307. //if (WebBrowser1->Visible == false) WebBrowser1->Visible = true;
  308. BrowserShow(true);
  309. }
  310. else
  311. {
  312. //if (WebBrowser1->Visible == true) WebBrowser1->Visible = false;
  313. BrowserShow(false);
  314. }
  315. }
  316. catch(Exception &exception)
  317. {
  318. }
  319. }
  320. //---------------------------------------------------------------------------
  321. void __fastcall TFrmIcsCamera::BrowserShow(bool AShow)
  322. {
  323. #if 0
  324. if (AShow)
  325. {
  326. WebBrowser1->Align = alClient;
  327. WebBrowser1->Tag = 1;
  328. }
  329. else
  330. {
  331. WebBrowser1->Align = alNone;
  332. WebBrowser1->Left = -WebBrowser1->Width - 1;
  333. WebBrowser1->Top = -WebBrowser1->Height - 1;
  334. //WebBrowser1->OnDocumentComplete = WebBrowser1DocumentComplete;
  335. WebBrowser1->Tag = 0;
  336. }
  337. #endif
  338. }
  339. //---------------------------------------------------------------------------