Implemented equalizer
[someplayer] / src / filestorage.cpp
index 93c7261..3dab290 100644 (file)
@@ -1,10 +1,28 @@
+/*
+ * SomePlayer - An alternate music player for Maemo 5
+ * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
+ *
+ * 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 "filestorage.h"
 #include <QDir>
 #include <QDirIterator>
 #include <QFileInfo>
 #include <QTextStream>
 #include <QRegExp>
-#include <QDebug>
 
 using namespace SomePlayer::Storage;
 using namespace SomePlayer::DataObjects;
@@ -27,6 +45,8 @@ QList<Playlist> FileStorage::getPlaylists() {
 }
 
 Playlist FileStorage::getPlaylist(QString name) {
+       if (name == _CURRENT_PLAYLIST_SUBST_)
+               name = _CURRENT_PLAYLIST_NAME_;
        QFile playlistFile (_path_prefix+"/"+name+"."+_PLAYLIST_FILE_EXTENSION_);
        Playlist playlist;
        playlist.setName(PLAYLIST_BAD_NAME);
@@ -68,6 +88,8 @@ QStringList FileStorage::getPlaylistsNames() {
                QString suffix = info.suffix().toLower();
                if (suffix == _PLAYLIST_FILE_EXTENSION_) {
                        QString name = info.fileName().replace(QString(".%1").arg(_PLAYLIST_FILE_EXTENSION_), "", Qt::CaseInsensitive);
+                       if (name == _CURRENT_PLAYLIST_NAME_)
+                           name = _CURRENT_PLAYLIST_SUBST_;
                        playlistNames.append(name);
                }
        }
@@ -75,7 +97,10 @@ QStringList FileStorage::getPlaylistsNames() {
 }
 
 void FileStorage::savePlaylist(Playlist playlist) {
-       QString filename = _path_prefix + "/" +playlist.name()+"."_PLAYLIST_FILE_EXTENSION_;
+       QString name = playlist.name();
+       if (playlist.name() == _CURRENT_PLAYLIST_SUBST_)
+               name = _CURRENT_PLAYLIST_NAME_;
+       QString filename = _path_prefix + "/" +name+"."_PLAYLIST_FILE_EXTENSION_;
        QFile playlistFile(filename);
        if (playlistFile.exists()) {
                playlistFile.remove();
@@ -99,7 +124,8 @@ void FileStorage::removePlaylist(Playlist playlist) {
 }
 
 void FileStorage::removePlaylist(QString name) {
-       QString filename = _path_prefix + "/" + name + "." + _PLAYLIST_FILE_EXTENSION_;
+       QString filename = _path_prefix + "/" + (name == _CURRENT_PLAYLIST_SUBST_ ? _CURRENT_PLAYLIST_NAME_ : name)
+                          + "." + _PLAYLIST_FILE_EXTENSION_;
        QFile file(filename);
        file.remove();
 }