Skip to content

Commit

Permalink
added sound notification support
Browse files Browse the repository at this point in the history
  • Loading branch information
naxuroqa committed Aug 21, 2014
1 parent 7eedfad commit 0584524
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 18 deletions.
35 changes: 35 additions & 0 deletions sounds/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright (C) 2013 Venom authors and contributors
#
# This file is part of Venom.
#
# Venom 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.
#
# Venom 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 Venom. If not, see <http://www.gnu.org/licenses/>.
#

SET(VENOM_SOUNDS
contact-logs-in.wav
contact-logs-out.wav
contact-request-accepted.wav
error.wav
incoming-call.wav
incoming-video-call.wav
log-in.wav
log-out.wav
new-message.wav
outgoing-call.wav
outgoing-video-call.wav
transfer-complete.wav
transfer-pending.wav
)
INSTALL(FILES ${VENOM_THEMES} DESTINATION "${COMMON_DATA_DIR}/venom/sounds")
Binary file added sounds/contact-logs-in.wav
Binary file not shown.
Binary file added sounds/contact-logs-out.wav
Binary file not shown.
Binary file added sounds/contact-request-accepted.wav
Binary file not shown.
Binary file added sounds/error.wav
Binary file not shown.
Binary file added sounds/incoming-call.wav
Binary file not shown.
Binary file added sounds/incoming-video-call.wav
Binary file not shown.
1 change: 1 addition & 0 deletions sounds/license
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tox's sounds are licensed under the "Creative Commons Attribution 3.0 Unported", all credit attributed to Adam Reid.
Binary file added sounds/log-in.wav
Binary file not shown.
Binary file added sounds/log-out.wav
Binary file not shown.
Binary file added sounds/new-message.wav
Binary file not shown.
Binary file added sounds/outgoing-call.wav
Binary file not shown.
Binary file added sounds/outgoing-video-call.wav
Binary file not shown.
Binary file added sounds/transfer-complete.wav
Binary file not shown.
Binary file added sounds/transfer-pending.wav
Binary file not shown.
38 changes: 34 additions & 4 deletions src/core/AVManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ namespace Venom {
public static AVManager instance {get; private set;}

public static void init() throws AVManagerError {
#if DEBUG
instance = new AVManager({"", "--gst-debug-level=3"});
#else
//#if DEBUG
// instance = new AVManager({"", "--gst-debug-level=3"});
//#else
instance = new AVManager({""});
#endif
//#endif
}

public static void free() {
Expand Down Expand Up @@ -649,5 +649,35 @@ namespace Venom {
}
}

public void play_sound(string location) {
Logger.log(LogLevel.DEBUG, "playing sound " + location);
Gst.Element playbin = Gst.ElementFactory.make("playbin2", "playbin");
Gst.Element sink = Gst.ElementFactory.make("autoaudiosink", "sink");
playbin.set("uri", location,
"audio-sink", sink);
Gst.Bus bus = ((Gst.Pipeline) playbin).get_bus();
bus.add_watch((bus, message) => {
Error e;
switch(message.type) {
case Gst.MessageType.ERROR:
message.parse_error(out e, null);
Logger.log(LogLevel.ERROR, "Error playing sound: " + e.message);
break;
case Gst.MessageType.EOS:
playbin.set_state(Gst.State.NULL);
playbin.unref();
Logger.log(LogLevel.DEBUG, "sound finished playing");
break;
case Gst.MessageType.WARNING:
message.parse_warning(out e, null);
Logger.log(LogLevel.WARNING, "Error playing sound: " + e.message);
break;
default:
break;
}
return true;
});
playbin.set_state(Gst.State.PLAYING);
}
}
}
8 changes: 6 additions & 2 deletions src/core/ResourceFactory.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ namespace Venom {
}

