TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicprocessmanager.cpp
Go to the documentation of this file.
1 #include "musicprocessmanager.h"
2 #include "musicapplication.h"
3 #include "ttkcommandline.h"
4 
5 #include <QUrl>
6 
7 #define MEMORY_SIZE 512 * TTK_SN_KB2B
8 #define MEMORY_KEY TTK_STR_CAT(TTK_AUTHOR_NAME, TTK_DEFAULT_STR, TTK_APP_NAME)
9 
10 void MusicProcessClient::execute(const QStringList &args) const
11 {
12  QSharedMemory client;
13  client.setKey(MEMORY_KEY);
14  client.attach();
15 
16  if(client.size() <= 0)
17  {
18  return;
19  }
20 
21  client.lock();
22  const QByteArray &data = QUrl::toPercentEncoding(args.join(TTK_SPLITER));
23  memcpy(client.data(), data.constData(), data.length());
24  client.unlock();
25  client.detach();
26 }
27 
28 
30  : QObject(parent)
31 {
32  m_timer.setInterval(TTK_DN_S2MS);
33  connect(&m_timer, SIGNAL(timeout()), SLOT(timeout()));
34 
35  m_memory.setKey(MEMORY_KEY);
36  if(m_memory.isAttached())
37  {
38  m_memory.detach();
39  }
40 
41  m_memory.create(MEMORY_SIZE);
42  m_timer.start();
43 }
44 
46 {
47  m_timer.stop();
48  m_memory.detach();
49 }
50 
51 void MusicProcessServer::execute(const QStringList &args) const
52 {
53  if(args.isEmpty())
54  {
55  return;
56  }
57 
58  TTK_INFO_STREAM("Args: " << args);
59 
60  TTKCommandLineOption op0("-h", "--help", "Show command line help options");
61  TTKCommandLineOption op1("-List", "--file-to-list", "Add file to playlist");
62  TTKCommandLineOption op2("-Open", "--file-to-list-play", "Add file to playlist and play it");
63 // TTKCommandLineOption op3("-p", "--play", "Pause if playing, play otherwise");
64 // TTKCommandLineOption op4("-s", "--stop", "Stop current song");
65 // TTKCommandLineOption op5("--next", "Start playing next song");
66 // TTKCommandLineOption op6("--previous", "Start playing previous song");
67 // TTKCommandLineOption op7("--toggle-mute", "Mute/Restore volume");
68 // TTKCommandLineOption op8("--volume", "Set playback volume (example: --volume 20)");
69 // TTKCommandLineOption op9("--add-file", "Display add file dialog");
70 // TTKCommandLineOption op10("--add-dir", "Display add directory dialog");
71 // TTKCommandLineOption op11("--add-url", "Display add url path dialog");
72 
73  TTKCommandLineParser parser;
74  parser.addOption(op0);
75  parser.addOption(op1);
76  parser.addOption(op2);
77  parser.process(args);
78 
79  if(parser.isSet(op0))
80  {
81  parser.showHelp();
82  return;
83  }
84 
85  if(parser.isSet(op1))
86  {
88  }
89  else if(parser.isSet(op2))
90  {
92  }
93  else if(args.count() == 1)
94  {
95  const QString &url = args.first();
96  if(url.startsWith('-'))
97  {
98  return;
99  }
100 
101  // for direct play url
103  }
104 }
105 
107 {
108  const QByteArray &buffer = QByteArray((char*)m_memory.data());
109  if(buffer.isEmpty())
110  {
111  return;
112  }
113 
114  m_memory.lock();
115  memset(m_memory.data(), 0, MEMORY_SIZE);
116  m_memory.unlock();
117 
118  execute(QUrl::fromPercentEncoding(buffer).split(TTK_SPLITER));
119 }
static MusicApplication * instance()
QString value(const TTKCommandLineOption &option) const
void execute(const QStringList &args) const
#define TTK_SPLITER
Definition: ttkglobal.h:275
The class of the command line option.
bool isSet(const TTKCommandLineOption &option) const
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
#define MEMORY_KEY
bool addOption(const TTKCommandLineOption &option)
TTK_MODULE_EXPORT QStringList split(const QString &value, const QString &key=TTK_DEFAULT_STR)
void importSongsByOutside(const QString &path, bool play)
#define TTK_DN_S2MS
Definition: ttkglobal.h:355
#define MEMORY_SIZE
void execute(const QStringList &args) const
void showHelp() const
MusicProcessServer(QObject *parent=nullptr)
The class of the command line parser.