File indexing completed on 2024-04-28 08:41:53

0001 /*
0002     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef K3BDEVICEMANAGER_H
0007 #define K3BDEVICEMANAGER_H
0008 
0009 #include "k3bdevice_export.h"
0010 
0011 #include <QDebug>
0012 #include <QObject>
0013 #include <QString>
0014 
0015 class KConfigGroup;
0016 
0017 namespace Solid {
0018     class Device;
0019 }
0020 
0021 namespace K3b {
0022     namespace Device {
0023 
0024         class Device;
0025 
0026         /**
0027          * \brief Manages all devices.
0028          *
0029          * Searches the system for devices and maintains lists of them.
0030          *
0031          * <b>Basic usage:</b>
0032          * \code
0033          *   K3b::Device::DeviceManager* manager = new K3b::Device::DeviceManager( this );
0034          *   manager->scanBus();
0035          *   K3b::Device::Device* dev = manager->findDevice( "/dev/cdrom" );
0036          * \endcode
0037          */
0038         class LIBK3BDEVICE_EXPORT DeviceManager : public QObject
0039         {
0040             Q_OBJECT
0041 
0042         public:
0043             /**
0044              * Creates a new DeviceManager
0045              */
0046             explicit DeviceManager( QObject* parent = 0 );
0047             ~DeviceManager() override;
0048 
0049             /**
0050              * By default the DeviceManager makes the Devices check their writing modes.
0051              * This includes commands to be sent which require writing permissions on the
0052              * devices and might take some time.
0053              *
0054              * So if you don't need the information about the writing modes use this method
0055              * to speed up the device detection procedure.
0056              *
0057              * Be aware that this only refers to CD writing modes. If you only want to handle
0058              * DVD devices it's always save to set this to false.
0059              */
0060             void setCheckWritingModes( bool b );
0061 
0062             /**
0063              * \deprecated use findDevice( const QString& )
0064              */
0065             Device* deviceByName( const QString& );
0066 
0067             /**
0068              * Search a device by blockdevice name.
0069              *
0070              * \return The corresponding device or 0 if there is no such device.
0071              */
0072             Device* findDevice( const QString& devicename );
0073 
0074             /**
0075              * Search a device by UDI.
0076              *
0077              * \return The corresponding device or 0 if there is no such device.
0078              */
0079             Device* findDeviceByUdi( const QString& udi );
0080 
0081             /**
0082              * Before getting the devices do a @ref scanBus().
0083              * \return List of all cd writer devices.
0084              * \deprecated use cdWriter()
0085              */
0086             QList<Device*> burningDevices() const;
0087 
0088             /**
0089              * \return List of all reader devices without writer devices.
0090              * \deprecated use cdReader()
0091              **/
0092             QList<Device*> readingDevices() const;
0093 
0094             /**
0095              * Before getting the devices do a @ref scanBus() or add 
0096              * devices via addDevice( const QString& ).
0097              *
0098              * \return List of all devices.
0099              */
0100             QList<Device*> allDevices() const;
0101 
0102             /**
0103              * Before getting the devices do a @ref scanBus() or add 
0104              * devices via addDevice( const QString& ).
0105              *
0106              * \return List of all cd writer devices.
0107              */
0108             QList<Device*> cdWriter() const;
0109 
0110             /**
0111              * Before getting the devices do a @ref scanBus() or add 
0112              * devices via addDevice( const QString& ).
0113              *
0114              * \return List of all cd reader devices.
0115              */
0116             QList<Device*> cdReader() const;
0117 
0118             /**
0119              * Before getting the devices do a @ref scanBus() or add 
0120              * devices via addDevice( const QString& ).
0121              *
0122              * \return List of all DVD writer devices.
0123              */
0124             QList<Device*> dvdWriter() const;
0125 
0126             /**
0127              * Before getting the devices do a @ref scanBus() or add 
0128              * devices via addDevice( const QString& ).
0129              *
0130              * \return List of all DVD reader devices.
0131              */
0132             QList<Device*> dvdReader() const;
0133 
0134             /**
0135              * Before getting the devices do a @ref scanBus() or add 
0136              * devices via addDevice( const QString& ).
0137              *
0138              * \return List of all Blue Ray reader devices.
0139              */
0140             QList<Device*> blueRayReader() const;
0141 
0142             /**
0143              * Before getting the devices do a @ref scanBus() or add 
0144              * devices via addDevice( const QString& ).
0145              *
0146              * \return List of all Blue Ray writer devices.
0147              */
0148             QList<Device*> blueRayWriters() const;
0149 
0150             /**
0151              * Reads the device information from the config file.
0152              */
0153             virtual bool readConfig( const KConfigGroup& );
0154 
0155             virtual bool saveConfig( KConfigGroup );
0156 
0157 
0158         public Q_SLOTS:
0159             /**
0160              * Writes a list of all devices to stderr.
0161              */
0162             void printDevices();
0163 
0164             /**
0165              * Scan the system for devices. Call this to initialize all devices.
0166              *
0167              * \return Number of found devices.
0168              **/
0169             virtual int scanBus();
0170 
0171             /**
0172              * Clears the writers and readers list of devices.
0173              */
0174             virtual void clear();
0175 
0176         Q_SIGNALS:
0177             /**
0178              * Emitted if the device configuration changed, i.e. a device was added or removed.
0179              */
0180             void changed( K3b::Device::DeviceManager* );
0181             void changed();
0182 
0183             private Q_SLOTS:
0184             K3b::Device::Device* checkDevice( const Solid::Device& dev );
0185             void slotSolidDeviceAdded( const QString& );
0186             void slotSolidDeviceRemoved( const QString& );
0187 
0188         protected:
0189             /**
0190              * Add a new device.
0191              *
0192              * Called by scanBus()
0193              *
0194              * \return The device if it could be found or 0 otherwise.
0195              */
0196             virtual Device* addDevice( const Solid::Device& dev );
0197 
0198             /**
0199              * Remove a device from the device manager.
0200              */
0201             virtual void removeDevice( const Solid::Device& dev );
0202 
0203         private:
0204             class Private;
0205             Private* const d;
0206 
0207             /**
0208              * Add a device to the managers device lists and initialize the device.
0209              */
0210             Device *addDevice( Device* );
0211         };
0212     }
0213 }
0214 
0215 #endif