aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/web/profilemanager.cpp43
-rw-r--r--lib/web/profilemanager.h8
-rw-r--r--plugins/ProfileEditor/forms/profilemanagerdialog.cpp4
-rw-r--r--plugins/ProfileEditor/forms/profileview.cpp15
-rw-r--r--plugins/ProfileEditor/forms/profileview.ui37
-rw-r--r--plugins/interfaces.h1
-rw-r--r--src/browser.cpp6
-rw-r--r--src/browser.h1
-rw-r--r--src/main.cpp1
-rw-r--r--src/mainwindow/mainwindow.cpp17
-rw-r--r--src/subwindow/subwindow.cpp15
-rw-r--r--src/webengine/webview.cpp16
12 files changed, 102 insertions, 62 deletions
diff --git a/lib/web/profilemanager.cpp b/lib/web/profilemanager.cpp
index f3de3b5..b747bf6 100644
--- a/lib/web/profilemanager.cpp
+++ b/lib/web/profilemanager.cpp
@@ -43,18 +43,18 @@ WebProfile *ProfileManager::loadProfile(const QString &path)
Q_CHECK_PTR(ptr->profile);
ptr->profile->setSearch(ptr->settings.value("search", defaults.value("profile.search")).toString());
- connect(ptr->profile, &WebProfile::searchChanged, &ptr->settings, [&](const QString &url) {
- ptr->settings.setValue("search", url);
+ connect(ptr->profile, &WebProfile::searchChanged, &ptr->settings, [this, id](const QString &url) {
+ this->m_profiles.at(id)->settings.setValue("search", url);
});
ptr->profile->setHomepage(ptr->settings.value("homepage", defaults.value("profile.homepage")).toUrl());
- connect(ptr->profile, &WebProfile::homepageChanged, &ptr->settings, [&](const QUrl &url) {
- ptr->settings.setValue("homepage", url);
+ connect(ptr->profile, &WebProfile::homepageChanged, &ptr->settings, [this, id](const QUrl &url) {
+ this->m_profiles.at(id)->settings.setValue("homepage", url);
});
ptr->profile->setNewtab(ptr->settings.value("newtab", defaults.value("profile.newtab")).toUrl());
- connect(ptr->profile, &WebProfile::newtabChanged, &ptr->settings, [&](const QUrl &url) {
- ptr->settings.setValue("newtab", url);
+ connect(ptr->profile, &WebProfile::newtabChanged, &ptr->settings, [this, id](const QUrl &url) {
+ this->m_profiles.at(id)->settings.setValue("newtab", url);
});
ptr->settings.beginGroup("properties");
@@ -81,6 +81,28 @@ WebProfile *ProfileManager::loadProfile(const QString &path)
return m_profiles.at(id)->profile;
}
+QMenu *ProfileManager::createProfileMenu(std::function<void(WebProfile *)> callback, QWidget *parent) const
+{
+ QMenu *menu = new QMenu(parent);
+ for(auto it = m_profiles.cbegin(); it != m_profiles.cend(); ++it) {
+ WebProfile *profile = it->second->profile;
+ QAction *action = menu->addAction(profile->name());
+ connect(action, &QAction::triggered, [profile, callback]() {
+ callback(profile);
+ });
+ }
+ return menu;
+}
+
+const QStringList ProfileManager::idList() const
+{
+ QStringList ids;
+ for(auto it = m_profiles.cbegin(); it != m_profiles.cend(); ++it) {
+ ids.append(it->first);
+ }
+ return ids;
+}
+
const QString ProfileManager::id(WebProfile *profile) const
{
for(auto it = m_profiles.cbegin(); it != m_profiles.cend(); ++it) {
@@ -105,12 +127,3 @@ const QString ProfileManager::configurationPath(const QString &id) const
}
return QString();
}
-
-const QMap<QString, WebProfile *> ProfileManager::profileList() const
-{
- QMap<QString, WebProfile *> profiles;
- for(auto it = m_profiles.cbegin(); it != m_profiles.cend(); ++it) {
- profiles.insert(it->first, it->second->profile);
- }
- return profiles;
-}
diff --git a/lib/web/profilemanager.h b/lib/web/profilemanager.h
index f58fdb5..72af472 100644
--- a/lib/web/profilemanager.h
+++ b/lib/web/profilemanager.h
@@ -15,8 +15,8 @@
#include <QSettings>
#include <map>
#include <memory>
-
-typedef QMapIterator<QString, WebProfile *> ProfileIterator;
+#include <functional>
+#include <QMenu>
#define profileManager ProfileManager::instance()
@@ -32,10 +32,12 @@ public:
WebProfile *loadProfile(const QString &path);
+ QMenu *createProfileMenu(std::function<void(WebProfile *)> callback, QWidget *parent = nullptr) const;
+
+ const QStringList idList() const;
const QString id(WebProfile *profile) const;
WebProfile *profile(const QString &id) const;
const QString configurationPath(const QString &id) const;
- const QMap<QString, WebProfile *> profileList() const;
private:
struct ProfileData
diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp
index 7920f90..72c56de 100644
--- a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp
+++ b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp
@@ -27,8 +27,8 @@ ProfileManagerDialog::ProfileManagerDialog(const ProfileManager *profiles, QWidg
deleteProfile(ui->listWidget->currentItem());
});
- for(auto *profile : profiles->profileList().values()) {
- addProfile(profile);
+ for(const QString &profileId : profiles->idList()) {
+ addProfile(profiles->profile(profileId));
}
}
diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp
index e265e16..2ffb119 100644
--- a/plugins/ProfileEditor/forms/profileview.cpp
+++ b/plugins/ProfileEditor/forms/profileview.cpp
@@ -35,6 +35,21 @@ ProfileView::ProfileView(WebProfile *profile, QWidget *parent)
ui->name->setText(profile->name());
ui->offTheRecord->setChecked(profile->isOffTheRecord());
+ ui->homepage->setText(profile->homepage().toString());
+ connect(ui->homepage, &QLineEdit::editingFinished, profile, [=]() {
+ profile->setHomepage(QUrl::fromUserInput(ui->homepage->text()));
+ });
+
+ ui->newtab->setText(profile->newtab().toString());
+ connect(ui->newtab, &QLineEdit::editingFinished, profile, [=]() {
+ profile->setNewtab(QUrl::fromUserInput(ui->newtab->text()));
+ });
+
+ ui->search->setText(profile->search());
+ connect(ui->search, &QLineEdit::editingFinished, profile, [=]() {
+ profile->setSearch(ui->search->text());
+ });
+
// http tab
ui->userAgent->setPlainText(m_profile->httpUserAgent());
connect(ui->userAgent, &QPlainTextEdit::textChanged, profile, [=]() {
diff --git a/plugins/ProfileEditor/forms/profileview.ui b/plugins/ProfileEditor/forms/profileview.ui
index 6c2edda..2b25184 100644
--- a/plugins/ProfileEditor/forms/profileview.ui
+++ b/plugins/ProfileEditor/forms/profileview.ui
@@ -68,6 +68,43 @@
</property>
</widget>
</item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="homepage_label">
+ <property name="text">
+ <string>Homepage</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="newtab_label">
+ <property name="text">
+ <string>New tab page</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="search_label">
+ <property name="text">
+ <string>Search</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QLineEdit" name="newtab"/>
+ </item>
+ <item row="6" column="1">
+ <widget class="QLineEdit" name="search"/>
+ </item>
+ <item row="4" column="1">
+ <widget class="QLineEdit" name="homepage"/>
+ </item>
+ <item row="3" column="1">
+ <widget class="Line" name="line_8">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<widget class="QWidget" name="httpTab">
diff --git a/plugins/interfaces.h b/plugins/interfaces.h
index 7ee10db..681a79e 100644
--- a/plugins/interfaces.h
+++ b/plugins/interfaces.h
@@ -28,7 +28,6 @@ public:
virtual QPair<QString, WebProfile *> loadProfile(const QString &id) = 0;
virtual const ProfileManager *getProfileManager() const = 0;
- virtual const QVector<WebProfile *> profiles() const = 0;
};
struct Plugin
diff --git a/src/browser.cpp b/src/browser.cpp
index 1e2ad25..493493f 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -139,12 +139,6 @@ void Browser::setup(const QString &defaultProfile)
});
}
-const QVector<WebProfile *> Browser::profiles() const
-{
- const QMap<QString, WebProfile *> profileList = profileManager->profileList();
- return QVector<WebProfile *>::fromList(profileList.values());
-}
-
void Browser::createSession(const QJsonObject &object)
{
MainWindow *mainwindow = nullptr;
diff --git a/src/browser.h b/src/browser.h
index 6969087..c82afa0 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -40,7 +40,6 @@ public:
Configuration *getConfiguration() const override;
const ProfileManager *getProfileManager() const override;
- const QVector<WebProfile *> profiles() const override;
QPair<QString, WebProfile *> loadProfile(const QString &id) override;
void setConfiguration(std::unique_ptr<Configuration> &config);
diff --git a/src/main.cpp b/src/main.cpp
index 405210f..12961ff 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -141,6 +141,7 @@ int main(int argc, char **argv)
// if app is primary, create new sessions from received messages
if(app.isPrimary() && !isStandalone) {
QObject::connect(&app, &Browser::receivedMessage, &app, [&app](quint32 instanceId, QByteArray message) {
+ Q_UNUSED(instanceId);
auto doc = QJsonDocument::fromJson(message);
app.createSession(doc.object());
});
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 91e820a..eb4d34f 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -161,6 +161,7 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *pa
QPrintDialog dlg(printer, this);
if(dlg.exec() == QDialog::Accepted) {
currentView->page()->print(printer, [printer](bool success) {
+ Q_UNUSED(success);
delete printer;
});
}
@@ -379,19 +380,9 @@ void MainWindow::updatePageLoadProfileMenu()
if(currentView == nullptr)
return;
- auto *browser = qobject_cast<Browser *>(qApp);
- Q_CHECK_PTR(browser);
-
- ProfileIterator it(profileManager->profileList());
- while(it.hasNext()) {
- it.next();
- auto *profile = it.value();
- auto *loadAction = pageLoadProfileMenu->addAction(profile->name());
-
- connect(loadAction, &QAction::triggered, this, [=]() {
- currentView->setProfile(profile);
- });
- }
+ pageLoadProfileMenu->addActions(profileManager->createProfileMenu([this](WebProfile *profile) {
+ this->currentView->setProfile(profile);
+ }, this)->actions());
}
void MainWindow::closeEvent(QCloseEvent *event)
diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp
index 4e79a03..0873010 100644
--- a/src/subwindow/subwindow.cpp
+++ b/src/subwindow/subwindow.cpp
@@ -50,17 +50,10 @@ SubWindow::SubWindow(const std::unique_ptr<Configuration> &config, QWidget *pare
Browser *browser = qobject_cast<Browser *>(qApp);
Q_CHECK_PTR(browser);
- ProfileIterator it(profileManager->profileList());
- while(it.hasNext()) {
- it.next();
- auto *profile = it.value();
- auto *loadAction = loadProfile_menu->addAction(profile->name());
-
- connect(loadAction, &QAction::triggered, this, [=]() {
- this->setProfile(profile);
- profileName_action->setText(tr("Profile: %1").arg(profile->name()));
- });
- }
+ loadProfile_menu->addActions(profileManager->createProfileMenu([this, profileName_action](WebProfile *profile) {
+ this->setProfile(profile);
+ profileName_action->setText(tr("Profile: %1").arg(profile->name()));
+ }, this)->actions());
menu->insertSeparator(firstAction);
}
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index 94f73bc..963a894 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -243,16 +243,12 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
createWindow(QWebEnginePage::WebBrowserTab)->load(ctxdata.linkUrl());
});
- auto *newTabMenu = new QMenu(tr("Open link in new tab with profile"), this);
- ProfileIterator it(profileManager->profileList());
- while(it.hasNext()) {
- it.next();
- connect(newTabMenu->addAction(it.key()), &QAction::triggered, this, [this, ctxdata, it]() {
- auto *view = createWindow(QWebEnginePage::WebBrowserTab);
- view->setProfile(it.value());
- view->load(ctxdata.linkUrl());
- });
- }
+ QMenu *newTabMenu = profileManager->createProfileMenu([this, ctxdata](WebProfile *profile) {
+ auto *view = this->createWindow(QWebEnginePage::WebBrowserTab);
+ view->setProfile(profile);
+ view->load(ctxdata.linkUrl());
+ }, this);
+ newTabMenu->setTitle(tr("Open link in new tab with profile"));
menu->addMenu(newTabMenu);
connect(menu->addAction(tr("Open link in new window")), &QAction::triggered, this, [this, ctxdata]() {