TTKMusicPlayer  4.3.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(2 * 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  m_timer->setInterval(msec);
26 }
27 
29 {
30  Data *data = new Data;
31  data->m_type = type;
32  m_observer << data;
33 }
34 
36 {
37  Data *data = new Data;
38  data->m_type = type;
39  data->m_args << args;
40  m_observer << data;
41 }
42 
43 void TTKDispatchManager::dispatch(Module type, void *funcs)
44 {
45  Data *data = new Data;
46  data->m_type = type;
47  data->m_args << QVariant::fromValue<void*>(funcs);
48  m_observer << data;
49 }
50 
51 void TTKDispatchManager::dispatch(Module type, const QVariant &arg1)
52 {
53  Data *data = new Data;
54  data->m_type = type;
55  data->m_args << arg1;
56  m_observer << data;
57 }
58 
59 void TTKDispatchManager::dispatch(Module type, const QVariant &arg1, const QVariant &arg2)
60 {
61  Data *data = new Data;
62  data->m_type = type;
63  data->m_args << arg1 << arg2;
64  m_observer << data;
65 }
66 
67 void TTKDispatchManager::dispatch(Module type, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3)
68 {
69  Data *data = new Data;
70  data->m_type = type;
71  data->m_args << arg1 << arg2 << arg3;
72  m_observer << data;
73 }
74 
75 void TTKDispatchManager::dispatch(Module type, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4)
76 {
77  Data *data = new Data;
78  data->m_type = type;
79  data->m_args << arg1 << arg2 << arg3 << arg4;
80  m_observer << data;
81 }
82 
84 {
85  m_mutex.lock();
86  if(m_observer.isEmpty())
87  {
88  m_mutex.unlock();
89  return;
90  }
91 
92  Data *data = m_observer.takeLast();
93  bool state = true;
94  switch(data->m_type)
95  {
96  case Module::FileRemove:
97  {
98  if(!data->m_args.isEmpty())
99  {
100  const QString &path = data->m_args.first().toString();
101  state = path.isEmpty() ? false : QFile::remove(path);
102  }
103  break;
104  }
105  default: break;
106  }
107 
108  if(state)
109  {
110  delete data;
111  }
112  else
113  {
114  data->m_times++;
115  if(data->isValid())
116  {
117  m_observer << data;
118  }
119  else
120  {
121  delete data;
122  }
123  }
124  m_mutex.unlock();
125 }
void dispatch(Module type)
QList< Data * > m_observer
void setInterval(int msec)
QList< QVariant > TTKVariantList
Definition: ttkqtglobal.h:201
#define TTK_DN_S2MS
Definition: ttkglobal.h:355
bool isValid() const noexcept
TTKDispatchManager::Module m_type
state
Definition: http_parser.c:279