![]() |
Home · All Namespaces · All Classes |
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (directui@nokia.com) 00006 ** 00007 ** This file is part of systemui. 00008 ** 00009 ** If you have questions regarding the use of this file, please contact 00010 ** Nokia at directui@nokia.com. 00011 ** 00012 ** This library is free software; you can redistribute it and/or 00013 ** modify it under the terms of the GNU Lesser General Public 00014 ** License version 2.1 as published by the Free Software Foundation 00015 ** and appearing in the file LICENSE.LGPL included in the packaging 00016 ** of this file. 00017 ** 00018 ****************************************************************************/ 00019 #include "widgetnotificationsink.h" 00020 #include "notificationwidgetparameterfactory.h" 00021 #include "genericnotificationparameterfactory.h" 00022 #include <MRemoteAction> 00023 #include <MLocale> 00024 #include <MGConfItem> 00025 00026 const char *WidgetNotificationSink::NOTIFICATION_ID_PROPERTY = "notificationId"; 00027 const char *WidgetNotificationSink::GROUP_ID_PROPERTY = "groupId"; 00028 const char *WidgetNotificationSink::USER_REMOVABLE_PROPERTY = "userRemovable"; 00029 const char *WidgetNotificationSink::TITLE_TEXT_PROPERTY = "titleText"; 00030 const char *WidgetNotificationSink::SUBTITLE_TEXT_PROPERTY = "subtitleText"; 00031 const char *WidgetNotificationSink::GENERIC_TEXT_PROPERTY = "genericText"; 00032 00033 WidgetNotificationSink::WidgetNotificationSink() : 00034 NotificationSink(), 00035 privacySetting(NULL), 00036 clickableNotifications(true) 00037 { 00038 } 00039 00040 QString WidgetNotificationSink::determineIconId(const NotificationParameters ¶meters) 00041 { 00042 return parameters.value(NotificationWidgetParameterFactory::iconIdKey()).toString(); 00043 } 00044 00045 bool WidgetNotificationSink::determineUserRemovability(const NotificationParameters ¶meters) 00046 { 00047 QVariant value = parameters.value(NotificationWidgetParameterFactory::userRemovableKey()); 00048 if(value.isValid()) { 00049 return value.toBool(); 00050 } 00051 return true; 00052 } 00053 00054 MBanner *WidgetNotificationSink::createInfoBanner(const Notification ¬ification) 00055 { 00056 MBanner *infoBanner = createInfoBanner(notification.type(), notification.groupId(), notification.parameters()); 00057 infoBanner->setProperty(NOTIFICATION_ID_PROPERTY, notification.notificationId()); 00058 00059 return infoBanner; 00060 } 00061 00062 MBanner *WidgetNotificationSink::createInfoBanner(Notification::NotificationType type, uint groupId, const NotificationParameters ¶meters) 00063 { 00064 // Create a banner on the basis of notification type 00065 MBanner *infoBanner = new MBanner; 00066 infoBanner->setObjectName(type == Notification::ApplicationEvent ? "EventBanner" : "SystemBanner"); 00067 infoBanner->setProperty(TITLE_TEXT_PROPERTY, infoBannerTitleText(parameters)); 00068 infoBanner->setProperty(SUBTITLE_TEXT_PROPERTY, infoBannerSubtitleText(parameters)); 00069 infoBanner->setProperty(GENERIC_TEXT_PROPERTY, infoBannerGenericText(parameters)); 00070 infoBanner->setProperty(GROUP_ID_PROPERTY, groupId); 00071 infoBanner->setProperty(USER_REMOVABLE_PROPERTY, determineUserRemovability(parameters)); 00072 infoBanner->setIconID(determineIconId(parameters)); 00073 updateTitles(infoBanner); 00074 updateActions(infoBanner, parameters); 00075 00076 // Catch clicks from the info banner 00077 if(clickableNotifications) { 00078 connect(infoBanner, SIGNAL(clicked()), this, SLOT(infoBannerClicked()), Qt::QueuedConnection); 00079 } 00080 return infoBanner; 00081 } 00082 00083 void WidgetNotificationSink::updateTitles(MBanner *infoBanner) 00084 { 00085 if (privacySetting != NULL && privacySetting->value().toBool()) { 00086 // Privacy is honored and privacy mode is enabled: use a generic text in the banner 00087 infoBanner->setTitle(infoBanner->property(GENERIC_TEXT_PROPERTY).toString()); 00088 infoBanner->setSubtitle(QString()); 00089 } else { 00090 // Privacy is not honored or privacy mode is disabled: use the given text in the banner 00091 infoBanner->setTitle(infoBanner->objectName() == "EventBanner" ? infoBanner->property(TITLE_TEXT_PROPERTY).toString() : QString()); 00092 infoBanner->setSubtitle(infoBanner->property(SUBTITLE_TEXT_PROPERTY).toString()); 00093 } 00094 } 00095 00096 void WidgetNotificationSink::updateActions(MBanner *infoBanner, const NotificationParameters ¶meters) 00097 { 00098 // Remove the old actions 00099 foreach(QAction * qAction, infoBanner->actions()) { 00100 infoBanner->removeAction(qAction); 00101 delete qAction; 00102 } 00103 00104 // Add the action if it exists 00105 QString action = parameters.value(NotificationWidgetParameterFactory::actionKey()).toString(); 00106 if (!action.isEmpty()) { 00107 MRemoteAction *remoteAction = new MRemoteAction(action, infoBanner); 00108 remoteAction->setVisible(false); 00109 infoBanner->addAction(remoteAction); 00110 } 00111 } 00112 00113 QString WidgetNotificationSink::infoBannerTitleText(const NotificationParameters ¶meters) 00114 { 00115 return parameters.value(NotificationWidgetParameterFactory::summaryKey()).toString(); 00116 } 00117 00118 QString WidgetNotificationSink::infoBannerSubtitleText(const NotificationParameters ¶meters) 00119 { 00120 return parameters.value(NotificationWidgetParameterFactory::bodyKey()).toString(); 00121 } 00122 00123 QString WidgetNotificationSink::infoBannerGenericText(const NotificationParameters ¶meters) 00124 { 00125 QString genericText; 00126 QString genericTextId = parameters.value(NotificationWidgetParameterFactory::genericTextIdKey()).toString(); 00127 00128 if(!genericTextId.isEmpty()) { 00129 QString genericTextCatalogue = parameters.value(NotificationWidgetParameterFactory::genericTextCatalogueKey()).toString(); 00130 00131 if(!genericTextCatalogue.isEmpty()) { 00132 // Load the catalog from disk if it's not yet loaded 00133 MLocale locale; 00134 locale.installTrCatalog(genericTextCatalogue); 00135 MLocale::setDefault(locale); 00136 00137 int eventCount = parameters.value(GenericNotificationParameterFactory::countKey()).toInt(); 00138 genericText = qtTrId(genericTextId.toUtf8(), eventCount).arg(eventCount); 00139 } 00140 } 00141 00142 return genericText; 00143 } 00144 00145 void WidgetNotificationSink::infoBannerClicked() 00146 { 00147 MBanner *infoBanner = qobject_cast<MBanner *>(sender()); 00148 00149 if (infoBanner != NULL) { 00150 // Trigger each remote action associated with the clicked info banner 00151 foreach(QAction * qAction, infoBanner->actions()) { 00152 MRemoteAction *remoteAction = dynamic_cast<MRemoteAction *>(qAction); 00153 if (remoteAction) { 00154 remoteAction->trigger(); 00155 } 00156 } 00157 00158 // Only remove the banner if it is user removable 00159 if (infoBanner->property(USER_REMOVABLE_PROPERTY).toBool()) { 00160 // Get the notification ID from the info banner 00161 bool ok = false; 00162 uint notificationId = infoBanner->property(NOTIFICATION_ID_PROPERTY).toUInt(&ok); 00163 if (ok) { 00164 // Request notification removal 00165 emit notificationRemovalRequested(notificationId); 00166 } else { 00167 uint groupId = infoBanner->property(GROUP_ID_PROPERTY).toUInt(&ok); 00168 if (ok) { 00169 // Request notification group clearing 00170 emit notificationGroupClearingRequested(groupId); 00171 } 00172 } 00173 } 00174 } 00175 } 00176 00177 void WidgetNotificationSink::setHonorPrivacySetting(bool honor) 00178 { 00179 if (honor) { 00180 if (privacySetting == NULL) { 00181 privacySetting = new MGConfItem("/desktop/meego/privacy/private_lockscreen_notifications", this); 00182 emitPrivacySettingValue(); 00183 00184 connect(privacySetting, SIGNAL(valueChanged()), this, SLOT(emitPrivacySettingValue())); 00185 } 00186 } else { 00187 if (privacySetting != NULL) { 00188 delete privacySetting; 00189 privacySetting = NULL; 00190 00191 emitPrivacySettingValue(); 00192 } 00193 } 00194 } 00195 00196 void WidgetNotificationSink::emitPrivacySettingValue() 00197 { 00198 emit privacySettingChanged(privacySetting != NULL ? privacySetting->value().toBool() : false); 00199 } 00200 00201 void WidgetNotificationSink::setNotificationsClickable(bool clickable) 00202 { 00203 clickableNotifications = clickable; 00204 }
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:19:34 Doxygen 1.7.1 |
MeeGo Touch |
