equal
deleted
inserted
replaced
1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the examples of the Qt Toolkit. |
7 ** This file is part of the examples of the Qt Toolkit. |
8 ** |
8 ** |
42 #include <QtGui> |
42 #include <QtGui> |
43 #include <QtNetwork> |
43 #include <QtNetwork> |
44 |
44 |
45 #include "dialog.h" |
45 #include "dialog.h" |
46 |
46 |
47 #if !defined(Q_OS_WINCE) |
47 #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
48 static const int TotalBytes = 50 * 1024 * 1024; |
48 static const int TotalBytes = 50 * 1024 * 1024; |
49 #else |
49 #else |
50 static const int TotalBytes = 5 * 1024 * 1024; |
50 static const int TotalBytes = 5 * 1024 * 1024; |
51 #endif |
51 #endif |
52 static const int PayloadSize = 65536; |
52 static const int PayloadSize = 64 * 1024; // 64 KB |
53 |
53 |
54 Dialog::Dialog(QWidget *parent) |
54 Dialog::Dialog(QWidget *parent) |
55 : QDialog(parent) |
55 : QDialog(parent) |
56 { |
56 { |
57 clientProgressBar = new QProgressBar; |
57 clientProgressBar = new QProgressBar; |
128 tcpServer.close(); |
128 tcpServer.close(); |
129 } |
129 } |
130 |
130 |
131 void Dialog::startTransfer() |
131 void Dialog::startTransfer() |
132 { |
132 { |
|
133 // called when the TCP client connected to the loopback server |
133 bytesToWrite = TotalBytes - (int)tcpClient.write(QByteArray(PayloadSize, '@')); |
134 bytesToWrite = TotalBytes - (int)tcpClient.write(QByteArray(PayloadSize, '@')); |
134 clientStatusLabel->setText(tr("Connected")); |
135 clientStatusLabel->setText(tr("Connected")); |
135 } |
136 } |
136 |
137 |
137 void Dialog::updateServerProgress() |
138 void Dialog::updateServerProgress() |
153 } |
154 } |
154 } |
155 } |
155 |
156 |
156 void Dialog::updateClientProgress(qint64 numBytes) |
157 void Dialog::updateClientProgress(qint64 numBytes) |
157 { |
158 { |
|
159 // callen when the TCP client has written some bytes |
158 bytesWritten += (int)numBytes; |
160 bytesWritten += (int)numBytes; |
159 if (bytesToWrite > 0) |
161 |
|
162 // only write more if not finished and when the Qt write buffer is below a certain size. |
|
163 if (bytesToWrite > 0 && tcpClient.bytesToWrite() <= 4*PayloadSize) |
160 bytesToWrite -= (int)tcpClient.write(QByteArray(qMin(bytesToWrite, PayloadSize), '@')); |
164 bytesToWrite -= (int)tcpClient.write(QByteArray(qMin(bytesToWrite, PayloadSize), '@')); |
161 |
165 |
162 clientProgressBar->setMaximum(TotalBytes); |
166 clientProgressBar->setMaximum(TotalBytes); |
163 clientProgressBar->setValue(bytesWritten); |
167 clientProgressBar->setValue(bytesWritten); |
164 clientStatusLabel->setText(tr("Sent %1MB") |
168 clientStatusLabel->setText(tr("Sent %1MB") |