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 / k3bdevicehandler.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-27  |  6.0 KB  |  238 lines

  1. /*
  2.  *
  3.  * $Id: k3bdevicehandler.h 619556 2007-01-03 17:38:12Z trueg $
  4.  * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
  5.  *
  6.  * This file is part of the K3b project.
  7.  * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  * See the file "COPYING" for the exact licensing terms.
  14.  */
  15.  
  16.  
  17. #ifndef _K3B_DEVICE_HANDLER_H_
  18. #define _K3B_DEVICE_HANDLER_H_
  19.  
  20. #include <k3bthreadjob.h>
  21. #include "k3bdevice.h"
  22. #include "k3bdiskinfo.h"
  23. #include "k3bmsf.h"
  24. #include "k3bcdtext.h"
  25. #include "k3b_export.h"
  26. #include <qcstring.h>
  27.  
  28. class QCustomEvent;
  29.  
  30.  
  31. namespace K3bDevice
  32. {
  33.   class Device;
  34.  
  35.  
  36.   /**
  37.    * The K3bDevice::Devicehandler is a threaded wrapper around K3bDevice::Device.
  38.    * It allows async access to the time comsuming blocking K3bDevice::Device methods.
  39.    * Since it's a K3bJob it is very easy to handle. Just use one of the methods and
  40.    * connect to the finished signal.
  41.    * Be aware that all methods only return valid values if the corresponding info has
  42.    * been successfuly requested.
  43.    *
  44.    * Be aware that multiple requests in a row (without waiting for the job to finish) will
  45.    * only result in one finished() signal answering the last request.
  46.    */
  47.   class LIBK3B_EXPORT DeviceHandler : public K3bThreadJob
  48.     {
  49.       Q_OBJECT
  50.  
  51.      public:
  52.       DeviceHandler( Device*, QObject* parent = 0, const char* name = 0 );
  53.       DeviceHandler( QObject* parent = 0, const char* name = 0 );
  54.  
  55.       /**
  56.        * This constructor is used by the global "quick" methods and should not be used
  57.        * otherwise except for the same usage.
  58.        */
  59.       DeviceHandler( int command, Device*, const char* name = 0 );
  60.  
  61.       ~DeviceHandler();
  62.  
  63.       const DiskInfo& diskInfo() const;
  64.       const Toc& toc() const;
  65.       const CdText& cdText() const;
  66.       const QByteArray& cdTextRaw() const;
  67.       K3b::Msf diskSize() const;
  68.       K3b::Msf remainingSize() const;
  69.       int tocType() const;
  70.       int numSessions() const;
  71.       long long bufferCapacity() const;
  72.       long long availableBufferCapacity() const;
  73.  
  74.       bool success() const;
  75.  
  76.       /**
  77.        * Use this when the command
  78.        * returnes some error code.
  79.        */
  80.       int errorCode() const;
  81.  
  82.       enum Command {
  83.     /**
  84.      * Always successful, even with an empty or no media at all!
  85.      */
  86.     NG_DISKINFO = 1, // TODO: rename this into DISKINFO
  87.     /**
  88.      * Always successful, even with an empty or no media at all!
  89.      */
  90.     TOC = 2,
  91.     /**
  92.      * Successful if the media contains CD-Text.
  93.      */
  94.     CD_TEXT = 4,
  95.     /**
  96.      * Successful if the media contains CD-Text.
  97.      */
  98.     CD_TEXT_RAW = 8,
  99.     /**
  100.      * Always successful, even with an empty or no media at all!
  101.      */
  102.     DISKSIZE = 16,
  103.     /**
  104.      * Always successful, even with an empty or no media at all!
  105.      */
  106.     REMAININGSIZE = 32,
  107.     /**
  108.      * Always successful, even with an empty or no media at all!
  109.      */
  110.     TOCTYPE = 64,
  111.     /**
  112.      * Always successful, even with an empty or no media at all!
  113.      */
  114.     NUMSESSIONS = 128,
  115.     /**
  116.      * Successful if the drive could be blocked.
  117.      */
  118.     BLOCK = 256,
  119.     /**
  120.      * Successful if the drive could be unblocked.
  121.      */
  122.     UNBLOCK = 512,
  123.     /**
  124.      * Successful if the media was ejected.
  125.      */
  126.     EJECT = 1024,
  127.     /**
  128.      * Successful if the media was loaded
  129.      */
  130.     LOAD = 2048,
  131.     RELOAD = EJECT|LOAD,
  132.     /**
  133.      * Retrieves NG_DISKINFO, TOC, and CD-Text in case of an audio or mixed
  134.      * mode cd.
  135.      * The only difference to NG_DISKINFO|TOC|CD_TEXT is that no CD-Text is not
  136.      * considered an error.
  137.      *
  138.      * Always successful, even with an empty or no media at all!
  139.      */
  140.     DISKINFO = 4096,  // TODO: rename this in somthing like: DISKINFO_COMPLETE
  141.     /**
  142.      * Determine the device buffer state.
  143.      */
  144.     BUFFER_CAPACITY = 8192
  145.       };
  146.  
  147.     signals:
  148.       void finished( K3bDevice::DeviceHandler* );
  149.  
  150.      public slots:
  151.       void setDevice( Device* );
  152.       void sendCommand( int command );
  153.  
  154.       void getToc();
  155.       void getDiskInfo();
  156.       void getDiskSize();
  157.       void getRemainingSize();
  158.       void getTocType();
  159.       void getNumSessions();
  160.       void block( bool );
  161.       void eject();
  162.  
  163.     protected:
  164.       /**
  165.        * reimplemented from K3bThreadJob for internal reasons
  166.        */
  167.       virtual void customEvent( QCustomEvent* );
  168.  
  169.      private:
  170.       class DeviceHandlerThread;
  171.       DeviceHandlerThread* m_thread;
  172.  
  173.       bool m_selfDelete;
  174.     };
  175.  
  176.   /**
  177.    * Usage: 
  178.    * \code 
  179.    *  connect( K3bDevice::sendCommand( K3bDevice::DeviceHandler::MOUNT, dev ), 
  180.    *           SIGNAL(finished(DeviceHandler*)),
  181.    *           this, SLOT(someSlot(DeviceHandler*)) );
  182.    *
  183.    *  void someSlot( DeviceHandler* dh ) {
  184.    *     if( dh->success() ) {
  185.    * \endcode
  186.    *
  187.    * Be aware that the DeviceHandler will get destroyed once the signal has been 
  188.    * emited.
  189.    */
  190.   LIBK3B_EXPORT DeviceHandler* sendCommand( int command, Device* );
  191.  
  192.   inline DeviceHandler* diskInfo(Device* dev) {
  193.     return sendCommand(DeviceHandler::DISKINFO,dev);
  194.   }
  195.  
  196.   inline DeviceHandler* toc(Device* dev) {
  197.     return sendCommand(DeviceHandler::TOC,dev);
  198.   }
  199.  
  200.   inline DeviceHandler* diskSize(Device* dev) {
  201.     return sendCommand(DeviceHandler::DISKSIZE,dev);
  202.   }
  203.  
  204.   inline DeviceHandler* remainingSize(Device* dev) {
  205.     return sendCommand(DeviceHandler::REMAININGSIZE,dev);
  206.   }
  207.  
  208.   inline DeviceHandler* tocType(Device* dev) {
  209.     return sendCommand(DeviceHandler::TOCTYPE,dev);
  210.   }
  211.  
  212.   inline DeviceHandler* numSessions(Device* dev) {
  213.     return sendCommand(DeviceHandler::NUMSESSIONS,dev);
  214.   }
  215.  
  216.   inline DeviceHandler* block(Device* dev) {
  217.     return sendCommand(DeviceHandler::BLOCK,dev);
  218.   }
  219.  
  220.   inline DeviceHandler* unblock(Device* dev) {
  221.     return sendCommand(DeviceHandler::UNBLOCK,dev);
  222.   }
  223.  
  224.   inline DeviceHandler* eject(Device* dev) {
  225.     return sendCommand(DeviceHandler::EJECT,dev);
  226.   }
  227.  
  228.   inline DeviceHandler* reload(Device* dev) {
  229.     return sendCommand(DeviceHandler::RELOAD,dev);
  230.   }
  231.  
  232.   inline DeviceHandler* load(Device* dev) {
  233.     return sendCommand(DeviceHandler::LOAD,dev);
  234.   }
  235. }
  236.  
  237. #endif
  238.