/* * javascriptinterfacendgui.cpp * * Created on: Feb 21, 2012 * Author: joe */ #include "javascriptinterfacendgui.h" #include #include "qlog4cxx.h" using namespace log4cxx; using namespace log4cxx::helpers; LoggerPtr ndjsiLogger(Logger::getLogger("ndgui.jsi")); JavascriptInterfaceNDGUI::JavascriptInterfaceNDGUI(QWebFrame* parent, NetworkDiscovery* nd) : JavascriptInterface(parent){ _nd = nd; } JavascriptInterfaceNDGUI::~JavascriptInterfaceNDGUI() { } //------------------------------------------------------------------------------------ // SLOTS //------------------------------------------------------------------------------------ /** * @brief show abortBoot dialog * * @param msg * the message, displayed in the dialog. */ void JavascriptInterfaceNDGUI::abortBoot(const QString msg) { QString code = QString("abortBootDialog('\%1')").arg(msg); _targetFrame->evaluateJavaScript(code); } /** * @brief opens ths chooseInterfaceDialog * * @param msg * the interfaces as json formated string. will be displayed in a select box. */ void JavascriptInterfaceNDGUI::chooseInterfaceDialog(const QList ifNameList) { QString jsonArr = "["; for (int i = 0; i < ifNameList.size() - 1; i++) { jsonArr += "\"" + ifNameList.value(i) + "\","; } jsonArr += "\"" + ifNameList.last() + "\"]"; QString code = QString("chooseInterfaceDialog(\%1)").arg(jsonArr); _targetFrame->evaluateJavaScript(code); } /** * @brief updates the over all status * * @param status * the new status message */ void JavascriptInterfaceNDGUI::updateStatus(const QString &status) { if (status == "") return; QString code = QString("updateStatus('\%1')").arg(status); _targetFrame->evaluateJavaScript(code); } /** * @brief updates the progress bar for each interface. * * @param ifname * the name ot the interface to update * * @param percent * the progress in percent */ void JavascriptInterfaceNDGUI::updateIfProgressBar(const QString &ifName, const int& percent) { if (percent == 0) return; QString code = QString("updateIfProgressBar('\%1',\%2)").arg(ifName).arg(percent); _targetFrame->evaluateJavaScript(code); } /** * @brief update the status for each interface * * @param ifName * the name ot the interface to update * * @param status * the new status of the interface. */ void JavascriptInterfaceNDGUI::updateIfStatus(const QString &ifName, const QString &status) { if (ifName == "") return; QString code = QString("updateIfStatus('\%1','\%2')").arg(ifName).arg(status); _targetFrame->evaluateJavaScript(code); } void JavascriptInterfaceNDGUI::addInterface(const QString &ifName) { if (ifName == "") return; QString code = QString("addInterface('\%1')").arg(ifName); _targetFrame->evaluateJavaScript(code); } void JavascriptInterfaceNDGUI::continueBoot(const QString& ifName) { emit startFbgui(ifName); } /** * @brief just for debugging. */ void JavascriptInterfaceNDGUI::notifyCall(QString msg){ LOG4CXX_DEBUG(ndjsiLogger, "Javascript notified: " << msg); } //------------------------------------------------------------------------------------ // INVOKABLES //------------------------------------------------------------------------------------ /** * @brief read the log file. Log File will be presented inside of a dialog. */ QString JavascriptInterfaceNDGUI::readLogFile() { QString retval("Contents of log file:\n"); QFile logFile(logFilePath); if (logFile.exists()) { if (logFile.open(QIODevice::ReadOnly | QIODevice::Text)) { while (!logFile.atEnd()) { retval.append(logFile.readLine()); } } else { LOG4CXX_DEBUG(ndjsiLogger, "could not open log file"); retval = "could not open log file"; } } else { LOG4CXX_DEBUG(ndjsiLogger, "log file does not exist at: " << logFilePath); retval = " log file does not exist at: " + logFilePath; } return retval; } /** * @brief fills the drop down box of the manual interface configuration * dialog. */ QVariantList JavascriptInterfaceNDGUI::getManualConfInterfaces() { LOG4CXX_DEBUG(ndjsiLogger, "call getManualConfInterfaces"); QVariantList jsonArr; QString debugOut; foreach (QString s, _nd->getIfUpList()) { QVariant e(s); jsonArr << e; debugOut += s + "; "; } LOG4CXX_DEBUG(ndjsiLogger, "value of jsonArr:" << debugOut); return jsonArr; } /** * @brief return a json formated interface configuration * * @param ifName * the name of the interface */ QVariantMap JavascriptInterfaceNDGUI::getInterfaceConf(QString ifName) { InterfaceConfiguration* ifc = _nd->getInterfaceConfig(ifName); QVariantMap jsonObj; QList dns; if (ifc != NULL) { jsonObj.insert("ipaddr", ifc->getIpAddress()); jsonObj.insert("netmask", ifc->getNetmask()); jsonObj.insert("broadcast", ifc->getBroadcast()); jsonObj.insert("gateway", ifc->getGateway()); dns.clear(); dns = ifc->getDnsservers().trimmed().split(" "); jsonObj.insert("dns", dns.first()); } return jsonObj; } /** * @brief takes the entered manual configuration dates and delivers it * to the networkDiscovery for further actions. * * @param jsonArr * a jsonArr which contains the manual entered interface configuration */ int JavascriptInterfaceNDGUI::ip4_setManualConfiguration(QVariantMap jsonArr) { return _nd->ip4_setManualConfiguration(jsonArr); }