Skip to content

Commit

Permalink
Refactor DONE, experimenting with BT
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodmg committed Nov 26, 2023
1 parent 0040bd0 commit c691536
Show file tree
Hide file tree
Showing 21 changed files with 420 additions and 77 deletions.
77 changes: 77 additions & 0 deletions audiosourcebluetooth.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "audiosourcebluetooth.h"

AudioSourceBluetooth::AudioSourceBluetooth(QObject *parent)
: AudioSource{parent}
{

}

void AudioSourceBluetooth::activate()
{
QMediaMetaData metadata = QMediaMetaData{};
metadata.insert(QMediaMetaData::Title, "Bluetooth");

emit playbackStateChanged(MediaPlayer::StoppedState);
emit positionChanged(0);
emit metadataChanged(metadata);
emit durationChanged(0);
emit eqEnabledChanged(false);
emit plEnabledChanged(false);
emit shuffleEnabledChanged(false);
emit repeatEnabledChanged(false);
}

void AudioSourceBluetooth::deactivate()
{

}

void AudioSourceBluetooth::handlePl()
{
emit plEnabledChanged(false);
}

void AudioSourceBluetooth::handlePrevious()
{

}

void AudioSourceBluetooth::handlePlay()
{

}

void AudioSourceBluetooth::handlePause()
{

}

void AudioSourceBluetooth::handleStop()
{

}

void AudioSourceBluetooth::handleNext()
{

}

void AudioSourceBluetooth::handleOpen()
{

}

void AudioSourceBluetooth::handleShuffle()
{
emit shuffleEnabledChanged(false);
}

void AudioSourceBluetooth::handleRepeat()
{
emit repeatEnabledChanged(false);
}

void AudioSourceBluetooth::handleSeek(int mseconds)
{

}
29 changes: 29 additions & 0 deletions audiosourcebluetooth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef AUDIOSOURCEBLUETOOTH_H
#define AUDIOSOURCEBLUETOOTH_H

#include <QObject>

#include "audiosource.h"

class AudioSourceBluetooth : public AudioSource
{
Q_OBJECT
public:
explicit AudioSourceBluetooth(QObject *parent = nullptr);

public slots:
void activate();
void deactivate();
void handlePl();
void handlePrevious();
void handlePlay();
void handlePause();
void handleStop();
void handleNext();
void handleOpen();
void handleShuffle();
void handleRepeat();
void handleSeek(int mseconds);
};

#endif // AUDIOSOURCEBLUETOOTH_H
8 changes: 7 additions & 1 deletion audiosourcecoordinator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "audiosourcecoordinator.h"
#include "audiosourcefile.h"

