NDEVR
API Documentation
DeviceWatcher.h
1#pragma once
2#include "DLLInfo.h"
3#include <QtCore/QEvent>
4#include <QtCore/QObject>
5namespace NDEVR
6{
7 class DeviceWatcherPrivate;
11 class NDEVR_WIDGETS_API DeviceWatcher : public QObject
12 {
13 Q_OBJECT
14 Q_DECLARE_PRIVATE(DeviceWatcher)
15 public:
20 explicit DeviceWatcher(QObject* parent = 0);
22
27 bool start();
32 bool stop();
37 bool isRunning() const;
38
43 void appendEventReceiver(QObject* receiver);
49 signals:
54 void deviceAdded(const QString& dev);
59 void deviceChanged(const QString& dev);
64 void deviceRemoved(const QString& dev);
65
66 protected:
67 bool running;
68 DeviceWatcherPrivate* d_ptr;
69 };
70
74 class NDEVR_WIDGETS_API QDeviceChangeEvent : public QEvent
75 {
76 public:
80 enum Action
81 {
85 };
86 //static const Type EventType; //VC link error
87
93 explicit QDeviceChangeEvent(Action action, const QString& device);
94
99 Action action() const { return m_action; }
104 QString device() const { return m_device; }
109 static Type registeredType()
110 {
111 static Type EventType = static_cast<Type>(registerEventType());
112 return EventType;
113 }
114
115 private:
116 Action m_action;
117 QString m_device;
118 };
119}
bool isRunning() const
Checks whether the watcher is currently monitoring for device changes.
DeviceWatcher(QObject *parent=0)
Constructs a DeviceWatcher with the given parent object.
void deviceAdded(const QString &dev)
Emitted when a new device is added to the system.
void appendEventReceiver(QObject *receiver)
Appends an additional event receiver that will be notified of device change events.
bool start()
Starts watching for device changes.
void deviceChanged(const QString &dev)
Emitted when a device state changes, such as when unmounting.
static DeviceWatcher & DefaultWatcher()
Returns the singleton default DeviceWatcher instance.
bool running
Whether the watcher is currently active.
bool stop()
Stops watching for device changes.
DeviceWatcherPrivate * d_ptr
Private implementation pointer for platform-specific watching logic.
void deviceRemoved(const QString &dev)
Emitted when a device is removed from the system.
Action
Enumerates the possible device change actions.
@ Remove
A device was removed.
@ Change
A device state changed (e.g., unmounting).
@ Add
A device was added.
static Type registeredType()
Returns the registered QEvent type for device change events.
QString device() const
Returns the device identifier associated with this event.
Action action() const
Returns the action type of this device change event.
QDeviceChangeEvent(Action action, const QString &device)
Constructs a device change event with the given action and device identifier.
The primary namespace for the NDEVR SDK.