diff --git a/src/core/Library/LocalDB.cpp b/src/core/Library/LocalDB.cpp index fc42490f9..c01a97373 100644 --- a/src/core/Library/LocalDB.cpp +++ b/src/core/Library/LocalDB.cpp @@ -193,6 +193,18 @@ void Library::LocalDB::CreateDatabase(){ "checksum INTEGER DEFAULT 0" ")"); + // Create the playlists-table + this->db.Execute("CREATE TABLE IF NOT EXISTS playlists (" + "id INTEGER PRIMARY KEY AUTOINCREMENT," + "name TEXT default ''" + ")"); + // Create the playlists-table + this->db.Execute("CREATE TABLE IF NOT EXISTS playlist_tracks (" + "track_id INTEGER DEFAULT 0," + "playlist_id INTEGER DEFAULT 0," + "sort_order INTEGER DEFAULT 0" + ")"); + // INDEXES this->db.Execute("CREATE UNIQUE INDEX IF NOT EXISTS folders_index ON folders (name,parent_id,path_id)"); @@ -213,6 +225,8 @@ void Library::LocalDB::CreateDatabase(){ this->db.Execute("CREATE INDEX IF NOT EXISTS metakey_index1 ON meta_keys (name)"); this->db.Execute("CREATE INDEX IF NOT EXISTS metavalues_index1 ON meta_values (meta_key_id)"); + this->db.Execute("CREATE INDEX IF NOT EXISTS playlist_index ON playlist_tracks (playlist_id,sort_order)"); + this->db.Execute("ANALYZE"); } diff --git a/src/core/Query/Base.h b/src/core/Query/Base.h index f745e6452..fc8aab1b6 100644 --- a/src/core/Query/Base.h +++ b/src/core/Query/Base.h @@ -155,7 +155,7 @@ namespace musik{ namespace core{ ///\returns ///Should return true if query is totaly finished. false otherwise. ////////////////////////////////////////// - virtual bool RunCallbacks(Library::Base *oLibrary)=0; + virtual bool RunCallbacks(Library::Base *oLibrary){return true;}; ////////////////////////////////////////// ///\brief diff --git a/src/core/Query/PlaylistLoad.cpp b/src/core/Query/PlaylistLoad.cpp new file mode 100644 index 000000000..932b26956 --- /dev/null +++ b/src/core/Query/PlaylistLoad.cpp @@ -0,0 +1,84 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright © 2008, Daniel Önnerby +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#include "pch.hpp" +#include +#include + +using namespace musik::core; + + +////////////////////////////////////////// +///\brief +///Constructor +////////////////////////////////////////// +Query::PlaylistLoad::PlaylistLoad(void){ +} + +////////////////////////////////////////// +///\brief +///Destructor +////////////////////////////////////////// +Query::PlaylistLoad::~PlaylistLoad(void){ +} + +void Query::PlaylistLoad::LoadPlaylist(int playlistId){ + this->playlistId = playlistId; +} + +bool Query::PlaylistLoad::ParseQuery(Library::Base *oLibrary,db::Connection &db){ + + db::Statement selectTracks("SELECT track_id FROM playlist_tracks WHERE playlist_id=? ORDER BY sort_order",db); + selectTracks.BindInt(0,this->playlistId); + + while(selectTracks.Step()==db::Row){ + boost::mutex::scoped_lock lock(oLibrary->oResultMutex); + this->trackResults.push_back(TrackPtr(new Track(selectTracks.ColumnInt(0)))); + } + return true; +} + +////////////////////////////////////////// +///\brief +///Copy a query +/// +///\returns +///A shared_ptr to the Query::Base +////////////////////////////////////////// +Query::Ptr Query::PlaylistLoad::copy() const{ + return Query::Ptr(new Query::PlaylistLoad(*this)); +} + diff --git a/src/core/Query/PlaylistLoad.h b/src/core/Query/PlaylistLoad.h new file mode 100644 index 000000000..d7549bfbc --- /dev/null +++ b/src/core/Query/PlaylistLoad.h @@ -0,0 +1,87 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright © 2008, Daniel Önnerby +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include + +////////////////////////////////////////////////////////////// +// Forward declarations +////////////////////////////////////////////////////////////// +namespace musik{ namespace core{ + namespace Library{ + class Base; + } +} } + + +namespace musik{ namespace core{ + namespace Query{ + + class PlaylistLoad : public Query::ListBase{ + public: + PlaylistLoad(void); + ~PlaylistLoad(void); + + void LoadPlaylist(int playlistId); + + protected: + + int playlistId; + + friend class Library::Base; + friend class Library::LocalDB; + + virtual bool ParseQuery(Library::Base *oLibrary,db::Connection &db); + + Ptr copy() const; + + private: + + }; + + } +} } + + diff --git a/src/core/Query/PlaylistSave.cpp b/src/core/Query/PlaylistSave.cpp new file mode 100644 index 000000000..82257875b --- /dev/null +++ b/src/core/Query/PlaylistSave.cpp @@ -0,0 +1,100 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright © 2008, Daniel Önnerby +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#include "pch.hpp" +#include +#include + +using namespace musik::core; + + +////////////////////////////////////////// +///\brief +///Constructor +////////////////////////////////////////// +Query::PlaylistSave::PlaylistSave(void){ +} + +////////////////////////////////////////// +///\brief +///Destructor +////////////////////////////////////////// +Query::PlaylistSave::~PlaylistSave(void){ +} + +void Query::PlaylistSave::SavePlaylist(int playlistId,musik::core::tracklist::IRandomAccess &tracklist){ + this->playlistId = playlistId; + for(int i(0);itracks.push_back(track->id); + } + } +} + +bool Query::PlaylistSave::ParseQuery(Library::Base *oLibrary,db::Connection &db){ + + db::ScopedTransaction transaction(db); + + { + db::Statement deleteTracks("DELETE FROM playlist_tracks WHERE playlist_id=?",db); + deleteTracks.BindInt(0,this->playlistId); + deleteTracks.Step(); + } + + db::Statement insertTracks("INSERT INTO playlist_tracks (track_id,playlist_id,sort_order) VALUES (?,?,?)",db); + + for(int i(0);itracks.size();++i){ + insertTracks.BindInt(0,this->tracks[i]); + insertTracks.BindInt(1,this->playlistId); + insertTracks.BindInt(2,i); + insertTracks.Step(); + insertTracks.Reset(); + } + return true; +} + +////////////////////////////////////////// +///\brief +///Copy a query +/// +///\returns +///A shared_ptr to the Query::Base +////////////////////////////////////////// +Query::Ptr Query::PlaylistSave::copy() const{ + return Query::Ptr(new Query::PlaylistSave(*this)); +} + diff --git a/src/core/Query/PlaylistSave.h b/src/core/Query/PlaylistSave.h new file mode 100644 index 000000000..f4a01e218 --- /dev/null +++ b/src/core/Query/PlaylistSave.h @@ -0,0 +1,89 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright © 2008, Daniel Önnerby +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +////////////////////////////////////////////////////////////// +// Forward declarations +////////////////////////////////////////////////////////////// +namespace musik{ namespace core{ + namespace Library{ + class Base; + } +} } + + +namespace musik{ namespace core{ + namespace Query{ + + class PlaylistSave : public Query::Base{ + public: + PlaylistSave(void); + ~PlaylistSave(void); + + void SavePlaylist(int playlistId,musik::core::tracklist::IRandomAccess &tracklist); + + protected: + + int playlistId; + std::vector tracks; + + friend class Library::Base; + friend class Library::LocalDB; + + virtual bool ParseQuery(Library::Base *oLibrary,db::Connection &db); + + Ptr copy() const; + + private: + + }; + + } +} } + + diff --git a/src/core/core.vcproj b/src/core/core.vcproj index 9f746c7a0..cdd17ab5a 100644 --- a/src/core/core.vcproj +++ b/src/core/core.vcproj @@ -298,6 +298,22 @@ RelativePath=".\Query\ListSelection.h" > + + + + + + + +