/
uploaddialog.cpp
99 lines (79 loc) · 3.11 KB
/
uploaddialog.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
96
97
98
99
/*
uploadDialog
Copyright (c) 2008-2009 by Alexander Kazarin <boiler@co.ru>
2011 Evgeny Khryukin
***************************************************************************
* *
* 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 <QFileInfo>
#include "uploaddialog.h"
#include "uploadmanager.h"
#include "options.h"
uploadDialog::uploadDialog(QWidget *p)
: QDialog(p, Qt::MSWindowsFixedSizeDialogHint)
{
ui.setupUi(this);
ui.progressBar->setValue(0);
connect(ui.btnUploadCancel, SIGNAL(clicked()), this, SIGNAL(canceled()));
connect(ui.btnUploadCancel, SIGNAL(clicked()), this, SLOT(close()));
setAttribute(Qt::WA_DeleteOnClose, true);
netman = new UploadManager(this);
connect(netman, SIGNAL(statusText(QString)), this, SLOT(setStatus(QString)));
connect(netman, SIGNAL(transferProgress(qint64,qint64)),this, SLOT(progress(qint64,qint64)));
connect(netman, SIGNAL(uploadFileURL(QString)), this, SIGNAL(fileUrl(QString)));
connect(netman, SIGNAL(uploaded()), this, SLOT(setDone()));
connect(netman, SIGNAL(uploadFileURL(QString)), this, SLOT(setLink(QString)));
}
uploadDialog::~uploadDialog()
{
}
void uploadDialog::setFilename(const QString& str)
{
ui.labelFile->setText(tr("File: ") + str);
setWindowTitle(O_M(MUploading) + " - " + str);
}
void uploadDialog::start(const QString& fileName)
{
QFileInfo fi(fileName);
setFilename(fi.fileName());
ui.progressBar->setValue(0);
ui.labelLink->setVisible(false);
utime.start();
netman->go(fileName);
}
void uploadDialog::progress(qint64 cBytes, qint64 totalBytes)
{
ui.labelStatus->setText(O_M(MUploading)+"...");
ui.labelProgress->setText(tr("Progress: ") + QString::number(cBytes) + " / " + QString::number(totalBytes));
ui.progressBar->setMaximum(totalBytes);
ui.progressBar->setValue(cBytes);
setWindowTitle("[" + ui.progressBar->text() + "] - " + O_M(MUploading)+"...");
QTime etime(0,0,0);
int elapsed = utime.elapsed();
etime = etime.addMSecs(elapsed);
ui.labelETime->setText(tr("Elapsed time: ") + etime.toString("hh:mm:ss") );
float speed_kbsec = (elapsed == 0) ? 0 : (cBytes / (((float)elapsed)/1000))/1024;
if (speed_kbsec > 0)
ui.labelSpeed->setText(tr("Speed: ")+QString::number(speed_kbsec)+tr(" kb/sec"));
if (cBytes == totalBytes)
ui.labelStatus->setText(tr("Upload completed. Waiting for verification."));
}
void uploadDialog::setDone()
{
if(netman->success())
ui.btnUploadCancel->setText(tr("Done"));
else
ui.btnUploadCancel->setText(tr("Close"));
emit finished();
}
void uploadDialog::setLink(const QString &link)
{
ui.labelLink->setVisible(true);
ui.labelLink->setText(tr("Link: <a href=\"%1\">%2</a>").arg(link, link.left(30)+"..."));
}