Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

mpdcom.h

Go to the documentation of this file.
00001 #ifndef __MPDCOM__H
00002 #define __MPDCOM__H
00003 
00004 #include <qobject.h>
00005 #include <qsocket.h>
00006 #include <qstringlist.h>
00007 #include <queue>
00008 #include <qtimer.h>
00009 
00010 #include "mpdc.h"
00011 #include "playlist.h"
00012 
00020 class MpdCom : public QObject
00021 {
00022 Q_OBJECT
00023 public:
00024   enum                          responcetype { CONNECTING, SIMPLE, PLAYLIST, PLAYLIST_INFO, STATUS, FILELIST };
00025   enum                          mpdstate     { PLAY, STOP, PAUSE };
00026 
00031   class Status
00032   {
00033   public:
00034     inline                      Status(void) : volume(0), repeat(false), random(false), playlist(0),
00035                                                playlistLength(0), state(STOP), songIndex(0),
00036                                                elapsed(0), songLength(0), bitrate(0), songInfo(NULL) {}
00037 
00038     unsigned                    volume;
00039     bool                        repeat;
00040     bool                        random;
00041     unsigned                    playlist;
00042     int                         playlistLength;
00043     mpdstate                    state;
00044     unsigned                    songIndex;
00045     int                         elapsed;
00046     int                         songLength;
00047     int                         bitrate;
00048     Playlist::SongInfo        * songInfo;
00049     int                         xfade;
00050     unsigned                    samplerate, bits, channels;
00051   };
00052 
00057   class Filelist
00058   {
00059   public:
00064     class ListItem
00065     {
00066     public:
00067                                 ListItem( QString n, unsigned p ) : name(n), properties(p) {}
00068 
00069       QString                   name;                                           
00070       unsigned                  properties;                                     
00071     };
00072 
00073     enum                        { DIR, FILE, PLAYLIST };                        
00074     typedef std::vector<ListItem *>::const_iterator iterator;                   
00075     inline iterator             begin() const                     { return list.begin(); } 
00076     inline iterator             end() const                       { return list.end(); }   
00077     inline void                 clear()                           { list.clear(); }        
00078 
00079     inline Filelist::ListItem * operator [](unsigned i)           { return list[i]; }      
00080 
00081     inline void                 add( QString n, unsigned p )      { list.push_back(new ListItem(n,p)); } 
00082 
00083   private:
00084     std::vector<ListItem *>     list;                                           
00085   };
00086 
00087 protected:
00092   class CommandItem
00093   {
00094   public:
00100     inline CommandItem(QString command, responcetype responce = SIMPLE, bool send = false)
00101                      :command(command),
00102                       responce(responce),
00103                       send(send) {}
00104 
00105     QString                     command;                                        
00106     responcetype                responce;                                       
00107     bool                        send;                                           
00108   };
00109 
00110 public:
00111                                 MpdCom( const char * hostname, int hostport, bool needsPlayList, QObject * ); 
00112 
00113   void                          reconnectCom(const char * hostname, int hostport); 
00114   void                          disconnectCom(void);                            
00115   void                          connectCom(void);                               
00116   bool                          minVersion(QString);                            
00117 
00120   inline QString                getVersion(void)                                { return QString::number(majorVersion) + "." + QString::number(minorVersion) + "." + QString::number(buildVersion); }
00123   inline void                   startCommandList(void)                          { buildingCommandList = true; commandList = "command_list_begin\n"; }
00126   inline void                   endCommandList(void)                            { buildingCommandList = false; commandList += "command_list_end"; postCommand(commandList); }
00127 
00128 public slots:
00129   void                          previous(void);                                 
00130   void                          next(void);                                     
00131   void                          stop(void);                                     
00132   void                          play(void);                                     
00133   void                          play(int);                                      
00134   void                          pause(void);                                    
00135   void                          seek(int songnr, int pos);                      
00136   void                          volume(int perc);                               
00137   void                          repeat(bool);                                   
00138   void                          random(bool);                                   
00139   void                          update(void);                                   
00140   void                          crossFade(int);                                 
00141 
00142   void                          requestPlaylist(void);                          
00143   void                          loadPlaylist(QString, bool = false);            
00144   void                          clearPlaylist(void);                            
00145   void                          deletePlaylist(QString);                        
00146   void                          requestSongInfo(unsigned);                      
00147   void                          requestStatusUpdate(void);                      
00148   void                          requestDirectoryContent(QString dir = "");      
00149   void                          addFile(QString);                               
00150   void                          removeFile(QString);                            
00151   void                          swap(unsigned, unsigned);                       
00152 
00153 protected slots:
00154   void                          slotReadyRead(void);                            
00155   void                          slotConnected(void);                            
00156   void                          slotError(int);                                 
00157   void                          slotReconnect(void);                            
00158   void                          slotConnectionClosed(void);                     
00159 
00160 signals:
00161   void                          playlistUpdate(const Playlist &p);              
00162   void                          statusUpdate(const MpdCom::Status &s);          
00163   void                          error(const QString &e);                        
00164   void                          directoryContent(const MpdCom::Filelist &f);    
00165 
00166 private:
00167   void                          setVersion(QString);
00168   void                          flushCommandQueue(void);
00169 
00170   std::queue<CommandItem *>     commandQueue;
00171   void                          postCommand(QString command, responcetype responce = SIMPLE );
00172   void                          sendData(void);
00173 
00174   QString                       hostname;
00175   int                           hostport;
00176   bool                          needsPlayList;
00177   QSocket                       socket;
00178   Playlist                      playlist;
00179   QTimer                        statusTimer, reconnectTimer;
00180   Playlist::SongInfo            songInfo;
00181   unsigned                      currentPlaylist;
00182   unsigned                      songIndex;
00183   Playlist::SongInfo          * si;
00184   Filelist                      filelist;
00185   QString                       data;
00186   unsigned                      majorVersion;
00187   unsigned                      minorVersion;
00188   unsigned                      buildVersion;
00189   int                           oldvol;
00190   unsigned                      playlistSize;
00191   bool                          buildingCommandList;
00192   QString                       commandList;
00193 };
00194 
00195 #endif

Generated on Thu Mar 11 21:57:51 2004 for Music Playing Daemon client by doxygen1.2.15