|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "feedview.h" |
|
19 |
|
20 #include <hbpushbutton.h> |
|
21 #include <hblabel.h> |
|
22 #include <hbmainwindow.h> |
|
23 |
|
24 #include <QTimer> |
|
25 |
|
26 #include <prcpresencebuddyinfo_qt.h> |
|
27 #include <prcpresencereader_qt.h> |
|
28 #include <prcpresencewriter_qt.h> |
|
29 |
|
30 FeedView::FeedView(QObject *parent): |
|
31 QObject(parent), |
|
32 mView(NULL), |
|
33 iWriter(NULL), |
|
34 iReader(NULL), |
|
35 mManager(NULL), |
|
36 mUpdateTimer(NULL), |
|
37 mStarted(false) |
|
38 { |
|
39 bool ok = false; |
|
40 mDocumentLoader.load(":/xml/feedview.docml", &ok); |
|
41 |
|
42 if (ok) |
|
43 { |
|
44 mView = static_cast<HbView*>(mDocumentLoader.findWidget(QString("view"))); |
|
45 } |
|
46 else |
|
47 { |
|
48 qFatal("Unable to read :/xml/feedview.docml"); |
|
49 } |
|
50 |
|
51 HbPushButton *create = static_cast<HbPushButton*>(mDocumentLoader.findObject("createContactsButton")); |
|
52 connect(create, SIGNAL(clicked()), this, SLOT(createPressed())); |
|
53 |
|
54 HbPushButton *start = static_cast<HbPushButton*>(mDocumentLoader.findObject("startButton")); |
|
55 connect(start, SIGNAL(clicked()), this, SLOT(startPressed())); |
|
56 |
|
57 HbPushButton *stop = static_cast<HbPushButton*>(mDocumentLoader.findObject("stopButton")); |
|
58 connect(stop, SIGNAL(clicked()), this, SLOT(stopPressed())); |
|
59 |
|
60 iWriter = PrcPresenceWriter::createWriter(); |
|
61 iReader = PrcPresenceReader::createReader(); |
|
62 |
|
63 mManager = new QContactManager("symbian"); |
|
64 |
|
65 mUpdateTimer = new QTimer(); |
|
66 mUpdateTimer->setInterval(2000); |
|
67 connect(mUpdateTimer, SIGNAL(timeout()), this, SLOT(updateRandomPresence())); |
|
68 } |
|
69 |
|
70 FeedView::~FeedView() |
|
71 { |
|
72 delete mView; |
|
73 delete iWriter; |
|
74 delete iReader; |
|
75 delete mManager; |
|
76 delete mUpdateTimer; |
|
77 } |
|
78 |
|
79 void FeedView::startPressed() |
|
80 { |
|
81 if (!mStarted) |
|
82 { |
|
83 static_cast<HbPushButton*>(mDocumentLoader.findObject("createContactsButton"))->setEnabled(false); |
|
84 |
|
85 HbMainWindow* window = mView->mainWindow(); |
|
86 window->setInteractive(false); |
|
87 HbLabel *label = static_cast<HbLabel*>(mDocumentLoader.findObject("textLabel")); |
|
88 label->setPlainText("Presence feeder active."); |
|
89 |
|
90 QContactDetailFilter filter; |
|
91 filter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
|
92 QString typeContact = QContactType::TypeContact; |
|
93 filter.setValue(typeContact); |
|
94 |
|
95 QList<QContactLocalId> contacts = mManager->contactIds(filter); |
|
96 |
|
97 foreach (QContactLocalId id, contacts) |
|
98 { |
|
99 QContact contact = mManager->contact(id); |
|
100 |
|
101 QList<QContactOnlineAccount> accounts = contact.details<QContactOnlineAccount>(); |
|
102 |
|
103 foreach (QContactOnlineAccount account, accounts) |
|
104 { |
|
105 PrcPresenceBuddyInfoQt* buddy = PrcPresenceBuddyInfoQt::createInstance(); |
|
106 |
|
107 QString fullAccount = account.serviceProvider() + ':' + account.accountUri(); |
|
108 buddy->setIdentity(fullAccount); |
|
109 mBuddyList.append(fullAccount); |
|
110 |
|
111 if (qrand() % 2 == 0) |
|
112 { |
|
113 buddy->setAvailability(PrcPresenceBuddyInfoQt::PrcNotAvailable, "hep"); |
|
114 } |
|
115 else |
|
116 { |
|
117 buddy->setAvailability(PrcPresenceBuddyInfoQt::PrcAvailable, "hep"); |
|
118 } |
|
119 iWriter->writePresence( *buddy ); |
|
120 |
|
121 delete buddy; |
|
122 } |
|
123 } |
|
124 |
|
125 window->setInteractive(true); |
|
126 mUpdateTimer->start(); |
|
127 mStarted = true; |
|
128 } |
|
129 } |
|
130 |
|
131 void FeedView::stopPressed() |
|
132 { |
|
133 HbLabel *label = static_cast<HbLabel*>(mDocumentLoader.findObject("textLabel")); |
|
134 label->setPlainText("Presence feeder not active."); |
|
135 mBuddyList.clear(); |
|
136 mUpdateTimer->stop(); |
|
137 mStarted = false; |
|
138 static_cast<HbPushButton*>(mDocumentLoader.findObject("createContactsButton"))->setEnabled(true); |
|
139 } |
|
140 |
|
141 void FeedView::createPressed() |
|
142 { |
|
143 QContact c; |
|
144 QContactName name; |
|
145 name.setFirstName("sip"); |
|
146 name.setLastName("test"); |
|
147 c.saveDetail(&name); |
|
148 QContactPhoneNumber number; |
|
149 number.setNumber("1234567"); |
|
150 number.setContexts(QContactDetail::ContextHome); |
|
151 number.setSubTypes(QContactPhoneNumber::SubTypeMobile); |
|
152 c.saveDetail(&number); |
|
153 QContactOnlineAccount account; |
|
154 account.setSubTypes(QStringList() << QContactOnlineAccount::SubTypeSip); |
|
155 account.setServiceProvider("sip"); |
|
156 account.setAccountUri("test@test.com"); |
|
157 c.saveDetail(&account); |
|
158 mManager->saveContact(&c); |
|
159 |
|
160 QContact c2; |
|
161 QContactName name2; |
|
162 name2.setFirstName("two"); |
|
163 name2.setLastName("accounts"); |
|
164 c2.saveDetail(&name2); |
|
165 QContactOnlineAccount account2; |
|
166 account2.setSubTypes(QStringList() << QContactOnlineAccount::SubTypeImpp); |
|
167 account2.setServiceProvider("yahoo"); |
|
168 account2.setAccountUri("test@yahoo.com"); |
|
169 c2.saveDetail(&account2); |
|
170 QContactOnlineAccount account3; |
|
171 account3.setSubTypes(QStringList() << QContactOnlineAccount::SubTypeImpp); |
|
172 account3.setServiceProvider("msn"); |
|
173 account3.setAccountUri("test@msn.com"); |
|
174 c2.saveDetail(&account3); |
|
175 mManager->saveContact(&c2); |
|
176 |
|
177 HbLabel *label = static_cast<HbLabel*>(mDocumentLoader.findObject("textLabel")); |
|
178 label->setPlainText("Contacts created."); |
|
179 } |
|
180 |
|
181 void FeedView::updateRandomPresence() |
|
182 { |
|
183 int random = qrand() % mBuddyList.count(); |
|
184 |
|
185 PrcPresenceBuddyInfoQt* buddy = iReader->presenceInfo(mBuddyList.at(random)); |
|
186 |
|
187 if (qrand() % 2 == 0) |
|
188 { |
|
189 buddy->setAvailability(PrcPresenceBuddyInfoQt::PrcNotAvailable, "hep"); |
|
190 } |
|
191 else |
|
192 { |
|
193 buddy->setAvailability(PrcPresenceBuddyInfoQt::PrcAvailable, "hep"); |
|
194 } |
|
195 iWriter->writePresence( *buddy ); |
|
196 |
|
197 delete buddy; |
|
198 } |