-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathModem.cpp
95 lines (76 loc) · 1.91 KB
/
Modem.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
#include "Modem.h"
#include "ui_modem.h"
#include "Ymodem.h"
#include <QMessageBox>
Modem::Modem(QWidget *parent) :
QDialog(parent),
ui(new Ui::Modem)
{
ui->setupUi(this);
ym = new Ymodem(this);
connect(ym, SIGNAL(showTransfer(int, int, float)), this, SLOT(showTransfer(int, int, float)));
connect(ym, SIGNAL(finished()), this, SLOT(closed()));
}
Modem::~Modem()
{
delete ui;
}
void Modem::getFile(QString &name)
{
name = filename;
}
void Modem::setFile(QString &name)
{
filename = name;
}
void Modem::showTransfer(int total, int remain, float speed)
{
float p;
QString fmt;
p = ((total - remain)/(float)total) * 100;
fmt = fmt.fromLocal8Bit("%1%").arg(QString::number(p, 'f', 2));
ui->progress->setValue((int)p);
ui->progress->setFormat(fmt);
fmt = fmt.asprintf("速度:%.2fKB/S 剩余:%d/%dKB",
speed/1024, remain/1024, total/1024);
showStatus(fmt);
}
void Modem::startTransfer(char type)
{
showTransfer(1, 1, 0);
show();
ym->setModemMode(type);
ym->start();
}
void Modem::putData(const QByteArray &data)
{
ym->put(data);
}
void Modem::showStatus(const char *s)
{
ui->lbmsg->setText(s);
}
void Modem::showStatus(QString &s)
{
ui->lbmsg->setText(s);
}
void Modem::closed()
{
emit exitTransfer();
}
void Modem::closeEvent(QCloseEvent *event)
{
QMessageBox::StandardButton button;
button = QMessageBox::question(this, tr("退出程序"),
QString(tr("警告:任务正在运行中,是否结束操作退出?")),
QMessageBox::Yes | QMessageBox::No);
if (button == QMessageBox::No)
{
event->ignore(); //忽略退出信号,程序继续运行
}
else if (button == QMessageBox::Yes)
{
event->accept(); //接受退出信号,程序退出
ym->close();
}
}