Skip to content

Commit

Permalink
feature #75 wip play sound notification with gsound
Browse files Browse the repository at this point in the history
  • Loading branch information
diegorubin committed Jul 2, 2020
1 parent 8bfb1f2 commit dbbb057
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 73 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AC_CONFIG_SRCDIR([src])
AC_CONFIG_MACRO_DIR([m4])

PKG_CHECK_MODULES([Gnomato],[gtkmm-3.0 >= 3.0.0, sqlite3, libnotify >= 0.7.3,
python3 >= 3.5])
python3 >= 3.5, gsound >= 1.0.0])

IT_PROG_INTLTOOL([0.35.0])

Expand Down
1 change: 1 addition & 0 deletions data/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ui_DATA = \
tomato.png \
tomato-green.png \
tomato-gray.png \
alert.ogg \
gnomato.ui

gsettings_SCHEMAS = com.diegorubin.gnomato.gschema.xml
Expand Down
Binary file added data/alert.ogg
Binary file not shown.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ gnomato_SOURCES = main.cc \
config.cc \
dbus_client.cc \
python_executor.cc \
sound_player.cc \
utils.cc

# [TODO] - Add boost in configure.ac
Expand Down
76 changes: 33 additions & 43 deletions src/dialog_preferences.cc
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/*!
* dialog_preferences.cc
* Copyright (C) Diego Rubin 2011 <[email protected]>
*
* Gnomato is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gnomato is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Diego Rubin <[email protected]>
*
*/
* dialog_preferences.cc
* Copyright (C) Diego Rubin 2011 <[email protected]>
*
* Gnomato is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gnomato is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Diego Rubin <[email protected]>
*
*/

#include <gdkmm/rgba.h>
#include "dialog_preferences.h"

