15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "nmindicatorplugin.h" |
18 #include "nmindicatorplugin.h" |
19 #include "nmindicator.h" |
19 #include "nmindicator.h" |
|
20 #include "nmsendingindicator.h" |
|
21 #include "nmsyncindicator.h" |
|
22 #include "nmunreadindicator.h" |
20 |
23 |
21 #include <QCoreApplication> |
24 #include <QCoreApplication> |
22 #include <QLocale> |
25 #include <QLocale> |
23 #include <QVariant> |
26 #include <QVariant> |
24 #include <QTimer> |
27 #include <QTimer> |
25 |
28 |
26 #include <xqservicerequest.h> |
|
27 #include <email_services_api.h> |
|
28 |
|
29 Q_EXPORT_PLUGIN(NmIndicatorPlugin) |
29 Q_EXPORT_PLUGIN(NmIndicatorPlugin) |
30 |
30 |
31 const int NmMaxIndicatorCount = 10; |
31 const int NmMaxIndicatorCount = 10; |
32 static const QString emailServiceNameMailbox = "nmail.com.nokia.symbian.IEmailInboxView"; |
32 static const QString NmIndicatorName = "com.nokia.nmail.indicatorplugin_%1/1.0"; |
|
33 |
33 |
34 |
34 /*! |
35 /*! |
35 \class NmIndicatorPlugin |
36 \class NmIndicatorPlugin |
36 \brief Mail indicator plugin class. |
37 \brief Mail indicator plugin class. |
37 */ |
38 */ |
38 |
39 |
39 /*! |
40 /*! |
40 Class constructor. |
41 Class constructor. |
41 */ |
42 */ |
42 NmIndicatorPlugin::NmIndicatorPlugin() |
43 NmIndicatorPlugin::NmIndicatorPlugin() |
43 : mError(0), mTranslator(0), mStatusBarIndicator(0), mSending(false) |
44 : mError(0), mTranslator(0) |
44 { |
45 { |
|
46 NM_FUNCTION; |
45 } |
47 } |
46 |
48 |
47 /*! |
49 /*! |
48 Class destructor. |
50 Class destructor. |
49 */ |
51 */ |
50 NmIndicatorPlugin::~NmIndicatorPlugin() |
52 NmIndicatorPlugin::~NmIndicatorPlugin() |
51 { |
53 { |
52 NMLOG("NmIndicatorPlugin::~NmIndicatorPlugin"); |
54 NM_FUNCTION; |
|
55 |
53 delete mTranslator; |
56 delete mTranslator; |
54 } |
57 } |
55 |
58 |
56 /*! |
59 /*! |
57 Return notification types this plugin implements |
60 Return notification types this plugin implements |
58 */ |
61 */ |
59 QStringList NmIndicatorPlugin::indicatorTypes() const |
62 QStringList NmIndicatorPlugin::indicatorTypes() const |
60 { |
63 { |
|
64 NM_FUNCTION; |
|
65 |
61 QStringList types; |
66 QStringList types; |
62 for (int i=0; i<NmMaxIndicatorCount; i++) { |
67 for (int i=0; i<NmMaxIndicatorCount; i++) { |
63 QString name = QString("com.nokia.nmail.indicatorplugin_%1/1.0").arg(i); |
68 QString name = QString(NmIndicatorName).arg(i); |
64 types << name; |
69 types << name; |
65 } |
70 } |
|
71 types << NmSendingIndicatorType; |
|
72 types << NmSyncIndicator::IndicatorType; |
|
73 types << NmUnreadIndicatorType; |
66 return types; |
74 return types; |
67 } |
75 } |
68 |
76 |
69 /*! |
77 /*! |
70 Check if client is allowed to use notification widget |
78 Check if client is allowed to use notification widget |
71 see HbIndicatorPluginInterface |
79 see HbIndicatorPluginInterface |
72 */ |
80 */ |
73 bool NmIndicatorPlugin::accessAllowed(const QString &indicatorType, |
81 bool NmIndicatorPlugin::accessAllowed(const QString &indicatorType, |
74 const QVariantMap &securityInfo) const |
82 const QVariantMap &securityInfo) const |
75 { |
83 { |
|
84 NM_FUNCTION; |
|
85 |
76 Q_UNUSED(indicatorType) |
86 Q_UNUSED(indicatorType) |
77 Q_UNUSED(securityInfo) |
87 Q_UNUSED(securityInfo) |
78 |
88 |
79 // This plugin doesn't perform operations that may compromise security. |
89 // This plugin doesn't perform operations that may compromise security. |
80 // All clients are allowed to use. |
90 // All clients are allowed to use. |
81 return true; |
91 return true; |
82 } |
92 } |
83 |
93 |
84 |
|
85 /*! |
|
86 Called when any of the indicator receive updated status of the global status |
|
87 */ |
|
88 void NmIndicatorPlugin::globalStatusChanged(bool sending) |
|
89 { |
|
90 mSending = sending; |
|
91 |
|
92 // Pass the information to the indicator handling the status bar icon |
|
93 if (mStatusBarIndicator) { |
|
94 mStatusBarIndicator->acceptIcon(sending); |
|
95 } |
|
96 else { |
|
97 // No indicator is showing the status now. |
|
98 indicatorIconLost(); |
|
99 } |
|
100 } |
|
101 |
|
102 /*! |
94 /*! |
103 Creates an indicator of type indicatorType. Ownership is passed to the caller. |
95 Creates an indicator of type indicatorType. Ownership is passed to the caller. |
104 */ |
96 */ |
105 HbIndicatorInterface* NmIndicatorPlugin::createIndicator( |
97 HbIndicatorInterface* NmIndicatorPlugin::createIndicator( |
106 const QString &indicatorType) |
98 const QString &indicatorType) |
107 { |
99 { |
|
100 NM_FUNCTION; |
|
101 |
108 if (!mTranslator) { |
102 if (!mTranslator) { |
109 mTranslator = new QTranslator(); |
103 mTranslator = new QTranslator(); |
110 QString lang = QLocale::system().name(); |
104 QString lang = QLocale::system().name(); |
111 QString appName = "mail_"; |
105 QString appName = "mail_"; |
112 QString path = "z:/resource/qt/translations/"; |
106 QString path = "z:/resource/qt/translations/"; |
113 mTranslator->load(appName + lang, path); |
107 mTranslator->load(appName + lang, path); |
114 QCoreApplication::installTranslator(mTranslator); |
108 QCoreApplication::installTranslator(mTranslator); |
115 } |
109 } |
116 |
110 |
117 NmIndicator* indicator = new NmIndicator(indicatorType); |
111 HbIndicatorInterface *indicator; |
118 connect(indicator, SIGNAL(indicatorIconLost()), this, SLOT(indicatorIconLost())); |
112 if (indicatorType == NmSendingIndicatorType) { |
119 connect(indicator, SIGNAL(destroyed(QObject *)), this, SLOT(indicatorDeactivated(QObject *))); |
113 indicator = new NmSendingIndicator(indicatorType); |
120 connect(indicator, SIGNAL(globalStatusChanged(bool)), this, SLOT(globalStatusChanged(bool))); |
114 } |
121 connect(indicator, SIGNAL(mailboxLaunched(quint64)), this, SLOT(showMailbox(quint64))); |
115 else if (indicatorType == NmUnreadIndicatorType) { |
122 mIndicators.append(indicator); |
116 indicator = new NmUnreadIndicator(indicatorType); |
|
117 } |
|
118 else if (indicatorType == NmSyncIndicator::IndicatorType) { |
|
119 indicator = new NmSyncIndicator(); |
|
120 } |
|
121 else { |
|
122 indicator = new NmIndicator(indicatorType); |
|
123 } |
123 |
124 |
124 return indicator; |
125 return indicator; |
125 } |
126 } |
126 |
127 |
127 /*! |
128 /*! |
128 Returns the last error code. |
129 Returns the last error code. |
129 */ |
130 */ |
130 int NmIndicatorPlugin::error() const |
131 int NmIndicatorPlugin::error() const |
131 { |
132 { |
|
133 NM_FUNCTION; |
|
134 |
132 return mError; |
135 return mError; |
133 } |
136 } |
134 |
|
135 /*! |
|
136 Called when an indicator signals about lost indicator. |
|
137 \param true if a new indicator was found |
|
138 */ |
|
139 bool NmIndicatorPlugin::indicatorIconLost() |
|
140 { |
|
141 bool found(false); |
|
142 mStatusBarIndicator = NULL; |
|
143 |
|
144 foreach (NmIndicator* indicator, mIndicators) { |
|
145 // Find a new candidate to handle the status bar icon |
|
146 if (indicator->acceptIcon(mSending)) { |
|
147 mStatusBarIndicator = indicator; |
|
148 found = true; |
|
149 break; |
|
150 } |
|
151 } |
|
152 return found; |
|
153 } |
|
154 |
|
155 /*! |
|
156 Remove destroyed indicators from the list. |
|
157 \param indicator item that has been deleted |
|
158 */ |
|
159 void NmIndicatorPlugin::indicatorDeactivated(QObject *indObject) |
|
160 { |
|
161 NMLOG(QString("NmIndicatorPlugin::indicatorDeactivated %1").arg((int)indObject)); |
|
162 NmIndicator *indicator = static_cast<NmIndicator*>(indObject); |
|
163 mIndicators.removeAll(indicator); |
|
164 if (mStatusBarIndicator == indicator) { |
|
165 mStatusBarIndicator = NULL; |
|
166 |
|
167 // Find new indicator to take care of the status bar icon |
|
168 indicatorIconLost(); |
|
169 } |
|
170 } |
|
171 |
|
172 /*! |
|
173 Opens inbox view to specific mailbox |
|
174 \return true if inbox is succesfully opened |
|
175 */ |
|
176 bool NmIndicatorPlugin::showMailbox(quint64 mailboxId) |
|
177 { |
|
178 NMLOG("NmIndicatorPlugin::showMailbox"); |
|
179 XQServiceRequest request( |
|
180 emailServiceNameMailbox, |
|
181 emailOperationViewInbox, |
|
182 true); |
|
183 |
|
184 QList<QVariant> list; |
|
185 list.append(QVariant(mailboxId)); |
|
186 |
|
187 request.setArguments(list); |
|
188 |
|
189 int returnValue(-1); |
|
190 return request.send(returnValue); |
|
191 } |
|
192 |
|
193 |
|