diff options
24 files changed, 333 insertions, 356 deletions
diff --git a/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp b/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp index 2fcd37b30..7930e84e4 100644 --- a/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp +++ b/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp @@ -25,6 +25,7 @@ #include <qmmpui/playlistmanager.h> #include <qmmpui/metadataformatter.h> #include <qmmpui/mediaplayer.h> +#include <qmmpui/qmmpuisettings.h> #include "playlistoption.h" bool PlayListOption::identify(const QString & str) const @@ -52,6 +53,7 @@ QString PlayListOption::executeCommand(const QString& opt_str, const QStringList QString out; PlayListManager *pl_manager = PlayListManager::instance(); MediaPlayer *player = MediaPlayer::instance(); + QmmpUiSettings *ui_settings = QmmpUiSettings::instance(); if(opt_str == "--pl-help") { @@ -121,18 +123,18 @@ QString PlayListOption::executeCommand(const QString& opt_str, const QStringList } else if(opt_str == "--pl-repeat-toggle") { - player->setRepeatable(!player->isRepeatable()); + ui_settings->setRepeatableTrack(!ui_settings->isRepeatableTrack()); } else if(opt_str == "--pl-shuffle-toggle") { - pl_manager->setShuffle(!pl_manager->isShuffle()); + ui_settings->setShuffle(!ui_settings->isShuffle()); } else if(opt_str == "--pl-state") { - out += "SHUFFLE: " + boolToText(pl_manager->isShuffle()) + "\n"; - out += "REPEAT PLAYLIST: " + boolToText(pl_manager->isRepeatableList()) + "\n"; - out += "REPEAT TRACK: " + boolToText(player->isRepeatable()) + "\n"; - out += "NO PLAYLIST ADVANCE: " + boolToText(player->isNoPlaylistAdvance()) + "\n"; + out += "SHUFFLE: " + boolToText(ui_settings->isShuffle()) + "\n"; + out += "REPEAT PLAYLIST: " + boolToText(ui_settings->isRepeatableList()) + "\n"; + out += "REPEAT TRACK: " + boolToText(ui_settings->isRepeatableTrack()) + "\n"; + out += "NO PLAYLIST ADVANCE: " + boolToText(ui_settings->isNoPlaylistAdvance()) + "\n"; } return out; } diff --git a/src/plugins/General/mpris/mpris1/playerobject.cpp b/src/plugins/General/mpris/mpris1/playerobject.cpp index 8d6d0e165..27c9ca9fa 100644 --- a/src/plugins/General/mpris/mpris1/playerobject.cpp +++ b/src/plugins/General/mpris/mpris1/playerobject.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 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 * @@ -25,7 +25,7 @@ #include <qmmp/metadatamanager.h> #include <qmmpui/mediaplayer.h> #include <qmmpui/playlistmanager.h> - +#include <qmmpui/qmmpuisettings.h> #include "playerobject.h" @@ -59,12 +59,13 @@ PlayerObject::PlayerObject(QObject *parent) : QObject(parent) m_core = SoundCore::instance(); m_player = MediaPlayer::instance(); m_pl_manager = m_player->playListManager(); + m_ui_settings = QmmpUiSettings::instance(); connect(m_core, SIGNAL(stateChanged (Qmmp::State)), SLOT(updateCaps())); connect(m_core, SIGNAL(metaDataChanged ()), SLOT(updateTrack())); connect(m_core, SIGNAL(stateChanged (Qmmp::State)), SLOT(updateStatus())); - connect(m_pl_manager, SIGNAL(repeatableListChanged(bool)), SLOT(updateStatus())); - connect(m_pl_manager, SIGNAL(shuffleChanged(bool)), SLOT(updateStatus())); - connect(m_player, SIGNAL(repeatableChanged(bool)), SLOT(updateStatus())); + connect(m_ui_settings, SIGNAL(repeatableListChanged(bool)), SLOT(updateStatus())); + connect(m_ui_settings, SIGNAL(shuffleChanged(bool)), SLOT(updateStatus())); + connect(m_ui_settings, SIGNAL(repeatableTrackChanged(bool)), SLOT(updateStatus())); } PlayerObject::~PlayerObject() @@ -97,7 +98,7 @@ void PlayerObject::Play() void PlayerObject::Repeat(bool in0) { - m_player->setRepeatable(in0); + m_ui_settings->setRepeatableTrack(in0); } PlayerStatus PlayerObject::GetStatus() @@ -117,9 +118,9 @@ PlayerStatus PlayerObject::GetStatus() case Qmmp::Paused: st.state = 1; }; - st.random = int(m_pl_manager->isShuffle()); - st.repeat = int(m_player->isRepeatable()); - st.repeatPlayList = int(m_pl_manager->isRepeatableList()); + st.random = int(m_ui_settings->isShuffle()); + st.repeat = int(m_ui_settings->isRepeatableTrack()); + st.repeatPlayList = int(m_ui_settings->isRepeatableList()); return st; } diff --git a/src/plugins/General/mpris/mpris1/playerobject.h b/src/plugins/General/mpris/mpris1/playerobject.h index 632ca989f..c4f07587e 100644 --- a/src/plugins/General/mpris/mpris1/playerobject.h +++ b/src/plugins/General/mpris/mpris1/playerobject.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 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 * @@ -26,6 +26,7 @@ class SoundCore; class MediaPlayer; class PlayListManager; +class QmmpUiSettings; /** @author Ilya Kotov <forkotov02@hotmail.ru> @@ -39,7 +40,7 @@ struct PlayerStatus int repeatPlayList; // 0 = Stop playing once the last element has been played, 1 = Never give up playing }; -Q_DECLARE_METATYPE(PlayerStatus); +Q_DECLARE_METATYPE(PlayerStatus) class PlayerObject : public QObject { @@ -95,6 +96,7 @@ private: SoundCore *m_core; MediaPlayer *m_player; PlayListManager *m_pl_manager; + QmmpUiSettings *m_ui_settings; }; diff --git a/src/plugins/General/mpris/mpris1/tracklistobject.cpp b/src/plugins/General/mpris/mpris1/tracklistobject.cpp index 0fb498788..c7176c371 100644 --- a/src/plugins/General/mpris/mpris1/tracklistobject.cpp +++ b/src/plugins/General/mpris/mpris1/tracklistobject.cpp @@ -24,12 +24,13 @@ #include <qmmpui/playlistmanager.h> #include <qmmpui/mediaplayer.h> #include <qmmpui/playlistitem.h> - +#include <qmmpui/qmmpuisettings.h> #include "tracklistobject.h" TrackListObject::TrackListObject(QObject *parent) : QObject(parent) { m_player = MediaPlayer::instance(); + m_ui_settings = QmmpUiSettings::instance(); m_pl_manager = m_player->playListManager(); m_model = m_pl_manager->currentPlayList(); connect (m_model, SIGNAL(listChanged()), SLOT(updateTrackList())); @@ -104,12 +105,12 @@ QVariantMap TrackListObject::GetMetadata(int in0) void TrackListObject::SetLoop(bool in0) { - m_pl_manager->setRepeatableList(in0); + m_ui_settings->setRepeatableList(in0); } void TrackListObject::SetRandom(bool in0) { - m_pl_manager->setShuffle(in0); + m_ui_settings->setShuffle(in0); } void TrackListObject::disconnectPl() diff --git a/src/plugins/General/mpris/mpris1/tracklistobject.h b/src/plugins/General/mpris/mpris1/tracklistobject.h index c92844d9f..b7532656a 100644 --- a/src/plugins/General/mpris/mpris1/tracklistobject.h +++ b/src/plugins/General/mpris/mpris1/tracklistobject.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 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 * @@ -27,6 +27,7 @@ class PlayListModel; class PlayListManager; class MediaPlayer; +class QmmpUiSettings; /** @author Ilya Kotov <forkotov02@hotmail.ru> @@ -63,6 +64,7 @@ private: PlayListModel *m_model; PlayListManager *m_pl_manager; MediaPlayer *m_player; + QmmpUiSettings *m_ui_settings; int m_prev_count; }; diff --git a/src/plugins/General/mpris/mpris2/player2object.cpp b/src/plugins/General/mpris/mpris2/player2object.cpp index 7427e15c4..e7fedac5e 100644 --- a/src/plugins/General/mpris/mpris2/player2object.cpp +++ b/src/plugins/General/mpris/mpris2/player2object.cpp @@ -27,6 +27,7 @@ #include <qmmp/metadatamanager.h> #include <qmmpui/mediaplayer.h> #include <qmmpui/playlistmanager.h> +#include <qmmpui/qmmpuisettings.h> #include "player2object.h" Player2Object::Player2Object(QObject *parent) : QDBusAbstractAdaptor(parent) @@ -36,17 +37,18 @@ Player2Object::Player2Object(QObject *parent) : QDBusAbstractAdaptor(parent) m_core = SoundCore::instance(); m_player = MediaPlayer::instance(); m_pl_manager = m_player->playListManager(); + m_ui_settings = QmmpUiSettings::instance(); connect(m_core, SIGNAL(metaDataChanged ()), SLOT(updateId())); connect(m_core, SIGNAL(metaDataChanged ()), SLOT(emitPropertiesChanged())); connect(m_core, SIGNAL(stateChanged (Qmmp::State)), SLOT(checkState(Qmmp::State))); connect(m_core, SIGNAL(stateChanged (Qmmp::State)), SLOT(emitPropertiesChanged())); connect(m_core, SIGNAL(volumeChanged(int,int)), SLOT(emitPropertiesChanged())); connect(m_core, SIGNAL(elapsedChanged(qint64)), SLOT(checkSeeking(qint64))); - connect(m_pl_manager, SIGNAL(repeatableListChanged(bool)), SLOT(emitPropertiesChanged())); - connect(m_pl_manager, SIGNAL(shuffleChanged(bool)), SLOT(emitPropertiesChanged())); + connect(m_ui_settings, SIGNAL(repeatableListChanged(bool)), SLOT(emitPropertiesChanged())); + connect(m_ui_settings, SIGNAL(shuffleChanged(bool)), SLOT(emitPropertiesChanged())); connect(m_pl_manager, SIGNAL(currentPlayListChanged(PlayListModel*,PlayListModel*)), SLOT(setModel(PlayListModel*,PlayListModel*))); - connect(m_player, SIGNAL(repeatableChanged(bool)), SLOT(emitPropertiesChanged())); + connect(m_ui_settings, SIGNAL(repeatableListChanged(bool)), SLOT(emitPropertiesChanged())); setModel(m_pl_manager->currentPlayList(), 0); updateId(); syncProperties(); @@ -86,9 +88,9 @@ bool Player2Object::canSeek() const QString Player2Object::loopStatus() const { - if(m_player->isRepeatable()) + if(m_ui_settings->isRepeatableTrack()) return "Track"; - else if(m_pl_manager->isRepeatableList()) + else if(m_ui_settings->isRepeatableList()) return "Playlist"; else return "None"; @@ -98,17 +100,18 @@ void Player2Object::setLoopStatus(const QString &value) { if(value == "Track") { - m_player->setRepeatable(true); + m_ui_settings->setRepeatableList(false); + m_ui_settings->setRepeatableTrack(true); } else if(value == "Playlist") { - m_pl_manager->setRepeatableList(true); - m_player->setRepeatable(false); + m_ui_settings->setRepeatableList(true); + m_ui_settings->setRepeatableTrack(false); } else { - m_pl_manager->setRepeatableList(false); - m_player->setRepeatable(false); + m_ui_settings->setRepeatableList(false); + m_ui_settings->setRepeatableTrack(false); } } @@ -184,12 +187,12 @@ void Player2Object::setRate(double value) bool Player2Object::shuffle() const { - return m_pl_manager->isShuffle(); + return m_ui_settings->isShuffle(); } void Player2Object::setShuffle(bool value) { - m_pl_manager->setShuffle(value); + m_ui_settings->setShuffle(value); } double Player2Object::volume() const diff --git a/src/plugins/General/mpris/mpris2/player2object.h b/src/plugins/General/mpris/mpris2/player2object.h index 19c7d24e0..f66b55664 100644 --- a/src/plugins/General/mpris/mpris2/player2object.h +++ b/src/plugins/General/mpris/mpris2/player2object.h @@ -32,6 +32,7 @@ class MediaPlayer; class PlayListManager; class PlayListTrack; class PlayListModel; +class QmmpUiSettings; /** @author Ilya Kotov <forkotov02@hotmail.ru> @@ -107,6 +108,7 @@ private: SoundCore *m_core; MediaPlayer *m_player; PlayListManager *m_pl_manager; + QmmpUiSettings *m_ui_settings; QMap<QString, QVariant> m_props; QDBusObjectPath m_trackID; PlayListTrack *m_prev_track; diff --git a/src/plugins/Ui/skinned/display.cpp b/src/plugins/Ui/skinned/display.cpp index 505725800..e72bf75d7 100644 --- a/src/plugins/Ui/skinned/display.cpp +++ b/src/plugins/Ui/skinned/display.cpp @@ -24,6 +24,7 @@ #include <qmmp/soundcore.h> #include <qmmpui/mediaplayer.h> #include <qmmpui/playlistmanager.h> +#include <qmmpui/qmmpuisettings.h> #include "skin.h" #include "mainvisual.h" #include "button.h" @@ -130,9 +131,9 @@ MainDisplay::MainDisplay (MainWindow *parent) m_volumeBar->setValue(m_core->volume()); m_balanceBar->setValue(m_core->balance()); - PlayListManager *pl_manager = MediaPlayer::instance()->playListManager(); - connect(pl_manager, SIGNAL(repeatableListChanged(bool)), m_repeatButton, SLOT(setChecked(bool))); - connect(pl_manager, SIGNAL(shuffleChanged(bool)), m_shuffleButton, SLOT(setChecked(bool))); + QmmpUiSettings *ui_settings = QmmpUiSettings::instance(); + connect(ui_settings, SIGNAL(repeatableListChanged(bool)), m_repeatButton, SLOT(setChecked(bool))); + connect(ui_settings, SIGNAL(shuffleChanged(bool)), m_shuffleButton, SLOT(setChecked(bool))); updatePositions(); updateMask(); } diff --git a/src/plugins/Ui/skinned/listwidget.cpp b/src/plugins/Ui/skinned/listwidget.cpp index 2dd80a8f5..c324eda66 100644 --- a/src/plugins/Ui/skinned/listwidget.cpp +++ b/src/plugins/Ui/skinned/listwidget.cpp @@ -30,7 +30,7 @@ #include <QTimer> #include <qmmpui/playlistitem.h> #include <qmmpui/playlistmodel.h> -#include <qmmpui/mediaplayer.h> +#include <qmmpui/qmmpuisettings.h> #include "listwidget.h" #include "skin.h" #include "popupwidget.h" @@ -53,8 +53,8 @@ ListWidget::ListWidget(QWidget *parent) m_prev_y = 0; m_anchor_index = INVALID_INDEX; m_pressed_index = INVALID_INDEX; - m_player = MediaPlayer::instance(); - connect (m_player, SIGNAL(repeatableChanged(bool)), SLOT(updateList())); + m_ui_settings = QmmpUiSettings::instance(); + connect (m_ui_settings, SIGNAL(repeatableTrackChanged(bool)), SLOT(updateList())); m_first = 0; m_row_count = 0; m_scroll = false; @@ -594,7 +594,7 @@ const QString ListWidget::getExtraString(int i) extra_string += "|"+QString::number(index + 1)+"|"; } - if(m_model->currentIndex() == i && m_player->isRepeatable()) + if(m_model->currentIndex() == i && m_ui_settings->isRepeatableTrack()) extra_string += "|R|"; else if(m_model->isStopAfter(track)) extra_string += "|S|"; diff --git a/src/plugins/Ui/skinned/listwidget.h b/src/plugins/Ui/skinned/listwidget.h index 5cfcdb695..70872fc20 100644 --- a/src/plugins/Ui/skinned/listwidget.h +++ b/src/plugins/Ui/skinned/listwidget.h @@ -33,7 +33,7 @@ class QTimer; class PlayListModel; class Skin; class PlayListItem; -class MediaPlayer; +class QmmpUiSettings; namespace PlayListPopup{ class PopupWidget; } @@ -144,7 +144,7 @@ private: int m_number_width; int m_drop_index; QList<ListWidgetRow *> m_rows; - MediaPlayer *m_player; + QmmpUiSettings *m_ui_settings; PlayListPopup::PopupWidget *m_popupWidget; QTimer *m_timer; }; diff --git a/src/plugins/Ui/skinned/mainwindow.cpp b/src/plugins/Ui/skinned/mainwindow.cpp index c1ec27841..378651079 100644 --- a/src/plugins/Ui/skinned/mainwindow.cpp +++ b/src/plugins/Ui/skinned/mainwindow.cpp @@ -36,6 +36,7 @@ #include <qmmpui/playlistmanager.h> #include <qmmpui/mediaplayer.h> #include <qmmpui/configdialog.h> +#include <qmmpui/qmmpuisettings.h> #include "hotkeyeditor.h" #include "skinnedsettings.h" #include "mainwindow.h" @@ -68,6 +69,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) m_core = SoundCore::instance(); m_pl_manager = PlayListManager::instance(); m_uiHelper = UiHelper::instance(); + m_ui_settings = QmmpUiSettings::instance(); //user interface m_skin = new Skin(this); @@ -99,8 +101,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) connect (m_playlist,SIGNAL(loadPlaylist()),SLOT(loadPlaylist())); connect (m_playlist,SIGNAL(savePlaylist()),SLOT(savePlaylist())); - connect(m_display,SIGNAL(shuffleToggled(bool)),m_pl_manager,SLOT(setShuffle(bool))); - connect(m_display,SIGNAL(repeatableToggled(bool)),m_pl_manager,SLOT(setRepeatableList(bool))); + connect(m_display,SIGNAL(shuffleToggled(bool)),m_ui_settings,SLOT(setShuffle(bool))); + connect(m_display,SIGNAL(repeatableToggled(bool)),m_ui_settings,SLOT(setRepeatableList(bool))); connect(m_core, SIGNAL(stateChanged(Qmmp::State)), SLOT(showState(Qmmp::State))); connect(m_core, SIGNAL(elapsedChanged(qint64)),m_playlist, SLOT(setTime(qint64))); @@ -241,10 +243,12 @@ void MainWindow::readSettings() m_equalizer->setVisible(settings.value("eq_visible",true).toBool()); qApp->processEvents(); // Repeat/Shuffle - m_display->setIsRepeatable(m_pl_manager->isRepeatableList()); - m_display->setIsShuffle(m_pl_manager->isShuffle()); - ACTION(ActionManager::REPEAT_ALL)->setChecked(m_pl_manager->isRepeatableList()); - ACTION(ActionManager::SHUFFLE)->setChecked(m_pl_manager->isShuffle()); + m_display->setIsRepeatable(m_ui_settings->isRepeatableList()); + m_display->setIsShuffle(m_ui_settings->isShuffle()); + ACTION(ActionManager::REPEAT_ALL)->setChecked(m_ui_settings->isRepeatableList()); + ACTION(ActionManager::SHUFFLE)->setChecked(m_ui_settings->isShuffle()); + ACTION(ActionManager::REPEAT_TRACK)->setChecked(m_ui_settings->isRepeatableTrack()); + ACTION(ActionManager::NO_PL_ADVANCE)->setChecked(m_ui_settings->isNoPlaylistAdvance()); m_update = true; } else @@ -379,21 +383,21 @@ void MainWindow::createActions() viewMenu->addAction(SET_ACTION(ActionManager::WM_DOUBLE_SIZE, this, SLOT(updateSettings()))); QMenu *plMenu = m_mainMenu->addMenu(tr("Playlist")); - plMenu->addAction(SET_ACTION(ActionManager::REPEAT_ALL, m_pl_manager, SLOT(setRepeatableList(bool)))); - plMenu->addAction(SET_ACTION(ActionManager::REPEAT_TRACK, m_player, SLOT(setRepeatable(bool)))); - plMenu->addAction(SET_ACTION(ActionManager::SHUFFLE, m_pl_manager, SLOT(setShuffle(bool)))); - plMenu->addAction(SET_ACTION(ActionManager::NO_PL_ADVANCE, m_player, + plMenu->addAction(SET_ACTION(ActionManager::REPEAT_ALL, m_ui_settings, SLOT(setRepeatableList(bool)))); + plMenu->addAction(SET_ACTION(ActionManager::REPEAT_TRACK, m_ui_settings, SLOT(setRepeatableTrack(bool)))); + plMenu->addAction(SET_ACTION(ActionManager::SHUFFLE, m_ui_settings, SLOT(setShuffle(bool)))); + plMenu->addAction(SET_ACTION(ActionManager::NO_PL_ADVANCE, m_ui_settings, SLOT(setNoPlaylistAdvance(bool)))); plMenu->addAction(SET_ACTION(ActionManager::STOP_AFTER_SELECTED, m_pl_manager, SLOT(stopAfterSelected()))); plMenu->addAction(SET_ACTION(ActionManager::CLEAR_QUEUE, m_pl_manager, SLOT(clearQueue()))); - connect(m_pl_manager, SIGNAL(repeatableListChanged(bool)), + connect(m_ui_settings, SIGNAL(repeatableListChanged(bool)), ACTION(ActionManager::REPEAT_ALL), SLOT(setChecked(bool))); - connect(m_player, SIGNAL (repeatableChanged(bool)), + connect(m_ui_settings, SIGNAL (repeatableTrackChanged(bool)), ACTION(ActionManager::REPEAT_TRACK), SLOT(setChecked(bool))); - connect(m_player, SIGNAL (noPlaylistAdvanceChanged(bool)), + connect(m_ui_settings, SIGNAL (noPlaylistAdvanceChanged(bool)), ACTION(ActionManager::NO_PL_ADVANCE), SLOT(setChecked(bool))); - connect(m_pl_manager, SIGNAL(shuffleChanged(bool)), + connect(m_ui_settings, SIGNAL(shuffleChanged(bool)), ACTION(ActionManager::SHUFFLE), SLOT(setChecked(bool))); QMenu *audioMenu = m_mainMenu->addMenu(tr("Audio")); diff --git a/src/plugins/Ui/skinned/mainwindow.h b/src/plugins/Ui/skinned/mainwindow.h index ec50fe483..48672c750 100644 --- a/src/plugins/Ui/skinned/mainwindow.h +++ b/src/plugins/Ui/skinned/mainwindow.h @@ -40,6 +40,7 @@ class UiHelper; class MediaPlayer; class QMenu; class QKeyEvent; +class QmmpUiSettings; /** @author Ilya Kotov <forkotov02@hotmail.ru> @@ -105,6 +106,7 @@ private: bool m_hideOnClose, m_startHidden; VisualMenu *m_visMenu; UiHelper *m_uiHelper; + QmmpUiSettings *m_ui_settings; MediaPlayer *m_player; }; diff --git a/src/plugins/Ui/skinned/playlist.cpp b/src/plugins/Ui/skinned/playlist.cpp index e95977804..ccb722460 100644 --- a/src/plugins/Ui/skinned/playlist.cpp +++ b/src/plugins/Ui/skinned/playlist.cpp @@ -30,6 +30,7 @@ #include <qmmpui/playlistmodel.h> #include <qmmpui/playlistmanager.h> #include <qmmpui/uihelper.h> +#include <qmmpui/qmmpuisettings.h> #include <qmmp/soundcore.h> #include "dock.h" #include "skin.h" @@ -53,6 +54,7 @@ PlayList::PlayList (PlayListManager *manager, QWidget *parent) setAttribute(Qt::WA_AlwaysShowToolTips,true); setWindowTitle(tr("Playlist")); m_pl_manager = manager; + m_ui_settings = QmmpUiSettings::instance(); m_update = false; m_resize = false; m_skin = Skin::instance(); @@ -299,8 +301,8 @@ void PlayList::createActions() m_sortMenu->addAction (QIcon::fromTheme("view-sort-descending"), tr("Reverse List"), m_pl_manager, SLOT(reverseList())); - m_sortMenu->addAction(SET_ACTION(ActionManager::PL_GROUP_TRACKS, m_pl_manager, SLOT(setGroupsEnabled(bool)))); - ACTION(ActionManager::PL_GROUP_TRACKS)->setChecked(m_pl_manager->isGroupsEnabled()); + m_sortMenu->addAction(SET_ACTION(ActionManager::PL_GROUP_TRACKS, m_ui_settings, SLOT(setGroupsEnabled(bool)))); + ACTION(ActionManager::PL_GROUP_TRACKS)->setChecked(m_ui_settings->isGroupsEnabled()); //playlist context menu m_listWidget->menu()->addAction(ActionManager::instance()->action(ActionManager::PL_SHOW_INFO)); m_listWidget->menu()->addSeparator(); diff --git a/src/plugins/Ui/skinned/playlist.h b/src/plugins/Ui/skinned/playlist.h index 1b7f73bd8..12454bbdf 100644 --- a/src/plugins/Ui/skinned/playlist.h +++ b/src/plugins/Ui/skinned/playlist.h @@ -40,6 +40,7 @@ class KeyboardManager; class PlayListManager; class PlayListBrowser; class PlayListSelector; +class QmmpUiSettings; /** @author Ilya Kotov <forkotov02@hotmail.ru> @@ -130,6 +131,7 @@ class PlayList : public QWidget int m_height; bool m_shaded; PlayListManager *m_pl_manager; + QmmpUiSettings *m_ui_settings; KeyboardManager* m_keyboardManager; QPointer <PlayListBrowser> m_pl_browser; PlayListSelector *m_pl_selector; 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; }; |
