emailuis/nmailuiengine/src/nmdatamanager.cpp
changeset 30 759dc5235cdb
parent 27 9ba4404ef423
equal deleted inserted replaced
27:9ba4404ef423 30:759dc5235cdb
    29     Constructor
    29     Constructor
    30 */
    30 */
    31 NmDataManager::NmDataManager() 
    31 NmDataManager::NmDataManager() 
    32 :mFactory(NULL)
    32 :mFactory(NULL)
    33 {
    33 {
       
    34     NM_FUNCTION;
       
    35     
    34     mFactory = NmDataPluginFactory::instance();
    36     mFactory = NmDataPluginFactory::instance();
    35 }
    37 }
    36 
    38 
    37 /*!
    39 /*!
    38     Destructor
    40     Destructor
    39 */
    41 */
    40 NmDataManager::~NmDataManager()
    42 NmDataManager::~NmDataManager()
    41 {
    43 {
       
    44     NM_FUNCTION;
       
    45     
    42     NmDataPluginFactory::releaseInstance(mFactory);
    46     NmDataPluginFactory::releaseInstance(mFactory);
    43 }
    47 }
    44 
    48 
    45 /*!
    49 /*!
    46     list mailbox ids in \a mailboxIdList array
    50     list mailbox ids in \a mailboxIdList array
    47 */
    51 */
    48 void NmDataManager::listMailboxIds(QList<NmId> &mailboxIdList)
    52 void NmDataManager::listMailboxIds(QList<NmId> &mailboxIdList)
    49 {
    53 {
       
    54     NM_FUNCTION;
       
    55     
    50     int count(mFactory->pluginInstances()->count());
    56     int count(mFactory->pluginInstances()->count());
    51     for (int i(0); i < count; i++) {
    57     for (int i(0); i < count; i++) {
    52         NmDataPluginInterface *instance =
    58         NmDataPluginInterface *instance =
    53             mFactory->interfaceInstance(mFactory->pluginInstances()->at(i));
    59             mFactory->interfaceInstance(mFactory->pluginInstances()->at(i));
    54         if (instance) {
    60         if (instance) {
    61     Creates mailbox instances and fill \a mailboxList array,
    67     Creates mailbox instances and fill \a mailboxList array,
    62     caller is responsible deletion of objects in the array
    68     caller is responsible deletion of objects in the array
    63 */
    69 */
    64 void NmDataManager::listMailboxes(QList<NmMailbox*> &mailboxList)
    70 void NmDataManager::listMailboxes(QList<NmMailbox*> &mailboxList)
    65 {
    71 {
       
    72     NM_FUNCTION;
       
    73     
    66     int count = mFactory->pluginInstances()->count();
    74     int count = mFactory->pluginInstances()->count();
    67     for (int i(0); i < count; i++) {
    75     for (int i(0); i < count; i++) {
    68         NmDataPluginInterface *instance =
    76         NmDataPluginInterface *instance =
    69             mFactory->interfaceInstance(mFactory->pluginInstances()->at(i));
    77             mFactory->interfaceInstance(mFactory->pluginInstances()->at(i));
    70         if (instance) {
    78         if (instance) {
    78      \a mailboxId Function fills \a folderList array,
    86      \a mailboxId Function fills \a folderList array,
    79      caller is responsible deletion of objects in the array
    87      caller is responsible deletion of objects in the array
    80 */
    88 */
    81 void NmDataManager::listFolders(const NmId mailboxId, QList<NmFolder*> &folderList)
    89 void NmDataManager::listFolders(const NmId mailboxId, QList<NmFolder*> &folderList)
    82 {
    90 {
       
    91     NM_FUNCTION;
       
    92     
    83     NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId);
    93     NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId);
    84     if (instance) {
    94     if (instance) {
    85         instance->listFolders(mailboxId, folderList);
    95         instance->listFolders(mailboxId, folderList);
    86     }
    96     }
    87 }
    97 }
    94 void NmDataManager::listMessages(
   104 void NmDataManager::listMessages(
    95         const NmId &mailboxId,
   105         const NmId &mailboxId,
    96         const NmId &folderId,
   106         const NmId &folderId,
    97         QList<NmMessageEnvelope*> &messageEnvelopeList)
   107         QList<NmMessageEnvelope*> &messageEnvelopeList)
    98 {
   108 {
       
   109     NM_FUNCTION;
       
   110     
    99     NmDataPluginInterface *instance = mFactory->interfaceInstance(folderId);
   111     NmDataPluginInterface *instance = mFactory->interfaceInstance(folderId);
   100     if (instance) {
   112     if (instance) {
   101         instance->listMessages(mailboxId, folderId, messageEnvelopeList);
   113         instance->listMessages(mailboxId, folderId, messageEnvelopeList);
   102     }
   114     }
   103 }
   115 }
   109 */
   121 */
   110 NmFolderMetaData *NmDataManager::folderById(
   122 NmFolderMetaData *NmDataManager::folderById(
   111     const NmId &mailboxId,
   123     const NmId &mailboxId,
   112     const NmId &folderId)
   124     const NmId &folderId)
   113 {
   125 {
   114     NMLOG("nmuiengine: getFolderById");
   126     NM_FUNCTION;
       
   127     
   115     NmFolderMetaData *folderMetaData(NULL);
   128     NmFolderMetaData *folderMetaData(NULL);
   116     QList<NmFolder*> folderList;
   129     QList<NmFolder*> folderList;
   117     listFolders(mailboxId, folderList);
   130     listFolders(mailboxId, folderList);
   118     const int folderListCount(folderList.count());
   131     const int folderListCount(folderList.count());
   119     for (int i(0); i < folderListCount; i++) {
   132     for (int i(0); i < folderListCount; i++) {
   133     Returns mailbox meta data. Ownership of NmMailboxMetaData is transferred.
   146     Returns mailbox meta data. Ownership of NmMailboxMetaData is transferred.
   134     NULL pointer is returned if mailbox by id is not found
   147     NULL pointer is returned if mailbox by id is not found
   135 */
   148 */
   136 NmMailboxMetaData *NmDataManager::mailboxById(const NmId &mailboxId)
   149 NmMailboxMetaData *NmDataManager::mailboxById(const NmId &mailboxId)
   137 {
   150 {
   138     NMLOG("nmuiengine: getMailboxById");
   151     NM_FUNCTION;
       
   152     
   139     NmMailboxMetaData *mailboxMetaData(NULL);
   153     NmMailboxMetaData *mailboxMetaData(NULL);
   140     NmMailbox* mbox = mailbox(mailboxId);
   154     NmMailbox* mbox = mailbox(mailboxId);
   141 
   155 
   142     if (mbox) {
   156     if (mbox) {
   143         mailboxMetaData = new NmMailboxMetaData();
   157         mailboxMetaData = new NmMailboxMetaData();
   159 NmMessageEnvelope *NmDataManager::envelopeById(
   173 NmMessageEnvelope *NmDataManager::envelopeById(
   160     const NmId &mailboxId,
   174     const NmId &mailboxId,
   161     const NmId &folderId,
   175     const NmId &folderId,
   162     const NmId &messageId)
   176     const NmId &messageId)
   163 {
   177 {
   164     NMLOG("nmuiengine: getMessageById");
   178     NM_FUNCTION;
   165 
   179     
   166     NmMessageEnvelope *msgEnvelope(NULL);
   180     NmMessageEnvelope *msgEnvelope(NULL);
   167     NmMessage* msg = message(mailboxId, folderId, messageId);
   181     NmMessage* msg = message(mailboxId, folderId, messageId);
   168 
   182 
   169     if (msg) {
   183     if (msg) {
   170     	msgEnvelope = new NmMessageEnvelope(msg->envelope());
   184     	msgEnvelope = new NmMessageEnvelope(msg->envelope());
   178     Get new NmMailbox object by id. Ownership is transferred to the caller.
   192     Get new NmMailbox object by id. Ownership is transferred to the caller.
   179     NULL pointer is returned if message id is not found from plugin.
   193     NULL pointer is returned if message id is not found from plugin.
   180 */
   194 */
   181 NmMailbox *NmDataManager::mailbox(const NmId &mailboxId)
   195 NmMailbox *NmDataManager::mailbox(const NmId &mailboxId)
   182 {
   196 {
       
   197     NM_FUNCTION;
       
   198     
   183     NmMailbox *newMailboxObject(NULL);
   199     NmMailbox *newMailboxObject(NULL);
   184     NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId);
   200     NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId);
   185     int retVal(NmNotFoundError);
   201     int retVal(NmNotFoundError);
   186 
   202 
   187     if (instance) {
   203     if (instance) {
   202 */
   218 */
   203 NmFolder *NmDataManager::folder(
   219 NmFolder *NmDataManager::folder(
   204     const NmId &mailboxId,
   220     const NmId &mailboxId,
   205     const NmId &folderId)
   221     const NmId &folderId)
   206 {
   222 {
       
   223     NM_FUNCTION;
       
   224     
   207     NmFolder* newFolderObject(NULL);
   225     NmFolder* newFolderObject(NULL);
   208     QList<NmFolder*> folderList;
   226     QList<NmFolder*> folderList;
   209     listFolders(mailboxId, folderList);
   227     listFolders(mailboxId, folderList);
   210     for (int i(0); i < folderList.count(); i++) {
   228     for (int i(0); i < folderList.count(); i++) {
   211         if (folderList[i]->folderId() == folderId) {
   229         if (folderList[i]->folderId() == folderId) {
   225 NmMessage *NmDataManager::message(
   243 NmMessage *NmDataManager::message(
   226     const NmId &mailboxId,
   244     const NmId &mailboxId,
   227     const NmId &folderId,
   245     const NmId &folderId,
   228     const NmId &messageId)
   246     const NmId &messageId)
   229 {
   247 {
       
   248     NM_FUNCTION;
       
   249     
   230     NmMessage *newMessageObject(NULL);
   250     NmMessage *newMessageObject(NULL);
   231     NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId);
   251     NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId);
   232 
   252 
   233     int retVal(NmNotFoundError);
   253     int retVal(NmNotFoundError);
   234     if (instance) {
   254     if (instance) {
   252     const NmId &mailboxId,
   272     const NmId &mailboxId,
   253     const NmId &folderId,
   273     const NmId &folderId,
   254     const NmId &messageId,
   274     const NmId &messageId,
   255     NmMessagePart &messagePart)
   275     NmMessagePart &messagePart)
   256 {
   276 {
       
   277     NM_FUNCTION;
       
   278     
   257     int retVal(NmNotFoundError);
   279     int retVal(NmNotFoundError);
   258     NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId);
   280     NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId);
   259     if (instance) {
   281     if (instance) {
   260         retVal =
   282         retVal =
   261             instance->contentToMessagePart(mailboxId, folderId, messageId, messagePart);
   283             instance->contentToMessagePart(mailboxId, folderId, messageId, messagePart);
   268 */
   290 */
   269 NmId NmDataManager::getStandardFolderId(
   291 NmId NmDataManager::getStandardFolderId(
   270         const NmId &mailboxId,
   292         const NmId &mailboxId,
   271         NmFolderType folderType )
   293         NmFolderType folderType )
   272 {
   294 {
       
   295     NM_FUNCTION;
       
   296     
   273     NmId folderId;
   297     NmId folderId;
   274     NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId);
   298     NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId);
   275     if (instance) {
   299     if (instance) {
   276         folderId =
   300         folderId =
   277             instance->getStandardFolderId(mailboxId, folderType);
   301             instance->getStandardFolderId(mailboxId, folderType);
   289 
   313 
   290     \return Folder type
   314     \return Folder type
   291 */
   315 */
   292 NmFolderType NmDataManager::folderTypeById(NmId mailboxId, NmId folderId)
   316 NmFolderType NmDataManager::folderTypeById(NmId mailboxId, NmId folderId)
   293 {
   317 {
       
   318     NM_FUNCTION;
       
   319     
   294     NmFolderType folderType(NmFolderOther);
   320     NmFolderType folderType(NmFolderOther);
   295     if (getStandardFolderId(mailboxId,NmFolderInbox)==folderId){
   321     if (getStandardFolderId(mailboxId,NmFolderInbox)==folderId){
   296         folderType=NmFolderInbox;
   322         folderType=NmFolderInbox;
   297     }
   323     }
   298     else if (getStandardFolderId(mailboxId,NmFolderOutbox)==folderId){
   324     else if (getStandardFolderId(mailboxId,NmFolderOutbox)==folderId){