/*******************************************************************************
**
** smolbote: yet another qute browser
** Copyright (C) 2017 Xian Nox
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see .
**
******************************************************************************/
#include "profileview.h"
#include "ui_profileview.h"
#include
#include
#include
#include
#include "webengine/webengineprofile.h"
#include "forms/cookiesform.h"
#include
#include
ProfileView::ProfileView(WebEngineProfile *profile, QWidget *parent) :
QWidget(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, SIGNAL(accepted()), this, SLOT(updateProfile()));
}
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();
}