|
1 /*! |
|
2 * Copyright (c) 2010 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: Handles phone indicators. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "phoneindicatorcontroller.h" |
|
19 #include "phoneindicators.h" |
|
20 |
|
21 #include <QList> |
|
22 #include <QPair> |
|
23 |
|
24 #ifdef Q_OS_SYMBIAN |
|
25 #include <logsmodel.h> |
|
26 #include <logsfilter.h> |
|
27 #include <logsdomaincrkeys.h> |
|
28 #include <hbicon.h> |
|
29 #endif |
|
30 |
|
31 PhoneIndicatorController::PhoneIndicatorController(QObject *parent): |
|
32 QObject(parent), m_logsModel(0), m_missedCallsFilter(0) |
|
33 { |
|
34 #ifdef Q_OS_SYMBIAN |
|
35 m_setManager = new XQSettingsManager(this); |
|
36 |
|
37 XQSettingsKey settingsKey( XQSettingsKey::TargetCentralRepository, |
|
38 KCRUidLogs.iUid, KLogsNewMissedCalls ); |
|
39 |
|
40 bool ok = connect( m_setManager, |
|
41 SIGNAL( valueChanged(const XQSettingsKey & ,const QVariant &)), |
|
42 this, SLOT(updateMissedCallIndicator(XQSettingsKey, |
|
43 QVariant))); |
|
44 ASSERT( ok ); |
|
45 ok = false; |
|
46 ok = m_setManager->startMonitoring( settingsKey ); |
|
47 ASSERT(ok); |
|
48 |
|
49 qRegisterMetaType<PhoneIndicatorInfo>("PhoneIndicatorInfo"); |
|
50 |
|
51 #endif |
|
52 } |
|
53 |
|
54 PhoneIndicatorController::~PhoneIndicatorController() |
|
55 { |
|
56 #ifdef Q_OS_SYMBIAN |
|
57 XQPublishAndSubscribeSettingsKey missedCallCountKey( |
|
58 (qint32)KCRUidLogs.iUid, (quint32)KLogsNewMissedCalls ); |
|
59 m_setManager->stopMonitoring(missedCallCountKey); |
|
60 delete m_setManager; |
|
61 delete m_missedCallsFilter; |
|
62 delete m_logsModel; |
|
63 #endif |
|
64 } |
|
65 |
|
66 void PhoneIndicatorController::setActiveCallData( |
|
67 const TDesC &text, const TDesC &icon ) |
|
68 { |
|
69 m_cli = QString::fromUtf16 (text.Ptr (), text.Length ()); |
|
70 m_callImage = QString::fromUtf16 (icon.Ptr (), icon.Length ()); |
|
71 } |
|
72 |
|
73 void PhoneIndicatorController::clearActiveCallData() |
|
74 { |
|
75 m_cli.clear(); |
|
76 m_callImage.clear(); |
|
77 disableActiveCallIndicator(); |
|
78 } |
|
79 |
|
80 void PhoneIndicatorController::enableActiveCallIndicator() |
|
81 { |
|
82 if (!m_cli.isEmpty()){ |
|
83 QString indicatorType(indicatorName(PhoneActiveCallIndicator)); |
|
84 QVariantMap parameters; |
|
85 |
|
86 parameters.insert( |
|
87 QVariant(HbIndicatorInterface::PrimaryTextRole ).toString(), |
|
88 m_cli); |
|
89 |
|
90 parameters.insert(QVariant( HbIndicatorInterface::DecorationNameRole).toString(), |
|
91 m_callImage); |
|
92 |
|
93 m_indicator.activate(indicatorType, parameters); |
|
94 } |
|
95 } |
|
96 void PhoneIndicatorController::disableActiveCallIndicator() |
|
97 { |
|
98 QString indicatorType(indicatorName(PhoneActiveCallIndicator)); |
|
99 m_indicator.deactivate(indicatorType); |
|
100 } |
|
101 |
|
102 void PhoneIndicatorController::updateMissedCallIndicator( |
|
103 const XQSettingsKey &key, const QVariant &value) |
|
104 { |
|
105 #ifdef Q_OS_SYMBIAN |
|
106 if ( key.key() == (quint32)KLogsNewMissedCalls ){ |
|
107 if ( value.toInt() == 0 ){ |
|
108 QString indicatorType(indicatorName(PhoneMissedCallIndicator)); |
|
109 m_indicator.deactivate(indicatorType); |
|
110 delete m_missedCallsFilter; |
|
111 m_missedCallsFilter = NULL; |
|
112 delete m_logsModel; |
|
113 m_logsModel = NULL; |
|
114 } else { |
|
115 m_logsModel = new LogsModel(LogsModel::LogsFullModel); |
|
116 m_missedCallsFilter = new LogsFilter(LogsFilter::Missed); |
|
117 connect( m_missedCallsFilter, |
|
118 SIGNAL(rowsInserted(const QModelIndex &, int, int )), |
|
119 this, SLOT(setMissedallIndicatorData())); |
|
120 m_missedCallsFilter->setMaxSize(value.toInt() + 1); |
|
121 m_missedCallsFilter->setSourceModel(m_logsModel); |
|
122 } |
|
123 } |
|
124 #endif |
|
125 } |
|
126 |
|
127 void PhoneIndicatorController::setMissedallIndicatorData() |
|
128 { |
|
129 #ifdef Q_OS_SYMBIAN |
|
130 |
|
131 XQSettingsKey settingsKey( XQSettingsKey::TargetCentralRepository, |
|
132 KCRUidLogs.iUid, KLogsNewMissedCalls ); |
|
133 QString indicatorType(indicatorName(PhoneMissedCallIndicator)); |
|
134 |
|
135 int missedCallCount = m_setManager->readItemValue( settingsKey, |
|
136 XQSettingsManager::TypeInt ).toInt(); |
|
137 |
|
138 if ( missedCallCount > 0 ) { |
|
139 QVariantMap parameters; |
|
140 QString lastMissedCallFrom; |
|
141 int repeatedMissedCalls(0); |
|
142 |
|
143 if ( m_missedCallsFilter->rowCount() > 0 ){ |
|
144 lastMissedCallFrom = m_missedCallsFilter->data( |
|
145 m_missedCallsFilter->index(0,0), |
|
146 Qt::DisplayRole).toStringList().takeFirst(); |
|
147 repeatedMissedCalls = 1; |
|
148 } |
|
149 for( int i = 1; i < missedCallCount && i |
|
150 < m_missedCallsFilter->rowCount(); i++ ){ |
|
151 QStringList displayData = m_missedCallsFilter->data( |
|
152 m_missedCallsFilter->index(i,0), |
|
153 Qt::DisplayRole).toStringList(); |
|
154 if ( lastMissedCallFrom == displayData.at(0) ){ |
|
155 repeatedMissedCalls++; |
|
156 } else { |
|
157 i = missedCallCount; // Break |
|
158 } |
|
159 } |
|
160 // First row |
|
161 parameters.insert( |
|
162 QVariant( HbIndicatorInterface::PrimaryTextRole ).toString(), |
|
163 ( hbTrId("txt_phone_dblist_ln_missed_calls", |
|
164 missedCallCount))); |
|
165 |
|
166 // Second row |
|
167 if ( missedCallCount >= repeatedMissedCalls ) |
|
168 { |
|
169 parameters.insert( |
|
170 QVariant( HbIndicatorInterface::SecondaryTextRole ).toString(), |
|
171 lastMissedCallFrom ); |
|
172 } |
|
173 |
|
174 // icon |
|
175 //QList<QVariant> icons = m_missedCallsFilter->data( |
|
176 // m_missedCallsFilter->index(0,0), |
|
177 // Qt::DecorationRole).value<QList<QVariant> >(); |
|
178 //QString iconName = icons.first().value<HbIcon>().iconName(); |
|
179 QString iconName = "qtg_mono_missed_call_unseen"; |
|
180 parameters.insert( |
|
181 QVariant( HbIndicatorInterface::DecorationNameRole ).toString(), |
|
182 iconName ); |
|
183 |
|
184 m_indicator.activate(indicatorType, parameters); |
|
185 } else { |
|
186 m_indicator.deactivate( indicatorType ); |
|
187 } |
|
188 #endif |
|
189 } |