26
|
1 |
/**
|
|
2 |
* Copyright (c) 2010 Sasken Communication Technologies Ltd.
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the "{License}"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "{LicenseUrl}".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Narasimhulu Kavadapu, Sasken Communication Technologies Ltd - Initial contribution
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
* Siddhartha Chandra, Sasken Communication Technologies Ltd
|
|
14 |
* Description:
|
|
15 |
* class to maintian session & all credential keys.
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "sessionSP.h"
|
|
19 |
#include "requestSP.h"
|
|
20 |
#include <qfile.h>
|
|
21 |
#include <QTimer>
|
|
22 |
#include <qdebug.h>
|
|
23 |
#include <keys.h>
|
|
24 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
25 |
// global
|
|
26 |
|
|
27 |
|
|
28 |
static FBSession* sharedSession = NULL;
|
|
29 |
|
|
30 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
31 |
// Static class functions
|
|
32 |
FBSession* FBSession::session()
|
|
33 |
{
|
|
34 |
return sharedSession;
|
|
35 |
}
|
|
36 |
|
|
37 |
void FBSession::setSession(FBSession* aSession)
|
|
38 |
{
|
|
39 |
sharedSession = aSession;
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
FBSession* FBSession::sessionForApplication ( const QString& aAppKey, const QString& aAppSecret, const QString& aSessionProxy)
|
|
44 |
{
|
|
45 |
FBSession* session = new FBSession ( aAppKey, aAppSecret, aSessionProxy );
|
|
46 |
return session;
|
|
47 |
}
|
|
48 |
|
|
49 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
50 |
// instance public functions
|
|
51 |
FBSession::FBSession( const QString& aAppKey, const QString& aAppSecret, const QString& aGetSessionProxy ) :
|
|
52 |
iApiKey (aAppKey),
|
|
53 |
iApiSecret ( aAppSecret ),
|
|
54 |
m_Client(new SmfCredMgrClient(this))
|
|
55 |
{
|
|
56 |
Q_UNUSED(aGetSessionProxy)
|
|
57 |
if (!sharedSession)
|
|
58 |
{
|
|
59 |
sharedSession = this;
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
|
63 |
FBSession::~FBSession()
|
|
64 |
{
|
|
65 |
if(m_Client){
|
|
66 |
delete m_Client;
|
|
67 |
m_Client = NULL;
|
|
68 |
}
|
|
69 |
}
|
|
70 |
|
|
71 |
const QString& FBSession::apiURL() const
|
|
72 |
{
|
|
73 |
return kAPIRestURL;
|
|
74 |
}
|
|
75 |
void FBSession::SaveToken (const QString& token )
|
|
76 |
{
|
|
77 |
iToken = token;
|
|
78 |
}
|
|
79 |
void FBSession::SaveSession (const QString& session, const QString& name )
|
|
80 |
{
|
|
81 |
qDebug()<<"Inside FBSession::SaveSession";
|
|
82 |
qDebug()<<"token argument = "<<session;
|
|
83 |
iLastfmSessionKey = session;
|
|
84 |
iLastfmUserName = name;
|
|
85 |
save();
|
|
86 |
emit sessionDidLogin(session);
|
|
87 |
}
|
|
88 |
bool FBSession::resume()
|
|
89 |
{
|
|
90 |
QString CMRegToken = iSettings.value("CMFlickrRegToken", "NA" ).toString();
|
|
91 |
QDateTime ExpiryTime = iSettings.value("FlckrExpiryTime","NA").toDateTime();
|
|
92 |
|
|
93 |
qDebug() << "CMRegToken = :" << CMRegToken;
|
|
94 |
qDebug() << "ExpiryTime = :" << ExpiryTime;
|
|
95 |
|
|
96 |
SmfAuthParams Params;
|
|
97 |
if(m_Client->AuthDataSet(CMRegToken,ExpiryTime,Params))
|
|
98 |
{
|
|
99 |
QByteArray accessToken = Params.value("finalToken");
|
|
100 |
emit sessionDidLogin( accessToken );
|
|
101 |
return true;
|
|
102 |
}
|
|
103 |
return false;
|
|
104 |
}
|
|
105 |
void FBSession::logout() {
|
|
106 |
|
|
107 |
iLastfmSessionKey.clear();
|
|
108 |
iLastfmUserName.clear();
|
|
109 |
iToken.clear();
|
|
110 |
|
|
111 |
unsave();
|
|
112 |
|
|
113 |
emit sessionDidLogout();
|
|
114 |
}
|
|
115 |
|
|
116 |
void FBSession::send (FBRequest* aRequest) {
|
|
117 |
qDebug()<<"Inside FBSession::send";
|
|
118 |
performRequest (aRequest, true);
|
|
119 |
}
|
|
120 |
|
|
121 |
|
|
122 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
123 |
// instance private functions
|
|
124 |
void FBSession::save()
|
|
125 |
{
|
|
126 |
qDebug()<<"Inside FBSession::save()";
|
|
127 |
qDebug()<<"Session Key= "<<iLastfmSessionKey;
|
|
128 |
|
|
129 |
SmfAuthParams Params;
|
|
130 |
Params.insert("ApiKey",kApiKey.toAscii());
|
|
131 |
Params.insert("ApiSecret",kApiSecret.toAscii());
|
|
132 |
Params.insert("ApiToken",iToken.toAscii());
|
|
133 |
Params.insert("SessionKey",iLastfmSessionKey.toAscii());
|
|
134 |
Params.insert("Name",iLastfmUserName.toAscii());
|
|
135 |
|
|
136 |
QList<QUrl> UrlList;
|
|
137 |
UrlList.append(QUrl(kAPIRestURL));
|
|
138 |
|
|
139 |
QStringList PluginList;
|
|
140 |
PluginList.append(QString("LastFmmusiceventplugin.qtplugin"));
|
|
141 |
PluginList.append(QString("LastFmmusicsearchplugin.qtplugin"));
|
|
142 |
PluginList.append(QString("LastFmmusicserviceplugin.qtplugin"));
|
|
143 |
PluginList.append(QString("LastFmplaylistserviceplugin.qtplugin"));
|
|
144 |
QString UID("0xE1D8C7D8");
|
|
145 |
|
|
146 |
//Currently Hardcoded with current time bcoz CM is not handling expiry time as '0' value
|
|
147 |
QDateTime ExpirationDate = QDateTime::currentDateTime();
|
|
148 |
ExpirationDate.addYears(1);
|
|
149 |
|
|
150 |
QString CMRegToken = m_Client->StoreAuthData(Params,ExpirationDate,UrlList,PluginList,UID,true);
|
|
151 |
|
|
152 |
if(CMRegToken.size()){
|
|
153 |
iSettings.setValue("CMLastFmRegToken", CMRegToken);
|
|
154 |
iSettings.setValue("LastFmExpiryTime", ExpirationDate);
|
|
155 |
}
|
|
156 |
}
|
|
157 |
|
|
158 |
void FBSession::unsave()
|
|
159 |
{
|
|
160 |
|
|
161 |
}
|
|
162 |
bool FBSession::performRequest(FBRequest* aRequest, bool aEnqueue) {
|
|
163 |
// Stagger requests that happen in short bursts to prevent the server from rejecting
|
|
164 |
// them for making too many requests in a short time
|
|
165 |
Q_UNUSED(aEnqueue)
|
|
166 |
qDebug()<<"Inside FBSession::performRequest";
|
|
167 |
aRequest->connect();
|
|
168 |
return true;
|
|
169 |
}
|