comparison data/fileio/RemoteFile.cpp @ 279:7802b0e2b0ff

* Encoded entities in file name when saving wave-file model * Proper handling for percent-encodings in URLs for RemoteFile, and for queries in URLs
author Chris Cannam
date Fri, 13 Jul 2007 10:51:15 +0000
parents 9a13687c078b
children 557e00480279
comparison
equal deleted inserted replaced
278:9a13687c078b 279:7802b0e2b0ff
62 connect(m_http, SIGNAL(done(bool)), this, SLOT(done(bool))); 62 connect(m_http, SIGNAL(done(bool)), this, SLOT(done(bool)));
63 connect(m_http, SIGNAL(dataReadProgress(int, int)), 63 connect(m_http, SIGNAL(dataReadProgress(int, int)),
64 this, SLOT(dataReadProgress(int, int))); 64 this, SLOT(dataReadProgress(int, int)));
65 connect(m_http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), 65 connect(m_http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
66 this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader &))); 66 this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader &)));
67 QString path = url.path(); 67
68 std::cerr << "RemoteFile: path is \"" << path.toStdString() << "\"" << std::endl; 68 // I don't quite understand this. url.path() returns a path
69 // without percent encoding; for example, spaces appear as
70 // literal spaces. This generally won't work if sent to the
71 // server directly. You can retrieve a correctly encoded URL
72 // from QUrl using url.toEncoded(), but that gives you the
73 // whole URL; there doesn't seem to be any way to retrieve
74 // only an encoded path. Furthermore there doesn't seem to be
75 // any way to convert a retrieved path into an encoded path
76 // without explicitly specifying that you don't want the path
77 // separators ("/") to be encoded. (Besides being painful to
78 // manage, I don't see how this can work correctly in any case
79 // where a percent-encoded "/" is supposed to appear within a
80 // path element?) There also seems to be no way to retrieve
81 // the path plus query string, i.e. everything that I need to
82 // send to the HTTP server. And no way for QHttp to take a
83 // QUrl argument. I'm obviously missing something.
84
85 // So, two ways to do this: query the bits from the URL,
86 // encode them individually, and glue them back together
87 // again...
88 /*
89 QString path = QUrl::toPercentEncoding(url.path(), "/");
90 QList<QPair<QString, QString> > query = url.queryItems();
91 if (!query.empty()) {
92 QStringList q2;
93 for (QList<QPair<QString, QString> >::iterator i = query.begin();
94 i != query.end(); ++i) {
95 q2.push_back(QString("%1=%3")
96 .arg(QString(QUrl::toPercentEncoding(i->first)))
97 .arg(QString(QUrl::toPercentEncoding(i->second))));
98 }
99 path = QString("%1%2%3")
100 .arg(path).arg("?")
101 .arg(q2.join("&"));
102 }
103 */
104
105 // ...or, much simpler but relying on knowledge about the
106 // scheme://host/path/path/query etc format of the URL, we can
107 // get the whole URL ready-encoded and then split it on "/" as
108 // appropriate...
109
110 QString path = "/" + QString(url.toEncoded()).section('/', 3);
111
112 std::cerr << "RemoteFile: path is \""
113 << path.toStdString() << "\"" << std::endl;
114
69 m_http->get(path, m_localFile); 115 m_http->get(path, m_localFile);
70 116
71 } else if (scheme == "ftp") { 117 } else if (scheme == "ftp") {
72 118
73 m_ok = true; 119 m_ok = true;