forked from MrBesen/soundboard
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
#include <Log.h>
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::Soundboard) {
|
|
ui->setupUi(this);
|
|
|
|
reloadConfig();
|
|
|
|
// init Buttons
|
|
SoundButton* sb;
|
|
sb = new SoundButton("Uwu_voice-xjrU3N8M4eo-251.mp3", "UwU", "Shift+F1");
|
|
ui->gridLayout->addWidget(sb->getButton(), 0, 0);
|
|
soundbuttons.push_back(sb);
|
|
sb = new SoundButton("bonk.wav", "Bonk");
|
|
ui->gridLayout->addWidget(sb->getButton(), 0, 1);
|
|
soundbuttons.push_back(sb);
|
|
|
|
QObject::connect(ui->reloadButton, SIGNAL( clicked() ), this, SLOT( reloadConfig() ));
|
|
QObject::connect(this, SIGNAL( newStatusMessage(const QString&) ), ui->statusbar, SLOT( showMessage(const QString&) ));
|
|
}
|
|
|
|
MainWindow::~MainWindow() {
|
|
delete ui;
|
|
|
|
Sound::deinit();
|
|
}
|
|
|
|
void MainWindow::reloadConfig() {
|
|
Log::info << "realodConfig()";
|
|
|
|
QString loaded = QString::fromStdString("loading config");
|
|
emit newStatusMessage(loaded);
|
|
|
|
config.load();
|
|
|
|
Sound& sound = Sound::instance(); // init sound
|
|
sound.reset();
|
|
const std::vector<std::string>& devices = config.rootConfig.audio.devices;
|
|
for(const std::string& device : devices) {
|
|
Log::note << "loadAudio device: \"" << device << '"';
|
|
|
|
if(!sound.addDeviceWithName(device)) {
|
|
Log::warn << "AudioDevice could not be loaded: \"" << device << '"';
|
|
QString done = QString::fromStdString("Sound Device: " + device + " not found!");
|
|
emit newStatusMessage(done);
|
|
return;
|
|
}
|
|
}
|
|
|
|
QString done = QString::fromStdString("config loaded");
|
|
emit newStatusMessage(done);
|
|
|
|
Log::info << "realodConfig() done";
|
|
}
|