- more work on audio notifications
This commit is contained in:
parent
95de5416f6
commit
e157c638ad
BIN
app/assets/sound/alarm-poehali.wav
Normal file
BIN
app/assets/sound/alarm-poehali.wav
Normal file
Binary file not shown.
@ -319,13 +319,16 @@ void MainWindow::onLongBreakEnd()
|
||||
onUpdateUI();
|
||||
|
||||
// Play audio
|
||||
if (mAppConfig.play_audio != Empty_Play_Audio)
|
||||
if (mAppConfig.play_audio != Audio_Empty && mAppConfig.play_audio != Audio_Custom)
|
||||
{
|
||||
if (mAppConfig.play_audio == Embedded_Play_Audio)
|
||||
QSound::play(":/assets/sound/alarm-retro.wav");
|
||||
else
|
||||
QSound::play(mAppConfig.play_audio);
|
||||
auto iter = AudioMap.find(mAppConfig.play_audio);
|
||||
if (iter != AudioMap.end())
|
||||
QSound::play(iter->second);
|
||||
}
|
||||
else
|
||||
if (mAppConfig.play_audio == Audio_Custom)
|
||||
QSound::play(mAppConfig.play_audio_custom);
|
||||
|
||||
|
||||
// Run script
|
||||
if (!mAppConfig.script_on_break_finish.isEmpty())
|
||||
|
||||
@ -13,5 +13,6 @@
|
||||
<file>assets/images/coffee_cup/icon_128x128.png</file>
|
||||
<file>assets/images/coffee_cup/icon_512x512.png</file>
|
||||
<file>assets/sound/alarm-retro.wav</file>
|
||||
<file>assets/sound/alarm-poehali.wav</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@ -10,8 +10,9 @@ const QString Key_Window_On_Top = "Window_On_Top";
|
||||
const QString Key_Verbose = "Verbose";
|
||||
const QString Key_Autostart = "Autostart";
|
||||
const QString Key_PreferredMonitor = "Preferred_Monitor";
|
||||
const QString Key_Audio_On_Break_Finish = "Audio_On_Break_Finish";
|
||||
const QString Key_Script_On_Break_Finish = "Script_On_Break_Finish";
|
||||
const QString Key_Audio = "Audio";
|
||||
const QString Key_Audio_Custom = "Audio_Custom";
|
||||
const QString Key_Script = "Script";
|
||||
|
||||
void app_settings::save(const config &cfg)
|
||||
{
|
||||
@ -24,8 +25,9 @@ void app_settings::save(const config &cfg)
|
||||
s.setValue(Key_Verbose, cfg.verbose);
|
||||
s.setValue(Key_Autostart, cfg.autostart);
|
||||
s.setValue(Key_PreferredMonitor, cfg.preferred_monitor);
|
||||
s.setValue(Key_Audio_On_Break_Finish, cfg.play_audio);
|
||||
s.setValue(Key_Script_On_Break_Finish, cfg.script_on_break_finish);
|
||||
s.setValue(Key_Audio, cfg.play_audio);
|
||||
s.setValue(Key_Audio_Custom, cfg.play_audio_custom);
|
||||
s.setValue(Key_Script, cfg.script_on_break_finish);
|
||||
}
|
||||
|
||||
app_settings::config app_settings::load()
|
||||
@ -40,8 +42,9 @@ app_settings::config app_settings::load()
|
||||
r.verbose = s.value(Key_Verbose, Default_Verbose).toBool();
|
||||
r.autostart = s.value(Key_Autostart, Default_Autostart).toBool();
|
||||
r.preferred_monitor = s.value(Key_PreferredMonitor, Default_Monitor).toString();
|
||||
r.play_audio = s.value(Key_Audio_On_Break_Finish, Empty_Play_Audio).toString();
|
||||
r.script_on_break_finish = s.value(Key_Script_On_Break_Finish, QString()).toString();
|
||||
r.play_audio = s.value(Key_Audio, Audio_Empty).toString();
|
||||
r.play_audio_custom = s.value(Key_Audio_Custom, Audio_Custom).toString();
|
||||
r.script_on_break_finish = s.value(Key_Script, QString()).toString();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#define SETTINGS_H
|
||||
|
||||
#include <QString>
|
||||
#include <map>
|
||||
|
||||
// Default values in seconds
|
||||
const int Default_LongBreak_Interval = 50 * 60;
|
||||
@ -22,8 +23,22 @@ const QString Default_Monitor = "";
|
||||
const QString Primary_Monitor = "[Primary]";
|
||||
|
||||
// Default behavior is not play any audio on break end.
|
||||
const QString Empty_Play_Audio = "[None]";
|
||||
const QString Embedded_Play_Audio = "[Embedded]";
|
||||
const QString Audio_Empty = "None";
|
||||
const QString Audio_Default_1 = "Default 1";
|
||||
const QString Audio_Default_2 = "Default_2";
|
||||
const QString Audio_Custom = "Custom...";
|
||||
|
||||
struct audio_item
|
||||
{
|
||||
QString name;
|
||||
QString path;
|
||||
};
|
||||
|
||||
const std::map<QString, QString> AudioMap {
|
||||
{Audio_Default_1, ":/assets/sound/alarm-retro.wav"},
|
||||
{Audio_Default_2, ":/assets/sound/alarm-poehali.wav"},
|
||||
};
|
||||
|
||||
|
||||
// Used app name
|
||||
const QString AppName = "QBreak";
|
||||
@ -44,7 +59,8 @@ public:
|
||||
QString preferred_monitor = Default_Monitor;
|
||||
|
||||
// This value can be path to audio file or empty or [embedded] string
|
||||
QString play_audio = Empty_Play_Audio;
|
||||
QString play_audio = Audio_Empty;
|
||||
QString play_audio_custom;
|
||||
QString script_on_break_finish;
|
||||
};
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <QTimer>
|
||||
#include <QWindow>
|
||||
#include <QScreen>
|
||||
#include <QFileDialog>
|
||||
|
||||
const QString ConversionError = "Integer value expected.";
|
||||
|
||||
@ -24,6 +25,8 @@ SettingsDialog::~SettingsDialog()
|
||||
|
||||
void SettingsDialog::init()
|
||||
{
|
||||
mDontRunEvents = true;
|
||||
|
||||
setWindowTitle("Settings");
|
||||
|
||||
auto c = app_settings::load();
|
||||
@ -49,15 +52,22 @@ void SettingsDialog::init()
|
||||
|
||||
ui->mPreferredMonitorCombobox->setCurrentIndex(found_idx);
|
||||
|
||||
ui->mAudioComboBox->addItem(Empty_Play_Audio);
|
||||
ui->mAudioComboBox->addItem(Embedded_Play_Audio);
|
||||
if (c.play_audio != Empty_Play_Audio && c.play_audio != Embedded_Play_Audio)
|
||||
ui->mAudioComboBox->addItem(c.play_audio);
|
||||
// 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
|
||||
for (int i = 0; i < ui->mAudioComboBox->count(); i++)
|
||||
if (ui->mAudioComboBox->itemText(i) == c.play_audio)
|
||||
ui->mAudioComboBox->setCurrentIndex(i);
|
||||
|
||||
mCustomAudioPath = c.play_audio_custom;
|
||||
|
||||
ui->mScriptEdit->setText(c.script_on_break_finish);
|
||||
connect(ui->mAudioComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onAudioIndexChanged(int)));
|
||||
|
||||
mDontRunEvents = false;
|
||||
}
|
||||
|
||||
void SettingsDialog::accept()
|
||||
@ -72,8 +82,28 @@ void SettingsDialog::accept()
|
||||
c.preferred_monitor = ui->mPreferredMonitorCombobox->currentData().toString();
|
||||
c.script_on_break_finish = ui->mScriptEdit->text();
|
||||
c.play_audio = ui->mAudioComboBox->currentText();
|
||||
if (c.play_audio == Audio_Custom)
|
||||
c.play_audio_custom = mCustomAudioPath;
|
||||
|
||||
app_settings::save(c);
|
||||
|
||||
emit accepted();
|
||||
}
|
||||
|
||||
void SettingsDialog::onAudioIndexChanged(int idx)
|
||||
{
|
||||
if (idx == mCustomAudioIdx)
|
||||
{
|
||||
// Ask about path to audio file
|
||||
auto path = QFileDialog::getOpenFileName(this, tr("Select audio file"), QString(), ".wav;*.mp3;*.ogg");
|
||||
if (!path.isEmpty())
|
||||
{
|
||||
mCustomAudioPath = path;
|
||||
// ToDo: show message "audio is selected"
|
||||
}
|
||||
else
|
||||
{
|
||||
// ToDo: show message "audio is not selected"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,11 +17,15 @@ public:
|
||||
|
||||
private:
|
||||
Ui::SettingsDialog *ui;
|
||||
QString mCustomAudioPath;
|
||||
int mCustomAudioIdx;
|
||||
bool mDontRunEvents;
|
||||
|
||||
void init();
|
||||
|
||||
private slots:
|
||||
void accept();
|
||||
void onAudioIndexChanged(int idx);
|
||||
};
|
||||
|
||||
#endif // SETTINGSDIALOG_H
|
||||
|
||||
@ -124,14 +124,14 @@
|
||||
<item row="8" column="1">
|
||||
<widget class="QComboBox" name="mAudioComboBox">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Script to run when break finish</string>
|
||||
<string>Command to run when break finish</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user