Mixxx

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

Go to the documentation of this file.
00001 /***************************************************************************
00002                           promotrackswebview.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 <QtXml>
00019 #include <QDebug>
00020 #include <QDesktopServices>
00021 #include "featuredartistswebview.h"
00022 
00023 #define LOAD_TIMEOUT 10000
00024 
00025 FeaturedArtistsWebView::FeaturedArtistsWebView(QWidget* parent, QString libraryPath, QString remoteURL, SongDownloader* downloader) : QWebView(parent), LibraryView()
00026 {
00027     m_sLibraryPath = libraryPath;
00028     m_sRemoteURL = remoteURL;
00029     m_sLocalErrorURL = "about:qt";
00030     m_bOfflineMode = false;
00031     m_pSongDownloader = downloader;
00032 
00033     QWidget::setContextMenuPolicy(Qt::PreventContextMenu);
00034 
00035     //Allow us to catch if opening the HTML file on promo.mixxx.org
00036     //fails, and display a local copy instead.
00037     connect(this, SIGNAL(loadFinished(bool)),
00038             this, SLOT(handleLoadFinished(bool)));
00039 
00040     //Load the promo tracks webpage
00041     QWebView::load(QUrl(m_sRemoteURL));
00042 
00043     //Let us manually handle links that are clicked via the linkClicked()
00044     //signal...
00045     QWebPage* page = QWebView::page();
00046     page->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
00047 
00048     connect(this, SIGNAL(linkClicked(const QUrl&)),
00049             this, SLOT(handleClickedLink(const QUrl&)));
00050 
00051     QTimer* loadingTimer = new QTimer(this);
00052     connect(loadingTimer, SIGNAL(timeout()),
00053             this, SLOT(checkWebpageLoadingProgress()));
00054     loadingTimer->start(LOAD_TIMEOUT);
00055 }
00056 
00057 
00058 /* Google Analytics doesn't like our crappy malformed "Mixxx 1.8" string
00059    as a user agent. Let Qt construct it for us instead by leaving this commented out.
00060 QString FeaturedArtistsWebView::userAgentForUrl (const QUrl & url) const
00061 {
00062     return QCoreApplication::applicationName() + " " + QCoreApplication::applicationVersion();
00063 } */
00064 
00065 void FeaturedArtistsWebView::handleLoadFinished(bool ok)
00066 {
00067     //If the remote webpage failed to load, show the
00068     //local copy of it.
00069     if (!ok)
00070     {
00071         /* This doesn't work inside this signal handler for some reason:
00072         QWebView::stop();
00073         QWebView::load(QUrl(m_sLocalErrorURL));
00074         */
00075         m_bOfflineMode = true;
00076         qDebug() << "PROMO: handleLoadFinished, error loading page!";
00077     }
00078 }
00079 
00080 void FeaturedArtistsWebView::checkWebpageLoadingProgress()
00081 {
00082     if (QWebView::page()->bytesReceived() == 0) {
00083         qDebug() << "PROMO: Load timed out, loading local page";
00084         QWebView::stop();
00085         QWebView::load(QUrl(m_sLocalErrorURL));
00086         m_bOfflineMode = true;
00087     }
00088 }
00089 
00090 FeaturedArtistsWebView::~FeaturedArtistsWebView()
00091 {
00092 
00093 }
00094 
00095 void FeaturedArtistsWebView::setup(QDomNode node)
00096 {
00097 
00098 }
00099 
00100 void FeaturedArtistsWebView::handleClickedLink(const QUrl& url)
00101 {
00102     qDebug() << "link clicked!" << url;
00103 
00104     /*
00105     if (url.scheme() == "deck1")
00106     {
00107         TrackInfoObject* track = new TrackInfoObject(m_sMixxxPath + "/" + url.path());
00108         emit(loadTrackToPlayer(track, "[Channel1]"));
00109     }
00110     else if (url.scheme() == "deck2")
00111     {
00112         TrackInfoObject* track = new TrackInfoObject(m_sMixxxPath + "/" + url.path());
00113         emit(loadTrackToPlayer(track, "[Channel2]"));
00114     }
00115     */
00116     if (url.host().contains("mixxx.org")) {
00117         //Allow navigation through any Mixxx site in the browser
00118         this->load(url);
00119     }
00120     else
00121     {
00122         QDesktopServices::openUrl(url);
00123     }
00124 }
00125 
00126 //TODO: Implement this for MIDI control
00127 void FeaturedArtistsWebView::keyPressEvent(QKeyEvent* event)
00128 {
00129     //Look at WTrackTableView::keyPressEvent(...) for some
00130     //code to start with...
00131 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines