Exemple #1
0
void RSSImp::on_actionManage_cookies_triggered()
{
    Q_ASSERT(!m_feedList->selectedItems().empty());

    // TODO: Create advanced application wide Cookie dialog and use it everywhere.
    QUrl feedUrl = QUrl::fromEncoded(m_feedList->getItemID(m_feedList->selectedItems().first()).toUtf8());
    QList<QNetworkCookie> cookies;
    if (CookiesDlg::askForCookies(this, feedUrl, cookies)) {
        auto downloadManager = Net::DownloadManager::instance();
        QList<QNetworkCookie> oldCookies = downloadManager->cookiesForUrl(feedUrl);
        foreach (const QNetworkCookie &oldCookie, oldCookies) {
            if (!cookies.contains(oldCookie))
                downloadManager->deleteCookie(oldCookie);
        }

        downloadManager->setCookiesFromUrl(cookies, feedUrl);
    }
Exemple #2
0
bool CookieJar::setCookie(const QString& cookieName, const QString& value, int maxAge, const QString& path, const QString& domain, bool isSecure)
{
	QNetworkCookie cookie;
	QUrl url = QString(isSecure ? "https://" : "http://" + QString(domain.startsWith('.') ? "www" : "") + domain + (path.isEmpty() ? "/" : path));
#ifdef U_CJ_DEBUG
	qDebug() << Q_FUNC_INFO << allCookies().count() << url;
#endif
	cookie.setName(cookieName.toUtf8());
	cookie.setValue(value.toUtf8());
	cookie.setDomain(domain);
	cookie.setPath(path);
	cookie.setSecure(isSecure);

	if(maxAge != 0) {
		QDateTime expireDate = QDateTime::currentDateTimeUtc().addSecs(maxAge);
		cookie.setExpirationDate(expireDate);
	}
#ifdef U_CJ_DEBUG
	qDebug() << Q_FUNC_INFO << cookie;
#endif
	return setCookiesFromUrl(QList<QNetworkCookie>() << cookie, url);
}