TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicservicemain.cpp
Go to the documentation of this file.
1 #include "ttkapplication.h"
2 #include "musicapplication.h"
3 #include "musicruntimemanager.h"
4 #include "musicconfigmodule.h"
5 #include "musicprocessmanager.h"
6 #include "ttkinitialization.h"
7 #include "ttkprocess.h"
8 
9 #ifdef Q_OS_LINUX
10 # include "musicmprisplayer.h"
11 #endif
12 
13 #include <QTranslator>
14 
15 static void cleanupCache()
16 {
17  QFile::remove(TTK_COLOR_FILE);
18  QFile::remove(TTK_IMAGE_FILE);
19  QFile::remove(TTK_RECORD_FILE);
20  QFile::remove(TTK_RECORD_DATA_FILE);
21 
23  QStringList process;
24  process << MAKE_TRANSFORM_NAME
26  << MAKE_GAIN_NAME;
27  TTK::killProcessByName(process);
28  TTK_INFO_STREAM("Application cache cleanup");
29 }
30 
31 
32 int main(int argc, char *argv[])
33 {
35 
36 #ifndef Q_OS_LINUX
37  TTKApplication app(argc, argv);
38 #else
39  // Fixes this: https://bugreports.qt.io/browse/QTBUG-96214
40  constexpr const char *WEB_SECURITY = "--disable-web-security";
41  constexpr const char *SECCOMP_SECURITY = "--disable-seccomp-filter-sandbox";
42  std::vector<char*> newArgv(argv, argv + argc);
43  newArgv.push_back(const_cast<char*>(WEB_SECURITY));
44  newArgv.push_back(const_cast<char*>(SECCOMP_SECURITY));
45  newArgv.push_back(nullptr);
46  int newArgc = argc + 2;
47  TTKApplication app(newArgc, newArgv.data());
48 #endif
50 
51  // parse command line args
52  QStringList args;
53  for(int i = 0; i < argc; ++i)
54  {
55  const QString &arg = QString::fromLocal8Bit(argv[i]);
56  if(ttk.argumentValid(arg))
57  {
58  args << arg;
59  }
60  }
61 
62  ttk.execute(args);
63 
64  if(app.isRunning())
65  {
66  MusicProcessClient client;
67  client.execute(args);
68 
69  TTK_INFO_STREAM("One app has already run");
70  return EXIT_FAILURE;
71  }
72 
74  config.execute();
75 
76  MusicRunTimeManager manager;
77  manager.execute();
78 
79  ttk.generateFont();
80  ttk.codecForLocale();
81 
82  if(!manager.configVersionCheck())
83  {
84  config.reset();
85  }
86 
87  for(const QString &ts : manager.translator())
88  {
89  QTranslator *translator = new QTranslator(&app);
90  if(!translator->load(ts))
91  {
92  TTK_ERROR_STREAM("Load translation error: " << ts);
93  delete translator;
94  continue;
95  }
96  app.installTranslator(translator);
97  }
98 
100  w.show();
101 
102  MusicProcessServer server;
103  server.execute(args);
104 
105 #ifdef Q_OS_LINUX
106  // unix mpris module
107  MusicMPRISPlayer mpris;
108  mpris.execute();
109 #endif
110  return app.exec();
111 }
The class of the process client.
The class of the process server.
struct config_s config
void execute(const QStringList &args) const
bool isRunning() const
The class of the app main widget.
TTK_MODULE_EXPORT void killProcessByName(const QString &process, bool more=false)
#define MAKE_PLAYER_NAME
Definition: musicobject.h:114
int main(int argc, char *argv[])
The class of the ttk initialization.
The class of the initialize module.
bool configVersionCheck() const noexcept
The class of the ttk application.
#define TTK_IMAGE_FILE
#define TTK_RECORD_DATA_FILE
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
#define MAKE_TRANSFORM_NAME
Definition: musicobject.h:113
#define TTK_RECORD_FILE
#define TTK_COLOR_FILE
The class of the app run time manager.
TTK_MODULE_EXPORT void initialize(TTK::Attribute attr)
#define MAKE_GAIN_NAME
Definition: musicobject.h:115
static void cleanupCache()
void execute(const QStringList &args) const
QStringList translator() const
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:76
The class of the app mpris main widget.