Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/library/mixxxlibraryfeature.cpp

Go to the documentation of this file.
00001 // mixxxlibraryfeature.cpp
00002 // Created 8/23/2009 by RJ Ryan (rryan@mit.edu)
00003 
00004 #include <QtDebug>
00005 
00006 #include "library/mixxxlibraryfeature.h"
00007 
00008 #include "library/basetrackcache.h"
00009 #include "library/librarytablemodel.h"
00010 #include "library/missingtablemodel.h"
00011 #include "library/queryutil.h"
00012 #include "library/trackcollection.h"
00013 #include "treeitem.h"
00014 
00015 #define CHILD_MISSING "Missing Songs"
00016 
00017 MixxxLibraryFeature::MixxxLibraryFeature(QObject* parent,
00018                                          TrackCollection* pTrackCollection)
00019         : LibraryFeature(parent) {
00020     QStringList columns;
00021     columns << "library." + LIBRARYTABLE_ID
00022             << "library." + LIBRARYTABLE_PLAYED
00023             << "library." + LIBRARYTABLE_TIMESPLAYED
00024             << "library." + LIBRARYTABLE_ARTIST
00025             << "library." + LIBRARYTABLE_TITLE
00026             << "library." + LIBRARYTABLE_ALBUM
00027             << "library." + LIBRARYTABLE_YEAR
00028             << "library." + LIBRARYTABLE_DURATION
00029             << "library." + LIBRARYTABLE_RATING
00030             << "library." + LIBRARYTABLE_GENRE
00031             << "library." + LIBRARYTABLE_FILETYPE
00032             << "library." + LIBRARYTABLE_TRACKNUMBER
00033             << "library." + LIBRARYTABLE_KEY
00034             << "library." + LIBRARYTABLE_DATETIMEADDED
00035             << "library." + LIBRARYTABLE_BPM
00036             << "library." + LIBRARYTABLE_BITRATE
00037             << "track_locations.location"
00038             << "track_locations.fs_deleted"
00039             << "library." + LIBRARYTABLE_COMMENT
00040             << "library." + LIBRARYTABLE_MIXXXDELETED;
00041 
00042     QSqlQuery query(pTrackCollection->getDatabase());
00043     QString tableName = "library_cache_view";
00044     QString queryString = QString(
00045         "CREATE TEMPORARY VIEW IF NOT EXISTS %1 AS "
00046         "SELECT %2 FROM library "
00047         "INNER JOIN track_locations ON library.location = track_locations.id")
00048             .arg(tableName)
00049             .arg(columns.join(","));
00050     query.prepare(queryString);
00051     if (!query.exec()) {
00052         LOG_FAILED_QUERY(query);
00053     }
00054 
00055     // Strip out library. and track_locations.
00056     for (QStringList::iterator it = columns.begin();
00057          it != columns.end(); ++it) {
00058         if (it->startsWith("library.")) {
00059             *it = it->replace("library.", "");
00060         } else if (it->startsWith("track_locations.")) {
00061             *it = it->replace("track_locations.", "");
00062         }
00063     }
00064 
00065     BaseTrackCache* pBaseTrackCache = new BaseTrackCache(
00066         pTrackCollection, tableName, LIBRARYTABLE_ID, columns, true);
00067     connect(&pTrackCollection->getTrackDAO(), SIGNAL(trackDirty(int)),
00068             pBaseTrackCache, SLOT(slotTrackDirty(int)));
00069     connect(&pTrackCollection->getTrackDAO(), SIGNAL(trackClean(int)),
00070             pBaseTrackCache, SLOT(slotTrackClean(int)));
00071     connect(&pTrackCollection->getTrackDAO(), SIGNAL(trackChanged(int)),
00072             pBaseTrackCache, SLOT(slotTrackChanged(int)));
00073     connect(&pTrackCollection->getTrackDAO(), SIGNAL(tracksAdded(QSet<int>)),
00074             pBaseTrackCache, SLOT(slotTracksAdded(QSet<int>)));
00075     connect(&pTrackCollection->getTrackDAO(), SIGNAL(tracksRemoved(QSet<int>)),
00076             pBaseTrackCache, SLOT(slotTracksRemoved(QSet<int>)));
00077 
00078     m_pBaseTrackCache = QSharedPointer<BaseTrackCache>(pBaseTrackCache);
00079     pTrackCollection->addTrackSource(QString("default"), m_pBaseTrackCache);
00080 
00081     // These rely on the 'default' track source being present.
00082     m_pLibraryTableModel = new LibraryTableModel(this, pTrackCollection);
00083     m_pMissingTableModel = new MissingTableModel(this, pTrackCollection);
00084 
00085     TreeItem *rootItem = new TreeItem();
00086     TreeItem *childItem = new TreeItem(CHILD_MISSING, CHILD_MISSING,
00087                                        this, rootItem);
00088     rootItem->appendChild(childItem);
00089     m_childModel.setRootItem(rootItem);
00090 }
00091 
00092 MixxxLibraryFeature::~MixxxLibraryFeature() {
00093     delete m_pLibraryTableModel;
00094     delete m_pMissingTableModel;
00095 }
00096 
00097 QVariant MixxxLibraryFeature::title() {
00098     return tr("Library");
00099 }
00100 
00101 QIcon MixxxLibraryFeature::getIcon() {
00102     return QIcon(":/images/library/ic_library_library.png");
00103 }
00104 
00105 TreeItemModel* MixxxLibraryFeature::getChildModel() {
00106     return &m_childModel;
00107 }
00108 
00109 void MixxxLibraryFeature::refreshLibraryModels()
00110 {
00111     if (m_pBaseTrackCache) {
00112         m_pBaseTrackCache->buildIndex();
00113     }
00114     if (m_pLibraryTableModel) {
00115         m_pLibraryTableModel->select();
00116     }
00117     if (m_pMissingTableModel) {
00118         m_pMissingTableModel->select();
00119     }
00120 }
00121 
00122 void MixxxLibraryFeature::activate() {
00123     qDebug() << "MixxxLibraryFeature::activate()";
00124     emit(showTrackModel(m_pLibraryTableModel));
00125 }
00126 
00127 void MixxxLibraryFeature::activateChild(const QModelIndex& index) {
00128     QString itemName = index.data().toString();
00129 
00130     /*if (itemName == m_childModel.stringList().at(0))
00131         emit(showTrackModel(m_pMissingTableModel));
00132      */
00133     if (itemName == CHILD_MISSING)
00134         emit(showTrackModel(m_pMissingTableModel));
00135 }
00136 
00137 void MixxxLibraryFeature::onRightClick(const QPoint& globalPos) {
00138 }
00139 
00140 void MixxxLibraryFeature::onRightClickChild(const QPoint& globalPos,
00141                                             QModelIndex index) {
00142 }
00143 
00144 bool MixxxLibraryFeature::dropAccept(QUrl url) {
00145     return false;
00146 }
00147 
00148 bool MixxxLibraryFeature::dropAcceptChild(const QModelIndex& index, QUrl url) {
00149     return false;
00150 }
00151 
00152 bool MixxxLibraryFeature::dragMoveAccept(QUrl url) {
00153     return false;
00154 }
00155 
00156 bool MixxxLibraryFeature::dragMoveAcceptChild(const QModelIndex& index,
00157                                               QUrl url) {
00158     return false;
00159 }void MixxxLibraryFeature::onLazyChildExpandation(const QModelIndex &index){
00160 //Nothing to do because the childmodel is not of lazy nature.
00161 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines