TTKMusicPlayer  4.2.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 "musichotkeymanager.h"
25 #include "ttklibrary.h"
26 #include "ttklogoutput.h"
27 #include "ttkconcurrent.h"
28 #include "ttkdesktopscreen.h"
29 #include "ttkfileassociation.h"
30 #include "ttkplatformsystem.h"
31 
32 #include "qdevicewatcher.h"
33 #include "qsync/qsyncconfig.h"
34 
35 static constexpr int MARGIN_SIDE = 10;
36 static constexpr const char *SYNC_HOST_URL = "VDVnYUdYMW9xNnVWSnd6L0J6NHI2MFZ5d0R3R2NiRVF4VW5WckpNcUhnUT0=";
37 
39 
41  : QObject(parent),
42  m_setWindowToTop(false),
43  m_direction(TTK::Direction::No),
44  m_mobileDeviceWidget(nullptr),
45  m_quitContainer(nullptr),
46  m_screenSaverWidget(nullptr)
47 {
48  m_instance = this;
49 
51 
52  m_quitAnimation = new QPropertyAnimation(this);
53  m_sideAnimation = new QPropertyAnimation(parent, "pos", this);
54  m_quitAnimation->setTargetObject(parent);
55  m_sideAnimation->setDuration(TTK_DN_S2MS / 4);
56 
59 
60  m_deviceWatcher = new QDeviceWatcher(this);
61  connect(m_deviceWatcher, SIGNAL(deviceChanged(bool)), SLOT(deviceChanged(bool)));
62  connect(m_deviceWatcher, SIGNAL(deviceAdded(QString)), SLOT(deviceNameChanged(QString)));
65 
69 
71 }
72 
74 {
75  Q_CLEANUP_RESOURCE(TTKModule);
76  G_HOTKEY_PTR->unsetShortcut();
78  //
79  delete m_backupModule;
80  delete m_timerAutoModule;
81  delete m_screenSaverWidget;
82  delete m_quitAnimation;
83  delete m_sideAnimation;
84  delete m_deviceWatcher;
85  delete m_mobileDeviceWidget;
86  delete m_quitContainer;
87  delete m_resourceRequest;
88  delete m_counterRequest;
89  delete m_sourceUpdateRequest;
90 }
91 
93 {
94  return m_instance;
95 }
96 
98 {
100  {
103  const QRect &rect = TTKDesktopScreen::screenGeometry();
104  w->move((rect.width() - w->width()) / 2, w->y());
105  }
106 }
107 
109 {
111 }
112 
114 {
115 #ifndef QT_NO_SSL
116  // ssl support check
117  TTK_INFO_STREAM("Application network support ssl:" << (QSslSocket::supportsSsl() ? "true" : "false"));
118 #endif
119  // sync host init
121  //
125 }
126 
128 {
130 
132  {
135  w->setMinimumSize(0, 0);
136 
137  m_quitAnimation->stop();
138  m_quitAnimation->setPropertyName("geometry");
139  m_quitAnimation->setDuration(TTK_DN_S2MS / 4);
140  m_quitAnimation->setStartValue(w->geometry());
141  m_quitAnimation->setEndValue(QRect(w->x(), w->geometry().center().y(), w->width(), 0));
142  m_quitAnimation->start();
144  }
145  else
146  {
148  v = TTK::Image::boundValue<float>(1.0f, 0.35f, TTK_RN_MAX - v);
149 
150  m_quitAnimation->stop();
151  m_quitAnimation->setPropertyName("windowOpacity");
152  m_quitAnimation->setDuration(TTK_DN_S2MS);
153  m_quitAnimation->setStartValue(v);
154  m_quitAnimation->setEndValue(0.0f);
155  m_quitAnimation->start();
156  }
157 
159 }
160 
162 {
164  widget->show();
165 }
166 
168 {
170  {
171  return;
172  }
173 
175  if(w->isFullScreen() || w->isMaximized())
176  {
177  return;
178  }
179 
180  const int lpx = w->x();
181  const int rpx = w->x() + w->width();
182  const int tpy = w->y();
183  const int bpy = w->y() + w->height();
184 #ifdef Q_OS_WIN
185  constexpr int gap = 2;
186 #elif defined Q_OS_UNIX
188 #endif
189  const QRect &rect = TTKDesktopScreen::screenGeometry();
191 
192  if(direction != TTK::Direction::Left && -MARGIN_SIDE <= lpx && lpx <= MARGIN_SIDE)
193  {
195  m_sideAnimation->stop();
196  m_sideAnimation->setStartValue(w->pos());
197  m_sideAnimation->setEndValue(QPoint(-w->width() + gap, w->y()));
198  m_sideAnimation->start();
200  }
201  else if(direction != TTK::Direction::Right && -MARGIN_SIDE + rect.width() <= rpx && rpx <= MARGIN_SIDE + rect.width())
202  {
204  m_sideAnimation->stop();
205  m_sideAnimation->setStartValue(w->pos());
206  m_sideAnimation->setEndValue(QPoint(rect.width() - gap, w->y()));
207  m_sideAnimation->start();
209  }
210  else if(direction != TTK::Direction::Top && -MARGIN_SIDE <= tpy && tpy <= MARGIN_SIDE)
211  {
213  m_sideAnimation->stop();
214  m_sideAnimation->setStartValue(w->pos());
215  m_sideAnimation->setEndValue(QPoint(w->x(), -w->height() + gap));
216  m_sideAnimation->start();
218  }
219  else if(direction != TTK::Direction::Bottom && -MARGIN_SIDE + rect.height() <= bpy && bpy <= MARGIN_SIDE + rect.height())
220  {
222  m_sideAnimation->stop();
223  m_sideAnimation->setStartValue(w->pos());
224  m_sideAnimation->setEndValue(QPoint(w->x(), rect.height() - gap));
225  m_sideAnimation->start();
227  }
228 }
229 
231 {
233  {
234  return;
235  }
236 
238  const QRect &rect = TTKDesktopScreen::screenGeometry();
239 
240  switch(m_direction)
241  {
244  {
245  m_sideAnimation->stop();
246  m_sideAnimation->setStartValue(w->pos());
247  m_sideAnimation->setEndValue(QPoint((rect.width() - w->width()) / 2, w->y()));
248  m_sideAnimation->start();
250  break;
251  }
252  case TTK::Direction::Top:
254  {
255  m_sideAnimation->stop();
256  m_sideAnimation->setStartValue(w->pos());
257  m_sideAnimation->setEndValue(QPoint(w->x(), (rect.height() - w->height()) / 2));
258  m_sideAnimation->start();
260  break;
261  }
262  case TTK::Direction::LeftTop: break;
263  case TTK::Direction::RightTop: break;
264  case TTK::Direction::LeftBottom: break;
265  case TTK::Direction::RightBottom: break;
266  default: break;
267  }
268 
270 }
271 
273 {
274  const QString &value = G_SETTING_PTR->value(MusicSettingManager::EnhancedEffectValue).toString();
275  const QStringList &effects = value.split(";", QtSkipEmptyParts);
276  for(const QString &effect : qAsConst(effects))
277  {
278  TTK::TTKQmmp::enabledEffectPlugin(true, effect);
279  }
280 }
281 
283 {
284 #ifdef Q_OS_WIN
285  QFile file(TTK::applicationPath() + TTK_QT_CONFIG);
286  if(file.open(QIODevice::ReadWrite))
287  {
288  if(!(G_SETTING_PTR->value(MusicSettingManager::OtherHighDpiScalingEnable).toBool() ? (file.write("[Platforms]\nWindowsArguments = dpiawareness=0\n") != -1) : file.remove()))
289  {
290  G_SETTING_PTR->setValue(MusicSettingManager::OtherHighDpiScalingEnable, Qt::PartiallyChecked);
291  }
292  file.close();
293  }
294 
295  MusicPlatformManager manager;
296  manager.windowsStartUpMode(G_SETTING_PTR->value(MusicSettingManager::StartUpMode).toBool());
297 
299  {
300  TTKFileAssociation association;
301  const QStringList &keys = association.keys();
302 
303  for(const QString &format : TTK::unsupportAssociations())
304  {
305  const bool exist = keys.contains(format) && association.exist(format);
306  if(exist)
307  {
308  association.remove(format);
309  }
310  }
311 
312  for(const QString &format : TTK::supportAssociations())
313  {
314  const bool exist = keys.contains(format) && association.exist(format);
315  const bool enable = G_SETTING_PTR->value(MusicSettingManager::FileAssociationMode).toBool();
316 
317  if(exist && !enable)
318  {
319  association.remove(format);
320  }
321  else if(!exist && enable)
322  {
323  association.append(format);
324  }
325  }
326  });
327 #endif
328  //
331  //
333  {
335  }
337  //
339 }
340 
342 {
343  qApp->exit();
344 }
345 
347 {
348  if(!m_quitContainer)
349  {
351  w->hide();
352 
353  m_quitContainer = new QWidget;
354  m_quitContainer->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
355  m_quitContainer->setAttribute(Qt::WA_TranslucentBackground);
356 
359  gifWidget->setInterval(25 * TTK_DN_MS);
360  gifWidget->setInfinited(false);
361  m_quitContainer->resize(gifWidget->size());
362 
363  const QPoint &center = w->geometry().center();
364  m_quitContainer->move(QPoint(center.x() - m_quitContainer->width() / 2, center.y() - m_quitContainer->height() / 2));
365 
366  m_quitContainer->raise();
367  m_quitContainer->show();
368  gifWidget->start();
369  gifWidget->show();
370  }
371 }
372 
374 {
376 }
377 
379 {
381 }
382 
384 {
386 }
387 
389 {
390  QStringList list;
392 
393  MusicTimerWidget widget;
394  widget.setSongStringList(list);
395  widget.exec();
396 }
397 
399 {
401 }
402 
404 {
406  Qt::WindowFlags flags = MusicApplication::instance()->windowFlags();
407  MusicApplication::instance()->setWindowFlags(m_setWindowToTop ? (flags | Qt::WindowStaysOnTopHint) : (flags & ~Qt::WindowStaysOnTopHint));
408  MusicApplication::instance()->show();
409 }
410 
412 {
414 
415  const QRect &rect = TTKDesktopScreen::screenGeometry();
416  G_SETTING_PTR->setValue(MusicSettingManager::ScreenSize, rect.size());
418 
419  QWidget *w = MusicApplication::instance();
420  if(w->isMaximized() || w->isMinimized() || w->isFullScreen())
421  {
422  w->showNormal();
423  }
424  w->setGeometry((rect.width() - WINDOW_WIDTH_MIN) / 2, (rect.height() - WINDOW_HEIGHT_MIN) / 2, WINDOW_WIDTH_MIN, WINDOW_HEIGHT_MIN);
425 }
426 
428 {
430 }
431 
433 {
435 }
436 
438 {
439  delete m_mobileDeviceWidget;
440  m_mobileDeviceWidget = nullptr;
441 
442  if(state)
443  {
445  m_mobileDeviceWidget->show();
446  }
447  else
448  {
450  }
451 }
452 
454 {
455  if(!closeCurrentEqualizer())
456  {
457  return;
458  }
459 
460  MusicEqualizerDialog widget;
461  widget.exec();
462 }
463 
465 {
466  if(!closeCurrentEqualizer())
467  {
468  return;
469  }
470 
472  widget.setInputModule(this);
473  widget.exec();
474 }
475 
477 {
479  {
480  MusicMessageBox message;
481  message.setText(tr("We are opening the magic sound, if you want to close?"));
482  if(!message.exec())
483  {
484  return false;
485  }
486 
487  Q_EMIT enhancedSongChanged(0);
488  }
489  return true;
490 }
#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 module.
static MusicApplication * instance()
flags
Definition: http_parser.h:135
MusicTimerAutoModule * m_timerAutoModule
void setText(const QString &text) const
The class of the platform system manager.
MusicScreenSaverBackgroundWidget * m_screenSaverWidget
#define G_HOTKEY_PTR
MusicSourceUpdateRequest * m_sourceUpdateRequest
static QString HOST
Definition: qsyncconfig.h:32
QPropertyAnimation * m_sideAnimation
#define TTK_APP_NAME
Definition: ttkobject.h:25
TTK_MODULE_EXPORT void initiailizeLog(const QString &module)
The class of the time auto run.
void enhancedSongChanged(int type)
The class of the app main widget.
#define TTK_QT_CONFIG
The class of the pv counter.
TTK_MODULE_EXPORT void installLogHandler()
The class of the messagebox widget.
The class of the device watcher.
The class of the screen saver background widget.
#define TTKGenerateSingleWidget(...)
MusicResourceRequest * m_resourceRequest
Direction
Definition: ttklibrary.h:27
#define TTK_RN_MAX
Definition: ttkglobal.h:439
The class of the mobile devices widget.
static TaskbarInfo screenTaskbar(int index=0)
TTK_MODULE_EXPORT QStringList supportAssociations()
TTK_MODULE_EXPORT void removeLogHandler()
static System systemName()
The class of the music spectrum widget all.
#define qAsConst
Definition: ttkqtglobal.h:57
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:74
The namespace of the application object.
Definition: ttkcompat.h:24
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:189
The class of the equalizer widget.
void currentPlaylist(QStringList &list)
static constexpr const char * REPORT_BUG_URL
TTK_MODULE_EXPORT QStringList unsupportAssociations()
#define TTK_SLOT
Definition: ttkqtglobal.h:177
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:355
The class of the about application info dialog.
MusicPVCounterRequest * m_counterRequest
MusicMobileDevicesWidget * m_mobileDeviceWidget
The class of the float gif label widget.
static MusicApplicationModule * instance()
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:167
void setInterval(int value)
static QString applicationPath()
Definition: ttkqtobject.h:44
bool isLastedVersion() const noexcept
void setSongStringList(const QStringList &list)
static QRect screenGeometry(int index=0)
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)
void setInfinited(bool s) noexcept
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:168
The class of the application upgrade widget.
#define TTK_DN_MS
Definition: ttkglobal.h:349
#define G_SETTING_PTR