-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
executable file
·152 lines (133 loc) · 5.06 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "simplefiledialog.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ed = new Editor();
term = new Terminal();
host = new HostFileSystem();
targ = new TargetFileSystem();
fileProgress = new QProgressBar();
fileProgress->setVisible(false);
ui->statusBar->addWidget(fileProgress,1);
this->setCentralWidget(ed);
ui->dockWidget_5->setFeatures(QDockWidget::DockWidgetMovable);
ui->dockWidget_5->setWindowTitle("Terminal");
ui->dockWidget_5->setWidget(term);
ui->dockWidget->setFeatures(QDockWidget::DockWidgetMovable);
ui->dockWidget->setWindowTitle("Archivos PC");
ui->dockWidget->setWidget(host);
ui->dockWidget_2->setFeatures(QDockWidget::DockWidgetMovable);
ui->dockWidget_2->setWindowTitle("Archivos Placa");
ui->dockWidget_2->setWidget(targ);
ed->addTab(new EditorTab(),"Nuevo");
connect(term,SIGNAL(update_file_status(int)),this,SLOT(update_file_status(int)));
connect(term,SIGNAL(connected(QString,bool)),this,SLOT(port_connected(QString,bool)));
connect(host,SIGNAL(openFile(QString)),ed,SLOT(openFile(QString)));
connect(term,SIGNAL(sendScannedTargetFiles(QStringList,QStringList)),targ,SLOT(addFiles(QStringList,QStringList)));
connect(targ,SIGNAL(currentDirChanged(QString)),term,SLOT(targetDirChanged(QString)));
connect(term,SIGNAL(update_target_dir(QString)),targ,SLOT(on_current_dir_changed(QString)));
connect(term,SIGNAL(port_connected(bool)),targ,SLOT(setEnabled(bool)));
connect(targ,SIGNAL(openFile(QString)),term,SLOT(openTargetFile(QString)));
connect(term,SIGNAL(targetFileOpened(QString,QString)),ed,SLOT(openTargetFile(QString,QString)));
connect(ed,SIGNAL(saveTargetFile(QString,QByteArray)),term,SLOT(saveTargetFile(QString,QByteArray)));
connect(this,SIGNAL(transferFile(QString,QByteArray)),term,SLOT(saveTargetFile(QString,QByteArray)));
connect(targ,SIGNAL(createNewTargetFile(QString,QByteArray)),term,SLOT(saveTargetFile(QString,QByteArray)));
connect(targ,SIGNAL(createNewTargetDir(QString)),term,SLOT(createTargetDir(QString)));
connect(targ,SIGNAL(deleteTargetDir(QString)),term,SLOT(deleteTargetDir(QString)));
connect(targ,SIGNAL(deleteTargetFile(QString)),term,SLOT(deleteTargetFile(QString)));
}
void MainWindow::update_file_status(int value){
fileProgress->setVisible(true);
fileProgress->setValue(value);
if(fileProgress->value() >= 100)
fileProgress->setVisible(false);
QApplication::processEvents();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionEjecutar_Resaltado_triggered()
{
EditorTab *et = ed->getCurrentTab();
QByteArray data;
data.append("\u0003");
data.append(0x05);
data.append(et->ed->selectedText().toLatin1());
data.append(0x04);
term->writeData(data);
}
void MainWindow::port_connected(QString portName, bool state){
if(state){
ui->statusBar->setStyleSheet("color: blue");
ui->statusBar->showMessage("Conexión Exitosa con el puerto "+portName,2000);
}
else{
ui->statusBar->setStyleSheet("color: red");
ui->statusBar->showMessage("Falló conexión con el puerto "+portName,2000);
}
}
void MainWindow::on_actionGuardar_triggered()
{
EditorTab *et= ed->getCurrentTab();
if(et->getFilePath() != "")
et->saveFile(QDir::cleanPath(et->getFilePath()));
else
on_actionGuardar_Como_triggered();
}
void MainWindow::on_actionEjecutar_triggered()
{
on_actionGuardar_triggered();
EditorTab *et = ed->getCurrentTab();
QByteArray data;
data.append("\u0003");
data.append(0x05);
data.append(et->ed->text().toLatin1());
data.append(0x04);
term->writeData(data);
}
void MainWindow::on_actionTransferir_triggered()
{
EditorTab *et = ed->getCurrentTab();
QString fileName = et->getFilePath().split('/').last();
if (et->is_host_file()){
transferFile(fileName,et->ed->text().toLatin1());
}else{
QFile f(fileName);
f.open(QIODevice::WriteOnly);
f.write(et->ed->text().toLatin1());
f.close();
}
}
void MainWindow::on_actionGuardar_Como_triggered()
{
QString fileName;
EditorTab *et = ed->getCurrentTab();
SimpleFileDialog sfd(&fileName,"Guardar Como",true);
if(sfd.exec()){
et->set_host_file(sfd.host_selected());
if (sfd.host_selected()){
et->saveFile(fileName);
ed->getTabWidget()->setTabText(ed->getTabWidget()->currentIndex(),QDir().absoluteFilePath(fileName));
}
else{
QString path = term->get_target_current_dir();
path = path == "/" ? path + fileName : path + "/" + fileName;
ed->getTabWidget()->setTabText(ed->getTabWidget()->currentIndex(),"(target)"+path);
et->saveFile(path);
}
}
}
void MainWindow::on_actionArchivo_Nuevo_triggered()
{
QString name;
SimpleFileDialog sfd(&name,"Nuevo");
if(sfd.exec()){
ed->addTab(new EditorTab(),name);
}
}