コード例 #1
0
ファイル: wmhelper.cpp プロジェクト: claudiutraistaru/octopi
/*
 * Edits a file based on your DE.
 */
void WMHelper::editFile( const QString& fileName ){
  QProcess *process = new QProcess(qApp->activeWindow());
  QStringList s;

  if (!UnixCommand::isRootRunning()){
    LinuxDistro distro = UnixCommand::getLinuxDistro();
    if (distro == ectn_ARCHBANGLINUX && UnixCommand::hasTheExecutable(ctn_ARCHBANG_EDITOR))
    {
      QString p = ctn_ARCHBANG_EDITOR + " " + fileName;
      process->startDetached(getSUCommand() + p);
    }
    else if (isXFCERunning() && (UnixCommand::hasTheExecutable(ctn_XFCE_EDITOR) ||
                             UnixCommand::hasTheExecutable(ctn_XFCE_EDITOR_ALT))){

      QString p = getXFCEEditor() + " " + fileName;
      process->startDetached(getSUCommand() + p);
    }
    else if (isKDERunning() && UnixCommand::hasTheExecutable(ctn_KDE_EDITOR)){
      QString p = " -d -t --noignorebutton -c ";
      p += ctn_KDE_EDITOR + " " + fileName;
      process->startDetached(getSUCommand() + p);
    }
    else if (isKDERunning() && UnixCommand::hasTheExecutable(ctn_KDE4_EDITOR)){
      QString p = " -d -t --noignorebutton -c ";
      p += ctn_KDE4_EDITOR + " " + fileName;
      process->startDetached(getSUCommand() + p);
    }
    else if (isTDERunning() && UnixCommand::hasTheExecutable(ctn_TDE_EDITOR)){
      QString p = " -d -t --noignorebutton ";
      p += ctn_TDE_EDITOR + " " + fileName;
      process->startDetached(getSUCommand() + p);
    }
    else if (isMATERunning() && UnixCommand::hasTheExecutable(ctn_MATE_EDITOR)){
      QString p = ctn_MATE_EDITOR + " " + fileName;
      process->startDetached(getSUCommand() + p);
    }
    else if (isCinnamonRunning() && UnixCommand::hasTheExecutable(ctn_CINNAMON_EDITOR)){
      QString p = ctn_CINNAMON_EDITOR + " " + fileName;
      process->startDetached(getSUCommand() + p);
    }
    else if (UnixCommand::hasTheExecutable(ctn_XFCE_EDITOR) || UnixCommand::hasTheExecutable(ctn_XFCE_EDITOR_ALT)){
      QString p = getXFCEEditor() + " " + fileName;
      process->startDetached(getSUCommand() + p);
    }
  }
  //Octopi was started by root account.
  else{
    if (UnixCommand::hasTheExecutable(ctn_XFCE_EDITOR) || UnixCommand::hasTheExecutable(ctn_XFCE_EDITOR_ALT))
      s << getXFCEEditor() + " " + fileName;
    else if (UnixCommand::hasTheExecutable(ctn_KDE_EDITOR))
      s << ctn_KDE_EDITOR + " " + fileName;
    else if (UnixCommand::hasTheExecutable(ctn_TDE_EDITOR))
      s << ctn_TDE_EDITOR + " " + fileName;

    process->startDetached("/bin/sh", s);
  }
}
コード例 #2
0
ファイル: wmhelper.cpp プロジェクト: martell/octopi
/*
 * Opens a file based on your DE
 */
