Qt 4.8
qaxfactory.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the ActiveQt framework of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
19 ** distribution.
20 ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21 ** of its contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
23 **
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 #include "qaxfactory.h"
42 
43 #ifndef QT_NO_WIN_ACTIVEQT
44 
45 #include <qfile.h>
46 #include <qfileinfo.h>
47 #include <qmetaobject.h>
48 #include <qsettings.h>
49 #include <qwidget.h>
50 #include <qt_windows.h>
51 
53 
54 extern wchar_t qAxModuleFilename[MAX_PATH];
55 
103 QAxFactory::QAxFactory(const QUuid &libid, const QUuid &appid)
104 : typelib(libid), app(appid)
105 {
106 }
107 
112 {
113 }
114 
125 {
126  return typelib;
127 }
128 
139 {
140  return app;
141 }
142 
181 // implementation in qaxserverbase.cpp
182 
192 {
193  const QMetaObject *mo = metaObject(key);
194  if (!mo)
195  return QUuid();
196  QString id = QString::fromLatin1(mo->classInfo(mo->indexOfClassInfo("ClassID")).value());
197 
198  return QUuid(id);
199 }
200 
210 {
211  const QMetaObject *mo = metaObject(key);
212  if (!mo)
213  return QUuid();
214  QString id = QString::fromLatin1(mo->classInfo(mo->indexOfClassInfo("InterfaceID")).value());
215 
216  return QUuid(id);
217 }
218 
229 {
230  const QMetaObject *mo = metaObject(key);
231  if (!mo)
232  return QUuid();
233  QString id = QString::fromLatin1(mo->classInfo(mo->indexOfClassInfo("EventsID")).value());
234 
235  return QUuid(id);
236 }
237 
252 void QAxFactory::registerClass(const QString &key, QSettings *settings) const
253 {
254  Q_UNUSED(key);
255  Q_UNUSED(settings)
256 }
257 
266 void QAxFactory::unregisterClass(const QString &key, QSettings *settings) const
267 {
268  Q_UNUSED(key);
269  Q_UNUSED(settings)
270 }
271 
282 bool QAxFactory::validateLicenseKey(const QString &key, const QString &licenseKey) const
283 {
284  const QMetaObject *mo = metaObject(key);
285  if (!mo)
286  return true;
287 
288  QString classKey = QString::fromLatin1(mo->classInfo(mo->indexOfClassInfo("LicenseKey")).value());
289  if (classKey.isEmpty())
290  return true;
291 
292  if (licenseKey.isEmpty()) {
294  int lastDot = licFile.lastIndexOf(QLatin1Char('.'));
295  licFile = licFile.left(lastDot) + QLatin1String(".lic");
296  if (QFile::exists(licFile))
297  return true;
298  return false;
299  }
300  return licenseKey == classKey;
301 }
302 
318 {
319  const QMetaObject *mo = metaObject(key);
320  if (!mo)
321  return QString();
322  return QString::fromLatin1(mo->classInfo(mo->indexOfClassInfo("ToSuperClass")).value());
323 }
324 
331 {
332  return false;
333 }
334 
354 {
355  const QMetaObject *mo = metaObject(key);
356  if (!mo)
357  return false;
358  return QString::fromLatin1(mo->classInfo(mo->indexOfClassInfo("StockEvents")).value()) == QLatin1String("yes");
359 }
360 
361 
362 extern bool qAxIsServer;
363 
372 {
373  return qAxIsServer;
374 }
375 
376 extern wchar_t qAxModuleFilename[MAX_PATH];
377 
387 {
389 }
390 
399 {
401 }
402 
411 {
412  return false;
413 }
414 
472 class ActiveObject : public QObject
473 {
474 public:
476  ~ActiveObject();
477 
478  IDispatch *wrapper;
479  DWORD cookie;
480 };
481 
483 : QObject(parent), wrapper(0), cookie(0)
484 {
485  QLatin1String key(parent->metaObject()->className());
486 
487  factory->createObjectWrapper(parent, &wrapper);
488  if (wrapper)
489  RegisterActiveObject(wrapper, QUuid(factory->classID(key)), ACTIVEOBJECT_STRONG, &cookie);
490 }
491 
493 {
494  if (cookie)
495  RevokeActiveObject(cookie, 0);
496  if (wrapper)
497  wrapper->Release();
498 }
499 
513 {
514  if (qstricmp(object->metaObject()->classInfo(object->metaObject()->indexOfClassInfo("RegisterObject")).value(), "yes"))
515  return false;
516 
518  return false;
519 
520  ActiveObject *active = new ActiveObject(object, qAxFactory());
521  if (!active->wrapper || !active->cookie) {
522  delete active;
523  return false;
524  }
525  return true;
526 }
527 
631 #endif // QT_NO_WIN_ACTIVEQT
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
virtual QUuid typeLibID() const
Reimplement this function to return the ActiveX server&#39;s type library identifier. ...
Definition: qaxfactory.cpp:124
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QAxFactory * qAxFactory()
Definition: qaxserver.cpp:81
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QMetaClassInfo classInfo(int index) const
Returns the meta-data for the item of class information with the given index.
The QAxFactory class defines a factory for the creation of COM components.
Definition: qaxfactory.h:64
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QString serverDirPath()
Returns the directory that contains the server binary.
Definition: qaxfactory.cpp:386
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
bool qAxIsServer
Definition: qaxserver.cpp:64
virtual QString exposeToSuperClass(const QString &key) const
Reimplement this function to return the name of the super class of key up to which methods and proper...
Definition: qaxfactory.cpp:317
static QString serverFilePath()
Returns the file path of the server binary.
Definition: qaxfactory.cpp:398
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QUuid app
Definition: qaxfactory.h:108
virtual ~QAxFactory()
Destroys the QAxFactory object.
Definition: qaxfactory.cpp:111
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
virtual bool hasStockEvents(const QString &key) const
Reimplement this function to return true if the ActiveX control key should support the standard Activ...
Definition: qaxfactory.cpp:353
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
wchar_t qAxModuleFilename[MAX_PATH]
Definition: qaxfactory.cpp:376
virtual QUuid appID() const
Reimplement this function to return the ActiveX server&#39;s application identifier.
Definition: qaxfactory.cpp:138
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
virtual QUuid interfaceID(const QString &key) const
Reimplement this function to return the interface identifier for each key returned by the featureList...
Definition: qaxfactory.cpp:209
virtual bool createObjectWrapper(QObject *object, IDispatch **wrapper)
Reimplement this function to provide the COM object for object in wrapper.
static bool registerActiveObject(QObject *object)
Registers the QObject object with COM as a running object, and returns true if the registration succe...
Definition: qaxfactory.cpp:512
virtual bool stayTopLevel(const QString &key) const
Reimplement this function to return true if the ActiveX control key should be a top level window...
Definition: qaxfactory.cpp:330
virtual QUuid eventsID(const QString &key) const
Reimplement this function to return the identifier of the event interface for each key returned by th...
Definition: qaxfactory.cpp:228
QAxFactory(const QUuid &libId, const QUuid &appId)
Constructs a QAxFactory object that returns libid and appid in the implementation of the respective i...
Definition: qaxfactory.cpp:103
virtual bool isService() const
Reimplement this function to return true if the server is running as a persistent service (e...
Definition: qaxfactory.cpp:410
static bool isServer()
Returns true if the application has been started (by COM) as an ActiveX server, otherwise returns fal...
Definition: qaxfactory.cpp:371
virtual void unregisterClass(const QString &key, QSettings *) const
Unregisters any additional values for the class key from the system registry using the settings objec...
Definition: qaxfactory.cpp:266
virtual bool validateLicenseKey(const QString &key, const QString &licenseKey) const
Reimplement this function to return true if licenseKey is a valid license for the class key...
Definition: qaxfactory.cpp:282
ActiveObject(QObject *parent, QAxFactory *factory)
Definition: qaxfactory.cpp:482
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
IDispatch * wrapper
Definition: qaxfactory.cpp:478
int key
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
Q_CORE_EXPORT int qstricmp(const char *, const char *)
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
int indexOfClassInfo(const char *name) const
Finds class information item name and returns its index; otherwise returns -1.
QUuid typelib
Definition: qaxfactory.h:107
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QString absolutePath() const
Returns a file&#39;s path absolute path.
Definition: qfileinfo.cpp:577
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67
virtual QUuid classID(const QString &key) const
Reimplement this function to return the class identifier for each key returned by the featureList() i...
Definition: qaxfactory.cpp:191
virtual void registerClass(const QString &key, QSettings *) const
Registers additional values for the class key in the system registry using the settings object...
Definition: qaxfactory.cpp:252