1 /**************************************************************************
2 * Otter Browser: Web browser controlled by the user, not vice-versa.
3 * Copyright (C) 2017 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 **************************************************************************/
19
20 #include "CookiePropertiesDialog.h"
21
22 #include "ui_CookiePropertiesDialog.h"
23
24 namespace Otter
25 {
26
CookiePropertiesDialog(const QNetworkCookie & cookie,QWidget * parent)27 CookiePropertiesDialog::CookiePropertiesDialog(const QNetworkCookie &cookie, QWidget *parent) : Dialog(parent),
28 m_cookie(cookie),
29 m_ui(new Ui::CookiePropertiesDialog)
30 {
31 m_ui->setupUi(this);
32
33 if (cookie.name().isEmpty())
34 {
35 setWindowTitle(tr("Add Cookie"));
36 }
37 else
38 {
39 setWindowTitle(tr("Edit Cookie"));
40 }
41
42 m_ui->nameLineEditWidget->setText(QString(cookie.name()));
43 m_ui->valueLineEditWidget->setText(QString(cookie.value()));
44 m_ui->domainLineEditWidget->setText(cookie.domain());
45 m_ui->pathLineEditWidget->setText(cookie.path());
46 m_ui->isSessionOnlyCheckBox->setChecked(!cookie.expirationDate().isValid());
47 m_ui->expiresDateTimeEdit->setDateTime(cookie.expirationDate());
48 m_ui->expiresDateTimeEdit->setEnabled(cookie.expirationDate().isValid());
49 m_ui->isSecureCheckBox->setChecked(cookie.isSecure());
50 m_ui->isHttpOnlyCheckBox->setChecked(cookie.isHttpOnly());
51
52 connect(m_ui->isSessionOnlyCheckBox, &QCheckBox::clicked, m_ui->expiresDateTimeEdit, &CookiePropertiesDialog::setDisabled);
53 }
54
~CookiePropertiesDialog()55 CookiePropertiesDialog::~CookiePropertiesDialog()
56 {
57 delete m_ui;
58 }
59
changeEvent(QEvent * event)60 void CookiePropertiesDialog::changeEvent(QEvent *event)
61 {
62 QDialog::changeEvent(event);
63
64 if (event->type() == QEvent::LanguageChange)
65 {
66 m_ui->retranslateUi(this);
67 }
68 }
69
getOriginalCookie() const70 QNetworkCookie CookiePropertiesDialog::getOriginalCookie() const
71 {
72 return m_cookie;
73 }
74
getModifiedCookie() const75 QNetworkCookie CookiePropertiesDialog::getModifiedCookie() const
76 {
77 QNetworkCookie cookie(m_cookie);
78 cookie.setName(m_ui->nameLineEditWidget->text().toUtf8());
79 cookie.setValue(m_ui->valueLineEditWidget->text().toUtf8());
80 cookie.setDomain(m_ui->domainLineEditWidget->text());
81 cookie.setPath(m_ui->pathLineEditWidget->text());
82 cookie.setExpirationDate(m_ui->isSessionOnlyCheckBox->isChecked() ? QDateTime() : m_ui->expiresDateTimeEdit->dateTime());
83 cookie.setSecure(m_ui->isSecureCheckBox->isChecked());
84 cookie.setHttpOnly(m_ui->isHttpOnlyCheckBox->isChecked());
85
86 return cookie;
87 }
88
isModified() const89 bool CookiePropertiesDialog::isModified() const
90 {
91 return (m_cookie != getModifiedCookie());
92 }
93
94 }
95