File indexing completed on 2025-01-05 04:25:47
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Rainer Sigle <rainer.sigle@web.de> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef AMAROK_TABS_ENGINE 0018 #define AMAROK_TABS_ENGINE 0019 0020 #include "TabsInfo.h" 0021 0022 #include "context/DataEngine.h" 0023 #include "core/meta/forward_declarations.h" 0024 #include "NetworkAccessManagerProxy.h" 0025 0026 #include <QVariant> 0027 0028 using namespace Context; 0029 0030 /** 0031 * This engine provides tab-data for the current song 0032 */ 0033 class TabsEngine : public DataEngine 0034 { 0035 Q_OBJECT 0036 Q_PROPERTY( QString artistName READ artistName WRITE setArtistName ) 0037 Q_PROPERTY( QString titleName READ titleName WRITE setTitleName ) 0038 Q_PROPERTY( bool fetchGuitarTabs READ fetchGuitar WRITE setFetchGuitar ) 0039 Q_PROPERTY( bool fetchBassTabs READ fetchBass WRITE setFetchBass ) 0040 0041 public: 0042 TabsEngine( QObject* parent, const QList<QVariant>& args ); 0043 virtual ~TabsEngine(); 0044 0045 QString artistName() const; 0046 void setArtistName( const QString &artistName ); 0047 0048 QString titleName() const; 0049 void setTitleName( const QString &titleName ); 0050 0051 bool fetchGuitar() const; 0052 void setFetchGuitar( const bool fetch ); 0053 0054 bool fetchBass() const; 0055 void setFetchBass( const bool fetch ); 0056 0057 QStringList sources() const; 0058 0059 protected: 0060 bool sourceRequestEvent( const QString &name ); 0061 0062 private Q_SLOTS: 0063 /** 0064 * handling of tab data search results from ultimateguitar.com 0065 */ 0066 void resultUltimateGuitarSearch( const QUrl &url, QByteArray data, NetworkAccessManagerProxy::Error e ); 0067 void resultUltimateGuitarTab( const QUrl &url, QByteArray data, NetworkAccessManagerProxy::Error e ); 0068 0069 /** 0070 * This method will send the info to the applet and order them if every jobs are finished 0071 */ 0072 void resultFinalize(); 0073 0074 /** 0075 * Prepare the calling of the requestTab method. 0076 * Launched when the track played on amarok has changed. 0077 */ 0078 void update(); 0079 0080 private: 0081 /** 0082 * starts a new tab-search 0083 */ 0084 void requestTab( const QString &artist, const QString &title ); 0085 0086 /** 0087 * starts a tab search at ultimateguitar.com 0088 */ 0089 void queryUltimateGuitar( const QString &artist, const QString &title ); 0090 0091 /** 0092 * The currently playing track 0093 */ 0094 Meta::TrackPtr m_currentTrack; 0095 0096 /** 0097 * Data strucuture which contains all tab-information for 0098 * the current song. After fetching this data will be send to the applet 0099 */ 0100 QList < TabsInfo * > m_tabs; 0101 0102 /** 0103 * Set containing urls of active jobs 0104 */ 0105 QSet < const QUrl > m_urls; 0106 0107 /** 0108 * Holds artist and title name of the current track 0109 */ 0110 QString m_titleName; 0111 QString m_artistName; 0112 0113 /** 0114 * Controls whether guitar-tabs will be fetched 0115 */ 0116 bool m_fetchGuitar; 0117 /** 0118 * Controls whether bass-tabs will be fetched 0119 */ 0120 bool m_fetchBass; 0121 0122 /** 0123 * Helper function which returns the intermediate string between two strings 0124 */ 0125 QString subStringBetween( const QString &src, const QString &from, const QString &to, 0126 bool lastIndexForFrom = false ); 0127 0128 /** 0129 * returns a list of possible search criteria for the current artist 0130 */ 0131 QStringList defineArtistSearchCriteria( const QString &artist ); 0132 0133 /** 0134 * returns a list of possible search criteria for the current title 0135 */ 0136 QStringList defineTitleSearchCriteria( const QString &title ); 0137 0138 /** 0139 * checks if a tab-fetch job aborted with an error 0140 * returns true in case of error, false otherwise 0141 */ 0142 bool netReplyError( NetworkAccessManagerProxy::Error e ); 0143 int m_numAbortedUrls; 0144 }; 0145 0146 Q_DECLARE_METATYPE ( TabsInfo * ) 0147 AMAROK_EXPORT_DATAENGINE( tabs, TabsEngine ) 0148 0149 #endif