ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/manualcommands.cpp
Revision: 1052
Committed: Sat Sep 17 13:32:34 2016 UTC (9 years ago) by s10k
Content type: text/x-c++src
Original Path: Vago/trunk/Vago/manualcommands.cpp
File size: 5624 byte(s)
Log Message:
Fixes for MacOS and minor bugfix

File Contents

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