diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1286fc054..4cac042fc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -305,7 +305,10 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent) playlistManager_->SetTabWidget(ui_.tabWidget); qDebug() << "restoring"; - playlistManager_->Restore() ; + bool bRestored = playlistManager_->Restore() ; + if ( !bRestored ) + playlistManager_->addPlaylist(); + } MainWindow::~MainWindow() { @@ -656,64 +659,29 @@ void MainWindow::AddStreamAccepted() { current_playlist_->InsertStreamUrls(urls); } -void MainWindow::NewPlaylist() -{ +void MainWindow::NewPlaylist(){ 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 ; //disconnects!! - - 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(PlayPauseItem(QModelIndex)),this, SLOT(PlayIndex(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_shuffle, SIGNAL(triggered()), current_playlist_, SLOT(Shuffle())); - disconnect(player_, SIGNAL(Paused()), current_playlist_, SLOT(Paused())); - disconnect(player_, SIGNAL(Playing()), current_playlist_, SLOT(Playing())); - disconnect(player_, SIGNAL(Stopped()), current_playlist_, SLOT(Stopped())); + if ( current_playlist_ != NULL && current_playlist_view_ != NULL ) { + 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(PlayPauseItem(QModelIndex)),this, SLOT(PlayIndex(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_shuffle, SIGNAL(triggered()), current_playlist_, SLOT(Shuffle())); + disconnect(player_, SIGNAL(Paused()), current_playlist_, SLOT(Paused())); + disconnect(player_, SIGNAL(Playing()), current_playlist_, SLOT(Playing())); + disconnect(player_, SIGNAL(Stopped()), current_playlist_, SLOT(Stopped())); - disconnect(player_, SIGNAL(Paused()), current_playlist_view_, SLOT(StopGlowing())); - disconnect(player_, SIGNAL(Playing()), current_playlist_view_, SLOT(StartGlowing())); - disconnect(player_, SIGNAL(Stopped()), current_playlist_view_, SLOT(StopGlowing())); - - disconnect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), current_playlist_, SLOT(SetStreamMetadata(QUrl,Song))); + disconnect(player_, SIGNAL(Paused()), current_playlist_view_, SLOT(StopGlowing())); + disconnect(player_, SIGNAL(Playing()), current_playlist_view_, SLOT(StartGlowing())); + disconnect(player_, SIGNAL(Stopped()), current_playlist_view_, SLOT(StopGlowing())); + + disconnect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), current_playlist_, SLOT(SetStreamMetadata(QUrl,Song))); + } // repin pointers @@ -742,12 +710,10 @@ void MainWindow::SetCurrentPlaylist(PlaylistView* pCurrent) 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() ); SetCurrentPlaylist(pCurrent); } -void MainWindow::CurrentPlaylistChanged(Playlist* pPlaylist) -{ +void MainWindow::CurrentPlaylistChanged(Playlist* pPlaylist){ } diff --git a/src/playlistmanager.cpp b/src/playlistmanager.cpp index 596f5d3b6..1c595430a 100644 --- a/src/playlistmanager.cpp +++ b/src/playlistmanager.cpp @@ -13,9 +13,8 @@ pCurrentPlaylistView_(NULL), playlistCount_(0) { } -void PlaylistManager::addPlaylist(const QString & playlistName /*= QString()*/) -{ - Q_ASSERT ( pTabWidget_ != NULL ) ; +void PlaylistManager::addPlaylist(const QString & playlistName /*= QString()*/){ + Q_ASSERT ( pTabWidget_ ) ; PlaylistView * playListView = new PlaylistView(pTabWidget_); playListView->setObjectName(QString::fromUtf8("playlist")); @@ -29,7 +28,7 @@ void PlaylistManager::addPlaylist(const QString & playlistName /*= QString()*/) playListView->setSortingEnabled(true); playListView->setAllColumnsShowFocus(true); - Playlist * playList = new Playlist(playListView) ; + Playlist* playList = new Playlist(playListView) ; playList->IgnoreSorting(true); playListView->setModel(playList); @@ -48,24 +47,21 @@ void PlaylistManager::addPlaylist(const QString & playlistName /*= QString()*/) playlists_ << playList ; } -void PlaylistManager::SetCurrentPlaylist(Playlist* pPlaylist) -{ +void PlaylistManager::SetCurrentPlaylist(Playlist* pPlaylist){ pCurrentPlaylist_ = pPlaylist ; emit CurrentPlaylistChanged( pCurrentPlaylist_ ) ; } -void PlaylistManager::Save() const -{ +void PlaylistManager::Save() const{ QSettings s ; - Q_FOREACH ( Playlist *p, playlists_ ) { + Q_FOREACH ( Playlist* p, playlists_ ) { qDebug() << "Saving" << p->GetTitle() ; p->SaveR() ; } s.setValue("numberofplaylists", playlistCount_ ) ; } -void PlaylistManager::Restore() -{ - Q_ASSERT ( pTabWidget_ != NULL ) ; +bool PlaylistManager::Restore(){ + Q_ASSERT ( pTabWidget_ ) ; QSettings s ; bool bOk ; int nOfPlaylist = s.value("numberofplaylists").toInt(&bOk) ; @@ -73,12 +69,12 @@ void PlaylistManager::Restore() qDebug() << nOfPlaylist ; if ( bOk == false || nOfPlaylist == 0 ) { qDebug()<< "No reading from settings"; - return ; + return false; } int nCurrentIndex = -1 ; for ( int i=0;isetObjectName(QString::fromUtf8("playlist")); playListView->setAcceptDrops(true); @@ -91,7 +87,7 @@ void PlaylistManager::Restore() playListView->setSortingEnabled(true); playListView->setAllColumnsShowFocus(true); - Playlist * playList = new Playlist(playListView) ; + Playlist* playList = new Playlist(playListView) ; playList->IgnoreSorting(true); playListView->setModel(playList); @@ -106,6 +102,7 @@ void PlaylistManager::Restore() pCurrentPlaylistView_ = playListView ; playlists_ << playList ; } + return true ; } diff --git a/src/playlistmanager.h b/src/playlistmanager.h index 4b1107051..df13582cd 100644 --- a/src/playlistmanager.h +++ b/src/playlistmanager.h @@ -15,23 +15,23 @@ class PlaylistManager : public QObject{ // accessors void SetTabWidget( QTabWidget * pWidget ) { pTabWidget_ = pWidget ; } - QTabWidget * GetTabWidget() const {return pTabWidget_; } + QTabWidget* GetTabWidget() const {return pTabWidget_; } void SetCurrentPlaylist ( Playlist * pPlaylist ) ; void Save() const ; - void Restore() ; + bool Restore() ; private: QList playlists_ ; - QTabWidget * pTabWidget_ ; + QTabWidget* pTabWidget_ ; QList playlistNames_ ; - Playlist * pCurrentPlaylist_ ; - PlaylistView * pCurrentPlaylistView_ ; + Playlist* pCurrentPlaylist_ ; + PlaylistView* pCurrentPlaylistView_ ; int playlistCount_ ; signals: - void CurrentPlaylistChanged( Playlist * pPlaylist ) ; + void CurrentPlaylistChanged( Playlist* pPlaylist ) ; }; #endif // PLAYLISTMANAGER_H