aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2015-02-28 19:58:56 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2015-02-28 19:58:56 +0000
commit48e1a9a6ee0f282c688072c2622c6756800fbc1c (patch)
treebbb7b95bf0ab2f6ef5b49992a8442d233cb1d9ad /src/qmmpui
parentd070edaee5fadeec66e44d2add8fdebe0bac983f (diff)
downloadqmmp-48e1a9a6ee0f282c688072c2622c6756800fbc1c.tar.gz
qmmp-48e1a9a6ee0f282c688072c2622c6756800fbc1c.tar.bz2
qmmp-48e1a9a6ee0f282c688072c2622c6756800fbc1c.zip
added ColumnManager class, reverted previous commit
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@4746 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui')
-rw-r--r--src/qmmpui/columnmanager.cpp160
-rw-r--r--src/qmmpui/columnmanager.h69
-rw-r--r--src/qmmpui/playlistgroup.cpp5
-rw-r--r--src/qmmpui/playlistgroup.h3
-rw-r--r--src/qmmpui/playlistitem.h3
-rw-r--r--src/qmmpui/playlistmanager.cpp6
-rw-r--r--src/qmmpui/playlistmanager.h5
-rw-r--r--src/qmmpui/playlisttrack.cpp3
-rw-r--r--src/qmmpui/playlisttrack.h3
-rw-r--r--src/qmmpui/qmmpui.pro6
-rw-r--r--src/qmmpui/qmmpuisettings.cpp24
-rw-r--r--src/qmmpui/qmmpuisettings.h7
12 files changed, 262 insertions, 32 deletions
diff --git a/src/qmmpui/columnmanager.cpp b/src/qmmpui/columnmanager.cpp
new file mode 100644
index 000000000..fd4e028a0
--- /dev/null
+++ b/src/qmmpui/columnmanager.cpp
@@ -0,0 +1,160 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include <QSettings>
+#include <qmmp/qmmp.h>
+#include "columnmanager.h"
+
+ColumnManager::ColumnManager(QObject *parent) :
+ QObject(parent)
+{
+ QSettings s (Qmmp::configFile(), QSettings::IniFormat);
+ s.beginGroup("PlayList");
+ int c = s.value("column_count", 2).toInt();
+ for(int i = 0; i < c; ++i)
+ {
+ s.beginGroup(QString("column%1").arg(i));
+ Column col;
+ col.name = s.value("name", tr("Album - Title")).toString();
+ col.pattern = s.value("pattern", "%p%if(%p&%t, - ,)%t").toString();
+ col.size = s.value("size", 150).toInt();
+ col.titleFormatter = new MetaDataFormatter(col.pattern);
+ m_columns.append(col);
+ s.endGroup();
+ }
+ s.endGroup();
+}
+
+ColumnManager::~ColumnManager()
+{
+ sync();
+ foreach (Column col, m_columns)
+ {
+ delete col.titleFormatter;
+ col.titleFormatter = 0;
+ }
+ m_columns.clear();
+}
+
+void ColumnManager::insert(int index, const QString &name, const QString &pattern)
+{
+ if(index < 0 || index >= m_columns.size())
+ qWarning("ColumnManager: index is out of range");
+
+ Column col;
+ col.name = name;
+ col.pattern = pattern;
+ col.titleFormatter = new MetaDataFormatter(pattern);
+ m_columns.insert(index, col);
+ sync();
+ emit inserted(index);
+}
+
+void ColumnManager::remove(int index)
+{
+ if(index < 0 || index >= m_columns.size())
+ qWarning("ColumnManager: index is out of range");
+
+ delete m_columns.takeAt(index).titleFormatter;
+ sync();
+ emit removed(index);
+}
+
+void ColumnManager::resize(int index, int size)
+{
+ if(index < 0 || index >= m_columns.size())
+ qWarning("ColumnManager: index is out of range");
+
+ m_columns[index].size = size;
+ sync();
+ emit resized(index);
+}
+
+void ColumnManager::execEditor(int index, QWidget *parent)
+{
+
+}
+
+int ColumnManager::count()
+{
+ return m_columns.count();
+}
+
+const MetaDataFormatter *ColumnManager::titleFormatter(int index) const
+{
+ if(index < 0 || index >= m_columns.size())
+ {
+ qWarning("ColumnManager: index is out of range");
+ return 0;
+ }
+ return m_columns[index].titleFormatter;
+}
+
+int ColumnManager::size(int index) const
+{
+ if(index < 0 || index >= m_columns.size())
+ {
+ qWarning("ColumnManager: index is out of range");
+ return 0;
+ }
+ return m_columns.count();
+}
+
+const QString ColumnManager::name(int index) const
+{
+ if(index < 0 || index >= m_columns.size())
+ {
+ qWarning("ColumnManager: index is out of range");
+ return QString();
+ }
+ return m_columns[index].name;
+}
+const QString ColumnManager::pattern(int index) const
+{
+ if(index < 0 || index >= m_columns.size())
+ {
+ qWarning("ColumnManager: index is out of range");
+ return QString();
+ }
+ return m_columns[index].pattern;
+}
+
+void ColumnManager::sync()
+{
+ QSettings s (Qmmp::configFile(), QSettings::IniFormat);
+ s.beginGroup("PlayList");
+ int old_count = s.value("column_count", 1).toInt();
+ s.setValue("column_count", m_columns.count());
+ for(int i = 0; i < m_columns.count(); ++i)
+ {
+ s.beginGroup(QString("column%1").arg(i));
+ Column col = m_columns.at(i);
+ s.setValue("name", col.name);
+ s.setValue("pattern", col.pattern);
+ s.value("size", col.size).toInt();
+ s.endGroup();
+ }
+ s.setValue("column_count", m_columns.count());
+ for(int i = m_columns.count(); i < old_count; ++i)
+ {
+ s.remove(QString("column%1").arg(i));
+ }
+ s.endGroup();
+}
diff --git a/src/qmmpui/columnmanager.h b/src/qmmpui/columnmanager.h
new file mode 100644
index 000000000..587480bb4
--- /dev/null
+++ b/src/qmmpui/columnmanager.h
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef COLUMNMANAGER_H
+#define COLUMNMANAGER_H
+
+#include <QObject>
+#include <QWidget>
+#include "metadataformatter.h"
+
+/**
+ * @author Ilya Kotov <forkotov02@hotmail.ru>
+ */
+class ColumnManager : public QObject
+{
+ Q_OBJECT
+public:
+ explicit ColumnManager(QObject *parent = 0);
+
+ ~ColumnManager();
+
+ void insert(int index, const QString &name, const QString &pattern);
+ void remove(int index);
+ void resize(int index, int size);
+ void execEditor(int index, QWidget *parent = 0);
+
+ int count();
+ const MetaDataFormatter* titleFormatter(int index) const;
+ int size(int index) const;
+ const QString name(int index) const;
+ const QString pattern(int index) const;
+
+signals:
+ void inserted(int index);
+ void removed(int index);
+ void changed(int index);
+ void resized(int index);
+ void moved(int from, int to);
+
+private:
+ void sync();
+ struct Column
+ {
+ QString name;
+ QString pattern;
+ QString size;
+ MetaDataFormatter *titleFormatter;
+ };
+ QList<Column> m_columns;
+};
+
+#endif // COLUMNMANAGER_H
diff --git a/src/qmmpui/playlistgroup.cpp b/src/qmmpui/playlistgroup.cpp
index ede365d89..ad3a5bc16 100644
--- a/src/qmmpui/playlistgroup.cpp
+++ b/src/qmmpui/playlistgroup.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2013-2015 by Ilya Kotov *
+ * Copyright (C) 2013-2014 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -38,9 +38,8 @@ PlayListGroup::~PlayListGroup()
}
}
-const QString PlayListGroup::formattedTitle(int column)
+const QString PlayListGroup::formattedTitle()
{
- Q_UNUSED(column);
return m_name;
}
diff --git a/src/qmmpui/playlistgroup.h b/src/qmmpui/playlistgroup.h
index 8db56c1ed..2a9f3be3a 100644
--- a/src/qmmpui/playlistgroup.h
+++ b/src/qmmpui/playlistgroup.h
@@ -43,9 +43,8 @@ public:
virtual ~PlayListGroup();
/*!
* Returns formatted title of the group.
- * @param column Number of column (unused).
*/
- const QString formattedTitle(int column = 0);
+ const QString formattedTitle();
/*!
* Returns \b true if the group contains track \b track.
* Otherwise returns \b false.
diff --git a/src/qmmpui/playlistitem.h b/src/qmmpui/playlistitem.h
index 0ec73e372..5739db5be 100644
--- a/src/qmmpui/playlistitem.h
+++ b/src/qmmpui/playlistitem.h
@@ -50,9 +50,8 @@ public:
bool isSelected() const;
/*!
* Returns formatted title of the item.
- * @param column Number of column.
*/
- virtual const QString formattedTitle(int column = 0) = 0;
+ virtual const QString formattedTitle() = 0;
/*!
* Returns formatted length of the item.
*/
diff --git a/src/qmmpui/playlistmanager.cpp b/src/qmmpui/playlistmanager.cpp
index 17dbd67e8..484f9da81 100644
--- a/src/qmmpui/playlistmanager.cpp
+++ b/src/qmmpui/playlistmanager.cpp
@@ -36,6 +36,7 @@ PlayListManager::PlayListManager(QObject *parent) : QObject(parent)
qFatal("PlayListManager: only one instance is allowed");
m_instance = this;
m_ui_settings = QmmpUiSettings::instance();
+ m_column_manager = new ColumnManager(this);
m_current = 0;
m_selected = 0;
m_timer = new QTimer(this);
@@ -56,6 +57,11 @@ PlayListManager* PlayListManager::instance()
return m_instance;
}
+ColumnManager *PlayListManager::columnManager() const
+{
+ return m_column_manager;
+}
+
PlayListModel *PlayListManager::selectedPlayList() const
{
return m_selected;
diff --git a/src/qmmpui/playlistmanager.h b/src/qmmpui/playlistmanager.h
index 4222273aa..fafb9865d 100644
--- a/src/qmmpui/playlistmanager.h
+++ b/src/qmmpui/playlistmanager.h
@@ -21,6 +21,7 @@
#define PLAYLISTMANAGER_H
#include <QObject>
+#include "columnmanager.h"
#include "playlistmodel.h"
class QTimer;
@@ -46,6 +47,9 @@ public:
* Returns a pointer to the object's instance.
*/
static PlayListManager* instance();
+
+
+ ColumnManager *columnManager() const;
/*!
* Returns a list of all playlists.
*/
@@ -249,6 +253,7 @@ private:
PlayListModel *m_selected;
QTimer *m_timer;
QmmpUiSettings *m_ui_settings;
+ ColumnManager *m_column_manager;
};
#endif // PLAYLISTMANAGER_H
diff --git a/src/qmmpui/playlisttrack.cpp b/src/qmmpui/playlisttrack.cpp
index f1c8d2fca..b9262c72b 100644
--- a/src/qmmpui/playlisttrack.cpp
+++ b/src/qmmpui/playlisttrack.cpp
@@ -126,9 +126,8 @@ bool PlayListTrack::isUsed() const
return (m_refCount != 0);
}
-const QString PlayListTrack::formattedTitle(int column)
+const QString PlayListTrack::formattedTitle()
{
- Q_UNUSED(column);
if(m_formattedTitle.isEmpty() || m_titleFormat != m_settings->titleFormat())
{
m_titleFormat = m_settings->titleFormat();
diff --git a/src/qmmpui/playlisttrack.h b/src/qmmpui/playlisttrack.h
index aa7ab59fb..810be411a 100644
--- a/src/qmmpui/playlisttrack.h
+++ b/src/qmmpui/playlisttrack.h
@@ -52,9 +52,8 @@ public:
virtual ~PlayListTrack();
/*!
* Returns formatted title of the item.
- * @param column Number of column.
*/
- const QString formattedTitle(int column = 0);
+ const QString formattedTitle();
/*!
* Returns formatted length of the item.
*/
diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro
index ebccd9594..a4593030f 100644
--- a/src/qmmpui/qmmpui.pro
+++ b/src/qmmpui/qmmpui.pro
@@ -69,7 +69,8 @@ HEADERS += general.h \
groupedcontainer_p.h \
normalcontainer_p.h \
playlisttask_p.h \
- metadataformatter.h
+ metadataformatter.h \
+ columnmanager.h
SOURCES += general.cpp \
playlistparser.cpp \
@@ -103,7 +104,8 @@ SOURCES += general.cpp \
normalcontainer.cpp \
playlistcontainer.cpp \
playlisttask.cpp \
- metadataformatter.cpp
+ metadataformatter.cpp \
+ columnmanager.cpp
FORMS += forms/detailsdialog.ui \
forms/tageditor.ui \
diff --git a/src/qmmpui/qmmpuisettings.cpp b/src/qmmpui/qmmpuisettings.cpp
index 53c137a05..c7355ecb3 100644
--- a/src/qmmpui/qmmpuisettings.cpp
+++ b/src/qmmpui/qmmpuisettings.cpp
@@ -34,8 +34,7 @@ QmmpUiSettings::QmmpUiSettings(QObject *parent) : QObject(parent)
m_instance = this;
QSettings s (Qmmp::configFile(), QSettings::IniFormat);
s.beginGroup("PlayList");
- m_title_formats = s.value("title_formats", QStringList() << "%p%if(%p&%t, - ,)%t")
- .toStringList();
+ m_title_format = s.value("title_format", "%p%if(%p&%t, - ,)%t").toString();
m_group_format = s.value("group_format", "%p%if(%p&%a, - %if(%y,[%y] ,),)%a").toString();
m_convertUnderscore = s.value ("convert_underscore", true).toBool();
m_convertTwenty = s.value ("convert_twenty", true).toBool();
@@ -62,23 +61,18 @@ QmmpUiSettings::QmmpUiSettings(QObject *parent) : QObject(parent)
connect(m_timer, SIGNAL(timeout()), SLOT(sync()));
m_group_formatter.setPattern(m_group_format);
-
- foreach (QString pattern, m_title_formats)
- {
- m_title_formatters << new MetaDataFormatter(pattern);
- }
+ m_title_formatter.setPattern(m_title_format);
}
QmmpUiSettings::~QmmpUiSettings()
{
m_instance = 0;
sync();
- qDeleteAll(m_title_formatters);
}
const QString QmmpUiSettings::titleFormat() const
{
- return m_title_formats.first();
+ return m_title_format;
}
const QString QmmpUiSettings::groupFormat() const
@@ -138,10 +132,10 @@ void QmmpUiSettings::setConvertTwenty(bool yes)
void QmmpUiSettings::setTitleFormat(const QString &titleFormat)
{
- if(titleFormat != m_title_formats.first())
+ if(titleFormat != m_title_format)
{
- m_title_formats[0] = titleFormat;
- m_title_formatters[0]->setPattern(titleFormat);
+ m_title_format = titleFormat;
+ m_title_formatter.setPattern(titleFormat);
foreach(PlayListModel *model, PlayListManager::instance()->playLists())
{
model->updateMetaData();
@@ -191,7 +185,7 @@ void QmmpUiSettings::sync()
{
qDebug("%s", Q_FUNC_INFO);
QSettings s(Qmmp::configFile(), QSettings::IniFormat);
- s.setValue("PlayList/title_formats", m_title_formats);
+ s.setValue("PlayList/title_format", m_title_format);
s.setValue("PlayList/group_format", m_group_format);
s.setValue("PlayList/convert_underscore", m_convertUnderscore);
s.setValue("PlayList/convert_twenty", m_convertTwenty);
@@ -324,9 +318,9 @@ bool QmmpUiSettings::clearPreviousPlayList() const
return m_clear_prev_playlist;
}
-const MetaDataFormatter *QmmpUiSettings::titleFormatter(int column) const
+const MetaDataFormatter *QmmpUiSettings::titleFormatter() const
{
- return m_title_formatters[column];
+ return &m_title_formatter;
}
const MetaDataFormatter *QmmpUiSettings::groupFormatter() const
diff --git a/src/qmmpui/qmmpuisettings.h b/src/qmmpui/qmmpuisettings.h
index 61d62f033..0380135ca 100644
--- a/src/qmmpui/qmmpuisettings.h
+++ b/src/qmmpui/qmmpuisettings.h
@@ -182,7 +182,7 @@ public:
*/
bool clearPreviousPlayList() const;
- const MetaDataFormatter* titleFormatter(int column = 0) const;
+ const MetaDataFormatter* titleFormatter() const;
const MetaDataFormatter* groupFormatter() const;
/*!
@@ -256,7 +256,7 @@ private slots:
private:
static QmmpUiSettings* m_instance;
//playlist
- QStringList m_title_formats;
+ QString m_title_format;
QString m_group_format;
bool m_convertUnderscore, m_convertTwenty;
bool m_useMetadata;
@@ -278,8 +278,7 @@ private:
//timer
QTimer *m_timer;
//formatters
- MetaDataFormatter m_group_formatter;
- QList<MetaDataFormatter *> m_title_formatters;
+ MetaDataFormatter m_group_formatter, m_title_formatter;
};
#endif // QMMPUISETTINGS_H