File indexing completed on 2025-02-16 04:13:56
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2011 Joshua Netterfield * 0004 * joshua.netterfield@gmail.com * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #include "cwidget.h" 0014 #include "ui_cwidget.h" 0015 #include <QStringList> 0016 #include <QCompleter> 0017 0018 CWidget::CWidget(QWidget *parent) : 0019 QMainWindow(parent), 0020 ui(new Ui::CWidget) 0021 { 0022 ls.connectToServer("kstScript"); 0023 ls.waitForConnected(3000); 0024 ui->setupUi(this); 0025 connect(ui->send,SIGNAL(clicked()),this,SLOT(send())); 0026 connect(ui->commandline,SIGNAL(returnPressed()),ui->send,SLOT(animateClick())); 0027 0028 QByteArray ba="commands()"; 0029 ls.write(ba); ls.flush(); ls.waitForReadyRead(3000); 0030 ui->doc->setText(ls.read(300000)); 0031 QStringList comp=ui->doc->toPlainText().split("\n"); 0032 delete ui->commandline->completer(); 0033 ui->commandline->setCompleter(new QCompleter(comp)); 0034 0035 setWindowTitle("Kst Control"); 0036 ui->commandline->setFocus(); 0037 } 0038 0039 void CWidget::send() { 0040 QByteArray ba(ui->commandline->text().toStdString().c_str()); 0041 ls.write(ba); ls.flush(); ls.waitForReadyRead(3000); 0042 QString x=ui->log->toHtml(); 0043 x+="<B>"+ui->commandline->text()+"</B><br>"+ls.read(30000)+"<br>"; 0044 ui->commandline->clear(); 0045 ui->log->setText(x); 0046 QTextCursor tc=ui->log->textCursor(); 0047 tc.movePosition(QTextCursor::End); 0048 ui->log->setTextCursor(tc); 0049 0050 ba="commands()"; 0051 ls.write(ba); ls.flush(); ls.waitForReadyRead(3000); 0052 ui->doc->setText(ls.read(300000)); 0053 QStringList comp=ui->doc->toPlainText().split("\n"); 0054 delete ui->commandline->completer(); 0055 ui->commandline->setCompleter(new QCompleter(comp)); 0056 0057 ui->commandline->setFocus(); 0058 } 0059 0060 CWidget::~CWidget() 0061 { 0062 QByteArray ba("done()"); 0063 ls.write(ba); ls.flush(); ls.waitForReadyRead(3000); qDebug()<<ls.read(30000); 0064 delete ui; 0065 }