- first audio notification
This commit is contained in:
parent
3777a11397
commit
95de5416f6
BIN
app/assets/sound/alarm-retro.wav
Normal file
BIN
app/assets/sound/alarm-retro.wav
Normal file
Binary file not shown.
@ -4,7 +4,7 @@
|
||||
// App version
|
||||
#define QBREAK_VERSION_MAJOR 0
|
||||
#define QBREAK_VERSION_MINOR 0
|
||||
#define QBREAK_VERSION_SUFFIX 8
|
||||
#define QBREAK_VERSION_SUFFIX 9
|
||||
|
||||
// How often UI is updated - interval in seconds
|
||||
#define INTERVAL_UPDATE_UI (60)
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
#include <QFileInfo>
|
||||
#include <QSound>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@ -170,7 +171,7 @@ void MainWindow::test_2()
|
||||
// 60 seconds test break
|
||||
mAppConfig.longbreak_length = 60;
|
||||
mAppConfig.longbreak_postpone_interval = 60;
|
||||
mAppConfig.longbreak_interval = 240;
|
||||
mAppConfig.longbreak_interval = 60;
|
||||
|
||||
mAppConfig.window_on_top = true;
|
||||
mAppConfig.verbose = true;
|
||||
@ -316,6 +317,23 @@ void MainWindow::onLongBreakEnd()
|
||||
|
||||
// Refresh UI
|
||||
onUpdateUI();
|
||||
|
||||
// Play audio
|
||||
if (mAppConfig.play_audio != Empty_Play_Audio)
|
||||
{
|
||||
if (mAppConfig.play_audio == Embedded_Play_Audio)
|
||||
QSound::play(":/assets/sound/alarm-retro.wav");
|
||||
else
|
||||
QSound::play(mAppConfig.play_audio);
|
||||
}
|
||||
|
||||
// Run script
|
||||
if (!mAppConfig.script_on_break_finish.isEmpty())
|
||||
{
|
||||
int retcode = system(mAppConfig.script_on_break_finish.toStdString().c_str());
|
||||
if (retcode != 0)
|
||||
qDebug() << "User script exited with error code " << retcode;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onLongBreakPostpone()
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
QT += core gui svg
|
||||
QT += core gui svg multimedia
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
|
||||
@ -12,5 +12,6 @@
|
||||
<file>assets/images/coffee_cup/icon_96x96.png</file>
|
||||
<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>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@ -10,6 +10,8 @@ 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";
|
||||
|
||||
void app_settings::save(const config &cfg)
|
||||
{
|
||||
@ -22,6 +24,8 @@ 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);
|
||||
}
|
||||
|
||||
app_settings::config app_settings::load()
|
||||
@ -36,5 +40,8 @@ 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();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -21,10 +21,14 @@ const bool Default_Autostart = true;
|
||||
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]";
|
||||
|
||||
// Used app name
|
||||
const QString AppName = "QBreak";
|
||||
|
||||
|
||||
class app_settings
|
||||
{
|
||||
public:
|
||||
@ -38,6 +42,10 @@ public:
|
||||
bool verbose = Default_Verbose;
|
||||
bool autostart = Default_Autostart;
|
||||
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 script_on_break_finish;
|
||||
};
|
||||
|
||||
static void save(const config& cfg);
|
||||
|
||||
@ -48,17 +48,31 @@ 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);
|
||||
for (int i = 0; i < ui->mAudioComboBox->count(); i++)
|
||||
if (ui->mAudioComboBox->itemText(i) == c.play_audio)
|
||||
ui->mAudioComboBox->setCurrentIndex(i);
|
||||
|
||||
ui->mScriptEdit->setText(c.script_on_break_finish);
|
||||
}
|
||||
|
||||
void SettingsDialog::accept()
|
||||
{
|
||||
auto c = app_settings::load();
|
||||
|
||||
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;
|
||||
c.preferred_monitor = ui->mPreferredMonitorCombobox->currentData().toString();
|
||||
c.script_on_break_finish = ui->mScriptEdit->text();
|
||||
c.play_audio = ui->mAudioComboBox->currentText();
|
||||
|
||||
app_settings::save(c);
|
||||
|
||||
emit accepted();
|
||||
|
||||
@ -6,14 +6,14 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>746</width>
|
||||
<height>217</height>
|
||||
<width>800</width>
|
||||
<height>359</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>746</width>
|
||||
<height>167</height>
|
||||
<height>220</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
@ -114,6 +114,30 @@
|
||||
<item row="6" column="1">
|
||||
<widget class="QComboBox" name="mPreferredMonitorCombobox"/>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Audio to play when break finish</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QComboBox" name="mAudioComboBox">
|
||||
<property name="editable">
|
||||
<bool>true</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>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<widget class="QLineEdit" name="mScriptEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user