aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp2
-rw-r--r--src/plugins/General/fileops/fileops.cpp2
-rw-r--r--src/plugins/General/mpris/mpris1/tracklistobject.cpp2
-rw-r--r--src/plugins/General/mpris/mpris2/player2object.cpp2
-rw-r--r--src/plugins/Ui/skinned/keyboardmanager.cpp10
-rw-r--r--src/plugins/Ui/skinned/listwidget.cpp12
-rw-r--r--src/plugins/Ui/skinned/playlisttitlebar.cpp2
-rw-r--r--src/qmmpui/configdialog.cpp3
-rw-r--r--src/qmmpui/forms/configdialog.ui188
-rw-r--r--src/qmmpui/playlistmanager.cpp53
-rw-r--r--src/qmmpui/playlistmanager.h14
-rw-r--r--src/qmmpui/playlistmodel.cpp52
-rw-r--r--src/qmmpui/playlistmodel.h60
-rw-r--r--src/qmmpui/playstate.cpp16
-rw-r--r--src/qmmpui/qmmpuisettings.cpp17
-rw-r--r--src/qmmpui/qmmpuisettings.h21
16 files changed, 257 insertions, 199 deletions
diff --git a/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp b/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp
index eb86f57a7..8e8f12c7e 100644
--- a/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp
+++ b/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp
@@ -84,7 +84,7 @@ QString PlayListOption::executeCommand(const QString& opt_str, const QStringList
for(int i = 0; i < model->count(); ++i)
{
out += QString("%1. %2").arg(i+1).arg(formatter.parse(model->item(i)));
- if(i == model->currentRow())
+ if(i == model->currentIndex())
out += " [*]";
out += "\n";
}
diff --git a/src/plugins/General/fileops/fileops.cpp b/src/plugins/General/fileops/fileops.cpp
index e14c208f7..245c4fe20 100644
--- a/src/plugins/General/fileops/fileops.cpp
+++ b/src/plugins/General/fileops/fileops.cpp
@@ -194,7 +194,7 @@ void FileOps::execAction(int n)
foreach(PlayListItem *item, items)
{
if (QFile::exists(item->url()) && QFile::remove(item->url()))
- model->removeAt (model->row(item));
+ model->removeAt (model->indexOf(item));
}
}
}
diff --git a/src/plugins/General/mpris/mpris1/tracklistobject.cpp b/src/plugins/General/mpris/mpris1/tracklistobject.cpp
index 5b31fe725..9576a902a 100644
--- a/src/plugins/General/mpris/mpris1/tracklistobject.cpp
+++ b/src/plugins/General/mpris/mpris1/tracklistobject.cpp
@@ -71,7 +71,7 @@ void TrackListObject::DelTrack(int in0)
int TrackListObject::GetCurrentTrack()
{
- return m_model->currentRow();
+ return m_model->currentIndex();
}
int TrackListObject::GetLength()
diff --git a/src/plugins/General/mpris/mpris2/player2object.cpp b/src/plugins/General/mpris/mpris2/player2object.cpp
index 78c77997b..d3dc81171 100644
--- a/src/plugins/General/mpris/mpris2/player2object.cpp
+++ b/src/plugins/General/mpris/mpris2/player2object.cpp
@@ -64,7 +64,7 @@ bool Player2Object::canGoNext() const
bool Player2Object::canGoPrevious() const
{
- return m_pl_manager->currentPlayList()->currentRow() > 0;
+ return m_pl_manager->currentPlayList()->currentIndex() > 0;
}
bool Player2Object::canPause() const
diff --git a/src/plugins/Ui/skinned/keyboardmanager.cpp b/src/plugins/Ui/skinned/keyboardmanager.cpp
index 88bd8dc0d..1576ea6db 100644
--- a/src/plugins/Ui/skinned/keyboardmanager.cpp
+++ b/src/plugins/Ui/skinned/keyboardmanager.cpp
@@ -72,7 +72,7 @@ bool KeyboardManager::handleKeyRelease (QKeyEvent*)
void KeyboardManager::keyUp (QKeyEvent * ke)
{
- QList<int> rows = m_playlist->listWidget()->model()->selectedRows();
+ QList<int> rows = m_playlist->listWidget()->model()->selectedIndexes();
ListWidget* list_widget = m_playlist->listWidget();
if (rows.count() > 0)
@@ -134,7 +134,7 @@ void KeyboardManager::keyUp (QKeyEvent * ke)
list_widget->setAnchorRow(list_widget->firstVisibleRow());
}
- rows = m_playlist->listWidget()->model()->selectedRows();
+ rows = m_playlist->listWidget()->model()->selectedIndexes();
if (rows.first() < list_widget->firstVisibleRow() && list_widget->firstVisibleRow() > 0)
{
@@ -155,7 +155,7 @@ void KeyboardManager::keyUp (QKeyEvent * ke)
void KeyboardManager::keyDown (QKeyEvent * ke)
{
- QList<int> rows = m_playlist->listWidget()->model()->selectedRows();
+ QList<int> rows = m_playlist->listWidget()->model()->selectedIndexes();
ListWidget* list_widget = m_playlist->listWidget();
//qWarning("count: %d",rows.count());
if (rows.count() > 0)
@@ -214,7 +214,7 @@ void KeyboardManager::keyDown (QKeyEvent * ke)
list_widget->setAnchorRow(list_widget->firstVisibleRow());
}
- rows = m_playlist->listWidget()->model()->selectedRows();
+ rows = m_playlist->listWidget()->model()->selectedIndexes();
if (!rows.isEmpty() && rows.last() >= list_widget->visibleRows() + list_widget->firstVisibleRow())
{
@@ -253,7 +253,7 @@ void KeyboardManager::keyPgDown (QKeyEvent *)
void KeyboardManager::keyEnter (QKeyEvent *)
{
- QList<int> rows = m_playlist->listWidget()->model()->selectedRows();
+ QList<int> rows = m_playlist->listWidget()->model()->selectedIndexes();
MainWindow* mw = qobject_cast<MainWindow*> (m_playlist->parentWidget());
if (mw && rows.count() > 0)
{
diff --git a/src/plugins/Ui/skinned/listwidget.cpp b/src/plugins/Ui/skinned/listwidget.cpp
index a296ac53c..a327cc127 100644
--- a/src/plugins/Ui/skinned/listwidget.cpp
+++ b/src/plugins/Ui/skinned/listwidget.cpp
@@ -148,7 +148,7 @@ void ListWidget::paintEvent(QPaintEvent *)
}
}
- if (m_model->currentRow() == i + m_first)
+ if (m_model->currentIndex() == i + m_first)
m_painter.setPen(m_current);
else
m_painter.setPen(m_normal); //243,58
@@ -459,7 +459,7 @@ const QString ListWidget::getExtraString(int i)
extra_string += "|"+QString::number(index + 1)+"|";
}
- if(m_model->currentRow() == i && m_player->isRepeatable())
+ if(m_model->currentIndex() == i && m_player->isRepeatable())
extra_string += "|R|";
else if(m_model->isStopAfter(m_model->item(i)))
extra_string += "|S|";
@@ -557,10 +557,10 @@ void ListWidget::recenterCurrent()
{
if (!m_scroll && m_rows)
{
- if (m_first + m_rows < m_model->currentRow() + 1)
+ if (m_first + m_rows < m_model->currentIndex() + 1)
m_first = qMin(m_model->count() - m_rows,
- m_model->currentRow() - m_rows/2);
- else if (m_first > m_model->currentRow())
- m_first = qMax (m_model->currentRow() - m_rows/2, 0);
+ m_model->currentIndex() - m_rows/2);
+ else if (m_first > m_model->currentIndex())
+ m_first = qMax (m_model->currentIndex() - m_rows/2, 0);
}
}
diff --git a/src/plugins/Ui/skinned/playlisttitlebar.cpp b/src/plugins/Ui/skinned/playlisttitlebar.cpp
index 85e993215..4682cd7c7 100644
--- a/src/plugins/Ui/skinned/playlisttitlebar.cpp
+++ b/src/plugins/Ui/skinned/playlisttitlebar.cpp
@@ -261,7 +261,7 @@ void PlayListTitleBar::showCurrent()
PlayListItem* info = m_model->currentItem();
if (info)
{
- m_text = QString("%1. ").arg(m_model->currentRow()+1);
+ m_text = QString("%1. ").arg(m_model->currentIndex()+1);
m_text.append(info->text());
m_text.append(QString(" (%1:%2)").arg(info->length()/60)
.arg(info->length()%60, 2, 10, QChar('0')));
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