Example #1
0
void SnoreToast::slotNotify(Notification notification)
{
    QProcess *p = new QProcess(this);
    p->setReadChannelMode(QProcess::MergedChannels);

    connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus)));
    connect(qApp,SIGNAL(aboutToQuit()),p,SLOT(kill()));

    QStringList arguements;
    arguements << "-t"
               << Snore::toPlainText(notification.title())
               << "-m"
               << Snore::toPlainText(notification.text());
    if(notification.icon().isValid())
    {
        arguements << "-p"
                   << QDir::toNativeSeparators(notification.icon().localUrl());
    }
    arguements << "-w"
               << "-appID"
               << appId(notification.application())
               << "-id"
               << QString::number(notification.id());
    if(notification.hints().value("silent",true).toBool())
    {
        arguements << "-silent";
    }
    snoreDebug( SNORE_DEBUG ) << "SnoreToast" << arguements;
    p->start("SnoreToast", arguements);

    p->setProperty("SNORE_NOTIFICATION_ID",notification.id());
}
Example #2
0
QString FoxGroundDocument::execlocal(const QString cmd, const QStringList args) {

    QString debughere = cmd;
    int success = -1;
    debughere.append(" ");
    debughere.append(args.join(" "));
    //// console(QString("Fox:execlocal: %1").arg(debughere));
    QString rec;
    QProcess *process = new QProcess(NULL);
    process->setReadChannelMode(QProcess::MergedChannels);
    process->start(cmd, args, QIODevice::ReadOnly);
    ////  waitForFinished default int msecs = 30000 ok
    if (!process->waitForFinished(80000)) {
        success = -1;
    } else {
        success = 1;
        rec = process->readAll();
    }
    if (success == 1) {
        process->close();
        return rec;
    } else {
        process->close();
        return QString("ERROR: Time out by %1").arg(debughere);
    }
}
Example #3
0
/*!
    \reimp

    This class overrides QSerialIODevice::run() to run pppd directly on the
    underlying device name so that it isn't necessary to create a pseudo-tty.
    This is generally more efficient for running pppd.
*/
QProcess *QSerialPort::run( const QStringList& arguments,
                              bool addPPPdOptions )
{
    if ( addPPPdOptions && d->isTty ) {
        // Make sure we aren't using the device before handing it off to pppd.
        if ( isOpen() )
            close();

        // Build a new argument list for pppd, with the device name in place.
        QStringList newargs;
        newargs << d->device;
        newargs << QString::number( d->rate );
        for ( int index = 1; index < arguments.size(); ++index )
            newargs << arguments[index];

        // Run the process.  When it exits, open() will be called again.
        QProcess *process = new QProcess();
        process->setReadChannelMode( QProcess::ForwardedChannels );
        connect( process, SIGNAL(stateChanged(QProcess::ProcessState)),
                 this, SLOT(pppdStateChanged(QProcess::ProcessState)) );
        connect( process, SIGNAL(destroyed()), this, SLOT(pppdDestroyed()) );
        process->start( arguments[0], newargs );
        return process;
    } else {
        return QSerialIODevice::run( arguments, addPPPdOptions );
    }
}
Example #4
0
double JavaVersion()
{
        QProcess process;
        QString Stversion;
        bool ok;
        double js_version = 0.00;
        QRegExp regExp1(" (\\d+)\\.(\\d+).*");
        process.setReadChannelMode(QProcess::MergedChannels);
        process.start( "java" ,  QStringList() << "-version");
          if (!process.waitForFinished()) {
          return js_version;
          } else {
              QString pu = process.readAll();
              /////QStringList line1 = pu.split("\n");
              ////////qDebug() << "### jsversion " << pu;
              int pos1 = regExp1.indexIn(pu);  /* only first line */
              if (pos1 > 0) {
                        Stversion = QString("%1.%2").arg(regExp1.cap(1).toInt()).arg(regExp1.cap(2).toInt());
                        double js_version = Stversion.toDouble(&ok);
                         if (ok && js_version > 1) {
                         return js_version;
                         }
              } else {
              return js_version;
              }
          }
return js_version;
}
Example #5
0
int callGS( const QStringList args )
{
   const QString startnow = QDir::currentPath();
   const QString GhostScriptPath = getGSDefaultExeName();
   QDir::setCurrent(_GSCACHE_);
   QString  cmd1 =  GhostScriptPath + " ";
   cmd1 += args.join(" ");
   int fax = -1;
   #if defined Q_WS_MAC
   fax = system(cmd1.toLocal8Bit());
   QDir::setCurrent(startnow);
   return fax;
   #endif
   QProcess *process = new QProcess(NULL);
   process->setReadChannelMode(QProcess::MergedChannels);
   process->start( GhostScriptPath ,  args , QIODevice::ReadOnly );
          if (!process->waitForFinished()) {
           fax = -1;
          } else {
            QString ghostcomment = process->readAll().trimmed();
            //////qDebug() << "ghostcomment-> " << ghostcomment; 
            fax = 0;
          }
          
   QDir::setCurrent(startnow);
   return fax;
}
Example #6
0
QString getGSLinuxPath( QString apps  )
{
    QStringList potential_paths;
    potential_paths.append("/usr/local/bin");
    potential_paths.append("/sw/bin");   /* to use on mac as same */
    potential_paths.append("/opt/bin");
    QProcess *process = new QProcess(NULL);
    process->setReadChannelMode(QProcess::MergedChannels);
    QStringList env = process->systemEnvironment();
    env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;"+potential_paths.join(";"));
    process->setEnvironment(env);
    
        process->start( QString("which") ,  QStringList() << apps , QIODevice::ReadOnly );
          if (!process->waitForFinished()) {
          return QString();
          } else {
              QString finder = process->readAll().trimmed();
              if (finder.endsWith(apps,Qt::CaseInsensitive)) {
                 ///////////// qDebug() << "### finder " <<  finder;
                return finder;  
              } else {
                return QString(); 
              }
          }
}
Example #7
0
/* find gpl GhostScript version  */
double getGSVersion()
{
        QProcess process;
        QString Stversion;
        bool ok;
        double GS_version = 0.00;
        QRegExp regExp1(" (\\d+)\\.(\\d+).*");
        process.setReadChannelMode(QProcess::MergedChannels);
        process.start( getGSDefaultExeName() ,  QStringList() << "-v");
          if (!process.waitForFinished()) {
          return GS_version;
          } else {
              QString pu = process.readAll();
              QStringList line1 = pu.split("\n");
              int pos1 = regExp1.indexIn(line1.at(0));  /* only first line */
              if (pos1 > 0) {
                        Stversion = QString("%1.%2").arg(regExp1.cap(1).toInt()).arg(regExp1.cap(2).toInt());
                        double GS_version = Stversion.toDouble(&ok);
                         if (ok && GS_version > 5) {
                         return GS_version;
                         }
              } else {
              return GS_version;
              }
          }
return GS_version;
}
Example #8
0
/*!
    \overload

    Starts the program \a program in a new process. \a program is a
    single string of text containing both the program name and its
    arguments. The arguments are separated by one or more spaces.
*/
int QProcess::execute(const QString &program)
{
    QProcess process;
    process.setReadChannelMode(ForwardedChannels);
    process.start(program);
    process.waitForFinished(-1);
    return process.exitCode();
}
/*!

Executes a command as a process
Output written to given socket as response.
*/
void ShellCommandService::detachedShellCommand(QString message, TasResponse& response)
{
    TasLogger::logger()->debug("ShellCommandService::detachedShellCommand: " + message);
    QProcess process;
    process.setReadChannelMode(QProcess::MergedChannels);
    process.setEnvironment(QProcess::systemEnvironment());
    bool started = process.startDetached(message);

    if(!started){
        response.setErrorMessage("Failed to start process!");
    }
}
/*!

Executes a command as a process
Output written to given socket as response.
*/
void ShellCommandService::shellCommand(QString message, TasResponse& response)
{
    TasLogger::logger()->debug("ShellCommandService::shellCommand: " + message);

    QProcess process;
    process.setReadChannelMode(QProcess::MergedChannels);
    process.setEnvironment(QProcess::systemEnvironment());
    process.start(message);

    process.closeWriteChannel();
    process.waitForFinished(4000);

    QByteArray output = process.readAll();
    response.setData(output);
}
Example #11
0
void SnoreToast::slotRegisterApplication(const Application &application)
{
    if(!application.constHints().contains("windows_app_id"))
    {
        QProcess *p = new QProcess(this);
        p->setReadChannelMode(QProcess::MergedChannels);

        QStringList arguements;
        arguements << "-install"
                   << QString("SnoreNotify\\%1").arg(qApp->applicationName())
                   << QDir::toNativeSeparators(qApp->applicationFilePath())
                   << appId(application);
        snoreDebug( SNORE_DEBUG ) << "SnoreToast" << arguements;
        p->start("SnoreToast", arguements);

        connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus)));
        connect(qApp,SIGNAL(aboutToQuit()),p,SLOT(kill()));
    }
