source: s10k/Vago/manualcommands.cpp@ 1114

Last change on this file since 1114 was 1093, checked in by s10k, 7 years ago

Vago 1.4

File size: 5.6 KB
Line 
1#include "manualcommands.h"
2#include "ui_manualcommands.h"
3
4ManualCommands::ManualCommands(QWidget *parent) :
5 QMainWindow(parent),
6 ui(new Ui::ManualCommands)
7{
8 ui->setupUi(this);
9 this->setAttribute(Qt::WA_DeleteOnClose, true); //destroy itself once finished.
10 this->myProcess = new QProcess();
11 this->myProcess->setProcessChannelMode(QProcess::MergedChannels);
12 this->myProcess->setWorkingDirectory(UtilVago::getAppPath());
13 ui->leManualCommand->installEventFilter(this);
14
15 this->nextInsertHistoryIdx=0;
16 this->searchHistoryIdx=0;
17 for(int i=0; i<this->limHistory; i++){
18 this->history[i]=""; //clean array
19 }
20}
21
22ManualCommands::~ManualCommands()
23{
24 delete myProcess;
25 delete ui;
26}
27
28void ManualCommands::on_pbInput_clicked()
29{
30 executeCommand();
31}
32
33void ManualCommands::executeCommand(){
34
35 QString toolExecutable;
36
37 if(ui->cbTargetTool->currentText() == "OniSplit"){
38 toolExecutable = UtilVago::getOniSplitExecutable();
39 }
40 else{
41 toolExecutable = UtilVago::getXmlToolsExecutable();
42 }
43
44 QString command=ui->leManualCommand->text().trimmed();
45
46 if(command.isEmpty()){
47 Util::Dialogs::showError("Please input a command first.");
48 return;
49 }
50
51 //Only add to the history if the last command is different
52 bool different=false;
53 if(this->nextInsertHistoryIdx==0){ //at the limit
54 if(this->history[this->limHistory-1]!=command){
55 different=true;
56 }
57 }
58 else{
59 if(this->history[this->nextInsertHistoryIdx-1]!=command){
60 different=true;
61 }
62 }
63
64 if(different){
65 this->history[this->nextInsertHistoryIdx++]=command; //assign and increment
66
67 if(this->nextInsertHistoryIdx==this->limHistory){ //if we are at the limit begin override
68 this->nextInsertHistoryIdx=0;
69 }
70 }
71
72 this->myProcess->start(toolExecutable+" "+ui->leManualCommand->text());
73 this->myProcess->waitForFinished(120000); //wait 2 minutes at maximum
74 ui->ptOutput->appendPlainText("> " + ui->cbTargetTool->currentText() + " " + command);
75 ui->ptOutput->appendPlainText(this->myProcess->readAll());
76 ui->ptOutput->ensureCursorVisible();
77 ui->ptOutput->verticalScrollBar()->setValue( ui->ptOutput->verticalScrollBar()->maximum() );
78 ui->leManualCommand->clear();
79}
80
81void ManualCommands::on_pcCopyClipboard_clicked()
82{
83 QApplication::clipboard()->setText(ui->ptOutput->toPlainText());
84}
85
86void ManualCommands::on_pbClear_clicked()
87{
88 if(Util::Dialogs::showQuestion(this,"Clear the output?")){
89 ui->ptOutput->clear();
90 }
91}
92
93//Allows detecting arrows press for history without subclassing lineedit.
94bool ManualCommands::eventFilter(QObject* obj, QEvent *event)
95{
96 if (obj == ui->leManualCommand)
97 {
98 if (event->type() == QEvent::KeyPress)
99 {
100 QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
101 if (keyEvent->key() == Qt::Key_Up) //UP ARROW
102 {
103
104 int oldValue=this->searchHistoryIdx;
105
106 //if it isn't the first member of history continue decrementing
107 if(this->searchHistoryIdx!=this->nextInsertHistoryIdx){ //for when it didn't the round
108 this->searchHistoryIdx--;
109 }
110
111 //start with the last elemented inputted
112 if(ui->leManualCommand->text().trimmed().isEmpty()){
113 this->searchHistoryIdx=this->nextInsertHistoryIdx-1;
114 }
115
116 //rotate
117 if(this->searchHistoryIdx < 0){
118 this->searchHistoryIdx=this->limHistory-1; //start from behind (49)
119 }
120 else if(this->searchHistoryIdx == this->limHistory){
121 this->searchHistoryIdx=0; //start from 0 again
122 }
123
124 //not filled yet value? Stop.
125 if(this->history[this->searchHistoryIdx].isEmpty()){
126 this->searchHistoryIdx=oldValue;
127 return true;
128 }
129
130 ui->leManualCommand->setText(this->history[this->searchHistoryIdx]);
131
132 return true;
133
134 }
135 else if(keyEvent->key() == Qt::Key_Down) //DOWN ARROW
136 {
137 if(ui->leManualCommand->text().trimmed().isEmpty()){
138 return true;
139 }
140
141 int oldValue=this->searchHistoryIdx;
142
143 //Continue incrementing if it isnt the last member of history
144 if(this->searchHistoryIdx!=this->nextInsertHistoryIdx-1 && //for when it didn't the round
145 !(this->nextInsertHistoryIdx==0 && this->searchHistoryIdx==this->limHistory-1)){ //for when it did the round
146 this->searchHistoryIdx++;
147 }
148
149 //rotate
150 if(this->searchHistoryIdx < 0){
151 this->searchHistoryIdx=this->limHistory-1; //start from behind (49)
152 }
153 else if(this->searchHistoryIdx == this->limHistory){
154 this->searchHistoryIdx=0; //start from 0 again
155 }
156
157 //not filled yet value? Stop.
158 if(this->history[this->searchHistoryIdx].isEmpty()){
159 this->searchHistoryIdx=oldValue;
160 return true;
161 }
162
163 ui->leManualCommand->setText(this->history[this->searchHistoryIdx]);
164
165 return true;
166 }
167 }
168 return false;
169 }
170 return QMainWindow::eventFilter(obj, event);
171}
Note: See TracBrowser for help on using the repository browser.