Ensure one playlist at startup if no restoring. Minor code modifications to compatibility with code guidelines.
This commit is contained in:
parent
8ae713802d
commit
0a1e7916d8
@ -305,7 +305,10 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
|||||||
|
|
||||||
playlistManager_->SetTabWidget(ui_.tabWidget);
|
playlistManager_->SetTabWidget(ui_.tabWidget);
|
||||||
qDebug() << "restoring";
|
qDebug() << "restoring";
|
||||||
playlistManager_->Restore() ;
|
bool bRestored = playlistManager_->Restore() ;
|
||||||
|
if ( !bRestored )
|
||||||
|
playlistManager_->addPlaylist();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
@ -656,64 +659,29 @@ void MainWindow::AddStreamAccepted() {
|
|||||||
|
|
||||||
current_playlist_->InsertStreamUrls(urls);
|
current_playlist_->InsertStreamUrls(urls);
|
||||||
}
|
}
|
||||||
void MainWindow::NewPlaylist()
|
void MainWindow::NewPlaylist(){
|
||||||
{
|
|
||||||
playlistManager_->addPlaylist();
|
playlistManager_->addPlaylist();
|
||||||
// PlaylistView * playListView = new PlaylistView(ui_.tabWidget);
|
|
||||||
// playListView->setObjectName(QString::fromUtf8("playlist"));
|
|
||||||
// playListView->setAcceptDrops(true);
|
|
||||||
// playListView->setDragEnabled(true);
|
|
||||||
// playListView->setDragDropMode(QAbstractItemView::DragDrop);
|
|
||||||
// playListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
||||||
// playListView->setRootIsDecorated(false);
|
|
||||||
// playListView->setUniformRowHeights(true);
|
|
||||||
// playListView->setItemsExpandable(false);
|
|
||||||
// playListView->setSortingEnabled(true);
|
|
||||||
// playListView->setAllColumnsShowFocus(true);
|
|
||||||
// Playlist * playList = new Playlist(playListView) ;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// playList->IgnoreSorting(true);
|
|
||||||
// playListView->setModel(playList);
|
|
||||||
// playList->IgnoreSorting(false);
|
|
||||||
//
|
|
||||||
// QString title = playList->Title();
|
|
||||||
// if ( title.isEmpty() )
|
|
||||||
// title = tr("New playlist") ;
|
|
||||||
// ui_.tabWidget->addTab(playListView, tr("New playlist"));
|
|
||||||
//
|
|
||||||
// SetCurrentPlaylist(playListView);
|
|
||||||
|
|
||||||
// if (title.isEmpty()) {
|
|
||||||
// actual_title = tr("New playlist %1").arg(next_playlist_number_++);
|
|
||||||
// playlist->SetTitle(actual_title);
|
|
||||||
// } else {
|
|
||||||
// playlist->SetTitle(title);
|
|
||||||
// playlist->Restore();
|
|
||||||
// }
|
|
||||||
// ui_.tabWidget->addTab(playlist_view, actual_title);
|
|
||||||
}
|
}
|
||||||
void MainWindow::SetCurrentPlaylist(PlaylistView* pCurrent)
|
void MainWindow::SetCurrentPlaylist(PlaylistView* pCurrent){
|
||||||
{
|
|
||||||
// tab widget ;
|
// tab widget ;
|
||||||
//disconnects!!
|
//disconnects!!
|
||||||
|
if ( current_playlist_ != NULL && current_playlist_view_ != NULL ) {
|
||||||
disconnect(current_playlist_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song)));
|
disconnect(current_playlist_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song)));
|
||||||
disconnect(current_playlist_view_, SIGNAL(doubleClicked(QModelIndex)),this, SLOT(PlayIndex(QModelIndex)));
|
disconnect(current_playlist_view_, SIGNAL(doubleClicked(QModelIndex)),this, SLOT(PlayIndex(QModelIndex)));
|
||||||
disconnect(current_playlist_view_, SIGNAL(PlayPauseItem(QModelIndex)),this, SLOT(PlayIndex(QModelIndex)));
|
disconnect(current_playlist_view_, SIGNAL(PlayPauseItem(QModelIndex)),this, SLOT(PlayIndex(QModelIndex)));
|
||||||
disconnect(current_playlist_view_, SIGNAL(RightClicked(QPoint,QModelIndex)),this, SLOT(PlaylistRightClick(QPoint,QModelIndex)));
|
disconnect(current_playlist_view_, SIGNAL(RightClicked(QPoint,QModelIndex)),this, SLOT(PlaylistRightClick(QPoint,QModelIndex)));
|
||||||
disconnect(ui_.action_clear_playlist, SIGNAL(triggered()), current_playlist_, SLOT(Clear()));
|
disconnect(ui_.action_clear_playlist, SIGNAL(triggered()), current_playlist_, SLOT(Clear()));
|
||||||
disconnect(ui_.action_shuffle, SIGNAL(triggered()), current_playlist_, SLOT(Shuffle()));
|
disconnect(ui_.action_shuffle, SIGNAL(triggered()), current_playlist_, SLOT(Shuffle()));
|
||||||
disconnect(player_, SIGNAL(Paused()), current_playlist_, SLOT(Paused()));
|
disconnect(player_, SIGNAL(Paused()), current_playlist_, SLOT(Paused()));
|
||||||
disconnect(player_, SIGNAL(Playing()), current_playlist_, SLOT(Playing()));
|
disconnect(player_, SIGNAL(Playing()), current_playlist_, SLOT(Playing()));
|
||||||
disconnect(player_, SIGNAL(Stopped()), current_playlist_, SLOT(Stopped()));
|
disconnect(player_, SIGNAL(Stopped()), current_playlist_, SLOT(Stopped()));
|
||||||
|
|
||||||
disconnect(player_, SIGNAL(Paused()), current_playlist_view_, SLOT(StopGlowing()));
|
disconnect(player_, SIGNAL(Paused()), current_playlist_view_, SLOT(StopGlowing()));
|
||||||
disconnect(player_, SIGNAL(Playing()), current_playlist_view_, SLOT(StartGlowing()));
|
disconnect(player_, SIGNAL(Playing()), current_playlist_view_, SLOT(StartGlowing()));
|
||||||
disconnect(player_, SIGNAL(Stopped()), current_playlist_view_, SLOT(StopGlowing()));
|
disconnect(player_, SIGNAL(Stopped()), current_playlist_view_, SLOT(StopGlowing()));
|
||||||
|
|
||||||
disconnect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), current_playlist_, SLOT(SetStreamMetadata(QUrl,Song)));
|
disconnect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), current_playlist_, SLOT(SetStreamMetadata(QUrl,Song)));
|
||||||
|
}
|
||||||
|
|
||||||
// repin pointers
|
// repin pointers
|
||||||
|
|
||||||
@ -742,12 +710,10 @@ void MainWindow::SetCurrentPlaylist(PlaylistView* pCurrent)
|
|||||||
connect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), current_playlist_, SLOT(SetStreamMetadata(QUrl,Song)));
|
connect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), current_playlist_, SLOT(SetStreamMetadata(QUrl,Song)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::CurrentTabChanged(int index )
|
void MainWindow::CurrentTabChanged(int index ){
|
||||||
{
|
|
||||||
PlaylistView *pCurrent = qobject_cast< PlaylistView* >( ui_.tabWidget->currentWidget() );
|
PlaylistView *pCurrent = qobject_cast< PlaylistView* >( ui_.tabWidget->currentWidget() );
|
||||||
SetCurrentPlaylist(pCurrent);
|
SetCurrentPlaylist(pCurrent);
|
||||||
}
|
}
|
||||||
void MainWindow::CurrentPlaylistChanged(Playlist* pPlaylist)
|
void MainWindow::CurrentPlaylistChanged(Playlist* pPlaylist){
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,8 @@ pCurrentPlaylistView_(NULL),
|
|||||||
playlistCount_(0)
|
playlistCount_(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void PlaylistManager::addPlaylist(const QString & playlistName /*= QString()*/)
|
void PlaylistManager::addPlaylist(const QString & playlistName /*= QString()*/){
|
||||||
{
|
Q_ASSERT ( pTabWidget_ ) ;
|
||||||
Q_ASSERT ( pTabWidget_ != NULL ) ;
|
|
||||||
PlaylistView * playListView = new PlaylistView(pTabWidget_);
|
PlaylistView * playListView = new PlaylistView(pTabWidget_);
|
||||||
|
|
||||||
playListView->setObjectName(QString::fromUtf8("playlist"));
|
playListView->setObjectName(QString::fromUtf8("playlist"));
|
||||||
@ -29,7 +28,7 @@ void PlaylistManager::addPlaylist(const QString & playlistName /*= QString()*/)
|
|||||||
playListView->setSortingEnabled(true);
|
playListView->setSortingEnabled(true);
|
||||||
playListView->setAllColumnsShowFocus(true);
|
playListView->setAllColumnsShowFocus(true);
|
||||||
|
|
||||||
Playlist * playList = new Playlist(playListView) ;
|
Playlist* playList = new Playlist(playListView) ;
|
||||||
|
|
||||||
playList->IgnoreSorting(true);
|
playList->IgnoreSorting(true);
|
||||||
playListView->setModel(playList);
|
playListView->setModel(playList);
|
||||||
@ -48,24 +47,21 @@ void PlaylistManager::addPlaylist(const QString & playlistName /*= QString()*/)
|
|||||||
|
|
||||||
playlists_ << playList ;
|
playlists_ << playList ;
|
||||||
}
|
}
|
||||||
void PlaylistManager::SetCurrentPlaylist(Playlist* pPlaylist)
|
void PlaylistManager::SetCurrentPlaylist(Playlist* pPlaylist){
|
||||||
{
|
|
||||||
pCurrentPlaylist_ = pPlaylist ;
|
pCurrentPlaylist_ = pPlaylist ;
|
||||||
|
|
||||||
emit CurrentPlaylistChanged( pCurrentPlaylist_ ) ;
|
emit CurrentPlaylistChanged( pCurrentPlaylist_ ) ;
|
||||||
}
|
}
|
||||||
void PlaylistManager::Save() const
|
void PlaylistManager::Save() const{
|
||||||
{
|
|
||||||
QSettings s ;
|
QSettings s ;
|
||||||
Q_FOREACH ( Playlist *p, playlists_ ) {
|
Q_FOREACH ( Playlist* p, playlists_ ) {
|
||||||
qDebug() << "Saving" << p->GetTitle() ;
|
qDebug() << "Saving" << p->GetTitle() ;
|
||||||
p->SaveR() ;
|
p->SaveR() ;
|
||||||
}
|
}
|
||||||
s.setValue("numberofplaylists", playlistCount_ ) ;
|
s.setValue("numberofplaylists", playlistCount_ ) ;
|
||||||
}
|
}
|
||||||
void PlaylistManager::Restore()
|
bool PlaylistManager::Restore(){
|
||||||
{
|
Q_ASSERT ( pTabWidget_ ) ;
|
||||||
Q_ASSERT ( pTabWidget_ != NULL ) ;
|
|
||||||
QSettings s ;
|
QSettings s ;
|
||||||
bool bOk ;
|
bool bOk ;
|
||||||
int nOfPlaylist = s.value("numberofplaylists").toInt(&bOk) ;
|
int nOfPlaylist = s.value("numberofplaylists").toInt(&bOk) ;
|
||||||
@ -73,12 +69,12 @@ void PlaylistManager::Restore()
|
|||||||
qDebug() << nOfPlaylist ;
|
qDebug() << nOfPlaylist ;
|
||||||
if ( bOk == false || nOfPlaylist == 0 ) {
|
if ( bOk == false || nOfPlaylist == 0 ) {
|
||||||
qDebug()<< "No reading from settings";
|
qDebug()<< "No reading from settings";
|
||||||
return ;
|
return false;
|
||||||
}
|
}
|
||||||
int nCurrentIndex = -1 ;
|
int nCurrentIndex = -1 ;
|
||||||
for ( int i=0;i<nOfPlaylist;++i){
|
for ( int i=0;i<nOfPlaylist;++i){
|
||||||
|
|
||||||
PlaylistView * playListView = new PlaylistView(pTabWidget_);
|
PlaylistView* playListView = new PlaylistView(pTabWidget_);
|
||||||
|
|
||||||
playListView->setObjectName(QString::fromUtf8("playlist"));
|
playListView->setObjectName(QString::fromUtf8("playlist"));
|
||||||
playListView->setAcceptDrops(true);
|
playListView->setAcceptDrops(true);
|
||||||
@ -91,7 +87,7 @@ void PlaylistManager::Restore()
|
|||||||
playListView->setSortingEnabled(true);
|
playListView->setSortingEnabled(true);
|
||||||
playListView->setAllColumnsShowFocus(true);
|
playListView->setAllColumnsShowFocus(true);
|
||||||
|
|
||||||
Playlist * playList = new Playlist(playListView) ;
|
Playlist* playList = new Playlist(playListView) ;
|
||||||
|
|
||||||
playList->IgnoreSorting(true);
|
playList->IgnoreSorting(true);
|
||||||
playListView->setModel(playList);
|
playListView->setModel(playList);
|
||||||
@ -106,6 +102,7 @@ void PlaylistManager::Restore()
|
|||||||
pCurrentPlaylistView_ = playListView ;
|
pCurrentPlaylistView_ = playListView ;
|
||||||
playlists_ << playList ;
|
playlists_ << playList ;
|
||||||
}
|
}
|
||||||
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,23 +15,23 @@ class PlaylistManager : public QObject{
|
|||||||
|
|
||||||
// accessors
|
// accessors
|
||||||
void SetTabWidget( QTabWidget * pWidget ) { pTabWidget_ = pWidget ; }
|
void SetTabWidget( QTabWidget * pWidget ) { pTabWidget_ = pWidget ; }
|
||||||
QTabWidget * GetTabWidget() const {return pTabWidget_; }
|
QTabWidget* GetTabWidget() const {return pTabWidget_; }
|
||||||
|
|
||||||
void SetCurrentPlaylist ( Playlist * pPlaylist ) ;
|
void SetCurrentPlaylist ( Playlist * pPlaylist ) ;
|
||||||
|
|
||||||
void Save() const ;
|
void Save() const ;
|
||||||
void Restore() ;
|
bool Restore() ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Playlist*> playlists_ ;
|
QList<Playlist*> playlists_ ;
|
||||||
QTabWidget * pTabWidget_ ;
|
QTabWidget* pTabWidget_ ;
|
||||||
QList<QString> playlistNames_ ;
|
QList<QString> playlistNames_ ;
|
||||||
Playlist * pCurrentPlaylist_ ;
|
Playlist* pCurrentPlaylist_ ;
|
||||||
PlaylistView * pCurrentPlaylistView_ ;
|
PlaylistView* pCurrentPlaylistView_ ;
|
||||||
|
|
||||||
int playlistCount_ ;
|
int playlistCount_ ;
|
||||||
signals:
|
signals:
|
||||||
void CurrentPlaylistChanged( Playlist * pPlaylist ) ;
|
void CurrentPlaylistChanged( Playlist* pPlaylist ) ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYLISTMANAGER_H
|
#endif // PLAYLISTMANAGER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user