Example #12
0
static ProbeABI qtVersionFromExec(const QString &path)
{
    ProbeABI abi;

    // yep, you can actually execute QtCore.so...
    QProcess proc;
    proc.setReadChannelMode(QProcess::SeparateChannels);
    proc.setReadChannel(QProcess::StandardOutput);
    proc.start(path);
    proc.waitForFinished();
    const QByteArray line = proc.readLine();
    const int pos = line.lastIndexOf(' ');
    const QList<QByteArray> version = line.mid(pos).split('.');
    if (version.size() < 3)
        return abi;

    abi.setQtVersion(version.at(0).toInt(), version.at(1).toInt());

    return abi;
}
Example #13
0
void MtrThread::run()
{
	QMutexLocker locker(&mutex);
	QStringList args;

 	args.append("--report-wide");
	if(uudp)
		args.append("-u");

 	args.append("-w");
	args.append(url.host());
	args.append("--report");
	args.append("-c 30");
	emit started();
	
	qDebug() << "Starting MTR";
	
	QProcess process;
	process.setReadChannelMode(QProcess::MergedChannels);
	process.closeWriteChannel();
	
	process.start("mtr",args);
	if(!process.waitForFinished(DEFAULT_MTRRUNTIME))
	{  
		error = true;
		process.kill();
		process.waitForFinished(DEFAULT_MTRRUNTIME);

	}
	else
	{
		error = false;
	}
	

	data = process.readAll();
	qDebug() << data;
	qDebug() << "Finishing MTR: " << url;
	emit finished();
}
Example #14
0
void GenGraphForm::runTask()
{
    QStringList argv = tasks.front();
    tasks.pop_front();
    exportButton->setText("&Kill");
    QString cmd = argv.join(QString(" "));
    std::cout << "STARTING TASK " << (const char*)cmd << std::endl;
#ifdef SOFA_QT4
    QProcess* p = new QProcess(this);
    QString program = argv.front();
    argv.pop_front();
    p->setReadChannelMode(QProcess::ForwardedChannels);
    connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(taskFinished()));
    p->start(program, argv);
