TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicapplicationmodule.cpp
Go to the documentation of this file.
4 #include "musictimerwidget.h"
5 #include "musicspectrumwidget.h"
6 #include "musictimerautomodule.h"
7 #include "musicbackupmodule.h"
8 #include "musicmessagebox.h"
9 #include "musictoastlabel.h"
10 #include "musicequalizerdialog.h"
11 #include "musicplatformmanager.h"
15 #include "musicapplication.h"
16 #include "musictopareawidget.h"
17 #include "musicimageutils.h"
18 #include "musicgiflabelwidget.h"
19 #include "musicfileutils.h"
20 #include "musicresourcerequest.h"
21 #include "musicpvcounterrequest.h"
23 #include "musicscreensaverwidget.h"
24 #include "musicplatformmanager.h"
25 #include "ttklibrary.h"
26 #include "ttkconcurrent.h"
27 #include "ttkdesktopwrapper.h"
28 #include "ttkfileassociation.h"
29 #include "ttkplatformsystem.h"
30 
31 #include "qdevicewatcher.h"
32 #include "qsync/qsyncconfig.h"
33 
34 static constexpr int MARGIN_SIDE = 10;
35 static constexpr const char *SYNC_HOST_URL = "VDVnYUdYMW9xNnVWSnd6L0J6NHI2MFZ5d0R3R2NiRVF4VW5WckpNcUhnUT0=";
36 
38 
40  : QObject(parent),
41  m_setWindowToTop(false),
42  m_direction(TTK::Direction::No),
43  m_mobileDeviceWidget(nullptr),
44  m_quitContainer(nullptr),
45  m_screenSaverWidget(nullptr)
46 {
47  m_instance = this;
48 
50 
51  m_quitAnimation = new QPropertyAnimation(this);
52  m_sideAnimation = new QPropertyAnimation(parent, "pos", this);
53  m_quitAnimation->setTargetObject(parent);
54  m_sideAnimation->setDuration(250);
55 
58 
59  m_deviceWatcher = new QDeviceWatcher(this);
60  connect(m_deviceWatcher, SIGNAL(deviceChanged(bool)), SLOT(deviceChanged(bool)));
61  connect(m_deviceWatcher, SIGNAL(deviceAdded(QString)), SLOT(deviceNameChanged(QString)));
64 
68 
70 
71 #ifdef Q_OS_WIN
72  MusicPlatformManager manager;
73  const int version = manager.windowsIEVersion();
74  if(version == -1 || version < 8)
75  {
76  MusicToastLabel::popup(version == -1 ? QObject::tr("No ie core version detected") : QObject::tr("IE core version less than 8"));
77  }
78 #endif
79 }
80 
82 {
83  Q_CLEANUP_RESOURCE(MusicPlayer);
84 
85  delete m_backupModule;
86  delete m_timerAutoModule;
87  delete m_screenSaverWidget;
88  delete m_quitAnimation;
89  delete m_sideAnimation;
90  delete m_deviceWatcher;
91  delete m_mobileDeviceWidget;
92  delete m_quitContainer;
93  delete m_resourceRequest;
94  delete m_counterRequest;
95  delete m_sourceUpdateRequest;
96 }
97 
99 {
100  return m_instance;
101 }
102 
104 {
106  {
109  const QRect &rect = TTKDesktopWrapper::screenGeometry();
110  w->move((rect.width() - w->width()) / 2, w->y());
111  }
112 }
113 
115 {
117 }
118 
120 {
121 #ifndef QT_NO_SSL
122  // ssl support check
123  TTK_INFO_STREAM("Application network support ssl:" << (QSslSocket::supportsSsl() ? "true" : "false"));
124 #endif
125  // sync host init
127  //
131 }
132 
134 {
136 
138  {
141  w->setMinimumSize(0, 0);
142 
143  m_quitAnimation->stop();
144  m_quitAnimation->setPropertyName("geometry");
145  m_quitAnimation->setDuration(250);
146  m_quitAnimation->setStartValue(w->geometry());
147  m_quitAnimation->setEndValue(QRect(w->x(), w->geometry().center().y(), w->width(), 0));
148  m_quitAnimation->start();
150  }
151  else
152  {
154  v = TTK::Image::reRenderValue<float>(1, 0.35, TTK_RN_MAX - v);
155  m_quitAnimation->stop();
156  m_quitAnimation->setPropertyName("windowOpacity");
157  m_quitAnimation->setDuration(TTK_DN_S2MS);
158  m_quitAnimation->setStartValue(v);
159  m_quitAnimation->setEndValue(0);
160  m_quitAnimation->start();
161  }
162 
164 }
165 
167 {
169  widget->show();
170 }
171 
173 {
175  {
176  return;
177  }
178 
180  if(w->isFullScreen() || w->isMaximized())
181  {
182  return;
183  }
184 
185  const int lpx = w->x();
186  const int rpx = w->x() + w->width();
187  const int tpy = w->y();
188  const int bpy = w->y() + w->height();
189 #ifdef Q_OS_WIN
190  constexpr int gap = 2;
191 #elif defined Q_OS_UNIX
193 #endif
194  const QRect &rect = TTKDesktopWrapper::screenGeometry();
196 
197  if(direction != TTK::Direction::Left && -MARGIN_SIDE <= lpx && lpx <= MARGIN_SIDE)
198  {
200  m_sideAnimation->stop();
201  m_sideAnimation->setStartValue(w->pos());
202  m_sideAnimation->setEndValue(QPoint(-w->width() + gap, w->y()));
203  m_sideAnimation->start();
205  }
206  else if(direction != TTK::Direction::Right && -MARGIN_SIDE + rect.width() <= rpx && rpx <= MARGIN_SIDE + rect.width())
207  {
209  m_sideAnimation->stop();
210  m_sideAnimation->setStartValue(w->pos());
211  m_sideAnimation->setEndValue(QPoint(rect.width() - gap, w->y()));
212  m_sideAnimation->start();
214  }
215  else if(direction != TTK::Direction::Top && -MARGIN_SIDE <= tpy && tpy <= MARGIN_SIDE)
216  {
218  m_sideAnimation->stop();
219  m_sideAnimation->setStartValue(w->pos());
220  m_sideAnimation->setEndValue(QPoint(w->x(), -w->height() + gap));
221  m_sideAnimation->start();
223  }
224  else if(direction != TTK::Direction::Bottom && -MARGIN_SIDE + rect.height() <= bpy && bpy <= MARGIN_SIDE + rect.height())
225  {
227  m_sideAnimation->stop();
228  m_sideAnimation->setStartValue(w->pos());
229  m_sideAnimation->setEndValue(QPoint(w->x(), rect.height() - gap));
230  m_sideAnimation->start();
232  }
233 }
234 
236 {
238  {
239  return;
240  }
241 
243  const QRect &rect = TTKDesktopWrapper::screenGeometry();
244 
245  switch(m_direction)
246  {
249  {
250  m_sideAnimation->stop();
251  m_sideAnimation->setStartValue(w->pos());
252  m_sideAnimation->setEndValue(QPoint((rect.width() - w->width()) / 2, w->y()));
253  m_sideAnimation->start();
255  break;
256  }
257  case TTK::Direction::Top:
259  {
260  m_sideAnimation->stop();
261  m_sideAnimation->setStartValue(w->pos());
262  m_sideAnimation->setEndValue(QPoint(w->x(), (rect.height() - w->height()) / 2));
263  m_sideAnimation->start();
265  break;
266  }
267  case TTK::Direction::LeftTop: break;
268  case TTK::Direction::RightTop: break;
269  case TTK::Direction::LeftBottom: break;
270  case TTK::Direction::RightBottom: break;
271  default: break;
272  }
273 
275 }
276 
278 {
279 #ifdef Q_OS_WIN
280  MusicPlatformManager manager;
281  manager.windowsStartUpMode(G_SETTING_PTR->value(MusicSettingManager::StartUpMode).toBool());
282 
284  {
285  TTKFileAssociation association;
286  const QStringList &keys = association.keys();
287 
288  for(const QString &format : TTK::unsupportAssociations())
289  {
290  const bool exist = keys.contains(format) && association.exist(format);
291  if(exist)
292  {
293  association.remove(format);
294  }
295  }
296 
297  for(const QString &format : TTK::supportAssociations())
298  {
299  const bool exist = keys.contains(format) && association.exist(format);
300  const bool enable = G_SETTING_PTR->value(MusicSettingManager::FileAssociationMode).toBool();
301 
302  if(exist && !enable)
303  {
304  association.remove(format);
305  }
306  else if(!exist && enable)
307  {
308  association.append(format);
309  }
310  }
311  });
312 #endif
313  //
315  {
317  }
319  //
320  m_backupModule->run();
321 }
322 
324 {
325  qApp->exit();
326 }
327 
329 {
330  if(!m_quitContainer)
331  {
333  w->hide();
334 
335  m_quitContainer = new QWidget;
336  m_quitContainer->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
337  m_quitContainer->setAttribute(Qt::WA_TranslucentBackground);
338 
341  gifWidget->setInterval(25 * TTK_DN_MS);
342  gifWidget->setInfinited(false);
343  m_quitContainer->resize(gifWidget->size());
344 
345  const QPoint &center = w->geometry().center();
346  m_quitContainer->move(QPoint(center.x() - m_quitContainer->width() / 2, center.y() - m_quitContainer->height() / 2));
347 
348  m_quitContainer->raise();
349  m_quitContainer->show();
350  gifWidget->start();
351  gifWidget->show();
352  }
353 }
354 
356 {
358 }
359 
361 {
363 }
364 
366 {
368 }
369 
371 {
372  QStringList list;
374 
375  MusicTimerWidget widget;
376  widget.setSongStringList(list);
377  widget.exec();
378 }
379 
381 {
383 }
384 
386 {
388  Qt::WindowFlags flags = MusicApplication::instance()->windowFlags();
389  MusicApplication::instance()->setWindowFlags(m_setWindowToTop ? (flags | Qt::WindowStaysOnTopHint) : (flags & ~Qt::WindowStaysOnTopHint));
390  MusicApplication::instance()->show();
391 }
392 
394 {
396 
397  const QRect &rect = TTKDesktopWrapper::screenGeometry();
398  G_SETTING_PTR->setValue(MusicSettingManager::ScreenSize, rect.size());
400 
401  QWidget *w = MusicApplication::instance();
402  if(w->isMaximized() || w->isMinimized() || w->isFullScreen())
403  {
404  w->showNormal();
405  }
406  w->setGeometry((rect.width() - WINDOW_WIDTH_MIN) / 2, (rect.height() - WINDOW_HEIGHT_MIN) / 2, WINDOW_WIDTH_MIN, WINDOW_HEIGHT_MIN);
407 }
408 
410 {
412 }
413 
415 {
417 }
418 
420 {
421  delete m_mobileDeviceWidget;
422  m_mobileDeviceWidget = nullptr;
423 
424  if(state)
425  {
427  m_mobileDeviceWidget->show();
428  }
429  else
430  {
432  }
433 }
434 
436 {
437  if(!closeCurrentEqualizer())
438  {
439  return;
440  }
441 
442  MusicEqualizerDialog widget;
443  widget.exec();
444 }
445 
447 {
448  if(!closeCurrentEqualizer())
449  {
450  return;
451  }
452 
454  widget.setInputModule(this);
455  widget.exec();
456 }
457 
459 {
460  const QString &value = G_SETTING_PTR->value(MusicSettingManager::EnhancedEffectValue).toString();
461  const QStringList &effects = value.split(";", QtSkipEmptyParts);
462  for(const QString &effect : qAsConst(effects))
463  {
464  TTK::TTKQmmp::enabledEffectPlugin(true, effect);
465  }
466 }
467 
469 {
471  {
472  MusicMessageBox message;
473  message.setText(tr("We are opening the magic sound, if you want to close?"));
474  if(!message.exec())
475  {
476  return false;
477  }
478 
479  Q_EMIT enhancedMusicChanged(0);
480  }
481  return true;
482 }
#define QtSkipEmptyParts
String skip empty parts.
Definition: ttkqtcompat.h:129
static constexpr const char * SYNC_HOST_URL
QPropertyAnimation * m_quitAnimation
void setInputModule(QObject *object)
The class of the app object widget.
static MusicApplication * instance()
flags
Definition: http_parser.h:135
MusicTimerAutoModule * m_timerAutoModule
void enhancedMusicChanged(int type)
void setText(const QString &text) const
The class of the platform system manager.
MusicScreenSaverBackgroundWidget * m_screenSaverWidget
MusicSourceUpdateRequest * m_sourceUpdateRequest
static QString HOST
Definition: qsyncconfig.h:32
QPropertyAnimation * m_sideAnimation
The class of the time auto run.
The class of the app main widget.
The class of the pv counter.
The class of the messagebox widget.
The class of the device watcher.
The class of the screen saver background widget.
#define TTKGenerateSingleWidget(...)
The class of the music player.
Definition: musicplayer.h:31
MusicResourceRequest * m_resourceRequest
Direction
Definition: ttklibrary.h:27
#define TTK_RN_MAX
Definition: ttkglobal.h:359
The class of the mobile devices widget.
System systemName() const
static void popup(const QString &text)
TTK_MODULE_EXPORT QStringList supportAssociations()
The class of the music spectrum widget all.
#define qAsConst
Definition: ttkqtglobal.h:53
The class of the source data query update request.
const char * name
Definition: http_parser.c:458
MusicApplicationModule(QObject *parent=nullptr)
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
The namespace of the process utils.
Definition: ttkcompat.h:24
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:177
The class of the platform system.
The class of the equalizer widget.
void currentPlaylist(QStringList &list)
static constexpr const char * REPORT_BUG_URL
TTK_MODULE_EXPORT QStringList unsupportAssociations()
static QRect screenGeometry(int index=0)
#define TTK_SLOT
Definition: ttkqtglobal.h:165
The class of the application upgrade notify widget.
void setType(Module type)
static constexpr int MARGIN_SIDE
TTK_MODULE_EXPORT bool openUrl(const QString &path, bool local=true)
The class of the resource data request.
void appendEventReceiver(QObject *receiver)
void deviceNameChanged(const QString &name)
#define TTKConcurrent(...)
Definition: ttkconcurrent.h:34
The class of the application backup module.
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
The class of the about application info dialog.
MusicPVCounterRequest * m_counterRequest
MusicMobileDevicesWidget * m_mobileDeviceWidget
static TaskbarInfo screenTaskbar(int index=0)
The class of the float gif label widget.
static MusicApplicationModule * instance()
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:153
void setInterval(int value)
void setSongStringList(const QStringList &list)
void setBackgroundAnimation(bool state)
MusicBackupModule * m_backupModule
The class of the sound effect widget.
static MusicApplicationModule * m_instance
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
The class of the timer widget.
TTK_MODULE_EXPORT void enabledEffectPlugin(bool enabled, const QString &name={})
static MusicTopAreaWidget * instance()
state
Definition: http_parser.c:279
#define WINDOW_HEIGHT_MIN
Definition: musicobject.h:154
The class of the application upgrade widget.
#define TTK_DN_MS
Definition: ttkglobal.h:270
#define G_SETTING_PTR