本文整理汇总了C++中QUrl::userName方法的典型用法代码示例。如果您正苦于以下问题:C++ QUrl::userName方法的具体用法?C++ QUrl::userName怎么用?C++ QUrl::userName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUrl
的用法示例。
在下文中一共展示了QUrl::userName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: proxy
QT_BEGIN_NAMESPACE
QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &)
{
QList<QNetworkProxy> proxyList;
QByteArray proxy_env = qgetenv("http_proxy");
if (!proxy_env.isEmpty()) {
QUrl url = QUrl(QString::fromLocal8Bit(proxy_env));
if (url.scheme() == QLatin1String("socks5")) {
QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(),
url.port() ? url.port() : 1080, url.userName(), url.password());
proxyList << proxy;
} else if (url.scheme() == QLatin1String("socks5h")) {
QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(),
url.port() ? url.port() : 1080, url.userName(), url.password());
proxy.setCapabilities(QNetworkProxy::HostNameLookupCapability);
proxyList << proxy;
} else if (url.scheme() == QLatin1String("http") || url.scheme().isEmpty()) {
QNetworkProxy proxy(QNetworkProxy::HttpProxy, url.host(),
url.port() ? url.port() : 8080, url.userName(), url.password());
proxyList << proxy;
}
}
if (proxyList.isEmpty())
proxyList << QNetworkProxy::NoProxy;
return proxyList;
}
示例2: initializePage
void OwncloudHttpCredsPage::initializePage()
{
WizardCommon::initErrorLabel(_ui.errorLabel);
OwncloudWizard* ocWizard = qobject_cast< OwncloudWizard* >(wizard());
AbstractCredentials *cred = ocWizard->account()->credentials();
HttpCredentials *httpCreds = qobject_cast<HttpCredentials*>(cred);
if (httpCreds) {
const QString user = httpCreds->fetchUser();
if (!user.isEmpty()) {
_ui.leUsername->setText(user);
}
} else {
QUrl url = ocWizard->account()->url();
// If the final url does not have a username, check the
// user specified url too. Sometimes redirects can lose
// the user:pw information.
if (url.userName().isEmpty()) {
url = ocWizard->ocUrl();
}
const QString user = url.userName();
const QString password = url.password();
if(!user.isEmpty()) {
_ui.leUsername->setText(user);
}
if(!password.isEmpty()) {
_ui.lePassword->setText(password);
}
}
_ui.leUsername->setFocus();
}
示例3: download
void FileDownloader::download(QUrl url) {
QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());
if (!url.userName().isEmpty())
http->setUser(url.userName(), url.password());
http_request_aborted = false;
http_get_id = http->get(url.path(), &buffer);
setLabelText(tr("Downloading %1").arg(url.toString()));
}
示例4: db_open
bool db_open(QUrl dburl)
{
QSqlDatabase db;
db.removeDatabase("vengeance");
if(dburl.scheme().isEmpty())
db=QSqlDatabase::addDatabase("QMYSQL","vengeance");
else
db=QSqlDatabase::addDatabase(dburl.scheme(),"vengeance");
if(dburl.host().isEmpty())
db.setHostName("localhost");
else
db.setHostName(dburl.host());
db.setDatabaseName(dburl.path().replace("/",""));
db.setUserName(dburl.userName());
db.setPassword(dburl.password());
bool w=db.open();
if(!w)
{
qDebug()<<db.lastError ();
}
return w;
}
示例5: userName
QString QUrlProto::userName() const
{
QUrl *item = qscriptvalue_cast<QUrl*>(thisObject());
if (item)
return item->userName();
return QString();
}
示例6: setGateway
/*!
\a url points to the new WAP gateway.
\sa gateway()
*/
void QWapAccount::setGateway( const QUrl& url )
{
d->conf->setValue( QLatin1String("Wap/Gateway"), url.host() );
d->conf->setValue( QLatin1String("Wap/UserName"), url.userName() );
d->conf->setValue( QLatin1String("Wap/Password"), url.password() );
d->conf->setValue( QLatin1String("Wap/Port"), url.port() );
}
示例7: cacheCredentials
void QNetworkAccessAuthenticationManager::cacheCredentials(const QUrl &url,
const QAuthenticator *authenticator)
{
Q_ASSERT(authenticator);
QString domain = QString::fromLatin1("/"); // FIXME: make QAuthenticator return the domain
QString realm = authenticator->realm();
QMutexLocker mutexLocker(&mutex);
// Set two credentials actually: one with and one without the username in the URL
QUrl copy = url;
copy.setUserName(authenticator->user());
do {
QByteArray cacheKey = authenticationKey(copy, realm);
if (authenticationCache.hasEntry(cacheKey)) {
QNetworkAuthenticationCache *auth =
static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));
auth->insert(domain, authenticator->user(), authenticator->password());
authenticationCache.releaseEntry(cacheKey);
} else {
QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache;
auth->insert(domain, authenticator->user(), authenticator->password());
authenticationCache.addEntry(cacheKey, auth);
}
if (copy.userName().isEmpty()) {
break;
} else {
copy.setUserName(QString());
}
} while (true);
}
示例8: openUrl
void DrawpileApp::openUrl(QUrl url)
{
// See if there is an existing replacable window
MainWindow *win = nullptr;
for(QWidget *widget : topLevelWidgets()) {
MainWindow *mw = qobject_cast<MainWindow*>(widget);
if(mw && mw->canReplace()) {
win = mw;
break;
}
}
// No? Create a new one
if(!win)
win = new MainWindow;
if(url.scheme() == "drawpile") {
// Our own protocol: connect to a session
if(url.userName().isEmpty()) {
// Set username if not specified
QSettings cfg;
url.setUserName(cfg.value("history/username").toString());
}
win->joinSession(url);
} else {
// Other protocols: load image
win->openUrl(url);
}
}
示例9: systemProxyForQuery
QList<QNetworkProxy> PackageManagerProxyFactory::queryProxy(const QNetworkProxyQuery &query)
{
const Settings &settings = m_core->settings();
QList<QNetworkProxy> list;
if (settings.proxyType() == Settings::SystemProxy) {
#if defined(Q_OS_UNIX) && !defined(Q_OS_OSX)
QUrl proxyUrl = QUrl::fromUserInput(QString::fromUtf8(qgetenv("http_proxy")));
if (proxyUrl.isValid()) {
return list << QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyUrl.port(),
proxyUrl.userName(), proxyUrl.password());
}
#endif
return QNetworkProxyFactory::systemProxyForQuery(query);
}
if ((settings.proxyType() == Settings::NoProxy))
return list << QNetworkProxy(QNetworkProxy::NoProxy);
if (query.queryType() == QNetworkProxyQuery::UrlRequest) {
if (query.url().scheme() == QLatin1String("ftp"))
return list << settings.ftpProxy();
if ((query.url().scheme() == QLatin1String("http"))
|| (query.url().scheme() == QLatin1String("https"))) {
return list << settings.httpProxy();
}
}
return list << QNetworkProxy(QNetworkProxy::DefaultProxy);
}
示例10: dropSlsk
void Transfers::dropSlsk(const QList<QUrl>& l) {
QList<QUrl>::const_iterator it = l.begin();
for(; it != l.end(); ++it) {
QUrl url = *it;
if(url.scheme() == "slsk" && !url.host().isEmpty() && !url.path().isEmpty()) {
// Try to find a size
qint64 size = 0;
bool ok;
size = url.password().toLongLong(&ok);
if(! ok)
size = 0;
// Find the user name
QString user = url.userName();
if (user.isEmpty())
user = url.host();
// Find the path (folder or file)
QString path = url.path().replace("/", "\\");
if(path.right(1) == "\\")
museeq->downloadFolder(user, QString(path));
else
museeq->downloadFile(user, QString(path), size);
}
}
}
示例11: setApplicationProxy
static void setApplicationProxy(QUrl url)
{
if (!url.isEmpty())
{
if (url.port() == -1)
url.setPort(8080);
QNetworkProxy proxy(QNetworkProxy::HttpProxy, url.host(), url.port(), url.userName(), url.password());
QNetworkProxy::setApplicationProxy(proxy);
}
}
示例12: parseCnnString
void ClientPrivate::parseCnnString(const QUrl &con) {
P_Q(QAMQP::Client);
if (con.scheme() == AMQPSCHEME || con.scheme() == AMQPSSCHEME) {
q->setSsl(con.scheme() == AMQPSSCHEME);
q->setPassword(con.password());
q->setUser(con.userName());
q->setPort(con.port());
q->setHost(con.host());
q->setVirtualHost(con.path());
}
}
示例13: authenticationRequired
void QNetworkAccessManagerPrivate::authenticationRequired(QNetworkAccessBackend *backend,
QAuthenticator *authenticator)
{
Q_Q(QNetworkAccessManager);
// FIXME: Add support for domains (i.e., the leading path)
QUrl url = backend->reply->url;
// don't try the cache for the same URL twice in a row
// being called twice for the same URL means the authentication failed
// also called when last URL is empty, e.g. on first call
if (backend->reply->urlForLastAuthentication.isEmpty()
|| url != backend->reply->urlForLastAuthentication) {
// if credentials are included in the url, then use them
if (!url.userName().isEmpty()
&& !url.password().isEmpty()) {
authenticator->setUser(url.userName());
authenticator->setPassword(url.password());
backend->reply->urlForLastAuthentication = url;
authenticationManager->cacheCredentials(url, authenticator);
return;
}
QNetworkAuthenticationCredential cred = authenticationManager->fetchCachedCredentials(url, authenticator);
if (!cred.isNull()) {
authenticator->setUser(cred.user);
authenticator->setPassword(cred.password);
backend->reply->urlForLastAuthentication = url;
return;
}
}
// if we emit a signal here in synchronous mode, the user might spin
// an event loop, which might recurse and lead to problems
if (backend->isSynchronous())
return;
backend->reply->urlForLastAuthentication = url;
emit q->authenticationRequired(backend->reply->q_func(), authenticator);
authenticationManager->cacheCredentials(url, authenticator);
}
示例14: getKey
QString SFtpConnectionCache::getKey(const QUrl &url) const
{
QString key;
key.append(url.userName());
key.append("@");
key.append(url.host());
key.append(":");
key.append(QString::number(url.port()));
return key;
}
示例15: setUrl
void setUrl(const QUrl &url)
{
QString hdr;
hdr = QString("GET %PATH% HTTP/1.1\r\n"
"Host: %HOST%\r\n"
"User-Agent: MythMusic/%VERSION%\r\n"
"Accept: */*\r\n");
QString path = url.path();
QString host = url.host();
if (path.isEmpty())
path = "/";
if (url.hasQuery())
path += '?' + url.encodedQuery();
if (url.port() != -1)
host += QString(":%1").arg(url.port());
hdr.replace("%PATH%", path);
hdr.replace("%HOST%", host);
hdr.replace("%VERSION%", MYTH_BINARY_VERSION);
if (!url.userName().isEmpty() && !url.password().isEmpty())
{
QString authstring = url.userName() + ":" + url.password();
QString auth = QCodecs::base64Encode(authstring.toLocal8Bit());
hdr += "Authorization: Basic " + auth + "\r\n";
}
hdr += QString("TE: trailers\r\n"
"Icy-Metadata: 1\r\n"
"\r\n");
LOG(VB_NETWORK, LOG_INFO, QString("ShoutCastRequest: '%1'").arg(hdr));
m_data = hdr.toAscii();
}