TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
qdevicewatcher.cpp
Go to the documentation of this file.
1 #include "qdevicewatcher.h"
2 #include "qdevicewatcher_p.h"
3 
5  : QObject(parent),
6  running(false),
7  d_ptr(new QDeviceWatcherPrivate)
8 {
9  Q_D(QDeviceWatcher);
10  d->setWatcher(this);
11 }
12 
14 {
15  if (d_ptr) {
16  delete d_ptr;
17  d_ptr = nullptr;
18  }
19 }
20 
22 {
23  Q_D(QDeviceWatcher);
24  if (!d->start()) {
25  stop();
26  running = false;
27  }
28  running = true;
29  return running;
30 }
31 
33 {
34  Q_D(QDeviceWatcher);
35  running = !d->stop();
36  return !running;
37 }
38 
40 {
41  return running;
42 }
43 
44 void QDeviceWatcher::appendEventReceiver(QObject *receiver)
45 {
46  Q_D(QDeviceWatcher);
47  d->event_receivers.append(receiver);
48 }
49 
51 {
52  if (!QMetaObject::invokeMethod(watcher, "deviceAdded", Q_ARG(QString, dev)))
53  qWarning("invoke deviceAdded failed");
54 
55  QMetaObject::invokeMethod(watcher, "deviceChanged", Q_ARG(bool, true));
56 }
57 
59 {
60  if (!QMetaObject::invokeMethod(watcher, "deviceChanged", Q_ARG(QString, dev)))
61  qWarning("invoke deviceChanged failed");
62 }
63 
65 {
66  if (!QMetaObject::invokeMethod(watcher, "deviceRemoved", Q_ARG(QString, dev)))
67  qWarning("invoke deviceRemoved failed");
68 
69  QMetaObject::invokeMethod(watcher, "deviceChanged", Q_ARG(bool, false));
70 }
71 
72 void QDeviceWatcherPrivate::emitDeviceAction(const QString &dev, const QString &action)
73 {
74  QString a(action.toLower());
75  if (a == QLatin1String("add"))
76  emitDeviceAdded(dev);
77  else if (a == QLatin1String("remove"))
78  emitDeviceRemoved(dev);
79  else if (a == QLatin1String("change"))
80  emitDeviceChanged(dev);
81 }
82 
83 QDeviceChangeEvent::QDeviceChangeEvent(Action action, const QString &device) :
84  QEvent(registeredType())
85 {
86  m_action = action;
87  m_device = device;
88 }
void emitDeviceAdded(const QString &dev)
bool isRunning() const
The class of the device watcher.
QDeviceWatcher(QObject *parent=nullptr)
void emitDeviceChanged(const QString &dev)
void emitDeviceAction(const QString &dev, const QString &action)
QDeviceWatcherPrivate * d_ptr
void appendEventReceiver(QObject *receiver)
void emitDeviceRemoved(const QString &dev)
The class of the device watcher private.
QDeviceWatcher * watcher
Action action() const
QDeviceChangeEvent(Action action, const QString &device)
QString device() const