|
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 #include "msgindicator.h" |
|
18 #include "msgindicator_p.h" |
|
19 |
|
20 #include <QThreadPool> |
|
21 #include <QRunnable> |
|
22 #include <QByteArray> |
|
23 #include <QProcess> |
|
24 #include "debugtraces.h" |
|
25 |
|
26 #include <xqservicerequest.h> |
|
27 |
|
28 //Localized Constants |
|
29 #define LOC_UNREAD_MESSAGES hbTrId("txt_messaging_list_ln") |
|
30 #define LOC_NEW_MESSAGES hbTrId("txt_common_opt_ln_new_messages") |
|
31 |
|
32 //---------------------------------------------------------------------- |
|
33 class ServiceRequestSenderTask : public QRunnable |
|
34 { |
|
35 public: |
|
36 ServiceRequestSenderTask(qint64 conversationId):mConvId(conversationId) {} |
|
37 |
|
38 void run() |
|
39 { |
|
40 XQServiceRequest snd( |
|
41 "com.nokia.services.hbserviceprovider.conversationview", |
|
42 "open(qint64)",false); |
|
43 snd << mConvId; |
|
44 bool res=snd.send(); |
|
45 } |
|
46 |
|
47 ~ServiceRequestSenderTask() |
|
48 { |
|
49 } |
|
50 |
|
51 private: |
|
52 qint64 mConvId; |
|
53 }; |
|
54 |
|
55 //---------------------------------------------------------------------- |
|
56 |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // MsgIndicator::MsgIndicator |
|
60 // @see msgindicator.h |
|
61 // ---------------------------------------------------------------------------- |
|
62 MsgIndicator::MsgIndicator(const QString &indicatorType) : |
|
63 HbIndicatorInterface(indicatorType, |
|
64 HbIndicatorInterface::GroupPriorityHigh, |
|
65 InteractionActivated) |
|
66 { |
|
67 d_ptr = new MsgIndicatorPrivate(this); |
|
68 } |
|
69 |
|
70 // ---------------------------------------------------------------------------- |
|
71 // MsgIndicator::~MsgIndicator |
|
72 // @see msgindicator.h |
|
73 // ---------------------------------------------------------------------------- |
|
74 MsgIndicator::~MsgIndicator() |
|
75 { |
|
76 delete d_ptr; |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // MsgIndicator::handleInteraction |
|
81 // @see msgindicator.h |
|
82 // ---------------------------------------------------------------------------- |
|
83 bool MsgIndicator::handleInteraction(InteractionType type) |
|
84 { |
|
85 bool handled = false; |
|
86 if (type == InteractionActivated) |
|
87 { |
|
88 QThreadPool::globalInstance()->start( |
|
89 new ServiceRequestSenderTask(mConversationId)); |
|
90 handled = true; |
|
91 } |
|
92 return handled; |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // MsgIndicator::indicatorData |
|
97 // @see msgindicator.h |
|
98 // ---------------------------------------------------------------------------- |
|
99 QVariant MsgIndicator::indicatorData(int role) const |
|
100 { |
|
101 switch(role) |
|
102 { |
|
103 case TextRole: |
|
104 { |
|
105 mConversationId = -100; |
|
106 |
|
107 IndicatorData data; |
|
108 d_ptr->getIndicatorInfo(data); |
|
109 |
|
110 mConversationFromSingleContact = data.mFromSingle; |
|
111 mBodyText = data.mDescription; |
|
112 |
|
113 if (mConversationFromSingleContact) |
|
114 { |
|
115 mConversationId = (int)data.mConversationId; |
|
116 QString name = prepareDisplayName(data); |
|
117 name.append(QString(" (%1)").arg(data.mUnreadMsgCount)); |
|
118 return name; |
|
119 } |
|
120 else |
|
121 { |
|
122 QString text = QString("%1 new messages").arg(data.mUnreadMsgCount); |
|
123 return text; |
|
124 } |
|
125 } |
|
126 case SecondaryTextRole: |
|
127 { |
|
128 if (mConversationFromSingleContact) |
|
129 { |
|
130 return mBodyText; |
|
131 } |
|
132 else |
|
133 { |
|
134 return QString(); |
|
135 } |
|
136 } |
|
137 case IconNameRole: |
|
138 { |
|
139 QString iconName("z:/resource/messaging/message.svg"); |
|
140 return iconName; |
|
141 } |
|
142 default: |
|
143 return QVariant(); |
|
144 } |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------------------------- |
|
148 // MsgIndicator::handleClientRequest |
|
149 // @see msgindicator.h |
|
150 // ---------------------------------------------------------------------------- |
|
151 bool MsgIndicator::handleClientRequest( RequestType type, |
|
152 const QVariant ¶meter) |
|
153 { |
|
154 Q_UNUSED(parameter); |
|
155 bool handled(false); |
|
156 switch (type) { |
|
157 case RequestActivate: |
|
158 { |
|
159 emit dataChanged(); |
|
160 handled = true; |
|
161 } |
|
162 |
|
163 break; |
|
164 case RequestDeactivate: |
|
165 { |
|
166 // reset data |
|
167 mConversationId = -100; |
|
168 mBodyText = QString(); |
|
169 emit deactivate(); |
|
170 } |
|
171 break; |
|
172 default: |
|
173 break; |
|
174 } |
|
175 |
|
176 return handled; |
|
177 } |
|
178 |
|
179 // ---------------------------------------------------------------------------- |
|
180 // MsgIndicator::prepareDisplayName |
|
181 // @see msgindicator.h |
|
182 // ---------------------------------------------------------------------------- |
|
183 QString MsgIndicator::prepareDisplayName(IndicatorData& indicatorData) const |
|
184 |
|
185 { |
|
186 //Set the Contact Name/Number |
|
187 QString firstName(indicatorData.mFirstName); |
|
188 QString lastName(indicatorData.mLastName); |
|
189 QString contactAddress(indicatorData.mContactNum); |
|
190 QString nickName(indicatorData.mNickName); |
|
191 |
|
192 QString displayName; |
|
193 |
|
194 if (!nickName.isEmpty()) |
|
195 { |
|
196 displayName.append(nickName); |
|
197 } |
|
198 else if ( firstName.isEmpty() && lastName.isEmpty()) |
|
199 { |
|
200 displayName.append(contactAddress); |
|
201 } |
|
202 else if (lastName.isEmpty() && !firstName.isEmpty()) |
|
203 { |
|
204 displayName.append(firstName); |
|
205 } |
|
206 else if (firstName.isEmpty() && !lastName.isEmpty()) |
|
207 { |
|
208 displayName.append(lastName); |
|
209 } |
|
210 else |
|
211 { |
|
212 // If both first Name and last name are present |
|
213 displayName.append(firstName); |
|
214 displayName.append(" "); |
|
215 displayName.append(lastName); |
|
216 } |
|
217 return displayName; |
|
218 } |