TTKMusicPlayer  4.1.3.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 "ttkdumper.h"
7 #include "ttkglobalwrapper.h"
8 #include "ttkplatformsystem.h"
9 
10 #ifdef Q_OS_UNIX
11 # include <malloc.h>
12 # include "musicmprisplayer.h"
13 #endif
14 
15 #include <QTranslator>
16 
17 static void cleanupCache()
18 {
19  QFile::remove(TTK_COLOR_FILE);
20  QFile::remove(TTK_IMAGE_FILE);
21  QFile::remove(TTK_RECORD_FILE);
22  QFile::remove(TTK_RECORD_DATA_FILE);
23 
25  QStringList process;
26  process << MAKE_TRANSFORM_NAME
28  << MAKE_GAIN_NAME;
29  TTK::killProcessByName(process);
30  TTK_INFO_STREAM("Application cache cleanup");
31 }
32 
34 {
35 #if TTK_QT_VERSION_CHECK(6,0,0)
36  // do nothing
37 #elif TTK_QT_VERSION_CHECK(5,4,0)
38 # if TTK_QT_VERSION_CHECK(5,12,0)
39  QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
40  QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
41 # if TTK_QT_VERSION_CHECK(5,14,0)
42  QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
43 # endif
44 # elif TTK_QT_VERSION_CHECK(5,6,0)
45  const float dpi = TTKPlatformSystem::logicalDotsPerInch() / 96.0;
46  qputenv("QT_SCALE_FACTOR", QByteArray::number(dpi < 1.0 ? 1.0 : dpi));
47 # endif
48 #endif
49 }
50 
51 int main(int argc, char *argv[])
52 {
54 
55  TTKApplication app(argc, argv);
56 
57  QCoreApplication::setOrganizationName(TTK_APP_NAME);
58  QCoreApplication::setOrganizationDomain(TTK_APP_COME_NAME);
59  QCoreApplication::setApplicationName(TTK_APP_NAME);
60 
61  // parse command line args
62  QStringList args;
63  for(int i = 0; i < argc; ++i)
64  {
65  const QString &&arg = QString::fromLocal8Bit(argv[i]);
66  if(!arg.endsWith(TTK_APP_NAME) && !arg.endsWith(TTK_SERVICE_NAME) && !arg.endsWith(TTK_APP_RUN_NAME) && !arg.endsWith(TTK_SERVICE_RUN_NAME))
67  {
68  args << arg;
69  }
70  }
71 
72  if(app.isRunning())
73  {
74  MusicProcessClient client;
75  client.run(args);
76 
77  TTK_INFO_STREAM("One app has already run");
78  return -1;
79  }
80 
82  config.valid();
83 
84  TTKDumper dumper(std::bind(cleanupCache));
85  dumper.run();
86 
87  MusicRunTimeManager manager;
88  manager.run();
89 
90  if(!manager.configVersionCheck())
91  {
92  config.reset();
93  }
94 
95  for(const QString &ts : manager.translator())
96  {
97  QTranslator *translator = new QTranslator(&app);
98  if(!translator->load(ts))
99  {
100  TTK_ERROR_STREAM("Load translation error: " << ts);
101  delete translator;
102  continue;
103  }
104  app.installTranslator(translator);
105  }
106 
108 
110  w.show();
111 
112  MusicProcessServer server;
113  server.run(args);
114 
115 #ifdef Q_OS_UNIX
116  // unix mpris module
117  MusicMPRISPlayer mpris;
118  mpris.run();
119 #endif
120 
121 #ifdef Q_OS_UNIX
122  // memory free
123  mallopt(M_MMAP_THRESHOLD, 1024 * 1024); // 1MB mmap
124  mallopt(M_TRIM_THRESHOLD, 2 * 1024 * 1024); // 2MB brk
125 #endif
126  return app.exec();
127 }
The class of the process client.
The class of the process server.
struct config_s config
The class of the ttk dumper.
Definition: ttkdumper.h:39
void run(const QStringList &args) const
#define TTK_APP_NAME
Definition: ttkobject.h:25
bool isRunning() const
The class of the app main widget.
void run(const QStringList &args) const
#define MAKE_PLAYER_NAME
Definition: musicobject.h:101
int main(int argc, char *argv[])
TTK_MODULE_EXPORT void setApplicationFont()
The class of the initialize module.
The class of the ttk application.
#define TTK_IMAGE_FILE
#define TTK_RECORD_DATA_FILE
#define TTK_APP_COME_NAME
Definition: ttkobject.h:26
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:68
#define MAKE_TRANSFORM_NAME
Definition: musicobject.h:100
static int logicalDotsPerInch()
#define TTK_RECORD_FILE
#define TTK_COLOR_FILE
The class of the app run time needed.
#define MAKE_GAIN_NAME
Definition: musicobject.h:102
bool configVersionCheck() const
#define TTK_SERVICE_NAME
Definition: ttkobject.h:24
static void cleanupCache()
TTK_MODULE_EXPORT void killProcessByName(const QString &process)
static void loadApplicationScaleFactor()
#define TTK_SERVICE_RUN_NAME
Definition: ttkobject.h:35
#define TTK_APP_RUN_NAME
Definition: ttkobject.h:34
QStringList translator() const
void run()
Definition: ttkdumper.cpp:227
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:70
The class of the app mpris main widget.