diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-03-17 15:43:36 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-03-17 09:49:58 +0100 |
| commit | 489512210b80e0bb441df27ead735722c9c68da2 (patch) | |
| tree | bc63a82c912683a2c0e2d4c55f13de56c3aac1a2 /src | |
| parent | 7321b9078c86d640c0df6120134d9c2a2274e4aa (diff) | |
| download | kristall-489512210b80e0bb441df27ead735722c9c68da2.tar.gz | |
sessions: save page titles and read them before loading page
Diffstat (limited to 'src')
| -rw-r--r-- | src/kristall.hpp | 7 | ||||
| -rw-r--r-- | src/main.cpp | 28 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 8 | ||||
| -rw-r--r-- | src/mainwindow.hpp | 2 |
4 files changed, 38 insertions, 7 deletions
diff --git a/src/kristall.hpp b/src/kristall.hpp index 66de0e1..884cf03 100644 --- a/src/kristall.hpp +++ b/src/kristall.hpp @@ -50,6 +50,12 @@ enum class AnsiEscRenderMode : int strip = 2 }; +struct PageMetadata +{ + QUrl location; + QString title; +}; + struct GenericSettings { enum TextDisplay { @@ -209,6 +215,7 @@ namespace kristall //! Opens a new window with the given list of urls. //! If the list is empty, no new tab will spawned. MainWindow * openNewWindow(QVector<QUrl> const & urls); + MainWindow * openNewWindow(QVector<PageMetadata> const & urls); //! Returns the number of currently open windows int getWindowCount(); diff --git a/src/main.cpp b/src/main.cpp index 2554535..b51dcb1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -339,19 +339,33 @@ MainWindow * kristall::openNewWindow(QUrl const & url) return openNewWindow(QVector<QUrl>{url}); } -//! Opens a new window with the given list of urls. -//! If the list is empty, no new tab will spawned. +//! Opens a new window with the given urls. +//! Almost identical to below overload. MainWindow * kristall::openNewWindow(QVector<QUrl> const & urls) { MainWindow * const window = new MainWindow(qApp); for(int i = 0; i < urls.length(); i++) { - window->addNewTab((i == 0), urls.at(i)); + window->addNewTab((i == 0), urls.at(i), ""); } window->show(); + return window; +} + +//! Opens a new window with the given list of urls. +//! If the list is empty, no new tab will spawned. +MainWindow * kristall::openNewWindow(QVector<PageMetadata> const & urls) +{ + MainWindow * const window = new MainWindow(qApp); + for(int i = 0; i < urls.length(); i++) + { + window->addNewTab((i == 0), urls.at(i).location, urls.at(i).title); + } + + window->show(); return window; } @@ -692,13 +706,16 @@ int main(int argc, char *argv[]) { settings.setArrayIndex(index); - QVector<QUrl> urls; + QVector<PageMetadata> urls; int tab_count = settings.beginReadArray("tabs"); for(int i = 0; i < tab_count; i++) { settings.setArrayIndex(i); - urls.push_back(settings.value("url").toString()); + urls.push_back({ + settings.value("url").toString(), + settings.value("title").toString() + }); } settings.endArray(); @@ -1065,6 +1082,7 @@ void kristall::saveSession() { settings.setArrayIndex(i); settings.setValue("url", main_window->tabAt(i)->current_location.toString(QUrl::FullyEncoded)); + settings.setValue("title", main_window->tabAt(i)->page_title); tab_count += 1; } settings.endArray(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index db833fb..42b7831 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -160,10 +160,16 @@ BrowserTab * MainWindow::addEmptyTab(bool focus_new, bool load_default) return tab; } -BrowserTab * MainWindow::addNewTab(bool focus_new, QUrl const & url) +BrowserTab * MainWindow::addNewTab(bool focus_new, QUrl const & url, QString defaultTitle) { auto tab = addEmptyTab(focus_new, false); tab->navigateTo(url, BrowserTab::PushImmediate); + + if (!defaultTitle.isEmpty()) + { + emit tab->titleChanged(defaultTitle); + } + return tab; } diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index e343033..f3e1442 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -31,7 +31,7 @@ public: ~MainWindow(); BrowserTab * addEmptyTab(bool focus_new, bool load_default); - BrowserTab * addNewTab(bool focus_new, QUrl const & url); + BrowserTab * addNewTab(bool focus_new, QUrl const & url, QString defaultTitle=""); BrowserTab * curTab() const; BrowserTab * tabAt(int index) const; int tabCount() const; |
