TTKMusicPlayer  4.3.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 "musicequalizerdialog.h"
9 #include "musicplatformmanager.h"
12 #include "musicmessagebox.h"
14 #include "musicapplication.h"
15 #include "musictopareawidget.h"
16 #include "musicrightareawidget.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 "ttklibrary.h"
25 #include "ttklogoutput.h"
26 #include "ttkconcurrent.h"
27 #include "ttkdesktopscreen.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(TTK_DN_S2MS / 4);
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 
73 {
74  Q_CLEANUP_RESOURCE(TTKModule);
76  //
77  delete m_backupModule;
78  delete m_timerAutoModule;
79  delete m_screenSaverWidget;
80  delete m_quitAnimation;
81  delete m_sideAnimation;
82  delete m_deviceWatcher;
83  delete m_mobileDeviceWidget;
84  delete m_quitContainer;
85  delete m_resourceRequest;
86  delete m_counterRequest;
87  delete m_sourceUpdateRequest;
88 }
89 
91 {
92  return m_instance;
93 }
94 
96 {
98  {
101  const QRect &rect = TTKDesktopScreen::currentGeometry();
102  w->move(rect.x() + (rect.width() - w->width()) / 2, rect.y() + w->y());
103  }
104 }
105 
107 {
109 }
110 
112 {
113 #ifndef QT_NO_SSL
114  // ssl support check
115  TTK_INFO_STREAM("Application network support ssl:" << (QSslSocket::supportsSsl() ? "true" : "false"));
116 # if TTK_QT_VERSION_CHECK(5,0,0)
117 # if TTK_QT_VERSION_CHECK(5,4,0)
118  TTK_INFO_STREAM("Application network ssl build version:" << QSslSocket::sslLibraryBuildVersionString());
119 # endif
120  TTK_INFO_STREAM("Application network ssl runtime version:" << QSslSocket::sslLibraryVersionString());
121 # endif
122 #endif
123  // sync host init
125  //
129 }
130 
132 {
134 
136  {
139  w->setMinimumSize(0, 0);
140 
141  m_quitAnimation->stop();
142  m_quitAnimation->setPropertyName("geometry");
143  m_quitAnimation->setDuration(TTK_DN_S2MS / 4);
144  m_quitAnimation->setStartValue(w->geometry());
145  m_quitAnimation->setEndValue(QRect(w->x(), w->geometry().center().y(), w->width(), 0));
146  m_quitAnimation->start();
148  }
149  else
150  {
152  v = TTK::Image::boundValue<float>(1.0f, 0.35f, TTK_RN_MAX - v);
153 
154  m_quitAnimation->stop();
155  m_quitAnimation->setPropertyName("windowOpacity");
156  m_quitAnimation->setDuration(TTK_DN_S2MS);
157  m_quitAnimation->setStartValue(v);
158  m_quitAnimation->setEndValue(0.0f);
159  m_quitAnimation->start();
160  }
161 
163 }
164 
166 {
168  widget->show();
169 }
170 
172 {
174  {
175  return;
176  }
177 
179  if(w->isFullScreen() || w->isMaximized())
180  {
181  return;
182  }
183 
184  const int lpx = w->x();
185  const int rpx = w->x() + w->width();
186  const int tpy = w->y();
187  const int bpy = w->y() + w->height();
188 #ifdef Q_OS_WIN
189  constexpr int gap = 2;
190 #elif defined Q_OS_UNIX
192 #endif
193  const int index = TTKDesktopScreen::currentIndex();
194  const QRect &rect = TTKDesktopScreen::screenGeometry(index);
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 = TTKDesktopScreen::currentGeometry();
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 {
280 }
281 
283 {
284  bool config = false;
285 #ifdef Q_OS_WIN
286  QFile file(TTK::applicationPath() + TTK_QT_CONFIG);
287  if(file.open(QIODevice::ReadWrite))
288  {
290  if(!(config ? (file.write("[Platforms]\nWindowsArguments = dpiawareness=0\n") != -1) : file.remove()))
291  {
292  G_SETTING_PTR->setValue(MusicSettingManager::OtherHighDpiScalingEnable, Qt::PartiallyChecked);
293  }
294  file.close();
295  }
296 
297  MusicPlatformManager manager;
298  manager.windowsStartUpMode(G_SETTING_PTR->value(MusicSettingManager::StartUpMode).toBool());
299 
301  {
302  TTKFileAssociation association;
303  const QStringList &keys = association.keys();
304 
305  for(const QString &format : TTK::unsupportAssociations())
306  {
307  const bool exist = keys.contains(format) && association.exist(format);
308  if(exist)
309  {
310  association.remove(format);
311  }
312  }
313 
314  for(const QString &format : TTK::supportAssociations())
315  {
316  const bool exist = keys.contains(format) && association.exist(format);
317  const bool enable = G_SETTING_PTR->value(MusicSettingManager::FileAssociationMode).toBool();
318 
319  if(exist && !enable)
320  {
321  association.remove(format);
322  }
323  else if(!exist && enable)
324  {
325  association.append(format);
326  }
327  }
328  });
329 #endif
330  //
333  //
335  {
337  }
339  //
341 }
342 
344 {
345  qApp->exit();
346 }
347 
349 {
350  if(!m_quitContainer)
351  {
353  w->hide();
354 
355  m_quitContainer = new QWidget;
356  m_quitContainer->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
357  m_quitContainer->setAttribute(Qt::WA_TranslucentBackground);
358 
361  gifWidget->setInterval(25 * TTK_DN_MS);
362  gifWidget->setInfinited(false);
363  m_quitContainer->resize(gifWidget->size());
364 
365  const QPoint &center = w->geometry().center();
366  m_quitContainer->move(QPoint(center.x() - m_quitContainer->width() / 2, center.y() - m_quitContainer->height() / 2));
367 
368  m_quitContainer->raise();
369  m_quitContainer->show();
370  gifWidget->start();
371  gifWidget->show();
372  }
373 }
374 
376 {
378 }
379 
381 {
383 }
384 
386 {
388 }
389 
391 {
392  QStringList list;
394 
395  MusicTimerWidget widget;
396  widget.setSongStringList(list);
397  widget.exec();
398 }
399 
401 {
403 }
404 
406 {
408  const Qt::WindowFlags flags = MusicApplication::instance()->windowFlags();
409  MusicApplication::instance()->setWindowFlags(m_setWindowToTop ? (flags | Qt::WindowStaysOnTopHint) : (flags & ~Qt::WindowStaysOnTopHint));
410  MusicApplication::instance()->show();
411 }
412 
414 {
416 
417  const QRect &rect = TTKDesktopScreen::currentGeometry();
418  G_SETTING_PTR->setValue(MusicSettingManager::ScreenSize, rect.size());
420 
421  QWidget *w = MusicApplication::instance();
422  if(w->isMaximized() || w->isMinimized() || w->isFullScreen())
423  {
424  w->showNormal();
425  }
426 
427  w->setGeometry(rect.x() + (rect.width() - WINDOW_WIDTH_MIN) / 2,
428  rect.y() + (rect.height() - WINDOW_HEIGHT_MIN) / 2,
430 }
431 
433 {
435 }
436 
438 {
440 }
441 
443 {
444  delete m_mobileDeviceWidget;
445  m_mobileDeviceWidget = nullptr;
446 
447  if(state)
448  {
450  m_mobileDeviceWidget->show();
451  }
452  else
453  {
455  }
456 }
457 
459 {
460  if(!closeCurrentEqualizer())
461  {
462  return;
463  }
464 
465  MusicEqualizerDialog widget;
466  widget.exec();
467 }
468 
470 {
471 // if(!closeCurrentEqualizer())
472 // {
473 // return;
474 // }
475 
477  widget.exec();
478 
480 }
481 
483 {
485  {
487  message.setText(tr("We are opening the magic sound, if you want to close?"));
488  if(!message.exec())
489  {
490  return false;
491  }
492 
493  Q_EMIT enhancedSongChanged(0);
494  }
495  return true;
496 }
static constexpr const char * SYNC_HOST_URL
static MusicRightAreaWidget * instance()
QPropertyAnimation * m_quitAnimation
The class of the app object module.
static QString message(const TTK::Attribute attr)
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
MusicSourceUpdateRequest * m_sourceUpdateRequest
static QString HOST
Definition: qsyncconfig.h:32
QPropertyAnimation * m_sideAnimation
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.
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)
static int currentIndex()
TTK_MODULE_EXPORT QStringList supportAssociations()
TTK_MODULE_EXPORT void removeLogHandler()
static System systemName()
The class of the music spectrum widget all.
The class of the source data query update request.
static QRect currentGeometry()
const char * name
Definition: http_parser.c:458
#define TTK_GENERATE_SINGLE_WIDGET(...)
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:172
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.
static MusicTopAreaWidget * instance()
state
Definition: http_parser.c:279
#define WINDOW_HEIGHT_MIN
Definition: musicobject.h:173
The class of the application upgrade widget.
#define TTK_DN_MS
Definition: ttkglobal.h:349
#define G_SETTING_PTR