mudlet/src/TMediaPlaylist.cpp
Vadim Peretokin b23d6f788e
Infrastructure: fix else-after-return in codebase (#9096)
<!-- Keep the title short & concise so anyone non-technical can
understand it,
     the title appears in PTB changelogs -->
#### Brief overview of PR changes/additions
Remove unnecessary else/else-if after return, break, continue, and throw
statements - and in places where fixing them is more trouble than its
worth, added NOLINT.
#### Motivation for adding to Mudlet

https://clang.llvm.org/extra/clang-tidy/checks/readability/else-after-return.html,
so it doesn't pop up in PR reviews.
#### Other info (issues closed, discussion etc)

---------

Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
Co-authored-by: Vadim Peretokin <vadi2@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-07-18 18:39:57 +02:00

139 lines
3.9 KiB
C++

/***************************************************************************
* Copyright (C) 2024 by Mike Conley - mike.conley@stickmud.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "TMediaPlaylist.h"
#include <QRandomGenerator>
TMediaPlaylist::TMediaPlaylist()
: mCurrentIndex(0)
, mPlaybackMode(Sequential)
{
}
TMediaPlaylist::~TMediaPlaylist() {}
void TMediaPlaylist::addMedia(const QUrl& url)
{
mMediaList.append(url);
}
void TMediaPlaylist::removeMedia(int startIndex, int endIndex)
{
if (endIndex >= startIndex && startIndex >= 0 && endIndex < mMediaList.size()) {
for (int i = endIndex; i >= startIndex; --i) {
mMediaList.removeAt(i);
}
}
}
void TMediaPlaylist::clear()
{
mMediaList.clear();
}
int TMediaPlaylist::mediaCount() const
{
return mMediaList.count();
}
bool TMediaPlaylist::isEmpty() const
{
return mMediaList.isEmpty();
}
void TMediaPlaylist::setPlaybackMode(PlaybackMode mode)
{
mPlaybackMode = mode;
}
TMediaPlaylist::PlaybackMode TMediaPlaylist::playbackMode() const
{
return mPlaybackMode;
}
QUrl TMediaPlaylist::currentMedia() const
{
if (!mMediaList.isEmpty() && mCurrentIndex >= 0 && mCurrentIndex < mMediaList.size()) {
return mMediaList.at(mCurrentIndex);
}
return QUrl();
}
bool TMediaPlaylist::setCurrentIndex(int index)
{
if (index >= 0 && index < mMediaList.size()) {
mCurrentIndex = index;
return true;
}
return false;
}
int TMediaPlaylist::currentIndex() const
{
return mCurrentIndex;
}
int TMediaPlaylist::nextIndex() const
{
if (mPlaybackMode == Loop && (mCurrentIndex + 1 == mMediaList.size())) {
return 0;
} else if (mPlaybackMode == Random) { // NOLINT(readability-else-after-return)
return QRandomGenerator::global()->bounded(mMediaList.size());
} else if (mCurrentIndex + 1 < mMediaList.size()) { // NOLINT(readability-else-after-return)
return mCurrentIndex + 1;
}
return -1; // No valid next index if out of range
}
QUrl TMediaPlaylist::next()
{
if (mMediaList.isEmpty()) {
return QUrl();
}
if (mPlaybackMode == Loop && (mCurrentIndex + 1 == mMediaList.size())) {
mCurrentIndex = 0;
} else if (mPlaybackMode == Random) {
mCurrentIndex = QRandomGenerator::global()->bounded(mMediaList.size());
} else {
mCurrentIndex++;
}
if (mCurrentIndex < mMediaList.size()) {
return mMediaList.at(mCurrentIndex);
}
return QUrl();
}
QUrl TMediaPlaylist::previous()
{
if (mPlaybackMode == Loop && mCurrentIndex == 0) {
mCurrentIndex = mMediaList.size() - 1;
} else {
mCurrentIndex--;
}
if (mCurrentIndex >= 0) {
return mMediaList.at(mCurrentIndex);
}
return QUrl();
}