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: Animated icon. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QLocalSocket> |
|
19 |
|
20 #include "bubbletester.h" |
|
21 |
|
22 |
|
23 BubbleTester::BubbleTester() : mLocalSocket(new QLocalSocket()) |
|
24 { |
|
25 } |
|
26 |
|
27 BubbleTester::~BubbleTester() |
|
28 { |
|
29 mLocalSocket->disconnectFromServer(); |
|
30 delete mLocalSocket; |
|
31 } |
|
32 |
|
33 bool BubbleTester::connectToServer() |
|
34 { |
|
35 mLocalSocket->connectToServer("bubbletestserver"); |
|
36 |
|
37 // This logic needs to be improved |
|
38 bool success = mLocalSocket->waitForConnected(500); |
|
39 |
|
40 qDebug() << "Socket Connect status: " << success; |
|
41 |
|
42 if (success) { |
|
43 connect(mLocalSocket, SIGNAL(readyRead()), this, SLOT(readData())); |
|
44 } |
|
45 |
|
46 return success; |
|
47 } |
|
48 |
|
49 void BubbleTester::readData() |
|
50 { |
|
51 QByteArray inputByteArray = mLocalSocket->readAll(); |
|
52 QDataStream inputDataStream(inputByteArray); |
|
53 QString textDocument; |
|
54 inputDataStream >> textDocument; |
|
55 |
|
56 QString errorStr; |
|
57 int errorLine; |
|
58 int errorColumn; |
|
59 |
|
60 if (!mDomDocument.setContent(textDocument, true, &errorStr, &errorLine, |
|
61 &errorColumn)) { |
|
62 qDebug() << "Cannot read tester data!"; |
|
63 } else { |
|
64 emit dataChanged(); |
|
65 } |
|
66 } |
|
67 |
|
68 QList<QString> BubbleTester::bubbles() |
|
69 { |
|
70 QDomNodeList list = mDomDocument.elementsByTagName("bubble"); |
|
71 |
|
72 QList<QString> testBubbles; |
|
73 |
|
74 for (int i=0; i<list.count(); i++ ) { |
|
75 QDomNode node = list.at(i); |
|
76 if (node.isElement()) { |
|
77 QDomElement e = node.toElement(); |
|
78 QString id = e.attribute("id"); |
|
79 testBubbles.append(id); |
|
80 } |
|
81 } |
|
82 |
|
83 return testBubbles; |
|
84 } |
|
85 |
|
86 QString BubbleTester::dataField( const QString& bubble, const QString& fieldName ) |
|
87 { |
|
88 QString text(""); |
|
89 QDomElement elem = bubbleElement(bubble); |
|
90 |
|
91 if (!elem.isNull()) { |
|
92 QDomNodeList list = elem.elementsByTagName(fieldName); |
|
93 |
|
94 if (list.count()) { |
|
95 QDomNode node = list.at(0); |
|
96 if (node.isElement()) { |
|
97 QDomElement e = node.toElement(); |
|
98 text = e.text(); |
|
99 } |
|
100 } |
|
101 } |
|
102 |
|
103 return text; |
|
104 } |
|
105 |
|
106 QDomElement BubbleTester::bubbleElement(const QString& bubble) |
|
107 { |
|
108 QDomNodeList list = mDomDocument.elementsByTagName("bubble"); |
|
109 |
|
110 QDomElement elem; |
|
111 |
|
112 for (int i=0; i<list.count(); i++ ) { |
|
113 QDomNode node = list.at(i); |
|
114 if (node.isElement()) { |
|
115 QDomElement e = node.toElement(); |
|
116 QString id = e.attribute("id"); |
|
117 if (id == bubble) { |
|
118 elem = e; |
|
119 break; |
|
120 } |
|
121 } |
|
122 } |
|
123 |
|
124 return elem; |
|
125 } |
|
126 |
|
127 QString BubbleTester::dataField(const QString& fieldName) |
|
128 { |
|
129 QString text(""); |
|
130 QDomNodeList list = mDomDocument.elementsByTagName(fieldName); |
|
131 |
|
132 if (list.count()) { |
|
133 QDomNode node = list.at(0); |
|
134 if (node.isElement()) { |
|
135 QDomElement e = node.toElement(); |
|
136 text = e.text(); |
|
137 } |
|
138 } |
|
139 |
|
140 return text; |
|
141 } |
|