You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

318 lines
11 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "OnvifVideoSourceFinderDialog.h"
  2. #include "addSourceDialog.h"
  3. #include "../../data/onvif/include/onvifclient.hpp"
  4. OnvifSourceFinderDialog::OnvifSourceFinderDialog(guiAddSourceDialog *parent) : QDialog(parent){
  5. m_pOnvifObserver = onvifMediaObserver::getInstance();
  6. m_pParentDialog = parent;
  7. // m_pStreamSource = NULL;
  8. m_pHL = new QHBoxLayout();
  9. m_pHL->setSpacing(6);
  10. //m_pHL->setContentsMargins(11, 11, 11, 11);
  11. m_pVL1 = new QVBoxLayout();
  12. m_pVL1->setSpacing(6);
  13. m_pVL2 = new QVBoxLayout();
  14. m_pVL2->setSpacing(6);
  15. m_pTreeWidget = new QTreeWidget();
  16. m_pTreeWidget->headerItem()->setText(0, QString("Networks"));
  17. connect(m_pTreeWidget, &QTreeWidget::itemClicked, this, &OnvifSourceFinderDialog::treeItemClicked);
  18. connect(m_pTreeWidget, &QTreeWidget::itemDoubleClicked, this, &OnvifSourceFinderDialog::treeItemClicked);
  19. //QTreeWidget::itemDoubleClicked
  20. //QTreeWidget::itemClicked
  21. //OnvifSourceFinder::treeItemClicked
  22. m_pHL->addWidget(m_pTreeWidget);
  23. m_pTxtLogin = new QLineEdit();
  24. m_pTxtLogin->setClearButtonEnabled(true);
  25. m_pTxtLogin->setText("gagua");
  26. m_pTxtLogin->setPlaceholderText(QApplication::translate("OnvifSourceFinder", "login name", 0));
  27. m_pTxtPassword = new QLineEdit();
  28. m_pTxtPassword->setClearButtonEnabled(true);
  29. m_pTxtPassword->setText("4GetMyID");
  30. m_pTxtPassword->setPlaceholderText(QApplication::translate("OnvifSourceFinder", "password", 0));
  31. m_pButtonCmdConnect = new QPushButton();
  32. m_pButtonCmdConnect->setFixedSize(240, 40);
  33. m_pButtonCmdConnect->setText("Connect");
  34. QIcon icon1;
  35. icon1.addFile(QStringLiteral(":pictures/appbar.disconnect.png"), QSize(), QIcon::Normal, QIcon::Off);
  36. m_pButtonCmdConnect->setIcon(icon1);
  37. m_pButtonCmdConnect->setIconSize(QSize(32, 32));
  38. m_pButtonCmdConnect->setEnabled(false);
  39. //m_pButtonCmdConnect->setFlat(false);
  40. connect(m_pButtonCmdConnect, &QPushButton::clicked, this, &OnvifSourceFinderDialog::connectToSelectedSource);
  41. m_pButtonCmdSearch = new QPushButton();
  42. m_pButtonCmdSearch->setFixedSize(240,40);
  43. m_pButtonCmdSearch->setText("Search Networks");
  44. QIcon icon2;
  45. icon2.addFile(QStringLiteral(":pictures/appbar.alien.png"), QSize(), QIcon::Normal, QIcon::Off);
  46. m_pButtonCmdSearch->setIcon(icon2);
  47. m_pButtonCmdSearch->setIconSize(QSize(32, 32));
  48. //m_pButtonCmdSearch->setFlat(false);
  49. connect(m_pButtonCmdSearch, &QPushButton::clicked, this, &OnvifSourceFinderDialog::startDevicesDiscovery);
  50. //m_pStreamPreview = new VideoThumbWidget();
  51. //m_pStreamPreview->setError(true, "No Stream");
  52. //m_pStreamPreview->init();
  53. m_pProgressBar = new QProgressBar();
  54. m_pVL2->addWidget(m_pButtonCmdSearch, 0, Qt::AlignLeft | Qt::AlignTop);
  55. m_pVL2->addWidget(m_pTxtLogin, 0, Qt::AlignLeft | Qt::AlignTop);
  56. m_pVL2->addWidget(m_pTxtPassword, 0, Qt::AlignLeft | Qt::AlignTop);
  57. m_pVL2->addWidget(m_pButtonCmdConnect, 0, Qt::AlignLeft | Qt::AlignTop);
  58. // m_pVL2->addWidget(m_pStreamPreview, 0, Qt::AlignLeft | Qt::AlignTop);
  59. m_pHL->addItem(m_pVL2);
  60. m_pVL1->addItem(m_pHL);
  61. m_pProfileslist = new QListWidget(this);
  62. m_pVL1->addWidget(m_pProfileslist);
  63. connect(m_pProfileslist, &QListWidget::itemClicked, this, &OnvifSourceFinderDialog::listItemClicked);
  64. connect(m_pProfileslist, &QListWidget::itemDoubleClicked, this, &OnvifSourceFinderDialog::listItemDblClicked);
  65. m_pButtonCmdUseProfile = new QPushButton();
  66. //m_pButtonCmdUseProfile->setFixedSize(240, 40);
  67. m_pButtonCmdUseProfile->setText("Use This Profile");
  68. m_pButtonCmdUseProfile->setIcon(QIcon(":pictures/appbar.alien.png"));
  69. m_pButtonCmdUseProfile->setEnabled(false);
  70. connect(m_pButtonCmdUseProfile, &QPushButton::clicked, this, &OnvifSourceFinderDialog::useSelectedProfile);
  71. m_pVL1->addWidget(m_pButtonCmdUseProfile);
  72. m_pVSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
  73. m_pVL1->addItem(m_pVSpacer);
  74. m_pVL1->addWidget(m_pProgressBar);
  75. setLayout(m_pVL1);
  76. setFixedSize(600, 480);
  77. setWindowTitle("OnVIF Network Observer");
  78. m_pTimer = NULL;
  79. };
  80. OnvifSourceFinderDialog::~OnvifSourceFinderDialog(){
  81. };
  82. void OnvifSourceFinderDialog::connectToSelectedSource(){
  83. startAskDevice();
  84. };
  85. void OnvifSourceFinderDialog::startDevicesDiscovery(){
  86. int nifCount;
  87. localIpAddresses *mNetworks;
  88. nifCount = m_pOnvifObserver->getNetworkCounts();
  89. if( nifCount ){
  90. m_pButtonCmdSearch->setEnabled(false);
  91. m_pTreeWidget->clear();
  92. m_pProgressBar->setValue(0);
  93. if (m_pTimer == NULL){
  94. m_pTimer = new QTimer();
  95. if (m_pTimer != NULL){
  96. connect(m_pTimer, &QTimer::timeout, this, &OnvifSourceFinderDialog::updateProgress);
  97. m_pTimer->start(40);
  98. };
  99. }
  100. else m_pTimer->start(40);
  101. mNetworks = m_pOnvifObserver->getNetworks();
  102. for (localIpAddresses::iterator index = mNetworks->begin(); index < mNetworks->end(); index++){
  103. QTreeWidgetItem *tNode = new QTreeWidgetItem();
  104. tNode->setText(0, QString((*index)->broadcast));
  105. m_pTreeWidget->addTopLevelItem(tNode);
  106. };
  107. QTreeWidgetItem *tNode = new QTreeWidgetItem();
  108. tNode->setText(0, QString("239.255.255.250"));
  109. m_pTreeWidget->addTopLevelItem(tNode);
  110. m_pProgressBar->setEnabled(true);
  111. m_pOnvifObserver->startDiscovery();
  112. } else {
  113. QMessageBox *mBox = new QMessageBox(
  114. QMessageBox::Icon::Information,
  115. QString("Error"),
  116. QString("No Network Interfaces defined in the system"),
  117. QMessageBox::StandardButton::Ok
  118. );
  119. mBox->show();
  120. };
  121. };
  122. void OnvifSourceFinderDialog::startAskDevice(void){
  123. m_pProgressBar->setValue(0);
  124. //m_pDeviceNode = new onvifDeviceNode(m_pDevURL);
  125. std::string A, B, C;
  126. A = std::string(m_pDevURL);
  127. B = m_pTxtLogin->text().toStdString(); //std::string("gagua");
  128. C = m_pTxtPassword->text().toStdString(); //std::string("4GetMyID");
  129. m_pDeviceNode = new OnvifClientDevice( A, B, C );
  130. if (m_pDeviceNode != NULL){
  131. m_pProfileslist->clear();
  132. m_pDeviceNode->GetCapabilities();
  133. OnvifClientMedia media( *m_pDeviceNode );
  134. _trt__GetProfilesResponse profiles;
  135. media.GetProfiles(profiles);
  136. std::vector<tt__Profile * >::iterator index;
  137. _trt__GetSnapshotUriResponse SnapshotUriResponse;
  138. _trt__GetStreamUriResponse StreamUriResponse;
  139. tt__StreamSetup StreamSetup;
  140. for (index = profiles.Profiles.begin(); index < profiles.Profiles.end(); index++){
  141. QListWidgetItem *tNode;
  142. char koko[256];
  143. sprintf(koko, "%s [%s]",
  144. (*index)->Name.c_str(),
  145. (*index)->token.c_str()
  146. );
  147. tNode = new QListWidgetItem( m_pProfileslist );
  148. tNode->setText(QString(koko));
  149. media.GetSnapshotUri(SnapshotUriResponse, (*index)->token);
  150. media.GetStreamUri(StreamUriResponse, StreamSetup, (*index)->token);
  151. tNode->setData( Qt::DisplayRole, QVariant(QString(koko)));
  152. if( StreamUriResponse.MediaUri != NULL ) tNode->setData( Qt::StatusTipRole, QVariant(QString(StreamUriResponse.MediaUri->Uri.c_str())));
  153. if( SnapshotUriResponse.MediaUri != NULL ) tNode->setData( Qt::ToolTipRole, QVariant(QString(SnapshotUriResponse.MediaUri->Uri.c_str())));
  154. tNode->setIcon(QIcon(":pictures/appbar.film.live.png"));
  155. };
  156. /*
  157. vectorProfileOnvif *tVector;
  158. tVector = m_pDeviceNode->getProfilesVector();
  159. if (tVector != NULL){
  160. for (int index = 0; index < tVector->size(); index++){
  161. char koko[256];
  162. sprintf( koko, "%s [%dx%d] %d FPS %s@%d KBps",
  163. tVector->at(index)->pName,
  164. tVector->at(index)->nWidth,
  165. tVector->at(index)->nHeight,
  166. tVector->at(index)->nFramerate,
  167. tVector->at(index)->pNcode,
  168. tVector->at(index)->nBitrate
  169. );
  170. QListWidgetItem *tNode;
  171. tNode = new QListWidgetItem(m_pProfileslist);
  172. tNode->setText(QString(koko));
  173. tNode->setIcon(QIcon(":pictures/appbar.film.live.png"));
  174. //m_pProfileslist->addItem(tNode);
  175. };
  176. };
  177. */
  178. };
  179. };
  180. void OnvifSourceFinderDialog::startPrevewNetStream(void){
  181. char koko[256];
  182. //koko = m_pDeviceNode->getStreamURI(m_nSelectedProfile);
  183. std::string A;
  184. m_pDeviceNode->GetMediaUrl(A);
  185. sprintf(koko,"s%", A.c_str());
  186. if (koko != NULL){
  187. /* if (m_pStreamSource != NULL)delete(m_pStreamSource);
  188. m_pStreamSource = new videoAVLIBSource();
  189. if (m_pStreamSource->_open(koko)){
  190. m_pStreamSource->attachDestination(m_pStreamPreview);
  191. m_pStreamSource->setStreaming(true);
  192. m_pStreamPreview->setError(false);
  193. }else{
  194. m_pStreamPreview->setError(true, "Error Opening Stream");
  195. };
  196. */
  197. };
  198. };
  199. void OnvifSourceFinderDialog::updateProgress(){
  200. int cStat;
  201. cStat = m_pOnvifObserver->getStatus();
  202. m_pProgressBar->setValue(cStat);
  203. if (cStat > 57){
  204. m_pTimer->stop();
  205. m_pProgressBar->setValue(100);
  206. m_pButtonCmdSearch->setEnabled(true);
  207. vectorWoWoResults *nResults;
  208. nResults = m_pOnvifObserver->getResults();
  209. if (nResults->size()){
  210. resultWoWo *tRecord;
  211. for (vectorWoWoResults::iterator index = nResults->begin(); index < nResults->end(); index++){
  212. tRecord = (*index);
  213. QTreeWidgetItem *tNode = new QTreeWidgetItem();
  214. tNode->setText(0, QString(tRecord->Type));
  215. QTreeWidgetItem *bNode = new QTreeWidgetItem();
  216. bNode->setText(0, QString(tRecord->XAddrs));
  217. QTreeWidgetItem *rNode = m_pTreeWidget->topLevelItem(tRecord->wowoID);
  218. tNode->addChild(bNode);
  219. rNode->addChild(tNode);
  220. };
  221. };
  222. };
  223. };
  224. void OnvifSourceFinderDialog::treeItemClicked(QTreeWidgetItem *item, int column){
  225. if ( NULL != item->parent() && 0 == item->childCount()){
  226. char fullBuffer[1024];
  227. sprintf(fullBuffer, "%s", item->text(column).toStdString().c_str());
  228. CArray *TArr;
  229. TArr = explode(' ', fullBuffer);
  230. sprintf(m_pDevURL, "%s", TArr->at(0));
  231. m_pButtonCmdConnect->setEnabled(true);
  232. } else {
  233. m_pButtonCmdConnect->setEnabled(false);
  234. };
  235. };
  236. void OnvifSourceFinderDialog::listItemClicked(QListWidgetItem *item){
  237. std::string S,L,P,K;
  238. S = item->data(Qt::StatusTipRole).toString().toStdString();
  239. K = item->data(Qt::ToolTipRole).toString().toStdString();
  240. L = m_pTxtLogin->text().toStdString();
  241. P = m_pTxtPassword->text().toStdString();
  242. int aPos = S.find_first_of("://");
  243. if (aPos > 0) {
  244. S.insert(aPos + 3, L);
  245. S.insert(aPos + 3 + L.length(), ":");
  246. S.insert(aPos + 4 + L.length(), P);
  247. S.insert(aPos + 4 + L.length() + P.length(), "@");
  248. }
  249. aPos = K.find_first_of("://");
  250. if (aPos > 0) {
  251. K.insert(aPos + 3, L);
  252. K.insert(aPos + 3 + L.length(), ":");
  253. K.insert(aPos + 4 + L.length(), P);
  254. K.insert(aPos + 4 + L.length() + P.length(), "@");
  255. };
  256. sprintf( m_pSelectedVideoMRL,"%s", S.c_str());
  257. sprintf( m_pSelectedPictureMRL,"%s", K.c_str());
  258. m_pButtonCmdUseProfile->setEnabled(true);
  259. };
  260. void OnvifSourceFinderDialog::listItemDblClicked(QListWidgetItem *item){
  261. std::string S, L, P, K;
  262. S = item->data(Qt::StatusTipRole).toString().toStdString();
  263. K = item->data(Qt::ToolTipRole).toString().toStdString();
  264. L = m_pTxtLogin->text().toStdString();
  265. P = m_pTxtPassword->text().toStdString();
  266. int aPos = S.find_first_of("://");
  267. if (aPos > 0) {
  268. S.insert(aPos + 3, L);
  269. S.insert(aPos + 3 + L.length(), ":");
  270. S.insert(aPos + 4 + L.length(), P);
  271. S.insert(aPos + 4 + L.length() + P.length(), "@");
  272. }
  273. aPos = K.find_first_of("://");
  274. if (aPos > 0) {
  275. K.insert(aPos + 3, L);
  276. K.insert(aPos + 3 + L.length(), ":");
  277. K.insert(aPos + 4 + L.length(), P);
  278. K.insert(aPos + 4 + L.length() + P.length(), "@");
  279. };
  280. sprintf(m_pSelectedVideoMRL, "%s", S.c_str());
  281. sprintf(m_pSelectedPictureMRL, "%s", K.c_str());
  282. m_pButtonCmdUseProfile->setEnabled(true);
  283. };
  284. void OnvifSourceFinderDialog::useSelectedProfile(void){
  285. m_pParentDialog->setNetworkSourcePath(
  286. m_pSelectedVideoMRL,
  287. m_pSelectedPictureMRL,
  288. "",
  289. m_pDevURL,
  290. (CSTR) m_pTxtLogin->text().toStdString().c_str(),
  291. (CSTR) m_pTxtPassword->text().toStdString().c_str()
  292. );
  293. hide();
  294. };