diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-12-15 09:55:53 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-12-15 09:55:53 +0000 |
| commit | 3a965fcd45d585c7e49afcc4b0d2e2d6ef8fe1f5 (patch) | |
| tree | d9ff3cd9621804632dca6001ad20ffb5f52de3f8 /src/qmmpui | |
| parent | f31d9ccf3dda970ce2f4139a8c2ab205759c5523 (diff) | |
| download | qmmp-3a965fcd45d585c7e49afcc4b0d2e2d6ef8fe1f5.tar.gz qmmp-3a965fcd45d585c7e49afcc4b0d2e2d6ef8fe1f5.tar.bz2 qmmp-3a965fcd45d585c7e49afcc4b0d2e2d6ef8fe1f5.zip | |
added playlists auto-save feauture (patch by Ferdinand Vesely) (Closes
issue 536), changed playlist api
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3063 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui')
| -rw-r--r-- | src/qmmpui/configdialog.cpp | 3 | ||||
| -rw-r--r-- | src/qmmpui/forms/configdialog.ui | 188 | ||||
| -rw-r--r-- | src/qmmpui/playlistmanager.cpp | 53 | ||||
| -rw-r--r-- | src/qmmpui/playlistmanager.h | 14 | ||||
| -rw-r--r-- | src/qmmpui/playlistmodel.cpp | 52 | ||||
| -rw-r--r-- | src/qmmpui/playlistmodel.h | 60 | ||||
| -rw-r--r-- | src/qmmpui/playstate.cpp | 16 | ||||
| -rw-r--r-- | src/qmmpui/qmmpuisettings.cpp | 17 | ||||
| -rw-r--r-- | src/qmmpui/qmmpuisettings.h | 21 |
9 files changed, 241 insertions, 183 deletions
diff --git a/src/qmmpui/configdialog.cpp b/src/qmmpui/configdialog.cpp index 492c7f815..4bcf42d9d 100644 --- a/src/qmmpui/configdialog.cpp +++ b/src/qmmpui/configdialog.cpp @@ -108,6 +108,8 @@ void ConfigDialog::readSettings() //default playlist m_ui->defaultPlayListCheckBox->setChecked(guis->useDefaultPlayList()); m_ui->defaultPlayListLineEdit->setText(guis->defaultPlayListName()); + //playlist auto-save when modified + m_ui->autoSavePlayListCheckBox->setChecked(guis->autoSavePlayList()); } //proxy settings QmmpSettings *gs = QmmpSettings::instance(); @@ -357,6 +359,7 @@ void ConfigDialog::saveSettings() guis->setExcludeFilters(m_ui->dirExcludeLineEdit->text()); guis->setDefaultPlayList(m_ui->defaultPlayListLineEdit->text(), m_ui->defaultPlayListCheckBox->isChecked()); + guis->setAutoSavePlayList(m_ui->autoSavePlayListCheckBox->isChecked()); guis->sync(); } diff --git a/src/qmmpui/forms/configdialog.ui b/src/qmmpui/forms/configdialog.ui index 14ecc4d49..46a2b048c 100644 --- a/src/qmmpui/forms/configdialog.ui +++ b/src/qmmpui/forms/configdialog.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>680</width> - <height>455</height> + <width>640</width> + <height>469</height> </rect> </property> <property name="windowTitle"> @@ -200,72 +200,18 @@ </widget> </item> <item> - <widget class="QGroupBox" name="groupBox_9"> + <widget class="QGroupBox" name="groupBox_4"> <property name="title"> - <string>Cover Image Retrieve</string> + <string>Miscellaneous</string> </property> - <layout class="QGridLayout" name="gridLayout_6"> - <item row="0" column="0" colspan="2"> - <widget class="QCheckBox" name="useCoverFilesCheckBox"> - <property name="text"> - <string>Use separate image files</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_11"> - <property name="text"> - <string>Include files:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="coverIncludeLineEdit"/> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_12"> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QCheckBox" name="autoSavePlayListCheckBox"> <property name="text"> - <string>Exclude files:</string> + <string>Auto-save playlist when modified</string> </property> </widget> </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="coverExcludeLineEdit"/> - </item> - <item row="3" column="0" colspan="2"> - <layout class="QHBoxLayout" name="horizontalLayout_4"> - <item> - <widget class="QLabel" name="label_13"> - <property name="text"> - <string>Recursive search depth:</string> - </property> - </widget> - </item> - <item> - <widget class="QSpinBox" name="coverDepthSpinBox"> - <property name="maximum"> - <number>6</number> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_3"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> </layout> </widget> </item> @@ -459,6 +405,76 @@ </widget> </item> <item> + <widget class="QGroupBox" name="groupBox_9"> + <property name="title"> + <string>Cover Image Retrieve</string> + </property> + <layout class="QGridLayout" name="gridLayout_6"> + <item row="0" column="0" colspan="2"> + <widget class="QCheckBox" name="useCoverFilesCheckBox"> + <property name="text"> + <string>Use separate image files</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_11"> + <property name="text"> + <string>Include files:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="coverIncludeLineEdit"/> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_12"> + <property name="text"> + <string>Exclude files:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="coverExcludeLineEdit"/> + </item> + <item row="3" column="0" colspan="2"> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QLabel" name="label_13"> + <property name="text"> + <string>Recursive search depth:</string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="coverDepthSpinBox"> + <property name="maximum"> + <number>6</number> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> <spacer name="verticalSpacer_3"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -918,54 +934,6 @@ </hints> </connection> <connection> - <sender>useCoverFilesCheckBox</sender> - <signal>toggled(bool)</signal> - <receiver>coverIncludeLineEdit</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>616</x> - <y>271</y> - </hint> - <hint type="destinationlabel"> - <x>654</x> - <y>296</y> - </hint> - </hints> - </connection> - <connection> - <sender>useCoverFilesCheckBox</sender> - <signal>toggled(bool)</signal> - <receiver>coverExcludeLineEdit</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>586</x> - <y>271</y> - </hint> - <hint type="destinationlabel"> - <x>654</x> - <y>321</y> - </hint> - </hints> - </connection> - <connection> - <sender>useCoverFilesCheckBox</sender> - <signal>toggled(bool)</signal> - <receiver>coverDepthSpinBox</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>560</x> - <y>271</y> - </hint> - <hint type="destinationlabel"> - <x>458</x> - <y>346</y> - </hint> - </hints> - </connection> - <connection> <sender>defaultPlayListCheckBox</sender> <signal>toggled(bool)</signal> <receiver>defaultPlayListLineEdit</receiver> diff --git a/src/qmmpui/playlistmanager.cpp b/src/qmmpui/playlistmanager.cpp index 59b865078..cc98ae8f7 100644 --- a/src/qmmpui/playlistmanager.cpp +++ b/src/qmmpui/playlistmanager.cpp @@ -22,8 +22,10 @@ #include <QFile> #include <QBuffer> #include <QDir> +#include <QTimer> #include <QSettings> #include <qmmp/fileinfo.h> +#include "qmmpuisettings.h" #include "playlistmanager.h" @@ -38,10 +40,18 @@ PlayListManager::PlayListManager(QObject *parent) : QObject(parent) m_selected = 0; m_repeatable = false; m_shuffle = false; - readPlayLists(); + m_timer = new QTimer(this); + m_timer->setInterval(5000); + m_timer->setSingleShot(true); + QmmpUiSettings *ui_settings = QmmpUiSettings::instance(); + connect(ui_settings, SIGNAL(playListSettingsChanged()), SLOT(readSettings())); + connect(m_timer, SIGNAL(timeout()), SLOT(writePlayLists())); + readPlayLists(); //read playlists + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); setRepeatableList(settings.value("Playlist/repeatable",false).toBool()); setShuffle(settings.value("Playlist/shuffle",false).toBool()); + readSettings(); //read other settings } PlayListManager::~PlayListManager() @@ -58,7 +68,6 @@ PlayListManager* PlayListManager::instance() return m_instance; } - PlayListModel *PlayListManager::selectedPlayList() const { return m_selected; @@ -171,6 +180,8 @@ PlayListModel *PlayListManager::createPlayList(const QString &name) model->prepareForRepeatablePlaying(m_repeatable); model->prepareForShufflePlaying(m_shuffle); connect(model, SIGNAL(nameChanged(QString)), SIGNAL(playListsChanged())); + if (m_autosave_playlist) + connect(model, SIGNAL(countChanged()), m_timer, SLOT(start())); emit playListAdded(m_models.indexOf(model)); emit playListsChanged(); return model; @@ -348,14 +359,19 @@ void PlayListManager::readPlayLists() void PlayListManager::writePlayLists() { + qDebug("PlayListManager: saving playlists..."); QFile file(QDir::homePath() +"/.qmmp/playlist.txt"); - file.open(QIODevice::WriteOnly); + if(!file.open(QIODevice::WriteOnly)) + { + qDebug("PlayListManager: error: %s", qPrintable(file.errorString())); + return; + } file.write(QString("current_playlist=%1\n").arg(m_models.indexOf(m_current)).toUtf8()); foreach(PlayListModel *model, m_models) { QList<PlayListItem *> items = model->items(); file.write(QString("playlist=%1\n").arg(model->name()).toUtf8()); - file.write(QString("current=%1\n").arg(model->currentRow()).toUtf8()); + file.write(QString("current=%1\n").arg(model->currentIndex()).toUtf8()); foreach(PlayListItem* m, items) { file.write(QString("file=%1\n").arg(m->url()).toUtf8()); @@ -468,3 +484,32 @@ void PlayListManager::stopAfterSelected() { m_selected->stopAfterSelected(); } + +void PlayListManager::readSettings() +{ + QmmpUiSettings *ui_settings = QmmpUiSettings::instance(); + bool enabled = ui_settings->autoSavePlayList(); + if (m_autosave_playlist != enabled) + { + m_autosave_playlist = enabled; + setAutoSavePlayList(); + } +} + +void PlayListManager::setAutoSavePlayList() +{ + if (m_autosave_playlist) + { + foreach(PlayListModel *model, m_models) + { + connect(model, SIGNAL(countChanged()), m_timer, SLOT(start()), Qt::UniqueConnection); + } + } + else + { + foreach(PlayListModel *model, m_models) + { + disconnect(model, SIGNAL(countChanged()), m_timer, SLOT(start())); + } + } +} diff --git a/src/qmmpui/playlistmanager.h b/src/qmmpui/playlistmanager.h index 3b3dcaea9..14de512ea 100644 --- a/src/qmmpui/playlistmanager.h +++ b/src/qmmpui/playlistmanager.h @@ -23,6 +23,8 @@ #include <QObject> #include "playlistmodel.h" +class QTimer; + /*! @brief The PlayListManager class is used to handle multiple playlists. * @author Ilya Kotov <forkotov02@hotmail.ru> */ @@ -260,15 +262,23 @@ public slots: * This is a convenience function and is the same as calling \b selectedPlayList()->stopAfterSelected() */ void stopAfterSelected(); + /*! + * Read the relevant settings. + */ + void readSettings(); + +private slots: + void writePlayLists(); private: void readPlayLists(); - void writePlayLists(); + void setAutoSavePlayList(); static PlayListManager* m_instance; QList <PlayListModel *> m_models; PlayListModel *m_current; PlayListModel *m_selected; - bool m_repeatable, m_shuffle; + bool m_repeatable, m_shuffle, m_autosave_playlist; + QTimer *m_timer; }; #endif // PLAYLISTMANAGER_H diff --git a/src/qmmpui/playlistmodel.cpp b/src/qmmpui/playlistmodel.cpp index 3331885dd..263e6c836 100644 --- a/src/qmmpui/playlistmodel.cpp +++ b/src/qmmpui/playlistmodel.cpp @@ -70,7 +70,7 @@ PlayListModel::PlayListModel(const QString &name, QObject *parent) m_shuffle = 0; m_total_length = 0; m_current = 0; - is_repeatable_list = false; + m_is_repeatable_list = false; m_stop_item = 0; m_play_state = new NormalPlayState(this); m_loader = new FileLoader(this); @@ -112,6 +112,7 @@ void PlayListModel::add(PlayListItem *item) emit itemAdded(item); emit listChanged(); + emit countChanged(); } void PlayListModel::add(QList <PlayListItem *> items) @@ -129,6 +130,7 @@ void PlayListModel::add(QList <PlayListItem *> items) emit itemAdded(item); } emit listChanged(); + emit countChanged(); } void PlayListModel::add(const QString &path) @@ -176,22 +178,27 @@ PlayListItem* PlayListModel::nextItem() return m_items.at(index); } -PlayListItem* PlayListModel::item(int row) const +int PlayListModel::indexOf(PlayListItem* item) const { - return (row < m_items.size() && row >= 0) ? m_items.at(row) : 0; + return m_items.indexOf(item); } -int PlayListModel::currentRow() +PlayListItem* PlayListModel::item(int index) const +{ + return (index < m_items.size() && index >= 0) ? m_items.at(index) : 0; +} + +int PlayListModel::currentIndex() { return m_current; } -bool PlayListModel::setCurrent(int c) +bool PlayListModel::setCurrent(int index) { - if (c > count()-1 || c < 0) + if (index > count()-1 || index < 0) return false; - m_current = c; - m_currentItem = m_items.at(c); + m_current = index; + m_currentItem = m_items.at(index); emit currentChanged(); emit listChanged(); return true; @@ -253,6 +260,7 @@ void PlayListModel::clear() m_total_length = 0; m_play_state->resetState(); emit listChanged(); + emit countChanged(); } void PlayListModel::clearSelection() @@ -291,10 +299,10 @@ QStringList PlayListModel::getTimes(int b,int l) return m_times; } -bool PlayListModel::isSelected(int row) +bool PlayListModel::isSelected(int index) { - if (m_items.count() > row && row >= 0) - return m_items.at(row)->isSelected(); + if (m_items.count() > index && index >= 0) + return m_items.at(index)->isSelected(); return false; } @@ -309,11 +317,11 @@ bool PlayListModel::contains(const QString &url) return false; } -void PlayListModel::setSelected(int row, bool selected) +void PlayListModel::setSelected(int index, bool selected) { - if (m_items.count() > row && row >= 0) + if (m_items.count() > index && index >= 0) { - m_items.at(row)->setSelected(selected); + m_items.at(index)->setSelected(selected); emit listChanged(); } } @@ -355,6 +363,7 @@ void PlayListModel::removeAt (int i) m_play_state->prepare(); emit listChanged(); + emit countChanged(); } } @@ -410,6 +419,7 @@ void PlayListModel::removeSelection(bool inverted) m_play_state->prepare(); emit listChanged(); + emit countChanged(); } void PlayListModel::invertSelection() @@ -468,7 +478,7 @@ void PlayListModel::moveItems(int from, int to) if (from == to) return; - QList<int> selected_rows = selectedRows(); + QList<int> selected_rows = selectedIndexes(); if (!(bottommostInSelection(from) == INVALID_ROW || from == INVALID_ROW || @@ -529,11 +539,11 @@ const SimpleSelection& PlayListModel::getSelection(int row) m_selection.m_top = topmostInSelection(row); m_selection.m_anchor = row; m_selection.m_bottom = bottommostInSelection(row); - m_selection.m_selected_rows = selectedRows(); + m_selection.m_selected_indexes = selectedIndexes(); return m_selection; } -QList<int> PlayListModel::selectedRows() const +QList<int> PlayListModel::selectedIndexes() const { QList<int>selected_rows; for (int i = 0;i<m_items.count();i++) @@ -583,7 +593,7 @@ bool PlayListModel::isQueued(PlayListItem* f) const void PlayListModel::setCurrentToQueued() { - setCurrent(row(m_queued_songs.dequeue())); + setCurrent(indexOf(m_queued_songs.dequeue())); } bool PlayListModel::isEmptyQueue() const @@ -785,7 +795,7 @@ void PlayListModel::doSort(int sort_mode,QList<PlayListItem*>& list_to_sort) void PlayListModel::sortSelection(int mode) { QList<PlayListItem*>selected_items = selectedItems(); - QList<int>selected_rows = selectedRows(); + QList<int>selected_rows = selectedIndexes(); doSort(mode,selected_items); @@ -819,7 +829,7 @@ void PlayListModel::prepareForShufflePlaying(bool val) void PlayListModel::prepareForRepeatablePlaying(bool val) { - is_repeatable_list = val; + m_is_repeatable_list = val; } void PlayListModel::doCurrentVisibleRequest() @@ -884,7 +894,7 @@ void PlayListModel::savePlaylist(const QString & f_name) bool PlayListModel::isRepeatableList() const { - return is_repeatable_list; + return m_is_repeatable_list; } bool PlayListModel::isShuffle() const diff --git a/src/qmmpui/playlistmodel.h b/src/qmmpui/playlistmodel.h index bd7051953..4a6a9a3f2 100644 --- a/src/qmmpui/playlistmodel.h +++ b/src/qmmpui/playlistmodel.h @@ -60,7 +60,7 @@ struct SimpleSelection */ inline void dump()const { - qWarning("top: %d\tbotom: %d\tanchor: %d",m_top,m_bottom,m_anchor); + qWarning("top: %d\tbotom: %d\tanchor: %d", m_top, m_bottom, m_anchor); } /*! * Returns number of selected items. @@ -72,7 +72,7 @@ struct SimpleSelection int m_bottom; /*!< */ int m_top; /*!< */ int m_anchor; /*!< */ - QList<int>m_selected_rows; /*!< Selected rows numbers */ + QList<int> m_selected_indexes; /*!< Selected items numbers */ }; /*! @internal * @brief Helper class used for tags update after details dialog closing. @@ -133,39 +133,36 @@ public: /*! * Returns the row of the \b item */ - int row(PlayListItem* item) const - { - return m_items.indexOf(item); - } + int indexOf(PlayListItem* item) const; /*! - * Returns the item of the \b row or 0 if item doesn't exist. + * Returns the item with the index \b index or 0 if item doesn't exist. */ - PlayListItem* item(int row) const; + PlayListItem* item(int index) const; /*! - * Returns current row. + * Returns index of the current item. */ - int currentRow(); + int currentIndex(); /*! - * Sets current row number. - * Returns \b false if item with this number doesn't exist, otherwise returns \b true + * Sets current index. + * Returns \b false if item with this index doesn't exist, otherwise returns \b true * @param row Number of item. */ - bool setCurrent (int row); + bool setCurrent (int index); /*! * Sets current item to \b item. * Returns \b true if success, otherwise returns \b false */ bool setCurrent(PlayListItem *item); /*! - * Returns \b true if \b row is selected, otherwise returns \b false + * Returns \b true if item with \b index is selected, otherwise returns \b false */ - bool isSelected(int row); + bool isSelected(int index); /*! * Sets the selected state of the item to \b select - * @param row Number of item. + * @param index Number of item. * @param selected Selection state (\b true - select, \b false - unselect) */ - void setSelected(int row, bool selected = true); + void setSelected(int index, bool selected = true); /*! * Advances to the next item. Returns \b false if next iten doesn't exist, * otherwise returns \b true @@ -222,9 +219,9 @@ public: */ const SimpleSelection& getSelection(int row); /*! - * Returns list with selected rows indexes. + * Returns list with selected items indexes. */ - QList<int> selectedRows() const; + QList<int> selectedIndexes() const; /*! * Returns list of \b PlayListItem pointers that are selected. */ @@ -313,6 +310,10 @@ signals: * Emitted when playlist loader thread has finished. */ void loaderFinished(); + /*! + * Emitted when playlist items are added or removed. + */ + void countChanged(); public slots: /*! @@ -452,27 +453,14 @@ private: PlayListItem* m_currentItem; PlayListItem* m_stop_item; int m_current; - /*! - * This flyweight object represents current selection. - */ - SimpleSelection m_selection; - /*! - * Songs in play queue. - */ - QQueue <PlayListItem*> m_queued_songs; - /*! - * Is playlist repeatable? - */ - bool is_repeatable_list; - /*! - * Current playing state (Normal or Shuffle) - */ - PlayState* m_play_state; + SimpleSelection m_selection; /*!< This flyweight object represents current selection. */ + QQueue <PlayListItem*> 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; QString m_name; }; - #endif diff --git a/src/qmmpui/playstate.cpp b/src/qmmpui/playstate.cpp index 065a3ddd2..e9d4c7aeb 100644 --- a/src/qmmpui/playstate.cpp +++ b/src/qmmpui/playstate.cpp @@ -94,14 +94,14 @@ void ShufflePlayState::prepare() resetState(); for(int i = 0;i < m_model->items().count();i++) { - if (i != m_model->currentRow()) + if (i != m_model->currentIndex()) m_shuffled_indexes << i; } for (int i = 0; i < m_shuffled_indexes.count(); i++) m_shuffled_indexes.swap(i, qrand()%m_shuffled_indexes.size()); - m_shuffled_indexes.prepend(m_model->currentRow()); + m_shuffled_indexes.prepend(m_model->currentIndex()); } void ShufflePlayState::resetState() @@ -120,14 +120,14 @@ bool NormalPlayState::next() if (itm_count > 0) { - if ( m_model->currentRow() == itm_count - 1) + if ( m_model->currentIndex() == itm_count - 1) { if (m_model->isRepeatableList()) return m_model->setCurrent(0); else return false; } - return m_model->setCurrent(m_model->currentRow() + 1); + return m_model->setCurrent(m_model->currentIndex() + 1); } else return false; @@ -139,9 +139,9 @@ bool NormalPlayState::previous() if (itm_count > 0) { - if ( m_model->currentRow() < 1 && !m_model->isRepeatableList()) + if ( m_model->currentIndex() < 1 && !m_model->isRepeatableList()) return false; - else if (m_model->setCurrent(m_model->currentRow() - 1)) + else if (m_model->setCurrent(m_model->currentIndex() - 1)) return true; else if (m_model->isRepeatableList()) return m_model->setCurrent(m_model->items().count() - 1); @@ -156,13 +156,13 @@ int NormalPlayState::nextIndex() if(!itm_count) return -1; - if (m_model->currentRow() == itm_count - 1) + if (m_model->currentIndex() == itm_count - 1) { if (m_model->isRepeatableList()) return 0; else return -1; } - return m_model->currentRow() + 1; + return m_model->currentIndex() + 1; } diff --git a/src/qmmpui/qmmpuisettings.cpp b/src/qmmpui/qmmpuisettings.cpp index f3630026f..c0534328f 100644 --- a/src/qmmpui/qmmpuisettings.cpp +++ b/src/qmmpui/qmmpuisettings.cpp @@ -34,6 +34,7 @@ QmmpUiSettings::QmmpUiSettings(QObject *parent) : QObject(parent) 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(); @@ -115,6 +116,7 @@ void QmmpUiSettings::sync() s.setValue("PlayList/convert_underscore", m_convertUnderscore); s.setValue("PlayList/convert_twenty", m_convertTwenty); s.setValue("PlayList/load_metadata", m_useMetadata); + s.setValue("PlayList/autosave", m_autosave_playlist); 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); @@ -164,3 +166,18 @@ void QmmpUiSettings::setDefaultPlayList(const QString &name, bool enabled) m_use_default_pl = enabled; m_default_pl_name = name; } + +void QmmpUiSettings::setAutoSavePlayList(bool enabled) +{ + if (autoSavePlayList() != enabled) + { + m_autosave_playlist = enabled; + emit playListSettingsChanged(); + } +} + +bool QmmpUiSettings::autoSavePlayList() const +{ + return m_autosave_playlist; +} + diff --git a/src/qmmpui/qmmpuisettings.h b/src/qmmpui/qmmpuisettings.h index b329339bf..9c2960859 100644 --- a/src/qmmpui/qmmpuisettings.h +++ b/src/qmmpui/qmmpuisettings.h @@ -119,10 +119,27 @@ public: */ void setDefaultPlayList(const QString &name, bool enabled = true); /*! + * Enable/disable playlist auto-saving. + * @param enabled New setting for the auto-save option (\b true to enable) + */ + void setAutoSavePlayList(bool enabled); + /*! + * Return the current setting for the playlist auto-save option. + * @return \b true if the playlist should be saved automatically, \b false + * otherwise. + */ + bool autoSavePlayList() const; + /*! * Returns a pointer to the QmmpUiSettings instance. */ static QmmpUiSettings* instance(); +signals: + /*! + * Emitted when the playlist settings change. + */ + void playListSettingsChanged(); + public slots: /*! * Writes all unsaved settings to configuration file @@ -141,8 +158,8 @@ private: //default playlist bool m_use_default_pl; QString m_default_pl_name; - - + //playlist auto-save option + bool m_autosave_playlist; }; #endif // QMMPUISETTINGS_H |
