File indexing completed on 2024-05-19 04:50:00
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Bart Cerneels <bart.cerneels@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef AMAROK_COLLECTION_SQLUSERPLAYLISTPROVIDER_H 0018 #define AMAROK_COLLECTION_SQLUSERPLAYLISTPROVIDER_H 0019 0020 #include "core-impl/playlists/providers/user/UserPlaylistProvider.h" 0021 #include "SqlPlaylist.h" 0022 #include "SqlPlaylistGroup.h" 0023 0024 #include <QIcon> 0025 0026 #include <KLocalizedString> 0027 0028 0029 namespace Playlists { 0030 0031 class AMAROK_EXPORT SqlUserPlaylistProvider : public UserPlaylistProvider 0032 { 0033 Q_OBJECT 0034 public: 0035 /** 0036 * SqlUserPlaylistProvider constructor 0037 * @param debug used for unit testing; enabling means skipping 0038 * confirmation dialogs when deleting or renaming playlists. 0039 */ 0040 explicit SqlUserPlaylistProvider( bool debug = false ); 0041 ~SqlUserPlaylistProvider() override; 0042 0043 /* PlaylistProvider functions */ 0044 QString prettyName() const override { return i18n( "Amarok Database" ); } 0045 virtual QString description() const { return i18n( "Local playlists stored in the database" ); } 0046 QIcon icon() const override { return QIcon::fromTheme( QStringLiteral("server-database") ); } 0047 0048 int playlistCount() const override; 0049 Playlists::PlaylistList playlists() override; 0050 0051 virtual Playlists::PlaylistPtr save( const Meta::TrackList &tracks ); 0052 Playlists::PlaylistPtr save( const Meta::TrackList &tracks, const QString& name ) override; 0053 0054 /* UserPlaylistProvider functions */ 0055 bool isWritable() override; 0056 bool deletePlaylists( const Playlists::PlaylistList &playlistlist ) override; 0057 void renamePlaylist(Playlists::PlaylistPtr playlist, const QString &newName ) override; 0058 0059 Playlists::SqlPlaylistGroupPtr group( const QString &name ); 0060 0061 static Playlists::SqlPlaylistList toSqlPlaylists( Playlists::PlaylistList playlists ); 0062 0063 private: 0064 void reloadFromDb(); 0065 Playlists::SqlPlaylistGroupPtr m_root; 0066 0067 void createTables(); 0068 void deleteTables(); 0069 void checkTables(); 0070 /** 0071 * removes COLUMN "description" from "playlists" 0072 */ 0073 void upgradeVersion2to3(); 0074 void loadFromDb(); 0075 0076 bool deleteSqlPlaylists( Playlists::SqlPlaylistList playlistlist ); 0077 0078 Playlists::SqlPlaylistList selectedPlaylists() const 0079 { return m_selectedPlaylists; } 0080 Playlists::SqlPlaylistList m_selectedPlaylists; 0081 0082 const bool m_debug; 0083 }; 0084 0085 } //namespace Playlists 0086 0087 #endif