aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-06-05 18:07:27 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-06-05 18:07:27 +0200
commit0f41f33263b7d09b1cac3b66beb4b3c5931f68ce (patch)
tree284aacbb197520ea7092ea0172531aea188b6336
parentAdd QString cast to Configuration::value (diff)
downloadsmolbote-0f41f33263b7d09b1cac3b66beb4b3c5931f68ce.tar.xz
Fix clazy warnings in WebProfile
- add missing notify signals - add more properties - apply defaults to all profiles - update manpage
-rw-r--r--linux/man/smolbote.7.ronn18
-rw-r--r--src/browser.cpp10
-rw-r--r--src/webengine/webprofile.cpp112
-rw-r--r--src/webengine/webprofile.h82
4 files changed, 151 insertions, 71 deletions
diff --git a/linux/man/smolbote.7.ronn b/linux/man/smolbote.7.ronn
index 40f6d5b..060c167 100644
--- a/linux/man/smolbote.7.ronn
+++ b/linux/man/smolbote.7.ronn
@@ -90,12 +90,30 @@ set of default plugins is installed in /usr/lib/smolbote.
* plugins.path: ~/.config/smolbote/plugins.d
### Profiles
+A Profile is a collection of settings, policies, scripts, cookies, cache and
+history. Profiles can be used to isolate pages from each other.
+
+Each window has a default profile it uses when opening new tabs. This can be
+changed from the window's menu. Additionally, tabs can have their profiles
+individually changed from their context menu.
+
+Because profiles store all their data separately, you can log in into the same
+site with a different account from each profile. However, links opened into new
+tabs will still use the subwindow's default profile. For example, you can set a
+profile to hold login information for a site, but all new tabs opened from that
+site would still be using the default off-the-record profile.
+
* profile.default: ''
* profile.path: ~/.config/smolbote/profiles.d
* profile.search: https://duckduckgo.com/?q=%1&ia=web
* profile.homepage: about:blank
* profile.newtab: about:blank
+An off-the-record profile is always created, with config read from
+profile.path/otr.ini. Additional non-otr profiles named from all files matching
+'*.profile' in profile.path are also created, and their properties are set from
+their respective name.profile.
+
### Bookmarks
* bookmarks.path: ~/.config/smolbote/bookmarks.xbel
* bookmarks.shortcut: Ctrl+B
diff --git a/src/browser.cpp b/src/browser.cpp
index 4f3f3d7..2985dd3 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -51,7 +51,7 @@ inline QVector<Plugin> loadPlugins(const QString &location)
return list;
}
-inline QHash<QString, WebProfile *> loadProfiles(const QString &location)
+inline QHash<QString, WebProfile *> loadProfiles(const QHash<QString, QString> &defaults, const QString &location)
{
QDir profilesDir(location);
QHash<QString, WebProfile *> list;
@@ -60,7 +60,7 @@ inline QHash<QString, WebProfile *> loadProfiles(const QString &location)
const QFileInfoList entries = profilesDir.entryInfoList({ "*.profile" }, QDir::Files | QDir::Readable);
for(const auto &entry : entries) {
auto *profile = new WebProfile(entry.baseName());
- loadProfile(profile, entry.absoluteFilePath());
+ loadProfile(profile, defaults, entry.absoluteFilePath());
list.insert(entry.baseName(), profile);
}
}
@@ -101,10 +101,10 @@ void Browser::setup(const QString &defaultProfile)
// load profiles
{
- auto *otr = new WebProfile(m_config->section("profile"), this);
- loadProfile(otr, QString::fromStdString(m_config->value<std::string>("profile.path").value()) + "/otr.ini");
+ auto *otr = new WebProfile(this);
+ loadProfile(otr, m_config->section("profile"), QString::fromStdString(m_config->value<std::string>("profile.path").value()) + "/otr.ini");
m_profiles.insert(tr("Off-the-record"), otr);
- m_profiles.unite(loadProfiles(QString::fromStdString(m_config->value<std::string>("profile.path").value())));
+ m_profiles.unite(loadProfiles(m_config->section("profile"), QString::fromStdString(m_config->value<std::string>("profile.path").value())));
if(defaultProfile == "") {
WebProfile::setDefaultProfile(otr);
diff --git a/src/webengine/webprofile.cpp b/src/webengine/webprofile.cpp
index 5b07645..b40a98c 100644
--- a/src/webengine/webprofile.cpp
+++ b/src/webengine/webprofile.cpp
@@ -14,8 +14,14 @@
WebProfile *WebProfile::profile = nullptr;
-void loadProfile(WebProfile *profile, const QString &path)
+void loadProfile(WebProfile *profile, const QHash<QString, QString> &defaults, const QString &path)
{
+ Q_CHECK_PTR(profile);
+
+ profile->setSearch(defaults.value("profile.search"));
+ profile->setHomepage(QUrl::fromUserInput(defaults.value("profile.homepage")));
+ profile->setNewtab(QUrl::fromUserInput(defaults.value("profile.newtab")));
+
// return if there is no config file
if(!QFileInfo::exists(path))
return;
@@ -50,38 +56,9 @@ void loadProfile(WebProfile *profile, const QString &path)
}
}
config.endGroup();
-
-// config.beginGroup("http");
-// setHttpUserAgent(config.value("userAgent", httpUserAgent()).toString());
-// setHttpAcceptLanguage(config.value("accept-lang", httpAcceptLanguage()).toString());
-// {
-// QString cacheType = config.value("cacheType").toString();
-// if(cacheType == "memory") {
-// setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
-// } else if(cacheType == "disk") {
-// setHttpCacheType(QWebEngineProfile::DiskHttpCache);
-// } else if(cacheType == "disabled") {
-// setHttpCacheType(QWebEngineProfile::NoCache);
-// }
-// }
-// setHttpCacheMaximumSize(config.value("cacheSize", httpCacheMaximumSize()).toInt());
-// config.endGroup(); // http
-
-// config.beginGroup("policy");
-// {
-// QString cookies = config.value("cookies").toString();
-// if(cookies == "disabled") {
-// setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
-// } else if(cookies == "allow") {
-// setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
-// } else if(cookies == "force") {
-// setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
-// }
-// }
-// config.endGroup(); // policy
}
-WebProfile::WebProfile(const QHash<QString, QString> &defaults, QObject *parent)
+WebProfile::WebProfile(QObject *parent)
: QWebEngineProfile(parent)
{
m_name = tr("Off-the-record");
@@ -89,10 +66,6 @@ WebProfile::WebProfile(const QHash<QString, QString> &defaults, QObject *parent)
#ifdef QT_DEBUG
qDebug("Creating off-the-record profile");
#endif
-
- m_search = defaults.value("profile.search");
- m_homepage = QUrl::fromUserInput(defaults.value("profile.homepage"));
- m_newtab = QUrl::fromUserInput(defaults.value("profile.newtab"));
}
WebProfile::WebProfile(const QString &name, QObject *parent)
@@ -105,4 +78,71 @@ WebProfile::WebProfile(const QString &name, QObject *parent)
#endif
}
-WebProfile::~WebProfile() = default;
+QString WebProfile::search() const
+{
+ return m_search;
+}
+
+void WebProfile::setSearch(const QString &url)
+{
+ m_search = url;
+ emit searchChanged(m_search);
+}
+
+QUrl WebProfile::homepage() const
+{
+ return m_homepage;
+}
+
+void WebProfile::setHomepage(const QUrl &url)
+{
+ m_homepage = url;
+ emit homepageChanged(m_homepage);
+}
+
+QUrl WebProfile::newtab() const
+{
+ return m_newtab;
+}
+
+void WebProfile::setNewtab(const QUrl &url)
+{
+ m_newtab = url;
+ emit newtabChanged(m_newtab);
+}
+
+void WebProfile::setCachePath(const QString &path)
+{
+ QWebEngineProfile::setCachePath(path);
+ emit cachePathChanged(QWebEngineProfile::cachePath());
+}
+
+void WebProfile::setPersistentStoragePath(const QString &path)
+{
+ QWebEngineProfile::setPersistentStoragePath(path);
+ emit persistentStoragePathChanged(QWebEngineProfile::persistentStoragePath());
+}
+
+void WebProfile::setHttpAcceptLanguage(const QString &httpAcceptLanguage)
+{
+ QWebEngineProfile::setHttpAcceptLanguage(httpAcceptLanguage);
+ emit httpAcceptLanguageChanged(QWebEngineProfile::httpAcceptLanguage());
+}
+
+void WebProfile::setHttpCacheMaximumSize(int maxSize)
+{
+ QWebEngineProfile::setHttpCacheMaximumSize(maxSize);
+ emit httpCacheMaximumSizeChanged(QWebEngineProfile::httpCacheMaximumSize());
+}
+
+void WebProfile::setHttpUserAgent(const QString &userAgent)
+{
+ QWebEngineProfile::setHttpUserAgent(userAgent);
+ emit httpUserAgentChanged(QWebEngineProfile::httpUserAgent());
+}
+
+void WebProfile::setSpellCheckEnabled(bool enable)
+{
+ QWebEngineProfile::setSpellCheckEnabled(enable);
+ emit spellCheckEnabledChanged(QWebEngineProfile::isSpellCheckEnabled());
+}
diff --git a/src/webengine/webprofile.h b/src/webengine/webprofile.h
index 1e3ac64..31c5b44 100644
--- a/src/webengine/webprofile.h
+++ b/src/webengine/webprofile.h
@@ -18,15 +18,27 @@ class WebProfile : public QWebEngineProfile
{
Q_OBJECT
- Q_PROPERTY(QString search READ search WRITE setSearch)
- Q_PROPERTY(QUrl homepage READ homepage WRITE setHomepage)
- Q_PROPERTY(QUrl newtab READ newtab WRITE setNewtab)
+ Q_PROPERTY(QString search READ search WRITE setSearch NOTIFY searchChanged)
+ Q_PROPERTY(QUrl homepage READ homepage WRITE setHomepage NOTIFY homepageChanged)
+ Q_PROPERTY(QUrl newtab READ newtab WRITE setNewtab NOTIFY newtabChanged)
+
+ // QWebEngineProfile should-be properties
+ Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath NOTIFY cachePathChanged)
+ Q_PROPERTY(QString persistentStoragePath READ persistentStoragePath WRITE setPersistentStoragePath NOTIFY persistentStoragePathChanged)
+
+ Q_PROPERTY(QString httpAcceptLanguage READ httpAcceptLanguage WRITE setHttpAcceptLanguage NOTIFY httpAcceptLanguageChanged)
+ Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY httpCacheMaximumSizeChanged)
+ Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY httpUserAgentChanged)
+
+ Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY spellCheckEnabledChanged)
public:
- explicit WebProfile(const QHash<QString, QString> &defaults, QObject *parent = nullptr);
+ // off-the-record constructor
+ explicit WebProfile(QObject *parent = nullptr);
+ // default constructor
explicit WebProfile(const QString &name, QObject *parent = nullptr);
- ~WebProfile() override;
+ ~WebProfile() = default;
static void setDefaultProfile(WebProfile *profile)
{
@@ -43,30 +55,27 @@ public:
{
return m_name;
}
- QString search() const
- {
- return m_search;
- }
- void setSearch(const QString &url)
- {
- m_search = url;
- }
- QUrl homepage() const
- {
- return m_homepage;
- }
- void setHomepage(const QUrl &url)
- {
- m_homepage = url;
- }
- QUrl newtab() const
- {
- return m_newtab;
- }
- void setNewtab(const QUrl &url)
- {
- m_newtab = url;
- }
+
+ // search url
+ QString search() const;
+ void setSearch(const QString &url);
+
+ // homepage url
+ QUrl homepage() const;
+ void setHomepage(const QUrl &url);
+
+ // new tab url
+ QUrl newtab() const;
+ void setNewtab(const QUrl &url);
+
+ void setCachePath(const QString &path);
+ void setPersistentStoragePath(const QString &path);
+
+ void setHttpAcceptLanguage(const QString &httpAcceptLanguage);
+ void setHttpCacheMaximumSize(int maxSize);
+ void setHttpUserAgent(const QString &userAgent);
+
+ void setSpellCheckEnabled(bool enable);
void addBookmark(const QString &title, const QString &url)
{
@@ -77,6 +86,19 @@ public:
signals:
void addBookmarkRequested(const QString &title, const QString &url);
+ void searchChanged(const QString &url);
+ void homepageChanged(const QUrl &url);
+ void newtabChanged(const QUrl &url);
+
+ void cachePathChanged(const QString &path);
+ void persistentStoragePathChanged(const QString &path);
+
+ void httpAcceptLanguageChanged(const QString &httpAcceptLanguage);
+ void httpCacheMaximumSizeChanged(int maxSize);
+ void httpUserAgentChanged(const QString &userAgent);
+
+ void spellCheckEnabledChanged(bool enable);
+
private:
static WebProfile *profile;
@@ -86,7 +108,7 @@ private:
QUrl m_newtab = QUrl("about:blank");
};
-void loadProfile(WebProfile *profile, const QString &path);
+void loadProfile(WebProfile *profile, const QHash<QString, QString> &defaults, const QString &path);
//WebProfile *saveProfile(WebProfile *profile, const QString &path);
#endif // SMOLBOTE_WEBENGINEPROFILE_H