本文整理汇总了C++中QNetworkCookie类的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkCookie类的具体用法?C++ QNetworkCookie怎么用?C++ QNetworkCookie使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QNetworkCookie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cnFile
void CookieJar::loadCookies()
{
QString fName = m_appPath;
fName += "cookies";
QSettings cnFile(fName, QSettings::IniFormat);
setVkLogin(cnFile.value("login").toString());
QList<QNetworkCookie> cookies;
int size = cnFile.beginReadArray("cookies");
for(int i=0; i<size; i++) {
QNetworkCookie cook;
cnFile.setArrayIndex(i);
cook.setName(cnFile.value("name").toByteArray());
cook.setValue(cnFile.value("value").toByteArray());
cook.setDomain(cnFile.value("domain").toByteArray());
cook.setPath(cnFile.value("path").toByteArray());
cookies.insert(i, cook);
}
cnFile.endArray();
setAllCookies(cookies);
}
示例2: QWidget
CookieWidget::CookieWidget(const QNetworkCookie &cookie, QWidget *parent): QWidget(parent)
{
setupUi(this);
setAutoFillBackground(true);
m_nameLabel->setText(cookie.name());
m_domainLabel->setText(cookie.domain());
connect(m_viewButton, &QPushButton::clicked, this, &CookieWidget::viewClicked);
connect(m_deleteButton, &QPushButton::clicked, this, &CookieWidget::deleteClicked);
}
示例3: insertRows
bool CookiesModel::insertRows(int row, int count, const QModelIndex &parent)
{
if ((row < 0) || (row > m_cookies.size())) return false;
QNetworkCookie newCookie;
newCookie.setExpirationDate(QDateTime::currentDateTime().addYears(99));
beginInsertRows(parent, row, row + count - 1);
while (count-- > 0)
m_cookies.insert(row, newCookie);
endInsertRows();
return true;
}
示例4: QVariant
QVariant CookieModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_cookies.size())
return QVariant();
switch (role) {
case Qt::DisplayRole:
case Qt::EditRole: {
QNetworkCookie cookie = m_cookies.at(index.row());
switch (index.column()) {
case 0:
return cookie.domain();
case 1:
return cookie.name();
case 2:
return cookie.path();
case 3:
return cookie.isSecure() ? tr("true") : tr("false");
case 4:
return cookie.isSessionCookie() ? tr("Session cookie") : cookie.expirationDate().toString();
case 5:
return cookie.value();
}
}
case Qt::FontRole: {
QFont font;
font.setPointSize(10);
return font;
}
}
return QVariant();
}
示例5: onNewCookieCreated
void ShibLoginDialog::onNewCookieCreated(const QUrl& url, const QNetworkCookie& cookie)
{
QString name = cookie.name();
if (url.host() == url_.host() && name == kSeahubShibCookieName) {
QString value = cookie.value();
Account account = parseAccount(value);
if (seafApplet->accountManager()->saveAccount(account) < 0) {
seafApplet->warningBox(tr("Failed to save current account"), this);
reject();
} else {
accept();
}
}
}
示例6: getCookies
void OnetAvatar::getCookies()
{
/* TODO: replace with central cookies storage */
QList<QNetworkCookie> cookies;
QNetworkCookie cookie;
QStringList constCookies;
constCookies << "onet_ubi" << "onet_cid" << "onet_sid" << "onet_uid" << "onetzuo_ticket" << "onet_uoi" << "onet_sgn";
foreach (const QString &constCookie, constCookies)
{
cookie.setName(constCookie.toLatin1());
cookie.setValue(Settings::instance()->get(constCookie).toLatin1());
cookies.append(cookie);
}
示例7: rejectCookie
bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie) const
{
Q_UNUSED(domain)
const QString &cookieDomain = cookie.domain();
if (!m_allowCookies) {
bool result = listMatchesDomain(m_whitelist, cookieDomain);
if (!result) {
#ifdef COOKIE_DEBUG
qDebug() << "not in whitelist" << cookie;
#endif
return true;
}
}
if (m_allowCookies) {
bool result = listMatchesDomain(m_blacklist, cookieDomain);
if (result) {
#ifdef COOKIE_DEBUG
qDebug() << "found in blacklist" << cookie;
#endif
return true;
}
}
// This feature is now natively in QtWebKit 2.3
#if QTWEBKIT_TO_2_3
if (m_blockThirdParty) {
bool result = matchDomain(cookieDomain, domain);
if (!result) {
#ifdef COOKIE_DEBUG
qDebug() << "purged for domain mismatch" << cookie << cookieDomain << domain;
#endif
return true;
}
}
#endif
if (m_filterTrackingCookie && cookie.name().startsWith("__utm")) {
#ifdef COOKIE_DEBUG
qDebug() << "purged as tracking " << cookie;
#endif
return true;
}
return false;
}
示例8: AddCookie
void CookiesEditModel::AddCookie (const QNetworkCookie& cookie)
{
int i = 0;
if (Cookies_.size ())
i = (Cookies_.end () - 1).key () + 1;
Cookies_ [i] = cookie;
QString domain = cookie.domain ();
QList<QStandardItem*> foundItems = findItems (domain);
QStandardItem *parent = 0;
if (!foundItems.size ())
{
parent = new QStandardItem (domain);
parent->setEditable (false);
parent->setData (-1);
invisibleRootItem ()->appendRow (parent);
}
else
parent = foundItems.back ();
QStandardItem *item = new QStandardItem (QString (Cookies_ [i].name ()));
item->setData (i);
item->setEditable (false);
parent->appendRow (item);
Jar_->setAllCookies (Cookies_.values ());
}
示例9: checkThisCookie
void connectWindowClass::checkThisCookie(QNetworkCookie cookie)
{
if(cookie.name() == "dlrowolleh" || cookie.name() == "coniunctio")
{
for(int j = 0; j < cookieList.size(); ++j)
{
if(cookieList.at(j).name() == cookie.name())
{
cookieList.removeAt(j);
break;
}
}
cookie.setExpirationDate(QDateTime::currentDateTime().addYears(8));
cookieList.append(cookie);
}
adjustSize();
}
示例10: if
QScriptValue MyWebView::cookiesFormUrl(QScriptValue url)
{
QUrl targetUrl;
if (url.isUndefined()) {
targetUrl = this->url();
} else if (url.toString().toLower().trimmed().indexOf("http://") == 0) {
targetUrl = QUrl(url.toString().toLower().trimmed());
} else {
targetUrl = this->url();
}
QByteArray str;
QNetworkCookie cookie;
QList<QNetworkCookie> list = cookieJar->cookiesForUrl(targetUrl);
foreach (cookie, list)
{
str += cookie.toRawForm() + "\n";
}
示例11: makePostData
QVariant NicoLiveManager::makePostData(QString session_id)
{
QVariant postData;
// make cookies
QList <QNetworkCookie> cookies;
QNetworkCookie ck;
ck.toRawForm(QNetworkCookie::NameAndValueOnly);
ck.setName("user_session");
QByteArray user_id_ba;
user_id_ba.append(session_id);
ck.setValue(user_id_ba);
cookies.append(ck);
postData.setValue(cookies);
return postData;
}
示例12: rejectCookie
bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie) const
{
const QString &cookieDomain = cookie.domain();
if (!m_allowCookies) {
int result = listContainsDomain(m_whitelist, cookieDomain);
if (result != 1) {
#ifdef COOKIE_DEBUG
qDebug() << "not in whitelist" << cookie;
#endif
return true;
}
}
if (m_allowCookies) {
int result = listContainsDomain(m_blacklist, cookieDomain);
if (result == 1) {
#ifdef COOKIE_DEBUG
qDebug() << "found in blacklist" << cookie;
#endif
return true;
}
}
if (m_blockThirdParty) {
bool result = !containsDomain(cookieDomain, domain);
if (result) {
#ifdef COOKIE_DEBUG
qDebug() << "purged for domain mismatch" << cookie << cookieDomain << domain;
#endif
return true;
}
}
if (m_filterTrackingCookie && cookie.name().startsWith("__utm")) {
#ifdef COOKIE_DEBUG
qDebug() << "purged as tracking " << cookie;
#endif
return true;
}
return false;
}
示例13: cookie
QNetworkCookie CookieDialog::cookie()
{
QNetworkCookie cookie;
cookie.setDomain(m_domainLineEdit->text());
cookie.setName(m_nameLineEdit->text().toLatin1());
cookie.setValue(m_valueLineEdit->text().toLatin1());
cookie.setExpirationDate(QDateTime(m_dateEdit->date()));
cookie.setPath(m_pathLineEdit->text());
cookie.setSecure(m_isSecureComboBox->currentText() == tr("yes"));
cookie.setHttpOnly(m_isHttpOnlyComboBox->currentText() == tr("yes"));
return cookie;
}
示例14: foreach
QList<QNetworkCookie> CookieJar::cookiesForUrl(const QUrl& url) const
{
QString requestUrl = url.toString();
QList<QNetworkCookie> cookies = QNetworkCookieJar::cookiesForUrl(url);
const QList<QString>& registeredDomains = WebKit::instance()->identifierCookieDomainList();
foreach(QString d, registeredDomains) {
if(requestUrl.startsWith(d)) {
QNetworkCookie identifierCookie = WebKit::instance()->identifierCookie();
identifierCookie.setDomain(d);
identifierCookie.setSecure(d.startsWith("https") ? true : false);
cookies.append(identifierCookie);
break;
}
}
return cookies;
}
示例15: expires
void HttpWriterTest::writeSetCookies () {
HttpWriter writer;
// Data
QByteArray expected = "Set-Cookie: expires=b%20a%3Br; Max-Age=0; Secure; HttpOnly\r\n"
"Set-Cookie: session=foo\r\n";
QNetworkCookie expires ("expires", "b a;r");
expires.setExpirationDate (QDateTime::fromMSecsSinceEpoch (123));
expires.setSecure (true);
expires.setHttpOnly (true);
HttpClient::Cookies cookies {
{ "session", QNetworkCookie ("session", "foo") },
{ "expires", expires }
};
//
QByteArray result = writer.writeSetCookies (cookies);
QCOMPARE(result, expected);
}