#include "dialog.h"
#include
#include
#include
Dialog::Dialog(QWidget *parent): QWidget(parent)
{
layout = new QGridLayout(this);
notice = new QLabel("",this);
edit = new QTextEdit(msg,this);
//edit->setEnabled(false);
//edit->setStyleSheet("font:20px;");
layout->addWidget(notice,0,0,1,1);
layout->addWidget(edit,1,0,1,1);
setLayout(layout);
setMinimumWidth(700);
proc= new QProcess(this);
connect(proc, SIGNAL(readyReadStandardOutput()), this,SLOT(readFromStdOut()));
connect(proc, SIGNAL(readyReadStandardError()), this, SLOT(readFromStdErr()));
//connect(proc, SIGNAL(started()), this, SLOT(proceed()));
connect(proc, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
connect(proc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
notice->setText(QString("正在登陆..."));
proc->start(QString("telnet bbs.ustc.edu.cn"));
timer = new QTimer(this);
timer->setSingleShot(true);
connect(timer,SIGNAL(timeout()),this,SLOT(timerOut()));
gbk=QTextCodec::codecForName("GBK");
}
void Dialog::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
}
Dialog::~Dialog()
{
}
//void Dialog::proceed()
//{
// proc->write(qPrintable(list[1]+'\n'));
//}
void Dialog::readFromStdOut()
{
msg.append(gbk->toUnicode(proc->readAllStandardOutput()));
QString tmp=msg.split('\n', QString::SkipEmptyParts).last();
if(tmp.contains("suffix"))
{
proc->write("guest\n");
}
edit->setText(msg);
}
void Dialog::readFromStdErr()
{
msg.append(proc->readAllStandardError());
edit->setText(msg);
qDebug()<
}
void Dialog::processError(QProcess::ProcessError error)
{
if(error==QProcess::FailedToStart)
{
msg.append("程序启动失败.");
}
edit->setText(msg);
}
void Dialog::processFinished(int ,QProcess::ExitStatus exitStatus)
{
if(exitStatus == QProcess::CrashExit)
{
msg.append("程序异常终止.");
edit->setText(msg);
}
else
{
//
}
edit->setText(msg);
qDebug()<
timer->start(3000);
notice->setText("quitting in 3 seconds.");
}
void Dialog::timerOut()
{
emit closing();
}