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
|
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
2 of the License, or (at your option) any later version.
*/
#include <QLineEdit>
#include <QSpinBox>
#include <QLabel>
#include <QPushButton>
#include <QFormLayout>
#include <QTextEdit>
#include <QTextBlock>
#include "smdialog.h"
#include "helper.h"
#include "unpacker.h"
SeriesPartsDialog::SeriesPartsDialog(QWidget *parent, Qt::WindowFlags f) : SmDialog(parent, f){
QFormLayout *mainLayout = new QFormLayout;
mSubtitle = new QLineEdit;
mSubtitle->setMinimumWidth(300);
mainLayout->addRow(tr("&Subtitle:"), mSubtitle);
mPartno = new QSpinBox;
mPartno->setValue(0);
mPartno->setMinimum(0);
mainLayout->addRow(tr("&Part no."), mPartno);
mOk = new QPushButton(tr("Ok"));
connect(mOk, SIGNAL(clicked()), this, SLOT(accept()));
mCancel = new QPushButton(tr("Cancel"));
connect(mCancel, SIGNAL(clicked()), this, SLOT(reject()));
mCancel->setDefault(true);
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
buttonLayout->addWidget(mOk);
buttonLayout->addWidget(mCancel);
mainLayout->addRow(buttonLayout);
setLayout(mainLayout);
}
QString SeriesPartsDialog::subtitle() const {
return mSubtitle->text();
}
void SeriesPartsDialog::setSubtitle(const QString &subtitle){
mSubtitle->setText(subtitle);
}
int SeriesPartsDialog::partNo() const {
return mPartno->value();
}
void SeriesPartsDialog::setPartno(int partNo){
mPartno->setValue(partNo);
}
UnpackDialog::UnpackDialog(QWidget *parent, Qt::WindowFlags f) : SmDialog(parent, f){
QVBoxLayout *mainLayout = new QVBoxLayout;
mCurrentL = new QLabel(tr("Unpacking:"));
mCurrentL->setMinimumWidth(400);
mainLayout->addWidget(mCurrentL);
mOutput = new QTextEdit;
mOutput->setMinimumHeight(400);
mainLayout->addWidget(mOutput);
QHBoxLayout *buttonLayout = new QHBoxLayout;
mClose = new QPushButton(tr("Close"));
connect(mClose, SIGNAL(clicked()), this, SLOT(hide()));
buttonLayout->addStretch();
buttonLayout->addWidget(mClose);
buttonLayout->addStretch();
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
mUnpacker = new Unpacker(this);
connect(mUnpacker, SIGNAL(outputRead(QByteArray)), this, SLOT(addProcOutput(QByteArray)));
connect(mUnpacker, SIGNAL(unpackStarted(QString)), this, SLOT(newPackage(QString)));
connect(mUnpacker, SIGNAL(unpackDone()), this, SLOT(unpackDone()));
}
void UnpackDialog::setCurrentLabel(const QString &cur){
mCurrentL->setText(cur);
}
void UnpackDialog::clearOutput(){
mOutput->clear();
}
void UnpackDialog::setCloseEnabled(bool enabled){
mClose->setEnabled(enabled);
}
void UnpackDialog::clearCommandQueue(){
mCommandQueue.clear();
}
void UnpackDialog::addOutput(const QString &msg, const QString &prepend){
QTextCursor cur = mOutput->textCursor();
QTextBlock block = cur.block();
if(!block.text().isEmpty()){
cur.insertBlock();
}
if(!prepend.isEmpty()){
QTextCharFormat fmtRed;
fmtRed.setForeground(QBrush(Qt::red));
cur.setCharFormat(fmtRed);
cur.insertText(prepend);
}
QTextCharFormat fmtBlack;
fmtBlack.setForeground(QBrush(Qt::black));
cur.setCharFormat(fmtBlack);
cur.insertText(msg);
mOutput->ensureCursorVisible();
}
void UnpackDialog::addProcOutput(const QByteArray &data){
QTextCursor cur = mOutput->textCursor();
QTextBlock block = cur.block();
if(!block.text().isEmpty()){
cur.insertBlock();
}
QString dataStr = QString(data);
cur.insertText(dataStr);
mOutput->ensureCursorVisible();
}
void UnpackDialog::appendCommand(const QStringList &cmd){
mCommandQueue.append(cmd);
}
void UnpackDialog::doIt(){
mUnpacker->setCommands(mCommandQueue);
mUnpacker->start();
}
void UnpackDialog::newPackage(const QString &package){
setCurrentLabel(package);
addOutput(" ", tr("\n[NEW ARCHIVE]"));
}
void UnpackDialog::unpackDone(){
setCloseEnabled(true);
emit workFinished();
close();
}
|