Ticket #5276: zoneminder_monitor_function_v1.patch

File zoneminder_monitor_function_v1.patch, 9.1 KB (added by jim@…, 16 years ago)

mythzoneminder monitor function patch

  • mythzmserver/zmserver.h

     
    147147    void handleDeleteEventList(vector<string> tokens);
    148148    void handleGetEventDates(vector<string> tokens);
    149149    void handleRunZMAudit(void);
     150    void handleSetMonitorFunction(vector<string> tokens);
    150151
    151152    bool                 m_debug;
    152153    int                  m_sock;
  • mythzmserver/zmserver.cpp

     
    5555#define ERROR_FILE_OPEN        "Cannot open event file"
    5656#define ERROR_INVALID_MONITOR  "Invalid Monitor"
    5757#define ERROR_INVALID_POINTERS "Cannot get shared memory pointers"
     58#define ERROR_INVALID_MONITOR_FUNCTION  "Invalid Monitor Function"
    5859
    5960MYSQL   g_dbConn;
    6061string  g_zmversion = "";
     
    303304        handleDeleteEventList(tokens);
    304305    else if (tokens[0] == "RUN_ZMAUDIT")
    305306        handleRunZMAudit();
     307     else if (tokens[0] == "SET_MONITOR_FUNCTION")
     308        handleSetMonitorFunction(tokens);
    306309    else
    307310        send("UNKNOWN_COMMAND");
    308311}
     
    14021405
    14031406    return result;
    14041407}
     1408
     1409void 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

     
    177177        {
    178178            handled = false;
    179179        }
     180        else if (action == "SELECT")
     181        {
     182            VERBOSE(VB_GENERAL, "SELECT pressed on frontend");
     183            showMenu();
     184        }
    180185        else
    181186            handled = false;
    182187    }
     
    185190        MythThemedDialog::keyPressEvent(e);
    186191}
    187192
     193void ZMConsole::showMenu()
     194{
     195    menu = new MythPopupBox(GetMythMainWindow(),"popupMenu");
     196
     197   /* QButton *temp = menu->addButton(tr("Monitor"), this,
     198                                        SLOT(setMonitorFunction("Monitor")));
     199    menu->addButton(tr("Modect"), this,
     200                                    SLOT(setMonitorFunction("Modect")));
     201    menu->addButton(tr("Record"), this,
     202                                    SLOT(setMonitorFunction("Record")));
     203    menu->addButton(tr("Mocord"), this,
     204                                    SLOT(setMonitorFunction("Mocord")));
     205    menu->addButton(tr("Nocord"), this,
     206                                    SLOT(setMonitorFunction("Nocord")));
     207    menu->addButton(tr("None"), this,
     208                                    SLOT(setMonitorFunction("None")));*/
     209
     210    QButton *temp = menu->addButton(tr("Monitor"), this,
     211                                        SLOT(setFunctionMonitor()));
     212    menu->addButton(tr("Modect"), this,
     213                                    SLOT(setFunctionModect()));
     214    menu->addButton(tr("Record"), this,
     215                                    SLOT(setFunctionRecord()));
     216    menu->addButton(tr("Mocord"), this,
     217                                    SLOT(setFunctionMocord()));
     218    menu->addButton(tr("Nodect"), this,
     219                                    SLOT(setFunctionNodect()));
     220    menu->addButton(tr("None"), this,
     221                                    SLOT(setFunctionNone()));
     222
     223    menu->addButton(tr("Cancel"), this, SLOT(cancelMenu()));
     224    temp->setFocus();
     225
     226    menu->ShowPopup(this, SLOT(cancelMenu()));
     227}
     228
     229void ZMConsole::cancelMenu()
     230{
     231    if (menu)
     232    {
     233        menu->deleteLater();
     234        menu=NULL;
     235    }
     236}
     237
     238void ZMConsole::setFunctionMonitor()
     239{
     240    cancelMenu();
     241    setMonitorFunction(FUNCTION_MONITOR);
     242}
     243
     244void ZMConsole::setFunctionModect()
     245{
     246    cancelMenu();
     247    setMonitorFunction(FUNCTION_MODECT);
     248}
     249
     250void ZMConsole::setFunctionNodect()
     251{
     252    cancelMenu();
     253    setMonitorFunction(FUNCTION_NODECT);
     254}
     255
     256void ZMConsole::setFunctionRecord()
     257{
     258    cancelMenu();
     259    setMonitorFunction(FUNCTION_RECORD);
     260}
     261
     262void ZMConsole::setFunctionMocord()
     263{
     264    cancelMenu();
     265    setMonitorFunction(FUNCTION_MOCORD);
     266}
     267
     268void ZMConsole::setFunctionNone()
     269{
     270    cancelMenu();
     271    setMonitorFunction(FUNCTION_NONE);
     272}
     273
    188274UITextType* ZMConsole::getTextType(QString name)
    189275{
    190276    UITextType* type = getUITextType(name);
     
    284370        updateMonitorList();
    285371    }
    286372}
     373
     374void ZMConsole::setMonitorFunction(const QString &function)
     375{
     376    if (class ZMClient *zm = ZMClient::get())
     377    {
     378        zm->getMonitorList(m_monitorList);
     379
     380        Monitor *currentMonitor = NULL;
     381
     382        if (m_currentMonitor < (int) m_monitorList->size())
     383            currentMonitor = m_monitorList->at(m_currentMonitor);
     384
     385        if (currentMonitor == NULL)
     386        {
     387            VERBOSE(VB_IMPORTANT, "Monitor not found error");
     388            return;
     389        }
     390
     391        zm->setMonitorFunction(currentMonitor->id, function);
     392        updateStatus();
     393    }
     394}
     395
  • mythzoneminder/zmconsole.h

     
    4040    void getDaemonStatus();
    4141    void getMonitorStatus(void);
    4242
     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
    4353  private:
    4454    void wireUpTheme(void);
    4555    UITextType* getTextType(QString name);
     
    4858    void monitorListDown(bool page);
    4959    void monitorListUp(bool page);
    5060
     61    void setMonitorFunction(const QString &function);
     62
    5163    int                m_currentMonitor;
    5264    int                m_monitorListSize;
    5365    vector<Monitor *> *m_monitorList;
    5466    UIListType        *m_monitor_list;
    5567
     68    MythPopupBox      *menu;
     69
    5670    UITextType        *m_status_text;
    5771    UITextType        *m_time_text;
    5872    UITextType        *m_date_text;
  • mythzoneminder/zmclient.cpp

     
    655655                .arg(item->name).arg(item->id).arg(item->palette));
    656656    }
    657657}
     658
     659void 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

     
    1919#include <qstring.h>
    2020#include <qrect.h>
    2121
     22const QString FUNCTION_MONITOR = "Monitor";
     23const QString FUNCTION_MODECT  = "Modect";
     24const QString FUNCTION_NODECT  = "Nodect";
     25const QString FUNCTION_RECORD  = "Record";
     26const QString FUNCTION_MOCORD  = "Mocord";
     27const QString FUNCTION_NONE    = "None";
     28
    2229// event details
    2330typedef struct
    2431{
  • mythzoneminder/zmclient.h

     
    6262    void getMonitorList(vector<Monitor*> *monitorList);
    6363    void getEventDates(const QString &monitorName, bool oldestFirst,
    6464                       QStringList &dateList);
     65    void setMonitorFunction(int monitorID, const QString &function);
    6566
    6667  private slots:
    6768    void restartConnection(void);  // Try to re-establish the connection to