Skip to content

Commit

Permalink
Merge pull request #6 from vivaladav/custom-sound
Browse files Browse the repository at this point in the history
Add support for custom sounds
  • Loading branch information
vivaladav authored Nov 20, 2024
2 parents 0e3a767 + 54ec7af commit ccdd0f2
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)

project(SIGBUILD LANGUAGES CXX VERSION 0.4.5)
project(SIGBUILD LANGUAGES CXX VERSION 0.5.0)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
Expand Down
6 changes: 3 additions & 3 deletions SIGBUILD.json.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"Name" : "SIGBUILD",
"Version" : "0.4.6",
"CompatVersion" : "0.4.6",
"Version" : "0.5.0",
"CompatVersion" : "0.5.0",
"Vendor" : "Davide Coppola",
"Copyright" : "(C) Davide Coppola",
"License" : "GPL v3.",
"Category" : "Qt Creator",
"Description" : "This plugin notifies you when a build ends and tracks stats of your builds.",
"Url" : "http://sigbuild.com",
"Url" : "https://github.com/vivaladav/SIGBUILD",
${IDE_PLUGIN_DEPENDENCIES}
}
91 changes: 86 additions & 5 deletions src/OptionsPageMainWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
#include "Settings.h"

#include <QCheckBox>
#include <QFileDialog>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSpacerItem>
#include <QSpinBox>
#include <QVBoxLayout>
Expand All @@ -15,17 +19,17 @@ namespace Sigbuild

OptionsPageMainWidget::OptionsPageMainWidget(const Settings * settings)
{
QVBoxLayout * layout = new QVBoxLayout(this);
auto layout = new QVBoxLayout(this);

// == SYSTRAY BOX ==
QGroupBox * box = new QGroupBox(tr("Systray"), this);
layout->addWidget(box);

QVBoxLayout * layoutBox = new QVBoxLayout(box);
auto layoutBox = new QVBoxLayout(box);

const bool SYSTRAY_ENABLED = settings->IsSystrayEnabled();
const bool SYSTRAY_NOTIFY_ENABLED = settings->IsSystrayNotificationEnabled();
const bool SYSTRAY_OPT_STATUS = SYSTRAY_ENABLED && SYSTRAY_NOTIFY_ENABLED;
const bool SYSTRAY_ENABLED = settings->IsSystrayEnabled();
const bool SYSTRAY_NOTIFY_ENABLED = settings->IsSystrayNotificationEnabled();
const bool SYSTRAY_OPT_STATUS = SYSTRAY_ENABLED && SYSTRAY_NOTIFY_ENABLED;

// -- systray on/off --
mSystrayEnabled = new QCheckBox(tr("Enable systray icon"), box);
Expand Down Expand Up @@ -103,6 +107,64 @@ OptionsPageMainWidget::OptionsPageMainWidget(const Settings * settings)
mAudioNotifyWhenActive->setEnabled(audioEnabled);
layoutBox->addWidget(mAudioNotifyWhenActive);

// -- audio custom sounds --
mAudioCustomSounds = new QCheckBox(tr("Use custom sounds"), box);
mAudioCustomSounds->setChecked(settings->UseCustomSounds());
mAudioCustomSounds->setEnabled(audioEnabled);
layoutBox->addWidget(mAudioCustomSounds);

// success sound
const int MIN_COL0_W = 200;
auto layoutGridRow = new QGridLayout;
layoutBox->addLayout(layoutGridRow);
layoutGridRow->setEnabled(false);
layoutGridRow->setColumnMinimumWidth(0, MIN_COL0_W);

mCustomSoundSuccessLabel = new QLabel(tr("Success sound:"));
layoutGridRow->addWidget(mCustomSoundSuccessLabel, 0, 0);
mCustomSoundSuccessLine = new QLineEdit(settings->GetCustomSuccessSound());
mCustomSoundSuccessLine->setReadOnly(true);
layoutGridRow->addWidget(mCustomSoundSuccessLine, 0, 1);
mCustomSoundSuccessButton = new QPushButton(tr("Select"));
layoutGridRow->addWidget(mCustomSoundSuccessButton, 0, 2);

connect(mCustomSoundSuccessButton, &QPushButton::clicked, this, [this, settings]
{
QString fileName = QFileDialog::getOpenFileName(this, tr("select a success sound"),
QString(), tr("Audio (*.ogg *.mp3 *.wav)"));

if(!fileName.isEmpty())
mCustomSoundSuccessLine->setText(fileName);
});

// fail sound
layoutGridRow = new QGridLayout;
layoutBox->addLayout(layoutGridRow);
layoutGridRow->setEnabled(false);
layoutGridRow->setColumnMinimumWidth(0, MIN_COL0_W);

mCustomSoundFailLabel = new QLabel(tr("Fail sound:"));
layoutGridRow->addWidget(mCustomSoundFailLabel, 0, 0);
mCustomSoundFailLine = new QLineEdit(settings->GetCustomFailSound());
mCustomSoundFailLine->setReadOnly(true);
layoutGridRow->addWidget(mCustomSoundFailLine, 0, 1);
mCustomSoundFailButton = new QPushButton(tr("Select"));
layoutGridRow->addWidget(mCustomSoundFailButton, 0, 2);

connect(mCustomSoundFailButton, &QPushButton::clicked, this, [this, settings]
{
QString fileName = QFileDialog::getOpenFileName(this, tr("select a failure sound"),
QString(), tr("Audio (*.ogg *.mp3 *.wav)"));

if(!fileName.isEmpty())
mCustomSoundFailLine->setText(fileName);
});

connect(mAudioCustomSounds, &QCheckBox::stateChanged,
this, &OptionsPageMainWidget::SetCustomAudioControlsVisible);

SetCustomAudioControlsVisible(settings->UseCustomSounds());

// -- audio volume --
layoutRow = new QHBoxLayout;
layoutBox->addLayout(layoutRow);
Expand Down Expand Up @@ -155,6 +217,9 @@ Settings OptionsPageMainWidget::GenerateSettings() const
// -- AUDIO --
settings.SetAudioEnabled(mAudioEnabled->isChecked());
settings.SetAudioNotificationWhenActive(mAudioNotifyWhenActive->isChecked());
settings.SetUseCustomSounds(mAudioCustomSounds->isChecked());
settings.SetCustomSuccessSound(mCustomSoundSuccessLine->text());
settings.SetCustomFailSound(mCustomSoundFailLine->text());
settings.SetAudioVolume(mAudioVolume->value());
settings.SetAudioMinBuildTime(mAudioMinBuildTime->value());

Expand All @@ -181,10 +246,26 @@ void OptionsPageMainWidget::OnAudioStateChanged()
const bool STATUS = mAudioEnabled->isChecked();

mAudioNotifyWhenActive->setEnabled(STATUS);
mAudioCustomSounds->setEnabled(STATUS);
mAudioVolume->setEnabled(STATUS);
mAudioVolumeLabel->setEnabled(STATUS);
mAudioMinBuildTime->setEnabled(STATUS);
mAudioMinBuildTimeLabel->setEnabled(STATUS);

mCustomSoundSuccessLabel->setEnabled(STATUS);
mCustomSoundSuccessLine->setEnabled(STATUS);
mCustomSoundFailLabel->setEnabled(STATUS);
mCustomSoundFailLine->setEnabled(STATUS);
}

