mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-17 07:10:44 +00:00
Addded queries for saving/loading playlists. Should also add a query for listing the playlists.
This commit is contained in:
parent
2026f54903
commit
1d7072fd8c
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
84
src/core/Query/PlaylistLoad.cpp
Normal file
84
src/core/Query/PlaylistLoad.cpp
Normal file
@ -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 <core/Query/PlaylistLoad.h>
|
||||
#include <core/Library/Base.h>
|
||||
|
||||
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));
|
||||
}
|
||||
|
87
src/core/Query/PlaylistLoad.h
Normal file
87
src/core/Query/PlaylistLoad.h
Normal file
@ -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 <boost/shared_ptr.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <core/config.h>
|
||||
#include <core/Query/ListBase.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// 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:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} }
|
||||
|
||||
|
100
src/core/Query/PlaylistSave.cpp
Normal file
100
src/core/Query/PlaylistSave.cpp
Normal file
@ -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 <core/Query/PlaylistSave.h>
|
||||
#include <core/Library/Base.h>
|
||||
|
||||
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);i<tracklist.Size();++i){
|
||||
musik::core::TrackPtr track=tracklist.Track(i);
|
||||
if(track){
|
||||
this->tracks.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);i<this->tracks.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));
|
||||
}
|
||||
|
89
src/core/Query/PlaylistSave.h
Normal file
89
src/core/Query/PlaylistSave.h
Normal file
@ -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 <boost/shared_ptr.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <core/config.h>
|
||||
#include <core/Query/Base.h>
|
||||
#include <core/tracklist/IRandomAccess.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// 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<int> tracks;
|
||||
|
||||
friend class Library::Base;
|
||||
friend class Library::LocalDB;
|
||||
|
||||
virtual bool ParseQuery(Library::Base *oLibrary,db::Connection &db);
|
||||
|
||||
Ptr copy() const;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} }
|
||||
|
||||
|
@ -298,6 +298,22 @@
|
||||
RelativePath=".\Query\ListSelection.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Query\PlaylistLoad.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Query\PlaylistLoad.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Query\PlaylistSave.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Query\PlaylistSave.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Query\TrackMetadata.cpp"
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user