Back to index

lightning-sunbird  0.9+nobinonly
nsSound.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Pierre Phaneuf <pp@ludusdesign.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 
00040 #include "nscore.h"
00041 #include "plstr.h"
00042 #include "prlink.h"
00043 
00044 #include "nsSound.h"
00045 
00046 #include "nsIURL.h"
00047 #include "nsNetUtil.h"
00048 #include "nsCOMPtr.h"
00049 
00050 #include <Pt.h>
00051 
00052 NS_IMPL_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver)
00053 
00054 
00055 nsSound::nsSound()
00056 {
00057   mInited = PR_FALSE;
00058 }
00059 
00060 nsSound::~nsSound()
00061 {
00062 }
00063 
00064 nsresult nsSound::Init()
00065 {
00066   if (mInited) return NS_OK;
00067 
00068   mInited = PR_TRUE;
00069   return NS_OK;
00070 }
00071 
00072 NS_METHOD nsSound::Beep()
00073 {
00074   ::PtBeep();
00075   return NS_OK;
00076 }
00077 
00078 NS_METHOD nsSound::Play(nsIURL *aURL)
00079 {
00080   NS_NOTYETIMPLEMENTED("nsSound::Play");
00081 
00082 #ifdef DEBUG
00083 printf( "\n\n\nnsSound::Play\n\n" );
00084 #endif
00085 
00086   return NS_OK;
00087 }
00088 
00089 NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
00090                                         nsISupports *context,
00091                                         nsresult aStatus,
00092                                         PRUint32 stringLen,
00093                                         const PRUint8 *stringData)
00094 {
00095   nsresult rv = NS_ERROR_FAILURE;
00096 
00097 #ifdef DEBUG
00098 printf( "\n\n\nnsSound::OnStreamComplete stringData=%s\n\n", stringData );
00099 #endif
00100 
00101   if (NS_FAILED(aStatus))
00102     return NS_ERROR_FAILURE;
00103 
00104   return rv;
00105 }
00106 
00107 static void child_exit( void *data, int status ) { }
00108 
00109 NS_IMETHODIMP nsSound::PlaySystemSound(const char *aSoundAlias)
00110 {
00111 #ifdef DEBUG
00112 printf( "\n\n\nnsSound::PlaySystemSound aSoundAlias=%s\n\n", aSoundAlias );
00113 #endif
00114 
00115        const char *soundfile;
00116 
00117        if( !strcmp( "_moz_mailbeep", aSoundAlias ) )
00118               soundfile = "/usr/share/mozilla/gotmail.wav";
00119        else {
00120               if( !access( aSoundAlias, F_OK ) ) /* the aSoundAlias is the fullpath to the soundfile */
00121                      soundfile = aSoundAlias;
00122               else soundfile = "/usr/share/mozilla/rest.wav";
00123               }
00124 
00125        const char* argv[] = { "/opt/Mozilla/mozilla/wave", soundfile, NULL };
00126        PtSpawn( "/opt/Mozilla/mozilla/wave", ( const char ** ) argv, NULL, NULL, child_exit, NULL, NULL );
00127 
00128        return NS_OK;
00129 }