source: src-qt4/qsudo/mainwindow.cpp @ 1f14f705

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 1f14f705 was 1f14f705, checked in by Kris Moore <kris@…>, 17 months ago

Update qsudo, since we like to see stdout / stderr messages ;)

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/****************************************************************************
2** ui.h extension file, included from the uic-generated form implementation.
3**
4** If you want to add, delete, or rename functions or slots, use
5** Qt Designer to update this file, preserving your code.
6**
7** You should not define a constructor or destructor in this file.
8** Instead, write your code in functions called init() and destroy().
9** These will automatically be called by the form's constructor and
10** destructor.
11*****************************************************************************/
12#include <QDebug>
13#include <QDir>
14#include <QString>
15#include <QProcess>
16#include <QTextStream>
17#include <QApplication>
18#include "mainwindow.h"
19#include "../config.h"
20
21void MainWindow::ProgramInit()
22{
23  tries=3;
24  connect(buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(slotButtonClicked(QAbstractButton *)));
25  connect(passwordLineEdit, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()));
26}
27
28void MainWindow::slotReturnPressed()
29{
30  testPass();
31}
32
33void MainWindow::testPass()
34{
35
36  QString program = "sudo";
37  QStringList arguments;
38  arguments << "-S";
39  arguments << "-k";
40  arguments << "true";
41
42  QProcess *tP = new QProcess(this);
43  tP->start(program, arguments);
44  tP->write(passwordLineEdit->text().toLatin1() + "\n");
45  tP->write(passwordLineEdit->text().toLatin1() + "\n");
46  tP->write(passwordLineEdit->text().toLatin1() + "\n");
47  while(tP->state() == QProcess::Starting || tP->state() == QProcess::Running ) {
48     tP->waitForFinished(500);
49     QCoreApplication::processEvents();
50  }
51  if ( tP->exitCode() != 0 )
52  {
53     QString tmp;
54     tmp.setNum(tries-1);
55     labelBadPW->setText(tr("Invalid Password! Tries Left: %1").arg(tmp) );
56     tries--;
57     if ( tries == 0 )
58       exit(1);
59  } else {
60     startSudo();
61  }
62}
63
64void MainWindow::startSudo()
65{
66  setVisible(false);
67  QString program = "sudo";
68  QStringList arguments;
69  arguments << "-S";
70  for ( int i = 1; i< qApp->argc() ; i++)
71    arguments << qApp->argv()[i];
72
73  sudoProc = new QProcess(this);
74  sudoProc->start(program, arguments);
75  sudoProc->write(passwordLineEdit->text().toLatin1() + "\n");
76  connect( sudoProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotProcDone() ) );
77  connect( sudoProc, SIGNAL(readyReadStandardError()), this, SLOT(slotPrintStdErr() ) );
78  connect( sudoProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotPrintStdOut() ) );
79  while(sudoProc->state() == QProcess::Starting ) {
80     sudoProc->waitForFinished(500);
81     QCoreApplication::processEvents();
82  }
83}
84
85void MainWindow::slotPrintStdErr()
86{
87  QTextStream cout(stderr); 
88  cout << sudoProc->readAllStandardError();
89}
90
91void MainWindow::slotPrintStdOut()
92{
93  QTextStream cout(stdout); 
94  cout << sudoProc->readAllStandardOutput();
95}
96
97void MainWindow::slotProcDone()
98{
99   exit(sudoProc->exitCode());
100}
101
102void MainWindow::slotButtonClicked(QAbstractButton *myBut)
103{
104  if ( buttonBox->buttonRole(myBut) == QDialogButtonBox::AcceptRole ) 
105     testPass();
106  close();
107}
Note: See TracBrowser for help on using the repository browser.