void OptionsPageMainWidget::SetCustomAudioControlsVisible(bool visible)
{
mCustomSoundSuccessLabel->setVisible(visible);
mCustomSoundSuccessLine->setVisible(visible);
mCustomSoundSuccessButton->setVisible(visible);
mCustomSoundFailLabel->setVisible(visible);
mCustomSoundFailLine->setVisible(visible);
mCustomSoundFailButton->setVisible(visible);
}

} // namespace Sigbuild
10 changes: 10 additions & 0 deletions src/OptionsPageMainWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;
class QSpinBox;

namespace Sigbuild
Expand All @@ -23,6 +25,7 @@ class OptionsPageMainWidget : public QWidget
private slots:
void OnSystrayStateChanged();
void OnAudioStateChanged();
void SetCustomAudioControlsVisible(bool visible);

private:
// -- SYSTRAY BOX --
Expand All @@ -37,6 +40,13 @@ private slots:
// -- AUDIO BOX --
QCheckBox * mAudioEnabled = nullptr;
QCheckBox * mAudioNotifyWhenActive = nullptr;
QCheckBox * mAudioCustomSounds = nullptr;
QLabel * mCustomSoundSuccessLabel = nullptr;
QLineEdit * mCustomSoundSuccessLine = nullptr;
QPushButton * mCustomSoundSuccessButton = nullptr;
QLabel * mCustomSoundFailLabel = nullptr;
QLineEdit * mCustomSoundFailLine = nullptr;
QPushButton * mCustomSoundFailButton = nullptr;
QSpinBox * mAudioVolume = nullptr;
QLabel * mAudioVolumeLabel = nullptr;
QSpinBox * mAudioMinBuildTime = nullptr;
Expand Down
27 changes: 23 additions & 4 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const QByteArray OPT_SYSTRAY_MIN_BUILD_TIME("SYSTRAY_MIN_BUILD_TIME");
const QByteArray OPT_SYSTRAY_NOTIFY_TIME("SYSTRAY_NOTIFY_TIME");
const QByteArray OPT_AUDIO_ENABLED("AUDIO_ENABLED");
const QByteArray OPT_AUDIO_NOTIFY_WHEN_ACTIVE("AUDIO_NOTIFY_WHEN_ACTIVE");
const QByteArray OPT_AUDIO_CUSTOM_SOUNDS("AUDIO_CUSTOMS_SOUNDS");
const QByteArray OPT_AUDIO_CUSTOM_SOUND_SUCCESS("AUDIO_CUSTOMS_SOUND_SUCCESS");
const QByteArray OPT_AUDIO_CUSTOM_SOUND_FAIL("AUDIO_CUSTOMS_SOUND_FAIL");
const QByteArray OPT_AUDIO_VOLUME("AUDIO_VOLUME");
const QByteArray OPT_AUDIO_MIN_BUILD_TIME("AUDIO_MIN_BUILD_TIME");

