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