compile on qt5

This commit is contained in:
Martin Rotter 2023-11-22 10:20:19 +01:00
parent 5d960972cb
commit 49d5716785
7 changed files with 117 additions and 34 deletions

View file

@ -4504,47 +4504,47 @@ Login tokens expiration: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="134"/>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="151"/>
<source>No media</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="137"/>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="154"/>
<source>Loading...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="140"/>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="157"/>
<source>Media loaded</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="143"/>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="160"/>
<source>Media stalled</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="146"/>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="163"/>
<source>Buffering...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="149"/>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="166"/>
<source>Loaded</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="152"/>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="169"/>
<source>Ended</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="155"/>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="172"/>
<source>Media is invalid</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="158"/>
<location filename="../src/librssguard/gui/reusable/mediaplayer.cpp" line="175"/>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
@ -7963,12 +7963,12 @@ Unread news: %2</translation>
<translation>Downloads</translation>
</message>
<message>
<location filename="../src/librssguard/gui/tabwidget.cpp" line="232"/>
<location filename="../src/librssguard/gui/tabwidget.cpp" line="237"/>
<source>Media player</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/tabwidget.cpp" line="257"/>
<location filename="../src/librssguard/gui/tabwidget.cpp" line="262"/>
<source>Web browser</source>
<translation>Web browser</translation>
</message>
@ -8497,17 +8497,17 @@ Last login on: %4</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/webviewers/webengine/webengineviewer.cpp" line="104"/>
<location filename="../src/librssguard/gui/webviewers/webengine/webengineviewer.cpp" line="105"/>
<source>Open link as audio/video</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/webviewers/webengine/webengineviewer.cpp" line="113"/>
<location filename="../src/librssguard/gui/webviewers/webengine/webengineviewer.cpp" line="115"/>
<source>Open with external tool</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/gui/webviewers/webengine/webengineviewer.cpp" line="132"/>
<location filename="../src/librssguard/gui/webviewers/webengine/webengineviewer.cpp" line="134"/>
<source>No external tools activated</source>
<translation type="unfinished"></translation>
</message>

View file

@ -542,8 +542,14 @@ QString FeedDownloadResults::overview(int how_many_feeds) const {
QStringList result;
for (int i = 0, number_items_output = qMin(how_many_feeds, m_updatedFeeds.size()); i < number_items_output; i++) {
result.append(m_updatedFeeds.keys().at(i)->title() + QSL(": ") +
QString::number(m_updatedFeeds.value(m_updatedFeeds.keys().at(i)).size()));
auto* fd = m_updatedFeeds.keys().at(i);
auto msgs = m_updatedFeeds.value(fd);
if (fd->isQuiet()) {
continue;
}
result.append(fd->title() + QSL(": ") + QString::number(msgs.size()));
}
QString res_str = result.join(QSL("\n"));

View file

@ -83,6 +83,10 @@ void ArticleListNotification::loadResults(const QHash<Feed*, QList<Message>>& ne
});
for (Feed* fd : ks) {
if (fd->isQuiet()) {
continue;
}
m_ui.m_cmbFeeds->addItem(fd->sanitizedTitle(), QVariant::fromValue(fd));
}
}

View file

