22 #include <QApplication> 23 #include <QCloseEvent> 24 #include <QGridLayout> 27 #include <QProgressBar> 28 #include <QPushButton> 31 #include <QVBoxLayout> 35 #include <KLocalizedString> 36 #include <KStandardGuiItem> 45 const QUrl &url, quint64 size,
52 m_lbl_length(Q_NULLPTR),
53 m_progress(Q_NULLPTR),
54 m_stat_transfer(Q_NULLPTR),
55 m_stat_bytes(Q_NULLPTR),
59 m_bits_per_sample(bits),
71 setWindowTitle(
m_url.toString());
74 QVBoxLayout *top_layout =
new QVBoxLayout(
this);
76 if (!top_layout)
return;
77 top_layout->setMargin(10);
78 top_layout->setSpacing(10);
81 QGridLayout *info_layout =
new QGridLayout();
82 Q_ASSERT(info_layout);
83 if (!info_layout)
return;
84 info_layout->setSpacing(0);
85 info_layout->setColumnStretch(0, 0);
86 info_layout->setColumnStretch(1, 100);
87 top_layout->addLayout(info_layout);
91 i18nc(
"file progress dialog",
"File: "), 0, 0))
return;
98 i18nc(
"file progress dialog",
"Length: "), 1, 0))
return;
102 setLength(quint64(samples) * quint64(tracks));
106 i18nc(
"file progress dialog",
"Sample Rate: "), 2, 0))
return;
107 text = i18nc(
"file progress dialog, %1=number of samples per second",
108 "%1 Samples per second", rate);
113 i18nc(
"file progress dialog",
"Resolution: "), 3, 0))
return;
114 text = i18nc(
"file progress dialog, " 115 "%1=number of bits per sample (8, 16, 24...)",
116 "%1 Bits per sample", bits);
121 i18nc(
"file progress dialog",
"Tracks: "), 4, 0))
return;
124 text = i18nc(
"number of tracks",
"1 (mono)");
127 text = i18nc(
"number of tracks",
"2 (stereo)");
130 text = i18nc(
"number of tracks",
"4 (quadro)");
133 text = text.setNum(tracks);
146 QGridLayout *status_layout =
new QGridLayout();
147 Q_ASSERT(status_layout);
148 if (!status_layout)
return;
149 status_layout->setSpacing(1);
150 status_layout->setColumnMinimumWidth(1, 20);
151 top_layout->addLayout(status_layout);
169 QPushButton *bt_cancel =
new QPushButton(
this);
171 if (!bt_cancel)
return;
172 KGuiItem::assign(bt_cancel, KStandardGuiItem::cancel());
173 bt_cancel->setFixedSize(bt_cancel->sizeHint());
174 bt_cancel->setFocus();
175 bt_cancel->setShortcut(Qt::Key_Escape);
177 top_layout->addWidget(bt_cancel, 0, Qt::AlignRight);
180 top_layout->activate();
181 setFixedHeight(sizeHint().height());
182 setMinimumWidth((sizeHint().width() * 110) / 100);
206 i18n(
"Do you really want to abort the operation?")) !=
227 int width =
m_lbl_url->frameRect().width();
228 QString url =
m_url.toString();
231 while (
m_lbl_url->sizeHint().width() > width) {
233 url =
m_url.toString();
234 int len = url.length();
235 if (len <= todel)
break;
236 url = url.left((len-todel)/2) +
_(
"...") +
237 url.right((len-todel)/2 + 4);
247 const QString text,
int row,
int col)
249 QLabel *label =
new QLabel(
this);
251 if (!label)
return Q_NULLPTR;
253 label->setText(text);
255 label->setFixedHeight(label->sizeHint().height());
256 label->setMinimumWidth(label->sizeHint().width());
258 layout->addWidget(label, row, col);
274 num = num.sprintf(
"%1.1f", rate / 1024.0);
276 quint64 ms = qMin(quint64(rest * 1000.0), 24ULL * 60ULL * 60ULL * 1000ULL);
277 text = i18nc(
"file progress dialog, " 278 "%1=transfer rate, %2=remaining duration",
279 "%1 kB/s (%2 remaining)", num,
280 KFormat().formatDecimalDuration(ms));
285 text = i18nc(
"file progress dialog, " 286 "%1=number of loaded/saved megabytes, " 287 "%2=number of total megabytes to load or save",
288 "%1 MB of %2 MB done",
289 num1.sprintf(
"%1.1f", pos / (1024.0 * 1024.0)),
290 num2.sprintf(
"%1.1f",
m_size / (1024.0 * 1024.0)));
296 Q_ASSERT(this->thread() == QThread::currentThread());
297 Q_ASSERT(this->thread() == qApp->thread());
299 t.setSingleShot(
true);
301 while (t.isActive()) {
302 qApp->sendPostedEvents();
303 qApp->processEvents();
311 quint64 pos =
static_cast<quint64
>(percent * qreal(
m_size) / 100.0);
323 (static_cast<double>(pos) / static_cast<double>(
m_size)) * 100.0);
332 "%1=Progress in percentage, %2=path to file",
334 percent,
m_url.toString()
336 setWindowTitle(newcap);
342 double seconds =
m_time.elapsed() / 1000.0;
343 double rate = pos / seconds;
346 rest =
static_cast<double>(
m_size - pos) / rate;
365 text = i18nc(
"file progress dialog, %1=a number of samples",
366 "%1 samples", samples);
QProgressBar * m_progress
void setBytePosition(quint64 pos)
QString Q_DECL_EXPORT ms2string(double ms, int precision=6)
void setLength(quint64 samples)
void setValue(qreal percent)
void updateStatistics(double rate, double rest, quint64 pos)
virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
virtual void closeEvent(QCloseEvent *e) Q_DECL_OVERRIDE
static int warningYesNo(QWidget *widget, QString message, QString caption=QString(), const QString buttonYes=QString(), const QString buttonNo=QString(), const QString &dontAskAgainName=QString())
QLabel * addInfoLabel(QGridLayout *layout, const QString text, int row, int column)
FileProgress(QWidget *parent, const QUrl &url, quint64 size, sample_index_t samples, double rate, unsigned int bits, unsigned int tracks)