void MessageFolder::openMailbox() { if (QMailStore* store = QMailStore::instance()) { if (!mFolder.id().isValid()) { QMailFolderKey key(QMailFolderKey::Name,mailbox()); key &= QMailFolderKey(QMailFolderKey::ParentId,QMailFolderId()); QMailFolderIdList folderIdList = QMailStore::instance()->queryFolders(key); if(folderIdList.isEmpty()) { // create folder QMailFolder newFolder(mailbox()); if(!QMailStore::instance()->addFolder(&newFolder)) qWarning() << "Failed to add folder " << mailbox(); mFolder = newFolder; } else { // load folder QMailFolderId folderId = folderIdList.first(); mFolder = QMailFolder(folderId); } //set the folder key mParentFolderKey = QMailMessageKey(QMailMessageKey::ParentFolderId,mFolder.id()); } // notify when our content is reported to have changed connect(store, SIGNAL(folderContentsModified(QMailFolderIdList)), this, SLOT(folderContentsModified(QMailFolderIdList))); } }
QVariant FolderListModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() > m_folderList.count()) return QVariant(); const FolderItem *item = static_cast<const FolderItem *>(index.internalPointer()); Q_ASSERT(item); QMailFolder folder(item->folderId); switch (role) { case FolderName: { if (item->folderId == QMailFolder::LocalStorageFolderId) { return localFolderName(item->folderType); } else { return folder.displayName(); } } case FolderId: return item->folderId.toULongLong(); case FolderUnreadCount: { return item->unreadCount; } case FolderServerCount: return (folder.serverCount()); case FolderNestingLevel: { QMailFolder tempFolder = folder; int level = 0; while (tempFolder.parentFolderId().isValid()) { tempFolder = QMailFolder(tempFolder.parentFolderId()); level++; } return level; } case FolderMessageKey: return item->messageKey; case FolderType: return item->folderType; default: return QVariant(); } }