Playlist manager for handling multiple playlists. Storing/restoring is enabled.
This commit is contained in:
parent
1aebf19077
commit
8ae713802d
@ -54,6 +54,7 @@ set(CLEMENTINE-SOURCES
|
|||||||
albumcovermanager.cpp
|
albumcovermanager.cpp
|
||||||
albumcoverloader.cpp
|
albumcoverloader.cpp
|
||||||
m3uparser.cpp
|
m3uparser.cpp
|
||||||
|
playlistmanager.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Header files that have Q_OBJECT in
|
# Header files that have Q_OBJECT in
|
||||||
@ -101,6 +102,7 @@ set(CLEMENTINE-MOC-HEADERS
|
|||||||
albumcovermanager.h
|
albumcovermanager.h
|
||||||
albumcoverloader.h
|
albumcoverloader.h
|
||||||
m3uparser.h
|
m3uparser.h
|
||||||
|
playlistmanager.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# UI files
|
# UI files
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "stylesheetloader.h"
|
#include "stylesheetloader.h"
|
||||||
#include "albumcovermanager.h"
|
#include "albumcovermanager.h"
|
||||||
#include "m3uparser.h"
|
#include "m3uparser.h"
|
||||||
|
#include "playlistmanager.h"
|
||||||
|
|
||||||
#include "qxtglobalshortcut.h"
|
#include "qxtglobalshortcut.h"
|
||||||
|
|
||||||
@ -38,6 +39,7 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
|
||||||
const int MainWindow::kStateVersion = 1;
|
const int MainWindow::kStateVersion = 1;
|
||||||
const char* MainWindow::kSettingsGroup = "MainWindow";
|
const char* MainWindow::kSettingsGroup = "MainWindow";
|
||||||
const char* MainWindow::kMediaFilterSpec =
|
const char* MainWindow::kMediaFilterSpec =
|
||||||
@ -64,7 +66,8 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
|||||||
playlist_menu_(new QMenu(this)),
|
playlist_menu_(new QMenu(this)),
|
||||||
library_sort_model_(new QSortFilterProxyModel(this)),
|
library_sort_model_(new QSortFilterProxyModel(this)),
|
||||||
track_position_timer_(new QTimer(this)),
|
track_position_timer_(new QTimer(this)),
|
||||||
next_playlist_number_(1)
|
next_playlist_number_(1),
|
||||||
|
playlistManager_( new PlaylistManager(this) )
|
||||||
{
|
{
|
||||||
ui_.setupUi(this);
|
ui_.setupUi(this);
|
||||||
tray_icon_->setIcon(windowIcon());
|
tray_icon_->setIcon(windowIcon());
|
||||||
@ -146,6 +149,9 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
|||||||
connect(player_, SIGNAL(Paused()), osd_, SLOT(Paused()));
|
connect(player_, SIGNAL(Paused()), osd_, SLOT(Paused()));
|
||||||
connect(player_, SIGNAL(Stopped()), osd_, SLOT(Stopped()));
|
connect(player_, SIGNAL(Stopped()), osd_, SLOT(Stopped()));
|
||||||
connect(player_, SIGNAL(VolumeChanged(int)), osd_, SLOT(VolumeChanged(int)));
|
connect(player_, SIGNAL(VolumeChanged(int)), osd_, SLOT(VolumeChanged(int)));
|
||||||
|
|
||||||
|
// PlaylistManager connections
|
||||||
|
connect (playlistManager_, SIGNAL(CurrentPlaylistChanged(Playlist*)), this, SLOT(CurrentPlaylistChanged(Playlist*)));
|
||||||
|
|
||||||
connect(track_slider_, SIGNAL(ValueChanged(int)), player_, SLOT(Seek(int)));
|
connect(track_slider_, SIGNAL(ValueChanged(int)), player_, SLOT(Seek(int)));
|
||||||
|
|
||||||
@ -211,6 +217,7 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
|||||||
connect(radio_model_, SIGNAL(StreamError(QString)), SLOT(ReportError(QString)));
|
connect(radio_model_, SIGNAL(StreamError(QString)), SLOT(ReportError(QString)));
|
||||||
connect(radio_model_, SIGNAL(StreamFinished()), player_, SLOT(NextItem()));
|
connect(radio_model_, SIGNAL(StreamFinished()), player_, SLOT(NextItem()));
|
||||||
connect(radio_model_, SIGNAL(StreamReady(QUrl,QUrl)), player_, SLOT(StreamReady(QUrl,QUrl)));
|
connect(radio_model_, SIGNAL(StreamReady(QUrl,QUrl)), player_, SLOT(StreamReady(QUrl,QUrl)));
|
||||||
|
connect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), current_playlist_, SLOT(SetStreamMetadata(QUrl,Song)));
|
||||||
connect(radio_model_, SIGNAL(AddItemToPlaylist(RadioItem*)), SLOT(InsertRadioItem(RadioItem*)));
|
connect(radio_model_, SIGNAL(AddItemToPlaylist(RadioItem*)), SLOT(InsertRadioItem(RadioItem*)));
|
||||||
connect(radio_model_->GetLastFMService(), SIGNAL(ScrobblingEnabledChanged(bool)), SLOT(ScrobblingEnabledChanged(bool)));
|
connect(radio_model_->GetLastFMService(), SIGNAL(ScrobblingEnabledChanged(bool)), SLOT(ScrobblingEnabledChanged(bool)));
|
||||||
connect(ui_.radio_view, SIGNAL(doubleClicked(QModelIndex)), SLOT(RadioDoubleClick(QModelIndex)));
|
connect(ui_.radio_view, SIGNAL(doubleClicked(QModelIndex)), SLOT(RadioDoubleClick(QModelIndex)));
|
||||||
@ -295,25 +302,17 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
library_->StartThreads();
|
library_->StartThreads();
|
||||||
|
|
||||||
settings_.endGroup();
|
playlistManager_->SetTabWidget(ui_.tabWidget);
|
||||||
settings_.beginGroup(Playlist::kSettingsGroup);
|
qDebug() << "restoring";
|
||||||
foreach (const QString& group, settings_.childGroups()) {
|
playlistManager_->Restore() ;
|
||||||
QRegExp re(" \\d+");
|
|
||||||
if (re.indexIn(group) != -1) {
|
|
||||||
next_playlist_number_ = qMax(re.cap(0).toInt() + 1, next_playlist_number_);
|
|
||||||
}
|
|
||||||
NewPlaylist(group);
|
|
||||||
}
|
|
||||||
if (settings_.childGroups().isEmpty()) {
|
|
||||||
NewPlaylist();
|
|
||||||
}
|
|
||||||
settings_.endGroup();
|
|
||||||
settings_.beginGroup(kSettingsGroup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
SaveGeometry();
|
SaveGeometry();
|
||||||
|
playlistManager_->Save() ;
|
||||||
|
|
||||||
|
delete player_ ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::HideShowTrayIcon() {
|
void MainWindow::HideShowTrayIcon() {
|
||||||
@ -657,48 +656,53 @@ void MainWindow::AddStreamAccepted() {
|
|||||||
|
|
||||||
current_playlist_->InsertStreamUrls(urls);
|
current_playlist_->InsertStreamUrls(urls);
|
||||||
}
|
}
|
||||||
|
void MainWindow::NewPlaylist()
|
||||||
void MainWindow::NewPlaylist(const QString& title) {
|
{
|
||||||
PlaylistView* playlist_view = new PlaylistView(ui_.tabWidget);
|
playlistManager_->addPlaylist();
|
||||||
playlist_view->setObjectName(QString::fromUtf8("playlist"));
|
// PlaylistView * playListView = new PlaylistView(ui_.tabWidget);
|
||||||
playlist_view->setAcceptDrops(true);
|
// playListView->setObjectName(QString::fromUtf8("playlist"));
|
||||||
playlist_view->setDragEnabled(true);
|
// playListView->setAcceptDrops(true);
|
||||||
playlist_view->setDragDropMode(QAbstractItemView::DragDrop);
|
// playListView->setDragEnabled(true);
|
||||||
playlist_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
// playListView->setDragDropMode(QAbstractItemView::DragDrop);
|
||||||
playlist_view->setRootIsDecorated(false);
|
// playListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
playlist_view->setUniformRowHeights(true);
|
// playListView->setRootIsDecorated(false);
|
||||||
playlist_view->setItemsExpandable(false);
|
// playListView->setUniformRowHeights(true);
|
||||||
playlist_view->setSortingEnabled(true);
|
// playListView->setItemsExpandable(false);
|
||||||
playlist_view->setAllColumnsShowFocus(true);
|
// playListView->setSortingEnabled(true);
|
||||||
Playlist* playlist = new Playlist(playlist_view) ;
|
// playListView->setAllColumnsShowFocus(true);
|
||||||
|
// Playlist * playList = new Playlist(playListView) ;
|
||||||
playlist->IgnoreSorting(true);
|
//
|
||||||
playlist_view->setModel(playlist);
|
//
|
||||||
playlist->IgnoreSorting(false);
|
//
|
||||||
|
// playList->IgnoreSorting(true);
|
||||||
QString actual_title = title;
|
// playListView->setModel(playList);
|
||||||
if (title.isEmpty()) {
|
// playList->IgnoreSorting(false);
|
||||||
actual_title = tr("New playlist %1").arg(next_playlist_number_++);
|
//
|
||||||
playlist->SetTitle(actual_title);
|
// QString title = playList->Title();
|
||||||
} else {
|
// if ( title.isEmpty() )
|
||||||
playlist->SetTitle(title);
|
// title = tr("New playlist") ;
|
||||||
playlist->Restore();
|
// ui_.tabWidget->addTab(playListView, tr("New playlist"));
|
||||||
}
|
//
|
||||||
ui_.tabWidget->addTab(playlist_view, actual_title);
|
// SetCurrentPlaylist(playListView);
|
||||||
|
|
||||||
SetCurrentPlaylist(playlist_view);
|
// 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* current) {
|
{
|
||||||
// Disconnect current playlist and tab.
|
// tab widget ;
|
||||||
if (current_playlist_) {
|
//disconnects!!
|
||||||
|
|
||||||
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)),
|
disconnect(current_playlist_view_, SIGNAL(doubleClicked(QModelIndex)),this, SLOT(PlayIndex(QModelIndex)));
|
||||||
this, SLOT(PlayIndex(QModelIndex)));
|
disconnect(current_playlist_view_, SIGNAL(PlayPauseItem(QModelIndex)),this, SLOT(PlayIndex(QModelIndex)));
|
||||||
disconnect(current_playlist_view_, SIGNAL(PlayPauseItem(QModelIndex)),
|
disconnect(current_playlist_view_, SIGNAL(RightClicked(QPoint,QModelIndex)),this, SLOT(PlaylistRightClick(QPoint,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_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()));
|
||||||
@ -708,35 +712,42 @@ void MainWindow::SetCurrentPlaylist(PlaylistView* current) {
|
|||||||
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)));
|
||||||
|
|
||||||
|
// repin pointers
|
||||||
|
|
||||||
|
ui_.tabWidget->setCurrentWidget(pCurrent);
|
||||||
|
current_playlist_view_ = pCurrent ;
|
||||||
|
current_playlist_ = qobject_cast< Playlist* >( pCurrent->model() );
|
||||||
|
player_->SetCurrentPlaylist(current_playlist_);
|
||||||
|
|
||||||
|
|
||||||
|
// connects !! :)
|
||||||
|
|
||||||
|
connect(current_playlist_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song)));
|
||||||
|
connect(current_playlist_view_, SIGNAL(doubleClicked(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
||||||
|
connect(current_playlist_view_, SIGNAL(PlayPauseItem(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
||||||
|
connect(current_playlist_view_, SIGNAL(RightClicked(QPoint,QModelIndex)), SLOT(PlaylistRightClick(QPoint,QModelIndex)));
|
||||||
|
connect(ui_.action_clear_playlist, SIGNAL(triggered()), current_playlist_, SLOT(Clear()));
|
||||||
|
connect(ui_.action_shuffle, SIGNAL(triggered()), current_playlist_, SLOT(Shuffle()));
|
||||||
|
connect(player_, SIGNAL(Paused()), current_playlist_, SLOT(Paused()));
|
||||||
|
connect(player_, SIGNAL(Playing()), current_playlist_, SLOT(Playing()));
|
||||||
|
connect(player_, SIGNAL(Stopped()), current_playlist_, SLOT(Stopped()));
|
||||||
|
|
||||||
// Repin pointers.
|
connect(player_, SIGNAL(Paused()), current_playlist_view_, SLOT(StopGlowing()));
|
||||||
ui_.tabWidget->setCurrentWidget(current);
|
connect(player_, SIGNAL(Playing()), current_playlist_view_, SLOT(StartGlowing()));
|
||||||
current_playlist_view_ = current;
|
connect(player_, SIGNAL(Stopped()), current_playlist_view_, SLOT(StopGlowing()));
|
||||||
current_playlist_ = qobject_cast<Playlist*>(current->model());
|
|
||||||
player_->SetCurrentPlaylist(current_playlist_);
|
connect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), current_playlist_, SLOT(SetStreamMetadata(QUrl,Song)));
|
||||||
|
|
||||||
// Connect new playlist and tab.
|
|
||||||
connect(current_playlist_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song)));
|
|
||||||
connect(current_playlist_view_, SIGNAL(doubleClicked(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
|
||||||
connect(current_playlist_view_, SIGNAL(PlayPauseItem(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
|
||||||
connect(current_playlist_view_, SIGNAL(RightClicked(QPoint,QModelIndex)),
|
|
||||||
SLOT(PlaylistRightClick(QPoint,QModelIndex)));
|
|
||||||
connect(ui_.action_clear_playlist, SIGNAL(triggered()), current_playlist_, SLOT(Clear()));
|
|
||||||
connect(ui_.action_shuffle, SIGNAL(triggered()), current_playlist_, SLOT(Shuffle()));
|
|
||||||
connect(player_, SIGNAL(Paused()), current_playlist_, SLOT(Paused()));
|
|
||||||
connect(player_, SIGNAL(Playing()), current_playlist_, SLOT(Playing()));
|
|
||||||
connect(player_, SIGNAL(Stopped()), current_playlist_, SLOT(Stopped()));
|
|
||||||
|
|
||||||
connect(player_, SIGNAL(Paused()), current_playlist_view_, SLOT(StopGlowing()));
|
|
||||||
connect(player_, SIGNAL(Playing()), current_playlist_view_, SLOT(StartGlowing()));
|
|
||||||
connect(player_, SIGNAL(Stopped()), current_playlist_view_, SLOT(StopGlowing()));
|
|
||||||
|
|
||||||
connect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)),
|
|
||||||
current_playlist_, SLOT(SetStreamMetadata(QUrl,Song)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::CurrentTabChanged(int index) {
|
void MainWindow::CurrentTabChanged(int index )
|
||||||
PlaylistView* current = qobject_cast<PlaylistView*>(ui_.tabWidget->currentWidget());
|
{
|
||||||
SetCurrentPlaylist(current);
|
PlaylistView *pCurrent = qobject_cast< PlaylistView* >( ui_.tabWidget->currentWidget() );
|
||||||
|
SetCurrentPlaylist(pCurrent);
|
||||||
|
}
|
||||||
|
void MainWindow::CurrentPlaylistChanged(Playlist* pPlaylist)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
|
class PlaylistManager;
|
||||||
class Playlist;
|
class Playlist;
|
||||||
class PlaylistView;
|
class PlaylistView;
|
||||||
class Player;
|
class Player;
|
||||||
@ -83,10 +84,12 @@ class MainWindow : public QMainWindow {
|
|||||||
void AddMedia();
|
void AddMedia();
|
||||||
void AddStream();
|
void AddStream();
|
||||||
void AddStreamAccepted();
|
void AddStreamAccepted();
|
||||||
|
|
||||||
void NewPlaylist(const QString& title = QString());
|
void NewPlaylist() ;
|
||||||
|
|
||||||
void CurrentTabChanged(int);
|
void CurrentTabChanged ( int ) ;
|
||||||
|
|
||||||
|
void CurrentPlaylistChanged( Playlist * pPlaylist ) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SaveGeometry();
|
void SaveGeometry();
|
||||||
@ -129,7 +132,7 @@ class MainWindow : public QMainWindow {
|
|||||||
|
|
||||||
QTimer* track_position_timer_;
|
QTimer* track_position_timer_;
|
||||||
QSettings settings_;
|
QSettings settings_;
|
||||||
|
PlaylistManager * playlistManager_ ;
|
||||||
int next_playlist_number_;
|
int next_playlist_number_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,7 +25,9 @@ Playlist::Playlist(QObject *parent) :
|
|||||||
current_is_paused_(false),
|
current_is_paused_(false),
|
||||||
scrobble_point_(-1),
|
scrobble_point_(-1),
|
||||||
has_scrobbled_(false),
|
has_scrobbled_(false),
|
||||||
ignore_sorting_(false)
|
ignore_sorting_(false),
|
||||||
|
title_(""),
|
||||||
|
index_(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +208,7 @@ bool Playlist::dropMimeData(const QMimeData* data, Qt::DropAction action, int ro
|
|||||||
}
|
}
|
||||||
|
|
||||||
layoutChanged();
|
layoutChanged();
|
||||||
Save();
|
// Save();
|
||||||
|
|
||||||
} else if (data->hasUrls()) {
|
} else if (data->hasUrls()) {
|
||||||
// URL list dragged from the file list or some other app
|
// URL list dragged from the file list or some other app
|
||||||
@ -270,7 +272,7 @@ QModelIndex Playlist::InsertItems(const QList<PlaylistItem*>& items, int after)
|
|||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
Save();
|
// Save();
|
||||||
|
|
||||||
return index(start, 0);
|
return index(start, 0);
|
||||||
}
|
}
|
||||||
@ -370,7 +372,7 @@ void Playlist::sort(int column, Qt::SortOrder order) {
|
|||||||
|
|
||||||
layoutChanged();
|
layoutChanged();
|
||||||
|
|
||||||
Save();
|
// Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Playlist::Playing() {
|
void Playlist::Playing() {
|
||||||
@ -396,11 +398,11 @@ void Playlist::SetCurrentIsPaused(bool paused) {
|
|||||||
index(current_item_.row(), ColumnCount));
|
index(current_item_.row(), ColumnCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Playlist::Save() const {
|
void Playlist::SaveR() const {
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(kSettingsGroup);
|
Q_ASSERT(index_ != -1 ) ;
|
||||||
s.beginGroup(title_);
|
QString setGrp = kSettingsGroup + QString::number(index_) ;
|
||||||
|
s.beginGroup(setGrp);
|
||||||
s.beginWriteArray("items", items_.count());
|
s.beginWriteArray("items", items_.count());
|
||||||
for (int i=0 ; i<items_.count() ; ++i) {
|
for (int i=0 ; i<items_.count() ; ++i) {
|
||||||
s.setArrayIndex(i);
|
s.setArrayIndex(i);
|
||||||
@ -408,15 +410,16 @@ void Playlist::Save() const {
|
|||||||
items_.at(i)->Save(s);
|
items_.at(i)->Save(s);
|
||||||
}
|
}
|
||||||
s.endArray();
|
s.endArray();
|
||||||
|
s.setValue("title",title_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Playlist::Restore() {
|
void Playlist::RestoreR() {
|
||||||
qDeleteAll(items_);
|
qDeleteAll(items_);
|
||||||
items_.clear();
|
items_.clear();
|
||||||
|
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(kSettingsGroup);
|
QString setGrp = kSettingsGroup + QString::number(index_) ;
|
||||||
s.beginGroup(title_);
|
s.beginGroup(setGrp);
|
||||||
|
|
||||||
int count = s.beginReadArray("items");
|
int count = s.beginReadArray("items");
|
||||||
for (int i=0 ; i<count ; ++i) {
|
for (int i=0 ; i<count ; ++i) {
|
||||||
@ -431,7 +434,7 @@ void Playlist::Restore() {
|
|||||||
items_ << item;
|
items_ << item;
|
||||||
}
|
}
|
||||||
s.endArray();
|
s.endArray();
|
||||||
|
title_ = s.value("title").toString();
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,7 +447,7 @@ bool Playlist::removeRows(int row, int count, const QModelIndex& parent) {
|
|||||||
|
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
Save();
|
// Save();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,7 +538,7 @@ void Playlist::Clear() {
|
|||||||
items_.clear();
|
items_.clear();
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
Save();
|
// Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Playlist::ReloadItems(const QList<int>& rows) {
|
void Playlist::ReloadItems(const QList<int>& rows) {
|
||||||
@ -564,5 +567,5 @@ void Playlist::Shuffle() {
|
|||||||
|
|
||||||
layoutChanged();
|
layoutChanged();
|
||||||
|
|
||||||
Save();
|
// Save();
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ class RadioService;
|
|||||||
class Playlist : public QAbstractListModel {
|
class Playlist : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
friend class PlaylistManager ;
|
||||||
public:
|
public:
|
||||||
Playlist(QObject* parent = 0);
|
Playlist(QObject* parent = 0);
|
||||||
~Playlist();
|
~Playlist();
|
||||||
@ -48,9 +49,7 @@ class Playlist : public QAbstractListModel {
|
|||||||
static bool CompareItems(int column, Qt::SortOrder order,
|
static bool CompareItems(int column, Qt::SortOrder order,
|
||||||
const PlaylistItem* a, const PlaylistItem* b);
|
const PlaylistItem* a, const PlaylistItem* b);
|
||||||
|
|
||||||
// Persistence
|
|
||||||
void Save() const;
|
|
||||||
void Restore();
|
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
int current_index() const;
|
int current_index() const;
|
||||||
@ -64,8 +63,11 @@ class Playlist : public QAbstractListModel {
|
|||||||
PlaylistItem::Options current_item_options() const;
|
PlaylistItem::Options current_item_options() const;
|
||||||
Song current_item_metadata() const;
|
Song current_item_metadata() const;
|
||||||
|
|
||||||
const QString& Title() const { return title_; }
|
const QString & GetTitle() const { return title_ ; }
|
||||||
void SetTitle(const QString& title) { title_ = title; }
|
void SetTitle(const QString& title) { title_ = title; }
|
||||||
|
|
||||||
|
void SetPlaylistIndex( int ipos ) { index_ = ipos ; }
|
||||||
|
int GetPlaylistIndex() const { return index_ ; }
|
||||||
|
|
||||||
// Scrobbling
|
// Scrobbling
|
||||||
int scrobble_point() const { return scrobble_point_; }
|
int scrobble_point() const { return scrobble_point_; }
|
||||||
@ -113,6 +115,10 @@ class Playlist : public QAbstractListModel {
|
|||||||
private:
|
private:
|
||||||
void SetCurrentIsPaused(bool paused);
|
void SetCurrentIsPaused(bool paused);
|
||||||
void UpdateScrobblePoint();
|
void UpdateScrobblePoint();
|
||||||
|
|
||||||
|
// Persistence
|
||||||
|
void SaveR() const;
|
||||||
|
void RestoreR();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<PlaylistItem*> items_;
|
QList<PlaylistItem*> items_;
|
||||||
@ -127,6 +133,7 @@ class Playlist : public QAbstractListModel {
|
|||||||
// Hack to stop QTreeView::setModel sorting the playlist
|
// Hack to stop QTreeView::setModel sorting the playlist
|
||||||
bool ignore_sorting_;
|
bool ignore_sorting_;
|
||||||
QString title_;
|
QString title_;
|
||||||
|
int index_ ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYLIST_H
|
#endif // PLAYLIST_H
|
||||||
|
112
src/playlistmanager.cpp
Normal file
112
src/playlistmanager.cpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#include "playlistmanager.h"
|
||||||
|
#include "playlistview.h"
|
||||||
|
#include "playlist.h"
|
||||||
|
|
||||||
|
#include <QAbstractItemView>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
PlaylistManager::PlaylistManager(QObject* parent): QObject(parent),
|
||||||
|
pTabWidget_( NULL ),
|
||||||
|
pCurrentPlaylist_(NULL),
|
||||||
|
pCurrentPlaylistView_(NULL),
|
||||||
|
playlistCount_(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void PlaylistManager::addPlaylist(const QString & playlistName /*= QString()*/)
|
||||||
|
{
|
||||||
|
Q_ASSERT ( pTabWidget_ != NULL ) ;
|
||||||
|
PlaylistView * playListView = new PlaylistView(pTabWidget_);
|
||||||
|
|
||||||
|
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->GetTitle();
|
||||||
|
playlistCount_++ ;
|
||||||
|
if ( title.isEmpty() )
|
||||||
|
title = tr("New playlist") + QString::number(playlistCount_) ;
|
||||||
|
playList->SetPlaylistIndex( playlistCount_) ;
|
||||||
|
playList->SetTitle(title);
|
||||||
|
pTabWidget_->addTab(playListView, title);
|
||||||
|
|
||||||
|
SetCurrentPlaylist(playList);
|
||||||
|
pCurrentPlaylistView_ = playListView ;
|
||||||
|
|
||||||
|
playlists_ << playList ;
|
||||||
|
}
|
||||||
|
void PlaylistManager::SetCurrentPlaylist(Playlist* pPlaylist)
|
||||||
|
{
|
||||||
|
pCurrentPlaylist_ = pPlaylist ;
|
||||||
|
|
||||||
|
emit CurrentPlaylistChanged( pCurrentPlaylist_ ) ;
|
||||||
|
}
|
||||||
|
void PlaylistManager::Save() const
|
||||||
|
{
|
||||||
|
QSettings s ;
|
||||||
|
Q_FOREACH ( Playlist *p, playlists_ ) {
|
||||||
|
qDebug() << "Saving" << p->GetTitle() ;
|
||||||
|
p->SaveR() ;
|
||||||
|
}
|
||||||
|
s.setValue("numberofplaylists", playlistCount_ ) ;
|
||||||
|
}
|
||||||
|
void PlaylistManager::Restore()
|
||||||
|
{
|
||||||
|
Q_ASSERT ( pTabWidget_ != NULL ) ;
|
||||||
|
QSettings s ;
|
||||||
|
bool bOk ;
|
||||||
|
int nOfPlaylist = s.value("numberofplaylists").toInt(&bOk) ;
|
||||||
|
playlistCount_ = nOfPlaylist ;
|
||||||
|
qDebug() << nOfPlaylist ;
|
||||||
|
if ( bOk == false || nOfPlaylist == 0 ) {
|
||||||
|
qDebug()<< "No reading from settings";
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
int nCurrentIndex = -1 ;
|
||||||
|
for ( int i=0;i<nOfPlaylist;++i){
|
||||||
|
|
||||||
|
PlaylistView * playListView = new PlaylistView(pTabWidget_);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
playList->SetPlaylistIndex( i+1 ) ;
|
||||||
|
playList->RestoreR() ;
|
||||||
|
|
||||||
|
pTabWidget_->addTab( playListView, playList->GetTitle() );
|
||||||
|
|
||||||
|
SetCurrentPlaylist(playList);
|
||||||
|
pCurrentPlaylistView_ = playListView ;
|
||||||
|
playlists_ << playList ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
37
src/playlistmanager.h
Normal file
37
src/playlistmanager.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef PLAYLISTMANAGER_H
|
||||||
|
#define PLAYLISTMANAGER_H
|
||||||
|
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
class PlaylistView;
|
||||||
|
class QTabWidget;
|
||||||
|
class Playlist;
|
||||||
|
|
||||||
|
class PlaylistManager : public QObject{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
PlaylistManager(QObject* parent = 0);
|
||||||
|
void addPlaylist( const QString& playlistName = QString() ) ;
|
||||||
|
|
||||||
|
// accessors
|
||||||
|
void SetTabWidget( QTabWidget * pWidget ) { pTabWidget_ = pWidget ; }
|
||||||
|
QTabWidget * GetTabWidget() const {return pTabWidget_; }
|
||||||
|
|
||||||
|
void SetCurrentPlaylist ( Playlist * pPlaylist ) ;
|
||||||
|
|
||||||
|
void Save() const ;
|
||||||
|
void Restore() ;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Playlist*> playlists_ ;
|
||||||
|
QTabWidget * pTabWidget_ ;
|
||||||
|
QList<QString> playlistNames_ ;
|
||||||
|
Playlist * pCurrentPlaylist_ ;
|
||||||
|
PlaylistView * pCurrentPlaylistView_ ;
|
||||||
|
|
||||||
|
int playlistCount_ ;
|
||||||
|
signals:
|
||||||
|
void CurrentPlaylistChanged( Playlist * pPlaylist ) ;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PLAYLISTMANAGER_H
|
Loading…
x
Reference in New Issue
Block a user