Expand All @@ -26,6 +29,9 @@ const int DEF_SYSTRAY_MIN_BUILD_TIME = 0;
const int DEF_SYSTRAY_NOTIFY_TIME = 5;
const bool DEF_AUDIO_ENABLED = true;
const bool DEF_AUDIO_NOTIFY_WHEN_ACTIVE = true;
const bool DEF_AUDIO_CUSTOM_SOUNDS = false;
const QString DEF_AUDIO_CUSTOM_SOUND_SUCCESS = QString();
const QString DEF_AUDIO_CUSTOM_SOUND_FAIL = QString();
const int DEF_AUDIO_VOLUME = Settings::AUDIO_VOL_MAX;
const int DEF_AUDIO_MIN_BUILD_TIME = 0;

Expand All @@ -36,6 +42,9 @@ Settings::Settings()
, mOptSystrayMinBuildTime(DEF_SYSTRAY_MIN_BUILD_TIME)
, mOptAudioEnabled(DEF_AUDIO_ENABLED)
, mOptAudioNotifyWhenActive(DEF_AUDIO_NOTIFY_WHEN_ACTIVE)
, mOptAudioCustomSounds(DEF_AUDIO_CUSTOM_SOUNDS)
, mOptAudioCustomSuccessSound(DEF_AUDIO_CUSTOM_SOUND_SUCCESS)
, mOptAudioCustomFailSound(DEF_AUDIO_CUSTOM_SOUND_FAIL)
, mOptAudioVolume(DEF_AUDIO_VOLUME)
, mOptAudioMinBuildTime(DEF_AUDIO_MIN_BUILD_TIME)
{
Expand All @@ -57,17 +66,24 @@ void Settings::Load()

// -- AUDIO --
mOptAudioEnabled = globalSettings->value(OPT_AUDIO_ENABLED, DEF_AUDIO_ENABLED).toBool();
mOptAudioNotifyWhenActive = globalSettings->value( OPT_AUDIO_NOTIFY_WHEN_ACTIVE,
DEF_AUDIO_NOTIFY_WHEN_ACTIVE).toBool();
mOptAudioNotifyWhenActive = globalSettings->value(OPT_AUDIO_NOTIFY_WHEN_ACTIVE,
DEF_AUDIO_NOTIFY_WHEN_ACTIVE).toBool();
mOptAudioCustomSounds = globalSettings->value(OPT_AUDIO_CUSTOM_SOUNDS,
DEF_AUDIO_CUSTOM_SOUNDS).toBool();
mOptAudioCustomSuccessSound = globalSettings->value(OPT_AUDIO_CUSTOM_SOUND_SUCCESS,
DEF_AUDIO_CUSTOM_SOUND_SUCCESS).toString();
mOptAudioCustomFailSound = globalSettings->value(OPT_AUDIO_CUSTOM_SOUND_FAIL,
DEF_AUDIO_CUSTOM_SOUND_FAIL).toString();
mOptAudioVolume = globalSettings->value(OPT_AUDIO_VOLUME, DEF_AUDIO_VOLUME).toInt();
mOptAudioMinBuildTime = globalSettings->value(OPT_AUDIO_MIN_BUILD_TIME, DEF_AUDIO_MIN_BUILD_TIME).toInt();
mOptAudioMinBuildTime = globalSettings->value(OPT_AUDIO_MIN_BUILD_TIME,
DEF_AUDIO_MIN_BUILD_TIME).toInt();

globalSettings->endGroup();
}