AudioSourceCoordinator::AudioSourceCoordinator(QObject *parent, PlayerView *playerView)
: QObject{parent}
Expand All @@ -19,6 +18,11 @@ AudioSourceCoordinator::AudioSourceCoordinator(QObject *parent, PlayerView *play

void AudioSourceCoordinator::setSource(int newSource)
{
if(newSource > sources.length() - 1) {
qDebug() << "WARNING: Trying to set source out of range";
return;
}

if(currentSource >= 0) {
// deactivate old source
sources[currentSource]->deactivate();
Expand All @@ -32,6 +36,7 @@ void AudioSourceCoordinator::setSource(int newSource)
disconnect(view, &PlayerView::openClicked, sources[currentSource], &AudioSource::handleOpen);
disconnect(view, &PlayerView::shuffleClicked, sources[currentSource], &AudioSource::handleShuffle);
disconnect(view, &PlayerView::repeatClicked, sources[currentSource], &AudioSource::handleRepeat);
disconnect(view, &PlayerView::plClicked, sources[currentSource], &AudioSource::handlePl);

disconnect(sources[currentSource], &AudioSource::playbackStateChanged, view, &PlayerView::setPlaybackState);
disconnect(sources[currentSource], &AudioSource::positionChanged, view, &PlayerView::setPosition);
Expand All @@ -57,6 +62,7 @@ void AudioSourceCoordinator::setSource(int newSource)
connect(view, &PlayerView::openClicked, sources[currentSource], &AudioSource::handleOpen);
connect(view, &PlayerView::shuffleClicked, sources[currentSource], &AudioSource::handleShuffle);
connect(view, &PlayerView::repeatClicked, sources[currentSource], &AudioSource::handleRepeat);
connect(view, &PlayerView::plClicked, sources[currentSource], &AudioSource::handlePl);

connect(sources[currentSource], &AudioSource::playbackStateChanged, view, &PlayerView::setPlaybackState);
connect(sources[currentSource], &AudioSource::positionChanged, view, &PlayerView::setPosition);
Expand Down
37 changes: 3 additions & 34 deletions audiosourcefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void AudioSourceFile::deactivate()

void AudioSourceFile::handlePl()
{

emit showPlaylistRequested();
emit plEnabledChanged(true);
}

void AudioSourceFile::handlePrevious()
Expand Down Expand Up @@ -101,7 +102,7 @@ void AudioSourceFile::handleNext()

void AudioSourceFile::handleOpen()
{

emit showPlaylistRequested();
}

void AudioSourceFile::handleShuffle()
Expand Down Expand Up @@ -221,38 +222,6 @@ void AudioSourceFile::jump(const QModelIndex &index)
}
}

void AudioSourceFile::open()
{

/*
QList<QUrl> urls;
urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first())
<< QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first())
<< QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::MusicLocation).first());
QFileDialog fileDialog(this);
QString filters = audioFileFilters().join(" ");
fileDialog.setNameFilter("Audio (" + filters + ")");
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
fileDialog.setFileMode(QFileDialog::ExistingFiles);
fileDialog.setWindowTitle(tr("Open Files"));
fileDialog.setDirectory(QStandardPaths::standardLocations(QStandardPaths::MusicLocation)
.value(0, QDir::homePath()));
fileDialog.setOption(QFileDialog::ReadOnly, true);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, true);
fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setSidebarUrls(urls);
#ifdef IS_EMBEDDED
fileDialog.setWindowState(Qt::WindowFullScreen);
#endif
if (fileDialog.exec() == QDialog::Accepted)
addToPlaylist(fileDialog.selectedUrls());
*/
}

void AudioSourceFile::addToPlaylist(const QList<QUrl> &urls)
{
const int previousMediaCount = m_playlist->mediaCount();
Expand Down
4 changes: 3 additions & 1 deletion audiosourcefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class AudioSourceFile : public AudioSource
public:
explicit AudioSourceFile(QObject *parent = nullptr, PlaylistModel *playlistModel = nullptr);

signals:
void showPlaylistRequested();

public slots:
void activate();
void deactivate();
Expand All @@ -31,7 +34,6 @@ public slots:

void jump(const QModelIndex &index);

void open();
void addToPlaylist(const QList<QUrl> &urls);

private slots:
Expand Down
10 changes: 10 additions & 0 deletions controlbuttonswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ void ControlButtonsWidget::scale()
this->setMaximumHeight(this->maximumHeight() * UI_SCALE);
this->setMinimumHeight(this->minimumHeight() * UI_SCALE);
}

void ControlButtonsWidget::setShuffleEnabled(bool enabled)
{
ui->shuffleButton->setChecked(enabled);
}

void ControlButtonsWidget::setRepeatEnabled(bool enabled)
{
ui->repeatButton->setChecked(enabled);
}
3 changes: 3 additions & 0 deletions controlbuttonswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class ControlButtonsWidget : public QWidget
explicit ControlButtonsWidget(QWidget *parent = nullptr);
~ControlButtonsWidget();

void setShuffleEnabled(bool enabled);
void setRepeatEnabled(bool enabled);

private:
Ui::ControlButtonsWidget *ui;
void scale();
Expand Down
44 changes: 44 additions & 0 deletions mainmenuview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "mainmenuview.h"
#include "ui_mainmenuview.h"

MainMenuView::MainMenuView(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainMenuView)
{
ui->setupUi(this);

connect(ui->backButton, &QPushButton::clicked, this, &MainMenuView::backClicked);
connect(ui->fileSourceButton, &QPushButton::clicked, this, &MainMenuView::fileSourceClicked);
connect(ui->btSourceButton, &QPushButton::clicked, this, &MainMenuView::btSourceClicked);
connect(ui->spotifySourceButton, &QPushButton::clicked, this, &MainMenuView::spotifySourceClicked);
connect(ui->shutdownButton, &QPushButton::clicked, this, &MainMenuView::shutdown);
}

MainMenuView::~MainMenuView()
{
delete ui;
}

void MainMenuView::fileSourceClicked()
{
emit sourceSelected(0);
}

void MainMenuView::btSourceClicked()
{
emit sourceSelected(1);
}

void MainMenuView::spotifySourceClicked()
{
emit sourceSelected(2);
}

void MainMenuView::shutdown()
{
QString appPath = QCoreApplication::applicationDirPath();
QString cmd = appPath + "/shutdown.sh";

shutdownProcess = new QProcess(this);
shutdownProcess->start(cmd);
}
34 changes: 34 additions & 0 deletions mainmenuview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef MAINMENUVIEW_H
#define MAINMENUVIEW_H

#include <QWidget>
#include <QProcess>

namespace Ui {
class MainMenuView;
}

class MainMenuView : public QWidget
{
Q_OBJECT

public:
explicit MainMenuView(QWidget *parent = nullptr);
~MainMenuView();

signals:
void sourceSelected(int source);
void backClicked();

private:
Ui::MainMenuView *ui;

void fileSourceClicked();
void btSourceClicked();
void spotifySourceClicked();

QProcess *shutdownProcess = nullptr;
void shutdown();
};

#endif // MAINMENUVIEW_H
Loading

0 comments on commit c691536

Please sign in to comment.