Example #1
0
void QNetCtlTool::chain()
{
    QProcess *proc = static_cast<QProcess*>(sender());
    const QString tag = proc->property("QNetCtlTag").toString();
    const QString info = proc->property("QNetCtlInfo").toString();
    if (proc->exitStatus() != QProcess::NormalExit || proc->exitCode()) {
        myClient->call(QDBus::NoBlock, "reply", tag, QString("ERROR: %1, %2").arg(proc->exitStatus()).arg(proc->exitCode()));
        return;
    }
    myClient->call(QDBus::NoBlock, "reply", tag, QString::fromLocal8Bit(proc->readAllStandardOutput()));

    QString cmd;
    if (tag == "remove_profile") {
        QFile::remove(gs_profilePath + info);
    } else if (tag == "scan_wifi") {
        myScanningDevices.removeAll(info);
        myUplinkingDevices.removeAll(info);
        cmd = TOOL(ip) + " link set " + info + " down";
    }

    if (cmd.isNull()) // should not happen
        return;

    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    env.remove("LC_ALL");
    env.remove("LANG");
    proc = new QProcess(this);
    proc->setProcessEnvironment(env);
//     proc->setProperty("QNetCtlTag", tag);
//     connect (proc, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(reply()));
    connect (proc, SIGNAL(finished(int, QProcess::ExitStatus)), proc, SLOT(deleteLater()));
    proc->start(cmd, QIODevice::ReadOnly);
}
Example #2
0
void QNetCtlTool::reply()
{
    QProcess *proc = static_cast<QProcess*>(sender());
    const QString tag = proc->property("QNetCtlTag").toString();
    if (proc->exitStatus() != QProcess::NormalExit || proc->exitCode()) {
        myClient->call(QDBus::NoBlock, "reply", tag, QString("ERROR: %1, %2").arg(proc->exitStatus()).arg(proc->exitCode()));
        return;
    }
    myClient->call(QDBus::NoBlock, "reply", tag, QString::fromLocal8Bit(proc->readAllStandardOutput()));
}
Example #3
0
void WPUserInfo::slotDetailsProcess(int i, QProcess::ExitStatus status)
{
	QProcess *ipProcess = dynamic_cast<QProcess *>(sender());
	QString ip;

	if ( ! ipProcess )
		return;

	if ( i == 0 && status != QProcess::CrashExit ) {
		QStringList output = QString::fromUtf8(ipProcess->readAll()).split('\n');
		if ( output.size() == 2 && ! output.contains("failed") )
			ip = output.at(1).split(' ').first();
		if ( QHostAddress(ip).isNull() )
			ip.clear();
	}

	QString host = ipProcess->property("host").toString();

	delete ipProcess;

	KConfigGroup group = KGlobal::config()->group("WinPopup");
	QString theSMBClientPath = group.readEntry("SMBClientPath", "/usr/bin/smbclient");

	if ( host == "LOCALHOST" ) //do not cycle
		noComment = false;

	detailsProcess = new QProcess(this);
	QStringList args;
	args << "-N" << "-g" << "-L" << host;

	if ( ! ip.isEmpty() )
		args << "-I" << ip;

	connect(detailsProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotDetailsProcessFinished(int,QProcess::ExitStatus)));

	detailsProcess->setProcessChannelMode(QProcess::MergedChannels);
	detailsProcess->start(theSMBClientPath, args);
}
Example #4
0
	void PackageProcessor::handlePackageUnarchFinished (int ret, QProcess::ExitStatus)
	{
		sender ()->deleteLater ();

		QProcess *unarch = qobject_cast<QProcess*> (sender ());
		int packageId = unarch->property ("PackageID").toInt ();
		const auto& stagingDir = unarch->property ("StagingDirectory").toString ();
		Mode mode = static_cast<Mode> (unarch->property ("Mode").toInt ());

		auto cleanupGuard = std::shared_ptr<void> (nullptr,
				[&stagingDir, this] (void*) { CleanupDir (stagingDir); });

		if (ret)
		{
			QString errString = QString::fromUtf8 (unarch->readAllStandardError ());
			qWarning () << Q_FUNC_INFO
					<< "unpacker exited with"
					<< ret
					<< errString
					<< "for"
					<< packageId
					<< unarch->property ("Path").toString ();

			QString errorString = tr ("Unable to unpack package archive, unpacker exited with %1: %2.")
					.arg (ret)
					.arg (errString);
			emit packageInstallError (packageId, errorString);

			return;
		}

		int oldId = -1;
		if (mode == MUpdate)
		{
			oldId = Core::Instance ().GetStorage ()->FindInstalledPackage (packageId);
			if (!CleanupBeforeUpdate (oldId, packageId))
			{
				qWarning () << Q_FUNC_INFO
						<< "unable to cleanup";
				return;
			}
		}

		QDir packageDir;
		try
		{
			packageDir = Core::Instance ().GetPackageDir (packageId);
		}
		catch (const std::exception& e)
		{
			qWarning () << Q_FUNC_INFO
					<< "while trying to get dir for package"
					<< packageId
					<< "got we exception"
					<< e.what ();
			QString errorString = tr ("Unable to get directory for the package: %1.")
					.arg (QString::fromUtf8 (e.what ()));
			emit packageInstallError (packageId, errorString);
			return;
		}

		QDirIterator dirIt (stagingDir,
				QDir::NoDotAndDotDot |
					QDir::Readable |
					QDir::NoSymLinks |
					QDir::Dirs |
					QDir::Files,
				QDirIterator::Subdirectories);
		while (dirIt.hasNext ())
		{
			dirIt.next ();
			QFileInfo fi = dirIt.fileInfo ();

			if (fi.isDir () ||
					fi.isFile ())
				if (!HandleEntry (packageId, fi, stagingDir, packageDir))
				{
					try
					{
						Remove (packageId);
					}
					catch (const std::exception& e)
					{
						qWarning () << Q_FUNC_INFO
								<< "while removing partially installed package"
								<< packageId
								<< "got:"
								<< e.what ();
					}

					QString errorString = tr ("Unable to copy "
							"files from staging area to "
							"destination directory.");
					emit packageInstallError (packageId, errorString);
					return;
				}
		}

		switch (mode)
		{
		case MInstall:
			emit packageInstalled (packageId);
			break;
		case MUpdate:
			emit packageUpdated (oldId, packageId);
			break;
		}
	}