Skip to content

Commit

Permalink
添加第一版
Browse files Browse the repository at this point in the history
  • Loading branch information
heyuanjie committed Jan 4, 2017
1 parent 20ea689 commit e49e2a5
Show file tree
Hide file tree
Showing 30 changed files with 2,844 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Modem/Modem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "Modem.h"
#include "ui_modem.h"

#include "Ymodem.h"

Modem::Modem(QWidget *parent) :
QDialog(parent),
ui(new Ui::Modem)
{
ui->setupUi(this);

ym = new Ymodem(this);
connect(ym, &ym->showTransfer, this, &this->showTransfer);
connect(ym, &ym->finished, this, &this->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', 1));
ui->progress->setValue((int)p);
ui->progress->setFormat(fmt);
}

void Modem::startTransfer(char type)
{
show();
ym->start();
}

void Modem::putData(const QByteArray &data)
{
ym->put(data);
}

void Modem::showStatus(const char *s)
{
ui->lbmsg->setText(s);
}

void Modem::closed()
{
emit exitTransfer();
}
42 changes: 42 additions & 0 deletions Modem/Modem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef MODEM_H
#define MODEM_H

#include <QDialog>

namespace Ui {
class Modem;
}

class Ymodem;

class Modem : public QDialog
{
Q_OBJECT

public:
explicit Modem(QWidget *parent = 0);
~Modem();

void setFile(QString &name);
void getFile(QString &name);
void startTransfer(char type = 'C');
void showStatus(const char *s);

public Q_SLOTS:
void putData(const QByteArray &data);

private Q_SLOTS:
void showTransfer(int total, int remain, float speed);
void closed();

Q_SIGNALS:
void outData(const QByteArray &data);
void exitTransfer();

private:
Ui::Modem *ui;
Ymodem *ym;
QString filename;
};

#endif // MODEM_H
Loading

0 comments on commit e49e2a5

Please sign in to comment.