Changeset 769 for trunk/examples/network
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/examples/network/fortuneclient/fortuneclient.pro
r561 r769 13 13 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) 14 14 HEADERS += $$QT_SOURCE_TREE/examples/network/qftp/sym_iap_util.h 15 LIBS += -lesock 15 LIBS += -lesock -lcommdb -linsock # For IAP selection 16 16 TARGET.CAPABILITY = "NetworkServices ReadUserData WriteUserData" 17 17 TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 -
trunk/examples/network/fortuneserver/fortuneserver.pro
r561 r769 14 14 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) 15 15 HEADERS += $$QT_SOURCE_TREE/examples/network/qftp/sym_iap_util.h 16 LIBS += -lesock 16 LIBS += -lesock -lcommdb -linsock # For IAP selection 17 17 TARGET.CAPABILITY = "All -TCB" 18 18 TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 -
trunk/examples/network/googlesuggest/googlesuggest.cpp
r651 r769 233 233 } 234 234 //! [9] 235 -
trunk/examples/network/googlesuggest/searchbox.cpp
r651 r769 71 71 } 72 72 //! [2] 73 -
trunk/examples/network/http/httpwindow.cpp
r651 r769 50 50 { 51 51 #ifndef QT_NO_OPENSSL 52 urlLineEdit = new QLineEdit("https:// ");52 urlLineEdit = new QLineEdit("https://qt.nokia.com/"); 53 53 #else 54 urlLineEdit = new QLineEdit("http:// ");54 urlLineEdit = new QLineEdit("http://qt.nokia.com/"); 55 55 #endif 56 56 … … 71 71 progressDialog = new QProgressDialog(this); 72 72 73 http = new QHttp(this);74 75 73 connect(urlLineEdit, SIGNAL(textChanged(QString)), 76 74 this, SLOT(enableDownloadButton())); 77 connect(http, SIGNAL(requestFinished(int,bool)), 78 this, SLOT(httpRequestFinished(int,bool))); 79 connect(http, SIGNAL(dataReadProgress(int,int)), 80 this, SLOT(updateDataReadProgress(int,int))); 81 connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), 82 this, SLOT(readResponseHeader(QHttpResponseHeader))); 83 connect(http, SIGNAL(authenticationRequired(QString,quint16,QAuthenticator*)), 84 this, SLOT(slotAuthenticationRequired(QString,quint16,QAuthenticator*))); 75 76 connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), 77 this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*))); 85 78 #ifndef QT_NO_OPENSSL 86 connect( http, SIGNAL(sslErrors(QList<QSslError>)),87 this, SLOT(sslErrors(Q List<QSslError>)));79 connect(&qnam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), 80 this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>))); 88 81 #endif 89 82 connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); … … 105 98 } 106 99 100 void HttpWindow::startRequest(QUrl url) 101 { 102 reply = qnam.get(QNetworkRequest(url)); 103 connect(reply, SIGNAL(finished()), 104 this, SLOT(httpFinished())); 105 connect(reply, SIGNAL(readyRead()), 106 this, SLOT(httpReadyRead())); 107 connect(reply, SIGNAL(downloadProgress(qint64,qint64)), 108 this, SLOT(updateDataReadProgress(qint64,qint64))); 109 } 110 107 111 void HttpWindow::downloadFile() 108 112 { 109 QUrl url(urlLineEdit->text()); 113 url = urlLineEdit->text(); 114 110 115 QFileInfo fileInfo(url.path()); 111 116 QString fileName = fileInfo.fileName(); … … 133 138 } 134 139 135 QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;136 http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());137 138 if (!url.userName().isEmpty())139 http->setUser(url.userName(), url.password());140 141 httpRequestAborted = false;142 QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/");143 if (path.isEmpty())144 path = "/";145 httpGetId = http->get(path, file);146 140 147 141 progressDialog->setWindowTitle(tr("HTTP")); 148 142 progressDialog->setLabelText(tr("Downloading %1.").arg(fileName)); 149 143 downloadButton->setEnabled(false); 144 145 // schedule the request 146 httpRequestAborted = false; 147 startRequest(url); 150 148 } 151 149 … … 154 152 statusLabel->setText(tr("Download canceled.")); 155 153 httpRequestAborted = true; 156 http->abort();154 reply->abort(); 157 155 downloadButton->setEnabled(true); 158 156 } 159 157 160 void HttpWindow::httpRequestFinished(int requestId, bool error) 161 { 162 if (requestId != httpGetId) 163 return; 158 void HttpWindow::httpFinished() 159 { 164 160 if (httpRequestAborted) { 165 161 if (file) { … … 169 165 file = 0; 170 166 } 171 167 reply->deleteLater(); 172 168 progressDialog->hide(); 173 169 return; 174 170 } 175 171 176 if (requestId != httpGetId)177 return;178 179 172 progressDialog->hide(); 173 file->flush(); 180 174 file->close(); 181 175 182 if (error) { 176 177 QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); 178 if (reply->error()) { 183 179 file->remove(); 184 180 QMessageBox::information(this, tr("HTTP"), 185 181 tr("Download failed: %1.") 186 .arg(http->errorString())); 182 .arg(reply->errorString())); 183 downloadButton->setEnabled(true); 184 } else if (!redirectionTarget.isNull()) { 185 QUrl newUrl = url.resolved(redirectionTarget.toUrl()); 186 if (QMessageBox::question(this, tr("HTTP"), 187 tr("Redirect to %1 ?").arg(newUrl.toString()), 188 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { 189 url = newUrl; 190 reply->deleteLater(); 191 file->open(QIODevice::WriteOnly); 192 file->resize(0); 193 startRequest(url); 194 return; 195 } 187 196 } else { 188 197 QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName(); 189 198 statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName)); 190 } 191 192 downloadButton->setEnabled(true); 199 downloadButton->setEnabled(true); 200 } 201 202 reply->deleteLater(); 203 reply = 0; 193 204 delete file; 194 205 file = 0; 195 206 } 196 207 197 void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader) 198 { 199 switch (responseHeader.statusCode()) { 200 case 200: // Ok 201 case 301: // Moved Permanently 202 case 302: // Found 203 case 303: // See Other 204 case 307: // Temporary Redirect 205 // these are not error conditions 206 break; 207 208 default: 209 QMessageBox::information(this, tr("HTTP"), 210 tr("Download failed: %1.") 211 .arg(responseHeader.reasonPhrase())); 212 httpRequestAborted = true; 213 progressDialog->hide(); 214 http->abort(); 215 } 216 } 217 218 void HttpWindow::updateDataReadProgress(int bytesRead, int totalBytes) 208 void HttpWindow::httpReadyRead() 209 { 210 // this slot gets called everytime the QNetworkReply has new data. 211 // We read all of its new data and write it into the file. 212 // That way we use less RAM than when reading it at the finished() 213 // signal of the QNetworkReply 214 if (file) 215 file->write(reply->readAll()); 216 } 217 218 void HttpWindow::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes) 219 219 { 220 220 if (httpRequestAborted) … … 230 230 } 231 231 232 void HttpWindow::slotAuthenticationRequired( const QString &hostName, quint16,QAuthenticator *authenticator)232 void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authenticator) 233 233 { 234 234 QDialog dlg; … … 236 236 ui.setupUi(&dlg); 237 237 dlg.adjustSize(); 238 ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(hostName)); 239 238 ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host())); 239 240 // Did the URL have information? Fill the UI 241 // This is only relevant if the URL-supplied credentials were wrong 242 ui.userEdit->setText(url.userName()); 243 ui.passwordEdit->setText(url.password()); 244 240 245 if (dlg.exec() == QDialog::Accepted) { 241 246 authenticator->setUser(ui.userEdit->text()); … … 245 250 246 251 #ifndef QT_NO_OPENSSL 247 void HttpWindow::sslErrors( const QList<QSslError> &errors)252 void HttpWindow::sslErrors(QNetworkReply*,const QList<QSslError> &errors) 248 253 { 249 254 QString errorString; … … 254 259 } 255 260 256 if (QMessageBox::warning(this, tr("HTTP Example"),261 if (QMessageBox::warning(this, tr("HTTP"), 257 262 tr("One or more SSL errors has occurred: %1").arg(errorString), 258 263 QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) { 259 http->ignoreSslErrors();264 reply->ignoreSslErrors(); 260 265 } 261 266 } -
trunk/examples/network/http/httpwindow.h
r651 r769 44 44 45 45 #include <QDialog> 46 #include <QNetworkAccessManager> 47 #include <QUrl> 46 48 47 49 QT_BEGIN_NAMESPACE 48 50 class QDialogButtonBox; 49 51 class QFile; 50 class QHttp;51 class QHttpResponseHeader;52 52 class QLabel; 53 53 class QLineEdit; … … 56 56 class QSslError; 57 57 class QAuthenticator; 58 class QNetworkReply; 59 60 58 61 QT_END_NAMESPACE 59 62 … … 65 68 HttpWindow(QWidget *parent = 0); 66 69 70 void startRequest(QUrl url); 71 67 72 private slots: 68 73 void downloadFile(); 69 74 void cancelDownload(); 70 void http RequestFinished(int requestId, bool error);71 void readResponseHeader(const QHttpResponseHeader &responseHeader);72 void updateDataReadProgress( int bytesRead, inttotalBytes);75 void httpFinished(); 76 void httpReadyRead(); 77 void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes); 73 78 void enableDownloadButton(); 74 void slotAuthenticationRequired( const QString &, quint16,QAuthenticator *);79 void slotAuthenticationRequired(QNetworkReply*,QAuthenticator *); 75 80 #ifndef QT_NO_OPENSSL 76 void sslErrors( const QList<QSslError> &errors);81 void sslErrors(QNetworkReply*,const QList<QSslError> &errors); 77 82 #endif 78 83 … … 86 91 QDialogButtonBox *buttonBox; 87 92 88 QHttp *http; 93 QUrl url; 94 QNetworkAccessManager qnam; 95 QNetworkReply *reply; 89 96 QFile *file; 90 97 int httpGetId; -
trunk/examples/network/http/main.cpp
r651 r769 47 47 { 48 48 QApplication app(argc, argv); 49 qWarning("The usage of QHttp is not recommended anymore, please use QNetworkAccessManager.");50 49 HttpWindow httpWin; 51 50 httpWin.show(); -
trunk/examples/network/loopback/dialog.cpp
r651 r769 45 45 #include "dialog.h" 46 46 47 #if !defined(Q_OS_WINCE) 47 #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) 48 48 static const int TotalBytes = 50 * 1024 * 1024; 49 49 #else 50 50 static const int TotalBytes = 5 * 1024 * 1024; 51 51 #endif 52 static const int PayloadSize = 6 5536;52 static const int PayloadSize = 64 * 1024; // 64 KB 53 53 54 54 Dialog::Dialog(QWidget *parent) … … 131 131 void Dialog::startTransfer() 132 132 { 133 // called when the TCP client connected to the loopback server 133 134 bytesToWrite = TotalBytes - (int)tcpClient.write(QByteArray(PayloadSize, '@')); 134 135 clientStatusLabel->setText(tr("Connected")); … … 156 157 void Dialog::updateClientProgress(qint64 numBytes) 157 158 { 159 // callen when the TCP client has written some bytes 158 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 164 bytesToWrite -= (int)tcpClient.write(QByteArray(qMin(bytesToWrite, PayloadSize), '@')); 161 165 -
trunk/examples/network/network-chat/chatdialog.cpp
r651 r769 80 80 cursor.movePosition(QTextCursor::End); 81 81 QTextTable *table = cursor.insertTable(1, 2, tableFormat); 82 table->cellAt(0, 0).firstCursorPosition().insertText( "<"+ from + "> ");82 table->cellAt(0, 0).firstCursorPosition().insertText('<' + from + "> "); 83 83 table->cellAt(0, 1).firstCursorPosition().insertText(message); 84 84 QScrollBar *bar = textEdit->verticalScrollBar(); -
trunk/examples/network/network-chat/client.cpp
r651 r769 70 70 QString Client::nickName() const 71 71 { 72 return QString(peerManager->userName()) + "@"+ QHostInfo::localHostName()73 + ":"+ QString::number(server.serverPort());72 return QString(peerManager->userName()) + '@' + QHostInfo::localHostName() 73 + ':' + QString::number(server.serverPort()); 74 74 } 75 75 -
trunk/examples/network/network-chat/connection.cpp
r651 r769 84 84 85 85 QByteArray msg = message.toUtf8(); 86 QByteArray data = "MESSAGE " + QByteArray::number(msg.size()) + " "+ msg;86 QByteArray data = "MESSAGE " + QByteArray::number(msg.size()) + ' ' + msg; 87 87 return write(data) == data.size(); 88 88 } … … 119 119 } 120 120 121 username = QString(buffer) + "@" + peerAddress().toString() + ":"121 username = QString(buffer) + '@' + peerAddress().toString() + ':' 122 122 + QString::number(peerPort()); 123 123 currentDataType = Undefined; … … 163 163 { 164 164 QByteArray greeting = greetingMessage.toUtf8(); 165 QByteArray data = "GREETING " + QByteArray::number(greeting.size()) + " "+ greeting;165 QByteArray data = "GREETING " + QByteArray::number(greeting.size()) + ' ' + greeting; 166 166 if (write(data) == data.size()) 167 167 isGreetingMessageSent = true; -
trunk/examples/network/network-chat/network-chat.pro
r561 r769 22 22 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) 23 23 HEADERS += $$QT_SOURCE_TREE/examples/network/qftp/sym_iap_util.h 24 LIBS += -lesock -lconnmon -lcharconv -linsock 24 LIBS += -lesock -lcommdb -linsock # For IAP selection 25 LIBS += -lcharconv 25 26 TARGET.CAPABILITY = "NetworkServices ReadUserData WriteUserData" 26 27 TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 -
trunk/examples/network/network-chat/peermanager.cpp
r651 r769 62 62 int index = environment.indexOf(QRegExp(string)); 63 63 if (index != -1) { 64 QStringList stringList = environment.at(index).split( "=");64 QStringList stringList = environment.at(index).split('='); 65 65 if (stringList.size() == 2) { 66 66 username = stringList.at(1).toUtf8(); -
trunk/examples/network/qftp/ftpwindow.cpp
r651 r769 325 325 fileList->clear(); 326 326 isDirectory.clear(); 327 currentPath += "/" + name; 327 currentPath += '/'; 328 currentPath += name; 328 329 ftp->cd(name); 329 330 ftp->list(); -
trunk/examples/network/qftp/sym_iap_util.h
r651 r769 61 61 62 62 _LIT(KIapNameSetting, "IAP\\Name"); // text - mandatory 63 _LIT(KIapTableIdField, "IAP\Id"); 63 64 _LIT(KIapDialogPref, "IAP\\DialogPref"); // TUnit32 - optional 64 65 _LIT(KIapService, "IAP\\IAPService"); // TUnit32 - mandatory … … 299 300 return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length()); 300 301 #else 301 return QString ::fromUtf16(aDescriptor.Ptr(), aDescriptor.Length());302 return QString((const QChar *)aDescriptor.Ptr(), aDescriptor.Length()); 302 303 #endif 303 304 } … … 368 369 369 370 socketServ.Connect(); 371 372 TCommDbConnPref prefs; 373 prefs.SetDialogPreference(ECommDbDialogPrefPrompt); 374 370 375 connection.Open(socketServ); 371 connection.Start( );376 connection.Start(prefs); 372 377 373 378 connection.GetDesSetting(TPtrC(KIapNameSetting), iapName); 374 375 379 //connection.Stop(); 376 380 … … 379 383 380 384 int error = 0; 381 if(!qt_SetDefaultIapName(strIapName, error)) { 382 //printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); 383 strIapName = QString(""); 385 if(!strIapName.isEmpty()) { 386 if(!qt_SetDefaultIapName(strIapName, error)) { 387 //printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); 388 strIapName = QString(""); 389 } 384 390 } 385 391 -
trunk/examples/network/securesocketclient/sslclient.cpp
r651 r769 178 178 { 179 179 QString input = form->sessionInput->text(); 180 appendString(input + "\n");180 appendString(input + '\n'); 181 181 socket->write(input.toUtf8() + "\r\n"); 182 182 form->sessionInput->clear(); -
trunk/examples/network/torrent/trackerclient.cpp
r651 r769 106 106 if (fullUrl.contains("?passkey")) { 107 107 passkey = metaInfo.announceUrl().mid(fullUrl.indexOf("?passkey"), -1); 108 passkey += "&";108 passkey += '&'; 109 109 } 110 110
Note:
See TracChangeset
for help on using the changeset viewer.