From 25fcf4a129545cdcdceb87ca8deaeabaf2239e03 Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Mon, 8 Jun 2020 12:20:31 +0200 Subject: Adds changelog, utility menus, and support for file:// --- src/browsertab.cpp | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'src/browsertab.cpp') diff --git a/src/browsertab.cpp b/src/browsertab.cpp index 0e94770..722b655 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include #include @@ -42,7 +45,6 @@ BrowserTab::BrowserTab(MainWindow * mainWindow) : connect(&gopher_client, &GopherClient::requestComplete, this, &BrowserTab::on_requestComplete); connect(&gopher_client, &GopherClient::requestFailed, this, &BrowserTab::on_requestFailed); - this->updateUI(); this->ui->media_browser->setVisible(false); @@ -99,6 +101,23 @@ void BrowserTab::navigateTo(const QUrl &url, PushToHistory mode) { gopher_client.startRequest(url); } + else if(url.scheme() == "file") + { + QFile file { url.path() }; + + if(file.open(QFile::ReadOnly)) + { + QMimeDatabase db; + auto mime = db.mimeTypeForUrl(url).name(); + auto data = file.readAll(); + qDebug() << "database:" << url << mime; + this->on_requestComplete(data, mime); + } + else + { + + } + } else if(url.scheme() == "about") { this->redirection_count = 0; @@ -177,6 +196,22 @@ void BrowserTab::reloadPage() this->navigateTo(this->current_location, DontPush); } +void BrowserTab::toggleIsFavourite() +{ + toggleIsFavourite(not this->ui->fav_button->isChecked()); +} + +void BrowserTab::toggleIsFavourite(bool isFavourite) +{ + if(isFavourite) { + this->mainWindow->favourites.add(this->current_location); + } else { + this->mainWindow->favourites.remove(this->current_location); + } + + this->updateUI(); +} + void BrowserTab::on_url_bar_returnPressed() { QUrl url { this->ui->url_bar->text() }; @@ -219,6 +254,9 @@ void BrowserTab::on_requestComplete(const QByteArray &data, const QString &mime) { qDebug() << "Loaded" << data.length() << "bytes of type" << mime; + this->current_mime = mime; + this->current_buffer = data; + this->graphics_scene.clear(); this->ui->text_browser->setText(""); @@ -462,13 +500,7 @@ void BrowserTab::pushToHistory(const QUrl &url) void BrowserTab::on_fav_button_clicked() { - if(this->ui->fav_button->isChecked()) { - this->mainWindow->favourites.add(this->current_location); - } else { - this->mainWindow->favourites.remove(this->current_location); - } - - this->updateUI(); + toggleIsFavourite(this->ui->fav_button->isChecked()); } -- cgit v1.2.3