예제 #1
0
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();
}
예제 #2
0
CookieDialog::CookieDialog(const QNetworkCookie &cookie, QWidget *parent): QDialog(parent)
{
    setupUi(this);
    m_nameLineEdit->setText(cookie.name());
    m_domainLineEdit->setText(cookie.domain());
    m_valueLineEdit->setText(cookie.value());
    m_pathLineEdit->setText(cookie.path());
    m_dateEdit->setDate(cookie.expirationDate().date());
    m_isSecureComboBox->addItem(cookie.isSecure() ? tr("yes") : tr("no"));
    m_isHttpOnlyComboBox->addItem(cookie.isHttpOnly() ? tr("yes") : tr("no"));
    m_addButton->setVisible(false);
    m_cancelButton->setText(tr("Close"));
}
예제 #3
0
bool CookieStore::insertCookie(const QNetworkCookie& cookie, const QUrl& firstUrl)
{
    sqlite3_stmt* stmt;
    int rc;
    
    QByteArray domain = cookie.domain().toLatin1();
    QByteArray path = cookie.path().toLatin1();
    QByteArray name = cookie.name();
    QByteArray fdomain = firstUrl.host().toLower().toLatin1();
    QByteArray expiration;
    if (cookie.isSessionCookie()) {
        expiration = "0";
    } else {
        expiration = cookie.expirationDate().toString().toLatin1();
    }
    QByteArray content = cookie.toRawForm();

    rc = sqlite3_prepare(m_db,
                         "insert into thirdPartyCookies (domain, path, name, fdomain, expiration, content) values (?, ?, ?, ?, ?, ?)",
                         -1, &stmt, 0);
    if (rc != SQLITE_OK) {
        qDebug() << "insertCookie prepare fail:" << rc;
        return false;
    }

    QByteArray text[6] = {domain, path, name, fdomain, expiration, content};
    
    for (int i = 0; i < 6; ++i) {
        rc = sqlite3_bind_text(stmt, i + 1, text[i].constData(), text[i].size(), SQLITE_TRANSIENT);
        if (rc != SQLITE_OK) {
            qDebug() << "insertCookie bind fail:" << i;
            sqlite3_finalize(stmt);
            return false;
        }
    }

    rc = sqlite3_step(stmt);
    if (rc != SQLITE_DONE) {
        qDebug() << "insertCookie step (execute) fail";
        sqlite3_finalize(stmt);
        return false;
    }

    sqlite3_finalize(stmt);
    return true;
}