aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2013-12-14 15:12:20 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2013-12-14 15:12:20 +0000
commit92f1159a134f4d9dbd93176107afc48e4f77cb81 (patch)
tree4aa971c42e00d36cc8d588273f3ad0ff6b46fb16 /src/qmmpui
parent8351bd6fbf8b9b6b3360a0cfd6546127794d0b89 (diff)
downloadqmmp-92f1159a134f4d9dbd93176107afc48e4f77cb81.tar.gz
qmmp-92f1159a134f4d9dbd93176107afc48e4f77cb81.tar.bz2
qmmp-92f1159a134f4d9dbd93176107afc48e4f77cb81.zip
fixed saving of the playlist settings (Fixes issue 622)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3960 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui')
-rw-r--r--src/qmmpui/mediaplayer.cpp51
-rw-r--r--src/qmmpui/mediaplayer.h36
-rw-r--r--src/qmmpui/playlistmanager.cpp105
-rw-r--r--src/qmmpui/playlistmanager.h48
-rw-r--r--src/qmmpui/playlistmodel.cpp47
-rw-r--r--src/qmmpui/playlistmodel.h42
-rw-r--r--src/qmmpui/playstate.cpp18
-rw-r--r--src/qmmpui/playstate_p.h9
-rw-r--r--src/qmmpui/qmmpuisettings.cpp105
-rw-r--r--src/qmmpui/qmmpuisettings.h88
10 files changed, 251 insertions, 298 deletions
diff --git a/src/qmmpui/mediaplayer.cpp b/src/qmmpui/mediaplayer.cpp
index fbe61d74e..b00771579 100644
--- a/src/qmmpui/mediaplayer.cpp
+++ b/src/qmmpui/mediaplayer.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008-2012 by Ilya Kotov *
+ * Copyright (C) 2008-2013 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -37,8 +37,6 @@ MediaPlayer::MediaPlayer(QObject *parent)
m_pl_manager = 0;
m_core = 0;
m_skips = 0;
- m_repeat = false;
- m_noPlaylistAdvance = false;
QTranslator *translator = new QTranslator(parent);
QString locale = Qmmp::systemLanguageID();
translator->load(QString(":/libqmmpui_") + locale);
@@ -67,16 +65,6 @@ PlayListManager *MediaPlayer::playListManager()
return m_pl_manager;
}
-bool MediaPlayer::isRepeatable() const
-{
- return m_repeat;
-}
-
-bool MediaPlayer::isNoPlaylistAdvance() const
-{
- return m_noPlaylistAdvance;
-}
-
void MediaPlayer::play(qint64 offset)
{
m_pl_manager->currentPlayList()->doCurrentVisibleRequest();
@@ -126,28 +114,14 @@ void MediaPlayer::previous()
play();
}
-void MediaPlayer::setRepeatable(bool r)
+void MediaPlayer::playNext()
{
- if (r != m_repeat)
+ if(m_settings->isRepeatableTrack())
{
- if(r)
- {
- disconnect(m_core, SIGNAL(finished()), this, SLOT(playNext()));
- connect(m_core, SIGNAL(finished()), SLOT(play()));
- }
- else
- {
- disconnect(m_core, SIGNAL(finished()), this, SLOT(play()));
- connect(m_core, SIGNAL(finished()), SLOT(playNext()));
- }
- m_repeat = r;
- emit repeatableChanged(r);
+ play();
+ return;
}
-}
-
-void MediaPlayer::playNext()
-{
- if(m_noPlaylistAdvance)
+ if(m_settings->isNoPlaylistAdvance())
{
stop();
return;
@@ -160,22 +134,13 @@ void MediaPlayer::playNext()
play();
}
-void MediaPlayer::setNoPlaylistAdvance(bool enabled)
-{
- if (enabled != m_noPlaylistAdvance)
- {
- m_noPlaylistAdvance = enabled;
- emit noPlaylistAdvanceChanged(enabled);
- }
-}
-
void MediaPlayer::updateNextUrl()
{
m_nextUrl.clear();
PlayListTrack *track = 0;
- if(isRepeatable())
+ if(m_settings->isRepeatableTrack())
track = m_pl_manager->currentPlayList()->currentTrack();
- else if(!m_noPlaylistAdvance)
+ else if(!m_settings->isNoPlaylistAdvance())
track = m_pl_manager->currentPlayList()->nextTrack();
if(track)
diff --git a/src/qmmpui/mediaplayer.h b/src/qmmpui/mediaplayer.h
index 1e302ddb2..2d2162527 100644
--- a/src/qmmpui/mediaplayer.h
+++ b/src/qmmpui/mediaplayer.h
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008-2012 by Ilya Kotov *
+ * Copyright (C) 2008-2013 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -52,14 +52,6 @@ public:
* Returns playlist manager pointer
*/
PlayListManager *playListManager();
- /*!
- * Returns \b true if "Repeate Track" option is enabled, otherwise returns \b false
- */
- bool isRepeatable() const;
- /*!
- * Returns \b true if "No playlist advance" option is enabled, otherwise returns \b false
- */
- bool isNoPlaylistAdvance() const;
public slots:
/*!
@@ -78,30 +70,6 @@ public slots:
* Sets previous playlist item for playing.
*/
void previous();
- /*!
- * Toggles the current track repeat.
- * @param enable Repeate state of the current track (\b true - to repeat, \b false - to stop repeating)
- */
- void setRepeatable(bool enable);
- /*!
- * When finished playing a song, don't automatically advance to the next
- * @param enable State of the 'No playlist advance' option
- * (\b true - enabled, \b false - normal playback)
- */
- void setNoPlaylistAdvance(bool enable);
-
-signals:
- /*!
- * Tracks current track repeat state;
- * @param enabled New repeate state of the current track (\b true - enabled, \b false - disabled)
- */
- void repeatableChanged(bool enabled);
- /*!
- * Emitted when state of the "No playlist advance" option changes.
- * @param enabled New state of this option (\b true - no playlist advance,
- * \b false - normal playlist behaviour)
- */
- void noPlaylistAdvanceChanged(bool enabled);
private slots:
void playNext();
@@ -114,8 +82,6 @@ private:
PlayListManager *m_pl_manager;
SoundCore *m_core;
static MediaPlayer* m_instance;
- bool m_repeat;
- bool m_noPlaylistAdvance;
int m_skips;
QString m_nextUrl;
};
diff --git a/src/qmmpui/playlistmanager.cpp b/src/qmmpui/playlistmanager.cpp
index a49698a6e..1a7e8a382 100644
--- a/src/qmmpui/playlistmanager.cpp
+++ b/src/qmmpui/playlistmanager.cpp
@@ -35,29 +35,19 @@ PlayListManager::PlayListManager(QObject *parent) : QObject(parent)
if(m_instance)
qFatal("PlayListManager: only one instance is allowed");
m_instance = this;
+ m_ui_settings = new QmmpUiSettings(this);
m_current = 0;
m_selected = 0;
- m_repeatable = false;
- m_shuffle = false;
- m_autosave_playlist = false;
- m_groups_enabled = false;
- m_update = false;
m_timer = new QTimer(this);
m_timer->setInterval(5000);
m_timer->setSingleShot(true);
-
connect(m_timer, SIGNAL(timeout()), SLOT(writePlayLists()));
- readSettings(); //read settings
readPlayLists(); //read playlists
}
PlayListManager::~PlayListManager()
{
writePlayLists();
- QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
- settings.setValue("Playlist/repeatable", m_repeatable);
- settings.setValue("Playlist/shuffle", m_shuffle);
- settings.setValue("Playlist/groups", m_groups_enabled);
m_instance = 0;
}
@@ -175,12 +165,8 @@ PlayListModel *PlayListManager::createPlayList(const QString &name)
model->setName(pl_name);
}
m_models.append(model);
- model->prepareForRepeatablePlaying(m_repeatable);
- model->prepareForShufflePlaying(m_shuffle);
- model->prepareGroups(m_groups_enabled);
connect(model, SIGNAL(nameChanged(QString)), SIGNAL(playListsChanged()));
- if (m_autosave_playlist)
- connect(model, SIGNAL(countChanged()), m_timer, SLOT(start()));
+ connect(model, SIGNAL(countChanged()), SLOT(onCountChanged()));
emit playListAdded(m_models.indexOf(model));
emit playListsChanged();
return model;
@@ -226,26 +212,6 @@ void PlayListManager::move(int i, int j)
}
}
-void PlayListManager::setRepeatableList(bool r)
-{
- if(m_repeatable == r)
- return;
- m_repeatable = r;
- foreach(PlayListModel *model, m_models)
- model->prepareForRepeatablePlaying(r);
- emit repeatableListChanged(r);
-}
-
-void PlayListManager::setShuffle(bool s)
-{
- if(m_shuffle == s)
- return;
- m_shuffle = s;
- foreach(PlayListModel *model, m_models)
- model->prepareForShufflePlaying(s);
- emit shuffleChanged(s);
-}
-
int PlayListManager::count() const
{
return m_models.count();
@@ -263,21 +229,6 @@ PlayListModel *PlayListManager::playListAt(int i) const
return 0;
}
-bool PlayListManager::isRepeatableList() const
-{
- return m_repeatable;
-}
-
-bool PlayListManager::isShuffle() const
-{
- return m_shuffle;
-}
-
-bool PlayListManager::isGroupsEnabled() const
-{
- return m_groups_enabled;
-}
-
void PlayListManager::readPlayLists()
{
QString line, param, value;
@@ -311,8 +262,6 @@ void PlayListManager::readPlayLists()
tracks.clear();
current = 0;
m_models << new PlayListModel(value, this);
- if(m_groups_enabled)
- m_models.last()->prepareGroups(true);
}
else if (param == "current")
{
@@ -350,8 +299,6 @@ void PlayListManager::readPlayLists()
if(m_models.isEmpty())
{
m_models << new PlayListModel(tr("Playlist"),this);
- if(m_groups_enabled)
- m_models.last()->prepareGroups(true);
}
else if(!tracks.isEmpty())
{
@@ -365,12 +312,7 @@ void PlayListManager::readPlayLists()
foreach(PlayListModel *model, m_models)
{
connect(model, SIGNAL(nameChanged(QString)), SIGNAL(playListsChanged()));
- if (m_autosave_playlist)
- connect(model, SIGNAL(countChanged()), m_timer, SLOT(start()));
- if(m_repeatable)
- model->prepareForRepeatablePlaying(true);
- if(m_shuffle)
- model->prepareForShufflePlaying(true);
+ connect(model, SIGNAL(countChanged()), SLOT(onCountChanged()));
}
}
@@ -410,6 +352,12 @@ void PlayListManager::writePlayLists()
file.close();
}
+void PlayListManager::onCountChanged()
+{
+ if(m_ui_settings->autoSavePlayList())
+ m_timer->start();
+}
+
void PlayListManager::clear()
{
m_selected->clear();
@@ -504,38 +452,3 @@ void PlayListManager::stopAfterSelected()
{
m_selected->stopAfterSelected();
}
-
-void PlayListManager::setGroupsEnabled(bool enabled)
-{
- if(m_groups_enabled == enabled)
- return;
-
- m_groups_enabled = enabled;
- foreach(PlayListModel *model, m_models)
- model->prepareGroups(enabled);
-}
-
-void PlayListManager::readSettings()
-{
- if(!m_update)
- {
- m_update = true;
- QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
- setRepeatableList(settings.value("Playlist/repeatable",false).toBool());
- setShuffle(settings.value("Playlist/shuffle",false).toBool());
- setGroupsEnabled(settings.value("Playlist/groups",false).toBool());
- }
-
- QmmpUiSettings *ui_settings = QmmpUiSettings::instance();
- if (m_autosave_playlist != ui_settings->autoSavePlayList())
- {
- m_autosave_playlist = ui_settings->autoSavePlayList();
- foreach(PlayListModel *model, m_models)
- {
- if (m_autosave_playlist)
- connect(model, SIGNAL(countChanged()), m_timer, SLOT(start()), Qt::UniqueConnection);
- else
- disconnect(model, SIGNAL(countChanged()), m_timer, SLOT(start()));
- }
- }
-}
diff --git a/src/qmmpui/playlistmanager.h b/src/qmmpui/playlistmanager.h
index dce8ba8bf..520d7c876 100644
--- a/src/qmmpui/playlistmanager.h
+++ b/src/qmmpui/playlistmanager.h
@@ -24,6 +24,7 @@
#include "playlistmodel.h"
class QTimer;
+class QmmpUiSettings;
/*! @brief The PlayListManager class is used to handle multiple playlists.
* @author Ilya Kotov <forkotov02@hotmail.ru>
@@ -82,18 +83,6 @@ public:
* \b i must be a valid index position in the list (i.e., 0 <= i < count()).
*/
PlayListModel *playListAt(int i) const;
- /*!
- * Returns state of "Repeat All" option.
- */
- bool isRepeatableList() const;
- /*!
- * Returns state of "Shuffle" option.
- */
- bool isShuffle() const;
- /*!
- * Returns \b true if the playlist groups are enabled. Otherwise returns \b false.
- */
- bool isGroupsEnabled() const;
signals:
/*!
@@ -124,16 +113,7 @@ signals:
* Emitted when the list of playlists is changed.
*/
void playListsChanged();
- /*!
- * Emitted when state of the "Repeat All" option has changed.
- * @param state New state of the "Repeat All" option (\b true - enabled, \b false disabled)
- */
- void repeatableListChanged(bool state);
- /*!
- * Emitted when state of the "Shuffle" option has changed.
- * @param state New state of the "Shuffle" option (\b true - enabled, \b false disabled)
- */
- void shuffleChanged(bool state);
+
public slots:
/*!
@@ -181,16 +161,6 @@ public slots:
*/
void move(int i, int j);
/*!
- * Prepares all playlists for repeatable playing (loop mode).
- * @param r State of the repeatable mode (\b true - enabled, \b false - disabled)
- */
- void setRepeatableList(bool r);
- /*!
- * Prepares all playlists for shuffle playing.
- * @param s State of the shuffle mode (\b true - enabled, \b false - disabled)
- */
- void setShuffle(bool s);
- /*!
* This is a convenience function and is the same as calling \b selectedPlayList()->clear()
*/
void clear();
@@ -266,18 +236,10 @@ public slots:
* This is a convenience function and is the same as calling \b selectedPlayList()->stopAfterSelected()
*/
void stopAfterSelected();
- /*!
- * Enables or disables playlist groups
- * * @param enabled State of the groups (\b true - enabled, \b false - disabled)
- */
- void setGroupsEnabled(bool enabled);
- /*!
- * Read the relevant settings.
- */
- void readSettings();
private slots:
void writePlayLists();
+ void onCountChanged();
private:
void readPlayLists();
@@ -285,10 +247,8 @@ private:
QList <PlayListModel *> m_models;
PlayListModel *m_current;
PlayListModel *m_selected;
- bool m_repeatable, m_shuffle, m_autosave_playlist;
- bool m_groups_enabled;
QTimer *m_timer;
- bool m_update;
+ QmmpUiSettings *m_ui_settings;
};
#endif // PLAYLISTMANAGER_H
diff --git a/src/qmmpui/playlistmodel.cpp b/src/qmmpui/playlistmodel.cpp
index aa39e3ece..fbf543f2e 100644
--- a/src/qmmpui/playlistmodel.cpp
+++ b/src/qmmpui/playlistmodel.cpp
@@ -31,6 +31,7 @@
#include "playstate_p.h"
#include "detailsdialog.h"
#include "tagupdater_p.h"
+#include "qmmpuisettings.h"
#include "playlistmodel.h"
#define INVALID_INDEX -1
@@ -39,16 +40,22 @@ PlayListModel::PlayListModel(const QString &name, QObject *parent)
: QObject(parent) , m_selection()
{
qsrand(time(0));
- m_name = name;
- m_shuffle = false;
+ m_ui_settings = QmmpUiSettings::instance();
m_total_length = 0;
m_current = 0;
- m_is_repeatable_list = false;
- m_groups_enabled = false;
m_stop_track = 0;
- m_play_state = new NormalPlayState(this);
+ m_name = name;
m_loader = new FileLoader(this);
- m_container = new NormalContainer;
+ if(m_ui_settings->isGroupsEnabled())
+ m_container = new GroupedContainer;
+ else
+ m_container = new NormalContainer;
+ if(m_ui_settings->isShuffle())
+ m_play_state = new ShufflePlayState(this);
+ else
+ m_play_state = new NormalPlayState(this);
+ connect(m_ui_settings, SIGNAL(groupsChanged(bool)), SLOT(prepareGroups(bool)));
+ connect(m_ui_settings, SIGNAL(shuffleChanged(bool)), SLOT(prepareForShufflePlaying(bool)));
connect(m_loader, SIGNAL(newTrackToAdd(PlayListTrack*)),
SLOT(add(PlayListTrack*)), Qt::QueuedConnection);
connect(m_loader, SIGNAL(newTrackToInsert(PlayListItem*, PlayListTrack*)),
@@ -91,7 +98,7 @@ void PlayListModel::add(PlayListTrack *track)
m_current = m_container->indexOf(track);
emit currentChanged();
}
- else if(m_groups_enabled)
+ else if(m_ui_settings->isGroupsEnabled())
{
//update current index for grouped container only
m_current = m_container->indexOf(m_current_track);
@@ -116,7 +123,7 @@ void PlayListModel::add(QList<PlayListTrack *> tracks)
m_current = m_container->indexOf(track);
emit currentChanged();
}
- else if(m_groups_enabled)
+ else if(m_ui_settings->isGroupsEnabled())
{
//update current index for grouped container only
m_current = m_container->indexOf(m_current_track);
@@ -772,13 +779,6 @@ void PlayListModel::prepareForShufflePlaying(bool val)
m_play_state = new ShufflePlayState(this);
else
m_play_state = new NormalPlayState(this);
-
- m_shuffle = val;
-}
-
-void PlayListModel::prepareForRepeatablePlaying(bool val)
-{
- m_is_repeatable_list = val;
}
void PlayListModel::prepareGroups(bool enabled)
@@ -793,7 +793,6 @@ void PlayListModel::prepareGroups(bool enabled)
m_container = container;
if(!m_container->isEmpty())
m_current = m_container->indexOf(m_current_track);
- m_groups_enabled = enabled;
emit listChanged();
}
@@ -820,16 +819,6 @@ void PlayListModel::savePlaylist(const QString &f_name)
PlayListParser::savePlayList(songs, f_name);
}
-bool PlayListModel::isRepeatableList() const
-{
- return m_is_repeatable_list;
-}
-
-bool PlayListModel::isShuffle() const
-{
- return m_shuffle;
-}
-
bool PlayListModel::isLoaderRunning() const
{
return m_loader->isRunning();
@@ -907,3 +896,9 @@ void PlayListModel::stopAfterSelected()
return;
emit listChanged();
}
+
+void PlayListModel::updateGroups()
+{
+ if(m_ui_settings->isGroupsEnabled())
+ prepareGroups(true);
+}
diff --git a/src/qmmpui/playlistmodel.h b/src/qmmpui/playlistmodel.h
index 31841387b..d73f5f441 100644
--- a/src/qmmpui/playlistmodel.h
+++ b/src/qmmpui/playlistmodel.h
@@ -36,6 +36,7 @@ class PlayState;
class PlayListFormat;
class PlayListModel;
class PlayListContainer;
+class QmmpUiSettings;
/*! @brief Helper class that keeps track of a view's selected items.
*
@@ -246,14 +247,6 @@ public:
*/
void savePlaylist(const QString& f_name);
/*!
- * Returns state of "Repeat All" option.
- */
- bool isRepeatableList() const;
- /*!
- * Returns state of "Shuffle" option.
- */
- bool isShuffle() const;
- /*!
* Returns \b true if the file loader thread is active; otherwise returns \b false.
*/
bool isLoaderRunning() const;
@@ -407,19 +400,6 @@ public slots:
*/
void reverseList();
/*!
- * Prepares model for shuffle playing. \b yes parameter is \b true - model iterates in shuffle mode.
- */
- void prepareForShufflePlaying(bool yes);
- /*!
- * Prepares model for shuffle playing. \b yes parameter is true - model iterates in repeat mode.
- */
- void prepareForRepeatablePlaying(bool);
- /*!
- * Enabled/Disabled groped mode
- * @param enabled State of the groups (\b true - enabled, \b false - disabled)
- */
- void prepareGroups(bool enabled);
- /*!
* Sorts selected items in \b mode sort mode.
*/
void sortSelection(int mode);
@@ -451,6 +431,10 @@ public slots:
* Toggles 'stop after selected' feature.
*/
void stopAfterSelected();
+ /*!
+ * Rebuilds groups
+ */
+ void updateGroups();
private:
/*!
@@ -468,7 +452,19 @@ private:
void removeSelection(bool inverted = false);
private slots:
+ /*!
+ * Prepares play state object
+ */
void preparePlayState();
+ /*!
+ * Prepares model for shuffle playing. \b yes parameter is \b true - model iterates in shuffle mode.
+ */
+ void prepareForShufflePlaying(bool yes);
+ /*!
+ * Enabled/Disabled groped mode
+ * @param enabled State of the groups (\b true - enabled, \b false - disabled)
+ */
+ void prepareGroups(bool enabled);
private:
PlayListTrack* m_current_track;
@@ -476,14 +472,12 @@ private:
int m_current;
SimpleSelection m_selection; /*!< This flyweight object represents current selection. */
QQueue <PlayListTrack*> m_queued_songs; /*!< Songs in play queue. */
- bool m_is_repeatable_list; /*!< Is playlist repeatable? */
PlayState* m_play_state; /*!< Current playing state (Normal or Shuffle) */
int m_total_length;
FileLoader *m_loader;
- bool m_shuffle;
- bool m_groups_enabled;
QString m_name;
PlayListContainer *m_container;
+ QmmpUiSettings *m_ui_settings;
};
#endif
diff --git a/src/qmmpui/playstate.cpp b/src/qmmpui/playstate.cpp
index 7744e56bb..4c6d5db22 100644
--- a/src/qmmpui/playstate.cpp
+++ b/src/qmmpui/playstate.cpp
@@ -18,8 +18,14 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+#include "qmmpuisettings.h"
#include "playstate_p.h"
+PlayState::PlayState(PlayListModel *model) : m_model(model)
+{
+ m_ui_settings = QmmpUiSettings::instance();
+}
+
ShufflePlayState::ShufflePlayState(PlayListModel * model) : PlayState(model)
{
prepare();
@@ -32,7 +38,7 @@ bool ShufflePlayState::next()
if (m_shuffled_current >= m_shuffled_indexes.count() - 1)
{
- if (!m_model->isRepeatableList())
+ if (!m_ui_settings->isRepeatableList())
return false;
else
prepare();
@@ -51,7 +57,7 @@ int ShufflePlayState::nextIndex()
if (m_shuffled_current >= m_shuffled_indexes.count() - 1)
{
- if (!m_model->isRepeatableList())
+ if (!m_ui_settings->isRepeatableList())
return -1;
else
prepare();
@@ -66,7 +72,7 @@ bool ShufflePlayState::previous()
if (m_shuffled_current <= 0)
{
- if (!m_model->isRepeatableList())
+ if (!m_ui_settings->isRepeatableList())
return false;
else
{
@@ -110,7 +116,7 @@ bool NormalPlayState::next()
if(!m_model->count())
return false;
- if (m_model->isRepeatableList() && m_model->currentIndex() == m_model->count() - 1)
+ if (m_ui_settings->isRepeatableList() && m_model->currentIndex() == m_model->count() - 1)
{
if(m_model->track(0))
return m_model->setCurrent(0);
@@ -136,7 +142,7 @@ bool NormalPlayState::previous()
if(!m_model->count())
return false;
- if(m_model->isRepeatableList())
+ if(m_ui_settings->isRepeatableList())
{
if(m_model->currentIndex() == 1 && !m_model->isTrack(0))
return (m_model->setCurrent(m_model->count() - 1));
@@ -162,7 +168,7 @@ int NormalPlayState::nextIndex()
if (m_model->currentIndex() == m_model->count() - 1)
{
- if (m_model->isRepeatableList())
+ if (m_ui_settings->isRepeatableList())
{
if(m_model->isTrack(0))
return 0;
diff --git a/src/qmmpui/playstate_p.h b/src/qmmpui/playstate_p.h
index e326b0943..09ac1f8a0 100644
--- a/src/qmmpui/playstate_p.h
+++ b/src/qmmpui/playstate_p.h
@@ -30,6 +30,7 @@
class PlayState
{
public:
+
/*! Makes single step forward through songs list.
* If the step has done returns \b true, otherwise returns \b false
*/
@@ -61,14 +62,12 @@ public:
{
;
}
- PlayState(PlayListModel* model) : m_model(model)
- {
- ;
- }
-protected:
+ PlayState(PlayListModel* model);
+protected:
/// Data model
PlayListModel* m_model;
+ QmmpUiSettings *m_ui_settings;
};
/*! @internal
diff --git a/src/qmmpui/qmmpuisettings.cpp b/src/qmmpui/qmmpuisettings.cpp
index f757a7b31..46be8610c 100644
--- a/src/qmmpui/qmmpuisettings.cpp
+++ b/src/qmmpui/qmmpuisettings.cpp
@@ -30,17 +30,26 @@ QmmpUiSettings::QmmpUiSettings(QObject *parent) : QObject(parent)
{
m_instance = this;
QSettings s (Qmmp::configFile(), QSettings::IniFormat);
+ s.beginGroup("PlayList");
m_title_format = s.value("PlayList/title_format", "%p%if(%p&%t, - ,)%t").toString();
m_group_format = s.value("PlayList/group_format", "%p%if(%p&%a, - %if(%y,[%y] ,),)%a").toString();
- m_convertUnderscore = s.value ("PlayList/convert_underscore", true).toBool();
- m_convertTwenty = s.value ("PlayList/convert_twenty", true).toBool();
- m_useMetadata = s.value ("PlayList/load_metadata", true).toBool();
- m_autosave_playlist = s.value("PlayList/autosave", true).toBool();
- m_resume_on_startup = s.value("General/resume_on_startup", false).toBool();
- m_restrict_filters = s.value("General/restrict_filters").toStringList();
- m_exclude_filters = s.value("General/exclude_filters", QStringList() << "*.cue").toStringList();
- m_use_default_pl = s.value("General/use_default_pl", false).toBool();
- m_default_pl_name = s.value("General/default_pl_name", tr("Playlist")).toString();
+ m_convertUnderscore = s.value ("convert_underscore", true).toBool();
+ m_convertTwenty = s.value ("convert_twenty", true).toBool();
+ m_useMetadata = s.value ("load_metadata", true).toBool();
+ m_autosave_playlist = s.value("autosave", true).toBool();
+ m_repeate_list = s.value("repeate_list",false).toBool();
+ m_shuffle = s.value("shuffle",false).toBool();
+ m_groups_enabled = s.value("groups",false).toBool();
+ m_repeat_track = s.value("repeate_track",false).toBool();
+ m_no_pl_advance = s.value("no_advance",false).toBool();
+ s.endGroup();
+ s.beginGroup("General");
+ m_resume_on_startup = s.value("resume_on_startup", false).toBool();
+ m_restrict_filters = s.value("restrict_filters").toStringList();
+ m_exclude_filters = s.value("exclude_filters", QStringList() << "*.cue").toStringList();
+ m_use_default_pl = s.value("use_default_pl", false).toBool();
+ m_default_pl_name = s.value("default_pl_name", tr("Playlist")).toString();
+ s.endGroup();
m_use_clipboard = s.value("URLDialog/use_clipboard", false).toBool();
}
@@ -60,6 +69,31 @@ const QString QmmpUiSettings::groupFormat() const
return m_group_format;
}
+bool QmmpUiSettings::isRepeatableList() const
+{
+ return m_repeate_list;
+}
+
+bool QmmpUiSettings::isShuffle() const
+{
+ return m_shuffle;
+}
+
+bool QmmpUiSettings::isGroupsEnabled() const
+{
+ return m_groups_enabled;
+}
+
+bool QmmpUiSettings::isRepeatableTrack() const
+{
+ return m_repeat_track;
+}
+
+bool QmmpUiSettings::isNoPlaylistAdvance() const
+{
+ return m_no_pl_advance;
+}
+
bool QmmpUiSettings::convertUnderscore() const
{
return m_convertUnderscore;
@@ -102,11 +136,9 @@ void QmmpUiSettings::setGroupFormat(const QString &groupFormat)
if(groupFormat != m_group_format)
{
m_group_format = groupFormat;
- if(!PlayListManager::instance()->isGroupsEnabled())
- return;
foreach(PlayListModel *model, PlayListManager::instance()->playLists())
{
- model->prepareGroups(true);
+ model->updateGroups();
}
}
}
@@ -145,6 +177,11 @@ void QmmpUiSettings::sync()
s.setValue("PlayList/convert_twenty", m_convertTwenty);
s.setValue("PlayList/load_metadata", m_useMetadata);
s.setValue("PlayList/autosave", m_autosave_playlist);
+ s.setValue("PlayList/repeate_list", m_repeate_list);
+ s.setValue("PlayList/shuffle", m_shuffle);
+ s.setValue("PlayList/groups", m_groups_enabled);
+ s.setValue("PlayList/repeate_track", m_repeat_track);
+ s.setValue("PlayList/no_advance", m_no_pl_advance);
s.setValue("General/resume_on_startup", m_resume_on_startup);
s.setValue("General/restrict_filters", m_restrict_filters);
s.setValue("General/exclude_filters", m_exclude_filters);
@@ -153,6 +190,46 @@ void QmmpUiSettings::sync()
s.setValue("URLDialog/use_clipboard", m_use_clipboard);
}
+void QmmpUiSettings::setRepeatableList(bool r)
+{
+ if(m_repeate_list == r)
+ return;
+ m_repeate_list = r;
+ emit repeatableListChanged(r);
+}
+
+void QmmpUiSettings::setShuffle(bool s)
+{
+ if(m_shuffle == s)
+ return;
+ m_shuffle = s;
+ emit shuffleChanged(s);
+}
+
+void QmmpUiSettings::setGroupsEnabled(bool enabled)
+{
+ if(m_groups_enabled == enabled)
+ return;
+ m_groups_enabled = enabled;
+ emit groupsChanged(enabled);
+}
+
+void QmmpUiSettings::setRepeatableTrack(bool enabled)
+{
+ if(m_repeat_track == enabled)
+ return;
+ m_repeat_track = enabled;
+ emit repeatableTrackChanged(enabled);
+}
+
+void QmmpUiSettings::setNoPlaylistAdvance(bool enabled)
+{
+ if(m_no_pl_advance == enabled)
+ return;
+ m_no_pl_advance = enabled;
+ emit noPlaylistAdvanceChanged(enabled);
+}
+
QStringList QmmpUiSettings::restrictFilters() const
{
return m_restrict_filters;
@@ -183,7 +260,7 @@ QString QmmpUiSettings::defaultPlayListName() const
return m_default_pl_name;
}
-QmmpUiSettings * QmmpUiSettings::instance()
+QmmpUiSettings *QmmpUiSettings::instance()
{
if(!m_instance)
return new QmmpUiSettings(qApp);
@@ -199,11 +276,9 @@ void QmmpUiSettings::setDefaultPlayList(const QString &name, bool enabled)
void QmmpUiSettings::setAutoSavePlayList(bool enabled)
{
m_autosave_playlist = enabled;
- PlayListManager::instance()->readSettings();
}
bool QmmpUiSettings::autoSavePlayList() const
{
return m_autosave_playlist;
}
-
diff --git a/src/qmmpui/qmmpuisettings.h b/src/qmmpui/qmmpuisettings.h
index 1c8915224..53a24788f 100644
--- a/src/qmmpui/qmmpuisettings.h
+++ b/src/qmmpui/qmmpuisettings.h
@@ -62,6 +62,26 @@ public:
*/
const QString groupFormat() const;
/*!
+ * Returns state of "Repeat All" option.
+ */
+ bool isRepeatableList() const;
+ /*!
+ * Returns state of "Shuffle" option.
+ */
+ bool isShuffle() const;
+ /*!
+ * Returns \b true if the playlist groups are enabled. Otherwise returns \b false.
+ */
+ bool isGroupsEnabled() const;
+ /*!
+ * Returns \b true if "Repeate Track" option is enabled, otherwise returns \b false
+ */
+ bool isRepeatableTrack() const;
+ /*!
+ * Returns \b true if "No playlist advance" option is enabled, otherwise returns \b false
+ */
+ bool isNoPlaylistAdvance() const;
+ /*!
* Sets the "Convert underscores to blanks" option state to \b enabled
* @param enabled Option state (\b true - enabled, \b false - disabled)
*/
@@ -152,27 +172,87 @@ public:
*/
static QmmpUiSettings* instance();
+
+signals:
+ /*!
+ * Emitted when state of the "Repeat All" option has changed.
+ * @param state New state of the "Repeat All" option (\b true - enabled, \b false disabled)
+ */
+ void repeatableListChanged(bool state);
+ /*!
+ * Emitted when state of the "Shuffle" option has changed.
+ * @param state New state of the "Shuffle" option (\b true - enabled, \b false disabled)
+ */
+ void shuffleChanged(bool state);
+ /*!
+ * Emitted when state of the "Group tracks" option has changed.
+ * @param state New state of the "Group tracks" option (\b true - enabled, \b false disabled
+ */
+ void groupsChanged(bool state);
+ /*!
+ * Tracks current track repeat state;
+ * @param enabled New repeate state of the current track (\b true - enabled, \b false - disabled)
+ */
+ void repeatableTrackChanged(bool enabled);
+ /*!
+ * Emitted when state of the "No playlist advance" option changes.
+ * @param enabled New state of this option (\b true - no playlist advance,
+ * \b false - normal playlist behaviour)
+ */
+ void noPlaylistAdvanceChanged(bool enabled);
+
public slots:
/*!
* Writes all unsaved settings to configuration file
*/
void sync();
+ /*!
+ * Prepares all playlists for repeatable playing (loop mode).
+ * @param r State of the repeatable mode (\b true - enabled, \b false - disabled)
+ */
+ void setRepeatableList(bool r);
+ /*!
+ * Prepares all playlists for shuffle playing.
+ * @param s State of the shuffle mode (\b true - enabled, \b false - disabled)
+ */
+ void setShuffle(bool s);
+ /*!
+ * Enables or disables playlist groups
+ * * @param enabled State of the groups (\b true - enabled, \b false - disabled)
+ */
+ void setGroupsEnabled(bool enabled);
+ /*!
+ * Toggles the current track repeat.
+ * @param enabled Repeate state of the current track (\b true - to repeat, \b false - to stop repeating)
+ */
+ void setRepeatableTrack(bool enabled);
+ /*!
+ * When finished playing a song, don't automatically advance to the next
+ * @param enabled State of the 'No playlist advance' option
+ * (\b true - enabled, \b false - normal playback)
+ */
+ void setNoPlaylistAdvance(bool enabled);
+
private:
static QmmpUiSettings* m_instance;
//playlist
- bool m_convertUnderscore, m_convertTwenty;
- bool m_useMetadata;
QString m_title_format;
QString m_group_format;
+ bool m_convertUnderscore, m_convertTwenty;
+ bool m_useMetadata;
+ bool m_autosave_playlist;
+ bool m_repeate_list;
+ bool m_shuffle;
+ bool m_groups_enabled;
+ bool m_repeat_track;
+ bool m_no_pl_advance;
//general
bool m_resume_on_startup;
QStringList m_exclude_filters, m_restrict_filters;
//default playlist
bool m_use_default_pl;
QString m_default_pl_name;
- //playlist auto-save option
- bool m_autosave_playlist;
//url dialog
bool m_use_clipboard;
};