~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/contacts/qcontactactionmanager_p.cpp

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtContacts module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
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 Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/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 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
 
 
43
#include "qcontactactionmanager_p.h"
 
44
 
 
45
#include "qcontactaction.h"
 
46
#include "qcontactactiondescriptor.h"
 
47
#include "qcontactactionfactory.h"
 
48
 
 
49
#include "qcontactmanager_p.h"
 
50
 
 
51
#include <QMutexLocker>
 
52
#include <QDebug>
 
53
 
 
54
QT_BEGIN_NAMESPACE_CONTACTS
 
55
 
 
56
Q_GLOBAL_STATIC(QContactActionManager, contactActionManagerInstance)
 
57
 
 
58
/*!
 
59
  \internal
 
60
  \class QContactActionManager
 
61
  This class uses a plugin to delegate discovery of actions (to avoid a dependency on SFW for QtContacts)
 
62
  It is an implementation detail of QContactAction.
 
63
 */
 
64
 
 
65
QContactActionManager* QContactActionManager::instance()
 
66
{
 
67
    return contactActionManagerInstance();
 
68
}
 
69
 
 
70
QContactActionManager::QContactActionManager()
 
71
    : QObject(),
 
72
    m_plugin(0)
 
73
{
 
74
}
 
75
 
 
76
void QContactActionManager::init()
 
77
{
 
78
    // We ask the qcontactmanager engine loading code, since it has to enumerate things anyway
 
79
    QContactManagerData::loadFactoriesMetadata();
 
80
    m_plugin = QContactManagerData::m_actionManagers.value(0);
 
81
}
 
82
 
 
83
QContactActionManager::~QContactActionManager()
 
84
{
 
85
    // Allow our subordinates to do their thing when they want,
 
86
    // since we just cache stuff
 
87
}
 
88
 
 
89
QList<QContactActionDescriptor> QContactActionManager::availableActions(const QContact &contact)
 
90
{
 
91
    QMutexLocker locker(&m_instanceMutex);
 
92
    init();
 
93
 
 
94
    QList<QContactActionDescriptor> ret;
 
95
    if (m_plugin) {
 
96
        QHash<QContactActionDescriptor, QContactActionFactory*> hash = m_plugin->actionFactoryHash();
 
97
        QHash<QContactActionDescriptor, QContactActionFactory*>::const_iterator it;
 
98
        for (it = hash.constBegin(); it != hash.constEnd(); ++it) {
 
99
            QContactActionFactory* curr = it.value();
 
100
            if (curr && curr->supportsContact(contact, it.key())) {
 
101
                ret.append(it.key());
 
102
            }
 
103
        }
 
104
    }
 
105
 
 
106
    return ret;
 
107
}
 
108
 
 
109
QList<QContactActionDescriptor> QContactActionManager::actionDescriptors(const QString& actionName)
 
110
{
 
111
    QMutexLocker locker(&m_instanceMutex);
 
112
    init();
 
113
 
 
114
    if (m_plugin) {
 
115
        if (actionName.isEmpty())
 
116
            return m_plugin->descriptorHash().values();
 
117
        return m_plugin->descriptorHash().values(actionName);
 
118
    }
 
119
    return QList<QContactActionDescriptor>();
 
120
}
 
121
 
 
122
/*! The caller takes ownership of the returned action pointer, and must delete it to avoid leaking memory. */
 
123
QContactAction* QContactActionManager::action(const QContactActionDescriptor& descriptor)
 
124
{
 
125
    QMutexLocker locker(&m_instanceMutex);
 
126
    init();
 
127
 
 
128
    if (m_plugin) {
 
129
        QContactActionFactory *factory = m_plugin->actionFactoryHash().value(descriptor);
 
130
        if (factory)
 
131
            return factory->create(descriptor);
 
132
    }
 
133
    return 0;
 
134
}
 
135
 
 
136
#include "moc_qcontactactionmanager_p.cpp"
 
137
 
 
138
QT_END_NAMESPACE_CONTACTS