@ -17,12 +17,15 @@ MediaPlayer::MediaPlayer(QWidget* parent)
m_ui.setupUi(this);
m_player->setVideoOutput(m_ui.m_video);
#if QT_VERSION_MAJOR == 6
m_player->setAudioOutput(m_audio);
#endif
setupIcons();
createConnections();
onPlaybackStateChanged(QMediaPlayer::PlaybackState::StoppedState);
onPlaybackStateChanged(QMediaPlayer::PLAYBACK_STATE::StoppedState);
onMediaStatusChanged(QMediaPlayer::MediaStatus::NoMedia);
}
@ -33,14 +36,24 @@ WebBrowser* MediaPlayer::webBrowser() const {
}
void MediaPlayer::playUrl(const QString& url) {
setVolume(m_ui.m_slidVolume->value());
if (m_muted) {
muteUnmute();
}
else {
setVolume(m_ui.m_slidVolume->value());
}
#if QT_VERSION_MAJOR == 6
m_player->setSource(url);
#else
m_player->setMedia(QUrl(url));
#endif
m_player->play();
}
void MediaPlayer::playPause() {
if (m_player->playbackState() != QMediaPlayer::PlaybackState::PlayingState) {
if (m_player->PLAYBACK_STATE_METHOD() != QMediaPlayer::PLAYBACK_STATE::PlayingState) {
m_player->play();
}
else {
@ -53,7 +66,13 @@ void MediaPlayer::stop() {
}
void MediaPlayer::download() {
emit urlDownloadRequested(m_player->source());
emit urlDownloadRequested(
#if QT_VERSION_MAJOR == 6
m_player->source()
#else
m_player->media().request().url()
#endif
);
}
void MediaPlayer::muteUnmute() {
@ -64,12 +83,17 @@ void MediaPlayer::muteUnmute() {
}
void MediaPlayer::setVolume(int volume) {
m_player->audioOutput()->setVolume(volume / 100.0f);
#if QT_VERSION_MAJOR == 6
m_player->audioOutput()->setVolume(convertSliderVolume(volume));
#else
m_player->setVolume(volume);
#endif
m_ui.m_btnVolume->setIcon(volume <= 0 ? m_iconMute : m_iconUnmute);
}
void MediaPlayer::seek(int position) {
m_player->setPosition(position * 1000);
m_player->setPosition(convertSliderProgress(position));
}
void MediaPlayer::onDurationChanged(qint64 duration) {
@ -95,19 +119,19 @@ void MediaPlayer::onMediaStatusChanged(QMediaPlayer::MediaStatus status) {
m_ui.m_lblStatus->setText(mediaStatusToString(status));
}
void MediaPlayer::onPlaybackStateChanged(QMediaPlayer::PlaybackState state) {
void MediaPlayer::onPlaybackStateChanged(QMediaPlayer::PLAYBACK_STATE state) {
switch (state) {
case QMediaPlayer::StoppedState:
case QMediaPlayer::PLAYBACK_STATE::StoppedState:
m_ui.m_btnPlayPause->setIcon(m_iconPlay);
m_ui.m_btnStop->setEnabled(false);
break;
case QMediaPlayer::PlayingState:
case QMediaPlayer::PLAYBACK_STATE::PlayingState:
m_ui.m_btnPlayPause->setIcon(m_iconPause);
m_ui.m_btnStop->setEnabled(true);
break;
case QMediaPlayer::PausedState:
case QMediaPlayer::PLAYBACK_STATE::PausedState:
m_ui.m_btnPlayPause->setIcon(m_iconPlay);
m_ui.m_btnStop->setEnabled(true);
break;
@ -116,10 +140,14 @@ void MediaPlayer::onPlaybackStateChanged(QMediaPlayer::PlaybackState state) {
void MediaPlayer::onPositionChanged(qint64 position) {
m_ui.m_slidProgress->blockSignals(true);
m_ui.m_slidProgress->setValue(position / 1000);
m_ui.m_slidProgress->setValue(convertToSliderProgress(position));
m_ui.m_slidProgress->blockSignals(false);
}
int MediaPlayer::convertToSliderProgress(qint64 player_progress) const {
return player_progress / 1000;
}
void MediaPlayer::onSeekableChanged(bool seekable) {
m_ui.m_slidProgress->setEnabled(seekable);
@ -128,6 +156,14 @@ void MediaPlayer::onSeekableChanged(bool seekable) {
}
}
float MediaPlayer::convertSliderVolume(int slider_volume) const {
return slider_volume / 100.0f;
}
qint64 MediaPlayer::convertSliderProgress(int slider_progress) const {
return qint64(slider_progress) * qint64(1000);
}
QString MediaPlayer::mediaStatusToString(QMediaPlayer::MediaStatus status) const {
switch (status) {
case QMediaPlayer::NoMedia:
@ -171,11 +207,26 @@ void MediaPlayer::setupIcons() {
void MediaPlayer::createConnections() {
connect(m_player, &QMediaPlayer::durationChanged, this, &MediaPlayer::onDurationChanged);
#if QT_VERSION_MAJOR == 6
connect(m_player, &QMediaPlayer::errorOccurred, this, &MediaPlayer::onErrorOccurred);
#else
connect(m_player, QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error), this, [this](QMediaPlayer::Error error) {
onErrorOccurred(error);
});
#endif
#if QT_VERSION_MAJOR == 6
connect(m_player, &QMediaPlayer::hasAudioChanged, this, &MediaPlayer::onAudioAvailable);
connect(m_player, &QMediaPlayer::hasVideoChanged, this, &MediaPlayer::onVideoAvailable);
connect(m_player, &QMediaPlayer::mediaStatusChanged, this, &MediaPlayer::onMediaStatusChanged);
connect(m_player, &QMediaPlayer::playbackStateChanged, this, &MediaPlayer::onPlaybackStateChanged);
#else
connect(m_player, &QMediaPlayer::audioAvailableChanged, this, &MediaPlayer::onAudioAvailable);
connect(m_player, &QMediaPlayer::videoAvailableChanged, this, &MediaPlayer::onVideoAvailable);
connect(m_player, &QMediaPlayer::stateChanged, this, &MediaPlayer::onPlaybackStateChanged);
#endif
connect(m_player, &QMediaPlayer::mediaStatusChanged, this, &MediaPlayer::onMediaStatusChanged);
connect(m_player, &QMediaPlayer::positionChanged, this, &MediaPlayer::onPositionChanged);
connect(m_player, &QMediaPlayer::seekableChanged, this, &MediaPlayer::onSeekableChanged);

View file

@ -9,6 +9,14 @@
#include <QMediaPlayer>
#if QT_VERSION_MAJOR == 6
#define PLAYBACK_STATE PlaybackState
#define PLAYBACK_STATE_METHOD playbackState
#else
#define PLAYBACK_STATE State
#define PLAYBACK_STATE_METHOD state
#endif
class QAudioOutput;
class MediaPlayer : public TabContent {
@ -29,7 +37,8 @@ class MediaPlayer : public TabContent {
void download();
void muteUnmute();
// NOTE: Volume is from 0 to 100.
// NOTE: Volume is from 0 to 100 taken directly from slider or
// elsewhere.
void setVolume(int volume);
// NOTE: Media is seekable in miliseconds, but that is too muc
@ -37,11 +46,13 @@ class MediaPlayer : public TabContent {
void seek(int position);
void onDurationChanged(qint64 duration);
void onErrorOccurred(QMediaPlayer::Error error, const QString& error_string);
void onErrorOccurred(QMediaPlayer::Error error, const QString& error_string = {});
void onAudioAvailable(bool available);
void onVideoAvailable(bool available);
void onMediaStatusChanged(QMediaPlayer::MediaStatus status);
void onPlaybackStateChanged(QMediaPlayer::PlaybackState state);
void onPlaybackStateChanged(QMediaPlayer::PLAYBACK_STATE state);
void onPositionChanged(qint64 position);
void onSeekableChanged(bool seekable);
@ -49,6 +60,10 @@ class MediaPlayer : public TabContent {
void urlDownloadRequested(const QUrl& url);
private:
float convertSliderVolume(int slider_volume) const;
qint64 convertSliderProgress(int slider_progress) const;
int convertToSliderProgress(qint64 player_progress) const;
QString mediaStatusToString(QMediaPlayer::MediaStatus status) const;
void setupIcons();

View file

@ -227,6 +227,11 @@ int TabWidget::addEmptyBrowser() {
int TabWidget::addMediaPlayer(const QString& url, bool make_active) {
auto* player = new MediaPlayer(this);
connect(player,
&MediaPlayer::urlDownloadRequested,
qApp->downloadManager(),
QOverload<const QUrl&>::of(&DownloadManager::download));
int index = addTab(player,
qApp->icons()->fromTheme(QSL("player_play"), QSL("media-playback-start")),
tr("Media player"),

View file

@ -101,9 +101,11 @@ void WebEngineViewer::contextMenuEvent(QContextMenuEvent* event) {
}
});
menu->addAction(qApp->icons()->fromTheme(QSL("document-open")), tr("Open link as audio/video"), [link_url]() {
qApp->mainForm()->tabWidget()->addMediaPlayer(link_url, true);
});
menu->addAction(qApp->icons()->fromTheme(QSL("player_play"), QSL("media-playback-start")),
tr("Open link as audio/video"),
[link_url]() {
qApp->mainForm()->tabWidget()->addMediaPlayer(link_url, true);
});
}
if (menu_data.mediaUrl().isValid() || menu_data.linkUrl().isValid()) {