File indexing completed on 2024-04-28 08:54:23

0001 /*
0002     Provides an interface to the computer's hardware
0003 
0004     SPDX-FileCopyrightText: 2015-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef SMB4KHARDWAREINTERFACE_H
0009 #define SMB4KHARDWAREINTERFACE_H
0010 
0011 // application specific includes
0012 #include "smb4kglobal.h"
0013 
0014 // Qt includes
0015 #include <QObject>
0016 #include <QScopedPointer>
0017 #include <QUrl>
0018 
0019 class Smb4KHardwareInterfacePrivate;
0020 
0021 /**
0022  * This class provides an interface to the computer's hardware.
0023  * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0024  * @since 2.0.0
0025  */
0026 
0027 class Q_DECL_EXPORT Smb4KHardwareInterface : public QObject
0028 {
0029     Q_OBJECT
0030 
0031     friend class Smb4KHardwareInterfacePrivate;
0032 
0033 public:
0034     /**
0035      * The constructor
0036      */
0037     explicit Smb4KHardwareInterface(QObject *parent = nullptr);
0038 
0039     /**
0040      * The destructor
0041      */
0042     ~Smb4KHardwareInterface();
0043 
0044     /**
0045      * The static pointer to this class.
0046      * @returns a static pointer to this class
0047      */
0048     static Smb4KHardwareInterface *self();
0049 
0050     /**
0051      * This function returns TRUE if the system is online and FALSE otherwise.
0052      * @returns TRUE if the system is online.
0053      */
0054     bool isOnline() const;
0055 
0056     /**
0057      * Inhibit shutdown and sleep.
0058      */
0059     void inhibit();
0060 
0061     /**
0062      * Uninhibit shutdown and sleep.
0063      */
0064     void uninhibit();
0065 
0066 protected:
0067     /**
0068      * Reimplemented from QObject to check the online state and to check
0069      * for mounts and unmounts on operating systems that are not fully
0070      * supported by Solid, yet.
0071      */
0072     void timerEvent(QTimerEvent *event) override;
0073 
0074 Q_SIGNALS:
0075     /**
0076      * This signal is emitted when a network share is added to the system
0077      */
0078     void networkShareAdded();
0079 
0080     /**
0081      * This signal is emitted when a network share is removed from the system
0082      */
0083     void networkShareRemoved();
0084 
0085     /**
0086      * This signal is emitted when the online state changed.
0087      */
0088     void onlineStateChanged(bool online);
0089 
0090 protected Q_SLOTS:
0091     /**
0092      * This slot is called when a device was added to the system.
0093      * @param udi     the device UDI
0094      */
0095     void slotDeviceAdded(const QString &udi);
0096 
0097     /**
0098      * This slot is called when a device was removed from the system.
0099      * @param udi     the device UDI
0100      */
0101     void slotDeviceRemoved(const QString &udi);
0102 
0103 private:
0104     /**
0105      * Check the online state and emit the @see onlineStateChanged() accordingly, if
0106      * @p emitSignal is set to TRUE.
0107      */
0108     void checkOnlineState(bool emitSignal = true);
0109 
0110     /**
0111      * Pointer to private class
0112      */
0113     QScopedPointer<Smb4KHardwareInterfacePrivate> d;
0114 };
0115 
0116 #endif