-
Notifications
You must be signed in to change notification settings - Fork 2
/
update698.cpp
87 lines (75 loc) · 2.29 KB
/
update698.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
#include "update698.h"
#include "ui_update698.h"
#include <QFileDialog>
#include <QDir>
#include <QMessageBox>
#include <QSettings>
update698::update698(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::update698),
m_settings(new QSettings("config/config.ini", QSettings::IniFormat, this))
{
ui->setupUi(this);
connect(ui->btn_browse, SIGNAL(clicked(bool)), this, SLOT(browse()));
int size = m_settings->value("fileBlocks/defaultSize").toInt();
m_oneBlockSize = (size > 0 ? size : 512);
ui->buttonGroup->setId(ui->rbtn_256, 0);
ui->buttonGroup->setId(ui->rbtn_512, 1);
ui->buttonGroup->setId(ui->rbtn_1024, 2);
QObject::connect(ui->buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(btnToggle(int)));
ui->buttonGroup->button(m_settings->value("fileBlocks/rbtnIndex").toInt()%3)->setChecked(true);
}
update698::~update698()
{
m_settings->setValue("fileBlocks/rbtnIndex", ui->buttonGroup->checkedId());
delete ui;
}
void update698::on_btn_exit_clicked(bool)
{
this->close();
}
void update698::btnToggle(int i)
{
switch (i) {
case 0:
m_oneBlockSize = 256;
break;
case 1:
m_oneBlockSize = 512;
break;
case 2:
m_oneBlockSize = 1024;
break;
default:
m_oneBlockSize = 512;
break;
}
}
void update698::browse()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"),
QDir::homePath(),
tr("all file (*)"));
ui->lineEdit_filename->setText(filename);
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, tr("open error"),
tr("can not open this file!"));
return;
}
file.seek(0);
m_fileblock = file.readAll();
file.close();
calcBlocks();
}
void update698::calcBlocks()
{
int i = 0;
m_filesize = m_fileblock.count();
m_blockCount = m_filesize/m_oneBlockSize + (((m_filesize%m_oneBlockSize)==0) ? 0 : 1);
m_blockList.clear();
for (i = 0; (i + m_oneBlockSize) <= m_filesize; i += m_oneBlockSize)
m_blockList.append(m_fileblock.mid(i, m_oneBlockSize));
if ((m_filesize-i) > 0)
m_blockList.append(m_fileblock.mid(i, (m_filesize-i)));
}