<commit_before>/****************************************************************************
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** If you have questions regarding the use of this file, please
** contact Nokia at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QMESSAGEWINHELPERPRIVATE_H
#define QMESSAGEWINHELPERPRIVATE_H
#include <QHash>
#include <QPair>
#include <QSharedPointer>
#include <QString>
#include <QByteArray>
#include <MAPIUtil.h>
#include <qmessagestore.h>

typedef QByteArray MapiRecordKey;

class MapiEntryId : public QByteArray
{
public:
    MapiEntryId():QByteArray(){}
    MapiEntryId(LPENTRYID mapiEntryId, ULONG entryIdLength)
    :
    QByteArray(reinterpret_cast<const char*>(mapiEntryId),entryIdLength){}

    MapiEntryId(LPBYTE mapiEntryId, ULONG entryIdLength)
    :
    QByteArray(reinterpret_cast<const char*>(mapiEntryId),entryIdLength){}
};

class MapiFolder;
class MapiStore;
class MapiSession;
typedef QSharedPointer<MapiFolder> MapiFolderPtr;
typedef QSharedPointer<MapiStore> MapiStorePtr;
typedef QSharedPointer<MapiSession> MapiSessionPtr;

namespace WinHelpers {

typedef QPair<QMessageId, ULONG> AttachmentLocator;
QMessageContentContainer fromLocator(const WinHelpers::AttachmentLocator &l);

}

QString QStringFromLpctstr(LPCTSTR lpszValue);

class MapiFolder {
public:

    enum CommonFolder { Drafts, Tasks, Notes, Journal, Contacts, Appointments };

    static MapiFolderPtr createFolder(QMessageStore::ErrorCode *lastError, IMAPIFolder *folder, const MapiRecordKey &recordKey, const MapiRecordKey &storeKey, const QString &name, const MapiEntryId &entryId, bool hasSubFolders, uint messageCount);

    ~MapiFolder();

    MapiFolderPtr nextSubFolder(QMessageStore::ErrorCode *lastError, const MapiStore &store);
    QMessageIdList queryMessages(QMessageStore::ErrorCode *lastError, const QMessageFilterKey &key = QMessageFilterKey(), const QMessageSortKey &sortKey = QMessageSortKey(), uint limit = 0, uint offset = 0) const;
    MapiEntryId messageEntryId(QMessageStore::ErrorCode *lastError, const MapiRecordKey &messagekey);
#ifdef QMESSAGING_OPTIONAL_FOLDER
    QMessageFolderId id();
#endif

    bool isValid() { return _valid; }
    LPMAPIFOLDER folder() { return _folder; }
    MapiRecordKey recordKey() { return _key; }
    MapiRecordKey storeKey() { return _parentStoreKey; }
    QString name() const { return _name; }
    MapiEntryId entryId() { return _entryId; }
    bool hasSubFolders() { return _hasSubFolders; }
    uint messageCount() { return _messageCount; }

    MapiFolderPtr subFolder(QMessageStore::ErrorCode *lastError, CommonFolder commonFolder, const MapiStore &store);

    LPMAPITABLE subFolders(QMessageStore::ErrorCode *lastError) { if (!_init) findSubFolders(lastError); return _subFolders; }
    IMessage *createMessage(QMessageStore::ErrorCode* lastError);

    IMessage *openMessage(QMessageStore::ErrorCode *lastError, const MapiEntryId &entryId);

private:
    MapiFolder();
    MapiFolder(IMAPIFolder *folder, const MapiRecordKey &recordKey, const MapiRecordKey &storeKey, const QString &name, const MapiEntryId &entryId, bool hasSubFolders, uint messageCount);

    void findSubFolders(QMessageStore::ErrorCode *lastError);

    friend class MapiStore;

    bool _valid;
    LPMAPIFOLDER _folder;
    MapiRecordKey _key;
    MapiRecordKey _parentStoreKey;
    QString _name;
    LPMAPITABLE _subFolders;
    uint _itemCount;
    MapiEntryId _entryId;
    bool _hasSubFolders;
    uint _messageCount;
    bool _init;

    enum columnOrder { entryIdColumn = 0, nameColumn, recordKeyColumn, countColumn, subFoldersColumn };
};

class MapiStore {
public:
    static MapiStorePtr createStore(QMessageStore::ErrorCode *lastError, LPMDB store, const MapiRecordKey &key, const MapiEntryId &entryId, const QString &name);

    ~MapiStore();

    bool isValid();
    MapiFolderPtr rootFolder(QMessageStore::ErrorCode *lastError);
    MapiFolderPtr receiveFolder(QMessageStore::ErrorCode *lastError);
    MapiFolderPtr findFolder(QMessageStore::ErrorCode *lastError, const MapiRecordKey &key);
#ifdef QMESSAGING_OPTIONAL_FOLDER
    QMessageFolderIdList folderIds(QMessageStore::ErrorCode *lastError);
    QMessageFolder folderFromId(QMessageStore::ErrorCode *lastError, const QMessageFolderId &folderId);
#endif
    QMessageAccountId id();
    MapiEntryId entryId() const { return _entryId; }
    QString name() const { return _name; }

    IMessage *openMessage(QMessageStore::ErrorCode *lastError, const MapiEntryId &entryId);

    LPMDB store() { return _store; }

    MapiFolderPtr openFolder(QMessageStore::ErrorCode *lastError, const MapiEntryId& id) const;

private:
    MapiStore();
    MapiStore(LPMDB store, const MapiRecordKey &key, const MapiEntryId &entryId, const QString &name);

    IMAPIFolder *openMapiFolder(QMessageStore::ErrorCode *lastError, const MapiEntryId &entryId) const;

    bool _valid;
    LPMDB _store;
    MapiRecordKey _key;
    MapiEntryId _entryId;
    QString _name;

    static QHash<MapiEntryId, QWeakPointer<MapiFolder> > _folderMap;
};

class MapiSession {
public:
    static MapiSessionPtr createSession(QMessageStore::ErrorCode *lastError, bool mapiInitialized);

    ~MapiSession();

    bool isValid();

    MapiStorePtr findStore(QMessageStore::ErrorCode *lastError, const QMessageAccountId &id = QMessageAccountId()) const;
    MapiStorePtr defaultStore(QMessageStore::ErrorCode *lastError) { return findStore(lastError); }
    QList<MapiStorePtr> allStores(QMessageStore::ErrorCode *lastError) const;

    QMessage message(QMessageStore::ErrorCode *lastError, const QMessageId& id) const;
    QByteArray attachmentData(QMessageStore::ErrorCode *lastError, const QMessageId& id, ULONG number) const;
    bool showForm(LPMESSAGE message, LPMAPIFOLDER folder, LPMDB store);

    MapiStorePtr openStore(QMessageStore::ErrorCode *lastError, const MapiEntryId& id) const;<commit_msg>defaultStore should be const.<commit_after>/****************************************************************************
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** If you have questions regarding the use of this file, please
** contact Nokia at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QMESSAGEWINHELPERPRIVATE_H
#define QMESSAGEWINHELPERPRIVATE_H
#include <QHash>
#include <QPair>
#include <QSharedPointer>
#include <QString>
#include <QByteArray>
#include <MAPIUtil.h>
#include <qmessagestore.h>

typedef QByteArray MapiRecordKey;

class MapiEntryId : public QByteArray
{
public:
    MapiEntryId():QByteArray(){}
    MapiEntryId(LPENTRYID mapiEntryId, ULONG entryIdLength)
    :
    QByteArray(reinterpret_cast<const char*>(mapiEntryId),entryIdLength){}

    MapiEntryId(LPBYTE mapiEntryId, ULONG entryIdLength)
    :
    QByteArray(reinterpret_cast<const char*>(mapiEntryId),entryIdLength){}
};

class MapiFolder;
class MapiStore;
class MapiSession;
typedef QSharedPointer<MapiFolder> MapiFolderPtr;
typedef QSharedPointer<MapiStore> MapiStorePtr;
typedef QSharedPointer<MapiSession> MapiSessionPtr;

namespace WinHelpers {

typedef QPair<QMessageId, ULONG> AttachmentLocator;
QMessageContentContainer fromLocator(const WinHelpers::AttachmentLocator &l);

}

QString QStringFromLpctstr(LPCTSTR lpszValue);

class MapiFolder {
public:

    enum CommonFolder { Drafts, Tasks, Notes, Journal, Contacts, Appointments };

    static MapiFolderPtr createFolder(QMessageStore::ErrorCode *lastError, IMAPIFolder *folder, const MapiRecordKey &recordKey, const MapiRecordKey &storeKey, const QString &name, const MapiEntryId &entryId, bool hasSubFolders, uint messageCount);

    ~MapiFolder();

    MapiFolderPtr nextSubFolder(QMessageStore::ErrorCode *lastError, const MapiStore &store);
    QMessageIdList queryMessages(QMessageStore::ErrorCode *lastError, const QMessageFilterKey &key = QMessageFilterKey(), const QMessageSortKey &sortKey = QMessageSortKey(), uint limit = 0, uint offset = 0) const;
    MapiEntryId messageEntryId(QMessageStore::ErrorCode *lastError, const MapiRecordKey &messagekey);
#ifdef QMESSAGING_OPTIONAL_FOLDER
    QMessageFolderId id();
#endif

    bool isValid() { return _valid; }
    LPMAPIFOLDER folder() { return _folder; }
    MapiRecordKey recordKey() { return _key; }
    MapiRecordKey storeKey() { return _parentStoreKey; }
    QString name() const { return _name; }
    MapiEntryId entryId() { return _entryId; }
    bool hasSubFolders() { return _hasSubFolders; }
    uint messageCount() { return _messageCount; }

    MapiFolderPtr subFolder(QMessageStore::ErrorCode *lastError, CommonFolder commonFolder, const MapiStore &store);

    LPMAPITABLE subFolders(QMessageStore::ErrorCode *lastError) { if (!_init) findSubFolders(lastError); return _subFolders; }
    IMessage *createMessage(QMessageStore::ErrorCode* lastError);

    IMessage *openMessage(QMessageStore::ErrorCode *lastError, const MapiEntryId &entryId);

private:
    MapiFolder();
    MapiFolder(IMAPIFolder *folder, const MapiRecordKey &recordKey, const MapiRecordKey &storeKey, const QString &name, const MapiEntryId &entryId, bool hasSubFolders, uint messageCount);

    void findSubFolders(QMessageStore::ErrorCode *lastError);

    friend class MapiStore;

    bool _valid;
    LPMAPIFOLDER _folder;
    MapiRecordKey _key;
    MapiRecordKey _parentStoreKey;
    QString _name;
    LPMAPITABLE _subFolders;
    uint _itemCount;
    MapiEntryId _entryId;
    bool _hasSubFolders;
    uint _messageCount;
    bool _init;

    enum columnOrder { entryIdColumn = 0, nameColumn, recordKeyColumn, countColumn, subFoldersColumn };
};

class MapiStore {
public:
    static MapiStorePtr createStore(QMessageStore::ErrorCode *lastError, LPMDB store, const MapiRecordKey &key, const MapiEntryId &entryId, const QString &name);

    ~MapiStore();

    bool isValid();
    MapiFolderPtr rootFolder(QMessageStore::ErrorCode *lastError);
    MapiFolderPtr receiveFolder(QMessageStore::ErrorCode *lastError);
    MapiFolderPtr findFolder(QMessageStore::ErrorCode *lastError, const MapiRecordKey &key);
#ifdef QMESSAGING_OPTIONAL_FOLDER
    QMessageFolderIdList folderIds(QMessageStore::ErrorCode *lastError);
    QMessageFolder folderFromId(QMessageStore::ErrorCode *lastError, const QMessageFolderId &folderId);
#endif
    QMessageAccountId id();
    MapiEntryId entryId() const { return _entryId; }
    QString name() const { return _name; }

    IMessage *openMessage(QMessageStore::ErrorCode *lastError, const MapiEntryId &entryId);

    LPMDB store() { return _store; }

    MapiFolderPtr openFolder(QMessageStore::ErrorCode *lastError, const MapiEntryId& id) const;

private:
    MapiStore();
    MapiStore(LPMDB store, const MapiRecordKey &key, const MapiEntryId &entryId, const QString &name);

    IMAPIFolder *openMapiFolder(QMessageStore::ErrorCode *lastError, const MapiEntryId &entryId) const;

    bool _valid;
    LPMDB _store;
    MapiRecordKey _key;
    MapiEntryId _entryId;
    QString _name;

    static QHash<MapiEntryId, QWeakPointer<MapiFolder> > _folderMap;
};

class MapiSession {
public:
    static MapiSessionPtr createSession(QMessageStore::ErrorCode *lastError, bool mapiInitialized);

    ~MapiSession();

    bool isValid();

    MapiStorePtr findStore(QMessageStore::ErrorCode *lastError, const QMessageAccountId &id = QMessageAccountId()) const;
    MapiStorePtr defaultStore(QMessageStore::ErrorCode *lastError) const { return findStore(lastError); }
    QList<MapiStorePtr> allStores(QMessageStore::ErrorCode *lastError) const;

    QMessage message(QMessageStore::ErrorCode *lastError, const QMessageId& id) const;
    QByteArray attachmentData(QMessageStore::ErrorCode *lastError, const QMessageId& id, ULONG number) const;
    bool showForm(LPMESSAGE message, LPMAPIFOLDER folder, LPMDB store);

    MapiStorePtr openStore(QMessageStore::ErrorCode *lastError, const MapiEntryId& id) const;
{'fraction_non_alphanumeric': 0.10790102628989175, 'fraction_numerical': 0.0026711654716715873, 'mean_word_length': 5.800669216061186, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4004762', 'n_tokens_mistral': 4288, 'n_tokens_neox': 4196, 'n_words': 1177}