1
/***************************************************************************
2
* Copyright (C) 2005 - 2007 by *
3
* Christian Muehlhaeuser, Last.fm Ltd <chris@last.fm> *
4
* Erik Jaelevik, Last.fm Ltd <erik@last.fm> *
5
* Max Howell, Last.fm Ltd <max@last.fm> *
7
* This program is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation; either version 2 of the License, or *
10
* (at your option) any later version. *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program; if not, write to the *
19
* Free Software Foundation, Inc., *
20
* 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. *
21
***************************************************************************/
23
#include <QMessageBox>
27
#include "WebService/Request.h"
28
#include "WebService.h"
31
WebService::WebService( QObject* parent ) :
33
m_isAutoDetectedProxy( false ),
35
m_isSubscriber( false )
37
LOGL( 3, "Initialising Web Service" );
39
//TODO needs to be a setting, to manually set the proxy or automatically
44
WebService::requestResult( Request *r )
52
//TODO mxcl before I refactored, the handshake success if block was still
53
// executed, but the result code was set to an error, I considered this a
54
// bug and hopefully I'll remember to ask someone if that is the case or not
56
Handshake *handshake = static_cast<Handshake*>(r);
58
if (handshake->succeeded()) {
59
m_username = handshake->username();
60
m_password = handshake->password();
61
m_streamUrl = handshake->streamUrl(); // legacy
62
m_isSubscriber = handshake->isSubscriber();
65
if (handshake->isMessage())
66
QMessageBox::information(
68
tr( "Last.fm Information" ),
69
handshake->message() );
71
emit handshakeResult( handshake );
76
// these macros makes the code more readable
77
#define CASE( T ) case Type##T: { T##Request *request = static_cast<T##Request*>(r);
81
StationUrl url = request->stationUrl();
82
QString name = request->stationName();
87
UserSettings &user = The::settings().currentUser();
89
// Don't store previews (i.e. the ones that have XSPF)
90
if (!request->hasXspf())
92
user.setResumeStation( url );
97
emit changeStationResult( request );
100
emit stationChanged( url, name );
104
emit setTagResult( request );
111
/// these are emitted only for the currentUsername()
115
emit loved( request->track() );
118
emit unloved( request->track() );
121
emit banned( request->track() );
124
emit unbanned( request->track() );
127
emit unlistened( request->track() );
130
if (request->username() == currentUsername())
131
emit userTags( request->tags() );
134
emit friendDeleted( request->deletedUsername() );
137
emit friends( request->usernames() );
140
emit neighbours( request->usernames() );
143
emit recentTracks( request->tracks() );
145
CASE( RecentlyLovedTracks )
146
emit recentLovedTracks( request->tracks() );
148
CASE( RecentlyBannedTracks )
149
emit recentBannedTracks( request->tracks() );
168
// do last in case one of the signals is queued
173
WebService::challengeString()
175
uint const unixTime = QDateTime::currentDateTime().toTime_t();
176
return QString::number( unixTime );
181
#include "CFStringToQString.h"
182
#include <SystemConfiguration/SystemConfiguration.h>
186
WebService::autoDetectProxy()
191
CFNumberRef enableNum;
194
// Get the dictionary.
195
CFDictionaryRef proxyDict = SCDynamicStoreCopyProxies( NULL );
196
bool result = (proxyDict != NULL);
198
// Get the enable flag. This isn't a CFBoolean, but a CFNumber.
200
enableNum = (CFNumberRef) CFDictionaryGetValue( proxyDict, kSCPropNetProxiesHTTPEnable );
201
result = (enableNum != NULL) && (CFGetTypeID(enableNum) == CFNumberGetTypeID());
205
result = CFNumberGetValue( enableNum, kCFNumberIntType, &enable ) && (enable != 0);
207
// Get the proxy host. DNS names must be in ASCII. If you
208
// put a non-ASCII character in the "Secure Web Proxy"
209
// field in the Network preferences panel, the CFStringGetCString
210
// function will fail and this function will return false.
215
hostStr = (CFStringRef) CFDictionaryGetValue( proxyDict, kSCPropNetProxiesHTTPProxy );
216
result = (hostStr != NULL) && (CFGetTypeID(hostStr) == CFStringGetTypeID());
219
m_proxyHost = CFStringToQString( hostStr );
222
////// Get the proxy port.
227
portNum = (CFNumberRef) CFDictionaryGetValue( proxyDict, kSCPropNetProxiesHTTPPort );
228
result = (portNum != NULL) && (CFGetTypeID(portNum) == CFNumberGetTypeID());
231
result = CFNumberGetValue( portNum, kCFNumberIntType, &portInt );
234
m_proxyPort = portInt;
236
////// Set that we found the proxy information
237
m_isAutoDetectedProxy = true;
241
if (proxyDict != NULL)
242
CFRelease( proxyDict );
245
// qDebug() << m_proxyHost << ':' << m_proxyPort;