Mixxx

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

Go to the documentation of this file.
00001 /***************************************************************************
00002                           promotracksfeature.cpp
00003                              -------------------
00004     begin                : Jan 2010
00005     copyright            : (C) 2010 Albert Santoni
00006     email                : alberts@mixxx.org
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010 *                                                                         *
00011 *   This program is free software; you can redistribute it and/or modify  *
00012 *   it under the terms of the GNU General Public License as published by  *
00013 *   the Free Software Foundation; either version 2 of the License, or     *
00014 *   (at your option) any later version.                                   *
00015 *                                                                         *
00016 ***************************************************************************/
00017 
00018 #include <QtDebug>
00019 
00020 #include "library/songdownloader.h"
00021 #include "library/promotracksfeature.h"
00022 #include "library/bundledsongswebview.h"
00023 #include "library/featuredartistswebview.h"
00024 #include "library/trackcollection.h"
00025 #include "library/dao/cratedao.h"
00026 #include "trackinfoobject.h"
00027 #include "defs_promo.h"
00028 #include "widget/wlibrary.h"
00029 #include "widget/wlibrarysidebar.h"
00030 #include "mixxxkeyboard.h"
00031 
00032 QString PromoTracksFeature::m_sPromoLocalHTMLLocation;
00033 QString PromoTracksFeature::m_sPromoRemoteHTMLLocation;
00034 #define PROMO_BUNDLE_PATH (config->getConfigPath() + "/promo/" + MIXXX_PROMO_VERSION + "/")
00035 #define LOCAL_HTML_LOCATION (PROMO_BUNDLE_PATH + "index.html")
00036 
00037 const QString PromoTracksFeature::m_sFeaturedArtistsViewName = "Featured Artists";
00038 const QString PromoTracksFeature::m_sBundledSongsViewName = "Bundled Songs";
00039 const QString PromoTracksFeature::m_sMyDownloadsViewName = "My Downloads";
00040 
00041 PromoTracksFeature::PromoTracksFeature(QObject* parent,
00042                              ConfigObject<ConfigValue>* config,
00043                              TrackCollection* pTrackCollection,
00044                              bool firstRun)
00045         : LibraryFeature(parent),
00046           m_pConfig(config),
00047           m_pTrackCollection(pTrackCollection),
00048           m_pFeaturedArtistsView(NULL),
00049           m_pBundledSongsView(NULL),
00050           m_downloadsTableModel(this, pTrackCollection),
00051           m_bFirstRun(firstRun) {
00052 
00053     m_sPromoRemoteHTMLLocation = QString("http://promo.mixxx.org/%1/index.html").arg(MIXXX_PROMO_VERSION); //m_pConfig->getConfigPath() + "/promo/promotracks.html";
00054     m_sPromoLocalHTMLLocation = LOCAL_HTML_LOCATION;
00055     m_sPromoAutoloadLocation = m_pConfig->getConfigPath() + "/promo/" + MIXXX_PROMO_VERSION + "/autoload.dat";
00056 
00057     //Load the extra.dat file so we can peek at some extra information, such
00058     //as which songs to auto-load into Mixxx's players.
00059     QFile file(m_sPromoAutoloadLocation);
00060     if (file.open(QIODevice::ReadOnly))
00061     {
00062         QTextStream extra(&file);
00063 
00064         //qDebug() << "PROMO: Autoload" << (file.exists() ? "" : "not") << "found";
00065         while (!extra.atEnd())
00066         {
00067             QString trackPath = extra.readLine();
00068             trackPath = m_pConfig->getConfigPath() + "/promo/" + MIXXX_PROMO_VERSION + "/" + trackPath;
00069             QFileInfo fileInfo(trackPath);
00070             trackPath = fileInfo.absoluteFilePath();
00071             //qDebug() << "PROMO: Auto-loading track" << trackPath;
00072 
00073             // Try to get TrackInfoObject* from library, identified by location.
00074             TrackDAO& trackDao = m_pTrackCollection->getTrackDAO();
00075             TrackPointer pTrack = trackDao.getTrack(trackDao.getTrackId(trackPath));
00076             // If not, create a new TrackInfoObject*
00077             if (pTrack == NULL)
00078             {
00079                 // TODO(XXX) These tracks are probably getting leaked b/c
00080                 // m_tracksToAutoLoad is never cleared.
00081                 pTrack = TrackPointer(new TrackInfoObject(trackPath), &QObject::deleteLater);
00082             }
00083 
00084             m_tracksToAutoLoad.append(pTrack);
00085         }
00086         file.close();
00087     }
00088 
00089 
00090     /*  XXX: Re-enable all this code to get the tree children back for Promo 3.0
00091     //XXX: Factor this out and put it in bundledsongsfeature.cpp
00092     //If we've bundled songs with Mixxx, show the fancy bundled songs view
00093     if (QFile::exists(LOCAL_HTML_LOCATION)) {
00094         qDebug() << "Bundled tracks found at:" << LOCAL_HTML_LOCATION;
00095         childrenStringList << tr(m_sBundledSongsViewName.toUtf8().constData());
00096     }
00097     else {
00098         qDebug() << "No bundled tracks found, disabling view. Looked in:" << LOCAL_HTML_LOCATION;
00099     }
00100 
00101     QStringList childrenStringList;
00102     childrenStringList <<  tr(m_sMyDownloadsViewName.toUtf8().constData());
00103     m_childModel.setStringList(childrenStringList);
00104 
00105     CrateDAO& crateDAO = pTrackCollection->getCrateDAO();
00106     crateDAO.createCrate(tr(m_sMyDownloadsViewName.toUtf8().constData())); //XXX: hidden = false for debug
00107     m_downloadsTableModel.setTable(tr(m_sMyDownloadsViewName.toUtf8().constData()));
00108     */
00109 
00110 }
00111 
00112 PromoTracksFeature::~PromoTracksFeature() {
00113 }
00114 
00115 QVariant PromoTracksFeature::title() {
00116     return tr(m_sFeaturedArtistsViewName.toUtf8().constData());
00117 }
00118 
00119 QIcon PromoTracksFeature::getIcon() {
00120     return QIcon(":/images/library/ic_library_promotracks.png");
00121 }
00122 
00123 bool PromoTracksFeature::isSupported(ConfigObject<ConfigValue>* config) {
00124     m_sPromoLocalHTMLLocation = LOCAL_HTML_LOCATION;
00125     qDebug() << "Promo dir:" << m_sPromoLocalHTMLLocation;
00126     return (QFile::exists(m_sPromoLocalHTMLLocation));
00127 }
00128 
00129 QList<TrackPointer> PromoTracksFeature::getTracksToAutoLoad()
00130 {
00131     return m_tracksToAutoLoad;
00132 }
00133 
00134 void PromoTracksFeature::bindWidget(WLibrarySidebar* sidebarWidget,
00135                                     WLibrary* libraryWidget,
00136                                     MixxxKeyboard* keyboard) {
00137 
00138     QString libraryPath = m_pConfig->getValueString(ConfigKey("[Playlist]","Directory"));
00139 
00140     ConfigObject<ConfigValue>* config = m_pConfig; //Long story, macros macros macros
00141     m_pBundledSongsView = new BundledSongsWebView(libraryWidget, m_pTrackCollection,
00142                                                   PROMO_BUNDLE_PATH,
00143                                                   m_sPromoLocalHTMLLocation,
00144                                                   m_bFirstRun, m_pConfig);
00145     m_pBundledSongsView->installEventFilter(keyboard);
00146 
00147     libraryWidget->registerView(tr(m_sBundledSongsViewName.toUtf8().constData()), m_pBundledSongsView);
00148     connect(m_pBundledSongsView, SIGNAL(loadTrack(TrackPointer)),
00149             this, SIGNAL(loadTrack(TrackPointer)));
00150     connect(m_pBundledSongsView, SIGNAL(loadTrackToPlayer(TrackPointer, QString)),
00151             this, SIGNAL(loadTrackToPlayer(TrackPointer, QString)));
00152 
00153 /*  XXX: Re-enable this code for Promo 3.0
00154     m_pFeaturedArtistsView = new FeaturedArtistsWebView(libraryWidget, libraryPath, m_sPromoRemoteHTMLLocation, new SongDownloader(this));
00155     libraryWidget->registerView(tr(m_sFeaturedArtistsViewName.toUtf8().constData()), m_pFeaturedArtistsView);
00156     connect(m_pFeaturedArtistsView, SIGNAL(loadTrack(TrackInfoObject*)),
00157             this, SIGNAL(loadTrack(TrackInfoObject*)));
00158     connect(m_pFeaturedArtistsView, SIGNAL(loadTrackToPlayer(TrackInfoObject*, QString)),
00159             this, SIGNAL(loadTrackToPlayer(TrackInfoObject*, QString)));
00160     */
00161 }
00162 
00163 TreeItemModel* PromoTracksFeature::getChildModel() {
00164     //XXX Promo 3.0:
00165     //return NULL;
00166     return &m_childModel;
00167 }
00168 
00169 void PromoTracksFeature::activate() {
00170     //XXX Promo 3.0:
00171     //emit(switchToView(tr(m_sFeaturedArtistsViewName.toUtf8().constData())));
00172     emit(switchToView(tr(m_sBundledSongsViewName.toUtf8().constData())));
00173 }
00174 
00175 void PromoTracksFeature::activateChild(const QModelIndex& index) {
00176     QString itemString = m_childModel.data(index, Qt::DisplayRole).toString();
00177     if (itemString == tr(m_sMyDownloadsViewName.toUtf8().constData()))
00178     {
00179         emit(showTrackModel(&m_downloadsTableModel));
00180     }
00181     else
00182         emit(switchToView(itemString));
00183 }
00184 
00185 void PromoTracksFeature::onRightClick(const QPoint& globalPos) {
00186 }
00187 
00188 void PromoTracksFeature::onRightClickChild(const QPoint& globalPos,
00189                                             QModelIndex index) {
00190 }
00191 
00192 bool PromoTracksFeature::dropAccept(QUrl url) {
00193     return false;
00194 }
00195 
00196 bool PromoTracksFeature::dropAcceptChild(const QModelIndex& index, QUrl url) {
00197     return false;
00198 }
00199 
00200 bool PromoTracksFeature::dragMoveAccept(QUrl url) {
00201     return false;
00202 }
00203 
00204 bool PromoTracksFeature::dragMoveAcceptChild(const QModelIndex& index,
00205                                               QUrl url) {
00206     return false;
00207 }
00208 void PromoTracksFeature::onLazyChildExpandation(const QModelIndex &index){
00209     //Nothing to do because the childmodel is not of lazy nature.
00210 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines