diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-08 12:20:31 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-08 12:20:31 +0200 |
| commit | 25fcf4a129545cdcdceb87ca8deaeabaf2239e03 (patch) | |
| tree | f8e9363779cb7b0c8510fd1c09df3db61a8abdeb /src/browsertab.cpp | |
| parent | 67af296c10de639c6d2391ae4608ec5c307549d2 (diff) | |
| download | kristall-25fcf4a129545cdcdceb87ca8deaeabaf2239e03.tar.gz | |
Adds changelog, utility menus, and support for file://
Diffstat (limited to 'src/browsertab.cpp')
| -rw-r--r-- | src/browsertab.cpp | 48 |
1 files changed, 40 insertions, 8 deletions
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 <QDockWidget> #include <QImage> #include <QPixmap> +#include <QFile> +#include <QMimeDatabase> +#include <QMimeType> #include <QGraphicsPixmapItem> #include <QGraphicsTextItem> @@ -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()); } |
