QString HttpDaemon::generateWebPage() { DeviceClass deviceClass = m_plugin->supportedDevices().first(); QString body = QString( "<html>" "<body>" "<h1>Mock device Controller</h1>\n" "<hr>" "<h2>Device Information</h2>" "Name: %1<br>" "ID: %2<br>" "DeviceClass ID: %3<br>").arg(m_device->paramValue("name").toString()).arg(m_device->id().toString()).arg(deviceClass.id().toString()); body.append("<hr>"); body.append("<h2>States</h2>"); body.append("<table>"); for (int i = 0; i < deviceClass.stateTypes().count(); ++i) { body.append("<tr>"); body.append("<form action=\"/setstate\" method=\"get\">"); const StateType &stateType = deviceClass.stateTypes().at(i); body.append("<td>" + stateType.name() + "</td>"); body.append(QString("<td><input type='input'' name='%1' value='%2'></td>").arg(stateType.id().toString()).arg(m_device->states().at(i).value().toString())); body.append("<td><input type=submit value='Set State'/></td>"); body.append("</form>"); body.append("</tr>"); } body.append("</table>"); body.append("<hr>"); body.append("<h2>Events</h2>"); body.append("<table>"); for (int i = 0; i < deviceClass.eventTypes().count(); ++i) { const EventType &eventType = deviceClass.eventTypes().at(i); body.append(QString( "<tr>" "<form action=\"/generateevent\" method=\"get\">" "<td>%1<input type='hidden' name='eventtypeid' value='%2'/></td>" "<td>").arg(eventType.name()).arg(eventType.id().toString())); if (!eventType.name().endsWith(" changed")) { body.append("<input type='submit' value='Generate'/>"); } body.append("</td>" "</form>" "</tr>" ); } body.append("</table>"); body.append("<hr>"); body.append("<h2>Actions</h2>"); body.append("<table border=2px>"); body.append("<tr><td>Name</td><td>Type ID</td><td>Timestamp</td></tr>"); for (int i = 0; i < m_actionList.count(); ++i) { ActionTypeId actionTypeId = ActionTypeId(m_actionList.at(i).first); QDateTime timestamp = m_actionList.at(i).second; QString actionName; foreach (const ActionType &at, deviceClass.actionTypes()) { if (at.id() == actionTypeId) { actionName = at.name(); break; } } body.append(QString( "<tr>" "<td>%1</td>" "<td>%2</td>" "<td>%3</td>" "</tr>" ).arg(actionName).arg(actionTypeId.toString()).arg(timestamp.toString())); } body.append("</table>"); body.append("</body></html>\n"); return generateHeader() + body; }
void HttpDaemon::actionExecuted(const ActionTypeId &actionTypeId) { qCDebug(dcMockDevice) << "Log actions executed" << actionTypeId.toString(); m_actionList.append(qMakePair<ActionTypeId, QDateTime>(actionTypeId, QDateTime::currentDateTime())); }