aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-06 20:12:38 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-06 20:12:38 +0200
commit9e1995b8672136b196bc4dccdb127e20156a630c (patch)
treed6a5bf13f316ffc4659dd30c8981e65ba63ff48e
parent0fd0f2d919d748280c48383840fe7c4d988bbd00 (diff)
downloadkristall-9e1995b8672136b196bc4dccdb127e20156a630c.tar.gz
Starts to implement history management.
-rw-r--r--README.md8
-rw-r--r--browsertab.cpp72
-rw-r--r--browsertab.hpp17
-rw-r--r--mainwindow.cpp38
-rw-r--r--mainwindow.hpp6
-rw-r--r--tabbrowsinghistory.cpp19
-rw-r--r--tabbrowsinghistory.hpp4
7 files changed, 116 insertions, 48 deletions
diff --git a/README.md b/README.md
index 6d5ae72..ad6fbcc 100644
--- a/README.md
+++ b/README.md
@@ -30,7 +30,11 @@ A high-quality visual cross-platform gemini browser.
- [ ] Correctly parse charset (0013, 0014)
- [ ] Correctly parse other params (0015)
- [ ] Correctly parse undefined params (0016)
-- [ ] Make document style customizable
- [ ] Add history navigation
- [ ] "also, being able to click and load a url from the history pane"
- - [ ] "Couldn't you just have an array of URLs? And when they go forward, you slice the array up to the that point and add the new url to the end" \ No newline at end of file
+ - [ ] "Couldn't you just have an array of URLs? And when they go forward, you slice the array up to the that point and add the new url to the end"
+- [ ] Recognize home directories with /~home and such and add "substyles"
+- [ ] Add favicon support
+ - [ ] Add auto-generated "favicons"
+ - [ ] Check if the site follows this guideline: `#<ICON> Title` where `<ICON>` is a unicode emoji
+ - [ ] Opt-In: Regularly check for `domain/favicon.ico` \ No newline at end of file
diff --git a/browsertab.cpp b/browsertab.cpp
index 5c8c453..dc374c1 100644
--- a/browsertab.cpp
+++ b/browsertab.cpp
@@ -49,7 +49,7 @@ BrowserTab::~BrowserTab()
delete ui;
}
-void BrowserTab::navigateTo(const QUrl &url)
+void BrowserTab::navigateTo(const QUrl &url, PushToHistory mode)
{
if(url.scheme() != "gemini") {
QMessageBox::warning(this, "Kristall", "Unsupported uri scheme: " + url.scheme());
@@ -65,15 +65,33 @@ void BrowserTab::navigateTo(const QUrl &url)
this->redirection_count = 0;
this->successfully_loaded = false;
+ this->push_to_history_after_load = (mode == PushAfterSuccess);
gemini_client.startRequest(url);
+
+ switch(mode)
+ {
+ case DontPush:
+ case PushAfterSuccess:
+ break;
+
+ case PushImmediate:
+ pushToHistory(url);
+ break;
+ }
+
this->updateUI();
}
void BrowserTab::navigateBack(QModelIndex history_index)
{
- qDebug() << history_index;
+ auto url = history.get(history_index);
+
+ if(url.isValid()) {
+ current_history_index = history_index;
+ navigateTo(url, DontPush);
+ }
}
void BrowserTab::on_menu_button_clicked()
@@ -112,13 +130,13 @@ void BrowserTab::on_menu_button_clicked()
void BrowserTab::on_url_bar_returnPressed()
{
- this->navigateTo(this->ui->url_bar->text());
+ this->navigateTo(this->ui->url_bar->text(), PushImmediate);
}
void BrowserTab::on_refresh_button_clicked()
{
if(current_location.isValid())
- this->navigateTo(this->current_location);
+ this->navigateTo(this->current_location, DontPush);
}
void BrowserTab::on_gemini_complete(const QByteArray &data, const QString &mime)
@@ -149,7 +167,7 @@ void BrowserTab::on_gemini_complete(const QByteArray &data, const QString &mime)
document = std::make_unique<QTextDocument>();
document->setHtml(QString::fromUtf8(data));
}
-#if QT_CONFIG(textmarkdownreader)
+#if defined(QT_FEATURE_textmarkdownreader)
else if(mime.startsWith("text/markdown")) {
document = std::make_unique<QTextDocument>();
document->setMarkdown(QString::fromUtf8(data));
@@ -186,14 +204,18 @@ void BrowserTab::on_gemini_complete(const QByteArray &data, const QString &mime)
this->ui->text_browser->setDocument(document.get());
this->current_document = std::move(document);
- this->pushToHistory(this->current_location);
-
emit this->locationChanged(this->current_location);
QString title = this->current_location.toString();
emit this->titleChanged(title);
this->successfully_loaded = true;
+
+ if(this->push_to_history_after_load) {
+ this->pushToHistory(this->current_location);
+ this->push_to_history_after_load = false;
+ }
+
this->updateUI();
}
@@ -216,7 +238,7 @@ void BrowserTab::on_inputRequired(const QString &query)
QUrl new_location = current_location;
new_location.setQuery(dialog.textValue());
- this->navigateTo(new_location);
+ this->navigateTo(new_location, DontPush);
}
void BrowserTab::on_redirected(const QUrl &uri, bool is_permanent)
@@ -314,17 +336,6 @@ void BrowserTab::on_linkHovered(const QString &url)
this->mainWindow->setUrlPreview(QUrl(url));
}
-void BrowserTab::on_navigationRequest(const QUrl &url, bool &allow)
-{
- if(url.scheme() != "gemini") {
- QMessageBox::warning(this, "Kristall", QString("Unsupported url: %1").arg(url.toString()));
- }
- else {
- this->navigateTo(url);
- allow = false;
- }
-}
-
void BrowserTab::setErrorMessage(const QString &msg)
{
// this->page.setContent(QString("An error happened:\n%0").arg(msg).toUtf8(), "text/plain charset=utf-8");
@@ -334,7 +345,8 @@ void BrowserTab::setErrorMessage(const QString &msg)
void BrowserTab::pushToHistory(const QUrl &url)
{
- this->history.pushUrl(url);
+ qDebug() << "push to history" << this->current_history_index << url;
+ this->current_history_index = this->history.pushUrl(this->current_history_index, url);
this->updateUI();
}
@@ -362,20 +374,10 @@ void BrowserTab::on_text_browser_anchorClicked(const QUrl &url)
QMessageBox::warning(this, "Kristall", QString("Unsupported url: %1").arg(real_url.toString()));
}
else {
- this->navigateTo(real_url);
+ this->navigateTo(real_url, PushAfterSuccess);
}
}
-void BrowserTab::on_text_browser_backwardAvailable(bool arg1)
-{
- this->ui->back_button->setEnabled(arg1);
-}
-
-void BrowserTab::on_text_browser_forwardAvailable(bool arg1)
-{
- this->ui->forward_button->setEnabled(arg1);
-}
-
void BrowserTab::on_text_browser_highlighted(const QUrl &url)
{
QUrl real_url = url;
@@ -392,18 +394,18 @@ void BrowserTab::on_stop_button_clicked()
void BrowserTab::on_back_button_clicked()
{
-
+ navigateBack(current_history_index.sibling(-1, 0));
}
void BrowserTab::on_forward_button_clicked()
{
-
+ navigateBack(current_history_index.sibling(1, 0));
}
void BrowserTab::updateUI()
{
- this->ui->back_button->setEnabled(this->history.canGoBack());
- this->ui->forward_button->setEnabled(this->history.canGoForward());
+ this->ui->back_button->setEnabled(current_history_index.sibling(-1, 0).isValid());
+ this->ui->forward_button->setEnabled(current_history_index.sibling(1, 0).isValid());
this->ui->refresh_button->setVisible(this->successfully_loaded);
this->ui->stop_button->setVisible(not this->successfully_loaded);
diff --git a/browsertab.hpp b/browsertab.hpp
index fa853e6..3bbcd31 100644
--- a/browsertab.hpp
+++ b/browsertab.hpp
@@ -20,12 +20,18 @@ class MainWindow;
class BrowserTab : public QWidget
{
Q_OBJECT
+public:
+ enum PushToHistory {
+ DontPush,
+ PushImmediate,
+ PushAfterSuccess,
+ };
public:
explicit BrowserTab(MainWindow * mainWindow);
~BrowserTab();
- void navigateTo(QUrl const & url);
+ void navigateTo(QUrl const & url, PushToHistory mode);
void navigateBack(QModelIndex history_index);
@@ -61,16 +67,10 @@ private slots:
void on_linkHovered(const QString &url);
- void on_navigationRequest(QUrl const & url, bool & allow);
-
void on_fav_button_clicked();
void on_text_browser_anchorClicked(const QUrl &arg1);
- void on_text_browser_backwardAvailable(bool arg1);
-
- void on_text_browser_forwardAvailable(bool arg1);
-
void on_text_browser_highlighted(const QUrl &arg1);
void on_back_button_clicked();
@@ -87,6 +87,7 @@ private:
void updateUI();
public:
+
Ui::BrowserTab *ui;
MainWindow * mainWindow;
QUrl current_location;
@@ -94,11 +95,13 @@ public:
GeminiClient gemini_client;
int redirection_count = 0;
+ bool push_to_history_after_load = false;
bool successfully_loaded = false;
DocumentOutlineModel outline;
QGraphicsScene graphics_scene;
TabBrowsingHistory history;
+ QModelIndex current_history_index;
std::unique_ptr<QTextDocument> current_document;
};
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 998a7d8..4cab251 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -3,6 +3,8 @@
#include "browsertab.hpp"
#include <memory>
+#include <QShortcut>
+#include <QKeySequence>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
@@ -19,9 +21,20 @@ MainWindow::MainWindow(QWidget *parent) :
ui->favourites_view->setModel(&favourites);
- this->ui->history_window->setVisible(false);
+ // this->ui->history_window->setVisible(false);
this->ui->clientcert_window->setVisible(false);
this->ui->bookmarks_window->setVisible(true);
+
+
+ auto add_shortcut = [this](QString const & sequence, void (MainWindow::*fun)())
+ {
+ auto * shortcut = new QShortcut(QKeySequence(sequence), this);
+ connect(shortcut, &QShortcut::activated, this, fun);
+ };
+
+ add_shortcut("Ctrl+T", &MainWindow::on_new_tab);
+ add_shortcut("Ctrl+W", &MainWindow::on_close_tab);
+ add_shortcut("F5", &MainWindow::on_refresh);
}
MainWindow::~MainWindow()
@@ -49,7 +62,7 @@ BrowserTab * MainWindow::addEmptyTab(bool focus_new)
BrowserTab * MainWindow::addNewTab(bool focus_new, QUrl const & url)
{
auto tab = addEmptyTab(focus_new);
- tab->navigateTo(url);
+ tab->navigateTo(url, BrowserTab::PushImmediate);
return tab;
}
@@ -127,3 +140,24 @@ void MainWindow::on_tab_locationChanged(const QUrl &url)
this->ui->browser_tabs->setTabToolTip(index, url.toString());
}
}
+
+void MainWindow::on_new_tab()
+{
+ this->addEmptyTab(true);
+}
+
+void MainWindow::on_refresh()
+{
+ BrowserTab * tab = qobject_cast<BrowserTab*>(this->ui->browser_tabs->currentWidget());
+ if(tab != nullptr) {
+ // tab->reloadPage();
+ }
+}
+
+void MainWindow::on_close_tab()
+{
+ BrowserTab * tab = qobject_cast<BrowserTab*>(this->ui->browser_tabs->currentWidget());
+ if(tab != nullptr) {
+ delete tab;
+ }
+}
diff --git a/mainwindow.hpp b/mainwindow.hpp
index eb8918b..78ead7e 100644
--- a/mainwindow.hpp
+++ b/mainwindow.hpp
@@ -44,6 +44,12 @@ private slots:
void on_tab_locationChanged(QUrl const & url);
+ void on_new_tab();
+
+ void on_refresh();
+
+ void on_close_tab();
+
public:
QSettings settings;
GeminiStyle current_style;
diff --git a/tabbrowsinghistory.cpp b/tabbrowsinghistory.cpp
index 1a2d07f..289d529 100644
--- a/tabbrowsinghistory.cpp
+++ b/tabbrowsinghistory.cpp
@@ -15,13 +15,30 @@ bool TabBrowsingHistory::canGoForward() const
return false;
}
-void TabBrowsingHistory::pushUrl(const QUrl &url)
+QModelIndex TabBrowsingHistory::pushUrl(QModelIndex const & position, const QUrl &url)
{
this->beginInsertRows(QModelIndex{}, this->history.length(),this->history.length() + 1);
+ if(position.isValid()) {
+ this->history.resize(position.row() + 1);
+ }
+
this->history.push_back(url);
this->endInsertRows();
+
+ return this->createIndex(this->history.size() - 1, 0);
+}
+
+QUrl TabBrowsingHistory::get(const QModelIndex &index) const
+{
+ if(not index.isValid())
+ return QUrl { };
+
+ if(index.row() >= history.size())
+ return QUrl { };
+ else
+ return history.at(index.row());
}
int TabBrowsingHistory::rowCount(const QModelIndex &parent) const
diff --git a/tabbrowsinghistory.hpp b/tabbrowsinghistory.hpp
index 55e8354..b15a701 100644
--- a/tabbrowsinghistory.hpp
+++ b/tabbrowsinghistory.hpp
@@ -16,7 +16,9 @@ public:
bool canGoForward() const;
- void pushUrl(QUrl const & url);
+ QModelIndex pushUrl(QModelIndex const & position, QUrl const & url);
+
+ QUrl get(QModelIndex const & index) const;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;