Пример #1
0
int Loader::load(QString program, QString workpath, QStringList args)
{
    this->program = program;
    this->workpath = workpath;

    stop();
    connect(process, SIGNAL(readyReadStandardOutput()),this,SLOT(procReadyRead()));
    connect(process, SIGNAL(started()),this,SLOT(procStarted()));
    connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(procFinished(int,QProcess::ExitStatus)));
    connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(procError(QProcess::ProcessError)));

    process->setProcessChannelMode(QProcess::MergedChannels);
    process->setWorkingDirectory(this->workpath);
#if 0
    this->port = "";
    for(int n = 0; n < args.length(); n++) {
        QString arg = args.at(n);
        if(arg.contains("-p", Qt::CaseInsensitive)){
            this->port = args.at(n+1);
            break;
        }
    }
#endif
    this->setPlainText("");
    setReady(false);
    setDisableIO(false);
    process->start(this->program,args);

    while(running == false)
        QApplication::processEvents();

    return process->exitCode();
}
Пример #2
0
void BtsSpawnClient::startClient()
{
	if(isClientReady() || (p->clientProc && p->clientProc->state() == QProcess::Starting))
		return;

	QJsonObject configObject;
	configObject.insert("storage_path", getDataPath());
	configObject.insert("use_gui", false);

	QJsonObject webuiObject;
	webuiObject.insert("listen", QString("%1:%2").arg(p->host).arg(p->port));
	webuiObject.insert("login", p->username);
	webuiObject.insert("password", p->password);
	webuiObject.insert("api_key", BtsGlobal::getApiKey().toString());

	configObject.insert("webui", webuiObject);

	p->configFile.open();
	QJsonDocument saveDoc(configObject);
	p->configFile.write(saveDoc.toJson());
	p->configFile.close();

	p->configFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner);

	p->cur_port = p->port;
	p->cur_password = p->password;
	p->cur_username = p->username;

	p->clientProc = new QProcess(this);
	connect(p->clientProc, SIGNAL(finished(int)), this, SLOT(procFinished(int)));
	connect(p->clientProc, SIGNAL(finished(int)), p->clientProc, SLOT(deleteLater()));
	connect(p->clientProc, SIGNAL(started()), this, SLOT(procStarted()));

#ifdef Q_OS_WIN
# define ARG_PREFIX "/"
#else
# define ARG_PREFIX "--"
#endif

	p->clientProc->setProgram(BtsGlobal::getBtsyncExecutablePath());
	p->clientProc->setArguments(QStringList()
	                            << ARG_PREFIX "nodaemon"
	                            << ARG_PREFIX "config" << p->configFile.fileName());

	p->clientProc->setProcessChannelMode(QProcess::ForwardedChannels);

	p->clientProc->start();
}
Пример #3
0
int Loader::reload(QString port)
{
    QStringList args;

    if(this->program.length() == 0) {
        QSettings settings(publisherKey, ASideGuiKey,this);
        QVariant incv = settings.value(includesKey);
        if(incv.canConvert(QVariant::String)) {
            QString s = incv.toString();
            s = QDir::fromNativeSeparators(s);
            this->program = s + "propeller-load";
#if defined(Q_WS_WIN32)
            this->program+=".exe";
#endif
        }
    }

    stop();
    connect(process, SIGNAL(readyReadStandardOutput()),this,SLOT(procReadyRead()));
    connect(process, SIGNAL(started()),this,SLOT(procStarted()));
    connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(procFinished(int,QProcess::ExitStatus)));
    connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(procError(QProcess::ProcessError)));

    process->setProcessChannelMode(QProcess::MergedChannels);
    process->setWorkingDirectory(this->workpath);

    if(port.length() > 0) {
        args.append("-p");
        args.append(port);
        args.append("-t");
    }

    setReady(false);
    setDisableIO(false);
    process->start(this->program,args);

    while(running == false)
        QApplication::processEvents();

    return process->exitCode();
}