tomboy r2059 - in trunk: . Tomboy/Addins/VoiceNotes
- From: nshmyrev svn gnome org
- To: svn-commits-list gnome org
- Subject: tomboy r2059 - in trunk: . Tomboy/Addins/VoiceNotes
- Date: Sun, 3 Aug 2008 11:31:22 +0000 (UTC)
Author: nshmyrev
Date: Sun Aug 3 11:31:22 2008
New Revision: 2059
URL: http://svn.gnome.org/viewvc/tomboy?rev=2059&view=rev
Log:
2008-08-03 Gabriel Marcondes <gabrielgeraldo gmail com>
* Tomboy/Addins/VoiceNotes/voicenomedia.c: added a bus handler
to make sure the state is correctly set after the end of stream,
and a get_status function to let the note know if it is streaming.
* Tomboy/Addins/VoiceNotes/VoiceNote.cs: media buttons sensitivity
are updated so the user won't do more than one action at a time;
renamed some variables to fit the patterns.
Modified:
trunk/ChangeLog
trunk/Tomboy/Addins/VoiceNotes/VoiceNote.cs
trunk/Tomboy/Addins/VoiceNotes/voicenotemedia.c
Modified: trunk/Tomboy/Addins/VoiceNotes/VoiceNote.cs
==============================================================================
--- trunk/Tomboy/Addins/VoiceNotes/VoiceNote.cs (original)
+++ trunk/Tomboy/Addins/VoiceNotes/VoiceNote.cs Sun Aug 3 11:31:22 2008
@@ -9,12 +9,14 @@
{
public class VoiceNote : NoteAddin
{
- Gtk.ToolButton recordButton;
- Gtk.ToolButton playButton;
- Gtk.ToolButton stopButton;
+ Gtk.ToolButton record_button;
+ Gtk.ToolButton play_button;
+ Gtk.ToolButton stop_button;
Gtk.SeparatorToolItem separator;
+ InterruptableTimeout button_manager;
String voice_note_path;
- FileStream voice_note_file;
+ bool has_voice_note;
+
static VoiceNote ()
{
@@ -31,69 +33,97 @@
[DllImport("libvoicenote")]
static extern void stop_stream ();
+
+ [DllImport("libvoicenote")]
+ static extern int get_state ();
public override void Initialize ()
{
separator = new Gtk.SeparatorToolItem ();
- recordButton = new Gtk.ToolButton (Gtk.Stock.MediaRecord);
- recordButton.Clicked += OnRecordButtonClicked;
- playButton = new Gtk.ToolButton (Gtk.Stock.MediaPlay);
- playButton.Clicked += OnPlayButtonClicked;
- stopButton = new Gtk.ToolButton (Gtk.Stock.MediaStop);
- stopButton.Clicked += OnStopButtonClicked;
+ record_button = new Gtk.ToolButton (Gtk.Stock.MediaRecord);
+ record_button.Clicked += OnRecordButtonClicked;
+ play_button = new Gtk.ToolButton (Gtk.Stock.MediaPlay);
+ play_button.Clicked += OnPlayButtonClicked;
+ stop_button = new Gtk.ToolButton (Gtk.Stock.MediaStop);
+ stop_button.Clicked += OnStopButtonClicked;
initialize ();
}
public override void Shutdown ()
{
- recordButton.Clicked -= OnRecordButtonClicked;
- playButton.Clicked -= OnPlayButtonClicked;
- stopButton.Clicked -= OnStopButtonClicked;
+ record_button.Clicked -= OnRecordButtonClicked;
+ play_button.Clicked -= OnPlayButtonClicked;
+ stop_button.Clicked -= OnStopButtonClicked;
}
public override void OnNoteOpened ()
{
- voice_note_path = Note.FilePath + ".ogg";
+ voice_note_path = Note.FilePath + ".ogg";
+ has_voice_note = voice_note_exists ();
separator.Show ();
- recordButton.Show ();
- playButton.Show ();
- stopButton.Show ();
+ record_button.Show ();
+ play_button.Sensitive = has_voice_note;
+ play_button.Show ();
+ stop_button.Sensitive = false;
+ stop_button.Show ();
AddToolItem (separator, -1);
- AddToolItem (recordButton, -1);
- AddToolItem (playButton, -1);
- AddToolItem (stopButton, -1);
+ AddToolItem (record_button, -1);
+ AddToolItem (play_button, -1);
+ AddToolItem (stop_button, -1);
+
+ button_manager = new InterruptableTimeout ();
+ button_manager.Timeout += UpdateButtons;
}
void OnRecordButtonClicked (object sender, EventArgs args)
{
start_record (voice_note_path);
+ button_manager.Reset (100);
}
void OnPlayButtonClicked (object sender, EventArgs args)
{
start_play (voice_note_path);
+ button_manager.Reset (100);
}
void OnStopButtonClicked (object sender, EventArgs args)
{
stop_stream ();
}
-
+
+ void UpdateButtons (object sender, EventArgs args)
+ {
+ int media_state = get_state ();
+ switch (media_state) {
+ case 0: //Stopped
+ record_button.Sensitive = true;
+ play_button.Sensitive = true;
+ stop_button.Sensitive = false;
+ break;
+ case 1: //Streaming
+ record_button.Sensitive = false;
+ play_button.Sensitive = false;
+ stop_button.Sensitive = true;
+ button_manager.Reset (100);
+ break;
+ default: //should not happen!!!
+ break;
+ }
+ }
bool voice_note_exists ()
{
+ FileStream voice_note_file;
try{
- /* Not guilty, I presume */
voice_note_file = File.Open (voice_note_path, FileMode.Open);
}
catch (Exception except) {
- /* Oh, you've disappointed me
- * I'll do nothing for you */
return false;
}
return true;
Modified: trunk/Tomboy/Addins/VoiceNotes/voicenotemedia.c
==============================================================================
--- trunk/Tomboy/Addins/VoiceNotes/voicenotemedia.c (original)
+++ trunk/Tomboy/Addins/VoiceNotes/voicenotemedia.c Sun Aug 3 11:31:22 2008
@@ -12,7 +12,30 @@
initialize ()
{
gst_init (NULL, NULL);
- return 0;
+}
+
+static gboolean
+bus_callback (GstBus *bus, GstMessage *message, gpointer data)
+{
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_EOS: {
+ gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY);
+ printf ("Finished?");
+ break;
+ }
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+void
+set_bus ()
+{
+ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
+ gst_bus_add_watch (bus, bus_callback, NULL);
+ gst_object_unref (bus);
}
void
@@ -22,6 +45,7 @@
gst_command = g_strconcat(gst_command, uri, NULL);
pipeline = gst_parse_launch (gst_command, NULL);
g_free (gst_command);
+ set_bus ();
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
}
@@ -33,6 +57,7 @@
gst_command = g_strconcat (gst_command, PLAY_CMD_END);
pipeline = gst_parse_launch (gst_command, NULL);
g_free (gst_command);
+ set_bus ();
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
}
@@ -41,3 +66,18 @@
{
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
}
+
+gint
+get_state ()
+{
+ gint status = GST_STATE (pipeline);
+ switch (status) {
+ case GST_STATE_PLAYING:
+ status = 1;
+ break;
+ default:
+ status = 0;
+ break;
+ }
+ return status;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]