void WMHelper::openFile(const QString& fileName){
  QString fileToOpen(fileName);

  if (!UnixCommand::isTextFile(fileToOpen)){
    int res = QMessageBox::question(qApp->activeWindow(), StrConstants::getConfirmation(),
                                    StrConstants::getThisIsNotATextFile(),
                                    QMessageBox::Yes | QMessageBox::No,
                                    QMessageBox::No);

    if ( res == QMessageBox::No ) return;
  }

  QProcess *p = new QProcess(qApp->activeWindow());
  QStringList s;

  LinuxDistro distro = UnixCommand::getLinuxDistro();
  if (distro == ectn_ARCHBANGLINUX && UnixCommand::hasTheExecutable(ctn_ARCHBANG_FILE_MANAGER))
  {
    s << fileToOpen;
    p->startDetached( ctn_ARCHBANG_FILE_MANAGER, s );
  }

  else if (isXFCERunning() && UnixCommand::hasTheExecutable(ctn_XFCE_FILE_MANAGER)){
    s << fileToOpen;
    p->startDetached( ctn_XFCE_FILE_MANAGER, s );
  }
  else if (isKDERunning() && UnixCommand::hasTheExecutable(ctn_KDE_FILE_MANAGER)){
    s << "exec";
    s << "file:" + fileToOpen;
    p->startDetached( ctn_KDE_FILE_MANAGER, s );
  }
  else if (isKDERunning() && UnixCommand::hasTheExecutable(ctn_KDE4_FILE_MANAGER)){
    s << fileToOpen;
    p->startDetached( ctn_KDE4_OPEN, s );
  }
  else if (isTDERunning() && UnixCommand::hasTheExecutable(ctn_TDE_FILE_MANAGER)){
    s << "exec";
    s << "file:" + fileToOpen;
    p->startDetached( ctn_TDE_FILE_MANAGER, s );
  }
  else if (isMATERunning() && UnixCommand::hasTheExecutable(ctn_MATE_EDITOR)){
    s << fileToOpen;
    p->startDetached( ctn_MATE_EDITOR, s );
  }
  else if (isCinnamonRunning() && UnixCommand::hasTheExecutable(ctn_CINNAMON_EDITOR)){
    s << fileToOpen;
    p->startDetached( ctn_CINNAMON_EDITOR, s );
  }
  else if (UnixCommand::hasTheExecutable(ctn_XFCE_FILE_MANAGER)){
    s << fileToOpen;
    p->startDetached( ctn_XFCE_FILE_MANAGER, s );
  }
  else if (UnixCommand::hasTheExecutable(ctn_LXDE_FILE_MANAGER)){
    s << fileToOpen;
    p->startDetached( ctn_LXDE_FILE_MANAGER, s );
  }
}
コード例 #3
0
ファイル: wmhelper.cpp プロジェクト: claudiutraistaru/octopi
/*
 * Opens a terminal based on your DE.
 */
void WMHelper::openTerminal(const QString& dirName){
  QProcess *p = new QProcess(qApp->activeWindow());
  QStringList s;
  QFileInfo f(dirName);

  if (f.exists()){
    if(isXFCERunning() && UnixCommand::hasTheExecutable(ctn_XFCE_TERMINAL)){
      s << "--working-directory=" + dirName;
      p->startDetached( ctn_XFCE_TERMINAL, s );
    }
    else if (isKDERunning() && UnixCommand::hasTheExecutable(ctn_KDE_TERMINAL)){
      s << "--workdir";            
      s << dirName;

      if (UnixCommand::isRootRunning())
      {
        p->startDetached( "dbus-launch " + ctn_KDE_TERMINAL + " --workdir " + dirName);
      }
      else
      {
        p->startDetached( ctn_KDE_TERMINAL, s );
      }
    }
    else if (isTDERunning() && UnixCommand::hasTheExecutable(ctn_TDE_TERMINAL)){
      s << "--workdir";
      s << dirName;
      p->startDetached( ctn_TDE_TERMINAL, s );
    }
    else if (isLXDERunning() && UnixCommand::hasTheExecutable(ctn_LXDE_TERMINAL)){
      s << "--working-directory=" + dirName;
      p->startDetached( ctn_LXDE_TERMINAL, s );
    }
    else if (isMATERunning() && UnixCommand::hasTheExecutable(ctn_MATE_TERMINAL)){
      s << "--working-directory=" + dirName;
      p->startDetached( ctn_MATE_TERMINAL, s );
    }
    else if (isCinnamonRunning() && UnixCommand::hasTheExecutable(ctn_CINNAMON_TERMINAL)){
      s << "--working-directory=" + dirName;
      p->startDetached( ctn_CINNAMON_TERMINAL, s );
    }
    else if (UnixCommand::hasTheExecutable(ctn_XFCE_TERMINAL)){
      s << "--working-directory=" + dirName;
      p->startDetached( ctn_XFCE_TERMINAL, s );
    }
    else if (UnixCommand::hasTheExecutable(ctn_LXDE_TERMINAL)){
      s << "--working-directory=" + dirName;
      p->startDetached( ctn_LXDE_TERMINAL, s );
    }
    else if (UnixCommand::hasTheExecutable(ctn_XTERM)){
      QString cmd = ctn_XTERM +
          " -fn \"*-fixed-*-*-*-18-*\" -fg White -bg Black -title xterm -e \"" +
          "cd " + dirName + " && /bin/bash\"";
      p->startDetached( cmd );
    }
  }
}
コード例 #4
0
ファイル: wmhelper.cpp プロジェクト: ColinDuquesnoy/octopi
/*
 * Edits a file based on your DE.
 */
