diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-08-04 13:12:32 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-08-04 13:12:32 +0200 |
commit | a85dc7d9133c3cf4c94a2ef37db4f53a3d0e4c91 (patch) | |
tree | 81cc123c4afbaf726fbc4a8a6b87d50732432b4b | |
parent | Updated documentation (diff) | |
download | smolbote-a85dc7d9133c3cf4c94a2ef37db4f53a3d0e4c91.tar.xz |
Profile window fixes
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | data/poi.toml | 14 | ||||
-rw-r--r-- | src/browser.cpp | 8 | ||||
-rw-r--r-- | src/forms/profilesdialog.cpp | 4 | ||||
-rw-r--r-- | src/forms/profilesdialog.ui | 2 | ||||
-rw-r--r-- | src/forms/profileview.cpp | 58 | ||||
-rw-r--r-- | src/forms/profileview.h | 4 | ||||
-rw-r--r-- | src/forms/profileview.ui | 7 | ||||
-rw-r--r-- | src/mainwindow.cpp | 14 | ||||
-rw-r--r-- | src/mainwindow.h | 3 | ||||
-rw-r--r-- | src/webengine/webengineprofile.cpp | 60 | ||||
-rw-r--r-- | src/webengine/webengineprofile.h | 8 | ||||
-rw-r--r-- | src/widgets/mainwindowmenubar.cpp | 3 | ||||
-rw-r--r-- | src/widgets/webviewtabbar.cpp | 2 |
14 files changed, 100 insertions, 88 deletions
@@ -3,6 +3,7 @@ _yet another Qt browser_ ### What is this and why should I care? The aim is to create a small, fast and clean web browser. + * minimal - just a browser, not a platform * configurable - settings file in plain sight and plain text diff --git a/data/poi.toml b/data/poi.toml index fe3a4fc..e5fc6ac 100644 --- a/data/poi.toml +++ b/data/poi.toml @@ -13,15 +13,13 @@ # - QStandardPaths::AppConfigLocation + "/poi.conf" # ## Variables -# §home is QStandardPaths::HomeLocation -# $cache is QStandardPaths::CacheLocation -# $settings is the directory where the settings file is located +# §home is QStandardPaths::HomeLocation, usually /home/username +# $cache is QStandardPaths::CacheLocation, usually /home/username/.cache/smolbote +# $settings is the directory where the settings file is located, usually /home/username/config/.smolbote # General [general] -homepage="https://duckduckgo.com" -newtab="about:blank" -search="https://duckduckgo.com/?q=$term&kp=-1" +search="https://duckduckgo.com/lite?q=$term" # FIXME remove; move to profile # Browser: application-wide settings [browser] @@ -32,11 +30,13 @@ search="https://duckduckgo.com/?q=$term&kp=-1" [browser.profile] default="" path="$home/.config/smolbote/profiles/" +storagePath="$home/.config/smolbote/profiles/" +cachePath="$home/.cache/smolbote/profiles/" [browser.profile.new] -path="$home/.config/smolbote/profiles" homepage="https://duckduckgo.com" newtab="about:blank" +search="https://duckduckgo.com/lite?q=$term" # FIXME # Main window settings [window] diff --git a/src/browser.cpp b/src/browser.cpp index 0c4191f..20a91dd 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -255,7 +255,13 @@ void Browser::removeWindow(MainWindow *window) WebEngineProfile* Browser::profile(const QString name) { if(!m_profiles.contains(name)) { - m_profiles.insert(name, new WebEngineProfile(name, this)); + if(name.isEmpty()) { + // Create off-the-record profile + m_profiles.insert(name, new WebEngineProfile(this)); + } else { + // Create regular profile + m_profiles.insert(name, new WebEngineProfile(name, this)); + } if(!m_urlRequestInterceptor) { m_urlRequestInterceptor = new UrlRequestInterceptor(this); diff --git a/src/forms/profilesdialog.cpp b/src/forms/profilesdialog.cpp index 34bd063..557d865 100644 --- a/src/forms/profilesdialog.cpp +++ b/src/forms/profilesdialog.cpp @@ -51,7 +51,9 @@ ProfilesDialog::ProfilesDialog(MainWindow *window, QWidget *parent) : connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(viewProfile(int))); connect(ui->new_toolButton, SIGNAL(released()), this, SLOT(newProfile())); - connect(this, SIGNAL(accepted()), this, SLOT(loadSelectedProfile())); + disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(loadSelectedProfile())); + connect(ui->buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), m_view, SLOT(updateProfile())); loadProfiles(); } diff --git a/src/forms/profilesdialog.ui b/src/forms/profilesdialog.ui index 7a140b5..7e8bad5 100644 --- a/src/forms/profilesdialog.ui +++ b/src/forms/profilesdialog.ui @@ -69,7 +69,7 @@ <enum>Qt::Horizontal</enum> </property> <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Save</set> </property> </widget> </item> diff --git a/src/forms/profileview.cpp b/src/forms/profileview.cpp index cece4e4..2695311 100644 --- a/src/forms/profileview.cpp +++ b/src/forms/profileview.cpp @@ -41,13 +41,13 @@ ProfileView::ProfileView(WebEngineProfile *profile, QWidget *parent) : // actions connect(ui->clearCache_pushButton, &QPushButton::clicked, [this]() { - this->_profile->clearHttpCache(); + this->m_profile->clearHttpCache(); }); connect(ui->clearHistory_pushButton, &QPushButton::clicked, [this]() { - this->_profile->clearAllVisitedLinks(); + this->m_profile->clearAllVisitedLinks(); }); - connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(updateProfile())); + //connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(updateProfile())); } ProfileView::~ProfileView() @@ -62,28 +62,28 @@ void ProfileView::setProfile(WebEngineProfile *profile) } //Q_ASSERT(profile); - _profile = profile; - setWindowTitle(_profile->name()); + m_profile = profile; + setWindowTitle(m_profile->name()); - m_cookiesForm = new CookiesForm(_profile->cookieStore(), this); + m_cookiesForm = new CookiesForm(m_profile->cookieStore(), this); //ui->tabWidget->addTab(m_cookiesForm, m_cookiesForm->windowTitle()); // general - ui->homepage_lineEdit->setText(_profile->homepage().toString()); - ui->newtab_lineEdit->setText(_profile->newtab().toString()); + ui->homepage_lineEdit->setText(m_profile->homepage().toString()); + ui->newtab_lineEdit->setText(m_profile->newtab().toString()); // http - ui->userAgent->setPlainText(_profile->httpUserAgent()); - ui->acceptLanguage->setPlainText(_profile->httpAcceptLanguage()); - ui->cacheType->setCurrentIndex(_profile->httpCacheType()); - ui->cacheSize->setText(QString::number(_profile->httpCacheMaximumSize())); + 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(_profile->persistentStoragePath()); - ui->cachePath_lineEdit->setText(_profile->cachePath()); + ui->storagePath_lineEdit->setText(m_profile->persistentStoragePath()); + ui->cachePath_lineEdit->setText(m_profile->cachePath()); // policy - ui->cookiePolicy->setCurrentIndex(_profile->persistentCookiesPolicy()); + ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy()); //ui->formLayout_3->addWidget(m_cookiesForm); ui->verticalLayout_3->addWidget(m_cookiesForm); @@ -97,44 +97,50 @@ void ProfileView::showProfile() void ProfileView::showCookies() { - ui->tabWidget->setCurrentIndex(4); + ui->tabWidget->setCurrentIndex(2); show(); } void ProfileView::updateProfile() { - qDebug("Updating profile..."); + 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 - _profile->setHttpUserAgent(ui->userAgent->toPlainText()); - _profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText()); + m_profile->setHttpUserAgent(ui->userAgent->toPlainText()); + m_profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText()); switch (ui->cacheType->currentIndex()) { case 0: - _profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache); + m_profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache); break; case 1: - _profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache); + m_profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache); break; case 2: - _profile->setHttpCacheType(QWebEngineProfile::NoCache); + m_profile->setHttpCacheType(QWebEngineProfile::NoCache); break; default: break; } - _profile->setHttpCacheMaximumSize(ui->cacheSize->text().toInt()); + m_profile->setHttpCacheMaximumSize(ui->cacheSize->text().toInt()); // policy switch (ui->cookiePolicy->currentIndex()) { case 0: - _profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); + m_profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); break; case 1: - _profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies); + m_profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies); break; case 2: - _profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies); + m_profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies); break; default: break; } + + m_profile->saveProfile(); } diff --git a/src/forms/profileview.h b/src/forms/profileview.h index 5dbdb59..a2ac98e 100644 --- a/src/forms/profileview.h +++ b/src/forms/profileview.h @@ -42,13 +42,11 @@ public: public slots: void showProfile(); void showCookies(); - -private slots: void updateProfile(); private: - WebEngineProfile *_profile; Ui::ProfileView *ui; + WebEngineProfile *m_profile; CookiesForm *m_cookiesForm; }; diff --git a/src/forms/profileview.ui b/src/forms/profileview.ui index bed045a..5823d02 100644 --- a/src/forms/profileview.ui +++ b/src/forms/profileview.ui @@ -216,13 +216,6 @@ </widget> </widget> </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="standardButtons"> - <set>QDialogButtonBox::Save</set> - </property> - </widget> - </item> </layout> </widget> <resources/> diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bda8bdb..856298d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -109,7 +109,7 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : if(!defaultUrl.isEmpty()) { newTab(defaultUrl); } else { - newTab(sSettings->value("general.homepage").toUrl()); + newTab(tabBar->profile()->homepage()); } resize(sSettings->value("window.width").toInt(), sSettings->value("window.height").toInt()); @@ -155,7 +155,7 @@ void MainWindow::newTab(const QUrl &url) if(!url.isEmpty()) { tabBar->addTab(url); } else { - tabBar->addTab(sSettings->value("general.newtab").toUrl()); + tabBar->addTab(tabBar->profile()->newtab()); } } @@ -241,13 +241,3 @@ void MainWindow::handleTitleUpdated(const QString &title) { setWindowTitle(sSettings->value("window.title").toString().replace("title", title).replace("profile", tabBar->profile()->name())); } - -void MainWindow::profileAction() -{ - tabBar->profile()->dialog()->showProfile(); -} - -void MainWindow::cookiesAction() -{ - tabBar->profile()->dialog()->showCookies(); -} diff --git a/src/mainwindow.h b/src/mainwindow.h index 2f5a662..4e0ed3a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -53,9 +53,6 @@ public slots: void newTab(const QUrl &url = QUrl("")); void newWindow(const QUrl &url = QUrl("")); - void profileAction(); - void cookiesAction(); - void setProfile(WebEngineProfile *profile); void toggleFullscreen(); diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp index 0a16cd5..583be3e 100644 --- a/src/webengine/webengineprofile.cpp +++ b/src/webengine/webengineprofile.cpp @@ -23,23 +23,38 @@ #include <QSettings> #include <QWebEngineSettings> -WebEngineProfile::WebEngineProfile(const QString &name, QObject *parent) : +WebEngineProfile::WebEngineProfile(QObject *parent) : QWebEngineProfile(parent) { - if(name.isEmpty()) { - m_name = tr("Off-the-record"); - // off-the-record should have no storage or cache - } else { - m_name = name; - setPersistentStoragePath(sSettings->value("browser.profile.path").toString() + name); - setCachePath(sSettings->value("browser.profile.path").toString() + name); - } + m_name = tr("Off-the-record"); - QString profilePath = sSettings->value("browser.profile.path").toString() + name + "/profile.ini"; - if(QFile::exists(profilePath)) { + // Off-the-record profiles have no persistent path - qDebug("Reading profile from [%s]", qUtf8Printable(profilePath)); - QSettings config(profilePath, QSettings::IniFormat); + m_homepage = sSettings->value("browser.profile.new.homepage").toUrl(); + m_newtab = sSettings->value("browser.profile.new.newtab").toUrl(); +} + +WebEngineProfile::WebEngineProfile(const QString &name, QObject *parent) : + QWebEngineProfile(name, parent) +{ + m_name = name; + setPersistentStoragePath(sSettings->value("browser.profile.storagePath").toString() + name); + setCachePath(sSettings->value("browser.profile.cachePath").toString() + name); + + // Read profile settings + QString profileIniPath = sSettings->value("browser.profile.path").toString() + name + "/profile.ini"; + + // If none exist, use the defaults + if(!QFile::exists(profileIniPath)) { + qDebug("Creating new profile..."); + m_homepage = sSettings->value("browser.profile.new.homepage").toUrl(); + m_newtab = sSettings->value("browser.profile.new.newtab").toUrl(); + + // Else read them + } else { + + qDebug("Reading profile from [%s]", qUtf8Printable(profileIniPath)); + QSettings config(profileIniPath, QSettings::IniFormat); m_homepage = config.value("homepage", m_homepage).toUrl(); m_newtab = config.value("newtab", m_newtab).toUrl(); @@ -117,17 +132,14 @@ QString WebEngineProfile::name() const return m_name; } -ProfileView *WebEngineProfile::dialog() +QUrl WebEngineProfile::homepage() const { - if(m_profileDialog == nullptr) { - m_profileDialog = new ProfileView(this); - } - return m_profileDialog; + return m_homepage; } -QUrl WebEngineProfile::homepage() const +void WebEngineProfile::setHomepage(const QUrl &url) { - return m_homepage; + m_homepage = url; } QUrl WebEngineProfile::newtab() const @@ -135,10 +147,18 @@ QUrl WebEngineProfile::newtab() const return m_newtab; } +void WebEngineProfile::setNewtab(const QUrl &url) +{ + m_newtab = url; +} + void WebEngineProfile::saveProfile() { QSettings config(persistentStoragePath() + "/profile.ini", QSettings::IniFormat); + config.setValue("homepage", homepage().toString()); + config.setValue("newtab", newtab().toString()); + config.beginGroup("http"); config.setValue("userAgent", httpUserAgent()); config.setValue("accept-lang", httpAcceptLanguage()); diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h index e225462..f457f53 100644 --- a/src/webengine/webengineprofile.h +++ b/src/webengine/webengineprofile.h @@ -29,16 +29,18 @@ class WebEngineProfile : public QWebEngineProfile { Q_OBJECT public: + explicit WebEngineProfile(QObject *parent = Q_NULLPTR); explicit WebEngineProfile(const QString &name, QObject *parent = Q_NULLPTR); ~WebEngineProfile(); QString name() const; + QUrl homepage() const; - QUrl newtab() const; + void setHomepage(const QUrl &url); - // TODO: remove - ProfileView *dialog(); + QUrl newtab() const; + void setNewtab(const QUrl &url); signals: diff --git a/src/widgets/mainwindowmenubar.cpp b/src/widgets/mainwindowmenubar.cpp index 4ad9d67..ba28607 100644 --- a/src/widgets/mainwindowmenubar.cpp +++ b/src/widgets/mainwindowmenubar.cpp @@ -69,9 +69,6 @@ MainWindowMenuBar::MainWindowMenuBar(MainWindow *parent) : QMenu *profileMenu = new QMenu(tr("Profile"), this); addMenu(profileMenu); profileMenu->addAction(tr("Profiles"), this, SLOT(handleLoadProfile())); - profileMenu->addSeparator(); - profileMenu->addAction(tr("View profile"), parent, SLOT(profileAction())); - profileMenu->addAction(tr("Cookies"), parent, SLOT(cookiesAction())); // Page menu QMenu *pageMenu = new QMenu(tr("Page"), this); diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp index bd24304..eb2e463 100644 --- a/src/widgets/webviewtabbar.cpp +++ b/src/widgets/webviewtabbar.cpp @@ -142,7 +142,7 @@ QSize WebViewTabBar::tabSizeHint(int index) const void WebViewTabBar::handleCurrentChanged(int index) { if(index < 0) { - addTab(QUrl::fromUserInput(sSettings->value("general.newtab").toString())); + addTab(profile()->newtab()); return; } emit currentTabChanged(m_views.at(index)); |