Exemplo n.º 1
0
/*
 * We need this to search for the SH process pid (which spaws yaourt)
 */
void ProcessWrapper::onSingleShot()
{
  QProcess proc;
  QProcess pAux;
  QString saux;

  proc.start("ps -o pid -C sh");
  proc.waitForFinished(-1);
  QString out = proc.readAll();
  proc.close();

  QStringList list = out.split("\n", QString::SkipEmptyParts);
  QStringList slist;

  for (int c=1; c<list.count(); c++)
  {
    int candidatePid = list.at(c).trimmed().toInt();

    if (candidatePid < m_pidTerminal) continue;

    QString cmd = QString("ps --ppid %1").arg(candidatePid);
    proc.start(cmd);
    proc.waitForFinished(-1);
    QString out = proc.readAll();

    if (out.contains("yaourt", Qt::CaseInsensitive))
    {
      pAux.start("ps -o pid -C yaourt");
      pAux.waitForFinished(-1);
      saux = pAux.readAll();
      slist = saux.split("\n", QString::SkipEmptyParts);

      for (int d=1; d<slist.count(); d++)
      {
        int candidatePid2 = slist.at(d).trimmed().toInt();

        if (candidatePid < candidatePid2)
        {
          m_pidSH = candidatePid;
          m_pidYaourt = candidatePid2;
          m_timer->start();

          return;
        }
      }
    }
  }

  emit finishedTerminal(0, QProcess::NormalExit);
}
Exemplo n.º 2
0
/*
 * Whenever the internal timer ticks, let's check if our process has finished
 */
void ProcessWrapper::onTimer()
{
  QProcess proc;
  QString cmd = QString("ps -p %1 %2").arg(m_pidSH).arg(m_pidYaourt);

  //std::cout << "PIDS: " << cmd.toAscii().data() << "\n" << std::endl;

  proc.start(cmd);
  proc.waitForFinished(-1);

  //If any of the processes have finished...
  QString out = proc.readAll();

  //std::cout << "Output: " << out.toAscii().data() << "\n" << std::endl;

  if (!out.contains(".qt_temp_", Qt::CaseInsensitive))
  {
    emit finishedTerminal(0, QProcess::NormalExit);
    m_timer->stop();
  }
}
Exemplo n.º 3
0
/*
 * Executes the given command list as normal user
 */
void Terminal::runCommandInTerminalAsNormalUser(const QStringList &commandList)
{
  QFile *ftemp = UnixCommand::getTemporaryFile();
  QTextStream out(ftemp);

  foreach(QString line, commandList)
  {
    //We must remove the "ccr/" prefix in Chakra, cos this will not work
    if(line.contains("ccr/"))
    {
      line = line.replace("ccr/", "");
    }

    out << line;
  }

  out.flush();
  ftemp->close();

  QString cmd;

  if (m_selectedTerminal == ctn_AUTOMATIC)
  {
    if (UnixCommand::getLinuxDistro() == ectn_MOOOSLINUX && UnixCommand::hasTheExecutable(ctn_RXVT_TERMINAL))
    {
      if (UnixCommand::isAppRunning("urxvtd"))
      {
        cmd = "urxvtc -name Urxvt -title Urxvt -e " + ftemp->fileName();
      }
      else
      {
        cmd = ctn_RXVT_TERMINAL + " -name Urxvt -title Urxvt -e " + ftemp->fileName();
      }
    }
    else if(WMHelper::isXFCERunning() && UnixCommand::hasTheExecutable(ctn_XFCE_TERMINAL)){
      cmd = ctn_XFCE_TERMINAL + " -e " + ftemp->fileName();
    }
    else if (WMHelper::isKDERunning() && UnixCommand::hasTheExecutable(ctn_KDE_TERMINAL))
    {
      cmd = ctn_KDE_TERMINAL + " --nofork -e bash -c " + ftemp->fileName();
    }
    else if (WMHelper::isTDERunning() && UnixCommand::hasTheExecutable(ctn_TDE_TERMINAL)){
      cmd = ctn_TDE_TERMINAL + " --nofork -e " + ftemp->fileName();
    }
    else if (WMHelper::isLXDERunning() && UnixCommand::hasTheExecutable(ctn_LXDE_TERMINAL)){
      cmd = ctn_LXDE_TERMINAL + " -e " + ftemp->fileName();
    }
    else if (WMHelper::isMATERunning() && UnixCommand::hasTheExecutable(ctn_MATE_TERMINAL)){
      cmd = ctn_MATE_TERMINAL + " -e " + ftemp->fileName();
    }
    else if (WMHelper::isLXQTRunning() && UnixCommand::hasTheExecutable(ctn_LXQT_TERMINAL)){
      cmd = ctn_LXQT_TERMINAL + " -e bash -c " + ftemp->fileName();
    }
    else if (UnixCommand::hasTheExecutable(ctn_XFCE_TERMINAL)){
      cmd = ctn_XFCE_TERMINAL + " -e " + ftemp->fileName();
    }
    else if (UnixCommand::hasTheExecutable(ctn_LXDE_TERMINAL)){
      cmd = ctn_LXDE_TERMINAL + " -e " + ftemp->fileName();
    }
    else if (UnixCommand::hasTheExecutable(ctn_XTERM)){
      cmd = ctn_XTERM +
          " -fn \"*-fixed-*-*-*-18-*\" -fg White -bg Black -title xterm -e " + ftemp->fileName();
    }
    else {
      std::cerr << "ERROR: Octopi found no suitable terminal!" << std::endl;
      emit finishedTerminal(0, QProcess::CrashExit);
      return;
    }
  }
  else //User has chosen his own terminal...
  {
    if (m_selectedTerminal == ctn_RXVT_TERMINAL)
    {
      if (UnixCommand::isAppRunning("urxvtd"))
      {
        cmd = "urxvtc -name Urxvt -title Urxvt -e " + ftemp->fileName();
      }
      else
      {
        cmd = ctn_RXVT_TERMINAL + " -name Urxvt -title Urxvt -e " + ftemp->fileName();
      }
    }
    else if(m_selectedTerminal == ctn_XFCE_TERMINAL){
      cmd = ctn_XFCE_TERMINAL + " -e " + ftemp->fileName();
    }
    else if (m_selectedTerminal == ctn_KDE_TERMINAL)
    {
      cmd = ctn_KDE_TERMINAL + " --nofork -e bash -c " + ftemp->fileName();
    }
    else if (m_selectedTerminal == ctn_TDE_TERMINAL){
      cmd = ctn_TDE_TERMINAL + " --nofork -e " + ftemp->fileName();
    }
    else if (m_selectedTerminal == ctn_LXDE_TERMINAL){
      cmd = ctn_LXDE_TERMINAL + " -e " + ftemp->fileName();
    }
    else if (m_selectedTerminal == ctn_MATE_TERMINAL){
      cmd = ctn_MATE_TERMINAL + " -e " + ftemp->fileName();
    }
    else if (m_selectedTerminal == ctn_LXQT_TERMINAL){
      cmd = ctn_LXQT_TERMINAL + " -e bash -c " + ftemp->fileName();
    }
    else if (m_selectedTerminal == ctn_XTERM){
      cmd = ctn_XTERM +
          " -fn \"*-fixed-*-*-*-18-*\" -fg White -bg Black -title xterm -e " + ftemp->fileName();
    }
  }

  m_processWrapper->executeCommand(cmd);
}
Exemplo n.º 4
0
/*
 * We need this to search for the SH process pid (which spaws AUR tool)
 */
