aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-08 12:20:31 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-08 12:20:31 +0200
commit25fcf4a129545cdcdceb87ca8deaeabaf2239e03 (patch)
treef8e9363779cb7b0c8510fd1c09df3db61a8abdeb /src
parent67af296c10de639c6d2391ae4608ec5c307549d2 (diff)
downloadkristall-25fcf4a129545cdcdceb87ca8deaeabaf2239e03.tar.gz
Adds changelog, utility menus, and support for file://
Diffstat (limited to 'src')
-rw-r--r--src/browsertab.cpp48
-rw-r--r--src/browsertab.hpp8
-rw-r--r--src/icons.qrc4
-rw-r--r--src/icons/pause.svg1
-rw-r--r--src/icons/play.svg1
-rw-r--r--src/icons/volume-high.svg1
-rw-r--r--src/icons/volume-off.svg1
-rw-r--r--src/mainwindow.cpp35
-rw-r--r--src/mainwindow.hpp6
-rw-r--r--src/mainwindow.ui19
-rw-r--r--src/mediaplayer.cpp11
-rw-r--r--src/mediaplayer.hpp2
-rw-r--r--src/mediaplayer.ui13
-rw-r--r--src/protocolsetup.cpp1
14 files changed, 135 insertions, 16 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());
}
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<QTextDocument> 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 @@
<file>icons/plus.svg</file>
<file>icons/content-save-import.svg</file>
<file>icons/folder-open.svg</file>
+ <file>icons/volume-high.svg</file>
+ <file>icons/volume-off.svg</file>
+ <file>icons/play.svg</file>
+ <file>icons/pause.svg</file>
</qresource>
</RCC>
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 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M14,19H18V5H14M6,19H10V5H6V19Z" /></svg> \ 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 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M8,5.14V19.14L19,12.14L8,5.14Z" /></svg> \ 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 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M14,3.23V5.29C16.89,6.15 19,8.83 19,12C19,15.17 16.89,17.84 14,18.7V20.77C18,19.86 21,16.28 21,12C21,7.72 18,4.14 14,3.23M16.5,12C16.5,10.23 15.5,8.71 14,7.97V16C15.5,15.29 16.5,13.76 16.5,12M3,9V15H7L12,20V4L7,9H3Z" /></svg> \ 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 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M12,4L9.91,6.09L12,8.18M4.27,3L3,4.27L7.73,9H3V15H7L12,20V13.27L16.25,17.53C15.58,18.04 14.83,18.46 14,18.7V20.77C15.38,20.45 16.63,19.82 17.68,18.96L19.73,21L21,19.73L12,10.73M19,12C19,12.94 18.8,13.82 18.46,14.64L19.97,16.15C20.62,14.91 21,13.5 21,12C21,7.72 18,4.14 14,3.23V5.29C16.89,6.15 19,8.83 19,12M16.5,12C16.5,10.23 15.5,8.71 14,7.97V10.18L16.45,12.63C16.5,12.43 16.5,12.21 16.5,12Z" /></svg> \ 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 <QKeySequence>
#include <QFile>
#include <QTextStream>
+#include <QFileDialog>
MainWindow::MainWindow(QApplication * app, QWidget *parent) :
QMainWindow(parent),
@@ -45,6 +46,13 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) :
connect(act, QOverload<bool>::of(&QAction::triggered), dock, &QDockWidget::setVisible);
}
+ connect(this->ui->menuNavigation, &QMenu::aboutToShow, [this]() {
+ BrowserTab * tab = qobject_cast<BrowserTab*>(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<BrowserTab*>(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<BrowserTab*>(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<BrowserTab*>(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 @@
<property name="title">
<string>Navigation</string>
</property>
+ <addaction name="actionGo_to_home"/>
<addaction name="actionBackward"/>
<addaction name="actionForward"/>
<addaction name="separator"/>
@@ -305,12 +306,11 @@
<string>About Qt...</string>
</property>
</action>
- <action name="actionSave">
- <property name="text">
- <string>Save</string>
- </property>
- </action>
<action name="actionSave_as">
+ <property name="icon">
+ <iconset>
+ <normaloff>icons/content-save.svg</normaloff>icons/content-save.svg</iconset>
+ </property>
<property name="text">
<string>Save as...</string>
</property>
@@ -333,6 +333,15 @@
<string>Ctrl+D</string>
</property>
</action>
+ <action name="actionGo_to_home">
+ <property name="icon">
+ <iconset>
+ <normaloff>icons/home.svg</normaloff>icons/home.svg</iconset>
+ </property>
+ <property name="text">
+ <string>Go to home</string>
+ </property>
+ </action>
</widget>
<resources>
<include location="icons.qrc"/>
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 <QMediaContent>
#include <QToolButton>
#include <QTime>
+#include <QIcon>
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 @@
<property name="text">
<string>...</string>
</property>
+ <property name="icon">
+ <iconset resource="icons.qrc">
+ <normaloff>:/icons/play.svg</normaloff>:/icons/play.svg</iconset>
+ </property>
</widget>
</item>
<item>
@@ -54,6 +58,11 @@
<property name="text">
<string>...</string>
</property>
+ <property name="icon">
+ <iconset resource="icons.qrc">
+ <normaloff>:/icons/volume-high.svg</normaloff>
+ <normalon>:/icons/volume-off.svg</normalon>:/icons/volume-high.svg</iconset>
+ </property>
<property name="checkable">
<bool>true</bool>
</property>
@@ -74,6 +83,8 @@
<container>1</container>
</customwidget>
</customwidgets>
- <resources/>
+ <resources>
+ <include location="icons.qrc"/>
+ </resources>
<connections/>
</ui>
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;
}