-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmainwindow.cpp
86 lines (71 loc) · 3.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QApplication>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// attach signals from listener to the terminal window
connect(&this->usbAlert, &qUSBListener::USBConnected,
this, &this->USBConnect);
connect(&this->usbAlert, &qUSBListener::USBDisconnected,
this, &this->USBDisconnect);
connect(&this->usbAlert, &qUSBListener::PortConnected,
this, &this->PortConnect);
connect(&this->usbAlert, &qUSBListener::PortDisconnected,
this, &this->PortDisconnect);
// set the model for the table view and the appearance of table
ui->tableView->setModel(&deviceList);
ui->tableView->setShowGrid(false);
ui->tableView->setSelectionBehavior( QAbstractItemView::SelectRows );
ui->tableView->setSelectionMode( QAbstractItemView::SingleSelection );
ui->tableView->setSortingEnabled(true);
// attach listener signals to the table view
connect(&this->usbAlert, &qUSBListener::USBConnected,
&this->deviceList, &UsbDeviceListModel::addDevice);
connect(&this->usbAlert, &qUSBListener::USBDisconnected,
&this->deviceList, &UsbDeviceListModel::removeDevice);
// start detection
usbAlert.start();
}
MainWindow::~MainWindow() {
usbAlert.stop();
delete ui;
}
void MainWindow::scrollWindow() {
QTextCursor c = ui->plainTextEdit->textCursor();
c.movePosition(QTextCursor::End);
ui->plainTextEdit->setTextCursor(c);
}
void MainWindow::USBConnect(usbDevice dev) {
ui->plainTextEdit->insertPlainText(QString("USB DEVICE CONNECTED: \n"));
ui->plainTextEdit->insertPlainText(QString(" VID: 0x%1 \n").arg(dev.VID, 4, 16, QLatin1Char('0') ));
ui->plainTextEdit->insertPlainText(QString(" PID: 0x%1 \n").arg(dev.PID, 4, 16, QLatin1Char('0') ));
ui->plainTextEdit->insertPlainText(" S\\N: ");
ui->plainTextEdit->insertPlainText(dev.serialNum);
ui->plainTextEdit->insertPlainText(QString("\n\n"));
scrollWindow();
}
void MainWindow::USBDisconnect(usbDevice dev) {
ui->plainTextEdit->insertPlainText(QString("USB DEVICE DISCONNECTED: \n"));
ui->plainTextEdit->insertPlainText(QString(" VID: 0x%1 \n").arg(dev.VID, 4, 16, QLatin1Char('0') ));
ui->plainTextEdit->insertPlainText(QString(" PID: 0x%1 \n").arg(dev.PID, 4, 16, QLatin1Char('0') ));
ui->plainTextEdit->insertPlainText(" S\\N: ");
ui->plainTextEdit->insertPlainText(dev.serialNum);
ui->plainTextEdit->insertPlainText(QString("\n\n"));
scrollWindow();
}
void MainWindow::PortConnect(QString name) {
ui->plainTextEdit->insertPlainText(QString("CONNECT: "));
ui->plainTextEdit->insertPlainText(name);
ui->plainTextEdit->insertPlainText(QString("\n\n"));
scrollWindow();
}
void MainWindow::PortDisconnect(QString name) {
ui->plainTextEdit->insertPlainText(QString("DISCONNECT: "));
ui->plainTextEdit->insertPlainText(name);
ui->plainTextEdit->insertPlainText(QString("\n\n"));
scrollWindow();
}