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_p.h
Go to the documentation of this file.
1 #ifndef QDEVICEWATCHER_P_H
2 #define QDEVICEWATCHER_P_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Music Player project
6  * Copyright (C) 2015 - 2024 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17 
18  * You should have received a copy of the GNU General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include <QtCore/qglobal.h>
23 #define CONFIG_SOCKETNOTIFIER 1
24 #define CONFIG_TCPSOCKET 0 //QtNetwork
25 
26 #if defined(Q_OS_WINCE)
27 # define CONFIG_THREAD 1
28 #elif defined(Q_OS_LINUX)
29 # define CONFIG_THREAD (!CONFIG_SOCKETNOTIFIER && !CONFIG_TCPSOCKET)
30 #elif defined Q_OS_MAC //OSX or MACX
31 # define CONFIG_THREAD 1
32 # include <DiskArbitration/DiskArbitration.h>
33 #else
34 # define CONFIG_THREAD 0
35 #endif
36 
37 #ifdef Q_OS_WIN
38 # define WIN32_LEAN_AND_MEAN
39 # include <qt_windows.h>
40 #else
41 # include <QtCore/QBuffer>
42 #endif //Q_OS_WIN
43 #include <QtCore/QList>
44 #include <QtCore/QThread>
45 #include "ttkprivate.h"
46 
47 class QDeviceWatcher;
48 
53 #if CONFIG_THREAD
54  : public QThread
55 #else
56  : public QObject
57 #endif //CONFIG_THREAD
58 {
59  Q_OBJECT
60 public:
61  QDeviceWatcherPrivate(QObject *parent = nullptr) :
62 #if CONFIG_THREAD
63  QThread(parent)
64 #else
65  QObject(parent)
66 #endif //CONFIG_THREAD
67  {
68  //initialize();
69  }
71 
72  void setWatcher(QDeviceWatcher *w) {watcher=w;}
73  bool start(); //conflict with QThread::start()
74  bool stop();
75 
76  //Do not use Qt::DirectConnection. this thread is not watcher's thread!
77  void emitDeviceAdded(const QString& dev);
78  void emitDeviceChanged(const QString& dev); //Linux: when umounting the device
79  void emitDeviceRemoved(const QString& dev);
80  void emitDeviceAction(const QString& dev, const QString& action);
81 
82  QObjectList event_receivers;
83 
84 private Q_SLOTS:
85  void parseDeviceInfo();
86 
87 private:
89 
90  bool initialize();
91 #if CONFIG_THREAD
92  virtual void run();
93 #endif //CONFIG_THREAD
94 #if defined(Q_OS_LINUX)
95  QBuffer buffer;
96  void parseLine(const QByteArray &line);
97 # if CONFIG_TCPSOCKET
98  class QTcpSocket *tcp_socket;
99 # elif CONFIG_SOCKETNOTIFIER
100  class QSocketNotifier *socket_notifier;
101 # endif
102 
103  QString bus_name;
104  int netlink_socket;
105 #elif defined(Q_OS_WIN32)
106  HWND hwnd;
107 #elif defined(Q_OS_WINCE)
108  HANDLE mQueueHandle;
109  HANDLE mNotificationHandle;
110 #endif
111 #ifdef Q_OS_MAC
112  volatile bool mStop;
113  DASessionRef mSession;
114 #endif //Q_OS_MAC
115 };
116 
117 #endif // QDEVICEWATCHER_P_H
#define TTK_MODULE_EXPORT
The class of the device watcher.
#define CONFIG_THREAD
QDeviceWatcherPrivate(QObject *parent=nullptr)
The class of the device watcher private.
QDeviceWatcher * watcher
void setWatcher(QDeviceWatcher *w)