|
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 "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html" |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Manasij Roy, Nalina Hariharan |
|
14 */ |
|
15 |
|
16 |
|
17 |
|
18 #include "displaywidget.h" |
|
19 #include <QApplication> |
|
20 #include <QDesktopWidget> |
|
21 |
|
22 DisplayWidget::DisplayWidget(QWidget *parent) |
|
23 : QWidget(parent) |
|
24 { |
|
25 ui.setupUi(this); |
|
26 ui.verticalLayout->setGeometry(QApplication::desktop()->availableGeometry()); |
|
27 //Add item as and when they are implemented |
|
28 ui.comboBox_intf->addItem("Contact Fetcher"); |
|
29 ui.comboBox_intf->addItem("Post Provider"); |
|
30 // connect(ui.comboBox_intf, |
|
31 // SIGNAL(currentIndexChanged(int)), |
|
32 // this, |
|
33 // SLOT(interfaceSelected(int))); |
|
34 connect(ui.pushButton_intf,SIGNAL(clicked()),this,SLOT(interfaceSelected())); |
|
35 connect(ui.pushButton_SP,SIGNAL(clicked()),this,SLOT(serviceProviderSelected())); |
|
36 connect(ui.pushButton_service,SIGNAL(clicked()),this,SLOT(serviceSelected())); |
|
37 writeLog("Start"); |
|
38 } |
|
39 void DisplayWidget::interfaceSelected() |
|
40 { |
|
41 SmfClient client; |
|
42 //TODO:- PM should use commented interface name instead |
|
43 // QString name("org.symbian.smf.client.contact.posts"); |
|
44 QString intfName; |
|
45 switch(ui.comboBox_intf->currentIndex()) |
|
46 { |
|
47 case 0: |
|
48 intfName = "org.symbian.smf.client.contact.fetcher"; |
|
49 break; |
|
50 case 1: |
|
51 intfName = "posts"; |
|
52 break; |
|
53 default: |
|
54 //should not reach here!!!! |
|
55 break; |
|
56 } |
|
57 writeLog("Before client.GetServices"); |
|
58 providerList= client.GetServices(intfName); |
|
59 ui.comboBox__SP->clear(); |
|
60 //add provider names to the combobox |
|
61 for(int i=0; i< providerList->count();i++) |
|
62 { |
|
63 SmfProvider provider = providerList->at(i); |
|
64 ui.comboBox__SP->addItem(provider.serviceName()); |
|
65 } |
|
66 |
|
67 //logging for debugging purpose |
|
68 writeLog("GetServices count="); |
|
69 QString c = QString::number(providerList->count()); |
|
70 writeLog(c); |
|
71 //serviceProviderSelected |
|
72 // connect(ui.comboBox__SP, |
|
73 // SIGNAL(currentIndexChanged(int)), |
|
74 // this, |
|
75 // SLOT(serviceProviderSelected(int))); |
|
76 } |
|
77 void DisplayWidget::serviceProviderSelected() |
|
78 { |
|
79 |
|
80 switch(ui.comboBox_intf->currentIndex()) |
|
81 { |
|
82 case 0: |
|
83 ui.comboBox_service->addItem("Get Friend List"); |
|
84 //ui.comboBox_3->addItem("Get Group List"); |
|
85 break; |
|
86 case 1: |
|
87 ui.comboBox_service->addItem("Get Own Posts"); |
|
88 //ui.comboBox_3->addItem("Get Friend's Posts"); |
|
89 break; |
|
90 } |
|
91 // connect(ui.comboBox_service, |
|
92 // SIGNAL(currentIndexChanged(int)), |
|
93 // this, |
|
94 // SLOT(serviceSelected(int))); |
|
95 } |
|
96 void DisplayWidget::serviceSelected() |
|
97 { |
|
98 SmfProvider smfP(providerList->at(ui.comboBox_service->currentIndex())); |
|
99 |
|
100 writeLog("Selected SmfProvider="); |
|
101 writeLog(smfP.m_description); |
|
102 writeLog(smfP.m_serviceUrl.toString()); |
|
103 writeLog(smfP.m_appUrl.toString()); |
|
104 switch(ui.comboBox_intf->currentIndex()) |
|
105 { |
|
106 case 1: |
|
107 m_postProvider = new SmfPostProvider(&smfP); |
|
108 //TODO:- it should be nested switch case as there are multiple APIs under one interface |
|
109 //connect to appropriate slot |
|
110 connect(m_postProvider, |
|
111 SIGNAL(postsAvailable(SmfPostList*, SmfError, SmfResultPage)), |
|
112 this, |
|
113 SLOT(showPosts(SmfPostList* , SmfError , SmfResultPage ))); |
|
114 |
|
115 writeLog("Before m_postProvider->posts="); |
|
116 //request for self posts |
|
117 m_postProvider->posts(); |
|
118 break; |
|
119 case 0: |
|
120 m_contactFetcher = new SmfContactFetcher(&smfP); |
|
121 //connect to appropriate slot |
|
122 connect(m_contactFetcher, |
|
123 SIGNAL(friendsListAvailable(SmfContactList*, SmfError , SmfResultPage)), |
|
124 this, |
|
125 SLOT(showFriends(SmfContactList*, SmfError , SmfResultPage))); |
|
126 |
|
127 writeLog("Before m_contactFetcher->friends="); |
|
128 //request for friends, excluding paging info |
|
129 m_contactFetcher->friends(); |
|
130 break; |
|
131 } |
|
132 } |
|
133 void DisplayWidget::showPosts(SmfPostList* postlist, SmfError error, SmfResultPage resultPage) |
|
134 { |
|
135 writeLog("TestScreen::showPosts"); |
|
136 ui.listWidget->clear(); |
|
137 ui.listWidget->setVerticalScrollBar(ui.verticalScrollBar_list); |
|
138 writeLog("TestScreen::showPosts count="); |
|
139 writeLog(QString::number(postlist->count())); |
|
140 writeLog("Error="); |
|
141 writeLog(QString::number(error)); |
|
142 if(error) |
|
143 { |
|
144 QString smferrString("Smf Error code="); |
|
145 smferrString += QString::number(error); |
|
146 QMessageBox::information(this,"Error",smferrString,QMessageBox::Ok); |
|
147 } |
|
148 //display post description |
|
149 |
|
150 foreach(SmfPost post, *postlist) |
|
151 { |
|
152 QString desc = post.description(); |
|
153 ui.listWidget->addItem(desc); |
|
154 } |
|
155 ui.listWidget->show(); |
|
156 } |
|
157 void DisplayWidget::showFriends(SmfContactList* frnds, SmfError err, SmfResultPage) |
|
158 { |
|
159 splash.finish(this); |
|
160 writeLog("TestScreen::showFriends count="); |
|
161 writeLog(QString::number(frnds->count())); |
|
162 writeLog("Error="); |
|
163 writeLog(QString::number(err)); |
|
164 //display friends |
|
165 |
|
166 foreach(SmfContact frnd, *frnds) |
|
167 { |
|
168 //lets display only street |
|
169 QVariant nameVar = frnd.value("Name"); |
|
170 QContactName name = nameVar.value<QContactName>(); |
|
171 QString fname; |
|
172 QString lname; |
|
173 #ifdef OLDER_QT_MOBILITY |
|
174 fname = name.first(); |
|
175 lname = name.last(); |
|
176 #else |
|
177 fname = name.firstName(); |
|
178 lname = name.lastName(); |
|
179 #endif |
|
180 |
|
181 ui.listWidget->addItem(fname); |
|
182 } |
|
183 ui.listWidget->show(); |
|
184 } |
|
185 void DisplayWidget::writeLog(QString log) const |
|
186 { |
|
187 #ifdef WRITE_LOG |
|
188 QFile file("c:\\data\\SmfClientLogs.txt"); |
|
189 if (!file.open(QIODevice::Append | QIODevice::Text)) |
|
190 ; |
|
191 QTextStream out(&file); |
|
192 out << log << "\n"; |
|
193 file.close(); |
|
194 #endif |
|
195 } |
|
196 DisplayWidget::~DisplayWidget() |
|
197 { |
|
198 |
|
199 } |