void utils::ProcessWrapper::onSingleShot()
{
  QProcess proc;
  QProcess pAux;
  QString saux;

  proc.start("ps -o pid -C sh");
  proc.waitForFinished(-1);
  QString out = proc.readAll();
  proc.close();

  QStringList list = out.split("\n", QString::SkipEmptyParts);

  if (list.count() == 1)
  {
    proc.start("ps -o pid -C " + UnixCommand::getShell());
    proc.waitForFinished(-1);
    out = proc.readAll();
    proc.close();

    list = out.split("\n", QString::SkipEmptyParts);
  }

  QStringList slist;

  for (int c=1; c<list.count(); c++)
  {
    int candidatePid = list.at(c).trimmed().toInt();

    if (candidatePid < m_pidTerminal) continue;

    QString cmd = QString("ps -O cmd --ppid %1").arg(candidatePid);
    proc.start(cmd);
    proc.waitForFinished(-1);
    QString out = proc.readAll();

    if (UnixCommand::getLinuxDistro() == ectn_KAOS)
    {
      if (out.contains("kcp", Qt::CaseInsensitive))
      {
        pAux.start("ps -o pid -C kcp");
        pAux.waitForFinished(-1);
        saux = pAux.readAll();
        slist = saux.split("\n", QString::SkipEmptyParts);

        for (int d=1; d<slist.count(); d++)
        {
          int candidatePid2 = slist.at(d).trimmed().toInt();

          if (candidatePid < candidatePid2)
          {
            m_pidSH = candidatePid;
            m_pidAUR = candidatePid2;
            m_timer->start();

            return;
          }
        }
      }
    }
    else
    {
      if (out.contains(Package::getForeignRepositoryToolName(), Qt::CaseInsensitive))
      {
        pAux.start("ps -o pid -C " + Package::getForeignRepositoryToolName());
        pAux.waitForFinished(-1);
        saux = pAux.readAll();
        slist = saux.split("\n", QString::SkipEmptyParts);

        for (int d=1; d<slist.count(); d++)
        {
          int candidatePid2 = slist.at(d).trimmed().toInt();

          if (candidatePid < candidatePid2)
          {
            m_pidSH = candidatePid;
            m_pidAUR = candidatePid2;
            m_timer->start();

            return;
          }
        }
      }
    }
  }

  emit finishedTerminal(0, QProcess::NormalExit);
}