diff -r 9ba4404ef423 -r 759dc5235cdb emailservices/nmregister/src/nmmailboxregisterinterface.cpp --- a/emailservices/nmregister/src/nmmailboxregisterinterface.cpp Thu May 27 12:43:55 2010 +0300 +++ b/emailservices/nmregister/src/nmmailboxregisterinterface.cpp Fri Jun 11 13:27:14 2010 +0300 @@ -15,6 +15,8 @@ * */ +#include "emailtrace.h" + #include #include #include @@ -25,284 +27,320 @@ #include "nmmailboxregisterinterface_p.h" //mandatory keys -const QString hsItemName ("item:name"); -const QString hsitemLaunchUri ("item:launchuri"); -const QString hsitemPublisherId ("item:publisherId"); +const QString hsItemName("item:name"); +const QString hsitemLaunchUri("item:launchuri"); +const QString hsitemPublisherId("item:publisherId"); //not mandatory -const QString hsItemWidgetUri ("widget:uri"); -const QString hsItemDescription ("item:description"); +const QString hsItemWidgetUri("widget:uri"); +const QString hsItemDescription("item:description"); //for icon - not mandatory -const QString hsIconFileName ("icon:filename");//to display specific icon from file -const QString hsIconName ("icon:name");// HbIcon -const QString hsIconApplicationId ("icon:applicationid"); // icon from associated application +const QString hsIconFileName("icon:filename");//to display specific icon from file +const QString hsIconName("icon:name");// HbIcon +const QString hsIconApplicationId("icon:applicationid"); // icon from associated application //Custom for nmHsWidgets //NmHsWidgetParamAccountId is used to identify what email account will be monitored by //the registered hs widget -const QString NmHsWidgetParamAccountId ("widgetparam:accountId"); +const QString NmHsWidgetParamAccountId("widgetparam:accountId"); //same as above but for pushing the widget to homescreen -const QString NmHsAccountId ("accountId"); +const QString NmHsAccountId("accountId"); //NmHsWidgetParamAccountIconName is used to identify mailbox icon in application library -const QString NmHsWidgetParamAccountIconName ("widgetparam:accountIconName"); +const QString NmHsWidgetParamAccountIconName("widgetparam:accountIconName"); //same as above but for pushing the widget to homescreen -const QString NmHsAccountIconName ("accountIconName"); +const QString NmHsAccountIconName("accountIconName"); //This is used to identify nmhswidget in homescreen -const QString NmHsWidget ("nmhswidget"); +const QString NmHsWidget("nmhswidget"); //parameter values -const QString NmPublisherName ("NmMailboxRegisterInterface"); -const QString NmLaunchUri ("appto://0x200255BA?activityname=EmailInboxView&accountId="); +const QString NmPublisherName("NmMailboxRegisterInterface"); +const QString NmLaunchUri("appto://0x200255BA?activityname=EmailInboxView&accountId="); //URI for the defined service const QLatin1String interfaceUri("com.nokia.symbian.IEmailRegisterAccount"); /** Localization file name*/ const QString KNmRegisterLocFileName = "nmregister_"; /** Localization file location*/ -const QString KNmRegisterLocLocation = "z:/resource/qt/translations/"; +const QString KNmRegisterLocLocation = "/translations/"; /*! - Constructor -*/ + Constructor + */ NmMailboxRegisterInterface::NmMailboxRegisterInterface(QObject *parent) : - QObject(parent), m_d( new NmMailboxRegisterInterfacePrivate(this) ) - { - } + QObject(parent), m_d(new NmMailboxRegisterInterfacePrivate(this)) +{ + NM_FUNCTION; +} /*! - Destructor -*/ + Destructor + */ NmMailboxRegisterInterface::~NmMailboxRegisterInterface() - { +{ + NM_FUNCTION; + delete m_d; - } +} /*! - registerNewMailbox -*/ -bool NmMailboxRegisterInterface::registerNewMailbox(quint64 accountId, - QString accountName, QString accountIconName) - { - return m_d->registerNewMailbox( accountId, accountName, accountIconName ); - } + registerNewMailbox + */ +bool NmMailboxRegisterInterface::registerNewMailbox( + quint64 accountId, + QString accountName, + QString accountIconName) +{ + NM_FUNCTION; + + return m_d->registerNewMailbox(accountId, accountName, accountIconName); +} /*! - updateMailboxName -*/ -bool NmMailboxRegisterInterface::updateMailboxName(quint64 accountId, - QString newName) - { - return m_d->updateMailboxName( accountId, newName ); - } - + updateMailboxName + */ +bool NmMailboxRegisterInterface::updateMailboxName(quint64 accountId, QString newName) +{ + NM_FUNCTION; + + return m_d->updateMailboxName(accountId, newName); +} /*! - unregisterMailbox -*/ + unregisterMailbox + */ bool NmMailboxRegisterInterface::unregisterMailbox(quint64 accountId) - { - return m_d->unregisterMailbox( accountId ); - } +{ + NM_FUNCTION; + + return m_d->unregisterMailbox(accountId); +} - - - +/*! + Constructor + */ +NmMailboxRegisterInterfacePrivate::NmMailboxRegisterInterfacePrivate(QObject *parent) : + XQServiceProvider(interfaceUri, parent), + mManager(new QServiceManager()), + mService(0), + mTranslator(new QTranslator()) +{ + NM_FUNCTION; +} /*! - Constructor -*/ -NmMailboxRegisterInterfacePrivate::NmMailboxRegisterInterfacePrivate(QObject *parent) : - XQServiceProvider(interfaceUri, parent ), - mManager(0), - mService(0), - mTranslator(0) - { - //commented out until MCL has nmregister files in place here: epoc32/include/platform/qt/translations/ - /*mTranslator = new QTranslator(); - QString lang = QLocale::system().name(); - bool loadSucceed = mTranslator->load(KNmRegisterLocFileName + lang, KNmRegisterLocLocation); - qDebug() << "NmMailboxRegisterInterfacePrivate mTranslator->load loadSucceed:"< interfaces = mManager->findInterfaces(filter); - mService = mManager->loadInterface(interfaces.first()); + if(interfaces.isEmpty()){ + return false; //no maching interfaces available } + + mService = mManager->loadInterface(interfaces.first()); + if(!mService){ + return false; //loading interface failed + } + + return true; //succesfully loaded the service +} /*! - Destructor -*/ + Destructor + */ NmMailboxRegisterInterfacePrivate::~NmMailboxRegisterInterfacePrivate() - { - if(mTranslator){ - delete mTranslator; - mTranslator = NULL; +{ + NM_FUNCTION; + + delete mTranslator; + mTranslator = NULL; + + delete mService; + mService = NULL; + + delete mManager; + mManager = NULL; +} + +bool NmMailboxRegisterInterfacePrivate::registerNewMailbox( + quint64 accountId, + QString accountName, + QString accountIconName) +{ + NM_FUNCTION; + + if(!loadMenuClientService()){ + NM_ERROR(1,"loadService() failed!"); + return false; } - if (mService) - { - delete mService; - } - if (mManager) - { - delete mManager; - } + + //localization + QString lang = QLocale::system().name(); + bool loadSucceed = mTranslator->load(KNmRegisterLocFileName + lang, KNmRegisterLocLocation); + QCoreApplication::installTranslator(mTranslator); + + //check that accountIconName is valid otherwise pass default mailbox icon + HbIcon mailBoxIcon(accountIconName); + if (mailBoxIcon.pixmap().height() == 0) { + mailBoxIcon = NmIcons::getIcon(NmIcons::NmIconDefaultMailbox); + accountIconName = mailBoxIcon.iconName(); } + QMap map; + //------------------------------ + map[hsItemName] = accountName; + map[hsitemLaunchUri] = formLaunchUri(accountId); + map[hsitemPublisherId] = NmPublisherName; + map[hsItemWidgetUri] = NmHsWidget; + map[hsItemDescription] = hbTrId("txt_mail_widget_dblist_preview_of_recent_mail"); + map[hsIconFileName] = accountIconName; + // to add widget params that are mapped to widgets properties + map[NmHsWidgetParamAccountId] = QString::number(accountId); + map[NmHsWidgetParamAccountIconName] = accountIconName; + //------------------------------ -bool NmMailboxRegisterInterfacePrivate::registerNewMailbox(quint64 accountId, - QString accountName, QString accountIconName) - { - //check that accountIconName is valid otherwise pass default mailbox icon - HbIcon mailBoxIcon(accountIconName); - if(mailBoxIcon.pixmap().height() == 0){ - mailBoxIcon = NmIcons::getIcon(NmIcons::NmIconDefaultMailbox); - accountIconName = mailBoxIcon.iconName(); + bool retVal(false); + bool ret(false); + ret = QMetaObject::invokeMethod( mService,"add", + Qt::DirectConnection, + Q_RETURN_ARG(bool, retVal), + Q_ARG(QVariantMap, map)); + + //Push the registered widget also to homescreen right away + bool pushRetVal = pushWidgetToHomescreen(accountId, accountIconName); + + return (retVal && ret && pushRetVal); +} + +bool NmMailboxRegisterInterfacePrivate::updateMailboxName(quint64 accountId, QString newName) +{ + NM_FUNCTION; + + if(!loadMenuClientService()){ + NM_ERROR(1,"loadService() failed!"); + return false; } QMap map; //------------------------------ - map[hsItemName] = accountName; - map[hsitemLaunchUri] = formLaunchUri(accountId); + map[hsitemLaunchUri] = formLaunchUri(accountId); map[hsitemPublisherId] = NmPublisherName; - map[hsItemWidgetUri] = NmHsWidget; - //commented out until MCL has nmregister files in place here: epoc32/include/platform/qt/translations/ - //map[hsItemDescription] = hbTrId("txt_mail_widget_dblist_preview_of_recent_mail"); - map[hsItemDescription] = "test description for widget"; - map[hsIconFileName] = accountIconName; - // to add widget params that are mapped to widgets properties - map[NmHsWidgetParamAccountId] = QString::number(accountId); - map[NmHsWidgetParamAccountIconName] = accountIconName; + map[hsItemWidgetUri] = NmHsWidget; + map[NmHsWidgetParamAccountId] = QString::number(accountId); //------------------------------ - + + QList list; //list of items that mach the query bool retVal(false); + bool ret(false); + ret = QMetaObject::invokeMethod(mService, "getList", + Qt::DirectConnection, + Q_RETURN_ARG(QList , list), + Q_ARG(QVariantMap, map)); + + //Normally there should be only one instance, but just in case + while (!list.isEmpty()) { + //update the account name + list.first()[hsItemName] = newName; + //commit changes + ret = QMetaObject::invokeMethod( mService,"add", + Qt::DirectConnection, + Q_RETURN_ARG(bool, retVal), + Q_ARG(QVariantMap, list.first())); + list.removeFirst(); + } + //if either invoke or "getList" or "add" return failure + return (retVal && ret); +} + +bool NmMailboxRegisterInterfacePrivate::unregisterMailbox(quint64 accountId) +{ + NM_FUNCTION; + + if(!loadMenuClientService()){ + NM_ERROR(1,"loadService() failed!"); + return false; + } - bool ret = QMetaObject::invokeMethod( mService,"add", - Qt::DirectConnection, - Q_RETURN_ARG(bool, retVal), - Q_ARG(QVariantMap, map)); + QMap map; + //------------------------------ + map[hsitemLaunchUri] = formLaunchUri(accountId); + map[hsitemPublisherId] = NmPublisherName; + map[hsItemWidgetUri] = NmHsWidget; + map[NmHsWidgetParamAccountId] = QString::number(accountId); + //------------------------------ - //Push the registered widget also to homescreen right away - bool pushRetVal = pushWidgetToHomescreen(accountId, accountIconName); - - return (retVal && ret && pushRetVal); + QList list; //list of items that mach the query + bool retVal(false); + bool ret(false); + ret = QMetaObject::invokeMethod(mService, "getList", + Qt::DirectConnection, + Q_RETURN_ARG(QList , list), + Q_ARG(QVariantMap, map)); + + //Normally there should be only one instance, but just in case + //Otherwise there will be ghost instances in the application list + while (!list.isEmpty()) { + + //commit changes + ret = QMetaObject::invokeMethod( mService,"remove", + Qt::DirectConnection, + Q_RETURN_ARG(bool, retVal), + Q_ARG(QVariantMap, list.first())); + list.removeFirst(); } -bool NmMailboxRegisterInterfacePrivate::updateMailboxName(quint64 accountId, - QString newName) - { - QMap map; - //------------------------------ - map[hsitemLaunchUri] = formLaunchUri(accountId); - map[hsitemPublisherId] = NmPublisherName; - map[hsItemWidgetUri] = NmHsWidget; - map[NmHsWidgetParamAccountId] = QString::number(accountId); - //------------------------------ - - QList list; //list of items that mach the query - bool retVal(false); - bool ret = QMetaObject::invokeMethod( mService,"getList", - Qt::DirectConnection, - Q_RETURN_ARG(QList, list), - Q_ARG(QVariantMap, map)); - - - //Normally there should be only one instance, but just in case - while( !list.isEmpty() ) - { - //update the account name - list.first()[hsItemName] = newName; - //commit changes - ret = QMetaObject::invokeMethod( mService,"add", - Qt::DirectConnection, - Q_RETURN_ARG(bool, retVal), - Q_ARG(QVariantMap, list.first())); - list.removeFirst(); - } - //if either invoke or "getList" or "add" return failure - return (retVal && ret); - } + return (retVal && ret); +} -bool NmMailboxRegisterInterfacePrivate::unregisterMailbox(quint64 accountId) - { - - QMap map; - //------------------------------ - map[hsitemLaunchUri] = formLaunchUri(accountId); - map[hsitemPublisherId] = NmPublisherName; - map[hsItemWidgetUri] = NmHsWidget; - map[NmHsWidgetParamAccountId] = QString::number(accountId); - //------------------------------ - - QList list; //list of items that mach the query - bool retVal(false); - bool ret = QMetaObject::invokeMethod( mService,"getList", - Qt::DirectConnection, - Q_RETURN_ARG(QList, list), - Q_ARG(QVariantMap, map)); - +bool NmMailboxRegisterInterfacePrivate::pushWidgetToHomescreen( + quint64 accountId, + QString accountIconName) +{ + NM_FUNCTION; - //Normally there should be only one instance, but just in case - //Otherwise there will be ghost instances in the application list - while( !list.isEmpty() ) - { - - //commit changes - ret = QMetaObject::invokeMethod( mService,"remove", - Qt::DirectConnection, - Q_RETURN_ARG(bool, retVal), - Q_ARG(QVariantMap, list.first())); - list.removeFirst(); - } - - return (retVal && ret); - } - -bool NmMailboxRegisterInterfacePrivate::pushWidgetToHomescreen( quint64 accountId, QString accountIconName ) - { // load plugin QServiceManager manager; QServiceFilter filter("com.nokia.symbian.IHomeScreenClient"); filter.setServiceName("hshomescreenclientplugin"); QList interfaces = manager.findInterfaces(filter); - - if(interfaces.isEmpty()) - { - QServiceManager::Error errori = manager.error(); + + if (interfaces.isEmpty()) { return false; - } - QObject* service = manager.loadInterface( interfaces.first() ); - if(!service){qDebug() << "service is null ";} - + } + QObject* service = manager.loadInterface(interfaces.first()); + if (!service) { + NM_ERROR(1,"service is null "); + return false; + } + //-------------------------------- QVariantHash map; map[NmHsAccountId] = QString::number(accountId); map[NmHsAccountIconName] = accountIconName; //-------------------------------- - + // invoke function synchronously bool retVal(false); - bool ret = QMetaObject::invokeMethod( service, "addWidget", - Qt::DirectConnection, - Q_RETURN_ARG(bool, retVal), - Q_ARG(QString, NmHsWidget), - Q_ARG(QVariantHash, map)); - - if(!ret){ - qDebug()<< "method invoke failed!"; - } - if(!retVal){ - qDebug() << "addWidget() failed!!"; - } - - if(service) - { - delete service; - } - + bool ret(false); + ret = QMetaObject::invokeMethod( service, "addWidget", + Qt::DirectConnection, + Q_RETURN_ARG(bool, retVal), + Q_ARG(QString, NmHsWidget), + Q_ARG(QVariantHash, map)); + + delete service; + service = NULL; + return (retVal && ret); - } +} QString NmMailboxRegisterInterfacePrivate::formLaunchUri(quint64 accountId) const - { +{ return NmLaunchUri + QString::number(accountId); - } +}