Started on TracklistInfo view. Only BrowseView is connected so far.

This commit is contained in:
Daniel Önnerby 2008-05-12 13:31:59 +00:00
parent 73365e99db
commit d7025b15da
6 changed files with 77 additions and 5 deletions

View File

@ -42,7 +42,12 @@
using namespace musik::core;
Query::ListBase::ListBase(void) : clearedTrackResults(false){
Query::ListBase::ListBase(void)
:clearedTrackResults(false)
,trackInfoTracks(0)
,trackInfoDuration(0)
,trackInfoSize(0)
{
}
Query::ListBase::~ListBase(void){
@ -104,6 +109,12 @@ bool Query::ListBase::RunCallbacks(Library::Base *oLibrary){
}
if(bReturn){
boost::mutex::scoped_lock lock(oLibrary->oResultMutex);
// Check for trackinfo update
this->trackInfoEvent(trackInfoTracks,trackInfoDuration,trackInfoSize);
}
return bReturn;
}
@ -119,4 +130,7 @@ Query::ListBase::TrackSignal& Query::ListBase::OnTrackEvent(){
return this->trackEvent;
}
Query::ListBase::TrackInfoSignal& Query::ListBase::OnTrackInfoEvent(){
return this->trackInfoEvent;
}

View File

@ -67,6 +67,7 @@ namespace musik{ namespace core{
typedef sigslot::signal2<MetadataValueVector*,bool> MetadataSignal;
typedef std::map<std::string,MetadataSignal> MetadataSignals;
typedef sigslot::signal2<TrackVector*,bool> TrackSignal;
typedef sigslot::signal3<UINT64,UINT64,UINT64> TrackInfoSignal;
protected:
bool RunCallbacks(Library::Base *oLibrary);
@ -79,11 +80,17 @@ namespace musik{ namespace core{
MetadataSignals metadataEvent;
TrackSignal trackEvent;
TrackInfoSignal trackInfoEvent;
UINT64 trackInfoTracks;
UINT64 trackInfoDuration;
UINT64 trackInfoSize;
public:
MetadataSignal& OnMetadataEvent(const char* metatag);
MetadataSignal& OnMetadataEvent(const wchar_t* metatag);
TrackSignal& OnTrackEvent();
TrackInfoSignal& OnTrackInfoEvent();
};
}
} }

View File

@ -271,7 +271,7 @@ bool Query::ListSelection::ParseQuery(Library::Base *oLibrary,db::Connection &db
////////////////////////////////////////////////
// Second. Select track
std::string sqlSelectTrack("SELECT t.id AS id");
std::string sqlSelectTrack("SELECT t.id AS id,t.duration AS sum_duration,t.filesize AS sum_filesize");
std::string sqlSelectTrackFrom(" FROM tracks t ");
std::string sqlSelectTrackWhere;
std::string sqlSelectTrackOrder("ORDER BY t.sort_order1");
@ -441,11 +441,13 @@ bool Query::ListSelection::ParseQuery(Library::Base *oLibrary,db::Connection &db
}
}
////////////////////////////////////////////////
// Select tracks
if(this->trackEvent.has_connections() && !oLibrary->QueryCanceled()){
std::string sql("SELECT t.id FROM tracks t ORDER BY t.sort_order1");
std::string sql("SELECT t.id,t.duration,t.filesize FROM tracks t ORDER BY t.sort_order1");
if(!metakeysSelectedCopy.empty()){
sql = "SELECT t.id FROM temp_tracks_list t";
sql = "SELECT t.id,t.sum_duration,t.sum_filesize FROM temp_tracks_list t";
}
db::CachedStatement tracks(sql.c_str(),db);
@ -454,12 +456,23 @@ bool Query::ListSelection::ParseQuery(Library::Base *oLibrary,db::Connection &db
TrackVector tempTrackResults;
tempTrackResults.reserve(101);
int row(0);
UINT64 duration(0);
UINT64 filesize(0);
while(tracks.Step()==db::ReturnCode::Row){
tempTrackResults.push_back(TrackPtr(new Track(tracks.ColumnInt(0))));
duration += tracks.ColumnInt64(1);
filesize += tracks.ColumnInt64(2);
if( (++row)%100==0 ){
boost::mutex::scoped_lock lock(oLibrary->oResultMutex);
this->trackResults.insert(this->trackResults.end(),tempTrackResults.begin(),tempTrackResults.end());
this->trackInfoTracks += tempTrackResults.size();
this->trackInfoDuration += duration;
this->trackInfoSize += filesize;
filesize = 0;
duration = 0;
tempTrackResults.clear();
trackResults.reserve(101);
}
@ -467,6 +480,11 @@ bool Query::ListSelection::ParseQuery(Library::Base *oLibrary,db::Connection &db
if(!tempTrackResults.empty()){
boost::mutex::scoped_lock lock(oLibrary->oResultMutex);
this->trackResults.insert(this->trackResults.end(),tempTrackResults.begin(),tempTrackResults.end());
this->trackInfoTracks += tempTrackResults.size();
this->trackInfoDuration += duration;
this->trackInfoSize += filesize;
}
}

View File

@ -57,6 +57,11 @@ using namespace musik::cube;
this->view.Handle()
? this->OnViewCreated(&view)
: this->view.Created.connect(this, &TracklistController::OnViewCreated);
if(connectedQuery){
connectedQuery->OnTrackInfoEvent().connect(this,&TracklistController::OnTracklistInfo);
}
}
void TracklistController::OnViewCreated(Window* window)
@ -91,3 +96,26 @@ void TracklistController::AddColumn(const utfchar *name,const char *metak
((TracklistModel*)this->model.get())->tracklist->AddRequestedMetakey(metakey);
}
void TracklistController::OnTracklistInfo(UINT64 tracks,UINT64 duration,UINT64 filesize){
if(this->view.infoView){
typedef boost::basic_format<uichar> format;
this->view.infoView->trackCountLabel->SetCaption( (format(_T("%1%"))%tracks).str() );
UINT64 days(duration/86400);
duration = duration%86400;
UINT64 hours(duration/3600);
duration = duration%3600;
UINT64 minutes(duration/60);
duration = duration%60;
this->view.infoView->durationLabel->SetCaption( (format(_T("%d days, %02d:%02d:%02d"))%days%hours%minutes%duration).str() );
if(filesize<1048576){
this->view.infoView->sizeLabel->SetCaption( (format(_T("%.2f KB"))%((double)filesize/(double)1024)).str() );
}else if(filesize<1073741824){
this->view.infoView->sizeLabel->SetCaption( (format(_T("%.2f MB"))%((double)filesize/(double)1048576)).str() );
}else{
this->view.infoView->sizeLabel->SetCaption( (format(_T("%.2f GB"))%((double)filesize/(double)1073741824)).str() );
}
}
}

View File

@ -76,6 +76,7 @@ protected: void AddColumn(const utfchar *name, const char *metakey, int
protected: ModelRef model;
protected: TracklistView& view;
protected: ColumnList columns;
private: void OnTracklistInfo(UINT64 tracks,UINT64 duration,UINT64 filesize);
};

View File

@ -38,16 +38,20 @@
#pragma once
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
namespace musik { namespace cube {
// Forward
class TracklistController;
//////////////////////////////////////////////////////////////////////////////
class TracklistInfoView: public LinearLayout
{
friend class TracklistController;
private: typedef LinearLayout base;
public: /*ctor*/ TracklistInfoView();