Ticket #5276: zoneminder_monitor_function_v2.patch
File zoneminder_monitor_function_v2.patch, 8.3 KB (added by , 16 years ago) |
---|
-
mythzmserver/zmserver.h
147 147 void handleDeleteEventList(vector<string> tokens); 148 148 void handleGetEventDates(vector<string> tokens); 149 149 void handleRunZMAudit(void); 150 void handleSetMonitorFunction(vector<string> tokens); 150 151 151 152 bool m_debug; 152 153 int m_sock; -
mythzmserver/zmserver.cpp
55 55 #define ERROR_FILE_OPEN "Cannot open event file" 56 56 #define ERROR_INVALID_MONITOR "Invalid Monitor" 57 57 #define ERROR_INVALID_POINTERS "Cannot get shared memory pointers" 58 #define ERROR_INVALID_MONITOR_FUNCTION "Invalid Monitor Function" 58 59 59 60 MYSQL g_dbConn; 60 61 string g_zmversion = ""; … … 303 304 handleDeleteEventList(tokens); 304 305 else if (tokens[0] == "RUN_ZMAUDIT") 305 306 handleRunZMAudit(); 307 else if (tokens[0] == "SET_MONITOR_FUNCTION") 308 handleSetMonitorFunction(tokens); 306 309 else 307 310 send("UNKNOWN_COMMAND"); 308 311 } … … 1402 1405 1403 1406 return result; 1404 1407 } 1408 1409 void ZMServer::handleSetMonitorFunction(vector<string> tokens) 1410 { 1411 if (tokens.size() != 3) 1412 { 1413 sendError(ERROR_TOKEN_COUNT); 1414 return; 1415 } 1416 1417 string monitorID(tokens[1]); 1418 string function(tokens[2]); 1419 1420 if (m_debug) 1421 cout << "Updating monitor function. Monitor: " << monitorID << " to perform function: " << function << endl; 1422 1423 // Check validity of input passed to server. Does monitor exist && is function ok 1424 if (m_monitors.find(atoi(monitorID.c_str())) == m_monitors.end()) 1425 { 1426 sendError(ERROR_INVALID_MONITOR); 1427 return; 1428 } 1429 1430 if (function != "None" && function != "Monitor" && 1431 function != "Modect" && function != "Nodect" && 1432 function != "Record" && function != "Mocord") 1433 { 1434 sendError(ERROR_INVALID_MONITOR_FUNCTION); 1435 return; 1436 } 1437 1438 string sql("UPDATE Monitors "); 1439 sql += "SET Function = '" + function + "' "; 1440 sql += "WHERE Id = '" + monitorID + "'"; 1441 1442 if (mysql_query(&g_dbConn, sql.c_str())) 1443 { 1444 fprintf(stderr, "%s\n", mysql_error(&g_dbConn)); 1445 sendError(ERROR_MYSQL_QUERY); 1446 return; 1447 } 1448 1449 if (m_debug) 1450 cout << "Updating monitor function complete" << endl; 1451 1452 string outStr(""); 1453 ADD_STR(outStr, "OK") 1454 send(outStr); 1455 } 1456 -
mythzoneminder/zmconsole.cpp
177 177 { 178 178 handled = false; 179 179 } 180 else if (action == "SELECT") 181 { 182 showMenu(); 183 } 180 184 else 181 185 handled = false; 182 186 } … … 185 189 MythThemedDialog::keyPressEvent(e); 186 190 } 187 191 192 void ZMConsole::showMenu() 193 { 194 menu = new MythPopupBox(GetMythMainWindow(),"popupMenu"); 195 196 QButton *temp = menu->addButton(tr("Monitor"), this, 197 SLOT(setFunctionMonitor())); 198 menu->addButton(tr("Modect"), this, 199 SLOT(setFunctionModect())); 200 menu->addButton(tr("Record"), this, 201 SLOT(setFunctionRecord())); 202 menu->addButton(tr("Mocord"), this, 203 SLOT(setFunctionMocord())); 204 menu->addButton(tr("Nodect"), this, 205 SLOT(setFunctionNodect())); 206 menu->addButton(tr("None"), this, 207 SLOT(setFunctionNone())); 208 209 menu->addButton(tr("Cancel"), this, SLOT(cancelMenu())); 210 temp->setFocus(); 211 212 menu->ShowPopup(this, SLOT(cancelMenu())); 213 } 214 215 void ZMConsole::cancelMenu() 216 { 217 if (menu) 218 { 219 menu->deleteLater(); 220 menu=NULL; 221 } 222 } 223 224 void ZMConsole::setFunctionMonitor() 225 { 226 cancelMenu(); 227 setMonitorFunction(FUNCTION_MONITOR); 228 } 229 230 void ZMConsole::setFunctionModect() 231 { 232 cancelMenu(); 233 setMonitorFunction(FUNCTION_MODECT); 234 } 235 236 void ZMConsole::setFunctionNodect() 237 { 238 cancelMenu(); 239 setMonitorFunction(FUNCTION_NODECT); 240 } 241 242 void ZMConsole::setFunctionRecord() 243 { 244 cancelMenu(); 245 setMonitorFunction(FUNCTION_RECORD); 246 } 247 248 void ZMConsole::setFunctionMocord() 249 { 250 cancelMenu(); 251 setMonitorFunction(FUNCTION_MOCORD); 252 } 253 254 void ZMConsole::setFunctionNone() 255 { 256 cancelMenu(); 257 setMonitorFunction(FUNCTION_NONE); 258 } 259 188 260 UITextType* ZMConsole::getTextType(QString name) 189 261 { 190 262 UITextType* type = getUITextType(name); … … 284 356 updateMonitorList(); 285 357 } 286 358 } 359 360 void ZMConsole::setMonitorFunction(const QString &function) 361 { 362 if (class ZMClient *zm = ZMClient::get()) 363 { 364 zm->getMonitorList(m_monitorList); 365 366 Monitor *currentMonitor = NULL; 367 368 if (m_currentMonitor < (int) m_monitorList->size()) 369 currentMonitor = m_monitorList->at(m_currentMonitor); 370 371 if (currentMonitor == NULL) 372 { 373 VERBOSE(VB_IMPORTANT, "Monitor not found error"); 374 return; 375 } 376 377 zm->setMonitorFunction(currentMonitor->id, function); 378 updateStatus(); 379 } 380 } 381 -
mythzoneminder/zmconsole.h
40 40 void getDaemonStatus(); 41 41 void getMonitorStatus(void); 42 42 43 void setFunctionMonitor(); 44 void setFunctionModect(); 45 void setFunctionNodect(); 46 void setFunctionRecord(); 47 void setFunctionMocord(); 48 void setFunctionNone(); 49 50 void showMenu(); 51 void cancelMenu(); 52 43 53 private: 44 54 void wireUpTheme(void); 45 55 UITextType* getTextType(QString name); … … 48 58 void monitorListDown(bool page); 49 59 void monitorListUp(bool page); 50 60 61 void setMonitorFunction(const QString &function); 62 51 63 int m_currentMonitor; 52 64 int m_monitorListSize; 53 65 vector<Monitor *> *m_monitorList; 54 66 UIListType *m_monitor_list; 55 67 68 MythPopupBox *menu; 69 56 70 UITextType *m_status_text; 57 71 UITextType *m_time_text; 58 72 UITextType *m_date_text; -
mythzoneminder/zmclient.cpp
655 655 .arg(item->name).arg(item->id).arg(item->palette)); 656 656 } 657 657 } 658 659 void ZMClient::setMonitorFunction(int monitorID, const QString &function) 660 { 661 QStringList strList("SET_MONITOR_FUNCTION"); 662 strList << QString::number(monitorID); 663 strList << function; 664 665 VERBOSE(VB_GENERAL, "ZMClient::setMonitorFunction : " + strList[0] + strList[1] + strList[2]); 666 667 if (!sendReceiveStringList(strList)) 668 return; 669 670 bool bOK; 671 strList[1].toInt(&bOK); 672 if (!bOK) 673 { 674 VERBOSE(VB_IMPORTANT, "ZMClient received bad int in setMonitorFunction()"); 675 return; 676 } 677 } 678 -
mythzoneminder/zmdefines.h
19 19 #include <qstring.h> 20 20 #include <qrect.h> 21 21 22 const QString FUNCTION_MONITOR = "Monitor"; 23 const QString FUNCTION_MODECT = "Modect"; 24 const QString FUNCTION_NODECT = "Nodect"; 25 const QString FUNCTION_RECORD = "Record"; 26 const QString FUNCTION_MOCORD = "Mocord"; 27 const QString FUNCTION_NONE = "None"; 28 22 29 // event details 23 30 typedef struct 24 31 { -
mythzoneminder/zmclient.h
62 62 void getMonitorList(vector<Monitor*> *monitorList); 63 63 void getEventDates(const QString &monitorName, bool oldestFirst, 64 64 QStringList &dateList); 65 void setMonitorFunction(int monitorID, const QString &function); 65 66 66 67 private slots: 67 68 void restartConnection(void); // Try to re-establish the connection to