void WMHelper::editFile( const QString& fileName, EditOptions opt ){
  QProcess *process = new QProcess(qApp->activeWindow());
  QString p;

  LinuxDistro distro = UnixCommand::getLinuxDistro();
  if (distro == ectn_ARCHBANGLINUX && UnixCommand::hasTheExecutable(ctn_ARCHBANG_EDITOR))
  {
    p = ctn_ARCHBANG_EDITOR + " " + fileName;
  }
  else if (distro == ectn_MOOOSLINUX && UnixCommand::hasTheExecutable(ctn_MOOOS_EDITOR))
  {
    p = ctn_MOOOS_EDITOR + " " + fileName;
  }
  else if (isXFCERunning() && (UnixCommand::hasTheExecutable(ctn_XFCE_EDITOR) ||
                               UnixCommand::hasTheExecutable(ctn_XFCE_EDITOR_ALT))){

    p = getXFCEEditor() + " " + fileName;
  }
  else if (isKDERunning() && UnixCommand::hasTheExecutable(ctn_KDE_EDITOR)){
    p += ctn_KDE_EDITOR + " " + fileName;
  }
  else if (isKDERunning() && UnixCommand::hasTheExecutable(ctn_KDE4_EDITOR)){
    p += ctn_KDE4_EDITOR + " " + fileName;
  }
  else if (isTDERunning() && UnixCommand::hasTheExecutable(ctn_TDE_EDITOR)){
    p += ctn_TDE_EDITOR + " " + fileName;
  }
  else if (isMATERunning() && UnixCommand::hasTheExecutable(ctn_MATE_EDITOR)){
    p = ctn_MATE_EDITOR + " " + fileName;
  }
  else if (isLXQTRunning() && UnixCommand::hasTheExecutable(ctn_LXQT_EDITOR)){
    p = ctn_LXQT_EDITOR + " " + fileName;
  }
  if (UnixCommand::hasTheExecutable(ctn_ARCHBANG_EDITOR))
  {
    p = ctn_ARCHBANG_EDITOR + " " + fileName;
  }
  else if (UnixCommand::hasTheExecutable(ctn_CINNAMON_EDITOR)){
    p = ctn_CINNAMON_EDITOR + " " + fileName;
  }
  else if (UnixCommand::hasTheExecutable(ctn_XFCE_EDITOR) || UnixCommand::hasTheExecutable(ctn_XFCE_EDITOR_ALT)){
    p = getXFCEEditor() + " " + fileName;
  }

  if (UnixCommand::isRootRunning() || opt == ectn_EDIT_AS_NORMAL_USER)
  {
    process->startDetached("/bin/sh -c \"" + p + "\"");
  }
  else
  {
    process->startDetached(getSUCommand() + p);
  }
}
コード例 #5
0
ファイル: wmhelper.cpp プロジェクト: martell/octopi
/*
 * The generic SU get method. It retrieves the SU you have installed in your system!
 */
QString WMHelper::getSUCommand(){
  QString result(ctn_NO_SU_COMMAND);

  if (SettingsManager::getPrivilegeEscalationTool() == ctn_AUTOMATIC){
    //User wants the app to automatically choose Privilege escalation tool
    if (isXFCERunning() && (UnixCommand::hasTheExecutable(ctn_GKSU_2))){
      result = getGKSUCommand();
    }
    else if (isKDERunning() && UnixCommand::hasTheExecutable(ctn_KDESU)){
      result = getKDESUCommand();
    }
    else if (isTDERunning() && UnixCommand::hasTheExecutable(ctn_TDESU)){
      result = getTDESUCommand();
    }
    else if (UnixCommand::hasTheExecutable(ctn_GKSU_2)){
      result = getGKSUCommand();
    }
    else if (UnixCommand::isKtsussVersionOK()){
      result = getKTSUSSCommand();
    }
    else if (UnixCommand::hasTheExecutable(ctn_KDESU)){
      result = getKDESUCommand();
    }
    else if (UnixCommand::hasTheExecutable(ctn_TDESU)){
      result = getTDESUCommand();
    }
    //Otherwise, user chose his own privilege escalation tool...
    else if (SettingsManager::getPrivilegeEscalationTool() == ctn_GKSU_2)
      result = getGKSUCommand();
    else if (SettingsManager::getPrivilegeEscalationTool() == ctn_KDESU)
      result = getKDESUCommand();
    else if (SettingsManager::getPrivilegeEscalationTool() == ctn_TDESU)
      result = getTDESUCommand();
    else if (SettingsManager::getPrivilegeEscalationTool() == ctn_KTSUSS){
      result = getKTSUSSCommand();
    }
  }

  return result;
}
コード例 #6
0
ファイル: wmhelper.cpp プロジェクト: ColinDuquesnoy/octopi
/*
 * The generic SU get method. It retrieves the SU you have installed in your system!
 */
