AmarokEngineScript::AmarokEngineScript( QScriptEngine* ScriptEngine ) : QObject( kapp ) { Q_UNUSED( ScriptEngine ); connect( The::engineController(), SIGNAL( trackChanged( Meta::TrackPtr ) ), this, SIGNAL( trackChanged() ) ); connect( The::engineController(), SIGNAL( trackFinished() ), this, SIGNAL( trackFinished() ) ); connect( The::engineController(), SIGNAL( trackSeeked( int ) ), this, SIGNAL( trackSeeked( int ) ) ); connect( The::engineController(), SIGNAL( volumeChanged( int ) ), this, SIGNAL( volumeChanged( int ) ) ); connect( The::engineController(), SIGNAL( trackPlayPause( int ) ), this, SIGNAL( trackPlayPause( int ) ) ); }
void K3b::MusicBrainzJob::slotMbJobFinished( bool success ) { if( hasBeenCanceled() ) { emit canceled(); jobFinished(false); } else { K3b::AudioTrack* currentTrack = d->tracks.at( d->currentTrackIndex ); if( success ) { // found entries QStringList resultStrings, resultStringsUnique; for( int i = 0; i < d->mbTrackLookupJob->results(); ++i ) resultStrings.append( d->mbTrackLookupJob->artist(i) + " - " + d->mbTrackLookupJob->title(i) ); // since we are only using the title and the artist a lot of entries are alike to us // so to not let the user have to choose between two equal entries we trim the list down for( QStringList::const_iterator it = resultStrings.constBegin(); it != resultStrings.constEnd(); ++it ) if( !resultStringsUnique.contains( *it ) ) resultStringsUnique.append( *it ); QString s; bool ok = true; if( resultStringsUnique.count() > 1 ) s = KInputDialog::getItem( i18n("MusicBrainz Query"), i18n("Found multiple matches for track %1 (%2). Please select one.", currentTrack->trackNumber(), currentTrack->firstSource()->sourceComment()), resultStringsUnique, 0, false, &ok, dynamic_cast<QWidget*>(parent()) ); else s = resultStringsUnique.first(); if( ok ) { int i = resultStrings.lastIndexOf( s ); currentTrack->setTitle( d->mbTrackLookupJob->title(i) ); currentTrack->setArtist( d->mbTrackLookupJob->artist(i) ); } } emit trackFinished( currentTrack, success ); // query next track ++d->currentTrackIndex; if( d->currentTrackIndex < d->tracks.count() ) { d->mbTrackLookupJob->setAudioTrack( d->tracks.at( d->currentTrackIndex ) ); d->mbTrackLookupJob->start(); } else { jobFinished( true ); } } }
//slot void AnalyserQueue::slotUpdateProgress() { if (m_progressInfo.current_track) { m_progressInfo.current_track->setAnalyserProgress(m_progressInfo.track_progress); } emit(trackProgress(m_progressInfo.track_progress/10)); if (m_progressInfo.track_progress == 1000) { emit(trackFinished(m_progressInfo.queue_size)); } m_progressInfo.sema.release(); }
Player::Player(QWidget *parent): QMainWindow(parent), _ui(new Ui::Player), _player(new Phonon::MediaObject(this)), _audioOutput(new Phonon::AudioOutput(Phonon::MusicCategory, this)), _trayIcon(new QSystemTrayIcon(this)), _isStopped(false), _isPaused(false), _artistToPlaylistAction(new QAction(tr("Add to playlist"), this)), _artistsMenu(new QMenu(this)), _albumToPlaylistAction(new QAction(tr("Add to playlist"), this)), _albumsMenu(new QMenu(this)), _trackToPlaylistAction(new QAction(tr("Add to playlist"), this)), _tracksMenu(new QMenu(this)), _removeTrackAction(new QAction(tr("Remove track"), this)), _playlistMenu(new QMenu(this)), _playAction(new QAction(tr("Play"), this)), _pauseAction(new QAction(tr("Pause"), this)), _playNextAction(new QAction(tr("Play next"), this)), _playPrevAction(new QAction(tr("Play previous"), this)), _stopAction(new QAction(tr("Stop"), this)), _trayMenu(new QMenu(this)), _lastFMDialog(new LastFMAuthDialog(this)) { _ui->setupUi(this); this->setWindowIcon(QIcon(":/icon.png")); this->setWindowTitle(qApp->applicationName()); _ui->pauseButton->setHidden(true); fixHeader(_ui->tracks->horizontalHeader()); fixHeader(_ui->playlist->horizontalHeader()); _ui->tracks->verticalHeader()->setDefaultSectionSize(_ui->artists->sizeHintForRow(0) + 4); _ui->playlist->verticalHeader()->setDefaultSectionSize(_ui->artists->sizeHintForRow(0) + 4); _ui->previousButton->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaSkipBackward)); _ui->playButton->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaPlay)); _ui->pauseButton->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaPause)); _ui->stopButton->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaStop)); _ui->nextButton->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaSkipForward)); _playPrevAction->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaSkipBackward)); _playAction->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaPlay)); _pauseAction->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaPause)); _pauseAction->setVisible(false); _stopAction->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaStop)); _playNextAction->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaSkipForward)); _ui->actionQuit->setIcon(qApp->style()->standardIcon(QStyle::SP_DialogCloseButton)); _trayMenu->addAction(_playAction); _trayMenu->addAction(_pauseAction); _trayMenu->addAction(_playPrevAction); _trayMenu->addAction(_playNextAction); _trayMenu->addAction(_stopAction); _trayMenu->addAction(_ui->actionQuit); _trayIcon->setContextMenu(_trayMenu); _trayIcon->setIcon(QIcon(":/icon.png")); _trayIcon->show(); Phonon::createPath(_player, _audioOutput); _ui->seekSlider->setMediaObject(_player); _ui->volumeSlider->setAudioOutput(_audioOutput); _artistsMenu->addAction(_artistToPlaylistAction); _albumsMenu->addAction(_albumToPlaylistAction); _tracksMenu->addAction(_trackToPlaylistAction); _playlistMenu->addAction(_removeTrackAction); connect(_ui->actionQuit, SIGNAL(triggered()), qApp, SLOT(quit())); connect(_ui->actionAdd_directory, SIGNAL(triggered()), this, SLOT(addDirToLibrary())); connect(_ui->actionAdd_files, SIGNAL(triggered()), this, SLOT(addFilesToLibrary())); connect(_ui->actionClear_playlist, SIGNAL(triggered()), this, SLOT(clearPlaylist())); connect(_ui->actionLoad_playlist, SIGNAL(triggered()), this, SLOT(loadPlaylist())); connect(_ui->actionSave_playlist, SIGNAL(triggered()), this, SLOT(savePlaylist())); connect(_ui->nextButton, SIGNAL(clicked()), this, SLOT(playNext())); connect(_ui->playButton, SIGNAL(clicked()), this, SLOT(play())); connect(_ui->tracks, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(playSelected())); connect(_ui->playlist, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(playSelected())); connect(_ui->stopButton, SIGNAL(clicked()), this, SLOT(stop())); connect(_ui->pauseButton, SIGNAL(clicked()), this, SLOT(pause())); connect(_ui->stopButton, SIGNAL(clicked()), _player, SLOT(stop())); connect(_ui->previousButton, SIGNAL(clicked()), this, SLOT(playPrevious())); connect(_playAction, SIGNAL(triggered()), this, SLOT(play())); connect(_pauseAction, SIGNAL(triggered()), _player, SLOT(pause())); connect(_stopAction, SIGNAL(triggered()), _player, SLOT(stop())); connect(_playNextAction, SIGNAL(triggered()), this, SLOT(playNext())); connect(_playPrevAction, SIGNAL(triggered()), this, SLOT(playPrevious())); connect(_ui->artists, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showArtistsContextMenu(const QPoint &))); connect(_ui->albums, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showAlbumsContextMenu(const QPoint &))); connect(_ui->tracks, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showTracksContextMenu(const QPoint &))); connect(_ui->playlist, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showPlaylistContextMenu(const QPoint &))); connect(DataBase::instance(), SIGNAL(albumsUpdated()), this, SLOT(updateAlbums())); connect(DataBase::instance(), SIGNAL(artistsUpdated()), this, SLOT(updateArtists())); connect(DataBase::instance(), SIGNAL(tracksUpdated()), this, SLOT(updateTracks())); connect(_ui->artists, SIGNAL(currentRowChanged(int)), this, SLOT(updateAlbums())); connect(_ui->albums, SIGNAL(currentRowChanged(int)), this, SLOT(updateTracks())); connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason))); connect(_player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(stateChanged(Phonon::State,Phonon::State))); connect(_player, SIGNAL(tick(qint64)), this, SLOT(tick(qint64))); connect(_player, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); connect(_player, SIGNAL(finished()), this, SLOT(trackFinished())); connect(_ui->actionSettings, SIGNAL(triggered()), _lastFMDialog, SLOT(show())); connect(_ui->actionScrobbling, SIGNAL(toggled(bool)), this, SLOT(scrobblingToggled(bool))); connect(Settings::instance(), SIGNAL(scrobblingChanged(bool)), _ui->actionScrobbling, SLOT(setChecked(bool))); _allArtists = _ui->artists->item(0); _allArtists->setText(ALL); _allAlbums = _ui->albums->item(0); _allAlbums->setText(ALL); loadPlaylist(RECENTPLAYLIST); _ui->actionScrobbling->setChecked(Settings::instance()->isScrobblingEnabled()); _ui->actionSettings->setEnabled(Settings::instance()->isScrobblingEnabled()); scrobblingToggled(Settings::instance()->isScrobblingEnabled()); }
bool QSpotifySession::event(QEvent *e) { if (e->type() == NotifyMainThreadEventType) { // qDebug() << "Process spotify event"; processSpotifyEvents(); e->accept(); return true; } else if (e->type() == QEvent::Timer) { // qDebug() << "Timer, start spotify events"; QTimerEvent *te = static_cast<QTimerEvent *>(e); if (te->timerId() == m_timerID) { processSpotifyEvents(); e->accept(); return true; } } else if (e->type() == ConnectionErrorEventType) { qDebug() << "Connection error"; QSpotifyConnectionErrorEvent *ev = static_cast<QSpotifyConnectionErrorEvent *>(e); setConnectionError(ConnectionError(ev->error()), QString::fromUtf8(sp_error_message(ev->error()))); e->accept(); return true; } else if (e->type() == MetaDataEventType) { // qDebug() << "Meta data"; emit metadataUpdated(); e->accept(); return true; } else if (e->type() == EndOfTrackEventType) { // qDebug() << "End track"; m_trackChangedAutomatically = true; emit trackFinished(); // playNext(); e->accept(); return true; } else if (e->type() == StopEventType) { // qDebug() << "Stop"; stop(); e->accept(); return true; } else if (e->type() == TrackProgressEventType) { // qDebug() << "Track progress"; if(!m_isPlaying) { e->accept(); return true; } // Track progressed QSpotifyTrackProgressEvent *ev = static_cast<QSpotifyTrackProgressEvent *>(e); int currentTrackPositionDelta = ev->delta(); if (m_previousTrackRemaining > 0) { // We're still playing the previous back from our buffer int fromPreviousTrack = qMin(currentTrackPositionDelta, m_previousTrackRemaining); currentTrackPositionDelta -= fromPreviousTrack; m_previousTrackRemaining -= fromPreviousTrack; } m_currentTrackPosition += currentTrackPositionDelta; m_currentTrackPlayedDuration += currentTrackPositionDelta; emit currentTrackPositionChanged(); e->accept(); return true; } else if (e->type() == SendImageRequestEventType) { QSpotifyRequestImageEvent *ev = static_cast<QSpotifyRequestImageEvent *>(e); sendImageRequest(ev->imageId()); e->accept(); return true; } else if (e->type() == ReceiveImageRequestEventType) { QSpotifyReceiveImageEvent *ev = static_cast<QSpotifyReceiveImageEvent *>(e); receiveImageResponse(ev->image()); e->accept(); return true; } else if (e->type() == PlayTokenLostEventType) { // qDebug() << "Play token lost"; emit playTokenLost(); pause(); e->accept(); return true; } else if (e->type() == LoggedInEventType) { qDebug() << "Logged in 1"; onLoggedIn(); e->accept(); return true; } else if (e->type() == LoggedOutEventType) { qDebug() << "Logged out"; onLoggedOut(); e->accept(); return true; } else if (e->type() == OfflineErrorEventType) { qDebug() << "Offline error"; QSpotifyOfflineErrorEvent *ev = static_cast<QSpotifyOfflineErrorEvent *>(e); m_offlineErrorMessage = QString::fromUtf8(sp_error_message(ev->error())); emit offlineErrorMessageChanged(); e->accept(); return true; } else if (e->type() == ScrobbleLoginErrorEventType) { qDebug() << "Scrobble login error"; m_lfmLoggedIn = false; emit lfmLoggedInChanged(); emit lfmLoginError(); e->accept(); return true; } else if (e->type() == ConnectionStateUpdateEventType) { qDebug() << "Connectionstate update event"; setConnectionStatus(ConnectionStatus(sp_session_connectionstate(m_sp_session))); if (m_offlineMode && m_connectionStatus == LoggedIn) { setConnectionRules(m_connectionRules | AllowNetwork); setConnectionRules(m_connectionRules & ~AllowNetwork); } e->accept(); return true; } return QObject::event(e); }