本文整理汇总了C++中KUrl::setEncodedPathAndQuery方法的典型用法代码示例。如果您正苦于以下问题:C++ KUrl::setEncodedPathAndQuery方法的具体用法?C++ KUrl::setEncodedPathAndQuery怎么用?C++ KUrl::setEncodedPathAndQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KUrl
的用法示例。
在下文中一共展示了KUrl::setEncodedPathAndQuery方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handlePost
void HttpServer::handlePost(HttpClientHandler* hdlr,const QHttpRequestHeader & hdr,const QByteArray & data)
{
Out(SYS_WEB|LOG_DEBUG) << "POST " << hdr.path() << endl;
KUrl url;
url.setEncodedPathAndQuery(hdr.path());
WebContentGenerator* gen = content_generators.find(url.path());
if (gen)
{
if ((gen->getPermissions() == WebContentGenerator::LOGIN_REQUIRED && (!session.logged_in || !checkSession(hdr))) && WebInterfacePluginSettings::authentication())
{
// redirect to login page
redirectToLoginPage(hdlr);
}
else
{
gen->post(hdlr,hdr,data);
}
}
else
{
KUrl url;
url.setEncodedPathAndQuery(hdr.path());
QString path = commonDir() + url.path();
// first try the common dir
if (!bt::Exists(path)) // doesn't exist so it must be in the skin dir
path = skinDir() + url.path();
handleFile(hdlr,hdr,path);
}
}
示例2: post
void TorrentPostHandler::post(HttpClientHandler* hdlr, const QHttpRequestHeader& hdr, const QByteArray& data)
{
const char* ptr = data.data();
int len = data.size();
int pos = QString(data).indexOf("\r\n\r\n");
if (pos == -1 || pos + 4 >= len)
{
HttpResponseHeader rhdr(500);
server->setDefaultResponseHeaders(rhdr, "text/html", false);
hdlr->send500(rhdr, i18n("Invalid data received"));
return;
}
// save torrent to a temporary file
QString save_file = kt::DataDir() + "webgui_load_torrent";
QFile tmp_file(save_file);
if (!tmp_file.open(QIODevice::WriteOnly))
{
HttpResponseHeader rhdr(500);
server->setDefaultResponseHeaders(rhdr, "text/html", false);
hdlr->send500(rhdr, i18n("Failed to open temporary file"));
return;
}
QDataStream out(&tmp_file);
out.writeRawData(ptr + (pos + 4), len - (pos + 4));
tmp_file.close();
Out(SYS_WEB | LOG_NOTICE) << "Loading file " << save_file << endl;
core->loadSilently(KUrl(save_file), QString());
KUrl url;
url.setEncodedPathAndQuery(hdr.path());
QString page = url.queryItem("page");
// there needs to be a page to send back
if (page.isEmpty())
{
server->redirectToLoginPage(hdlr);
}
else
{
// redirect to page mentioned in page parameter
HttpResponseHeader rhdr(301);
server->setDefaultResponseHeaders(rhdr, "text/html", true);
rhdr.setValue("Location", "/" + page);
hdlr->send(rhdr, QByteArray());
}
}
示例3: handleGet
void HttpServer::handleGet(HttpClientHandler* hdlr,const QHttpRequestHeader & hdr)
{
if (rootDir.isEmpty())
{
HttpResponseHeader rhdr(500,hdr.majorVersion(),hdr.minorVersion());
setDefaultResponseHeaders(rhdr,"text/html",false);
hdlr->send500(rhdr,i18n("Cannot find web interface skins."));
return;
}
QString file = hdr.path();
if (file == "/" && WebInterfacePluginSettings::authentication())
file = "/login.html";
else if (file == "/")
file = "/interface.html";
KUrl url;
url.setEncodedPathAndQuery(file);
Out(SYS_WEB|LOG_DEBUG) << "GET " << hdr.path() << endl;
WebContentGenerator* gen = content_generators.find(url.path());
if (gen)
{
if ((gen->getPermissions() == WebContentGenerator::LOGIN_REQUIRED && (!session.logged_in || !checkSession(hdr))) && WebInterfacePluginSettings::authentication())
{
// redirect to login page
redirectToLoginPage(hdlr);
}
else
{
gen->get(hdlr,hdr);
}
}
else
{
QString path = commonDir() + url.path();
// first try the common dir
if (!bt::Exists(path)) // doesn't exist so it must be in the skin dir
path = skinDir() + url.path();
handleFile(hdlr,hdr,path);
}
}
示例4: doRequest
void HTTPTracker::doRequest(WaitJob* wjob)
{
KUrl u = url;
if (!url.isValid())
{
requestPending();
QTimer::singleShot(500, this, SLOT(emitInvalidURLFailure()));
return;
}
Uint16 port = ServerInterface::getPort();
u.addQueryItem("peer_id", peer_id.toString());
u.addQueryItem("port", QString::number(port));
u.addQueryItem("uploaded", QString::number(bytesUploaded()));
u.addQueryItem("downloaded", QString::number(bytesDownloaded()));
if (event == "completed")
u.addQueryItem("left", "0"); // need to send 0 when we are completed
else
u.addQueryItem("left", QString::number(tds->bytesLeft()));
u.addQueryItem("compact", "1");
if (event != "stopped")
u.addQueryItem("numwant", "200");
else
u.addQueryItem("numwant", "0");
u.addQueryItem("key", QString::number(key));
QString cip = Tracker::getCustomIP();
if (cip.isNull())
cip = CurrentIPv6Address();
if (!cip.isEmpty())
u.addQueryItem("ip", cip);
if (event.isEmpty() && supports_partial_seed_extension && tds->isPartialSeed())
event = "paused";
if (!event.isEmpty())
u.addQueryItem("event", event);
QString epq = u.encodedPathAndQuery();
const SHA1Hash & info_hash = tds->infoHash();
epq += "&info_hash=" + info_hash.toURLString();
u.setEncodedPathAndQuery(epq);
if (active_job)
{
announce_queue.append(u);
Out(SYS_TRK | LOG_NOTICE) << "Announce ongoing, queueing announce" << endl;
}
else
{
doAnnounce(u);
// if there is a wait job, add this job to the waitjob
if (wjob)
wjob->addExitOperation(new ExitJobOperation(active_job));
}
}