void tst_QUdpSocket::outOfProcessUnconnectedClientServerTest() { #if defined(Q_OS_WINCE) QSKIP("This test depends on reading data from QProcess (not supported on Qt/WinCE.", SkipAll); #endif #if defined(QT_NO_PROCESS) QSKIP("Qt was compiled with QT_NO_PROCESS", SkipAll); #else QProcess serverProcess; serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"), QIODevice::ReadWrite | QIODevice::Text); // Wait until the server has started and reports success. while (!serverProcess.canReadLine()) QVERIFY(serverProcess.waitForReadyRead(3000)); QByteArray serverGreeting = serverProcess.readLine(); QVERIFY(serverGreeting != QByteArray("XXX\n")); int serverPort = serverGreeting.trimmed().toInt(); QVERIFY(serverPort > 0 && serverPort < 65536); QProcess clientProcess; clientProcess.start(QString::fromLatin1("clientserver/clientserver unconnectedclient %1 %2") .arg(QLatin1String("127.0.0.1")).arg(serverPort), QIODevice::ReadWrite | QIODevice::Text); // Wait until the server has started and reports success. while (!clientProcess.canReadLine()) QVERIFY(clientProcess.waitForReadyRead(3000)); QByteArray clientGreeting = clientProcess.readLine(); QCOMPARE(clientGreeting, QByteArray("ok\n")); // Let the client and server talk for 3 seconds QTest::qWait(3000); QStringList serverData = QString::fromLocal8Bit(serverProcess.readAll()).split("\n"); QStringList clientData = QString::fromLocal8Bit(clientProcess.readAll()).split("\n"); QVERIFY(serverData.size() > 5); QVERIFY(clientData.size() > 5); for (int i = 0; i < clientData.size() / 2; ++i) { QCOMPARE(clientData.at(i * 2), QString("readData()")); QCOMPARE(serverData.at(i * 3), QString("readData()")); QString cdata = clientData.at(i * 2 + 1); QString sdata = serverData.at(i * 3 + 1); QVERIFY(cdata.startsWith(QLatin1String("got "))); QCOMPARE(cdata.mid(4).trimmed().toInt(), sdata.mid(4).trimmed().toInt() * 2); QVERIFY(serverData.at(i * 3 + 2).startsWith(QLatin1String("sending "))); QCOMPARE(serverData.at(i * 3 + 2).trimmed().mid(8).toInt(), sdata.mid(4).trimmed().toInt() * 2); } clientProcess.kill(); QVERIFY(clientProcess.waitForFinished()); serverProcess.kill(); QVERIFY(serverProcess.waitForFinished()); #endif }
void PFManagerDlg::refreshStatus(void) { //First check if the firewall is running firewallRunning = false; QProcess proc; proc.start("sysctl net.inet.ip.fw.enable"); if(proc.waitForFinished() || proc.canReadLine()){ if (proc.canReadLine()){ QString line = proc.readLine(); if(line.section(":",1,1).simplified().toInt() ==1) { firewallRunning = true; } } } //Enable/disable the UI elements if (firewallRunning) { pbStart->setEnabled(false); pbStop->setEnabled(true); pbRestart->setEnabled(true); } else { pbStart->setEnabled(true); pbStop->setEnabled(false); pbRestart->setEnabled(false); } UpdatePortButtons(); }
QStringList CJoystick::available() { QStringList ret; QProcess process; process.start( "bash -c \"ls /dev/input/js*\"" /*, args*/ ); process.waitForFinished(10000); while( process.canReadLine() ) { QString line = process.readLine(); line.remove( "\n" ); line.remove( "\r" ); ret.append( line ); } #if 0 QDir dir( "/dev/input/by-id" ); dir.setFilter( QDir::NoFilter ); qDebug( "dirName == %s", dir.path().toAscii().constData() ); QStringList list; list.append( "*-joystick" ); ret = dir.entryList( list ); #endif /*foreach( QString str, ret ) { qDebug( "%s", str.toStdString().c_str() ); }*/ return ret; }
void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatus exitStatus) { QProcess *p = static_cast<QProcess*>(sender()); p->deleteLater(); if (exitCode != 0 || exitStatus != QProcess::NormalExit) { qCWarning(dcWifiDetector) << "error performing network scan:" << p->readAllStandardError(); return; } QList<Device*> watchedDevices = deviceManager()->findConfiguredDevices(supportedDevices().first().id()); if (watchedDevices.isEmpty()) { return; } QStringList foundDevices; while(p->canReadLine()) { QString result = QString::fromLatin1(p->readLine()); if (result.startsWith("MAC Address:")) { QStringList lineParts = result.split(' '); if (lineParts.count() > 3) { QString addr = lineParts.at(2); foundDevices << addr.toLower(); } } } foreach (Device *device, watchedDevices) { bool wasInRange = device->stateValue(inRangeStateTypeId).toBool(); bool wasFound = foundDevices.contains(device->paramValue("mac").toString().toLower()); if (wasInRange != wasFound) { device->setStateValue(inRangeStateTypeId, wasFound); } }
DeviceList DeviceInfo::xvAdaptors() { qDebug("DeviceInfo::xvAdaptors"); DeviceList l; QRegExp rx_device("^.*Adaptor #([0-9]+): \"(.*)\""); QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); p.setEnvironment(QProcess::systemEnvironment() << "LC_ALL=C"); p.start("xvinfo"); if (p.waitForFinished()) { QByteArray line; while (p.canReadLine()) { line = p.readLine(); qDebug("DeviceInfo::xvAdaptors: '%s'", line.constData()); if (rx_device.indexIn(line) > -1) { QString id = rx_device.cap(1); QString desc = rx_device.cap(2); qDebug("DeviceInfo::xvAdaptors: found adaptor: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData()); l.append(DeviceData(id, desc)); } } } else { qDebug("DeviceInfo::xvAdaptors: could not start xvinfo, error %d", p.error()); } return l; }
QString MainWindow::runCmd(QString cmd, QStringList argv, int start, int length){ QProcess proc; proc.start(cmd,argv); QString res = ""; proc.waitForFinished(); int i=0; while(proc.canReadLine()){ if(i>=start){ res = res + proc.readLine() + "\n"; }else{ proc.readLine(); } if(i>=start+length){ break; } i+=1; } proc.kill(); res = res.trimmed(); return res; }
DeviceList DeviceInfo::retrieveDevices(DeviceType type) { qDebug("DeviceInfo::retrieveDevices: %d", type); DeviceList l; QRegExp rx_device("^(\\d+): (.*)"); if (QFile::exists("dxlist.exe")) { QProcess p; p.setProcessChannelMode( QProcess::MergedChannels ); QStringList arg; if (type == Sound) arg << "-s"; else arg << "-d"; p.start("dxlist", arg); if (p.waitForFinished()) { QByteArray line; while (p.canReadLine()) { line = p.readLine().trimmed(); qDebug("DeviceInfo::retrieveDevices: '%s'", line.constData()); if ( rx_device.indexIn(line) > -1 ) { int id = rx_device.cap(1).toInt(); QString desc = rx_device.cap(2); qDebug("DeviceInfo::retrieveDevices: found device: '%d' '%s'", id, desc.toUtf8().constData()); l.append( DeviceData(id, desc) ); } } } } return l; }
bool QProcessProto::canReadLine() const { QProcess *item = qscriptvalue_cast<QProcess*>(thisObject()); if (item) return item->canReadLine(); return false; }
void dialogCheckHardware::getSound() { QString tmp, snd; // Figure out the driver QProcess d; d.start(QString("cat"), QStringList() << "/dev/sndstat"); while(d.state() == QProcess::Starting || d.state() == QProcess::Running) { d.waitForFinished(200); QCoreApplication::processEvents(); } while (d.canReadLine()) { tmp = d.readLine().simplified(); if ( tmp.indexOf("default") != -1 ) { snd = tmp.section(":", 0, 0); break; } } if ( snd.isEmpty() ) { labelSound->setText(tr("No sound detected")); labelSoundIcon->setPixmap(QPixmap(":/modules/images/failed.png")); labelSoundIcon->setScaledContents(true); } else { labelSound->setText(tr("Sound device:") + " (" + snd + ")" ); labelSoundIcon->setPixmap(QPixmap(":/modules/images/ok.png")); labelSoundIcon->setScaledContents(true); } }
DeviceList DeviceInfo::alsaDevices() { qDebug("DeviceInfo::alsaDevices"); DeviceList l; QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):"); QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); p.setEnvironment(QStringList() << "LC_ALL=C"); p.start("aplay", QStringList() << "-l"); if (p.waitForFinished()) { QByteArray line; while (p.canReadLine()) { line = p.readLine(); qDebug("DeviceInfo::alsaDevices: '%s'", line.constData()); if (rx_device.indexIn(line) > -1) { QString id = rx_device.cap(1); id.append("."); id.append(rx_device.cap(3)); QString desc = rx_device.cap(2); qDebug("DeviceInfo::alsaDevices: found device: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData()); l.append(DeviceData(id, desc)); } } } else { qDebug("DeviceInfo::alsaDevices: could not start aplay, error %d", p.error()); } return l; }
TDeviceList TDeviceInfo::alsaDevices() { Log4Qt::Logger* logger = Log4Qt::Logger::logger("Gui::TDeviceInfo"); logger->debug("alsaDevices"); TDeviceList l; QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):"); QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); p.setEnvironment(QStringList() << "LC_ALL=C"); p.start("aplay", QStringList() << "-l"); if (p.waitForFinished()) { QByteArray line; while (p.canReadLine()) { line = p.readLine().trimmed(); if (rx_device.indexIn(line) >= 0) { QString id = rx_device.cap(1); id.append("."); id.append(rx_device.cap(3)); QString desc = rx_device.cap(2); logger->debug("alsaDevices: found device: '%1' '%2'", id, desc); l.append(TDeviceData(id, desc)); } } } else { logger->warn("alsaDevices: could not start aplay, error %1", p.error()); } return l; }
TDeviceList TDeviceInfo::xvAdaptors() { Log4Qt::Logger* logger = Log4Qt::Logger::logger("Gui::TDeviceInfo"); logger->debug("xvAdaptors"); TDeviceList l; QRegExp rx_device("^Adaptor #([0-9]+): \"(.*)\""); QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); p.setEnvironment(QProcess::systemEnvironment() << "LC_ALL=C"); p.start("xvinfo"); if (p.waitForFinished()) { while (p.canReadLine()) { QString s = QString::fromLocal8Bit(p.readLine()).trimmed(); logger->trace("xvAdaptors: line '%1'", s); if (rx_device.indexIn(s) >= 0) { QString id = rx_device.cap(1); QString desc = rx_device.cap(2); logger->debug("xvAdaptors: found adaptor: '" + id + " '" + desc + "'"); l.append(TDeviceData(id, desc)); } } } else { logger->warn("xvAdaptors: could not start xvinfo, error %1", p.error()); } return l; }
void OscapScannerBase::watchStdErr(QProcess& process) { process.setReadChannel(QProcess::StandardError); QString stdErrOutput(""); // As readStdOut() is greedy and will continue reading for as long as there is output for it, // by the time we come to handle sdterr output there may be multiple warning and/or error messages. while (process.canReadLine()) { // Trailing \n is returned by QProcess::readLine stdErrOutput = process.readLine(); if (!stdErrOutput.isEmpty()) { if (stdErrOutput.contains("WARNING: ")) { QString guiMessage = guiFriendlyMessage(stdErrOutput); emit warningMessage(QObject::tr(guiMessage.toUtf8().constData())); } // Openscap >= 1.2.11 (60fb9f0c98eee) sends this message through stderr else if (stdErrOutput.contains(QRegExp("^Downloading: .+ \\.{3} \\w+\\n"))) { emit infoMessage(stdErrOutput); } else { emit errorMessage(QObject::tr("The 'oscap' process has written the following content to stderr:\n" "%1").arg(stdErrOutput)); } } } }
QString mainWin::getConflictDetailText() { QStringList ConList = ConflictList.split(" "); QStringList tmpDeps; QString retText; for (int i = 0; i < ConList.size(); ++i) { QProcess p; tmpDeps.clear(); if ( wDir.isEmpty() ) p.start("pkg", QStringList() << "rquery" << "%rn-%rv" << ConList.at(i)); else p.start("chroot", QStringList() << wDir << "pkg" "rquery" << "%rn-%rv" << ConList.at(i) ); if(p.waitForFinished()) { while (p.canReadLine()) { tmpDeps << p.readLine().simplified(); } } retText+= ConList.at(i) + " " + tr("required by:") + "\n" + tmpDeps.join(" "); } return retText; }
/** * for now our data is just the MAC address of the default gateway */ NetworkLocation NetworkLocation::currentLocation() { QProcess ip; ip.start("/sbin/ip", QStringList() << "route"); if (!ip.waitForStarted()) return NetworkLocation(); if (!ip.waitForFinished()) return NetworkLocation(); QByteArray gwIp; while (ip.canReadLine()) { QByteArray line = ip.readLine(); if (line.startsWith("default")) { QList<QByteArray> parts = line.split(' '); gwIp = parts[2]; break; } } if (gwIp.isEmpty()) return NetworkLocation(); QProcess arp; arp.start("/sbin/arp", QStringList() << "-a"); if (!arp.waitForStarted()) return NetworkLocation(); if (!arp.waitForFinished()) return NetworkLocation(); QByteArray gwMAC; while (arp.canReadLine()) { QByteArray line = arp.readLine(); if (line.contains(gwIp)) { QList<QByteArray> parts = line.split(' '); gwMAC = parts[3]; break; } } if (gwMAC.isEmpty()) return NetworkLocation(); return NetworkLocation(gwMAC); }
void mainWin::checkMPKGUpdates() { QString line, tmp, name, pkgname, pkgover, pkgnver; QStringList up, listPkgs; bool haveUpdates = false; int totPkgs=0; buttonRescanPkgs->setEnabled(false); pushUpdatePkgs->setEnabled(false); listViewUpdatesPkgs->clear(); groupUpdatesPkgs->setTitle(tr("Checking for updates")); QProcess p; if ( wDir.isEmpty() ) p.start(QString("pc-updatemanager"), QStringList() << "pkgcheck"); else p.start(QString("chroot"), QStringList() << wDir << "pc-updatemanager" << "pkgcheck"); while(p.state() == QProcess::Starting || p.state() == QProcess::Running) QCoreApplication::processEvents(); while (p.canReadLine()) { line = p.readLine().simplified(); qDebug() << line; if ( line.indexOf("Upgrading") == 0 ) { tmp = line; pkgname = tmp.section(" ", 1, 1); pkgname.replace(":", ""); pkgover = tmp.section(" ", 2, 2); pkgnver = tmp.section(" ", 4, 4); QTreeWidgetItem *myItem = new QTreeWidgetItem(QStringList() << pkgname << pkgover << pkgnver); listViewUpdatesPkgs->addTopLevelItem(myItem); haveUpdates = true; totPkgs++; } // End of upgrading section if ( line.indexOf("Reinstalling") == 0 ) { tmp = line; pkgname = tmp.section(" ", 1, 1); pkgover = pkgname.section("-", -1); pkgname.truncate(pkgname.lastIndexOf("-")); pkgnver = tmp.section(" ", 2); QTreeWidgetItem *myItem = new QTreeWidgetItem(QStringList() << pkgname << pkgover << pkgnver); listViewUpdatesPkgs->addTopLevelItem(myItem); haveUpdates = true; totPkgs++; } } buttonRescanPkgs->setEnabled(true); pushUpdatePkgs->setEnabled(haveUpdates); if ( totPkgs > 0 ) { tabUpdates->setTabText(1, tr("Package Updates (%1)").arg(totPkgs)); groupUpdatesPkgs->setTitle(tr("Available updates")); } else { tabUpdates->setTabText(1, tr("Package Updates")); groupUpdatesPkgs->setTitle(tr("No available updates")); } }
void SyncProcess::readAllChannelsIntoDialog(QProcess& process, ProcessProgressDialog& dialog) { assert(process.processChannelMode() == QProcess::MergedChannels); process.setReadChannel(QProcess::StandardOutput); while (process.canReadLine()) { const QString line = process.readLine(); dialog.insertStdOutLine(line); } }
static int de_info(bool isCurrent, QVector<DesktopEnvironmentInfo>& retVal) { static const char* const DE_NAME = "DE name:"; static const char* const DE_ACTIVE = "Current DE:"; static const char* const DE_XDG = "XDG compatible:"; static const char* const DE_INSTALLED = "Installed:"; static const char* const DE_SUDO = "Sudo command:"; static const char* const DE_FILE_MANAGER = "File manager:"; static const char* const DE_TERMINAL = "Terminal:"; static const char* const DE_CONFIG_APP = "Configuration app:"; retVal.clear(); QStringList flags; if (!isCurrent) flags<<"-i"; QProcess* deinfo = new QProcess(); deinfo->setProcessChannelMode(QProcess::MergedChannels); deinfo->start(QString("/usr/local/bin/de-info"), flags); deinfo->waitForFinished(-1); DesktopEnvironmentInfo Entry; QString Str; while ( deinfo->canReadLine() ) { Str = deinfo->readLine().simplified(); if (Str.contains(DE_NAME)) { if (Entry.Name.length()) { retVal.push_back(Entry); Entry = DesktopEnvironmentInfo(); } Entry.Name = Str.replace(DE_NAME,"").trimmed(); continue; }//if found 'DE name' TRY_GET_VALUE_BOOL(DE_ACTIVE, isActive, "yes"); TRY_GET_VALUE_BOOL(DE_INSTALLED, isInstalled, "yes"); TRY_GET_VALUE_BOOL(DE_XDG, isXDG, "yes"); TRY_GET_VALUE_STR(DE_SUDO, SudoCommand); TRY_GET_VALUE_STR(DE_FILE_MANAGER, FileManager); TRY_GET_VALUE_STR(DE_TERMINAL, TerminalCommand); TRY_GET_VALUE_STR(DE_CONFIG_APP, ConfigurationApplication); //TODO: another fields }//while process output reading if (Entry.Name.length()) retVal.push_back(Entry); return retVal.size(); }
void Config::readMachineArch(){ //set the "is64bit" flag QString arch; QProcess p; p.start("uname -m"); if (p.waitForFinished()) { while (p.canReadLine()) { arch = p.readLine().simplified(); } } qDebug() << "architecture:" << arch; TFstruct[0] = ( arch == "amd64" ); }
bool PreloadCheck::test(const QString& symbol) { const QString fileName = findSharedObjectFile(symbol); if (fileName.isEmpty()) { setErrorString(QObject::tr("Cannot find file containing symbol: %1").arg(symbol)); return false; } if (!QFile(fileName).exists()) { setErrorString(QObject::tr("Invalid shared object: %1").arg(fileName)); return false; } QStringList args; args << "--relocs" << "--wide" << fileName; QProcess proc; proc.setProcessChannelMode(QProcess::MergedChannels); proc.start("readelf", args, QIODevice::ReadOnly); if (!proc.waitForFinished()) { // TODO: Find out if we want to error out if 'readelf' is missing // The question is: Do all (major) distributions ship binutils by default? setErrorString(QObject::tr("Failed to run 'readelf' (binutils) binary: %1").arg(QString(proc.errorString()))); return false; } if (proc.exitCode() != 0) { setErrorString(QObject::tr("Cannot read shared object: %1").arg(QString(proc.readAll()))); return false; } // Example line on x86_64: 00000049f3d8 054300000007 R_X86_64_JUMP_SLO 000000000016c930 qt_startup_hook + 0 // Example line on i386: 002e02f0 00034407 R_386_JUMP_SLOT 00181490 qt_startup_hook QRegExp rx("^(?:[^ ]+\\s+){4}([^ ]+)(?:.*)$"); while(proc.canReadLine()) { const QString line = proc.readLine().trimmed(); if (!rx.exactMatch(line)) continue; const QString currentSymbol = rx.cap(1); if (currentSymbol == symbol) { qDebug() << "Found relocatable symbol in" << fileName << ":" << symbol; setErrorString(QString()); return true; } } setErrorString(QObject::tr("Symbol is not marked as relocatable: %1").arg(symbol)); return false; }
void dialogCheckHardware::getVideo() { QString tmp, res, driver; QProcess d; d.start(QString("xdpyinfo"), QStringList()); while(d.state() == QProcess::Starting || d.state() == QProcess::Running) { d.waitForFinished(200); QCoreApplication::processEvents(); } while (d.canReadLine()) { tmp = d.readLine().simplified(); if ( tmp.indexOf("dimensions:") != -1 ) { res = tmp.section(" ", 1, 1); break; } } // Figure out the driver QFile file("/var/log/Xorg.0.log"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file); while (!in.atEnd()) { QString line = in.readLine(); if ( line.indexOf("Loading /usr/local/lib/xorg/modules/drivers/") != -1 ) { QFileInfo fi(line); driver = fi.fileName(); driver = driver.section("_", 0, 0); break; } } file.close(); } if ( driver != "vesa" ) { labelVideoDriverIcon->setPixmap(QPixmap(":/modules/images/ok.png")); } else { labelVideoDriverIcon->setPixmap(QPixmap(":/modules/images/failed.png")); } labelVideoDriverIcon->setScaledContents(true); labelVideoDriver->setText(tr("Video driver:") + " (" + driver + ")" ); labelVideoResolution->setText(tr("Video resolution:") + " (" + res + ")" ); labelVideoResolutionIcon->setPixmap(QPixmap(":/modules/images/ok.png")); labelVideoResolutionIcon->setScaledContents(true); }
void OscapScannerBase::watchStdErr(QProcess& process) { process.setReadChannel(QProcess::StandardError); QString errorMessage(""); while (process.canReadLine()) { // Trailing \n is returned by QProcess::readLine errorMessage += process.readLine(); } if (!errorMessage.isEmpty()) { emit warningMessage(QObject::tr("The 'oscap' process has written the following content to stderr:\n" "%1").arg(errorMessage)); } }
QStringList AndroidConfigurations::sdkTargets(int minApiLevel) const { QStringList targets; QProcess proc; proc.start(androidToolPath().toString(), QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs if (!proc.waitForFinished(-1)) { proc.terminate(); return targets; } while (proc.canReadLine()) { const QString line = QString::fromLocal8Bit(proc.readLine().trimmed()); int index = line.indexOf(QLatin1String("\"android-")); if (index == -1) continue; QString apiLevel = line.mid(index + 1, line.length() - index - 2); if (apiLevel.mid(apiLevel.lastIndexOf(QLatin1Char('-')) + 1).toInt() >= minApiLevel) targets.push_back(apiLevel); } return targets; }
Defines GccLikeCompiler::defines(const QString& arguments) const { if (!m_definesIncludes.value(arguments).definedMacros.isEmpty() ) { return m_definesIncludes.value(arguments).definedMacros; } // #define a 1 // #define a QRegExp defineExpression( "#define\\s+(\\S+)(?:\\s+(.*)\\s*)?"); QProcess proc; proc.setProcessChannelMode( QProcess::MergedChannels ); // TODO: what about -mXXX or -target= flags, some of these change search paths/defines auto compilerArguments = languageOptions(arguments); compilerArguments.append("-dM"); compilerArguments.append("-E"); compilerArguments.append(QProcess::nullDevice()); proc.start(path(), compilerArguments); if ( !proc.waitForStarted( 1000 ) || !proc.waitForFinished( 1000 ) ) { definesAndIncludesDebug() << "Unable to read standard macro definitions from "<< path(); return {}; } while ( proc.canReadLine() ) { auto line = proc.readLine(); if ( defineExpression.indexIn( line ) != -1 ) { m_definesIncludes[arguments].definedMacros[defineExpression.cap( 1 )] = defineExpression.cap( 2 ).trimmed(); } } return m_definesIncludes[arguments].definedMacros; }
void sndDialog::refreshDevices() { defaultUnit = -1 ; comboSound->clear(); // List the sound devices QString tmp, snd; QProcess d; d.start(QString("cat"), QStringList() << "/dev/sndstat"); while(d.state() == QProcess::Starting || d.state() == QProcess::Running) { d.waitForFinished(200); QCoreApplication::processEvents(); } int i = 0; while (d.canReadLine()) { tmp = d.readLine().simplified(); if ( tmp.indexOf("pcm") == 0 ) { comboSound->addItem(tmp); if ( tmp.indexOf("default") != -1 ) { defaultUnit=i; comboSound->setCurrentIndex(i); } i++; } } if ( defaultUnit == -1 ) { labelDesc->setText(tr("No sound devices detected!")); pushTest->setEnabled(false); pushApply->setEnabled(false); comboSound->setEnabled(false); } pushApply->setEnabled(false); }
void mainWin::checkFBSDUpdates() { QString line, toPatchVer, tmp; QStringList up, listDesc, listPkgs; if ( QFile::exists("/tmp/.fbsdup-reboot") ) { qDebug() << "Skipping update check - Waiting for reboot"; return; } if ( QFile::exists("/tmp/.fbsdup-lock") ) { qDebug() << "Skipping update check - freebsd-update is running elsewhere"; return; } // Now check if there are freebsd-updates to install QProcess f; if ( wDir.isEmpty() ) f.start(QString("pc-fbsdupdatecheck"), QStringList() << "update" ); else { QProcess::execute("cp /usr/local/bin/pc-fbsdupdatecheck " + wDir + "/tmp/.fbupdatechk"); QProcess::execute("chmod 755 " + wDir + "/tmp/.fbupdatechk"); f.start(QString("chroot"), QStringList() << wDir << "/tmp/.fbupdatechk" << "update" ); } while(f.state() == QProcess::Starting || f.state() == QProcess::Running) QCoreApplication::processEvents(); bool fUp = false; while (f.canReadLine()) { line = f.readLine().simplified(); qDebug() << line; if ( line.indexOf("The following files will be ") == 0) { toPatchVer= line.remove(0, line.lastIndexOf(" ")); toPatchVer=toPatchVer.section("-", 2,2); toPatchVer=toPatchVer.section(":", 0,0); toPatchVer=toPatchVer.section("p", 1,1); fUp = true; listPkgs << " " << tr("The following files will be updated:"); continue; } if ( fUp ) listPkgs << line; } if ( ! wDir.isEmpty() ) QProcess::execute("rm " + wDir + "/tmp/.fbupdatechk"); // Are there freebsd updates to install? if ( fUp ) { QString mySysVer; QString myPatchVer; // Lets try and fetch the desc file QProcess::execute("fetch -o /tmp/.fbsdupdesc http://fbsd-update.pcbsd.org/updates.desc"); // Get the current system ver QProcess p; p.start(QString("uname"), QStringList() << "-r"); while(p.state() == QProcess::Starting || p.state() == QProcess::Running) QCoreApplication::processEvents(); tmp = p.readLine().simplified(); mySysVer = tmp; myPatchVer = tmp; mySysVer = mySysVer.section("-", 0, 1); mySysVer = mySysVer.section("-", 0, 1); myPatchVer = myPatchVer.section("-", 2, 2); myPatchVer = myPatchVer.section(":", 0, 0); myPatchVer = myPatchVer.section("p", 1, 1); QFile file("/tmp/.fbsdupdesc"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { listDesc << tr("Update Details:"); while (!file.atEnd()) { line = file.readLine(); tmp = line; if ( tmp.section(":::", 0, 0) != mySysVer ) continue; if ( tmp.section(":::", 1, 1) <= myPatchVer ) continue; if ( tmp.section(":::", 1, 1) > toPatchVer ) continue; listDesc << tmp.section(":::", 2, 2); } } up.clear(); up << "FreeBSD Security Updates" << "FBSDUPDATE"; up.append(listDesc + listPkgs); listUpdates.append(up); } }
void mainWin::checkPCUpdates() { QString line, tmp, name, type, version, date, tag, url, size, sa, rr; QStringList up; QProcess p; p.start(QString("pc-updatemanager"), QStringList() << "check"); while(p.state() == QProcess::Starting || p.state() == QProcess::Running) QCoreApplication::processEvents(); while (p.canReadLine()) { line = p.readLine().simplified(); if ( line.indexOf("NAME: ") == 0) { name = line.replace("NAME: ", ""); continue; } if ( line.indexOf("TYPE: ") == 0) { type = line.replace("TYPE: ", ""); continue; } if ( type == "SYSUPDATE" ) { if ( line.indexOf("VERSION: ") == 0) { version = line.replace("VERSION: ", ""); continue; } if ( line.indexOf("DATE: ") == 0) { date = line.replace("DATE: ", ""); continue; } if ( line.indexOf("TAG: ") == 0) { tag = line.replace("TAG: ", ""); continue; } if ( line.indexOf("DETAILS: ") == 0) { url = line.replace("DETAILS: ", ""); continue; } if ( line.indexOf("To install:") == 0) { up.clear(); up << name << type << version << date << tag << url; listUpdates.append(up); type=""; name="", version="", date="", tag="", url=""; continue; } } if ( type == "PATCH" ) { if ( line.indexOf("DATE: ") == 0) { date = line.replace("DATE: ", ""); continue; } if ( line.indexOf("TAG: ") == 0) { tag = line.replace("TAG: ", ""); continue; } if ( line.indexOf("SIZE: ") == 0) { size = line.replace("SIZE: ", ""); continue; } if ( line.indexOf("STANDALONE: ") == 0) { sa = line.replace("STANDALONE: ", ""); continue; } if ( line.indexOf("REQUIRESREBOOT: ") == 0) { rr = line.replace("REQUIRESREBOOT: ", ""); continue; } if ( line.indexOf("DETAILS: ") == 0) { url = line.replace("DETAILS: ", ""); continue; } if ( line.indexOf("To install:") == 0) { // TODO add this update to list up.clear(); up << name << type << date << tag << size << sa << rr << url; listUpdates.append(up); type=""; name="", date="", tag="", size="", sa="", rr="", url=""; continue; } } } }
bool AnalyzeTask::analyzeAvisynthFile(const QString &filePath, AudioFileModel &info) { QProcess process; MUtils::init_process(process, QFileInfo(m_avs2wavBin).absolutePath()); process.start(m_avs2wavBin, QStringList() << QDir::toNativeSeparators(filePath) << "?"); if(!process.waitForStarted()) { qWarning("AVS2WAV process failed to create!"); qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData()); process.kill(); process.waitForFinished(-1); return false; } bool bInfoHeaderFound = false; while(process.state() != QProcess::NotRunning) { if(*m_abortFlag) { process.kill(); qWarning("Process was aborted on user request!"); break; } if(!process.waitForReadyRead()) { if(process.state() == QProcess::Running) { qWarning("AVS2WAV time out. Killing process and skipping file!"); process.kill(); process.waitForFinished(-1); return false; } } QByteArray data; while(process.canReadLine()) { QString line = QString::fromUtf8(process.readLine().constData()).simplified(); if(!line.isEmpty()) { int index = line.indexOf(':'); if(index > 0) { QString key = line.left(index).trimmed(); QString val = line.mid(index+1).trimmed(); if(bInfoHeaderFound && !key.isEmpty() && !val.isEmpty()) { if(key.compare("TotalSeconds", Qt::CaseInsensitive) == 0) { bool ok = false; unsigned int duration = val.toUInt(&ok); if(ok) info.techInfo().setDuration(duration); } if(key.compare("SamplesPerSec", Qt::CaseInsensitive) == 0) { bool ok = false; unsigned int samplerate = val.toUInt(&ok); if(ok) info.techInfo().setAudioSamplerate (samplerate); } if(key.compare("Channels", Qt::CaseInsensitive) == 0) { bool ok = false; unsigned int channels = val.toUInt(&ok); if(ok) info.techInfo().setAudioChannels(channels); } if(key.compare("BitsPerSample", Qt::CaseInsensitive) == 0) { bool ok = false; unsigned int bitdepth = val.toUInt(&ok); if(ok) info.techInfo().setAudioBitdepth(bitdepth); } } } else { if(line.contains("[Audio Info]", Qt::CaseInsensitive)) { info.techInfo().setAudioType("Avisynth"); info.techInfo().setContainerType("Avisynth"); bInfoHeaderFound = true; } } } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } //Check exit code switch(process.exitCode()) { case 0: qDebug("Avisynth script was analyzed successfully."); return true; break; case -5: qWarning("It appears that Avisynth is not installed on the system!"); return false; break; default: qWarning("Failed to open the Avisynth script, bad AVS file?"); return false; break; } }
// Function which checks for our GUI package schema data, and sets found if its located QList<QStringList> Backend::getPackageData(bool &found, QString pkgset) { if ( pkgset.isEmpty() ) pkgset="pcbsd"; QList<QStringList> metaPkgs; found=false; bool onDisk; onDisk=true; QString tmp, mName, mDesc, mIcon, mParent, mDesktop, mPkgFileList; QStringList package; QProcess pcmp; qDebug() << "Searching for meta-pkgs..."; pcmp.start(QString("/root/get-pkgset.sh"), QStringList()); if (pcmp.waitForFinished()) { while (pcmp.canReadLine()) { tmp = pcmp.readLine().simplified(); if ( tmp.indexOf("Meta Package: ") == 0) { mName = tmp.replace("Meta Package: ", ""); continue; } if ( tmp.indexOf("Description: ") == 0) { mDesc = tmp.replace("Description: ", ""); continue; } if ( tmp.indexOf("Icon: ") == 0) { mIcon = tmp.replace("Icon: ", ""); mPkgFileList = mIcon; mPkgFileList.replace("pkg-icon.png", "pkg-list"); continue; } if ( tmp.indexOf("Parent: ") == 0) { mParent = tmp.replace("Parent: ", ""); continue; } if ( tmp.indexOf("Desktop: ") == 0) { mDesktop = tmp.replace("Desktop: ", ""); continue; } if ( tmp.indexOf("Category Entry") == 0) { // Now add this category to the string list package.clear(); //qDebug() << "Found Category" << mName << mDesc << mIcon << mParent<< mDesktop << "CATEGORY"; package << mName << mDesc << mIcon << mParent << mDesktop << "CATEGORY"; metaPkgs.append(package); mName=""; mDesc=""; mIcon=""; mParent=""; mDesktop=""; mPkgFileList=""; } if ( tmp.indexOf("Required Packages:") == 0) { // Now add this meta-pkg to the string list package.clear(); //qDebug() << "Found Package" << mName << mDesc << mIcon << mParent << mDesktop << "NO" << mPkgFileList; package << mName << mDesc << mIcon << mParent << mDesktop << "NO" << mPkgFileList; metaPkgs.append(package); found = true; mName=""; mDesc=""; mIcon=""; mParent=""; mDesktop=""; mPkgFileList=""; } } } return metaPkgs; }
bool AnalyzeTask::analyzeAvisynthFile(const QString &filePath, AudioFileModel &info) { QProcess process; MUtils::init_process(process, QFileInfo(m_avs2wavBin).absolutePath()); process.start(m_avs2wavBin, QStringList() << QDir::toNativeSeparators(filePath) << "?"); if(!process.waitForStarted()) { qWarning("AVS2WAV process failed to create!"); qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData()); process.kill(); process.waitForFinished(-1); return false; } bool bInfoHeaderFound = false; while(process.state() != QProcess::NotRunning) { if(MUTILS_BOOLIFY(m_abortFlag)) { process.kill(); qWarning("Process was aborted on user request!"); break; } if(!process.waitForReadyRead()) { if(process.state() == QProcess::Running) { qWarning("AVS2WAV time out. Killing process and skipping file!"); process.kill(); process.waitForFinished(-1); return false; } } while(process.canReadLine()) { const QString line = QString::fromUtf8(process.readLine().constData()).simplified(); if(!line.isEmpty()) { if(bInfoHeaderFound) { const qint32 index = line.indexOf(':'); if (index > 0) { const QString key = line.left(index).trimmed(); const QString val = line.mid(index + 1).trimmed(); if (!(key.isEmpty() || val.isEmpty())) { switch (m_avisynthIdx.value(key.toLower(), MI_propertyId_t(-1))) { case propertyId_duration: SET_OPTIONAL(quint32, parseUnsigned(val, _tmp), info.techInfo().setDuration(_tmp)); break; case propertyId_samplingrate: SET_OPTIONAL(quint32, parseUnsigned(val, _tmp), info.techInfo().setAudioSamplerate(_tmp)); break; case propertyId_channel_s_: SET_OPTIONAL(quint32, parseUnsigned(val, _tmp), info.techInfo().setAudioChannels(_tmp)); break; case propertyId_bitdepth: SET_OPTIONAL(quint32, parseUnsigned(val, _tmp), info.techInfo().setAudioBitdepth(_tmp)); break; } } } } else { if(line.contains("[Audio Info]", Qt::CaseInsensitive)) { info.techInfo().setAudioType("Avisynth"); info.techInfo().setContainerType("Avisynth"); bInfoHeaderFound = true; } } } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } //Check exit code switch(process.exitCode()) { case 0: qDebug("Avisynth script was analyzed successfully."); return true; break; case -5: qWarning("It appears that Avisynth is not installed on the system!"); return false; break; default: qWarning("Failed to open the Avisynth script, bad AVS file?"); return false; break; } }