![]() |
Mixxx
|
00001 // autodjfeature.cpp 00002 // FORK FORK FORK on 11/1/2009 by Albert Santoni (alberts@mixxx.org) 00003 // Created 8/23/2009 by RJ Ryan (rryan@mit.edu) 00004 00005 #include <QtDebug> 00006 00007 #include "library/autodjfeature.h" 00008 #include "library/playlisttablemodel.h" 00009 00010 #include "library/trackcollection.h" 00011 #include "dlgautodj.h" 00012 #include "widget/wlibrary.h" 00013 #include "widget/wlibrarysidebar.h" 00014 #include "mixxxkeyboard.h" 00015 #include "soundsourceproxy.h" 00016 00017 const QString AutoDJFeature::m_sAutoDJViewName = QString("Auto DJ"); 00018 00019 AutoDJFeature::AutoDJFeature(QObject* parent, 00020 ConfigObject<ConfigValue>* pConfig, 00021 TrackCollection* pTrackCollection) 00022 : LibraryFeature(parent), 00023 m_pConfig(pConfig), 00024 m_pTrackCollection(pTrackCollection), 00025 m_playlistDao(pTrackCollection->getPlaylistDAO()) { 00026 } 00027 00028 AutoDJFeature::~AutoDJFeature() { 00029 } 00030 00031 QVariant AutoDJFeature::title() { 00032 return tr("Auto DJ"); 00033 } 00034 00035 QIcon AutoDJFeature::getIcon() { 00036 return QIcon(":/images/library/ic_library_autodj.png"); 00037 } 00038 00039 void AutoDJFeature::bindWidget(WLibrarySidebar* sidebarWidget, 00040 WLibrary* libraryWidget, 00041 MixxxKeyboard* keyboard) { 00042 00043 DlgAutoDJ* pAutoDJView = new DlgAutoDJ(libraryWidget, 00044 m_pConfig, 00045 m_pTrackCollection, 00046 keyboard); 00047 pAutoDJView->installEventFilter(keyboard); 00048 libraryWidget->registerView(m_sAutoDJViewName, pAutoDJView); 00049 connect(pAutoDJView, SIGNAL(loadTrack(TrackPointer)), 00050 this, SIGNAL(loadTrack(TrackPointer))); 00051 connect(pAutoDJView, SIGNAL(loadTrackToPlayer(TrackPointer, QString)), 00052 this, SIGNAL(loadTrackToPlayer(TrackPointer, QString))); 00053 } 00054 00055 TreeItemModel* AutoDJFeature::getChildModel() { 00056 return &m_childModel; 00057 } 00058 00059 void AutoDJFeature::activate() { 00060 //qDebug() << "AutoDJFeature::activate()"; 00061 //emit(showTrackModel(m_pAutoDJTableModelProxy)); 00062 emit(switchToView("Auto DJ")); 00063 } 00064 00065 void AutoDJFeature::activateChild(const QModelIndex& index) { 00066 00067 } 00068 00069 void AutoDJFeature::onRightClick(const QPoint& globalPos) { 00070 } 00071 00072 void AutoDJFeature::onRightClickChild(const QPoint& globalPos, 00073 QModelIndex index) { 00074 } 00075 00076 bool AutoDJFeature::dropAccept(QUrl url) { 00077 00078 //TODO: Filter by supported formats regex and reject anything that doesn't match. 00079 00080 TrackDAO &trackDao = m_pTrackCollection->getTrackDAO(); 00081 00082 //If a track is dropped onto a playlist's name, but the track isn't in the library, 00083 //then add the track to the library before adding it to the playlist. 00084 00085 //XXX: See the note in PlaylistFeature::dropAccept() about using QUrl::toLocalFile() 00086 // instead of toString() 00087 QFileInfo file(url.toLocalFile()); 00088 00089 if (!SoundSourceProxy::isFilenameSupported(file.fileName())) { 00090 return false; 00091 } 00092 00093 // Adds track, does not insert duplicates, handles unremoving logic. 00094 int trackId = trackDao.addTrack(file, true); 00095 00096 if (trackId < 0) { 00097 return false; 00098 } 00099 00100 // TODO(XXX) No feedback on whether this worked. 00101 int playlistId = m_playlistDao.getPlaylistIdFromName(AUTODJ_TABLE); 00102 m_playlistDao.appendTrackToPlaylist(trackId, playlistId); 00103 return true; 00104 } 00105 00106 bool AutoDJFeature::dropAcceptChild(const QModelIndex& index, QUrl url) { 00107 return false; 00108 } 00109 00110 bool AutoDJFeature::dragMoveAccept(QUrl url) { 00111 QFileInfo file(url.toLocalFile()); 00112 return SoundSourceProxy::isFilenameSupported(file.fileName()); 00113 } 00114 00115 bool AutoDJFeature::dragMoveAcceptChild(const QModelIndex& index, 00116 QUrl url) { 00117 return false; 00118 } 00119 void AutoDJFeature::onLazyChildExpandation(const QModelIndex &index){ 00120 //Nothing to do because the childmodel is not of lazy nature. 00121 }