| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 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 tools applications of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 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 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #include <QAxObject> | 
|---|
| 43 | #include <QFile> | 
|---|
| 44 | #include <QTextStream> | 
|---|
| 45 | #include <qt_windows.h> | 
|---|
| 46 |  | 
|---|
| 47 | QT_USE_NAMESPACE | 
|---|
| 48 |  | 
|---|
| 49 | int main(int argc, char **argv) | 
|---|
| 50 | { | 
|---|
| 51 | CoInitialize(0); | 
|---|
| 52 |  | 
|---|
| 53 | enum State { | 
|---|
| 54 | Default = 0, | 
|---|
| 55 | OutOption | 
|---|
| 56 | } state; | 
|---|
| 57 | state = Default; | 
|---|
| 58 |  | 
|---|
| 59 | QByteArray outname; | 
|---|
| 60 | QByteArray object; | 
|---|
| 61 |  | 
|---|
| 62 | for (int a = 1; a < argc; ++a) { | 
|---|
| 63 | QByteArray arg(argv[a]); | 
|---|
| 64 | const char first = arg[0]; | 
|---|
| 65 | switch(state) { | 
|---|
| 66 | case Default: | 
|---|
| 67 | if (first == '-' || first == '/') { | 
|---|
| 68 | arg = arg.mid(1); | 
|---|
| 69 | arg.toLower(); | 
|---|
| 70 | if (arg == "o") | 
|---|
| 71 | state = OutOption; | 
|---|
| 72 | else if (arg == "v") { | 
|---|
| 73 | qWarning("dumpdoc: Version 1.0"); | 
|---|
| 74 | return 0; | 
|---|
| 75 | } else if (arg == "h") { | 
|---|
| 76 | qWarning("dumpdoc Usage:\n\tdumpdoc object [-o <file>]" | 
|---|
| 77 | "              \n\tobject   : object[/subobject]*" | 
|---|
| 78 | "              \n\tsubobject: property\n" | 
|---|
| 79 | "      \nexample:\n\tdumpdoc Outlook.Application/Session/CurrentUser -o outlook.html"); | 
|---|
| 80 | return 0; | 
|---|
| 81 | } | 
|---|
| 82 | } else { | 
|---|
| 83 | object = arg; | 
|---|
| 84 | } | 
|---|
| 85 | break; | 
|---|
| 86 | case OutOption: | 
|---|
| 87 | outname = arg; | 
|---|
| 88 | state = Default; | 
|---|
| 89 | break; | 
|---|
| 90 |  | 
|---|
| 91 | default: | 
|---|
| 92 | break; | 
|---|
| 93 | } | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 | if (object.isEmpty()) { | 
|---|
| 97 | qWarning("dumpdoc: No object name provided.\n" | 
|---|
| 98 | "         Use -h for help."); | 
|---|
| 99 | return -1; | 
|---|
| 100 | } | 
|---|
| 101 | QFile outfile; | 
|---|
| 102 | if (!outname.isEmpty()) { | 
|---|
| 103 | outfile.setFileName(QString::fromLatin1(outname.constData())); | 
|---|
| 104 | if (!outfile.open(QIODevice::WriteOnly | QIODevice::Text)) { | 
|---|
| 105 | qWarning("dumpdoc: Could not open output file '%s'", outname.data()); | 
|---|
| 106 | } | 
|---|
| 107 | } else { | 
|---|
| 108 | outfile.open(stdout, QIODevice::WriteOnly); | 
|---|
| 109 | } | 
|---|
| 110 | QTextStream out(&outfile); | 
|---|
| 111 |  | 
|---|
| 112 | QByteArray subobject = object; | 
|---|
| 113 | int index = subobject.indexOf('/'); | 
|---|
| 114 | if (index != -1) | 
|---|
| 115 | subobject = subobject.left(index); | 
|---|
| 116 |  | 
|---|
| 117 | QAxObject topobject(QString::fromLatin1(subobject.constData())); | 
|---|
| 118 |  | 
|---|
| 119 | if (topobject.isNull()) { | 
|---|
| 120 | qWarning("dumpdoc: Could not instantiate COM object '%s'", subobject.data()); | 
|---|
| 121 | return -2; | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | QAxObject *axobject = &topobject; | 
|---|
| 125 | while (index != -1 && axobject) { | 
|---|
| 126 | index++; | 
|---|
| 127 | subobject = object.mid(index); | 
|---|
| 128 | if (object.indexOf('/', index) != -1) { | 
|---|
| 129 | int oldindex = index; | 
|---|
| 130 | index = object.indexOf('/', index); | 
|---|
| 131 | subobject = object.mid(oldindex, index-oldindex); | 
|---|
| 132 | } else { | 
|---|
| 133 | index = -1; | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | axobject = axobject->querySubObject(subobject); | 
|---|
| 137 | } | 
|---|
| 138 | if (!axobject || axobject->isNull()) { | 
|---|
| 139 | qWarning("dumpdoc: Subobject '%s' does not exist in '%s'", subobject.data(), object.data()); | 
|---|
| 140 | return -3; | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | QString docu = axobject->generateDocumentation(); | 
|---|
| 144 | out << docu; | 
|---|
| 145 | return 0; | 
|---|
| 146 | } | 
|---|