1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* This file is part of smolbote. It's copyrighted by the contributors recorded
* in the version control history of the file, available from its original
* location: git://neueland.iserlohn-fortress.net/smolbote.git
*
* SPDX-License-Identifier: GPL-3.0
*/
#include "profileview.h"
#include "ui_profileview.h"
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QComboBox>
#include <QPushButton>
#include "webengine/webengineprofile.h"
#include "forms/cookiesform.h"
#include <QDialogButtonBox>
#include <QFormLayout>
ProfileView::ProfileView(WebEngineProfile *profile, QWidget *parent) :
QDialog(parent),
ui(new Ui::ProfileView)
{
ui->setupUi(this);
setProfile(profile);
// actions
connect(ui->clearCache_pushButton, &QPushButton::clicked, [this]() {
this->m_profile->clearHttpCache();
});
connect(ui->clearHistory_pushButton, &QPushButton::clicked, [this]() {
this->m_profile->clearAllVisitedLinks();
});
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ProfileView::updateProfile);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ProfileView::close);
}
ProfileView::~ProfileView()
{
delete ui;
}
void ProfileView::setProfile(WebEngineProfile *profile)
{
Q_CHECK_PTR(profile);
m_profile = profile;
setWindowTitle(m_profile->name());
m_cookiesForm = new CookiesForm(m_profile->cookieStore(), this);
//ui->tabWidget->addTab(m_cookiesForm, m_cookiesForm->windowTitle());
// general
ui->homepage_lineEdit->setText(m_profile->homepage().toString());
ui->newtab_lineEdit->setText(m_profile->newtab().toString());
// http
ui->userAgent->setPlainText(m_profile->httpUserAgent());
ui->acceptLanguage->setPlainText(m_profile->httpAcceptLanguage());
ui->cacheType->setCurrentIndex(m_profile->httpCacheType());
ui->cacheSize->setText(QString::number(m_profile->httpCacheMaximumSize()));
// path
ui->storagePath_lineEdit->setText(m_profile->persistentStoragePath());
ui->cachePath_lineEdit->setText(m_profile->cachePath());
// policy
ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy());
//ui->formLayout_3->addWidget(m_cookiesForm);
ui->verticalLayout_3->addWidget(m_cookiesForm);
}
void ProfileView::showProfile()
{
ui->tabWidget->setCurrentIndex(0);
show();
}
void ProfileView::showCookies()
{
ui->tabWidget->setCurrentIndex(2);
show();
}
void ProfileView::updateProfile()
{
qDebug("Updating profile [%s]...", qUtf8Printable(m_profile->name()));
// general
m_profile->setHomepage(QUrl::fromUserInput(ui->homepage_lineEdit->text()));
m_profile->setNewtab(QUrl::fromUserInput(ui->newtab_lineEdit->text()));
// http
m_profile->setHttpUserAgent(ui->userAgent->toPlainText());
m_profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText());
switch (ui->cacheType->currentIndex()) {
case 0:
m_profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
break;
case 1:
m_profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
break;
case 2:
m_profile->setHttpCacheType(QWebEngineProfile::NoCache);
break;
default:
break;
}
m_profile->setHttpCacheMaximumSize(ui->cacheSize->text().toInt());
// policy
switch (ui->cookiePolicy->currentIndex()) {
case 0:
m_profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
break;
case 1:
m_profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
break;
case 2:
m_profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
break;
default:
break;
}
m_profile->saveProfile();
}
|