DialogPreferences::DialogPreferences(BaseObjectType* cobject,
const Glib::RefPtr<Gtk::Builder>& refGlade)
: Gtk::Dialog(cobject),
m_refGlade(refGlade)
{
DialogPreferences::DialogPreferences(BaseObjectType *cobject,
const Glib::RefPtr<Gtk::Builder> &refGlade)
: Gtk::Dialog(cobject), m_refGlade(refGlade) {
configs.load();

// buttons
m_refGlade->get_widget("btnOk", btnOk);
m_refGlade->get_widget("btnCancel", btnCancel);

// page 1 - intervals
// page 1 - intervals
m_refGlade->get_widget("spnWork", spnWork);
m_refGlade->get_widget("spnShortBreak", spnShortBreak);
m_refGlade->get_widget("spnLongBreak", spnLongBreak);
Expand All @@ -47,35 +44,29 @@ DialogPreferences::DialogPreferences(BaseObjectType* cobject,
// page 2 - colors
m_refGlade->get_widget("clrTimer", clrTimer);
Gdk::RGBA timer;
timer.set_rgba(
configs.colorTimerRed,
configs.colorTimerGreen,
configs.colorTimerBlue);
timer.set_rgba(configs.colorTimerRed, configs.colorTimerGreen,
configs.colorTimerBlue);
clrTimer->set_rgba(timer);

// connect signals
btnCancel->signal_clicked().connect(sigc::mem_fun(*this,&DialogPreferences::on_button_cancel_clicked));
btnOk->signal_clicked().connect(sigc::mem_fun(*this,&DialogPreferences::on_button_ok_clicked));
btnCancel->signal_clicked().connect(
sigc::mem_fun(*this, &DialogPreferences::on_button_cancel_clicked));
btnOk->signal_clicked().connect(
sigc::mem_fun(*this, &DialogPreferences::on_button_ok_clicked));

show_all();
}

DialogPreferences::~DialogPreferences()
{
}
DialogPreferences::~DialogPreferences() {}

void DialogPreferences::on_button_cancel_clicked()
{
hide();
}
void DialogPreferences::on_button_cancel_clicked() { hide(); }

void DialogPreferences::on_button_ok_clicked()
{
void DialogPreferences::on_button_ok_clicked() {
configs.work_interval = spnWork->get_text();
configs.break_interval = spnShortBreak->get_text();
configs.long_interval = spnLongBreak->get_text();
configs.inactive_interval = spnInactiveInterval->get_text();

Gdk::RGBA timer = clrTimer->get_rgba();
configs.colorTimerRed = timer.get_red();
configs.colorTimerGreen = timer.get_green();
Expand All @@ -84,4 +75,3 @@ void DialogPreferences::on_button_ok_clicked()
configs.save();
hide();
}

51 changes: 26 additions & 25 deletions src/dialog_preferences.h
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/*!
* dialog_preferences.h
* Copyright (C) Diego Rubin 2011 <[email protected]>
*
* Gnomato is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gnomato is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Diego Rubin <[email protected]>
*
*/
* dialog_preferences.h
* Copyright (C) Diego Rubin 2011 <[email protected]>
*
* Gnomato is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gnomato is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Diego Rubin <[email protected]>
*
*/

#ifndef _WIN_PREFERENCES_H_
#define _WIN_PREFERENCES_H_

#include <gdkmm/rgba.h>
#include <gtkmm.h>

#include "config.h"

using namespace Gtk;

class DialogPreferences: public Gtk::Dialog
{
class DialogPreferences : public Gtk::Dialog {
public:
DialogPreferences(BaseObjectType* cobject,
const Glib::RefPtr<Gtk::Builder>& refGlade);
DialogPreferences(BaseObjectType *cobject,
const Glib::RefPtr<Gtk::Builder> &refGlade);

virtual ~DialogPreferences();
protected:
virtual ~DialogPreferences();

protected:
private:
// attributes
Config configs;
Expand Down
3 changes: 1 addition & 2 deletions src/dialog_work_log_entries.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/*!
* dialog_preferences.cc
* dialog_work_log_entries.cc
* Copyright (C) Diego Rubin 2020 <[email protected]>
*
* Gnomato is free software: you can redistribute it and/or modify it
Expand All @@ -21,7 +21,6 @@
*/

#include "dialog_work_log_entries.h"
#include <gdkmm/rgba.h>

DialogWorkLogEntries::DialogWorkLogEntries(
BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &refGlade)
Expand Down
2 changes: 1 addition & 1 deletion src/dialog_work_log_entries.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/*!
* dialog_preferences.h
* dialog_work_log_entries.h
* Copyright (C) Diego Rubin 2020 <[email protected]>
*
* Gnomato is free software: you can redistribute it and/or modify it
Expand Down
1 change: 0 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ void migrate_database() {
}

int main(int argc, char **argv) {

sprintf(dbpath, "%s", dbfile().c_str());
bootstrap();
migrate_database();
Expand Down
41 changes: 41 additions & 0 deletions src/sound_player.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/*!
* sound_player.cc
* Copyright (C) Diego Rubin 2020 <[email protected]>
*
* Gnomato is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gnomato is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Diego Rubin <[email protected]>
*
*/

#include "sound_player.h"

SoundPlayer::SoundPlayer(string file) : file(file) {
gsound = gsound_context_new(NULL, NULL);
}

SoundPlayer::SoundPlayer() : SoundPlayer(GNOMATO_DATADIR "/alert.ogg") {}

SoundPlayer::~SoundPlayer() {}

void SoundPlayer::play() {
if (!gsound) {
cout << _("Error on load gsound context") << endl;
return;
}

gsound_context_play_simple(gsound, NULL, NULL, GSOUND_ATTR_MEDIA_FILENAME,
"phone-incoming-call", NULL);
}
49 changes: 49 additions & 0 deletions src/sound_player.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/*!
* sound_player.h
* Copyright (C) Diego Rubin 2020 <[email protected]>
*
* Gnomato is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gnomato is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Diego Rubin <[email protected]>
*
*/

#ifndef _SOUND_PLAYER_H_
#define _SOUND_PLAYER_H_

#include <glibmm/i18n.h>
#include <gsound.h>
#include <iostream>
#include <sstream>

using namespace std;

class SoundPlayer {
public:
SoundPlayer(string file);
SoundPlayer();

virtual ~SoundPlayer();

// methods
void play();

private:
// attributes
string file;
GSoundContext *gsound;
};

#endif // SOUND_PLAYER
3 changes: 3 additions & 0 deletions src/win_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ void WinMain::notify(const char *message) {
}

void WinMain::notify(const char *icon, const char *message) {
SoundPlayer soundPlayer;

NotifyNotification *notMessage;
GError *error = NULL;

Expand All @@ -357,6 +359,7 @@ void WinMain::notify(const char *icon, const char *message) {

notify_notification_set_urgency(notMessage, NOTIFY_URGENCY_NORMAL);

soundPlayer.play();
notify_notification_show(notMessage, &error);
}

Expand Down
1 change: 1 addition & 0 deletions src/win_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "dialog_task.h"
#include "dialog_work_log_entries.h"
#include "python_executor.h"
#include "sound_player.h"
#include "task.h"
#include "task_list.h"
#include "utils.h"
Expand Down

0 comments on commit dbbb057

Please sign in to comment.