void Settings::Save()
{
Utils::QtcSettings *globalSettings = Core::ICore::settings();
Utils::QtcSettings * globalSettings = Core::ICore::settings();

globalSettings->beginGroup(GROUP);

Expand All @@ -81,6 +97,9 @@ void Settings::Save()
// -- AUDIO --
globalSettings->setValue(OPT_AUDIO_ENABLED, mOptAudioEnabled);
globalSettings->setValue(OPT_AUDIO_NOTIFY_WHEN_ACTIVE, mOptAudioNotifyWhenActive);
globalSettings->setValue(OPT_AUDIO_CUSTOM_SOUNDS, mOptAudioCustomSounds);
globalSettings->setValue(OPT_AUDIO_CUSTOM_SOUND_SUCCESS, mOptAudioCustomSuccessSound);
globalSettings->setValue(OPT_AUDIO_CUSTOM_SOUND_FAIL, mOptAudioCustomFailSound);
globalSettings->setValue(OPT_AUDIO_VOLUME, mOptAudioVolume);
globalSettings->setValue(OPT_AUDIO_MIN_BUILD_TIME, mOptAudioMinBuildTime);

Expand Down
26 changes: 24 additions & 2 deletions src/Settings.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <QString>

namespace Sigbuild
{

Expand Down Expand Up @@ -34,6 +36,13 @@ class Settings
bool PlayAudioNotificationWhenActive() const;
void SetAudioNotificationWhenActive(bool val);

bool UseCustomSounds() const;
void SetUseCustomSounds(bool val);
QString GetCustomSuccessSound() const;
void SetCustomSuccessSound(QString filename);
QString GetCustomFailSound() const;
void SetCustomFailSound(QString filename);

int GetAudioVolume() const;
double GetAudioVolumeAsReal() const;
void SetAudioVolume(int val);
Expand Down Expand Up @@ -69,6 +78,9 @@ class Settings
// -- AUDIO --
bool mOptAudioEnabled;
bool mOptAudioNotifyWhenActive;
bool mOptAudioCustomSounds;
QString mOptAudioCustomSuccessSound;
QString mOptAudioCustomFailSound;
int mOptAudioVolume;
int mOptAudioMinBuildTime;
};
Expand All @@ -94,6 +106,13 @@ inline void Settings::SetAudioEnabled(bool val) { mOptAudioEnabled = val; }
inline bool Settings::PlayAudioNotificationWhenActive() const { return mOptAudioNotifyWhenActive; }
inline void Settings::SetAudioNotificationWhenActive(bool val) { mOptAudioNotifyWhenActive = val; }

inline bool Settings::UseCustomSounds() const { return mOptAudioCustomSounds; }
inline void Settings::SetUseCustomSounds(bool val) { mOptAudioCustomSounds = val; }
inline QString Settings::GetCustomSuccessSound() const { return mOptAudioCustomSuccessSound; }
inline void Settings::SetCustomSuccessSound(QString filename) { mOptAudioCustomSuccessSound = filename; }
inline QString Settings::GetCustomFailSound() const { return mOptAudioCustomFailSound; }
inline void Settings::SetCustomFailSound(QString filename) { mOptAudioCustomFailSound = filename; }

inline int Settings::GetAudioVolume() const { return mOptAudioVolume; }
inline double Settings::GetAudioVolumeAsReal() const
{
Expand All @@ -105,15 +124,18 @@ inline int Settings::GetAudioMinBuildtime() const { return mOptAudioMinBuildTime
// -- OPERATORS --
inline bool Settings::operator==(const Settings & other) const
{
return mOptSystrayEnabled == other.mOptSystrayEnabled &&
return mOptSystrayEnabled == other.mOptSystrayEnabled &&
mOptSystrayNotifyEnabled == other.mOptSystrayNotifyEnabled &&
mOptSystrayNotifyWhenActive == other.mOptSystrayNotifyWhenActive &&
mOptSystrayMinBuildTime == other.mOptSystrayMinBuildTime &&
mOptSystrayNotifyTime == other.mOptSystrayNotifyTime &&
mOptAudioEnabled == other.mOptAudioEnabled &&
mOptAudioNotifyWhenActive == other.mOptAudioNotifyWhenActive &&
mOptAudioVolume == other.mOptAudioVolume &&
mOptAudioMinBuildTime == other.mOptAudioMinBuildTime;
mOptAudioMinBuildTime == other.mOptAudioMinBuildTime &&
mOptAudioCustomSounds == other.mOptAudioCustomSounds &&
mOptAudioCustomSuccessSound == other.mOptAudioCustomSuccessSound &&
mOptAudioCustomFailSound == other.mOptAudioCustomFailSound;
}

inline bool Settings::operator!=(const Settings & other) const
Expand Down
Loading

0 comments on commit ccdd0f2

Please sign in to comment.