#else
    QProcess* p = new QProcess(argv, this);
    p->setCommunication(0);
    connect(p,SIGNAL(processExited()),this,SLOT(taskFinished()));
    p->start();
#endif
    currentTask = p;
}
/*!
   \param program The program to execute.
   \param arguments The arguments to be passed to the program.
   \return The exit code of the executed program.
    Starts a program with arguments in a new process, waits for it to finish, and then returns
    the exit code of the process. Any data the new process writes to the console is forwarded to
    the calling process.

    The environment and working directory are inherited by the calling process.

    On Windows, arguments that contain spaces are wrapped in quotes.
*/
int TSystem::execute(const QString &program, const QStringList &arguments) const
{
    QDEBUG_METHOD_NAME;

    QProcess process;

    // As seen in http://jira.codehaus.org/browse/IZPACK-20 and http://labs.trolltech.com/forums/topic/156, the method
    // execute() from QProcess is not used.

    qDebug() << TDebug::indentation << "Going to execute: " << program << " with arguments: " << arguments;

    process.setReadChannelMode(QProcess::ForwardedChannels);
    process.start(program, arguments);
    process.waitForFinished(-1);

    int exitCode = process.exitCode();
    if (process.error() == QProcess::FailedToStart)
    {
       exitCode = -1;
    }

    return exitCode;
}
Example #16
0
static bool runHelper(const QString &program, const QStringList &arguments, QByteArray *errorMessage)
{
    QProcess process;
    process.setReadChannelMode(QProcess::ForwardedChannels);
    process.start(program, arguments);
    if (!process.waitForStarted()) {
        *errorMessage = "Unable to start '" + program.toLocal8Bit() + " ': "
                        + process.errorString().toLocal8Bit();
        return false;
    }

    // Windows: Due to implementation changes, the event loop needs
    // to be spun since we ourselves also need to answer the
    // WM_DRAWCLIPBOARD message as we are in the chain of clipboard
    // viewers.
    bool running = true;
    for (int i = 0; i < 60 && running; ++i) {
        QGuiApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
        if (process.waitForFinished(500))
            running = false;
    }
    if (running) {
        process.kill();
        *errorMessage = "Timeout running '" + program.toLocal8Bit() + '\'';
        return false;
    }
    if (process.exitStatus() != QProcess::NormalExit) {
        *errorMessage = "Process '" + program.toLocal8Bit() + "' crashed.";
        return false;
    }
    if (process.exitCode()) {
        *errorMessage = "Process '" + program.toLocal8Bit() + "' returns "
                        + QByteArray::number(process.exitCode());
        return false;
    }
    return true;
}
Example #17
0
// Function to get the default Python version if any by running the python process.
static QString getDefaultPythonVersionIfAny() {
  QString defaultPythonVersion;
  QProcess pythonProcess;

  QString pythonCommand = "python";

// This is a hack for MinGW to allow the debugging of Tulip through GDB when compiled with Python 3.X installed in a non standard way.
#ifdef __MINGW32__
  char *pythonDirEv = getenv("PYTHONDIR");

  if (pythonDirEv) {
    pythonCommand = QString(pythonDirEv) + "/" + pythonCommand;
  }

#endif

  // Before Python 3.4, the version number was printed on the standard error output.
  // Starting Python 3.4 the version number is printed on the standard output.
  // So merge the output channels of the process.
  pythonProcess.setReadChannelMode(QProcess::MergedChannels);
  pythonProcess.setReadChannel(QProcess::StandardOutput);
  pythonProcess.start(pythonCommand, QStringList() << "--version");
  pythonProcess.waitForFinished(-1);

  if (pythonProcess.exitStatus() == QProcess::NormalExit) {

    QString result = pythonProcess.readAll();

    QRegExp versionRegexp(".*([0-9]*\\.[0-9]*)\\..*");

    if (versionRegexp.exactMatch(result)) {
      defaultPythonVersion = versionRegexp.cap(1);

// This is a hack for MinGW to allow the debugging of Tulip through GDB when compiled with Python 3.X installed in a non standard way.
#ifdef __MINGW32__

      if (pythonDirEv) {
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
        env.insert("PYTHONHOME", QString(pythonDirEv));
        pythonProcess.setProcessEnvironment(env);
      }

#endif

      // Check the binary type of the python executable (32 or 64 bits)
      pythonProcess.start(pythonCommand, QStringList() << "-c" << "import struct;import sys;sys.stdout.write(str(struct.calcsize('P')*8))");
      pythonProcess.waitForFinished(-1);
      QString arch = pythonProcess.readAll();

#ifdef I64

      if (arch != "64") {
        defaultPythonVersion = "";
      }

#else

      if (arch != "32") {
        defaultPythonVersion = "";
      }

#endif

    }
  }

  return defaultPythonVersion;
}