aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUGS.md5
-rw-r--r--src/browser.cpp18
-rw-r--r--src/browser.h2
-rw-r--r--src/main.cpp11
-rw-r--r--src/mainwindow.cpp6
-rw-r--r--src/singleapplication.cpp36
-rw-r--r--src/singleapplication.h12
7 files changed, 25 insertions, 65 deletions
diff --git a/BUGS.md b/BUGS.md
index 7392a8a..3b8f03c 100644
--- a/BUGS.md
+++ b/BUGS.md
@@ -15,14 +15,11 @@ https://bugreports.qt.io/browse/QTBUG-62957
## To do list
List of things to do before 1.0 release
-### Instance check on startup
-- review SingleApplication::SessionParam
-
### Auto-destruct cookies
- cookie whitelist and blacklist
### Adblocker
-- adblocker load list (.config/smolbote/filter.d/**.txt)
+- adblocker load list (.config/smolbote/filter.d/*.txt)
### No Script
- there's already a profile setting to disable scripts
diff --git a/src/browser.cpp b/src/browser.cpp
index 25ff5fb..4221eb9 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -98,16 +98,18 @@ MainWindow *Browser::createWindow()
return window;
}
-MainWindow *Browser::createSession(const SessionParam &params)
+MainWindow *Browser::createSession(const QString &profileName, bool newWindow, const QStringList &urls)
{
MainWindow *window = nullptr;
- if(params.newWindow || m_windows.isEmpty()) {
+
+ // if we need to open in a new window, or there are no windows, make one
+ if(newWindow || m_windows.isEmpty()) {
window = createWindow();
- window->setProfile(profile(params.profile));
+ window->setProfile(profile(profileName));
} else {
// reverse-iterate through windows to check for window with the same profile
for(auto it = m_windows.rbegin(); it != m_windows.rend(); ++it) {
- if((*it)->profile()->storageName() == params.profile) {
+ if((*it)->profile()->storageName() == profileName) {
window = *it;
break;
}
@@ -115,18 +117,18 @@ MainWindow *Browser::createSession(const SessionParam &params)
// if none is found, create one
if(window == nullptr) {
window = createWindow();
- window->setProfile(profile(params.profile));
+ window->setProfile(profile(profileName));
}
}
Q_CHECK_PTR(window);
- if(params.urls.isEmpty()) {
+ if(urls.isEmpty()) {
// no URLs were given
window->newTab(QUrl::fromUserInput(m_config->value<std::string>("profile.homepage").value().c_str()));
} else {
- for(const QUrl &url : params.urls) {
- window->newTab(url);
+ for(const QString &url : urls) {
+ window->newTab(QUrl::fromUserInput(url));
}
}
diff --git a/src/browser.h b/src/browser.h
index 52dc97e..ceb98d5 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -34,7 +34,7 @@ public:
// QStringList profiles();
public slots:
- MainWindow *createSession(const SessionParam &params);
+ MainWindow *createSession(const QString &profileName, bool newWindow, const QStringList &urls);
private:
Q_DISABLE_COPY(Browser)
diff --git a/src/main.cpp b/src/main.cpp
index e8307c6..084e102 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -119,13 +119,6 @@ int main(int argc, char *argv[])
return 0;
}
- Browser::SessionParam sessionParams;
- sessionParams.profile = parser.value(profileOption);
- sessionParams.newWindow = parser.isSet(newWindowOption);
- for(const QString &url : parser.positionalArguments()) {
- sessionParams.urls.append(QUrl::fromUserInput(url));
- }
-
// TODO: check for other instances
// if we socket hasn't been disabled (socket is not none)
if(parser.value(socketOption) != "none") {
@@ -134,7 +127,7 @@ int main(int argc, char *argv[])
qDebug("Connected to local socket: %s", qUtf8Printable(instance.serverName()));
} else {
// pass arguments to new instance
- return instance.sendMessage(sessionParams);
+ return instance.sendMessage(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments());
}
}
@@ -173,7 +166,7 @@ int main(int argc, char *argv[])
instance.setConfiguration(config);
instance.loadProfiles();
- instance.createSession(sessionParams);
+ instance.createSession(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments());
#ifdef QT_DEBUG
qDebug("Startup complete in %lldms", timer.elapsed());
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 66d0092..01abc85 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -182,11 +182,7 @@ void MainWindow::newTab(const QUrl &url)
MainWindow *MainWindow::newWindow(const QUrl &url)
{
Browser *instance = static_cast<Browser*>(qApp->instance());
- Browser::SessionParam params;
- params.profile = m_profile->storageName();
- params.newWindow = true;
- params.urls.append(url);
- return instance->createSession(params);
+ return instance->createSession(m_profile->storageName(), true, QStringList(url.toString()));
}
void MainWindow::focusAddress()
diff --git a/src/singleapplication.cpp b/src/singleapplication.cpp
index e71d1be..0f928df 100644
--- a/src/singleapplication.cpp
+++ b/src/singleapplication.cpp
@@ -10,33 +10,8 @@
#include <QLocalServer>
#include <QLocalSocket>
#include <QDataStream>
-#include <QUrl>
#include <cstdlib>
-QHash<QString, QVariant> paramStructToHash(const SingleApplication::SessionParam &params)
-{
- QHash<QString, QVariant> hashedParams;
- hashedParams.insert("profile", params.profile);
- hashedParams.insert("newWindow", params.newWindow);
- QList<QVariant> urls;
- for(const QUrl &url : params.urls) {
- urls.append(url);
- }
- hashedParams.insert("urls", urls);
- return hashedParams;
-}
-
-SingleApplication::SessionParam paramStructFromHash(const QHash<QString, QVariant> &params)
-{
- SingleApplication::SessionParam structParams;
- structParams.profile = params.value("profile").toString();
- structParams.newWindow = params.value("newWindow").toBool();
- for(const QVariant &val : params.value("urls").toList()) {
- structParams.urls.append(val.toUrl());
- }
- return structParams;
-}
-
SingleApplication::SingleApplication(int &argc, char **argv) : QApplication(argc, argv)
{
#ifdef Q_OS_UNIX
@@ -100,14 +75,19 @@ QString SingleApplication::serverName() const
return m_localServer->fullServerName();
}
-int SingleApplication::sendMessage(const SessionParam &params)
+int SingleApplication::sendMessage(const QString &profileName, bool newWindow, const QStringList &urls)
{
QLocalSocket socket;
socket.connectToServer(LOCALSERVER_KEY);
if(socket.waitForConnected(LOCALSERVER_TIMEOUT)) {
+ QHash<QString, QVariant> hashedParams;
+ hashedParams.insert("profile", profileName);
+ hashedParams.insert("newWindow", newWindow);
+ hashedParams.insert("urls", urls);
+
QByteArray argumentData;
QDataStream ds(&argumentData, QIODevice::WriteOnly);
- ds << paramStructToHash(params);
+ ds << hashedParams;
socket.write(argumentData);
socket.waitForBytesWritten(LOCALSERVER_TIMEOUT);
@@ -140,5 +120,5 @@ void SingleApplication::parseMessage()
socket->deleteLater();
- emit messageAvailable(paramStructFromHash(params));
+ emit messageAvailable(params["profile"].toString(), params["newWindow"].toBool(), params["urls"].toStringList());
}
diff --git a/src/singleapplication.h b/src/singleapplication.h
index fd9ce39..59361b1 100644
--- a/src/singleapplication.h
+++ b/src/singleapplication.h
@@ -10,7 +10,6 @@
#define SINGLEAPPLICATION_H
#include <QApplication>
-#include <QVector>
class QLocalServer;
class SingleApplication : public QApplication
@@ -19,23 +18,16 @@ class SingleApplication : public QApplication
public:
- struct SessionParam
- {
- QString profile;
- bool newWindow;
- QVector<QUrl> urls;
- };
-
explicit SingleApplication(int &argc, char **argv);
~SingleApplication();
bool bindLocalSocket(const QString &name = QString());
QString serverName() const;
- int sendMessage(const SessionParam &params);
+ int sendMessage(const QString &profileName, bool newWindow, const QStringList &urls);
signals:
- void messageAvailable(const SessionParam &params);
+ void messageAvailable(const QString &profileName, bool newWindow, const QStringList &urls);
private slots:
void parseMessage();