From 27742143d60e80bc925439e44664cc23c472f433 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 28 May 2017 12:46:11 +0200 Subject: Profiles dialog --- src/forms/profiledialog.cpp | 124 ------------------- src/forms/profiledialog.h | 53 --------- src/forms/profiledialog.ui | 236 ------------------------------------- src/forms/profilesdialog.cpp | 17 ++- src/forms/profilesdialog.h | 3 + src/forms/profilesdialog.ui | 9 +- src/forms/profileview.cpp | 134 +++++++++++++++++++++ src/forms/profileview.h | 55 +++++++++ src/forms/profileview.ui | 206 ++++++++++++++++++++++++++++++++ src/mainwindow.cpp | 2 +- src/webengine/webengineprofile.cpp | 11 +- src/webengine/webengineprofile.h | 9 +- 12 files changed, 431 insertions(+), 428 deletions(-) delete mode 100644 src/forms/profiledialog.cpp delete mode 100644 src/forms/profiledialog.h delete mode 100644 src/forms/profiledialog.ui create mode 100644 src/forms/profileview.cpp create mode 100644 src/forms/profileview.h create mode 100644 src/forms/profileview.ui (limited to 'src') diff --git a/src/forms/profiledialog.cpp b/src/forms/profiledialog.cpp deleted file mode 100644 index 4d6c047..0000000 --- a/src/forms/profiledialog.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - ** - ** 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 "profiledialog.h" -#include "ui_profiledialog.h" - -#include -#include -#include -#include -#include "webengine/webengineprofile.h" -#include "forms/cookiesform.h" - -ProfileDialog::ProfileDialog(WebEngineProfile *profile, QWidget *parent) : - QDialog(parent), - ui(new Ui::ProfileDialog) -{ - _profile = profile; - - ui->setupUi(this); - if(!_profile->storageName().isEmpty()) { - setWindowTitle(_profile->storageName()); - } else { - setWindowTitle(tr("Off-the-record")); - } - - m_cookiesForm = new CookiesForm(_profile->cookieStore(), this); - ui->tabWidget->addTab(m_cookiesForm, m_cookiesForm->windowTitle()); - - // http - ui->userAgent->setPlainText(_profile->httpUserAgent()); - ui->acceptLanguage->setPlainText(_profile->httpAcceptLanguage()); - ui->cacheType->setCurrentIndex(_profile->httpCacheType()); - ui->cacheSize->setText(QString::number(_profile->httpCacheMaximumSize())); - - // path - ui->storagePath_lineEdit->setText(_profile->persistentStoragePath()); - ui->cachePath_lineEdit->setText(_profile->cachePath()); - - // policy - ui->cookiePolicy->setCurrentIndex(_profile->persistentCookiesPolicy()); - - // actions - connect(ui->clearCache_pushButton, &QPushButton::clicked, [this]() { - this->_profile->clearHttpCache(); - }); - connect(ui->clearHistory_pushButton, &QPushButton::clicked, [this]() { - this->_profile->clearAllVisitedLinks(); - }); - - connect(this, SIGNAL(accepted()), this, SLOT(updateProfile())); -} - -ProfileDialog::~ProfileDialog() -{ - delete ui; -} - -void ProfileDialog::showProfile() -{ - ui->tabWidget->setCurrentIndex(0); - show(); -} - -void ProfileDialog::showCookies() -{ - ui->tabWidget->setCurrentIndex(4); - show(); -} - -void ProfileDialog::updateProfile() -{ - qDebug("Updating profile..."); - - // http - _profile->setHttpUserAgent(ui->userAgent->toPlainText()); - _profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText()); - switch (ui->cacheType->currentIndex()) { - case 0: - _profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache); - break; - case 1: - _profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache); - break; - case 2: - _profile->setHttpCacheType(QWebEngineProfile::NoCache); - break; - default: - break; - } - _profile->setHttpCacheMaximumSize(ui->cacheSize->text().toInt()); - - // policy - switch (ui->cookiePolicy->currentIndex()) { - case 0: - _profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); - break; - case 1: - _profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies); - break; - case 2: - _profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies); - break; - default: - break; - } -} diff --git a/src/forms/profiledialog.h b/src/forms/profiledialog.h deleted file mode 100644 index 613ed80..0000000 --- a/src/forms/profiledialog.h +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - ** - ** 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 . - ** - ******************************************************************************/ - -#ifndef PROFILEDIALOG_H -#define PROFILEDIALOG_H - -#include - -namespace Ui { -class ProfileDialog; -} - -class WebEngineProfile; -class CookiesForm; -class ProfileDialog : public QDialog -{ - Q_OBJECT - -public: - explicit ProfileDialog(WebEngineProfile *profile, QWidget *parent = 0); - ~ProfileDialog(); - -public slots: - void showProfile(); - void showCookies(); - -private slots: - void updateProfile(); - -private: - WebEngineProfile *_profile; - Ui::ProfileDialog *ui; - CookiesForm *m_cookiesForm; -}; - -#endif // PROFILEDIALOG_H diff --git a/src/forms/profiledialog.ui b/src/forms/profiledialog.ui deleted file mode 100644 index 528d672..0000000 --- a/src/forms/profiledialog.ui +++ /dev/null @@ -1,236 +0,0 @@ - - - ProfileDialog - - - - 0 - 0 - 480 - 640 - - - - Profile - - - - - - 0 - - - - HTTP - - - - - - User Agent - - - - - - - - - - Accept Language - - - - - - - Cache Type - - - - - - - Cache Size - - - - - - - - - - - Memory Cache - - - - - Disk Cache - - - - - Disabled - - - - - - - - - - - - Paths - - - - - - Storage Path - - - - - - - false - - - - - - - Cache Path - - - - - - - false - - - - - - - - Policies - - - - - - Cookies - - - - - - - - No Persistent Cookies - - - - - Allow Persistent Cookies - - - - - Force Persistent Cookies - - - - - - - - - Actions - - - - - - Clear History - - - - - - - Clear Cache - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Close|QDialogButtonBox::Save - - - - - - - - - buttonBox - accepted() - ProfileDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - ProfileDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/src/forms/profilesdialog.cpp b/src/forms/profilesdialog.cpp index c77208d..cf6791c 100644 --- a/src/forms/profilesdialog.cpp +++ b/src/forms/profilesdialog.cpp @@ -23,14 +23,19 @@ #include "browser.h" #include +#include ProfilesDialog::ProfilesDialog(MainWindow *window, QWidget *parent) : QDialog(parent), ui(new Ui::ProfilesDialog) { - ui->setupUi(this); m_window = window; + m_view = new ProfileView(0, this); + ui->setupUi(this); + ui->horizontalLayout->addWidget(m_view); + + connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(viewProfile(int))); connect(this, SIGNAL(accepted()), this, SLOT(loadSelectedProfile())); } @@ -43,12 +48,18 @@ int ProfilesDialog::exec() { qDebug("Showing..."); for(QString name : qApp->profiles()) { - ui->listWidget->addItem(name); + QListWidgetItem *item = new QListWidgetItem(qApp->profile(name)->name(), ui->listWidget); + item->setData(Qt::UserRole, name); } return QDialog::exec(); } void ProfilesDialog::loadSelectedProfile() { - m_window->setProfile(qApp->profile(ui->listWidget->currentItem()->text())); + m_window->setProfile(qApp->profile(ui->listWidget->currentItem()->data(Qt::UserRole).toString())); +} + +void ProfilesDialog::viewProfile(int index) +{ + m_view->setProfile(qApp->profile(ui->listWidget->item(index)->data(Qt::UserRole).toString())); } diff --git a/src/forms/profilesdialog.h b/src/forms/profilesdialog.h index bb6655b..302bf82 100644 --- a/src/forms/profilesdialog.h +++ b/src/forms/profilesdialog.h @@ -22,6 +22,7 @@ #define PROFILESDIALOG_H #include +#include "forms/profileview.h" namespace Ui { class ProfilesDialog; @@ -41,9 +42,11 @@ public slots: private slots: void loadSelectedProfile(); + void viewProfile(int index); private: Ui::ProfilesDialog *ui; + ProfileView *m_view; MainWindow *m_window; }; diff --git a/src/forms/profilesdialog.ui b/src/forms/profilesdialog.ui index 880e441..7675a9d 100644 --- a/src/forms/profilesdialog.ui +++ b/src/forms/profilesdialog.ui @@ -6,12 +6,12 @@ 0 0 - 564 - 458 + 580 + 620 - Dialog + Profiles @@ -19,9 +19,6 @@ - - - diff --git a/src/forms/profileview.cpp b/src/forms/profileview.cpp new file mode 100644 index 0000000..9d2e9ed --- /dev/null +++ b/src/forms/profileview.cpp @@ -0,0 +1,134 @@ +/******************************************************************************* + ** + ** 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 + +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->_profile->clearHttpCache(); + }); + connect(ui->clearHistory_pushButton, &QPushButton::clicked, [this]() { + this->_profile->clearAllVisitedLinks(); + }); + + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(updateProfile())); +} + +ProfileView::~ProfileView() +{ + delete ui; +} + +void ProfileView::setProfile(WebEngineProfile *profile) +{ + if(!profile) { + return; + } + + _profile = profile; + if(!_profile->storageName().isEmpty()) { + setWindowTitle(_profile->storageName()); + } else { + setWindowTitle(tr("Off-the-record")); + } + + m_cookiesForm = new CookiesForm(_profile->cookieStore(), this); + ui->tabWidget->addTab(m_cookiesForm, m_cookiesForm->windowTitle()); + + // http + ui->userAgent->setPlainText(_profile->httpUserAgent()); + ui->acceptLanguage->setPlainText(_profile->httpAcceptLanguage()); + ui->cacheType->setCurrentIndex(_profile->httpCacheType()); + ui->cacheSize->setText(QString::number(_profile->httpCacheMaximumSize())); + + // path + ui->storagePath_lineEdit->setText(_profile->persistentStoragePath()); + ui->cachePath_lineEdit->setText(_profile->cachePath()); + + // policy + ui->cookiePolicy->setCurrentIndex(_profile->persistentCookiesPolicy()); +} + +void ProfileView::showProfile() +{ + ui->tabWidget->setCurrentIndex(0); + show(); +} + +void ProfileView::showCookies() +{ + ui->tabWidget->setCurrentIndex(4); + show(); +} + +void ProfileView::updateProfile() +{ + qDebug("Updating profile..."); + + // http + _profile->setHttpUserAgent(ui->userAgent->toPlainText()); + _profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText()); + switch (ui->cacheType->currentIndex()) { + case 0: + _profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache); + break; + case 1: + _profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache); + break; + case 2: + _profile->setHttpCacheType(QWebEngineProfile::NoCache); + break; + default: + break; + } + _profile->setHttpCacheMaximumSize(ui->cacheSize->text().toInt()); + + // policy + switch (ui->cookiePolicy->currentIndex()) { + case 0: + _profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); + break; + case 1: + _profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies); + break; + case 2: + _profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies); + break; + default: + break; + } +} diff --git a/src/forms/profileview.h b/src/forms/profileview.h new file mode 100644 index 0000000..5dbdb59 --- /dev/null +++ b/src/forms/profileview.h @@ -0,0 +1,55 @@ +/******************************************************************************* + ** + ** 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 . + ** + ******************************************************************************/ + +#ifndef PROFILEDIALOG_H +#define PROFILEDIALOG_H + +#include + +namespace Ui { +class ProfileView; +} + +class WebEngineProfile; +class CookiesForm; +class ProfileView : public QWidget +{ + Q_OBJECT + +public: + explicit ProfileView(WebEngineProfile *profile, QWidget *parent = 0); + ~ProfileView(); + + void setProfile(WebEngineProfile *profile); + +public slots: + void showProfile(); + void showCookies(); + +private slots: + void updateProfile(); + +private: + WebEngineProfile *_profile; + Ui::ProfileView *ui; + CookiesForm *m_cookiesForm; +}; + +#endif // PROFILEDIALOG_H diff --git a/src/forms/profileview.ui b/src/forms/profileview.ui new file mode 100644 index 0000000..e7bcbae --- /dev/null +++ b/src/forms/profileview.ui @@ -0,0 +1,206 @@ + + + ProfileView + + + + 0 + 0 + 480 + 640 + + + + + 200 + 0 + + + + Profile + + + + + + 0 + + + + HTTP + + + + + + User Agent + + + + + + + + + + Accept Language + + + + + + + Cache Type + + + + + + + Cache Size + + + + + + + + + + + Memory Cache + + + + + Disk Cache + + + + + Disabled + + + + + + + + + + + + Paths + + + + + + Storage Path + + + + + + + false + + + + + + + Cache Path + + + + + + + false + + + + + + + + Policies + + + + + + Cookies + + + + + + + + No Persistent Cookies + + + + + Allow Persistent Cookies + + + + + Force Persistent Cookies + + + + + + + + + Actions + + + + + + Clear History + + + + + + + Clear Cache + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + QDialogButtonBox::Save + + + + + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 79552d6..851ee9e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -231,7 +231,7 @@ void MainWindow::handleUrlChanged() void MainWindow::handleTitleUpdated(const QString &title) { - setWindowTitle(sSettings->value("window.title").toString().replace("title", title).replace("profile", m_profile->storageName())); + setWindowTitle(sSettings->value("window.title").toString().replace("title", title).replace("profile", m_profile->name())); } void MainWindow::profileAction() diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp index 89cc301..2fed937 100644 --- a/src/webengine/webengineprofile.cpp +++ b/src/webengine/webengineprofile.cpp @@ -27,11 +27,13 @@ WebEngineProfile::WebEngineProfile(QObject *parent) : QWebEngineProfile(parent) { // Off-the-record constructor + m_name = tr("Off-the-record"); } WebEngineProfile::WebEngineProfile(const QString &storageName, QObject *parent) : QWebEngineProfile(storageName, parent) { + m_name = storageName; setPersistentStoragePath(sSettings->value("browser.profile.path").toString() + storageName); setCachePath(sSettings->value("browser.profile.path").toString() + storageName); @@ -111,10 +113,15 @@ WebEngineProfile::~WebEngineProfile() } } -ProfileDialog *WebEngineProfile::dialog() +QString WebEngineProfile::name() const +{ + return m_name; +} + +ProfileView *WebEngineProfile::dialog() { if(m_profileDialog == nullptr) { - m_profileDialog = new ProfileDialog(this); + m_profileDialog = new ProfileView(this); } return m_profileDialog; } diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h index 4b36940..9a7be22 100644 --- a/src/webengine/webengineprofile.h +++ b/src/webengine/webengineprofile.h @@ -22,7 +22,7 @@ #define WEBENGINEPROFILE_H #include -#include "forms/profiledialog.h" +#include "forms/profileview.h" class WebEngineProfile : public QWebEngineProfile { @@ -33,7 +33,9 @@ public: ~WebEngineProfile(); - ProfileDialog *dialog(); + QString name() const; + + ProfileView *dialog(); signals: @@ -41,7 +43,8 @@ public slots: void saveProfile(); private: - ProfileDialog *m_profileDialog = nullptr; + QString m_name; + ProfileView *m_profileDialog = nullptr; }; #endif // WEBENGINEPROFILE_H -- cgit v1.2.1