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 +++++++++++++++++++++++++++++++++++++++-------- src/browsertab.hpp | 8 +++++++- src/icons.qrc | 4 ++++ src/icons/pause.svg | 1 + src/icons/play.svg | 1 + src/icons/volume-high.svg | 1 + src/icons/volume-off.svg | 1 + src/mainwindow.cpp | 35 ++++++++++++++++++++++++++++++++++ src/mainwindow.hpp | 6 ++++++ src/mainwindow.ui | 19 ++++++++++++++----- src/mediaplayer.cpp | 11 ++++++++++- src/mediaplayer.hpp | 2 ++ src/mediaplayer.ui | 13 ++++++++++++- src/protocolsetup.cpp | 1 + 14 files changed, 135 insertions(+), 16 deletions(-) create mode 100644 src/icons/pause.svg create mode 100644 src/icons/play.svg create mode 100644 src/icons/volume-high.svg create mode 100644 src/icons/volume-off.svg (limited to 'src') 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()); } diff --git a/src/browsertab.hpp b/src/browsertab.hpp index feb0455..a7bda50 100644 --- a/src/browsertab.hpp +++ b/src/browsertab.hpp @@ -46,6 +46,10 @@ public: void reloadPage(); + void toggleIsFavourite(); + + void toggleIsFavourite(bool isFavourite); + signals: void titleChanged(QString const & title); void locationChanged(QUrl const & url); @@ -95,7 +99,6 @@ private: void pushToHistory(QUrl const & url); void updateUI(); - public: Ui::BrowserTab *ui; @@ -116,6 +119,9 @@ public: QModelIndex current_history_index; std::unique_ptr current_document; + + QByteArray current_buffer; + QString current_mime; }; #endif // BROWSERTAB_HPP diff --git a/src/icons.qrc b/src/icons.qrc index 0e7b163..a475b23 100644 --- a/src/icons.qrc +++ b/src/icons.qrc @@ -17,5 +17,9 @@ icons/plus.svg icons/content-save-import.svg icons/folder-open.svg + icons/volume-high.svg + icons/volume-off.svg + icons/play.svg + icons/pause.svg diff --git a/src/icons/pause.svg b/src/icons/pause.svg new file mode 100644 index 0000000..37ed32d --- /dev/null +++ b/src/icons/pause.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/play.svg b/src/icons/play.svg new file mode 100644 index 0000000..87a70f2 --- /dev/null +++ b/src/icons/play.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/volume-high.svg b/src/icons/volume-high.svg new file mode 100644 index 0000000..a002372 --- /dev/null +++ b/src/icons/volume-high.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/volume-off.svg b/src/icons/volume-off.svg new file mode 100644 index 0000000..01e450f --- /dev/null +++ b/src/icons/volume-off.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e8dbd23..f2c4390 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -9,6 +9,7 @@ #include #include #include +#include MainWindow::MainWindow(QApplication * app, QWidget *parent) : QMainWindow(parent), @@ -45,6 +46,13 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) : connect(act, QOverload::of(&QAction::triggered), dock, &QDockWidget::setVisible); } + connect(this->ui->menuNavigation, &QMenu::aboutToShow, [this]() { + BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); + if(tab != nullptr) { + ui->actionAdd_to_favourites->setChecked(this->favourites.contains(tab->current_location)); + } + }); + connect(this->ui->menuView, &QMenu::aboutToShow, [this]() { for(QAction * act : this->ui->menuView->actions()) { @@ -309,3 +317,30 @@ void MainWindow::reloadTheme() application->setStyleSheet(stream.readAll()); } } + +void MainWindow::on_actionSave_as_triggered() +{ + BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); + if(tab != nullptr) { + QFileDialog::saveFileContent( + tab->current_buffer, + tab->current_location.fileName() + ); + } +} + +void MainWindow::on_actionGo_to_home_triggered() +{ + BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); + if(tab != nullptr) { + tab->navigateTo(QUrl(this->settings.value("start_page").toString()), BrowserTab::PushAfterSuccess); + } +} + +void MainWindow::on_actionAdd_to_favourites_triggered() +{ + BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); + if(tab != nullptr) { + tab->toggleIsFavourite(); + } +} diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index fb1d282..9a460a8 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -67,6 +67,12 @@ private slots: void on_actionAbout_Qt_triggered(); + void on_actionSave_as_triggered(); + + void on_actionGo_to_home_triggered(); + + void on_actionAdd_to_favourites_triggered(); + private: void reloadTheme(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index f2a54f4..83c8d52 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -217,6 +217,7 @@ Navigation + @@ -305,12 +306,11 @@ About Qt... - - - Save - - + + + icons/content-save.svgicons/content-save.svg + Save as... @@ -333,6 +333,15 @@ Ctrl+D + + + + icons/home.svgicons/home.svg + + + Go to home + + diff --git a/src/mediaplayer.cpp b/src/mediaplayer.cpp index 6b6c67d..809d24a 100644 --- a/src/mediaplayer.cpp +++ b/src/mediaplayer.cpp @@ -4,6 +4,7 @@ #include #include #include +#include MediaPlayer::MediaPlayer(QWidget *parent) : QWidget(parent), @@ -19,8 +20,9 @@ MediaPlayer::MediaPlayer(QWidget *parent) : connect(&this->player, &QMediaPlayer::positionChanged, this->ui->media_progress, &QSlider::setValue); connect(&this->player, &QMediaPlayer::audioAvailableChanged, this->ui->mute_button, &QToolButton::setEnabled); - connect(&this->player, &QMediaPlayer::videoAvailableChanged, this->ui->video_out, &QVideoWidget::setVisible); + // connect(&this->player, &QMediaPlayer::videoAvailableChanged, this->ui->video_out, &QVideoWidget::setVisible); + connect(&this->player, &QMediaPlayer::stateChanged, this, &MediaPlayer::on_media_playbackChanged); connect(&this->player, &QMediaPlayer::mediaStatusChanged, [](QMediaPlayer::MediaStatus status) { qDebug() << "media status changed" << status; }); @@ -70,3 +72,10 @@ void MediaPlayer::on_media_positionChanged(qint64 pos) this->ui->media_position->setText(time.toString()); } + +void MediaPlayer::on_media_playbackChanged(QMediaPlayer::State status) +{ + this->ui->playpause_button->setIcon(QIcon( + (status == QMediaPlayer::PlayingState) ? ":/icons/pause.svg" : ":/icons/play.svg" + )); +} diff --git a/src/mediaplayer.hpp b/src/mediaplayer.hpp index b848ec1..a4440a6 100644 --- a/src/mediaplayer.hpp +++ b/src/mediaplayer.hpp @@ -27,6 +27,8 @@ private slots: void on_media_positionChanged(qint64 pos); + void on_media_playbackChanged(QMediaPlayer::State); + private: Ui::MediaPlayer *ui; QBuffer media_stream; diff --git a/src/mediaplayer.ui b/src/mediaplayer.ui index eebbcc2..cdbb21d 100644 --- a/src/mediaplayer.ui +++ b/src/mediaplayer.ui @@ -27,6 +27,10 @@ ... + + + :/icons/play.svg:/icons/play.svg + @@ -54,6 +58,11 @@ ... + + + :/icons/volume-high.svg + :/icons/volume-off.svg:/icons/volume-high.svg + true @@ -74,6 +83,8 @@ 1 - + + + diff --git a/src/protocolsetup.cpp b/src/protocolsetup.cpp index bbecfa0..fcf971a 100644 --- a/src/protocolsetup.cpp +++ b/src/protocolsetup.cpp @@ -37,6 +37,7 @@ bool ProtocolSetup::isSchemeSupported(QString const & _scheme) const // built-in schemes: if(scheme == "about") return true; + if(scheme == "file") return true; return false; } -- cgit v1.2.3