|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qdeclarativeservice.h" |
|
43 |
|
44 QServiceWrapper::QServiceWrapper() |
|
45 : serviceInstance(0) |
|
46 { |
|
47 serviceManager = new QServiceManager(); |
|
48 } |
|
49 |
|
50 QServiceWrapper::~QServiceWrapper() |
|
51 { |
|
52 delete serviceInstance; |
|
53 } |
|
54 |
|
55 bool QServiceWrapper::isValid() const |
|
56 { |
|
57 return m_descriptor.isValid(); |
|
58 } |
|
59 |
|
60 void QServiceWrapper::setInterfaceDesc(const QServiceInterfaceDescriptor &desc) |
|
61 { |
|
62 if (desc == m_descriptor) |
|
63 return; |
|
64 |
|
65 m_descriptor = desc; |
|
66 |
|
67 if (serviceInstance) |
|
68 delete serviceInstance; |
|
69 |
|
70 serviceInstance = 0; |
|
71 } |
|
72 |
|
73 QServiceInterfaceDescriptor QServiceWrapper::interfaceDesc() const |
|
74 { |
|
75 return m_descriptor; |
|
76 } |
|
77 |
|
78 void QServiceWrapper::setInterfaceName(const QString &interface) |
|
79 { |
|
80 m_descriptor = serviceManager->interfaceDefault(interface); |
|
81 |
|
82 if (!isValid()) |
|
83 qWarning() << "WARNING: No default service found for interface name: " << interface; |
|
84 } |
|
85 |
|
86 QString QServiceWrapper::interfaceName() const |
|
87 { |
|
88 if (isValid()) |
|
89 return m_descriptor.interfaceName(); |
|
90 else |
|
91 return "No Interface"; |
|
92 } |
|
93 |
|
94 QString QServiceWrapper::serviceName() const |
|
95 { |
|
96 if (isValid()) |
|
97 return m_descriptor.serviceName(); |
|
98 else |
|
99 return "No Service"; |
|
100 } |
|
101 |
|
102 QString QServiceWrapper::versionNumber() const |
|
103 { |
|
104 if (isValid()) |
|
105 return (QString::number(m_descriptor.majorVersion())+"."+QString::number(m_descriptor.minorVersion())); |
|
106 else |
|
107 return "0.0"; |
|
108 } |
|
109 |
|
110 QObject* QServiceWrapper::serviceObject() |
|
111 { |
|
112 if (serviceInstance) { |
|
113 return serviceInstance; |
|
114 } |
|
115 |
|
116 if (isValid()) { |
|
117 QServiceManager manager; |
|
118 serviceInstance = manager.loadInterface(m_descriptor); |
|
119 |
|
120 return serviceInstance; |
|
121 } else { |
|
122 return 0; |
|
123 } |
|
124 } |
|
125 |
|
126 QServiceListWrapper::QServiceListWrapper() |
|
127 { |
|
128 serviceManager = new QServiceManager(); |
|
129 } |
|
130 |
|
131 QServiceListWrapper::~QServiceListWrapper() |
|
132 { |
|
133 } |
|
134 |
|
135 void QServiceListWrapper::setInterfaceName(const QString &interface) |
|
136 { |
|
137 m_interface = interface; |
|
138 |
|
139 // ![0] |
|
140 QServiceWrapper *service; |
|
141 QServiceFilter filter(m_interface, m_version); |
|
142 QList<QServiceInterfaceDescriptor> list = serviceManager->findInterfaces(filter); |
|
143 for (int i = 0; i < list.size(); i++) { |
|
144 service = new QServiceWrapper(); |
|
145 service->setInterfaceDesc(list.at(i)); |
|
146 m_services.append(service); |
|
147 } |
|
148 // ![0] |
|
149 } |
|
150 |
|
151 QString QServiceListWrapper::interfaceName() const |
|
152 { |
|
153 return m_interface; |
|
154 } |
|
155 |
|
156 void QServiceListWrapper::setMinVersion(const QString &version) |
|
157 { |
|
158 m_version = version; |
|
159 } |
|
160 |
|
161 QString QServiceListWrapper::minVersion() const |
|
162 { |
|
163 return m_version; |
|
164 } |
|
165 |
|
166 QDeclarativeListProperty<QServiceWrapper> QServiceListWrapper::services() |
|
167 { |
|
168 return QDeclarativeListProperty<QServiceWrapper>(this, m_services); |
|
169 } |