private ResourceFactory () {
string theme_folder = Path.build_filename(Tools.find_data_dir(), "theme");
string data_dir = Tools.find_data_dir();
theme_directory = Path.build_filename(data_dir, "theme");
sounds_directory = Path.build_filename(data_dir, "sounds");

arrow = load_image_from_resource("/org/gtk/venom/pixmaps/button_icons/arrow_white.png");
send_file = load_image_from_resource("/org/gtk/venom/pixmaps/button_icons/attach.png");
Expand Down Expand Up @@ -63,7 +65,7 @@ namespace Venom {
default_contact = load_image_from_resource("/org/gtk/venom/pixmaps/user_icons/default_contact.png");
default_groupchat = load_image_from_resource("/org/gtk/venom/pixmaps/user_icons/default_groupchat.png");

default_theme_filename = Path.build_filename(theme_folder, "default.css");
default_theme_filename = Path.build_filename(theme_directory, "default.css");


tox_config_dir = Path.build_filename(GLib.Environment.get_user_config_dir(), "tox");
Expand Down Expand Up @@ -104,6 +106,8 @@ namespace Venom {

public Gdk.Pixbuf arrow {get; private set;}

public string sounds_directory {get; set;}
public string theme_directory {get; set;}
public string default_theme_filename {get; private set;}
public string tox_config_dir {get; private set;}
public string data_filename {get; set;}
Expand Down
7 changes: 4 additions & 3 deletions src/core/Tools.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ namespace Venom {
return dir;
}
}
string current_dir = GLib.Environment.get_current_dir();
// Check for common directories on portable versions
string[] portable_directories = {
Path.build_filename(GLib.Environment.get_user_data_dir(), "venom"),
Path.build_filename("share", "venom"),
Path.build_filename("..", "share", "venom")
Path.build_filename(current_dir, "share", "venom"),
Path.build_filename(current_dir, "..", "share", "venom")
};
foreach (string s in portable_directories) {
File f = File.new_for_path(s);
Expand All @@ -48,7 +49,7 @@ namespace Venom {

// Assume that our current pwd is our data dir
Logger.log(LogLevel.INFO, "Assuming current working directory is data directoy");
return "";
return current_dir;
}

public static void create_path_for_file(string filename, int mode) {
Expand Down
24 changes: 15 additions & 9 deletions src/ui/ContactListWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace Venom {
init_save_session_hooks();
init_user();

on_ownconnectionstatus(false);
//on_ownconnectionstatus(false);

Logger.log(LogLevel.INFO, "ID: " + Tools.bin_to_hexstring(session.get_address()));
if(ResourceFactory.instance.offline_mode) {
Expand All @@ -99,6 +99,7 @@ namespace Venom {
public void cleanup() {
if(cleaned_up)
return;

Logger.log(LogLevel.DEBUG, "Ending session...");
// Stop background thread
session.stop();
Expand Down Expand Up @@ -633,10 +634,13 @@ namespace Venom {
}
}

public void set_urgency () {
public void set_urgency (string? sound = null) {
if(!is_active && Settings.instance.enable_urgency_notification) {
this.set_urgency_hint(true);
this.set_title("* %s".printf(this.our_title));
if(sound != null) {
AVManager.instance.play_sound(sound);
}
}
}

Expand Down Expand Up @@ -694,7 +698,7 @@ namespace Venom {
c.unread_messages++;
contact_list_tree_view.update_entry(c);
}
this.set_urgency();
this.set_urgency(Path.build_filename("file://" + ResourceFactory.instance.sounds_directory, "new-message.wav"));
}
private void on_action(Contact c, string action) {
Logger.log(LogLevel.DEBUG, "[ac] %i:%s".printf(c.friend_id, action));
Expand All @@ -704,7 +708,7 @@ namespace Venom {
c.unread_messages++;
contact_list_tree_view.update_entry(c);
}
this.set_urgency();
this.set_urgency(Path.build_filename("file://" + ResourceFactory.instance.sounds_directory, "new-message.wav"));
}
private void on_namechange(Contact c, string? old_name) {
Logger.log(LogLevel.INFO, old_name + " changed name to " + c.name);
Expand All @@ -731,9 +735,11 @@ namespace Venom {
if(status) {
image_status.set_tooltip_text(_("Connected to the network"));
session.set_user_status(user_status);
AVManager.instance.play_sound(Path.build_filename("file://" + ResourceFactory.instance.sounds_directory, "log-in.wav"));
} else {
image_status.set_tooltip_text(_("Disconnected from the network"));
on_ownuserstatus(UserStatus.OFFLINE);
AVManager.instance.play_sound(Path.build_filename("file://" + ResourceFactory.instance.sounds_directory, "log-out.wav"));
}
image_status.show();
spinner_status.hide();
Expand Down Expand Up @@ -768,7 +774,7 @@ namespace Venom {

private void on_group_invite(Contact c, GroupChat g) {
Logger.log(LogLevel.INFO, "Group invite from %s with public key %s".printf(c.name, Tools.bin_to_hexstring(g.public_key)));
this.set_urgency();
this.set_urgency(Path.build_filename("file://" + ResourceFactory.instance.sounds_directory, "new-message.wav"));
Gtk.MessageDialog message_dialog = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.QUESTION,
Expand Down Expand Up @@ -814,7 +820,7 @@ namespace Venom {
GroupMessage group_message = new GroupMessage.incoming(g, gcc, message);
// only set urgency in groupchat if the message contains our name
if(User.instance.name in message) {
this.set_urgency();
this.set_urgency(Path.build_filename("file://" + ResourceFactory.instance.sounds_directory, "new-message.wav"));
group_message.important = true;
}
incoming_group_message(group_message);
Expand Down Expand Up @@ -844,7 +850,7 @@ namespace Venom {
GroupActionMessage group_message = new GroupActionMessage.incoming(g, gcc, message);
// only set urgency in groupchat if the message contains our name
if(User.instance.name in message) {
this.set_urgency();
this.set_urgency(Path.build_filename("file://" + ResourceFactory.instance.sounds_directory, "new-message.wav"));
group_message.important = true;
}
incoming_group_action(group_message);
Expand All @@ -857,7 +863,7 @@ namespace Venom {
}

private void on_av_invite(Contact c) {
this.set_urgency();
this.set_urgency(Path.build_filename("file://" + ResourceFactory.instance.sounds_directory, (c.video ? "incoming-video-call.wav" : "incoming-call")));
if(c.auto_video && c.video || c.auto_audio && !c.video) {
//Auto accept
session.answer_call(c);
Expand Down Expand Up @@ -947,7 +953,7 @@ namespace Venom {
ft.status = FileTransferStatus.IN_PROGRESS;
}

this.set_urgency();
this.set_urgency(Path.build_filename("file://" + ResourceFactory.instance.sounds_directory, "transfer-pending.wav"));
}

private void send_file(int friendnumber, uint8 filenumber) {
Expand Down

0 comments on commit 0584524

Please sign in to comment.