2022-04-17 15:37:04 +03:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
|
#include "ui_settingsdialog.h"
|
|
|
|
|
#include "settings.h"
|
2022-05-07 17:02:41 +03:00
|
|
|
#include "audio_support.h"
|
2022-04-17 15:37:04 +03:00
|
|
|
|
|
|
|
|
#include <QToolTip>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QWindow>
|
2022-04-20 18:18:44 +03:00
|
|
|
#include <QScreen>
|
2022-05-04 21:20:58 +03:00
|
|
|
#include <QFileDialog>
|
2022-05-07 17:02:41 +03:00
|
|
|
#include <QStandardPaths>
|
2022-04-17 15:37:04 +03:00
|
|
|
|
|
|
|
|
const QString ConversionError = "Integer value expected.";
|
|
|
|
|
|
|
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent) :
|
|
|
|
|
QDialog(parent),
|
|
|
|
|
ui(new Ui::SettingsDialog)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::init()
|
|
|
|
|
{
|
2022-05-07 17:02:41 +03:00
|
|
|
mSkipAudioChangeEvent = true;
|
2022-05-04 21:20:58 +03:00
|
|
|
|
2022-04-17 15:37:04 +03:00
|
|
|
setWindowTitle("Settings");
|
|
|
|
|
|
|
|
|
|
auto c = app_settings::load();
|
|
|
|
|
ui->mAutostartCheckbox->setChecked(c.autostart);
|
|
|
|
|
ui->mWindowOnTopCheckbox->setChecked(c.window_on_top);
|
|
|
|
|
ui->mBreakIntervalEdit->setText(QString::number(c.longbreak_interval / 60));
|
|
|
|
|
ui->mBreakDurationEdit->setText(QString::number(c.longbreak_length / 60));
|
|
|
|
|
ui->mPostponeTimeEdit->setText(QString::number(c.longbreak_postpone_interval / 60));
|
2022-04-20 18:18:44 +03:00
|
|
|
|
|
|
|
|
ui->mPreferredMonitorCombobox->addItem(Primary_Monitor, Primary_Monitor);
|
|
|
|
|
int found_idx = 0;
|
|
|
|
|
auto ql = QGuiApplication::screens();
|
|
|
|
|
int screen_idx = 1;
|
|
|
|
|
for (QScreen* s: ql)
|
|
|
|
|
{
|
|
|
|
|
ui->mPreferredMonitorCombobox->addItem(s->name() +" / " + s->model() + " " + s->manufacturer(), s->name());
|
|
|
|
|
|
|
|
|
|
if (s->name() == c.preferred_monitor)
|
|
|
|
|
found_idx = screen_idx;
|
|
|
|
|
|
|
|
|
|
screen_idx++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->mPreferredMonitorCombobox->setCurrentIndex(found_idx);
|
2022-05-03 21:47:32 +03:00
|
|
|
|
2022-05-04 21:20:58 +03:00
|
|
|
// Fill audio combo box
|
|
|
|
|
auto audios = {Audio_Empty, Audio_Default_1, Audio_Default_2, Audio_Custom};
|
|
|
|
|
ui->mAudioComboBox->addItems(audios);
|
|
|
|
|
mCustomAudioIdx = audios.size() - 1;
|
|
|
|
|
|
|
|
|
|
// Preselect active audio
|
2022-05-03 21:47:32 +03:00
|
|
|
for (int i = 0; i < ui->mAudioComboBox->count(); i++)
|
2022-05-07 17:02:41 +03:00
|
|
|
if (ui->mAudioComboBox->itemText(i) == c.play_audio.name)
|
2022-05-03 21:47:32 +03:00
|
|
|
ui->mAudioComboBox->setCurrentIndex(i);
|
|
|
|
|
|
2022-05-07 17:02:41 +03:00
|
|
|
mCustomAudioPath = c.play_audio.path;
|
2022-05-04 21:20:58 +03:00
|
|
|
|
2022-05-03 21:47:32 +03:00
|
|
|
ui->mScriptEdit->setText(c.script_on_break_finish);
|
2022-05-04 21:20:58 +03:00
|
|
|
connect(ui->mAudioComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onAudioIndexChanged(int)));
|
|
|
|
|
|
2022-05-07 17:02:41 +03:00
|
|
|
mSkipAudioChangeEvent = false;
|
2022-04-17 15:37:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::accept()
|
|
|
|
|
{
|
|
|
|
|
auto c = app_settings::load();
|
2022-05-03 21:47:32 +03:00
|
|
|
|
2022-04-17 15:37:04 +03:00
|
|
|
c.autostart = ui->mAutostartCheckbox->isChecked();
|
|
|
|
|
c.window_on_top = ui->mWindowOnTopCheckbox->isChecked();
|
|
|
|
|
c.longbreak_interval = ui->mBreakIntervalEdit->text().toInt() * 60;
|
|
|
|
|
c.longbreak_length = ui->mBreakDurationEdit->text().toInt() * 60;
|
|
|
|
|
c.longbreak_postpone_interval = ui->mPostponeTimeEdit->text().toInt() * 60;
|
2022-04-20 18:18:44 +03:00
|
|
|
c.preferred_monitor = ui->mPreferredMonitorCombobox->currentData().toString();
|
2022-05-03 21:47:32 +03:00
|
|
|
c.script_on_break_finish = ui->mScriptEdit->text();
|
2022-05-07 17:02:41 +03:00
|
|
|
c.play_audio.name = ui->mAudioComboBox->currentText();
|
|
|
|
|
if (c.play_audio.name == Audio_Custom)
|
|
|
|
|
c.play_audio.path = mCustomAudioPath;
|
2022-05-03 21:47:32 +03:00
|
|
|
|
2022-04-17 15:37:04 +03:00
|
|
|
app_settings::save(c);
|
|
|
|
|
|
|
|
|
|
emit accepted();
|
|
|
|
|
}
|
2022-05-04 21:20:58 +03:00
|
|
|
|
|
|
|
|
void SettingsDialog::onAudioIndexChanged(int idx)
|
|
|
|
|
{
|
2022-05-07 17:02:41 +03:00
|
|
|
if (mSkipAudioChangeEvent)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-05-04 21:20:58 +03:00
|
|
|
if (idx == mCustomAudioIdx)
|
|
|
|
|
{
|
|
|
|
|
// Ask about path to audio file
|
2022-05-07 17:02:41 +03:00
|
|
|
auto home = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
|
|
|
|
auto path = QFileDialog::getOpenFileName(this, tr("Select audio file"), home, tr("Sound files(*.wav *.mp3 *.ogg)"));
|
2022-05-04 21:20:58 +03:00
|
|
|
if (!path.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
mCustomAudioPath = path;
|
|
|
|
|
// ToDo: show message "audio is selected"
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// ToDo: show message "audio is not selected"
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-07 17:02:41 +03:00
|
|
|
|
|
|
|
|
// Play selected audio to ensure this is fine
|
|
|
|
|
play_audio({.name = ui->mAudioComboBox->itemText(idx), .path = mCustomAudioPath});
|
|
|
|
|
|
2022-05-04 21:20:58 +03:00
|
|
|
}
|