TTKMusicPlayer  4.1.3.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 "ttklibrary.h"
25 #include "ttklogoutput.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(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(MusicPlayer);
75  delete m_backupModule;
76  delete m_timerAutoModule;
77  delete m_screenSaverWidget;
78  delete m_quitAnimation;
79  delete m_sideAnimation;
80  delete m_deviceWatcher;
81  delete m_mobileDeviceWidget;
82  delete m_quitContainer;
83  delete m_resourceRequest;
84  delete m_counterRequest;
85  delete m_sourceUpdateRequest;
86 }
87 
89 {
90  return m_instance;
91 }
92 
94 {
96  {
99  const QRect &rect = TTKDesktopWrapper::screenGeometry();
100  w->move((rect.width() - w->width()) / 2, w->y());
101  }
102 }
103 
105 {
107 }
108 
110 {
111 #ifndef QT_NO_SSL
112  // ssl support check
113  TTK_INFO_STREAM("Application network support ssl:" << (QSslSocket::supportsSsl() ? "true" : "false"));
114 #endif
115  // sync host init
117  //
121 }
122 
124 {
126 
128  {
131  w->setMinimumSize(0, 0);
132 
133  m_quitAnimation->stop();
134  m_quitAnimation->setPropertyName("geometry");
135  m_quitAnimation->setDuration(TTK_DN_S2MS / 4);
136  m_quitAnimation->setStartValue(w->geometry());
137  m_quitAnimation->setEndValue(QRect(w->x(), w->geometry().center().y(), w->width(), 0));
138  m_quitAnimation->start();
140  }
141  else
142  {
144  v = TTK::Image::boundValue<float>(1.0f, 0.35f, TTK_RN_MAX - v);
145 
146  m_quitAnimation->stop();
147  m_quitAnimation->setPropertyName("windowOpacity");
148  m_quitAnimation->setDuration(TTK_DN_S2MS);
149  m_quitAnimation->setStartValue(v);
150  m_quitAnimation->setEndValue(0.0f);
151  m_quitAnimation->start();
152  }
153 
155 }
156 
158 {
160  widget->show();
161 }
162 
164 {
166  {
167  return;
168  }
169 
171  if(w->isFullScreen() || w->isMaximized())
172  {
173  return;
174  }
175 
176  const int lpx = w->x();
177  const int rpx = w->x() + w->width();
178  const int tpy = w->y();
179  const int bpy = w->y() + w->height();
180 #ifdef Q_OS_WIN
181  constexpr int gap = 2;
182 #elif defined Q_OS_UNIX
184 #endif
185  const QRect &rect = TTKDesktopWrapper::screenGeometry();
187 
188  if(direction != TTK::Direction::Left && -MARGIN_SIDE <= lpx && lpx <= MARGIN_SIDE)
189  {
191  m_sideAnimation->stop();
192  m_sideAnimation->setStartValue(w->pos());
193  m_sideAnimation->setEndValue(QPoint(-w->width() + gap, w->y()));
194  m_sideAnimation->start();
196  }
197  else if(direction != TTK::Direction::Right && -MARGIN_SIDE + rect.width() <= rpx && rpx <= MARGIN_SIDE + rect.width())
198  {
200  m_sideAnimation->stop();
201  m_sideAnimation->setStartValue(w->pos());
202  m_sideAnimation->setEndValue(QPoint(rect.width() - gap, w->y()));
203  m_sideAnimation->start();
205  }
206  else if(direction != TTK::Direction::Top && -MARGIN_SIDE <= tpy && tpy <= MARGIN_SIDE)
207  {
209  m_sideAnimation->stop();
210  m_sideAnimation->setStartValue(w->pos());
211  m_sideAnimation->setEndValue(QPoint(w->x(), -w->height() + gap));
212  m_sideAnimation->start();
214  }
215  else if(direction != TTK::Direction::Bottom && -MARGIN_SIDE + rect.height() <= bpy && bpy <= MARGIN_SIDE + rect.height())
216  {
218  m_sideAnimation->stop();
219  m_sideAnimation->setStartValue(w->pos());
220  m_sideAnimation->setEndValue(QPoint(w->x(), rect.height() - gap));
221  m_sideAnimation->start();
223  }
224 }
225 
227 {
229  {
230  return;
231  }
232 
234  const QRect &rect = TTKDesktopWrapper::screenGeometry();
235 
236  switch(m_direction)
237  {
240  {
241  m_sideAnimation->stop();
242  m_sideAnimation->setStartValue(w->pos());
243  m_sideAnimation->setEndValue(QPoint((rect.width() - w->width()) / 2, w->y()));
244  m_sideAnimation->start();
246  break;
247  }
248  case TTK::Direction::Top:
250  {
251  m_sideAnimation->stop();
252  m_sideAnimation->setStartValue(w->pos());
253  m_sideAnimation->setEndValue(QPoint(w->x(), (rect.height() - w->height()) / 2));
254  m_sideAnimation->start();
256  break;
257  }
258  case TTK::Direction::LeftTop: break;
259  case TTK::Direction::RightTop: break;
260  case TTK::Direction::LeftBottom: break;
261  case TTK::Direction::RightBottom: break;
262  default: break;
263  }
264 
266 }
267 
269 {
270 #ifdef Q_OS_WIN
271  QFile file(TTK::applicationPath() + TTK_QT_CONFIG);
272  file.open(QFile::ReadWrite);
273 
274  if(!(G_SETTING_PTR->value(MusicSettingManager::OtherHighDpiScalingEnable).toBool() ? (file.write("[Platforms]\nWindowsArguments = dpiawareness=0\n") != -1) : file.remove()))
275  {
276  G_SETTING_PTR->setValue(MusicSettingManager::OtherHighDpiScalingEnable, Qt::PartiallyChecked);
277  }
278  file.close();
279 
280  //
281  MusicPlatformManager manager;
282  manager.windowsStartUpMode(G_SETTING_PTR->value(MusicSettingManager::StartUpMode).toBool());
283 
284  //
286  {
287  TTKFileAssociation association;
288  const QStringList &keys = association.keys();
289 
290  for(const QString &format : TTK::unsupportAssociations())
291  {
292  const bool exist = keys.contains(format) && association.exist(format);
293  if(exist)
294  {
295  association.remove(format);
296  }
297  }
298 
299  for(const QString &format : TTK::supportAssociations())
300  {
301  const bool exist = keys.contains(format) && association.exist(format);
302  const bool enable = G_SETTING_PTR->value(MusicSettingManager::FileAssociationMode).toBool();
303 
304  if(exist && !enable)
305  {
306  association.remove(format);
307  }
308  else if(!exist && enable)
309  {
310  association.append(format);
311  }
312  }
313  });
314 #endif
315  //
317  //
319  {
321  }
323  //
324  m_backupModule->run();
325 }
326 
328 {
329  qApp->exit();
330 }
331 
333 {
334  if(!m_quitContainer)
335  {
337  w->hide();
338 
339  m_quitContainer = new QWidget;
340  m_quitContainer->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
341  m_quitContainer->setAttribute(Qt::WA_TranslucentBackground);
342 
345  gifWidget->setInterval(25 * TTK_DN_MS);
346  gifWidget->setInfinited(false);
347  m_quitContainer->resize(gifWidget->size());
348 
349  const QPoint &center = w->geometry().center();
350  m_quitContainer->move(QPoint(center.x() - m_quitContainer->width() / 2, center.y() - m_quitContainer->height() / 2));
351 
352  m_quitContainer->raise();
353  m_quitContainer->show();
354  gifWidget->start();
355  gifWidget->show();
356  }
357 }
358 
360 {
362 }
363 
365 {
367 }
368 
370 {
372 }
373 
375 {
376  QStringList list;
378 
379  MusicTimerWidget widget;
380  widget.setSongStringList(list);
381  widget.exec();
382 }
383 
385 {
387 }
388 
390 {
392  Qt::WindowFlags flags = MusicApplication::instance()->windowFlags();
393  MusicApplication::instance()->setWindowFlags(m_setWindowToTop ? (flags | Qt::WindowStaysOnTopHint) : (flags & ~Qt::WindowStaysOnTopHint));
394  MusicApplication::instance()->show();
395 }
396 
398 {
400 
401  const QRect &rect = TTKDesktopWrapper::screenGeometry();
402  G_SETTING_PTR->setValue(MusicSettingManager::ScreenSize, rect.size());
404 
405  QWidget *w = MusicApplication::instance();
406  if(w->isMaximized() || w->isMinimized() || w->isFullScreen())
407  {
408  w->showNormal();
409  }
410  w->setGeometry((rect.width() - WINDOW_WIDTH_MIN) / 2, (rect.height() - WINDOW_HEIGHT_MIN) / 2, WINDOW_WIDTH_MIN, WINDOW_HEIGHT_MIN);
411 }
412 
414 {
416 }
417 
419 {
421 }
422 
424 {
425  delete m_mobileDeviceWidget;
426  m_mobileDeviceWidget = nullptr;
427 
428  if(state)
429  {
431  m_mobileDeviceWidget->show();
432  }
433  else
434  {
436  }
437 }
438 
440 {
441  if(!closeCurrentEqualizer())
442  {
443  return;
444  }
445 
446  MusicEqualizerDialog widget;
447  widget.exec();
448 }
449 
451 {
452  if(!closeCurrentEqualizer())
453  {
454  return;
455  }
456 
458  widget.setInputModule(this);
459  widget.exec();
460 }
461 
463 {
464  const QString &value = G_SETTING_PTR->value(MusicSettingManager::EnhancedEffectValue).toString();
465  const QStringList &effects = value.split(";", QtSkipEmptyParts);
466  for(const QString &effect : qAsConst(effects))
467  {
468  TTK::TTKQmmp::enabledEffectPlugin(true, effect);
469  }
470 }
471 
473 {
475  {
476  MusicMessageBox message;
477  message.setText(tr("We are opening the magic sound, if you want to close?"));
478  if(!message.exec())
479  {
480  return false;
481  }
482 
483  Q_EMIT enhancedSongChanged(0);
484  }
485  return true;
486 }
#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
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.
#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:364
The class of the mobile devices widget.
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:51
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:68
The namespace of the process utils.
Definition: ttkcompat.h:24
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:193
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:181
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:281
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:155
void setInterval(int value)
static QString applicationPath()
Definition: ttkqtobject.h:44
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:156
The class of the application upgrade widget.
#define TTK_DN_MS
Definition: ttkglobal.h:275
#define G_SETTING_PTR