TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttkdispatchmanager.cpp
Go to the documentation of this file.
1 #include "ttkdispatchmanager.h"
2 
3 #include <QFile>
4 #include <QTimer>
5 
7  : QObject(nullptr)
8 {
9  m_timer = new QTimer(this);
10  m_timer->setInterval(5 * TTK_DN_S2MS);
11 
12  connect(m_timer, SIGNAL(timeout()), SLOT(activeFunctions()));
13  m_timer->start();
14 }
15 
17 {
18  m_timer->stop();
19  delete m_timer;
20  qDeleteAll(m_observer);
21 }
22 
24 {
25  TTKDispatchItem *item = new TTKDispatchItem;
26  item->m_type = type;
27  m_observer << item;
28 }
29 
31 {
32  TTKDispatchItem *item = new TTKDispatchItem;
33  item->m_type = type;
34  item->m_args << args;
35  m_observer << item;
36 }
37 
38 void TTKDispatchManager::dispatch(Module type, void *funcs)
39 {
40  TTKDispatchItem *item = new TTKDispatchItem;
41  item->m_type = type;
42  item->m_args << QVariant::fromValue<void*>(funcs);
43  m_observer << item;
44 }
45 
46 void TTKDispatchManager::dispatch(Module type, const QVariant &arg1)
47 {
48  TTKDispatchItem *item = new TTKDispatchItem;
49  item->m_type = type;
50  item->m_args << arg1;
51  m_observer << item;
52 }
53 
54 void TTKDispatchManager::dispatch(Module type, const QVariant &arg1, const QVariant &arg2)
55 {
56  TTKDispatchItem *item = new TTKDispatchItem;
57  item->m_type = type;
58  item->m_args << arg1 << arg2;
59  m_observer << item;
60 }
61 
62 void TTKDispatchManager::dispatch(Module type, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3)
63 {
64  TTKDispatchItem *item = new TTKDispatchItem;
65  item->m_type = type;
66  item->m_args << arg1 << arg2 << arg3;
67  m_observer << item;
68 }
69 
70 void TTKDispatchManager::dispatch(Module type, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4)
71 {
72  TTKDispatchItem *item = new TTKDispatchItem;
73  item->m_type = type;
74  item->m_args << arg1 << arg2 << arg3 << arg4;
75  m_observer << item;
76 }
77 
79 {
80  m_mutex.lock();
81  if(m_observer.isEmpty())
82  {
83  m_mutex.unlock();
84  return;
85  }
86 
87  TTKDispatchItem *item = m_observer.takeLast();
88  bool state = true;
89  switch(item->m_type)
90  {
91  case Module::FileRemove:
92  {
93  if(!item->m_args.isEmpty())
94  {
95  state = QFile::remove(item->m_args.front().toString());
96  }
97  break;
98  }
99  default: break;
100  }
101 
102  if(state)
103  {
104  delete item;
105  }
106  else
107  {
108  item->m_times++;
109  if(item->isValid())
110  {
111  m_observer << item;
112  }
113  }
114  m_mutex.unlock();
115 }
void dispatch(Module type)
QList< TTKDispatchItem * > m_observer
TTKDispatchManager::Module m_type
QList< QVariant > TTKVariantList
Definition: ttkqtglobal.h:189
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
state
Definition: http_parser.c:279