// Created by RJ Ryan (rryan@mit.edu) 1/29/2010
#include <QtDebug>
#include <QUrl>
#include "library/basesqltablemodel.h"
#include "library/coverartdelegate.h"
#include "library/stardelegate.h"
#include "library/starrating.h"
#include "library/bpmdelegate.h"
#include "library/previewbuttondelegate.h"
#include "library/locationdelegate.h"
#include "library/queryutil.h"
#include "mixer/playermanager.h"
#include "mixer/playerinfo.h"
#include "track/keyutils.h"
#include "track/trackmetadata.h"
#include "util/db/dbconnection.h"
#include "util/duration.h"
#include "util/assert.h"
#include "util/performancetimer.h"
#include "widget/wlibrarytableview.h"
static const bool sDebug = false;
// The logic in the following code relies to a track column = 0
// Do not change it without changing the logic
// Column 0 is skipped when calculating the the columns of the view table
static const int kIdColumn = 0;
static const int kMaxSortColumns = 3;
// Constant for getModelSetting(name)
static const char* COLUMNS_SORTING = "ColumnsSorting";
BaseSqlTableModel::BaseSqlTableModel(QObject* pParent,
TrackCollection* pTrackCollection,
const char* settingsNamespace)
: QAbstractTableModel(pParent),
TrackModel(pTrackCollection->database(), settingsNamespace),
m_pTrackCollection(pTrackCollection),
m_database(pTrackCollection->database()),
m_previewDeckGroup(PlayerManager::groupForPreviewDeck(0)),
m_bInitialized(false),
m_currentSearch("") {
DEBUG_ASSERT(m_pTrackCollection);
connect(&PlayerInfo::instance(),
&PlayerInfo::trackLoaded,
this,
&BaseSqlTableModel::trackLoaded);
connect(&m_pTrackCollection->getTrackDAO(),
&TrackDAO::forceModelUpdate,
this,
&BaseSqlTableModel::select);
// TODO(rryan): This is a virtual function call from a constructor.
trackLoaded(m_previewDeckGroup, PlayerInfo::instance().getTrackInfo(m_previewDeckGroup));
}
BaseSqlTableModel::~BaseSqlTableModel() {
}
void BaseSqlTableModel::initHeaderData() {
// Set the column heading labels, rename them for translations and have
// proper capitalization
// TODO(owilliams): Clean this up to make it readable.
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_TIMESPLAYED,
tr("Played"), 50);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_ARTIST,
tr("Artist"), 200);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_TITLE,
tr("Title"), 300);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_ALBUM,
tr("Album"), 200);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_ALBUMARTIST,
tr("Album Artist"), 100);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_GENRE,
tr("Genre"), 100);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_COMPOSER,
tr("Composer"), 50);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_GROUPING,
tr("Grouping"), 10);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_YEAR,
tr("Year"), 40);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_FILETYPE,
tr("Type"), 50);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_NATIVELOCATION,
tr("Location"), 100);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_COMMENT,
tr("Comment"), 250);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_DURATION,
tr("Duration"), 70);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_RATING,
tr("Rating"), 100);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_BITRATE,
tr("Bitrate"), 50);
setHeaderProperties(ColumnCache::COLUMN_LIBRARYTABLE_BPM,
tr("BPM"), 70);
setHeaderProperties(ColumnCache::