home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kabc / sound.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-01-15  |  3.9 KB  |  154 lines

  1. /*
  2.     This file is part of libkabc.
  3.     Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef KABC_SOUND_H
  22. #define KABC_SOUND_H
  23.  
  24. #include <qcstring.h>
  25. #include <qstring.h>
  26.  
  27. #include <kdelibs_export.h>
  28.  
  29. namespace KABC {
  30.  
  31. /** @short Class that holds a Sound clip for a contact.
  32.  *
  33.  *  The sound can be played doing something like this:
  34.  *
  35.  *  \code
  36.  *    KTempFile tmp;
  37.  *    if(sound.isIntern()) {
  38.  *      tmp.file()->writeBlock( sound.data() );
  39.  *      tmp.close();
  40.  *      KAudioPlayer::play( tmp.name() );
  41.  *    } else if(!sound.url().isEmpty()) {
  42.  *      QString tmpFile;
  43.  *      if(!KIO::NetAccess::download(KURL(themeURL.url()), tmpFile, NULL))
  44.  *      {
  45.  *        KMessageBox::error(0L,
  46.  *                           KIO::NetAccess::lastErrorString(),
  47.  *                           i18n("Failed to download sound file"),
  48.  *                           KMessageBox::Notify
  49.  *                          );
  50.  *        return;
  51.  *      }
  52.  *      KAudioPlayer::play( tmpFile ); 
  53.  *    }
  54.  *  \endcode
  55.  *       
  56.  *  Unfortunetly KAudioPlayer::play is ASync, so to delete the temporary file, the best you can really do is set a timer.
  57.  *
  58.  */
  59. class KABC_EXPORT Sound
  60. {
  61.   friend KABC_EXPORT QDataStream &operator<<( QDataStream &, const Sound & );
  62.   friend KABC_EXPORT QDataStream &operator>>( QDataStream &, Sound & );
  63.  
  64. public:
  65.  
  66.   /**
  67.    * Consturctor. Creates an empty object.
  68.    */
  69.   Sound();
  70.  
  71.   /**
  72.    * Consturctor.
  73.    *
  74.    * @param url  A URL that describes the position of the sound file.
  75.    */
  76.   Sound( const QString &url );
  77.  
  78.   /**
  79.    * Consturctor.
  80.    *
  81.    * @param data  The raw data of the sound.
  82.    */
  83.   Sound( const QByteArray &data );
  84.  
  85.   /**
  86.    * Destructor.
  87.    */
  88.   ~Sound();
  89.  
  90.  
  91.   bool operator==( const Sound & ) const;
  92.   bool operator!=( const Sound & ) const;
  93.  
  94.   /**
  95.    * Sets a URL for the location of the sound file. When using this
  96.    * function, isIntern() will return 'false' until you use
  97.    * setData().
  98.    *
  99.    * @param url  The location URL of the sound file.
  100.    */
  101.   void setUrl( const QString &url );
  102.  
  103.   /**
  104.    * Test if this sound file has been set.
  105.    * Just does:  !isIntern() && url.isEmpty()
  106.    * @since 3.4
  107.    */
  108.   bool isEmpty() const;
  109.   
  110.   /**
  111.    * Sets the raw data of the sound. When using this function,
  112.    * isIntern() will return 'true' until you use setUrl().
  113.    *
  114.    * @param data  The raw data of the sound.
  115.    */
  116.   void setData( const QByteArray &data );
  117.  
  118.   /**
  119.    * Returns whether the sound is described by a URL (extern) or
  120.    * by the raw data (intern).
  121.    * When this method returns 'true' you can use data() to
  122.    * get the raw data. Otherwise you can request the URL of this
  123.    * sound by url() and load the raw data from that location.
  124.    */
  125.   bool isIntern() const;
  126.  
  127.   /**
  128.    * Returns the location URL of this sound.
  129.    */
  130.   QString url() const;
  131.  
  132.   /**
  133.    * Returns the raw data of this sound.
  134.    */
  135.   QByteArray data() const;
  136.  
  137.   /**
  138.    * Returns string representation of the sound.
  139.    */
  140.   QString asString() const;
  141.  
  142. private:
  143.   QString mUrl;
  144.   QByteArray mData;
  145.  
  146.   int mIntern;
  147. };
  148.  
  149. KABC_EXPORT QDataStream &operator<<( QDataStream &, const Sound & );
  150. KABC_EXPORT QDataStream &operator>>( QDataStream &, Sound & );
  151.  
  152. }
  153. #endif
  154.