Mixxx

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

Go to the documentation of this file.
00001 // library.cpp
00002 // Created 8/23/2009 by RJ Ryan (rryan@mit.edu)
00003 
00004 #include <QItemSelectionModel>
00005 
00006 #include "library/library.h"
00007 #include "library/libraryfeature.h"
00008 #include "library/librarytablemodel.h"
00009 #include "library/sidebarmodel.h"
00010 #include "library/trackcollection.h"
00011 #include "library/trackmodel.h"
00012 #include "library/browse/browsefeature.h"
00013 #include "library/cratefeature.h"
00014 #include "library/rhythmbox/rhythmboxfeature.h"
00015 #include "library/recording/recordingfeature.h"
00016 #include "library/itunes/itunesfeature.h"
00017 #include "library/mixxxlibraryfeature.h"
00018 #include "library/autodjfeature.h"
00019 #include "library/playlistfeature.h"
00020 #include "library/preparefeature.h"
00021 #include "library/promotracksfeature.h"
00022 #include "library/traktor/traktorfeature.h"
00023 #include "library/librarycontrol.h"
00024 
00025 #include "widget/wtracktableview.h"
00026 #include "widget/wlibrary.h"
00027 #include "widget/wlibrarysidebar.h"
00028 
00029 #include "mixxxkeyboard.h"
00030 
00031 // This is is the name which we use to register the WTrackTableView with the
00032 // WLibrary
00033 const QString Library::m_sTrackViewName = QString("WTrackTableView");
00034 
00035 Library::Library(QObject* parent, ConfigObject<ConfigValue>* pConfig, bool firstRun,
00036                  RecordingManager* pRecordingManager)
00037     : m_pConfig(pConfig),
00038       m_pRecordingManager(pRecordingManager) {
00039     m_pTrackCollection = new TrackCollection(pConfig);
00040     m_pSidebarModel = new SidebarModel(parent);
00041     m_pLibraryControl = new LibraryControl(this);
00042 
00043     // TODO(rryan) -- turn this construction / adding of features into a static
00044     // method or something -- CreateDefaultLibrary
00045     m_pMixxxLibraryFeature = new MixxxLibraryFeature(this, m_pTrackCollection);
00046     addFeature(m_pMixxxLibraryFeature);
00047     if (PromoTracksFeature::isSupported(m_pConfig)) {
00048         m_pPromoTracksFeature = new PromoTracksFeature(this, pConfig,
00049                                                        m_pTrackCollection,
00050                                                        firstRun);
00051         addFeature(m_pPromoTracksFeature);
00052     } else {
00053         m_pPromoTracksFeature = NULL;
00054     }
00055 
00056     addFeature(new AutoDJFeature(this, pConfig, m_pTrackCollection));
00057     m_pPlaylistFeature = new PlaylistFeature(this, m_pTrackCollection, pConfig);
00058     addFeature(m_pPlaylistFeature);
00059     m_pCrateFeature = new CrateFeature(this, m_pTrackCollection, pConfig);
00060     addFeature(m_pCrateFeature);
00061     addFeature(new BrowseFeature(this, pConfig, m_pTrackCollection, m_pRecordingManager));
00062     addFeature(new RecordingFeature(this, pConfig, m_pTrackCollection, m_pRecordingManager));
00063     addFeature(new PrepareFeature(this, pConfig, m_pTrackCollection));
00064     //iTunes and Rhythmbox should be last until we no longer have an obnoxious
00065     //messagebox popup when you select them. (This forces you to reach for your
00066     //mouse or keyboard if you're using MIDI control and you scroll through them...)
00067     if (RhythmboxFeature::isSupported())
00068         addFeature(new RhythmboxFeature(this, m_pTrackCollection));
00069     if (ITunesFeature::isSupported())
00070         addFeature(new ITunesFeature(this, m_pTrackCollection));
00071     if (TraktorFeature::isSupported())
00072         addFeature(new TraktorFeature(this, m_pTrackCollection));
00073 
00074     //Show the promo tracks view on first run, otherwise show the library
00075     if (firstRun) {
00076         //qDebug() << "First Run, switching to PROMO view!";
00077         //This doesn't trigger onShow()... argh
00078         //m_pSidebarModel->setDefaultSelection(1);
00079         //slotSwitchToView(tr("Bundled Songs"));
00080         //Note the promo tracks item has index=1... hardcoded hack. :/
00081     }
00082 }
00083 
00084 Library::~Library() {
00085     QMutableListIterator<LibraryFeature*> features_it(m_features);
00086     while(features_it.hasNext()) {
00087         LibraryFeature* feature = features_it.next();
00088         features_it.remove();
00089         delete feature;
00090     }
00091 
00092     delete m_pLibraryControl;
00093     delete m_pSidebarModel;
00094     //IMPORTANT: m_pTrackCollection gets destroyed via the QObject hierarchy somehow.
00095     //           Qt does it for us due to the way RJ wrote all this stuff.
00096     //Update:  - OR NOT! As of Dec 8, 2009, this pointer must be destroyed manually otherwise
00097     // we never see the TrackCollection's destructor being called... - Albert
00098     delete m_pTrackCollection;
00099 }
00100 
00101 void Library::bindWidget(WLibrarySidebar* pSidebarWidget,
00102                          WLibrary* pLibraryWidget,
00103                          MixxxKeyboard* pKeyboard) {
00104     WTrackTableView* pTrackTableView =
00105             new WTrackTableView(pLibraryWidget, m_pConfig, m_pTrackCollection);
00106     pTrackTableView->installEventFilter(pKeyboard);
00107     connect(this, SIGNAL(showTrackModel(QAbstractItemModel*)),
00108             pTrackTableView, SLOT(loadTrackModel(QAbstractItemModel*)));
00109     connect(pTrackTableView, SIGNAL(loadTrack(TrackPointer)),
00110             this, SLOT(slotLoadTrack(TrackPointer)));
00111     connect(pTrackTableView, SIGNAL(loadTrackToPlayer(TrackPointer, QString)),
00112             this, SLOT(slotLoadTrackToPlayer(TrackPointer, QString)));
00113     pLibraryWidget->registerView(m_sTrackViewName, pTrackTableView);
00114 
00115     connect(this, SIGNAL(switchToView(const QString&)),
00116             pLibraryWidget, SLOT(switchToView(const QString&)));
00117 
00118     m_pLibraryControl->bindWidget(pSidebarWidget, pLibraryWidget, pKeyboard);
00119 
00120     // Setup the sources view
00121     pSidebarWidget->setModel(m_pSidebarModel);
00122     connect(m_pSidebarModel, SIGNAL(selectIndex(const QModelIndex&)),
00123             pSidebarWidget, SLOT(selectIndex(const QModelIndex&)));
00124     connect(pSidebarWidget, SIGNAL(pressed(const QModelIndex&)),
00125             m_pSidebarModel, SLOT(clicked(const QModelIndex&)));
00126     // Lazy model: Let triange symbol increment the model
00127     connect(pSidebarWidget, SIGNAL(expanded(const QModelIndex&)),
00128             m_pSidebarModel, SLOT(doubleClicked(const QModelIndex&)));
00129 
00130     connect(pSidebarWidget, SIGNAL(rightClicked(const QPoint&, const QModelIndex&)),
00131             m_pSidebarModel, SLOT(rightClicked(const QPoint&, const QModelIndex&)));
00132 
00133     QListIterator<LibraryFeature*> feature_it(m_features);
00134     while(feature_it.hasNext()) {
00135         LibraryFeature* feature = feature_it.next();
00136         feature->bindWidget(pSidebarWidget, pLibraryWidget, pKeyboard);
00137     }
00138 
00139     // Enable the default selection
00140     pSidebarWidget->selectionModel()
00141         ->select(m_pSidebarModel->getDefaultSelection(),
00142                  QItemSelectionModel::SelectCurrent);
00143     m_pSidebarModel->activateDefaultSelection();
00144 
00145 }
00146 
00147 void Library::addFeature(LibraryFeature* feature) {
00148     Q_ASSERT(feature);
00149     m_features.push_back(feature);
00150     m_pSidebarModel->addLibraryFeature(feature);
00151     connect(feature, SIGNAL(showTrackModel(QAbstractItemModel*)),
00152             this, SLOT(slotShowTrackModel(QAbstractItemModel*)));
00153     connect(feature, SIGNAL(switchToView(const QString&)),
00154             this, SLOT(slotSwitchToView(const QString&)));
00155     connect(feature, SIGNAL(loadTrack(TrackPointer)),
00156             this, SLOT(slotLoadTrack(TrackPointer)));
00157     connect(feature, SIGNAL(loadTrackToPlayer(TrackPointer, QString)),
00158             this, SLOT(slotLoadTrackToPlayer(TrackPointer, QString)));
00159     connect(feature, SIGNAL(restoreSearch(const QString&)),
00160             this, SLOT(slotRestoreSearch(const QString&)));
00161 }
00162 
00163 void Library::slotShowTrackModel(QAbstractItemModel* model) {
00164     //qDebug() << "Library::slotShowTrackModel" << model;
00165     TrackModel* trackModel = dynamic_cast<TrackModel*>(model);
00166     Q_ASSERT(trackModel);
00167     emit(showTrackModel(model));
00168     emit(switchToView(m_sTrackViewName));
00169     emit(restoreSearch(trackModel->currentSearch()));
00170 }
00171 
00172 void Library::slotSwitchToView(const QString& view) {
00173     //qDebug() << "Library::slotSwitchToView" << view;
00174     emit(switchToView(view));
00175 }
00176 
00177 void Library::slotLoadTrack(TrackPointer pTrack) {
00178     emit(loadTrack(pTrack));
00179 }
00180 
00181 void Library::slotLoadTrackToPlayer(TrackPointer pTrack, QString group) {
00182     emit(loadTrackToPlayer(pTrack, group));
00183 }
00184 
00185 void Library::slotRestoreSearch(const QString& text) {
00186     emit(restoreSearch(text));
00187 }
00188 
00189 void Library::slotRefreshLibraryModels()
00190 {
00191    m_pMixxxLibraryFeature->refreshLibraryModels();
00192 }
00193 
00194 void Library::slotCreatePlaylist()
00195 {
00196     m_pPlaylistFeature->slotCreatePlaylist();
00197 }
00198 
00199 void Library::slotCreateCrate()
00200 {
00201     m_pCrateFeature->slotCreateCrate();
00202 }
00203 
00204 
00205 QList<TrackPointer> Library::getTracksToAutoLoad()
00206 {
00207     if (m_pPromoTracksFeature)
00208         return m_pPromoTracksFeature->getTracksToAutoLoad();
00209     else
00210         return QList<TrackPointer>();
00211 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines