TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicruntimemanager.cpp
Go to the documentation of this file.
1 #include "musicruntimemanager.h"
2 #include "musicconfigmanager.h"
3 #include "musicsettingmanager.h"
4 #include "musicnetworkthread.h"
5 #include "musicqmmputils.h"
6 #include "ttkversion.h"
7 
8 #include <QFont>
9 #include <QApplication>
10 
11 namespace TTK
12 {
16  static quint64 directorySize(const QString &dirName);
20  static void checkCacheSize();
24  static QString languageCore(int index);
28  static QString languageQmmp(int index);
29 
30 }
31 
32 quint64 TTK::directorySize(const QString &dirName)
33 {
34  quint64 size = 0;
35  if(QFileInfo(dirName).isDir())
36  {
37  const QDir dir(dirName);
38  const QFileInfoList &fileList = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot);
39  for(const QFileInfo &fin : qAsConst(fileList))
40  {
41  if(fin.isDir())
42  {
43  size += directorySize(fin.absoluteFilePath());
44  }
45  else
46  {
47  size += fin.size();
48  }
49  }
50  }
51  return size;
52 }
53 
55 {
56  const bool disabled = G_SETTING_PTR->value(MusicSettingManager::DownloadCacheEnable).toInt();
57  if(!disabled)
58  {
59  return;
60  }
61 
62  const quint64 cacheSize = G_SETTING_PTR->value(MusicSettingManager::DownloadCacheSize).toInt() * TTK_SN_MB2B;
63  const QString &path = G_SETTING_PTR->value(MusicSettingManager::DownloadMusicDirPath).toString();
64  quint64 size = directorySize(path);
65  if(size > cacheSize)
66  {
67  const QFileInfoList &fileList = QDir(path).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
68  for(const QFileInfo &fin : qAsConst(fileList))
69  {
70  size -= fin.size();
71  QFile::remove(fin.absoluteFilePath());
72  if(size <= cacheSize)
73  {
74  break;
75  }
76  }
77  }
78 }
79 
80 QString TTK::languageCore(int index)
81 {
82  QString lan(LANGUAGE_DIR_FULL);
83  switch(index)
84  {
85  case 0: return lan.append("cn.ln");
86  case 1: return lan.append("tc.ln");
87  case 2: return lan.append("en.ln");
88  default: return {};
89  }
90 }
91 
92 QString TTK::languageQmmp(int index)
93 {
94  QString lan(LANGUAGE_DIR_FULL);
95  switch(index)
96  {
97  case 0: return lan.append("cnq.ln");
98  case 1: return lan.append("tcq.ln");
99  case 2: return lan.append("enq.ln");
100  default: return {};
101  }
102 }
103 
104 
106 {
107  TTK_INFO_STREAM("MusicApplication Run");
108  // read config
109  MusicConfigManager manager;
110  if(manager.fromFile(COFIG_PATH_FULL))
111  {
112  manager.readBuffer();
113  }
114 
116 
117 #ifdef Q_OS_WIN
118  bool status = true;
119  if(!QFile::exists(PLUGINS_DIR_FULL + "libeay32.dll") || !QFile::exists(PLUGINS_DIR_FULL + "ssleay32.dll"))
120  {
121  const QString &path = TTK::applicationPath();
122  status &= QFile::copy(path + "libeay32.dll", PLUGINS_DIR_FULL + "libeay32.dll");
123  status &= QFile::copy(path + "ssleay32.dll", PLUGINS_DIR_FULL + "ssleay32.dll");
124  }
125  TTK_INFO_STREAM("Install openssl library to plugin dir is" << (status ? "success" : "failed"));
126 #elif defined Q_OS_UNIX
127  QFont font;
128  font.setPixelSize(13);
129  qApp->setFont(font);
130 #endif
131 
132  //detect the current network state
133  G_NETWORK_PTR->start();
134 
136  G_NETWORK_PTR->setBlockNetwork(G_SETTING_PTR->value(MusicSettingManager::CloseNetWorkMode).toBool());
137 }
138 
140 {
141  const int index = G_SETTING_PTR->value(MusicSettingManager::LanguageIndex).toInt();
142  return {TTK::languageCore(index), TTK::languageQmmp(index)};
143 }
144 
146 {
148 }
static QString languageQmmp(int index)
bool fromFile(const QString &name)
static quint64 directorySize(const QString &dirName)
static QString languageCore(int index)
voidpf void uLong size
Definition: ioapi.h:136
The class of the xml config manager.
bool configVersionCheck() const noexcept
#define qAsConst
Definition: ttkqtglobal.h:57
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
The namespace of the application object.
Definition: ttkcompat.h:24
#define PLUGINS_DIR_FULL
Definition: musicobject.h:162
#define LANGUAGE_DIR_FULL
Definition: musicobject.h:163
TTK_MODULE_EXPORT void updateBaseConfig()
static void checkCacheSize()
#define COFIG_PATH_FULL
Definition: musicobject.h:152
#define G_NETWORK_PTR
#define TTK_SN_MB2B
Definition: ttkglobal.h:393
static QString applicationPath()
Definition: ttkqtobject.h:44
#define const
Definition: zconf.h:233
QStringList translator() const
#define TTK_CONFIG_VERSION_STR
Definition: ttkversion.h:176
#define G_SETTING_PTR