1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtOrganizer module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#ifndef QCONTACTMANAGER_P_H
35#define QCONTACTMANAGER_P_H
36
37//
38// W A R N I N G
39// -------------
40//
41// This file is not part of the Qt API. It exists purely as an
42// implementation detail. This header file may change from version to
43// version without notice, or even be removed.
44//
45// We mean it.
46//
47
48#include <QtCore/qhash.h>
49#include <QtCore/qlist.h>
50#include <QtCore/qmap.h>
51#include <QtCore/qstringlist.h>
52
53#include <QtOrganizer/qorganizermanager.h>
54#include <QtOrganizer/qorganizermanagerengine.h>
55
56QT_BEGIN_NAMESPACE_ORGANIZER
57
58class QOrganizerItemObserver;
59class QOrganizerManagerEngineFactory;
60
61class QOrganizerManagerData
62{
63public:
64 QOrganizerManagerData()
65 : m_engine(0), m_lastError(QOrganizerManager::NoError)
66 {
67 }
68
69 ~QOrganizerManagerData()
70 {
71 delete m_engine;
72 }
73
74 // helpers
75 static bool parseUri(const QString &uriString, QString *managerName, QMap<QString, QString> *params, bool strict = true);
76 static QString buildUri(const QString &managerName, const QMap<QString, QString> &params);
77
78 static bool parseIdData(const QByteArray &idData, QString *managerName, QMap<QString, QString> *params, QString *managerUri = 0, QByteArray *localId = 0);
79
80 static QByteArray buildIdData(const QString &managerUri, const QByteArray &localId = QByteArray());
81 static QByteArray buildIdData(const QString &managerName, const QMap<QString, QString> &params, const QByteArray &localId = QByteArray());
82
83 static QString cachedUri(const QString &managerUri);
84
85 void createEngine(const QString &managerName, const QMap<QString, QString> &parameters);
86 static QOrganizerManagerData *get(const QOrganizerManager *manager);
87 static QOrganizerManagerEngine *engine(const QOrganizerManager *manager);
88
89 QOrganizerManagerEngine *m_engine;
90 QOrganizerManager::Error m_lastError;
91 QMap<int, QOrganizerManager::Error> m_lastErrorMap;
92
93 // manager plugins
94 static QHash<QString, QOrganizerManagerEngineFactory *> m_engines;
95 static bool m_discovered;
96 static bool m_discoveredStatic;
97 static QStringList m_pluginPaths;
98 static void loadFactories();
99 static void loadStaticFactories();
100
101 // observer stuff
102 void registerObserver(QOrganizerItemObserver *observer);
103 void unregisterObserver(QOrganizerItemObserver *observer);
104 void _q_itemsUpdated(const QList<QOrganizerItemId> &ids, const QList<QOrganizerItemDetail::DetailType> &typesChanged);
105 void _q_itemsDeleted(const QList<QOrganizerItemId> &ids);
106 QMultiHash<QOrganizerItemId, QOrganizerItemObserver *> m_observerForItem;
107
108 // helpers
109 static QOrganizerManagerData *managerData(const QOrganizerManager *m) { return m->d; }
110};
111
112/*!
113 \internal
114
115 Helper to hold the error state of a synchronous operation - when destructed, updates the
116 manager's last error variables to the result of this operation. This means that during
117 callbacks the error state can't be modified behind the engines back. and it's more conceptually
118 correct.
119 */
120class QOrganizerManagerSyncOpErrorHolder
121{
122public:
123 QOrganizerManagerSyncOpErrorHolder(const QOrganizerManager *m, QMap<int, QOrganizerManager::Error> *pUserError = 0)
124 : error(QOrganizerManager::NoError), data(QOrganizerManagerData::managerData(m)), userError(pUserError)
125 {
126 }
127
128 ~QOrganizerManagerSyncOpErrorHolder()
129 {
130 data->m_lastError = error;
131 data->m_lastErrorMap = errorMap;
132 if (userError)
133 *userError = errorMap;
134 }
135
136 QOrganizerManager::Error error;
137 QOrganizerManagerData *data;
138 QMap<int, QOrganizerManager::Error> errorMap;
139 QMap<int, QOrganizerManager::Error> *userError;
140};
141
142QT_END_NAMESPACE_ORGANIZER
143
144#endif // QCONTACTMANAGER_P_H
145

source code of qtpim/src/organizer/qorganizermanager_p.h