aboutsummaryrefslogtreecommitdiff
path: root/src/session
diff options
context:
space:
mode:
Diffstat (limited to 'src/session')
-rw-r--r--src/session/session.cpp78
-rw-r--r--src/session/session.h4
-rw-r--r--src/session/sessiondialog.cpp24
-rw-r--r--src/session/sessiondialog.h3
-rw-r--r--src/session/sessiondialog.ui5
5 files changed, 58 insertions, 56 deletions
diff --git a/src/session/session.cpp b/src/session/session.cpp
index 0853c70..10aca4e 100644
--- a/src/session/session.cpp
+++ b/src/session/session.cpp
@@ -19,46 +19,7 @@
#include <memory>
#include "configuration.h"
-QJsonObject Session::session(QVector<MainWindow *> windows)
-{
- QJsonObject obj;
-
- QJsonArray windowsArray;
- for(const MainWindow *window : windows) {
- windowsArray.append(Session::window(window));
- }
- obj.insert("windows", windowsArray);
-
- return obj;
-}
-
-QJsonObject Session::window(const MainWindow *window)
-{
- QJsonObject obj;
- auto *profileManager = dynamic_cast<Browser *>(qApp)->getProfileManager();
-
- QJsonArray subwindows;
- for(const SubWindow *subwindow : window->subWindows()) {
- QJsonObject window;
- window.insert("profile", profileManager->id(subwindow->profile()));
-
- QJsonArray tabs;
- for(int i = 0; i < subwindow->tabCount(); ++i) {
- QJsonObject tab;
- tab.insert("url", subwindow->view(i)->url().toString());
- tab.insert("profile", profileManager->id(subwindow->view(i)->profile()));
- tabs.append(tab);
- }
- window.insert("tabs", tabs);
-
- subwindows.append(window);
- }
- obj.insert("subwindows", subwindows);
-
- return obj;
-}
-
-QJsonObject Session::window(const QString &profile, const QStringList &urls)
+QJsonObject Session::fromCommandLine(const QString &profile, const QStringList &urls)
{
QJsonObject session;
@@ -162,10 +123,15 @@ void Session::restoreView(WebView *view, const QJsonObject &data)
if(profile)
view->setProfile(profile);
- // restore history: toLatin1 (turn into bytearray), fromBase64, uncompress
- QByteArray historyData = qUncompress(QByteArray::fromBase64(data["history"].toString().toLatin1()));
- QDataStream historyStream(&historyData, QIODevice::ReadOnly);
- historyStream >> *view->history();
+ auto url = data.value("url");
+ if(url.isString())
+ view->load(QUrl::fromUserInput(url.toString()));
+ else {
+ // restore history: toLatin1 (turn into bytearray), fromBase64, uncompress
+ QByteArray historyData = qUncompress(QByteArray::fromBase64(data["history"].toString().toLatin1()));
+ QDataStream historyStream(&historyData, QIODevice::ReadOnly);
+ historyStream >> *view->history();
+ }
}
void Session::restoreSession(const QJsonObject &sessionData)
@@ -175,12 +141,32 @@ void Session::restoreSession(const QJsonObject &sessionData)
auto *profileManager = browser->getProfileManager();
Q_CHECK_PTR(profileManager);
+ for(const auto subwindowData : sessionData["subwindows"].toArray()) {
+ MainWindow *window = nullptr;
+ SubWindow *subwindow = nullptr;
+
+ if(!browser->windows().isEmpty()) {
+ window = browser->windows().last();
+ subwindow = window->currentSubWindow();
+ } else {
+ window = browser->createWindow();
+ subwindow = window->createSubWindow(browser->getConfiguration(), profileManager->profile(subwindowData.toObject()["profile"].toString()));
+ }
+
+ Q_CHECK_PTR(window);
+ Q_CHECK_PTR(subwindow);
+
+ for(const auto tabData : subwindowData.toObject()["tabs"].toArray()) {
+ auto *view = subwindow->view(subwindow->addTab());
+ Session::restoreView(view, tabData.toObject());
+ }
+ }
+
for(const auto windowData : sessionData["windows"].toArray()) {
auto *window = browser->createWindow();
for(const auto subwindowData : windowData.toObject()["subwindows"].toArray()) {
- auto *subwindow = window->createSubWindow(browser->getConfiguration(), WebProfile::defaultProfile());
- subwindow->setProfile(profileManager->profile(subwindowData.toObject()["profile"].toString()));
+ auto *subwindow = window->createSubWindow(browser->getConfiguration(), profileManager->profile(subwindowData.toObject()["profile"].toString()));
for(const auto tabData : subwindowData.toObject()["tabs"].toArray()) {
auto *view = subwindow->view(subwindow->addTab());
diff --git a/src/session/session.h b/src/session/session.h
index 720b711..8a96bb2 100644
--- a/src/session/session.h
+++ b/src/session/session.h
@@ -16,9 +16,7 @@ class SubWindow;
class WebView;
namespace Session {
-QJsonObject session(QVector<MainWindow *> windows);
-QJsonObject window(const MainWindow *window);
-QJsonObject window(const QString &profile, const QStringList &urls);
+QJsonObject fromCommandLine(const QString &profile, const QStringList &urls);
// TODO:
QJsonObject _session(const QVector<MainWindow *> windows);
diff --git a/src/session/sessiondialog.cpp b/src/session/sessiondialog.cpp
index 5fd65c3..287950d 100644
--- a/src/session/sessiondialog.cpp
+++ b/src/session/sessiondialog.cpp
@@ -37,9 +37,7 @@ SessionDialog::SessionDialog(QWidget *parent)
ui->listWidget->setItemWidget(item, widget);
}
-#ifdef QT_DEBUG
- ui->listWidget->addItem(tr("Start new session"));
-#endif
+ ui->listWidget->addItem(tr("Create a new window"));
connect(ui->listWidget, &QListWidget::currentItemChanged, this, [this](QListWidgetItem *currentItem, QListWidgetItem *previousItem) {
auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(currentItem));
@@ -60,11 +58,15 @@ SessionDialog::SessionDialog(QWidget *parent)
}
});
- connect(this, &SessionDialog::accepted, this, [this]() {
+ connect(this, &SessionDialog::accepted, this, [this, browser]() {
auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(ui->listWidget->currentItem()));
if(currentWidget)
this->openSession(currentWidget->ui->label->text());
+ else
+ browser->createWindow();
});
+
+ connect(ui->search, &QLineEdit::textEdited, this, &SessionDialog::search);
}
SessionDialog::~SessionDialog()
@@ -72,6 +74,19 @@ SessionDialog::~SessionDialog()
delete ui;
}
+void SessionDialog::search(const QString &text)
+{
+ for(int i = 0; i < ui->listWidget->count(); ++i) {
+ auto *item = ui->listWidget->item(i);
+ auto *widget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(item));
+
+ if(widget == nullptr)
+ item->setHidden(!text.isEmpty());
+ else
+ item->setHidden(!widget->ui->label->text().contains(text));
+ }
+}
+
void SessionDialog::openSession(const QString &filename)
{
auto *browser = qobject_cast<Browser *>(qApp);
@@ -79,7 +94,6 @@ void SessionDialog::openSession(const QString &filename)
QFile json(filename);
if(json.open(QIODevice::ReadOnly | QIODevice::Text)) {
- auto *browser = qobject_cast<Browser *>(qApp);
auto doc = QJsonDocument::fromJson(json.readAll());
Session::restoreSession(doc.object());
json.close();
diff --git a/src/session/sessiondialog.h b/src/session/sessiondialog.h
index 7fea3c2..ff4d3af 100644
--- a/src/session/sessiondialog.h
+++ b/src/session/sessiondialog.h
@@ -24,7 +24,8 @@ public:
explicit SessionDialog(QWidget *parent = nullptr);
~SessionDialog() override;
-private:
+private slots:
+ void search(const QString &text);
void openSession(const QString &filename);
private:
diff --git a/src/session/sessiondialog.ui b/src/session/sessiondialog.ui
index 3a61dc1..dab49d9 100644
--- a/src/session/sessiondialog.ui
+++ b/src/session/sessiondialog.ui
@@ -24,10 +24,13 @@
</widget>
</item>
<item>
- <widget class="QLineEdit" name="lineEdit">
+ <widget class="QLineEdit" name="search">
<property name="placeholderText">
<string>Search</string>
</property>
+ <property name="clearButtonEnabled">
+ <bool>true</bool>
+ </property>
</widget>
</item>
</layout>