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

  1. /* 
  2.  *
  3.  * $Id: sourceheader,v 1.3 2005/01/19 13:03:46 trueg Exp $
  4.  * Copyright (C) 2005-2007 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. #ifndef _K3B_HAL_CONNECTION_H_
  17. #define _K3B_HAL_CONNECTION_H_
  18.  
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22.  
  23. #include "k3bdevice_export.h"
  24.  
  25. #include <qobject.h>
  26. #include <qmap.h>
  27. #include <qstringlist.h>
  28.  
  29. class DBusConnection;
  30.  
  31.  
  32. namespace K3bDevice {
  33.  
  34.   class Device;
  35.  
  36.   /**
  37.    * This is a simple HAL/DBUS wrapper which creates QT signals whenever a new optical
  38.    * drive is plugged into the system or one is unplugged.
  39.    *
  40.    * The HalConnection class also handles media changes. Whenever a new medium is inserted
  41.    * into a drive or a medium is removed (i.e. ejected) a signal is emitted. This way it
  42.    * is easy to keep track of the inserted media.
  43.    *
  44.    * This class does not deal with K3b devices but with system device names
  45.    * such as /dev/cdrom. These device names can be used in DeviceManager::findDevice().
  46.    */
  47.   class LIBK3BDEVICE_EXPORT HalConnection : public QObject
  48.     {
  49.       Q_OBJECT
  50.  
  51.     public:
  52.       ~HalConnection();
  53.  
  54.       /**
  55.        * Creates a new singleton HalConnection object or returns the already existing one.
  56.        * A newly created HalConnection will emit newDevice signals for all devices in the HAL
  57.        * manager. However, since one cannot be sure if this is the first time the HalConnection
  58.        * is created it is recommended to connect to the signals and query the list of current
  59.        * devices.
  60.        *
  61.        * \return An instance of the singleton HalConnection object.
  62.        */
  63.       static HalConnection* instance();
  64.  
  65.       /**
  66.        * \return true if a connection to the HAL deamon could be established and
  67.        *         communication has been set up.
  68.        */
  69.       bool isConnected() const;
  70.  
  71.       /**
  72.        * \return a list of optical devices as reported by HAL.
  73.        */
  74.       QStringList devices() const;
  75.  
  76.       /**
  77.        * \internal
  78.        */
  79.       void addDevice( const char* udi );
  80.  
  81.       /**
  82.        * \internal
  83.        */
  84.       void removeDevice( const char* udi );
  85.  
  86.       /**
  87.        * Error codes named as the HAL deamon raises them
  88.        */
  89.       enum ErrorCodes {
  90.     org_freedesktop_Hal_Success = 0, //*< The operation was successful. This code does not match any in HAL
  91.     org_freedesktop_Hal_CommunicationError, //*< DBus communication error. This code does not match any in HAL
  92.     org_freedesktop_Hal_NoSuchDevice,
  93.     org_freedesktop_Hal_DeviceAlreadyLocked,
  94.     org_freedesktop_Hal_PermissionDenied,
  95.     org_freedesktop_Hal_Device_Volume_NoSuchDevice,
  96.     org_freedesktop_Hal_Device_Volume_PermissionDenied,
  97.     org_freedesktop_Hal_Device_Volume_AlreadyMounted,
  98.     org_freedesktop_Hal_Device_Volume_InvalidMountOption,
  99.     org_freedesktop_Hal_Device_Volume_UnknownFilesystemType,
  100.     org_freedesktop_Hal_Device_Volume_InvalidMountpoint,
  101.     org_freedesktop_Hal_Device_Volume_MountPointNotAvailable,
  102.     org_freedesktop_Hal_Device_Volume_PermissionDeniedByPolicy,
  103.     org_freedesktop_Hal_Device_Volume_InvalidUnmountOption,
  104.     org_freedesktop_Hal_Device_Volume_InvalidEjectOption
  105.       };
  106.  
  107.      public slots:
  108.       /**
  109.        * Lock the device in HAL
  110.        * 
  111.        * Be aware that once the method returns the HAL deamon has not necessarily 
  112.        * finished the procedure yet.
  113.        *
  114.        * \param dev The device to lock
  115.        * \return An error code
  116.        *
  117.        * \see ErrorCode
  118.        */
  119.       int lock( Device* );
  120.  
  121.       /**
  122.        * Unlock a previously locked device in HAL
  123.        * 
  124.        * Be aware that once the method returns the HAL deamon has not necessarily 
  125.        * finished the procedure yet.
  126.        *
  127.        * \param dev The device to lock
  128.        * \return An error code
  129.        *
  130.        * \see ErrorCode
  131.        */
  132.       int unlock( Device* );
  133.  
  134.       /**
  135.        * Mounts a device via HAL
  136.        * 
  137.        * Be aware that once the method returns the HAL deamon has not necessarily 
  138.        * finished the procedure yet.
  139.        *
  140.        * \param dev The device to lock
  141.        * \return An error code
  142.        *
  143.        * \see ErrorCode
  144.        */
  145.       int mount( Device*, 
  146.          const QString& mountPoint = QString::null, 
  147.          const QString& fstype = QString::null,
  148.          const QStringList& options = QStringList() );
  149.  
  150.       /**
  151.        * Unmounts a device via HAL
  152.        * 
  153.        * Be aware that once the method returns the HAL deamon has not necessarily 
  154.        * finished the procedure yet.
  155.        *
  156.        * \param dev The device to lock
  157.        * \return An error code
  158.        *
  159.        * \see ErrorCode
  160.        */
  161.       int unmount( Device*,
  162.            const QStringList& options = QStringList() );
  163.  
  164.       /**
  165.        * Unmounts a device via HAL
  166.        * 
  167.        * Be aware that once the method returns the HAL deamon has not necessarily 
  168.        * finished the procedure yet.
  169.        *
  170.        * \param dev The device to lock
  171.        * \return An error code
  172.        *
  173.        * \see ErrorCode
  174.        */
  175.       int eject( Device*,
  176.          const QStringList& options = QStringList() );
  177.  
  178.     signals:
  179.       /**
  180.        * This signal gets emitted whenever HAL finds a new optical drive.
  181.        *
  182.        * \param dev The block device name of the new drive.
  183.        */
  184.       void deviceAdded( const QString& dev );
  185.  
  186.       /**
  187.        * This signal gets emitted whenever HAL detects that an optical drive
  188.        * has been unplugged.
  189.        *
  190.        * \param dev The block device name of the drive.
  191.        */
  192.       void deviceRemoved( const QString& dev );
  193.  
  194.       /**
  195.        * This signal gets emitted whenever a new medium is inserted into a
  196.        * device or an inserted is removed (i.e. ejected)
  197.        *
  198.        * \param dev The block device name of the drive the medium is or was inserted into.
  199.        */
  200.       void mediumChanged( const QString& dev );
  201.  
  202.     private:
  203.       /**
  204.        * HalConnection is a signelton class. Use the instance() method to create it.
  205.        */
  206.       HalConnection( QObject* parent = 0, const char* name = 0 );
  207.  
  208.       /**
  209.        * Tries to open a connection to HAL.
  210.        */
  211.       bool open();
  212.       void close();
  213.  
  214.       static HalConnection* s_instance;
  215.  
  216.       class Private;
  217.       Private* d;
  218.  
  219.       void setupDBusQtConnection( DBusConnection* dbusConnection );
  220.     };
  221. }
  222.  
  223. #endif
  224.