/*! * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, * IN PART OR IN WHOLE, * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file DriveWatcher.h * \date 12/31/2019 * \author Behrouz NematiPour * */ #pragma once // Qt #include // Project #include "main.h" #include "threads.h" // Define #define _DriveWatcher Storage::DriveWatcher::I() // forward diclations class tst_initializations; namespace Storage { /*! * \brief The DriveWatcher class * \details This class is to watch the USB device to be mounted if plugged in * or to be unmounted if user through UI requests it. * and will notify UI (user) on mounted and removed(No USB drive exists). */ class DriveWatcher : public QObject { Q_OBJECT // friends friend class ::tst_initializations; bool _mounted = false; bool _umounted = false; bool _removed = false; const char *_usbDrive = ""; const int _interval = 1000; // in ms QThread *_thread = nullptr; bool _init = false; // Singleton SINGLETON(DriveWatcher) public slots: bool init(); bool init(QThread &vThread); private slots: void quit(); protected: void timerEvent(QTimerEvent *) override; private: void initConnections(); void initThread(QThread &vThread); void quitThread(); bool usbSeek(QString &vDevice); bool driveSpaceCheck(const QString &vPath, qint64 &vTotalBytes, qint64 &vAvailableBytes); signals: /*! * \brief didUSBDriveMount * \details notifies UI when USB device is available and has been mounted. */ void didUSBDriveMount (); /*! * \brief didUSBDriveUmount * \details notifies USB watcher on UI(user) request for USB umount. */ void didUSBDriveUmount(); /*! * \brief didUSBDriveRemove * \details notifies UI when USB device has been removed(not exists). */ void didUSBDriveRemove(); /*! * \brief didSDCardFreeSpaceChange * \param vReady - Device is mounted and ready * \note if device ejected manually system assumes it's still ready. * \param vTotal - Returns the total volume size in bytes. * Returns -1 if QStorageInfo object is not valid * \param vAvailable - Returns the size (in bytes) available for the current user. * It returns the total size available if the user is the root user or a system administrator. * This size can be less than or equal to the free size returned by bytesFree() function. * Returns -1 if QStorageInfo object is not valid. * \param vPercent - The percentage of availabe spcae. * \note Will emitted if only one of the publishing paramter changes. */ void didSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent); private slots: // ----- usb void usbCheck(); bool usbMount (const QString &vDevice); bool usbUmount(const QString &vDevice); void usbRemove(); void usbError (const QString &vDevice); void onUSBDriveUmount(); // ----- sdcard void sdcardSpaceCheck(); }; }