QString WMHelper::getSUCommand(){
  QString result(ctn_NO_SU_COMMAND);

  if (isXFCERunning() && (UnixCommand::hasTheExecutable(ctn_GKSU_2))){
    result = getGKSUCommand();
  }
  else if (isKDERunning() && UnixCommand::hasTheExecutable(ctn_KDESU)){
    result = getKDESUCommand();
  }
  else if (isTDERunning() && UnixCommand::hasTheExecutable(ctn_TDESU)){
    result = getTDESUCommand();
  }
  else if (UnixCommand::hasTheExecutable(ctn_GKSU_2)){
    result = getGKSUCommand();
  }
  else if (UnixCommand::hasTheExecutable(ctn_KDESU)){
    result = getKDESUCommand();
  }
  else if (UnixCommand::hasTheExecutable(ctn_TDESU)){
    result = getTDESUCommand();
  }

  return result;
}
コード例 #7
0
ファイル: wmhelper.cpp プロジェクト: ColinDuquesnoy/octopi
/*
 * Opens a directory based on your DE.
 */
void WMHelper::openDirectory( const QString& dirName ){
  QProcess *p = new QProcess(qApp->activeWindow());
  QStringList s;
  QString dir(dirName);

  //Is it really a directory?
  QFileInfo f(dirName);
  if (!f.isDir())
  {
    dir = f.absolutePath();
    f = QFileInfo(dir);
  }

  if (f.exists())
  {
    LinuxDistro distro = UnixCommand::getLinuxDistro();

    if (distro == ectn_ARCHBANGLINUX && UnixCommand::hasTheExecutable(ctn_ARCHBANG_FILE_MANAGER))
    {
      s << dir;
      p->startDetached( ctn_ARCHBANG_FILE_MANAGER, s );
    }
    else if(isXFCERunning() && UnixCommand::hasTheExecutable(ctn_XFCE_FILE_MANAGER))
    {
      s << dir;
      p->startDetached( ctn_XFCE_FILE_MANAGER, s );
    }
    else if (distro == ectn_MOOOSLINUX || isKDERunning())
    {
      if (UnixCommand::hasTheExecutable(ctn_KDE4_FILE_MANAGER))
      {
        s << dir;

        if (UnixCommand::isRootRunning())
        {
          p->startDetached( "dbus-launch " + ctn_KDE4_FILE_MANAGER + " " + dir);
        }
        else
        {
          p->startDetached( ctn_KDE4_FILE_MANAGER, s);
        }
      }
      else if (UnixCommand::hasTheExecutable(ctn_KDE_FILE_MANAGER))
      {
        s << "newTab";
        s << dir;
        p->startDetached( ctn_KDE_FILE_MANAGER, s );
      }
    }
    else if (isTDERunning())
    {
      if (UnixCommand::hasTheExecutable(ctn_TDE_FILE_MANAGER))
      {
        s << "newTab";
        s << dir;
        p->startDetached( ctn_TDE_FILE_MANAGER, s );
      }
    }
    else if (isMATERunning() && UnixCommand::hasTheExecutable(ctn_MATE_FILE_MANAGER))
    {
      s << dir;
      p->startDetached( ctn_MATE_FILE_MANAGER, s );
    }
    else if (UnixCommand::getLinuxDistro() == ectn_ANTERGOS && UnixCommand::hasTheExecutable(ctn_ANTERGOS_FILE_MANAGER))
    {
      s << dir;
      p->startDetached( ctn_ANTERGOS_FILE_MANAGER, s );
    }
    else if (isCinnamonRunning() && UnixCommand::hasTheExecutable(ctn_CINNAMON_FILE_MANAGER))
    {
      s << dir;
      p->startDetached( ctn_CINNAMON_FILE_MANAGER, s );
    }
    else if (isLXQTRunning() && UnixCommand::hasTheExecutable(ctn_LXQT_FILE_MANAGER))
    {
      s << dir;
      p->startDetached( ctn_LXQT_FILE_MANAGER, s );
    }
    else if (UnixCommand::hasTheExecutable(ctn_XFCE_FILE_MANAGER))
    {
      s << dir;
      p->startDetached( ctn_XFCE_FILE_MANAGER, s );
    }
    else if (UnixCommand::hasTheExecutable(ctn_LXDE_FILE_MANAGER))
    {
      s << dir;
      p->startDetached( ctn_LXDE_FILE_MANAGER, s );
    }
  }
}