String WIFI::set(Topic &topic) { if (topic.itemIs(3, "scan")) { return scanWifi(); } else { return TOPIC_NO; } }
void QNetCtlTool::scanWifi(QString device) { if (device.isNull() && sender()) device = sender()->property("QNetCtlScanDevice").toString(); if (myScanningDevices.contains(device)) return; QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.remove("LC_ALL"); env.remove("LANG"); QProcess *proc = new QProcess(this); proc->setProcessEnvironment(env); bool isDown = false; proc->start(TOOL(ip) + " link show " + device, QIODevice::ReadOnly); proc->waitForFinished(); if (proc->exitStatus() == QProcess::NormalExit && !proc->exitCode()) isDown = !QString::fromLocal8Bit(proc->readAllStandardOutput()).section('>', 0, 0).contains("UP"); bool waitsForUp = myUplinkingDevices.contains(device); if (isDown) { if (!waitsForUp) { waitsForUp = true; myUplinkingDevices << device; proc->start(TOOL(ip) + " link set " + device + " up", QIODevice::ReadOnly); proc->waitForFinished(); } // we're waiting for the device to come up delete proc; QTimer *t = new QTimer(this); t->setProperty("QNetCtlScanDevice", device); t->setSingleShot(true); connect(t, SIGNAL(timeout()), this, SLOT(scanWifi())); connect(t, SIGNAL(timeout()), t, SLOT(deleteLater())); t->start(500); return; } myScanningDevices << device; proc->setProperty("QNetCtlTag", "scan_wifi"); proc->setProperty("QNetCtlInfo", device); // if we set it up, we've to set it back down through the chain slot connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), waitsForUp ? SLOT(chain()) : SLOT(reply())); connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), proc, SLOT(deleteLater())); proc->start(TOOL(iw) + " dev " + device + " scan"); }
void wifiscanssid::slotRescan() { pushSelect->setEnabled(FALSE); scanWifi(); }
void QNetCtlTool::request(const QString tag, const QString information) { QString cmd; bool chain = false; // debug(tag + information); if (tag == "switch_to_profile") { cmd = TOOL(netctl) + " switch-to " + information; } else if (tag == "stop_profile") { cmd = TOOL(netctl) + " stop " + information; } else if (tag == "scan_wifi") { scanWifi(information); return; } else if (tag == "enable_profile") { cmd = TOOL(netctl) + " enable " + information; } else if (tag == "enable_service") { if (information.startsWith("netctl-")) cmd = TOOL(systemctl) + " enable " + information; } else if (tag == "disable_profile") { cmd = TOOL(netctl) + " disable " + information; } else if (tag == "disable_service") { if (information.startsWith("netctl-")) cmd = TOOL(systemctl) + " disable " + information; } else if (tag == "remove_profile") { chain = true; cmd = TOOL(netctl) + " disable " + information; } else if (tag.startsWith("write_profile")) { QString name = tag.section(' ', 1); QFile file(gs_profilePath + name); if (file.open(QIODevice::WriteOnly|QIODevice::Text)) { file.write(information.toLocal8Bit()); file.close(); myClient->call(QDBus::NoBlock, "reply", tag, "SUCCESS"); } else { myClient->call(QDBus::NoBlock, "reply", tag, "ERROR"); } return; // no process to run } else if (tag == "reparse_config") { return; } else if (tag == "quit") { quit(); return; } if (cmd.isNull()) { myClient->call(QDBus::NoBlock, "reply", tag, "ERROR: unsupported command / request:" + information); return; } QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.remove("LC_ALL"); env.remove("LANG"); QProcess *proc = new QProcess(this); proc->setProcessEnvironment(env); proc->setProperty("QNetCtlTag", tag); if (chain) { proc->setProperty("QNetCtlInfo", information); connect (proc, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(chain())); } else { connect (proc, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(reply())); } connect (proc, SIGNAL(finished(int, QProcess::ExitStatus)), proc, SLOT(deleteLater())); // debug(cmd); proc->start(cmd, QIODevice::ReadOnly); }