1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
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 Nokia Corporation and its Subsidiary(-ies) nor
|
---|
21 | ** the names of its contributors may be used to endorse or promote
|
---|
22 | ** products derived from this software without specific prior written
|
---|
23 | ** permission.
|
---|
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 | ** $QT_END_LICENSE$
|
---|
37 | **
|
---|
38 | ****************************************************************************/
|
---|
39 |
|
---|
40 | #include "qaxselect.h"
|
---|
41 |
|
---|
42 | #ifndef QT_NO_WIN_ACTIVEQT
|
---|
43 |
|
---|
44 | #include <qt_windows.h>
|
---|
45 |
|
---|
46 | QT_BEGIN_NAMESPACE
|
---|
47 |
|
---|
48 | class ControlList : public QAbstractListModel
|
---|
49 | {
|
---|
50 | public:
|
---|
51 | ControlList(QObject *parent=0)
|
---|
52 | : QAbstractListModel(parent)
|
---|
53 | {
|
---|
54 | HKEY classes_key;
|
---|
55 | QT_WA_INLINE(
|
---|
56 | RegOpenKeyExW(HKEY_CLASSES_ROOT, L"CLSID", 0, KEY_READ, &classes_key),
|
---|
57 | RegOpenKeyExA(HKEY_CLASSES_ROOT, "CLSID", 0, KEY_READ, &classes_key));
|
---|
58 | if (!classes_key)
|
---|
59 | return;
|
---|
60 |
|
---|
61 | DWORD index = 0;
|
---|
62 | LONG result = 0;
|
---|
63 | TCHAR buffer[256];
|
---|
64 | DWORD szBuffer = sizeof(buffer);
|
---|
65 | FILETIME ft;
|
---|
66 | do {
|
---|
67 | result = QT_WA_INLINE(
|
---|
68 | RegEnumKeyExW(classes_key, index, (wchar_t*)&buffer, &szBuffer, 0, 0, 0, &ft),
|
---|
69 | RegEnumKeyExA(classes_key, index, (char*)&buffer, &szBuffer, 0, 0, 0, &ft));
|
---|
70 | szBuffer = sizeof(buffer);
|
---|
71 | if (result == ERROR_SUCCESS) {
|
---|
72 | HKEY sub_key;
|
---|
73 | QString clsid = QT_WA_INLINE(QString::fromUtf16((ushort*)buffer), QString::fromLocal8Bit((char*)buffer));
|
---|
74 | result = QT_WA_INLINE(
|
---|
75 | RegOpenKeyExW(classes_key, reinterpret_cast<const wchar_t *>(QString(clsid + "\\Control").utf16()), 0, KEY_READ, &sub_key),
|
---|
76 | RegOpenKeyA(classes_key, QString(clsid + QLatin1String("\\Control")).toLocal8Bit(), &sub_key));
|
---|
77 | if (result == ERROR_SUCCESS) {
|
---|
78 | RegCloseKey(sub_key);
|
---|
79 | QT_WA_INLINE(
|
---|
80 | RegistryQueryValueW(classes_key, buffer, (LPBYTE)buffer, &szBuffer),
|
---|
81 | RegQueryValueA(classes_key, (char*)buffer, (char*)buffer, (LONG*)&szBuffer));
|
---|
82 | QString name = QT_WA_INLINE(QString::fromUtf16((ushort*)buffer, szBuffer / sizeof(TCHAR)) , QString::fromLocal8Bit((char*)buffer, szBuffer));
|
---|
83 |
|
---|
84 | controls << name;
|
---|
85 | clsids.insert(name, clsid);
|
---|
86 | }
|
---|
87 | result = ERROR_SUCCESS;
|
---|
88 | }
|
---|
89 | szBuffer = sizeof(buffer);
|
---|
90 | ++index;
|
---|
91 | } while (result == ERROR_SUCCESS);
|
---|
92 | RegCloseKey(classes_key);
|
---|
93 | controls.sort();
|
---|
94 | }
|
---|
95 |
|
---|
96 | LONG RegistryQueryValueW(HKEY hKey, LPCWSTR lpSubKey, LPBYTE lpData, LPDWORD lpcbData)
|
---|
97 | {
|
---|
98 | LONG ret = ERROR_FILE_NOT_FOUND;
|
---|
99 | HKEY hSubKey = NULL;
|
---|
100 | RegOpenKeyExW(hKey, lpSubKey, 0, KEY_READ, &hSubKey);
|
---|
101 | if (hSubKey) {
|
---|
102 | ret = RegQueryValueExW(hSubKey, 0, 0, 0, lpData, lpcbData);
|
---|
103 | RegCloseKey(hSubKey);
|
---|
104 | }
|
---|
105 | return ret;
|
---|
106 | }
|
---|
107 |
|
---|
108 | int rowCount(const QModelIndex & = QModelIndex()) const { return controls.count(); }
|
---|
109 | QVariant data(const QModelIndex &index, int role) const;
|
---|
110 |
|
---|
111 | private:
|
---|
112 | QStringList controls;
|
---|
113 | QMap<QString, QString> clsids;
|
---|
114 | };
|
---|
115 |
|
---|
116 | QVariant ControlList::data(const QModelIndex &index, int role) const
|
---|
117 | {
|
---|
118 | if (!index.isValid())
|
---|
119 | return QVariant();
|
---|
120 |
|
---|
121 | if (role == Qt::DisplayRole)
|
---|
122 | return controls.at(index.row());
|
---|
123 | if (role == Qt::UserRole)
|
---|
124 | return clsids.value(controls.at(index.row()));
|
---|
125 |
|
---|
126 | return QVariant();
|
---|
127 | }
|
---|
128 |
|
---|
129 | QAxSelect::QAxSelect(QWidget *parent, Qt::WindowFlags f)
|
---|
130 | : QDialog(parent, f)
|
---|
131 | {
|
---|
132 | #ifndef QT_NO_CURSOR
|
---|
133 | QApplication::setOverrideCursor(Qt::WaitCursor);
|
---|
134 | #endif
|
---|
135 |
|
---|
136 | setupUi(this);
|
---|
137 | ActiveXList->setModel(new ControlList(this));
|
---|
138 | connect(ActiveXList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
---|
139 | this, SLOT(on_ActiveXList_clicked(QModelIndex)));
|
---|
140 | #ifndef QT_NO_CURSOR
|
---|
141 | QApplication::restoreOverrideCursor();
|
---|
142 | #endif
|
---|
143 | ActiveXList->setFocus();
|
---|
144 |
|
---|
145 | connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
|
---|
146 | connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
|
---|
147 | }
|
---|
148 |
|
---|
149 | void QAxSelect::on_ActiveXList_clicked(const QModelIndex &index)
|
---|
150 | {
|
---|
151 | QVariant clsid = ActiveXList->model()->data(index, Qt::UserRole);
|
---|
152 | ActiveX->setText(clsid.toString());
|
---|
153 | }
|
---|
154 |
|
---|
155 | void QAxSelect::on_ActiveXList_doubleClicked(const QModelIndex &index)
|
---|
156 | {
|
---|
157 | QVariant clsid = ActiveXList->model()->data(index, Qt::UserRole);
|
---|
158 | ActiveX->setText(clsid.toString());
|
---|
159 |
|
---|
160 | accept();
|
---|
161 | }
|
---|
162 |
|
---|
163 | QT_END_NAMESPACE
|
---|
164 | #endif // QT_NO_WIN_ACTIVEQT
|
---|