TTKMusicPlayer  3.7.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 "musicconfigobject.h"
5 #include "musicprocessmanager.h"
6 #include "ttkdumper.h"
7 #include "ttkglobalhelper.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  TTKPlatformSystem platform;
46  const float dpi = platform.logicalDotsPerInch() / 96.0;
47  qputenv("QT_SCALE_FACTOR", QByteArray::number(dpi < 1.0 ? 1.0 : dpi));
48 # endif
49 #endif
50 }
51 
52 int main(int argc, char *argv[])
53 {
55 
56  TTKApplication app(argc, argv);
57 
58  QCoreApplication::setOrganizationName(TTK_APP_NAME);
59  QCoreApplication::setOrganizationDomain(TTK_APP_COME_NAME);
60  QCoreApplication::setApplicationName(TTK_APP_NAME);
61 
62  // parse command line args
63  QStringList args;
64  for(int i = 0; i < argc; ++i)
65  {
66  const QString &&arg = QString::fromLocal8Bit(argv[i]);
67  if(!arg.endsWith(TTK_APP_NAME) && !arg.endsWith(TTK_SERVICE_NAME) && !arg.endsWith(TTK_APP_RUN_NAME) && !arg.endsWith(TTK_SERVICE_RUN_NAME))
68  {
69  args << arg;
70  }
71  }
72 
73  if(app.isRunning())
74  {
75  MusicProcessClient client;
76  client.run(args);
77 
78  TTK_INFO_STREAM("One app has already run");
79  return -1;
80  }
81 
83  config.valid();
84 
85  TTKDumper dumper(std::bind(cleanupCache));
86  dumper.run();
87 
88  MusicRunTimeManager manager;
89  manager.run();
90 
91  if(!manager.configVersionCheck())
92  {
93  config.reset();
94  }
95 
96  for(const QString &ts : manager.translator())
97  {
98  QTranslator *translator = new QTranslator(&app);
99  if(!translator->load(ts))
100  {
101  TTK_ERROR_STREAM("Load translation error: " << ts);
102  delete translator;
103  continue;
104  }
105  app.installTranslator(translator);
106  }
107 
109 
111  w.show();
112 
113  MusicProcessServer server;
114  server.run(args);
115 
116 #ifdef Q_OS_UNIX
117  // unix mpris module
118  MusicMPRISPlayer mpris;
119  mpris.run();
120 #endif
121 
122 #ifdef Q_OS_UNIX
123  // memory free
124  mallopt(M_MMAP_THRESHOLD, 1024 * 1024); // 1MB mmap
125  mallopt(M_TRIM_THRESHOLD, 2 * 1024 * 1024); // 2MB brk
126 #endif
127  return app.exec();
128 }
The class of the process client.
The class of the process server.
int logicalDotsPerInch() const
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:99
int main(int argc, char *argv[])
TTK_MODULE_EXPORT void setApplicationFont()
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:67
#define MAKE_TRANSFORM_NAME
Definition: musicobject.h:98
The class of the platform system.
#define TTK_RECORD_FILE
#define TTK_COLOR_FILE
The class of the app run time needed.
The class of the music initialize object.
#define MAKE_GAIN_NAME
Definition: musicobject.h:100
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:232
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:69
The class of the app mpris main widget.