1 #include "testscreen.h" |
|
2 #include "smfclient.h" |
|
3 #include <QFile> |
|
4 #include <QMessageBox> |
|
5 #include <QTextStream> |
|
6 |
|
7 TestScreen::TestScreen(QWidget *parent) |
|
8 : QWidget(parent) |
|
9 { |
|
10 ui.setupUi(this); |
|
11 |
|
12 connect(ui.pushButton,SIGNAL(clicked()),this,SLOT(friendsButtonClicked())); |
|
13 connect(ui.pushButton_2,SIGNAL(clicked()),this,SLOT(postsButtonClicked())); |
|
14 writeLog("Start"); |
|
15 SmfClient client; |
|
16 |
|
17 //Getting list of provider who implement this interface |
|
18 // QString name("org.symbian.smf.client.contact.fetcher"); |
|
19 //TODO:- PM should use commented interface name instead |
|
20 // QString name("org.symbian.smf.client.contact.posts"); |
|
21 QString name("posts"); |
|
22 writeLog("Before client.GetServices"); |
|
23 providerList= client.GetServices(name); |
|
24 //add provider names to the combobox |
|
25 for(int i=0; i< providerList->count();i++) |
|
26 { |
|
27 SmfProvider provider = providerList->at(i); |
|
28 ui.comboBox->addItem(provider.serviceName()); |
|
29 } |
|
30 |
|
31 //logging for debugging purpose |
|
32 writeLog("GetServices count="); |
|
33 QString c = QString::number(providerList->count()); |
|
34 writeLog(c); |
|
35 SmfProvider smfP(providerList->at(0)); |
|
36 |
|
37 writeLog("0th SmfProvider="); |
|
38 writeLog(smfP.m_description); |
|
39 writeLog(smfP.m_serviceUrl.toString()); |
|
40 writeLog(smfP.m_appUrl.toString()); |
|
41 m_postProvider = new SmfPostProvider(&smfP); |
|
42 //connect to appropriate slot |
|
43 connect(m_postProvider, |
|
44 SIGNAL(postsAvailable(SmfPostList*, SmfError, SmfResultPage)), |
|
45 this, |
|
46 SLOT(showPosts(SmfPostList* , SmfError , SmfResultPage ))); |
|
47 |
|
48 writeLog("Before m_postProvider->posts="); |
|
49 //request for self posts |
|
50 m_postProvider->posts(); |
|
51 } |
|
52 void TestScreen::friendsButtonClicked() |
|
53 { |
|
54 ui.listWidget->clear(); |
|
55 // pixmap.load("c:\\data\\smfpix.bmp"); |
|
56 // splash.setPixmap(pixmap); |
|
57 // splash.show(); |
|
58 //get the current index of combobox to get the SmfProvider |
|
59 int providerIndex = ui.comboBox->currentIndex(); |
|
60 //now create contact fetcher with 0th |
|
61 SmfProvider smfP(providerList->at(providerIndex)); |
|
62 |
|
63 writeLog("0th SmfProvider="); |
|
64 writeLog(smfP.m_description); |
|
65 writeLog(smfP.m_serviceUrl.toString()); |
|
66 writeLog(smfP.m_appUrl.toString()); |
|
67 m_contactFetcher = new SmfContactFetcher(&smfP); |
|
68 //connect to appropriate slot |
|
69 connect(m_contactFetcher,SIGNAL(friendsListAvailable(SmfContactList*, SmfError , SmfResultPage)), |
|
70 this,SLOT(showFriends(SmfContactList*, SmfError , SmfResultPage))); |
|
71 /*connect(m_contactFetcher,SIGNAL(groupListAvailable(SmfGroupList*, SmfError , SmfResultPage)), |
|
72 this,SLOT(showFriends(SmfGroupList*, SmfError , SmfResultPage)));*/ |
|
73 |
|
74 writeLog("Before m_contactFetcher->friends="); |
|
75 //request for friends, excluding paging info |
|
76 m_contactFetcher->friends(); |
|
77 //m_contactFetcher->groups(); |
|
78 } |
|
79 void TestScreen::postsButtonClicked() |
|
80 { |
|
81 //get the current index of combobox to get the SmfProvider |
|
82 int providerIndex = ui.comboBox->currentIndex(); |
|
83 //now create contact fetcher with 0th |
|
84 SmfProvider smfP(providerList->at(providerIndex)); |
|
85 |
|
86 writeLog("0th SmfProvider="); |
|
87 writeLog(smfP.m_description); |
|
88 writeLog(smfP.m_serviceUrl.toString()); |
|
89 writeLog(smfP.m_appUrl.toString()); |
|
90 m_postProvider = new SmfPostProvider(&smfP); |
|
91 // //connect to appropriate slot |
|
92 connect(m_postProvider, |
|
93 SIGNAL(postsAvailable(SmfPostList*, SmfError, SmfResultPage)), |
|
94 this, |
|
95 SLOT(showPosts(SmfPostList*, SmfError, SmfResultPage))); |
|
96 |
|
97 writeLog("Before m_contactFetcher->posts="); |
|
98 //request for self posts |
|
99 m_postProvider->posts(); |
|
100 } |
|
101 void TestScreen::writeLog(QString log) const |
|
102 { |
|
103 #ifdef WRITE_LOG |
|
104 QFile file("c:\\data\\SmfClientLogs.txt"); |
|
105 if (!file.open(QIODevice::Append | QIODevice::Text)) |
|
106 ; |
|
107 QTextStream out(&file); |
|
108 out << log << "\n"; |
|
109 file.close(); |
|
110 #endif |
|
111 } |
|
112 void TestScreen::showGroups(SmfGroupList* grps, SmfError err, SmfResultPage) |
|
113 { |
|
114 writeLog("TestScreen::showFriends count="); |
|
115 writeLog(QString::number(grps->count())); |
|
116 writeLog("Error="); |
|
117 writeLog(QString::number(err)); |
|
118 //display friends |
|
119 QMessageBox::information(this,QString("Name"),grps->at(0).name(),QMessageBox::Ok); |
|
120 QMessageBox::information(this,QString("Name"),grps->at(1).name(),QMessageBox::Ok); |
|
121 // SmfContact frnd1 = frnds->at(0); |
|
122 // SmfContact frnd2 = frnds->at(1); |
|
123 // QString name = frnd1.value("Name").toString(); |
|
124 // QMessageBox::information(this,QString("Name"),name,QMessageBox::Ok); |
|
125 // QString name2 = frnd2.value("Name").toString(); |
|
126 // QMessageBox::information(this,QString("Name"),name2,QMessageBox::Ok); |
|
127 // foreach(SmfContact frnd, *frnds) |
|
128 // { |
|
129 // //lets display only street |
|
130 //// QContactNickname name = frnd.value("Nickname").value<QContactNickname>(); |
|
131 //// QString nick = name.value("Nickname"); |
|
132 // QString name = frnd.value("Name").toString(); |
|
133 // QMessageBox::information(this,QString("Name"),name,QMessageBox::Ok); |
|
134 // } |
|
135 } |
|
136 void TestScreen::showFriends(SmfContactList* frnds, SmfError err, SmfResultPage) |
|
137 { |
|
138 splash.finish(this); |
|
139 writeLog("TestScreen::showFriends count="); |
|
140 writeLog(QString::number(frnds->count())); |
|
141 writeLog("Error="); |
|
142 writeLog(QString::number(err)); |
|
143 //display friends |
|
144 |
|
145 foreach(SmfContact frnd, *frnds) |
|
146 { |
|
147 //lets display only street |
|
148 QVariant nameVar = frnd.value("Name"); |
|
149 QContactName name = nameVar.value<QContactName>(); |
|
150 // QString nick = name.value("Nickname"); |
|
151 QString fname; |
|
152 QString lname; |
|
153 #ifdef OLDER_QT_MOBILITY |
|
154 fname = name.first(); |
|
155 lname = name.last(); |
|
156 #else |
|
157 fname = name.firstName(); |
|
158 lname = name.lastName(); |
|
159 #endif |
|
160 |
|
161 ui.listWidget->addItem(fname); |
|
162 // QMessageBox::information(this,QString("First Name"),fname,QMessageBox::Ok); |
|
163 // QMessageBox::information(this,QString("Last Name"),lname,QMessageBox::Ok); |
|
164 } |
|
165 ui.listWidget->show(); |
|
166 } |
|
167 void TestScreen::showPosts(SmfPostList* postlist, SmfError error, SmfResultPage resultPage) |
|
168 { |
|
169 writeLog("TestScreen::showPosts"); |
|
170 ui.listWidget->clear(); |
|
171 writeLog("TestScreen::showPosts count="); |
|
172 writeLog(QString::number(postlist->count())); |
|
173 writeLog("Error="); |
|
174 writeLog(QString::number(error)); |
|
175 if(error) |
|
176 { |
|
177 QString smferrString("Smf Error code="); |
|
178 smferrString += QString::number(error); |
|
179 QMessageBox::information(this,"Error",smferrString,QMessageBox::Ok); |
|
180 } |
|
181 //display post description |
|
182 |
|
183 foreach(SmfPost post, *postlist) |
|
184 { |
|
185 QString desc = post.description(); |
|
186 ui.listWidget->addItem(desc); |
|
187 } |
|
188 ui.listWidget->show(); |
|
189 } |
|
190 TestScreen::~TestScreen() |
|
191 { |
|
192 |
|
193 } |
|