Ticket #5276: zoneminder_monitor_function_v2.patch

File zoneminder_monitor_function_v2.patch, 8.3 KB (added by jim@…, 16 years ago)

mythzoneminder monitor function patch v2 - commented code slipped in in v1 patch. Now removed.

  • 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            showMenu();
     183        }
    180184        else
    181185            handled = false;
    182186    }
     
    185189        MythThemedDialog::keyPressEvent(e);
    186190}
    187191
     192void 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
     215void ZMConsole::cancelMenu()
     216{
     217    if (menu)
     218    {
     219        menu->deleteLater();
     220        menu=NULL;
     221    }
     222}
     223
     224void ZMConsole::setFunctionMonitor()
     225{
     226    cancelMenu();
     227    setMonitorFunction(FUNCTION_MONITOR);
     228}
     229
     230void ZMConsole::setFunctionModect()
     231{
     232    cancelMenu();
     233    setMonitorFunction(FUNCTION_MODECT);
     234}
     235
     236void ZMConsole::setFunctionNodect()
     237{
     238    cancelMenu();
     239    setMonitorFunction(FUNCTION_NODECT);
     240}
     241
     242void ZMConsole::setFunctionRecord()
     243{
     244    cancelMenu();
     245    setMonitorFunction(FUNCTION_RECORD);
     246}
     247
     248void ZMConsole::setFunctionMocord()
     249{
     250    cancelMenu();
     251    setMonitorFunction(FUNCTION_MOCORD);
     252}
     253
     254void ZMConsole::setFunctionNone()
     255{
     256    cancelMenu();
     257    setMonitorFunction(FUNCTION_NONE);
     258}
     259
    188260UITextType* ZMConsole::getTextType(QString name)
    189261{
    190262    UITextType* type = getUITextType(name);
     
    284356        updateMonitorList();
    285357    }
    286358}
     359
     360void 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

     
    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