|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 ActiveQt framework of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:BSD$ |
|
10 ** You may use this file under the terms of the BSD license as follows: |
|
11 ** |
|
12 ** "Redistribution and use in source and binary forms, with or without |
|
13 ** modification, are permitted provided that the following conditions are |
|
14 ** met: |
|
15 ** * Redistributions of source code must retain the above copyright |
|
16 ** notice, this list of conditions and the following disclaimer. |
|
17 ** * Redistributions in binary form must reproduce the above copyright |
|
18 ** notice, this list of conditions and the following disclaimer in |
|
19 ** the documentation and/or other materials provided with the |
|
20 ** distribution. |
|
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
|
22 ** the names of its contributors may be used to endorse or promote |
|
23 ** products derived from this software without specific prior written |
|
24 ** permission. |
|
25 ** |
|
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
|
37 ** $QT_END_LICENSE$ |
|
38 ** |
|
39 ****************************************************************************/ |
|
40 |
|
41 #include "qaxselect.h" |
|
42 |
|
43 #ifndef QT_NO_WIN_ACTIVEQT |
|
44 |
|
45 #include <qt_windows.h> |
|
46 |
|
47 QT_BEGIN_NAMESPACE |
|
48 |
|
49 class ControlList : public QAbstractListModel |
|
50 { |
|
51 public: |
|
52 ControlList(QObject *parent=0) |
|
53 : QAbstractListModel(parent) |
|
54 { |
|
55 HKEY classes_key; |
|
56 RegOpenKeyEx(HKEY_CLASSES_ROOT, L"CLSID", 0, KEY_READ, &classes_key); |
|
57 if (!classes_key) |
|
58 return; |
|
59 |
|
60 DWORD index = 0; |
|
61 LONG result = 0; |
|
62 wchar_t buffer[256]; |
|
63 DWORD szBuffer = sizeof(buffer) / sizeof(wchar_t); |
|
64 FILETIME ft; |
|
65 do { |
|
66 result = RegEnumKeyEx(classes_key, index, buffer, &szBuffer, 0, 0, 0, &ft); |
|
67 szBuffer = sizeof(buffer) / sizeof(wchar_t); |
|
68 if (result == ERROR_SUCCESS) { |
|
69 HKEY sub_key; |
|
70 QString clsid = QString::fromWCharArray(buffer); |
|
71 result = RegOpenKeyEx(classes_key, reinterpret_cast<const wchar_t *>(QString(clsid + "\\Control").utf16()), 0, KEY_READ, &sub_key); |
|
72 if (result == ERROR_SUCCESS) { |
|
73 RegCloseKey(sub_key); |
|
74 RegistryQueryValue(classes_key, buffer, (LPBYTE)buffer, &szBuffer); |
|
75 QString name = QString::fromWCharArray(buffer); |
|
76 |
|
77 controls << name; |
|
78 clsids.insert(name, clsid); |
|
79 } |
|
80 result = ERROR_SUCCESS; |
|
81 } |
|
82 szBuffer = sizeof(buffer) / sizeof(wchar_t); |
|
83 ++index; |
|
84 } while (result == ERROR_SUCCESS); |
|
85 RegCloseKey(classes_key); |
|
86 controls.sort(); |
|
87 } |
|
88 |
|
89 LONG RegistryQueryValue(HKEY hKey, LPCWSTR lpSubKey, LPBYTE lpData, LPDWORD lpcbData) |
|
90 { |
|
91 LONG ret = ERROR_FILE_NOT_FOUND; |
|
92 HKEY hSubKey = NULL; |
|
93 RegOpenKeyEx(hKey, lpSubKey, 0, KEY_READ, &hSubKey); |
|
94 if (hSubKey) { |
|
95 ret = RegQueryValueEx(hSubKey, 0, 0, 0, lpData, lpcbData); |
|
96 RegCloseKey(hSubKey); |
|
97 } |
|
98 return ret; |
|
99 } |
|
100 |
|
101 int rowCount(const QModelIndex & = QModelIndex()) const { return controls.count(); } |
|
102 QVariant data(const QModelIndex &index, int role) const; |
|
103 |
|
104 private: |
|
105 QStringList controls; |
|
106 QMap<QString, QString> clsids; |
|
107 }; |
|
108 |
|
109 QVariant ControlList::data(const QModelIndex &index, int role) const |
|
110 { |
|
111 if (!index.isValid()) |
|
112 return QVariant(); |
|
113 |
|
114 if (role == Qt::DisplayRole) |
|
115 return controls.at(index.row()); |
|
116 if (role == Qt::UserRole) |
|
117 return clsids.value(controls.at(index.row())); |
|
118 |
|
119 return QVariant(); |
|
120 } |
|
121 |
|
122 QAxSelect::QAxSelect(QWidget *parent, Qt::WindowFlags f) |
|
123 : QDialog(parent, f) |
|
124 { |
|
125 #ifndef QT_NO_CURSOR |
|
126 QApplication::setOverrideCursor(Qt::WaitCursor); |
|
127 #endif |
|
128 |
|
129 setupUi(this); |
|
130 ActiveXList->setModel(new ControlList(this)); |
|
131 connect(ActiveXList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), |
|
132 this, SLOT(on_ActiveXList_clicked(QModelIndex))); |
|
133 #ifndef QT_NO_CURSOR |
|
134 QApplication::restoreOverrideCursor(); |
|
135 #endif |
|
136 ActiveXList->setFocus(); |
|
137 |
|
138 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept())); |
|
139 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); |
|
140 } |
|
141 |
|
142 void QAxSelect::on_ActiveXList_clicked(const QModelIndex &index) |
|
143 { |
|
144 QVariant clsid = ActiveXList->model()->data(index, Qt::UserRole); |
|
145 ActiveX->setText(clsid.toString()); |
|
146 } |
|
147 |
|
148 void QAxSelect::on_ActiveXList_doubleClicked(const QModelIndex &index) |
|
149 { |
|
150 QVariant clsid = ActiveXList->model()->data(index, Qt::UserRole); |
|
151 ActiveX->setText(clsid.toString()); |
|
152 |
|
153 accept(); |
|
154 } |
|
155 |
|
156 QT_END_NAMESPACE |
|
157 #endif // QT_NO_WIN_ACTIVEQT |