Tests/SmfMusicEventsnService/SmfMusicEventsnService.cpp
changeset 26 83d6a149c755
child 27 b3e1347ac96a
equal deleted inserted replaced
25:a180113055cb 26:83d6a149c755
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Trolltech hereby grants a license to use the Qt/Eclipse Integration
       
     4 ** plug-in (the software contained herein), in binary form, solely for the
       
     5 ** purpose of creating code to be used with Trolltech's Qt software.
       
     6 **
       
     7 ** Qt Designer is licensed under the terms of the GNU General Public
       
     8 ** License versions 2.0 and 3.0 ("GPL License"). Trolltech offers users the
       
     9 ** right to use certain no GPL licensed software under the terms of its GPL
       
    10 ** Exception version 1.2 (http://trolltech.com/products/qt/gplexception).
       
    11 **
       
    12 ** THIS SOFTWARE IS PROVIDED BY TROLLTECH AND ITS CONTRIBUTORS (IF ANY) "AS
       
    13 ** IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
       
    14 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
       
    15 ** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
       
    16 ** OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       
    17 ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    18 ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       
    19 ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
       
    20 ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
       
    21 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
       
    22 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
       
    23 **
       
    24 ** Since we now have the GPL exception I think that the "special exception
       
    25 ** is no longer needed. The license text proposed above (other than the
       
    26 ** special exception portion of it) is the BSD license and we have added
       
    27 ** the BSD license as a permissible license under the exception.
       
    28 **
       
    29 ****************************************************************************/
       
    30 
       
    31 #include <qdebug.h>
       
    32 #include <smfclient.h>
       
    33 #include <smfcontactfetcher.h>
       
    34 
       
    35 #include "SmfMusicEventsnService.h"
       
    36 
       
    37 SmfTestApp::SmfTestApp(QWidget *parent)
       
    38     : QWidget(parent)
       
    39 {
       
    40 	ui.setupUi(this);
       
    41 	m_contactFetcher = NULL;
       
    42 	m_providerList = NULL;
       
    43 }
       
    44 
       
    45 SmfTestApp::~SmfTestApp()
       
    46 {
       
    47 	if(m_contactFetcher)
       
    48 		delete m_contactFetcher;
       
    49 	if(m_providerList)
       
    50 		delete m_providerList;
       
    51 }
       
    52 
       
    53 void SmfTestApp::getFacebookFriends()
       
    54 	{
       
    55 	qDebug()<<"Inside SmfTestApp::getFacebookFriends()";
       
    56 	
       
    57 	// Get the list of providers
       
    58 	SmfClient client;
       
    59 	QString intfName("org.symbian.smf.plugin.contact.fetcher");
       
    60 	
       
    61 	m_providerList = client.GetServices(intfName);
       
    62 	qDebug()<<"client.GetServices returned a list with count = "<<m_providerList->count();
       
    63 	
       
    64 	// flag to check if required plugin is there
       
    65 	bool pluginFound = false;
       
    66 	foreach(SmfProvider provider, *m_providerList)
       
    67 		{
       
    68 		if("Facebook" == provider.serviceName())
       
    69 			{
       
    70 			qDebug()<<"Plugin for Facebook found";
       
    71 			pluginFound = true;
       
    72 			m_contactFetcher = new SmfContactFetcher(&provider);
       
    73 			SmfError err = m_contactFetcher->friends(1, 10);
       
    74 			qDebug()<<"Ret value of friends() = "<<err;
       
    75 			
       
    76 			bool connected = connect(m_contactFetcher, SIGNAL(friendsListAvailable(SmfContactList*, SmfError , SmfResultPage)),
       
    77 					this, SLOT(friendsListAvailable(SmfContactList*, SmfError , SmfResultPage)));
       
    78 			qDebug()<<"Signal-slot connected ? = "<<connected;
       
    79 			}
       
    80 		}
       
    81 	
       
    82 	if(!pluginFound)
       
    83 		{
       
    84 		qDebug()<<"Plugin for Facebook not found!!!";
       
    85 		}
       
    86 	
       
    87 	qDebug()<<"Returning from SmfTestApp::getFacebookFriends()";
       
    88 	}
       
    89 
       
    90 
       
    91 void SmfTestApp::friendsListAvailable ( SmfContactList* list, SmfError error, SmfResultPage resultPage )
       
    92 	{
       
    93 	Q_UNUSED(resultPage)
       
    94 	qDebug()<<"Inside SmfTestApp::friendsListAvailable()";
       
    95 			
       
    96 	if(error)
       
    97 		{
       
    98 		SmfClient client;
       
    99 		QString errStr = client.errorString(error);
       
   100 		qDebug()<<"Error found, code = "<<error;
       
   101 		qDebug()<<"Error string is = "<<errStr;
       
   102 
       
   103 		return;
       
   104 		}
       
   105 		
       
   106 	//display friends information
       
   107 	int count = 0;
       
   108 	qDebug()<<"Number of friends retrieved = "<<list->count();
       
   109 	if(0 == list->count())
       
   110 		{
       
   111 		qDebug()<<"No friends available!!!";
       
   112 		return;
       
   113 		}
       
   114 		
       
   115 	foreach(SmfContact contact, *list)
       
   116 		{
       
   117 		qDebug()<<"Friends name = "<<contact.value("Name").value<QContactName>().firstName();
       
   118 		qDebug()<<"Friends status msg desc = "<<contact.value("Presence").value<QContactPresence>().customMessage();
       
   119 		qDebug()<<"Friends profile image URL = "<<contact.value("Avatar").value<QContactAvatar>().imageUrl();
       
   120 		qDebug()<<"";
       
   121 		}
       
   122 	
       
   123 	delete list;
       
   124 	}
       
   125 //chinmaya
       
   126 void SmfTestApp::lastFm()
       
   127 	{
       
   128 	qDebug()<<"Inside SmfTestApp::lastFm()";
       
   129 		
       
   130 	// Get the list of providers
       
   131 	SmfClient client;
       
   132 	QString intfName("org.symbian.smf.plugin.music.service");
       
   133 	
       
   134 	m_providerList = client.GetServices(intfName);
       
   135 	qDebug()<<"client.GetServices returned a list with count = "<<m_providerList->count();
       
   136 	
       
   137 	// flag to check if required plugin is there
       
   138 	bool pluginFound = false;
       
   139 	foreach(SmfProvider provider, *m_providerList)
       
   140 		{
       
   141 		if("last.fm" == provider.serviceName())
       
   142 			{
       
   143 			qDebug()<<"Plugin for last.fm found";
       
   144 			pluginFound = true;
       
   145 			SmfMusicService *m_musicService = new SmfMusicService(&provider);
       
   146 			SmfError err = m_musicService->userMusicInfo();			
       
   147 			bool connected = QObject::connect(m_musicService,SIGNAL(userMusicInfoAvailable(SmfMusicProfile*,SmfError)),
       
   148 					this,SLOT(userMusicInfoAvlbl(SmfMusicProfile*,SmfError)));
       
   149 			qDebug() <<"Smfmusicservice::userMusicInfo" ;
       
   150 			qDebug()<<"Signal-slot connected ? = "<<connected;
       
   151 			}
       
   152 		}
       
   153 	
       
   154 	if(!pluginFound)
       
   155 		{
       
   156 		qDebug()<<"Plugin for last.fm not found!!!";
       
   157 		}
       
   158 	
       
   159 	qDebug()<<"Returning from SmfTestApp::last.fm()";
       
   160 	}
       
   161 void SmfTestApp::userMusicInfoAvlbl(SmfMusicProfile*,SmfError)
       
   162 	{
       
   163 	qDebug()<<"User music info";
       
   164 	}
       
   165 
       
   166 
       
   167 
       
   168 
       
   169 
       
   170 void SmfTestApp::FacebookFiltered()
       
   171 	{
       
   172 	qDebug()<<"Inside SmfTestApp::FacebookFiltered()";
       
   173 		
       
   174 	// Get the list of providers
       
   175 	SmfClient client;
       
   176 	QString intfName("org.symbian.smf.client.activity.fetcher");
       
   177 	
       
   178 	m_providerList = client.GetServices(intfName);
       
   179 	qDebug()<<"client.GetServices returned a list with count = "<<m_providerList->count();
       
   180 	
       
   181 	// flag to check if required plugin is there
       
   182 	bool pluginFound = false;
       
   183 	foreach(SmfProvider provider, *m_providerList)
       
   184 		{
       
   185 		if("Facebook" == provider.serviceName())
       
   186 			{
       
   187 			qDebug()<<"Plugin for Facebook found";
       
   188 			pluginFound = true;
       
   189 			SmfActivityFetcher *p_smfActivityFetcher = new SmfActivityFetcher(&provider);
       
   190 			QList<SmfActivityObjectType> Article;
       
   191 			
       
   192 			SmfActivityObjectType SmfActivityObjTypeComment;			
       
   193 			Article.append(SmfActivityObjTypeComment);
       
   194 			
       
   195 			// specify some dummy value for Article
       
   196 			int pageNum = 1,perPage=1;			  
       
   197 			SmfError err = p_smfActivityFetcher->filtered(Article);
       
   198 			bool connected = QObject::connect(p_smfActivityFetcher,SIGNAL(resultsAvailable(SmfActivityEntryList*, SmfError, SmfResultPage)),
       
   199 					this,SLOT(resultsAvailableSlot(SmfActivityEntryList*, SmfError, SmfResultPage)));
       
   200 			qDebug() <<"SmfActivityFetcher::filter" ;
       
   201 			qDebug()<<"Signal-slot connected ? = "<<connected;
       
   202 			}
       
   203 		}
       
   204 	
       
   205 	if(!pluginFound)
       
   206 		{
       
   207 		qDebug()<<"Plugin for Facebook not found!!!";
       
   208 		}
       
   209 	
       
   210 	qDebug()<<"Returning from SmfTestApp::getFacebookFriends()";
       
   211 	}
       
   212 
       
   213 void SmfTestApp::FacebookActivities()
       
   214 	{
       
   215 	qDebug()<<"Inside SmfTestApp::FacebookFiltered()";
       
   216 		
       
   217 	// Get the list of providers
       
   218 	SmfClient client;
       
   219 	QString intfName("org.symbian.smf.client.activity.fetcher");
       
   220 	
       
   221 	m_providerList = client.GetServices(intfName);
       
   222 	qDebug()<<"client.GetServices returned a list with count = "<<m_providerList->count();
       
   223 	
       
   224 	// flag to check if required plugin is there
       
   225 	bool pluginFound = false;
       
   226 	foreach(SmfProvider provider, *m_providerList)
       
   227 		{
       
   228 		if("Facebook" == provider.serviceName())
       
   229 			{
       
   230 			qDebug()<<"Plugin for Facebook found";
       
   231 			pluginFound = true;
       
   232 			SmfActivityFetcher *p_smfActivityFetcher = new SmfActivityFetcher(&provider);
       
   233 			QContactName Name;
       
   234 			//Name.setFirstName("Siddartha");
       
   235 			//Name.setLastName("Chandra");
       
   236 			
       
   237 			SmfContact aFriend;
       
   238 			// add some dummy values to aFriend methods
       
   239 			QString str;
       
   240 			str.append("Name");
       
   241 			QVariant var = QVariant::fromValue<QContactName>(Name);
       
   242 
       
   243 			aFriend.setValue(str,var);
       
   244 			QContactGuid guid;
       
   245 
       
   246 			// contact->value("Guid").value<QContactGuid>() ;
       
   247 
       
   248 			QString userId = "558588290";
       
   249 
       
   250 			guid.setGuid(userId); 
       
   251 
       
   252 			QVariant contactId = QVariant::fromValue<QContactGuid>(guid);
       
   253 
       
   254 			aFriend.setValue("Guid",contactId);
       
   255 			int pageNum = 1,perPage=2;			  
       
   256 			SmfError err = p_smfActivityFetcher->friendsActivities(aFriend,pageNum,perPage);
       
   257 			bool connected = QObject::connect(p_smfActivityFetcher,SIGNAL(resultsAvailable(SmfActivityEntryList*, SmfError, SmfResultPage)),
       
   258 					this,SLOT(resultsAvailableSlot(SmfActivityEntryList*, SmfError, SmfResultPage)));
       
   259 			qDebug() <<"SmfActivityFetcher::filter" ;
       
   260 			qDebug()<<"Signal-slot connected ? = "<<connected;
       
   261 			}
       
   262 		}
       
   263 	
       
   264 	if(!pluginFound)
       
   265 		{
       
   266 		qDebug()<<"Plugin for Facebook not found!!!";
       
   267 		}
       
   268 	
       
   269 	qDebug()<<"Returning from SmfTestApp::getFacebookFriends()";
       
   270 	}
       
   271 
       
   272 
       
   273 void SmfTestApp::resultsAvailableSlot(SmfActivityEntryList *ptr, SmfError _t2, SmfResultPage _t3)
       
   274 	{
       
   275 	qDebug()<<"inside resultsAvailableSlot";	
       
   276 	//qDebug()<<"data"<<SmfActivityEntryList->_t3;
       
   277 	qDebug()<<ptr->at(0).id();
       
   278 	foreach(SmfActivityEntry contact, (*ptr))
       
   279 		{
       
   280 		qDebug()<<"SmfActivityEntry id = "<<contact.id();
       
   281 		/*qDebug()<<"Friends status msg desc = "<<contact.;
       
   282 		qDebug()<<"Friends profile image URL = "<<contact.value("Avatar").value<QContactAvatar>().imageUrl();
       
   283 		qDebug()<<"";*/
       
   284 		}
       
   285 	
       
   286 	delete ptr;
       
   287 	}