void PlayerWidget::onBtnOpen_Clicked() { std::unique_ptr<Player> player(MusicSelector::select()); if (player == nullptr) return ; if (m_player) { m_player->disconnect(); m_player->deleteLater(); } m_player = std::move(player); m_ui->le_Title->setText(m_player->metaData(Player::Title).toString()); m_ui->le_Artist->setText(m_player->metaData(Player::Artist).toString()); m_ui->le_Album->setText(m_player->metaData(Player::AlbumTitle).toString()); updateTitle(); m_ui->btn_PlayPause->setEnabled(true); m_ui->slider_Duration->setEnabled(m_player->isSeekable()); m_ui->slider_Duration->setMaximum(m_player->duration()); m_ui->slider_Duration->setValue(m_player->position()); onPlayerPositionChanged(m_player->position()); onPlayerStateChanged(m_player->state()); connect(m_player.get(), SIGNAL(stateChanged(Player::State)), this, SLOT(onPlayerStateChanged(Player::State))); connect(m_player.get(), SIGNAL(durationChanged(qint64)), this, SLOT(onPlayerDurationChanged(qint64))); connect(m_player.get(), SIGNAL(positionChanged(qint64)), this, SLOT(onPlayerPositionChanged(qint64))); connect(m_player.get(), SIGNAL(metaDataChanged(Player::MetaData,QVariant)), this, SLOT(onPlayerMetadataChanged(Player::MetaData,QVariant))); }
void PlayerSubtitle::disconnectSignals() { disconnect(m_player, SIGNAL(sourceChanged()), this, SLOT(onPlayerSourceChanged())); disconnect(m_player, SIGNAL(positionChanged(qint64)), this, SLOT(onPlayerPositionChanged())); disconnect(m_player, SIGNAL(started()), this, SLOT(onPlayerStart())); disconnect(m_sub, SIGNAL(codecChanged()), this, SLOT(tryReload())); disconnect(m_sub, SIGNAL(enginesChanged()), this, SLOT(tryReload())); }
void PlayerSubtitle::disconnectSignals() { disconnect(m_player, SIGNAL(sourceChanged()), this, SLOT(onPlayerSourceChanged())); disconnect(m_player, SIGNAL(positionChanged(qint64)), this, SLOT(onPlayerPositionChanged())); disconnect(m_player, SIGNAL(started()), this, SLOT(onPlayerStart())); disconnect(m_player, SIGNAL(internalSubtitlePacketRead(int,QtAV::Packet)), this, SLOT(processInternalSubtitlePacket(int,QtAV::Packet))); disconnect(m_player, SIGNAL(internalSubtitleHeaderRead(QByteArray,QByteArray)), this, SLOT(processInternalSubtitleHeader(QByteArray,QByteArray))); disconnect(m_player, SIGNAL(internalSubtitleTracksChanged(QVariantList)), this, SLOT(updateInternalSubtitleTracks(QVariantList))); disconnect(m_sub, SIGNAL(codecChanged()), this, SLOT(tryReload())); disconnect(m_sub, SIGNAL(enginesChanged()), this, SLOT(tryReload())); }
void PlayerSubtitle::connectSignals() { connect(m_player, SIGNAL(sourceChanged()), this, SLOT(onPlayerSourceChanged())); connect(m_player, SIGNAL(positionChanged(qint64)), this, SLOT(onPlayerPositionChanged())); connect(m_player, SIGNAL(started()), this, SLOT(onPlayerStart())); connect(m_player, SIGNAL(internalSubtitlePacketRead(int,QtAV::Packet)), this, SLOT(processInternalSubtitlePacket(int,QtAV::Packet))); connect(m_player, SIGNAL(internalSubtitleHeaderRead(QByteArray,QByteArray)), this, SLOT(processInternalSubtitleHeader(QByteArray,QByteArray))); connect(m_player, SIGNAL(internalSubtitleTracksChanged(QVariantList)), this, SLOT(updateInternalSubtitleTracks(QVariantList))); // try to reload internal subtitle track. if failed and external subtitle is enabled, fallback to external connect(m_player, SIGNAL(subtitleStreamChanged(int)), this, SLOT(tryReloadInternalSub())); connect(m_sub, SIGNAL(codecChanged()), this, SLOT(tryReload())); connect(m_sub, SIGNAL(enginesChanged()), this, SLOT(tryReload())); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_fileMenu(new QMenu(tr("&File"), this)), m_viewMenu(new QMenu(tr("&View"), this)), m_playbackMenu(new QMenu(tr("&Playback"), this)), m_transfersMenu(new QMenu(tr("&Downloads"), this)), m_editMenu(new QMenu(tr("&Edit"), this)), m_helpMenu(new QMenu(tr("&About"), this)), m_openFilesAction(new QAction(QIcon::fromTheme("document-open"), tr("&Open files"), this)), m_openUrlAction(new QAction(QIcon::fromTheme("folder-remote"), tr("Open &URL"), this)), m_addFilesAction(new QAction(QIcon::fromTheme("list-add"), tr("&Add files"), this)), m_addUrlAction(new QAction(QIcon::fromTheme("folder-remote"), tr("Add &URL"), this)), m_searchAction(new QAction(QIcon::fromTheme("edit-find"), tr("&Search"), this)), m_pluginsAction(new QAction(QIcon::fromTheme("view-refresh"), tr("Load &plugins"), this)), m_quitAction(new QAction(QIcon::fromTheme("application-exit"), tr("&Quit"), this)), m_showPlaybackQueueAction(new QAction(QIcon::fromTheme("music-library"), tr("Show &playback queue"), this)), m_showTransfersAction(new QAction(QIcon::fromTheme("folder-publicshare"), tr("Show &transfers"), this)), m_reloadAction(new QAction(QIcon::fromTheme("view-refresh"), tr("&Reload current tab"), this)), m_closeAction(new QAction(QIcon::fromTheme("list-remove"), tr("&Close current tab"), this)), m_playPauseAction(new QAction(QIcon::fromTheme("media-playback-start"), tr("&Play"), this)), m_stopAction(new QAction(QIcon::fromTheme("media-playback-stop"), tr("&Stop"), this)), m_previousAction(new QAction(QIcon::fromTheme("media-skip-backward"), tr("&Previous"), this)), m_nextAction(new QAction(QIcon::fromTheme("media-skip-forward"), tr("&Next"), this)), m_repeatAction(new QAction(QIcon::fromTheme("media-playlist-repeat"), tr("&Repeat"), this)), m_shuffleAction(new QAction(QIcon::fromTheme("media-playlist-shuffle"), tr("&Shuffle"), this)), m_stopAfterCurrentAction(new QAction(tr("Stop &after current track"), this)), m_clearAction(new QAction(QIcon::fromTheme("list-remove"), tr("&Clear playback queue"), this)), m_startTransfersAction(new QAction(QIcon::fromTheme("media-playback-start"), tr("&Start transfers"), this)), m_pauseTransfersAction(new QAction(QIcon::fromTheme("media-playback-pause"), tr("&Pause transfers"), this)), m_settingsAction(new QAction(QIcon::fromTheme("preferences-desktop"), tr("&Preferences"), this)), m_aboutAction(new QAction(QIcon::fromTheme("help-about"), tr("&About"), this)), m_positionSpacer(new QWidget(this)), m_positionSpacerAction(0), m_positionSlider(new QSlider(Qt::Horizontal, this)), m_positionSliderAction(0), m_positionLabel(new QLabel(this)), m_positionLabelAction(0), m_toolBar(new QToolBar(this)), m_widget(new QWidget(this)), m_tabWidget(new QTabWidget(m_widget)), m_nowPlayingMetaData(new ItemMetaData(m_widget)), m_layout(new QVBoxLayout(m_widget)) { setWindowTitle("MusiKloud2"); // Initialise status bar statusBar(); // Add menus menuBar()->addMenu(m_fileMenu); menuBar()->addMenu(m_viewMenu); menuBar()->addMenu(m_playbackMenu); menuBar()->addMenu(m_transfersMenu); menuBar()->addMenu(m_editMenu); menuBar()->addMenu(m_helpMenu); // Setup file menu m_fileMenu->addAction(m_openFilesAction); m_fileMenu->addAction(m_openUrlAction); m_fileMenu->addAction(m_addFilesAction); m_fileMenu->addAction(m_addUrlAction); m_fileMenu->addAction(m_searchAction); m_fileMenu->addSeparator(); m_fileMenu->addAction(m_pluginsAction); m_fileMenu->addAction(m_quitAction); // Setup file menu actions m_openFilesAction->setShortcut(tr("Ctrl+O")); m_openUrlAction->setShortcut(tr("Ctrl+U")); m_addFilesAction->setShortcut(tr("Ctrl+Shift+O")); m_addUrlAction->setShortcut(tr("Ctrl+Shift+U")); m_searchAction->setShortcut(tr("Ctrl+Y")); m_pluginsAction->setShortcut(tr("Ctrl+L")); m_quitAction->setShortcut(tr("Ctrl+Q")); // Setup view menu m_viewMenu->addAction(m_showPlaybackQueueAction); m_viewMenu->addAction(m_showTransfersAction); m_viewMenu->addSeparator(); m_viewMenu->addAction(m_reloadAction); m_viewMenu->addAction(m_closeAction); // Setup view menu actions m_reloadAction->setEnabled(false); m_closeAction->setShortcut(tr("Ctrl+W")); m_closeAction->setEnabled(false); // Setup playback menu m_playbackMenu->addAction(m_playPauseAction); m_playbackMenu->addAction(m_stopAction); m_playbackMenu->addAction(m_previousAction); m_playbackMenu->addAction(m_nextAction); m_playbackMenu->addSeparator(); m_playbackMenu->addAction(m_repeatAction); m_playbackMenu->addAction(m_shuffleAction); m_playbackMenu->addAction(m_stopAfterCurrentAction); m_playbackMenu->addSeparator(); m_playbackMenu->addAction(m_clearAction); // Setup playback menu actions m_playPauseAction->setShortcut(tr("Ctrl+Return")); m_stopAction->setShortcut(tr("Ctrl+.")); m_previousAction->setShortcut(tr("Alt+Up")); m_nextAction->setShortcut(tr("Alt+Down")); m_repeatAction->setCheckable(true); m_repeatAction->setShortcut(tr("Ctrl+R")); m_repeatAction->setToolTip(tr("Toggle repeat playback mode")); m_shuffleAction->setCheckable(true); m_shuffleAction->setShortcut(tr("Ctrl+S")); m_shuffleAction->setToolTip(tr("Toggle shuffle playback mode")); m_stopAfterCurrentAction->setCheckable(true); m_clearAction->setShortcut(tr("Ctrl+Shift+X")); // Setup transfers menu m_transfersMenu->addAction(m_startTransfersAction); m_transfersMenu->addAction(m_pauseTransfersAction); // Setup edit menu m_editMenu->addAction(m_settingsAction); // Setup edit menu actions m_settingsAction->setShortcut(tr("Ctrl+P")); // Setup help menu m_helpMenu->addAction(m_aboutAction); // Setup toolbar m_toolBar->setObjectName("mainToolBar"); m_toolBar->setWindowTitle(tr("Main toolbar")); m_toolBar->setMovable(false); m_toolBar->setAllowedAreas(Qt::TopToolBarArea); m_toolBar->addAction(m_openFilesAction); m_toolBar->addAction(m_addFilesAction); m_toolBar->addAction(m_searchAction); m_toolBar->addAction(m_previousAction); m_toolBar->addAction(m_nextAction); m_toolBar->addAction(m_playPauseAction); m_toolBar->addAction(m_stopAction); m_positionSpacerAction = m_toolBar->addWidget(m_positionSpacer); m_positionSliderAction = m_toolBar->addWidget(m_positionSlider); m_positionLabelAction = m_toolBar->addWidget(m_positionLabel); m_toolBar->addAction(m_repeatAction); m_toolBar->addAction(m_shuffleAction); addToolBar(Qt::TopToolBarArea, m_toolBar); // Setup position spacer, slider and label m_positionSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_positionSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_positionSliderAction->setVisible(false); m_positionLabel->setFixedWidth(m_positionLabel->fontMetrics().width("000:00 / 000:00")); m_positionLabel->setAlignment(Qt::AlignCenter); m_positionLabelAction->setVisible(false); // Setup tab widget m_tabWidget->setTabsClosable(true); m_tabWidget->tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectLeftTab); m_tabWidget->tabBar()->setExpanding(false); // Setup now playing metadata m_nowPlayingMetaData->setStyleSheet("font-weight: bold"); m_nowPlayingMetaData->setThumbnailSize(QSize(96, 96)); m_nowPlayingMetaData->hide(); // Setup layout m_layout->addWidget(m_tabWidget); m_layout->addWidget(m_nowPlayingMetaData); m_layout->setContentsMargins(0, 0, 0, 0); setCentralWidget(m_widget); // Restore window geometry/state restoreGeometry(Settings::mainWindowGeometry()); restoreState(Settings::mainWindowState()); // Connect signals and slots connect(AudioPlayer::instance(), SIGNAL(durationChanged(qint64)), this, SLOT(onPlayerDurationChanged(qint64))); connect(AudioPlayer::instance(), SIGNAL(metaDataChanged()), this, SLOT(updateNowPlayingMetaData())); connect(AudioPlayer::instance(), SIGNAL(positionChanged(qint64)), this, SLOT(onPlayerPositionChanged(qint64))); connect(AudioPlayer::instance(), SIGNAL(seekableChanged(bool)), this, SLOT(onPlayerSeekableChanged(bool))); connect(AudioPlayer::instance(), SIGNAL(statusChanged(AudioPlayer::Status)), this, SLOT(onPlayerStatusChanged(AudioPlayer::Status))); connect(m_openFilesAction, SIGNAL(triggered()), this, SLOT(openFiles())); connect(m_openUrlAction, SIGNAL(triggered()), this, SLOT(openUrl())); connect(m_addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles())); connect(m_addUrlAction, SIGNAL(triggered()), this, SLOT(addUrl())); connect(m_searchAction, SIGNAL(triggered()), this, SLOT(search())); connect(m_pluginsAction, SIGNAL(triggered()), this, SLOT(loadPlugins())); connect(m_quitAction, SIGNAL(triggered()), this, SLOT(close())); connect(m_showPlaybackQueueAction, SIGNAL(triggered()), this, SLOT(showPlaybackQueue())); connect(m_showTransfersAction, SIGNAL(triggered()), this, SLOT(showTransfers())); connect(m_reloadAction, SIGNAL(triggered()), this, SLOT(reloadCurrentTab())); connect(m_closeAction, SIGNAL(triggered()), this, SLOT(closeCurrentTab())); connect(m_playPauseAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(togglePlaying())); connect(m_stopAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(stop())); connect(m_previousAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(previous())); connect(m_nextAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(next())); connect(m_repeatAction, SIGNAL(triggered(bool)), AudioPlayer::instance(), SLOT(setRepeatEnabled(bool))); connect(m_shuffleAction, SIGNAL(triggered(bool)), AudioPlayer::instance(), SLOT(setShuffleEnabled(bool))); connect(m_stopAfterCurrentAction, SIGNAL(triggered(bool)), AudioPlayer::instance(), SLOT(setStopAfterCurrentTrack(bool))); connect(m_clearAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(clearQueue())); connect(m_startTransfersAction, SIGNAL(triggered()), Transfers::instance(), SLOT(start())); connect(m_pauseTransfersAction, SIGNAL(triggered()), Transfers::instance(), SLOT(pause())); connect(m_settingsAction, SIGNAL(triggered()), this, SLOT(showSettingsDialog())); connect(m_aboutAction, SIGNAL(triggered()), this, SLOT(showAboutDialog())); connect(m_positionSlider, SIGNAL(sliderReleased()), this, SLOT(updatePlayerPosition())); connect(m_positionSlider, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int))); connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(onTabStatusChanged())); connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); }
void PlayerWidget::onPlayerDurationChanged(qint64 duration) { m_ui->slider_Duration->setMaximum(duration); onPlayerPositionChanged(m_player->position()); }