]>
Commit | Line | Data |
---|---|---|
6a4b7e55 JR |
1 | diff --git a/.travis.yml b/.travis.yml |
2 | index fa33cf0..550518a 100644 | |
3 | --- a/.travis.yml | |
4 | +++ b/.travis.yml | |
5 | @@ -5,16 +5,20 @@ compiler: | |
6 | - gcc | |
7 | - clang | |
8 | language: cpp | |
9 | +sudo: required | |
10 | +dist: trusty | |
11 | install: | |
12 | - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -qq update; fi | |
13 | - - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -qq install cmake libqt4-dev libgcrypt11-dev zlib1g-dev libxtst-dev; fi | |
14 | + - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -qq install cmake qtbase5-dev libqt5x11extras5-dev qttools5-dev qttools5-dev-tools libgcrypt20-dev zlib1g-dev libxtst-dev xvfb; fi | |
15 | - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi | |
16 | - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew ls | grep -wq cmake || brew install cmake; fi | |
17 | - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew ls | grep -wq qt || brew install qt; fi | |
18 | + - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew ls | grep -wq qt5 || brew install qt5; fi | |
19 | - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew ls | grep -wq libgcrypt || brew install libgcrypt; fi | |
20 | -before_script: mkdir build && pushd build | |
21 | +before_script: | |
22 | + - if [ "$TRAVIS_OS_NAME" = "osx" ]; then CMAKE_ARGS="-DCMAKE_PREFIX_PATH=/usr/local/opt/qt5"; fi | |
23 | + - mkdir build && pushd build | |
24 | script: | |
25 | - - cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_GUI_TESTS=ON .. | |
26 | + - cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_GUI_TESTS=ON $CMAKE_ARGS .. | |
27 | - make | |
28 | - if [ "$TRAVIS_OS_NAME" = "linux" ]; then make test ARGS+="-E testgui --output-on-failure"; fi | |
29 | - if [ "$TRAVIS_OS_NAME" = "linux" ]; then xvfb-run -a --server-args="-screen 0 800x600x24" make test ARGS+="-R testgui --output-on-failure"; fi | |
30 | diff --git a/CMakeLists.txt b/CMakeLists.txt | |
31 | index 6df5503..21c46fa 100644 | |
32 | --- a/CMakeLists.txt | |
33 | +++ b/CMakeLists.txt | |
34 | @@ -21,7 +21,7 @@ endif() | |
35 | ||
36 | project(KeePassX) | |
37 | ||
38 | -cmake_minimum_required(VERSION 2.6.4) | |
39 | +cmake_minimum_required(VERSION 2.8.12) | |
40 | ||
41 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | |
42 | ||
43 | @@ -31,7 +31,7 @@ include(CheckCXXSourceCompiles) | |
44 | ||
45 | option(WITH_TESTS "Enable building of unit tests" ON) | |
46 | option(WITH_GUI_TESTS "Enable building of GUI tests" OFF) | |
47 | -option(WITH_CXX11 "Build with the C++ 11 standard" ON) | |
48 | +option(WITH_DEV_BUILD "Use only for development. Disables/warns about deprecated methods." OFF) | |
49 | ||
50 | set(KEEPASSX_VERSION "2.0.2") | |
51 | set(KEEPASSX_VERSION_NUM "2.0.2") | |
52 | @@ -61,7 +61,7 @@ macro(add_gcc_compiler_flags FLAGS) | |
53 | add_gcc_compiler_cflags("${FLAGS}") | |
54 | endmacro(add_gcc_compiler_flags) | |
55 | ||
56 | -add_definitions(-DQT_NO_KEYWORDS -DQT_NO_EXCEPTIONS -DQT_NO_STL -DQT_STRICT_ITERATORS -DQT_NO_CAST_TO_ASCII) | |
57 | +add_definitions(-DQT_NO_KEYWORDS -DQT_NO_EXCEPTIONS -DQT_STRICT_ITERATORS -DQT_NO_CAST_TO_ASCII) | |
58 | ||
59 | add_gcc_compiler_flags("-fno-common -fstack-protector --param=ssp-buffer-size=4") | |
60 | add_gcc_compiler_flags("-Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long") | |
61 | @@ -100,14 +100,16 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") | |
62 | set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,relro") | |
63 | endif() | |
64 | ||
65 | -if (WITH_CXX11) | |
66 | - add_gcc_compiler_cxxflags("-std=c++0x") | |
67 | - add_gcc_compiler_cflags("-ansi") | |
68 | - if(APPLE) | |
69 | - add_gcc_compiler_cxxflags("-stdlib=libc++") | |
70 | - endif() | |
71 | -else() | |
72 | - add_gcc_compiler_flags("-ansi") | |
73 | +add_gcc_compiler_cxxflags("-std=c++11") | |
74 | + | |
75 | +if(APPLE) | |
76 | + add_gcc_compiler_cxxflags("-stdlib=libc++") | |
77 | +endif() | |
78 | + | |
79 | +add_gcc_compiler_cflags("-ansi") | |
80 | + | |
81 | +if(WITH_DEV_BUILD) | |
82 | + add_definitions(-DQT_DEPRECATED_WARNINGS -DGCRYPT_NO_DEPRECATED) | |
83 | endif() | |
84 | ||
85 | if(MINGW) | |
86 | @@ -146,19 +148,18 @@ if(WITH_TESTS) | |
87 | enable_testing() | |
88 | endif(WITH_TESTS) | |
89 | ||
90 | -set(QT_REQUIRED_MODULES QtCore QtGui QtTest) | |
91 | +find_package(Qt5Core 5.2 REQUIRED) | |
92 | +find_package(Qt5Concurrent 5.2 REQUIRED) | |
93 | +find_package(Qt5Widgets 5.2 REQUIRED) | |
94 | +find_package(Qt5Test 5.2 REQUIRED) | |
95 | +find_package(Qt5LinguistTools 5.2 REQUIRED) | |
96 | +set(CMAKE_AUTOMOC ON) | |
97 | ||
98 | -find_package(Qt4 4.6.0 REQUIRED ${QT_REQUIRED_MODULES}) | |
99 | -include(${QT_USE_FILE}) | |
100 | # Debian sets the the build type to None for package builds. | |
101 | # Make sure we don't enable asserts there. | |
102 | set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_NONE QT_NO_DEBUG) | |
103 | ||
104 | -find_package(Gcrypt REQUIRED) | |
105 | -if(NOT (${GCRYPT_VERSION_STRING} VERSION_LESS "1.6.0")) | |
106 | - message(STATUS "Gcrypt ${GCRYPT_VERSION_STRING} supports the SALSA20 cipher") | |
107 | - set(GCRYPT_HAS_SALSA20 1) | |
108 | -endif() | |
109 | +find_package(Gcrypt 1.6.0 REQUIRED) | |
110 | ||
111 | find_package(ZLIB REQUIRED) | |
112 | ||
113 | @@ -199,10 +200,7 @@ endif() | |
114 | ||
115 | include_directories(SYSTEM ${GCRYPT_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR}) | |
116 | ||
117 | -if(NOT (${CMAKE_VERSION} VERSION_LESS 2.8.3)) | |
118 | - set(PRINT_SUMMARY ON) | |
119 | - include(FeatureSummary) | |
120 | -endif() | |
121 | +include(FeatureSummary) | |
122 | ||
123 | add_subdirectory(src) | |
124 | add_subdirectory(share) | |
125 | diff --git a/README.md b/README.md | |
126 | index 326bd4a..0c18ff3 100644 | |
127 | --- a/README.md | |
128 | +++ b/README.md | |
129 | @@ -49,20 +49,20 @@ Once downloaded, double click on the file to execute the installer. | |
130 | The following tools must exist within your PATH: | |
131 | ||
132 | * make | |
133 | -* cmake (>= 2.6.4) | |
134 | -* g++ or clang++ | |
135 | +* cmake (>= 2.8.12) | |
136 | +* g++ (>= 4.7) or clang++ (>= 3.0) | |
137 | ||
138 | The following libraries are required: | |
139 | ||
140 | -* Qt 4 (>= 4.6) | |
141 | -* libgcrypt | |
142 | +* Qt 5 (>= 5.2): qtbase and qttools5 | |
143 | +* libgcrypt (>= 1.6) | |
144 | * zlib | |
145 | -* libxtst (optional for auto-type on X11) | |
146 | +* libxtst, qtx11extras (optional for auto-type on X11) | |
147 | ||
148 | On Debian you can install them with: | |
149 | ||
150 | ```bash | |
151 | -sudo apt-get install build-essential cmake libqt4-dev libgcrypt11-dev zlib1g-dev | |
152 | +sudo apt-get install build-essential cmake qtbase5-dev libqt5x11extras5-dev qttools5-dev qttools5-dev-tools libgcrypt20-dev zlib1g-dev | |
153 | ``` | |
154 | ||
155 | #### Build Steps | |
156 | diff --git a/share/translations/CMakeLists.txt b/share/translations/CMakeLists.txt | |
157 | index b1aa878..7380750 100644 | |
158 | --- a/share/translations/CMakeLists.txt | |
159 | +++ b/share/translations/CMakeLists.txt | |
160 | @@ -17,9 +17,9 @@ file(GLOB TRANSLATION_FILES *.ts) | |
161 | get_filename_component(TRANSLATION_EN_ABS keepassx_en.ts ABSOLUTE) | |
162 | list(REMOVE_ITEM TRANSLATION_FILES keepassx_en.ts) | |
163 | list(REMOVE_ITEM TRANSLATION_FILES ${TRANSLATION_EN_ABS}) | |
164 | -message(STATUS ${TRANSLATION_FILES}) | |
165 | +message(STATUS "${TRANSLATION_FILES}") | |
166 | ||
167 | -qt4_add_translation(QM_FILES ${TRANSLATION_FILES}) | |
168 | +qt5_add_translation(QM_FILES ${TRANSLATION_FILES}) | |
169 | ||
170 | install(FILES ${QM_FILES} DESTINATION ${DATA_INSTALL_DIR}/translations) | |
171 | add_custom_target(translations DEPENDS ${QM_FILES}) | |
172 | diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt | |
173 | index da8b9ec..da35651 100644 | |
174 | --- a/src/CMakeLists.txt | |
175 | +++ b/src/CMakeLists.txt | |
176 | @@ -54,9 +54,6 @@ set(keepassx_SOURCES | |
177 | core/ListDeleter.h | |
178 | core/Metadata.cpp | |
179 | core/PasswordGenerator.cpp | |
180 | - core/qlockfile.cpp | |
181 | - core/qsavefile.cpp | |
182 | - core/qsavefile_p.h | |
183 | core/SignalMultiplexer.cpp | |
184 | core/TimeDelta.cpp | |
185 | core/TimeInfo.cpp | |
186 | @@ -64,8 +61,6 @@ set(keepassx_SOURCES | |
187 | core/Tools.cpp | |
188 | core/Translator.cpp | |
189 | core/Uuid.cpp | |
190 | - core/qcommandlineoption.cpp | |
191 | - core/qcommandlineparser.cpp | |
192 | crypto/Crypto.cpp | |
193 | crypto/CryptoHash.cpp | |
194 | crypto/Random.cpp | |
195 | @@ -133,94 +128,10 @@ set(keepassx_SOURCES | |
196 | streams/SymmetricCipherStream.cpp | |
197 | ) | |
198 | ||
199 | -if(NOT GCRYPT_HAS_SALSA20) | |
200 | - set(keepassx_SOURCES | |
201 | - ${keepassx_SOURCES} | |
202 | - crypto/salsa20/ecrypt-config.h | |
203 | - crypto/salsa20/ecrypt-machine.h | |
204 | - crypto/salsa20/ecrypt-portable.h | |
205 | - crypto/salsa20/ecrypt-sync.h | |
206 | - crypto/salsa20/salsa20.c | |
207 | - crypto/SymmetricCipherSalsa20.cpp | |
208 | - ) | |
209 | -endif() | |
210 | - | |
211 | -if(UNIX) | |
212 | - set(keepassx_SOURCES | |
213 | - ${keepassx_SOURCES} | |
214 | - core/qlockfile_unix.cpp | |
215 | - ) | |
216 | -elseif(MINGW) | |
217 | - set(keepassx_SOURCES | |
218 | - ${keepassx_SOURCES} | |
219 | - core/qlockfile_win.cpp | |
220 | - ) | |
221 | -endif() | |
222 | - | |
223 | set(keepassx_SOURCES_MAINEXE | |
224 | main.cpp | |
225 | ) | |
226 | ||
227 | -set(keepassx_MOC | |
228 | - autotype/AutoType.h | |
229 | - autotype/AutoTypeSelectDialog.h | |
230 | - autotype/AutoTypeSelectView.h | |
231 | - autotype/ShortcutWidget.h | |
232 | - autotype/WindowSelectComboBox.h | |
233 | - core/AutoTypeAssociations.h | |
234 | - core/Config.h | |
235 | - core/Database.h | |
236 | - core/Entry.h | |
237 | - core/EntryAttachments.h | |
238 | - core/EntryAttributes.h | |
239 | - core/Group.h | |
240 | - core/InactivityTimer.h | |
241 | - core/Metadata.h | |
242 | - core/qsavefile.h | |
243 | - gui/AboutDialog.h | |
244 | - gui/Application.h | |
245 | - gui/ChangeMasterKeyWidget.h | |
246 | - gui/Clipboard.h | |
247 | - gui/DatabaseOpenWidget.h | |
248 | - gui/DatabaseRepairWidget.h | |
249 | - gui/DatabaseSettingsWidget.h | |
250 | - gui/DatabaseTabWidget.h | |
251 | - gui/DatabaseWidget.h | |
252 | - gui/DatabaseWidgetStateSync.h | |
253 | - gui/DialogyWidget.h | |
254 | - gui/DragTabBar.h | |
255 | - gui/EditWidget.h | |
256 | - gui/EditWidgetIcons.h | |
257 | - gui/EditWidgetProperties.h | |
258 | - gui/IconModels.h | |
259 | - gui/KeePass1OpenWidget.h | |
260 | - gui/LineEdit.h | |
261 | - gui/MainWindow.h | |
262 | - gui/PasswordEdit.h | |
263 | - gui/PasswordGeneratorWidget.h | |
264 | - gui/PasswordComboBox.h | |
265 | - gui/SettingsWidget.h | |
266 | - gui/SortFilterHideProxyModel.h | |
267 | - gui/UnlockDatabaseWidget.h | |
268 | - gui/WelcomeWidget.h | |
269 | - gui/entry/AutoTypeAssociationsModel.h | |
270 | - gui/entry/EditEntryWidget.h | |
271 | - gui/entry/EntryAttachmentsModel.h | |
272 | - gui/entry/EntryAttributesModel.h | |
273 | - gui/entry/EntryHistoryModel.h | |
274 | - gui/entry/EntryModel.h | |
275 | - gui/entry/EntryView.h | |
276 | - gui/group/EditGroupWidget.h | |
277 | - gui/group/GroupModel.h | |
278 | - gui/group/GroupView.h | |
279 | - keys/CompositeKey_p.h | |
280 | - streams/HashedBlockStream.h | |
281 | - streams/LayeredStream.h | |
282 | - streams/qtiocompressor.h | |
283 | - streams/StoreDataStream.h | |
284 | - streams/SymmetricCipherStream.h | |
285 | -) | |
286 | - | |
287 | set(keepassx_FORMS | |
288 | gui/AboutDialog.ui | |
289 | gui/ChangeMasterKeyWidget.ui | |
290 | @@ -248,17 +159,18 @@ if(MINGW) | |
291 | ${CMAKE_SOURCE_DIR}/share/windows/icon.rc) | |
292 | endif() | |
293 | ||
294 | -qt4_wrap_ui(keepassx_SOURCES ${keepassx_FORMS}) | |
295 | -qt4_wrap_cpp(keepassx_SOURCES ${keepassx_MOC}) | |
296 | +qt5_wrap_ui(keepassx_SOURCES ${keepassx_FORMS}) | |
297 | ||
298 | add_library(keepassx_core STATIC ${keepassx_SOURCES}) | |
299 | set_target_properties(keepassx_core PROPERTIES COMPILE_DEFINITIONS KEEPASSX_BUILDING_CORE) | |
300 | +target_link_libraries(keepassx_core Qt5::Core Qt5::Concurrent Qt5::Widgets) | |
301 | ||
302 | add_executable(${PROGNAME} WIN32 MACOSX_BUNDLE ${keepassx_SOURCES_MAINEXE}) | |
303 | target_link_libraries(${PROGNAME} | |
304 | keepassx_core | |
305 | - ${QT_QTCORE_LIBRARY} | |
306 | - ${QT_QTGUI_LIBRARY} | |
307 | + Qt5::Core | |
308 | + Qt5::Concurrent | |
309 | + Qt5::Widgets | |
310 | ${GCRYPT_LIBRARIES} | |
311 | ${ZLIB_LIBRARIES}) | |
312 | ||
313 | @@ -276,7 +188,7 @@ install(TARGETS ${PROGNAME} | |
314 | ||
315 | add_subdirectory(autotype) | |
316 | ||
317 | -if(APPLE AND NOT (${CMAKE_VERSION} VERSION_LESS 2.8.8)) | |
318 | +if(APPLE) | |
319 | if(QT_MAC_USE_COCOA AND EXISTS "${QT_LIBRARY_DIR}/Resources/qt_menu.nib") | |
320 | install(DIRECTORY "${QT_LIBRARY_DIR}/Resources/qt_menu.nib" | |
321 | DESTINATION "${DATA_INSTALL_DIR}") | |
322 | @@ -294,7 +206,7 @@ if(APPLE AND NOT (${CMAKE_VERSION} VERSION_LESS 2.8.8)) | |
323 | install_qt4_executable(${PROGNAME}.app "qjpeg;qgif;qico;qtaccessiblewidgets") | |
324 | endif() | |
325 | ||
326 | -if(MINGW AND NOT (${CMAKE_VERSION} VERSION_LESS 2.8.8)) | |
327 | +if(MINGW ) | |
328 | set(CPACK_GENERATOR "ZIP") | |
329 | set(CPACK_STRIP_FILES ON) | |
330 | set(CPACK_PACKAGE_FILE_NAME "${PROGNAME}-${KEEPASSX_VERSION_NUM}") | |
331 | diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp | |
332 | index f1b7e3e..15185b2 100644 | |
333 | --- a/src/autotype/AutoType.cpp | |
334 | +++ b/src/autotype/AutoType.cpp | |
335 | @@ -32,7 +32,7 @@ | |
336 | #include "core/Tools.h" | |
337 | #include "gui/MessageBox.h" | |
338 | ||
339 | -AutoType* AutoType::m_instance = Q_NULLPTR; | |
340 | +AutoType* AutoType::m_instance = nullptr; | |
341 | ||
342 | AutoType::AutoType(QObject* parent, bool test) | |
343 | : QObject(parent) | |
344 | @@ -40,8 +40,8 @@ AutoType::AutoType(QObject* parent, bool test) | |
345 | , m_currentGlobalKey(static_cast<Qt::Key>(0)) | |
346 | , m_currentGlobalModifiers(0) | |
347 | , m_pluginLoader(new QPluginLoader(this)) | |
348 | - , m_plugin(Q_NULLPTR) | |
349 | - , m_executor(Q_NULLPTR) | |
350 | + , m_plugin(nullptr) | |
351 | + , m_executor(nullptr) | |
352 | , m_windowFromGlobal(0) | |
353 | { | |
354 | // prevent crash when the plugin has unresolved symbols | |
355 | @@ -49,7 +49,7 @@ AutoType::AutoType(QObject* parent, bool test) | |
356 | ||
357 | QString pluginName = "keepassx-autotype-"; | |
358 | if (!test) { | |
359 | - pluginName += Tools::platform(); | |
360 | + pluginName += QApplication::platformName(); | |
361 | } | |
362 | else { | |
363 | pluginName += "test"; | |
364 | @@ -68,7 +68,7 @@ AutoType::~AutoType() | |
365 | { | |
366 | if (m_executor) { | |
367 | delete m_executor; | |
368 | - m_executor = Q_NULLPTR; | |
369 | + m_executor = nullptr; | |
370 | } | |
371 | } | |
372 | ||
373 | @@ -79,7 +79,7 @@ void AutoType::loadPlugin(const QString& pluginPath) | |
374 | QObject* pluginInstance = m_pluginLoader->instance(); | |
375 | if (pluginInstance) { | |
376 | m_plugin = qobject_cast<AutoTypePlatformInterface*>(pluginInstance); | |
377 | - m_executor = Q_NULLPTR; | |
378 | + m_executor = nullptr; | |
379 | ||
380 | if (m_plugin) { | |
381 | if (m_plugin->isAvailable()) { | |
382 | @@ -202,11 +202,11 @@ void AutoType::performGlobalAutoType(const QList<Database*>& dbList) | |
383 | QString message = tr("Couldn't find an entry that matches the window title:"); | |
384 | message.append("\n\n"); | |
385 | message.append(windowTitle); | |
386 | - MessageBox::information(Q_NULLPTR, tr("Auto-Type - KeePassX"), message); | |
387 | + MessageBox::information(nullptr, tr("Auto-Type - KeePassX"), message); | |
388 | } | |
389 | else if ((entryList.size() == 1) && !config()->get("security/autotypeask").toBool()) { | |
390 | m_inAutoType = false; | |
391 | - performAutoType(entryList.first(), Q_NULLPTR, sequenceHash[entryList.first()]); | |
392 | + performAutoType(entryList.first(), nullptr, sequenceHash[entryList.first()]); | |
393 | } | |
394 | else { | |
395 | m_windowFromGlobal = m_plugin->activeWindow(); | |
396 | @@ -228,7 +228,7 @@ void AutoType::performAutoTypeFromGlobal(Entry* entry, const QString& sequence) | |
397 | m_plugin->raiseWindow(m_windowFromGlobal); | |
398 | ||
399 | m_inAutoType = false; | |
400 | - performAutoType(entry, Q_NULLPTR, sequence, m_windowFromGlobal); | |
401 | + performAutoType(entry, nullptr, sequence, m_windowFromGlobal); | |
402 | } | |
403 | ||
404 | void AutoType::resetInAutoType() | |
405 | @@ -242,12 +242,12 @@ void AutoType::unloadPlugin() | |
406 | { | |
407 | if (m_executor) { | |
408 | delete m_executor; | |
409 | - m_executor = Q_NULLPTR; | |
410 | + m_executor = nullptr; | |
411 | } | |
412 | ||
413 | if (m_plugin) { | |
414 | m_plugin->unload(); | |
415 | - m_plugin = Q_NULLPTR; | |
416 | + m_plugin = nullptr; | |
417 | } | |
418 | } | |
419 | ||
420 | diff --git a/src/autotype/AutoType.h b/src/autotype/AutoType.h | |
421 | index f3d626c..d1c8817 100644 | |
422 | --- a/src/autotype/AutoType.h | |
423 | +++ b/src/autotype/AutoType.h | |
424 | @@ -22,8 +22,6 @@ | |
425 | #include <QStringList> | |
426 | #include <QWidget> | |
427 | ||
428 | -#include "core/Global.h" | |
429 | - | |
430 | class AutoTypeAction; | |
431 | class AutoTypeExecutor; | |
432 | class AutoTypePlatformInterface; | |
433 | @@ -37,7 +35,7 @@ class AutoType : public QObject | |
434 | ||
435 | public: | |
436 | QStringList windowTitles(); | |
437 | - void performAutoType(const Entry* entry, QWidget* hideWindow = Q_NULLPTR, | |
438 | + void performAutoType(const Entry* entry, QWidget* hideWindow = nullptr, | |
439 | const QString& customSequence = QString(), WId window = 0); | |
440 | bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers); | |
441 | void unregisterGlobalShortcut(); | |
442 | @@ -62,7 +60,7 @@ private Q_SLOTS: | |
443 | void unloadPlugin(); | |
444 | ||
445 | private: | |
446 | - explicit AutoType(QObject* parent = Q_NULLPTR, bool test = false); | |
447 | + explicit AutoType(QObject* parent = nullptr, bool test = false); | |
448 | ~AutoType(); | |
449 | void loadPlugin(const QString& pluginPath); | |
450 | bool parseActions(const QString& sequence, const Entry* entry, QList<AutoTypeAction*>& actions); | |
451 | diff --git a/src/autotype/AutoTypeAction.h b/src/autotype/AutoTypeAction.h | |
452 | index 07e050b..490f0d8 100644 | |
453 | --- a/src/autotype/AutoTypeAction.h | |
454 | +++ b/src/autotype/AutoTypeAction.h | |
455 | @@ -66,7 +66,7 @@ public: | |
456 | class KEEPASSX_EXPORT AutoTypeClearField : public AutoTypeAction | |
457 | { | |
458 | public: | |
459 | - explicit AutoTypeClearField(); | |
460 | + AutoTypeClearField(); | |
461 | AutoTypeAction* clone(); | |
462 | void accept(AutoTypeExecutor* executor); | |
463 | }; | |
464 | diff --git a/src/autotype/AutoTypeSelectDialog.h b/src/autotype/AutoTypeSelectDialog.h | |
465 | index 4f455c7..c0dbfe4 100644 | |
466 | --- a/src/autotype/AutoTypeSelectDialog.h | |
467 | +++ b/src/autotype/AutoTypeSelectDialog.h | |
468 | @@ -22,8 +22,6 @@ | |
469 | #include <QDialog> | |
470 | #include <QHash> | |
471 | ||
472 | -#include "core/Global.h" | |
473 | - | |
474 | class AutoTypeSelectView; | |
475 | class Entry; | |
476 | ||
477 | @@ -32,7 +30,7 @@ class AutoTypeSelectDialog : public QDialog | |
478 | Q_OBJECT | |
479 | ||
480 | public: | |
481 | - explicit AutoTypeSelectDialog(QWidget* parent = Q_NULLPTR); | |
482 | + explicit AutoTypeSelectDialog(QWidget* parent = nullptr); | |
483 | void setEntries(const QList<Entry*>& entries, const QHash<Entry*, QString>& sequences); | |
484 | ||
485 | Q_SIGNALS: | |
486 | diff --git a/src/autotype/AutoTypeSelectView.h b/src/autotype/AutoTypeSelectView.h | |
487 | index bcbb262..749f6a9 100644 | |
488 | --- a/src/autotype/AutoTypeSelectView.h | |
489 | +++ b/src/autotype/AutoTypeSelectView.h | |
490 | @@ -18,7 +18,6 @@ | |
491 | #ifndef KEEPASSX_AUTOTYPESELECTVIEW_H | |
492 | #define KEEPASSX_AUTOTYPESELECTVIEW_H | |
493 | ||
494 | -#include "core/Global.h" | |
495 | #include "gui/entry/EntryView.h" | |
496 | ||
497 | class Entry; | |
498 | @@ -28,10 +27,10 @@ class AutoTypeSelectView : public EntryView | |
499 | Q_OBJECT | |
500 | ||
501 | public: | |
502 | - explicit AutoTypeSelectView(QWidget* parent = Q_NULLPTR); | |
503 | + explicit AutoTypeSelectView(QWidget* parent = nullptr); | |
504 | ||
505 | protected: | |
506 | - void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE; | |
507 | + void mouseMoveEvent(QMouseEvent* event) override; | |
508 | ||
509 | private Q_SLOTS: | |
510 | void selectFirstEntry(); | |
511 | diff --git a/src/autotype/CMakeLists.txt b/src/autotype/CMakeLists.txt | |
512 | index a0f7877..707edf9 100644 | |
513 | --- a/src/autotype/CMakeLists.txt | |
514 | +++ b/src/autotype/CMakeLists.txt | |
515 | @@ -1,12 +1,12 @@ | |
516 | -if(Q_WS_X11) | |
517 | +if(UNIX AND NOT APPLE) | |
518 | find_package(X11) | |
519 | - if(PRINT_SUMMARY) | |
520 | - add_feature_info(libXi X11_Xi_FOUND "The X11 Xi Protocol library is required for auto-type") | |
521 | - add_feature_info(libXtest X11_XTest_FOUND "The X11 XTEST Protocol library is required for auto-type") | |
522 | - endif() | |
523 | + find_package(Qt5X11Extras 5.2) | |
524 | + add_feature_info(libXi X11_Xi_FOUND "The X11 Xi Protocol library is required for auto-type") | |
525 | + add_feature_info(libXtest X11_XTest_FOUND "The X11 XTEST Protocol library is required for auto-type") | |
526 | + add_feature_info(Qt5X11Extras Qt5X11Extras_FOUND "The Qt5X11Extras library is required for auto-type") | |
527 | ||
528 | - if(X11_FOUND AND X11_Xi_FOUND AND X11_XTest_FOUND) | |
529 | - add_subdirectory(x11) | |
530 | + if(X11_FOUND AND X11_Xi_FOUND AND X11_XTest_FOUND AND Qt5X11Extras_FOUND) | |
531 | + add_subdirectory(xcb) | |
532 | endif() | |
533 | endif() | |
534 | ||
535 | diff --git a/src/autotype/ShortcutWidget.h b/src/autotype/ShortcutWidget.h | |
536 | index 5ff306c..60898ab 100644 | |
537 | --- a/src/autotype/ShortcutWidget.h | |
538 | +++ b/src/autotype/ShortcutWidget.h | |
539 | @@ -20,21 +20,19 @@ | |
540 | ||
541 | #include <QLineEdit> | |
542 | ||
543 | -#include "core/Global.h" | |
544 | - | |
545 | class ShortcutWidget : public QLineEdit | |
546 | { | |
547 | Q_OBJECT | |
548 | ||
549 | public: | |
550 | - explicit ShortcutWidget(QWidget* parent = Q_NULLPTR); | |
551 | + explicit ShortcutWidget(QWidget* parent = nullptr); | |
552 | Qt::Key key() const; | |
553 | Qt::KeyboardModifiers modifiers() const; | |
554 | void setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers); | |
555 | ||
556 | protected: | |
557 | - void keyPressEvent(QKeyEvent* event) Q_DECL_OVERRIDE; | |
558 | - void keyReleaseEvent(QKeyEvent* event) Q_DECL_OVERRIDE; | |
559 | + void keyPressEvent(QKeyEvent* event) override; | |
560 | + void keyReleaseEvent(QKeyEvent* event) override; | |
561 | ||
562 | private: | |
563 | void keyEvent(QKeyEvent* event); | |
564 | diff --git a/src/autotype/WindowSelectComboBox.h b/src/autotype/WindowSelectComboBox.h | |
565 | index 661bc84..244119a 100644 | |
566 | --- a/src/autotype/WindowSelectComboBox.h | |
567 | +++ b/src/autotype/WindowSelectComboBox.h | |
568 | @@ -20,19 +20,17 @@ | |
569 | ||
570 | #include <QComboBox> | |
571 | ||
572 | -#include "core/Global.h" | |
573 | - | |
574 | class WindowSelectComboBox : public QComboBox | |
575 | { | |
576 | Q_OBJECT | |
577 | ||
578 | public: | |
579 | - explicit WindowSelectComboBox(QWidget* parent = Q_NULLPTR); | |
580 | + explicit WindowSelectComboBox(QWidget* parent = nullptr); | |
581 | void refreshWindowList(); | |
582 | ||
583 | - void showPopup() Q_DECL_OVERRIDE; | |
584 | - QSize sizeHint() const Q_DECL_OVERRIDE; | |
585 | - QSize minimumSizeHint() const Q_DECL_OVERRIDE; | |
586 | + void showPopup() override; | |
587 | + QSize sizeHint() const override; | |
588 | + QSize minimumSizeHint() const override; | |
589 | }; | |
590 | ||
591 | #endif // KEEPASSX_WINDOWSELECTCOMBOBOX_H | |
592 | diff --git a/src/autotype/test/AutoTypeTest.cpp b/src/autotype/test/AutoTypeTest.cpp | |
593 | index a8bcc71..979af8b 100644 | |
594 | --- a/src/autotype/test/AutoTypeTest.cpp | |
595 | +++ b/src/autotype/test/AutoTypeTest.cpp | |
596 | @@ -129,5 +129,3 @@ void AutoTypeExecturorTest::execKey(AutoTypeKey* action) | |
597 | { | |
598 | m_platform->addActionKey(action); | |
599 | } | |
600 | - | |
601 | -Q_EXPORT_PLUGIN2(keepassx-autotype-test, AutoTypePlatformTest) | |
602 | diff --git a/src/autotype/test/AutoTypeTest.h b/src/autotype/test/AutoTypeTest.h | |
603 | index c791c15..8c6e524 100644 | |
604 | --- a/src/autotype/test/AutoTypeTest.h | |
605 | +++ b/src/autotype/test/AutoTypeTest.h | |
606 | @@ -23,34 +23,34 @@ | |
607 | #include "autotype/AutoTypePlatformPlugin.h" | |
608 | #include "autotype/AutoTypeAction.h" | |
609 | #include "autotype/test/AutoTypeTestInterface.h" | |
610 | -#include "core/Global.h" | |
611 | ||
612 | class AutoTypePlatformTest : public QObject, | |
613 | public AutoTypePlatformInterface, | |
614 | public AutoTypeTestInterface | |
615 | { | |
616 | Q_OBJECT | |
617 | + Q_PLUGIN_METADATA(IID "org.keepassx.AutoTypePlatformInterface") | |
618 | Q_INTERFACES(AutoTypePlatformInterface AutoTypeTestInterface) | |
619 | ||
620 | public: | |
621 | - QString keyToString(Qt::Key key) Q_DECL_OVERRIDE; | |
622 | + QString keyToString(Qt::Key key) override; | |
623 | ||
624 | - bool isAvailable() Q_DECL_OVERRIDE; | |
625 | - QStringList windowTitles() Q_DECL_OVERRIDE; | |
626 | - WId activeWindow() Q_DECL_OVERRIDE; | |
627 | - QString activeWindowTitle() Q_DECL_OVERRIDE; | |
628 | - bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE; | |
629 | - void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE; | |
630 | - int platformEventFilter(void* event) Q_DECL_OVERRIDE; | |
631 | - int initialTimeout() Q_DECL_OVERRIDE; | |
632 | - bool raiseWindow(WId window) Q_DECL_OVERRIDE; | |
633 | - AutoTypeExecutor* createExecutor() Q_DECL_OVERRIDE; | |
634 | + bool isAvailable() override; | |
635 | + QStringList windowTitles() override; | |
636 | + WId activeWindow() override; | |
637 | + QString activeWindowTitle() override; | |
638 | + bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) override; | |
639 | + void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) override; | |
640 | + int platformEventFilter(void* event) override; | |
641 | + int initialTimeout() override; | |
642 | + bool raiseWindow(WId window) override; | |
643 | + AutoTypeExecutor* createExecutor() override; | |
644 | ||
645 | - void setActiveWindowTitle(const QString& title) Q_DECL_OVERRIDE; | |
646 | + void setActiveWindowTitle(const QString& title) override; | |
647 | ||
648 | - QString actionChars() Q_DECL_OVERRIDE; | |
649 | - int actionCount() Q_DECL_OVERRIDE; | |
650 | - void clearActions() Q_DECL_OVERRIDE; | |
651 | + QString actionChars() override; | |
652 | + int actionCount() override; | |
653 | + void clearActions() override; | |
654 | ||
655 | void addActionChar(AutoTypeChar* action); | |
656 | void addActionKey(AutoTypeKey* action); | |
657 | @@ -69,8 +69,8 @@ class AutoTypeExecturorTest : public AutoTypeExecutor | |
658 | public: | |
659 | explicit AutoTypeExecturorTest(AutoTypePlatformTest* platform); | |
660 | ||
661 | - void execChar(AutoTypeChar* action) Q_DECL_OVERRIDE; | |
662 | - void execKey(AutoTypeKey* action) Q_DECL_OVERRIDE; | |
663 | + void execChar(AutoTypeChar* action) override; | |
664 | + void execKey(AutoTypeKey* action) override; | |
665 | ||
666 | private: | |
667 | AutoTypePlatformTest* const m_platform; | |
668 | diff --git a/src/autotype/test/CMakeLists.txt b/src/autotype/test/CMakeLists.txt | |
669 | index 749f7d5..9b3dbd4 100644 | |
670 | --- a/src/autotype/test/CMakeLists.txt | |
671 | +++ b/src/autotype/test/CMakeLists.txt | |
672 | @@ -2,11 +2,5 @@ set(autotype_test_SOURCES | |
673 | AutoTypeTest.cpp | |
674 | ) | |
675 | ||
676 | -set(autotype_test_MOC | |
677 | - AutoTypeTest.h | |
678 | -) | |
679 | - | |
680 | -qt4_wrap_cpp(autotype_test_SOURCES ${autotype_test_MOC}) | |
681 | - | |
682 | add_library(keepassx-autotype-test MODULE ${autotype_test_SOURCES}) | |
683 | -target_link_libraries(keepassx-autotype-test testautotype ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) | |
684 | +target_link_libraries(keepassx-autotype-test testautotype Qt5::Core Qt5::Widgets) | |
685 | diff --git a/src/autotype/x11/AutoTypeX11.cpp b/src/autotype/x11/AutoTypeX11.cpp | |
686 | deleted file mode 100644 | |
687 | index 6a20a88..0000000 | |
688 | --- a/src/autotype/x11/AutoTypeX11.cpp | |
689 | +++ /dev/null | |
690 | @@ -1,850 +0,0 @@ | |
691 | -/* | |
692 | - * Copyright (C) 2012 Felix Geyer <debfx@fobos.de> | |
693 | - * Copyright (C) 2000-2008 Tom Sato <VEF00200@nifty.ne.jp> | |
694 | - * | |
695 | - * This program is free software: you can redistribute it and/or modify | |
696 | - * it under the terms of the GNU General Public License as published by | |
697 | - * the Free Software Foundation, either version 2 or (at your option) | |
698 | - * version 3 of the License. | |
699 | - * | |
700 | - * This program is distributed in the hope that it will be useful, | |
701 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
702 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
703 | - * GNU General Public License for more details. | |
704 | - * | |
705 | - * You should have received a copy of the GNU General Public License | |
706 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
707 | - */ | |
708 | - | |
709 | -#include "AutoTypeX11.h" | |
710 | -#include "KeySymMap.h" | |
711 | - | |
712 | -#include <time.h> | |
713 | - | |
714 | -bool AutoTypePlatformX11::m_catchXErrors = false; | |
715 | -bool AutoTypePlatformX11::m_xErrorOccured = false; | |
716 | -int (*AutoTypePlatformX11::m_oldXErrorHandler)(Display*, XErrorEvent*) = Q_NULLPTR; | |
717 | - | |
718 | -AutoTypePlatformX11::AutoTypePlatformX11() | |
719 | -{ | |
720 | - m_dpy = QX11Info::display(); | |
721 | - m_rootWindow = QX11Info::appRootWindow(); | |
722 | - | |
723 | - m_atomWmState = XInternAtom(m_dpy, "WM_STATE", True); | |
724 | - m_atomWmName = XInternAtom(m_dpy, "WM_NAME", True); | |
725 | - m_atomNetWmName = XInternAtom(m_dpy, "_NET_WM_NAME", True); | |
726 | - m_atomString = XInternAtom(m_dpy, "STRING", True); | |
727 | - m_atomUtf8String = XInternAtom(m_dpy, "UTF8_STRING", True); | |
728 | - m_atomNetActiveWindow = XInternAtom(m_dpy, "_NET_ACTIVE_WINDOW", True); | |
729 | - | |
730 | - m_classBlacklist << "desktop_window" << "gnome-panel"; // Gnome | |
731 | - m_classBlacklist << "kdesktop" << "kicker"; // KDE 3 | |
732 | - m_classBlacklist << "Plasma"; // KDE 4 | |
733 | - m_classBlacklist << "plasmashell"; // KDE 5 | |
734 | - m_classBlacklist << "xfdesktop" << "xfce4-panel"; // Xfce 4 | |
735 | - | |
736 | - m_currentGlobalKey = static_cast<Qt::Key>(0); | |
737 | - m_currentGlobalModifiers = 0; | |
738 | - | |
739 | - m_keysymTable = Q_NULLPTR; | |
740 | - m_xkb = Q_NULLPTR; | |
741 | - m_remapKeycode = 0; | |
742 | - m_currentRemapKeysym = NoSymbol; | |
743 | - m_modifierMask = ControlMask | ShiftMask | Mod1Mask | Mod4Mask; | |
744 | - | |
745 | - m_loaded = true; | |
746 | - | |
747 | - updateKeymap(); | |
748 | -} | |
749 | - | |
750 | -bool AutoTypePlatformX11::isAvailable() | |
751 | -{ | |
752 | - int ignore; | |
753 | - | |
754 | - if (!XQueryExtension(m_dpy, "XInputExtension", &ignore, &ignore, &ignore)) { | |
755 | - return false; | |
756 | - } | |
757 | - | |
758 | - if (!XQueryExtension(m_dpy, "XTEST", &ignore, &ignore, &ignore)) { | |
759 | - return false; | |
760 | - } | |
761 | - | |
762 | - if (!m_xkb) { | |
763 | - XkbDescPtr kbd = getKeyboard(); | |
764 | - | |
765 | - if (!kbd) { | |
766 | - return false; | |
767 | - } | |
768 | - | |
769 | - XkbFreeKeyboard(kbd, XkbAllComponentsMask, True); | |
770 | - } | |
771 | - | |
772 | - return true; | |
773 | -} | |
774 | - | |
775 | -void AutoTypePlatformX11::unload() | |
776 | -{ | |
777 | - // Restore the KeyboardMapping to its original state. | |
778 | - if (m_currentRemapKeysym != NoSymbol) { | |
779 | - AddKeysym(NoSymbol); | |
780 | - } | |
781 | - | |
782 | - if (m_keysymTable) { | |
783 | - XFree(m_keysymTable); | |
784 | - } | |
785 | - | |
786 | - if (m_xkb) { | |
787 | - XkbFreeKeyboard(m_xkb, XkbAllComponentsMask, True); | |
788 | - } | |
789 | - | |
790 | - m_loaded = false; | |
791 | -} | |
792 | - | |
793 | -QStringList AutoTypePlatformX11::windowTitles() | |
794 | -{ | |
795 | - return windowTitlesRecursive(m_rootWindow); | |
796 | -} | |
797 | - | |
798 | -WId AutoTypePlatformX11::activeWindow() | |
799 | -{ | |
800 | - Window window; | |
801 | - int revert_to_return; | |
802 | - XGetInputFocus(m_dpy, &window, &revert_to_return); | |
803 | - | |
804 | - int tree; | |
805 | - do { | |
806 | - if (isTopLevelWindow(window)) { | |
807 | - break; | |
808 | - } | |
809 | - | |
810 | - Window root; | |
811 | - Window parent; | |
812 | - Window* children = Q_NULLPTR; | |
813 | - unsigned int numChildren; | |
814 | - tree = XQueryTree(m_dpy, window, &root, &parent, &children, &numChildren); | |
815 | - window = parent; | |
816 | - if (children) { | |
817 | - XFree(children); | |
818 | - } | |
819 | - } while (tree && window); | |
820 | - | |
821 | - return window; | |
822 | -} | |
823 | - | |
824 | -QString AutoTypePlatformX11::activeWindowTitle() | |
825 | -{ | |
826 | - return windowTitle(activeWindow(), true); | |
827 | -} | |
828 | - | |
829 | -bool AutoTypePlatformX11::registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) | |
830 | -{ | |
831 | - int keycode = XKeysymToKeycode(m_dpy, charToKeySym(key)); | |
832 | - uint nativeModifiers = qtToNativeModifiers(modifiers); | |
833 | - | |
834 | - startCatchXErrors(); | |
835 | - XGrabKey(m_dpy, keycode, nativeModifiers, m_rootWindow, True, GrabModeAsync, GrabModeAsync); | |
836 | - XGrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask, m_rootWindow, True, GrabModeAsync, | |
837 | - GrabModeAsync); | |
838 | - XGrabKey(m_dpy, keycode, nativeModifiers | LockMask, m_rootWindow, True, GrabModeAsync, | |
839 | - GrabModeAsync); | |
840 | - XGrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask | LockMask, m_rootWindow, True, | |
841 | - GrabModeAsync, GrabModeAsync); | |
842 | - stopCatchXErrors(); | |
843 | - | |
844 | - if (!m_xErrorOccured) { | |
845 | - m_currentGlobalKey = key; | |
846 | - m_currentGlobalModifiers = modifiers; | |
847 | - m_currentGlobalKeycode = keycode; | |
848 | - m_currentGlobalNativeModifiers = nativeModifiers; | |
849 | - return true; | |
850 | - } | |
851 | - else { | |
852 | - unregisterGlobalShortcut(key, modifiers); | |
853 | - return false; | |
854 | - } | |
855 | -} | |
856 | - | |
857 | -uint AutoTypePlatformX11::qtToNativeModifiers(Qt::KeyboardModifiers modifiers) | |
858 | -{ | |
859 | - uint nativeModifiers = 0; | |
860 | - | |
861 | - if (modifiers & Qt::ShiftModifier) { | |
862 | - nativeModifiers |= ShiftMask; | |
863 | - } | |
864 | - if (modifiers & Qt::ControlModifier) { | |
865 | - nativeModifiers |= ControlMask; | |
866 | - } | |
867 | - if (modifiers & Qt::AltModifier) { | |
868 | - nativeModifiers |= Mod1Mask; | |
869 | - } | |
870 | - if (modifiers & Qt::MetaModifier) { | |
871 | - nativeModifiers |= Mod4Mask; | |
872 | - } | |
873 | - | |
874 | - return nativeModifiers; | |
875 | -} | |
876 | - | |
877 | -void AutoTypePlatformX11::unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) | |
878 | -{ | |
879 | - KeyCode keycode = XKeysymToKeycode(m_dpy, charToKeySym(key)); | |
880 | - uint nativeModifiers = qtToNativeModifiers(modifiers); | |
881 | - | |
882 | - XUngrabKey(m_dpy, keycode, nativeModifiers, m_rootWindow); | |
883 | - XUngrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask, m_rootWindow); | |
884 | - XUngrabKey(m_dpy, keycode, nativeModifiers | LockMask, m_rootWindow); | |
885 | - XUngrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask | LockMask, m_rootWindow); | |
886 | - | |
887 | - m_currentGlobalKey = static_cast<Qt::Key>(0); | |
888 | - m_currentGlobalModifiers = 0; | |
889 | - m_currentGlobalKeycode = 0; | |
890 | - m_currentGlobalNativeModifiers = 0; | |
891 | -} | |
892 | - | |
893 | -int AutoTypePlatformX11::platformEventFilter(void* event) | |
894 | -{ | |
895 | - XEvent* xevent = static_cast<XEvent*>(event); | |
896 | - | |
897 | - if ((xevent->type == KeyPress || xevent->type == KeyRelease) | |
898 | - && m_currentGlobalKey | |
899 | - && xevent->xkey.keycode == m_currentGlobalKeycode | |
900 | - && (xevent->xkey.state & m_modifierMask) == m_currentGlobalNativeModifiers | |
901 | - && (!QApplication::activeWindow() || QApplication::activeWindow()->isMinimized()) | |
902 | - && m_loaded) { | |
903 | - if (xevent->type == KeyPress) { | |
904 | - Q_EMIT globalShortcutTriggered(); | |
905 | - } | |
906 | - return 1; | |
907 | - } | |
908 | - if (xevent->type == MappingNotify && m_loaded) { | |
909 | - XRefreshKeyboardMapping(reinterpret_cast<XMappingEvent*>(xevent)); | |
910 | - updateKeymap(); | |
911 | - } | |
912 | - | |
913 | - return -1; | |
914 | -} | |
915 | - | |
916 | -AutoTypeExecutor* AutoTypePlatformX11::createExecutor() | |
917 | -{ | |
918 | - return new AutoTypeExecturorX11(this); | |
919 | -} | |
920 | - | |
921 | -QString AutoTypePlatformX11::windowTitle(Window window, bool useBlacklist) | |
922 | -{ | |
923 | - QString title; | |
924 | - | |
925 | - Atom type; | |
926 | - int format; | |
927 | - unsigned long nitems; | |
928 | - unsigned long after; | |
929 | - unsigned char* data = Q_NULLPTR; | |
930 | - | |
931 | - // the window manager spec says we should read _NET_WM_NAME first, then fall back to WM_NAME | |
932 | - | |
933 | - int retVal = XGetWindowProperty(m_dpy, window, m_atomNetWmName, 0, 1000, False, m_atomUtf8String, | |
934 | - &type, &format, &nitems, &after, &data); | |
935 | - | |
936 | - if ((retVal == 0) && data) { | |
937 | - title = QString::fromUtf8(reinterpret_cast<char*>(data)); | |
938 | - } | |
939 | - else { | |
940 | - XTextProperty textProp; | |
941 | - retVal = XGetTextProperty(m_dpy, window, &textProp, m_atomWmName); | |
942 | - if ((retVal != 0) && textProp.value) { | |
943 | - char** textList = Q_NULLPTR; | |
944 | - int count; | |
945 | - | |
946 | - if (textProp.encoding == m_atomUtf8String) { | |
947 | - title = QString::fromUtf8(reinterpret_cast<char*>(textProp.value)); | |
948 | - } | |
949 | - else if ((XmbTextPropertyToTextList(m_dpy, &textProp, &textList, &count) == 0) | |
950 | - && textList && (count > 0)) { | |
951 | - title = QString::fromLocal8Bit(textList[0]); | |
952 | - } | |
953 | - else if (textProp.encoding == m_atomString) { | |
954 | - title = QString::fromLocal8Bit(reinterpret_cast<char*>(textProp.value)); | |
955 | - } | |
956 | - | |
957 | - if (textList) { | |
958 | - XFreeStringList(textList); | |
959 | - } | |
960 | - } | |
961 | - | |
962 | - if (textProp.value) { | |
963 | - XFree(textProp.value); | |
964 | - } | |
965 | - } | |
966 | - | |
967 | - if (data) { | |
968 | - XFree(data); | |
969 | - } | |
970 | - | |
971 | - if (useBlacklist && !title.isEmpty()) { | |
972 | - if (window == m_rootWindow) { | |
973 | - return QString(); | |
974 | - } | |
975 | - | |
976 | - QString className = windowClassName(window); | |
977 | - if (m_classBlacklist.contains(className)) { | |
978 | - return QString(); | |
979 | - } | |
980 | - | |
981 | - QList<Window> keepassxWindows = widgetsToX11Windows(QApplication::topLevelWidgets()); | |
982 | - if (keepassxWindows.contains(window)) { | |
983 | - return QString(); | |
984 | - } | |
985 | - } | |
986 | - | |
987 | - return title; | |
988 | -} | |
989 | - | |
990 | -QString AutoTypePlatformX11::windowClassName(Window window) | |
991 | -{ | |
992 | - QString className; | |
993 | - | |
994 | - XClassHint wmClass; | |
995 | - wmClass.res_name = Q_NULLPTR; | |
996 | - wmClass.res_class = Q_NULLPTR; | |
997 | - | |
998 | - if (XGetClassHint(m_dpy, window, &wmClass) && wmClass.res_name) { | |
999 | - className = QString::fromLocal8Bit(wmClass.res_name); | |
1000 | - } | |
1001 | - if (wmClass.res_name) { | |
1002 | - XFree(wmClass.res_name); | |
1003 | - } | |
1004 | - if (wmClass.res_class) { | |
1005 | - XFree(wmClass.res_class); | |
1006 | - } | |
1007 | - | |
1008 | - return className; | |
1009 | -} | |
1010 | - | |
1011 | -QList<Window> AutoTypePlatformX11::widgetsToX11Windows(const QWidgetList& widgetList) | |
1012 | -{ | |
1013 | - QList<Window> windows; | |
1014 | - | |
1015 | - Q_FOREACH (const QWidget* widget, widgetList) { | |
1016 | - windows.append(widget->effectiveWinId()); | |
1017 | - } | |
1018 | - | |
1019 | - return windows; | |
1020 | -} | |
1021 | - | |
1022 | -QStringList AutoTypePlatformX11::windowTitlesRecursive(Window window) | |
1023 | -{ | |
1024 | - QStringList titles; | |
1025 | - | |
1026 | - if (isTopLevelWindow(window)) { | |
1027 | - QString title = windowTitle(window, true); | |
1028 | - if (!title.isEmpty()) { | |
1029 | - titles.append(title); | |
1030 | - } | |
1031 | - } | |
1032 | - | |
1033 | - Window root; | |
1034 | - Window parent; | |
1035 | - Window* children = Q_NULLPTR; | |
1036 | - unsigned int numChildren; | |
1037 | - if (XQueryTree(m_dpy, window, &root, &parent, &children, &numChildren) && children) { | |
1038 | - for (uint i = 0; i < numChildren; i++) { | |
1039 | - titles.append(windowTitlesRecursive(children[i])); | |
1040 | - } | |
1041 | - } | |
1042 | - if (children) { | |
1043 | - XFree(children); | |
1044 | - } | |
1045 | - | |
1046 | - return titles; | |
1047 | -} | |
1048 | - | |
1049 | -bool AutoTypePlatformX11::isTopLevelWindow(Window window) | |
1050 | -{ | |
1051 | - Atom type = None; | |
1052 | - int format; | |
1053 | - unsigned long nitems; | |
1054 | - unsigned long after; | |
1055 | - unsigned char* data = Q_NULLPTR; | |
1056 | - int retVal = XGetWindowProperty(m_dpy, window, m_atomWmState, 0, 0, False, AnyPropertyType, &type, &format, | |
1057 | - &nitems, &after, &data); | |
1058 | - if (data) { | |
1059 | - XFree(data); | |
1060 | - } | |
1061 | - | |
1062 | - return (retVal == 0) && type; | |
1063 | -} | |
1064 | - | |
1065 | -KeySym AutoTypePlatformX11::charToKeySym(const QChar& ch) | |
1066 | -{ | |
1067 | - ushort unicode = ch.unicode(); | |
1068 | - | |
1069 | - /* first check for Latin-1 characters (1:1 mapping) */ | |
1070 | - if ((unicode >= 0x0020 && unicode <= 0x007e) | |
1071 | - || (unicode >= 0x00a0 && unicode <= 0x00ff)) { | |
1072 | - return unicode; | |
1073 | - } | |
1074 | - | |
1075 | - /* mapping table generated from keysymdef.h */ | |
1076 | - const uint* match = qBinaryFind(m_unicodeToKeysymKeys, | |
1077 | - m_unicodeToKeysymKeys + m_unicodeToKeysymLen, | |
1078 | - unicode); | |
1079 | - int index = match - m_unicodeToKeysymKeys; | |
1080 | - if (index != m_unicodeToKeysymLen) { | |
1081 | - return m_unicodeToKeysymValues[index]; | |
1082 | - } | |
1083 | - | |
1084 | - if (unicode >= 0x0100) { | |
1085 | - return unicode | 0x01000000; | |
1086 | - } | |
1087 | - | |
1088 | - return NoSymbol; | |
1089 | -} | |
1090 | - | |
1091 | -KeySym AutoTypePlatformX11::keyToKeySym(Qt::Key key) | |
1092 | -{ | |
1093 | - switch (key) { | |
1094 | - case Qt::Key_Tab: | |
1095 | - return XK_Tab; | |
1096 | - case Qt::Key_Enter: | |
1097 | - return XK_Return; | |
1098 | - case Qt::Key_Up: | |
1099 | - return XK_Up; | |
1100 | - case Qt::Key_Down: | |
1101 | - return XK_Down; | |
1102 | - case Qt::Key_Left: | |
1103 | - return XK_Left; | |
1104 | - case Qt::Key_Right: | |
1105 | - return XK_Right; | |
1106 | - case Qt::Key_Insert: | |
1107 | - return XK_Insert; | |
1108 | - case Qt::Key_Delete: | |
1109 | - return XK_Delete; | |
1110 | - case Qt::Key_Home: | |
1111 | - return XK_Home; | |
1112 | - case Qt::Key_End: | |
1113 | - return XK_End; | |
1114 | - case Qt::Key_PageUp: | |
1115 | - return XK_Page_Up; | |
1116 | - case Qt::Key_PageDown: | |
1117 | - return XK_Page_Down; | |
1118 | - case Qt::Key_Backspace: | |
1119 | - return XK_BackSpace; | |
1120 | - case Qt::Key_Pause: | |
1121 | - return XK_Break; | |
1122 | - case Qt::Key_CapsLock: | |
1123 | - return XK_Caps_Lock; | |
1124 | - case Qt::Key_Escape: | |
1125 | - return XK_Escape; | |
1126 | - case Qt::Key_Help: | |
1127 | - return XK_Help; | |
1128 | - case Qt::Key_NumLock: | |
1129 | - return XK_Num_Lock; | |
1130 | - case Qt::Key_Print: | |
1131 | - return XK_Print; | |
1132 | - case Qt::Key_ScrollLock: | |
1133 | - return XK_Scroll_Lock; | |
1134 | - default: | |
1135 | - if (key >= Qt::Key_F1 && key <= Qt::Key_F16) { | |
1136 | - return XK_F1 + (key - Qt::Key_F1); | |
1137 | - } | |
1138 | - else { | |
1139 | - return NoSymbol; | |
1140 | - } | |
1141 | - } | |
1142 | -} | |
1143 | - | |
1144 | -/* | |
1145 | - * Update the keyboard and modifier mapping. | |
1146 | - * We need the KeyboardMapping for AddKeysym. | |
1147 | - * Modifier mapping is required for clearing the modifiers. | |
1148 | - */ | |
1149 | -void AutoTypePlatformX11::updateKeymap() | |
1150 | -{ | |
1151 | - int keycode, inx; | |
1152 | - int mod_index, mod_key; | |
1153 | - XModifierKeymap *modifiers; | |
1154 | - | |
1155 | - if (m_xkb) { | |
1156 | - XkbFreeKeyboard(m_xkb, XkbAllComponentsMask, True); | |
1157 | - } | |
1158 | - m_xkb = getKeyboard(); | |
1159 | - | |
1160 | - XDisplayKeycodes(m_dpy, &m_minKeycode, &m_maxKeycode); | |
1161 | - if (m_keysymTable != NULL) XFree(m_keysymTable); | |
1162 | - m_keysymTable = XGetKeyboardMapping(m_dpy, | |
1163 | - m_minKeycode, m_maxKeycode - m_minKeycode + 1, | |
1164 | - &m_keysymPerKeycode); | |
1165 | - | |
1166 | - /* determine the keycode to use for remapped keys */ | |
1167 | - inx = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode; | |
1168 | - if (m_remapKeycode == 0 || !isRemapKeycodeValid()) { | |
1169 | - for (keycode = m_minKeycode; keycode <= m_maxKeycode; keycode++) { | |
1170 | - inx = (keycode - m_minKeycode) * m_keysymPerKeycode; | |
1171 | - if (m_keysymTable[inx] == NoSymbol) { | |
1172 | - m_remapKeycode = keycode; | |
1173 | - m_currentRemapKeysym = NoSymbol; | |
1174 | - break; | |
1175 | - } | |
1176 | - } | |
1177 | - } | |
1178 | - | |
1179 | - /* determine the keycode to use for modifiers */ | |
1180 | - modifiers = XGetModifierMapping(m_dpy); | |
1181 | - for (mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index ++) { | |
1182 | - m_modifier_keycode[mod_index] = 0; | |
1183 | - for (mod_key = 0; mod_key < modifiers->max_keypermod; mod_key++) { | |
1184 | - keycode = modifiers->modifiermap[mod_index * modifiers->max_keypermod + mod_key]; | |
1185 | - if (keycode) { | |
1186 | - m_modifier_keycode[mod_index] = keycode; | |
1187 | - break; | |
1188 | - } | |
1189 | - } | |
1190 | - } | |
1191 | - XFreeModifiermap(modifiers); | |
1192 | - | |
1193 | - /* Xlib needs some time until the mapping is distributed to | |
1194 | - all clients */ | |
1195 | - // TODO: we should probably only sleep while in the middle of typing something | |
1196 | - timespec ts; | |
1197 | - ts.tv_sec = 0; | |
1198 | - ts.tv_nsec = 30 * 1000 * 1000; | |
1199 | - nanosleep(&ts, Q_NULLPTR); | |
1200 | -} | |
1201 | - | |
1202 | -bool AutoTypePlatformX11::isRemapKeycodeValid() | |
1203 | -{ | |
1204 | - int baseKeycode = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode; | |
1205 | - for (int i = 0; i < m_keysymPerKeycode; i++) { | |
1206 | - if (m_keysymTable[baseKeycode + i] == m_currentRemapKeysym) { | |
1207 | - return true; | |
1208 | - } | |
1209 | - } | |
1210 | - | |
1211 | - return false; | |
1212 | -} | |
1213 | - | |
1214 | -void AutoTypePlatformX11::startCatchXErrors() | |
1215 | -{ | |
1216 | - Q_ASSERT(!m_catchXErrors); | |
1217 | - | |
1218 | - m_catchXErrors = true; | |
1219 | - m_xErrorOccured = false; | |
1220 | - m_oldXErrorHandler = XSetErrorHandler(x11ErrorHandler); | |
1221 | -} | |
1222 | - | |
1223 | -void AutoTypePlatformX11::stopCatchXErrors() | |
1224 | -{ | |
1225 | - Q_ASSERT(m_catchXErrors); | |
1226 | - | |
1227 | - XSync(m_dpy, False); | |
1228 | - XSetErrorHandler(m_oldXErrorHandler); | |
1229 | - m_catchXErrors = false; | |
1230 | -} | |
1231 | - | |
1232 | -int AutoTypePlatformX11::x11ErrorHandler(Display* display, XErrorEvent* error) | |
1233 | -{ | |
1234 | - Q_UNUSED(display) | |
1235 | - Q_UNUSED(error) | |
1236 | - | |
1237 | - if (m_catchXErrors) { | |
1238 | - m_xErrorOccured = true; | |
1239 | - } | |
1240 | - | |
1241 | - return 1; | |
1242 | -} | |
1243 | - | |
1244 | -XkbDescPtr AutoTypePlatformX11::getKeyboard() | |
1245 | -{ | |
1246 | - int num_devices; | |
1247 | - XID keyboard_id = XkbUseCoreKbd; | |
1248 | - XDeviceInfo* devices = XListInputDevices(m_dpy, &num_devices); | |
1249 | - if (!devices) { | |
1250 | - return Q_NULLPTR; | |
1251 | - } | |
1252 | - | |
1253 | - for (int i = 0; i < num_devices; i++) { | |
1254 | - if (QString(devices[i].name) == "Virtual core XTEST keyboard") { | |
1255 | - keyboard_id = devices[i].id; | |
1256 | - break; | |
1257 | - } | |
1258 | - } | |
1259 | - | |
1260 | - XFreeDeviceList(devices); | |
1261 | - | |
1262 | - return XkbGetKeyboard(m_dpy, XkbCompatMapMask | XkbGeometryMask, keyboard_id); | |
1263 | -} | |
1264 | - | |
1265 | -// -------------------------------------------------------------------------- | |
1266 | -// The following code is taken from xvkbd 3.0 and has been slightly modified. | |
1267 | -// -------------------------------------------------------------------------- | |
1268 | - | |
1269 | -/* | |
1270 | - * Insert a specified keysym on the dedicated position in the keymap | |
1271 | - * table. | |
1272 | - */ | |
1273 | -int AutoTypePlatformX11::AddKeysym(KeySym keysym) | |
1274 | -{ | |
1275 | - if (m_remapKeycode == 0) { | |
1276 | - return 0; | |
1277 | - } | |
1278 | - | |
1279 | - int inx = (m_remapKeycode- m_minKeycode) * m_keysymPerKeycode; | |
1280 | - m_keysymTable[inx] = keysym; | |
1281 | - m_currentRemapKeysym = keysym; | |
1282 | - | |
1283 | - XChangeKeyboardMapping(m_dpy, m_remapKeycode, m_keysymPerKeycode, &m_keysymTable[inx], 1); | |
1284 | - XFlush(m_dpy); | |
1285 | - updateKeymap(); | |
1286 | - | |
1287 | - return m_remapKeycode; | |
1288 | -} | |
1289 | - | |
1290 | -/* | |
1291 | - * Send event to the focused window. | |
1292 | - * If input focus is specified explicitly, select the window | |
1293 | - * before send event to the window. | |
1294 | - */ | |
1295 | -void AutoTypePlatformX11::SendEvent(XKeyEvent* event, int event_type) | |
1296 | -{ | |
1297 | - XSync(event->display, False); | |
1298 | - int (*oldHandler) (Display*, XErrorEvent*) = XSetErrorHandler(MyErrorHandler); | |
1299 | - | |
1300 | - event->type = event_type; | |
1301 | - Bool press; | |
1302 | - if (event->type == KeyPress) { | |
1303 | - press = True; | |
1304 | - } | |
1305 | - else { | |
1306 | - press = False; | |
1307 | - } | |
1308 | - XTestFakeKeyEvent(event->display, event->keycode, press, 0); | |
1309 | - XFlush(event->display); | |
1310 | - | |
1311 | - XSetErrorHandler(oldHandler); | |
1312 | -} | |
1313 | - | |
1314 | -/* | |
1315 | - * Send a modifier press/release event for all modifiers | |
1316 | - * which are set in the mask variable. | |
1317 | - */ | |
1318 | -void AutoTypePlatformX11::SendModifier(XKeyEvent *event, unsigned int mask, int event_type) | |
1319 | -{ | |
1320 | - int mod_index; | |
1321 | - for (mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index ++) { | |
1322 | - if (mask & (1 << mod_index)) { | |
1323 | - event->keycode = m_modifier_keycode[mod_index]; | |
1324 | - SendEvent(event, event_type); | |
1325 | - if (event_type == KeyPress) | |
1326 | - event->state |= (1 << mod_index); | |
1327 | - else | |
1328 | - event->state &= (1 << mod_index); | |
1329 | - } | |
1330 | - } | |
1331 | -} | |
1332 | - | |
1333 | -/* | |
1334 | - * Determines the keycode and modifier mask for the given | |
1335 | - * keysym. | |
1336 | - */ | |
1337 | -int AutoTypePlatformX11::GetKeycode(KeySym keysym, unsigned int *mask) | |
1338 | -{ | |
1339 | - int keycode = XKeysymToKeycode(m_dpy, keysym); | |
1340 | - | |
1341 | - if (keycode && keysymModifiers(keysym, keycode, mask)) { | |
1342 | - return keycode; | |
1343 | - } | |
1344 | - | |
1345 | - /* no modifier matches => resort to remapping */ | |
1346 | - keycode = AddKeysym(keysym); | |
1347 | - if (keycode && keysymModifiers(keysym, keycode, mask)) { | |
1348 | - return keycode; | |
1349 | - } | |
1350 | - | |
1351 | - *mask = 0; | |
1352 | - return 0; | |
1353 | -} | |
1354 | - | |
1355 | -bool AutoTypePlatformX11::keysymModifiers(KeySym keysym, int keycode, unsigned int *mask) | |
1356 | -{ | |
1357 | - int shift, mod; | |
1358 | - unsigned int mods_rtrn; | |
1359 | - | |
1360 | - /* determine whether there is a combination of the modifiers | |
1361 | - (Mod1-Mod5) with or without shift which returns keysym */ | |
1362 | - for (shift = 0; shift < 2; shift ++) { | |
1363 | - for (mod = ControlMapIndex; mod <= Mod5MapIndex; mod ++) { | |
1364 | - KeySym keysym_rtrn; | |
1365 | - *mask = (mod == ControlMapIndex) ? shift : shift | (1 << mod); | |
1366 | - XkbTranslateKeyCode(m_xkb, keycode, *mask, &mods_rtrn, &keysym_rtrn); | |
1367 | - if (keysym_rtrn == keysym) { | |
1368 | - return true; | |
1369 | - } | |
1370 | - } | |
1371 | - } | |
1372 | - | |
1373 | - return false; | |
1374 | -} | |
1375 | - | |
1376 | - | |
1377 | - | |
1378 | -/* | |
1379 | - * Send sequence of KeyPressed/KeyReleased events to the focused | |
1380 | - * window to simulate keyboard. If modifiers (shift, control, etc) | |
1381 | - * are set ON, many events will be sent. | |
1382 | - */ | |
1383 | -void AutoTypePlatformX11::SendKeyPressedEvent(KeySym keysym) | |
1384 | -{ | |
1385 | - Window cur_focus; | |
1386 | - int revert_to; | |
1387 | - XKeyEvent event; | |
1388 | - int keycode; | |
1389 | - | |
1390 | - if (keysym == NoSymbol) { | |
1391 | - qWarning("No such key: keysym=0x%lX", keysym); | |
1392 | - return; | |
1393 | - } | |
1394 | - | |
1395 | - XGetInputFocus(m_dpy, &cur_focus, &revert_to); | |
1396 | - | |
1397 | - event.display = m_dpy; | |
1398 | - event.window = cur_focus; | |
1399 | - event.root = m_rootWindow; | |
1400 | - event.subwindow = None; | |
1401 | - event.time = CurrentTime; | |
1402 | - event.x = 1; | |
1403 | - event.y = 1; | |
1404 | - event.x_root = 1; | |
1405 | - event.y_root = 1; | |
1406 | - event.same_screen = TRUE; | |
1407 | - | |
1408 | - Window root, child; | |
1409 | - int root_x, root_y, x, y; | |
1410 | - unsigned int wanted_mask = 0; | |
1411 | - unsigned int original_mask; | |
1412 | - | |
1413 | - XQueryPointer(m_dpy, event.root, &root, &child, &root_x, &root_y, &x, &y, &original_mask); | |
1414 | - | |
1415 | - /* determine keycode and mask for the given keysym */ | |
1416 | - keycode = GetKeycode(keysym, &wanted_mask); | |
1417 | - if (keycode < 8 || keycode > 255) { | |
1418 | - qWarning("Unable to get valid keycode for key: keysym=0x%lX", keysym); | |
1419 | - return; | |
1420 | - } | |
1421 | - | |
1422 | - event.state = original_mask; | |
1423 | - | |
1424 | - // modifiers that need to be pressed but aren't | |
1425 | - unsigned int press_mask = wanted_mask & ~original_mask; | |
1426 | - | |
1427 | - // modifiers that are pressed but maybe shouldn't | |
1428 | - unsigned int release_check_mask = original_mask & ~wanted_mask; | |
1429 | - | |
1430 | - // modifiers we need to release before sending the keycode | |
1431 | - unsigned int release_mask = 0; | |
1432 | - | |
1433 | - // check every release_check_mask individually if it affects the keysym we would generate | |
1434 | - // if it doesn't we probably don't need to release it | |
1435 | - for (int mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index ++) { | |
1436 | - if (release_check_mask & (1 << mod_index)) { | |
1437 | - unsigned int mods_rtrn; | |
1438 | - KeySym keysym_rtrn; | |
1439 | - XkbTranslateKeyCode(m_xkb, keycode, wanted_mask | (1 << mod_index), &mods_rtrn, &keysym_rtrn); | |
1440 | - | |
1441 | - if (keysym_rtrn != keysym) { | |
1442 | - release_mask |= (1 << mod_index); | |
1443 | - } | |
1444 | - } | |
1445 | - } | |
1446 | - | |
1447 | - // finally check if the combination of pressed modifiers that we chose to ignore affects the keysym | |
1448 | - unsigned int mods_rtrn; | |
1449 | - KeySym keysym_rtrn; | |
1450 | - XkbTranslateKeyCode(m_xkb, keycode, wanted_mask | (release_check_mask & ~release_mask), &mods_rtrn, &keysym_rtrn); | |
1451 | - if (keysym_rtrn != keysym) { | |
1452 | - // oh well, release all the modifiers we don't want | |
1453 | - release_mask = release_check_mask; | |
1454 | - } | |
1455 | - | |
1456 | - /* release all modifiers */ | |
1457 | - SendModifier(&event, release_mask, KeyRelease); | |
1458 | - | |
1459 | - SendModifier(&event, press_mask, KeyPress); | |
1460 | - | |
1461 | - /* press and release key */ | |
1462 | - event.keycode = keycode; | |
1463 | - SendEvent(&event, KeyPress); | |
1464 | - SendEvent(&event, KeyRelease); | |
1465 | - | |
1466 | - /* release the modifiers */ | |
1467 | - SendModifier(&event, press_mask, KeyRelease); | |
1468 | - | |
1469 | - /* restore the old keyboard mask */ | |
1470 | - SendModifier(&event, release_mask, KeyPress); | |
1471 | -} | |
1472 | - | |
1473 | -int AutoTypePlatformX11::MyErrorHandler(Display* my_dpy, XErrorEvent* event) | |
1474 | -{ | |
1475 | - char msg[200]; | |
1476 | - | |
1477 | - if (event->error_code == BadWindow) { | |
1478 | - return 0; | |
1479 | - } | |
1480 | - XGetErrorText(my_dpy, event->error_code, msg, sizeof(msg) - 1); | |
1481 | - qWarning("X error trapped: %s, request-code=%d\n", msg, event->request_code); | |
1482 | - return 0; | |
1483 | -} | |
1484 | - | |
1485 | - | |
1486 | -AutoTypeExecturorX11::AutoTypeExecturorX11(AutoTypePlatformX11* platform) | |
1487 | - : m_platform(platform) | |
1488 | -{ | |
1489 | -} | |
1490 | - | |
1491 | -void AutoTypeExecturorX11::execChar(AutoTypeChar* action) | |
1492 | -{ | |
1493 | - m_platform->SendKeyPressedEvent(m_platform->charToKeySym(action->character)); | |
1494 | -} | |
1495 | - | |
1496 | -void AutoTypeExecturorX11::execKey(AutoTypeKey* action) | |
1497 | -{ | |
1498 | - m_platform->SendKeyPressedEvent(m_platform->keyToKeySym(action->key)); | |
1499 | -} | |
1500 | - | |
1501 | -int AutoTypePlatformX11::initialTimeout() | |
1502 | -{ | |
1503 | - return 500; | |
1504 | -} | |
1505 | - | |
1506 | -bool AutoTypePlatformX11::raiseWindow(WId window) | |
1507 | -{ | |
1508 | - if (m_atomNetActiveWindow == None) { | |
1509 | - return false; | |
1510 | - } | |
1511 | - | |
1512 | - XRaiseWindow(m_dpy, window); | |
1513 | - | |
1514 | - XEvent event; | |
1515 | - event.xclient.type = ClientMessage; | |
1516 | - event.xclient.serial = 0; | |
1517 | - event.xclient.send_event = True; | |
1518 | - event.xclient.window = window; | |
1519 | - event.xclient.message_type = m_atomNetActiveWindow; | |
1520 | - event.xclient.format = 32; | |
1521 | - event.xclient.data.l[0] = 1; // FromApplication | |
1522 | - event.xclient.data.l[1] = QX11Info::appUserTime(); | |
1523 | - QWidget* activeWindow = QApplication::activeWindow(); | |
1524 | - if (activeWindow) { | |
1525 | - event.xclient.data.l[2] = activeWindow->internalWinId(); | |
1526 | - } | |
1527 | - else { | |
1528 | - event.xclient.data.l[2] = 0; | |
1529 | - } | |
1530 | - event.xclient.data.l[3] = 0; | |
1531 | - event.xclient.data.l[4] = 0; | |
1532 | - XSendEvent(m_dpy, m_rootWindow, False, | |
1533 | - SubstructureRedirectMask | SubstructureNotifyMask, | |
1534 | - &event); | |
1535 | - XFlush(m_dpy); | |
1536 | - | |
1537 | - return true; | |
1538 | -} | |
1539 | - | |
1540 | -Q_EXPORT_PLUGIN2(keepassx-autotype-x11, AutoTypePlatformX11) | |
1541 | diff --git a/src/autotype/x11/AutoTypeX11.h b/src/autotype/x11/AutoTypeX11.h | |
1542 | deleted file mode 100644 | |
1543 | index 99abb23..0000000 | |
1544 | --- a/src/autotype/x11/AutoTypeX11.h | |
1545 | +++ /dev/null | |
1546 | @@ -1,134 +0,0 @@ | |
1547 | -/* | |
1548 | - * Copyright (C) 2012 Felix Geyer <debfx@fobos.de> | |
1549 | - * Copyright (C) 2000-2008 Tom Sato <VEF00200@nifty.ne.jp> | |
1550 | - * | |
1551 | - * This program is free software: you can redistribute it and/or modify | |
1552 | - * it under the terms of the GNU General Public License as published by | |
1553 | - * the Free Software Foundation, either version 2 or (at your option) | |
1554 | - * version 3 of the License. | |
1555 | - * | |
1556 | - * This program is distributed in the hope that it will be useful, | |
1557 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1558 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1559 | - * GNU General Public License for more details. | |
1560 | - * | |
1561 | - * You should have received a copy of the GNU General Public License | |
1562 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
1563 | - */ | |
1564 | - | |
1565 | -#ifndef KEEPASSX_AUTOTYPEX11_H | |
1566 | -#define KEEPASSX_AUTOTYPEX11_H | |
1567 | - | |
1568 | -#include <QApplication> | |
1569 | -#include <QSet> | |
1570 | -#include <QtPlugin> | |
1571 | -#include <QWidget> | |
1572 | -#include <QX11Info> | |
1573 | - | |
1574 | -#include <X11/Xutil.h> | |
1575 | -#include <X11/extensions/XTest.h> | |
1576 | -#include <X11/XKBlib.h> | |
1577 | - | |
1578 | -#include "autotype/AutoTypePlatformPlugin.h" | |
1579 | -#include "autotype/AutoTypeAction.h" | |
1580 | -#include "core/Global.h" | |
1581 | - | |
1582 | -#define N_MOD_INDICES (Mod5MapIndex + 1) | |
1583 | - | |
1584 | -class AutoTypePlatformX11 : public QObject, public AutoTypePlatformInterface | |
1585 | -{ | |
1586 | - Q_OBJECT | |
1587 | - Q_INTERFACES(AutoTypePlatformInterface) | |
1588 | - | |
1589 | -public: | |
1590 | - AutoTypePlatformX11(); | |
1591 | - bool isAvailable() Q_DECL_OVERRIDE; | |
1592 | - void unload() Q_DECL_OVERRIDE; | |
1593 | - QStringList windowTitles() Q_DECL_OVERRIDE; | |
1594 | - WId activeWindow() Q_DECL_OVERRIDE; | |
1595 | - QString activeWindowTitle() Q_DECL_OVERRIDE; | |
1596 | - bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE; | |
1597 | - void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE; | |
1598 | - int platformEventFilter(void* event) Q_DECL_OVERRIDE; | |
1599 | - int initialTimeout() Q_DECL_OVERRIDE; | |
1600 | - bool raiseWindow(WId window) Q_DECL_OVERRIDE; | |
1601 | - AutoTypeExecutor* createExecutor() Q_DECL_OVERRIDE; | |
1602 | - | |
1603 | - KeySym charToKeySym(const QChar& ch); | |
1604 | - KeySym keyToKeySym(Qt::Key key); | |
1605 | - | |
1606 | - void SendKeyPressedEvent(KeySym keysym); | |
1607 | - | |
1608 | -Q_SIGNALS: | |
1609 | - void globalShortcutTriggered(); | |
1610 | - | |
1611 | -private: | |
1612 | - QString windowTitle(Window window, bool useBlacklist); | |
1613 | - QStringList windowTitlesRecursive(Window window); | |
1614 | - QString windowClassName(Window window); | |
1615 | - QList<Window> widgetsToX11Windows(const QWidgetList& widgetList); | |
1616 | - bool isTopLevelWindow(Window window); | |
1617 | - uint qtToNativeModifiers(Qt::KeyboardModifiers modifiers); | |
1618 | - void startCatchXErrors(); | |
1619 | - void stopCatchXErrors(); | |
1620 | - static int x11ErrorHandler(Display* display, XErrorEvent* error); | |
1621 | - | |
1622 | - XkbDescPtr getKeyboard(); | |
1623 | - void updateKeymap(); | |
1624 | - bool isRemapKeycodeValid(); | |
1625 | - int AddKeysym(KeySym keysym); | |
1626 | - void AddModifier(KeySym keysym); | |
1627 | - void SendEvent(XKeyEvent* event, int event_type); | |
1628 | - void SendModifier(XKeyEvent *event, unsigned int mask, int event_type); | |
1629 | - int GetKeycode(KeySym keysym, unsigned int *mask); | |
1630 | - bool keysymModifiers(KeySym keysym, int keycode, unsigned int *mask); | |
1631 | - | |
1632 | - static int MyErrorHandler(Display* my_dpy, XErrorEvent* event); | |
1633 | - | |
1634 | - Display* m_dpy; | |
1635 | - Window m_rootWindow; | |
1636 | - Atom m_atomWmState; | |
1637 | - Atom m_atomWmName; | |
1638 | - Atom m_atomNetWmName; | |
1639 | - Atom m_atomString; | |
1640 | - Atom m_atomUtf8String; | |
1641 | - Atom m_atomNetActiveWindow; | |
1642 | - QSet<QString> m_classBlacklist; | |
1643 | - Qt::Key m_currentGlobalKey; | |
1644 | - Qt::KeyboardModifiers m_currentGlobalModifiers; | |
1645 | - uint m_currentGlobalKeycode; | |
1646 | - uint m_currentGlobalNativeModifiers; | |
1647 | - int m_modifierMask; | |
1648 | - static bool m_catchXErrors; | |
1649 | - static bool m_xErrorOccured; | |
1650 | - static int (*m_oldXErrorHandler)(Display*, XErrorEvent*); | |
1651 | - | |
1652 | - static const int m_unicodeToKeysymLen; | |
1653 | - static const uint m_unicodeToKeysymKeys[]; | |
1654 | - static const uint m_unicodeToKeysymValues[]; | |
1655 | - | |
1656 | - XkbDescPtr m_xkb; | |
1657 | - KeySym* m_keysymTable; | |
1658 | - int m_minKeycode; | |
1659 | - int m_maxKeycode; | |
1660 | - int m_keysymPerKeycode; | |
1661 | - /* dedicated keycode for remapped keys */ | |
1662 | - unsigned int m_remapKeycode; | |
1663 | - KeySym m_currentRemapKeysym; | |
1664 | - KeyCode m_modifier_keycode[N_MOD_INDICES]; | |
1665 | - bool m_loaded; | |
1666 | -}; | |
1667 | - | |
1668 | -class AutoTypeExecturorX11 : public AutoTypeExecutor | |
1669 | -{ | |
1670 | -public: | |
1671 | - explicit AutoTypeExecturorX11(AutoTypePlatformX11* platform); | |
1672 | - | |
1673 | - void execChar(AutoTypeChar* action) Q_DECL_OVERRIDE; | |
1674 | - void execKey(AutoTypeKey* action) Q_DECL_OVERRIDE; | |
1675 | - | |
1676 | -private: | |
1677 | - AutoTypePlatformX11* const m_platform; | |
1678 | -}; | |
1679 | - | |
1680 | -#endif // KEEPASSX_AUTOTYPEX11_H | |
1681 | diff --git a/src/autotype/x11/CMakeLists.txt b/src/autotype/x11/CMakeLists.txt | |
1682 | deleted file mode 100644 | |
1683 | index cc401f7..0000000 | |
1684 | --- a/src/autotype/x11/CMakeLists.txt | |
1685 | +++ /dev/null | |
1686 | @@ -1,17 +0,0 @@ | |
1687 | -include_directories(SYSTEM ${X11_X11_INCLUDE_PATH}) | |
1688 | - | |
1689 | -set(autotype_X11_SOURCES | |
1690 | - AutoTypeX11.cpp | |
1691 | -) | |
1692 | - | |
1693 | -set(autotype_X11_MOC | |
1694 | - AutoTypeX11.h | |
1695 | -) | |
1696 | - | |
1697 | -qt4_wrap_cpp(autotype_X11_SOURCES ${autotype_X11_MOC}) | |
1698 | - | |
1699 | -add_library(keepassx-autotype-x11 MODULE ${autotype_X11_SOURCES}) | |
1700 | -target_link_libraries(keepassx-autotype-x11 ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${X11_X11_LIB} ${X11_Xi_LIB} ${X11_XTest_LIB}) | |
1701 | -install(TARGETS keepassx-autotype-x11 | |
1702 | - BUNDLE DESTINATION . COMPONENT Runtime | |
1703 | - LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime) | |
1704 | diff --git a/src/autotype/x11/KeySymMap.h b/src/autotype/x11/KeySymMap.h | |
1705 | deleted file mode 100644 | |
1706 | index 55022fe..0000000 | |
1707 | --- a/src/autotype/x11/KeySymMap.h | |
1708 | +++ /dev/null | |
1709 | @@ -1,169 +0,0 @@ | |
1710 | -/* | |
1711 | - * Automatically generated by keysymmap.py from parsing keysymdef.h. | |
1712 | - */ | |
1713 | - | |
1714 | -const int AutoTypePlatformX11::m_unicodeToKeysymLen = 632; | |
1715 | - | |
1716 | -const uint AutoTypePlatformX11::m_unicodeToKeysymKeys[] = { | |
1717 | - 0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, | |
1718 | - 0x0108, 0x0109, 0x010a, 0x010b, 0x010c, 0x010d, 0x010e, 0x010f, | |
1719 | - 0x0110, 0x0111, 0x0112, 0x0113, 0x0116, 0x0117, 0x0118, 0x0119, | |
1720 | - 0x011a, 0x011b, 0x011c, 0x011d, 0x011e, 0x011f, 0x0120, 0x0121, | |
1721 | - 0x0122, 0x0123, 0x0124, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, | |
1722 | - 0x012a, 0x012b, 0x012e, 0x012f, 0x0130, 0x0131, 0x0134, 0x0135, | |
1723 | - 0x0136, 0x0137, 0x0138, 0x0139, 0x013a, 0x013b, 0x013c, 0x013d, | |
1724 | - 0x013e, 0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0147, | |
1725 | - 0x0148, 0x014a, 0x014b, 0x014c, 0x014d, 0x0150, 0x0151, 0x0152, | |
1726 | - 0x0153, 0x0154, 0x0155, 0x0156, 0x0157, 0x0158, 0x0159, 0x015a, | |
1727 | - 0x015b, 0x015c, 0x015d, 0x015e, 0x015f, 0x0160, 0x0161, 0x0162, | |
1728 | - 0x0163, 0x0164, 0x0165, 0x0166, 0x0167, 0x0168, 0x0169, 0x016a, | |
1729 | - 0x016b, 0x016c, 0x016d, 0x016e, 0x016f, 0x0170, 0x0171, 0x0172, | |
1730 | - 0x0173, 0x0178, 0x0179, 0x017a, 0x017b, 0x017c, 0x017d, 0x017e, | |
1731 | - 0x0192, 0x02c7, 0x02d8, 0x02d9, 0x02db, 0x02dd, 0x0385, 0x0386, | |
1732 | - 0x0388, 0x0389, 0x038a, 0x038c, 0x038e, 0x038f, 0x0390, 0x0391, | |
1733 | - 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, | |
1734 | - 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, 0x03a0, 0x03a1, | |
1735 | - 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9, 0x03aa, | |
1736 | - 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af, 0x03b0, 0x03b1, 0x03b2, | |
1737 | - 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, | |
1738 | - 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, 0x03c0, 0x03c1, 0x03c2, | |
1739 | - 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x03ca, | |
1740 | - 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0401, 0x0402, 0x0403, 0x0404, | |
1741 | - 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, | |
1742 | - 0x040e, 0x040f, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, | |
1743 | - 0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, | |
1744 | - 0x041e, 0x041f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, | |
1745 | - 0x0426, 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, | |
1746 | - 0x042e, 0x042f, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, | |
1747 | - 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, | |
1748 | - 0x043e, 0x043f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, | |
1749 | - 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, | |
1750 | - 0x044e, 0x044f, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, | |
1751 | - 0x0457, 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x045e, 0x045f, | |
1752 | - 0x0490, 0x0491, 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, | |
1753 | - 0x05d6, 0x05d7, 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, | |
1754 | - 0x05de, 0x05df, 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, | |
1755 | - 0x05e6, 0x05e7, 0x05e8, 0x05e9, 0x05ea, 0x060c, 0x061b, 0x061f, | |
1756 | - 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, 0x0628, | |
1757 | - 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f, 0x0630, | |
1758 | - 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, 0x0638, | |
1759 | - 0x0639, 0x063a, 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, | |
1760 | - 0x0646, 0x0647, 0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, | |
1761 | - 0x064e, 0x064f, 0x0650, 0x0651, 0x0652, 0x0e01, 0x0e02, 0x0e03, | |
1762 | - 0x0e04, 0x0e05, 0x0e06, 0x0e07, 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, | |
1763 | - 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, 0x0e10, 0x0e11, 0x0e12, 0x0e13, | |
1764 | - 0x0e14, 0x0e15, 0x0e16, 0x0e17, 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, | |
1765 | - 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, 0x0e20, 0x0e21, 0x0e22, 0x0e23, | |
1766 | - 0x0e24, 0x0e25, 0x0e26, 0x0e27, 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, | |
1767 | - 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, 0x0e30, 0x0e31, 0x0e32, 0x0e33, | |
1768 | - 0x0e34, 0x0e35, 0x0e36, 0x0e37, 0x0e38, 0x0e39, 0x0e3a, 0x0e3f, | |
1769 | - 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, | |
1770 | - 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e50, 0x0e51, | |
1771 | - 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, 0x0e58, 0x0e59, | |
1772 | - 0x2002, 0x2003, 0x2004, 0x2005, 0x2007, 0x2008, 0x2009, 0x200a, | |
1773 | - 0x2012, 0x2013, 0x2014, 0x2015, 0x2017, 0x2018, 0x2019, 0x201a, | |
1774 | - 0x201c, 0x201d, 0x201e, 0x2020, 0x2021, 0x2025, 0x2026, 0x2030, | |
1775 | - 0x2032, 0x2033, 0x2038, 0x203e, 0x20ac, 0x2105, 0x2116, 0x2117, | |
1776 | - 0x211e, 0x2122, 0x2153, 0x2154, 0x2155, 0x2156, 0x2157, 0x2158, | |
1777 | - 0x2159, 0x215a, 0x215b, 0x215c, 0x215d, 0x215e, 0x2190, 0x2191, | |
1778 | - 0x2192, 0x2193, 0x21d2, 0x21d4, 0x2202, 0x2207, 0x2218, 0x221a, | |
1779 | - 0x221d, 0x221e, 0x2227, 0x2228, 0x2229, 0x222a, 0x222b, 0x2234, | |
1780 | - 0x223c, 0x2243, 0x2260, 0x2261, 0x2264, 0x2265, 0x2282, 0x2283, | |
1781 | - 0x22a2, 0x22a3, 0x22a4, 0x22a5, 0x2308, 0x230a, 0x2315, 0x2320, | |
1782 | - 0x2321, 0x2395, 0x239b, 0x239d, 0x239e, 0x23a0, 0x23a1, 0x23a3, | |
1783 | - 0x23a4, 0x23a6, 0x23a8, 0x23ac, 0x23b7, 0x23ba, 0x23bb, 0x23bc, | |
1784 | - 0x23bd, 0x2409, 0x240a, 0x240b, 0x240c, 0x240d, 0x2424, 0x2500, | |
1785 | - 0x2502, 0x250c, 0x2510, 0x2514, 0x2518, 0x251c, 0x2524, 0x252c, | |
1786 | - 0x2534, 0x253c, 0x2592, 0x25c6, 0x25cb, 0x260e, 0x2640, 0x2642, | |
1787 | - 0x2663, 0x2665, 0x2666, 0x266d, 0x266f, 0x2713, 0x2717, 0x271d, | |
1788 | - 0x2720, 0x3001, 0x3002, 0x300c, 0x300d, 0x309b, 0x309c, 0x30a1, | |
1789 | - 0x30a2, 0x30a3, 0x30a4, 0x30a5, 0x30a6, 0x30a7, 0x30a8, 0x30a9, | |
1790 | - 0x30aa, 0x30ab, 0x30ad, 0x30af, 0x30b1, 0x30b3, 0x30b5, 0x30b7, | |
1791 | - 0x30b9, 0x30bb, 0x30bd, 0x30bf, 0x30c1, 0x30c3, 0x30c4, 0x30c6, | |
1792 | - 0x30c8, 0x30ca, 0x30cb, 0x30cc, 0x30cd, 0x30ce, 0x30cf, 0x30d2, | |
1793 | - 0x30d5, 0x30d8, 0x30db, 0x30de, 0x30df, 0x30e0, 0x30e1, 0x30e2, | |
1794 | - 0x30e3, 0x30e4, 0x30e5, 0x30e6, 0x30e7, 0x30e8, 0x30e9, 0x30ea, | |
1795 | - 0x30eb, 0x30ec, 0x30ed, 0x30ef, 0x30f2, 0x30f3, 0x30fb, 0x30fc | |
1796 | -}; | |
1797 | - | |
1798 | -const uint AutoTypePlatformX11::m_unicodeToKeysymValues[] = { | |
1799 | - 0x03c0, 0x03e0, 0x01c3, 0x01e3, 0x01a1, 0x01b1, 0x01c6, 0x01e6, | |
1800 | - 0x02c6, 0x02e6, 0x02c5, 0x02e5, 0x01c8, 0x01e8, 0x01cf, 0x01ef, | |
1801 | - 0x01d0, 0x01f0, 0x03aa, 0x03ba, 0x03cc, 0x03ec, 0x01ca, 0x01ea, | |
1802 | - 0x01cc, 0x01ec, 0x02d8, 0x02f8, 0x02ab, 0x02bb, 0x02d5, 0x02f5, | |
1803 | - 0x03ab, 0x03bb, 0x02a6, 0x02b6, 0x02a1, 0x02b1, 0x03a5, 0x03b5, | |
1804 | - 0x03cf, 0x03ef, 0x03c7, 0x03e7, 0x02a9, 0x02b9, 0x02ac, 0x02bc, | |
1805 | - 0x03d3, 0x03f3, 0x03a2, 0x01c5, 0x01e5, 0x03a6, 0x03b6, 0x01a5, | |
1806 | - 0x01b5, 0x01a3, 0x01b3, 0x01d1, 0x01f1, 0x03d1, 0x03f1, 0x01d2, | |
1807 | - 0x01f2, 0x03bd, 0x03bf, 0x03d2, 0x03f2, 0x01d5, 0x01f5, 0x13bc, | |
1808 | - 0x13bd, 0x01c0, 0x01e0, 0x03a3, 0x03b3, 0x01d8, 0x01f8, 0x01a6, | |
1809 | - 0x01b6, 0x02de, 0x02fe, 0x01aa, 0x01ba, 0x01a9, 0x01b9, 0x01de, | |
1810 | - 0x01fe, 0x01ab, 0x01bb, 0x03ac, 0x03bc, 0x03dd, 0x03fd, 0x03de, | |
1811 | - 0x03fe, 0x02dd, 0x02fd, 0x01d9, 0x01f9, 0x01db, 0x01fb, 0x03d9, | |
1812 | - 0x03f9, 0x13be, 0x01ac, 0x01bc, 0x01af, 0x01bf, 0x01ae, 0x01be, | |
1813 | - 0x08f6, 0x01b7, 0x01a2, 0x01ff, 0x01b2, 0x01bd, 0x07ae, 0x07a1, | |
1814 | - 0x07a2, 0x07a3, 0x07a4, 0x07a7, 0x07a8, 0x07ab, 0x07b6, 0x07c1, | |
1815 | - 0x07c2, 0x07c3, 0x07c4, 0x07c5, 0x07c6, 0x07c7, 0x07c8, 0x07c9, | |
1816 | - 0x07ca, 0x07cb, 0x07cc, 0x07cd, 0x07ce, 0x07cf, 0x07d0, 0x07d1, | |
1817 | - 0x07d2, 0x07d4, 0x07d5, 0x07d6, 0x07d7, 0x07d8, 0x07d9, 0x07a5, | |
1818 | - 0x07a9, 0x07b1, 0x07b2, 0x07b3, 0x07b4, 0x07ba, 0x07e1, 0x07e2, | |
1819 | - 0x07e3, 0x07e4, 0x07e5, 0x07e6, 0x07e7, 0x07e8, 0x07e9, 0x07ea, | |
1820 | - 0x07eb, 0x07ec, 0x07ed, 0x07ee, 0x07ef, 0x07f0, 0x07f1, 0x07f3, | |
1821 | - 0x07f2, 0x07f4, 0x07f5, 0x07f6, 0x07f7, 0x07f8, 0x07f9, 0x07b5, | |
1822 | - 0x07b9, 0x07b7, 0x07b8, 0x07bb, 0x06b3, 0x06b1, 0x06b2, 0x06b4, | |
1823 | - 0x06b5, 0x06b6, 0x06b7, 0x06b8, 0x06b9, 0x06ba, 0x06bb, 0x06bc, | |
1824 | - 0x06be, 0x06bf, 0x06e1, 0x06e2, 0x06f7, 0x06e7, 0x06e4, 0x06e5, | |
1825 | - 0x06f6, 0x06fa, 0x06e9, 0x06ea, 0x06eb, 0x06ec, 0x06ed, 0x06ee, | |
1826 | - 0x06ef, 0x06f0, 0x06f2, 0x06f3, 0x06f4, 0x06f5, 0x06e6, 0x06e8, | |
1827 | - 0x06e3, 0x06fe, 0x06fb, 0x06fd, 0x06ff, 0x06f9, 0x06f8, 0x06fc, | |
1828 | - 0x06e0, 0x06f1, 0x06c1, 0x06c2, 0x06d7, 0x06c7, 0x06c4, 0x06c5, | |
1829 | - 0x06d6, 0x06da, 0x06c9, 0x06ca, 0x06cb, 0x06cc, 0x06cd, 0x06ce, | |
1830 | - 0x06cf, 0x06d0, 0x06d2, 0x06d3, 0x06d4, 0x06d5, 0x06c6, 0x06c8, | |
1831 | - 0x06c3, 0x06de, 0x06db, 0x06dd, 0x06df, 0x06d9, 0x06d8, 0x06dc, | |
1832 | - 0x06c0, 0x06d1, 0x06a3, 0x06a1, 0x06a2, 0x06a4, 0x06a5, 0x06a6, | |
1833 | - 0x06a7, 0x06a8, 0x06a9, 0x06aa, 0x06ab, 0x06ac, 0x06ae, 0x06af, | |
1834 | - 0x06bd, 0x06ad, 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, | |
1835 | - 0x0ce6, 0x0ce7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, | |
1836 | - 0x0cee, 0x0cef, 0x0cf0, 0x0cf1, 0x0cf2, 0x0cf3, 0x0cf4, 0x0cf5, | |
1837 | - 0x0cf6, 0x0cf7, 0x0cf8, 0x0cf9, 0x0cfa, 0x05ac, 0x05bb, 0x05bf, | |
1838 | - 0x05c1, 0x05c2, 0x05c3, 0x05c4, 0x05c5, 0x05c6, 0x05c7, 0x05c8, | |
1839 | - 0x05c9, 0x05ca, 0x05cb, 0x05cc, 0x05cd, 0x05ce, 0x05cf, 0x05d0, | |
1840 | - 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, 0x05d8, | |
1841 | - 0x05d9, 0x05da, 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, | |
1842 | - 0x05e6, 0x05e7, 0x05e8, 0x05e9, 0x05ea, 0x05eb, 0x05ec, 0x05ed, | |
1843 | - 0x05ee, 0x05ef, 0x05f0, 0x05f1, 0x05f2, 0x0da1, 0x0da2, 0x0da3, | |
1844 | - 0x0da4, 0x0da5, 0x0da6, 0x0da7, 0x0da8, 0x0da9, 0x0daa, 0x0dab, | |
1845 | - 0x0dac, 0x0dad, 0x0dae, 0x0daf, 0x0db0, 0x0db1, 0x0db2, 0x0db3, | |
1846 | - 0x0db4, 0x0db5, 0x0db6, 0x0db7, 0x0db8, 0x0db9, 0x0dba, 0x0dbb, | |
1847 | - 0x0dbc, 0x0dbd, 0x0dbe, 0x0dbf, 0x0dc0, 0x0dc1, 0x0dc2, 0x0dc3, | |
1848 | - 0x0dc4, 0x0dc5, 0x0dc6, 0x0dc7, 0x0dc8, 0x0dc9, 0x0dca, 0x0dcb, | |
1849 | - 0x0dcc, 0x0dcd, 0x0dce, 0x0dcf, 0x0dd0, 0x0dd1, 0x0dd2, 0x0dd3, | |
1850 | - 0x0dd4, 0x0dd5, 0x0dd6, 0x0dd7, 0x0dd8, 0x0dd9, 0x0dda, 0x0ddf, | |
1851 | - 0x0de0, 0x0de1, 0x0de2, 0x0de3, 0x0de4, 0x0de5, 0x0de6, 0x0de7, | |
1852 | - 0x0de8, 0x0de9, 0x0dea, 0x0deb, 0x0dec, 0x0ded, 0x0df0, 0x0df1, | |
1853 | - 0x0df2, 0x0df3, 0x0df4, 0x0df5, 0x0df6, 0x0df7, 0x0df8, 0x0df9, | |
1854 | - 0x0aa2, 0x0aa1, 0x0aa3, 0x0aa4, 0x0aa5, 0x0aa6, 0x0aa7, 0x0aa8, | |
1855 | - 0x0abb, 0x0aaa, 0x0aa9, 0x07af, 0x0cdf, 0x0ad0, 0x0ad1, 0x0afd, | |
1856 | - 0x0ad2, 0x0ad3, 0x0afe, 0x0af1, 0x0af2, 0x0aaf, 0x0aae, 0x0ad5, | |
1857 | - 0x0ad6, 0x0ad7, 0x0afc, 0x047e, 0x20ac, 0x0ab8, 0x06b0, 0x0afb, | |
1858 | - 0x0ad4, 0x0ac9, 0x0ab0, 0x0ab1, 0x0ab2, 0x0ab3, 0x0ab4, 0x0ab5, | |
1859 | - 0x0ab6, 0x0ab7, 0x0ac3, 0x0ac4, 0x0ac5, 0x0ac6, 0x08fb, 0x08fc, | |
1860 | - 0x08fd, 0x08fe, 0x08ce, 0x08cd, 0x08ef, 0x08c5, 0x0bca, 0x08d6, | |
1861 | - 0x08c1, 0x08c2, 0x08de, 0x08df, 0x08dc, 0x08dd, 0x08bf, 0x08c0, | |
1862 | - 0x08c8, 0x08c9, 0x08bd, 0x08cf, 0x08bc, 0x08be, 0x08da, 0x08db, | |
1863 | - 0x0bfc, 0x0bdc, 0x0bc2, 0x0bce, 0x0bd3, 0x0bc4, 0x0afa, 0x08a4, | |
1864 | - 0x08a5, 0x0bcc, 0x08ab, 0x08ac, 0x08ad, 0x08ae, 0x08a7, 0x08a8, | |
1865 | - 0x08a9, 0x08aa, 0x08af, 0x08b0, 0x08a1, 0x09ef, 0x09f0, 0x09f2, | |
1866 | - 0x09f3, 0x09e2, 0x09e5, 0x09e9, 0x09e3, 0x09e4, 0x09e8, 0x09f1, | |
1867 | - 0x09f8, 0x09ec, 0x09eb, 0x09ed, 0x09ea, 0x09f4, 0x09f5, 0x09f7, | |
1868 | - 0x09f6, 0x09ee, 0x09e1, 0x09e0, 0x0bcf, 0x0af9, 0x0af8, 0x0af7, | |
1869 | - 0x0aec, 0x0aee, 0x0aed, 0x0af6, 0x0af5, 0x0af3, 0x0af4, 0x0ad9, | |
1870 | - 0x0af0, 0x04a4, 0x04a1, 0x04a2, 0x04a3, 0x04de, 0x04df, 0x04a7, | |
1871 | - 0x04b1, 0x04a8, 0x04b2, 0x04a9, 0x04b3, 0x04aa, 0x04b4, 0x04ab, | |
1872 | - 0x04b5, 0x04b6, 0x04b7, 0x04b8, 0x04b9, 0x04ba, 0x04bb, 0x04bc, | |
1873 | - 0x04bd, 0x04be, 0x04bf, 0x04c0, 0x04c1, 0x04af, 0x04c2, 0x04c3, | |
1874 | - 0x04c4, 0x04c5, 0x04c6, 0x04c7, 0x04c8, 0x04c9, 0x04ca, 0x04cb, | |
1875 | - 0x04cc, 0x04cd, 0x04ce, 0x04cf, 0x04d0, 0x04d1, 0x04d2, 0x04d3, | |
1876 | - 0x04ac, 0x04d4, 0x04ad, 0x04d5, 0x04ae, 0x04d6, 0x04d7, 0x04d8, | |
1877 | - 0x04d9, 0x04da, 0x04db, 0x04dc, 0x04a6, 0x04dd, 0x04a5, 0x04b0 | |
1878 | -}; | |
1879 | diff --git a/src/autotype/x11/keysymmap.py b/src/autotype/x11/keysymmap.py | |
1880 | deleted file mode 100755 | |
1881 | index a359710..0000000 | |
1882 | --- a/src/autotype/x11/keysymmap.py | |
1883 | +++ /dev/null | |
1884 | @@ -1,107 +0,0 @@ | |
1885 | -#!/usr/bin/python3 | |
1886 | - | |
1887 | -# | |
1888 | -# Copyright (C) 2013 Felix Geyer <debfx@fobos.de> | |
1889 | -# | |
1890 | -# This program is free software: you can redistribute it and/or modify | |
1891 | -# it under the terms of the GNU General Public License as published by | |
1892 | -# the Free Software Foundation, either version 2 or (at your option) | |
1893 | -# version 3 of the License. | |
1894 | -# | |
1895 | -# This program is distributed in the hope that it will be useful, | |
1896 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1897 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1898 | -# GNU General Public License for more details. | |
1899 | -# | |
1900 | -# You should have received a copy of the GNU General Public License | |
1901 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
1902 | -# | |
1903 | - | |
1904 | -# | |
1905 | -# Parses keysymdef.h to construct a unicode symbol -> keysym mapping table. | |
1906 | -# | |
1907 | -# The lines that are parsed look like this: | |
1908 | -# #define XK_Aogonek 0x01a1 /* U+0104 LATIN CAPITAL LETTER A WITH OGONEK */ | |
1909 | -# | |
1910 | -# This would create a 0x0104 -> 0x01a1 mapping. | |
1911 | -# | |
1912 | - | |
1913 | -import sys | |
1914 | -import re | |
1915 | -import collections | |
1916 | - | |
1917 | -cols = 8 | |
1918 | - | |
1919 | -if len(sys.argv) >= 2: | |
1920 | - keysymdef = sys.argv[1] | |
1921 | -else: | |
1922 | - keysymdef = "/usr/include/X11/keysymdef.h" | |
1923 | - | |
1924 | -keysymMap = {} | |
1925 | - | |
1926 | -f = open(keysymdef, "r") | |
1927 | -for line in f: | |
1928 | - match = re.search(r'0x([0-9a-fA-F]+)\s+/\* U\+([0-9a-fA-F]+)', line) | |
1929 | - if match: | |
1930 | - keysym = int(match.group(1), 16) | |
1931 | - unicodeVal = int(match.group(2), 16) | |
1932 | - | |
1933 | - # ignore 1:1 mappings | |
1934 | - if keysym >= 0x0020 and keysym <= 0x007e: | |
1935 | - continue | |
1936 | - if keysym >= 0x00a0 and keysym <= 0x00ff: | |
1937 | - continue | |
1938 | - # ignore unicode | 0x01000000 mappings | |
1939 | - if keysym >= 0x1000000: | |
1940 | - continue | |
1941 | - | |
1942 | - keysymMap[unicodeVal] = keysym | |
1943 | - | |
1944 | -keysymMap = collections.OrderedDict(sorted(keysymMap.items(), key=lambda t: t[0])) | |
1945 | - | |
1946 | -print("""/* | |
1947 | - * Automatically generated by keysymmap.py from parsing keysymdef.h. | |
1948 | - */ | |
1949 | -""") | |
1950 | - | |
1951 | -print("const int AutoTypePlatformX11::m_unicodeToKeysymLen = " + str(len(keysymMap)) + ";") | |
1952 | - | |
1953 | -print() | |
1954 | - | |
1955 | -print("const uint AutoTypePlatformX11::m_unicodeToKeysymKeys[] = {") | |
1956 | -keys = keysymMap.keys() | |
1957 | -keyLen = len(keys) | |
1958 | -i = 1 | |
1959 | -for val in keys: | |
1960 | - hexVal = "{0:#0{1}x}".format(val, 6) | |
1961 | - | |
1962 | - if i == keyLen: | |
1963 | - print(hexVal) | |
1964 | - elif (i % cols) == 0: | |
1965 | - print(hexVal + ",") | |
1966 | - elif ((i - 1) % cols) == 0: | |
1967 | - print(" " + hexVal + ", ", end="") | |
1968 | - else: | |
1969 | - print(hexVal + ", ", end="") | |
1970 | - i += 1 | |
1971 | -print("};") | |
1972 | - | |
1973 | -print() | |
1974 | - | |
1975 | -print("const uint AutoTypePlatformX11::m_unicodeToKeysymValues[] = {") | |
1976 | -values = keysymMap.values() | |
1977 | -valuesLen = len(values) | |
1978 | -i = 1 | |
1979 | -for val in values: | |
1980 | - hexVal = "{0:#0{1}x}".format(val, 6) | |
1981 | - | |
1982 | - if i == valuesLen: | |
1983 | - print(hexVal) | |
1984 | - elif (i % cols) == 0: | |
1985 | - print(hexVal + ",") | |
1986 | - elif ((i - 1) % cols) == 0: | |
1987 | - print(" " + hexVal + ", ", end="") | |
1988 | - else: | |
1989 | - print(hexVal + ", ", end="") | |
1990 | - i += 1 | |
1991 | -print("};") | |
1992 | diff --git a/src/autotype/xcb/AutoTypeXCB.cpp b/src/autotype/xcb/AutoTypeXCB.cpp | |
1993 | new file mode 100644 | |
1994 | index 0000000..40acaf6 | |
1995 | --- /dev/null | |
1996 | +++ b/src/autotype/xcb/AutoTypeXCB.cpp | |
1997 | @@ -0,0 +1,870 @@ | |
1998 | +/* | |
1999 | + * Copyright (C) 2012 Felix Geyer <debfx@fobos.de> | |
2000 | + * Copyright (C) 2000-2008 Tom Sato <VEF00200@nifty.ne.jp> | |
2001 | + * | |
2002 | + * This program is free software: you can redistribute it and/or modify | |
2003 | + * it under the terms of the GNU General Public License as published by | |
2004 | + * the Free Software Foundation, either version 2 or (at your option) | |
2005 | + * version 3 of the License. | |
2006 | + * | |
2007 | + * This program is distributed in the hope that it will be useful, | |
2008 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2009 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2010 | + * GNU General Public License for more details. | |
2011 | + * | |
2012 | + * You should have received a copy of the GNU General Public License | |
2013 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
2014 | + */ | |
2015 | + | |
2016 | +#include "AutoTypeXCB.h" | |
2017 | +#include "KeySymMap.h" | |
2018 | +#include "core/Tools.h" | |
2019 | + | |
2020 | +#include <time.h> | |
2021 | +#include <xcb/xcb.h> | |
2022 | + | |
2023 | +bool AutoTypePlatformX11::m_catchXErrors = false; | |
2024 | +bool AutoTypePlatformX11::m_xErrorOccured = false; | |
2025 | +int (*AutoTypePlatformX11::m_oldXErrorHandler)(Display*, XErrorEvent*) = nullptr; | |
2026 | + | |
2027 | +AutoTypePlatformX11::AutoTypePlatformX11() | |
2028 | +{ | |
2029 | + m_dpy = QX11Info::display(); | |
2030 | + m_rootWindow = QX11Info::appRootWindow(); | |
2031 | + | |
2032 | + m_atomWmState = XInternAtom(m_dpy, "WM_STATE", True); | |
2033 | + m_atomWmName = XInternAtom(m_dpy, "WM_NAME", True); | |
2034 | + m_atomNetWmName = XInternAtom(m_dpy, "_NET_WM_NAME", True); | |
2035 | + m_atomString = XInternAtom(m_dpy, "STRING", True); | |
2036 | + m_atomUtf8String = XInternAtom(m_dpy, "UTF8_STRING", True); | |
2037 | + m_atomNetActiveWindow = XInternAtom(m_dpy, "_NET_ACTIVE_WINDOW", True); | |
2038 | + | |
2039 | + m_classBlacklist << "desktop_window" << "gnome-panel"; // Gnome | |
2040 | + m_classBlacklist << "kdesktop" << "kicker"; // KDE 3 | |
2041 | + m_classBlacklist << "Plasma"; // KDE 4 | |
2042 | + m_classBlacklist << "plasmashell"; // KDE 5 | |
2043 | + m_classBlacklist << "xfdesktop" << "xfce4-panel"; // Xfce 4 | |
2044 | + | |
2045 | + m_currentGlobalKey = static_cast<Qt::Key>(0); | |
2046 | + m_currentGlobalModifiers = 0; | |
2047 | + | |
2048 | + m_keysymTable = nullptr; | |
2049 | + m_xkb = nullptr; | |
2050 | + m_remapKeycode = 0; | |
2051 | + m_currentRemapKeysym = NoSymbol; | |
2052 | + m_modifierMask = ControlMask | ShiftMask | Mod1Mask | Mod4Mask; | |
2053 | + | |
2054 | + m_loaded = true; | |
2055 | + | |
2056 | + updateKeymap(); | |
2057 | +} | |
2058 | + | |
2059 | +bool AutoTypePlatformX11::isAvailable() | |
2060 | +{ | |
2061 | + int ignore; | |
2062 | + | |
2063 | + if (!XQueryExtension(m_dpy, "XInputExtension", &ignore, &ignore, &ignore)) { | |
2064 | + return false; | |
2065 | + } | |
2066 | + | |
2067 | + if (!XQueryExtension(m_dpy, "XTEST", &ignore, &ignore, &ignore)) { | |
2068 | + return false; | |
2069 | + } | |
2070 | + | |
2071 | + if (!m_xkb) { | |
2072 | + XkbDescPtr kbd = getKeyboard(); | |
2073 | + | |
2074 | + if (!kbd) { | |
2075 | + return false; | |
2076 | + } | |
2077 | + | |
2078 | + XkbFreeKeyboard(kbd, XkbAllComponentsMask, True); | |
2079 | + } | |
2080 | + | |
2081 | + return true; | |
2082 | +} | |
2083 | + | |
2084 | +void AutoTypePlatformX11::unload() | |
2085 | +{ | |
2086 | + // Restore the KeyboardMapping to its original state. | |
2087 | + if (m_currentRemapKeysym != NoSymbol) { | |
2088 | + AddKeysym(NoSymbol); | |
2089 | + } | |
2090 | + | |
2091 | + if (m_keysymTable) { | |
2092 | + XFree(m_keysymTable); | |
2093 | + } | |
2094 | + | |
2095 | + if (m_xkb) { | |
2096 | + XkbFreeKeyboard(m_xkb, XkbAllComponentsMask, True); | |
2097 | + } | |
2098 | + | |
2099 | + m_loaded = false; | |
2100 | +} | |
2101 | + | |
2102 | +QStringList AutoTypePlatformX11::windowTitles() | |
2103 | +{ | |
2104 | + return windowTitlesRecursive(m_rootWindow); | |
2105 | +} | |
2106 | + | |
2107 | +WId AutoTypePlatformX11::activeWindow() | |
2108 | +{ | |
2109 | + Window window; | |
2110 | + int revert_to_return; | |
2111 | + XGetInputFocus(m_dpy, &window, &revert_to_return); | |
2112 | + | |
2113 | + int tree; | |
2114 | + do { | |
2115 | + if (isTopLevelWindow(window)) { | |
2116 | + break; | |
2117 | + } | |
2118 | + | |
2119 | + Window root; | |
2120 | + Window parent; | |
2121 | + Window* children = nullptr; | |
2122 | + unsigned int numChildren; | |
2123 | + tree = XQueryTree(m_dpy, window, &root, &parent, &children, &numChildren); | |
2124 | + window = parent; | |
2125 | + if (children) { | |
2126 | + XFree(children); | |
2127 | + } | |
2128 | + } while (tree && window); | |
2129 | + | |
2130 | + return window; | |
2131 | +} | |
2132 | + | |
2133 | +QString AutoTypePlatformX11::activeWindowTitle() | |
2134 | +{ | |
2135 | + return windowTitle(activeWindow(), true); | |
2136 | +} | |
2137 | + | |
2138 | +bool AutoTypePlatformX11::registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) | |
2139 | +{ | |
2140 | + int keycode = XKeysymToKeycode(m_dpy, charToKeySym(key)); | |
2141 | + uint nativeModifiers = qtToNativeModifiers(modifiers); | |
2142 | + | |
2143 | + startCatchXErrors(); | |
2144 | + XGrabKey(m_dpy, keycode, nativeModifiers, m_rootWindow, True, GrabModeAsync, GrabModeAsync); | |
2145 | + XGrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask, m_rootWindow, True, GrabModeAsync, | |
2146 | + GrabModeAsync); | |
2147 | + XGrabKey(m_dpy, keycode, nativeModifiers | LockMask, m_rootWindow, True, GrabModeAsync, | |
2148 | + GrabModeAsync); | |
2149 | + XGrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask | LockMask, m_rootWindow, True, | |
2150 | + GrabModeAsync, GrabModeAsync); | |
2151 | + stopCatchXErrors(); | |
2152 | + | |
2153 | + if (!m_xErrorOccured) { | |
2154 | + m_currentGlobalKey = key; | |
2155 | + m_currentGlobalModifiers = modifiers; | |
2156 | + m_currentGlobalKeycode = keycode; | |
2157 | + m_currentGlobalNativeModifiers = nativeModifiers; | |
2158 | + return true; | |
2159 | + } | |
2160 | + else { | |
2161 | + unregisterGlobalShortcut(key, modifiers); | |
2162 | + return false; | |
2163 | + } | |
2164 | +} | |
2165 | + | |
2166 | +uint AutoTypePlatformX11::qtToNativeModifiers(Qt::KeyboardModifiers modifiers) | |
2167 | +{ | |
2168 | + uint nativeModifiers = 0; | |
2169 | + | |
2170 | + if (modifiers & Qt::ShiftModifier) { | |
2171 | + nativeModifiers |= ShiftMask; | |
2172 | + } | |
2173 | + if (modifiers & Qt::ControlModifier) { | |
2174 | + nativeModifiers |= ControlMask; | |
2175 | + } | |
2176 | + if (modifiers & Qt::AltModifier) { | |
2177 | + nativeModifiers |= Mod1Mask; | |
2178 | + } | |
2179 | + if (modifiers & Qt::MetaModifier) { | |
2180 | + nativeModifiers |= Mod4Mask; | |
2181 | + } | |
2182 | + | |
2183 | + return nativeModifiers; | |
2184 | +} | |
2185 | + | |
2186 | +void AutoTypePlatformX11::unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) | |
2187 | +{ | |
2188 | + KeyCode keycode = XKeysymToKeycode(m_dpy, charToKeySym(key)); | |
2189 | + uint nativeModifiers = qtToNativeModifiers(modifiers); | |
2190 | + | |
2191 | + XUngrabKey(m_dpy, keycode, nativeModifiers, m_rootWindow); | |
2192 | + XUngrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask, m_rootWindow); | |
2193 | + XUngrabKey(m_dpy, keycode, nativeModifiers | LockMask, m_rootWindow); | |
2194 | + XUngrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask | LockMask, m_rootWindow); | |
2195 | + | |
2196 | + m_currentGlobalKey = static_cast<Qt::Key>(0); | |
2197 | + m_currentGlobalModifiers = 0; | |
2198 | + m_currentGlobalKeycode = 0; | |
2199 | + m_currentGlobalNativeModifiers = 0; | |
2200 | +} | |
2201 | + | |
2202 | +int AutoTypePlatformX11::platformEventFilter(void* event) | |
2203 | +{ | |
2204 | + xcb_generic_event_t* genericEvent = static_cast<xcb_generic_event_t*>(event); | |
2205 | + quint8 type = genericEvent->response_type & 0x7f; | |
2206 | + | |
2207 | + if (type == XCB_KEY_PRESS || type == XCB_KEY_RELEASE) { | |
2208 | + xcb_key_press_event_t* keyPressEvent = static_cast<xcb_key_press_event_t*>(event); | |
2209 | + if (keyPressEvent->detail == m_currentGlobalKeycode | |
2210 | + && (keyPressEvent->state & m_modifierMask) == m_currentGlobalNativeModifiers | |
2211 | + && (!QApplication::activeWindow() || QApplication::activeWindow()->isMinimized()) | |
2212 | + && m_loaded) { | |
2213 | + if (type == XCB_KEY_PRESS) { | |
2214 | + Q_EMIT globalShortcutTriggered(); | |
2215 | + } | |
2216 | + | |
2217 | + return 1; | |
2218 | + } | |
2219 | + } | |
2220 | + else if (type == XCB_MAPPING_NOTIFY) { | |
2221 | + xcb_mapping_notify_event_t* mappingNotifyEvent = static_cast<xcb_mapping_notify_event_t*>(event); | |
2222 | + if (mappingNotifyEvent->request == XCB_MAPPING_KEYBOARD | |
2223 | + || mappingNotifyEvent->request == XCB_MAPPING_MODIFIER) | |
2224 | + { | |
2225 | + XMappingEvent xMappingEvent; | |
2226 | + memset(&xMappingEvent, 0, sizeof(xMappingEvent)); | |
2227 | + xMappingEvent.type = MappingNotify; | |
2228 | + xMappingEvent.display = m_dpy; | |
2229 | + if (mappingNotifyEvent->request == XCB_MAPPING_KEYBOARD) { | |
2230 | + xMappingEvent.request = MappingKeyboard; | |
2231 | + } | |
2232 | + else { | |
2233 | + xMappingEvent.request = MappingModifier; | |
2234 | + } | |
2235 | + xMappingEvent.first_keycode = mappingNotifyEvent->first_keycode; | |
2236 | + xMappingEvent.count = mappingNotifyEvent->count; | |
2237 | + XRefreshKeyboardMapping(&xMappingEvent); | |
2238 | + updateKeymap(); | |
2239 | + } | |
2240 | + } | |
2241 | + | |
2242 | + return -1; | |
2243 | +} | |
2244 | + | |
2245 | +AutoTypeExecutor* AutoTypePlatformX11::createExecutor() | |
2246 | +{ | |
2247 | + return new AutoTypeExecturorX11(this); | |
2248 | +} | |
2249 | + | |
2250 | +QString AutoTypePlatformX11::windowTitle(Window window, bool useBlacklist) | |
2251 | +{ | |
2252 | + QString title; | |
2253 | + | |
2254 | + Atom type; | |
2255 | + int format; | |
2256 | + unsigned long nitems; | |
2257 | + unsigned long after; | |
2258 | + unsigned char* data = nullptr; | |
2259 | + | |
2260 | + // the window manager spec says we should read _NET_WM_NAME first, then fall back to WM_NAME | |
2261 | + | |
2262 | + int retVal = XGetWindowProperty(m_dpy, window, m_atomNetWmName, 0, 1000, False, m_atomUtf8String, | |
2263 | + &type, &format, &nitems, &after, &data); | |
2264 | + | |
2265 | + if ((retVal == 0) && data) { | |
2266 | + title = QString::fromUtf8(reinterpret_cast<char*>(data)); | |
2267 | + } | |
2268 | + else { | |
2269 | + XTextProperty textProp; | |
2270 | + retVal = XGetTextProperty(m_dpy, window, &textProp, m_atomWmName); | |
2271 | + if ((retVal != 0) && textProp.value) { | |
2272 | + char** textList = nullptr; | |
2273 | + int count; | |
2274 | + | |
2275 | + if (textProp.encoding == m_atomUtf8String) { | |
2276 | + title = QString::fromUtf8(reinterpret_cast<char*>(textProp.value)); | |
2277 | + } | |
2278 | + else if ((XmbTextPropertyToTextList(m_dpy, &textProp, &textList, &count) == 0) | |
2279 | + && textList && (count > 0)) { | |
2280 | + title = QString::fromLocal8Bit(textList[0]); | |
2281 | + } | |
2282 | + else if (textProp.encoding == m_atomString) { | |
2283 | + title = QString::fromLocal8Bit(reinterpret_cast<char*>(textProp.value)); | |
2284 | + } | |
2285 | + | |
2286 | + if (textList) { | |
2287 | + XFreeStringList(textList); | |
2288 | + } | |
2289 | + } | |
2290 | + | |
2291 | + if (textProp.value) { | |
2292 | + XFree(textProp.value); | |
2293 | + } | |
2294 | + } | |
2295 | + | |
2296 | + if (data) { | |
2297 | + XFree(data); | |
2298 | + } | |
2299 | + | |
2300 | + if (useBlacklist && !title.isEmpty()) { | |
2301 | + if (window == m_rootWindow) { | |
2302 | + return QString(); | |
2303 | + } | |
2304 | + | |
2305 | + QString className = windowClassName(window); | |
2306 | + if (m_classBlacklist.contains(className)) { | |
2307 | + return QString(); | |
2308 | + } | |
2309 | + | |
2310 | + QList<Window> keepassxWindows = widgetsToX11Windows(QApplication::topLevelWidgets()); | |
2311 | + if (keepassxWindows.contains(window)) { | |
2312 | + return QString(); | |
2313 | + } | |
2314 | + } | |
2315 | + | |
2316 | + return title; | |
2317 | +} | |
2318 | + | |
2319 | +QString AutoTypePlatformX11::windowClassName(Window window) | |
2320 | +{ | |
2321 | + QString className; | |
2322 | + | |
2323 | + XClassHint wmClass; | |
2324 | + wmClass.res_name = nullptr; | |
2325 | + wmClass.res_class = nullptr; | |
2326 | + | |
2327 | + if (XGetClassHint(m_dpy, window, &wmClass) && wmClass.res_name) { | |
2328 | + className = QString::fromLocal8Bit(wmClass.res_name); | |
2329 | + } | |
2330 | + if (wmClass.res_name) { | |
2331 | + XFree(wmClass.res_name); | |
2332 | + } | |
2333 | + if (wmClass.res_class) { | |
2334 | + XFree(wmClass.res_class); | |
2335 | + } | |
2336 | + | |
2337 | + return className; | |
2338 | +} | |
2339 | + | |
2340 | +QList<Window> AutoTypePlatformX11::widgetsToX11Windows(const QWidgetList& widgetList) | |
2341 | +{ | |
2342 | + QList<Window> windows; | |
2343 | + | |
2344 | + Q_FOREACH (const QWidget* widget, widgetList) { | |
2345 | + windows.append(widget->effectiveWinId()); | |
2346 | + } | |
2347 | + | |
2348 | + return windows; | |
2349 | +} | |
2350 | + | |
2351 | +QStringList AutoTypePlatformX11::windowTitlesRecursive(Window window) | |
2352 | +{ | |
2353 | + QStringList titles; | |
2354 | + | |
2355 | + if (isTopLevelWindow(window)) { | |
2356 | + QString title = windowTitle(window, true); | |
2357 | + if (!title.isEmpty()) { | |
2358 | + titles.append(title); | |
2359 | + } | |
2360 | + } | |
2361 | + | |
2362 | + Window root; | |
2363 | + Window parent; | |
2364 | + Window* children = nullptr; | |
2365 | + unsigned int numChildren; | |
2366 | + if (XQueryTree(m_dpy, window, &root, &parent, &children, &numChildren) && children) { | |
2367 | + for (uint i = 0; i < numChildren; i++) { | |
2368 | + titles.append(windowTitlesRecursive(children[i])); | |
2369 | + } | |
2370 | + } | |
2371 | + if (children) { | |
2372 | + XFree(children); | |
2373 | + } | |
2374 | + | |
2375 | + return titles; | |
2376 | +} | |
2377 | + | |
2378 | +bool AutoTypePlatformX11::isTopLevelWindow(Window window) | |
2379 | +{ | |
2380 | + Atom type = None; | |
2381 | + int format; | |
2382 | + unsigned long nitems; | |
2383 | + unsigned long after; | |
2384 | + unsigned char* data = nullptr; | |
2385 | + int retVal = XGetWindowProperty(m_dpy, window, m_atomWmState, 0, 0, False, AnyPropertyType, &type, &format, | |
2386 | + &nitems, &after, &data); | |
2387 | + if (data) { | |
2388 | + XFree(data); | |
2389 | + } | |
2390 | + | |
2391 | + return (retVal == 0) && type; | |
2392 | +} | |
2393 | + | |
2394 | +KeySym AutoTypePlatformX11::charToKeySym(const QChar& ch) | |
2395 | +{ | |
2396 | + ushort unicode = ch.unicode(); | |
2397 | + | |
2398 | + /* first check for Latin-1 characters (1:1 mapping) */ | |
2399 | + if ((unicode >= 0x0020 && unicode <= 0x007e) | |
2400 | + || (unicode >= 0x00a0 && unicode <= 0x00ff)) { | |
2401 | + return unicode; | |
2402 | + } | |
2403 | + | |
2404 | + /* mapping table generated from keysymdef.h */ | |
2405 | + const uint* match = Tools::binaryFind(m_unicodeToKeysymKeys, | |
2406 | + m_unicodeToKeysymKeys + m_unicodeToKeysymLen, | |
2407 | + unicode); | |
2408 | + int index = match - m_unicodeToKeysymKeys; | |
2409 | + if (index != m_unicodeToKeysymLen) { | |
2410 | + return m_unicodeToKeysymValues[index]; | |
2411 | + } | |
2412 | + | |
2413 | + if (unicode >= 0x0100) { | |
2414 | + return unicode | 0x01000000; | |
2415 | + } | |
2416 | + | |
2417 | + return NoSymbol; | |
2418 | +} | |
2419 | + | |
2420 | +KeySym AutoTypePlatformX11::keyToKeySym(Qt::Key key) | |
2421 | +{ | |
2422 | + switch (key) { | |
2423 | + case Qt::Key_Tab: | |
2424 | + return XK_Tab; | |
2425 | + case Qt::Key_Enter: | |
2426 | + return XK_Return; | |
2427 | + case Qt::Key_Up: | |
2428 | + return XK_Up; | |
2429 | + case Qt::Key_Down: | |
2430 | + return XK_Down; | |
2431 | + case Qt::Key_Left: | |
2432 | + return XK_Left; | |
2433 | + case Qt::Key_Right: | |
2434 | + return XK_Right; | |
2435 | + case Qt::Key_Insert: | |
2436 | + return XK_Insert; | |
2437 | + case Qt::Key_Delete: | |
2438 | + return XK_Delete; | |
2439 | + case Qt::Key_Home: | |
2440 | + return XK_Home; | |
2441 | + case Qt::Key_End: | |
2442 | + return XK_End; | |
2443 | + case Qt::Key_PageUp: | |
2444 | + return XK_Page_Up; | |
2445 | + case Qt::Key_PageDown: | |
2446 | + return XK_Page_Down; | |
2447 | + case Qt::Key_Backspace: | |
2448 | + return XK_BackSpace; | |
2449 | + case Qt::Key_Pause: | |
2450 | + return XK_Break; | |
2451 | + case Qt::Key_CapsLock: | |
2452 | + return XK_Caps_Lock; | |
2453 | + case Qt::Key_Escape: | |
2454 | + return XK_Escape; | |
2455 | + case Qt::Key_Help: | |
2456 | + return XK_Help; | |
2457 | + case Qt::Key_NumLock: | |
2458 | + return XK_Num_Lock; | |
2459 | + case Qt::Key_Print: | |
2460 | + return XK_Print; | |
2461 | + case Qt::Key_ScrollLock: | |
2462 | + return XK_Scroll_Lock; | |
2463 | + default: | |
2464 | + if (key >= Qt::Key_F1 && key <= Qt::Key_F16) { | |
2465 | + return XK_F1 + (key - Qt::Key_F1); | |
2466 | + } | |
2467 | + else { | |
2468 | + return NoSymbol; | |
2469 | + } | |
2470 | + } | |
2471 | +} | |
2472 | + | |
2473 | +/* | |
2474 | + * Update the keyboard and modifier mapping. | |
2475 | + * We need the KeyboardMapping for AddKeysym. | |
2476 | + * Modifier mapping is required for clearing the modifiers. | |
2477 | + */ | |
2478 | +void AutoTypePlatformX11::updateKeymap() | |
2479 | +{ | |
2480 | + int keycode, inx; | |
2481 | + int mod_index, mod_key; | |
2482 | + XModifierKeymap *modifiers; | |
2483 | + | |
2484 | + if (m_xkb) { | |
2485 | + XkbFreeKeyboard(m_xkb, XkbAllComponentsMask, True); | |
2486 | + } | |
2487 | + m_xkb = getKeyboard(); | |
2488 | + | |
2489 | + XDisplayKeycodes(m_dpy, &m_minKeycode, &m_maxKeycode); | |
2490 | + if (m_keysymTable != NULL) XFree(m_keysymTable); | |
2491 | + m_keysymTable = XGetKeyboardMapping(m_dpy, | |
2492 | + m_minKeycode, m_maxKeycode - m_minKeycode + 1, | |
2493 | + &m_keysymPerKeycode); | |
2494 | + | |
2495 | + /* determine the keycode to use for remapped keys */ | |
2496 | + inx = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode; | |
2497 | + if (m_remapKeycode == 0 || !isRemapKeycodeValid()) { | |
2498 | + for (keycode = m_minKeycode; keycode <= m_maxKeycode; keycode++) { | |
2499 | + inx = (keycode - m_minKeycode) * m_keysymPerKeycode; | |
2500 | + if (m_keysymTable[inx] == NoSymbol) { | |
2501 | + m_remapKeycode = keycode; | |
2502 | + m_currentRemapKeysym = NoSymbol; | |
2503 | + break; | |
2504 | + } | |
2505 | + } | |
2506 | + } | |
2507 | + | |
2508 | + /* determine the keycode to use for modifiers */ | |
2509 | + modifiers = XGetModifierMapping(m_dpy); | |
2510 | + for (mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index ++) { | |
2511 | + m_modifier_keycode[mod_index] = 0; | |
2512 | + for (mod_key = 0; mod_key < modifiers->max_keypermod; mod_key++) { | |
2513 | + keycode = modifiers->modifiermap[mod_index * modifiers->max_keypermod + mod_key]; | |
2514 | + if (keycode) { | |
2515 | + m_modifier_keycode[mod_index] = keycode; | |
2516 | + break; | |
2517 | + } | |
2518 | + } | |
2519 | + } | |
2520 | + XFreeModifiermap(modifiers); | |
2521 | + | |
2522 | + /* Xlib needs some time until the mapping is distributed to | |
2523 | + all clients */ | |
2524 | + // TODO: we should probably only sleep while in the middle of typing something | |
2525 | + timespec ts; | |
2526 | + ts.tv_sec = 0; | |
2527 | + ts.tv_nsec = 30 * 1000 * 1000; | |
2528 | + nanosleep(&ts, nullptr); | |
2529 | +} | |
2530 | + | |
2531 | +bool AutoTypePlatformX11::isRemapKeycodeValid() | |
2532 | +{ | |
2533 | + int baseKeycode = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode; | |
2534 | + for (int i = 0; i < m_keysymPerKeycode; i++) { | |
2535 | + if (m_keysymTable[baseKeycode + i] == m_currentRemapKeysym) { | |
2536 | + return true; | |
2537 | + } | |
2538 | + } | |
2539 | + | |
2540 | + return false; | |
2541 | +} | |
2542 | + | |
2543 | +void AutoTypePlatformX11::startCatchXErrors() | |
2544 | +{ | |
2545 | + Q_ASSERT(!m_catchXErrors); | |
2546 | + | |
2547 | + m_catchXErrors = true; | |
2548 | + m_xErrorOccured = false; | |
2549 | + m_oldXErrorHandler = XSetErrorHandler(x11ErrorHandler); | |
2550 | +} | |
2551 | + | |
2552 | +void AutoTypePlatformX11::stopCatchXErrors() | |
2553 | +{ | |
2554 | + Q_ASSERT(m_catchXErrors); | |
2555 | + | |
2556 | + XSync(m_dpy, False); | |
2557 | + XSetErrorHandler(m_oldXErrorHandler); | |
2558 | + m_catchXErrors = false; | |
2559 | +} | |
2560 | + | |
2561 | +int AutoTypePlatformX11::x11ErrorHandler(Display* display, XErrorEvent* error) | |
2562 | +{ | |
2563 | + Q_UNUSED(display) | |
2564 | + Q_UNUSED(error) | |
2565 | + | |
2566 | + if (m_catchXErrors) { | |
2567 | + m_xErrorOccured = true; | |
2568 | + } | |
2569 | + | |
2570 | + return 1; | |
2571 | +} | |
2572 | + | |
2573 | +XkbDescPtr AutoTypePlatformX11::getKeyboard() | |
2574 | +{ | |
2575 | + int num_devices; | |
2576 | + XID keyboard_id = XkbUseCoreKbd; | |
2577 | + XDeviceInfo* devices = XListInputDevices(m_dpy, &num_devices); | |
2578 | + if (!devices) { | |
2579 | + return nullptr; | |
2580 | + } | |
2581 | + | |
2582 | + for (int i = 0; i < num_devices; i++) { | |
2583 | + if (QString(devices[i].name) == "Virtual core XTEST keyboard") { | |
2584 | + keyboard_id = devices[i].id; | |
2585 | + break; | |
2586 | + } | |
2587 | + } | |
2588 | + | |
2589 | + XFreeDeviceList(devices); | |
2590 | + | |
2591 | + return XkbGetKeyboard(m_dpy, XkbCompatMapMask | XkbGeometryMask, keyboard_id); | |
2592 | +} | |
2593 | + | |
2594 | +// -------------------------------------------------------------------------- | |
2595 | +// The following code is taken from xvkbd 3.0 and has been slightly modified. | |
2596 | +// -------------------------------------------------------------------------- | |
2597 | + | |
2598 | +/* | |
2599 | + * Insert a specified keysym on the dedicated position in the keymap | |
2600 | + * table. | |
2601 | + */ | |
2602 | +int AutoTypePlatformX11::AddKeysym(KeySym keysym) | |
2603 | +{ | |
2604 | + if (m_remapKeycode == 0) { | |
2605 | + return 0; | |
2606 | + } | |
2607 | + | |
2608 | + int inx = (m_remapKeycode- m_minKeycode) * m_keysymPerKeycode; | |
2609 | + m_keysymTable[inx] = keysym; | |
2610 | + m_currentRemapKeysym = keysym; | |
2611 | + | |
2612 | + XChangeKeyboardMapping(m_dpy, m_remapKeycode, m_keysymPerKeycode, &m_keysymTable[inx], 1); | |
2613 | + XFlush(m_dpy); | |
2614 | + updateKeymap(); | |
2615 | + | |
2616 | + return m_remapKeycode; | |
2617 | +} | |
2618 | + | |
2619 | +/* | |
2620 | + * Send event to the focused window. | |
2621 | + * If input focus is specified explicitly, select the window | |
2622 | + * before send event to the window. | |
2623 | + */ | |
2624 | +void AutoTypePlatformX11::SendEvent(XKeyEvent* event, int event_type) | |
2625 | +{ | |
2626 | + XSync(event->display, False); | |
2627 | + int (*oldHandler) (Display*, XErrorEvent*) = XSetErrorHandler(MyErrorHandler); | |
2628 | + | |
2629 | + event->type = event_type; | |
2630 | + Bool press; | |
2631 | + if (event->type == KeyPress) { | |
2632 | + press = True; | |
2633 | + } | |
2634 | + else { | |
2635 | + press = False; | |
2636 | + } | |
2637 | + XTestFakeKeyEvent(event->display, event->keycode, press, 0); | |
2638 | + XFlush(event->display); | |
2639 | + | |
2640 | + XSetErrorHandler(oldHandler); | |
2641 | +} | |
2642 | + | |
2643 | +/* | |
2644 | + * Send a modifier press/release event for all modifiers | |
2645 | + * which are set in the mask variable. | |
2646 | + */ | |
2647 | +void AutoTypePlatformX11::SendModifier(XKeyEvent *event, unsigned int mask, int event_type) | |
2648 | +{ | |
2649 | + int mod_index; | |
2650 | + for (mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index ++) { | |
2651 | + if (mask & (1 << mod_index)) { | |
2652 | + event->keycode = m_modifier_keycode[mod_index]; | |
2653 | + SendEvent(event, event_type); | |
2654 | + if (event_type == KeyPress) | |
2655 | + event->state |= (1 << mod_index); | |
2656 | + else | |
2657 | + event->state &= (1 << mod_index); | |
2658 | + } | |
2659 | + } | |
2660 | +} | |
2661 | + | |
2662 | +/* | |
2663 | + * Determines the keycode and modifier mask for the given | |
2664 | + * keysym. | |
2665 | + */ | |
2666 | +int AutoTypePlatformX11::GetKeycode(KeySym keysym, unsigned int *mask) | |
2667 | +{ | |
2668 | + int keycode = XKeysymToKeycode(m_dpy, keysym); | |
2669 | + | |
2670 | + if (keycode && keysymModifiers(keysym, keycode, mask)) { | |
2671 | + return keycode; | |
2672 | + } | |
2673 | + | |
2674 | + /* no modifier matches => resort to remapping */ | |
2675 | + keycode = AddKeysym(keysym); | |
2676 | + if (keycode && keysymModifiers(keysym, keycode, mask)) { | |
2677 | + return keycode; | |
2678 | + } | |
2679 | + | |
2680 | + *mask = 0; | |
2681 | + return 0; | |
2682 | +} | |
2683 | + | |
2684 | +bool AutoTypePlatformX11::keysymModifiers(KeySym keysym, int keycode, unsigned int *mask) | |
2685 | +{ | |
2686 | + int shift, mod; | |
2687 | + unsigned int mods_rtrn; | |
2688 | + | |
2689 | + /* determine whether there is a combination of the modifiers | |
2690 | + (Mod1-Mod5) with or without shift which returns keysym */ | |
2691 | + for (shift = 0; shift < 2; shift ++) { | |
2692 | + for (mod = ControlMapIndex; mod <= Mod5MapIndex; mod ++) { | |
2693 | + KeySym keysym_rtrn; | |
2694 | + *mask = (mod == ControlMapIndex) ? shift : shift | (1 << mod); | |
2695 | + XkbTranslateKeyCode(m_xkb, keycode, *mask, &mods_rtrn, &keysym_rtrn); | |
2696 | + if (keysym_rtrn == keysym) { | |
2697 | + return true; | |
2698 | + } | |
2699 | + } | |
2700 | + } | |
2701 | + | |
2702 | + return false; | |
2703 | +} | |
2704 | + | |
2705 | + | |
2706 | + | |
2707 | +/* | |
2708 | + * Send sequence of KeyPressed/KeyReleased events to the focused | |
2709 | + * window to simulate keyboard. If modifiers (shift, control, etc) | |
2710 | + * are set ON, many events will be sent. | |
2711 | + */ | |
2712 | +void AutoTypePlatformX11::SendKeyPressedEvent(KeySym keysym) | |
2713 | +{ | |
2714 | + Window cur_focus; | |
2715 | + int revert_to; | |
2716 | + XKeyEvent event; | |
2717 | + int keycode; | |
2718 | + | |
2719 | + if (keysym == NoSymbol) { | |
2720 | + qWarning("No such key: keysym=0x%lX", keysym); | |
2721 | + return; | |
2722 | + } | |
2723 | + | |
2724 | + XGetInputFocus(m_dpy, &cur_focus, &revert_to); | |
2725 | + | |
2726 | + event.display = m_dpy; | |
2727 | + event.window = cur_focus; | |
2728 | + event.root = m_rootWindow; | |
2729 | + event.subwindow = None; | |
2730 | + event.time = CurrentTime; | |
2731 | + event.x = 1; | |
2732 | + event.y = 1; | |
2733 | + event.x_root = 1; | |
2734 | + event.y_root = 1; | |
2735 | + event.same_screen = True; | |
2736 | + | |
2737 | + Window root, child; | |
2738 | + int root_x, root_y, x, y; | |
2739 | + unsigned int wanted_mask = 0; | |
2740 | + unsigned int original_mask; | |
2741 | + | |
2742 | + XQueryPointer(m_dpy, event.root, &root, &child, &root_x, &root_y, &x, &y, &original_mask); | |
2743 | + | |
2744 | + /* determine keycode and mask for the given keysym */ | |
2745 | + keycode = GetKeycode(keysym, &wanted_mask); | |
2746 | + if (keycode < 8 || keycode > 255) { | |
2747 | + qWarning("Unable to get valid keycode for key: keysym=0x%lX", keysym); | |
2748 | + return; | |
2749 | + } | |
2750 | + | |
2751 | + event.state = original_mask; | |
2752 | + | |
2753 | + // modifiers that need to be pressed but aren't | |
2754 | + unsigned int press_mask = wanted_mask & ~original_mask; | |
2755 | + | |
2756 | + // modifiers that are pressed but maybe shouldn't | |
2757 | + unsigned int release_check_mask = original_mask & ~wanted_mask; | |
2758 | + | |
2759 | + // modifiers we need to release before sending the keycode | |
2760 | + unsigned int release_mask = 0; | |
2761 | + | |
2762 | + // check every release_check_mask individually if it affects the keysym we would generate | |
2763 | + // if it doesn't we probably don't need to release it | |
2764 | + for (int mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index ++) { | |
2765 | + if (release_check_mask & (1 << mod_index)) { | |
2766 | + unsigned int mods_rtrn; | |
2767 | + KeySym keysym_rtrn; | |
2768 | + XkbTranslateKeyCode(m_xkb, keycode, wanted_mask | (1 << mod_index), &mods_rtrn, &keysym_rtrn); | |
2769 | + | |
2770 | + if (keysym_rtrn != keysym) { | |
2771 | + release_mask |= (1 << mod_index); | |
2772 | + } | |
2773 | + } | |
2774 | + } | |
2775 | + | |
2776 | + // finally check if the combination of pressed modifiers that we chose to ignore affects the keysym | |
2777 | + unsigned int mods_rtrn; | |
2778 | + KeySym keysym_rtrn; | |
2779 | + XkbTranslateKeyCode(m_xkb, keycode, wanted_mask | (release_check_mask & ~release_mask), &mods_rtrn, &keysym_rtrn); | |
2780 | + if (keysym_rtrn != keysym) { | |
2781 | + // oh well, release all the modifiers we don't want | |
2782 | + release_mask = release_check_mask; | |
2783 | + } | |
2784 | + | |
2785 | + /* release all modifiers */ | |
2786 | + SendModifier(&event, release_mask, KeyRelease); | |
2787 | + | |
2788 | + SendModifier(&event, press_mask, KeyPress); | |
2789 | + | |
2790 | + /* press and release key */ | |
2791 | + event.keycode = keycode; | |
2792 | + SendEvent(&event, KeyPress); | |
2793 | + SendEvent(&event, KeyRelease); | |
2794 | + | |
2795 | + /* release the modifiers */ | |
2796 | + SendModifier(&event, press_mask, KeyRelease); | |
2797 | + | |
2798 | + /* restore the old keyboard mask */ | |
2799 | + SendModifier(&event, release_mask, KeyPress); | |
2800 | +} | |
2801 | + | |
2802 | +int AutoTypePlatformX11::MyErrorHandler(Display* my_dpy, XErrorEvent* event) | |
2803 | +{ | |
2804 | + char msg[200]; | |
2805 | + | |
2806 | + if (event->error_code == BadWindow) { | |
2807 | + return 0; | |
2808 | + } | |
2809 | + XGetErrorText(my_dpy, event->error_code, msg, sizeof(msg) - 1); | |
2810 | + qWarning("X error trapped: %s, request-code=%d\n", msg, event->request_code); | |
2811 | + return 0; | |
2812 | +} | |
2813 | + | |
2814 | + | |
2815 | +AutoTypeExecturorX11::AutoTypeExecturorX11(AutoTypePlatformX11* platform) | |
2816 | + : m_platform(platform) | |
2817 | +{ | |
2818 | +} | |
2819 | + | |
2820 | +void AutoTypeExecturorX11::execChar(AutoTypeChar* action) | |
2821 | +{ | |
2822 | + m_platform->SendKeyPressedEvent(m_platform->charToKeySym(action->character)); | |
2823 | +} | |
2824 | + | |
2825 | +void AutoTypeExecturorX11::execKey(AutoTypeKey* action) | |
2826 | +{ | |
2827 | + m_platform->SendKeyPressedEvent(m_platform->keyToKeySym(action->key)); | |
2828 | +} | |
2829 | + | |
2830 | +int AutoTypePlatformX11::initialTimeout() | |
2831 | +{ | |
2832 | + return 500; | |
2833 | +} | |
2834 | + | |
2835 | +bool AutoTypePlatformX11::raiseWindow(WId window) | |
2836 | +{ | |
2837 | + if (m_atomNetActiveWindow == None) { | |
2838 | + return false; | |
2839 | + } | |
2840 | + | |
2841 | + XRaiseWindow(m_dpy, window); | |
2842 | + | |
2843 | + XEvent event; | |
2844 | + event.xclient.type = ClientMessage; | |
2845 | + event.xclient.serial = 0; | |
2846 | + event.xclient.send_event = True; | |
2847 | + event.xclient.window = window; | |
2848 | + event.xclient.message_type = m_atomNetActiveWindow; | |
2849 | + event.xclient.format = 32; | |
2850 | + event.xclient.data.l[0] = 1; // FromApplication | |
2851 | + event.xclient.data.l[1] = QX11Info::appUserTime(); | |
2852 | + QWidget* activeWindow = QApplication::activeWindow(); | |
2853 | + if (activeWindow) { | |
2854 | + event.xclient.data.l[2] = activeWindow->internalWinId(); | |
2855 | + } | |
2856 | + else { | |
2857 | + event.xclient.data.l[2] = 0; | |
2858 | + } | |
2859 | + event.xclient.data.l[3] = 0; | |
2860 | + event.xclient.data.l[4] = 0; | |
2861 | + XSendEvent(m_dpy, m_rootWindow, False, | |
2862 | + SubstructureRedirectMask | SubstructureNotifyMask, | |
2863 | + &event); | |
2864 | + XFlush(m_dpy); | |
2865 | + | |
2866 | + return true; | |
2867 | +} | |
2868 | diff --git a/src/autotype/xcb/AutoTypeXCB.h b/src/autotype/xcb/AutoTypeXCB.h | |
2869 | new file mode 100644 | |
2870 | index 0000000..8adee77 | |
2871 | --- /dev/null | |
2872 | +++ b/src/autotype/xcb/AutoTypeXCB.h | |
2873 | @@ -0,0 +1,134 @@ | |
2874 | +/* | |
2875 | + * Copyright (C) 2012 Felix Geyer <debfx@fobos.de> | |
2876 | + * Copyright (C) 2000-2008 Tom Sato <VEF00200@nifty.ne.jp> | |
2877 | + * | |
2878 | + * This program is free software: you can redistribute it and/or modify | |
2879 | + * it under the terms of the GNU General Public License as published by | |
2880 | + * the Free Software Foundation, either version 2 or (at your option) | |
2881 | + * version 3 of the License. | |
2882 | + * | |
2883 | + * This program is distributed in the hope that it will be useful, | |
2884 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2885 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2886 | + * GNU General Public License for more details. | |
2887 | + * | |
2888 | + * You should have received a copy of the GNU General Public License | |
2889 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
2890 | + */ | |
2891 | + | |
2892 | +#ifndef KEEPASSX_AUTOTYPEXCB_H | |
2893 | +#define KEEPASSX_AUTOTYPEXCB_H | |
2894 | + | |
2895 | +#include <QApplication> | |
2896 | +#include <QSet> | |
2897 | +#include <QtPlugin> | |
2898 | +#include <QWidget> | |
2899 | +#include <QX11Info> | |
2900 | + | |
2901 | +#include <X11/Xutil.h> | |
2902 | +#include <X11/extensions/XTest.h> | |
2903 | +#include <X11/XKBlib.h> | |
2904 | + | |
2905 | +#include "autotype/AutoTypePlatformPlugin.h" | |
2906 | +#include "autotype/AutoTypeAction.h" | |
2907 | + | |
2908 | +#define N_MOD_INDICES (Mod5MapIndex + 1) | |
2909 | + | |
2910 | +class AutoTypePlatformX11 : public QObject, public AutoTypePlatformInterface | |
2911 | +{ | |
2912 | + Q_OBJECT | |
2913 | + Q_PLUGIN_METADATA(IID "org.keepassx.AutoTypePlatformX11") | |
2914 | + Q_INTERFACES(AutoTypePlatformInterface) | |
2915 | + | |
2916 | +public: | |
2917 | + AutoTypePlatformX11(); | |
2918 | + bool isAvailable() override; | |
2919 | + void unload() override; | |
2920 | + QStringList windowTitles() override; | |
2921 | + WId activeWindow() override; | |
2922 | + QString activeWindowTitle() override; | |
2923 | + bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) override; | |
2924 | + void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) override; | |
2925 | + int platformEventFilter(void* event) override; | |
2926 | + int initialTimeout() override; | |
2927 | + bool raiseWindow(WId window) override; | |
2928 | + AutoTypeExecutor* createExecutor() override; | |
2929 | + | |
2930 | + KeySym charToKeySym(const QChar& ch); | |
2931 | + KeySym keyToKeySym(Qt::Key key); | |
2932 | + | |
2933 | + void SendKeyPressedEvent(KeySym keysym); | |
2934 | + | |
2935 | +Q_SIGNALS: | |
2936 | + void globalShortcutTriggered(); | |
2937 | + | |
2938 | +private: | |
2939 | + QString windowTitle(Window window, bool useBlacklist); | |
2940 | + QStringList windowTitlesRecursive(Window window); | |
2941 | + QString windowClassName(Window window); | |
2942 | + QList<Window> widgetsToX11Windows(const QWidgetList& widgetList); | |
2943 | + bool isTopLevelWindow(Window window); | |
2944 | + uint qtToNativeModifiers(Qt::KeyboardModifiers modifiers); | |
2945 | + void startCatchXErrors(); | |
2946 | + void stopCatchXErrors(); | |
2947 | + static int x11ErrorHandler(Display* display, XErrorEvent* error); | |
2948 | + | |
2949 | + XkbDescPtr getKeyboard(); | |
2950 | + void updateKeymap(); | |
2951 | + bool isRemapKeycodeValid(); | |
2952 | + int AddKeysym(KeySym keysym); | |
2953 | + void AddModifier(KeySym keysym); | |
2954 | + void SendEvent(XKeyEvent* event, int event_type); | |
2955 | + void SendModifier(XKeyEvent *event, unsigned int mask, int event_type); | |
2956 | + int GetKeycode(KeySym keysym, unsigned int *mask); | |
2957 | + bool keysymModifiers(KeySym keysym, int keycode, unsigned int *mask); | |
2958 | + | |
2959 | + static int MyErrorHandler(Display* my_dpy, XErrorEvent* event); | |
2960 | + | |
2961 | + Display* m_dpy; | |
2962 | + Window m_rootWindow; | |
2963 | + Atom m_atomWmState; | |
2964 | + Atom m_atomWmName; | |
2965 | + Atom m_atomNetWmName; | |
2966 | + Atom m_atomString; | |
2967 | + Atom m_atomUtf8String; | |
2968 | + Atom m_atomNetActiveWindow; | |
2969 | + QSet<QString> m_classBlacklist; | |
2970 | + Qt::Key m_currentGlobalKey; | |
2971 | + Qt::KeyboardModifiers m_currentGlobalModifiers; | |
2972 | + uint m_currentGlobalKeycode; | |
2973 | + uint m_currentGlobalNativeModifiers; | |
2974 | + int m_modifierMask; | |
2975 | + static bool m_catchXErrors; | |
2976 | + static bool m_xErrorOccured; | |
2977 | + static int (*m_oldXErrorHandler)(Display*, XErrorEvent*); | |
2978 | + | |
2979 | + static const int m_unicodeToKeysymLen; | |
2980 | + static const uint m_unicodeToKeysymKeys[]; | |
2981 | + static const uint m_unicodeToKeysymValues[]; | |
2982 | + | |
2983 | + XkbDescPtr m_xkb; | |
2984 | + KeySym* m_keysymTable; | |
2985 | + int m_minKeycode; | |
2986 | + int m_maxKeycode; | |
2987 | + int m_keysymPerKeycode; | |
2988 | + /* dedicated keycode for remapped keys */ | |
2989 | + unsigned int m_remapKeycode; | |
2990 | + KeySym m_currentRemapKeysym; | |
2991 | + KeyCode m_modifier_keycode[N_MOD_INDICES]; | |
2992 | + bool m_loaded; | |
2993 | +}; | |
2994 | + | |
2995 | +class AutoTypeExecturorX11 : public AutoTypeExecutor | |
2996 | +{ | |
2997 | +public: | |
2998 | + explicit AutoTypeExecturorX11(AutoTypePlatformX11* platform); | |
2999 | + | |
3000 | + void execChar(AutoTypeChar* action) override; | |
3001 | + void execKey(AutoTypeKey* action) override; | |
3002 | + | |
3003 | +private: | |
3004 | + AutoTypePlatformX11* const m_platform; | |
3005 | +}; | |
3006 | + | |
3007 | +#endif // KEEPASSX_AUTOTYPEXCB_H | |
3008 | diff --git a/src/autotype/xcb/CMakeLists.txt b/src/autotype/xcb/CMakeLists.txt | |
3009 | new file mode 100644 | |
3010 | index 0000000..3b56b31 | |
3011 | --- /dev/null | |
3012 | +++ b/src/autotype/xcb/CMakeLists.txt | |
3013 | @@ -0,0 +1,11 @@ | |
3014 | +include_directories(SYSTEM ${X11_X11_INCLUDE_PATH}) | |
3015 | + | |
3016 | +set(autotype_XCB_SOURCES | |
3017 | + AutoTypeXCB.cpp | |
3018 | +) | |
3019 | + | |
3020 | +add_library(keepassx-autotype-xcb MODULE ${autotype_XCB_SOURCES}) | |
3021 | +target_link_libraries(keepassx-autotype-xcb Qt5::Core Qt5::Widgets Qt5::X11Extras ${X11_X11_LIB} ${X11_Xi_LIB} ${X11_XTest_LIB}) | |
3022 | +install(TARGETS keepassx-autotype-xcb | |
3023 | + BUNDLE DESTINATION . COMPONENT Runtime | |
3024 | + LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime) | |
3025 | diff --git a/src/autotype/xcb/KeySymMap.h b/src/autotype/xcb/KeySymMap.h | |
3026 | new file mode 100644 | |
3027 | index 0000000..55022fe | |
3028 | --- /dev/null | |
3029 | +++ b/src/autotype/xcb/KeySymMap.h | |
3030 | @@ -0,0 +1,169 @@ | |
3031 | +/* | |
3032 | + * Automatically generated by keysymmap.py from parsing keysymdef.h. | |
3033 | + */ | |
3034 | + | |
3035 | +const int AutoTypePlatformX11::m_unicodeToKeysymLen = 632; | |
3036 | + | |
3037 | +const uint AutoTypePlatformX11::m_unicodeToKeysymKeys[] = { | |
3038 | + 0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, | |
3039 | + 0x0108, 0x0109, 0x010a, 0x010b, 0x010c, 0x010d, 0x010e, 0x010f, | |
3040 | + 0x0110, 0x0111, 0x0112, 0x0113, 0x0116, 0x0117, 0x0118, 0x0119, | |
3041 | + 0x011a, 0x011b, 0x011c, 0x011d, 0x011e, 0x011f, 0x0120, 0x0121, | |
3042 | + 0x0122, 0x0123, 0x0124, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, | |
3043 | + 0x012a, 0x012b, 0x012e, 0x012f, 0x0130, 0x0131, 0x0134, 0x0135, | |
3044 | + 0x0136, 0x0137, 0x0138, 0x0139, 0x013a, 0x013b, 0x013c, 0x013d, | |
3045 | + 0x013e, 0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0147, | |
3046 | + 0x0148, 0x014a, 0x014b, 0x014c, 0x014d, 0x0150, 0x0151, 0x0152, | |
3047 | + 0x0153, 0x0154, 0x0155, 0x0156, 0x0157, 0x0158, 0x0159, 0x015a, | |
3048 | + 0x015b, 0x015c, 0x015d, 0x015e, 0x015f, 0x0160, 0x0161, 0x0162, | |
3049 | + 0x0163, 0x0164, 0x0165, 0x0166, 0x0167, 0x0168, 0x0169, 0x016a, | |
3050 | + 0x016b, 0x016c, 0x016d, 0x016e, 0x016f, 0x0170, 0x0171, 0x0172, | |
3051 | + 0x0173, 0x0178, 0x0179, 0x017a, 0x017b, 0x017c, 0x017d, 0x017e, | |
3052 | + 0x0192, 0x02c7, 0x02d8, 0x02d9, 0x02db, 0x02dd, 0x0385, 0x0386, | |
3053 | + 0x0388, 0x0389, 0x038a, 0x038c, 0x038e, 0x038f, 0x0390, 0x0391, | |
3054 | + 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, | |
3055 | + 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, 0x03a0, 0x03a1, | |
3056 | + 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9, 0x03aa, | |
3057 | + 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af, 0x03b0, 0x03b1, 0x03b2, | |
3058 | + 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, | |
3059 | + 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, 0x03c0, 0x03c1, 0x03c2, | |
3060 | + 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x03ca, | |
3061 | + 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0401, 0x0402, 0x0403, 0x0404, | |
3062 | + 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, | |
3063 | + 0x040e, 0x040f, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, | |
3064 | + 0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, | |
3065 | + 0x041e, 0x041f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, | |
3066 | + 0x0426, 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, | |
3067 | + 0x042e, 0x042f, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, | |
3068 | + 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, | |
3069 | + 0x043e, 0x043f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, | |
3070 | + 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, | |
3071 | + 0x044e, 0x044f, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, | |
3072 | + 0x0457, 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x045e, 0x045f, | |
3073 | + 0x0490, 0x0491, 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, | |
3074 | + 0x05d6, 0x05d7, 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, | |
3075 | + 0x05de, 0x05df, 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, | |
3076 | + 0x05e6, 0x05e7, 0x05e8, 0x05e9, 0x05ea, 0x060c, 0x061b, 0x061f, | |
3077 | + 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, 0x0628, | |
3078 | + 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f, 0x0630, | |
3079 | + 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, 0x0638, | |
3080 | + 0x0639, 0x063a, 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, | |
3081 | + 0x0646, 0x0647, 0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, | |
3082 | + 0x064e, 0x064f, 0x0650, 0x0651, 0x0652, 0x0e01, 0x0e02, 0x0e03, | |
3083 | + 0x0e04, 0x0e05, 0x0e06, 0x0e07, 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, | |
3084 | + 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, 0x0e10, 0x0e11, 0x0e12, 0x0e13, | |
3085 | + 0x0e14, 0x0e15, 0x0e16, 0x0e17, 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, | |
3086 | + 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, 0x0e20, 0x0e21, 0x0e22, 0x0e23, | |
3087 | + 0x0e24, 0x0e25, 0x0e26, 0x0e27, 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, | |
3088 | + 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, 0x0e30, 0x0e31, 0x0e32, 0x0e33, | |
3089 | + 0x0e34, 0x0e35, 0x0e36, 0x0e37, 0x0e38, 0x0e39, 0x0e3a, 0x0e3f, | |
3090 | + 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, | |
3091 | + 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e50, 0x0e51, | |
3092 | + 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, 0x0e58, 0x0e59, | |
3093 | + 0x2002, 0x2003, 0x2004, 0x2005, 0x2007, 0x2008, 0x2009, 0x200a, | |
3094 | + 0x2012, 0x2013, 0x2014, 0x2015, 0x2017, 0x2018, 0x2019, 0x201a, | |
3095 | + 0x201c, 0x201d, 0x201e, 0x2020, 0x2021, 0x2025, 0x2026, 0x2030, | |
3096 | + 0x2032, 0x2033, 0x2038, 0x203e, 0x20ac, 0x2105, 0x2116, 0x2117, | |
3097 | + 0x211e, 0x2122, 0x2153, 0x2154, 0x2155, 0x2156, 0x2157, 0x2158, | |
3098 | + 0x2159, 0x215a, 0x215b, 0x215c, 0x215d, 0x215e, 0x2190, 0x2191, | |
3099 | + 0x2192, 0x2193, 0x21d2, 0x21d4, 0x2202, 0x2207, 0x2218, 0x221a, | |
3100 | + 0x221d, 0x221e, 0x2227, 0x2228, 0x2229, 0x222a, 0x222b, 0x2234, | |
3101 | + 0x223c, 0x2243, 0x2260, 0x2261, 0x2264, 0x2265, 0x2282, 0x2283, | |
3102 | + 0x22a2, 0x22a3, 0x22a4, 0x22a5, 0x2308, 0x230a, 0x2315, 0x2320, | |
3103 | + 0x2321, 0x2395, 0x239b, 0x239d, 0x239e, 0x23a0, 0x23a1, 0x23a3, | |
3104 | + 0x23a4, 0x23a6, 0x23a8, 0x23ac, 0x23b7, 0x23ba, 0x23bb, 0x23bc, | |
3105 | + 0x23bd, 0x2409, 0x240a, 0x240b, 0x240c, 0x240d, 0x2424, 0x2500, | |
3106 | + 0x2502, 0x250c, 0x2510, 0x2514, 0x2518, 0x251c, 0x2524, 0x252c, | |
3107 | + 0x2534, 0x253c, 0x2592, 0x25c6, 0x25cb, 0x260e, 0x2640, 0x2642, | |
3108 | + 0x2663, 0x2665, 0x2666, 0x266d, 0x266f, 0x2713, 0x2717, 0x271d, | |
3109 | + 0x2720, 0x3001, 0x3002, 0x300c, 0x300d, 0x309b, 0x309c, 0x30a1, | |
3110 | + 0x30a2, 0x30a3, 0x30a4, 0x30a5, 0x30a6, 0x30a7, 0x30a8, 0x30a9, | |
3111 | + 0x30aa, 0x30ab, 0x30ad, 0x30af, 0x30b1, 0x30b3, 0x30b5, 0x30b7, | |
3112 | + 0x30b9, 0x30bb, 0x30bd, 0x30bf, 0x30c1, 0x30c3, 0x30c4, 0x30c6, | |
3113 | + 0x30c8, 0x30ca, 0x30cb, 0x30cc, 0x30cd, 0x30ce, 0x30cf, 0x30d2, | |
3114 | + 0x30d5, 0x30d8, 0x30db, 0x30de, 0x30df, 0x30e0, 0x30e1, 0x30e2, | |
3115 | + 0x30e3, 0x30e4, 0x30e5, 0x30e6, 0x30e7, 0x30e8, 0x30e9, 0x30ea, | |
3116 | + 0x30eb, 0x30ec, 0x30ed, 0x30ef, 0x30f2, 0x30f3, 0x30fb, 0x30fc | |
3117 | +}; | |
3118 | + | |
3119 | +const uint AutoTypePlatformX11::m_unicodeToKeysymValues[] = { | |
3120 | + 0x03c0, 0x03e0, 0x01c3, 0x01e3, 0x01a1, 0x01b1, 0x01c6, 0x01e6, | |
3121 | + 0x02c6, 0x02e6, 0x02c5, 0x02e5, 0x01c8, 0x01e8, 0x01cf, 0x01ef, | |
3122 | + 0x01d0, 0x01f0, 0x03aa, 0x03ba, 0x03cc, 0x03ec, 0x01ca, 0x01ea, | |
3123 | + 0x01cc, 0x01ec, 0x02d8, 0x02f8, 0x02ab, 0x02bb, 0x02d5, 0x02f5, | |
3124 | + 0x03ab, 0x03bb, 0x02a6, 0x02b6, 0x02a1, 0x02b1, 0x03a5, 0x03b5, | |
3125 | + 0x03cf, 0x03ef, 0x03c7, 0x03e7, 0x02a9, 0x02b9, 0x02ac, 0x02bc, | |
3126 | + 0x03d3, 0x03f3, 0x03a2, 0x01c5, 0x01e5, 0x03a6, 0x03b6, 0x01a5, | |
3127 | + 0x01b5, 0x01a3, 0x01b3, 0x01d1, 0x01f1, 0x03d1, 0x03f1, 0x01d2, | |
3128 | + 0x01f2, 0x03bd, 0x03bf, 0x03d2, 0x03f2, 0x01d5, 0x01f5, 0x13bc, | |
3129 | + 0x13bd, 0x01c0, 0x01e0, 0x03a3, 0x03b3, 0x01d8, 0x01f8, 0x01a6, | |
3130 | + 0x01b6, 0x02de, 0x02fe, 0x01aa, 0x01ba, 0x01a9, 0x01b9, 0x01de, | |
3131 | + 0x01fe, 0x01ab, 0x01bb, 0x03ac, 0x03bc, 0x03dd, 0x03fd, 0x03de, | |
3132 | + 0x03fe, 0x02dd, 0x02fd, 0x01d9, 0x01f9, 0x01db, 0x01fb, 0x03d9, | |
3133 | + 0x03f9, 0x13be, 0x01ac, 0x01bc, 0x01af, 0x01bf, 0x01ae, 0x01be, | |
3134 | + 0x08f6, 0x01b7, 0x01a2, 0x01ff, 0x01b2, 0x01bd, 0x07ae, 0x07a1, | |
3135 | + 0x07a2, 0x07a3, 0x07a4, 0x07a7, 0x07a8, 0x07ab, 0x07b6, 0x07c1, | |
3136 | + 0x07c2, 0x07c3, 0x07c4, 0x07c5, 0x07c6, 0x07c7, 0x07c8, 0x07c9, | |
3137 | + 0x07ca, 0x07cb, 0x07cc, 0x07cd, 0x07ce, 0x07cf, 0x07d0, 0x07d1, | |
3138 | + 0x07d2, 0x07d4, 0x07d5, 0x07d6, 0x07d7, 0x07d8, 0x07d9, 0x07a5, | |
3139 | + 0x07a9, 0x07b1, 0x07b2, 0x07b3, 0x07b4, 0x07ba, 0x07e1, 0x07e2, | |
3140 | + 0x07e3, 0x07e4, 0x07e5, 0x07e6, 0x07e7, 0x07e8, 0x07e9, 0x07ea, | |
3141 | + 0x07eb, 0x07ec, 0x07ed, 0x07ee, 0x07ef, 0x07f0, 0x07f1, 0x07f3, | |
3142 | + 0x07f2, 0x07f4, 0x07f5, 0x07f6, 0x07f7, 0x07f8, 0x07f9, 0x07b5, | |
3143 | + 0x07b9, 0x07b7, 0x07b8, 0x07bb, 0x06b3, 0x06b1, 0x06b2, 0x06b4, | |
3144 | + 0x06b5, 0x06b6, 0x06b7, 0x06b8, 0x06b9, 0x06ba, 0x06bb, 0x06bc, | |
3145 | + 0x06be, 0x06bf, 0x06e1, 0x06e2, 0x06f7, 0x06e7, 0x06e4, 0x06e5, | |
3146 | + 0x06f6, 0x06fa, 0x06e9, 0x06ea, 0x06eb, 0x06ec, 0x06ed, 0x06ee, | |
3147 | + 0x06ef, 0x06f0, 0x06f2, 0x06f3, 0x06f4, 0x06f5, 0x06e6, 0x06e8, | |
3148 | + 0x06e3, 0x06fe, 0x06fb, 0x06fd, 0x06ff, 0x06f9, 0x06f8, 0x06fc, | |
3149 | + 0x06e0, 0x06f1, 0x06c1, 0x06c2, 0x06d7, 0x06c7, 0x06c4, 0x06c5, | |
3150 | + 0x06d6, 0x06da, 0x06c9, 0x06ca, 0x06cb, 0x06cc, 0x06cd, 0x06ce, | |
3151 | + 0x06cf, 0x06d0, 0x06d2, 0x06d3, 0x06d4, 0x06d5, 0x06c6, 0x06c8, | |
3152 | + 0x06c3, 0x06de, 0x06db, 0x06dd, 0x06df, 0x06d9, 0x06d8, 0x06dc, | |
3153 | + 0x06c0, 0x06d1, 0x06a3, 0x06a1, 0x06a2, 0x06a4, 0x06a5, 0x06a6, | |
3154 | + 0x06a7, 0x06a8, 0x06a9, 0x06aa, 0x06ab, 0x06ac, 0x06ae, 0x06af, | |
3155 | + 0x06bd, 0x06ad, 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, | |
3156 | + 0x0ce6, 0x0ce7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, | |
3157 | + 0x0cee, 0x0cef, 0x0cf0, 0x0cf1, 0x0cf2, 0x0cf3, 0x0cf4, 0x0cf5, | |
3158 | + 0x0cf6, 0x0cf7, 0x0cf8, 0x0cf9, 0x0cfa, 0x05ac, 0x05bb, 0x05bf, | |
3159 | + 0x05c1, 0x05c2, 0x05c3, 0x05c4, 0x05c5, 0x05c6, 0x05c7, 0x05c8, | |
3160 | + 0x05c9, 0x05ca, 0x05cb, 0x05cc, 0x05cd, 0x05ce, 0x05cf, 0x05d0, | |
3161 | + 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, 0x05d8, | |
3162 | + 0x05d9, 0x05da, 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, | |
3163 | + 0x05e6, 0x05e7, 0x05e8, 0x05e9, 0x05ea, 0x05eb, 0x05ec, 0x05ed, | |
3164 | + 0x05ee, 0x05ef, 0x05f0, 0x05f1, 0x05f2, 0x0da1, 0x0da2, 0x0da3, | |
3165 | + 0x0da4, 0x0da5, 0x0da6, 0x0da7, 0x0da8, 0x0da9, 0x0daa, 0x0dab, | |
3166 | + 0x0dac, 0x0dad, 0x0dae, 0x0daf, 0x0db0, 0x0db1, 0x0db2, 0x0db3, | |
3167 | + 0x0db4, 0x0db5, 0x0db6, 0x0db7, 0x0db8, 0x0db9, 0x0dba, 0x0dbb, | |
3168 | + 0x0dbc, 0x0dbd, 0x0dbe, 0x0dbf, 0x0dc0, 0x0dc1, 0x0dc2, 0x0dc3, | |
3169 | + 0x0dc4, 0x0dc5, 0x0dc6, 0x0dc7, 0x0dc8, 0x0dc9, 0x0dca, 0x0dcb, | |
3170 | + 0x0dcc, 0x0dcd, 0x0dce, 0x0dcf, 0x0dd0, 0x0dd1, 0x0dd2, 0x0dd3, | |
3171 | + 0x0dd4, 0x0dd5, 0x0dd6, 0x0dd7, 0x0dd8, 0x0dd9, 0x0dda, 0x0ddf, | |
3172 | + 0x0de0, 0x0de1, 0x0de2, 0x0de3, 0x0de4, 0x0de5, 0x0de6, 0x0de7, | |
3173 | + 0x0de8, 0x0de9, 0x0dea, 0x0deb, 0x0dec, 0x0ded, 0x0df0, 0x0df1, | |
3174 | + 0x0df2, 0x0df3, 0x0df4, 0x0df5, 0x0df6, 0x0df7, 0x0df8, 0x0df9, | |
3175 | + 0x0aa2, 0x0aa1, 0x0aa3, 0x0aa4, 0x0aa5, 0x0aa6, 0x0aa7, 0x0aa8, | |
3176 | + 0x0abb, 0x0aaa, 0x0aa9, 0x07af, 0x0cdf, 0x0ad0, 0x0ad1, 0x0afd, | |
3177 | + 0x0ad2, 0x0ad3, 0x0afe, 0x0af1, 0x0af2, 0x0aaf, 0x0aae, 0x0ad5, | |
3178 | + 0x0ad6, 0x0ad7, 0x0afc, 0x047e, 0x20ac, 0x0ab8, 0x06b0, 0x0afb, | |
3179 | + 0x0ad4, 0x0ac9, 0x0ab0, 0x0ab1, 0x0ab2, 0x0ab3, 0x0ab4, 0x0ab5, | |
3180 | + 0x0ab6, 0x0ab7, 0x0ac3, 0x0ac4, 0x0ac5, 0x0ac6, 0x08fb, 0x08fc, | |
3181 | + 0x08fd, 0x08fe, 0x08ce, 0x08cd, 0x08ef, 0x08c5, 0x0bca, 0x08d6, | |
3182 | + 0x08c1, 0x08c2, 0x08de, 0x08df, 0x08dc, 0x08dd, 0x08bf, 0x08c0, | |
3183 | + 0x08c8, 0x08c9, 0x08bd, 0x08cf, 0x08bc, 0x08be, 0x08da, 0x08db, | |
3184 | + 0x0bfc, 0x0bdc, 0x0bc2, 0x0bce, 0x0bd3, 0x0bc4, 0x0afa, 0x08a4, | |
3185 | + 0x08a5, 0x0bcc, 0x08ab, 0x08ac, 0x08ad, 0x08ae, 0x08a7, 0x08a8, | |
3186 | + 0x08a9, 0x08aa, 0x08af, 0x08b0, 0x08a1, 0x09ef, 0x09f0, 0x09f2, | |
3187 | + 0x09f3, 0x09e2, 0x09e5, 0x09e9, 0x09e3, 0x09e4, 0x09e8, 0x09f1, | |
3188 | + 0x09f8, 0x09ec, 0x09eb, 0x09ed, 0x09ea, 0x09f4, 0x09f5, 0x09f7, | |
3189 | + 0x09f6, 0x09ee, 0x09e1, 0x09e0, 0x0bcf, 0x0af9, 0x0af8, 0x0af7, | |
3190 | + 0x0aec, 0x0aee, 0x0aed, 0x0af6, 0x0af5, 0x0af3, 0x0af4, 0x0ad9, | |
3191 | + 0x0af0, 0x04a4, 0x04a1, 0x04a2, 0x04a3, 0x04de, 0x04df, 0x04a7, | |
3192 | + 0x04b1, 0x04a8, 0x04b2, 0x04a9, 0x04b3, 0x04aa, 0x04b4, 0x04ab, | |
3193 | + 0x04b5, 0x04b6, 0x04b7, 0x04b8, 0x04b9, 0x04ba, 0x04bb, 0x04bc, | |
3194 | + 0x04bd, 0x04be, 0x04bf, 0x04c0, 0x04c1, 0x04af, 0x04c2, 0x04c3, | |
3195 | + 0x04c4, 0x04c5, 0x04c6, 0x04c7, 0x04c8, 0x04c9, 0x04ca, 0x04cb, | |
3196 | + 0x04cc, 0x04cd, 0x04ce, 0x04cf, 0x04d0, 0x04d1, 0x04d2, 0x04d3, | |
3197 | + 0x04ac, 0x04d4, 0x04ad, 0x04d5, 0x04ae, 0x04d6, 0x04d7, 0x04d8, | |
3198 | + 0x04d9, 0x04da, 0x04db, 0x04dc, 0x04a6, 0x04dd, 0x04a5, 0x04b0 | |
3199 | +}; | |
3200 | diff --git a/src/autotype/xcb/keysymmap.py b/src/autotype/xcb/keysymmap.py | |
3201 | new file mode 100755 | |
3202 | index 0000000..a359710 | |
3203 | --- /dev/null | |
3204 | +++ b/src/autotype/xcb/keysymmap.py | |
3205 | @@ -0,0 +1,107 @@ | |
3206 | +#!/usr/bin/python3 | |
3207 | + | |
3208 | +# | |
3209 | +# Copyright (C) 2013 Felix Geyer <debfx@fobos.de> | |
3210 | +# | |
3211 | +# This program is free software: you can redistribute it and/or modify | |
3212 | +# it under the terms of the GNU General Public License as published by | |
3213 | +# the Free Software Foundation, either version 2 or (at your option) | |
3214 | +# version 3 of the License. | |
3215 | +# | |
3216 | +# This program is distributed in the hope that it will be useful, | |
3217 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
3218 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
3219 | +# GNU General Public License for more details. | |
3220 | +# | |
3221 | +# You should have received a copy of the GNU General Public License | |
3222 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
3223 | +# | |
3224 | + | |
3225 | +# | |
3226 | +# Parses keysymdef.h to construct a unicode symbol -> keysym mapping table. | |
3227 | +# | |
3228 | +# The lines that are parsed look like this: | |
3229 | +# #define XK_Aogonek 0x01a1 /* U+0104 LATIN CAPITAL LETTER A WITH OGONEK */ | |
3230 | +# | |
3231 | +# This would create a 0x0104 -> 0x01a1 mapping. | |
3232 | +# | |
3233 | + | |
3234 | +import sys | |
3235 | +import re | |
3236 | +import collections | |
3237 | + | |
3238 | +cols = 8 | |
3239 | + | |
3240 | +if len(sys.argv) >= 2: | |
3241 | + keysymdef = sys.argv[1] | |
3242 | +else: | |
3243 | + keysymdef = "/usr/include/X11/keysymdef.h" | |
3244 | + | |
3245 | +keysymMap = {} | |
3246 | + | |
3247 | +f = open(keysymdef, "r") | |
3248 | +for line in f: | |
3249 | + match = re.search(r'0x([0-9a-fA-F]+)\s+/\* U\+([0-9a-fA-F]+)', line) | |
3250 | + if match: | |
3251 | + keysym = int(match.group(1), 16) | |
3252 | + unicodeVal = int(match.group(2), 16) | |
3253 | + | |
3254 | + # ignore 1:1 mappings | |
3255 | + if keysym >= 0x0020 and keysym <= 0x007e: | |
3256 | + continue | |
3257 | + if keysym >= 0x00a0 and keysym <= 0x00ff: | |
3258 | + continue | |
3259 | + # ignore unicode | 0x01000000 mappings | |
3260 | + if keysym >= 0x1000000: | |
3261 | + continue | |
3262 | + | |
3263 | + keysymMap[unicodeVal] = keysym | |
3264 | + | |
3265 | +keysymMap = collections.OrderedDict(sorted(keysymMap.items(), key=lambda t: t[0])) | |
3266 | + | |
3267 | +print("""/* | |
3268 | + * Automatically generated by keysymmap.py from parsing keysymdef.h. | |
3269 | + */ | |
3270 | +""") | |
3271 | + | |
3272 | +print("const int AutoTypePlatformX11::m_unicodeToKeysymLen = " + str(len(keysymMap)) + ";") | |
3273 | + | |
3274 | +print() | |
3275 | + | |
3276 | +print("const uint AutoTypePlatformX11::m_unicodeToKeysymKeys[] = {") | |
3277 | +keys = keysymMap.keys() | |
3278 | +keyLen = len(keys) | |
3279 | +i = 1 | |
3280 | +for val in keys: | |
3281 | + hexVal = "{0:#0{1}x}".format(val, 6) | |
3282 | + | |
3283 | + if i == keyLen: | |
3284 | + print(hexVal) | |
3285 | + elif (i % cols) == 0: | |
3286 | + print(hexVal + ",") | |
3287 | + elif ((i - 1) % cols) == 0: | |
3288 | + print(" " + hexVal + ", ", end="") | |
3289 | + else: | |
3290 | + print(hexVal + ", ", end="") | |
3291 | + i += 1 | |
3292 | +print("};") | |
3293 | + | |
3294 | +print() | |
3295 | + | |
3296 | +print("const uint AutoTypePlatformX11::m_unicodeToKeysymValues[] = {") | |
3297 | +values = keysymMap.values() | |
3298 | +valuesLen = len(values) | |
3299 | +i = 1 | |
3300 | +for val in values: | |
3301 | + hexVal = "{0:#0{1}x}".format(val, 6) | |
3302 | + | |
3303 | + if i == valuesLen: | |
3304 | + print(hexVal) | |
3305 | + elif (i % cols) == 0: | |
3306 | + print(hexVal + ",") | |
3307 | + elif ((i - 1) % cols) == 0: | |
3308 | + print(" " + hexVal + ", ", end="") | |
3309 | + else: | |
3310 | + print(hexVal + ", ", end="") | |
3311 | + i += 1 | |
3312 | +print("};") | |
3313 | diff --git a/src/config-keepassx.h.cmake b/src/config-keepassx.h.cmake | |
3314 | index 197c0d3..dc418b6 100644 | |
3315 | --- a/src/config-keepassx.h.cmake | |
3316 | +++ b/src/config-keepassx.h.cmake | |
3317 | @@ -16,6 +16,4 @@ | |
3318 | #cmakedefine HAVE_RLIMIT_CORE 1 | |
3319 | #cmakedefine HAVE_PT_DENY_ATTACH 1 | |
3320 | ||
3321 | -#cmakedefine GCRYPT_HAS_SALSA20 | |
3322 | - | |
3323 | #endif // KEEPASSX_CONFIG_KEEPASSX_H | |
3324 | diff --git a/src/core/AutoTypeAssociations.h b/src/core/AutoTypeAssociations.h | |
3325 | index 1b5871b..491a5db 100644 | |
3326 | --- a/src/core/AutoTypeAssociations.h | |
3327 | +++ b/src/core/AutoTypeAssociations.h | |
3328 | @@ -20,8 +20,6 @@ | |
3329 | ||
3330 | #include <QObject> | |
3331 | ||
3332 | -#include "core/Global.h" | |
3333 | - | |
3334 | class AutoTypeAssociations : public QObject | |
3335 | { | |
3336 | Q_OBJECT | |
3337 | @@ -36,7 +34,7 @@ public: | |
3338 | bool operator!=(const AutoTypeAssociations::Association& other) const; | |
3339 | }; | |
3340 | ||
3341 | - explicit AutoTypeAssociations(QObject* parent = Q_NULLPTR); | |
3342 | + explicit AutoTypeAssociations(QObject* parent = nullptr); | |
3343 | void copyDataFrom(const AutoTypeAssociations* other); | |
3344 | void add(const AutoTypeAssociations::Association& association); | |
3345 | void remove(int index); | |
3346 | diff --git a/src/core/Config.cpp b/src/core/Config.cpp | |
3347 | index 046a0fe..5b06c22 100644 | |
3348 | --- a/src/core/Config.cpp | |
3349 | +++ b/src/core/Config.cpp | |
3350 | @@ -18,12 +18,12 @@ | |
3351 | #include "Config.h" | |
3352 | ||
3353 | #include <QCoreApplication> | |
3354 | -#include <QDesktopServices> | |
3355 | #include <QDir> | |
3356 | #include <QSettings> | |
3357 | +#include <QStandardPaths> | |
3358 | #include <QTemporaryFile> | |
3359 | ||
3360 | -Config* Config::m_instance(Q_NULLPTR); | |
3361 | +Config* Config::m_instance(nullptr); | |
3362 | ||
3363 | QVariant Config::get(const QString& key) | |
3364 | { | |
3365 | @@ -53,7 +53,7 @@ Config::Config(QObject* parent) | |
3366 | QString homePath = QDir::homePath(); | |
3367 | ||
3368 | #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) | |
3369 | - // we can't use QDesktopServices on X11 as it uses XDG_DATA_HOME instead of XDG_CONFIG_HOME | |
3370 | + // we can't use QStandardPaths on X11 as it uses XDG_DATA_HOME instead of XDG_CONFIG_HOME | |
3371 | QByteArray env = qgetenv("XDG_CONFIG_HOME"); | |
3372 | if (env.isEmpty()) { | |
3373 | userPath = homePath; | |
3374 | @@ -70,7 +70,7 @@ Config::Config(QObject* parent) | |
3375 | ||
3376 | userPath += "/keepassx/"; | |
3377 | #else | |
3378 | - userPath = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::DataLocation)); | |
3379 | + userPath = QDir::fromNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); | |
3380 | // storageLocation() appends the application name ("/keepassx") to the end | |
3381 | userPath += "/"; | |
3382 | #endif | |
3383 | diff --git a/src/core/Config.h b/src/core/Config.h | |
3384 | index ca0f74c..09aa02f 100644 | |
3385 | --- a/src/core/Config.h | |
3386 | +++ b/src/core/Config.h | |
3387 | @@ -21,8 +21,6 @@ | |
3388 | #include <QScopedPointer> | |
3389 | #include <QVariant> | |
3390 | ||
3391 | -#include "core/Global.h" | |
3392 | - | |
3393 | class QSettings; | |
3394 | ||
3395 | class Config : public QObject | |
3396 | diff --git a/src/core/Database.cpp b/src/core/Database.cpp | |
3397 | index 098cc06..6f94235 100644 | |
3398 | --- a/src/core/Database.cpp | |
3399 | +++ b/src/core/Database.cpp | |
3400 | @@ -23,7 +23,6 @@ | |
3401 | ||
3402 | #include "core/Group.h" | |
3403 | #include "core/Metadata.h" | |
3404 | -#include "core/Tools.h" | |
3405 | #include "crypto/Random.h" | |
3406 | #include "format/KeePass2.h" | |
3407 | ||
3408 | @@ -105,7 +104,7 @@ Entry* Database::recFindEntry(const Uuid& uuid, Group* group) | |
3409 | } | |
3410 | } | |
3411 | ||
3412 | - return Q_NULLPTR; | |
3413 | + return nullptr; | |
3414 | } | |
3415 | ||
3416 | Group* Database::resolveGroup(const Uuid& uuid) | |
3417 | @@ -126,7 +125,7 @@ Group* Database::recFindGroup(const Uuid& uuid, Group* group) | |
3418 | } | |
3419 | } | |
3420 | ||
3421 | - return Q_NULLPTR; | |
3422 | + return nullptr; | |
3423 | } | |
3424 | ||
3425 | QList<DeletedObject> Database::deletedObjects() | |
3426 | @@ -143,7 +142,7 @@ void Database::addDeletedObject(const DeletedObject& delObj) | |
3427 | void Database::addDeletedObject(const Uuid& uuid) | |
3428 | { | |
3429 | DeletedObject delObj; | |
3430 | - delObj.deletionTime = Tools::currentDateTimeUtc(); | |
3431 | + delObj.deletionTime = QDateTime::currentDateTimeUtc(); | |
3432 | delObj.uuid = uuid; | |
3433 | ||
3434 | addDeletedObject(delObj); | |
3435 | @@ -223,7 +222,7 @@ bool Database::setKey(const CompositeKey& key, const QByteArray& transformSeed, | |
3436 | m_data.transformedMasterKey = transformedMasterKey; | |
3437 | m_data.hasKey = true; | |
3438 | if (updateChangedTime) { | |
3439 | - m_metadata->setMasterKeyChanged(Tools::currentDateTimeUtc()); | |
3440 | + m_metadata->setMasterKeyChanged(QDateTime::currentDateTimeUtc()); | |
3441 | } | |
3442 | Q_EMIT modifiedImmediate(); | |
3443 | ||
3444 | diff --git a/src/core/Database.h b/src/core/Database.h | |
3445 | index 97ccad2..6fde3c6 100644 | |
3446 | --- a/src/core/Database.h | |
3447 | +++ b/src/core/Database.h | |
3448 | @@ -20,6 +20,7 @@ | |
3449 | ||
3450 | #include <QDateTime> | |
3451 | #include <QHash> | |
3452 | +#include <QObject> | |
3453 | ||
3454 | #include "core/Uuid.h" | |
3455 | #include "keys/CompositeKey.h" | |
3456 | diff --git a/src/core/DatabaseIcons.cpp b/src/core/DatabaseIcons.cpp | |
3457 | index d6e816f..4e62f79 100644 | |
3458 | --- a/src/core/DatabaseIcons.cpp | |
3459 | +++ b/src/core/DatabaseIcons.cpp | |
3460 | @@ -19,7 +19,7 @@ | |
3461 | ||
3462 | #include "core/FilePath.h" | |
3463 | ||
3464 | -DatabaseIcons* DatabaseIcons::m_instance(Q_NULLPTR); | |
3465 | +DatabaseIcons* DatabaseIcons::m_instance(nullptr); | |
3466 | const int DatabaseIcons::IconCount(69); | |
3467 | const int DatabaseIcons::ExpiredIconIndex(45); | |
3468 | const char* const DatabaseIcons::m_indexToName[] = { | |
3469 | diff --git a/src/core/DatabaseIcons.h b/src/core/DatabaseIcons.h | |
3470 | index 68d1e0c..a1d9480 100644 | |
3471 | --- a/src/core/DatabaseIcons.h | |
3472 | +++ b/src/core/DatabaseIcons.h | |
3473 | @@ -23,8 +23,6 @@ | |
3474 | #include <QPixmapCache> | |
3475 | #include <QVector> | |
3476 | ||
3477 | -#include "core/Global.h" | |
3478 | - | |
3479 | class DatabaseIcons | |
3480 | { | |
3481 | public: | |
3482 | diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp | |
3483 | index 784b489..2fd52d0 100644 | |
3484 | --- a/src/core/Entry.cpp | |
3485 | +++ b/src/core/Entry.cpp | |
3486 | @@ -21,7 +21,6 @@ | |
3487 | #include "core/DatabaseIcons.h" | |
3488 | #include "core/Group.h" | |
3489 | #include "core/Metadata.h" | |
3490 | -#include "core/Tools.h" | |
3491 | ||
3492 | const int Entry::DefaultIconNumber = 0; | |
3493 | ||
3494 | @@ -29,7 +28,7 @@ Entry::Entry() | |
3495 | : m_attributes(new EntryAttributes(this)) | |
3496 | , m_attachments(new EntryAttachments(this)) | |
3497 | , m_autoTypeAssociations(new AutoTypeAssociations(this)) | |
3498 | - , m_tmpHistoryItem(Q_NULLPTR) | |
3499 | + , m_tmpHistoryItem(nullptr) | |
3500 | , m_modifiedSinceBegin(false) | |
3501 | , m_updateTimeinfo(true) | |
3502 | { | |
3503 | @@ -74,8 +73,8 @@ template <class T> inline bool Entry::set(T& property, const T& value) | |
3504 | void Entry::updateTimeinfo() | |
3505 | { | |
3506 | if (m_updateTimeinfo) { | |
3507 | - m_data.timeInfo.setLastModificationTime(Tools::currentDateTimeUtc()); | |
3508 | - m_data.timeInfo.setLastAccessTime(Tools::currentDateTimeUtc()); | |
3509 | + m_data.timeInfo.setLastModificationTime(QDateTime::currentDateTimeUtc()); | |
3510 | + m_data.timeInfo.setLastAccessTime(QDateTime::currentDateTimeUtc()); | |
3511 | } | |
3512 | } | |
3513 | ||
3514 | @@ -223,7 +222,7 @@ QString Entry::notes() const | |
3515 | ||
3516 | bool Entry::isExpired() const | |
3517 | { | |
3518 | - return m_data.timeInfo.expires() && m_data.timeInfo.expiryTime() < Tools::currentDateTimeUtc(); | |
3519 | + return m_data.timeInfo.expires() && m_data.timeInfo.expiryTime() < QDateTime::currentDateTimeUtc(); | |
3520 | } | |
3521 | ||
3522 | EntryAttributes* Entry::attributes() | |
3523 | @@ -474,7 +473,7 @@ Entry* Entry::clone(CloneFlags flags) const | |
3524 | entry->setUpdateTimeinfo(true); | |
3525 | ||
3526 | if (flags & CloneResetTimeInfo) { | |
3527 | - QDateTime now = Tools::currentDateTimeUtc(); | |
3528 | + QDateTime now = QDateTime::currentDateTimeUtc(); | |
3529 | entry->m_data.timeInfo.setCreationTime(now); | |
3530 | entry->m_data.timeInfo.setLastModificationTime(now); | |
3531 | entry->m_data.timeInfo.setLastAccessTime(now); | |
3532 | @@ -522,7 +521,7 @@ void Entry::endUpdate() | |
3533 | delete m_tmpHistoryItem; | |
3534 | } | |
3535 | ||
3536 | - m_tmpHistoryItem = Q_NULLPTR; | |
3537 | + m_tmpHistoryItem = nullptr; | |
3538 | } | |
3539 | ||
3540 | void Entry::updateModifiedSinceBegin() | |
3541 | @@ -568,7 +567,7 @@ void Entry::setGroup(Group* group) | |
3542 | QObject::setParent(group); | |
3543 | ||
3544 | if (m_updateTimeinfo) { | |
3545 | - m_data.timeInfo.setLocationChanged(Tools::currentDateTimeUtc()); | |
3546 | + m_data.timeInfo.setLocationChanged(QDateTime::currentDateTimeUtc()); | |
3547 | } | |
3548 | } | |
3549 | ||
3550 | @@ -583,7 +582,7 @@ const Database* Entry::database() const | |
3551 | return m_group->database(); | |
3552 | } | |
3553 | else { | |
3554 | - return Q_NULLPTR; | |
3555 | + return nullptr; | |
3556 | } | |
3557 | } | |
3558 | ||
3559 | diff --git a/src/core/Entry.h b/src/core/Entry.h | |
3560 | index 3044dc8..cd7c7b7 100644 | |
3561 | --- a/src/core/Entry.h | |
3562 | +++ b/src/core/Entry.h | |
3563 | @@ -29,7 +29,6 @@ | |
3564 | #include "core/AutoTypeAssociations.h" | |
3565 | #include "core/EntryAttachments.h" | |
3566 | #include "core/EntryAttributes.h" | |
3567 | -#include "core/Global.h" | |
3568 | #include "core/TimeInfo.h" | |
3569 | #include "core/Uuid.h" | |
3570 | ||
3571 | diff --git a/src/core/EntryAttachments.h b/src/core/EntryAttachments.h | |
3572 | index 3446b31..903ca10 100644 | |
3573 | --- a/src/core/EntryAttachments.h | |
3574 | +++ b/src/core/EntryAttachments.h | |
3575 | @@ -21,14 +21,12 @@ | |
3576 | #include <QMap> | |
3577 | #include <QObject> | |
3578 | ||
3579 | -#include "core/Global.h" | |
3580 | - | |
3581 | class EntryAttachments : public QObject | |
3582 | { | |
3583 | Q_OBJECT | |
3584 | ||
3585 | public: | |
3586 | - explicit EntryAttachments(QObject* parent = Q_NULLPTR); | |
3587 | + explicit EntryAttachments(QObject* parent = nullptr); | |
3588 | QList<QString> keys() const; | |
3589 | bool hasKey(const QString& key) const; | |
3590 | QList<QByteArray> values() const; | |
3591 | diff --git a/src/core/EntryAttributes.h b/src/core/EntryAttributes.h | |
3592 | index 334eb0a..c6bbf29 100644 | |
3593 | --- a/src/core/EntryAttributes.h | |
3594 | +++ b/src/core/EntryAttributes.h | |
3595 | @@ -23,14 +23,12 @@ | |
3596 | #include <QSet> | |
3597 | #include <QStringList> | |
3598 | ||
3599 | -#include "core/Global.h" | |
3600 | - | |
3601 | class EntryAttributes : public QObject | |
3602 | { | |
3603 | Q_OBJECT | |
3604 | ||
3605 | public: | |
3606 | - explicit EntryAttributes(QObject* parent = Q_NULLPTR); | |
3607 | + explicit EntryAttributes(QObject* parent = nullptr); | |
3608 | QList<QString> keys() const; | |
3609 | bool hasKey(const QString& key) const; | |
3610 | QList<QString> customKeys(); | |
3611 | diff --git a/src/core/EntrySearcher.cpp b/src/core/EntrySearcher.cpp | |
3612 | index 82a553e..05c4c58 100644 | |
3613 | --- a/src/core/EntrySearcher.cpp | |
3614 | +++ b/src/core/EntrySearcher.cpp | |
3615 | @@ -19,7 +19,8 @@ | |
3616 | ||
3617 | #include "core/Group.h" | |
3618 | ||
3619 | -QList<Entry*> EntrySearcher::search(const QString &searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity) | |
3620 | +QList<Entry*> EntrySearcher::search(const QString& searchTerm, const Group* group, | |
3621 | + Qt::CaseSensitivity caseSensitivity) | |
3622 | { | |
3623 | if (!group->resolveSearchingEnabled()) { | |
3624 | return QList<Entry*>(); | |
3625 | @@ -28,7 +29,8 @@ QList<Entry*> EntrySearcher::search(const QString &searchTerm, const Group* grou | |
3626 | return searchEntries(searchTerm, group, caseSensitivity); | |
3627 | } | |
3628 | ||
3629 | -QList<Entry*> EntrySearcher::searchEntries(const QString& searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity) | |
3630 | +QList<Entry*> EntrySearcher::searchEntries(const QString& searchTerm, const Group* group, | |
3631 | + Qt::CaseSensitivity caseSensitivity) | |
3632 | { | |
3633 | QList<Entry*> searchResult; | |
3634 | ||
3635 | @@ -44,7 +46,8 @@ QList<Entry*> EntrySearcher::searchEntries(const QString& searchTerm, const Grou | |
3636 | return searchResult; | |
3637 | } | |
3638 | ||
3639 | -QList<Entry*> EntrySearcher::matchEntry(const QString& searchTerm, Entry* entry, Qt::CaseSensitivity caseSensitivity) | |
3640 | +QList<Entry*> EntrySearcher::matchEntry(const QString& searchTerm, Entry* entry, | |
3641 | + Qt::CaseSensitivity caseSensitivity) | |
3642 | { | |
3643 | QStringList wordList = searchTerm.split(QRegExp("\\s"), QString::SkipEmptyParts); | |
3644 | Q_FOREACH (const QString& word, wordList) { | |
3645 | diff --git a/src/core/EntrySearcher.h b/src/core/EntrySearcher.h | |
3646 | index 246538c..c7075dc 100644 | |
3647 | --- a/src/core/EntrySearcher.h | |
3648 | +++ b/src/core/EntrySearcher.h | |
3649 | @@ -28,10 +28,11 @@ class EntrySearcher | |
3650 | { | |
3651 | public: | |
3652 | QList<Entry*> search(const QString& searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity); | |
3653 | + | |
3654 | private: | |
3655 | QList<Entry*> searchEntries(const QString& searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity); | |
3656 | QList<Entry*> matchEntry(const QString& searchTerm, Entry* entry, Qt::CaseSensitivity caseSensitivity); | |
3657 | - bool wordMatch(const QString &word, Entry *entry, Qt::CaseSensitivity caseSensitivity); | |
3658 | + bool wordMatch(const QString& word, Entry* entry, Qt::CaseSensitivity caseSensitivity); | |
3659 | }; | |
3660 | ||
3661 | #endif // KEEPASSX_ENTRYSEARCHER_H | |
3662 | diff --git a/src/core/FilePath.cpp b/src/core/FilePath.cpp | |
3663 | index f7c4075..497568a 100644 | |
3664 | --- a/src/core/FilePath.cpp | |
3665 | +++ b/src/core/FilePath.cpp | |
3666 | @@ -23,7 +23,7 @@ | |
3667 | ||
3668 | #include "config-keepassx.h" | |
3669 | ||
3670 | -FilePath* FilePath::m_instance(Q_NULLPTR); | |
3671 | +FilePath* FilePath::m_instance(nullptr); | |
3672 | ||
3673 | QString FilePath::dataPath(const QString& name) | |
3674 | { | |
3675 | diff --git a/src/core/FilePath.h b/src/core/FilePath.h | |
3676 | index 9e98d3e..c37a908 100644 | |
3677 | --- a/src/core/FilePath.h | |
3678 | +++ b/src/core/FilePath.h | |
3679 | @@ -22,8 +22,6 @@ | |
3680 | #include <QIcon> | |
3681 | #include <QString> | |
3682 | ||
3683 | -#include "core/Global.h" | |
3684 | - | |
3685 | class FilePath | |
3686 | { | |
3687 | public: | |
3688 | diff --git a/src/core/Global.h b/src/core/Global.h | |
3689 | index 914c7b4..14281ee 100644 | |
3690 | --- a/src/core/Global.h | |
3691 | +++ b/src/core/Global.h | |
3692 | @@ -20,104 +20,8 @@ | |
3693 | #ifndef KEEPASSX_GLOBAL_H | |
3694 | #define KEEPASSX_GLOBAL_H | |
3695 | ||
3696 | -// mostly copied from qcompilerdetection.h which is part of Qt 5 | |
3697 | - | |
3698 | #include <QtGlobal> | |
3699 | ||
3700 | -#ifdef Q_CC_CLANG | |
3701 | -# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) | |
3702 | -# if __has_feature(cxx_strong_enums) | |
3703 | -# define COMPILER_CLASS_ENUM | |
3704 | -# endif | |
3705 | -# if __has_feature(cxx_constexpr) | |
3706 | -# define COMPILER_CONSTEXPR | |
3707 | -# endif | |
3708 | -# if __has_feature(cxx_decltype) /* && __has_feature(cxx_decltype_incomplete_return_types) */ | |
3709 | -# define COMPILER_DECLTYPE | |
3710 | -# endif | |
3711 | -# if __has_feature(cxx_override_control) | |
3712 | -# define COMPILER_EXPLICIT_OVERRIDES | |
3713 | -# endif | |
3714 | -# if __has_feature(cxx_nullptr) | |
3715 | -# define COMPILER_NULLPTR | |
3716 | -# endif | |
3717 | -# if __has_feature(cxx_static_assert) | |
3718 | -# define COMPILER_STATIC_ASSERT | |
3719 | -# endif | |
3720 | -# endif | |
3721 | -#endif // Q_CC_CLANG | |
3722 | - | |
3723 | -#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG) | |
3724 | -# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L | |
3725 | -# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403 | |
3726 | -# define COMPILER_DECLTYPE | |
3727 | -# define COMPILER_STATIC_ASSERT | |
3728 | -# endif | |
3729 | -# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 404 | |
3730 | -# define COMPILER_CLASS_ENUM | |
3731 | -# endif | |
3732 | -# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 | |
3733 | -# define COMPILER_CONSTEXPR | |
3734 | -# define COMPILER_NULLPTR | |
3735 | -# endif | |
3736 | -# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 407 | |
3737 | -# define COMPILER_EXPLICIT_OVERRIDES | |
3738 | -# endif | |
3739 | -# endif | |
3740 | -#endif | |
3741 | - | |
3742 | -/* | |
3743 | - * C++11 keywords and expressions | |
3744 | - */ | |
3745 | -#if !defined(Q_NULLPTR) | |
3746 | -# ifdef COMPILER_NULLPTR | |
3747 | -# define Q_NULLPTR nullptr | |
3748 | -# else | |
3749 | -# define Q_NULLPTR 0 | |
3750 | -# endif | |
3751 | -#endif | |
3752 | - | |
3753 | -#if !defined(Q_DECL_CONSTEXPR) | |
3754 | -# ifdef COMPILER_CONSTEXPR | |
3755 | -# define Q_DECL_CONSTEXPR constexpr | |
3756 | -# else | |
3757 | -# define Q_DECL_CONSTEXPR | |
3758 | -# endif | |
3759 | -#endif | |
3760 | - | |
3761 | -#if !defined(Q_DECL_OVERRIDE) && !defined(Q_DECL_FINAL) && !defined(Q_DECL_FINAL_CLASS) | |
3762 | -# ifdef COMPILER_EXPLICIT_OVERRIDES | |
3763 | -# define Q_DECL_OVERRIDE override | |
3764 | -# define Q_DECL_FINAL final | |
3765 | -# ifdef COMPILER_DECLTYPE | |
3766 | -# define Q_DECL_FINAL_CLASS final | |
3767 | -# else | |
3768 | -# define Q_DECL_FINAL_CLASS | |
3769 | -# endif | |
3770 | -# else | |
3771 | -# define Q_DECL_OVERRIDE | |
3772 | -# define Q_DECL_FINAL | |
3773 | -# define Q_DECL_FINAL_CLASS | |
3774 | -# endif | |
3775 | -#endif | |
3776 | - | |
3777 | -#if !defined(Q_STATIC_ASSERT) && !defined(Q_STATIC_ASSERT_X) | |
3778 | -#ifdef COMPILER_STATIC_ASSERT | |
3779 | -#define Q_STATIC_ASSERT(Condition) static_assert(static_cast<bool>(Condition), #Condition) | |
3780 | -#define Q_STATIC_ASSERT_X(Condition, Message) static_assert(static_cast<bool>(Condition), Message) | |
3781 | -#else | |
3782 | -// Intentionally undefined | |
3783 | -template <bool Test> class QStaticAssertFailure; | |
3784 | -template <> class QStaticAssertFailure<true> {}; | |
3785 | - | |
3786 | -#define Q_STATIC_ASSERT_PRIVATE_JOIN(A, B) Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) | |
3787 | -#define Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) A ## B | |
3788 | -#define Q_STATIC_ASSERT(Condition) \ | |
3789 | - enum {Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) = sizeof(QStaticAssertFailure<!!(Condition)>)} | |
3790 | -#define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition) | |
3791 | -#endif // COMPILER_STATIC_ASSERT | |
3792 | -#endif // !defined(Q_STATIC_ASSERT) && !defined(Q_STATIC_ASSERT_X) | |
3793 | - | |
3794 | #if defined(Q_OS_WIN) | |
3795 | # if defined(KEEPASSX_BUILDING_CORE) | |
3796 | # define KEEPASSX_EXPORT Q_DECL_EXPORT | |
3797 | diff --git a/src/core/Group.cpp b/src/core/Group.cpp | |
3798 | index 371f3e4..2b9e9bc 100644 | |
3799 | --- a/src/core/Group.cpp | |
3800 | +++ b/src/core/Group.cpp | |
3801 | @@ -20,7 +20,6 @@ | |
3802 | #include "core/Config.h" | |
3803 | #include "core/DatabaseIcons.h" | |
3804 | #include "core/Metadata.h" | |
3805 | -#include "core/Tools.h" | |
3806 | ||
3807 | const int Group::DefaultIconNumber = 48; | |
3808 | const int Group::RecycleBinIconNumber = 43; | |
3809 | @@ -50,7 +49,7 @@ Group::~Group() | |
3810 | ||
3811 | if (m_db && m_parent) { | |
3812 | DeletedObject delGroup; | |
3813 | - delGroup.deletionTime = Tools::currentDateTimeUtc(); | |
3814 | + delGroup.deletionTime = QDateTime::currentDateTimeUtc(); | |
3815 | delGroup.uuid = m_uuid; | |
3816 | m_db->addDeletedObject(delGroup); | |
3817 | } | |
3818 | @@ -84,8 +83,8 @@ template <class P, class V> inline bool Group::set(P& property, const V& value) | |
3819 | void Group::updateTimeinfo() | |
3820 | { | |
3821 | if (m_updateTimeinfo) { | |
3822 | - m_data.timeInfo.setLastModificationTime(Tools::currentDateTimeUtc()); | |
3823 | - m_data.timeInfo.setLastAccessTime(Tools::currentDateTimeUtc()); | |
3824 | + m_data.timeInfo.setLastModificationTime(QDateTime::currentDateTimeUtc()); | |
3825 | + m_data.timeInfo.setLastAccessTime(QDateTime::currentDateTimeUtc()); | |
3826 | } | |
3827 | } | |
3828 | ||
3829 | @@ -203,7 +202,7 @@ Entry* Group::lastTopVisibleEntry() const | |
3830 | ||
3831 | bool Group::isExpired() const | |
3832 | { | |
3833 | - return m_data.timeInfo.expires() && m_data.timeInfo.expiryTime() < Tools::currentDateTimeUtc(); | |
3834 | + return m_data.timeInfo.expires() && m_data.timeInfo.expiryTime() < QDateTime::currentDateTimeUtc(); | |
3835 | } | |
3836 | ||
3837 | void Group::setUuid(const Uuid& uuid) | |
3838 | @@ -365,7 +364,7 @@ void Group::setParent(Group* parent, int index) | |
3839 | } | |
3840 | ||
3841 | if (m_updateTimeinfo) { | |
3842 | - m_data.timeInfo.setLocationChanged(Tools::currentDateTimeUtc()); | |
3843 | + m_data.timeInfo.setLocationChanged(QDateTime::currentDateTimeUtc()); | |
3844 | } | |
3845 | ||
3846 | Q_EMIT modified(); | |
3847 | @@ -385,7 +384,7 @@ void Group::setParent(Database* db) | |
3848 | ||
3849 | cleanupParent(); | |
3850 | ||
3851 | - m_parent = Q_NULLPTR; | |
3852 | + m_parent = nullptr; | |
3853 | recSetDatabase(db); | |
3854 | ||
3855 | QObject::setParent(db); | |
3856 | @@ -510,7 +509,7 @@ Group* Group::clone(Entry::CloneFlags entryFlags) const | |
3857 | ||
3858 | clonedGroup->setUpdateTimeinfo(true); | |
3859 | ||
3860 | - QDateTime now = Tools::currentDateTimeUtc(); | |
3861 | + QDateTime now = QDateTime::currentDateTimeUtc(); | |
3862 | clonedGroup->m_data.timeInfo.setCreationTime(now); | |
3863 | clonedGroup->m_data.timeInfo.setLastModificationTime(now); | |
3864 | clonedGroup->m_data.timeInfo.setLastAccessTime(now); | |
3865 | diff --git a/src/core/InactivityTimer.h b/src/core/InactivityTimer.h | |
3866 | index e0a21e0..ba571a5 100644 | |
3867 | --- a/src/core/InactivityTimer.h | |
3868 | +++ b/src/core/InactivityTimer.h | |
3869 | @@ -21,8 +21,6 @@ | |
3870 | #include <QMutex> | |
3871 | #include <QObject> | |
3872 | ||
3873 | -#include "core/Global.h" | |
3874 | - | |
3875 | class QTimer; | |
3876 | ||
3877 | class InactivityTimer : public QObject | |
3878 | @@ -30,7 +28,7 @@ class InactivityTimer : public QObject | |
3879 | Q_OBJECT | |
3880 | ||
3881 | public: | |
3882 | - explicit InactivityTimer(QObject* parent = Q_NULLPTR); | |
3883 | + explicit InactivityTimer(QObject* parent = nullptr); | |
3884 | void setInactivityTimeout(int inactivityTimeout); | |
3885 | void activate(); | |
3886 | void deactivate(); | |
3887 | diff --git a/src/core/Metadata.cpp b/src/core/Metadata.cpp | |
3888 | index 0c67bba..a50c6ef 100644 | |
3889 | --- a/src/core/Metadata.cpp | |
3890 | +++ b/src/core/Metadata.cpp | |
3891 | @@ -42,7 +42,7 @@ Metadata::Metadata(QObject* parent) | |
3892 | m_data.protectNotes = false; | |
3893 | // m_data.autoEnableVisualHiding = false; | |
3894 | ||
3895 | - QDateTime now = Tools::currentDateTimeUtc(); | |
3896 | + QDateTime now = QDateTime::currentDateTimeUtc(); | |
3897 | m_data.nameChanged = now; | |
3898 | m_data.descriptionChanged = now; | |
3899 | m_data.defaultUserNameChanged = now; | |
3900 | @@ -67,7 +67,7 @@ template <class P, class V> bool Metadata::set(P& property, const V& value, QDat | |
3901 | if (property != value) { | |
3902 | property = value; | |
3903 | if (m_updateDatetime) { | |
3904 | - dateTime = Tools::currentDateTimeUtc(); | |
3905 | + dateTime = QDateTime::currentDateTimeUtc(); | |
3906 | } | |
3907 | Q_EMIT modified(); | |
3908 | return true; | |
3909 | diff --git a/src/core/Metadata.h b/src/core/Metadata.h | |
3910 | index 062e552..c35aed3 100644 | |
3911 | --- a/src/core/Metadata.h | |
3912 | +++ b/src/core/Metadata.h | |
3913 | @@ -26,7 +26,6 @@ | |
3914 | #include <QPixmapCache> | |
3915 | #include <QPointer> | |
3916 | ||
3917 | -#include "core/Global.h" | |
3918 | #include "core/Uuid.h" | |
3919 | ||
3920 | class Database; | |
3921 | @@ -37,7 +36,7 @@ class Metadata : public QObject | |
3922 | Q_OBJECT | |
3923 | ||
3924 | public: | |
3925 | - explicit Metadata(QObject* parent = Q_NULLPTR); | |
3926 | + explicit Metadata(QObject* parent = nullptr); | |
3927 | ||
3928 | struct MetadataData | |
3929 | { | |
3930 | diff --git a/src/core/PasswordGenerator.h b/src/core/PasswordGenerator.h | |
3931 | index 6a9d212..cc8196f 100644 | |
3932 | --- a/src/core/PasswordGenerator.h | |
3933 | +++ b/src/core/PasswordGenerator.h | |
3934 | @@ -22,8 +22,6 @@ | |
3935 | #include <QString> | |
3936 | #include <QVector> | |
3937 | ||
3938 | -#include "core/Global.h" | |
3939 | - | |
3940 | typedef QVector<QChar> PasswordGroup; | |
3941 | ||
3942 | class PasswordGenerator | |
3943 | diff --git a/src/core/SignalMultiplexer.cpp b/src/core/SignalMultiplexer.cpp | |
3944 | index a70e9ef..ebf38bf 100644 | |
3945 | --- a/src/core/SignalMultiplexer.cpp | |
3946 | +++ b/src/core/SignalMultiplexer.cpp | |
3947 | @@ -24,7 +24,7 @@ SignalMultiplexer::SignalMultiplexer() | |
3948 | SignalMultiplexer::~SignalMultiplexer() | |
3949 | { | |
3950 | // disconnect all connections | |
3951 | - setCurrentObject(Q_NULLPTR); | |
3952 | + setCurrentObject(nullptr); | |
3953 | } | |
3954 | ||
3955 | QObject* SignalMultiplexer::currentObject() const | |
3956 | diff --git a/src/core/SignalMultiplexer.h b/src/core/SignalMultiplexer.h | |
3957 | index 6d39cd5..b27e1f3 100644 | |
3958 | --- a/src/core/SignalMultiplexer.h | |
3959 | +++ b/src/core/SignalMultiplexer.h | |
3960 | @@ -21,8 +21,6 @@ | |
3961 | #include <QObject> | |
3962 | #include <QPointer> | |
3963 | ||
3964 | -#include "core/Global.h" | |
3965 | - | |
3966 | class SignalMultiplexer | |
3967 | { | |
3968 | public: | |
3969 | diff --git a/src/core/TimeInfo.cpp b/src/core/TimeInfo.cpp | |
3970 | index 2613325..ec6ebde 100644 | |
3971 | --- a/src/core/TimeInfo.cpp | |
3972 | +++ b/src/core/TimeInfo.cpp | |
3973 | @@ -23,7 +23,7 @@ TimeInfo::TimeInfo() | |
3974 | : m_expires(false) | |
3975 | , m_usageCount(0) | |
3976 | { | |
3977 | - QDateTime now = Tools::currentDateTimeUtc(); | |
3978 | + QDateTime now = QDateTime::currentDateTimeUtc(); | |
3979 | m_lastModificationTime = now; | |
3980 | m_creationTime = now; | |
3981 | m_lastAccessTime = now; | |
3982 | diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp | |
3983 | index db3baa8..06eb73d 100644 | |
3984 | --- a/src/core/Tools.cpp | |
3985 | +++ b/src/core/Tools.cpp | |
3986 | @@ -23,11 +23,7 @@ | |
3987 | #include <QLocale> | |
3988 | #include <QStringList> | |
3989 | ||
3990 | -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) | |
3991 | #include <QElapsedTimer> | |
3992 | -#else | |
3993 | -#include <QTime> | |
3994 | -#endif | |
3995 | ||
3996 | #ifdef Q_OS_WIN | |
3997 | #include <windows.h> // for Sleep(), SetDllDirectoryA() and SetSearchPathMode() | |
3998 | @@ -122,15 +118,6 @@ bool readAllFromDevice(QIODevice* device, QByteArray& data) | |
3999 | } | |
4000 | } | |
4001 | ||
4002 | -QDateTime currentDateTimeUtc() | |
4003 | -{ | |
4004 | -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) | |
4005 | - return QDateTime::currentDateTimeUtc(); | |
4006 | -#else | |
4007 | - return QDateTime::currentDateTime().toUTC(); | |
4008 | -#endif | |
4009 | -} | |
4010 | - | |
4011 | QString imageReaderFilter() | |
4012 | { | |
4013 | QList<QByteArray> formats = QImageReader::supportedImageFormats(); | |
4014 | @@ -184,7 +171,7 @@ void sleep(int ms) | |
4015 | timespec ts; | |
4016 | ts.tv_sec = ms / 1000; | |
4017 | ts.tv_nsec = (ms % 1000) * 1000 * 1000; | |
4018 | - nanosleep(&ts, Q_NULLPTR); | |
4019 | + nanosleep(&ts, nullptr); | |
4020 | #endif | |
4021 | } | |
4022 | ||
4023 | @@ -196,11 +183,7 @@ void wait(int ms) | |
4024 | return; | |
4025 | } | |
4026 | ||
4027 | -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) | |
4028 | QElapsedTimer timer; | |
4029 | -#else | |
4030 | - QTime timer; | |
4031 | -#endif | |
4032 | timer.start(); | |
4033 | ||
4034 | if (ms <= 50) { | |
4035 | @@ -215,23 +198,10 @@ void wait(int ms) | |
4036 | QCoreApplication::processEvents(QEventLoop::AllEvents, timeLeft); | |
4037 | sleep(10); | |
4038 | } | |
4039 | - } while (timer.elapsed() < ms); | |
4040 | + } while (!timer.hasExpired(ms)); | |
4041 | } | |
4042 | } | |
4043 | ||
4044 | -QString platform() | |
4045 | -{ | |
4046 | -#if defined(Q_WS_X11) | |
4047 | - return "x11"; | |
4048 | -#elif defined(Q_WS_MAC) | |
4049 | - return "mac"; | |
4050 | -#elif defined(Q_WS_WIN) | |
4051 | - return "win"; | |
4052 | -#else | |
4053 | - return QString(); | |
4054 | -#endif | |
4055 | -} | |
4056 | - | |
4057 | void disableCoreDumps() | |
4058 | { | |
4059 | // default to true | |
4060 | diff --git a/src/core/Tools.h b/src/core/Tools.h | |
4061 | index 68e9dcd..65df1ea 100644 | |
4062 | --- a/src/core/Tools.h | |
4063 | +++ b/src/core/Tools.h | |
4064 | @@ -18,11 +18,13 @@ | |
4065 | #ifndef KEEPASSX_TOOLS_H | |
4066 | #define KEEPASSX_TOOLS_H | |
4067 | ||
4068 | +#include "core/Global.h" | |
4069 | + | |
4070 | #include <QDateTime> | |
4071 | #include <QObject> | |
4072 | #include <QString> | |
4073 | ||
4074 | -#include "core/Global.h" | |
4075 | +#include <algorithm> | |
4076 | ||
4077 | class QIODevice; | |
4078 | ||
4079 | @@ -32,16 +34,27 @@ QString humanReadableFileSize(qint64 bytes); | |
4080 | bool hasChild(const QObject* parent, const QObject* child); | |
4081 | bool readFromDevice(QIODevice* device, QByteArray& data, int size = 16384); | |
4082 | bool readAllFromDevice(QIODevice* device, QByteArray& data); | |
4083 | -QDateTime currentDateTimeUtc(); | |
4084 | QString imageReaderFilter(); | |
4085 | bool isHex(const QByteArray& ba); | |
4086 | bool isBase64(const QByteArray& ba); | |
4087 | void sleep(int ms); | |
4088 | void wait(int ms); | |
4089 | -QString platform(); | |
4090 | void disableCoreDumps(); | |
4091 | void setupSearchPaths(); | |
4092 | ||
4093 | +template <typename RandomAccessIterator, typename T> | |
4094 | +RandomAccessIterator binaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T& value) | |
4095 | +{ | |
4096 | + RandomAccessIterator it = std::lower_bound(begin, end, value); | |
4097 | + | |
4098 | + if ((it == end) || (value < *it)) { | |
4099 | + return end; | |
4100 | + } | |
4101 | + else { | |
4102 | + return it; | |
4103 | + } | |
4104 | +} | |
4105 | + | |
4106 | } // namespace Tools | |
4107 | ||
4108 | #endif // KEEPASSX_TOOLS_H | |
4109 | diff --git a/src/core/qcommandlineoption.cpp b/src/core/qcommandlineoption.cpp | |
4110 | deleted file mode 100644 | |
4111 | index c908807..0000000 | |
4112 | --- a/src/core/qcommandlineoption.cpp | |
4113 | +++ /dev/null | |
4114 | @@ -1,305 +0,0 @@ | |
4115 | -/**************************************************************************** | |
4116 | -** | |
4117 | -** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> | |
4118 | -** Copyright (C) 2013 David Faure <faure@kde.org> | |
4119 | -** Contact: http://www.qt-project.org/legal | |
4120 | -** | |
4121 | -** This file is part of the QtCore module of the Qt Toolkit. | |
4122 | -** | |
4123 | -** $QT_BEGIN_LICENSE:LGPL$ | |
4124 | -** Commercial License Usage | |
4125 | -** Licensees holding valid commercial Qt licenses may use this file in | |
4126 | -** accordance with the commercial license agreement provided with the | |
4127 | -** Software or, alternatively, in accordance with the terms contained in | |
4128 | -** a written agreement between you and Digia. For licensing terms and | |
4129 | -** conditions see http://qt.digia.com/licensing. For further information | |
4130 | -** use the contact form at http://qt.digia.com/contact-us. | |
4131 | -** | |
4132 | -** GNU Lesser General Public License Usage | |
4133 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
4134 | -** General Public License version 2.1 as published by the Free Software | |
4135 | -** Foundation and appearing in the file LICENSE.LGPL included in the | |
4136 | -** packaging of this file. Please review the following information to | |
4137 | -** ensure the GNU Lesser General Public License version 2.1 requirements | |
4138 | -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
4139 | -** | |
4140 | -** In addition, as a special exception, Digia gives you certain additional | |
4141 | -** rights. These rights are described in the Digia Qt LGPL Exception | |
4142 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
4143 | -** | |
4144 | -** GNU General Public License Usage | |
4145 | -** Alternatively, this file may be used under the terms of the GNU | |
4146 | -** General Public License version 3.0 as published by the Free Software | |
4147 | -** Foundation and appearing in the file LICENSE.GPL included in the | |
4148 | -** packaging of this file. Please review the following information to | |
4149 | -** ensure the GNU General Public License version 3.0 requirements will be | |
4150 | -** met: http://www.gnu.org/copyleft/gpl.html. | |
4151 | -** | |
4152 | -** | |
4153 | -** $QT_END_LICENSE$ | |
4154 | -** | |
4155 | -****************************************************************************/ | |
4156 | - | |
4157 | -#include "qcommandlineoption.h" | |
4158 | - | |
4159 | -#include <QSet> | |
4160 | - | |
4161 | -class QCommandLineOptionPrivate : public QSharedData | |
4162 | -{ | |
4163 | -public: | |
4164 | - inline QCommandLineOptionPrivate() | |
4165 | - { } | |
4166 | - | |
4167 | - void setNames(const QStringList &nameList); | |
4168 | - | |
4169 | - //! The list of names used for this option. | |
4170 | - QStringList names; | |
4171 | - | |
4172 | - //! The documentation name for the value, if one is expected | |
4173 | - //! Example: "-o <file>" means valueName == "file" | |
4174 | - QString valueName; | |
4175 | - | |
4176 | - //! The description used for this option. | |
4177 | - QString description; | |
4178 | - | |
4179 | - //! The list of default values used for this option. | |
4180 | - QStringList defaultValues; | |
4181 | -}; | |
4182 | - | |
4183 | -/*! | |
4184 | - \since 5.2 | |
4185 | - \class QCommandLineOption | |
4186 | - \brief The QCommandLineOption class defines a possible command-line option. | |
4187 | - \inmodule QtCore | |
4188 | - \ingroup shared | |
4189 | - \ingroup tools | |
4190 | - | |
4191 | - This class is used to describe an option on the command line. It allows | |
4192 | - different ways of defining the same option with multiple aliases possible. | |
4193 | - It is also used to describe how the option is used - it may be a flag (e.g. \c{-v}) | |
4194 | - or take an argument (e.g. \c{-o file}). | |
4195 | - | |
4196 | - Examples: | |
4197 | - \snippet code/src_corelib_tools_qcommandlineoption.cpp 0 | |
4198 | - | |
4199 | - \sa QCommandLineParser | |
4200 | -*/ | |
4201 | - | |
4202 | -/*! | |
4203 | - Constructs a command line option object with the given arguments. | |
4204 | - | |
4205 | - The name of the option is set to \a name. | |
4206 | - The name can be either short or long. If the name is one character in | |
4207 | - length, it is considered a short name. Option names must not be empty, | |
4208 | - must not start with a dash or a slash character, must not contain a \c{=} | |
4209 | - and cannot be repeated. | |
4210 | - | |
4211 | - The description is set to \a description. It is customary to add a "." | |
4212 | - at the end of the description. | |
4213 | - | |
4214 | - In addition, the \a valueName can be set if the option expects a value. | |
4215 | - The default value for the option is set to \a defaultValue. | |
4216 | - | |
4217 | - \sa setDescription(), setValueName(), setDefaultValues() | |
4218 | -*/ | |
4219 | -QCommandLineOption::QCommandLineOption(const QString &name, const QString &description, | |
4220 | - const QString &valueName, | |
4221 | - const QString &defaultValue) | |
4222 | - : d(new QCommandLineOptionPrivate) | |
4223 | -{ | |
4224 | - d->setNames(QStringList(name)); | |
4225 | - setValueName(valueName); | |
4226 | - setDescription(description); | |
4227 | - setDefaultValue(defaultValue); | |
4228 | -} | |
4229 | - | |
4230 | -/*! | |
4231 | - Constructs a command line option object with the given arguments. | |
4232 | - | |
4233 | - This overload allows to set multiple names for the option, for instance | |
4234 | - \c{o} and \c{output}. | |
4235 | - | |
4236 | - The names of the option are set to \a names. | |
4237 | - The names can be either short or long. Any name in the list that is one | |
4238 | - character in length is a short name. Option names must not be empty, | |
4239 | - must not start with a dash or a slash character, must not contain a \c{=} | |
4240 | - and cannot be repeated. | |
4241 | - | |
4242 | - The description is set to \a description. It is customary to add a "." | |
4243 | - at the end of the description. | |
4244 | - | |
4245 | - In addition, the \a valueName can be set if the option expects a value. | |
4246 | - The default value for the option is set to \a defaultValue. | |
4247 | - | |
4248 | - \sa setDescription(), setValueName(), setDefaultValues() | |
4249 | -*/ | |
4250 | -QCommandLineOption::QCommandLineOption(const QStringList &names, const QString &description, | |
4251 | - const QString &valueName, | |
4252 | - const QString &defaultValue) | |
4253 | - : d(new QCommandLineOptionPrivate) | |
4254 | -{ | |
4255 | - d->setNames(names); | |
4256 | - setValueName(valueName); | |
4257 | - setDescription(description); | |
4258 | - setDefaultValue(defaultValue); | |
4259 | -} | |
4260 | - | |
4261 | -/*! | |
4262 | - Constructs a QCommandLineOption object that is a copy of the QCommandLineOption | |
4263 | - object \a other. | |
4264 | - | |
4265 | - \sa operator=() | |
4266 | -*/ | |
4267 | -QCommandLineOption::QCommandLineOption(const QCommandLineOption &other) | |
4268 | - : d(other.d) | |
4269 | -{ | |
4270 | -} | |
4271 | - | |
4272 | -/*! | |
4273 | - Destroys the command line option object. | |
4274 | -*/ | |
4275 | -QCommandLineOption::~QCommandLineOption() | |
4276 | -{ | |
4277 | -} | |
4278 | - | |
4279 | -/*! | |
4280 | - Makes a copy of the \a other object and assigns it to this QCommandLineOption | |
4281 | - object. | |
4282 | -*/ | |
4283 | -QCommandLineOption &QCommandLineOption::operator=(const QCommandLineOption &other) | |
4284 | -{ | |
4285 | - d = other.d; | |
4286 | - return *this; | |
4287 | -} | |
4288 | - | |
4289 | -/*! | |
4290 | - Returns the names set for this option. | |
4291 | - */ | |
4292 | -QStringList QCommandLineOption::names() const | |
4293 | -{ | |
4294 | - return d->names; | |
4295 | -} | |
4296 | - | |
4297 | -void QCommandLineOptionPrivate::setNames(const QStringList &nameList) | |
4298 | -{ | |
4299 | - QStringList newNames; | |
4300 | - if (nameList.isEmpty()) | |
4301 | - qWarning("QCommandLineOption: Options must have at least one name"); | |
4302 | - Q_FOREACH (const QString &name, nameList) { | |
4303 | - if (name.isEmpty()) { | |
4304 | - qWarning("QCommandLineOption: Option names cannot be empty"); | |
4305 | - } else { | |
4306 | - const QChar c = name.at(0); | |
4307 | - if (c == QLatin1Char('-')) | |
4308 | - qWarning("QCommandLineOption: Option names cannot start with a '-'"); | |
4309 | - else if (c == QLatin1Char('/')) | |
4310 | - qWarning("QCommandLineOption: Option names cannot start with a '/'"); | |
4311 | - else if (name.contains(QLatin1Char('='))) | |
4312 | - qWarning("QCommandLineOption: Option names cannot contain a '='"); | |
4313 | - else | |
4314 | - newNames.append(name); | |
4315 | - } | |
4316 | - } | |
4317 | - // commit | |
4318 | - names = newNames; | |
4319 | -} | |
4320 | - | |
4321 | -/*! | |
4322 | - Sets the name of the expected value, for the documentation, to \a valueName. | |
4323 | - | |
4324 | - Options without a value assigned have a boolean-like behavior: | |
4325 | - either the user specifies --option or they don't. | |
4326 | - | |
4327 | - Options with a value assigned need to set a name for the expected value, | |
4328 | - for the documentation of the option in the help output. An option with names \c{o} and \c{output}, | |
4329 | - and a value name of \c{file} will appear as \c{-o, --output <file>}. | |
4330 | - | |
4331 | - Call QCommandLineParser::argument() if you expect the option to be present | |
4332 | - only once, and QCommandLineParser::arguments() if you expect that option | |
4333 | - to be present multiple times. | |
4334 | - | |
4335 | - \sa valueName() | |
4336 | - */ | |
4337 | -void QCommandLineOption::setValueName(const QString &valueName) | |
4338 | -{ | |
4339 | - d->valueName = valueName; | |
4340 | -} | |
4341 | - | |
4342 | -/*! | |
4343 | - Returns the name of the expected value. | |
4344 | - | |
4345 | - If empty, the option doesn't take a value. | |
4346 | - | |
4347 | - \sa setValueName() | |
4348 | - */ | |
4349 | -QString QCommandLineOption::valueName() const | |
4350 | -{ | |
4351 | - return d->valueName; | |
4352 | -} | |
4353 | - | |
4354 | -/*! | |
4355 | - Sets the description used for this option to \a description. | |
4356 | - | |
4357 | - It is customary to add a "." at the end of the description. | |
4358 | - | |
4359 | - The description is used by QCommandLineParser::showHelp(). | |
4360 | - | |
4361 | - \sa description() | |
4362 | - */ | |
4363 | -void QCommandLineOption::setDescription(const QString &description) | |
4364 | -{ | |
4365 | - d->description = description; | |
4366 | -} | |
4367 | - | |
4368 | -/*! | |
4369 | - Returns the description set for this option. | |
4370 | - | |
4371 | - \sa setDescription() | |
4372 | - */ | |
4373 | -QString QCommandLineOption::description() const | |
4374 | -{ | |
4375 | - return d->description; | |
4376 | -} | |
4377 | - | |
4378 | -/*! | |
4379 | - Sets the default value used for this option to \a defaultValue. | |
4380 | - | |
4381 | - The default value is used if the user of the application does not specify | |
4382 | - the option on the command line. | |
4383 | - | |
4384 | - If \a defaultValue is empty, the option has no default values. | |
4385 | - | |
4386 | - \sa defaultValues() setDefaultValues() | |
4387 | - */ | |
4388 | -void QCommandLineOption::setDefaultValue(const QString &defaultValue) | |
4389 | -{ | |
4390 | - QStringList newDefaultValues; | |
4391 | - if (!defaultValue.isEmpty()) { | |
4392 | - newDefaultValues << defaultValue; | |
4393 | - } | |
4394 | - // commit: | |
4395 | - d->defaultValues = newDefaultValues; | |
4396 | -} | |
4397 | - | |
4398 | -/*! | |
4399 | - Sets the list of default values used for this option to \a defaultValues. | |
4400 | - | |
4401 | - The default values are used if the user of the application does not specify | |
4402 | - the option on the command line. | |
4403 | - | |
4404 | - \sa defaultValues() setDefaultValue() | |
4405 | - */ | |
4406 | -void QCommandLineOption::setDefaultValues(const QStringList &defaultValues) | |
4407 | -{ | |
4408 | - d->defaultValues = defaultValues; | |
4409 | -} | |
4410 | - | |
4411 | -/*! | |
4412 | - Returns the default values set for this option. | |
4413 | - | |
4414 | - \sa setDefaultValues() | |
4415 | - */ | |
4416 | -QStringList QCommandLineOption::defaultValues() const | |
4417 | -{ | |
4418 | - return d->defaultValues; | |
4419 | -} | |
4420 | diff --git a/src/core/qcommandlineoption.h b/src/core/qcommandlineoption.h | |
4421 | deleted file mode 100644 | |
4422 | index b97d44c..0000000 | |
4423 | --- a/src/core/qcommandlineoption.h | |
4424 | +++ /dev/null | |
4425 | @@ -1,81 +0,0 @@ | |
4426 | -/**************************************************************************** | |
4427 | -** | |
4428 | -** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> | |
4429 | -** Contact: http://www.qt-project.org/legal | |
4430 | -** | |
4431 | -** This file is part of the QtCore module of the Qt Toolkit. | |
4432 | -** | |
4433 | -** $QT_BEGIN_LICENSE:LGPL$ | |
4434 | -** Commercial License Usage | |
4435 | -** Licensees holding valid commercial Qt licenses may use this file in | |
4436 | -** accordance with the commercial license agreement provided with the | |
4437 | -** Software or, alternatively, in accordance with the terms contained in | |
4438 | -** a written agreement between you and Digia. For licensing terms and | |
4439 | -** conditions see http://qt.digia.com/licensing. For further information | |
4440 | -** use the contact form at http://qt.digia.com/contact-us. | |
4441 | -** | |
4442 | -** GNU Lesser General Public License Usage | |
4443 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
4444 | -** General Public License version 2.1 as published by the Free Software | |
4445 | -** Foundation and appearing in the file LICENSE.LGPL included in the | |
4446 | -** packaging of this file. Please review the following information to | |
4447 | -** ensure the GNU Lesser General Public License version 2.1 requirements | |
4448 | -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
4449 | -** | |
4450 | -** In addition, as a special exception, Digia gives you certain additional | |
4451 | -** rights. These rights are described in the Digia Qt LGPL Exception | |
4452 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
4453 | -** | |
4454 | -** GNU General Public License Usage | |
4455 | -** Alternatively, this file may be used under the terms of the GNU | |
4456 | -** General Public License version 3.0 as published by the Free Software | |
4457 | -** Foundation and appearing in the file LICENSE.GPL included in the | |
4458 | -** packaging of this file. Please review the following information to | |
4459 | -** ensure the GNU General Public License version 3.0 requirements will be | |
4460 | -** met: http://www.gnu.org/copyleft/gpl.html. | |
4461 | -** | |
4462 | -** | |
4463 | -** $QT_END_LICENSE$ | |
4464 | -** | |
4465 | -****************************************************************************/ | |
4466 | - | |
4467 | -#ifndef QCOMMANDLINEOPTION_H | |
4468 | -#define QCOMMANDLINEOPTION_H | |
4469 | - | |
4470 | -#include <QStringList> | |
4471 | -#include <QSharedData> | |
4472 | - | |
4473 | -class QCommandLineOptionPrivate; | |
4474 | - | |
4475 | -class QCommandLineOption | |
4476 | -{ | |
4477 | -public: | |
4478 | - explicit QCommandLineOption(const QString &name, const QString &description = QString(), | |
4479 | - const QString &valueName = QString(), | |
4480 | - const QString &defaultValue = QString()); | |
4481 | - explicit QCommandLineOption(const QStringList &names, const QString &description = QString(), | |
4482 | - const QString &valueName = QString(), | |
4483 | - const QString &defaultValue = QString()); | |
4484 | - QCommandLineOption(const QCommandLineOption &other); | |
4485 | - | |
4486 | - ~QCommandLineOption(); | |
4487 | - | |
4488 | - QCommandLineOption &operator=(const QCommandLineOption &other); | |
4489 | - | |
4490 | - QStringList names() const; | |
4491 | - | |
4492 | - void setValueName(const QString &name); | |
4493 | - QString valueName() const; | |
4494 | - | |
4495 | - void setDescription(const QString &description); | |
4496 | - QString description() const; | |
4497 | - | |
4498 | - void setDefaultValue(const QString &defaultValue); | |
4499 | - void setDefaultValues(const QStringList &defaultValues); | |
4500 | - QStringList defaultValues() const; | |
4501 | - | |
4502 | -private: | |
4503 | - QSharedDataPointer<QCommandLineOptionPrivate> d; | |
4504 | -}; | |
4505 | - | |
4506 | -#endif // QCOMMANDLINEOPTION_H | |
4507 | diff --git a/src/core/qcommandlineparser.cpp b/src/core/qcommandlineparser.cpp | |
4508 | deleted file mode 100644 | |
4509 | index f97d78a..0000000 | |
4510 | --- a/src/core/qcommandlineparser.cpp | |
4511 | +++ /dev/null | |
4512 | @@ -1,944 +0,0 @@ | |
4513 | -/**************************************************************************** | |
4514 | -** | |
4515 | -** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> | |
4516 | -** Copyright (C) 2013 David Faure <faure@kde.org> | |
4517 | -** Contact: http://www.qt-project.org/legal | |
4518 | -** | |
4519 | -** This file is part of the QtCore module of the Qt Toolkit. | |
4520 | -** | |
4521 | -** $QT_BEGIN_LICENSE:LGPL$ | |
4522 | -** Commercial License Usage | |
4523 | -** Licensees holding valid commercial Qt licenses may use this file in | |
4524 | -** accordance with the commercial license agreement provided with the | |
4525 | -** Software or, alternatively, in accordance with the terms contained in | |
4526 | -** a written agreement between you and Digia. For licensing terms and | |
4527 | -** conditions see http://qt.digia.com/licensing. For further information | |
4528 | -** use the contact form at http://qt.digia.com/contact-us. | |
4529 | -** | |
4530 | -** GNU Lesser General Public License Usage | |
4531 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
4532 | -** General Public License version 2.1 as published by the Free Software | |
4533 | -** Foundation and appearing in the file LICENSE.LGPL included in the | |
4534 | -** packaging of this file. Please review the following information to | |
4535 | -** ensure the GNU Lesser General Public License version 2.1 requirements | |
4536 | -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
4537 | -** | |
4538 | -** In addition, as a special exception, Digia gives you certain additional | |
4539 | -** rights. These rights are described in the Digia Qt LGPL Exception | |
4540 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
4541 | -** | |
4542 | -** GNU General Public License Usage | |
4543 | -** Alternatively, this file may be used under the terms of the GNU | |
4544 | -** General Public License version 3.0 as published by the Free Software | |
4545 | -** Foundation and appearing in the file LICENSE.GPL included in the | |
4546 | -** packaging of this file. Please review the following information to | |
4547 | -** ensure the GNU General Public License version 3.0 requirements will be | |
4548 | -** met: http://www.gnu.org/copyleft/gpl.html. | |
4549 | -** | |
4550 | -** | |
4551 | -** $QT_END_LICENSE$ | |
4552 | -** | |
4553 | -****************************************************************************/ | |
4554 | - | |
4555 | -#include "qcommandlineparser.h" | |
4556 | - | |
4557 | -#include <QCoreApplication> | |
4558 | -#include <QHash> | |
4559 | -#include <QVector> | |
4560 | -#include <stdio.h> | |
4561 | -#include <stdlib.h> | |
4562 | - | |
4563 | -typedef QHash<QString, int> NameHash_t; | |
4564 | - | |
4565 | -class QCommandLineParserPrivate | |
4566 | -{ | |
4567 | -public: | |
4568 | - inline QCommandLineParserPrivate() | |
4569 | - : singleDashWordOptionMode(QCommandLineParser::ParseAsCompactedShortOptions), | |
4570 | - builtinVersionOption(false), | |
4571 | - builtinHelpOption(false), | |
4572 | - needsParsing(true) | |
4573 | - { } | |
4574 | - | |
4575 | - bool parse(const QStringList &args); | |
4576 | - void checkParsed(const char *method); | |
4577 | - QStringList aliases(const QString &name) const; | |
4578 | - QString helpText() const; | |
4579 | - bool registerFoundOption(const QString &optionName); | |
4580 | - bool parseOptionValue(const QString &optionName, const QString &argument, | |
4581 | - QStringList::const_iterator *argumentIterator, | |
4582 | - QStringList::const_iterator argsEnd); | |
4583 | - | |
4584 | - //! Error text set when parse() returns false | |
4585 | - QString errorText; | |
4586 | - | |
4587 | - //! The command line options used for parsing | |
4588 | - QList<QCommandLineOption> commandLineOptionList; | |
4589 | - | |
4590 | - //! Hash mapping option names to their offsets in commandLineOptionList and optionArgumentList. | |
4591 | - NameHash_t nameHash; | |
4592 | - | |
4593 | - //! Option values found (only for options with a value) | |
4594 | - QHash<int, QStringList> optionValuesHash; | |
4595 | - | |
4596 | - //! Names of options found on the command line. | |
4597 | - QStringList optionNames; | |
4598 | - | |
4599 | - //! Arguments which did not belong to any option. | |
4600 | - QStringList positionalArgumentList; | |
4601 | - | |
4602 | - //! Names of options which were unknown. | |
4603 | - QStringList unknownOptionNames; | |
4604 | - | |
4605 | - //! Application description | |
4606 | - QString description; | |
4607 | - | |
4608 | - //! Documentation for positional arguments | |
4609 | - struct PositionalArgumentDefinition | |
4610 | - { | |
4611 | - QString name; | |
4612 | - QString description; | |
4613 | - QString syntax; | |
4614 | - }; | |
4615 | - QVector<PositionalArgumentDefinition> positionalArgumentDefinitions; | |
4616 | - | |
4617 | - //! The parsing mode for "-abc" | |
4618 | - QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode; | |
4619 | - | |
4620 | - //! Whether addVersionOption was called | |
4621 | - bool builtinVersionOption; | |
4622 | - | |
4623 | - //! Whether addHelpOption was called | |
4624 | - bool builtinHelpOption; | |
4625 | - | |
4626 | - //! True if parse() needs to be called | |
4627 | - bool needsParsing; | |
4628 | -}; | |
4629 | - | |
4630 | -QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const | |
4631 | -{ | |
4632 | - const NameHash_t::const_iterator it = nameHash.find(optionName); | |
4633 | - if (it == nameHash.end()) { | |
4634 | - qWarning("QCommandLineParser: option not defined: \"%s\"", qPrintable(optionName)); | |
4635 | - return QStringList(); | |
4636 | - } | |
4637 | - return commandLineOptionList.at(*it).names(); | |
4638 | -} | |
4639 | - | |
4640 | -/*! | |
4641 | - \since 5.2 | |
4642 | - \class QCommandLineParser | |
4643 | - \inmodule QtCore | |
4644 | - \ingroup tools | |
4645 | - | |
4646 | - \brief The QCommandLineParser class provides a means for handling the | |
4647 | - command line options. | |
4648 | - | |
4649 | - QCoreApplication provides the command-line arguments as a simple list of strings. | |
4650 | - QCommandLineParser provides the ability to define a set of options, parse the | |
4651 | - command-line arguments, and store which options have actually been used, as | |
4652 | - well as option values. | |
4653 | - | |
4654 | - Any argument that isn't an option (i.e. doesn't start with a \c{-}) is stored | |
4655 | - as a "positional argument". | |
4656 | - | |
4657 | - The parser handles short names, long names, more than one name for the same | |
4658 | - option, and option values. | |
4659 | - | |
4660 | - Options on the command line are recognized as starting with a single or | |
4661 | - double \c{-} character(s). | |
4662 | - The option \c{-} (single dash alone) is a special case, often meaning standard | |
4663 | - input, and not treated as an option. The parser will treat everything after the | |
4664 | - option \c{--} (double dash) as positional arguments. | |
4665 | - | |
4666 | - Short options are single letters. The option \c{v} would be specified by | |
4667 | - passing \c{-v} on the command line. In the default parsing mode, short options | |
4668 | - can be written in a compact form, for instance \c{-abc} is equivalent to \c{-a -b -c}. | |
4669 | - The parsing mode for can be set to ParseAsLongOptions, in which case \c{-abc} | |
4670 | - will be parsed as the long option \c{abc}. | |
4671 | - | |
4672 | - Long options are more than one letter long and cannot be compacted together. | |
4673 | - The long option \c{verbose} would be passed as \c{--verbose} or \c{-verbose}. | |
4674 | - | |
4675 | - Passing values to options can be done using the assignment operator: \c{-v=value} | |
4676 | - \c{--verbose=value}, or a space: \c{-v value} \c{--verbose value}, i.e. the next | |
4677 | - argument is used as value (even if it starts with a \c{-}). | |
4678 | - | |
4679 | - The parser does not support optional values - if an option is set to | |
4680 | - require a value, one must be present. If such an option is placed last | |
4681 | - and has no value, the option will be treated as if it had not been | |
4682 | - specified. | |
4683 | - | |
4684 | - The parser does not automatically support negating or disabling long options | |
4685 | - by using the format \c{--disable-option} or \c{--no-option}. However, it is | |
4686 | - possible to handle this case explicitly by making an option with \c{no-option} | |
4687 | - as one of its names, and handling the option explicitly. | |
4688 | - | |
4689 | - Example: | |
4690 | - \snippet code/src_corelib_tools_qcommandlineparser_main.cpp 0 | |
4691 | - | |
4692 | - Known limitation: the parsing of Qt options inside QCoreApplication and subclasses | |
4693 | - happens before QCommandLineParser exists, so it can't take it into account. This | |
4694 | - means any option value that looks like a builtin Qt option, will be treated by | |
4695 | - QCoreApplication as a builtin Qt option. Example: \c{--profile -reverse} will | |
4696 | - lead to QGuiApplication seeing the -reverse option set, and removing it from | |
4697 | - QCoreApplication::arguments() before QCommandLineParser defines the \c{profile} | |
4698 | - option and parses the command line. | |
4699 | - | |
4700 | - \sa QCommandLineOption, QCoreApplication | |
4701 | -*/ | |
4702 | - | |
4703 | -/*! | |
4704 | - Constructs a command line parser object. | |
4705 | -*/ | |
4706 | -QCommandLineParser::QCommandLineParser() | |
4707 | - : d(new QCommandLineParserPrivate) | |
4708 | -{ | |
4709 | -} | |
4710 | - | |
4711 | -/*! | |
4712 | - Destroys the command line parser object. | |
4713 | -*/ | |
4714 | -QCommandLineParser::~QCommandLineParser() | |
4715 | -{ | |
4716 | - delete d; | |
4717 | -} | |
4718 | - | |
4719 | -/*! | |
4720 | - \enum QCommandLineParser::SingleDashWordOptionMode | |
4721 | - | |
4722 | - This enum describes the way the parser interprets command-line | |
4723 | - options that use a single dash followed by multiple letters, as as \c{-abc}. | |
4724 | - | |
4725 | - \value ParseAsCompactedShortOptions \c{-abc} is interpreted as \c{-a -b -c}, | |
4726 | - i.e. as three short options that have been compacted on the command-line, | |
4727 | - if none of the options take a value. If \c{a} takes a value, then it | |
4728 | - is interpreted as \c{-a bc}, i.e. the short option \c{a} followed by the value \c{bc}. | |
4729 | - This is typically used in tools that behave like compilers, in order | |
4730 | - to handle options such as \c{-DDEFINE=VALUE} or \c{-I/include/path}. | |
4731 | - This is the default parsing mode. New applications are recommended to | |
4732 | - use this mode. | |
4733 | - | |
4734 | - \value ParseAsLongOptions \c{-abc} is interpreted as \c{--abc}, | |
4735 | - i.e. as the long option named \c{abc}. This is how Qt's own tools | |
4736 | - (uic, rcc...) have always been parsing arguments. This mode should be | |
4737 | - used for preserving compatibility in applications that were parsing | |
4738 | - arguments in such a way. | |
4739 | - | |
4740 | - \sa setSingleDashWordOptionMode() | |
4741 | -*/ | |
4742 | - | |
4743 | -/*! | |
4744 | - Sets the parsing mode to \a singleDashWordOptionMode. | |
4745 | - This must be called before process() or parse(). | |
4746 | -*/ | |
4747 | -void QCommandLineParser::setSingleDashWordOptionMode(QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode) | |
4748 | -{ | |
4749 | - d->singleDashWordOptionMode = singleDashWordOptionMode; | |
4750 | -} | |
4751 | - | |
4752 | -/*! | |
4753 | - Adds the option \a option to look for while parsing. | |
4754 | - | |
4755 | - Returns \c true if adding the option was successful; otherwise returns \c false. | |
4756 | - | |
4757 | - Adding the option fails if there is no name attached to the option, or | |
4758 | - the option has a name that clashes with an option name added before. | |
4759 | - */ | |
4760 | -bool QCommandLineParser::addOption(const QCommandLineOption &option) | |
4761 | -{ | |
4762 | - QStringList optionNames = option.names(); | |
4763 | - | |
4764 | - if (!optionNames.isEmpty()) { | |
4765 | - Q_FOREACH (const QString &name, optionNames) { | |
4766 | - if (d->nameHash.contains(name)) | |
4767 | - return false; | |
4768 | - } | |
4769 | - | |
4770 | - d->commandLineOptionList.append(option); | |
4771 | - | |
4772 | - const int offset = d->commandLineOptionList.size() - 1; | |
4773 | - Q_FOREACH (const QString &name, optionNames) | |
4774 | - d->nameHash.insert(name, offset); | |
4775 | - | |
4776 | - return true; | |
4777 | - } | |
4778 | - | |
4779 | - return false; | |
4780 | -} | |
4781 | - | |
4782 | -/*! | |
4783 | - Adds the \c{-v} / \c{--version} option, which displays the version string of the application. | |
4784 | - | |
4785 | - This option is handled automatically by QCommandLineParser. | |
4786 | - | |
4787 | - You can set the actual version string by using QCoreApplication::setApplicationVersion(). | |
4788 | - | |
4789 | - Returns the option instance, which can be used to call isSet(). | |
4790 | -*/ | |
4791 | -QCommandLineOption QCommandLineParser::addVersionOption() | |
4792 | -{ | |
4793 | - QCommandLineOption opt(QStringList() << "v" << "version", tr("Displays version information.")); | |
4794 | - addOption(opt); | |
4795 | - d->builtinVersionOption = true; | |
4796 | - return opt; | |
4797 | -} | |
4798 | - | |
4799 | -/*! | |
4800 | - Adds the help option (\c{-h}, \c{--help} and \c{-?} on Windows) | |
4801 | - This option is handled automatically by QCommandLineParser. | |
4802 | - | |
4803 | - Remember to use setApplicationDescription to set the application description, | |
4804 | - which will be displayed when this option is used. | |
4805 | - | |
4806 | - Example: | |
4807 | - \snippet code/src_corelib_tools_qcommandlineparser_main.cpp 0 | |
4808 | - | |
4809 | - Returns the option instance, which can be used to call isSet(). | |
4810 | -*/ | |
4811 | -QCommandLineOption QCommandLineParser::addHelpOption() | |
4812 | -{ | |
4813 | - QCommandLineOption opt(QStringList() | |
4814 | -#ifdef Q_OS_WIN | |
4815 | - << "?" | |
4816 | -#endif | |
4817 | - << "h" | |
4818 | - << "help", tr("Displays this help.")); | |
4819 | - addOption(opt); | |
4820 | - d->builtinHelpOption = true; | |
4821 | - return opt; | |
4822 | -} | |
4823 | - | |
4824 | -/*! | |
4825 | - Sets the application \a description shown by helpText(). | |
4826 | -*/ | |
4827 | -void QCommandLineParser::setApplicationDescription(const QString &description) | |
4828 | -{ | |
4829 | - d->description = description; | |
4830 | -} | |
4831 | - | |
4832 | -/*! | |
4833 | - Returns the application description set in setApplicationDescription(). | |
4834 | -*/ | |
4835 | -QString QCommandLineParser::applicationDescription() const | |
4836 | -{ | |
4837 | - return d->description; | |
4838 | -} | |
4839 | - | |
4840 | -/*! | |
4841 | - Defines an additional argument to the application, for the benefit of the help text. | |
4842 | - | |
4843 | - The argument \a name and \a description will appear under the \c{Arguments:} section | |
4844 | - of the help. If \a syntax is specified, it will be appended to the Usage line, otherwise | |
4845 | - the \a name will be appended. | |
4846 | - | |
4847 | - Example: | |
4848 | - \snippet code/src_corelib_tools_qcommandlineparser.cpp 2 | |
4849 | - | |
4850 | - \sa addHelpOption(), helpText() | |
4851 | -*/ | |
4852 | -void QCommandLineParser::addPositionalArgument(const QString &name, const QString &description, const QString &syntax) | |
4853 | -{ | |
4854 | - QCommandLineParserPrivate::PositionalArgumentDefinition arg; | |
4855 | - arg.name = name; | |
4856 | - arg.description = description; | |
4857 | - arg.syntax = syntax.isEmpty() ? name : syntax; | |
4858 | - d->positionalArgumentDefinitions.append(arg); | |
4859 | -} | |
4860 | - | |
4861 | -/*! | |
4862 | - Clears the definitions of additional arguments from the help text. | |
4863 | - | |
4864 | - This is only needed for the special case of tools which support multiple commands | |
4865 | - with different options. Once the actual command has been identified, the options | |
4866 | - for this command can be defined, and the help text for the command can be adjusted | |
4867 | - accordingly. | |
4868 | - | |
4869 | - Example: | |
4870 | - \snippet code/src_corelib_tools_qcommandlineparser.cpp 3 | |
4871 | -*/ | |
4872 | -void QCommandLineParser::clearPositionalArguments() | |
4873 | -{ | |
4874 | - d->positionalArgumentDefinitions.clear(); | |
4875 | -} | |
4876 | - | |
4877 | -/*! | |
4878 | - Parses the command line \a arguments. | |
4879 | - | |
4880 | - Most programs don't need to call this, a simple call to process() is enough. | |
4881 | - | |
4882 | - parse() is more low-level, and only does the parsing. The application will have to | |
4883 | - take care of the error handling, using errorText() if parse() returns \c false. | |
4884 | - This can be useful for instance to show a graphical error message in graphical programs. | |
4885 | - | |
4886 | - Calling parse() instead of process() can also be useful in order to ignore unknown | |
4887 | - options temporarily, because more option definitions will be provided later on | |
4888 | - (depending on one of the arguments), before calling process(). | |
4889 | - | |
4890 | - Don't forget that \a arguments must start with the name of the executable (ignored, though). | |
4891 | - | |
4892 | - Returns \c false in case of a parse error (unknown option or missing value); returns \c true otherwise. | |
4893 | - | |
4894 | - \sa process() | |
4895 | -*/ | |
4896 | -bool QCommandLineParser::parse(const QStringList &arguments) | |
4897 | -{ | |
4898 | - return d->parse(arguments); | |
4899 | -} | |
4900 | - | |
4901 | -/*! | |
4902 | - Returns a translated error text for the user. | |
4903 | - This should only be called when parse() returns \c false. | |
4904 | -*/ | |
4905 | -QString QCommandLineParser::errorText() const | |
4906 | -{ | |
4907 | - if (!d->errorText.isEmpty()) | |
4908 | - return d->errorText; | |
4909 | - if (d->unknownOptionNames.count() == 1) | |
4910 | - return tr("Unknown option '%1'.").arg(d->unknownOptionNames.first()); | |
4911 | - if (d->unknownOptionNames.count() > 1) | |
4912 | - return tr("Unknown options: %1.").arg(d->unknownOptionNames.join(", ")); | |
4913 | - return QString(); | |
4914 | -} | |
4915 | - | |
4916 | -/*! | |
4917 | - Processes the command line \a arguments. | |
4918 | - | |
4919 | - In addition to parsing the options (like parse()), this function also handles the builtin | |
4920 | - options and handles errors. | |
4921 | - | |
4922 | - The builtin options are \c{--version} if addVersionOption was called and \c{--help} if addHelpOption was called. | |
4923 | - | |
4924 | - When invoking one of these options, or when an error happens (for instance an unknown option was | |
4925 | - passed), the current process will then stop, using the exit() function. | |
4926 | - | |
4927 | - \sa QCoreApplication::arguments(), parse() | |
4928 | - */ | |
4929 | -void QCommandLineParser::process(const QStringList &arguments) | |
4930 | -{ | |
4931 | - if (!d->parse(arguments)) { | |
4932 | - fprintf(stderr, "%s\n", qPrintable(errorText())); | |
4933 | - ::exit(EXIT_FAILURE); | |
4934 | - } | |
4935 | - | |
4936 | - if (d->builtinVersionOption && isSet("version")) { | |
4937 | - printf("%s %s\n", qPrintable(QCoreApplication::applicationName()), qPrintable(QCoreApplication::applicationVersion())); | |
4938 | - ::exit(EXIT_SUCCESS); | |
4939 | - } | |
4940 | - | |
4941 | - if (d->builtinHelpOption && isSet("help")) | |
4942 | - showHelp(EXIT_SUCCESS); | |
4943 | -} | |
4944 | - | |
4945 | -/*! | |
4946 | - \overload | |
4947 | - | |
4948 | - The command line is obtained from the QCoreApplication instance \a app. | |
4949 | - */ | |
4950 | -void QCommandLineParser::process(const QCoreApplication &app) | |
4951 | -{ | |
4952 | - // QCoreApplication::arguments() is static, but the app instance must exist so we require it as parameter | |
4953 | - Q_UNUSED(app); | |
4954 | - process(QCoreApplication::arguments()); | |
4955 | -} | |
4956 | - | |
4957 | -void QCommandLineParserPrivate::checkParsed(const char *method) | |
4958 | -{ | |
4959 | - if (needsParsing) | |
4960 | - qWarning("QCommandLineParser: call process() or parse() before %s", method); | |
4961 | -} | |
4962 | - | |
4963 | -/*! | |
4964 | - \internal | |
4965 | - Looks up the option \a optionName (found on the command line) and register it as found. | |
4966 | - Returns \c true on success. | |
4967 | - */ | |
4968 | -bool QCommandLineParserPrivate::registerFoundOption(const QString &optionName) | |
4969 | -{ | |
4970 | - if (nameHash.contains(optionName)) { | |
4971 | - optionNames.append(optionName); | |
4972 | - return true; | |
4973 | - } else { | |
4974 | - unknownOptionNames.append(optionName); | |
4975 | - return false; | |
4976 | - } | |
4977 | -} | |
4978 | - | |
4979 | -/*! | |
4980 | - \internal | |
4981 | - \brief Parse the value for a given option, if it was defined to expect one. | |
4982 | - | |
4983 | - The value is taken from the next argument, or after the equal sign in \a argument. | |
4984 | - | |
4985 | - \param optionName the short option name | |
4986 | - \param argument the argument from the command line currently parsed. Only used for -k=value parsing. | |
4987 | - \param argumentIterator iterator to the currently parsed argument. Incremented if the next argument contains the value. | |
4988 | - \param argsEnd args.end(), to check if ++argumentIterator goes out of bounds | |
4989 | - Returns \c true on success. | |
4990 | - */ | |
4991 | -bool QCommandLineParserPrivate::parseOptionValue(const QString &optionName, const QString &argument, | |
4992 | - QStringList::const_iterator *argumentIterator, QStringList::const_iterator argsEnd) | |
4993 | -{ | |
4994 | - const QLatin1Char assignChar('='); | |
4995 | - const NameHash_t::const_iterator nameHashIt = nameHash.constFind(optionName); | |
4996 | - if (nameHashIt != nameHash.constEnd()) { | |
4997 | - const int assignPos = argument.indexOf(assignChar); | |
4998 | - const NameHash_t::mapped_type optionOffset = *nameHashIt; | |
4999 | - const bool withValue = !commandLineOptionList.at(optionOffset).valueName().isEmpty(); | |
5000 | - if (withValue) { | |
5001 | - if (assignPos == -1) { | |
5002 | - ++(*argumentIterator); | |
5003 | - if (*argumentIterator == argsEnd) { | |
5004 | - errorText = QCommandLineParser::tr("Missing value after '%1'.").arg(argument); | |
5005 | - return false; | |
5006 | - } | |
5007 | - optionValuesHash[optionOffset].append(*(*argumentIterator)); | |
5008 | - } else { | |
5009 | - optionValuesHash[optionOffset].append(argument.mid(assignPos + 1)); | |
5010 | - } | |
5011 | - } else { | |
5012 | - if (assignPos != -1) { | |
5013 | - errorText = QCommandLineParser::tr("Unexpected value after '%1'.").arg(argument.left(assignPos)); | |
5014 | - return false; | |
5015 | - } | |
5016 | - } | |
5017 | - } | |
5018 | - return true; | |
5019 | -} | |
5020 | - | |
5021 | -/*! | |
5022 | - \internal | |
5023 | - | |
5024 | - Parse the list of arguments \a args, and fills in | |
5025 | - optionNames, optionValuesHash, unknownOptionNames, positionalArguments, and errorText. | |
5026 | - | |
5027 | - Any results from a previous parse operation are removed. | |
5028 | - | |
5029 | - The parser will not look for further options once it encounters the option | |
5030 | - \c{--}; this does not include when \c{--} follows an option that requires a value. | |
5031 | - */ | |
5032 | -bool QCommandLineParserPrivate::parse(const QStringList &args) | |
5033 | -{ | |
5034 | - needsParsing = false; | |
5035 | - bool error = false; | |
5036 | - | |
5037 | - const QString doubleDashString("--"); | |
5038 | - const QLatin1Char dashChar('-'); | |
5039 | - const QLatin1Char assignChar('='); | |
5040 | - | |
5041 | - bool doubleDashFound = false; | |
5042 | - errorText.clear(); | |
5043 | - positionalArgumentList.clear(); | |
5044 | - optionNames.clear(); | |
5045 | - unknownOptionNames.clear(); | |
5046 | - optionValuesHash.clear(); | |
5047 | - | |
5048 | - if (args.isEmpty()) { | |
5049 | - qWarning("QCommandLineParser: argument list cannot be empty, it should contain at least the executable name"); | |
5050 | - return false; | |
5051 | - } | |
5052 | - | |
5053 | - QStringList::const_iterator argumentIterator = args.begin(); | |
5054 | - ++argumentIterator; // skip executable name | |
5055 | - | |
5056 | - for (; argumentIterator != args.end() ; ++argumentIterator) { | |
5057 | - QString argument = *argumentIterator; | |
5058 | - | |
5059 | - if (doubleDashFound) { | |
5060 | - positionalArgumentList.append(argument); | |
5061 | - } else if (argument.startsWith(doubleDashString)) { | |
5062 | - if (argument.length() > 2) { | |
5063 | - QString optionName = argument.mid(2).section(assignChar, 0, 0); | |
5064 | - if (registerFoundOption(optionName)) { | |
5065 | - if (!parseOptionValue(optionName, argument, &argumentIterator, args.end())) | |
5066 | - error = true; | |
5067 | - } else { | |
5068 | - error = true; | |
5069 | - } | |
5070 | - } else { | |
5071 | - doubleDashFound = true; | |
5072 | - } | |
5073 | - } else if (argument.startsWith(dashChar)) { | |
5074 | - if (argument.size() == 1) { // single dash ("stdin") | |
5075 | - positionalArgumentList.append(argument); | |
5076 | - continue; | |
5077 | - } | |
5078 | - switch (singleDashWordOptionMode) { | |
5079 | - case QCommandLineParser::ParseAsCompactedShortOptions: | |
5080 | - { | |
5081 | - QString optionName; | |
5082 | - bool valueFound = false; | |
5083 | - for (int pos = 1 ; pos < argument.size(); ++pos) { | |
5084 | - optionName = argument.mid(pos, 1); | |
5085 | - if (!registerFoundOption(optionName)) { | |
5086 | - error = true; | |
5087 | - } else { | |
5088 | - const NameHash_t::const_iterator nameHashIt = nameHash.constFind(optionName); | |
5089 | - Q_ASSERT(nameHashIt != nameHash.constEnd()); // checked by registerFoundOption | |
5090 | - const NameHash_t::mapped_type optionOffset = *nameHashIt; | |
5091 | - const bool withValue = !commandLineOptionList.at(optionOffset).valueName().isEmpty(); | |
5092 | - if (withValue) { | |
5093 | - if (pos + 1 < argument.size()) { | |
5094 | - if (argument.at(pos + 1) == assignChar) | |
5095 | - ++pos; | |
5096 | - optionValuesHash[optionOffset].append(argument.mid(pos + 1)); | |
5097 | - valueFound = true; | |
5098 | - } | |
5099 | - break; | |
5100 | - } | |
5101 | - if (pos + 1 < argument.size() && argument.at(pos + 1) == assignChar) | |
5102 | - break; | |
5103 | - } | |
5104 | - } | |
5105 | - if (!valueFound && !parseOptionValue(optionName, argument, &argumentIterator, args.end())) | |
5106 | - error = true; | |
5107 | - break; | |
5108 | - } | |
5109 | - case QCommandLineParser::ParseAsLongOptions: | |
5110 | - { | |
5111 | - const QString optionName = argument.mid(1).section(assignChar, 0, 0); | |
5112 | - if (registerFoundOption(optionName)) { | |
5113 | - if (!parseOptionValue(optionName, argument, &argumentIterator, args.end())) | |
5114 | - error = true; | |
5115 | - } else { | |
5116 | - error = true; | |
5117 | - } | |
5118 | - break; | |
5119 | - } | |
5120 | - } | |
5121 | - } else { | |
5122 | - positionalArgumentList.append(argument); | |
5123 | - } | |
5124 | - if (argumentIterator == args.end()) | |
5125 | - break; | |
5126 | - } | |
5127 | - return !error; | |
5128 | -} | |
5129 | - | |
5130 | -/*! | |
5131 | - Checks whether the option \a name was passed to the application. | |
5132 | - | |
5133 | - Returns \c true if the option \a name was set, false otherwise. | |
5134 | - | |
5135 | - The name provided can be any long or short name of any option that was | |
5136 | - added with \c addOption(). All the options names are treated as being | |
5137 | - equivalent. If the name is not recognized or that option was not present, | |
5138 | - false is returned. | |
5139 | - | |
5140 | - Example: | |
5141 | - \snippet code/src_corelib_tools_qcommandlineparser.cpp 0 | |
5142 | - */ | |
5143 | - | |
5144 | -bool QCommandLineParser::isSet(const QString &name) const | |
5145 | -{ | |
5146 | - d->checkParsed("isSet"); | |
5147 | - if (d->optionNames.contains(name)) | |
5148 | - return true; | |
5149 | - const QStringList aliases = d->aliases(name); | |
5150 | - Q_FOREACH (const QString &optionName, d->optionNames) { | |
5151 | - if (aliases.contains(optionName)) | |
5152 | - return true; | |
5153 | - } | |
5154 | - return false; | |
5155 | -} | |
5156 | - | |
5157 | -/*! | |
5158 | - Returns the option value found for the given option name \a optionName, or | |
5159 | - an empty string if not found. | |
5160 | - | |
5161 | - The name provided can be any long or short name of any option that was | |
5162 | - added with \c addOption(). All the option names are treated as being | |
5163 | - equivalent. If the name is not recognized or that option was not present, an | |
5164 | - empty string is returned. | |
5165 | - | |
5166 | - For options found by the parser, the last value found for | |
5167 | - that option is returned. If the option wasn't specified on the command line, | |
5168 | - the default value is returned. | |
5169 | - | |
5170 | - An empty string is returned if the option does not take a value. | |
5171 | - | |
5172 | - \sa values(), QCommandLineOption::setDefaultValue(), QCommandLineOption::setDefaultValues() | |
5173 | - */ | |
5174 | - | |
5175 | -QString QCommandLineParser::value(const QString &optionName) const | |
5176 | -{ | |
5177 | - d->checkParsed("value"); | |
5178 | - const QStringList valueList = values(optionName); | |
5179 | - | |
5180 | - if (!valueList.isEmpty()) | |
5181 | - return valueList.last(); | |
5182 | - | |
5183 | - return QString(); | |
5184 | -} | |
5185 | - | |
5186 | -/*! | |
5187 | - Returns a list of option values found for the given option name \a | |
5188 | - optionName, or an empty list if not found. | |
5189 | - | |
5190 | - The name provided can be any long or short name of any option that was | |
5191 | - added with \c addOption(). All the options names are treated as being | |
5192 | - equivalent. If the name is not recognized or that option was not present, an | |
5193 | - empty list is returned. | |
5194 | - | |
5195 | - For options found by the parser, the list will contain an entry for | |
5196 | - each time the option was encountered by the parser. If the option wasn't | |
5197 | - specified on the command line, the default values are returned. | |
5198 | - | |
5199 | - An empty list is returned if the option does not take a value. | |
5200 | - | |
5201 | - \sa value(), QCommandLineOption::setDefaultValue(), QCommandLineOption::setDefaultValues() | |
5202 | - */ | |
5203 | - | |
5204 | -QStringList QCommandLineParser::values(const QString &optionName) const | |
5205 | -{ | |
5206 | - d->checkParsed("values"); | |
5207 | - const NameHash_t::const_iterator it = d->nameHash.constFind(optionName); | |
5208 | - if (it != d->nameHash.constEnd()) { | |
5209 | - const int optionOffset = *it; | |
5210 | - QStringList values = d->optionValuesHash.value(optionOffset); | |
5211 | - if (values.isEmpty()) | |
5212 | - values = d->commandLineOptionList.at(optionOffset).defaultValues(); | |
5213 | - return values; | |
5214 | - } | |
5215 | - | |
5216 | - qWarning("QCommandLineParser: option not defined: \"%s\"", qPrintable(optionName)); | |
5217 | - return QStringList(); | |
5218 | -} | |
5219 | - | |
5220 | -/*! | |
5221 | - \overload | |
5222 | - Checks whether the \a option was passed to the application. | |
5223 | - | |
5224 | - Returns \c true if the \a option was set, false otherwise. | |
5225 | - | |
5226 | - This is the recommended way to check for options with no values. | |
5227 | - | |
5228 | - Example: | |
5229 | - \snippet code/src_corelib_tools_qcommandlineparser.cpp 1 | |
5230 | -*/ | |
5231 | -bool QCommandLineParser::isSet(const QCommandLineOption &option) const | |
5232 | -{ | |
5233 | - // option.names() might be empty if the constructor failed | |
5234 | - return !option.names().isEmpty() && isSet(option.names().first()); | |
5235 | -} | |
5236 | - | |
5237 | -/*! | |
5238 | - \overload | |
5239 | - Returns the option value found for the given \a option, or | |
5240 | - an empty string if not found. | |
5241 | - | |
5242 | - For options found by the parser, the last value found for | |
5243 | - that option is returned. If the option wasn't specified on the command line, | |
5244 | - the default value is returned. | |
5245 | - | |
5246 | - An empty string is returned if the option does not take a value. | |
5247 | - | |
5248 | - \sa values(), QCommandLineOption::setDefaultValue(), QCommandLineOption::setDefaultValues() | |
5249 | -*/ | |
5250 | -QString QCommandLineParser::value(const QCommandLineOption &option) const | |
5251 | -{ | |
5252 | - return value(option.names().first()); | |
5253 | -} | |
5254 | - | |
5255 | -/*! | |
5256 | - \overload | |
5257 | - Returns a list of option values found for the given \a option, | |
5258 | - or an empty list if not found. | |
5259 | - | |
5260 | - For options found by the parser, the list will contain an entry for | |
5261 | - each time the option was encountered by the parser. If the option wasn't | |
5262 | - specified on the command line, the default values are returned. | |
5263 | - | |
5264 | - An empty list is returned if the option does not take a value. | |
5265 | - | |
5266 | - \sa value(), QCommandLineOption::setDefaultValue(), QCommandLineOption::setDefaultValues() | |
5267 | -*/ | |
5268 | -QStringList QCommandLineParser::values(const QCommandLineOption &option) const | |
5269 | -{ | |
5270 | - return values(option.names().first()); | |
5271 | -} | |
5272 | - | |
5273 | -/*! | |
5274 | - Returns a list of positional arguments. | |
5275 | - | |
5276 | - These are all of the arguments that were not recognized as part of an | |
5277 | - option. | |
5278 | - */ | |
5279 | - | |
5280 | -QStringList QCommandLineParser::positionalArguments() const | |
5281 | -{ | |
5282 | - d->checkParsed("positionalArguments"); | |
5283 | - return d->positionalArgumentList; | |
5284 | -} | |
5285 | - | |
5286 | -/*! | |
5287 | - Returns a list of option names that were found. | |
5288 | - | |
5289 | - This returns a list of all the recognized option names found by the | |
5290 | - parser, in the order in which they were found. For any long options | |
5291 | - that were in the form {--option=value}, the value part will have been | |
5292 | - dropped. | |
5293 | - | |
5294 | - The names in this list do not include the preceding dash characters. | |
5295 | - Names may appear more than once in this list if they were encountered | |
5296 | - more than once by the parser. | |
5297 | - | |
5298 | - Any entry in the list can be used with \c value() or with | |
5299 | - \c values() to get any relevant option values. | |
5300 | - */ | |
5301 | - | |
5302 | -QStringList QCommandLineParser::optionNames() const | |
5303 | -{ | |
5304 | - d->checkParsed("optionNames"); | |
5305 | - return d->optionNames; | |
5306 | -} | |
5307 | - | |
5308 | -/*! | |
5309 | - Returns a list of unknown option names. | |
5310 | - | |
5311 | - This list will include both long an short name options that were not | |
5312 | - recognized. For any long options that were in the form {--option=value}, | |
5313 | - the value part will have been dropped and only the long name is added. | |
5314 | - | |
5315 | - The names in this list do not include the preceding dash characters. | |
5316 | - Names may appear more than once in this list if they were encountered | |
5317 | - more than once by the parser. | |
5318 | - | |
5319 | - \sa optionNames() | |
5320 | - */ | |
5321 | - | |
5322 | -QStringList QCommandLineParser::unknownOptionNames() const | |
5323 | -{ | |
5324 | - d->checkParsed("unknownOptionNames"); | |
5325 | - return d->unknownOptionNames; | |
5326 | -} | |
5327 | - | |
5328 | -/*! | |
5329 | - Displays the help information, and exits the application. | |
5330 | - This is automatically triggered by the --help option, but can also | |
5331 | - be used to display the help when the user is not invoking the | |
5332 | - application correctly. | |
5333 | - The exit code is set to \a exitCode. It should be set to 0 if the | |
5334 | - user requested to see the help, and to any other value in case of | |
5335 | - an error. | |
5336 | - | |
5337 | - \sa helpText() | |
5338 | -*/ | |
5339 | -void QCommandLineParser::showHelp(int exitCode) | |
5340 | -{ | |
5341 | - fprintf(stdout, "%s", qPrintable(d->helpText())); | |
5342 | - ::exit(exitCode); | |
5343 | -} | |
5344 | - | |
5345 | -/*! | |
5346 | - Returns a string containing the complete help information. | |
5347 | - | |
5348 | - \sa showHelp() | |
5349 | -*/ | |
5350 | -QString QCommandLineParser::helpText() const | |
5351 | -{ | |
5352 | - return d->helpText(); | |
5353 | -} | |
5354 | - | |
5355 | -static QString wrapText(const QString &names, int longestOptionNameString, const QString &description) | |
5356 | -{ | |
5357 | - const QLatin1Char nl('\n'); | |
5358 | - QString text = QString(" ") + names.leftJustified(longestOptionNameString) + QLatin1Char(' '); | |
5359 | - const int indent = text.length(); | |
5360 | - int lineStart = 0; | |
5361 | - int lastBreakable = -1; | |
5362 | - const int max = 79 - indent; | |
5363 | - int x = 0; | |
5364 | - const int len = description.length(); | |
5365 | - | |
5366 | - for (int i = 0; i < len; ++i) { | |
5367 | - ++x; | |
5368 | - const QChar c = description.at(i); | |
5369 | - if (c.isSpace()) | |
5370 | - lastBreakable = i; | |
5371 | - | |
5372 | - int breakAt = -1; | |
5373 | - int nextLineStart = -1; | |
5374 | - if (x > max && lastBreakable != -1) { | |
5375 | - // time to break and we know where | |
5376 | - breakAt = lastBreakable; | |
5377 | - nextLineStart = lastBreakable + 1; | |
5378 | - } else if ((x > max - 1 && lastBreakable == -1) || i == len - 1) { | |
5379 | - // time to break but found nowhere [-> break here], or end of last line | |
5380 | - breakAt = i + 1; | |
5381 | - nextLineStart = breakAt; | |
5382 | - } else if (c == nl) { | |
5383 | - // forced break | |
5384 | - breakAt = i; | |
5385 | - nextLineStart = i + 1; | |
5386 | - } | |
5387 | - | |
5388 | - if (breakAt != -1) { | |
5389 | - const int numChars = breakAt - lineStart; | |
5390 | - //qDebug() << "breakAt=" << description.at(breakAt) << "breakAtSpace=" << breakAtSpace << lineStart << "to" << breakAt << description.mid(lineStart, numChars); | |
5391 | - if (lineStart > 0) | |
5392 | - text += QString(indent, QLatin1Char(' ')); | |
5393 | - text += description.mid(lineStart, numChars) + nl; | |
5394 | - x = 0; | |
5395 | - lastBreakable = -1; | |
5396 | - lineStart = nextLineStart; | |
5397 | - if (lineStart < len && description.at(lineStart).isSpace()) | |
5398 | - ++lineStart; // don't start a line with a space | |
5399 | - i = lineStart; | |
5400 | - } | |
5401 | - } | |
5402 | - | |
5403 | - return text; | |
5404 | -} | |
5405 | - | |
5406 | -QString QCommandLineParserPrivate::helpText() const | |
5407 | -{ | |
5408 | - const QLatin1Char nl('\n'); | |
5409 | - QString text; | |
5410 | - const QString exeName = QCoreApplication::instance()->arguments().first(); | |
5411 | - QString usage = exeName; | |
5412 | - if (!commandLineOptionList.isEmpty()) { | |
5413 | - usage += QLatin1Char(' '); | |
5414 | - usage += QCommandLineParser::tr("[options]"); | |
5415 | - } | |
5416 | - Q_FOREACH (const PositionalArgumentDefinition &arg, positionalArgumentDefinitions) { | |
5417 | - usage += QLatin1Char(' '); | |
5418 | - usage += arg.syntax; | |
5419 | - } | |
5420 | - text += QCommandLineParser::tr("Usage: %1").arg(usage) + nl; | |
5421 | - if (!description.isEmpty()) | |
5422 | - text += description + nl; | |
5423 | - text += nl; | |
5424 | - if (!commandLineOptionList.isEmpty()) | |
5425 | - text += QCommandLineParser::tr("Options:") + nl; | |
5426 | - QStringList optionNameList; | |
5427 | - int longestOptionNameString = 0; | |
5428 | - Q_FOREACH (const QCommandLineOption &option, commandLineOptionList) { | |
5429 | - QStringList optionNames; | |
5430 | - Q_FOREACH (const QString &optionName, option.names()) { | |
5431 | - if (optionName.length() == 1) | |
5432 | - optionNames.append(QLatin1Char('-') + optionName); | |
5433 | - else | |
5434 | - optionNames.append(QString("--") + optionName); | |
5435 | - } | |
5436 | - QString optionNamesString = optionNames.join(", "); | |
5437 | - if (!option.valueName().isEmpty()) | |
5438 | - optionNamesString += QString(" <") + option.valueName() + QLatin1Char('>'); | |
5439 | - optionNameList.append(optionNamesString); | |
5440 | - longestOptionNameString = qMax(longestOptionNameString, optionNamesString.length()); | |
5441 | - } | |
5442 | - ++longestOptionNameString; | |
5443 | - for (int i = 0; i < commandLineOptionList.count(); ++i) { | |
5444 | - const QCommandLineOption &option = commandLineOptionList.at(i); | |
5445 | - text += wrapText(optionNameList.at(i), longestOptionNameString, option.description()); | |
5446 | - } | |
5447 | - if (!positionalArgumentDefinitions.isEmpty()) { | |
5448 | - if (!commandLineOptionList.isEmpty()) | |
5449 | - text += nl; | |
5450 | - text += QCommandLineParser::tr("Arguments:") + nl; | |
5451 | - Q_FOREACH (const PositionalArgumentDefinition &arg, positionalArgumentDefinitions) { | |
5452 | - text += wrapText(arg.name, longestOptionNameString, arg.description); | |
5453 | - } | |
5454 | - } | |
5455 | - return text; | |
5456 | -} | |
5457 | diff --git a/src/core/qcommandlineparser.h b/src/core/qcommandlineparser.h | |
5458 | deleted file mode 100644 | |
5459 | index eeecf2d..0000000 | |
5460 | --- a/src/core/qcommandlineparser.h | |
5461 | +++ /dev/null | |
5462 | @@ -1,102 +0,0 @@ | |
5463 | -/**************************************************************************** | |
5464 | -** | |
5465 | -** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> | |
5466 | -** Contact: http://www.qt-project.org/legal | |
5467 | -** | |
5468 | -** This file is part of the QtCore module of the Qt Toolkit. | |
5469 | -** | |
5470 | -** $QT_BEGIN_LICENSE:LGPL$ | |
5471 | -** Commercial License Usage | |
5472 | -** Licensees holding valid commercial Qt licenses may use this file in | |
5473 | -** accordance with the commercial license agreement provided with the | |
5474 | -** Software or, alternatively, in accordance with the terms contained in | |
5475 | -** a written agreement between you and Digia. For licensing terms and | |
5476 | -** conditions see http://qt.digia.com/licensing. For further information | |
5477 | -** use the contact form at http://qt.digia.com/contact-us. | |
5478 | -** | |
5479 | -** GNU Lesser General Public License Usage | |
5480 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
5481 | -** General Public License version 2.1 as published by the Free Software | |
5482 | -** Foundation and appearing in the file LICENSE.LGPL included in the | |
5483 | -** packaging of this file. Please review the following information to | |
5484 | -** ensure the GNU Lesser General Public License version 2.1 requirements | |
5485 | -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
5486 | -** | |
5487 | -** In addition, as a special exception, Digia gives you certain additional | |
5488 | -** rights. These rights are described in the Digia Qt LGPL Exception | |
5489 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
5490 | -** | |
5491 | -** GNU General Public License Usage | |
5492 | -** Alternatively, this file may be used under the terms of the GNU | |
5493 | -** General Public License version 3.0 as published by the Free Software | |
5494 | -** Foundation and appearing in the file LICENSE.GPL included in the | |
5495 | -** packaging of this file. Please review the following information to | |
5496 | -** ensure the GNU General Public License version 3.0 requirements will be | |
5497 | -** met: http://www.gnu.org/copyleft/gpl.html. | |
5498 | -** | |
5499 | -** | |
5500 | -** $QT_END_LICENSE$ | |
5501 | -** | |
5502 | -****************************************************************************/ | |
5503 | - | |
5504 | -#ifndef QCOMMANDLINEPARSER_H | |
5505 | -#define QCOMMANDLINEPARSER_H | |
5506 | - | |
5507 | -#include <QStringList> | |
5508 | -#include <QCoreApplication> | |
5509 | - | |
5510 | -#include "qcommandlineoption.h" | |
5511 | - | |
5512 | -class QCommandLineParserPrivate; | |
5513 | -class QCoreApplication; | |
5514 | - | |
5515 | -class QCommandLineParser | |
5516 | -{ | |
5517 | - Q_DECLARE_TR_FUNCTIONS(QCommandLineParser) | |
5518 | -public: | |
5519 | - QCommandLineParser(); | |
5520 | - ~QCommandLineParser(); | |
5521 | - | |
5522 | - enum SingleDashWordOptionMode { | |
5523 | - ParseAsCompactedShortOptions, | |
5524 | - ParseAsLongOptions | |
5525 | - }; | |
5526 | - void setSingleDashWordOptionMode(SingleDashWordOptionMode parsingMode); | |
5527 | - | |
5528 | - bool addOption(const QCommandLineOption &commandLineOption); | |
5529 | - | |
5530 | - QCommandLineOption addVersionOption(); | |
5531 | - QCommandLineOption addHelpOption(); | |
5532 | - void setApplicationDescription(const QString &description); | |
5533 | - QString applicationDescription() const; | |
5534 | - void addPositionalArgument(const QString &name, const QString &description, const QString &syntax = QString()); | |
5535 | - void clearPositionalArguments(); | |
5536 | - | |
5537 | - void process(const QStringList &arguments); | |
5538 | - void process(const QCoreApplication &app); | |
5539 | - | |
5540 | - bool parse(const QStringList &arguments); | |
5541 | - QString errorText() const; | |
5542 | - | |
5543 | - bool isSet(const QString &name) const; | |
5544 | - QString value(const QString &name) const; | |
5545 | - QStringList values(const QString &name) const; | |
5546 | - | |
5547 | - bool isSet(const QCommandLineOption &option) const; | |
5548 | - QString value(const QCommandLineOption &option) const; | |
5549 | - QStringList values(const QCommandLineOption &option) const; | |
5550 | - | |
5551 | - QStringList positionalArguments() const; | |
5552 | - QStringList optionNames() const; | |
5553 | - QStringList unknownOptionNames() const; | |
5554 | - | |
5555 | - void showHelp(int exitCode = 0); | |
5556 | - QString helpText() const; | |
5557 | - | |
5558 | -private: | |
5559 | - Q_DISABLE_COPY(QCommandLineParser) | |
5560 | - | |
5561 | - QCommandLineParserPrivate * const d; | |
5562 | -}; | |
5563 | - | |
5564 | -#endif // QCOMMANDLINEPARSER_H | |
5565 | diff --git a/src/core/qlockfile.cpp b/src/core/qlockfile.cpp | |
5566 | deleted file mode 100644 | |
5567 | index 567440c..0000000 | |
5568 | --- a/src/core/qlockfile.cpp | |
5569 | +++ /dev/null | |
5570 | @@ -1,344 +0,0 @@ | |
5571 | -/**************************************************************************** | |
5572 | -** | |
5573 | -** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org> | |
5574 | -** Contact: http://www.qt-project.org/legal | |
5575 | -** | |
5576 | -** This file is part of the QtCore module of the Qt Toolkit. | |
5577 | -** | |
5578 | -** $QT_BEGIN_LICENSE:LGPL21$ | |
5579 | -** Commercial License Usage | |
5580 | -** Licensees holding valid commercial Qt licenses may use this file in | |
5581 | -** accordance with the commercial license agreement provided with the | |
5582 | -** Software or, alternatively, in accordance with the terms contained in | |
5583 | -** a written agreement between you and Digia. For licensing terms and | |
5584 | -** conditions see http://qt.digia.com/licensing. For further information | |
5585 | -** use the contact form at http://qt.digia.com/contact-us. | |
5586 | -** | |
5587 | -** GNU Lesser General Public License Usage | |
5588 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
5589 | -** General Public License version 2.1 or version 3 as published by the Free | |
5590 | -** Software Foundation and appearing in the file LICENSE.LGPLv21 and | |
5591 | -** LICENSE.LGPLv3 included in the packaging of this file. Please review the | |
5592 | -** following information to ensure the GNU Lesser General Public License | |
5593 | -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | |
5594 | -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
5595 | -** | |
5596 | -** In addition, as a special exception, Digia gives you certain additional | |
5597 | -** rights. These rights are described in the Digia Qt LGPL Exception | |
5598 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
5599 | -** | |
5600 | -** $QT_END_LICENSE$ | |
5601 | -** | |
5602 | -****************************************************************************/ | |
5603 | - | |
5604 | -#include "qlockfile.h" | |
5605 | -#include "qlockfile_p.h" | |
5606 | -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) | |
5607 | -# include <QElapsedTimer> | |
5608 | -#else | |
5609 | -# include <QTime> | |
5610 | -#endif | |
5611 | -#include <QDateTime> | |
5612 | - | |
5613 | -QT_BEGIN_NAMESPACE | |
5614 | - | |
5615 | -/*! | |
5616 | - \class QLockFile | |
5617 | - \inmodule QtCore | |
5618 | - \brief The QLockFile class provides locking between processes using a file. | |
5619 | - \since 5.1 | |
5620 | - | |
5621 | - A lock file can be used to prevent multiple processes from accessing concurrently | |
5622 | - the same resource. For instance, a configuration file on disk, or a socket, a port, | |
5623 | - a region of shared memory... | |
5624 | - | |
5625 | - Serialization is only guaranteed if all processes that access the shared resource | |
5626 | - use QLockFile, with the same file path. | |
5627 | - | |
5628 | - QLockFile supports two use cases: | |
5629 | - to protect a resource for a short-term operation (e.g. verifying if a configuration | |
5630 | - file has changed before saving new settings), and for long-lived protection of a | |
5631 | - resource (e.g. a document opened by a user in an editor) for an indefinite amount of time. | |
5632 | - | |
5633 | - When protecting for a short-term operation, it is acceptable to call lock() and wait | |
5634 | - until any running operation finishes. | |
5635 | - When protecting a resource over a long time, however, the application should always | |
5636 | - call setStaleLockTime(0) and then tryLock() with a short timeout, in order to | |
5637 | - warn the user that the resource is locked. | |
5638 | - | |
5639 | - If the process holding the lock crashes, the lock file stays on disk and can prevent | |
5640 | - any other process from accessing the shared resource, ever. For this reason, QLockFile | |
5641 | - tries to detect such a "stale" lock file, based on the process ID written into the file, | |
5642 | - and (in case that process ID got reused meanwhile), on the last modification time of | |
5643 | - the lock file (30s by default, for the use case of a short-lived operation). | |
5644 | - If the lock file is found to be stale, it will be deleted. | |
5645 | - | |
5646 | - For the use case of protecting a resource over a long time, you should therefore call | |
5647 | - setStaleLockTime(0), and when tryLock() returns LockFailedError, inform the user | |
5648 | - that the document is locked, possibly using getLockInfo() for more details. | |
5649 | -*/ | |
5650 | - | |
5651 | -/*! | |
5652 | - \enum QLockFile::LockError | |
5653 | - | |
5654 | - This enum describes the result of the last call to lock() or tryLock(). | |
5655 | - | |
5656 | - \value NoError The lock was acquired successfully. | |
5657 | - \value LockFailedError The lock could not be acquired because another process holds it. | |
5658 | - \value PermissionError The lock file could not be created, for lack of permissions | |
5659 | - in the parent directory. | |
5660 | - \value UnknownError Another error happened, for instance a full partition | |
5661 | - prevented writing out the lock file. | |
5662 | -*/ | |
5663 | - | |
5664 | -/*! | |
5665 | - Constructs a new lock file object. | |
5666 | - The object is created in an unlocked state. | |
5667 | - When calling lock() or tryLock(), a lock file named \a fileName will be created, | |
5668 | - if it doesn't already exist. | |
5669 | - | |
5670 | - \sa lock(), unlock() | |
5671 | -*/ | |
5672 | -QLockFile::QLockFile(const QString &fileName) | |
5673 | - : d_ptr(new QLockFilePrivate(fileName)) | |
5674 | -{ | |
5675 | -} | |
5676 | - | |
5677 | -/*! | |
5678 | - Destroys the lock file object. | |
5679 | - If the lock was acquired, this will release the lock, by deleting the lock file. | |
5680 | -*/ | |
5681 | -QLockFile::~QLockFile() | |
5682 | -{ | |
5683 | - unlock(); | |
5684 | -} | |
5685 | - | |
5686 | -/*! | |
5687 | - Sets \a staleLockTime to be the time in milliseconds after which | |
5688 | - a lock file is considered stale. | |
5689 | - The default value is 30000, i.e. 30 seconds. | |
5690 | - If your application typically keeps the file locked for more than 30 seconds | |
5691 | - (for instance while saving megabytes of data for 2 minutes), you should set | |
5692 | - a bigger value using setStaleLockTime(). | |
5693 | - | |
5694 | - The value of \a staleLockTime is used by lock() and tryLock() in order | |
5695 | - to determine when an existing lock file is considered stale, i.e. left over | |
5696 | - by a crashed process. This is useful for the case where the PID got reused | |
5697 | - meanwhile, so the only way to detect a stale lock file is by the fact that | |
5698 | - it has been around for a long time. | |
5699 | - | |
5700 | - \sa staleLockTime() | |
5701 | -*/ | |
5702 | -void QLockFile::setStaleLockTime(int staleLockTime) | |
5703 | -{ | |
5704 | - Q_D(QLockFile); | |
5705 | - d->staleLockTime = staleLockTime; | |
5706 | -} | |
5707 | - | |
5708 | -/*! | |
5709 | - Returns the time in milliseconds after which | |
5710 | - a lock file is considered stale. | |
5711 | - | |
5712 | - \sa setStaleLockTime() | |
5713 | -*/ | |
5714 | -int QLockFile::staleLockTime() const | |
5715 | -{ | |
5716 | - Q_D(const QLockFile); | |
5717 | - return d->staleLockTime; | |
5718 | -} | |
5719 | - | |
5720 | -/*! | |
5721 | - Returns \c true if the lock was acquired by this QLockFile instance, | |
5722 | - otherwise returns \c false. | |
5723 | - | |
5724 | - \sa lock(), unlock(), tryLock() | |
5725 | -*/ | |
5726 | -bool QLockFile::isLocked() const | |
5727 | -{ | |
5728 | - Q_D(const QLockFile); | |
5729 | - return d->isLocked; | |
5730 | -} | |
5731 | - | |
5732 | -/*! | |
5733 | - Creates the lock file. | |
5734 | - | |
5735 | - If another process (or another thread) has created the lock file already, | |
5736 | - this function will block until that process (or thread) releases it. | |
5737 | - | |
5738 | - Calling this function multiple times on the same lock from the same | |
5739 | - thread without unlocking first is not allowed. This function will | |
5740 | - \e dead-lock when the file is locked recursively. | |
5741 | - | |
5742 | - Returns \c true if the lock was acquired, false if it could not be acquired | |
5743 | - due to an unrecoverable error, such as no permissions in the parent directory. | |
5744 | - | |
5745 | - \sa unlock(), tryLock() | |
5746 | -*/ | |
5747 | -bool QLockFile::lock() | |
5748 | -{ | |
5749 | - return tryLock(-1); | |
5750 | -} | |
5751 | - | |
5752 | -/*! | |
5753 | - Attempts to create the lock file. This function returns \c true if the | |
5754 | - lock was obtained; otherwise it returns \c false. If another process (or | |
5755 | - another thread) has created the lock file already, this function will | |
5756 | - wait for at most \a timeout milliseconds for the lock file to become | |
5757 | - available. | |
5758 | - | |
5759 | - Note: Passing a negative number as the \a timeout is equivalent to | |
5760 | - calling lock(), i.e. this function will wait forever until the lock | |
5761 | - file can be locked if \a timeout is negative. | |
5762 | - | |
5763 | - If the lock was obtained, it must be released with unlock() | |
5764 | - before another process (or thread) can successfully lock it. | |
5765 | - | |
5766 | - Calling this function multiple times on the same lock from the same | |
5767 | - thread without unlocking first is not allowed, this function will | |
5768 | - \e always return false when attempting to lock the file recursively. | |
5769 | - | |
5770 | - \sa lock(), unlock() | |
5771 | -*/ | |
5772 | -bool QLockFile::tryLock(int timeout) | |
5773 | -{ | |
5774 | - Q_D(QLockFile); | |
5775 | -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) | |
5776 | - QElapsedTimer timer; | |
5777 | -#else | |
5778 | - QTime timer; | |
5779 | -#endif | |
5780 | - if (timeout > 0) | |
5781 | - timer.start(); | |
5782 | - int sleepTime = 100; | |
5783 | - Q_FOREVER { | |
5784 | - d->lockError = d->tryLock_sys(); | |
5785 | - switch (d->lockError) { | |
5786 | - case NoError: | |
5787 | - d->isLocked = true; | |
5788 | - return true; | |
5789 | - case PermissionError: | |
5790 | - case UnknownError: | |
5791 | - return false; | |
5792 | - case LockFailedError: | |
5793 | - if (!d->isLocked && d->isApparentlyStale()) { | |
5794 | - // Stale lock from another thread/process | |
5795 | - // Ensure two processes don't remove it at the same time | |
5796 | - QLockFile rmlock(d->fileName + QLatin1String(".rmlock")); | |
5797 | - if (rmlock.tryLock()) { | |
5798 | - if (d->isApparentlyStale() && d->removeStaleLock()) | |
5799 | - continue; | |
5800 | - } | |
5801 | - } | |
5802 | - break; | |
5803 | - } | |
5804 | - if (timeout == 0 || (timeout > 0 && (timer.elapsed() > timeout))) | |
5805 | - return false; | |
5806 | - QLockFileThread::msleep(sleepTime); | |
5807 | - if (sleepTime < 5 * 1000) | |
5808 | - sleepTime *= 2; | |
5809 | - } | |
5810 | - // not reached | |
5811 | - return false; | |
5812 | -} | |
5813 | - | |
5814 | -/*! | |
5815 | - \fn void QLockFile::unlock() | |
5816 | - Releases the lock, by deleting the lock file. | |
5817 | - | |
5818 | - Calling unlock() without locking the file first, does nothing. | |
5819 | - | |
5820 | - \sa lock(), tryLock() | |
5821 | -*/ | |
5822 | - | |
5823 | -/*! | |
5824 | - Retrieves information about the current owner of the lock file. | |
5825 | - | |
5826 | - If tryLock() returns \c false, and error() returns LockFailedError, | |
5827 | - this function can be called to find out more information about the existing | |
5828 | - lock file: | |
5829 | - \list | |
5830 | - \li the PID of the application (returned in \a pid) | |
5831 | - \li the \a hostname it's running on (useful in case of networked filesystems), | |
5832 | - \li the name of the application which created it (returned in \a appname), | |
5833 | - \endlist | |
5834 | - | |
5835 | - Note that tryLock() automatically deleted the file if there is no | |
5836 | - running application with this PID, so LockFailedError can only happen if there is | |
5837 | - an application with this PID (it could be unrelated though). | |
5838 | - | |
5839 | - This can be used to inform users about the existing lock file and give them | |
5840 | - the choice to delete it. After removing the file using removeStaleLockFile(), | |
5841 | - the application can call tryLock() again. | |
5842 | - | |
5843 | - This function returns \c true if the information could be successfully retrieved, false | |
5844 | - if the lock file doesn't exist or doesn't contain the expected data. | |
5845 | - This can happen if the lock file was deleted between the time where tryLock() failed | |
5846 | - and the call to this function. Simply call tryLock() again if this happens. | |
5847 | -*/ | |
5848 | -bool QLockFile::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const | |
5849 | -{ | |
5850 | - Q_D(const QLockFile); | |
5851 | - return d->getLockInfo(pid, hostname, appname); | |
5852 | -} | |
5853 | - | |
5854 | -bool QLockFilePrivate::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const | |
5855 | -{ | |
5856 | - QFile reader(fileName); | |
5857 | - if (!reader.open(QIODevice::ReadOnly)) | |
5858 | - return false; | |
5859 | - | |
5860 | - QByteArray pidLine = reader.readLine(); | |
5861 | - pidLine.chop(1); | |
5862 | - QByteArray appNameLine = reader.readLine(); | |
5863 | - appNameLine.chop(1); | |
5864 | - QByteArray hostNameLine = reader.readLine(); | |
5865 | - hostNameLine.chop(1); | |
5866 | - if (pidLine.isEmpty()) | |
5867 | - return false; | |
5868 | - | |
5869 | - qint64 thePid = pidLine.toLongLong(); | |
5870 | - if (pid) | |
5871 | - *pid = thePid; | |
5872 | - if (appname) | |
5873 | - *appname = QString::fromUtf8(appNameLine); | |
5874 | - if (hostname) | |
5875 | - *hostname = QString::fromUtf8(hostNameLine); | |
5876 | - return thePid > 0; | |
5877 | -} | |
5878 | - | |
5879 | -/*! | |
5880 | - Attempts to forcefully remove an existing lock file. | |
5881 | - | |
5882 | - Calling this is not recommended when protecting a short-lived operation: QLockFile | |
5883 | - already takes care of removing lock files after they are older than staleLockTime(). | |
5884 | - | |
5885 | - This method should only be called when protecting a resource for a long time, i.e. | |
5886 | - with staleLockTime(0), and after tryLock() returned LockFailedError, and the user | |
5887 | - agreed on removing the lock file. | |
5888 | - | |
5889 | - Returns \c true on success, false if the lock file couldn't be removed. This happens | |
5890 | - on Windows, when the application owning the lock is still running. | |
5891 | -*/ | |
5892 | -bool QLockFile::removeStaleLockFile() | |
5893 | -{ | |
5894 | - Q_D(QLockFile); | |
5895 | - if (d->isLocked) { | |
5896 | - qWarning("removeStaleLockFile can only be called when not holding the lock"); | |
5897 | - return false; | |
5898 | - } | |
5899 | - return d->removeStaleLock(); | |
5900 | -} | |
5901 | - | |
5902 | -/*! | |
5903 | - Returns the lock file error status. | |
5904 | - | |
5905 | - If tryLock() returns \c false, this function can be called to find out | |
5906 | - the reason why the locking failed. | |
5907 | -*/ | |
5908 | -QLockFile::LockError QLockFile::error() const | |
5909 | -{ | |
5910 | - Q_D(const QLockFile); | |
5911 | - return d->lockError; | |
5912 | -} | |
5913 | - | |
5914 | -QT_END_NAMESPACE | |
5915 | diff --git a/src/core/qlockfile.h b/src/core/qlockfile.h | |
5916 | deleted file mode 100644 | |
5917 | index 673026f..0000000 | |
5918 | --- a/src/core/qlockfile.h | |
5919 | +++ /dev/null | |
5920 | @@ -1,79 +0,0 @@ | |
5921 | -/**************************************************************************** | |
5922 | -** | |
5923 | -** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org> | |
5924 | -** Contact: http://www.qt-project.org/legal | |
5925 | -** | |
5926 | -** This file is part of the QtCore module of the Qt Toolkit. | |
5927 | -** | |
5928 | -** $QT_BEGIN_LICENSE:LGPL21$ | |
5929 | -** Commercial License Usage | |
5930 | -** Licensees holding valid commercial Qt licenses may use this file in | |
5931 | -** accordance with the commercial license agreement provided with the | |
5932 | -** Software or, alternatively, in accordance with the terms contained in | |
5933 | -** a written agreement between you and Digia. For licensing terms and | |
5934 | -** conditions see http://qt.digia.com/licensing. For further information | |
5935 | -** use the contact form at http://qt.digia.com/contact-us. | |
5936 | -** | |
5937 | -** GNU Lesser General Public License Usage | |
5938 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
5939 | -** General Public License version 2.1 or version 3 as published by the Free | |
5940 | -** Software Foundation and appearing in the file LICENSE.LGPLv21 and | |
5941 | -** LICENSE.LGPLv3 included in the packaging of this file. Please review the | |
5942 | -** following information to ensure the GNU Lesser General Public License | |
5943 | -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | |
5944 | -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
5945 | -** | |
5946 | -** In addition, as a special exception, Digia gives you certain additional | |
5947 | -** rights. These rights are described in the Digia Qt LGPL Exception | |
5948 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
5949 | -** | |
5950 | -** $QT_END_LICENSE$ | |
5951 | -** | |
5952 | -****************************************************************************/ | |
5953 | - | |
5954 | -#ifndef QLOCKFILE_H | |
5955 | -#define QLOCKFILE_H | |
5956 | - | |
5957 | -#include <QString> | |
5958 | -#include <QScopedPointer> | |
5959 | - | |
5960 | -QT_BEGIN_NAMESPACE | |
5961 | - | |
5962 | -class QLockFilePrivate; | |
5963 | - | |
5964 | -class QLockFile | |
5965 | -{ | |
5966 | -public: | |
5967 | - QLockFile(const QString &fileName); | |
5968 | - ~QLockFile(); | |
5969 | - | |
5970 | - bool lock(); | |
5971 | - bool tryLock(int timeout = 0); | |
5972 | - void unlock(); | |
5973 | - | |
5974 | - void setStaleLockTime(int); | |
5975 | - int staleLockTime() const; | |
5976 | - | |
5977 | - bool isLocked() const; | |
5978 | - bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const; | |
5979 | - bool removeStaleLockFile(); | |
5980 | - | |
5981 | - enum LockError { | |
5982 | - NoError = 0, | |
5983 | - LockFailedError = 1, | |
5984 | - PermissionError = 2, | |
5985 | - UnknownError = 3 | |
5986 | - }; | |
5987 | - LockError error() const; | |
5988 | - | |
5989 | -protected: | |
5990 | - QScopedPointer<QLockFilePrivate> d_ptr; | |
5991 | - | |
5992 | -private: | |
5993 | - Q_DECLARE_PRIVATE(QLockFile) | |
5994 | - Q_DISABLE_COPY(QLockFile) | |
5995 | -}; | |
5996 | - | |
5997 | -QT_END_NAMESPACE | |
5998 | - | |
5999 | -#endif // QLOCKFILE_H | |
6000 | diff --git a/src/core/qlockfile_p.h b/src/core/qlockfile_p.h | |
6001 | deleted file mode 100644 | |
6002 | index 15fa37b..0000000 | |
6003 | --- a/src/core/qlockfile_p.h | |
6004 | +++ /dev/null | |
6005 | @@ -1,101 +0,0 @@ | |
6006 | -/**************************************************************************** | |
6007 | -** | |
6008 | -** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org> | |
6009 | -** Contact: http://www.qt-project.org/legal | |
6010 | -** | |
6011 | -** This file is part of the QtCore module of the Qt Toolkit. | |
6012 | -** | |
6013 | -** $QT_BEGIN_LICENSE:LGPL21$ | |
6014 | -** Commercial License Usage | |
6015 | -** Licensees holding valid commercial Qt licenses may use this file in | |
6016 | -** accordance with the commercial license agreement provided with the | |
6017 | -** Software or, alternatively, in accordance with the terms contained in | |
6018 | -** a written agreement between you and Digia. For licensing terms and | |
6019 | -** conditions see http://qt.digia.com/licensing. For further information | |
6020 | -** use the contact form at http://qt.digia.com/contact-us. | |
6021 | -** | |
6022 | -** GNU Lesser General Public License Usage | |
6023 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
6024 | -** General Public License version 2.1 or version 3 as published by the Free | |
6025 | -** Software Foundation and appearing in the file LICENSE.LGPLv21 and | |
6026 | -** LICENSE.LGPLv3 included in the packaging of this file. Please review the | |
6027 | -** following information to ensure the GNU Lesser General Public License | |
6028 | -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | |
6029 | -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
6030 | -** | |
6031 | -** In addition, as a special exception, Digia gives you certain additional | |
6032 | -** rights. These rights are described in the Digia Qt LGPL Exception | |
6033 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
6034 | -** | |
6035 | -** $QT_END_LICENSE$ | |
6036 | -** | |
6037 | -****************************************************************************/ | |
6038 | - | |
6039 | -#ifndef QLOCKFILE_P_H | |
6040 | -#define QLOCKFILE_P_H | |
6041 | - | |
6042 | -// | |
6043 | -// W A R N I N G | |
6044 | -// ------------- | |
6045 | -// | |
6046 | -// This file is not part of the Qt API. It exists purely as an | |
6047 | -// implementation detail. This header file may change from version to | |
6048 | -// version without notice, or even be removed. | |
6049 | -// | |
6050 | -// We mean it. | |
6051 | -// | |
6052 | - | |
6053 | -#include "qlockfile.h" | |
6054 | - | |
6055 | -#include <QFile> | |
6056 | -#include <QThread> | |
6057 | - | |
6058 | -#ifdef Q_OS_WIN | |
6059 | -#include <qt_windows.h> | |
6060 | -#endif | |
6061 | - | |
6062 | -QT_BEGIN_NAMESPACE | |
6063 | - | |
6064 | -class QLockFileThread : public QThread | |
6065 | -{ | |
6066 | -public: | |
6067 | - static void msleep(unsigned long msecs) { QThread::msleep(msecs); } | |
6068 | -}; | |
6069 | - | |
6070 | -class QLockFilePrivate | |
6071 | -{ | |
6072 | -public: | |
6073 | - QLockFilePrivate(const QString &fn) | |
6074 | - : fileName(fn), | |
6075 | -#ifdef Q_OS_WIN | |
6076 | - fileHandle(INVALID_HANDLE_VALUE), | |
6077 | -#else | |
6078 | - fileHandle(-1), | |
6079 | -#endif | |
6080 | - staleLockTime(30 * 1000), // 30 seconds | |
6081 | - lockError(QLockFile::NoError), | |
6082 | - isLocked(false) | |
6083 | - { | |
6084 | - } | |
6085 | - QLockFile::LockError tryLock_sys(); | |
6086 | - bool removeStaleLock(); | |
6087 | - bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const; | |
6088 | - // Returns \c true if the lock belongs to dead PID, or is old. | |
6089 | - // The attempt to delete it will tell us if it was really stale or not, though. | |
6090 | - bool isApparentlyStale() const; | |
6091 | - static QString processNameByPid(qint64 pid); | |
6092 | - | |
6093 | - QString fileName; | |
6094 | -#ifdef Q_OS_WIN | |
6095 | - Qt::HANDLE fileHandle; | |
6096 | -#else | |
6097 | - int fileHandle; | |
6098 | -#endif | |
6099 | - int staleLockTime; // "int milliseconds" is big enough for 24 days | |
6100 | - QLockFile::LockError lockError; | |
6101 | - bool isLocked; | |
6102 | -}; | |
6103 | - | |
6104 | -QT_END_NAMESPACE | |
6105 | - | |
6106 | -#endif /* QLOCKFILE_P_H */ | |
6107 | diff --git a/src/core/qlockfile_unix.cpp b/src/core/qlockfile_unix.cpp | |
6108 | deleted file mode 100644 | |
6109 | index 5b3add3..0000000 | |
6110 | --- a/src/core/qlockfile_unix.cpp | |
6111 | +++ /dev/null | |
6112 | @@ -1,244 +0,0 @@ | |
6113 | -/**************************************************************************** | |
6114 | -** | |
6115 | -** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org> | |
6116 | -** Copyright (C) 2015 The Qt Company Ltd. | |
6117 | -** Contact: http://www.qt-project.org/legal | |
6118 | -** | |
6119 | -** This file is part of the QtCore module of the Qt Toolkit. | |
6120 | -** | |
6121 | -** $QT_BEGIN_LICENSE:LGPL21$ | |
6122 | -** Commercial License Usage | |
6123 | -** Licensees holding valid commercial Qt licenses may use this file in | |
6124 | -** accordance with the commercial license agreement provided with the | |
6125 | -** Software or, alternatively, in accordance with the terms contained in | |
6126 | -** a written agreement between you and Digia. For licensing terms and | |
6127 | -** conditions see http://qt.digia.com/licensing. For further information | |
6128 | -** use the contact form at http://qt.digia.com/contact-us. | |
6129 | -** | |
6130 | -** GNU Lesser General Public License Usage | |
6131 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
6132 | -** General Public License version 2.1 or version 3 as published by the Free | |
6133 | -** Software Foundation and appearing in the file LICENSE.LGPLv21 and | |
6134 | -** LICENSE.LGPLv3 included in the packaging of this file. Please review the | |
6135 | -** following information to ensure the GNU Lesser General Public License | |
6136 | -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | |
6137 | -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
6138 | -** | |
6139 | -** In addition, as a special exception, Digia gives you certain additional | |
6140 | -** rights. These rights are described in the Digia Qt LGPL Exception | |
6141 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
6142 | -** | |
6143 | -** $QT_END_LICENSE$ | |
6144 | -** | |
6145 | -****************************************************************************/ | |
6146 | - | |
6147 | -#include "qlockfile_p.h" | |
6148 | - | |
6149 | -#include <QTemporaryFile> | |
6150 | -#include <QCoreApplication> | |
6151 | -#include <QFileInfo> | |
6152 | -#include <QDebug> | |
6153 | -#include <QDateTime> | |
6154 | - | |
6155 | -#include <sys/file.h> // flock | |
6156 | -#include <sys/types.h> // kill | |
6157 | -#include <signal.h> // kill | |
6158 | -#include <unistd.h> // gethostname | |
6159 | - | |
6160 | -#include <errno.h> | |
6161 | - | |
6162 | -#if defined(Q_OS_MAC) | |
6163 | -# include <libproc.h> | |
6164 | -#elif defined(Q_OS_LINUX) | |
6165 | -# include <unistd.h> | |
6166 | -# include <cstdio> | |
6167 | -#endif | |
6168 | - | |
6169 | -QT_BEGIN_NAMESPACE | |
6170 | - | |
6171 | -#define EINTR_LOOP(var, cmd) \ | |
6172 | - do { \ | |
6173 | - var = cmd; \ | |
6174 | - } while (var == -1 && errno == EINTR) | |
6175 | - | |
6176 | -// don't call QT_OPEN or ::open | |
6177 | -// call qt_safe_open | |
6178 | -static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 0777) | |
6179 | -{ | |
6180 | -#ifdef O_CLOEXEC | |
6181 | - flags |= O_CLOEXEC; | |
6182 | -#endif | |
6183 | - int fd; | |
6184 | - EINTR_LOOP(fd, ::open(pathname, flags, mode)); | |
6185 | - | |
6186 | - // unknown flags are ignored, so we have no way of verifying if | |
6187 | - // O_CLOEXEC was accepted | |
6188 | - if (fd != -1) | |
6189 | - ::fcntl(fd, F_SETFD, FD_CLOEXEC); | |
6190 | - return fd; | |
6191 | -} | |
6192 | - | |
6193 | -static inline qint64 qt_safe_write(int fd, const void *data, qint64 len) | |
6194 | -{ | |
6195 | - qint64 ret = 0; | |
6196 | - EINTR_LOOP(ret, ::write(fd, data, len)); | |
6197 | - return ret; | |
6198 | -} | |
6199 | - | |
6200 | -static QByteArray localHostName() // from QHostInfo::localHostName(), modified to return a QByteArray | |
6201 | -{ | |
6202 | - QByteArray hostName(512, Qt::Uninitialized); | |
6203 | - if (gethostname(hostName.data(), hostName.size()) == -1) | |
6204 | - return QByteArray(); | |
6205 | - hostName.truncate(strlen(hostName.data())); | |
6206 | - return hostName; | |
6207 | -} | |
6208 | - | |
6209 | -// ### merge into qt_safe_write? | |
6210 | -static qint64 qt_write_loop(int fd, const char *data, qint64 len) | |
6211 | -{ | |
6212 | - qint64 pos = 0; | |
6213 | - while (pos < len) { | |
6214 | - const qint64 ret = qt_safe_write(fd, data + pos, len - pos); | |
6215 | - if (ret == -1) // e.g. partition full | |
6216 | - return pos; | |
6217 | - pos += ret; | |
6218 | - } | |
6219 | - return pos; | |
6220 | -} | |
6221 | - | |
6222 | -static bool setNativeLocks(int fd) | |
6223 | -{ | |
6224 | -#if defined(LOCK_EX) && defined(LOCK_NB) | |
6225 | - if (flock(fd, LOCK_EX | LOCK_NB) == -1) // other threads, and other processes on a local fs | |
6226 | - return false; | |
6227 | -#endif | |
6228 | - struct flock flockData; | |
6229 | - flockData.l_type = F_WRLCK; | |
6230 | - flockData.l_whence = SEEK_SET; | |
6231 | - flockData.l_start = 0; | |
6232 | - flockData.l_len = 0; // 0 = entire file | |
6233 | - flockData.l_pid = getpid(); | |
6234 | - if (fcntl(fd, F_SETLK, &flockData) == -1) // for networked filesystems | |
6235 | - return false; | |
6236 | - return true; | |
6237 | -} | |
6238 | - | |
6239 | -QLockFile::LockError QLockFilePrivate::tryLock_sys() | |
6240 | -{ | |
6241 | - // Assemble data, to write in a single call to write | |
6242 | - // (otherwise we'd have to check every write call) | |
6243 | - // Use operator% from the fast builder to avoid multiple memory allocations. | |
6244 | - QByteArray fileData = QByteArray::number(QCoreApplication::applicationPid()) + '\n' | |
6245 | - + QCoreApplication::applicationName().toUtf8() + '\n' | |
6246 | - + localHostName() + '\n'; | |
6247 | - | |
6248 | - const QByteArray lockFileName = QFile::encodeName(fileName); | |
6249 | - const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY | O_CREAT | O_EXCL, 0644); | |
6250 | - if (fd < 0) { | |
6251 | - switch (errno) { | |
6252 | - case EEXIST: | |
6253 | - return QLockFile::LockFailedError; | |
6254 | - case EACCES: | |
6255 | - case EROFS: | |
6256 | - return QLockFile::PermissionError; | |
6257 | - default: | |
6258 | - return QLockFile::UnknownError; | |
6259 | - } | |
6260 | - } | |
6261 | - // Ensure nobody else can delete the file while we have it | |
6262 | - if (!setNativeLocks(fd)) | |
6263 | - qWarning() << "setNativeLocks failed:" << strerror(errno); | |
6264 | - | |
6265 | - if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) { | |
6266 | - close(fd); | |
6267 | - if (!QFile::remove(fileName)) | |
6268 | - qWarning("QLockFile: Could not remove our own lock file %s.", qPrintable(fileName)); | |
6269 | - return QLockFile::UnknownError; // partition full | |
6270 | - } | |
6271 | - | |
6272 | - // We hold the lock, continue. | |
6273 | - fileHandle = fd; | |
6274 | - | |
6275 | - return QLockFile::NoError; | |
6276 | -} | |
6277 | - | |
6278 | -bool QLockFilePrivate::removeStaleLock() | |
6279 | -{ | |
6280 | - const QByteArray lockFileName = QFile::encodeName(fileName); | |
6281 | - const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY, 0644); | |
6282 | - if (fd < 0) // gone already? | |
6283 | - return false; | |
6284 | -#ifdef Q_OS_MAC | |
6285 | - // ugly workaround: ignore setNativeLocks() result on Mac since it's broken there | |
6286 | - setNativeLocks(fd); | |
6287 | - bool success = (::unlink(lockFileName) == 0); | |
6288 | -#else | |
6289 | - bool success = setNativeLocks(fd) && (::unlink(lockFileName) == 0); | |
6290 | -#endif | |
6291 | - close(fd); | |
6292 | - return success; | |
6293 | -} | |
6294 | - | |
6295 | -bool QLockFilePrivate::isApparentlyStale() const | |
6296 | -{ | |
6297 | - qint64 pid; | |
6298 | - QString hostname, appname; | |
6299 | - if (getLockInfo(&pid, &hostname, &appname)) { | |
6300 | - if (hostname.isEmpty() || hostname == QString::fromLocal8Bit(localHostName())) { | |
6301 | - if (::kill(pid, 0) == -1 && errno == ESRCH) | |
6302 | - return true; // PID doesn't exist anymore | |
6303 | - const QString processName = processNameByPid(pid); | |
6304 | - if (!processName.isEmpty()) { | |
6305 | - QFileInfo fi(appname); | |
6306 | - if (fi.isSymLink()) | |
6307 | - fi.setFile(fi.symLinkTarget()); | |
6308 | - if (processName.toLower() != fi.fileName().toLower()) | |
6309 | - return true; // PID got reused by a different application. | |
6310 | - } | |
6311 | - } | |
6312 | - } | |
6313 | - const qint64 age = QFileInfo(fileName).lastModified().secsTo(QDateTime::currentDateTime()) * 1000; | |
6314 | - return staleLockTime > 0 && age > staleLockTime; | |
6315 | -} | |
6316 | - | |
6317 | -QString QLockFilePrivate::processNameByPid(qint64 pid) | |
6318 | -{ | |
6319 | -#if defined(Q_OS_MAC) | |
6320 | - char name[1024]; | |
6321 | - proc_name(pid, name, sizeof(name) / sizeof(char)); | |
6322 | - return QFile::decodeName(name); | |
6323 | -#elif defined(Q_OS_LINUX) | |
6324 | - if (!QFile::exists(QString("/proc/version"))) | |
6325 | - return QString(); | |
6326 | - char exePath[64]; | |
6327 | - char buf[PATH_MAX + 1]; | |
6328 | - sprintf(exePath, "/proc/%lld/exe", pid); | |
6329 | - size_t len = static_cast<size_t>(readlink(exePath, buf, sizeof(buf))); | |
6330 | - if (len >= sizeof(buf)) { | |
6331 | - // The pid is gone. Return some invalid process name to fail the test. | |
6332 | - return QString("/ERROR/"); | |
6333 | - } | |
6334 | - buf[len] = 0; | |
6335 | - return QFileInfo(QFile::decodeName(buf)).fileName(); | |
6336 | -#else | |
6337 | - return QString(); | |
6338 | -#endif | |
6339 | -} | |
6340 | - | |
6341 | -void QLockFile::unlock() | |
6342 | -{ | |
6343 | - Q_D(QLockFile); | |
6344 | - if (!d->isLocked) | |
6345 | - return; | |
6346 | - close(d->fileHandle); | |
6347 | - d->fileHandle = -1; | |
6348 | - if (!QFile::remove(d->fileName)) { | |
6349 | - qWarning() << "Could not remove our own lock file" << d->fileName << "maybe permissions changed meanwhile?"; | |
6350 | - // This is bad because other users of this lock file will now have to wait for the stale-lock-timeout... | |
6351 | - } | |
6352 | - d->lockError = QLockFile::NoError; | |
6353 | - d->isLocked = false; | |
6354 | -} | |
6355 | - | |
6356 | -QT_END_NAMESPACE | |
6357 | diff --git a/src/core/qlockfile_win.cpp b/src/core/qlockfile_win.cpp | |
6358 | deleted file mode 100644 | |
6359 | index 5fc3327..0000000 | |
6360 | --- a/src/core/qlockfile_win.cpp | |
6361 | +++ /dev/null | |
6362 | @@ -1,227 +0,0 @@ | |
6363 | -/**************************************************************************** | |
6364 | -** | |
6365 | -** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org> | |
6366 | -** Copyright (C) 2015 The Qt Company Ltd. | |
6367 | -** Contact: http://www.qt.io/licensing/ | |
6368 | -** | |
6369 | -** This file is part of the QtCore module of the Qt Toolkit. | |
6370 | -** | |
6371 | -** $QT_BEGIN_LICENSE:LGPL21$ | |
6372 | -** Commercial License Usage | |
6373 | -** Licensees holding valid commercial Qt licenses may use this file in | |
6374 | -** accordance with the commercial license agreement provided with the | |
6375 | -** Software or, alternatively, in accordance with the terms contained in | |
6376 | -** a written agreement between you and The Qt Company. For licensing terms | |
6377 | -** and conditions see http://www.qt.io/terms-conditions. For further | |
6378 | -** information use the contact form at http://www.qt.io/contact-us. | |
6379 | -** | |
6380 | -** GNU Lesser General Public License Usage | |
6381 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
6382 | -** General Public License version 2.1 or version 3 as published by the Free | |
6383 | -** Software Foundation and appearing in the file LICENSE.LGPLv21 and | |
6384 | -** LICENSE.LGPLv3 included in the packaging of this file. Please review the | |
6385 | -** following information to ensure the GNU Lesser General Public License | |
6386 | -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | |
6387 | -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
6388 | -** | |
6389 | -** As a special exception, The Qt Company gives you certain additional | |
6390 | -** rights. These rights are described in The Qt Company LGPL Exception | |
6391 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
6392 | -** | |
6393 | -** $QT_END_LICENSE$ | |
6394 | -** | |
6395 | -****************************************************************************/ | |
6396 | - | |
6397 | -#ifndef _UNICODE | |
6398 | -#define _UNICODE | |
6399 | -#endif | |
6400 | - | |
6401 | -#ifndef UNICODE | |
6402 | -#define UNICODE | |
6403 | -#endif | |
6404 | - | |
6405 | -#include "qlockfile_p.h" | |
6406 | - | |
6407 | -#include <qt_windows.h> | |
6408 | - | |
6409 | -#include <QCoreApplication> | |
6410 | -#include <QDir> | |
6411 | -#include <QFileInfo> | |
6412 | -#include <QDateTime> | |
6413 | -#include <QDebug> | |
6414 | - | |
6415 | -QT_BEGIN_NAMESPACE | |
6416 | - | |
6417 | -static inline QByteArray localHostName() | |
6418 | -{ | |
6419 | - return qgetenv("COMPUTERNAME"); | |
6420 | -} | |
6421 | - | |
6422 | -static inline bool fileExists(const wchar_t *fileName) | |
6423 | -{ | |
6424 | - WIN32_FILE_ATTRIBUTE_DATA data; | |
6425 | - return GetFileAttributesEx(fileName, GetFileExInfoStandard, &data); | |
6426 | -} | |
6427 | - | |
6428 | -QLockFile::LockError QLockFilePrivate::tryLock_sys() | |
6429 | -{ | |
6430 | - const ushort* nativePath = QDir::toNativeSeparators(fileName).utf16(); | |
6431 | - // When writing, allow others to read. | |
6432 | - // When reading, QFile will allow others to read and write, all good. | |
6433 | - // Adding FILE_SHARE_DELETE would allow forceful deletion of stale files, | |
6434 | - // but Windows doesn't allow recreating it while this handle is open anyway, | |
6435 | - // so this would only create confusion (can't lock, but no lock file to read from). | |
6436 | - const DWORD dwShareMode = FILE_SHARE_READ; | |
6437 | -#ifndef Q_OS_WINRT | |
6438 | - SECURITY_ATTRIBUTES securityAtts = { sizeof(SECURITY_ATTRIBUTES), NULL, FALSE }; | |
6439 | - HANDLE fh = CreateFile((const wchar_t*)nativePath, | |
6440 | - GENERIC_WRITE, | |
6441 | - dwShareMode, | |
6442 | - &securityAtts, | |
6443 | - CREATE_NEW, // error if already exists | |
6444 | - FILE_ATTRIBUTE_NORMAL, | |
6445 | - NULL); | |
6446 | -#else // !Q_OS_WINRT | |
6447 | - HANDLE fh = CreateFile2((const wchar_t*)nativePath, | |
6448 | - GENERIC_WRITE, | |
6449 | - dwShareMode, | |
6450 | - CREATE_NEW, // error if already exists | |
6451 | - NULL); | |
6452 | -#endif // Q_OS_WINRT | |
6453 | - if (fh == INVALID_HANDLE_VALUE) { | |
6454 | - const DWORD lastError = GetLastError(); | |
6455 | - switch (lastError) { | |
6456 | - case ERROR_SHARING_VIOLATION: | |
6457 | - case ERROR_ALREADY_EXISTS: | |
6458 | - case ERROR_FILE_EXISTS: | |
6459 | - return QLockFile::LockFailedError; | |
6460 | - case ERROR_ACCESS_DENIED: | |
6461 | - // readonly file, or file still in use by another process. | |
6462 | - // Assume the latter if the file exists, since we don't create it readonly. | |
6463 | - return fileExists((const wchar_t*)nativePath) | |
6464 | - ? QLockFile::LockFailedError | |
6465 | - : QLockFile::PermissionError; | |
6466 | - default: | |
6467 | - qWarning() << "Got unexpected locking error" << lastError; | |
6468 | - return QLockFile::UnknownError; | |
6469 | - } | |
6470 | - } | |
6471 | - | |
6472 | - // We hold the lock, continue. | |
6473 | - fileHandle = fh; | |
6474 | - // Assemble data, to write in a single call to write | |
6475 | - // (otherwise we'd have to check every write call) | |
6476 | - QByteArray fileData; | |
6477 | - fileData += QByteArray::number(QCoreApplication::applicationPid()); | |
6478 | - fileData += '\n'; | |
6479 | - fileData += QCoreApplication::applicationName().toUtf8(); | |
6480 | - fileData += '\n'; | |
6481 | - fileData += localHostName(); | |
6482 | - fileData += '\n'; | |
6483 | - DWORD bytesWritten = 0; | |
6484 | - QLockFile::LockError error = QLockFile::NoError; | |
6485 | - if (!WriteFile(fh, fileData.constData(), fileData.size(), &bytesWritten, NULL) || !FlushFileBuffers(fh)) | |
6486 | - error = QLockFile::UnknownError; // partition full | |
6487 | - return error; | |
6488 | -} | |
6489 | - | |
6490 | -bool QLockFilePrivate::removeStaleLock() | |
6491 | -{ | |
6492 | - // QFile::remove fails on Windows if the other process is still using the file, so it's not stale. | |
6493 | - return QFile::remove(fileName); | |
6494 | -} | |
6495 | - | |
6496 | -bool QLockFilePrivate::isApparentlyStale() const | |
6497 | -{ | |
6498 | - qint64 pid; | |
6499 | - QString hostname, appname; | |
6500 | - | |
6501 | - // On WinRT there seems to be no way of obtaining information about other | |
6502 | - // processes due to sandboxing | |
6503 | -#ifndef Q_OS_WINRT | |
6504 | - if (getLockInfo(&pid, &hostname, &appname)) { | |
6505 | - if (hostname.isEmpty() || hostname == QString::fromLocal8Bit(localHostName())) { | |
6506 | - HANDLE procHandle = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); | |
6507 | - if (!procHandle) | |
6508 | - return true; | |
6509 | - // We got a handle but check if process is still alive | |
6510 | - DWORD dwR = ::WaitForSingleObject(procHandle, 0); | |
6511 | - ::CloseHandle(procHandle); | |
6512 | - if (dwR == WAIT_TIMEOUT) | |
6513 | - return true; | |
6514 | - const QString processName = processNameByPid(pid); | |
6515 | - if (!processName.isEmpty() && processName != appname) | |
6516 | - return true; // PID got reused by a different application. | |
6517 | - } | |
6518 | - } | |
6519 | -#else // !Q_OS_WINRT | |
6520 | - Q_UNUSED(pid); | |
6521 | - Q_UNUSED(hostname); | |
6522 | - Q_UNUSED(appname); | |
6523 | -#endif // Q_OS_WINRT | |
6524 | - const qint64 age = QFileInfo(fileName).lastModified().msecsTo(QDateTime::currentDateTime()); | |
6525 | - return staleLockTime > 0 && age > staleLockTime; | |
6526 | -} | |
6527 | - | |
6528 | -QString QLockFilePrivate::processNameByPid(qint64 pid) | |
6529 | -{ | |
6530 | -#if !defined(Q_OS_WINRT) && !defined(Q_OS_WINCE) | |
6531 | - typedef DWORD (WINAPI *GetModuleFileNameExFunc)(HANDLE, HMODULE, LPTSTR, DWORD); | |
6532 | - | |
6533 | - HMODULE hPsapi = LoadLibraryA("psapi"); | |
6534 | - if (!hPsapi) | |
6535 | - return QString(); | |
6536 | - | |
6537 | - GetModuleFileNameExFunc qGetModuleFileNameEx | |
6538 | - = (GetModuleFileNameExFunc)GetProcAddress(hPsapi, "GetModuleFileNameExW"); | |
6539 | - if (!qGetModuleFileNameEx) { | |
6540 | - FreeLibrary(hPsapi); | |
6541 | - return QString(); | |
6542 | - } | |
6543 | - | |
6544 | - HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, DWORD(pid)); | |
6545 | - if (!hProcess) { | |
6546 | - FreeLibrary(hPsapi); | |
6547 | - return QString(); | |
6548 | - } | |
6549 | - wchar_t buf[MAX_PATH]; | |
6550 | - const DWORD length = qGetModuleFileNameEx(hProcess, NULL, buf, sizeof(buf) / sizeof(wchar_t)); | |
6551 | - CloseHandle(hProcess); | |
6552 | - FreeLibrary(hPsapi); | |
6553 | - if (!length) | |
6554 | - return QString(); | |
6555 | - QString name = QString::fromWCharArray(buf, length); | |
6556 | - int i = name.lastIndexOf(QLatin1Char('\\')); | |
6557 | - if (i >= 0) | |
6558 | - name.remove(0, i + 1); | |
6559 | - i = name.lastIndexOf(QLatin1Char('.')); | |
6560 | - if (i >= 0) | |
6561 | - name.truncate(i); | |
6562 | - return name; | |
6563 | -#else | |
6564 | - Q_UNUSED(pid); | |
6565 | - return QString(); | |
6566 | -#endif | |
6567 | -} | |
6568 | - | |
6569 | -void QLockFile::unlock() | |
6570 | -{ | |
6571 | - Q_D(QLockFile); | |
6572 | - if (!d->isLocked) | |
6573 | - return; | |
6574 | - CloseHandle(d->fileHandle); | |
6575 | - int attempts = 0; | |
6576 | - static const int maxAttempts = 500; // 500ms | |
6577 | - while (!QFile::remove(d->fileName) && ++attempts < maxAttempts) { | |
6578 | - // Someone is reading the lock file right now (on Windows this prevents deleting it). | |
6579 | - QLockFileThread::msleep(1); | |
6580 | - } | |
6581 | - if (attempts == maxAttempts) { | |
6582 | - qWarning() << "Could not remove our own lock file" << d->fileName << ". Either other users of the lock file are reading it constantly for 500 ms, or we (no longer) have permissions to delete the file"; | |
6583 | - // This is bad because other users of this lock file will now have to wait for the stale-lock-timeout... | |
6584 | - } | |
6585 | - d->lockError = QLockFile::NoError; | |
6586 | - d->isLocked = false; | |
6587 | -} | |
6588 | - | |
6589 | -QT_END_NAMESPACE | |
6590 | diff --git a/src/core/qsavefile.cpp b/src/core/qsavefile.cpp | |
6591 | deleted file mode 100644 | |
6592 | index 287f9e8..0000000 | |
6593 | --- a/src/core/qsavefile.cpp | |
6594 | +++ /dev/null | |
6595 | @@ -1,452 +0,0 @@ | |
6596 | -/**************************************************************************** | |
6597 | -** | |
6598 | -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). | |
6599 | -** Contact: http://www.qt-project.org/ | |
6600 | -** | |
6601 | -** This file is part of the QtCore module of the Qt Toolkit. | |
6602 | -** | |
6603 | -** $QT_BEGIN_LICENSE:LGPL$ | |
6604 | -** GNU Lesser General Public License Usage | |
6605 | -** This file may be used under the terms of the GNU Lesser General Public | |
6606 | -** License version 2.1 as published by the Free Software Foundation and | |
6607 | -** appearing in the file LICENSE.LGPL included in the packaging of this | |
6608 | -** file. Please review the following information to ensure the GNU Lesser | |
6609 | -** General Public License version 2.1 requirements will be met: | |
6610 | -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
6611 | -** | |
6612 | -** In addition, as a special exception, Nokia gives you certain additional | |
6613 | -** rights. These rights are described in the Nokia Qt LGPL Exception | |
6614 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
6615 | -** | |
6616 | -** GNU General Public License Usage | |
6617 | -** Alternatively, this file may be used under the terms of the GNU General | |
6618 | -** Public License version 3.0 as published by the Free Software Foundation | |
6619 | -** and appearing in the file LICENSE.GPL included in the packaging of this | |
6620 | -** file. Please review the following information to ensure the GNU General | |
6621 | -** Public License version 3.0 requirements will be met: | |
6622 | -** http://www.gnu.org/copyleft/gpl.html. | |
6623 | -** | |
6624 | -** Other Usage | |
6625 | -** Alternatively, this file may be used in accordance with the terms and | |
6626 | -** conditions contained in a signed written agreement between you and Nokia. | |
6627 | -** | |
6628 | -** | |
6629 | -** | |
6630 | -** | |
6631 | -** | |
6632 | -** | |
6633 | -** $QT_END_LICENSE$ | |
6634 | -** | |
6635 | -****************************************************************************/ | |
6636 | - | |
6637 | -#include "qsavefile.h" | |
6638 | -#include "qsavefile_p.h" | |
6639 | - | |
6640 | -#include <QAbstractFileEngine> | |
6641 | -#include <QFileInfo> | |
6642 | -#include <QTemporaryFile> | |
6643 | - | |
6644 | -#ifdef Q_OS_WIN | |
6645 | -# include <windows.h> | |
6646 | -#else | |
6647 | -# include <unistd.h> | |
6648 | -#endif | |
6649 | - | |
6650 | -QSaveFilePrivate::QSaveFilePrivate() | |
6651 | - : tempFile(0), error(QFile::NoError) | |
6652 | -{ | |
6653 | -} | |
6654 | - | |
6655 | -QSaveFilePrivate::~QSaveFilePrivate() | |
6656 | -{ | |
6657 | -} | |
6658 | - | |
6659 | -/*! | |
6660 | - \class QSaveFile | |
6661 | - \brief The QSaveFile class provides an interface for safely writing to files. | |
6662 | - | |
6663 | - \ingroup io | |
6664 | - | |
6665 | - \reentrant | |
6666 | - | |
6667 | - QSaveFile is an I/O device for writing text and binary files, without losing | |
6668 | - existing data if the writing operation fails. | |
6669 | - | |
6670 | - While writing, the contents will be written to a temporary file, and if | |
6671 | - no error happened, commit() will move it to the final file. This ensures that | |
6672 | - no data at the final file is lost in case an error happens while writing, | |
6673 | - and no partially-written file is ever present at the final location. Always | |
6674 | - use QSaveFile when saving entire documents to disk. | |
6675 | - | |
6676 | - QSaveFile automatically detects errors while writing, such as the full partition | |
6677 | - situation, where write() cannot write all the bytes. It will remember that | |
6678 | - an error happened, and will discard the temporary file in commit(). | |
6679 | - | |
6680 | - Much like with QFile, the file is opened with open(). Data is usually read | |
6681 | - and written using QDataStream or QTextStream, but you can also call the | |
6682 | - QIODevice-inherited functions read(), readLine(), readAll(), write(). | |
6683 | - | |
6684 | - Unlike QFile, calling close() is not allowed. commit() replaces it. If commit() | |
6685 | - was not called and the QSaveFile instance is destroyed, the temporary file is | |
6686 | - discarded. | |
6687 | - | |
6688 | - \sa QTextStream, QDataStream, QFileInfo, QDir, QFile, QTemporaryFile | |
6689 | -*/ | |
6690 | - | |
6691 | -/*! | |
6692 | - \internal | |
6693 | -*/ | |
6694 | -QSaveFile::QSaveFile() | |
6695 | - : QIODevice(), d_ptr(new QSaveFilePrivate) | |
6696 | -{ | |
6697 | -} | |
6698 | -/*! | |
6699 | - Constructs a new file object with the given \a parent. | |
6700 | -*/ | |
6701 | -QSaveFile::QSaveFile(QObject *parent) | |
6702 | - : QIODevice(parent), d_ptr(new QSaveFilePrivate) | |
6703 | -{ | |
6704 | -} | |
6705 | -/*! | |
6706 | - Constructs a new file object to represent the file with the given \a name. | |
6707 | -*/ | |
6708 | -QSaveFile::QSaveFile(const QString &name) | |
6709 | - : QIODevice(0), d_ptr(new QSaveFilePrivate) | |
6710 | -{ | |
6711 | - Q_D(QSaveFile); | |
6712 | - d->fileName = name; | |
6713 | -} | |
6714 | -/*! | |
6715 | - Constructs a new file object with the given \a parent to represent the | |
6716 | - file with the specified \a name. | |
6717 | -*/ | |
6718 | -QSaveFile::QSaveFile(const QString &name, QObject *parent) | |
6719 | - : QIODevice(parent), d_ptr(new QSaveFilePrivate) | |
6720 | -{ | |
6721 | - Q_D(QSaveFile); | |
6722 | - d->fileName = name; | |
6723 | -} | |
6724 | - | |
6725 | -/*! | |
6726 | - Destroys the file object, discarding the saved contents unless commit() was called. | |
6727 | -*/ | |
6728 | -QSaveFile::~QSaveFile() | |
6729 | -{ | |
6730 | - Q_D(QSaveFile); | |
6731 | - if (d->tempFile) { | |
6732 | - d->tempFile->setAutoRemove(true); | |
6733 | - delete d->tempFile; | |
6734 | - } | |
6735 | - QIODevice::close(); | |
6736 | - delete d; | |
6737 | -} | |
6738 | - | |
6739 | -/*! | |
6740 | - Returns false since temporary files support random access. | |
6741 | - | |
6742 | - \sa QIODevice::isSequential() | |
6743 | -*/ | |
6744 | -bool QSaveFile::isSequential() const | |
6745 | -{ | |
6746 | - return false; | |
6747 | -} | |
6748 | - | |
6749 | -/*! | |
6750 | - Returns the file error status. | |
6751 | - | |
6752 | - The I/O device status returns an error code. For example, if open() | |
6753 | - returns false, or a read/write operation returns -1, this function can | |
6754 | - be called to find out the reason why the operation failed. | |
6755 | - | |
6756 | - Unlike QFile which clears the error on the next operation, QSaveFile remembers | |
6757 | - the error until the file is closed, in order to discard the file contents in close(). | |
6758 | - | |
6759 | - \sa unsetError() | |
6760 | -*/ | |
6761 | - | |
6762 | -QFile::FileError QSaveFile::error() const | |
6763 | -{ | |
6764 | - return d_func()->error; | |
6765 | -} | |
6766 | - | |
6767 | -/*! | |
6768 | - Sets the file's error to QFile::NoError. | |
6769 | - | |
6770 | - This will make QSaveFile forget that an error happened during saving, so you | |
6771 | - probably don't want to call this, unless you're really sure that you want to | |
6772 | - save the file anyway. | |
6773 | - | |
6774 | - \sa error() | |
6775 | -*/ | |
6776 | -void QSaveFile::unsetError() | |
6777 | -{ | |
6778 | - d_func()->error = QFile::NoError; | |
6779 | - setErrorString(QString()); | |
6780 | -} | |
6781 | - | |
6782 | -/*! | |
6783 | - Returns the name set by setFileName() or to the QSaveFile | |
6784 | - constructor. | |
6785 | - | |
6786 | - \sa setFileName() | |
6787 | -*/ | |
6788 | -QString QSaveFile::fileName() const | |
6789 | -{ | |
6790 | - return d_func()->fileName; | |
6791 | -} | |
6792 | - | |
6793 | -/*! | |
6794 | - Sets the \a name of the file. The name can have no path, a | |
6795 | - relative path, or an absolute path. | |
6796 | - | |
6797 | - \sa QFile::setFileName(), fileName() | |
6798 | -*/ | |
6799 | -void QSaveFile::setFileName(const QString &name) | |
6800 | -{ | |
6801 | - d_func()->fileName = name; | |
6802 | -} | |
6803 | - | |
6804 | -/*! | |
6805 | - Opens the file using OpenMode \a mode, returning true if successful; | |
6806 | - otherwise false. | |
6807 | - | |
6808 | - Important: the \a mode must be QIODevice::WriteOnly. | |
6809 | - It may also have additional flags, such as QIODevice::Text and QIODevice::Unbuffered. | |
6810 | - | |
6811 | - QIODevice::ReadWrite and QIODevice::Append are not supported at the moment. | |
6812 | - | |
6813 | - \sa QIODevice::OpenMode, setFileName() | |
6814 | -*/ | |
6815 | -bool QSaveFile::open(OpenMode mode) | |
6816 | -{ | |
6817 | - Q_D(QSaveFile); | |
6818 | - if (isOpen()) { | |
6819 | - qWarning("QSaveFile::open: File (%s) already open", qPrintable(fileName())); | |
6820 | - return false; | |
6821 | - } | |
6822 | - unsetError(); | |
6823 | - if ((mode & (ReadOnly | WriteOnly)) == 0) { | |
6824 | - qWarning("QSaveFile::open: Open mode not specified"); | |
6825 | - return false; | |
6826 | - } | |
6827 | - // In the future we could implement Append and ReadWrite by copying from the existing file to the temp file... | |
6828 | - if ((mode & ReadOnly) || (mode & Append)) { | |
6829 | - qWarning("QSaveFile::open: Unsupported open mode %d", int(mode)); | |
6830 | - return false; | |
6831 | - } | |
6832 | - | |
6833 | - // check if existing file is writable | |
6834 | - QFileInfo existingFile(d->fileName); | |
6835 | - if (existingFile.exists() && !existingFile.isWritable()) { | |
6836 | - d->error = QFile::WriteError; | |
6837 | - setErrorString(QSaveFile::tr("Existing file %1 is not writable").arg(d->fileName)); | |
6838 | - return false; | |
6839 | - } | |
6840 | - d->tempFile = new QTemporaryFile; | |
6841 | - d->tempFile->setAutoRemove(false); | |
6842 | - d->tempFile->setFileTemplate(d->fileName); | |
6843 | - if (!d->tempFile->open()) { | |
6844 | - d->error = d->tempFile->error(); | |
6845 | - setErrorString(d->tempFile->errorString()); | |
6846 | - delete d->tempFile; | |
6847 | - d->tempFile = 0; | |
6848 | - return false; | |
6849 | - } | |
6850 | - QIODevice::open(mode); | |
6851 | - if (existingFile.exists()) | |
6852 | - d->tempFile->setPermissions(existingFile.permissions()); | |
6853 | - return true; | |
6854 | -} | |
6855 | - | |
6856 | -/*! | |
6857 | - \reimp | |
6858 | - Cannot be called. | |
6859 | - Call commit() instead. | |
6860 | -*/ | |
6861 | -void QSaveFile::close() | |
6862 | -{ | |
6863 | - qFatal("QSaveFile::close called"); | |
6864 | -} | |
6865 | - | |
6866 | -/* | |
6867 | - Commits the changes to disk, if all previous writes were successful. | |
6868 | - | |
6869 | - It is mandatory to call this at the end of the saving operation, otherwise the file will be | |
6870 | - discarded. | |
6871 | - | |
6872 | - If an error happened during writing, deletes the temporary file and returns false. | |
6873 | - Otherwise, renames it to the final fileName and returns true on success. | |
6874 | - Finally, closes the device. | |
6875 | - | |
6876 | - \sa cancelWriting() | |
6877 | -*/ | |
6878 | -bool QSaveFile::commit() | |
6879 | -{ | |
6880 | - Q_D(QSaveFile); | |
6881 | - if (!d->tempFile) | |
6882 | - return false; | |
6883 | - if (!isOpen()) { | |
6884 | - qWarning("QSaveFile::commit: File (%s) is not open", qPrintable(fileName())); | |
6885 | - return false; | |
6886 | - } | |
6887 | - flush(); | |
6888 | -#ifdef Q_OS_WIN | |
6889 | - FlushFileBuffers(reinterpret_cast<HANDLE>(handle())); | |
6890 | -#elif defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 | |
6891 | - fdatasync(d->tempFile->handle()); | |
6892 | -#else | |
6893 | - fsync(d->tempFile->handle()); | |
6894 | -#endif | |
6895 | - QIODevice::close(); | |
6896 | - if (d->error != QFile::NoError) { | |
6897 | - d->tempFile->remove(); | |
6898 | - unsetError(); | |
6899 | - delete d->tempFile; | |
6900 | - d->tempFile = 0; | |
6901 | - return false; | |
6902 | - } | |
6903 | - d->tempFile->close(); | |
6904 | -#ifdef Q_OS_WIN | |
6905 | - // On Windows QAbstractFileEngine::rename() fails if the the target exists, | |
6906 | - // so we have to rename the target. | |
6907 | - // Ideally the winapi ReplaceFile() method should be used. | |
6908 | - QString bakname = d->fileName + "~"; | |
6909 | - QFile::remove(bakname); | |
6910 | - QFile::rename(d->fileName, bakname); | |
6911 | -#endif | |
6912 | - QAbstractFileEngine* fileEngine = d->tempFile->fileEngine(); | |
6913 | - Q_ASSERT(fileEngine); | |
6914 | - if (!fileEngine->rename(d->fileName)) { | |
6915 | - d->error = fileEngine->error(); | |
6916 | - setErrorString(fileEngine->errorString()); | |
6917 | - d->tempFile->remove(); | |
6918 | - delete d->tempFile; | |
6919 | - d->tempFile = 0; | |
6920 | -#ifdef Q_OS_WIN | |
6921 | - QFile::rename(bakname, d->fileName); | |
6922 | -#endif | |
6923 | - return false; | |
6924 | - } | |
6925 | - delete d->tempFile; | |
6926 | - d->tempFile = 0; | |
6927 | -#ifdef Q_OS_WIN | |
6928 | - QFile::remove(bakname); | |
6929 | -#endif | |
6930 | - return true; | |
6931 | -} | |
6932 | - | |
6933 | -/*! | |
6934 | - Sets an error code so that commit() discards the temporary file. | |
6935 | - | |
6936 | - Further write operations are possible after calling this method, but none | |
6937 | - of it will have any effect, the written file will be discarded. | |
6938 | - | |
6939 | - \sa commit() | |
6940 | -*/ | |
6941 | -void QSaveFile::cancelWriting() | |
6942 | -{ | |
6943 | - if (!isOpen()) | |
6944 | - return; | |
6945 | - d_func()->error = QFile::WriteError; | |
6946 | - setErrorString(QSaveFile::tr("Writing canceled by application")); | |
6947 | -} | |
6948 | - | |
6949 | -/*! | |
6950 | - Returns the size of the file. | |
6951 | - \sa QFile::size() | |
6952 | -*/ | |
6953 | -qint64 QSaveFile::size() const | |
6954 | -{ | |
6955 | - Q_D(const QSaveFile); | |
6956 | - return d->tempFile ? d->tempFile->size() : qint64(-1); | |
6957 | -} | |
6958 | - | |
6959 | -/*! | |
6960 | - \reimp | |
6961 | -*/ | |
6962 | -qint64 QSaveFile::pos() const | |
6963 | -{ | |
6964 | - Q_D(const QSaveFile); | |
6965 | - return d->tempFile ? d->tempFile->pos() : qint64(-1); | |
6966 | -} | |
6967 | - | |
6968 | -/*! | |
6969 | - \reimp | |
6970 | -*/ | |
6971 | -bool QSaveFile::seek(qint64 offset) | |
6972 | -{ | |
6973 | - Q_D(QSaveFile); | |
6974 | - return d->tempFile ? d->tempFile->seek(offset) : false; | |
6975 | -} | |
6976 | - | |
6977 | -/*! | |
6978 | - \reimp | |
6979 | -*/ | |
6980 | -bool QSaveFile::atEnd() const | |
6981 | -{ | |
6982 | - Q_D(const QSaveFile); | |
6983 | - return d->tempFile ? d->tempFile->atEnd() : true; | |
6984 | -} | |
6985 | - | |
6986 | -/*! | |
6987 | - Flushes any buffered data to the file. Returns true if successful; | |
6988 | - otherwise returns false. | |
6989 | -*/ | |
6990 | -bool QSaveFile::flush() | |
6991 | -{ | |
6992 | - Q_D(QSaveFile); | |
6993 | - if (d->tempFile) { | |
6994 | - if (!d->tempFile->flush()) { | |
6995 | - d->error = d->tempFile->error(); | |
6996 | - setErrorString(d->tempFile->errorString()); | |
6997 | - return false; | |
6998 | - } | |
6999 | - return true; | |
7000 | - } | |
7001 | - return false; | |
7002 | -} | |
7003 | - | |
7004 | -/*! | |
7005 | - Returns the file handle of the temporary file. | |
7006 | - | |
7007 | - \sa QFile::handle() | |
7008 | -*/ | |
7009 | -int QSaveFile::handle() const | |
7010 | -{ | |
7011 | - Q_D(const QSaveFile); | |
7012 | - return d->tempFile ? d->tempFile->handle() : -1; | |
7013 | -} | |
7014 | - | |
7015 | -/*! | |
7016 | - \reimp | |
7017 | -*/ | |
7018 | -qint64 QSaveFile::readData(char *data, qint64 maxlen) | |
7019 | -{ | |
7020 | - Q_D(QSaveFile); | |
7021 | - return d->tempFile ? d->tempFile->read(data, maxlen) : -1; | |
7022 | -} | |
7023 | - | |
7024 | -/*! | |
7025 | - \reimp | |
7026 | -*/ | |
7027 | -qint64 QSaveFile::writeData(const char *data, qint64 len) | |
7028 | -{ | |
7029 | - Q_D(QSaveFile); | |
7030 | - if (!d->tempFile) | |
7031 | - return -1; | |
7032 | - const qint64 written = d->tempFile->write(data, len); | |
7033 | - if (written != len) { | |
7034 | - d->error = QFile::WriteError; | |
7035 | - setErrorString(QSaveFile::tr("Partial write. Partition full?")); | |
7036 | - } | |
7037 | - return written; | |
7038 | -} | |
7039 | - | |
7040 | -/*! | |
7041 | - \reimp | |
7042 | -*/ | |
7043 | -qint64 QSaveFile::readLineData(char *data, qint64 maxlen) | |
7044 | -{ | |
7045 | - Q_D(QSaveFile); | |
7046 | - return d->tempFile ? d->tempFile->readLine(data, maxlen) : -1; | |
7047 | -} | |
7048 | diff --git a/src/core/qsavefile.h b/src/core/qsavefile.h | |
7049 | deleted file mode 100644 | |
7050 | index 84d5a24..0000000 | |
7051 | --- a/src/core/qsavefile.h | |
7052 | +++ /dev/null | |
7053 | @@ -1,105 +0,0 @@ | |
7054 | -/**************************************************************************** | |
7055 | -** | |
7056 | -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). | |
7057 | -** Contact: http://www.qt-project.org/ | |
7058 | -** | |
7059 | -** This file is part of the QtCore module of the Qt Toolkit. | |
7060 | -** | |
7061 | -** $QT_BEGIN_LICENSE:LGPL$ | |
7062 | -** GNU Lesser General Public License Usage | |
7063 | -** This file may be used under the terms of the GNU Lesser General Public | |
7064 | -** License version 2.1 as published by the Free Software Foundation and | |
7065 | -** appearing in the file LICENSE.LGPL included in the packaging of this | |
7066 | -** file. Please review the following information to ensure the GNU Lesser | |
7067 | -** General Public License version 2.1 requirements will be met: | |
7068 | -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
7069 | -** | |
7070 | -** In addition, as a special exception, Nokia gives you certain additional | |
7071 | -** rights. These rights are described in the Nokia Qt LGPL Exception | |
7072 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
7073 | -** | |
7074 | -** GNU General Public License Usage | |
7075 | -** Alternatively, this file may be used under the terms of the GNU General | |
7076 | -** Public License version 3.0 as published by the Free Software Foundation | |
7077 | -** and appearing in the file LICENSE.GPL included in the packaging of this | |
7078 | -** file. Please review the following information to ensure the GNU General | |
7079 | -** Public License version 3.0 requirements will be met: | |
7080 | -** http://www.gnu.org/copyleft/gpl.html. | |
7081 | -** | |
7082 | -** Other Usage | |
7083 | -** Alternatively, this file may be used in accordance with the terms and | |
7084 | -** conditions contained in a signed written agreement between you and Nokia. | |
7085 | -** | |
7086 | -** | |
7087 | -** | |
7088 | -** | |
7089 | -** | |
7090 | -** | |
7091 | -** $QT_END_LICENSE$ | |
7092 | -** | |
7093 | -****************************************************************************/ | |
7094 | - | |
7095 | -#ifndef QSAVEFILE_H | |
7096 | -#define QSAVEFILE_H | |
7097 | - | |
7098 | -#include <QFile> | |
7099 | -#include <QString> | |
7100 | - | |
7101 | -#ifdef open | |
7102 | -#error qsavefile.h must be included before any header file that defines open | |
7103 | -#endif | |
7104 | - | |
7105 | -class QAbstractFileEngine; | |
7106 | -class QSaveFilePrivate; | |
7107 | - | |
7108 | -class QSaveFile : public QIODevice | |
7109 | -{ | |
7110 | - Q_OBJECT | |
7111 | - Q_DECLARE_PRIVATE(QSaveFile) | |
7112 | - | |
7113 | -public: | |
7114 | - | |
7115 | - QSaveFile(); | |
7116 | - explicit QSaveFile(const QString &name); | |
7117 | - explicit QSaveFile(QObject *parent); | |
7118 | - QSaveFile(const QString &name, QObject *parent); | |
7119 | - ~QSaveFile(); | |
7120 | - | |
7121 | - QFile::FileError error() const; | |
7122 | - void unsetError(); | |
7123 | - | |
7124 | - QString fileName() const; | |
7125 | - void setFileName(const QString &name); | |
7126 | - | |
7127 | - bool isSequential() const; | |
7128 | - | |
7129 | - virtual bool open(OpenMode flags); | |
7130 | - bool commit(); | |
7131 | - | |
7132 | - void cancelWriting(); | |
7133 | - | |
7134 | - qint64 size() const; | |
7135 | - qint64 pos() const; | |
7136 | - bool seek(qint64 offset); | |
7137 | - bool atEnd() const; | |
7138 | - bool flush(); | |
7139 | - | |
7140 | - bool resize(qint64 sz); | |
7141 | - | |
7142 | - int handle() const; | |
7143 | - | |
7144 | -protected: | |
7145 | - qint64 readData(char *data, qint64 maxlen); | |
7146 | - qint64 writeData(const char *data, qint64 len); | |
7147 | - qint64 readLineData(char *data, qint64 maxlen); | |
7148 | - | |
7149 | -private: | |
7150 | - virtual void close(); | |
7151 | - | |
7152 | -private: | |
7153 | - Q_DISABLE_COPY(QSaveFile) | |
7154 | - | |
7155 | - QSaveFilePrivate* const d_ptr; | |
7156 | -}; | |
7157 | - | |
7158 | -#endif // QSAVEFILE_H | |
7159 | diff --git a/src/core/qsavefile_p.h b/src/core/qsavefile_p.h | |
7160 | deleted file mode 100644 | |
7161 | index 549ecc1..0000000 | |
7162 | --- a/src/core/qsavefile_p.h | |
7163 | +++ /dev/null | |
7164 | @@ -1,71 +0,0 @@ | |
7165 | -/**************************************************************************** | |
7166 | -** | |
7167 | -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). | |
7168 | -** Contact: http://www.qt-project.org/ | |
7169 | -** | |
7170 | -** This file is part of the QtCore module of the Qt Toolkit. | |
7171 | -** | |
7172 | -** $QT_BEGIN_LICENSE:LGPL$ | |
7173 | -** GNU Lesser General Public License Usage | |
7174 | -** This file may be used under the terms of the GNU Lesser General Public | |
7175 | -** License version 2.1 as published by the Free Software Foundation and | |
7176 | -** appearing in the file LICENSE.LGPL included in the packaging of this | |
7177 | -** file. Please review the following information to ensure the GNU Lesser | |
7178 | -** General Public License version 2.1 requirements will be met: | |
7179 | -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
7180 | -** | |
7181 | -** In addition, as a special exception, Nokia gives you certain additional | |
7182 | -** rights. These rights are described in the Nokia Qt LGPL Exception | |
7183 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
7184 | -** | |
7185 | -** GNU General Public License Usage | |
7186 | -** Alternatively, this file may be used under the terms of the GNU General | |
7187 | -** Public License version 3.0 as published by the Free Software Foundation | |
7188 | -** and appearing in the file LICENSE.GPL included in the packaging of this | |
7189 | -** file. Please review the following information to ensure the GNU General | |
7190 | -** Public License version 3.0 requirements will be met: | |
7191 | -** http://www.gnu.org/copyleft/gpl.html. | |
7192 | -** | |
7193 | -** Other Usage | |
7194 | -** Alternatively, this file may be used in accordance with the terms and | |
7195 | -** conditions contained in a signed written agreement between you and Nokia. | |
7196 | -** | |
7197 | -** | |
7198 | -** | |
7199 | -** | |
7200 | -** | |
7201 | -** | |
7202 | -** $QT_END_LICENSE$ | |
7203 | -** | |
7204 | -****************************************************************************/ | |
7205 | - | |
7206 | -#ifndef QSAVEFILE_P_H | |
7207 | -#define QSAVEFILE_P_H | |
7208 | - | |
7209 | -// | |
7210 | -// W A R N I N G | |
7211 | -// ------------- | |
7212 | -// | |
7213 | -// This file is not part of the Qt API. It exists purely as an | |
7214 | -// implementation detail. This header file may change from version to | |
7215 | -// version without notice, or even be removed. | |
7216 | -// | |
7217 | -// We mean it. | |
7218 | -// | |
7219 | - | |
7220 | -#include <QTemporaryFile> | |
7221 | - | |
7222 | -class QSaveFilePrivate | |
7223 | -{ | |
7224 | -public: | |
7225 | - QSaveFilePrivate(); | |
7226 | - ~QSaveFilePrivate(); | |
7227 | - | |
7228 | - QString fileName; | |
7229 | - QTemporaryFile *tempFile; | |
7230 | - | |
7231 | - QFile::FileError error; | |
7232 | -}; | |
7233 | - | |
7234 | -#endif // QSAVEFILE_P_H | |
7235 | - | |
7236 | diff --git a/src/crypto/Crypto.cpp b/src/crypto/Crypto.cpp | |
7237 | index 40ec7ea..1ff6fde 100644 | |
7238 | --- a/src/crypto/Crypto.cpp | |
7239 | +++ b/src/crypto/Crypto.cpp | |
7240 | @@ -29,43 +29,6 @@ bool Crypto::m_initalized(false); | |
7241 | QString Crypto::m_errorStr; | |
7242 | QString Crypto::m_backendVersion; | |
7243 | ||
7244 | -#if !defined(GCRYPT_VERSION_NUMBER) || (GCRYPT_VERSION_NUMBER < 0x010600) | |
7245 | -static int gcry_qt_mutex_init(void** p_sys) | |
7246 | -{ | |
7247 | - *p_sys = new QMutex(); | |
7248 | - return 0; | |
7249 | -} | |
7250 | - | |
7251 | -static int gcry_qt_mutex_destroy(void** p_sys) | |
7252 | -{ | |
7253 | - delete reinterpret_cast<QMutex*>(*p_sys); | |
7254 | - return 0; | |
7255 | -} | |
7256 | - | |
7257 | -static int gcry_qt_mutex_lock(void** p_sys) | |
7258 | -{ | |
7259 | - reinterpret_cast<QMutex*>(*p_sys)->lock(); | |
7260 | - return 0; | |
7261 | -} | |
7262 | - | |
7263 | -static int gcry_qt_mutex_unlock(void** p_sys) | |
7264 | -{ | |
7265 | - reinterpret_cast<QMutex*>(*p_sys)->unlock(); | |
7266 | - return 0; | |
7267 | -} | |
7268 | - | |
7269 | -static const struct gcry_thread_cbs gcry_threads_qt = | |
7270 | -{ | |
7271 | - GCRY_THREAD_OPTION_USER, | |
7272 | - 0, | |
7273 | - gcry_qt_mutex_init, | |
7274 | - gcry_qt_mutex_destroy, | |
7275 | - gcry_qt_mutex_lock, | |
7276 | - gcry_qt_mutex_unlock, | |
7277 | - 0, 0, 0, 0, 0, 0, 0, 0 | |
7278 | -}; | |
7279 | -#endif | |
7280 | - | |
7281 | Crypto::Crypto() | |
7282 | { | |
7283 | } | |
7284 | @@ -77,10 +40,6 @@ bool Crypto::init() | |
7285 | return true; | |
7286 | } | |
7287 | ||
7288 | - // libgcrypt >= 1.6 doesn't allow custom thread callbacks anymore. | |
7289 | -#if !defined(GCRYPT_VERSION_NUMBER) || (GCRYPT_VERSION_NUMBER < 0x010600) | |
7290 | - gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_qt); | |
7291 | -#endif | |
7292 | m_backendVersion = QString::fromLocal8Bit(gcry_check_version(0)); | |
7293 | gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); | |
7294 | ||
7295 | @@ -121,18 +80,18 @@ bool Crypto::backendSelfTest() | |
7296 | ||
7297 | bool Crypto::checkAlgorithms() | |
7298 | { | |
7299 | - if (gcry_cipher_algo_info(GCRY_CIPHER_AES256, GCRYCTL_TEST_ALGO, Q_NULLPTR, Q_NULLPTR) != 0) { | |
7300 | + if (gcry_cipher_algo_info(GCRY_CIPHER_AES256, GCRYCTL_TEST_ALGO, nullptr, nullptr) != 0) { | |
7301 | m_errorStr = "GCRY_CIPHER_AES256 not found."; | |
7302 | qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr)); | |
7303 | return false; | |
7304 | } | |
7305 | - if (gcry_cipher_algo_info(GCRY_CIPHER_TWOFISH, GCRYCTL_TEST_ALGO, Q_NULLPTR, Q_NULLPTR) != 0) { | |
7306 | + if (gcry_cipher_algo_info(GCRY_CIPHER_TWOFISH, GCRYCTL_TEST_ALGO, nullptr, nullptr) != 0) { | |
7307 | m_errorStr = "GCRY_CIPHER_TWOFISH not found."; | |
7308 | qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr)); | |
7309 | return false; | |
7310 | } | |
7311 | #ifdef GCRYPT_HAS_SALSA20 | |
7312 | - if (gcry_cipher_algo_info(GCRY_CIPHER_SALSA20, GCRYCTL_TEST_ALGO, Q_NULLPTR, Q_NULLPTR) != 0) { | |
7313 | + if (gcry_cipher_algo_info(GCRY_CIPHER_SALSA20, GCRYCTL_TEST_ALGO, nullptr, nullptr) != 0) { | |
7314 | m_errorStr = "GCRY_CIPHER_SALSA20 not found."; | |
7315 | qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr)); | |
7316 | return false; | |
7317 | diff --git a/src/crypto/Crypto.h b/src/crypto/Crypto.h | |
7318 | index 1726865..0ce2903 100644 | |
7319 | --- a/src/crypto/Crypto.h | |
7320 | +++ b/src/crypto/Crypto.h | |
7321 | @@ -20,8 +20,6 @@ | |
7322 | ||
7323 | #include <QString> | |
7324 | ||
7325 | -#include "core/Global.h" | |
7326 | - | |
7327 | class Crypto | |
7328 | { | |
7329 | public: | |
7330 | diff --git a/src/crypto/Random.cpp b/src/crypto/Random.cpp | |
7331 | index 2a375f3..dc0667f 100644 | |
7332 | --- a/src/crypto/Random.cpp | |
7333 | +++ b/src/crypto/Random.cpp | |
7334 | @@ -19,15 +19,16 @@ | |
7335 | ||
7336 | #include <gcrypt.h> | |
7337 | ||
7338 | +#include "core/Global.h" | |
7339 | #include "crypto/Crypto.h" | |
7340 | ||
7341 | class RandomBackendGcrypt : public RandomBackend | |
7342 | { | |
7343 | public: | |
7344 | - void randomize(void* data, int len) Q_DECL_OVERRIDE; | |
7345 | + void randomize(void* data, int len) override; | |
7346 | }; | |
7347 | ||
7348 | -Random* Random::m_instance(Q_NULLPTR); | |
7349 | +Random* Random::m_instance(nullptr); | |
7350 | ||
7351 | void Random::randomize(QByteArray& ba) | |
7352 | { | |
7353 | diff --git a/src/crypto/SymmetricCipher.cpp b/src/crypto/SymmetricCipher.cpp | |
7354 | index 454548c..12ec264 100644 | |
7355 | --- a/src/crypto/SymmetricCipher.cpp | |
7356 | +++ b/src/crypto/SymmetricCipher.cpp | |
7357 | @@ -19,7 +19,6 @@ | |
7358 | ||
7359 | #include "config-keepassx.h" | |
7360 | #include "crypto/SymmetricCipherGcrypt.h" | |
7361 | -#include "crypto/SymmetricCipherSalsa20.h" | |
7362 | ||
7363 | SymmetricCipher::SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode, | |
7364 | SymmetricCipher::Direction direction) | |
7365 | @@ -61,19 +60,12 @@ SymmetricCipherBackend* SymmetricCipher::createBackend(SymmetricCipher::Algorith | |
7366 | switch (algo) { | |
7367 | case SymmetricCipher::Aes256: | |
7368 | case SymmetricCipher::Twofish: | |
7369 | -#if defined(GCRYPT_HAS_SALSA20) | |
7370 | case SymmetricCipher::Salsa20: | |
7371 | -#endif | |
7372 | return new SymmetricCipherGcrypt(algo, mode, direction); | |
7373 | ||
7374 | -#if !defined(GCRYPT_HAS_SALSA20) | |
7375 | - case SymmetricCipher::Salsa20: | |
7376 | - return new SymmetricCipherSalsa20(algo, mode, direction); | |
7377 | -#endif | |
7378 | - | |
7379 | default: | |
7380 | Q_ASSERT(false); | |
7381 | - return Q_NULLPTR; | |
7382 | + return nullptr; | |
7383 | } | |
7384 | } | |
7385 | ||
7386 | diff --git a/src/crypto/SymmetricCipher.h b/src/crypto/SymmetricCipher.h | |
7387 | index b8b3eb1..4fc06b7 100644 | |
7388 | --- a/src/crypto/SymmetricCipher.h | |
7389 | +++ b/src/crypto/SymmetricCipher.h | |
7390 | @@ -22,7 +22,6 @@ | |
7391 | #include <QScopedPointer> | |
7392 | #include <QString> | |
7393 | ||
7394 | -#include "core/Global.h" | |
7395 | #include "crypto/SymmetricCipherBackend.h" | |
7396 | ||
7397 | class SymmetricCipher | |
7398 | diff --git a/src/crypto/SymmetricCipherGcrypt.cpp b/src/crypto/SymmetricCipherGcrypt.cpp | |
7399 | index 5c4fe6a..cd43240 100644 | |
7400 | --- a/src/crypto/SymmetricCipherGcrypt.cpp | |
7401 | +++ b/src/crypto/SymmetricCipherGcrypt.cpp | |
7402 | @@ -22,7 +22,7 @@ | |
7403 | ||
7404 | SymmetricCipherGcrypt::SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode, | |
7405 | SymmetricCipher::Direction direction) | |
7406 | - : m_ctx(Q_NULLPTR) | |
7407 | + : m_ctx(nullptr) | |
7408 | , m_algo(gcryptAlgo(algo)) | |
7409 | , m_mode(gcryptMode(mode)) | |
7410 | , m_direction(direction) | |
7411 | @@ -44,10 +44,8 @@ int SymmetricCipherGcrypt::gcryptAlgo(SymmetricCipher::Algorithm algo) | |
7412 | case SymmetricCipher::Twofish: | |
7413 | return GCRY_CIPHER_TWOFISH; | |
7414 | ||
7415 | -#ifdef GCRYPT_HAS_SALSA20 | |
7416 | case SymmetricCipher::Salsa20: | |
7417 | return GCRY_CIPHER_SALSA20; | |
7418 | -#endif | |
7419 | ||
7420 | default: | |
7421 | Q_ASSERT(false); | |
7422 | @@ -95,7 +93,7 @@ bool SymmetricCipherGcrypt::init() | |
7423 | } | |
7424 | ||
7425 | size_t blockSizeT; | |
7426 | - error = gcry_cipher_algo_info(m_algo, GCRYCTL_GET_BLKLEN, Q_NULLPTR, &blockSizeT); | |
7427 | + error = gcry_cipher_algo_info(m_algo, GCRYCTL_GET_BLKLEN, nullptr, &blockSizeT); | |
7428 | if (error != 0) { | |
7429 | setErrorString(error); | |
7430 | return false; | |
7431 | @@ -163,10 +161,10 @@ bool SymmetricCipherGcrypt::processInPlace(QByteArray& data) | |
7432 | gcry_error_t error; | |
7433 | ||
7434 | if (m_direction == SymmetricCipher::Decrypt) { | |
7435 | - error = gcry_cipher_decrypt(m_ctx, data.data(), data.size(), Q_NULLPTR, 0); | |
7436 | + error = gcry_cipher_decrypt(m_ctx, data.data(), data.size(), nullptr, 0); | |
7437 | } | |
7438 | else { | |
7439 | - error = gcry_cipher_encrypt(m_ctx, data.data(), data.size(), Q_NULLPTR, 0); | |
7440 | + error = gcry_cipher_encrypt(m_ctx, data.data(), data.size(), nullptr, 0); | |
7441 | } | |
7442 | ||
7443 | if (error != 0) { | |
7444 | @@ -188,7 +186,7 @@ bool SymmetricCipherGcrypt::processInPlace(QByteArray& data, quint64 rounds) | |
7445 | ||
7446 | if (m_direction == SymmetricCipher::Decrypt) { | |
7447 | for (quint64 i = 0; i != rounds; ++i) { | |
7448 | - error = gcry_cipher_decrypt(m_ctx, rawData, size, Q_NULLPTR, 0); | |
7449 | + error = gcry_cipher_decrypt(m_ctx, rawData, size, nullptr, 0); | |
7450 | ||
7451 | if (error != 0) { | |
7452 | setErrorString(error); | |
7453 | @@ -198,7 +196,7 @@ bool SymmetricCipherGcrypt::processInPlace(QByteArray& data, quint64 rounds) | |
7454 | } | |
7455 | else { | |
7456 | for (quint64 i = 0; i != rounds; ++i) { | |
7457 | - error = gcry_cipher_encrypt(m_ctx, rawData, size, Q_NULLPTR, 0); | |
7458 | + error = gcry_cipher_encrypt(m_ctx, rawData, size, nullptr, 0); | |
7459 | ||
7460 | if (error != 0) { | |
7461 | setErrorString(error); | |
7462 | diff --git a/src/crypto/salsa20/ecrypt-config.h b/src/crypto/salsa20/ecrypt-config.h | |
7463 | deleted file mode 100644 | |
7464 | index 0914fbc..0000000 | |
7465 | --- a/src/crypto/salsa20/ecrypt-config.h | |
7466 | +++ /dev/null | |
7467 | @@ -1,260 +0,0 @@ | |
7468 | -/* ecrypt-config.h */ | |
7469 | - | |
7470 | -/* *** Normally, it should not be necessary to edit this file. *** */ | |
7471 | - | |
7472 | -#ifndef ECRYPT_CONFIG | |
7473 | -#define ECRYPT_CONFIG | |
7474 | - | |
7475 | -/* ------------------------------------------------------------------------- */ | |
7476 | - | |
7477 | -/* Guess the endianness of the target architecture. */ | |
7478 | - | |
7479 | -#include <QtGlobal> | |
7480 | - | |
7481 | -#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN | |
7482 | -#define ECRYPT_LITTLE_ENDIAN | |
7483 | -#elif Q_BYTE_ORDER == Q_BIG_ENDIAN | |
7484 | -#define ECRYPT_BIG_ENDIAN | |
7485 | -#else | |
7486 | -#define ECRYPT_UNKNOWN | |
7487 | -#endif | |
7488 | - | |
7489 | -/* ------------------------------------------------------------------------- */ | |
7490 | - | |
7491 | -/* | |
7492 | - * Find minimal-width types to store 8-bit, 16-bit, 32-bit, and 64-bit | |
7493 | - * integers. | |
7494 | - * | |
7495 | - * Note: to enable 64-bit types on 32-bit compilers, it might be | |
7496 | - * necessary to switch from ISO C90 mode to ISO C99 mode (e.g., gcc | |
7497 | - * -std=c99), or to allow compiler-specific extensions. | |
7498 | - */ | |
7499 | - | |
7500 | -#include <limits.h> | |
7501 | - | |
7502 | -/* --- check char --- */ | |
7503 | - | |
7504 | -#if (UCHAR_MAX / 0xFU > 0xFU) | |
7505 | -#ifndef I8T | |
7506 | -#define I8T char | |
7507 | -#define U8C(v) (v##U) | |
7508 | - | |
7509 | -#if (UCHAR_MAX == 0xFFU) | |
7510 | -#define ECRYPT_I8T_IS_BYTE | |
7511 | -#endif | |
7512 | - | |
7513 | -#endif | |
7514 | - | |
7515 | -#if (UCHAR_MAX / 0xFFU > 0xFFU) | |
7516 | -#ifndef I16T | |
7517 | -#define I16T char | |
7518 | -#define U16C(v) (v##U) | |
7519 | -#endif | |
7520 | - | |
7521 | -#if (UCHAR_MAX / 0xFFFFU > 0xFFFFU) | |
7522 | -#ifndef I32T | |
7523 | -#define I32T char | |
7524 | -#define U32C(v) (v##U) | |
7525 | -#endif | |
7526 | - | |
7527 | -#if (UCHAR_MAX / 0xFFFFFFFFU > 0xFFFFFFFFU) | |
7528 | -#ifndef I64T | |
7529 | -#define I64T char | |
7530 | -#define U64C(v) (v##U) | |
7531 | -#define ECRYPT_NATIVE64 | |
7532 | -#endif | |
7533 | - | |
7534 | -#endif | |
7535 | -#endif | |
7536 | -#endif | |
7537 | -#endif | |
7538 | - | |
7539 | -/* --- check short --- */ | |
7540 | - | |
7541 | -#if (USHRT_MAX / 0xFU > 0xFU) | |
7542 | -#ifndef I8T | |
7543 | -#define I8T short | |
7544 | -#define U8C(v) (v##U) | |
7545 | - | |
7546 | -#if (USHRT_MAX == 0xFFU) | |
7547 | -#define ECRYPT_I8T_IS_BYTE | |
7548 | -#endif | |
7549 | - | |
7550 | -#endif | |
7551 | - | |
7552 | -#if (USHRT_MAX / 0xFFU > 0xFFU) | |
7553 | -#ifndef I16T | |
7554 | -#define I16T short | |
7555 | -#define U16C(v) (v##U) | |
7556 | -#endif | |
7557 | - | |
7558 | -#if (USHRT_MAX / 0xFFFFU > 0xFFFFU) | |
7559 | -#ifndef I32T | |
7560 | -#define I32T short | |
7561 | -#define U32C(v) (v##U) | |
7562 | -#endif | |
7563 | - | |
7564 | -#if (USHRT_MAX / 0xFFFFFFFFU > 0xFFFFFFFFU) | |
7565 | -#ifndef I64T | |
7566 | -#define I64T short | |
7567 | -#define U64C(v) (v##U) | |
7568 | -#define ECRYPT_NATIVE64 | |
7569 | -#endif | |
7570 | - | |
7571 | -#endif | |
7572 | -#endif | |
7573 | -#endif | |
7574 | -#endif | |
7575 | - | |
7576 | -/* --- check int --- */ | |
7577 | - | |
7578 | -#if (UINT_MAX / 0xFU > 0xFU) | |
7579 | -#ifndef I8T | |
7580 | -#define I8T int | |
7581 | -#define U8C(v) (v##U) | |
7582 | - | |
7583 | -#if (ULONG_MAX == 0xFFU) | |
7584 | -#define ECRYPT_I8T_IS_BYTE | |
7585 | -#endif | |
7586 | - | |
7587 | -#endif | |
7588 | - | |
7589 | -#if (UINT_MAX / 0xFFU > 0xFFU) | |
7590 | -#ifndef I16T | |
7591 | -#define I16T int | |
7592 | -#define U16C(v) (v##U) | |
7593 | -#endif | |
7594 | - | |
7595 | -#if (UINT_MAX / 0xFFFFU > 0xFFFFU) | |
7596 | -#ifndef I32T | |
7597 | -#define I32T int | |
7598 | -#define U32C(v) (v##U) | |
7599 | -#endif | |
7600 | - | |
7601 | -#if (UINT_MAX / 0xFFFFFFFFU > 0xFFFFFFFFU) | |
7602 | -#ifndef I64T | |
7603 | -#define I64T int | |
7604 | -#define U64C(v) (v##U) | |
7605 | -#define ECRYPT_NATIVE64 | |
7606 | -#endif | |
7607 | - | |
7608 | -#endif | |
7609 | -#endif | |
7610 | -#endif | |
7611 | -#endif | |
7612 | - | |
7613 | -/* --- check long --- */ | |
7614 | - | |
7615 | -#if (ULONG_MAX / 0xFUL > 0xFUL) | |
7616 | -#ifndef I8T | |
7617 | -#define I8T long | |
7618 | -#define U8C(v) (v##UL) | |
7619 | - | |
7620 | -#if (ULONG_MAX == 0xFFUL) | |
7621 | -#define ECRYPT_I8T_IS_BYTE | |
7622 | -#endif | |
7623 | - | |
7624 | -#endif | |
7625 | - | |
7626 | -#if (ULONG_MAX / 0xFFUL > 0xFFUL) | |
7627 | -#ifndef I16T | |
7628 | -#define I16T long | |
7629 | -#define U16C(v) (v##UL) | |
7630 | -#endif | |
7631 | - | |
7632 | -#if (ULONG_MAX / 0xFFFFUL > 0xFFFFUL) | |
7633 | -#ifndef I32T | |
7634 | -#define I32T long | |
7635 | -#define U32C(v) (v##UL) | |
7636 | -#endif | |
7637 | - | |
7638 | -#if (ULONG_MAX / 0xFFFFFFFFUL > 0xFFFFFFFFUL) | |
7639 | -#ifndef I64T | |
7640 | -#define I64T long | |
7641 | -#define U64C(v) (v##UL) | |
7642 | -#define ECRYPT_NATIVE64 | |
7643 | -#endif | |
7644 | - | |
7645 | -#endif | |
7646 | -#endif | |
7647 | -#endif | |
7648 | -#endif | |
7649 | - | |
7650 | -/* --- check long long --- */ | |
7651 | - | |
7652 | -#ifdef ULLONG_MAX | |
7653 | - | |
7654 | -#if (ULLONG_MAX / 0xFULL > 0xFULL) | |
7655 | -#ifndef I8T | |
7656 | -#define I8T long long | |
7657 | -#define U8C(v) (v##ULL) | |
7658 | - | |
7659 | -#if (ULLONG_MAX == 0xFFULL) | |
7660 | -#define ECRYPT_I8T_IS_BYTE | |
7661 | -#endif | |
7662 | - | |
7663 | -#endif | |
7664 | - | |
7665 | -#if (ULLONG_MAX / 0xFFULL > 0xFFULL) | |
7666 | -#ifndef I16T | |
7667 | -#define I16T long long | |
7668 | -#define U16C(v) (v##ULL) | |
7669 | -#endif | |
7670 | - | |
7671 | -#if (ULLONG_MAX / 0xFFFFULL > 0xFFFFULL) | |
7672 | -#ifndef I32T | |
7673 | -#define I32T long long | |
7674 | -#define U32C(v) (v##ULL) | |
7675 | -#endif | |
7676 | - | |
7677 | -#if (ULLONG_MAX / 0xFFFFFFFFULL > 0xFFFFFFFFULL) | |
7678 | -#ifndef I64T | |
7679 | -#define I64T long long | |
7680 | -#define U64C(v) (v##ULL) | |
7681 | -#endif | |
7682 | - | |
7683 | -#endif | |
7684 | -#endif | |
7685 | -#endif | |
7686 | -#endif | |
7687 | - | |
7688 | -#endif | |
7689 | - | |
7690 | -/* --- check __int64 --- */ | |
7691 | - | |
7692 | -#if !defined(__STDC__) && defined(_UI64_MAX) | |
7693 | - | |
7694 | -#ifndef I64T | |
7695 | -#define I64T __int64 | |
7696 | -#define U64C(v) (v##ui64) | |
7697 | -#endif | |
7698 | - | |
7699 | -#endif | |
7700 | - | |
7701 | -/* ------------------------------------------------------------------------- */ | |
7702 | - | |
7703 | -/* find the largest type on this platform (used for alignment) */ | |
7704 | - | |
7705 | -#if defined(__SSE__) || (defined(_MSC_VER) && (_MSC_VER >= 1300)) | |
7706 | - | |
7707 | -#include <xmmintrin.h> | |
7708 | -#define MAXT __m128 | |
7709 | - | |
7710 | -#elif defined(__MMX__) | |
7711 | - | |
7712 | -#include <mmintrin.h> | |
7713 | -#define MAXT __m64 | |
7714 | - | |
7715 | -#elif defined(__ALTIVEC__) | |
7716 | - | |
7717 | -#define MAXT __vector int | |
7718 | - | |
7719 | -#else | |
7720 | - | |
7721 | -#define MAXT long | |
7722 | - | |
7723 | -#endif | |
7724 | - | |
7725 | -/* ------------------------------------------------------------------------- */ | |
7726 | - | |
7727 | -#endif | |
7728 | diff --git a/src/crypto/salsa20/ecrypt-machine.h b/src/crypto/salsa20/ecrypt-machine.h | |
7729 | deleted file mode 100644 | |
7730 | index d006bed..0000000 | |
7731 | --- a/src/crypto/salsa20/ecrypt-machine.h | |
7732 | +++ /dev/null | |
7733 | @@ -1,49 +0,0 @@ | |
7734 | -/* ecrypt-machine.h */ | |
7735 | - | |
7736 | -/* | |
7737 | - * This file is included by 'ecrypt-portable.h'. It allows to override | |
7738 | - * the default macros for specific platforms. Please carefully check | |
7739 | - * the machine code generated by your compiler (with optimisations | |
7740 | - * turned on) before deciding to edit this file. | |
7741 | - */ | |
7742 | - | |
7743 | -/* ------------------------------------------------------------------------- */ | |
7744 | - | |
7745 | -#if (defined(ECRYPT_DEFAULT_ROT) && !defined(ECRYPT_MACHINE_ROT)) | |
7746 | - | |
7747 | -#define ECRYPT_MACHINE_ROT | |
7748 | - | |
7749 | -#if (defined(WIN32) && defined(_MSC_VER)) | |
7750 | - | |
7751 | -#undef ROTL32 | |
7752 | -#undef ROTR32 | |
7753 | -#undef ROTL64 | |
7754 | -#undef ROTR64 | |
7755 | - | |
7756 | -#include <stdlib.h> | |
7757 | - | |
7758 | -#pragma intrinsic(_lrotl) /* compile rotations "inline" */ | |
7759 | -#pragma intrinsic(_lrotr) | |
7760 | - | |
7761 | -#define ROTL32(v, n) _lrotl(v, n) | |
7762 | -#define ROTR32(v, n) _lrotr(v, n) | |
7763 | -#define ROTL64(v, n) _rotl64(v, n) | |
7764 | -#define ROTR64(v, n) _rotr64(v, n) | |
7765 | - | |
7766 | -#endif | |
7767 | - | |
7768 | -#endif | |
7769 | - | |
7770 | -/* ------------------------------------------------------------------------- */ | |
7771 | - | |
7772 | -#if (defined(ECRYPT_DEFAULT_SWAP) && !defined(ECRYPT_MACHINE_SWAP)) | |
7773 | - | |
7774 | -#define ECRYPT_MACHINE_SWAP | |
7775 | - | |
7776 | -/* | |
7777 | - * If you want to overwrite the default swap macros, put it here. And so on. | |
7778 | - */ | |
7779 | - | |
7780 | -#endif | |
7781 | - | |
7782 | -/* ------------------------------------------------------------------------- */ | |
7783 | diff --git a/src/crypto/salsa20/ecrypt-portable.h b/src/crypto/salsa20/ecrypt-portable.h | |
7784 | deleted file mode 100644 | |
7785 | index 438a464..0000000 | |
7786 | --- a/src/crypto/salsa20/ecrypt-portable.h | |
7787 | +++ /dev/null | |
7788 | @@ -1,310 +0,0 @@ | |
7789 | -/* ecrypt-portable.h */ | |
7790 | - | |
7791 | -/* | |
7792 | - * WARNING: the conversions defined below are implemented as macros, | |
7793 | - * and should be used carefully. They should NOT be used with | |
7794 | - * parameters which perform some action. E.g., the following two lines | |
7795 | - * are not equivalent: | |
7796 | - * | |
7797 | - * 1) ++x; y = ROTL32(x, n); | |
7798 | - * 2) y = ROTL32(++x, n); | |
7799 | - */ | |
7800 | - | |
7801 | -/* | |
7802 | - * *** Please do not edit this file. *** | |
7803 | - * | |
7804 | - * The default macros can be overridden for specific architectures by | |
7805 | - * editing 'ecrypt-machine.h'. | |
7806 | - */ | |
7807 | - | |
7808 | -#ifndef ECRYPT_PORTABLE | |
7809 | -#define ECRYPT_PORTABLE | |
7810 | - | |
7811 | -#include "ecrypt-config.h" | |
7812 | - | |
7813 | -/* ------------------------------------------------------------------------- */ | |
7814 | - | |
7815 | -/* | |
7816 | - * The following types are defined (if available): | |
7817 | - * | |
7818 | - * u8: unsigned integer type, at least 8 bits | |
7819 | - * u16: unsigned integer type, at least 16 bits | |
7820 | - * u32: unsigned integer type, at least 32 bits | |
7821 | - * u64: unsigned integer type, at least 64 bits | |
7822 | - * | |
7823 | - * s8, s16, s32, s64 -> signed counterparts of u8, u16, u32, u64 | |
7824 | - * | |
7825 | - * The selection of minimum-width integer types is taken care of by | |
7826 | - * 'ecrypt-config.h'. Note: to enable 64-bit types on 32-bit | |
7827 | - * compilers, it might be necessary to switch from ISO C90 mode to ISO | |
7828 | - * C99 mode (e.g., gcc -std=c99). | |
7829 | - */ | |
7830 | - | |
7831 | -#ifdef I8T | |
7832 | -typedef signed I8T s8; | |
7833 | -typedef unsigned I8T u8; | |
7834 | -#endif | |
7835 | - | |
7836 | -#ifdef I16T | |
7837 | -typedef signed I16T s16; | |
7838 | -typedef unsigned I16T u16; | |
7839 | -#endif | |
7840 | - | |
7841 | -#ifdef I32T | |
7842 | -typedef signed I32T s32; | |
7843 | -typedef unsigned I32T u32; | |
7844 | -#endif | |
7845 | - | |
7846 | -#ifdef I64T | |
7847 | -typedef signed I64T s64; | |
7848 | -typedef unsigned I64T u64; | |
7849 | -#endif | |
7850 | - | |
7851 | -/* | |
7852 | - * The following macros are used to obtain exact-width results. | |
7853 | - */ | |
7854 | - | |
7855 | -#define U8V(v) ((u8)(v) & U8C(0xFF)) | |
7856 | -#define U16V(v) ((u16)(v) & U16C(0xFFFF)) | |
7857 | -#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF)) | |
7858 | -#define U64V(v) ((u64)(v) & U64C(0xFFFFFFFFFFFFFFFF)) | |
7859 | - | |
7860 | -/* ------------------------------------------------------------------------- */ | |
7861 | - | |
7862 | -/* | |
7863 | - * The following macros return words with their bits rotated over n | |
7864 | - * positions to the left/right. | |
7865 | - */ | |
7866 | - | |
7867 | -#define ECRYPT_DEFAULT_ROT | |
7868 | - | |
7869 | -#define ROTL8(v, n) \ | |
7870 | - (U8V((v) << (n)) | ((v) >> (8 - (n)))) | |
7871 | - | |
7872 | -#define ROTL16(v, n) \ | |
7873 | - (U16V((v) << (n)) | ((v) >> (16 - (n)))) | |
7874 | - | |
7875 | -#define ROTL32(v, n) \ | |
7876 | - (U32V((v) << (n)) | ((v) >> (32 - (n)))) | |
7877 | - | |
7878 | -#define ROTL64(v, n) \ | |
7879 | - (U64V((v) << (n)) | ((v) >> (64 - (n)))) | |
7880 | - | |
7881 | -#define ROTR8(v, n) ROTL8(v, 8 - (n)) | |
7882 | -#define ROTR16(v, n) ROTL16(v, 16 - (n)) | |
7883 | -#define ROTR32(v, n) ROTL32(v, 32 - (n)) | |
7884 | -#define ROTR64(v, n) ROTL64(v, 64 - (n)) | |
7885 | - | |
7886 | -#include "ecrypt-machine.h" | |
7887 | - | |
7888 | -/* ------------------------------------------------------------------------- */ | |
7889 | - | |
7890 | -/* | |
7891 | - * The following macros return a word with bytes in reverse order. | |
7892 | - */ | |
7893 | - | |
7894 | -#define ECRYPT_DEFAULT_SWAP | |
7895 | - | |
7896 | -#define SWAP16(v) \ | |
7897 | - ROTL16(v, 8) | |
7898 | - | |
7899 | -#define SWAP32(v) \ | |
7900 | - ((ROTL32(v, 8) & U32C(0x00FF00FF)) | \ | |
7901 | - (ROTL32(v, 24) & U32C(0xFF00FF00))) | |
7902 | - | |
7903 | -#ifdef ECRYPT_NATIVE64 | |
7904 | -#define SWAP64(v) \ | |
7905 | - ((ROTL64(v, 8) & U64C(0x000000FF000000FF)) | \ | |
7906 | - (ROTL64(v, 24) & U64C(0x0000FF000000FF00)) | \ | |
7907 | - (ROTL64(v, 40) & U64C(0x00FF000000FF0000)) | \ | |
7908 | - (ROTL64(v, 56) & U64C(0xFF000000FF000000))) | |
7909 | -#else | |
7910 | -#define SWAP64(v) \ | |
7911 | - (((u64)SWAP32(U32V(v)) << 32) | (u64)SWAP32(U32V(v >> 32))) | |
7912 | -#endif | |
7913 | - | |
7914 | -#include "ecrypt-machine.h" | |
7915 | - | |
7916 | -#define ECRYPT_DEFAULT_WTOW | |
7917 | - | |
7918 | -#ifdef ECRYPT_LITTLE_ENDIAN | |
7919 | -#define U16TO16_LITTLE(v) (v) | |
7920 | -#define U32TO32_LITTLE(v) (v) | |
7921 | -#define U64TO64_LITTLE(v) (v) | |
7922 | - | |
7923 | -#define U16TO16_BIG(v) SWAP16(v) | |
7924 | -#define U32TO32_BIG(v) SWAP32(v) | |
7925 | -#define U64TO64_BIG(v) SWAP64(v) | |
7926 | -#endif | |
7927 | - | |
7928 | -#ifdef ECRYPT_BIG_ENDIAN | |
7929 | -#define U16TO16_LITTLE(v) SWAP16(v) | |
7930 | -#define U32TO32_LITTLE(v) SWAP32(v) | |
7931 | -#define U64TO64_LITTLE(v) SWAP64(v) | |
7932 | - | |
7933 | -#define U16TO16_BIG(v) (v) | |
7934 | -#define U32TO32_BIG(v) (v) | |
7935 | -#define U64TO64_BIG(v) (v) | |
7936 | -#endif | |
7937 | - | |
7938 | -#include "ecrypt-machine.h" | |
7939 | - | |
7940 | -/* | |
7941 | - * The following macros load words from an array of bytes with | |
7942 | - * different types of endianness, and vice versa. | |
7943 | - */ | |
7944 | - | |
7945 | -#define ECRYPT_DEFAULT_BTOW | |
7946 | - | |
7947 | -#if (!defined(ECRYPT_UNKNOWN) && defined(ECRYPT_I8T_IS_BYTE)) | |
7948 | - | |
7949 | -#define U8TO16_LITTLE(p) U16TO16_LITTLE(((u16*)(p))[0]) | |
7950 | -#define U8TO32_LITTLE(p) U32TO32_LITTLE(((u32*)(p))[0]) | |
7951 | -#define U8TO64_LITTLE(p) U64TO64_LITTLE(((u64*)(p))[0]) | |
7952 | - | |
7953 | -#define U8TO16_BIG(p) U16TO16_BIG(((u16*)(p))[0]) | |
7954 | -#define U8TO32_BIG(p) U32TO32_BIG(((u32*)(p))[0]) | |
7955 | -#define U8TO64_BIG(p) U64TO64_BIG(((u64*)(p))[0]) | |
7956 | - | |
7957 | -#define U16TO8_LITTLE(p, v) (((u16*)(p))[0] = U16TO16_LITTLE(v)) | |
7958 | -#define U32TO8_LITTLE(p, v) (((u32*)(p))[0] = U32TO32_LITTLE(v)) | |
7959 | -#define U64TO8_LITTLE(p, v) (((u64*)(p))[0] = U64TO64_LITTLE(v)) | |
7960 | - | |
7961 | -#define U16TO8_BIG(p, v) (((u16*)(p))[0] = U16TO16_BIG(v)) | |
7962 | -#define U32TO8_BIG(p, v) (((u32*)(p))[0] = U32TO32_BIG(v)) | |
7963 | -#define U64TO8_BIG(p, v) (((u64*)(p))[0] = U64TO64_BIG(v)) | |
7964 | - | |
7965 | -#else | |
7966 | - | |
7967 | -#define U8TO16_LITTLE(p) \ | |
7968 | - (((u16)((p)[0]) ) | \ | |
7969 | - ((u16)((p)[1]) << 8)) | |
7970 | - | |
7971 | -#define U8TO32_LITTLE(p) \ | |
7972 | - (((u32)((p)[0]) ) | \ | |
7973 | - ((u32)((p)[1]) << 8) | \ | |
7974 | - ((u32)((p)[2]) << 16) | \ | |
7975 | - ((u32)((p)[3]) << 24)) | |
7976 | - | |
7977 | -#ifdef ECRYPT_NATIVE64 | |
7978 | -#define U8TO64_LITTLE(p) \ | |
7979 | - (((u64)((p)[0]) ) | \ | |
7980 | - ((u64)((p)[1]) << 8) | \ | |
7981 | - ((u64)((p)[2]) << 16) | \ | |
7982 | - ((u64)((p)[3]) << 24) | \ | |
7983 | - ((u64)((p)[4]) << 32) | \ | |
7984 | - ((u64)((p)[5]) << 40) | \ | |
7985 | - ((u64)((p)[6]) << 48) | \ | |
7986 | - ((u64)((p)[7]) << 56)) | |
7987 | -#else | |
7988 | -#define U8TO64_LITTLE(p) \ | |
7989 | - ((u64)U8TO32_LITTLE(p) | ((u64)U8TO32_LITTLE((p) + 4) << 32)) | |
7990 | -#endif | |
7991 | - | |
7992 | -#define U8TO16_BIG(p) \ | |
7993 | - (((u16)((p)[0]) << 8) | \ | |
7994 | - ((u16)((p)[1]) )) | |
7995 | - | |
7996 | -#define U8TO32_BIG(p) \ | |
7997 | - (((u32)((p)[0]) << 24) | \ | |
7998 | - ((u32)((p)[1]) << 16) | \ | |
7999 | - ((u32)((p)[2]) << 8) | \ | |
8000 | - ((u32)((p)[3]) )) | |
8001 | - | |
8002 | -#ifdef ECRYPT_NATIVE64 | |
8003 | -#define U8TO64_BIG(p) \ | |
8004 | - (((u64)((p)[0]) << 56) | \ | |
8005 | - ((u64)((p)[1]) << 48) | \ | |
8006 | - ((u64)((p)[2]) << 40) | \ | |
8007 | - ((u64)((p)[3]) << 32) | \ | |
8008 | - ((u64)((p)[4]) << 24) | \ | |
8009 | - ((u64)((p)[5]) << 16) | \ | |
8010 | - ((u64)((p)[6]) << 8) | \ | |
8011 | - ((u64)((p)[7]) )) | |
8012 | -#else | |
8013 | -#define U8TO64_BIG(p) \ | |
8014 | - (((u64)U8TO32_BIG(p) << 32) | (u64)U8TO32_BIG((p) + 4)) | |
8015 | -#endif | |
8016 | - | |
8017 | -#define U16TO8_LITTLE(p, v) \ | |
8018 | - do { \ | |
8019 | - (p)[0] = U8V((v) ); \ | |
8020 | - (p)[1] = U8V((v) >> 8); \ | |
8021 | - } while (0) | |
8022 | - | |
8023 | -#define U32TO8_LITTLE(p, v) \ | |
8024 | - do { \ | |
8025 | - (p)[0] = U8V((v) ); \ | |
8026 | - (p)[1] = U8V((v) >> 8); \ | |
8027 | - (p)[2] = U8V((v) >> 16); \ | |
8028 | - (p)[3] = U8V((v) >> 24); \ | |
8029 | - } while (0) | |
8030 | - | |
8031 | -#ifdef ECRYPT_NATIVE64 | |
8032 | -#define U64TO8_LITTLE(p, v) \ | |
8033 | - do { \ | |
8034 | - (p)[0] = U8V((v) ); \ | |
8035 | - (p)[1] = U8V((v) >> 8); \ | |
8036 | - (p)[2] = U8V((v) >> 16); \ | |
8037 | - (p)[3] = U8V((v) >> 24); \ | |
8038 | - (p)[4] = U8V((v) >> 32); \ | |
8039 | - (p)[5] = U8V((v) >> 40); \ | |
8040 | - (p)[6] = U8V((v) >> 48); \ | |
8041 | - (p)[7] = U8V((v) >> 56); \ | |
8042 | - } while (0) | |
8043 | -#else | |
8044 | -#define U64TO8_LITTLE(p, v) \ | |
8045 | - do { \ | |
8046 | - U32TO8_LITTLE((p), U32V((v) )); \ | |
8047 | - U32TO8_LITTLE((p) + 4, U32V((v) >> 32)); \ | |
8048 | - } while (0) | |
8049 | -#endif | |
8050 | - | |
8051 | -#define U16TO8_BIG(p, v) \ | |
8052 | - do { \ | |
8053 | - (p)[0] = U8V((v) ); \ | |
8054 | - (p)[1] = U8V((v) >> 8); \ | |
8055 | - } while (0) | |
8056 | - | |
8057 | -#define U32TO8_BIG(p, v) \ | |
8058 | - do { \ | |
8059 | - (p)[0] = U8V((v) >> 24); \ | |
8060 | - (p)[1] = U8V((v) >> 16); \ | |
8061 | - (p)[2] = U8V((v) >> 8); \ | |
8062 | - (p)[3] = U8V((v) ); \ | |
8063 | - } while (0) | |
8064 | - | |
8065 | -#ifdef ECRYPT_NATIVE64 | |
8066 | -#define U64TO8_BIG(p, v) \ | |
8067 | - do { \ | |
8068 | - (p)[0] = U8V((v) >> 56); \ | |
8069 | - (p)[1] = U8V((v) >> 48); \ | |
8070 | - (p)[2] = U8V((v) >> 40); \ | |
8071 | - (p)[3] = U8V((v) >> 32); \ | |
8072 | - (p)[4] = U8V((v) >> 24); \ | |
8073 | - (p)[5] = U8V((v) >> 16); \ | |
8074 | - (p)[6] = U8V((v) >> 8); \ | |
8075 | - (p)[7] = U8V((v) ); \ | |
8076 | - } while (0) | |
8077 | -#else | |
8078 | -#define U64TO8_BIG(p, v) \ | |
8079 | - do { \ | |
8080 | - U32TO8_BIG((p), U32V((v) >> 32)); \ | |
8081 | - U32TO8_BIG((p) + 4, U32V((v) )); \ | |
8082 | - } while (0) | |
8083 | -#endif | |
8084 | - | |
8085 | -#endif | |
8086 | - | |
8087 | -#include "ecrypt-machine.h" | |
8088 | - | |
8089 | -/* ------------------------------------------------------------------------- */ | |
8090 | - | |
8091 | -#define AT_LEAST_ONE(n) (((n) < 1) ? 1 : (n)) | |
8092 | - | |
8093 | -#define ALIGN(t, v, n) \ | |
8094 | - union { t b[n]; MAXT l[AT_LEAST_ONE(n * sizeof(t) / sizeof(MAXT))]; } v | |
8095 | - | |
8096 | -/* ------------------------------------------------------------------------- */ | |
8097 | - | |
8098 | -#endif | |
8099 | diff --git a/src/crypto/salsa20/ecrypt-sync.h b/src/crypto/salsa20/ecrypt-sync.h | |
8100 | deleted file mode 100644 | |
8101 | index 245793e..0000000 | |
8102 | --- a/src/crypto/salsa20/ecrypt-sync.h | |
8103 | +++ /dev/null | |
8104 | @@ -1,287 +0,0 @@ | |
8105 | -/* ecrypt-sync.h */ | |
8106 | - | |
8107 | -/* | |
8108 | - * Header file for synchronous stream ciphers without authentication | |
8109 | - * mechanism. | |
8110 | - * | |
8111 | - * *** Please only edit parts marked with "[edit]". *** | |
8112 | - */ | |
8113 | - | |
8114 | -#ifndef ECRYPT_SYNC | |
8115 | -#define ECRYPT_SYNC | |
8116 | - | |
8117 | -#ifdef __cplusplus | |
8118 | -extern "C" { | |
8119 | -#endif | |
8120 | - | |
8121 | -#include "ecrypt-portable.h" | |
8122 | - | |
8123 | -/* ------------------------------------------------------------------------- */ | |
8124 | - | |
8125 | -/* Cipher parameters */ | |
8126 | - | |
8127 | -/* | |
8128 | - * The name of your cipher. | |
8129 | - */ | |
8130 | -#define ECRYPT_NAME "Salsa20" /* [edit] */ | |
8131 | -#define ECRYPT_PROFILE "S!_H." | |
8132 | - | |
8133 | -/* | |
8134 | - * Specify which key and IV sizes are supported by your cipher. A user | |
8135 | - * should be able to enumerate the supported sizes by running the | |
8136 | - * following code: | |
8137 | - * | |
8138 | - * for (i = 0; ECRYPT_KEYSIZE(i) <= ECRYPT_MAXKEYSIZE; ++i) | |
8139 | - * { | |
8140 | - * keysize = ECRYPT_KEYSIZE(i); | |
8141 | - * | |
8142 | - * ... | |
8143 | - * } | |
8144 | - * | |
8145 | - * All sizes are in bits. | |
8146 | - */ | |
8147 | - | |
8148 | -#define ECRYPT_MAXKEYSIZE 256 /* [edit] */ | |
8149 | -#define ECRYPT_KEYSIZE(i) (128 + (i)*128) /* [edit] */ | |
8150 | - | |
8151 | -#define ECRYPT_MAXIVSIZE 64 /* [edit] */ | |
8152 | -#define ECRYPT_IVSIZE(i) (64 + (i)*64) /* [edit] */ | |
8153 | - | |
8154 | -/* ------------------------------------------------------------------------- */ | |
8155 | - | |
8156 | -/* Data structures */ | |
8157 | - | |
8158 | -/* | |
8159 | - * ECRYPT_ctx is the structure containing the representation of the | |
8160 | - * internal state of your cipher. | |
8161 | - */ | |
8162 | - | |
8163 | -typedef struct | |
8164 | -{ | |
8165 | - u32 input[16]; /* could be compressed */ | |
8166 | - /* | |
8167 | - * [edit] | |
8168 | - * | |
8169 | - * Put here all state variable needed during the encryption process. | |
8170 | - */ | |
8171 | -} ECRYPT_ctx; | |
8172 | - | |
8173 | -/* ------------------------------------------------------------------------- */ | |
8174 | - | |
8175 | -/* Mandatory functions */ | |
8176 | - | |
8177 | -/* | |
8178 | - * Key and message independent initialization. This function will be | |
8179 | - * called once when the program starts (e.g., to build expanded S-box | |
8180 | - * tables). | |
8181 | - */ | |
8182 | -void ECRYPT_init(); | |
8183 | - | |
8184 | -/* | |
8185 | - * Key setup. It is the user's responsibility to select the values of | |
8186 | - * keysize and ivsize from the set of supported values specified | |
8187 | - * above. | |
8188 | - */ | |
8189 | -void ECRYPT_keysetup( | |
8190 | - ECRYPT_ctx* ctx, | |
8191 | - const u8* key, | |
8192 | - u32 keysize, /* Key size in bits. */ | |
8193 | - u32 ivsize); /* IV size in bits. */ | |
8194 | - | |
8195 | -/* | |
8196 | - * IV setup. After having called ECRYPT_keysetup(), the user is | |
8197 | - * allowed to call ECRYPT_ivsetup() different times in order to | |
8198 | - * encrypt/decrypt different messages with the same key but different | |
8199 | - * IV's. | |
8200 | - */ | |
8201 | -void ECRYPT_ivsetup( | |
8202 | - ECRYPT_ctx* ctx, | |
8203 | - const u8* iv); | |
8204 | - | |
8205 | -/* | |
8206 | - * Encryption/decryption of arbitrary length messages. | |
8207 | - * | |
8208 | - * For efficiency reasons, the API provides two types of | |
8209 | - * encrypt/decrypt functions. The ECRYPT_encrypt_bytes() function | |
8210 | - * (declared here) encrypts byte strings of arbitrary length, while | |
8211 | - * the ECRYPT_encrypt_blocks() function (defined later) only accepts | |
8212 | - * lengths which are multiples of ECRYPT_BLOCKLENGTH. | |
8213 | - * | |
8214 | - * The user is allowed to make multiple calls to | |
8215 | - * ECRYPT_encrypt_blocks() to incrementally encrypt a long message, | |
8216 | - * but he is NOT allowed to make additional encryption calls once he | |
8217 | - * has called ECRYPT_encrypt_bytes() (unless he starts a new message | |
8218 | - * of course). For example, this sequence of calls is acceptable: | |
8219 | - * | |
8220 | - * ECRYPT_keysetup(); | |
8221 | - * | |
8222 | - * ECRYPT_ivsetup(); | |
8223 | - * ECRYPT_encrypt_blocks(); | |
8224 | - * ECRYPT_encrypt_blocks(); | |
8225 | - * ECRYPT_encrypt_bytes(); | |
8226 | - * | |
8227 | - * ECRYPT_ivsetup(); | |
8228 | - * ECRYPT_encrypt_blocks(); | |
8229 | - * ECRYPT_encrypt_blocks(); | |
8230 | - * | |
8231 | - * ECRYPT_ivsetup(); | |
8232 | - * ECRYPT_encrypt_bytes(); | |
8233 | - * | |
8234 | - * The following sequence is not: | |
8235 | - * | |
8236 | - * ECRYPT_keysetup(); | |
8237 | - * ECRYPT_ivsetup(); | |
8238 | - * ECRYPT_encrypt_blocks(); | |
8239 | - * ECRYPT_encrypt_bytes(); | |
8240 | - * ECRYPT_encrypt_blocks(); | |
8241 | - */ | |
8242 | - | |
8243 | -void ECRYPT_encrypt_bytes( | |
8244 | - ECRYPT_ctx* ctx, | |
8245 | - const u8* plaintext, | |
8246 | - u8* ciphertext, | |
8247 | - u32 msglen); /* Message length in bytes. */ | |
8248 | - | |
8249 | -void ECRYPT_decrypt_bytes( | |
8250 | - ECRYPT_ctx* ctx, | |
8251 | - const u8* ciphertext, | |
8252 | - u8* plaintext, | |
8253 | - u32 msglen); /* Message length in bytes. */ | |
8254 | - | |
8255 | -/* ------------------------------------------------------------------------- */ | |
8256 | - | |
8257 | -/* Optional features */ | |
8258 | - | |
8259 | -/* | |
8260 | - * For testing purposes it can sometimes be useful to have a function | |
8261 | - * which immediately generates keystream without having to provide it | |
8262 | - * with a zero plaintext. If your cipher cannot provide this function | |
8263 | - * (e.g., because it is not strictly a synchronous cipher), please | |
8264 | - * reset the ECRYPT_GENERATES_KEYSTREAM flag. | |
8265 | - */ | |
8266 | - | |
8267 | -#define ECRYPT_GENERATES_KEYSTREAM | |
8268 | -#ifdef ECRYPT_GENERATES_KEYSTREAM | |
8269 | - | |
8270 | -void ECRYPT_keystream_bytes( | |
8271 | - ECRYPT_ctx* ctx, | |
8272 | - u8* keystream, | |
8273 | - u32 length); /* Length of keystream in bytes. */ | |
8274 | - | |
8275 | -#endif | |
8276 | - | |
8277 | -/* ------------------------------------------------------------------------- */ | |
8278 | - | |
8279 | -/* Optional optimizations */ | |
8280 | - | |
8281 | -/* | |
8282 | - * By default, the functions in this section are implemented using | |
8283 | - * calls to functions declared above. However, you might want to | |
8284 | - * implement them differently for performance reasons. | |
8285 | - */ | |
8286 | - | |
8287 | -/* | |
8288 | - * All-in-one encryption/decryption of (short) packets. | |
8289 | - * | |
8290 | - * The default definitions of these functions can be found in | |
8291 | - * "ecrypt-sync.c". If you want to implement them differently, please | |
8292 | - * undef the ECRYPT_USES_DEFAULT_ALL_IN_ONE flag. | |
8293 | - */ | |
8294 | -#define ECRYPT_USES_DEFAULT_ALL_IN_ONE /* [edit] */ | |
8295 | - | |
8296 | -void ECRYPT_encrypt_packet( | |
8297 | - ECRYPT_ctx* ctx, | |
8298 | - const u8* iv, | |
8299 | - const u8* plaintext, | |
8300 | - u8* ciphertext, | |
8301 | - u32 msglen); | |
8302 | - | |
8303 | -void ECRYPT_decrypt_packet( | |
8304 | - ECRYPT_ctx* ctx, | |
8305 | - const u8* iv, | |
8306 | - const u8* ciphertext, | |
8307 | - u8* plaintext, | |
8308 | - u32 msglen); | |
8309 | - | |
8310 | -/* | |
8311 | - * Encryption/decryption of blocks. | |
8312 | - * | |
8313 | - * By default, these functions are defined as macros. If you want to | |
8314 | - * provide a different implementation, please undef the | |
8315 | - * ECRYPT_USES_DEFAULT_BLOCK_MACROS flag and implement the functions | |
8316 | - * declared below. | |
8317 | - */ | |
8318 | - | |
8319 | -#define ECRYPT_BLOCKLENGTH 64 /* [edit] */ | |
8320 | - | |
8321 | -#define ECRYPT_USES_DEFAULT_BLOCK_MACROS /* [edit] */ | |
8322 | -#ifdef ECRYPT_USES_DEFAULT_BLOCK_MACROS | |
8323 | - | |
8324 | -#define ECRYPT_encrypt_blocks(ctx, plaintext, ciphertext, blocks) \ | |
8325 | - ECRYPT_encrypt_bytes(ctx, plaintext, ciphertext, \ | |
8326 | - (blocks) * ECRYPT_BLOCKLENGTH) | |
8327 | - | |
8328 | -#define ECRYPT_decrypt_blocks(ctx, ciphertext, plaintext, blocks) \ | |
8329 | - ECRYPT_decrypt_bytes(ctx, ciphertext, plaintext, \ | |
8330 | - (blocks) * ECRYPT_BLOCKLENGTH) | |
8331 | - | |
8332 | -#ifdef ECRYPT_GENERATES_KEYSTREAM | |
8333 | - | |
8334 | -#define ECRYPT_keystream_blocks(ctx, keystream, blocks) \ | |
8335 | - ECRYPT_keystream_bytes(ctx, keystream, \ | |
8336 | - (blocks) * ECRYPT_BLOCKLENGTH) | |
8337 | - | |
8338 | -#endif | |
8339 | - | |
8340 | -#else | |
8341 | - | |
8342 | -void ECRYPT_encrypt_blocks( | |
8343 | - ECRYPT_ctx* ctx, | |
8344 | - const u8* plaintext, | |
8345 | - u8* ciphertext, | |
8346 | - u32 blocks); /* Message length in blocks. */ | |
8347 | - | |
8348 | -void ECRYPT_decrypt_blocks( | |
8349 | - ECRYPT_ctx* ctx, | |
8350 | - const u8* ciphertext, | |
8351 | - u8* plaintext, | |
8352 | - u32 blocks); /* Message length in blocks. */ | |
8353 | - | |
8354 | -#ifdef ECRYPT_GENERATES_KEYSTREAM | |
8355 | - | |
8356 | -void ECRYPT_keystream_blocks( | |
8357 | - ECRYPT_ctx* ctx, | |
8358 | - const u8* keystream, | |
8359 | - u32 blocks); /* Keystream length in blocks. */ | |
8360 | - | |
8361 | -#endif | |
8362 | - | |
8363 | -#endif | |
8364 | - | |
8365 | -/* | |
8366 | - * If your cipher can be implemented in different ways, you can use | |
8367 | - * the ECRYPT_VARIANT parameter to allow the user to choose between | |
8368 | - * them at compile time (e.g., gcc -DECRYPT_VARIANT=3 ...). Please | |
8369 | - * only use this possibility if you really think it could make a | |
8370 | - * significant difference and keep the number of variants | |
8371 | - * (ECRYPT_MAXVARIANT) as small as possible (definitely not more than | |
8372 | - * 10). Note also that all variants should have exactly the same | |
8373 | - * external interface (i.e., the same ECRYPT_BLOCKLENGTH, etc.). | |
8374 | - */ | |
8375 | -#define ECRYPT_MAXVARIANT 1 /* [edit] */ | |
8376 | - | |
8377 | -#ifndef ECRYPT_VARIANT | |
8378 | -#define ECRYPT_VARIANT 1 | |
8379 | -#endif | |
8380 | - | |
8381 | -#if (ECRYPT_VARIANT > ECRYPT_MAXVARIANT) | |
8382 | -#error this variant does not exist | |
8383 | -#endif | |
8384 | - | |
8385 | -/* ------------------------------------------------------------------------- */ | |
8386 | - | |
8387 | -#ifdef __cplusplus | |
8388 | -} | |
8389 | -#endif | |
8390 | - | |
8391 | -#endif | |
8392 | diff --git a/src/crypto/salsa20/salsa20.c b/src/crypto/salsa20/salsa20.c | |
8393 | deleted file mode 100644 | |
8394 | index 74f806c..0000000 | |
8395 | --- a/src/crypto/salsa20/salsa20.c | |
8396 | +++ /dev/null | |
8397 | @@ -1,133 +0,0 @@ | |
8398 | -/* | |
8399 | -salsa20-ref.c version 20051118 | |
8400 | -D. J. Bernstein | |
8401 | -Public domain. | |
8402 | -*/ | |
8403 | - | |
8404 | -#include "ecrypt-sync.h" | |
8405 | - | |
8406 | -#define ROTATE(v,c) (ROTL32(v,c)) | |
8407 | -#define XOR(v,w) ((v) ^ (w)) | |
8408 | -#define PLUS(v,w) (U32V((v) + (w))) | |
8409 | -#define PLUSONE(v) (PLUS((v),1)) | |
8410 | - | |
8411 | -static void salsa20_wordtobyte(u8 output[64],const u32 input[16]) | |
8412 | -{ | |
8413 | - u32 x[16]; | |
8414 | - int i; | |
8415 | - | |
8416 | - for (i = 0;i < 16;++i) x[i] = input[i]; | |
8417 | - for (i = 20;i > 0;i -= 2) { | |
8418 | - x[ 4] = XOR(x[ 4],ROTATE(PLUS(x[ 0],x[12]), 7)); | |
8419 | - x[ 8] = XOR(x[ 8],ROTATE(PLUS(x[ 4],x[ 0]), 9)); | |
8420 | - x[12] = XOR(x[12],ROTATE(PLUS(x[ 8],x[ 4]),13)); | |
8421 | - x[ 0] = XOR(x[ 0],ROTATE(PLUS(x[12],x[ 8]),18)); | |
8422 | - x[ 9] = XOR(x[ 9],ROTATE(PLUS(x[ 5],x[ 1]), 7)); | |
8423 | - x[13] = XOR(x[13],ROTATE(PLUS(x[ 9],x[ 5]), 9)); | |
8424 | - x[ 1] = XOR(x[ 1],ROTATE(PLUS(x[13],x[ 9]),13)); | |
8425 | - x[ 5] = XOR(x[ 5],ROTATE(PLUS(x[ 1],x[13]),18)); | |
8426 | - x[14] = XOR(x[14],ROTATE(PLUS(x[10],x[ 6]), 7)); | |
8427 | - x[ 2] = XOR(x[ 2],ROTATE(PLUS(x[14],x[10]), 9)); | |
8428 | - x[ 6] = XOR(x[ 6],ROTATE(PLUS(x[ 2],x[14]),13)); | |
8429 | - x[10] = XOR(x[10],ROTATE(PLUS(x[ 6],x[ 2]),18)); | |
8430 | - x[ 3] = XOR(x[ 3],ROTATE(PLUS(x[15],x[11]), 7)); | |
8431 | - x[ 7] = XOR(x[ 7],ROTATE(PLUS(x[ 3],x[15]), 9)); | |
8432 | - x[11] = XOR(x[11],ROTATE(PLUS(x[ 7],x[ 3]),13)); | |
8433 | - x[15] = XOR(x[15],ROTATE(PLUS(x[11],x[ 7]),18)); | |
8434 | - x[ 1] = XOR(x[ 1],ROTATE(PLUS(x[ 0],x[ 3]), 7)); | |
8435 | - x[ 2] = XOR(x[ 2],ROTATE(PLUS(x[ 1],x[ 0]), 9)); | |
8436 | - x[ 3] = XOR(x[ 3],ROTATE(PLUS(x[ 2],x[ 1]),13)); | |
8437 | - x[ 0] = XOR(x[ 0],ROTATE(PLUS(x[ 3],x[ 2]),18)); | |
8438 | - x[ 6] = XOR(x[ 6],ROTATE(PLUS(x[ 5],x[ 4]), 7)); | |
8439 | - x[ 7] = XOR(x[ 7],ROTATE(PLUS(x[ 6],x[ 5]), 9)); | |
8440 | - x[ 4] = XOR(x[ 4],ROTATE(PLUS(x[ 7],x[ 6]),13)); | |
8441 | - x[ 5] = XOR(x[ 5],ROTATE(PLUS(x[ 4],x[ 7]),18)); | |
8442 | - x[11] = XOR(x[11],ROTATE(PLUS(x[10],x[ 9]), 7)); | |
8443 | - x[ 8] = XOR(x[ 8],ROTATE(PLUS(x[11],x[10]), 9)); | |
8444 | - x[ 9] = XOR(x[ 9],ROTATE(PLUS(x[ 8],x[11]),13)); | |
8445 | - x[10] = XOR(x[10],ROTATE(PLUS(x[ 9],x[ 8]),18)); | |
8446 | - x[12] = XOR(x[12],ROTATE(PLUS(x[15],x[14]), 7)); | |
8447 | - x[13] = XOR(x[13],ROTATE(PLUS(x[12],x[15]), 9)); | |
8448 | - x[14] = XOR(x[14],ROTATE(PLUS(x[13],x[12]),13)); | |
8449 | - x[15] = XOR(x[15],ROTATE(PLUS(x[14],x[13]),18)); | |
8450 | - } | |
8451 | - for (i = 0;i < 16;++i) x[i] = PLUS(x[i],input[i]); | |
8452 | - for (i = 0;i < 16;++i) U32TO8_LITTLE(output + 4 * i,x[i]); | |
8453 | -} | |
8454 | - | |
8455 | -void ECRYPT_init(void) | |
8456 | -{ | |
8457 | - return; | |
8458 | -} | |
8459 | - | |
8460 | -static const char sigma[16] = "expand 32-byte k"; | |
8461 | -static const char tau[16] = "expand 16-byte k"; | |
8462 | - | |
8463 | -void ECRYPT_keysetup(ECRYPT_ctx *x,const u8 *k,u32 kbits,u32 ivbits) | |
8464 | -{ | |
8465 | - (void)ivbits; | |
8466 | - const char *constants; | |
8467 | - | |
8468 | - x->input[1] = U8TO32_LITTLE(k + 0); | |
8469 | - x->input[2] = U8TO32_LITTLE(k + 4); | |
8470 | - x->input[3] = U8TO32_LITTLE(k + 8); | |
8471 | - x->input[4] = U8TO32_LITTLE(k + 12); | |
8472 | - if (kbits == 256) { /* recommended */ | |
8473 | - k += 16; | |
8474 | - constants = sigma; | |
8475 | - } else { /* kbits == 128 */ | |
8476 | - constants = tau; | |
8477 | - } | |
8478 | - x->input[11] = U8TO32_LITTLE(k + 0); | |
8479 | - x->input[12] = U8TO32_LITTLE(k + 4); | |
8480 | - x->input[13] = U8TO32_LITTLE(k + 8); | |
8481 | - x->input[14] = U8TO32_LITTLE(k + 12); | |
8482 | - x->input[0] = U8TO32_LITTLE(constants + 0); | |
8483 | - x->input[5] = U8TO32_LITTLE(constants + 4); | |
8484 | - x->input[10] = U8TO32_LITTLE(constants + 8); | |
8485 | - x->input[15] = U8TO32_LITTLE(constants + 12); | |
8486 | -} | |
8487 | - | |
8488 | -void ECRYPT_ivsetup(ECRYPT_ctx *x,const u8 *iv) | |
8489 | -{ | |
8490 | - x->input[6] = U8TO32_LITTLE(iv + 0); | |
8491 | - x->input[7] = U8TO32_LITTLE(iv + 4); | |
8492 | - x->input[8] = 0; | |
8493 | - x->input[9] = 0; | |
8494 | -} | |
8495 | - | |
8496 | -void ECRYPT_encrypt_bytes(ECRYPT_ctx *x,const u8 *m,u8 *c,u32 bytes) | |
8497 | -{ | |
8498 | - u8 output[64]; | |
8499 | - u32 i; | |
8500 | - | |
8501 | - if (!bytes) return; | |
8502 | - for (;;) { | |
8503 | - salsa20_wordtobyte(output,x->input); | |
8504 | - x->input[8] = PLUSONE(x->input[8]); | |
8505 | - if (!x->input[8]) { | |
8506 | - x->input[9] = PLUSONE(x->input[9]); | |
8507 | - /* stopping at 2^70 bytes per nonce is user's responsibility */ | |
8508 | - } | |
8509 | - if (bytes <= 64) { | |
8510 | - for (i = 0;i < bytes;++i) c[i] = m[i] ^ output[i]; | |
8511 | - return; | |
8512 | - } | |
8513 | - for (i = 0;i < 64;++i) c[i] = m[i] ^ output[i]; | |
8514 | - bytes -= 64; | |
8515 | - c += 64; | |
8516 | - m += 64; | |
8517 | - } | |
8518 | -} | |
8519 | - | |
8520 | -void ECRYPT_decrypt_bytes(ECRYPT_ctx *x,const u8 *c,u8 *m,u32 bytes) | |
8521 | -{ | |
8522 | - ECRYPT_encrypt_bytes(x,c,m,bytes); | |
8523 | -} | |
8524 | - | |
8525 | -void ECRYPT_keystream_bytes(ECRYPT_ctx *x,u8 *stream,u32 bytes) | |
8526 | -{ | |
8527 | - u32 i; | |
8528 | - for (i = 0;i < bytes;++i) stream[i] = 0; | |
8529 | - ECRYPT_encrypt_bytes(x,stream,stream,bytes); | |
8530 | -} | |
8531 | diff --git a/src/format/KeePass1Reader.cpp b/src/format/KeePass1Reader.cpp | |
8532 | index 0e6b4a9..89775b5 100644 | |
8533 | --- a/src/format/KeePass1Reader.cpp | |
8534 | +++ b/src/format/KeePass1Reader.cpp | |
8535 | @@ -49,9 +49,9 @@ private: | |
8536 | ||
8537 | ||
8538 | KeePass1Reader::KeePass1Reader() | |
8539 | - : m_db(Q_NULLPTR) | |
8540 | - , m_tmpParent(Q_NULLPTR) | |
8541 | - , m_device(Q_NULLPTR) | |
8542 | + : m_db(nullptr) | |
8543 | + , m_tmpParent(nullptr) | |
8544 | + , m_device(nullptr) | |
8545 | , m_encryptionFlags(0) | |
8546 | , m_transformRounds(0) | |
8547 | , m_error(false) | |
8548 | @@ -72,16 +72,16 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor | |
8549 | ||
8550 | if (keyfileData.isEmpty()) { | |
8551 | raiseError(tr("Unable to read keyfile.").append("\n").append(keyfileDevice->errorString())); | |
8552 | - return Q_NULLPTR; | |
8553 | + return nullptr; | |
8554 | } | |
8555 | if (!keyfileDevice->seek(0)) { | |
8556 | raiseError(tr("Unable to read keyfile.").append("\n").append(keyfileDevice->errorString())); | |
8557 | - return Q_NULLPTR; | |
8558 | + return nullptr; | |
8559 | } | |
8560 | ||
8561 | if (!newFileKey.load(keyfileDevice)) { | |
8562 | raiseError(tr("Unable to read keyfile.").append("\n").append(keyfileDevice->errorString())); | |
8563 | - return Q_NULLPTR; | |
8564 | + return nullptr; | |
8565 | } | |
8566 | } | |
8567 | ||
8568 | @@ -96,72 +96,72 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor | |
8569 | quint32 signature1 = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok); | |
8570 | if (!ok || signature1 != KeePass1::SIGNATURE_1) { | |
8571 | raiseError(tr("Not a KeePass database.")); | |
8572 | - return Q_NULLPTR; | |
8573 | + return nullptr; | |
8574 | } | |
8575 | ||
8576 | quint32 signature2 = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok); | |
8577 | if (!ok || signature2 != KeePass1::SIGNATURE_2) { | |
8578 | raiseError(tr("Not a KeePass database.")); | |
8579 | - return Q_NULLPTR; | |
8580 | + return nullptr; | |
8581 | } | |
8582 | ||
8583 | m_encryptionFlags = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok); | |
8584 | if (!ok || !(m_encryptionFlags & KeePass1::Rijndael || m_encryptionFlags & KeePass1::Twofish)) { | |
8585 | raiseError(tr("Unsupported encryption algorithm.")); | |
8586 | - return Q_NULLPTR; | |
8587 | + return nullptr; | |
8588 | } | |
8589 | ||
8590 | quint32 version = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok); | |
8591 | if (!ok || (version & KeePass1::FILE_VERSION_CRITICAL_MASK) | |
8592 | != (KeePass1::FILE_VERSION & KeePass1::FILE_VERSION_CRITICAL_MASK)) { | |
8593 | raiseError(tr("Unsupported KeePass database version.")); | |
8594 | - return Q_NULLPTR; | |
8595 | + return nullptr; | |
8596 | } | |
8597 | ||
8598 | m_masterSeed = m_device->read(16); | |
8599 | if (m_masterSeed.size() != 16) { | |
8600 | raiseError("Unable to read master seed"); | |
8601 | - return Q_NULLPTR; | |
8602 | + return nullptr; | |
8603 | } | |
8604 | ||
8605 | m_encryptionIV = m_device->read(16); | |
8606 | if (m_encryptionIV.size() != 16) { | |
8607 | raiseError("Unable to read encryption IV"); | |
8608 | - return Q_NULLPTR; | |
8609 | + return nullptr; | |
8610 | } | |
8611 | ||
8612 | quint32 numGroups = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok); | |
8613 | if (!ok) { | |
8614 | raiseError("Invalid number of groups"); | |
8615 | - return Q_NULLPTR; | |
8616 | + return nullptr; | |
8617 | } | |
8618 | ||
8619 | quint32 numEntries = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok); | |
8620 | if (!ok) { | |
8621 | raiseError("Invalid number of entries"); | |
8622 | - return Q_NULLPTR; | |
8623 | + return nullptr; | |
8624 | } | |
8625 | ||
8626 | m_contentHashHeader = m_device->read(32); | |
8627 | if (m_contentHashHeader.size() != 32) { | |
8628 | raiseError("Invalid content hash size"); | |
8629 | - return Q_NULLPTR; | |
8630 | + return nullptr; | |
8631 | } | |
8632 | ||
8633 | m_transformSeed = m_device->read(32); | |
8634 | if (m_transformSeed.size() != 32) { | |
8635 | raiseError("Invalid transform seed size"); | |
8636 | - return Q_NULLPTR; | |
8637 | + return nullptr; | |
8638 | } | |
8639 | ||
8640 | m_transformRounds = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok); | |
8641 | if (!ok) { | |
8642 | raiseError("Invalid number of transform rounds"); | |
8643 | - return Q_NULLPTR; | |
8644 | + return nullptr; | |
8645 | } | |
8646 | if (!m_db->setTransformRounds(m_transformRounds)) { | |
8647 | raiseError(tr("Unable to calculate master key")); | |
8648 | - return Q_NULLPTR; | |
8649 | + return nullptr; | |
8650 | } | |
8651 | ||
8652 | qint64 contentPos = m_device->pos(); | |
8653 | @@ -169,14 +169,14 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor | |
8654 | QScopedPointer<SymmetricCipherStream> cipherStream(testKeys(password, keyfileData, contentPos)); | |
8655 | ||
8656 | if (!cipherStream) { | |
8657 | - return Q_NULLPTR; | |
8658 | + return nullptr; | |
8659 | } | |
8660 | ||
8661 | QList<Group*> groups; | |
8662 | for (quint32 i = 0; i < numGroups; i++) { | |
8663 | Group* group = readGroup(cipherStream.data()); | |
8664 | if (!group) { | |
8665 | - return Q_NULLPTR; | |
8666 | + return nullptr; | |
8667 | } | |
8668 | groups.append(group); | |
8669 | } | |
8670 | @@ -185,14 +185,14 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor | |
8671 | for (quint32 i = 0; i < numEntries; i++) { | |
8672 | Entry* entry = readEntry(cipherStream.data()); | |
8673 | if (!entry) { | |
8674 | - return Q_NULLPTR; | |
8675 | + return nullptr; | |
8676 | } | |
8677 | entries.append(entry); | |
8678 | } | |
8679 | ||
8680 | if (!constructGroupTree(groups)) { | |
8681 | raiseError("Unable to construct group tree"); | |
8682 | - return Q_NULLPTR; | |
8683 | + return nullptr; | |
8684 | } | |
8685 | ||
8686 | Q_FOREACH (Entry* entry, entries) { | |
8687 | @@ -243,7 +243,7 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor | |
8688 | ||
8689 | if (!db->setKey(key)) { | |
8690 | raiseError(tr("Unable to calculate master key")); | |
8691 | - return Q_NULLPTR; | |
8692 | + return nullptr; | |
8693 | } | |
8694 | ||
8695 | return db.take(); | |
8696 | @@ -257,7 +257,7 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor | |
8697 | keyFile.reset(new QFile(keyfileName)); | |
8698 | if (!keyFile->open(QFile::ReadOnly)) { | |
8699 | raiseError(keyFile->errorString()); | |
8700 | - return Q_NULLPTR; | |
8701 | + return nullptr; | |
8702 | } | |
8703 | } | |
8704 | ||
8705 | @@ -272,14 +272,14 @@ Database* KeePass1Reader::readDatabase(const QString& filename, const QString& p | |
8706 | QFile dbFile(filename); | |
8707 | if (!dbFile.open(QFile::ReadOnly)) { | |
8708 | raiseError(dbFile.errorString()); | |
8709 | - return Q_NULLPTR; | |
8710 | + return nullptr; | |
8711 | } | |
8712 | ||
8713 | Database* db = readDatabase(&dbFile, password, keyfileName); | |
8714 | ||
8715 | if (dbFile.error() != QFile::NoError) { | |
8716 | raiseError(dbFile.errorString()); | |
8717 | - return Q_NULLPTR; | |
8718 | + return nullptr; | |
8719 | } | |
8720 | ||
8721 | return db; | |
8722 | @@ -337,7 +337,7 @@ SymmetricCipherStream* KeePass1Reader::testKeys(const QString& password, const Q | |
8723 | ||
8724 | QByteArray finalKey = key(passwordData, keyfileData); | |
8725 | if (finalKey.isEmpty()) { | |
8726 | - return Q_NULLPTR; | |
8727 | + return nullptr; | |
8728 | } | |
8729 | if (m_encryptionFlags & KeePass1::Rijndael) { | |
8730 | cipherStream.reset(new SymmetricCipherStream(m_device, SymmetricCipher::Aes256, | |
8731 | @@ -350,11 +350,11 @@ SymmetricCipherStream* KeePass1Reader::testKeys(const QString& password, const Q | |
8732 | ||
8733 | if (!cipherStream->init(finalKey, m_encryptionIV)) { | |
8734 | raiseError(cipherStream->errorString()); | |
8735 | - return Q_NULLPTR; | |
8736 | + return nullptr; | |
8737 | } | |
8738 | if (!cipherStream->open(QIODevice::ReadOnly)) { | |
8739 | raiseError(cipherStream->errorString()); | |
8740 | - return Q_NULLPTR; | |
8741 | + return nullptr; | |
8742 | } | |
8743 | ||
8744 | bool success = verifyKey(cipherStream.data()); | |
8745 | @@ -368,7 +368,7 @@ SymmetricCipherStream* KeePass1Reader::testKeys(const QString& password, const Q | |
8746 | } | |
8747 | raiseError(msg); | |
8748 | ||
8749 | - return Q_NULLPTR; | |
8750 | + return nullptr; | |
8751 | } | |
8752 | cipherStream->open(QIODevice::ReadOnly); | |
8753 | ||
8754 | @@ -442,19 +442,19 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream) | |
8755 | quint16 fieldType = Endian::readUInt16(cipherStream, KeePass1::BYTEORDER, &ok); | |
8756 | if (!ok) { | |
8757 | raiseError("Invalid group field type number"); | |
8758 | - return Q_NULLPTR; | |
8759 | + return nullptr; | |
8760 | } | |
8761 | ||
8762 | int fieldSize = static_cast<int>(Endian::readUInt32(cipherStream, KeePass1::BYTEORDER, &ok)); | |
8763 | if (!ok) { | |
8764 | raiseError("Invalid group field size"); | |
8765 | - return Q_NULLPTR; | |
8766 | + return nullptr; | |
8767 | } | |
8768 | ||
8769 | QByteArray fieldData = cipherStream->read(fieldSize); | |
8770 | if (fieldData.size() != fieldSize) { | |
8771 | raiseError("Read group field data doesn't match size"); | |
8772 | - return Q_NULLPTR; | |
8773 | + return nullptr; | |
8774 | } | |
8775 | ||
8776 | switch (fieldType) { | |
8777 | @@ -464,7 +464,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream) | |
8778 | case 0x0001: | |
8779 | if (fieldSize != 4) { | |
8780 | raiseError("Incorrect group id field size"); | |
8781 | - return Q_NULLPTR; | |
8782 | + return nullptr; | |
8783 | } | |
8784 | groupId = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER); | |
8785 | groupIdSet = true; | |
8786 | @@ -476,7 +476,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream) | |
8787 | { | |
8788 | if (fieldSize != 5) { | |
8789 | raiseError("Incorrect group creation time field size"); | |
8790 | - return Q_NULLPTR; | |
8791 | + return nullptr; | |
8792 | } | |
8793 | QDateTime dateTime = dateFromPackedStruct(fieldData); | |
8794 | if (dateTime.isValid()) { | |
8795 | @@ -488,7 +488,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream) | |
8796 | { | |
8797 | if (fieldSize != 5) { | |
8798 | raiseError("Incorrect group modification time field size"); | |
8799 | - return Q_NULLPTR; | |
8800 | + return nullptr; | |
8801 | } | |
8802 | QDateTime dateTime = dateFromPackedStruct(fieldData); | |
8803 | if (dateTime.isValid()) { | |
8804 | @@ -523,7 +523,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream) | |
8805 | { | |
8806 | if (fieldSize != 4) { | |
8807 | raiseError("Incorrect group icon field size"); | |
8808 | - return Q_NULLPTR; | |
8809 | + return nullptr; | |
8810 | } | |
8811 | quint32 iconNumber = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER); | |
8812 | group->setIcon(iconNumber); | |
8813 | @@ -533,7 +533,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream) | |
8814 | { | |
8815 | if (fieldSize != 2) { | |
8816 | raiseError("Incorrect group level field size"); | |
8817 | - return Q_NULLPTR; | |
8818 | + return nullptr; | |
8819 | } | |
8820 | groupLevel = Endian::bytesToUInt16(fieldData, KeePass1::BYTEORDER); | |
8821 | groupLevelSet = true; | |
8822 | @@ -548,13 +548,13 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream) | |
8823 | default: | |
8824 | // invalid field | |
8825 | raiseError("Invalid group field type"); | |
8826 | - return Q_NULLPTR; | |
8827 | + return nullptr; | |
8828 | } | |
8829 | } while (!reachedEnd); | |
8830 | ||
8831 | if (!groupIdSet || !groupLevelSet) { | |
8832 | raiseError("Missing group id or level"); | |
8833 | - return Q_NULLPTR; | |
8834 | + return nullptr; | |
8835 | } | |
8836 | ||
8837 | group->setUuid(Uuid::random()); | |
8838 | @@ -580,19 +580,19 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream) | |
8839 | quint16 fieldType = Endian::readUInt16(cipherStream, KeePass1::BYTEORDER, &ok); | |
8840 | if (!ok) { | |
8841 | raiseError("Missing entry field type number"); | |
8842 | - return Q_NULLPTR; | |
8843 | + return nullptr; | |
8844 | } | |
8845 | ||
8846 | int fieldSize = static_cast<int>(Endian::readUInt32(cipherStream, KeePass1::BYTEORDER, &ok)); | |
8847 | if (!ok) { | |
8848 | raiseError("Invalid entry field size"); | |
8849 | - return Q_NULLPTR; | |
8850 | + return nullptr; | |
8851 | } | |
8852 | ||
8853 | QByteArray fieldData = cipherStream->read(fieldSize); | |
8854 | if (fieldData.size() != fieldSize) { | |
8855 | raiseError("Read entry field data doesn't match size"); | |
8856 | - return Q_NULLPTR; | |
8857 | + return nullptr; | |
8858 | } | |
8859 | ||
8860 | switch (fieldType) { | |
8861 | @@ -602,7 +602,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream) | |
8862 | case 0x0001: | |
8863 | if (fieldSize != 16) { | |
8864 | raiseError("Invalid entry uuid field size"); | |
8865 | - return Q_NULLPTR; | |
8866 | + return nullptr; | |
8867 | } | |
8868 | m_entryUuids.insert(fieldData, entry.data()); | |
8869 | break; | |
8870 | @@ -610,7 +610,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream) | |
8871 | { | |
8872 | if (fieldSize != 4) { | |
8873 | raiseError("Invalid entry group id field size"); | |
8874 | - return Q_NULLPTR; | |
8875 | + return nullptr; | |
8876 | } | |
8877 | quint32 groupId = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER); | |
8878 | m_entryGroupIds.insert(entry.data(), groupId); | |
8879 | @@ -620,7 +620,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream) | |
8880 | { | |
8881 | if (fieldSize != 4) { | |
8882 | raiseError("Invalid entry icon field size"); | |
8883 | - return Q_NULLPTR; | |
8884 | + return nullptr; | |
8885 | } | |
8886 | quint32 iconNumber = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER); | |
8887 | entry->setIcon(iconNumber); | |
8888 | @@ -645,7 +645,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream) | |
8889 | { | |
8890 | if (fieldSize != 5) { | |
8891 | raiseError("Invalid entry creation time field size"); | |
8892 | - return Q_NULLPTR; | |
8893 | + return nullptr; | |
8894 | } | |
8895 | QDateTime dateTime = dateFromPackedStruct(fieldData); | |
8896 | if (dateTime.isValid()) { | |
8897 | @@ -657,7 +657,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream) | |
8898 | { | |
8899 | if (fieldSize != 5) { | |
8900 | raiseError("Invalid entry modification time field size"); | |
8901 | - return Q_NULLPTR; | |
8902 | + return nullptr; | |
8903 | } | |
8904 | QDateTime dateTime = dateFromPackedStruct(fieldData); | |
8905 | if (dateTime.isValid()) { | |
8906 | @@ -669,7 +669,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream) | |
8907 | { | |
8908 | if (fieldSize != 5) { | |
8909 | raiseError("Invalid entry creation time field size"); | |
8910 | - return Q_NULLPTR; | |
8911 | + return nullptr; | |
8912 | } | |
8913 | QDateTime dateTime = dateFromPackedStruct(fieldData); | |
8914 | if (dateTime.isValid()) { | |
8915 | @@ -681,7 +681,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream) | |
8916 | { | |
8917 | if (fieldSize != 5) { | |
8918 | raiseError("Invalid entry expiry time field size"); | |
8919 | - return Q_NULLPTR; | |
8920 | + return nullptr; | |
8921 | } | |
8922 | QDateTime dateTime = dateFromPackedStruct(fieldData); | |
8923 | if (dateTime.isValid()) { | |
8924 | @@ -704,7 +704,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream) | |
8925 | default: | |
8926 | // invalid field | |
8927 | raiseError("Invalid entry field type"); | |
8928 | - return Q_NULLPTR; | |
8929 | + return nullptr; | |
8930 | } | |
8931 | } while (!reachedEnd); | |
8932 | ||
8933 | diff --git a/src/format/KeePass2Reader.cpp b/src/format/KeePass2Reader.cpp | |
8934 | index d1ca9ed..00ebc07 100644 | |
8935 | --- a/src/format/KeePass2Reader.cpp | |
8936 | +++ b/src/format/KeePass2Reader.cpp | |
8937 | @@ -34,12 +34,12 @@ | |
8938 | #include "streams/SymmetricCipherStream.h" | |
8939 | ||
8940 | KeePass2Reader::KeePass2Reader() | |
8941 | - : m_device(Q_NULLPTR) | |
8942 | - , m_headerStream(Q_NULLPTR) | |
8943 | + : m_device(nullptr) | |
8944 | + , m_headerStream(nullptr) | |
8945 | , m_error(false) | |
8946 | , m_headerEnd(false) | |
8947 | , m_saveXml(false) | |
8948 | - , m_db(Q_NULLPTR) | |
8949 | + , m_db(nullptr) | |
8950 | { | |
8951 | } | |
8952 | ||
8953 | @@ -67,7 +67,7 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke | |
8954 | quint32 signature1 = Endian::readUInt32(m_headerStream, KeePass2::BYTEORDER, &ok); | |
8955 | if (!ok || signature1 != KeePass2::SIGNATURE_1) { | |
8956 | raiseError(tr("Not a KeePass database.")); | |
8957 | - return Q_NULLPTR; | |
8958 | + return nullptr; | |
8959 | } | |
8960 | ||
8961 | quint32 signature2 = Endian::readUInt32(m_headerStream, KeePass2::BYTEORDER, &ok); | |
8962 | @@ -76,11 +76,11 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke | |
8963 | "You can import it by clicking on Database > 'Import KeePass 1 database'.\n" | |
8964 | "This is a one-way migration. You won't be able to open the imported " | |
8965 | "database with the old KeePassX 0.4 version.")); | |
8966 | - return Q_NULLPTR; | |
8967 | + return nullptr; | |
8968 | } | |
8969 | else if (!ok || signature2 != KeePass2::SIGNATURE_2) { | |
8970 | raiseError(tr("Not a KeePass database.")); | |
8971 | - return Q_NULLPTR; | |
8972 | + return nullptr; | |
8973 | } | |
8974 | ||
8975 | quint32 version = Endian::readUInt32(m_headerStream, KeePass2::BYTEORDER, &ok) | |
8976 | @@ -88,7 +88,7 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke | |
8977 | quint32 maxVersion = KeePass2::FILE_VERSION & KeePass2::FILE_VERSION_CRITICAL_MASK; | |
8978 | if (!ok || (version < KeePass2::FILE_VERSION_MIN) || (version > maxVersion)) { | |
8979 | raiseError(tr("Unsupported KeePass database version.")); | |
8980 | - return Q_NULLPTR; | |
8981 | + return nullptr; | |
8982 | } | |
8983 | ||
8984 | while (readHeaderField() && !hasError()) { | |
8985 | @@ -97,7 +97,7 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke | |
8986 | headerStream.close(); | |
8987 | ||
8988 | if (hasError()) { | |
8989 | - return Q_NULLPTR; | |
8990 | + return nullptr; | |
8991 | } | |
8992 | ||
8993 | // check if all required headers were present | |
8994 | @@ -105,12 +105,12 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke | |
8995 | || m_streamStartBytes.isEmpty() || m_protectedStreamKey.isEmpty() | |
8996 | || m_db->cipher().isNull()) { | |
8997 | raiseError("missing database headers"); | |
8998 | - return Q_NULLPTR; | |
8999 | + return nullptr; | |
9000 | } | |
9001 | ||
9002 | if (!m_db->setKey(key, m_transformSeed, false)) { | |
9003 | raiseError(tr("Unable to calculate master key")); | |
9004 | - return Q_NULLPTR; | |
9005 | + return nullptr; | |
9006 | } | |
9007 | ||
9008 | CryptoHash hash(CryptoHash::Sha256); | |
9009 | @@ -122,24 +122,24 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke | |
9010 | SymmetricCipher::Cbc, SymmetricCipher::Decrypt); | |
9011 | if (!cipherStream.init(finalKey, m_encryptionIV)) { | |
9012 | raiseError(cipherStream.errorString()); | |
9013 | - return Q_NULLPTR; | |
9014 | + return nullptr; | |
9015 | } | |
9016 | if (!cipherStream.open(QIODevice::ReadOnly)) { | |
9017 | raiseError(cipherStream.errorString()); | |
9018 | - return Q_NULLPTR; | |
9019 | + return nullptr; | |
9020 | } | |
9021 | ||
9022 | QByteArray realStart = cipherStream.read(32); | |
9023 | ||
9024 | if (realStart != m_streamStartBytes) { | |
9025 | raiseError(tr("Wrong key or database file is corrupt.")); | |
9026 | - return Q_NULLPTR; | |
9027 | + return nullptr; | |
9028 | } | |
9029 | ||
9030 | HashedBlockStream hashedStream(&cipherStream); | |
9031 | if (!hashedStream.open(QIODevice::ReadOnly)) { | |
9032 | raiseError(hashedStream.errorString()); | |
9033 | - return Q_NULLPTR; | |
9034 | + return nullptr; | |
9035 | } | |
9036 | ||
9037 | QIODevice* xmlDevice; | |
9038 | @@ -153,7 +153,7 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke | |
9039 | ioCompressor->setStreamFormat(QtIOCompressor::GzipFormat); | |
9040 | if (!ioCompressor->open(QIODevice::ReadOnly)) { | |
9041 | raiseError(ioCompressor->errorString()); | |
9042 | - return Q_NULLPTR; | |
9043 | + return nullptr; | |
9044 | } | |
9045 | xmlDevice = ioCompressor.data(); | |
9046 | } | |
9047 | @@ -161,7 +161,7 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke | |
9048 | KeePass2RandomStream randomStream; | |
9049 | if (!randomStream.init(m_protectedStreamKey)) { | |
9050 | raiseError(randomStream.errorString()); | |
9051 | - return Q_NULLPTR; | |
9052 | + return nullptr; | |
9053 | } | |
9054 | ||
9055 | QScopedPointer<QBuffer> buffer; | |
9056 | @@ -182,7 +182,7 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke | |
9057 | return db.take(); | |
9058 | } | |
9059 | else { | |
9060 | - return Q_NULLPTR; | |
9061 | + return nullptr; | |
9062 | } | |
9063 | } | |
9064 | ||
9065 | @@ -192,7 +192,7 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke | |
9066 | QByteArray headerHash = CryptoHash::hash(headerStream.storedData(), CryptoHash::Sha256); | |
9067 | if (headerHash != xmlReader.headerHash()) { | |
9068 | raiseError("Head doesn't match hash"); | |
9069 | - return Q_NULLPTR; | |
9070 | + return nullptr; | |
9071 | } | |
9072 | } | |
9073 | ||
9074 | @@ -204,14 +204,14 @@ Database* KeePass2Reader::readDatabase(const QString& filename, const CompositeK | |
9075 | QFile file(filename); | |
9076 | if (!file.open(QFile::ReadOnly)) { | |
9077 | raiseError(file.errorString()); | |
9078 | - return Q_NULLPTR; | |
9079 | + return nullptr; | |
9080 | } | |
9081 | ||
9082 | QScopedPointer<Database> db(readDatabase(&file, key)); | |
9083 | ||
9084 | if (file.error() != QFile::NoError) { | |
9085 | raiseError(file.errorString()); | |
9086 | - return Q_NULLPTR; | |
9087 | + return nullptr; | |
9088 | } | |
9089 | ||
9090 | return db.take(); | |
9091 | diff --git a/src/format/KeePass2Repair.cpp b/src/format/KeePass2Repair.cpp | |
9092 | index f435a7d..81ada2f 100644 | |
9093 | --- a/src/format/KeePass2Repair.cpp | |
9094 | +++ b/src/format/KeePass2Repair.cpp | |
9095 | @@ -25,13 +25,13 @@ | |
9096 | #include "format/KeePass2XmlReader.h" | |
9097 | ||
9098 | KeePass2Repair::KeePass2Repair() | |
9099 | - : m_db(Q_NULLPTR) | |
9100 | + : m_db(nullptr) | |
9101 | { | |
9102 | } | |
9103 | ||
9104 | KeePass2Repair::RepairResult KeePass2Repair::repairDatabase(QIODevice* device, const CompositeKey& key) | |
9105 | { | |
9106 | - m_db = Q_NULLPTR; | |
9107 | + m_db = nullptr; | |
9108 | m_errorStr.clear(); | |
9109 | ||
9110 | KeePass2Reader reader; | |
9111 | diff --git a/src/format/KeePass2XmlReader.cpp b/src/format/KeePass2XmlReader.cpp | |
9112 | index 815cbf9..40087a6 100644 | |
9113 | --- a/src/format/KeePass2XmlReader.cpp | |
9114 | +++ b/src/format/KeePass2XmlReader.cpp | |
9115 | @@ -31,10 +31,10 @@ | |
9116 | typedef QPair<QString, QString> StringPair; | |
9117 | ||
9118 | KeePass2XmlReader::KeePass2XmlReader() | |
9119 | - : m_randomStream(Q_NULLPTR) | |
9120 | - , m_db(Q_NULLPTR) | |
9121 | - , m_meta(Q_NULLPTR) | |
9122 | - , m_tmpParent(Q_NULLPTR) | |
9123 | + : m_randomStream(nullptr) | |
9124 | + , m_db(nullptr) | |
9125 | + , m_meta(nullptr) | |
9126 | + , m_tmpParent(nullptr) | |
9127 | , m_error(false) | |
9128 | , m_strictMode(false) | |
9129 | { | |
9130 | @@ -1045,7 +1045,7 @@ QDateTime KeePass2XmlReader::readDateTime() | |
9131 | raiseError("Invalid date time value"); | |
9132 | } | |
9133 | else { | |
9134 | - dt = Tools::currentDateTimeUtc(); | |
9135 | + dt = QDateTime::currentDateTimeUtc(); | |
9136 | } | |
9137 | } | |
9138 | ||
9139 | @@ -1146,7 +1146,7 @@ QByteArray KeePass2XmlReader::readCompressedBinary() | |
9140 | Group* KeePass2XmlReader::getGroup(const Uuid& uuid) | |
9141 | { | |
9142 | if (uuid.isNull()) { | |
9143 | - return Q_NULLPTR; | |
9144 | + return nullptr; | |
9145 | } | |
9146 | ||
9147 | if (m_groups.contains(uuid)) { | |
9148 | @@ -1165,7 +1165,7 @@ Group* KeePass2XmlReader::getGroup(const Uuid& uuid) | |
9149 | Entry* KeePass2XmlReader::getEntry(const Uuid& uuid) | |
9150 | { | |
9151 | if (uuid.isNull()) { | |
9152 | - return Q_NULLPTR; | |
9153 | + return nullptr; | |
9154 | } | |
9155 | ||
9156 | if (m_entries.contains(uuid)) { | |
9157 | diff --git a/src/format/KeePass2XmlReader.h b/src/format/KeePass2XmlReader.h | |
9158 | index ca311b0..d2e0e00 100644 | |
9159 | --- a/src/format/KeePass2XmlReader.h | |
9160 | +++ b/src/format/KeePass2XmlReader.h | |
9161 | @@ -25,7 +25,6 @@ | |
9162 | #include <QPair> | |
9163 | #include <QXmlStreamReader> | |
9164 | ||
9165 | -#include "core/Global.h" | |
9166 | #include "core/TimeInfo.h" | |
9167 | #include "core/Uuid.h" | |
9168 | ||
9169 | @@ -42,7 +41,7 @@ class KeePass2XmlReader | |
9170 | public: | |
9171 | KeePass2XmlReader(); | |
9172 | Database* readDatabase(QIODevice* device); | |
9173 | - void readDatabase(QIODevice* device, Database* db, KeePass2RandomStream* randomStream = Q_NULLPTR); | |
9174 | + void readDatabase(QIODevice* device, Database* db, KeePass2RandomStream* randomStream = nullptr); | |
9175 | Database* readDatabase(const QString& filename); | |
9176 | bool hasError(); | |
9177 | QString errorString(); | |
9178 | diff --git a/src/format/KeePass2XmlWriter.cpp b/src/format/KeePass2XmlWriter.cpp | |
9179 | index 1eb8dc1..7fd03cc 100644 | |
9180 | --- a/src/format/KeePass2XmlWriter.cpp | |
9181 | +++ b/src/format/KeePass2XmlWriter.cpp | |
9182 | @@ -25,9 +25,9 @@ | |
9183 | #include "streams/QtIOCompressor" | |
9184 | ||
9185 | KeePass2XmlWriter::KeePass2XmlWriter() | |
9186 | - : m_db(Q_NULLPTR) | |
9187 | - , m_meta(Q_NULLPTR) | |
9188 | - , m_randomStream(Q_NULLPTR) | |
9189 | + : m_db(nullptr) | |
9190 | + , m_meta(nullptr) | |
9191 | + , m_randomStream(nullptr) | |
9192 | , m_error(false) | |
9193 | { | |
9194 | m_xml.setAutoFormatting(true); | |
9195 | @@ -58,11 +58,9 @@ void KeePass2XmlWriter::writeDatabase(QIODevice* device, Database* db, KeePass2R | |
9196 | ||
9197 | m_xml.writeEndDocument(); | |
9198 | ||
9199 | -#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) | |
9200 | if (m_xml.hasError()) { | |
9201 | raiseError(device->errorString()); | |
9202 | } | |
9203 | -#endif | |
9204 | } | |
9205 | ||
9206 | void KeePass2XmlWriter::writeDatabase(const QString& filename, Database* db) | |
9207 | diff --git a/src/format/KeePass2XmlWriter.h b/src/format/KeePass2XmlWriter.h | |
9208 | index 48dde6a..23e148d 100644 | |
9209 | --- a/src/format/KeePass2XmlWriter.h | |
9210 | +++ b/src/format/KeePass2XmlWriter.h | |
9211 | @@ -36,7 +36,7 @@ class KeePass2XmlWriter | |
9212 | { | |
9213 | public: | |
9214 | KeePass2XmlWriter(); | |
9215 | - void writeDatabase(QIODevice* device, Database* db, KeePass2RandomStream* randomStream = Q_NULLPTR, | |
9216 | + void writeDatabase(QIODevice* device, Database* db, KeePass2RandomStream* randomStream = nullptr, | |
9217 | const QByteArray& headerHash = QByteArray()); | |
9218 | void writeDatabase(const QString& filename, Database* db); | |
9219 | bool hasError(); | |
9220 | diff --git a/src/gui/AboutDialog.h b/src/gui/AboutDialog.h | |
9221 | index 1436aee..08db6c8 100644 | |
9222 | --- a/src/gui/AboutDialog.h | |
9223 | +++ b/src/gui/AboutDialog.h | |
9224 | @@ -21,8 +21,6 @@ | |
9225 | #include <QDialog> | |
9226 | #include <QScopedPointer> | |
9227 | ||
9228 | -#include "core/Global.h" | |
9229 | - | |
9230 | namespace Ui { | |
9231 | class AboutDialog; | |
9232 | } | |
9233 | @@ -32,7 +30,7 @@ class AboutDialog : public QDialog | |
9234 | Q_OBJECT | |
9235 | ||
9236 | public: | |
9237 | - explicit AboutDialog(QWidget* parent = Q_NULLPTR); | |
9238 | + explicit AboutDialog(QWidget* parent = nullptr); | |
9239 | ~AboutDialog(); | |
9240 | ||
9241 | private: | |
9242 | diff --git a/src/gui/Application.cpp b/src/gui/Application.cpp | |
9243 | index ae6931f..70550c5 100644 | |
9244 | --- a/src/gui/Application.cpp | |
9245 | +++ b/src/gui/Application.cpp | |
9246 | @@ -18,14 +18,38 @@ | |
9247 | ||
9248 | #include "Application.h" | |
9249 | ||
9250 | +#include <QAbstractNativeEventFilter> | |
9251 | #include <QFileOpenEvent> | |
9252 | ||
9253 | #include "autotype/AutoType.h" | |
9254 | ||
9255 | +#if defined(Q_OS_UNIX) && !defined(Q_OS_OSX) | |
9256 | +class XcbEventFilter : public QAbstractNativeEventFilter | |
9257 | +{ | |
9258 | +public: | |
9259 | + bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) override | |
9260 | + { | |
9261 | + Q_UNUSED(result) | |
9262 | + | |
9263 | + if (eventType == QByteArrayLiteral("xcb_generic_event_t")) { | |
9264 | + int retCode = autoType()->callEventFilter(message); | |
9265 | + if (retCode == 1) { | |
9266 | + return true; | |
9267 | + } | |
9268 | + } | |
9269 | + | |
9270 | + return false; | |
9271 | + } | |
9272 | +}; | |
9273 | +#endif | |
9274 | + | |
9275 | Application::Application(int& argc, char** argv) | |
9276 | : QApplication(argc, argv) | |
9277 | - , m_mainWindow(Q_NULLPTR) | |
9278 | + , m_mainWindow(nullptr) | |
9279 | { | |
9280 | +#if defined(Q_OS_UNIX) && !defined(Q_OS_OSX) | |
9281 | + installNativeEventFilter(new XcbEventFilter()); | |
9282 | +#endif | |
9283 | } | |
9284 | ||
9285 | void Application::setMainWindow(QWidget* mainWindow) | |
9286 | @@ -53,19 +77,3 @@ bool Application::event(QEvent* event) | |
9287 | ||
9288 | return QApplication::event(event); | |
9289 | } | |
9290 | - | |
9291 | -#ifdef Q_WS_X11 | |
9292 | -bool Application::x11EventFilter(XEvent* event) | |
9293 | -{ | |
9294 | - int retCode = autoType()->callEventFilter(event); | |
9295 | - | |
9296 | - if (retCode == 0) { | |
9297 | - return false; | |
9298 | - } | |
9299 | - else if (retCode == 1) { | |
9300 | - return true; | |
9301 | - } | |
9302 | - | |
9303 | - return QApplication::x11EventFilter(event); | |
9304 | -} | |
9305 | -#endif | |
9306 | diff --git a/src/gui/Application.h b/src/gui/Application.h | |
9307 | index 2b78998..149b61d 100644 | |
9308 | --- a/src/gui/Application.h | |
9309 | +++ b/src/gui/Application.h | |
9310 | @@ -21,8 +21,6 @@ | |
9311 | ||
9312 | #include <QApplication> | |
9313 | ||
9314 | -#include "core/Global.h" | |
9315 | - | |
9316 | class Application : public QApplication | |
9317 | { | |
9318 | Q_OBJECT | |
9319 | @@ -31,10 +29,7 @@ public: | |
9320 | Application(int& argc, char** argv); | |
9321 | void setMainWindow(QWidget* mainWindow); | |
9322 | ||
9323 | - bool event(QEvent* event) Q_DECL_OVERRIDE; | |
9324 | -#ifdef Q_WS_X11 | |
9325 | - bool x11EventFilter(XEvent* event) Q_DECL_OVERRIDE; | |
9326 | -#endif | |
9327 | + bool event(QEvent* event) override; | |
9328 | ||
9329 | Q_SIGNALS: | |
9330 | void openFile(const QString& filename); | |
9331 | diff --git a/src/gui/ChangeMasterKeyWidget.h b/src/gui/ChangeMasterKeyWidget.h | |
9332 | index 46fc3ef..8985ff7 100644 | |
9333 | --- a/src/gui/ChangeMasterKeyWidget.h | |
9334 | +++ b/src/gui/ChangeMasterKeyWidget.h | |
9335 | @@ -33,7 +33,7 @@ class ChangeMasterKeyWidget : public DialogyWidget | |
9336 | Q_OBJECT | |
9337 | ||
9338 | public: | |
9339 | - explicit ChangeMasterKeyWidget(QWidget* parent = Q_NULLPTR); | |
9340 | + explicit ChangeMasterKeyWidget(QWidget* parent = nullptr); | |
9341 | ~ChangeMasterKeyWidget(); | |
9342 | void clearForms(); | |
9343 | CompositeKey newMasterKey(); | |
9344 | diff --git a/src/gui/Clipboard.cpp b/src/gui/Clipboard.cpp | |
9345 | index 698ca89..bf4db8f 100644 | |
9346 | --- a/src/gui/Clipboard.cpp | |
9347 | +++ b/src/gui/Clipboard.cpp | |
9348 | @@ -23,7 +23,7 @@ | |
9349 | ||
9350 | #include "core/Config.h" | |
9351 | ||
9352 | -Clipboard* Clipboard::m_instance(Q_NULLPTR); | |
9353 | +Clipboard* Clipboard::m_instance(nullptr); | |
9354 | ||
9355 | Clipboard::Clipboard(QObject* parent) | |
9356 | : QObject(parent) | |
9357 | diff --git a/src/gui/Clipboard.h b/src/gui/Clipboard.h | |
9358 | index 8c234a2..dafce70 100644 | |
9359 | --- a/src/gui/Clipboard.h | |
9360 | +++ b/src/gui/Clipboard.h | |
9361 | @@ -20,8 +20,6 @@ | |
9362 | ||
9363 | #include <QObject> | |
9364 | ||
9365 | -#include "core/Global.h" | |
9366 | - | |
9367 | class QTimer; | |
9368 | ||
9369 | class Clipboard : public QObject | |
9370 | @@ -40,7 +38,7 @@ private Q_SLOTS: | |
9371 | void clearClipboard(); | |
9372 | ||
9373 | private: | |
9374 | - explicit Clipboard(QObject* parent = Q_NULLPTR); | |
9375 | + explicit Clipboard(QObject* parent = nullptr); | |
9376 | ||
9377 | static Clipboard* m_instance; | |
9378 | ||
9379 | diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp | |
9380 | index 7e34176..00aae6b 100644 | |
9381 | --- a/src/gui/DatabaseOpenWidget.cpp | |
9382 | +++ b/src/gui/DatabaseOpenWidget.cpp | |
9383 | @@ -30,7 +30,7 @@ | |
9384 | DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent) | |
9385 | : DialogyWidget(parent) | |
9386 | , m_ui(new Ui::DatabaseOpenWidget()) | |
9387 | - , m_db(Q_NULLPTR) | |
9388 | + , m_db(nullptr) | |
9389 | { | |
9390 | m_ui->setupUi(this); | |
9391 | ||
9392 | diff --git a/src/gui/DatabaseOpenWidget.h b/src/gui/DatabaseOpenWidget.h | |
9393 | index 9c9a062..ba55e4c 100644 | |
9394 | --- a/src/gui/DatabaseOpenWidget.h | |
9395 | +++ b/src/gui/DatabaseOpenWidget.h | |
9396 | @@ -35,7 +35,7 @@ class DatabaseOpenWidget : public DialogyWidget | |
9397 | Q_OBJECT | |
9398 | ||
9399 | public: | |
9400 | - explicit DatabaseOpenWidget(QWidget* parent = Q_NULLPTR); | |
9401 | + explicit DatabaseOpenWidget(QWidget* parent = nullptr); | |
9402 | ~DatabaseOpenWidget(); | |
9403 | void load(const QString& filename); | |
9404 | void enterKey(const QString& pw, const QString& keyFile); | |
9405 | diff --git a/src/gui/DatabaseRepairWidget.h b/src/gui/DatabaseRepairWidget.h | |
9406 | index 56c5c96..6775d2d 100644 | |
9407 | --- a/src/gui/DatabaseRepairWidget.h | |
9408 | +++ b/src/gui/DatabaseRepairWidget.h | |
9409 | @@ -25,14 +25,14 @@ class DatabaseRepairWidget : public DatabaseOpenWidget | |
9410 | Q_OBJECT | |
9411 | ||
9412 | public: | |
9413 | - explicit DatabaseRepairWidget(QWidget* parent = Q_NULLPTR); | |
9414 | + explicit DatabaseRepairWidget(QWidget* parent = nullptr); | |
9415 | ||
9416 | Q_SIGNALS: | |
9417 | void success(); | |
9418 | void error(); | |
9419 | ||
9420 | protected: | |
9421 | - void openDatabase() Q_DECL_OVERRIDE; | |
9422 | + void openDatabase() override; | |
9423 | ||
9424 | private Q_SLOTS: | |
9425 | void processEditFinished(bool result); | |
9426 | diff --git a/src/gui/DatabaseSettingsWidget.cpp b/src/gui/DatabaseSettingsWidget.cpp | |
9427 | index 007c44a..d4ca8dd 100644 | |
9428 | --- a/src/gui/DatabaseSettingsWidget.cpp | |
9429 | +++ b/src/gui/DatabaseSettingsWidget.cpp | |
9430 | @@ -26,7 +26,7 @@ | |
9431 | DatabaseSettingsWidget::DatabaseSettingsWidget(QWidget* parent) | |
9432 | : DialogyWidget(parent) | |
9433 | , m_ui(new Ui::DatabaseSettingsWidget()) | |
9434 | - , m_db(Q_NULLPTR) | |
9435 | + , m_db(nullptr) | |
9436 | { | |
9437 | m_ui->setupUi(this); | |
9438 | ||
9439 | diff --git a/src/gui/DatabaseSettingsWidget.h b/src/gui/DatabaseSettingsWidget.h | |
9440 | index a7d2832..040e0db 100644 | |
9441 | --- a/src/gui/DatabaseSettingsWidget.h | |
9442 | +++ b/src/gui/DatabaseSettingsWidget.h | |
9443 | @@ -33,7 +33,7 @@ class DatabaseSettingsWidget : public DialogyWidget | |
9444 | Q_OBJECT | |
9445 | ||
9446 | public: | |
9447 | - explicit DatabaseSettingsWidget(QWidget* parent = Q_NULLPTR); | |
9448 | + explicit DatabaseSettingsWidget(QWidget* parent = nullptr); | |
9449 | ~DatabaseSettingsWidget(); | |
9450 | ||
9451 | void load(Database* db); | |
9452 | diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp | |
9453 | index 3d03093..69b4f7e 100644 | |
9454 | --- a/src/gui/DatabaseTabWidget.cpp | |
9455 | +++ b/src/gui/DatabaseTabWidget.cpp | |
9456 | @@ -18,6 +18,8 @@ | |
9457 | #include "DatabaseTabWidget.h" | |
9458 | ||
9459 | #include <QFileInfo> | |
9460 | +#include <QLockFile> | |
9461 | +#include <QSaveFile> | |
9462 | #include <QTabWidget> | |
9463 | ||
9464 | #include "autotype/AutoType.h" | |
9465 | @@ -25,7 +27,6 @@ | |
9466 | #include "core/Database.h" | |
9467 | #include "core/Group.h" | |
9468 | #include "core/Metadata.h" | |
9469 | -#include "core/qsavefile.h" | |
9470 | #include "format/CsvExporter.h" | |
9471 | #include "gui/Clipboard.h" | |
9472 | #include "gui/DatabaseWidget.h" | |
9473 | @@ -37,8 +38,8 @@ | |
9474 | #include "gui/group/GroupView.h" | |
9475 | ||
9476 | DatabaseManagerStruct::DatabaseManagerStruct() | |
9477 | - : dbWidget(Q_NULLPTR) | |
9478 | - , lockFile(Q_NULLPTR) | |
9479 | + : dbWidget(nullptr) | |
9480 | + , lockFile(nullptr) | |
9481 | , saveToFilename(false) | |
9482 | , modified(false) | |
9483 | , readOnly(false) | |
9484 | @@ -160,7 +161,7 @@ void DatabaseTabWidget::openDatabase(const QString& fileName, const QString& pw, | |
9485 | if (result == QMessageBox::No) { | |
9486 | dbStruct.readOnly = true; | |
9487 | delete lockFile; | |
9488 | - lockFile = Q_NULLPTR; | |
9489 | + lockFile = nullptr; | |
9490 | } | |
9491 | else { | |
9492 | // take over the lock file if possible | |
9493 | @@ -332,7 +333,7 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db) | |
9494 | } | |
9495 | QString fileName = fileDialog()->getSaveFileName(this, tr("Save database as"), | |
9496 | oldFileName, tr("KeePass 2 Database").append(" (*.kdbx)"), | |
9497 | - Q_NULLPTR, 0, "kdbx"); | |
9498 | + nullptr, 0, "kdbx"); | |
9499 | if (!fileName.isEmpty()) { | |
9500 | QFileInfo fileInfo(fileName); | |
9501 | QString lockFilePath; | |
9502 | @@ -453,7 +454,7 @@ void DatabaseTabWidget::exportToCsv() | |
9503 | ||
9504 | QString fileName = fileDialog()->getSaveFileName(this, tr("Export database to CSV file"), | |
9505 | QString(), tr("CSV file").append(" (*.csv)"), | |
9506 | - Q_NULLPTR, 0, "csv"); | |
9507 | + nullptr, 0, "csv"); | |
9508 | if (fileName.isEmpty()) { | |
9509 | return; | |
9510 | } | |
9511 | @@ -558,7 +559,7 @@ Database* DatabaseTabWidget::indexDatabase(int index) | |
9512 | } | |
9513 | } | |
9514 | ||
9515 | - return Q_NULLPTR; | |
9516 | + return nullptr; | |
9517 | } | |
9518 | ||
9519 | DatabaseManagerStruct DatabaseTabWidget::indexDatabaseManagerStruct(int index) | |
9520 | @@ -586,7 +587,7 @@ Database* DatabaseTabWidget::databaseFromDatabaseWidget(DatabaseWidget* dbWidget | |
9521 | } | |
9522 | } | |
9523 | ||
9524 | - return Q_NULLPTR; | |
9525 | + return nullptr; | |
9526 | } | |
9527 | ||
9528 | void DatabaseTabWidget::insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct) | |
9529 | @@ -611,7 +612,7 @@ DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget() | |
9530 | return m_dbList[db].dbWidget; | |
9531 | } | |
9532 | else { | |
9533 | - return Q_NULLPTR; | |
9534 | + return nullptr; | |
9535 | } | |
9536 | } | |
9537 | ||
9538 | diff --git a/src/gui/DatabaseTabWidget.h b/src/gui/DatabaseTabWidget.h | |
9539 | index c15408d..de4a9ca 100644 | |
9540 | --- a/src/gui/DatabaseTabWidget.h | |
9541 | +++ b/src/gui/DatabaseTabWidget.h | |
9542 | @@ -21,7 +21,6 @@ | |
9543 | #include <QHash> | |
9544 | #include <QTabWidget> | |
9545 | ||
9546 | -#include "core/qlockfile.h" | |
9547 | #include "format/KeePass2Writer.h" | |
9548 | #include "gui/DatabaseWidget.h" | |
9549 | ||
9550 | @@ -29,6 +28,7 @@ class DatabaseWidget; | |
9551 | class DatabaseWidgetStateSync; | |
9552 | class DatabaseOpenWidget; | |
9553 | class QFile; | |
9554 | +class QLockFile; | |
9555 | ||
9556 | struct DatabaseManagerStruct | |
9557 | { | |
9558 | @@ -51,7 +51,7 @@ class DatabaseTabWidget : public QTabWidget | |
9559 | Q_OBJECT | |
9560 | ||
9561 | public: | |
9562 | - explicit DatabaseTabWidget(QWidget* parent = Q_NULLPTR); | |
9563 | + explicit DatabaseTabWidget(QWidget* parent = nullptr); | |
9564 | ~DatabaseTabWidget(); | |
9565 | void openDatabase(const QString& fileName, const QString& pw = QString(), | |
9566 | const QString& keyFile = QString()); | |
9567 | @@ -101,7 +101,7 @@ private: | |
9568 | Database* databaseFromDatabaseWidget(DatabaseWidget* dbWidget); | |
9569 | void insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct); | |
9570 | void updateLastDatabases(const QString& filename); | |
9571 | - void connectDatabase(Database* newDb, Database* oldDb = Q_NULLPTR); | |
9572 | + void connectDatabase(Database* newDb, Database* oldDb = nullptr); | |
9573 | ||
9574 | KeePass2Writer m_writer; | |
9575 | QHash<Database*, DatabaseManagerStruct> m_dbList; | |
9576 | diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp | |
9577 | index 8de842f..3bca6fa 100644 | |
9578 | --- a/src/gui/DatabaseWidget.cpp | |
9579 | +++ b/src/gui/DatabaseWidget.cpp | |
9580 | @@ -52,9 +52,9 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) | |
9581 | , m_db(db) | |
9582 | , m_searchUi(new Ui::SearchWidget()) | |
9583 | , m_searchWidget(new QWidget()) | |
9584 | - , m_newGroup(Q_NULLPTR) | |
9585 | - , m_newEntry(Q_NULLPTR) | |
9586 | - , m_newParent(Q_NULLPTR) | |
9587 | + , m_newGroup(nullptr) | |
9588 | + , m_newEntry(nullptr) | |
9589 | + , m_newParent(nullptr) | |
9590 | { | |
9591 | m_searchUi->setupUi(m_searchWidget); | |
9592 | ||
9593 | @@ -175,7 +175,7 @@ DatabaseWidget::~DatabaseWidget() | |
9594 | ||
9595 | DatabaseWidget::Mode DatabaseWidget::currentMode() const | |
9596 | { | |
9597 | - if (currentWidget() == Q_NULLPTR) { | |
9598 | + if (currentWidget() == nullptr) { | |
9599 | return DatabaseWidget::None; | |
9600 | } | |
9601 | else if (currentWidget() == m_mainWidget) { | |
9602 | @@ -554,8 +554,8 @@ void DatabaseWidget::switchToView(bool accepted) | |
9603 | delete m_newGroup; | |
9604 | } | |
9605 | ||
9606 | - m_newGroup = Q_NULLPTR; | |
9607 | - m_newParent = Q_NULLPTR; | |
9608 | + m_newGroup = nullptr; | |
9609 | + m_newParent = nullptr; | |
9610 | } | |
9611 | else if (m_newEntry) { | |
9612 | if (accepted) { | |
9613 | @@ -567,8 +567,8 @@ void DatabaseWidget::switchToView(bool accepted) | |
9614 | delete m_newEntry; | |
9615 | } | |
9616 | ||
9617 | - m_newEntry = Q_NULLPTR; | |
9618 | - m_newParent = Q_NULLPTR; | |
9619 | + m_newEntry = nullptr; | |
9620 | + m_newParent = nullptr; | |
9621 | } | |
9622 | ||
9623 | setCurrentWidget(m_mainWidget); | |
9624 | @@ -638,9 +638,9 @@ void DatabaseWidget::openDatabase(bool accepted) | |
9625 | // We won't need those anymore and KeePass1OpenWidget closes | |
9626 | // the file in its dtor. | |
9627 | delete m_databaseOpenWidget; | |
9628 | - m_databaseOpenWidget = Q_NULLPTR; | |
9629 | + m_databaseOpenWidget = nullptr; | |
9630 | delete m_keepass1OpenWidget; | |
9631 | - m_keepass1OpenWidget = Q_NULLPTR; | |
9632 | + m_keepass1OpenWidget = nullptr; | |
9633 | } | |
9634 | else { | |
9635 | if (m_databaseOpenWidget->database()) { | |
9636 | @@ -883,7 +883,7 @@ bool DatabaseWidget::isInSearchMode() const | |
9637 | void DatabaseWidget::clearLastGroup(Group* group) | |
9638 | { | |
9639 | if (group) { | |
9640 | - m_lastGroup = Q_NULLPTR; | |
9641 | + m_lastGroup = nullptr; | |
9642 | m_searchWidget->hide(); | |
9643 | } | |
9644 | } | |
9645 | @@ -932,7 +932,7 @@ QStringList DatabaseWidget::customEntryAttributes() const | |
9646 | ||
9647 | bool DatabaseWidget::isGroupSelected() const | |
9648 | { | |
9649 | - return m_groupView->currentGroup() != Q_NULLPTR; | |
9650 | + return m_groupView->currentGroup() != nullptr; | |
9651 | } | |
9652 | ||
9653 | bool DatabaseWidget::currentEntryHasTitle() | |
9654 | diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h | |
9655 | index a925606..38a685c 100644 | |
9656 | --- a/src/gui/DatabaseWidget.h | |
9657 | +++ b/src/gui/DatabaseWidget.h | |
9658 | @@ -21,7 +21,6 @@ | |
9659 | #include <QScopedPointer> | |
9660 | #include <QStackedWidget> | |
9661 | ||
9662 | -#include "core/Global.h" | |
9663 | #include "core/Uuid.h" | |
9664 | ||
9665 | #include "gui/entry/EntryModel.h" | |
9666 | @@ -59,7 +58,7 @@ public: | |
9667 | LockedMode | |
9668 | }; | |
9669 | ||
9670 | - explicit DatabaseWidget(Database* db, QWidget* parent = Q_NULLPTR); | |
9671 | + explicit DatabaseWidget(Database* db, QWidget* parent = nullptr); | |
9672 | ~DatabaseWidget(); | |
9673 | Database* database(); | |
9674 | bool dbHasKey() const; | |
9675 | @@ -103,7 +102,7 @@ Q_SIGNALS: | |
9676 | void entryColumnSizesChanged(); | |
9677 | ||
9678 | protected: | |
9679 | - bool eventFilter(QObject* object, QEvent* event) Q_DECL_OVERRIDE; | |
9680 | + bool eventFilter(QObject* object, QEvent* event) override; | |
9681 | ||
9682 | public Q_SLOTS: | |
9683 | void createEntry(); | |
9684 | diff --git a/src/gui/DatabaseWidgetStateSync.cpp b/src/gui/DatabaseWidgetStateSync.cpp | |
9685 | index 66b8492..430380c 100644 | |
9686 | --- a/src/gui/DatabaseWidgetStateSync.cpp | |
9687 | +++ b/src/gui/DatabaseWidgetStateSync.cpp | |
9688 | @@ -22,7 +22,7 @@ | |
9689 | ||
9690 | DatabaseWidgetStateSync::DatabaseWidgetStateSync(QObject* parent) | |
9691 | : QObject(parent) | |
9692 | - , m_activeDbWidget(Q_NULLPTR) | |
9693 | + , m_activeDbWidget(nullptr) | |
9694 | , m_blockUpdates(false) | |
9695 | { | |
9696 | m_splitterSizes = variantToIntList(config()->get("GUI/SplitterState")); | |
9697 | diff --git a/src/gui/DatabaseWidgetStateSync.h b/src/gui/DatabaseWidgetStateSync.h | |
9698 | index f6a87cd..a486117 100644 | |
9699 | --- a/src/gui/DatabaseWidgetStateSync.h | |
9700 | +++ b/src/gui/DatabaseWidgetStateSync.h | |
9701 | @@ -16,8 +16,8 @@ | |
9702 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
9703 | */ | |
9704 | ||
9705 | -#ifndef KEEPASSX_HEADERVIEWSYNC_H | |
9706 | -#define KEEPASSX_HEADERVIEWSYNC_H | |
9707 | +#ifndef KEEPASSX_DATABASEWIDGETSTATESYNC_H | |
9708 | +#define KEEPASSX_DATABASEWIDGETSTATESYNC_H | |
9709 | ||
9710 | #include "gui/DatabaseWidget.h" | |
9711 | ||
9712 | @@ -26,7 +26,7 @@ class DatabaseWidgetStateSync : public QObject | |
9713 | Q_OBJECT | |
9714 | ||
9715 | public: | |
9716 | - explicit DatabaseWidgetStateSync(QObject* parent = Q_NULLPTR); | |
9717 | + explicit DatabaseWidgetStateSync(QObject* parent = nullptr); | |
9718 | ~DatabaseWidgetStateSync(); | |
9719 | ||
9720 | public Q_SLOTS: | |
9721 | @@ -51,4 +51,4 @@ private: | |
9722 | QList<int> m_columnSizesSearch; | |
9723 | }; | |
9724 | ||
9725 | -#endif // KEEPASSX_HEADERVIEWSYNC_H | |
9726 | +#endif // KEEPASSX_DATABASEWIDGETSTATESYNC_H | |
9727 | diff --git a/src/gui/DialogyWidget.h b/src/gui/DialogyWidget.h | |
9728 | index 9dd0528..b0915a2 100644 | |
9729 | --- a/src/gui/DialogyWidget.h | |
9730 | +++ b/src/gui/DialogyWidget.h | |
9731 | @@ -21,17 +21,15 @@ | |
9732 | #include <QDialogButtonBox> | |
9733 | #include <QWidget> | |
9734 | ||
9735 | -#include "core/Global.h" | |
9736 | - | |
9737 | class DialogyWidget : public QWidget | |
9738 | { | |
9739 | Q_OBJECT | |
9740 | ||
9741 | public: | |
9742 | - explicit DialogyWidget(QWidget* parent = Q_NULLPTR); | |
9743 | + explicit DialogyWidget(QWidget* parent = nullptr); | |
9744 | ||
9745 | protected: | |
9746 | - virtual void keyPressEvent(QKeyEvent* e) Q_DECL_OVERRIDE; | |
9747 | + void keyPressEvent(QKeyEvent* e) override; | |
9748 | ||
9749 | private: | |
9750 | bool clickButton(QDialogButtonBox::StandardButton standardButton); | |
9751 | diff --git a/src/gui/DragTabBar.h b/src/gui/DragTabBar.h | |
9752 | index 1b6005d..a6117a0 100644 | |
9753 | --- a/src/gui/DragTabBar.h | |
9754 | +++ b/src/gui/DragTabBar.h | |
9755 | @@ -20,21 +20,19 @@ | |
9756 | ||
9757 | #include <QTabBar> | |
9758 | ||
9759 | -#include "core/Global.h" | |
9760 | - | |
9761 | class DragTabBar : public QTabBar | |
9762 | { | |
9763 | Q_OBJECT | |
9764 | ||
9765 | public: | |
9766 | - explicit DragTabBar(QWidget* parent = Q_NULLPTR); | |
9767 | + explicit DragTabBar(QWidget* parent = nullptr); | |
9768 | ||
9769 | protected: | |
9770 | - void dragEnterEvent(QDragEnterEvent* event) Q_DECL_OVERRIDE; | |
9771 | - void dragMoveEvent(QDragMoveEvent* event) Q_DECL_OVERRIDE; | |
9772 | - void dragLeaveEvent(QDragLeaveEvent* event) Q_DECL_OVERRIDE; | |
9773 | - void dropEvent(QDropEvent* event) Q_DECL_OVERRIDE; | |
9774 | - void tabLayoutChange() Q_DECL_OVERRIDE; | |
9775 | + void dragEnterEvent(QDragEnterEvent* event) override; | |
9776 | + void dragMoveEvent(QDragMoveEvent* event) override; | |
9777 | + void dragLeaveEvent(QDragLeaveEvent* event) override; | |
9778 | + void dropEvent(QDropEvent* event) override; | |
9779 | + void tabLayoutChange() override; | |
9780 | ||
9781 | private Q_SLOTS: | |
9782 | void dragSwitchTab(); | |
9783 | diff --git a/src/gui/EditWidget.h b/src/gui/EditWidget.h | |
9784 | index d27abe9..c5f507a 100644 | |
9785 | --- a/src/gui/EditWidget.h | |
9786 | +++ b/src/gui/EditWidget.h | |
9787 | @@ -33,7 +33,7 @@ class EditWidget : public DialogyWidget | |
9788 | Q_OBJECT | |
9789 | ||
9790 | public: | |
9791 | - explicit EditWidget(QWidget* parent = Q_NULLPTR); | |
9792 | + explicit EditWidget(QWidget* parent = nullptr); | |
9793 | ~EditWidget(); | |
9794 | ||
9795 | void add(const QString& labelText, QWidget* widget); | |
9796 | diff --git a/src/gui/EditWidgetIcons.cpp b/src/gui/EditWidgetIcons.cpp | |
9797 | index c408940..3d3565c 100644 | |
9798 | --- a/src/gui/EditWidgetIcons.cpp | |
9799 | +++ b/src/gui/EditWidgetIcons.cpp | |
9800 | @@ -35,7 +35,7 @@ IconStruct::IconStruct() | |
9801 | EditWidgetIcons::EditWidgetIcons(QWidget* parent) | |
9802 | : QWidget(parent) | |
9803 | , m_ui(new Ui::EditWidgetIcons()) | |
9804 | - , m_database(Q_NULLPTR) | |
9805 | + , m_database(nullptr) | |
9806 | , m_defaultIconModel(new DefaultIconModel(this)) | |
9807 | , m_customIconModel(new CustomIconModel(this)) | |
9808 | { | |
9809 | @@ -85,7 +85,7 @@ IconStruct EditWidgetIcons::save() | |
9810 | } | |
9811 | } | |
9812 | ||
9813 | - m_database = Q_NULLPTR; | |
9814 | + m_database = nullptr; | |
9815 | m_currentUuid = Uuid(); | |
9816 | return iconStruct; | |
9817 | } | |
9818 | diff --git a/src/gui/EditWidgetIcons.h b/src/gui/EditWidgetIcons.h | |
9819 | index e18f444..f3f3f11 100644 | |
9820 | --- a/src/gui/EditWidgetIcons.h | |
9821 | +++ b/src/gui/EditWidgetIcons.h | |
9822 | @@ -20,7 +20,6 @@ | |
9823 | ||
9824 | #include <QWidget> | |
9825 | ||
9826 | -#include "core/Global.h" | |
9827 | #include "core/Uuid.h" | |
9828 | ||
9829 | class Database; | |
9830 | @@ -44,7 +43,7 @@ class EditWidgetIcons : public QWidget | |
9831 | Q_OBJECT | |
9832 | ||
9833 | public: | |
9834 | - explicit EditWidgetIcons(QWidget* parent = Q_NULLPTR); | |
9835 | + explicit EditWidgetIcons(QWidget* parent = nullptr); | |
9836 | ~EditWidgetIcons(); | |
9837 | ||
9838 | IconStruct save(); | |
9839 | diff --git a/src/gui/EditWidgetProperties.h b/src/gui/EditWidgetProperties.h | |
9840 | index c5d0eb0..4a2c059 100644 | |
9841 | --- a/src/gui/EditWidgetProperties.h | |
9842 | +++ b/src/gui/EditWidgetProperties.h | |
9843 | @@ -20,7 +20,6 @@ | |
9844 | ||
9845 | #include <QWidget> | |
9846 | ||
9847 | -#include "core/Global.h" | |
9848 | #include "core/TimeInfo.h" | |
9849 | #include "core/Uuid.h" | |
9850 | ||
9851 | @@ -33,7 +32,7 @@ class EditWidgetProperties : public QWidget | |
9852 | Q_OBJECT | |
9853 | ||
9854 | public: | |
9855 | - explicit EditWidgetProperties(QWidget* parent = Q_NULLPTR); | |
9856 | + explicit EditWidgetProperties(QWidget* parent = nullptr); | |
9857 | ~EditWidgetProperties(); | |
9858 | ||
9859 | void setFields(TimeInfo timeInfo, Uuid uuid); | |
9860 | diff --git a/src/gui/FileDialog.cpp b/src/gui/FileDialog.cpp | |
9861 | index 8448258..e293db2 100644 | |
9862 | --- a/src/gui/FileDialog.cpp | |
9863 | +++ b/src/gui/FileDialog.cpp | |
9864 | @@ -19,7 +19,7 @@ | |
9865 | ||
9866 | #include "core/Config.h" | |
9867 | ||
9868 | -FileDialog* FileDialog::m_instance(Q_NULLPTR); | |
9869 | +FileDialog* FileDialog::m_instance(nullptr); | |
9870 | ||
9871 | QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, QString dir, | |
9872 | const QString& filter, QString* selectedFilter, | |
9873 | diff --git a/src/gui/FileDialog.h b/src/gui/FileDialog.h | |
9874 | index 46c6353..9f8fbb5 100644 | |
9875 | --- a/src/gui/FileDialog.h | |
9876 | +++ b/src/gui/FileDialog.h | |
9877 | @@ -20,17 +20,15 @@ | |
9878 | ||
9879 | #include <QFileDialog> | |
9880 | ||
9881 | -#include "core/Global.h" | |
9882 | - | |
9883 | class FileDialog | |
9884 | { | |
9885 | public: | |
9886 | - QString getOpenFileName(QWidget* parent = Q_NULLPTR, const QString& caption = QString(), | |
9887 | + QString getOpenFileName(QWidget* parent = nullptr, const QString& caption = QString(), | |
9888 | QString dir = QString(), const QString& filter = QString(), | |
9889 | - QString* selectedFilter = Q_NULLPTR, QFileDialog::Options options = 0); | |
9890 | - QString getSaveFileName(QWidget* parent = Q_NULLPTR, const QString& caption = QString(), | |
9891 | + QString* selectedFilter = nullptr, QFileDialog::Options options = 0); | |
9892 | + QString getSaveFileName(QWidget* parent = nullptr, const QString& caption = QString(), | |
9893 | QString dir = QString(), const QString& filter = QString(), | |
9894 | - QString* selectedFilter = Q_NULLPTR, QFileDialog::Options options = 0, | |
9895 | + QString* selectedFilter = nullptr, QFileDialog::Options options = 0, | |
9896 | const QString& defaultExtension = QString()); | |
9897 | ||
9898 | /** | |
9899 | diff --git a/src/gui/IconModels.h b/src/gui/IconModels.h | |
9900 | index 8a24707..868ce44 100644 | |
9901 | --- a/src/gui/IconModels.h | |
9902 | +++ b/src/gui/IconModels.h | |
9903 | @@ -21,7 +21,6 @@ | |
9904 | #include <QAbstractListModel> | |
9905 | #include <QPixmap> | |
9906 | ||
9907 | -#include "core/Global.h" | |
9908 | #include "core/Uuid.h" | |
9909 | ||
9910 | class DefaultIconModel : public QAbstractListModel | |
9911 | @@ -29,10 +28,10 @@ class DefaultIconModel : public QAbstractListModel | |
9912 | Q_OBJECT | |
9913 | ||
9914 | public: | |
9915 | - explicit DefaultIconModel(QObject* parent = Q_NULLPTR); | |
9916 | + explicit DefaultIconModel(QObject* parent = nullptr); | |
9917 | ||
9918 | - int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
9919 | - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
9920 | + int rowCount(const QModelIndex& parent = QModelIndex()) const override; | |
9921 | + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
9922 | }; | |
9923 | ||
9924 | class CustomIconModel : public QAbstractListModel | |
9925 | @@ -40,10 +39,10 @@ class CustomIconModel : public QAbstractListModel | |
9926 | Q_OBJECT | |
9927 | ||
9928 | public: | |
9929 | - explicit CustomIconModel(QObject* parent = Q_NULLPTR); | |
9930 | + explicit CustomIconModel(QObject* parent = nullptr); | |
9931 | ||
9932 | - virtual int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
9933 | - virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
9934 | + int rowCount(const QModelIndex& parent = QModelIndex()) const override; | |
9935 | + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
9936 | void setIcons(const QHash<Uuid, QPixmap>& icons, const QList<Uuid>& iconsOrder); | |
9937 | Uuid uuidFromIndex(const QModelIndex& index) const; | |
9938 | QModelIndex indexFromUuid(const Uuid& uuid) const; | |
9939 | diff --git a/src/gui/KeePass1OpenWidget.h b/src/gui/KeePass1OpenWidget.h | |
9940 | index a398f9a..203b786 100644 | |
9941 | --- a/src/gui/KeePass1OpenWidget.h | |
9942 | +++ b/src/gui/KeePass1OpenWidget.h | |
9943 | @@ -25,10 +25,10 @@ class KeePass1OpenWidget : public DatabaseOpenWidget | |
9944 | Q_OBJECT | |
9945 | ||
9946 | public: | |
9947 | - explicit KeePass1OpenWidget(QWidget* parent = Q_NULLPTR); | |
9948 | + explicit KeePass1OpenWidget(QWidget* parent = nullptr); | |
9949 | ||
9950 | protected: | |
9951 | - void openDatabase() Q_DECL_OVERRIDE; | |
9952 | + void openDatabase() override; | |
9953 | }; | |
9954 | ||
9955 | #endif // KEEPASSX_KEEPASS1OPENWIDGET_H | |
9956 | diff --git a/src/gui/LineEdit.h b/src/gui/LineEdit.h | |
9957 | index 2672aae..f5f0584 100644 | |
9958 | --- a/src/gui/LineEdit.h | |
9959 | +++ b/src/gui/LineEdit.h | |
9960 | @@ -22,8 +22,6 @@ | |
9961 | ||
9962 | #include <QLineEdit> | |
9963 | ||
9964 | -#include "core/Global.h" | |
9965 | - | |
9966 | class QToolButton; | |
9967 | ||
9968 | class LineEdit : public QLineEdit | |
9969 | @@ -31,10 +29,10 @@ class LineEdit : public QLineEdit | |
9970 | Q_OBJECT | |
9971 | ||
9972 | public: | |
9973 | - explicit LineEdit(QWidget* parent = Q_NULLPTR); | |
9974 | + explicit LineEdit(QWidget* parent = nullptr); | |
9975 | ||
9976 | protected: | |
9977 | - void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE; | |
9978 | + void resizeEvent(QResizeEvent* event) override; | |
9979 | ||
9980 | private Q_SLOTS: | |
9981 | void updateCloseButton(const QString& text); | |
9982 | diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp | |
9983 | index b6dc1df..6245dc7 100644 | |
9984 | --- a/src/gui/MainWindow.cpp | |
9985 | +++ b/src/gui/MainWindow.cpp | |
9986 | @@ -38,7 +38,7 @@ const QString MainWindow::BaseWindowTitle = "KeePassX"; | |
9987 | ||
9988 | MainWindow::MainWindow() | |
9989 | : m_ui(new Ui::MainWindow()) | |
9990 | - , m_trayIcon(Q_NULLPTR) | |
9991 | + , m_trayIcon(nullptr) | |
9992 | { | |
9993 | m_ui->setupUi(this); | |
9994 | ||
9995 | @@ -227,6 +227,7 @@ void MainWindow::updateLastDatabasesMenu() | |
9996 | QStringList lastDatabases = config()->get("LastDatabases", QVariant()).toStringList(); | |
9997 | Q_FOREACH (const QString& database, lastDatabases) { | |
9998 | QAction* action = m_ui->menuRecentDatabases->addAction(database); | |
9999 | + action->setData(database); | |
10000 | m_lastDatabasesActions->addAction(action); | |
10001 | } | |
10002 | m_ui->menuRecentDatabases->addSeparator(); | |
10003 | @@ -257,7 +258,7 @@ void MainWindow::updateCopyAttributesMenu() | |
10004 | ||
10005 | void MainWindow::openRecentDatabase(QAction* action) | |
10006 | { | |
10007 | - openDatabase(action->text()); | |
10008 | + openDatabase(action->data().toString()); | |
10009 | } | |
10010 | ||
10011 | void MainWindow::clearLastDatabases() | |
10012 | @@ -450,7 +451,7 @@ void MainWindow::closeEvent(QCloseEvent* event) | |
10013 | } | |
10014 | } | |
10015 | ||
10016 | -void MainWindow::changeEvent(QEvent *event) | |
10017 | +void MainWindow::changeEvent(QEvent* event) | |
10018 | { | |
10019 | if ((event->type() == QEvent::WindowStateChange) && isMinimized() | |
10020 | && isTrayIconEnabled() && m_trayIcon && m_trayIcon->isVisible() | |
10021 | @@ -521,7 +522,7 @@ void MainWindow::updateTrayIcon() | |
10022 | if (m_trayIcon) { | |
10023 | m_trayIcon->hide(); | |
10024 | delete m_trayIcon; | |
10025 | - m_trayIcon = Q_NULLPTR; | |
10026 | + m_trayIcon = nullptr; | |
10027 | } | |
10028 | } | |
10029 | } | |
10030 | @@ -622,7 +623,7 @@ void MainWindow::repairDatabase() | |
10031 | if (dialog->exec() == QDialog::Accepted && dbRepairWidget->database()) { | |
10032 | QString saveFileName = fileDialog()->getSaveFileName(this, tr("Save repaired database"), QString(), | |
10033 | tr("KeePass 2 Database").append(" (*.kdbx)"), | |
10034 | - Q_NULLPTR, 0, "kdbx"); | |
10035 | + nullptr, 0, "kdbx"); | |
10036 | ||
10037 | if (!saveFileName.isEmpty()) { | |
10038 | KeePass2Writer writer; | |
10039 | diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h | |
10040 | index 5aa39ca..c52cfba 100644 | |
10041 | --- a/src/gui/MainWindow.h | |
10042 | +++ b/src/gui/MainWindow.h | |
10043 | @@ -44,8 +44,8 @@ public Q_SLOTS: | |
10044 | const QString& keyFile = QString()); | |
10045 | ||
10046 | protected: | |
10047 | - void closeEvent(QCloseEvent* event) Q_DECL_OVERRIDE; | |
10048 | - void changeEvent(QEvent* event) Q_DECL_OVERRIDE; | |
10049 | + void closeEvent(QCloseEvent* event) override; | |
10050 | + void changeEvent(QEvent* event) override; | |
10051 | ||
10052 | private Q_SLOTS: | |
10053 | void setMenuActionState(DatabaseWidget::Mode mode = DatabaseWidget::None); | |
10054 | diff --git a/src/gui/MessageBox.h b/src/gui/MessageBox.h | |
10055 | index abb12c0..1ea4022 100644 | |
10056 | --- a/src/gui/MessageBox.h | |
10057 | +++ b/src/gui/MessageBox.h | |
10058 | @@ -20,8 +20,6 @@ | |
10059 | ||
10060 | #include <QMessageBox> | |
10061 | ||
10062 | -#include "core/Global.h" | |
10063 | - | |
10064 | class MessageBox | |
10065 | { | |
10066 | public: | |
10067 | diff --git a/src/gui/PasswordComboBox.cpp b/src/gui/PasswordComboBox.cpp | |
10068 | index f11311a..e121850 100644 | |
10069 | --- a/src/gui/PasswordComboBox.cpp | |
10070 | +++ b/src/gui/PasswordComboBox.cpp | |
10071 | @@ -24,7 +24,7 @@ | |
10072 | ||
10073 | PasswordComboBox::PasswordComboBox(QWidget* parent) | |
10074 | : QComboBox(parent) | |
10075 | - , m_generator(Q_NULLPTR) | |
10076 | + , m_generator(nullptr) | |
10077 | , m_alternatives(10) | |
10078 | { | |
10079 | setEditable(true); | |
10080 | @@ -51,7 +51,6 @@ void PasswordComboBox::setEcho(bool echo) | |
10081 | #else | |
10082 | setStyleSheet("QComboBox { font-family: monospace,Courier; }"); | |
10083 | #endif | |
10084 | - | |
10085 | } | |
10086 | else { | |
10087 | // clear items so the combobox indicates that no popup menu is available | |
10088 | diff --git a/src/gui/PasswordComboBox.h b/src/gui/PasswordComboBox.h | |
10089 | index 69ce152..7c54e27 100644 | |
10090 | --- a/src/gui/PasswordComboBox.h | |
10091 | +++ b/src/gui/PasswordComboBox.h | |
10092 | @@ -21,8 +21,6 @@ | |
10093 | ||
10094 | #include <QComboBox> | |
10095 | ||
10096 | -#include "core/Global.h" | |
10097 | - | |
10098 | class PasswordGenerator; | |
10099 | ||
10100 | class PasswordComboBox : public QComboBox | |
10101 | @@ -30,7 +28,7 @@ class PasswordComboBox : public QComboBox | |
10102 | Q_OBJECT | |
10103 | ||
10104 | public: | |
10105 | - explicit PasswordComboBox(QWidget* parent = Q_NULLPTR); | |
10106 | + explicit PasswordComboBox(QWidget* parent = nullptr); | |
10107 | ~PasswordComboBox(); | |
10108 | ||
10109 | void setGenerator(PasswordGenerator* generator); | |
10110 | diff --git a/src/gui/PasswordEdit.cpp b/src/gui/PasswordEdit.cpp | |
10111 | index b68eef6..e5bbf6b 100644 | |
10112 | --- a/src/gui/PasswordEdit.cpp | |
10113 | +++ b/src/gui/PasswordEdit.cpp | |
10114 | @@ -17,14 +17,12 @@ | |
10115 | ||
10116 | #include "PasswordEdit.h" | |
10117 | ||
10118 | -#include "core/Global.h" | |
10119 | - | |
10120 | const QColor PasswordEdit::CorrectSoFarColor = QColor(255, 205, 15); | |
10121 | const QColor PasswordEdit::ErrorColor = QColor(255, 125, 125); | |
10122 | ||
10123 | PasswordEdit::PasswordEdit(QWidget* parent) | |
10124 | : QLineEdit(parent) | |
10125 | - , m_basePasswordEdit(Q_NULLPTR) | |
10126 | + , m_basePasswordEdit(nullptr) | |
10127 | { | |
10128 | } | |
10129 | ||
10130 | diff --git a/src/gui/PasswordEdit.h b/src/gui/PasswordEdit.h | |
10131 | index cfb4a76..7ce4908 100644 | |
10132 | --- a/src/gui/PasswordEdit.h | |
10133 | +++ b/src/gui/PasswordEdit.h | |
10134 | @@ -20,8 +20,6 @@ | |
10135 | ||
10136 | #include <QLineEdit> | |
10137 | ||
10138 | -#include "core/Global.h" | |
10139 | - | |
10140 | class PasswordEdit : public QLineEdit | |
10141 | { | |
10142 | Q_OBJECT | |
10143 | @@ -30,7 +28,7 @@ public: | |
10144 | static const QColor CorrectSoFarColor; | |
10145 | static const QColor ErrorColor; | |
10146 | ||
10147 | - explicit PasswordEdit(QWidget* parent = Q_NULLPTR); | |
10148 | + explicit PasswordEdit(QWidget* parent = nullptr); | |
10149 | void enableVerifyMode(PasswordEdit* baseEdit); | |
10150 | ||
10151 | public Q_SLOTS: | |
10152 | diff --git a/src/gui/PasswordGeneratorWidget.h b/src/gui/PasswordGeneratorWidget.h | |
10153 | index 96f3f60..cfb21bb 100644 | |
10154 | --- a/src/gui/PasswordGeneratorWidget.h | |
10155 | +++ b/src/gui/PasswordGeneratorWidget.h | |
10156 | @@ -21,7 +21,6 @@ | |
10157 | #include <QWidget> | |
10158 | #include <QComboBox> | |
10159 | ||
10160 | -#include "core/Global.h" | |
10161 | #include "core/PasswordGenerator.h" | |
10162 | ||
10163 | namespace Ui { | |
10164 | @@ -35,7 +34,7 @@ class PasswordGeneratorWidget : public QWidget | |
10165 | Q_OBJECT | |
10166 | ||
10167 | public: | |
10168 | - explicit PasswordGeneratorWidget(QWidget* parent = Q_NULLPTR); | |
10169 | + explicit PasswordGeneratorWidget(QWidget* parent = nullptr); | |
10170 | ~PasswordGeneratorWidget(); | |
10171 | void loadSettings(); | |
10172 | void reset(); | |
10173 | diff --git a/src/gui/SettingsWidget.h b/src/gui/SettingsWidget.h | |
10174 | index cefbf6d..3fe621d 100644 | |
10175 | --- a/src/gui/SettingsWidget.h | |
10176 | +++ b/src/gui/SettingsWidget.h | |
10177 | @@ -30,7 +30,7 @@ class SettingsWidget : public EditWidget | |
10178 | Q_OBJECT | |
10179 | ||
10180 | public: | |
10181 | - explicit SettingsWidget(QWidget* parent = Q_NULLPTR); | |
10182 | + explicit SettingsWidget(QWidget* parent = nullptr); | |
10183 | ~SettingsWidget(); | |
10184 | void loadSettings(); | |
10185 | ||
10186 | diff --git a/src/gui/SortFilterHideProxyModel.cpp b/src/gui/SortFilterHideProxyModel.cpp | |
10187 | index 0902361..0193d95 100644 | |
10188 | --- a/src/gui/SortFilterHideProxyModel.cpp | |
10189 | +++ b/src/gui/SortFilterHideProxyModel.cpp | |
10190 | @@ -22,6 +22,11 @@ SortFilterHideProxyModel::SortFilterHideProxyModel(QObject* parent) | |
10191 | { | |
10192 | } | |
10193 | ||
10194 | +Qt::DropActions SortFilterHideProxyModel::supportedDragActions() const | |
10195 | +{ | |
10196 | + return sourceModel()->supportedDragActions(); | |
10197 | +} | |
10198 | + | |
10199 | void SortFilterHideProxyModel::hideColumn(int column, bool hide) | |
10200 | { | |
10201 | m_hiddenColumns.resize(column + 1); | |
10202 | diff --git a/src/gui/SortFilterHideProxyModel.h b/src/gui/SortFilterHideProxyModel.h | |
10203 | index a6f1e71..58d9ff7 100644 | |
10204 | --- a/src/gui/SortFilterHideProxyModel.h | |
10205 | +++ b/src/gui/SortFilterHideProxyModel.h | |
10206 | @@ -21,18 +21,17 @@ | |
10207 | #include <QBitArray> | |
10208 | #include <QSortFilterProxyModel> | |
10209 | ||
10210 | -#include "core/Global.h" | |
10211 | - | |
10212 | class SortFilterHideProxyModel : public QSortFilterProxyModel | |
10213 | { | |
10214 | Q_OBJECT | |
10215 | ||
10216 | public: | |
10217 | - explicit SortFilterHideProxyModel(QObject* parent = Q_NULLPTR); | |
10218 | + explicit SortFilterHideProxyModel(QObject* parent = nullptr); | |
10219 | + Qt::DropActions supportedDragActions() const override; | |
10220 | void hideColumn(int column, bool hide); | |
10221 | ||
10222 | protected: | |
10223 | - bool filterAcceptsColumn(int sourceColumn, const QModelIndex& sourceParent) const Q_DECL_OVERRIDE; | |
10224 | + bool filterAcceptsColumn(int sourceColumn, const QModelIndex& sourceParent) const override; | |
10225 | ||
10226 | private: | |
10227 | QBitArray m_hiddenColumns; | |
10228 | diff --git a/src/gui/UnlockDatabaseWidget.cpp b/src/gui/UnlockDatabaseWidget.cpp | |
10229 | index 242b07a..a005d0e 100644 | |
10230 | --- a/src/gui/UnlockDatabaseWidget.cpp | |
10231 | +++ b/src/gui/UnlockDatabaseWidget.cpp | |
10232 | @@ -34,5 +34,5 @@ void UnlockDatabaseWidget::clearForms() | |
10233 | m_ui->checkPassword->setChecked(false); | |
10234 | m_ui->checkKeyFile->setChecked(false); | |
10235 | m_ui->buttonTogglePassword->setChecked(false); | |
10236 | - m_db = Q_NULLPTR; | |
10237 | + m_db = nullptr; | |
10238 | } | |
10239 | diff --git a/src/gui/UnlockDatabaseWidget.h b/src/gui/UnlockDatabaseWidget.h | |
10240 | index 052578b..adb5efb 100644 | |
10241 | --- a/src/gui/UnlockDatabaseWidget.h | |
10242 | +++ b/src/gui/UnlockDatabaseWidget.h | |
10243 | @@ -25,7 +25,7 @@ class UnlockDatabaseWidget : public DatabaseOpenWidget | |
10244 | Q_OBJECT | |
10245 | ||
10246 | public: | |
10247 | - explicit UnlockDatabaseWidget(QWidget* parent = Q_NULLPTR); | |
10248 | + explicit UnlockDatabaseWidget(QWidget* parent = nullptr); | |
10249 | void clearForms(); | |
10250 | }; | |
10251 | ||
10252 | diff --git a/src/gui/WelcomeWidget.h b/src/gui/WelcomeWidget.h | |
10253 | index 983aaa0..80a0dde 100644 | |
10254 | --- a/src/gui/WelcomeWidget.h | |
10255 | +++ b/src/gui/WelcomeWidget.h | |
10256 | @@ -20,8 +20,6 @@ | |
10257 | ||
10258 | #include <QWidget> | |
10259 | ||
10260 | -#include "core/Global.h" | |
10261 | - | |
10262 | namespace Ui { | |
10263 | class WelcomeWidget; | |
10264 | } | |
10265 | @@ -31,7 +29,7 @@ class WelcomeWidget : public QWidget | |
10266 | Q_OBJECT | |
10267 | ||
10268 | public: | |
10269 | - explicit WelcomeWidget(QWidget* parent = Q_NULLPTR); | |
10270 | + explicit WelcomeWidget(QWidget* parent = nullptr); | |
10271 | ~WelcomeWidget(); | |
10272 | ||
10273 | private: | |
10274 | diff --git a/src/gui/entry/AutoTypeAssociationsModel.cpp b/src/gui/entry/AutoTypeAssociationsModel.cpp | |
10275 | index 6d6dc97..49f6786 100644 | |
10276 | --- a/src/gui/entry/AutoTypeAssociationsModel.cpp | |
10277 | +++ b/src/gui/entry/AutoTypeAssociationsModel.cpp | |
10278 | @@ -19,7 +19,7 @@ | |
10279 | ||
10280 | AutoTypeAssociationsModel::AutoTypeAssociationsModel(QObject* parent) | |
10281 | : QAbstractListModel(parent) | |
10282 | - , m_autoTypeAssociations(Q_NULLPTR) | |
10283 | + , m_autoTypeAssociations(nullptr) | |
10284 | { | |
10285 | } | |
10286 | ||
10287 | diff --git a/src/gui/entry/AutoTypeAssociationsModel.h b/src/gui/entry/AutoTypeAssociationsModel.h | |
10288 | index ecb4247..c75168c 100644 | |
10289 | --- a/src/gui/entry/AutoTypeAssociationsModel.h | |
10290 | +++ b/src/gui/entry/AutoTypeAssociationsModel.h | |
10291 | @@ -29,12 +29,12 @@ class AutoTypeAssociationsModel : public QAbstractListModel | |
10292 | Q_OBJECT | |
10293 | ||
10294 | public: | |
10295 | - explicit AutoTypeAssociationsModel(QObject* parent = Q_NULLPTR); | |
10296 | + explicit AutoTypeAssociationsModel(QObject* parent = nullptr); | |
10297 | void setAutoTypeAssociations(AutoTypeAssociations* autoTypeAssociations); | |
10298 | - int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10299 | - int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10300 | - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
10301 | - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
10302 | + int rowCount(const QModelIndex& parent = QModelIndex()) const override; | |
10303 | + int columnCount(const QModelIndex& parent = QModelIndex()) const override; | |
10304 | + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; | |
10305 | + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
10306 | ||
10307 | public Q_SLOTS: | |
10308 | void associationChange(int i); | |
10309 | diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp | |
10310 | index 8cad924..00d510c 100644 | |
10311 | --- a/src/gui/entry/EditEntryWidget.cpp | |
10312 | +++ b/src/gui/entry/EditEntryWidget.cpp | |
10313 | @@ -23,6 +23,7 @@ | |
10314 | ||
10315 | #include <QDesktopServices> | |
10316 | #include <QStackedLayout> | |
10317 | +#include <QStandardPaths> | |
10318 | #include <QMenu> | |
10319 | #include <QSortFilterProxyModel> | |
10320 | #include <QTemporaryFile> | |
10321 | @@ -45,7 +46,7 @@ | |
10322 | ||
10323 | EditEntryWidget::EditEntryWidget(QWidget* parent) | |
10324 | : EditWidget(parent) | |
10325 | - , m_entry(Q_NULLPTR) | |
10326 | + , m_entry(nullptr) | |
10327 | , m_mainUi(new Ui::EditEntryWidgetMain()) | |
10328 | , m_advancedUi(new Ui::EditEntryWidgetAdvanced()) | |
10329 | , m_autoTypeUi(new Ui::EditEntryWidgetAutoType()) | |
10330 | @@ -232,7 +233,7 @@ void EditEntryWidget::useExpiryPreset(QAction* action) | |
10331 | { | |
10332 | m_mainUi->expireCheck->setChecked(true); | |
10333 | TimeDelta delta = action->data().value<TimeDelta>(); | |
10334 | - QDateTime now = Tools::currentDateTimeUtc().toLocalTime(); | |
10335 | + QDateTime now = QDateTime::currentDateTime(); | |
10336 | QDateTime expiryDateTime = now + delta; | |
10337 | m_mainUi->expireDatePicker->setDateTime(expiryDateTime); | |
10338 | } | |
10339 | @@ -477,8 +478,8 @@ void EditEntryWidget::cancel() | |
10340 | ||
10341 | void EditEntryWidget::clear() | |
10342 | { | |
10343 | - m_entry = Q_NULLPTR; | |
10344 | - m_database = Q_NULLPTR; | |
10345 | + m_entry = nullptr; | |
10346 | + m_database = nullptr; | |
10347 | m_entryAttributes->clear(); | |
10348 | m_entryAttachments->clear(); | |
10349 | m_autoTypeAssoc->clear(); | |
10350 | @@ -590,7 +591,7 @@ void EditEntryWidget::insertAttachment() | |
10351 | ||
10352 | QString defaultDir = config()->get("LastAttachmentDir").toString(); | |
10353 | if (defaultDir.isEmpty() || !QDir(defaultDir).exists()) { | |
10354 | - defaultDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); | |
10355 | + defaultDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).value(0); | |
10356 | } | |
10357 | QString filename = fileDialog()->getOpenFileName(this, tr("Select file"), defaultDir); | |
10358 | if (filename.isEmpty() || !QFile::exists(filename)) { | |
10359 | @@ -624,7 +625,7 @@ void EditEntryWidget::saveCurrentAttachment() | |
10360 | QString filename = m_attachmentsModel->keyByIndex(index); | |
10361 | QString defaultDirName = config()->get("LastAttachmentDir").toString(); | |
10362 | if (defaultDirName.isEmpty() || !QDir(defaultDirName).exists()) { | |
10363 | - defaultDirName = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); | |
10364 | + defaultDirName = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); | |
10365 | } | |
10366 | QDir dir(defaultDirName); | |
10367 | QString savePath = fileDialog()->getSaveFileName(this, tr("Save attachment"), | |
10368 | diff --git a/src/gui/entry/EditEntryWidget.h b/src/gui/entry/EditEntryWidget.h | |
10369 | index 03811bf..3c66b2a 100644 | |
10370 | --- a/src/gui/entry/EditEntryWidget.h | |
10371 | +++ b/src/gui/entry/EditEntryWidget.h | |
10372 | @@ -52,7 +52,7 @@ class EditEntryWidget : public EditWidget | |
10373 | Q_OBJECT | |
10374 | ||
10375 | public: | |
10376 | - explicit EditEntryWidget(QWidget* parent = Q_NULLPTR); | |
10377 | + explicit EditEntryWidget(QWidget* parent = nullptr); | |
10378 | ~EditEntryWidget(); | |
10379 | ||
10380 | void loadEntry(Entry* entry, bool create, bool history, const QString& parentName, | |
10381 | diff --git a/src/gui/entry/EntryAttachmentsModel.cpp b/src/gui/entry/EntryAttachmentsModel.cpp | |
10382 | index e072d17..39ed69f 100644 | |
10383 | --- a/src/gui/entry/EntryAttachmentsModel.cpp | |
10384 | +++ b/src/gui/entry/EntryAttachmentsModel.cpp | |
10385 | @@ -20,9 +20,11 @@ | |
10386 | #include "core/Entry.h" | |
10387 | #include "core/Tools.h" | |
10388 | ||
10389 | +#include <algorithm> | |
10390 | + | |
10391 | EntryAttachmentsModel::EntryAttachmentsModel(QObject* parent) | |
10392 | : QAbstractListModel(parent) | |
10393 | - , m_entryAttachments(Q_NULLPTR) | |
10394 | + , m_entryAttachments(nullptr) | |
10395 | { | |
10396 | } | |
10397 | ||
10398 | @@ -102,7 +104,7 @@ void EntryAttachmentsModel::attachmentAboutToAdd(const QString& key) | |
10399 | { | |
10400 | QList<QString> rows = m_entryAttachments->keys(); | |
10401 | rows.append(key); | |
10402 | - qSort(rows); | |
10403 | + std::sort(rows.begin(), rows.end()); | |
10404 | int row = rows.indexOf(key); | |
10405 | beginInsertRows(QModelIndex(), row, row); | |
10406 | } | |
10407 | diff --git a/src/gui/entry/EntryAttachmentsModel.h b/src/gui/entry/EntryAttachmentsModel.h | |
10408 | index 177cde0..c2e238a 100644 | |
10409 | --- a/src/gui/entry/EntryAttachmentsModel.h | |
10410 | +++ b/src/gui/entry/EntryAttachmentsModel.h | |
10411 | @@ -20,8 +20,6 @@ | |
10412 | ||
10413 | #include <QAbstractListModel> | |
10414 | ||
10415 | -#include "core/Global.h" | |
10416 | - | |
10417 | class EntryAttachments; | |
10418 | ||
10419 | class EntryAttachmentsModel : public QAbstractListModel | |
10420 | @@ -29,11 +27,11 @@ class EntryAttachmentsModel : public QAbstractListModel | |
10421 | Q_OBJECT | |
10422 | ||
10423 | public: | |
10424 | - explicit EntryAttachmentsModel(QObject* parent = Q_NULLPTR); | |
10425 | + explicit EntryAttachmentsModel(QObject* parent = nullptr); | |
10426 | void setEntryAttachments(EntryAttachments* entry); | |
10427 | - int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10428 | - int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10429 | - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
10430 | + int rowCount(const QModelIndex& parent = QModelIndex()) const override; | |
10431 | + int columnCount(const QModelIndex& parent = QModelIndex()) const override; | |
10432 | + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
10433 | QString keyByIndex(const QModelIndex& index) const; | |
10434 | ||
10435 | private Q_SLOTS: | |
10436 | diff --git a/src/gui/entry/EntryAttributesModel.cpp b/src/gui/entry/EntryAttributesModel.cpp | |
10437 | index f73a2d2..297740c 100644 | |
10438 | --- a/src/gui/entry/EntryAttributesModel.cpp | |
10439 | +++ b/src/gui/entry/EntryAttributesModel.cpp | |
10440 | @@ -20,9 +20,11 @@ | |
10441 | #include "core/Entry.h" | |
10442 | #include "core/Tools.h" | |
10443 | ||
10444 | +#include <algorithm> | |
10445 | + | |
10446 | EntryAttributesModel::EntryAttributesModel(QObject* parent) | |
10447 | : QAbstractListModel(parent) | |
10448 | - , m_entryAttributes(Q_NULLPTR) | |
10449 | + , m_entryAttributes(nullptr) | |
10450 | , m_nextRenameDataChange(false) | |
10451 | { | |
10452 | } | |
10453 | @@ -152,7 +154,7 @@ void EntryAttributesModel::attributeAboutToAdd(const QString& key) | |
10454 | { | |
10455 | QList<QString> rows = m_attributes; | |
10456 | rows.append(key); | |
10457 | - qSort(rows); | |
10458 | + std::sort(rows.begin(), rows.end()); | |
10459 | int row = rows.indexOf(key); | |
10460 | beginInsertRows(QModelIndex(), row, row); | |
10461 | } | |
10462 | @@ -182,7 +184,7 @@ void EntryAttributesModel::attributeAboutToRename(const QString& oldKey, const Q | |
10463 | QList<QString> rows = m_attributes; | |
10464 | rows.removeOne(oldKey); | |
10465 | rows.append(newKey); | |
10466 | - qSort(rows); | |
10467 | + std::sort(rows.begin(), rows.end()); | |
10468 | int newRow = rows.indexOf(newKey); | |
10469 | if (newRow > oldRow) { | |
10470 | newRow++; | |
10471 | diff --git a/src/gui/entry/EntryAttributesModel.h b/src/gui/entry/EntryAttributesModel.h | |
10472 | index f6ac651..1eec8bf 100644 | |
10473 | --- a/src/gui/entry/EntryAttributesModel.h | |
10474 | +++ b/src/gui/entry/EntryAttributesModel.h | |
10475 | @@ -20,8 +20,6 @@ | |
10476 | ||
10477 | #include <QAbstractListModel> | |
10478 | ||
10479 | -#include "core/Global.h" | |
10480 | - | |
10481 | class EntryAttributes; | |
10482 | ||
10483 | class EntryAttributesModel : public QAbstractListModel | |
10484 | @@ -29,14 +27,14 @@ class EntryAttributesModel : public QAbstractListModel | |
10485 | Q_OBJECT | |
10486 | ||
10487 | public: | |
10488 | - explicit EntryAttributesModel(QObject* parent = Q_NULLPTR); | |
10489 | + explicit EntryAttributesModel(QObject* parent = nullptr); | |
10490 | void setEntryAttributes(EntryAttributes* entryAttributes); | |
10491 | - int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10492 | - int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10493 | - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
10494 | - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
10495 | - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) Q_DECL_OVERRIDE; | |
10496 | - Qt::ItemFlags flags(const QModelIndex& index) const Q_DECL_OVERRIDE; | |
10497 | + int rowCount(const QModelIndex& parent = QModelIndex()) const override; | |
10498 | + int columnCount(const QModelIndex& parent = QModelIndex()) const override; | |
10499 | + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; | |
10500 | + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
10501 | + bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; | |
10502 | + Qt::ItemFlags flags(const QModelIndex& index) const override; | |
10503 | QModelIndex indexByKey(const QString& key) const; | |
10504 | QString keyByIndex(const QModelIndex& index) const; | |
10505 | ||
10506 | diff --git a/src/gui/entry/EntryHistoryModel.h b/src/gui/entry/EntryHistoryModel.h | |
10507 | index 6c8073a..a7434e0 100644 | |
10508 | --- a/src/gui/entry/EntryHistoryModel.h | |
10509 | +++ b/src/gui/entry/EntryHistoryModel.h | |
10510 | @@ -20,8 +20,6 @@ | |
10511 | ||
10512 | #include <QAbstractTableModel> | |
10513 | ||
10514 | -#include "core/Global.h" | |
10515 | - | |
10516 | class Entry; | |
10517 | ||
10518 | class EntryHistoryModel : public QAbstractTableModel | |
10519 | @@ -29,13 +27,13 @@ class EntryHistoryModel : public QAbstractTableModel | |
10520 | Q_OBJECT | |
10521 | ||
10522 | public: | |
10523 | - explicit EntryHistoryModel(QObject* parent = Q_NULLPTR); | |
10524 | + explicit EntryHistoryModel(QObject* parent = nullptr); | |
10525 | ||
10526 | Entry* entryFromIndex(const QModelIndex& index) const; | |
10527 | - int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10528 | - int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10529 | - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
10530 | - QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE; | |
10531 | + int columnCount(const QModelIndex& parent = QModelIndex()) const override; | |
10532 | + int rowCount(const QModelIndex& parent = QModelIndex()) const override; | |
10533 | + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
10534 | + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; | |
10535 | ||
10536 | void setEntries(const QList<Entry*>& entries); | |
10537 | void clear(); | |
10538 | diff --git a/src/gui/entry/EntryModel.cpp b/src/gui/entry/EntryModel.cpp | |
10539 | index 084ad72..efb64de 100644 | |
10540 | --- a/src/gui/entry/EntryModel.cpp | |
10541 | +++ b/src/gui/entry/EntryModel.cpp | |
10542 | @@ -27,9 +27,8 @@ | |
10543 | ||
10544 | EntryModel::EntryModel(QObject* parent) | |
10545 | : QAbstractTableModel(parent) | |
10546 | - , m_group(Q_NULLPTR) | |
10547 | + , m_group(nullptr) | |
10548 | { | |
10549 | - setSupportedDragActions(Qt::MoveAction | Qt::CopyAction); | |
10550 | } | |
10551 | ||
10552 | Entry* EntryModel::entryFromIndex(const QModelIndex& index) const | |
10553 | @@ -72,7 +71,7 @@ void EntryModel::setEntryList(const QList<Entry*>& entries) | |
10554 | ||
10555 | severConnections(); | |
10556 | ||
10557 | - m_group = Q_NULLPTR; | |
10558 | + m_group = nullptr; | |
10559 | m_allGroups.clear(); | |
10560 | m_entries = entries; | |
10561 | m_orgEntries = entries; | |
10562 | @@ -191,6 +190,11 @@ Qt::DropActions EntryModel::supportedDropActions() const | |
10563 | return 0; | |
10564 | } | |
10565 | ||
10566 | +Qt::DropActions EntryModel::supportedDragActions() const | |
10567 | +{ | |
10568 | + return (Qt::MoveAction | Qt::CopyAction); | |
10569 | +} | |
10570 | + | |
10571 | Qt::ItemFlags EntryModel::flags(const QModelIndex& modelIndex) const | |
10572 | { | |
10573 | if (!modelIndex.isValid()) { | |
10574 | @@ -211,7 +215,7 @@ QStringList EntryModel::mimeTypes() const | |
10575 | QMimeData* EntryModel::mimeData(const QModelIndexList& indexes) const | |
10576 | { | |
10577 | if (indexes.isEmpty()) { | |
10578 | - return Q_NULLPTR; | |
10579 | + return nullptr; | |
10580 | } | |
10581 | ||
10582 | QMimeData* data = new QMimeData(); | |
10583 | @@ -236,7 +240,7 @@ QMimeData* EntryModel::mimeData(const QModelIndexList& indexes) const | |
10584 | ||
10585 | if (seenEntries.isEmpty()) { | |
10586 | delete data; | |
10587 | - return Q_NULLPTR; | |
10588 | + return nullptr; | |
10589 | } | |
10590 | else { | |
10591 | data->setData(mimeTypes().at(0), encoded); | |
10592 | @@ -294,11 +298,11 @@ void EntryModel::entryDataChanged(Entry* entry) | |
10593 | void EntryModel::severConnections() | |
10594 | { | |
10595 | if (m_group) { | |
10596 | - disconnect(m_group, Q_NULLPTR, this, Q_NULLPTR); | |
10597 | + disconnect(m_group, nullptr, this, nullptr); | |
10598 | } | |
10599 | ||
10600 | Q_FOREACH (const Group* group, m_allGroups) { | |
10601 | - disconnect(group, Q_NULLPTR, this, Q_NULLPTR); | |
10602 | + disconnect(group, nullptr, this, nullptr); | |
10603 | } | |
10604 | } | |
10605 | ||
10606 | diff --git a/src/gui/entry/EntryModel.h b/src/gui/entry/EntryModel.h | |
10607 | index 20bcad9..0183c47 100644 | |
10608 | --- a/src/gui/entry/EntryModel.h | |
10609 | +++ b/src/gui/entry/EntryModel.h | |
10610 | @@ -20,8 +20,6 @@ | |
10611 | ||
10612 | #include <QAbstractTableModel> | |
10613 | ||
10614 | -#include "core/Global.h" | |
10615 | - | |
10616 | class Entry; | |
10617 | class Group; | |
10618 | ||
10619 | @@ -38,18 +36,19 @@ public: | |
10620 | Url = 3 | |
10621 | }; | |
10622 | ||
10623 | - explicit EntryModel(QObject* parent = Q_NULLPTR); | |
10624 | + explicit EntryModel(QObject* parent = nullptr); | |
10625 | Entry* entryFromIndex(const QModelIndex& index) const; | |
10626 | QModelIndex indexFromEntry(Entry* entry) const; | |
10627 | ||
10628 | - int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10629 | - int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10630 | - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
10631 | - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
10632 | - Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE; | |
10633 | - Qt::ItemFlags flags(const QModelIndex& modelIndex) const Q_DECL_OVERRIDE; | |
10634 | - QStringList mimeTypes() const Q_DECL_OVERRIDE; | |
10635 | - QMimeData* mimeData(const QModelIndexList& indexes) const Q_DECL_OVERRIDE; | |
10636 | + int rowCount(const QModelIndex& parent = QModelIndex()) const override; | |
10637 | + int columnCount(const QModelIndex& parent = QModelIndex()) const override; | |
10638 | + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
10639 | + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; | |
10640 | + Qt::DropActions supportedDropActions() const override; | |
10641 | + Qt::DropActions supportedDragActions() const override; | |
10642 | + Qt::ItemFlags flags(const QModelIndex& modelIndex) const override; | |
10643 | + QStringList mimeTypes() const override; | |
10644 | + QMimeData* mimeData(const QModelIndexList& indexes) const override; | |
10645 | ||
10646 | void setEntryList(const QList<Entry*>& entries); | |
10647 | ||
10648 | diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp | |
10649 | index cd2c6fb..1c900a5 100644 | |
10650 | --- a/src/gui/entry/EntryView.cpp | |
10651 | +++ b/src/gui/entry/EntryView.cpp | |
10652 | @@ -32,7 +32,6 @@ EntryView::EntryView(QWidget* parent) | |
10653 | m_sortModel->setDynamicSortFilter(true); | |
10654 | m_sortModel->setSortLocaleAware(true); | |
10655 | m_sortModel->setSortCaseSensitivity(Qt::CaseInsensitive); | |
10656 | - m_sortModel->setSupportedDragActions(m_model->supportedDragActions()); | |
10657 | QTreeView::setModel(m_sortModel); | |
10658 | ||
10659 | setUniformRowHeights(true); | |
10660 | @@ -75,7 +74,7 @@ void EntryView::setEntryList(const QList<Entry*>& entries) | |
10661 | ||
10662 | void EntryView::setFirstEntryActive() | |
10663 | { | |
10664 | - if(m_model->rowCount() > 0) { | |
10665 | + if (m_model->rowCount() > 0) { | |
10666 | QModelIndex index = m_sortModel->mapToSource(m_sortModel->index(0, 0)); | |
10667 | setCurrentEntry(m_model->entryFromIndex(index)); | |
10668 | } | |
10669 | @@ -109,7 +108,7 @@ Entry* EntryView::currentEntry() | |
10670 | return m_model->entryFromIndex(m_sortModel->mapToSource(list.first())); | |
10671 | } | |
10672 | else { | |
10673 | - return Q_NULLPTR; | |
10674 | + return nullptr; | |
10675 | } | |
10676 | } | |
10677 | ||
10678 | @@ -130,7 +129,7 @@ Entry* EntryView::entryFromIndex(const QModelIndex& index) | |
10679 | return m_model->entryFromIndex(m_sortModel->mapToSource(index)); | |
10680 | } | |
10681 | else { | |
10682 | - return Q_NULLPTR; | |
10683 | + return nullptr; | |
10684 | } | |
10685 | } | |
10686 | ||
10687 | diff --git a/src/gui/entry/EntryView.h b/src/gui/entry/EntryView.h | |
10688 | index c11d041..fb9e356 100644 | |
10689 | --- a/src/gui/entry/EntryView.h | |
10690 | +++ b/src/gui/entry/EntryView.h | |
10691 | @@ -20,8 +20,6 @@ | |
10692 | ||
10693 | #include <QTreeView> | |
10694 | ||
10695 | -#include "core/Global.h" | |
10696 | - | |
10697 | #include "gui/entry/EntryModel.h" | |
10698 | ||
10699 | class Entry; | |
10700 | @@ -34,8 +32,8 @@ class EntryView : public QTreeView | |
10701 | Q_OBJECT | |
10702 | ||
10703 | public: | |
10704 | - explicit EntryView(QWidget* parent = Q_NULLPTR); | |
10705 | - void setModel(QAbstractItemModel* model) Q_DECL_OVERRIDE; | |
10706 | + explicit EntryView(QWidget* parent = nullptr); | |
10707 | + void setModel(QAbstractItemModel* model) override; | |
10708 | Entry* currentEntry(); | |
10709 | void setCurrentEntry(Entry* entry); | |
10710 | Entry* entryFromIndex(const QModelIndex& index); | |
10711 | @@ -52,7 +50,7 @@ Q_SIGNALS: | |
10712 | void entrySelectionChanged(); | |
10713 | ||
10714 | protected: | |
10715 | - void keyPressEvent(QKeyEvent* event) Q_DECL_OVERRIDE; | |
10716 | + void keyPressEvent(QKeyEvent* event) override; | |
10717 | ||
10718 | private Q_SLOTS: | |
10719 | void emitEntryActivated(const QModelIndex& index); | |
10720 | diff --git a/src/gui/group/EditGroupWidget.cpp b/src/gui/group/EditGroupWidget.cpp | |
10721 | index ebe5cb9..7fdec89 100644 | |
10722 | --- a/src/gui/group/EditGroupWidget.cpp | |
10723 | +++ b/src/gui/group/EditGroupWidget.cpp | |
10724 | @@ -28,8 +28,8 @@ EditGroupWidget::EditGroupWidget(QWidget* parent) | |
10725 | , m_editGroupWidgetMain(new QWidget()) | |
10726 | , m_editGroupWidgetIcons(new EditWidgetIcons()) | |
10727 | , m_editWidgetProperties(new EditWidgetProperties()) | |
10728 | - , m_group(Q_NULLPTR) | |
10729 | - , m_database(Q_NULLPTR) | |
10730 | + , m_group(nullptr) | |
10731 | + , m_database(nullptr) | |
10732 | { | |
10733 | m_mainUi->setupUi(m_editGroupWidgetMain); | |
10734 | ||
10735 | @@ -142,8 +142,8 @@ void EditGroupWidget::cancel() | |
10736 | ||
10737 | void EditGroupWidget::clear() | |
10738 | { | |
10739 | - m_group = Q_NULLPTR; | |
10740 | - m_database = Q_NULLPTR; | |
10741 | + m_group = nullptr; | |
10742 | + m_database = nullptr; | |
10743 | } | |
10744 | ||
10745 | void EditGroupWidget::addTriStateItems(QComboBox* comboBox, bool inheritDefault) | |
10746 | diff --git a/src/gui/group/EditGroupWidget.h b/src/gui/group/EditGroupWidget.h | |
10747 | index c6d91a5..94ad891 100644 | |
10748 | --- a/src/gui/group/EditGroupWidget.h | |
10749 | +++ b/src/gui/group/EditGroupWidget.h | |
10750 | @@ -37,7 +37,7 @@ class EditGroupWidget : public EditWidget | |
10751 | Q_OBJECT | |
10752 | ||
10753 | public: | |
10754 | - explicit EditGroupWidget(QWidget* parent = Q_NULLPTR); | |
10755 | + explicit EditGroupWidget(QWidget* parent = nullptr); | |
10756 | ~EditGroupWidget(); | |
10757 | ||
10758 | void loadGroup(Group* group, bool create, Database* database); | |
10759 | diff --git a/src/gui/group/GroupModel.cpp b/src/gui/group/GroupModel.cpp | |
10760 | index 1244ad7..fc6d83e 100644 | |
10761 | --- a/src/gui/group/GroupModel.cpp | |
10762 | +++ b/src/gui/group/GroupModel.cpp | |
10763 | @@ -28,7 +28,7 @@ | |
10764 | ||
10765 | GroupModel::GroupModel(Database* db, QObject* parent) | |
10766 | : QAbstractItemModel(parent) | |
10767 | - , m_db(Q_NULLPTR) | |
10768 | + , m_db(nullptr) | |
10769 | { | |
10770 | changeDatabase(db); | |
10771 | } | |
10772 | @@ -329,7 +329,7 @@ QStringList GroupModel::mimeTypes() const | |
10773 | QMimeData* GroupModel::mimeData(const QModelIndexList& indexes) const | |
10774 | { | |
10775 | if (indexes.isEmpty()) { | |
10776 | - return Q_NULLPTR; | |
10777 | + return nullptr; | |
10778 | } | |
10779 | ||
10780 | QMimeData* data = new QMimeData(); | |
10781 | @@ -354,7 +354,7 @@ QMimeData* GroupModel::mimeData(const QModelIndexList& indexes) const | |
10782 | ||
10783 | if (seenGroups.isEmpty()) { | |
10784 | delete data; | |
10785 | - return Q_NULLPTR; | |
10786 | + return nullptr; | |
10787 | } | |
10788 | else { | |
10789 | data->setData(mimeTypes().at(0), encoded); | |
10790 | diff --git a/src/gui/group/GroupModel.h b/src/gui/group/GroupModel.h | |
10791 | index 752eb2b..0ef0ba9 100644 | |
10792 | --- a/src/gui/group/GroupModel.h | |
10793 | +++ b/src/gui/group/GroupModel.h | |
10794 | @@ -20,8 +20,6 @@ | |
10795 | ||
10796 | #include <QAbstractItemModel> | |
10797 | ||
10798 | -#include "core/Global.h" | |
10799 | - | |
10800 | class Database; | |
10801 | class Group; | |
10802 | ||
10803 | @@ -30,23 +28,23 @@ class GroupModel : public QAbstractItemModel | |
10804 | Q_OBJECT | |
10805 | ||
10806 | public: | |
10807 | - explicit GroupModel(Database* db, QObject* parent = Q_NULLPTR); | |
10808 | + explicit GroupModel(Database* db, QObject* parent = nullptr); | |
10809 | void changeDatabase(Database* newDb); | |
10810 | QModelIndex index(Group* group) const; | |
10811 | Group* groupFromIndex(const QModelIndex& index) const; | |
10812 | ||
10813 | - int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10814 | - int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10815 | - QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; | |
10816 | - QModelIndex parent(const QModelIndex& index) const Q_DECL_OVERRIDE; | |
10817 | - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
10818 | - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | |
10819 | - Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE; | |
10820 | - Qt::ItemFlags flags(const QModelIndex& modelIndex) const Q_DECL_OVERRIDE; | |
10821 | + int rowCount(const QModelIndex& parent = QModelIndex()) const override; | |
10822 | + int columnCount(const QModelIndex& parent = QModelIndex()) const override; | |
10823 | + QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; | |
10824 | + QModelIndex parent(const QModelIndex& index) const override; | |
10825 | + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
10826 | + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; | |
10827 | + Qt::DropActions supportedDropActions() const override; | |
10828 | + Qt::ItemFlags flags(const QModelIndex& modelIndex) const override; | |
10829 | bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, | |
10830 | - const QModelIndex& parent) Q_DECL_OVERRIDE; | |
10831 | - QStringList mimeTypes() const Q_DECL_OVERRIDE; | |
10832 | - QMimeData* mimeData(const QModelIndexList& indexes) const Q_DECL_OVERRIDE; | |
10833 | + const QModelIndex& parent) override; | |
10834 | + QStringList mimeTypes() const override; | |
10835 | + QMimeData* mimeData(const QModelIndexList& indexes) const override; | |
10836 | ||
10837 | private: | |
10838 | QModelIndex parent(Group* group) const; | |
10839 | diff --git a/src/gui/group/GroupView.cpp b/src/gui/group/GroupView.cpp | |
10840 | index 3c93662..1f94dc0 100644 | |
10841 | --- a/src/gui/group/GroupView.cpp | |
10842 | +++ b/src/gui/group/GroupView.cpp | |
10843 | @@ -19,6 +19,7 @@ | |
10844 | ||
10845 | #include <QDragMoveEvent> | |
10846 | #include <QMetaObject> | |
10847 | +#include <QMimeData> | |
10848 | ||
10849 | #include "core/Database.h" | |
10850 | #include "core/Group.h" | |
10851 | @@ -74,7 +75,7 @@ void GroupView::dragMoveEvent(QDragMoveEvent* event) | |
10852 | Group* GroupView::currentGroup() | |
10853 | { | |
10854 | if (currentIndex() == QModelIndex()) { | |
10855 | - return Q_NULLPTR; | |
10856 | + return nullptr; | |
10857 | } | |
10858 | else { | |
10859 | return m_model->groupFromIndex(currentIndex()); | |
10860 | diff --git a/src/gui/group/GroupView.h b/src/gui/group/GroupView.h | |
10861 | index 06bdbaf..69ca828 100644 | |
10862 | --- a/src/gui/group/GroupView.h | |
10863 | +++ b/src/gui/group/GroupView.h | |
10864 | @@ -20,8 +20,6 @@ | |
10865 | ||
10866 | #include <QTreeView> | |
10867 | ||
10868 | -#include "core/Global.h" | |
10869 | - | |
10870 | class Database; | |
10871 | class Group; | |
10872 | class GroupModel; | |
10873 | @@ -31,9 +29,9 @@ class GroupView : public QTreeView | |
10874 | Q_OBJECT | |
10875 | ||
10876 | public: | |
10877 | - explicit GroupView(Database* db, QWidget* parent = Q_NULLPTR); | |
10878 | + explicit GroupView(Database* db, QWidget* parent = nullptr); | |
10879 | void changeDatabase(Database* newDb); | |
10880 | - void setModel(QAbstractItemModel* model) Q_DECL_OVERRIDE; | |
10881 | + void setModel(QAbstractItemModel* model) override; | |
10882 | Group* currentGroup(); | |
10883 | void setCurrentGroup(Group* group); | |
10884 | void expandGroup(Group* group, bool expand = true); | |
10885 | @@ -49,7 +47,7 @@ private Q_SLOTS: | |
10886 | void modelReset(); | |
10887 | ||
10888 | protected: | |
10889 | - void dragMoveEvent(QDragMoveEvent* event) Q_DECL_OVERRIDE; | |
10890 | + void dragMoveEvent(QDragMoveEvent* event) override; | |
10891 | ||
10892 | private: | |
10893 | void recInitExpanded(Group* group); | |
10894 | diff --git a/src/keys/CompositeKey.cpp b/src/keys/CompositeKey.cpp | |
10895 | index 5bf9cae..d38f466 100644 | |
10896 | --- a/src/keys/CompositeKey.cpp | |
10897 | +++ b/src/keys/CompositeKey.cpp | |
10898 | @@ -18,8 +18,8 @@ | |
10899 | #include "CompositeKey.h" | |
10900 | #include "CompositeKey_p.h" | |
10901 | ||
10902 | -#include <QtConcurrentRun> | |
10903 | -#include <QTime> | |
10904 | +#include <QtConcurrent> | |
10905 | +#include <QElapsedTimer> | |
10906 | ||
10907 | #include "crypto/CryptoHash.h" | |
10908 | #include "crypto/SymmetricCipher.h" | |
10909 | @@ -94,7 +94,8 @@ QByteArray CompositeKey::transform(const QByteArray& seed, quint64 rounds, | |
10910 | ||
10911 | QByteArray key = rawKey(); | |
10912 | ||
10913 | - QFuture<QByteArray> future = QtConcurrent::run(transformKeyRaw, key.left(16), seed, rounds, &okLeft, &errorStringLeft); | |
10914 | + QFuture<QByteArray> future = QtConcurrent::run(transformKeyRaw, key.left(16), seed, rounds, | |
10915 | + &okLeft, &errorStringLeft); | |
10916 | QByteArray result2 = transformKeyRaw(key.right(16), seed, rounds, &okRight, &errorStringRight); | |
10917 | ||
10918 | QByteArray transformed; | |
10919 | @@ -182,7 +183,7 @@ void TransformKeyBenchmarkThread::run() | |
10920 | SymmetricCipher::Encrypt); | |
10921 | cipher.init(seed, iv); | |
10922 | ||
10923 | - QTime t; | |
10924 | + QElapsedTimer t; | |
10925 | t.start(); | |
10926 | ||
10927 | do { | |
10928 | @@ -191,5 +192,5 @@ void TransformKeyBenchmarkThread::run() | |
10929 | return; | |
10930 | } | |
10931 | m_rounds += 10000; | |
10932 | - } while (t.elapsed() < m_msec); | |
10933 | + } while (!t.hasExpired(m_msec)); | |
10934 | } | |
10935 | diff --git a/src/keys/FileKey.h b/src/keys/FileKey.h | |
10936 | index f985433..7a9b1ca 100644 | |
10937 | --- a/src/keys/FileKey.h | |
10938 | +++ b/src/keys/FileKey.h | |
10939 | @@ -20,7 +20,6 @@ | |
10940 | ||
10941 | #include <QXmlStreamReader> | |
10942 | ||
10943 | -#include "core/Global.h" | |
10944 | #include "keys/Key.h" | |
10945 | ||
10946 | class QIODevice; | |
10947 | @@ -30,11 +29,11 @@ class FileKey : public Key | |
10948 | public: | |
10949 | FileKey(); | |
10950 | bool load(QIODevice* device); | |
10951 | - bool load(const QString& fileName, QString* errorMsg = Q_NULLPTR); | |
10952 | + bool load(const QString& fileName, QString* errorMsg = nullptr); | |
10953 | QByteArray rawKey() const; | |
10954 | FileKey* clone() const; | |
10955 | static void create(QIODevice* device); | |
10956 | - static bool create(const QString& fileName, QString* errorMsg = Q_NULLPTR); | |
10957 | + static bool create(const QString& fileName, QString* errorMsg = nullptr); | |
10958 | ||
10959 | private: | |
10960 | bool loadXml(QIODevice* device); | |
10961 | diff --git a/src/main.cpp b/src/main.cpp | |
10962 | index bf558f1..04b70a4 100644 | |
10963 | --- a/src/main.cpp | |
10964 | +++ b/src/main.cpp | |
10965 | @@ -15,11 +15,11 @@ | |
10966 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
10967 | */ | |
10968 | ||
10969 | +#include <QCommandLineParser> | |
10970 | #include <QFile> | |
10971 | ||
10972 | #include "config-keepassx.h" | |
10973 | #include "core/Config.h" | |
10974 | -#include "core/qcommandlineparser.h" | |
10975 | #include "core/Tools.h" | |
10976 | #include "core/Translator.h" | |
10977 | #include "crypto/Crypto.h" | |
10978 | @@ -38,7 +38,7 @@ int main(int argc, char** argv) | |
10979 | Application::setApplicationName("keepassx"); | |
10980 | Application::setApplicationVersion(KEEPASSX_VERSION); | |
10981 | // don't set organizationName as that changes the return value of | |
10982 | - // QDesktopServices::storageLocation(QDesktopServices::DataLocation) | |
10983 | + // QStandardPaths::writableLocation(QDesktopServices::DataLocation) | |
10984 | ||
10985 | QApplication::setQuitOnLastWindowClosed(false); | |
10986 | ||
10987 | @@ -47,7 +47,7 @@ int main(int argc, char** argv) | |
10988 | "Fatal error while testing the cryptographic functions."); | |
10989 | error.append("\n"); | |
10990 | error.append(Crypto::errorString()); | |
10991 | - MessageBox::critical(Q_NULLPTR, QCoreApplication::translate("Main", "KeePassX - Error"), error); | |
10992 | + MessageBox::critical(nullptr, QCoreApplication::translate("Main", "KeePassX - Error"), error); | |
10993 | return 1; | |
10994 | } | |
10995 | ||
10996 | diff --git a/src/streams/HashedBlockStream.h b/src/streams/HashedBlockStream.h | |
10997 | index cae4eb4..93e4af5 100644 | |
10998 | --- a/src/streams/HashedBlockStream.h | |
10999 | +++ b/src/streams/HashedBlockStream.h | |
11000 | @@ -31,12 +31,12 @@ public: | |
11001 | HashedBlockStream(QIODevice* baseDevice, qint32 blockSize); | |
11002 | ~HashedBlockStream(); | |
11003 | ||
11004 | - bool reset() Q_DECL_OVERRIDE; | |
11005 | - void close() Q_DECL_OVERRIDE; | |
11006 | + bool reset() override; | |
11007 | + void close() override; | |
11008 | ||
11009 | protected: | |
11010 | - qint64 readData(char* data, qint64 maxSize) Q_DECL_OVERRIDE; | |
11011 | - qint64 writeData(const char* data, qint64 maxSize) Q_DECL_OVERRIDE; | |
11012 | + qint64 readData(char* data, qint64 maxSize) override; | |
11013 | + qint64 writeData(const char* data, qint64 maxSize) override; | |
11014 | ||
11015 | private: | |
11016 | void init(); | |
11017 | diff --git a/src/streams/LayeredStream.h b/src/streams/LayeredStream.h | |
11018 | index b243e55..8586b41 100644 | |
11019 | --- a/src/streams/LayeredStream.h | |
11020 | +++ b/src/streams/LayeredStream.h | |
11021 | @@ -20,8 +20,6 @@ | |
11022 | ||
11023 | #include <QIODevice> | |
11024 | ||
11025 | -#include "core/Global.h" | |
11026 | - | |
11027 | class LayeredStream : public QIODevice | |
11028 | { | |
11029 | Q_OBJECT | |
11030 | @@ -30,12 +28,12 @@ public: | |
11031 | explicit LayeredStream(QIODevice* baseDevice); | |
11032 | virtual ~LayeredStream(); | |
11033 | ||
11034 | - bool isSequential() const Q_DECL_OVERRIDE; | |
11035 | - bool open(QIODevice::OpenMode mode) Q_DECL_OVERRIDE; | |
11036 | + bool isSequential() const override; | |
11037 | + bool open(QIODevice::OpenMode mode) override; | |
11038 | ||
11039 | protected: | |
11040 | - qint64 readData(char* data, qint64 maxSize) Q_DECL_OVERRIDE; | |
11041 | - qint64 writeData(const char* data, qint64 maxSize) Q_DECL_OVERRIDE; | |
11042 | + qint64 readData(char* data, qint64 maxSize) override; | |
11043 | + qint64 writeData(const char* data, qint64 maxSize) override; | |
11044 | ||
11045 | QIODevice* const m_baseDevice; | |
11046 | ||
11047 | diff --git a/src/streams/StoreDataStream.h b/src/streams/StoreDataStream.h | |
11048 | index 4143438..9f39d6a 100644 | |
11049 | --- a/src/streams/StoreDataStream.h | |
11050 | +++ b/src/streams/StoreDataStream.h | |
11051 | @@ -26,11 +26,11 @@ class StoreDataStream : public LayeredStream | |
11052 | ||
11053 | public: | |
11054 | explicit StoreDataStream(QIODevice* baseDevice); | |
11055 | - bool open(QIODevice::OpenMode mode) Q_DECL_OVERRIDE; | |
11056 | + bool open(QIODevice::OpenMode mode) override; | |
11057 | QByteArray storedData() const; | |
11058 | ||
11059 | protected: | |
11060 | - qint64 readData(char* data, qint64 maxSize) Q_DECL_OVERRIDE; | |
11061 | + qint64 readData(char* data, qint64 maxSize) override; | |
11062 | ||
11063 | private: | |
11064 | QByteArray m_storedData; | |
11065 | diff --git a/src/streams/SymmetricCipherStream.h b/src/streams/SymmetricCipherStream.h | |
11066 | index fa44605..b6228e1 100644 | |
11067 | --- a/src/streams/SymmetricCipherStream.h | |
11068 | +++ b/src/streams/SymmetricCipherStream.h | |
11069 | @@ -33,13 +33,13 @@ public: | |
11070 | SymmetricCipher::Mode mode, SymmetricCipher::Direction direction); | |
11071 | ~SymmetricCipherStream(); | |
11072 | bool init(const QByteArray& key, const QByteArray& iv); | |
11073 | - bool open(QIODevice::OpenMode mode) Q_DECL_OVERRIDE; | |
11074 | - bool reset() Q_DECL_OVERRIDE; | |
11075 | - void close() Q_DECL_OVERRIDE; | |
11076 | + bool open(QIODevice::OpenMode mode) override; | |
11077 | + bool reset() override; | |
11078 | + void close() override; | |
11079 | ||
11080 | protected: | |
11081 | - qint64 readData(char* data, qint64 maxSize) Q_DECL_OVERRIDE; | |
11082 | - qint64 writeData(const char* data, qint64 maxSize) Q_DECL_OVERRIDE; | |
11083 | + qint64 readData(char* data, qint64 maxSize) override; | |
11084 | + qint64 writeData(const char* data, qint64 maxSize) override; | |
11085 | ||
11086 | private: | |
11087 | void resetInternalState(); | |
11088 | diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt | |
11089 | index 2de7094..7ea399f 100644 | |
11090 | --- a/tests/CMakeLists.txt | |
11091 | +++ b/tests/CMakeLists.txt | |
11092 | @@ -52,10 +52,9 @@ macro(parse_arguments prefix arg_names option_names) | |
11093 | endmacro(parse_arguments) | |
11094 | ||
11095 | macro(add_unit_test) | |
11096 | - parse_arguments(TEST "NAME;SOURCES;MOCS;LIBS" "" ${ARGN}) | |
11097 | + parse_arguments(TEST "NAME;SOURCES;LIBS" "" ${ARGN}) | |
11098 | set(_test_NAME ${TEST_NAME}) | |
11099 | set(_srcList ${TEST_SOURCES}) | |
11100 | - qt4_wrap_cpp(_srcList ${TEST_MOCS}) | |
11101 | add_executable(${_test_NAME} ${_srcList}) | |
11102 | target_link_libraries(${_test_NAME} ${TEST_LIBS}) | |
11103 | ||
11104 | @@ -86,85 +85,80 @@ endmacro(add_unit_test) | |
11105 | ||
11106 | set(TEST_LIBRARIES | |
11107 | keepassx_core | |
11108 | - ${QT_QTCORE_LIBRARY} | |
11109 | - ${QT_QTGUI_LIBRARY} | |
11110 | - ${QT_QTTEST_LIBRARY} | |
11111 | + Qt5::Core | |
11112 | + Qt5::Concurrent | |
11113 | + Qt5::Widgets | |
11114 | + Qt5::Test | |
11115 | ${GCRYPT_LIBRARIES} | |
11116 | ${ZLIB_LIBRARIES} | |
11117 | ) | |
11118 | ||
11119 | set(testsupport_SOURCES modeltest.cpp FailDevice.cpp) | |
11120 | -qt4_wrap_cpp(testsupport_SOURCES modeltest.h FailDevice.h) | |
11121 | add_library(testsupport STATIC ${testsupport_SOURCES}) | |
11122 | +target_link_libraries(testsupport Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test) | |
11123 | ||
11124 | -add_unit_test(NAME testgroup SOURCES TestGroup.cpp MOCS TestGroup.h | |
11125 | +add_unit_test(NAME testgroup SOURCES TestGroup.cpp | |
11126 | LIBS ${TEST_LIBRARIES}) | |
11127 | ||
11128 | -add_unit_test(NAME testkeepass2xmlreader SOURCES TestKeePass2XmlReader.cpp MOCS TestKeePass2XmlReader.h | |
11129 | +add_unit_test(NAME testkeepass2xmlreader SOURCES TestKeePass2XmlReader.cpp | |
11130 | LIBS ${TEST_LIBRARIES}) | |
11131 | ||
11132 | -add_unit_test(NAME testkeys SOURCES TestKeys.cpp MOCS TestKeys.h | |
11133 | +add_unit_test(NAME testkeys SOURCES TestKeys.cpp | |
11134 | LIBS ${TEST_LIBRARIES}) | |
11135 | ||
11136 | -add_unit_test(NAME testkeepass2reader SOURCES TestKeePass2Reader.cpp MOCS TestKeePass2Reader.h | |
11137 | +add_unit_test(NAME testkeepass2reader SOURCES TestKeePass2Reader.cpp | |
11138 | LIBS ${TEST_LIBRARIES}) | |
11139 | ||
11140 | -add_unit_test(NAME testkeepass2writer SOURCES TestKeePass2Writer.cpp MOCS TestKeePass2Writer.h | |
11141 | +add_unit_test(NAME testkeepass2writer SOURCES TestKeePass2Writer.cpp | |
11142 | LIBS testsupport ${TEST_LIBRARIES}) | |
11143 | ||
11144 | -add_unit_test(NAME testgroupmodel SOURCES TestGroupModel.cpp MOCS TestGroupModel.h | |
11145 | +add_unit_test(NAME testgroupmodel SOURCES TestGroupModel.cpp | |
11146 | LIBS testsupport ${TEST_LIBRARIES}) | |
11147 | ||
11148 | -add_unit_test(NAME testentrymodel SOURCES TestEntryModel.cpp MOCS TestEntryModel.h | |
11149 | +add_unit_test(NAME testentrymodel SOURCES TestEntryModel.cpp | |
11150 | LIBS testsupport ${TEST_LIBRARIES}) | |
11151 | ||
11152 | -add_unit_test(NAME testcryptohash SOURCES TestCryptoHash.cpp MOCS TestCryptoHash.h | |
11153 | +add_unit_test(NAME testcryptohash SOURCES TestCryptoHash.cpp | |
11154 | LIBS ${TEST_LIBRARIES}) | |
11155 | ||
11156 | -add_unit_test(NAME testsymmetriccipher SOURCES TestSymmetricCipher.cpp MOCS TestSymmetricCipher.h | |
11157 | +add_unit_test(NAME testsymmetriccipher SOURCES TestSymmetricCipher.cpp | |
11158 | LIBS ${TEST_LIBRARIES}) | |
11159 | ||
11160 | -add_unit_test(NAME testhashedblockstream SOURCES TestHashedBlockStream.cpp MOCS TestHashedBlockStream.h | |
11161 | +add_unit_test(NAME testhashedblockstream SOURCES TestHashedBlockStream.cpp | |
11162 | LIBS testsupport ${TEST_LIBRARIES}) | |
11163 | ||
11164 | -add_unit_test(NAME testkeepass2randomstream SOURCES TestKeePass2RandomStream.cpp MOCS TestKeePass2RandomStream.h | |
11165 | +add_unit_test(NAME testkeepass2randomstream SOURCES TestKeePass2RandomStream.cpp | |
11166 | LIBS ${TEST_LIBRARIES}) | |
11167 | ||
11168 | -add_unit_test(NAME testmodified SOURCES TestModified.cpp MOCS TestModified.h | |
11169 | +add_unit_test(NAME testmodified SOURCES TestModified.cpp | |
11170 | LIBS ${TEST_LIBRARIES}) | |
11171 | ||
11172 | -add_unit_test(NAME testdeletedobjects SOURCES TestDeletedObjects.cpp MOCS TestDeletedObjects.h | |
11173 | +add_unit_test(NAME testdeletedobjects SOURCES TestDeletedObjects.cpp | |
11174 | LIBS ${TEST_LIBRARIES}) | |
11175 | ||
11176 | -add_unit_test(NAME testkeepass1reader SOURCES TestKeePass1Reader.cpp MOCS TestKeePass1Reader.h | |
11177 | +add_unit_test(NAME testkeepass1reader SOURCES TestKeePass1Reader.cpp | |
11178 | LIBS ${TEST_LIBRARIES}) | |
11179 | ||
11180 | -add_unit_test(NAME testqsavefile SOURCES TestQSaveFile.cpp MOCS TestQSaveFile.h | |
11181 | +add_unit_test(NAME testwildcardmatcher SOURCES TestWildcardMatcher.cpp | |
11182 | LIBS ${TEST_LIBRARIES}) | |
11183 | ||
11184 | -add_unit_test(NAME testwildcardmatcher SOURCES TestWildcardMatcher.cpp MOCS TestWildcardMatcher.h | |
11185 | - LIBS ${TEST_LIBRARIES}) | |
11186 | - | |
11187 | -add_unit_test(NAME testautotype SOURCES TestAutoType.cpp MOCS TestAutoType.h | |
11188 | +add_unit_test(NAME testautotype SOURCES TestAutoType.cpp | |
11189 | LIBS ${TEST_LIBRARIES}) | |
11190 | set_target_properties(testautotype PROPERTIES ENABLE_EXPORTS ON) | |
11191 | ||
11192 | -add_unit_test(NAME testentry SOURCES TestEntry.cpp MOCS TestEntry.h | |
11193 | - LIBS ${TEST_LIBRARIES}) | |
11194 | - | |
11195 | -add_unit_test(NAME testqcommandlineparser SOURCES TestQCommandLineParser.cpp MOCS TestQCommandLineParser.h | |
11196 | +add_unit_test(NAME testentry SOURCES TestEntry.cpp | |
11197 | LIBS ${TEST_LIBRARIES}) | |
11198 | ||
11199 | -add_unit_test(NAME testrandom SOURCES TestRandom.cpp MOCS TestRandom.h | |
11200 | +add_unit_test(NAME testrandom SOURCES TestRandom.cpp | |
11201 | LIBS ${TEST_LIBRARIES}) | |
11202 | ||
11203 | -add_unit_test(NAME testentrysearcher SOURCES TestEntrySearcher.cpp MOCS TestEntrySearcher.h | |
11204 | +add_unit_test(NAME testentrysearcher SOURCES TestEntrySearcher.cpp | |
11205 | LIBS ${TEST_LIBRARIES}) | |
11206 | ||
11207 | -add_unit_test(NAME testexporter SOURCES TestExporter.cpp MOCS TestExporter.h | |
11208 | +add_unit_test(NAME testexporter SOURCES TestExporter.cpp | |
11209 | LIBS ${TEST_LIBRARIES}) | |
11210 | ||
11211 | -add_unit_test(NAME testcsvexporter SOURCES TestCsvExporter.cpp MOCS TestCsvExporter.h | |
11212 | +add_unit_test(NAME testcsvexporter SOURCES TestCsvExporter.cpp | |
11213 | LIBS ${TEST_LIBRARIES}) | |
11214 | ||
11215 | if(WITH_GUI_TESTS) | |
11216 | diff --git a/tests/FailDevice.h b/tests/FailDevice.h | |
11217 | index f812593..194d617 100644 | |
11218 | --- a/tests/FailDevice.h | |
11219 | +++ b/tests/FailDevice.h | |
11220 | @@ -20,19 +20,17 @@ | |
11221 | ||
11222 | #include <QBuffer> | |
11223 | ||
11224 | -#include "core/Global.h" | |
11225 | - | |
11226 | class FailDevice : public QBuffer | |
11227 | { | |
11228 | Q_OBJECT | |
11229 | ||
11230 | public: | |
11231 | - explicit FailDevice(int failAfter, QObject* parent = Q_NULLPTR); | |
11232 | - bool open(QIODevice::OpenMode openMode) Q_DECL_OVERRIDE; | |
11233 | + explicit FailDevice(int failAfter, QObject* parent = nullptr); | |
11234 | + bool open(QIODevice::OpenMode openMode) override; | |
11235 | ||
11236 | protected: | |
11237 | - qint64 readData(char* data, qint64 len) Q_DECL_OVERRIDE; | |
11238 | - qint64 writeData(const char* data, qint64 len) Q_DECL_OVERRIDE; | |
11239 | + qint64 readData(char* data, qint64 len) override; | |
11240 | + qint64 writeData(const char* data, qint64 len) override; | |
11241 | ||
11242 | private: | |
11243 | int m_failAfter; | |
11244 | diff --git a/tests/TestAutoType.cpp b/tests/TestAutoType.cpp | |
11245 | index 8968348..cbd927f 100644 | |
11246 | --- a/tests/TestAutoType.cpp | |
11247 | +++ b/tests/TestAutoType.cpp | |
11248 | @@ -20,7 +20,6 @@ | |
11249 | #include <QPluginLoader> | |
11250 | #include <QTest> | |
11251 | ||
11252 | -#include "tests.h" | |
11253 | #include "core/Config.h" | |
11254 | #include "core/FilePath.h" | |
11255 | #include "core/Entry.h" | |
11256 | @@ -108,7 +107,7 @@ void TestAutoType::testInternal() | |
11257 | ||
11258 | void TestAutoType::testAutoTypeWithoutSequence() | |
11259 | { | |
11260 | - m_autoType->performAutoType(m_entry1, Q_NULLPTR); | |
11261 | + m_autoType->performAutoType(m_entry1, nullptr); | |
11262 | ||
11263 | QCOMPARE(m_test->actionCount(), 14); | |
11264 | QCOMPARE(m_test->actionChars(), | |
11265 | @@ -119,7 +118,7 @@ void TestAutoType::testAutoTypeWithoutSequence() | |
11266 | ||
11267 | void TestAutoType::testAutoTypeWithSequence() | |
11268 | { | |
11269 | - m_autoType->performAutoType(m_entry1, Q_NULLPTR, "{Username}abc{PaSsWoRd}"); | |
11270 | + m_autoType->performAutoType(m_entry1, nullptr, "{Username}abc{PaSsWoRd}"); | |
11271 | ||
11272 | QCOMPARE(m_test->actionCount(), 15); | |
11273 | QCOMPARE(m_test->actionChars(), | |
11274 | diff --git a/tests/TestCryptoHash.cpp b/tests/TestCryptoHash.cpp | |
11275 | index 4002aea..c166f55 100644 | |
11276 | --- a/tests/TestCryptoHash.cpp | |
11277 | +++ b/tests/TestCryptoHash.cpp | |
11278 | @@ -19,7 +19,6 @@ | |
11279 | ||
11280 | #include <QTest> | |
11281 | ||
11282 | -#include "tests.h" | |
11283 | #include "crypto/Crypto.h" | |
11284 | #include "crypto/CryptoHash.h" | |
11285 | ||
11286 | diff --git a/tests/TestCsvExporter.cpp b/tests/TestCsvExporter.cpp | |
11287 | index 5965e60..1fa6634 100644 | |
11288 | --- a/tests/TestCsvExporter.cpp | |
11289 | +++ b/tests/TestCsvExporter.cpp | |
11290 | @@ -21,8 +21,6 @@ | |
11291 | #include <QBuffer> | |
11292 | #include <QTest> | |
11293 | ||
11294 | -#include "tests.h" | |
11295 | - | |
11296 | #include "core/Database.h" | |
11297 | #include "core/Entry.h" | |
11298 | #include "core/Group.h" | |
11299 | @@ -53,7 +51,7 @@ void TestCsvExporter::cleanUp() | |
11300 | void TestCsvExporter::testExport() | |
11301 | { | |
11302 | Group* groupRoot = m_db->rootGroup(); | |
11303 | - Group* group= new Group(); | |
11304 | + Group* group = new Group(); | |
11305 | group->setName("Test Group Name"); | |
11306 | group->setParent(groupRoot); | |
11307 | Entry* entry = new Entry(); | |
11308 | @@ -85,10 +83,10 @@ void TestCsvExporter::testEmptyDatabase() | |
11309 | void TestCsvExporter::testNestedGroups() | |
11310 | { | |
11311 | Group* groupRoot = m_db->rootGroup(); | |
11312 | - Group* group= new Group(); | |
11313 | + Group* group = new Group(); | |
11314 | group->setName("Test Group Name"); | |
11315 | group->setParent(groupRoot); | |
11316 | - Group* childGroup= new Group(); | |
11317 | + Group* childGroup = new Group(); | |
11318 | childGroup->setName("Test Sub Group Name"); | |
11319 | childGroup->setParent(group); | |
11320 | Entry* entry = new Entry(); | |
11321 | diff --git a/tests/TestCsvExporter.h b/tests/TestCsvExporter.h | |
11322 | index a71c936..c8cc4dc 100644 | |
11323 | --- a/tests/TestCsvExporter.h | |
11324 | +++ b/tests/TestCsvExporter.h | |
11325 | @@ -42,7 +42,6 @@ private Q_SLOTS: | |
11326 | private: | |
11327 | Database* m_db; | |
11328 | CsvExporter* m_csvExporter; | |
11329 | - | |
11330 | }; | |
11331 | ||
11332 | #endif // KEEPASSX_TESTCSVEXPORTER_H | |
11333 | diff --git a/tests/TestDeletedObjects.cpp b/tests/TestDeletedObjects.cpp | |
11334 | index cf9e3d1..5af0178 100644 | |
11335 | --- a/tests/TestDeletedObjects.cpp | |
11336 | +++ b/tests/TestDeletedObjects.cpp | |
11337 | @@ -19,7 +19,6 @@ | |
11338 | ||
11339 | #include <QTest> | |
11340 | ||
11341 | -#include "tests.h" | |
11342 | #include "core/Database.h" | |
11343 | #include "core/Group.h" | |
11344 | #include "crypto/Crypto.h" | |
11345 | diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp | |
11346 | index f918b6c..1eaca32 100644 | |
11347 | --- a/tests/TestEntry.cpp | |
11348 | +++ b/tests/TestEntry.cpp | |
11349 | @@ -19,7 +19,6 @@ | |
11350 | ||
11351 | #include <QTest> | |
11352 | ||
11353 | -#include "tests.h" | |
11354 | #include "core/Entry.h" | |
11355 | #include "crypto/Crypto.h" | |
11356 | ||
11357 | diff --git a/tests/TestEntryModel.cpp b/tests/TestEntryModel.cpp | |
11358 | index b323a73..3f956d7 100644 | |
11359 | --- a/tests/TestEntryModel.cpp | |
11360 | +++ b/tests/TestEntryModel.cpp | |
11361 | @@ -21,7 +21,6 @@ | |
11362 | #include <QTest> | |
11363 | ||
11364 | #include "modeltest.h" | |
11365 | -#include "tests.h" | |
11366 | #include "core/DatabaseIcons.h" | |
11367 | #include "core/Entry.h" | |
11368 | #include "core/Group.h" | |
11369 | diff --git a/tests/TestEntrySearcher.cpp b/tests/TestEntrySearcher.cpp | |
11370 | index 9f7ca13..6b951c7 100644 | |
11371 | --- a/tests/TestEntrySearcher.cpp | |
11372 | +++ b/tests/TestEntrySearcher.cpp | |
11373 | @@ -19,8 +19,6 @@ | |
11374 | ||
11375 | #include <QTest> | |
11376 | ||
11377 | -#include "tests.h" | |
11378 | - | |
11379 | QTEST_GUILESS_MAIN(TestEntrySearcher) | |
11380 | ||
11381 | void TestEntrySearcher::initTestCase() | |
11382 | diff --git a/tests/TestExporter.cpp b/tests/TestExporter.cpp | |
11383 | index 76a6f75..656b76c 100644 | |
11384 | --- a/tests/TestExporter.cpp | |
11385 | +++ b/tests/TestExporter.cpp | |
11386 | @@ -20,7 +20,6 @@ | |
11387 | ||
11388 | #include <QTest> | |
11389 | ||
11390 | -#include "tests.h" | |
11391 | #include "core/ToDbExporter.h" | |
11392 | #include "core/Group.h" | |
11393 | #include "core/Metadata.h" | |
11394 | @@ -77,6 +76,3 @@ void TestExporter::testToDbExporter() | |
11395 | delete dbOrg; | |
11396 | delete dbExp; | |
11397 | } | |
11398 | - | |
11399 | - | |
11400 | - | |
11401 | diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp | |
11402 | index 507cf15..13ce82e 100644 | |
11403 | --- a/tests/TestGroup.cpp | |
11404 | +++ b/tests/TestGroup.cpp | |
11405 | @@ -21,7 +21,6 @@ | |
11406 | #include <QSignalSpy> | |
11407 | #include <QTest> | |
11408 | ||
11409 | -#include "tests.h" | |
11410 | #include "core/Database.h" | |
11411 | #include "core/Group.h" | |
11412 | #include "core/Metadata.h" | |
11413 | diff --git a/tests/TestGroupModel.cpp b/tests/TestGroupModel.cpp | |
11414 | index 32a4b8e..3608cc4 100644 | |
11415 | --- a/tests/TestGroupModel.cpp | |
11416 | +++ b/tests/TestGroupModel.cpp | |
11417 | @@ -21,7 +21,6 @@ | |
11418 | #include <QTest> | |
11419 | ||
11420 | #include "modeltest.h" | |
11421 | -#include "tests.h" | |
11422 | #include "core/Database.h" | |
11423 | #include "core/Group.h" | |
11424 | #include "crypto/Crypto.h" | |
11425 | diff --git a/tests/TestHashedBlockStream.cpp b/tests/TestHashedBlockStream.cpp | |
11426 | index d5a0cea..b78a46b 100644 | |
11427 | --- a/tests/TestHashedBlockStream.cpp | |
11428 | +++ b/tests/TestHashedBlockStream.cpp | |
11429 | @@ -20,7 +20,6 @@ | |
11430 | #include <QBuffer> | |
11431 | #include <QTest> | |
11432 | ||
11433 | -#include "tests.h" | |
11434 | #include "FailDevice.h" | |
11435 | #include "crypto/Crypto.h" | |
11436 | #include "streams/HashedBlockStream.h" | |
11437 | diff --git a/tests/TestKeePass1Reader.cpp b/tests/TestKeePass1Reader.cpp | |
11438 | index d9dff9e..f60846d 100644 | |
11439 | --- a/tests/TestKeePass1Reader.cpp | |
11440 | +++ b/tests/TestKeePass1Reader.cpp | |
11441 | @@ -21,7 +21,6 @@ | |
11442 | #include <QTest> | |
11443 | ||
11444 | #include "config-keepassx-tests.h" | |
11445 | -#include "tests.h" | |
11446 | #include "core/Database.h" | |
11447 | #include "core/Entry.h" | |
11448 | #include "core/Group.h" | |
11449 | diff --git a/tests/TestKeePass2RandomStream.cpp b/tests/TestKeePass2RandomStream.cpp | |
11450 | index cb88133..03dfbe5 100644 | |
11451 | --- a/tests/TestKeePass2RandomStream.cpp | |
11452 | +++ b/tests/TestKeePass2RandomStream.cpp | |
11453 | @@ -19,7 +19,6 @@ | |
11454 | ||
11455 | #include <QTest> | |
11456 | ||
11457 | -#include "tests.h" | |
11458 | #include "crypto/Crypto.h" | |
11459 | #include "crypto/CryptoHash.h" | |
11460 | #include "crypto/SymmetricCipher.h" | |
11461 | diff --git a/tests/TestKeePass2Reader.cpp b/tests/TestKeePass2Reader.cpp | |
11462 | index d6cb70c..22973ee 100644 | |
11463 | --- a/tests/TestKeePass2Reader.cpp | |
11464 | +++ b/tests/TestKeePass2Reader.cpp | |
11465 | @@ -20,7 +20,6 @@ | |
11466 | #include <QTest> | |
11467 | ||
11468 | #include "config-keepassx-tests.h" | |
11469 | -#include "tests.h" | |
11470 | #include "core/Database.h" | |
11471 | #include "core/Group.h" | |
11472 | #include "core/Metadata.h" | |
11473 | diff --git a/tests/TestKeePass2Writer.cpp b/tests/TestKeePass2Writer.cpp | |
11474 | index c872794..60b7b90 100644 | |
11475 | --- a/tests/TestKeePass2Writer.cpp | |
11476 | +++ b/tests/TestKeePass2Writer.cpp | |
11477 | @@ -21,7 +21,6 @@ | |
11478 | #include <QTest> | |
11479 | ||
11480 | #include "config-keepassx-tests.h" | |
11481 | -#include "tests.h" | |
11482 | #include "FailDevice.h" | |
11483 | #include "core/Database.h" | |
11484 | #include "core/Group.h" | |
11485 | diff --git a/tests/TestKeePass2XmlReader.cpp b/tests/TestKeePass2XmlReader.cpp | |
11486 | index dd81327..f04c548 100644 | |
11487 | --- a/tests/TestKeePass2XmlReader.cpp | |
11488 | +++ b/tests/TestKeePass2XmlReader.cpp | |
11489 | @@ -21,7 +21,6 @@ | |
11490 | #include <QFile> | |
11491 | #include <QTest> | |
11492 | ||
11493 | -#include "tests.h" | |
11494 | #include "core/Database.h" | |
11495 | #include "core/Group.h" | |
11496 | #include "core/Metadata.h" | |
11497 | @@ -112,12 +111,12 @@ void TestKeePass2XmlReader::testMetadata() | |
11498 | QCOMPARE(m_db->metadata()->protectUrl(), true); | |
11499 | QCOMPARE(m_db->metadata()->protectNotes(), false); | |
11500 | QCOMPARE(m_db->metadata()->recycleBinEnabled(), true); | |
11501 | - QVERIFY(m_db->metadata()->recycleBin() != Q_NULLPTR); | |
11502 | + QVERIFY(m_db->metadata()->recycleBin() != nullptr); | |
11503 | QCOMPARE(m_db->metadata()->recycleBin()->name(), QString("Recycle Bin")); | |
11504 | QCOMPARE(m_db->metadata()->recycleBinChanged(), genDT(2010, 8, 25, 16, 12, 57)); | |
11505 | - QVERIFY(m_db->metadata()->entryTemplatesGroup() == Q_NULLPTR); | |
11506 | + QVERIFY(m_db->metadata()->entryTemplatesGroup() == nullptr); | |
11507 | QCOMPARE(m_db->metadata()->entryTemplatesGroupChanged(), genDT(2010, 8, 8, 17, 24, 19)); | |
11508 | - QVERIFY(m_db->metadata()->lastSelectedGroup() != Q_NULLPTR); | |
11509 | + QVERIFY(m_db->metadata()->lastSelectedGroup() != nullptr); | |
11510 | QCOMPARE(m_db->metadata()->lastSelectedGroup()->name(), QString("NewDatabase")); | |
11511 | QVERIFY(m_db->metadata()->lastTopVisibleGroup() == m_db->metadata()->lastSelectedGroup()); | |
11512 | QCOMPARE(m_db->metadata()->historyMaxItems(), -1); | |
11513 | diff --git a/tests/TestKeys.cpp b/tests/TestKeys.cpp | |
11514 | index b661775..6c1953f 100644 | |
11515 | --- a/tests/TestKeys.cpp | |
11516 | +++ b/tests/TestKeys.cpp | |
11517 | @@ -21,7 +21,6 @@ | |
11518 | #include <QTest> | |
11519 | ||
11520 | #include "config-keepassx-tests.h" | |
11521 | -#include "tests.h" | |
11522 | #include "core/Database.h" | |
11523 | #include "core/Metadata.h" | |
11524 | #include "crypto/Crypto.h" | |
11525 | @@ -177,7 +176,7 @@ void TestKeys::benchmarkTransformKey() | |
11526 | QByteArray env = qgetenv("BENCHMARK"); | |
11527 | ||
11528 | if (env.isEmpty() || env == "0" || env == "no") { | |
11529 | - QSKIP("Benchmark skipped. Set env variable BENCHMARK=1 to enable.", SkipAll); | |
11530 | + QSKIP("Benchmark skipped. Set env variable BENCHMARK=1 to enable."); | |
11531 | } | |
11532 | ||
11533 | PasswordKey pwKey; | |
11534 | diff --git a/tests/TestModified.cpp b/tests/TestModified.cpp | |
11535 | index e275e83..70a4a48 100644 | |
11536 | --- a/tests/TestModified.cpp | |
11537 | +++ b/tests/TestModified.cpp | |
11538 | @@ -20,7 +20,6 @@ | |
11539 | #include <QSignalSpy> | |
11540 | #include <QTest> | |
11541 | ||
11542 | -#include "tests.h" | |
11543 | #include "core/Database.h" | |
11544 | #include "core/Group.h" | |
11545 | #include "core/Metadata.h" | |
11546 | @@ -237,7 +236,7 @@ void TestModified::testEntrySets() | |
11547 | entry->setExpires(entry->timeInfo().expires()); | |
11548 | QCOMPARE(spyModified.count(), spyCount); | |
11549 | ||
11550 | - entry->setExpiryTime(Tools::currentDateTimeUtc().addYears(1)); | |
11551 | + entry->setExpiryTime(QDateTime::currentDateTimeUtc().addYears(1)); | |
11552 | QCOMPARE(spyModified.count(), ++spyCount); | |
11553 | entry->setExpiryTime(entry->timeInfo().expiryTime()); | |
11554 | QCOMPARE(spyModified.count(), spyCount); | |
11555 | diff --git a/tests/TestQCommandLineParser.cpp b/tests/TestQCommandLineParser.cpp | |
11556 | deleted file mode 100644 | |
11557 | index 4e2c635..0000000 | |
11558 | --- a/tests/TestQCommandLineParser.cpp | |
11559 | +++ /dev/null | |
11560 | @@ -1,416 +0,0 @@ | |
11561 | -/**************************************************************************** | |
11562 | -** | |
11563 | -** Copyright (C) 2013 David Faure <faure@kde.org> | |
11564 | -** Contact: http://www.qt-project.org/legal | |
11565 | -** | |
11566 | -** This file is part of the test suite of the Qt Toolkit. | |
11567 | -** | |
11568 | -** $QT_BEGIN_LICENSE:LGPL$ | |
11569 | -** Commercial License Usage | |
11570 | -** Licensees holding valid commercial Qt licenses may use this file in | |
11571 | -** accordance with the commercial license agreement provided with the | |
11572 | -** Software or, alternatively, in accordance with the terms contained in | |
11573 | -** a written agreement between you and Digia. For licensing terms and | |
11574 | -** conditions see http://qt.digia.com/licensing. For further information | |
11575 | -** use the contact form at http://qt.digia.com/contact-us. | |
11576 | -** | |
11577 | -** GNU Lesser General Public License Usage | |
11578 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
11579 | -** General Public License version 2.1 as published by the Free Software | |
11580 | -** Foundation and appearing in the file LICENSE.LGPL included in the | |
11581 | -** packaging of this file. Please review the following information to | |
11582 | -** ensure the GNU Lesser General Public License version 2.1 requirements | |
11583 | -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
11584 | -** | |
11585 | -** In addition, as a special exception, Digia gives you certain additional | |
11586 | -** rights. These rights are described in the Digia Qt LGPL Exception | |
11587 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
11588 | -** | |
11589 | -** GNU General Public License Usage | |
11590 | -** Alternatively, this file may be used under the terms of the GNU | |
11591 | -** General Public License version 3.0 as published by the Free Software | |
11592 | -** Foundation and appearing in the file LICENSE.GPL included in the | |
11593 | -** packaging of this file. Please review the following information to | |
11594 | -** ensure the GNU General Public License version 3.0 requirements will be | |
11595 | -** met: http://www.gnu.org/copyleft/gpl.html. | |
11596 | -** | |
11597 | -** | |
11598 | -** $QT_END_LICENSE$ | |
11599 | -** | |
11600 | -****************************************************************************/ | |
11601 | - | |
11602 | -#include "TestQCommandLineParser.h" | |
11603 | - | |
11604 | -#include <QtTest> | |
11605 | - | |
11606 | -#include "tests.h" | |
11607 | -#include "core/qcommandlineparser.h" | |
11608 | - | |
11609 | -QTEST_GUILESS_MAIN(TestQCommandLineParser) | |
11610 | - | |
11611 | -Q_DECLARE_METATYPE(char**) | |
11612 | - | |
11613 | -static char *empty_argv[] = { 0 }; | |
11614 | -static int empty_argc = 1; | |
11615 | - | |
11616 | -void TestQCommandLineParser::initTestCase() | |
11617 | -{ | |
11618 | - Q_ASSERT(!empty_argv[0]); | |
11619 | - empty_argv[0] = const_cast<char*>("TestQCommandLineParser"); | |
11620 | -} | |
11621 | - | |
11622 | -Q_DECLARE_METATYPE(QCommandLineParser::SingleDashWordOptionMode) | |
11623 | - | |
11624 | -void TestQCommandLineParser::parsingModes_data() | |
11625 | -{ | |
11626 | - QTest::addColumn<QCommandLineParser::SingleDashWordOptionMode>("parsingMode"); | |
11627 | - | |
11628 | - QTest::newRow("collapsed") << QCommandLineParser::ParseAsCompactedShortOptions; | |
11629 | - QTest::newRow("implicitlylong") << QCommandLineParser::ParseAsLongOptions; | |
11630 | -} | |
11631 | - | |
11632 | -void TestQCommandLineParser::testInvalidOptions() | |
11633 | -{ | |
11634 | - QCoreApplication app(empty_argc, empty_argv); | |
11635 | - QCommandLineParser parser; | |
11636 | - QTest::ignoreMessage(QtWarningMsg, "QCommandLineOption: Option names cannot start with a '-'"); | |
11637 | - parser.addOption(QCommandLineOption("-v", "Displays version information.")); | |
11638 | -} | |
11639 | - | |
11640 | -void TestQCommandLineParser::testPositionalArguments() | |
11641 | -{ | |
11642 | - QCoreApplication app(empty_argc, empty_argv); | |
11643 | - QCommandLineParser parser; | |
11644 | - QVERIFY(parser.parse(QStringList() << "TestQCommandLineParser" << "file.txt")); | |
11645 | - QCOMPARE(parser.positionalArguments(), QStringList() << "file.txt"); | |
11646 | -} | |
11647 | - | |
11648 | -void TestQCommandLineParser::testBooleanOption_data() | |
11649 | -{ | |
11650 | - QTest::addColumn<QStringList>("args"); | |
11651 | - QTest::addColumn<QStringList>("expectedOptionNames"); | |
11652 | - QTest::addColumn<bool>("expectedIsSet"); | |
11653 | - | |
11654 | - QTest::newRow("set") << (QStringList() << "TestQCommandLineParser" << "-b") << (QStringList() << "b") << true; | |
11655 | - QTest::newRow("unset") << (QStringList() << "TestQCommandLineParser") << QStringList() << false; | |
11656 | -} | |
11657 | - | |
11658 | -void TestQCommandLineParser::testBooleanOption() | |
11659 | -{ | |
11660 | - QFETCH(QStringList, args); | |
11661 | - QFETCH(QStringList, expectedOptionNames); | |
11662 | - QFETCH(bool, expectedIsSet); | |
11663 | - QCoreApplication app(empty_argc, empty_argv); | |
11664 | - QCommandLineParser parser; | |
11665 | - QVERIFY(parser.addOption(QCommandLineOption("b", "a boolean option"))); | |
11666 | - QVERIFY(parser.parse(args)); | |
11667 | - QCOMPARE(parser.optionNames(), expectedOptionNames); | |
11668 | - QCOMPARE(parser.isSet("b"), expectedIsSet); | |
11669 | - QCOMPARE(parser.values("b"), QStringList()); | |
11670 | - QCOMPARE(parser.positionalArguments(), QStringList()); | |
11671 | - // Should warn on typos | |
11672 | - QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: option not defined: \"c\""); | |
11673 | - QVERIFY(!parser.isSet("c")); | |
11674 | -} | |
11675 | - | |
11676 | -void TestQCommandLineParser::testMultipleNames_data() | |
11677 | -{ | |
11678 | - QTest::addColumn<QStringList>("args"); | |
11679 | - QTest::addColumn<QStringList>("expectedOptionNames"); | |
11680 | - | |
11681 | - QTest::newRow("short") << (QStringList() << "TestQCommandLineParser" << "-v") << (QStringList() << "v"); | |
11682 | - QTest::newRow("long") << (QStringList() << "TestQCommandLineParser" << "--version") << (QStringList() << "version"); | |
11683 | - QTest::newRow("not_set") << (QStringList() << "TestQCommandLineParser") << QStringList(); | |
11684 | -} | |
11685 | - | |
11686 | -void TestQCommandLineParser::testMultipleNames() | |
11687 | -{ | |
11688 | - QFETCH(QStringList, args); | |
11689 | - QFETCH(QStringList, expectedOptionNames); | |
11690 | - QCoreApplication app(empty_argc, empty_argv); | |
11691 | - QCommandLineOption option(QStringList() << "v" << "version", "Show version information"); | |
11692 | - QCOMPARE(option.names(), QStringList() << "v" << "version"); | |
11693 | - QCommandLineParser parser; | |
11694 | - QVERIFY(parser.addOption(option)); | |
11695 | - QVERIFY(parser.parse(args)); | |
11696 | - QCOMPARE(parser.optionNames(), expectedOptionNames); | |
11697 | - const bool expectedIsSet = !expectedOptionNames.isEmpty(); | |
11698 | - QCOMPARE(parser.isSet("v"), expectedIsSet); | |
11699 | - QCOMPARE(parser.isSet("version"), expectedIsSet); | |
11700 | -} | |
11701 | - | |
11702 | -void TestQCommandLineParser::testSingleValueOption_data() | |
11703 | -{ | |
11704 | - QTest::addColumn<QStringList>("args"); | |
11705 | - QTest::addColumn<QStringList>("defaults"); | |
11706 | - QTest::addColumn<bool>("expectedIsSet"); | |
11707 | - | |
11708 | - QTest::newRow("short") << (QStringList() << "tst" << "-s" << "oxygen") << QStringList() << true; | |
11709 | - QTest::newRow("long") << (QStringList() << "tst" << "--style" << "oxygen") << QStringList() << true; | |
11710 | - QTest::newRow("longequal") << (QStringList() << "tst" << "--style=oxygen") << QStringList() << true; | |
11711 | - QTest::newRow("default") << (QStringList() << "tst") << (QStringList() << "oxygen") << false; | |
11712 | -} | |
11713 | - | |
11714 | -void TestQCommandLineParser::testSingleValueOption() | |
11715 | -{ | |
11716 | - QFETCH(QStringList, args); | |
11717 | - QFETCH(QStringList, defaults); | |
11718 | - QFETCH(bool, expectedIsSet); | |
11719 | - QCoreApplication app(empty_argc, empty_argv); | |
11720 | - QCommandLineParser parser; | |
11721 | - QCommandLineOption option(QStringList() << "s" << "style", "style name", "styleName"); | |
11722 | - option.setDefaultValues(defaults); | |
11723 | - QVERIFY(parser.addOption(option)); | |
11724 | - for (int mode = 0; mode < 2; ++mode) { | |
11725 | - parser.setSingleDashWordOptionMode(QCommandLineParser::SingleDashWordOptionMode(mode)); | |
11726 | - QVERIFY(parser.parse(args)); | |
11727 | - QCOMPARE(parser.isSet("s"), expectedIsSet); | |
11728 | - QCOMPARE(parser.isSet("style"), expectedIsSet); | |
11729 | - QCOMPARE(parser.isSet(option), expectedIsSet); | |
11730 | - QCOMPARE(parser.value("s"), QString("oxygen")); | |
11731 | - QCOMPARE(parser.value("style"), QString("oxygen")); | |
11732 | - QCOMPARE(parser.values("s"), QStringList() << "oxygen"); | |
11733 | - QCOMPARE(parser.values("style"), QStringList() << "oxygen"); | |
11734 | - QCOMPARE(parser.values(option), QStringList() << "oxygen"); | |
11735 | - QCOMPARE(parser.positionalArguments(), QStringList()); | |
11736 | - } | |
11737 | - // Should warn on typos | |
11738 | - QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: option not defined: \"c\""); | |
11739 | - QVERIFY(parser.values("c").isEmpty()); | |
11740 | -} | |
11741 | - | |
11742 | -void TestQCommandLineParser::testValueNotSet() | |
11743 | -{ | |
11744 | - QCoreApplication app(empty_argc, empty_argv); | |
11745 | - // Not set, no default value | |
11746 | - QCommandLineParser parser; | |
11747 | - QCommandLineOption option(QStringList() << "s" << "style", "style name"); | |
11748 | - option.setValueName("styleName"); | |
11749 | - QVERIFY(parser.addOption(option)); | |
11750 | - QVERIFY(parser.parse(QStringList() << "tst")); | |
11751 | - QCOMPARE(parser.optionNames(), QStringList()); | |
11752 | - QVERIFY(!parser.isSet("s")); | |
11753 | - QVERIFY(!parser.isSet("style")); | |
11754 | - QCOMPARE(parser.value("s"), QString()); | |
11755 | - QCOMPARE(parser.value("style"), QString()); | |
11756 | - QCOMPARE(parser.values("s"), QStringList()); | |
11757 | - QCOMPARE(parser.values("style"), QStringList()); | |
11758 | -} | |
11759 | - | |
11760 | -void TestQCommandLineParser::testMultipleValuesOption() | |
11761 | -{ | |
11762 | - QCoreApplication app(empty_argc, empty_argv); | |
11763 | - QCommandLineOption option("param", "Pass parameter to the backend."); | |
11764 | - option.setValueName("key=value"); | |
11765 | - QCommandLineParser parser; | |
11766 | - QVERIFY(parser.addOption(option)); | |
11767 | - { | |
11768 | - QVERIFY(parser.parse(QStringList() << "tst" << "--param" << "key1=value1")); | |
11769 | - QVERIFY(parser.isSet("param")); | |
11770 | - QCOMPARE(parser.values("param"), QStringList() << "key1=value1"); | |
11771 | - QCOMPARE(parser.value("param"), QString("key1=value1")); | |
11772 | - } | |
11773 | - { | |
11774 | - QVERIFY(parser.parse(QStringList() << "tst" << "--param" << "key1=value1" << "--param" << "key2=value2")); | |
11775 | - QVERIFY(parser.isSet("param")); | |
11776 | - QCOMPARE(parser.values("param"), QStringList() << "key1=value1" << "key2=value2"); | |
11777 | - QCOMPARE(parser.value("param"), QString("key2=value2")); | |
11778 | - } | |
11779 | - | |
11780 | - QString expected = | |
11781 | - "Usage: TestQCommandLineParser [options]\n" | |
11782 | - "\n" | |
11783 | - "Options:\n" | |
11784 | - " --param <key=value> Pass parameter to the backend.\n"; | |
11785 | - | |
11786 | - const QString exeName = QCoreApplication::instance()->arguments().first(); // e.g. debug\tst_qcommandlineparser.exe on Windows | |
11787 | - expected.replace("TestQCommandLineParser", exeName); | |
11788 | - QCOMPARE(parser.helpText(), expected); | |
11789 | -} | |
11790 | - | |
11791 | -void TestQCommandLineParser::testUnknownOptionErrorHandling_data() | |
11792 | -{ | |
11793 | - QTest::addColumn<QCommandLineParser::SingleDashWordOptionMode>("parsingMode"); | |
11794 | - QTest::addColumn<QStringList>("args"); | |
11795 | - QTest::addColumn<QStringList>("expectedUnknownOptionNames"); | |
11796 | - QTest::addColumn<QString>("expectedErrorText"); | |
11797 | - | |
11798 | - const QStringList args_hello = QStringList() << "TestQCommandLineParser" << "--hello"; | |
11799 | - const QString error_hello("Unknown option 'hello'."); | |
11800 | - QTest::newRow("unknown_name_collapsed") << QCommandLineParser::ParseAsCompactedShortOptions << args_hello << QStringList("hello") << error_hello; | |
11801 | - QTest::newRow("unknown_name_long") << QCommandLineParser::ParseAsLongOptions << args_hello << QStringList("hello") << error_hello; | |
11802 | - | |
11803 | - const QStringList args_value = QStringList() << "TestQCommandLineParser" << "-b=1"; | |
11804 | - QTest::newRow("bool_with_value_collapsed") << QCommandLineParser::ParseAsCompactedShortOptions << args_value << QStringList() << QString("Unexpected value after '-b'."); | |
11805 | - QTest::newRow("bool_with_value_long") << QCommandLineParser::ParseAsLongOptions << args_value << QStringList() << QString("Unexpected value after '-b'."); | |
11806 | - | |
11807 | - const QStringList args_dash_long = QStringList() << "TestQCommandLineParser" << "-bool"; | |
11808 | - const QString error_bool("Unknown options: o, o, l."); | |
11809 | - QTest::newRow("unknown_name_long_collapsed") << QCommandLineParser::ParseAsCompactedShortOptions << args_dash_long << (QStringList() << "o" << "o" << "l") << error_bool; | |
11810 | -} | |
11811 | - | |
11812 | -void TestQCommandLineParser::testUnknownOptionErrorHandling() | |
11813 | -{ | |
11814 | - QFETCH(QCommandLineParser::SingleDashWordOptionMode, parsingMode); | |
11815 | - QFETCH(QStringList, args); | |
11816 | - QFETCH(QStringList, expectedUnknownOptionNames); | |
11817 | - QFETCH(QString, expectedErrorText); | |
11818 | - | |
11819 | - QCoreApplication app(empty_argc, empty_argv); | |
11820 | - QCommandLineParser parser; | |
11821 | - parser.setSingleDashWordOptionMode(parsingMode); | |
11822 | - QVERIFY(parser.addOption(QCommandLineOption(QStringList() << "b" << "bool", "a boolean option"))); | |
11823 | - QCOMPARE(parser.parse(args), expectedErrorText.isEmpty()); | |
11824 | - QCOMPARE(parser.unknownOptionNames(), expectedUnknownOptionNames); | |
11825 | - QCOMPARE(parser.errorText(), expectedErrorText); | |
11826 | -} | |
11827 | - | |
11828 | -void TestQCommandLineParser::testDoubleDash_data() | |
11829 | -{ | |
11830 | - parsingModes_data(); | |
11831 | -} | |
11832 | - | |
11833 | -void TestQCommandLineParser::testDoubleDash() | |
11834 | -{ | |
11835 | - QFETCH(QCommandLineParser::SingleDashWordOptionMode, parsingMode); | |
11836 | - | |
11837 | - QCoreApplication app(empty_argc, empty_argv); | |
11838 | - QCommandLineParser parser; | |
11839 | - parser.addOption(QCommandLineOption(QStringList() << "o" << "output", "Output file", "filename")); | |
11840 | - parser.setSingleDashWordOptionMode(parsingMode); | |
11841 | - QVERIFY(parser.parse(QStringList() << "TestQCommandLineParser" << "--output" << "foo")); | |
11842 | - QCOMPARE(parser.value("output"), QString("foo")); | |
11843 | - QCOMPARE(parser.positionalArguments(), QStringList()); | |
11844 | - QCOMPARE(parser.unknownOptionNames(), QStringList()); | |
11845 | - QVERIFY(parser.parse(QStringList() << "TestQCommandLineParser" << "--" << "--output" << "bar" << "-b" << "bleh")); | |
11846 | - QCOMPARE(parser.value("output"), QString()); | |
11847 | - QCOMPARE(parser.positionalArguments(), QStringList() << "--output" << "bar" << "-b" << "bleh"); | |
11848 | - QCOMPARE(parser.unknownOptionNames(), QStringList()); | |
11849 | -} | |
11850 | - | |
11851 | -void TestQCommandLineParser::testDefaultValue() | |
11852 | -{ | |
11853 | - QCommandLineOption opt("name", "desc", | |
11854 | - "valueName", "default"); | |
11855 | - QCOMPARE(opt.defaultValues(), QStringList("default")); | |
11856 | - opt.setDefaultValue(""); | |
11857 | - QCOMPARE(opt.defaultValues(), QStringList()); | |
11858 | - opt.setDefaultValue("default"); | |
11859 | - QCOMPARE(opt.defaultValues(), QStringList("default")); | |
11860 | -} | |
11861 | - | |
11862 | -void TestQCommandLineParser::testProcessNotCalled() | |
11863 | -{ | |
11864 | - QCoreApplication app(empty_argc, empty_argv); | |
11865 | - QCommandLineParser parser; | |
11866 | - QVERIFY(parser.addOption(QCommandLineOption("b", "a boolean option"))); | |
11867 | - QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: call process() or parse() before isSet"); | |
11868 | - QVERIFY(!parser.isSet("b")); | |
11869 | - QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: call process() or parse() before values"); | |
11870 | - QCOMPARE(parser.values("b"), QStringList()); | |
11871 | -} | |
11872 | - | |
11873 | -void TestQCommandLineParser::testEmptyArgsList() | |
11874 | -{ | |
11875 | - QCoreApplication app(empty_argc, empty_argv); | |
11876 | - QCommandLineParser parser; | |
11877 | - QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: argument list cannot be empty, it should contain at least the executable name"); | |
11878 | - QVERIFY(!parser.parse(QStringList())); // invalid call, argv[0] is missing | |
11879 | -} | |
11880 | - | |
11881 | -void TestQCommandLineParser::testMissingOptionValue() | |
11882 | -{ | |
11883 | - QCoreApplication app(empty_argc, empty_argv); | |
11884 | - QCommandLineParser parser; | |
11885 | - parser.addOption(QCommandLineOption("option", "An option", "value")); | |
11886 | - QVERIFY(!parser.parse(QStringList() << "argv0" << "--option")); // the user forgot to pass a value for --option | |
11887 | - QCOMPARE(parser.value("option"), QString()); | |
11888 | - QCOMPARE(parser.errorText(), QString("Missing value after '--option'.")); | |
11889 | -} | |
11890 | - | |
11891 | -void TestQCommandLineParser::testStdinArgument_data() | |
11892 | -{ | |
11893 | - parsingModes_data(); | |
11894 | -} | |
11895 | - | |
11896 | -void TestQCommandLineParser::testStdinArgument() | |
11897 | -{ | |
11898 | - QFETCH(QCommandLineParser::SingleDashWordOptionMode, parsingMode); | |
11899 | - | |
11900 | - QCoreApplication app(empty_argc, empty_argv); | |
11901 | - QCommandLineParser parser; | |
11902 | - parser.setSingleDashWordOptionMode(parsingMode); | |
11903 | - parser.addOption(QCommandLineOption(QStringList() << "i" << "input", "Input file.", "filename")); | |
11904 | - parser.addOption(QCommandLineOption("b", "Boolean option.")); | |
11905 | - QVERIFY(parser.parse(QStringList() << "TestQCommandLineParser" << "--input" << "-")); | |
11906 | - QCOMPARE(parser.value("input"), QString("-")); | |
11907 | - QCOMPARE(parser.positionalArguments(), QStringList()); | |
11908 | - QCOMPARE(parser.unknownOptionNames(), QStringList()); | |
11909 | - | |
11910 | - QVERIFY(parser.parse(QStringList() << "TestQCommandLineParser" << "--input" << "-" << "-b" << "arg")); | |
11911 | - QCOMPARE(parser.value("input"), QString("-")); | |
11912 | - QVERIFY(parser.isSet("b")); | |
11913 | - QCOMPARE(parser.positionalArguments(), QStringList() << "arg"); | |
11914 | - QCOMPARE(parser.unknownOptionNames(), QStringList()); | |
11915 | - | |
11916 | - QVERIFY(parser.parse(QStringList() << "TestQCommandLineParser" << "-")); | |
11917 | - QCOMPARE(parser.value("input"), QString()); | |
11918 | - QVERIFY(!parser.isSet("b")); | |
11919 | - QCOMPARE(parser.positionalArguments(), QStringList() << "-"); | |
11920 | - QCOMPARE(parser.unknownOptionNames(), QStringList()); | |
11921 | -} | |
11922 | - | |
11923 | -void TestQCommandLineParser::testSingleDashWordOptionModes_data() | |
11924 | -{ | |
11925 | - QTest::addColumn<QCommandLineParser::SingleDashWordOptionMode>("parsingMode"); | |
11926 | - QTest::addColumn<QStringList>("commandLine"); | |
11927 | - QTest::addColumn<QStringList>("expectedOptionNames"); | |
11928 | - QTest::addColumn<QStringList>("expectedOptionValues"); | |
11929 | - | |
11930 | - QTest::newRow("collapsed") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-abc" << "val") | |
11931 | - << (QStringList() << "a" << "b" << "c") << (QStringList() << QString() << QString() << "val"); | |
11932 | - QTest::newRow("collapsed_with_equalsign_value") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-abc=val") | |
11933 | - << (QStringList() << "a" << "b" << "c") << (QStringList() << QString() << QString() << "val"); | |
11934 | - QTest::newRow("collapsed_explicit_longoption") << QCommandLineParser::ParseAsCompactedShortOptions << QStringList("--nn") | |
11935 | - << QStringList("nn") << QStringList(); | |
11936 | - QTest::newRow("collapsed_longoption_value") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "--abc" << "val") | |
11937 | - << QStringList("abc") << QStringList("val"); | |
11938 | - QTest::newRow("compiler") << QCommandLineParser::ParseAsCompactedShortOptions << QStringList("-cab") | |
11939 | - << QStringList("c") << QStringList("ab"); | |
11940 | - QTest::newRow("compiler_with_space") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-c" << "val") | |
11941 | - << QStringList("c") << QStringList("val"); | |
11942 | - | |
11943 | - QTest::newRow("implicitlylong") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-abc" << "val") | |
11944 | - << QStringList("abc") << QStringList("val"); | |
11945 | - QTest::newRow("implicitlylong_equal") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-abc=val") | |
11946 | - << QStringList("abc") << QStringList("val"); | |
11947 | - QTest::newRow("implicitlylong_longoption") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "--nn") | |
11948 | - << QStringList("nn") << QStringList(); | |
11949 | - QTest::newRow("implicitlylong_longoption_value") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "--abc" << "val") | |
11950 | - << QStringList("abc") << QStringList("val"); | |
11951 | - QTest::newRow("implicitlylong_with_space") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-c" << "val") | |
11952 | - << QStringList("c") << QStringList("val"); | |
11953 | -} | |
11954 | - | |
11955 | -void TestQCommandLineParser::testSingleDashWordOptionModes() | |
11956 | -{ | |
11957 | - QFETCH(QCommandLineParser::SingleDashWordOptionMode, parsingMode); | |
11958 | - QFETCH(QStringList, commandLine); | |
11959 | - QFETCH(QStringList, expectedOptionNames); | |
11960 | - QFETCH(QStringList, expectedOptionValues); | |
11961 | - | |
11962 | - commandLine.prepend("TestQCommandLineParser"); | |
11963 | - | |
11964 | - QCoreApplication app(empty_argc, empty_argv); | |
11965 | - QCommandLineParser parser; | |
11966 | - parser.setSingleDashWordOptionMode(parsingMode); | |
11967 | - parser.addOption(QCommandLineOption("a", "a option.")); | |
11968 | - parser.addOption(QCommandLineOption("b", "b option.")); | |
11969 | - parser.addOption(QCommandLineOption(QStringList() << "c" << "abc", "c option.", "value")); | |
11970 | - parser.addOption(QCommandLineOption("nn", "nn option.")); | |
11971 | - QVERIFY(parser.parse(commandLine)); | |
11972 | - QCOMPARE(parser.optionNames(), expectedOptionNames); | |
11973 | - for (int i = 0; i < expectedOptionValues.count(); ++i) | |
11974 | - QCOMPARE(parser.value(parser.optionNames().at(i)), expectedOptionValues.at(i)); | |
11975 | - QCOMPARE(parser.unknownOptionNames(), QStringList()); | |
11976 | -} | |
11977 | diff --git a/tests/TestQCommandLineParser.h b/tests/TestQCommandLineParser.h | |
11978 | deleted file mode 100644 | |
11979 | index 46214cd..0000000 | |
11980 | --- a/tests/TestQCommandLineParser.h | |
11981 | +++ /dev/null | |
11982 | @@ -1,82 +0,0 @@ | |
11983 | -/**************************************************************************** | |
11984 | -** | |
11985 | -** Copyright (C) 2013 David Faure <faure@kde.org> | |
11986 | -** Contact: http://www.qt-project.org/legal | |
11987 | -** | |
11988 | -** This file is part of the test suite of the Qt Toolkit. | |
11989 | -** | |
11990 | -** $QT_BEGIN_LICENSE:LGPL$ | |
11991 | -** Commercial License Usage | |
11992 | -** Licensees holding valid commercial Qt licenses may use this file in | |
11993 | -** accordance with the commercial license agreement provided with the | |
11994 | -** Software or, alternatively, in accordance with the terms contained in | |
11995 | -** a written agreement between you and Digia. For licensing terms and | |
11996 | -** conditions see http://qt.digia.com/licensing. For further information | |
11997 | -** use the contact form at http://qt.digia.com/contact-us. | |
11998 | -** | |
11999 | -** GNU Lesser General Public License Usage | |
12000 | -** Alternatively, this file may be used under the terms of the GNU Lesser | |
12001 | -** General Public License version 2.1 as published by the Free Software | |
12002 | -** Foundation and appearing in the file LICENSE.LGPL included in the | |
12003 | -** packaging of this file. Please review the following information to | |
12004 | -** ensure the GNU Lesser General Public License version 2.1 requirements | |
12005 | -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
12006 | -** | |
12007 | -** In addition, as a special exception, Digia gives you certain additional | |
12008 | -** rights. These rights are described in the Digia Qt LGPL Exception | |
12009 | -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
12010 | -** | |
12011 | -** GNU General Public License Usage | |
12012 | -** Alternatively, this file may be used under the terms of the GNU | |
12013 | -** General Public License version 3.0 as published by the Free Software | |
12014 | -** Foundation and appearing in the file LICENSE.GPL included in the | |
12015 | -** packaging of this file. Please review the following information to | |
12016 | -** ensure the GNU General Public License version 3.0 requirements will be | |
12017 | -** met: http://www.gnu.org/copyleft/gpl.html. | |
12018 | -** | |
12019 | -** | |
12020 | -** $QT_END_LICENSE$ | |
12021 | -** | |
12022 | -****************************************************************************/ | |
12023 | - | |
12024 | -#ifndef KEEPASSX_TESTQCOMMANDLINEPARSER_H | |
12025 | -#define KEEPASSX_TESTQCOMMANDLINEPARSER_H | |
12026 | - | |
12027 | -#include <QObject> | |
12028 | - | |
12029 | -class TestQCommandLineParser : public QObject | |
12030 | -{ | |
12031 | - Q_OBJECT | |
12032 | - | |
12033 | -public Q_SLOTS: | |
12034 | - void initTestCase(); | |
12035 | - | |
12036 | -private Q_SLOTS: | |
12037 | - void parsingModes_data(); | |
12038 | - | |
12039 | - // In-process tests | |
12040 | - void testInvalidOptions(); | |
12041 | - void testPositionalArguments(); | |
12042 | - void testBooleanOption_data(); | |
12043 | - void testBooleanOption(); | |
12044 | - void testMultipleNames_data(); | |
12045 | - void testMultipleNames(); | |
12046 | - void testSingleValueOption_data(); | |
12047 | - void testSingleValueOption(); | |
12048 | - void testValueNotSet(); | |
12049 | - void testMultipleValuesOption(); | |
12050 | - void testUnknownOptionErrorHandling_data(); | |
12051 | - void testUnknownOptionErrorHandling(); | |
12052 | - void testDoubleDash_data(); | |
12053 | - void testDoubleDash(); | |
12054 | - void testDefaultValue(); | |
12055 | - void testProcessNotCalled(); | |
12056 | - void testEmptyArgsList(); | |
12057 | - void testMissingOptionValue(); | |
12058 | - void testStdinArgument_data(); | |
12059 | - void testStdinArgument(); | |
12060 | - void testSingleDashWordOptionModes_data(); | |
12061 | - void testSingleDashWordOptionModes(); | |
12062 | -}; | |
12063 | - | |
12064 | -#endif // KEEPASSX_TESTQCOMMANDLINEPARSER_H | |
12065 | diff --git a/tests/TestQSaveFile.cpp b/tests/TestQSaveFile.cpp | |
12066 | deleted file mode 100644 | |
12067 | index 443db52..0000000 | |
12068 | --- a/tests/TestQSaveFile.cpp | |
12069 | +++ /dev/null | |
12070 | @@ -1,204 +0,0 @@ | |
12071 | -/* | |
12072 | - * Copyright (C) 2012 Felix Geyer <debfx@fobos.de> | |
12073 | - * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) | |
12074 | - * | |
12075 | - * This program is free software: you can redistribute it and/or modify | |
12076 | - * it under the terms of the GNU General Public License as published by | |
12077 | - * the Free Software Foundation, either version 2 or (at your option) | |
12078 | - * version 3 of the License. | |
12079 | - * | |
12080 | - * This program is distributed in the hope that it will be useful, | |
12081 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12082 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12083 | - * GNU General Public License for more details. | |
12084 | - * | |
12085 | - * You should have received a copy of the GNU General Public License | |
12086 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
12087 | - */ | |
12088 | - | |
12089 | -#include "TestQSaveFile.h" | |
12090 | - | |
12091 | -#include <QtTest> | |
12092 | - | |
12093 | -#include <unistd.h> | |
12094 | - | |
12095 | -#if defined(Q_OS_WIN) | |
12096 | -# include <windows.h> | |
12097 | -#endif | |
12098 | - | |
12099 | -#include "tests.h" | |
12100 | -#include "core/qsavefile.h" | |
12101 | - | |
12102 | -QTEST_GUILESS_MAIN(TestQSaveFile) | |
12103 | - | |
12104 | -class DirCleanup | |
12105 | -{ | |
12106 | -public: | |
12107 | - DirCleanup(const QString& dir, const QString& filePrefix) : m_dir(dir), m_filePrefix(filePrefix) {} | |
12108 | - ~DirCleanup() { | |
12109 | - QDir dir(m_dir); | |
12110 | - QStringList files = dir.entryList(QStringList() << (m_filePrefix + "*"), QDir::Files); | |
12111 | - Q_FOREACH (const QString& file, files) { | |
12112 | - QFile::remove(m_dir + "/" + file); | |
12113 | - } | |
12114 | - | |
12115 | - QDir().rmdir(m_dir); | |
12116 | - } | |
12117 | - | |
12118 | -private: | |
12119 | - QString m_dir; | |
12120 | - QString m_filePrefix; | |
12121 | -}; | |
12122 | - | |
12123 | -void TestQSaveFile::transactionalWrite() | |
12124 | -{ | |
12125 | - const QString dir = tmpDir(); | |
12126 | - QVERIFY(!dir.isEmpty()); | |
12127 | - const QString targetFile = dir + QString::fromLatin1("/outfile"); | |
12128 | - DirCleanup dirCleanup(dir, "outfile"); | |
12129 | - QFile::remove(targetFile); | |
12130 | - QSaveFile file(targetFile); | |
12131 | - QVERIFY(file.open(QIODevice::WriteOnly)); | |
12132 | - QVERIFY(file.isOpen()); | |
12133 | - QCOMPARE(file.fileName(), targetFile); | |
12134 | - QVERIFY(!QFile::exists(targetFile)); | |
12135 | - | |
12136 | - QTextStream ts(&file); | |
12137 | - ts << "This is test data one.\n"; | |
12138 | - ts.flush(); | |
12139 | - QCOMPARE(file.error(), QFile::NoError); | |
12140 | - QVERIFY(!QFile::exists(targetFile)); | |
12141 | - | |
12142 | - QVERIFY(file.commit()); | |
12143 | - QVERIFY(QFile::exists(targetFile)); | |
12144 | - QCOMPARE(file.fileName(), targetFile); | |
12145 | - | |
12146 | - // Check that we can reuse a QSaveFile object | |
12147 | - // (and test the case of an existing target file) | |
12148 | - QVERIFY(file.open(QIODevice::WriteOnly)); | |
12149 | - QCOMPARE(file.write("Hello"), 5LL); | |
12150 | - QVERIFY(file.commit()); | |
12151 | - | |
12152 | - QFile reader(targetFile); | |
12153 | - QVERIFY(reader.open(QIODevice::ReadOnly)); | |
12154 | - QCOMPARE(QString::fromLatin1(reader.readAll().constData()), QString::fromLatin1("Hello")); | |
12155 | - reader.close(); | |
12156 | - | |
12157 | - QVERIFY(QFile::remove(targetFile)); | |
12158 | -} | |
12159 | - | |
12160 | -void TestQSaveFile::autoFlush() | |
12161 | -{ | |
12162 | - const QString dir = tmpDir(); | |
12163 | - QVERIFY(!dir.isEmpty()); | |
12164 | - const QString targetFile = dir + QString::fromLatin1("/outfile"); | |
12165 | - DirCleanup dirCleanup(dir, "outfile"); | |
12166 | - QFile::remove(targetFile); | |
12167 | - QSaveFile file(targetFile); | |
12168 | - QVERIFY(file.open(QIODevice::WriteOnly)); | |
12169 | - | |
12170 | - QTextStream ts(&file); | |
12171 | - ts << "Auto-flush."; | |
12172 | - // no flush | |
12173 | - QVERIFY(file.commit()); // close will emit aboutToClose, which will flush the stream | |
12174 | - QFile reader(targetFile); | |
12175 | - QVERIFY(reader.open(QIODevice::ReadOnly)); | |
12176 | - QCOMPARE(QString::fromLatin1(reader.readAll().constData()), QString::fromLatin1("Auto-flush.")); | |
12177 | - reader.close(); | |
12178 | - | |
12179 | - QVERIFY(QFile::remove(targetFile)); | |
12180 | -} | |
12181 | - | |
12182 | -void TestQSaveFile::transactionalWriteNoPermissions() | |
12183 | -{ | |
12184 | -#ifdef Q_OS_UNIX | |
12185 | - if (::geteuid() == 0) { | |
12186 | - QSKIP("not valid running this test as root", SkipAll); | |
12187 | - } | |
12188 | - | |
12189 | - // You can write into /dev/zero, but you can't create a /dev/zero.XXXXXX temp file. | |
12190 | - QSaveFile file("/dev/zero"); | |
12191 | - if (!QDir("/dev").exists()) { | |
12192 | - QSKIP("/dev doesn't exist on this system", SkipAll); | |
12193 | - } | |
12194 | - | |
12195 | - QVERIFY(!file.open(QIODevice::WriteOnly)); | |
12196 | - QCOMPARE(static_cast<int>(file.error()), static_cast<int>(QFile::OpenError)); | |
12197 | - QVERIFY(!file.commit()); | |
12198 | -#endif | |
12199 | -} | |
12200 | - | |
12201 | -void TestQSaveFile::transactionalWriteCanceled() | |
12202 | -{ | |
12203 | - const QString dir = tmpDir(); | |
12204 | - QVERIFY(!dir.isEmpty()); | |
12205 | - const QString targetFile = dir + QString::fromLatin1("/outfile"); | |
12206 | - DirCleanup dirCleanup(dir, "outfile"); | |
12207 | - QFile::remove(targetFile); | |
12208 | - QSaveFile file(targetFile); | |
12209 | - QVERIFY(file.open(QIODevice::WriteOnly)); | |
12210 | - | |
12211 | - QTextStream ts(&file); | |
12212 | - ts << "This writing operation will soon be canceled.\n"; | |
12213 | - ts.flush(); | |
12214 | - QCOMPARE(file.error(), QFile::NoError); | |
12215 | - QVERIFY(!QFile::exists(targetFile)); | |
12216 | - | |
12217 | - // We change our mind, let's abort writing | |
12218 | - file.cancelWriting(); | |
12219 | - | |
12220 | - QVERIFY(!file.commit()); | |
12221 | - | |
12222 | - QVERIFY(!QFile::exists(targetFile)); // temp file was discarded | |
12223 | - QCOMPARE(file.fileName(), targetFile); | |
12224 | -} | |
12225 | - | |
12226 | -void TestQSaveFile::transactionalWriteErrorRenaming() | |
12227 | -{ | |
12228 | -#ifndef Q_OS_WIN | |
12229 | - if (::geteuid() == 0) { | |
12230 | - QSKIP("not valid running this test as root", SkipAll); | |
12231 | - } | |
12232 | - const QString dir = tmpDir(); | |
12233 | - QVERIFY(!dir.isEmpty()); | |
12234 | - const QString targetFile = dir + QString::fromLatin1("/outfile"); | |
12235 | - DirCleanup dirCleanup(dir, "outfile"); | |
12236 | - QSaveFile file(targetFile); | |
12237 | - QVERIFY(file.open(QIODevice::WriteOnly)); | |
12238 | - QCOMPARE(file.write("Hello"), qint64(5)); | |
12239 | - QVERIFY(!QFile::exists(targetFile)); | |
12240 | - | |
12241 | -#ifdef Q_OS_UNIX | |
12242 | - QFile dirAsFile(dir); // yay, I have to use QFile to change a dir's permissions... | |
12243 | - QVERIFY(dirAsFile.setPermissions(QFile::Permissions(0))); // no permissions | |
12244 | -#else | |
12245 | - QVERIFY(file.setPermissions(QFile::ReadOwner)); | |
12246 | -#endif | |
12247 | - | |
12248 | - QVERIFY(!file.commit()); | |
12249 | - QVERIFY(!QFile::exists(targetFile)); // renaming failed | |
12250 | - QCOMPARE(file.error(), QFile::RenameError); | |
12251 | - | |
12252 | - // Restore permissions so that the cleanup can happen | |
12253 | -#ifdef Q_OS_UNIX | |
12254 | - QVERIFY(dirAsFile.setPermissions(QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner))); | |
12255 | -#else | |
12256 | - QVERIFY(file.setPermissions(QFile::ReadOwner | QFile::WriteOwner)); | |
12257 | -#endif | |
12258 | -#endif // !Q_OS_WIN | |
12259 | -} | |
12260 | - | |
12261 | -QString TestQSaveFile::tmpDir() | |
12262 | -{ | |
12263 | - QTemporaryFile* tmpFile = new QTemporaryFile(QDir::tempPath() + "/qttest_temp.XXXXXX"); | |
12264 | - if (!tmpFile->open()) { | |
12265 | - return QString(); | |
12266 | - } | |
12267 | - QString dirName = tmpFile->fileName(); | |
12268 | - delete tmpFile; | |
12269 | - if (!QDir().mkdir(dirName)) { | |
12270 | - return QString(); | |
12271 | - } | |
12272 | - | |
12273 | - return dirName; | |
12274 | -} | |
12275 | diff --git a/tests/TestQSaveFile.h b/tests/TestQSaveFile.h | |
12276 | deleted file mode 100644 | |
12277 | index 8e1caf0..0000000 | |
12278 | --- a/tests/TestQSaveFile.h | |
12279 | +++ /dev/null | |
12280 | @@ -1,39 +0,0 @@ | |
12281 | -/* | |
12282 | - * Copyright (C) 2012 Felix Geyer <debfx@fobos.de> | |
12283 | - * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) | |
12284 | - * | |
12285 | - * This program is free software: you can redistribute it and/or modify | |
12286 | - * it under the terms of the GNU General Public License as published by | |
12287 | - * the Free Software Foundation, either version 2 or (at your option) | |
12288 | - * version 3 of the License. | |
12289 | - * | |
12290 | - * This program is distributed in the hope that it will be useful, | |
12291 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12292 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12293 | - * GNU General Public License for more details. | |
12294 | - * | |
12295 | - * You should have received a copy of the GNU General Public License | |
12296 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
12297 | - */ | |
12298 | - | |
12299 | -#ifndef KEEPASSX_TESTQSAVEFILE_H | |
12300 | -#define KEEPASSX_TESTQSAVEFILE_H | |
12301 | - | |
12302 | -#include <QObject> | |
12303 | - | |
12304 | -class TestQSaveFile : public QObject | |
12305 | -{ | |
12306 | - Q_OBJECT | |
12307 | - | |
12308 | -private Q_SLOTS: | |
12309 | - void transactionalWrite(); | |
12310 | - void autoFlush(); | |
12311 | - void transactionalWriteNoPermissions(); | |
12312 | - void transactionalWriteCanceled(); | |
12313 | - void transactionalWriteErrorRenaming(); | |
12314 | - | |
12315 | -private: | |
12316 | - QString tmpDir(); | |
12317 | -}; | |
12318 | - | |
12319 | -#endif // KEEPASSX_TESTQSAVEFILE_H | |
12320 | diff --git a/tests/TestRandom.cpp b/tests/TestRandom.cpp | |
12321 | index 40ab702..6c5b1f7 100644 | |
12322 | --- a/tests/TestRandom.cpp | |
12323 | +++ b/tests/TestRandom.cpp | |
12324 | @@ -17,8 +17,8 @@ | |
12325 | ||
12326 | #include "TestRandom.h" | |
12327 | ||
12328 | -#include "tests.h" | |
12329 | #include "core/Endian.h" | |
12330 | +#include "core/Global.h" | |
12331 | ||
12332 | #include <QTest> | |
12333 | ||
12334 | diff --git a/tests/TestRandom.h b/tests/TestRandom.h | |
12335 | index a308f36..c879f94 100644 | |
12336 | --- a/tests/TestRandom.h | |
12337 | +++ b/tests/TestRandom.h | |
12338 | @@ -18,7 +18,6 @@ | |
12339 | #ifndef KEEPASSX_TESTRANDOM_H | |
12340 | #define KEEPASSX_TESTRANDOM_H | |
12341 | ||
12342 | -#include "core/Global.h" | |
12343 | #include "crypto/Random.h" | |
12344 | ||
12345 | #include <QObject> | |
12346 | @@ -27,7 +26,7 @@ class RandomBackendTest : public RandomBackend | |
12347 | { | |
12348 | public: | |
12349 | RandomBackendTest(); | |
12350 | - void randomize(void* data, int len) Q_DECL_OVERRIDE; | |
12351 | + void randomize(void* data, int len) override; | |
12352 | void setNextBytes(const QByteArray& nextBytes); | |
12353 | ||
12354 | private: | |
12355 | diff --git a/tests/TestSymmetricCipher.cpp b/tests/TestSymmetricCipher.cpp | |
12356 | index 578d250..698ecb2 100644 | |
12357 | --- a/tests/TestSymmetricCipher.cpp | |
12358 | +++ b/tests/TestSymmetricCipher.cpp | |
12359 | @@ -20,7 +20,6 @@ | |
12360 | #include <QBuffer> | |
12361 | #include <QTest> | |
12362 | ||
12363 | -#include "tests.h" | |
12364 | #include "crypto/Crypto.h" | |
12365 | #include "crypto/SymmetricCipher.h" | |
12366 | #include "streams/SymmetricCipherStream.h" | |
12367 | diff --git a/tests/TestWildcardMatcher.cpp b/tests/TestWildcardMatcher.cpp | |
12368 | index dc9991d..dffe1c8 100644 | |
12369 | --- a/tests/TestWildcardMatcher.cpp | |
12370 | +++ b/tests/TestWildcardMatcher.cpp | |
12371 | @@ -19,7 +19,6 @@ | |
12372 | ||
12373 | #include <QTest> | |
12374 | ||
12375 | -#include "tests.h" | |
12376 | #include "autotype/WildcardMatcher.h" | |
12377 | ||
12378 | QTEST_GUILESS_MAIN(TestWildcardMatcher) | |
12379 | diff --git a/tests/gui/CMakeLists.txt b/tests/gui/CMakeLists.txt | |
12380 | index 91fcd69..a1ca914 100644 | |
12381 | --- a/tests/gui/CMakeLists.txt | |
12382 | +++ b/tests/gui/CMakeLists.txt | |
12383 | @@ -13,6 +13,6 @@ | |
12384 | # You should have received a copy of the GNU General Public License | |
12385 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
12386 | ||
12387 | -add_unit_test(NAME testgui SOURCES TestGui.cpp MOCS TestGui.h LIBS ${TEST_LIBRARIES}) | |
12388 | +add_unit_test(NAME testgui SOURCES TestGui.cpp LIBS ${TEST_LIBRARIES}) | |
12389 | ||
12390 | -add_unit_test(NAME testguipixmaps SOURCES TestGuiPixmaps.cpp MOCS TestGuiPixmaps.h LIBS ${TEST_LIBRARIES}) | |
12391 | +add_unit_test(NAME testguipixmaps SOURCES TestGuiPixmaps.cpp LIBS ${TEST_LIBRARIES}) | |
12392 | diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp | |
12393 | index 6aa49b8..1585c8a 100644 | |
12394 | --- a/tests/gui/TestGui.cpp | |
12395 | +++ b/tests/gui/TestGui.cpp | |
12396 | @@ -21,6 +21,7 @@ | |
12397 | #include <QApplication> | |
12398 | #include <QDialogButtonBox> | |
12399 | #include <QLineEdit> | |
12400 | +#include <QMimeData> | |
12401 | #include <QPushButton> | |
12402 | #include <QSpinBox> | |
12403 | #include <QTemporaryFile> | |
12404 | @@ -29,7 +30,6 @@ | |
12405 | #include <QToolButton> | |
12406 | ||
12407 | #include "config-keepassx-tests.h" | |
12408 | -#include "tests.h" | |
12409 | #include "core/Config.h" | |
12410 | #include "core/Database.h" | |
12411 | #include "core/Entry.h" | |
12412 | @@ -56,6 +56,7 @@ void TestGui::initTestCase() | |
12413 | m_mainWindow = new MainWindow(); | |
12414 | m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget"); | |
12415 | m_mainWindow->show(); | |
12416 | + m_mainWindow->activateWindow(); | |
12417 | Tools::wait(50); | |
12418 | ||
12419 | QByteArray tmpData; | |
12420 | @@ -184,7 +185,7 @@ void TestGui::testSearch() | |
12421 | QLineEdit* searchEdit = m_dbWidget->findChild<QLineEdit*>("searchEdit"); | |
12422 | QToolButton* clearSearch = m_dbWidget->findChild<QToolButton*>("clearButton"); | |
12423 | ||
12424 | - QVERIFY(!searchEdit->hasFocus()); | |
12425 | + QVERIFY(!searchEdit->isVisible()); | |
12426 | ||
12427 | // Enter search | |
12428 | QTest::mouseClick(searchActionWidget, Qt::LeftButton); | |
12429 | @@ -439,8 +440,8 @@ void TestGui::testDatabaseLocking() | |
12430 | ||
12431 | triggerAction("actionLockDatabases"); | |
12432 | ||
12433 | - QCOMPARE(m_tabWidget->tabText(0), QString("Save [locked]")); | |
12434 | - QCOMPARE(m_tabWidget->tabText(1), QString("basic [New database]*")); | |
12435 | + QCOMPARE(m_tabWidget->tabText(0).remove('&'), QString("Save [locked]")); | |
12436 | + QCOMPARE(m_tabWidget->tabText(1).remove('&'), QString("basic [New database]*")); | |
12437 | ||
12438 | QWidget* dbWidget = m_tabWidget->currentDatabaseWidget(); | |
12439 | QWidget* unlockDatabaseWidget = dbWidget->findChild<QWidget*>("unlockDatabaseWidget"); | |
12440 | @@ -450,7 +451,7 @@ void TestGui::testDatabaseLocking() | |
12441 | QTest::keyClicks(editPassword, "masterpw"); | |
12442 | QTest::keyClick(editPassword, Qt::Key_Enter); | |
12443 | ||
12444 | - QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("basic [New database]*")); | |
12445 | + QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()).remove('&'), QString("basic [New database]*")); | |
12446 | } | |
12447 | ||
12448 | void TestGui::cleanupTestCase() | |
12449 | diff --git a/tests/gui/TestGuiPixmaps.cpp b/tests/gui/TestGuiPixmaps.cpp | |
12450 | index 87e3f24..3637494 100644 | |
12451 | --- a/tests/gui/TestGuiPixmaps.cpp | |
12452 | +++ b/tests/gui/TestGuiPixmaps.cpp | |
12453 | @@ -19,7 +19,6 @@ | |
12454 | ||
12455 | #include <QTest> | |
12456 | ||
12457 | -#include "tests.h" | |
12458 | #include "core/Database.h" | |
12459 | #include "core/DatabaseIcons.h" | |
12460 | #include "core/Entry.h" | |
12461 | diff --git a/tests/modeltest.cpp b/tests/modeltest.cpp | |
12462 | index 19f02d9..360a7be 100644 | |
12463 | --- a/tests/modeltest.cpp | |
12464 | +++ b/tests/modeltest.cpp | |
12465 | @@ -1,50 +1,40 @@ | |
12466 | /**************************************************************************** | |
12467 | ** | |
12468 | -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). | |
12469 | -** Contact: http://www.qt-project.org/ | |
12470 | +** Copyright (C) 2015 The Qt Company Ltd. | |
12471 | +** Contact: http://www.qt.io/licensing/ | |
12472 | ** | |
12473 | ** This file is part of the test suite of the Qt Toolkit. | |
12474 | ** | |
12475 | -** $QT_BEGIN_LICENSE:LGPL$ | |
12476 | +** $QT_BEGIN_LICENSE:LGPL21$ | |
12477 | +** Commercial License Usage | |
12478 | +** Licensees holding valid commercial Qt licenses may use this file in | |
12479 | +** accordance with the commercial license agreement provided with the | |
12480 | +** Software or, alternatively, in accordance with the terms contained in | |
12481 | +** a written agreement between you and The Qt Company. For licensing terms | |
12482 | +** and conditions see http://www.qt.io/terms-conditions. For further | |
12483 | +** information use the contact form at http://www.qt.io/contact-us. | |
12484 | +** | |
12485 | ** GNU Lesser General Public License Usage | |
12486 | -** This file may be used under the terms of the GNU Lesser General Public | |
12487 | -** License version 2.1 as published by the Free Software Foundation and | |
12488 | -** appearing in the file LICENSE.LGPL included in the packaging of this | |
12489 | -** file. Please review the following information to ensure the GNU Lesser | |
12490 | -** General Public License version 2.1 requirements will be met: | |
12491 | +** Alternatively, this file may be used under the terms of the GNU Lesser | |
12492 | +** General Public License version 2.1 or version 3 as published by the Free | |
12493 | +** Software Foundation and appearing in the file LICENSE.LGPLv21 and | |
12494 | +** LICENSE.LGPLv3 included in the packaging of this file. Please review the | |
12495 | +** following information to ensure the GNU Lesser General Public License | |
12496 | +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | |
12497 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
12498 | ** | |
12499 | -** In addition, as a special exception, Nokia gives you certain additional | |
12500 | -** rights. These rights are described in the Nokia Qt LGPL Exception | |
12501 | +** As a special exception, The Qt Company gives you certain additional | |
12502 | +** rights. These rights are described in The Qt Company LGPL Exception | |
12503 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
12504 | ** | |
12505 | -** GNU General Public License Usage | |
12506 | -** Alternatively, this file may be used under the terms of the GNU General | |
12507 | -** Public License version 3.0 as published by the Free Software Foundation | |
12508 | -** and appearing in the file LICENSE.GPL included in the packaging of this | |
12509 | -** file. Please review the following information to ensure the GNU General | |
12510 | -** Public License version 3.0 requirements will be met: | |
12511 | -** http://www.gnu.org/copyleft/gpl.html. | |
12512 | -** | |
12513 | -** Other Usage | |
12514 | -** Alternatively, this file may be used in accordance with the terms and | |
12515 | -** conditions contained in a signed written agreement between you and Nokia. | |
12516 | -** | |
12517 | -** | |
12518 | -** | |
12519 | -** | |
12520 | -** | |
12521 | ** $QT_END_LICENSE$ | |
12522 | ** | |
12523 | ****************************************************************************/ | |
12524 | ||
12525 | - | |
12526 | #include "modeltest.h" | |
12527 | ||
12528 | -#include <QDebug> | |
12529 | -#include <QTest> | |
12530 | - | |
12531 | -Q_DECLARE_METATYPE ( QModelIndex ) | |
12532 | +#include <QtCore> | |
12533 | +#include <QtTest> | |
12534 | ||
12535 | /*! | |
12536 | Connect to all of the models signals. Whenever anything happens recheck everything. | |
12537 | @@ -54,50 +44,52 @@ ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QObject ( | |
12538 | if (!model) | |
12539 | qFatal("%s: model must not be null", Q_FUNC_INFO); | |
12540 | ||
12541 | - connect ( model, SIGNAL ( columnsAboutToBeInserted ( const QModelIndex &, int, int ) ), | |
12542 | - this, SLOT ( runAllTests() ) ); | |
12543 | - connect ( model, SIGNAL ( columnsAboutToBeRemoved ( const QModelIndex &, int, int ) ), | |
12544 | - this, SLOT ( runAllTests() ) ); | |
12545 | - connect ( model, SIGNAL ( columnsInserted ( const QModelIndex &, int, int ) ), | |
12546 | - this, SLOT ( runAllTests() ) ); | |
12547 | - connect ( model, SIGNAL ( columnsRemoved ( const QModelIndex &, int, int ) ), | |
12548 | - this, SLOT ( runAllTests() ) ); | |
12549 | - connect ( model, SIGNAL ( dataChanged ( const QModelIndex &, const QModelIndex & ) ), | |
12550 | - this, SLOT ( runAllTests() ) ); | |
12551 | - connect ( model, SIGNAL ( headerDataChanged ( Qt::Orientation, int, int ) ), | |
12552 | - this, SLOT ( runAllTests() ) ); | |
12553 | - connect ( model, SIGNAL ( layoutAboutToBeChanged () ), this, SLOT ( runAllTests() ) ); | |
12554 | - connect ( model, SIGNAL ( layoutChanged () ), this, SLOT ( runAllTests() ) ); | |
12555 | - connect ( model, SIGNAL ( modelReset () ), this, SLOT ( runAllTests() ) ); | |
12556 | - connect ( model, SIGNAL ( rowsAboutToBeInserted ( const QModelIndex &, int, int ) ), | |
12557 | - this, SLOT ( runAllTests() ) ); | |
12558 | - connect ( model, SIGNAL ( rowsAboutToBeRemoved ( const QModelIndex &, int, int ) ), | |
12559 | - this, SLOT ( runAllTests() ) ); | |
12560 | - connect ( model, SIGNAL ( rowsInserted ( const QModelIndex &, int, int ) ), | |
12561 | - this, SLOT ( runAllTests() ) ); | |
12562 | - connect ( model, SIGNAL ( rowsRemoved ( const QModelIndex &, int, int ) ), | |
12563 | - this, SLOT ( runAllTests() ) ); | |
12564 | - | |
12565 | - // Special checks for inserting/removing | |
12566 | - connect ( model, SIGNAL ( layoutAboutToBeChanged() ), | |
12567 | - this, SLOT ( layoutAboutToBeChanged() ) ); | |
12568 | - connect ( model, SIGNAL ( layoutChanged() ), | |
12569 | - this, SLOT ( layoutChanged() ) ); | |
12570 | - | |
12571 | - connect ( model, SIGNAL ( rowsAboutToBeInserted ( const QModelIndex &, int, int ) ), | |
12572 | - this, SLOT ( rowsAboutToBeInserted ( const QModelIndex &, int, int ) ) ); | |
12573 | - connect ( model, SIGNAL ( rowsAboutToBeRemoved ( const QModelIndex &, int, int ) ), | |
12574 | - this, SLOT ( rowsAboutToBeRemoved ( const QModelIndex &, int, int ) ) ); | |
12575 | - connect ( model, SIGNAL ( rowsInserted ( const QModelIndex &, int, int ) ), | |
12576 | - this, SLOT ( rowsInserted ( const QModelIndex &, int, int ) ) ); | |
12577 | - connect ( model, SIGNAL ( rowsRemoved ( const QModelIndex &, int, int ) ), | |
12578 | - this, SLOT ( rowsRemoved ( const QModelIndex &, int, int ) ) ); | |
12579 | - | |
12580 | - connect ( model, SIGNAL (rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), | |
12581 | - this, SLOT (rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)) ); | |
12582 | - connect ( model, SIGNAL (rowsMoved(QModelIndex,int,int,QModelIndex,int)), | |
12583 | - this, SLOT (rowsMoved(QModelIndex,int,int,QModelIndex,int)) ); | |
12584 | - | |
12585 | + connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), | |
12586 | + this, SLOT(runAllTests()) ); | |
12587 | + connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), | |
12588 | + this, SLOT(runAllTests()) ); | |
12589 | + connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)), | |
12590 | + this, SLOT(runAllTests()) ); | |
12591 | + connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), | |
12592 | + this, SLOT(runAllTests()) ); | |
12593 | + connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
12594 | + this, SLOT(runAllTests()) ); | |
12595 | + connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), | |
12596 | + this, SLOT(runAllTests()) ); | |
12597 | + connect(model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(runAllTests()) ); | |
12598 | + connect(model, SIGNAL(layoutChanged()), this, SLOT(runAllTests()) ); | |
12599 | + connect(model, SIGNAL(modelReset()), this, SLOT(runAllTests()) ); | |
12600 | + connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), | |
12601 | + this, SLOT(runAllTests()) ); | |
12602 | + connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), | |
12603 | + this, SLOT(runAllTests()) ); | |
12604 | + connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), | |
12605 | + this, SLOT(runAllTests()) ); | |
12606 | + connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), | |
12607 | + this, SLOT(runAllTests()) ); | |
12608 | + | |
12609 | + // Special checks for changes | |
12610 | + connect(model, SIGNAL(layoutAboutToBeChanged()), | |
12611 | + this, SLOT(layoutAboutToBeChanged()) ); | |
12612 | + connect(model, SIGNAL(layoutChanged()), | |
12613 | + this, SLOT(layoutChanged()) ); | |
12614 | + | |
12615 | + connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), | |
12616 | + this, SLOT(rowsAboutToBeInserted(QModelIndex,int,int)) ); | |
12617 | + connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), | |
12618 | + this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)) ); | |
12619 | + connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), | |
12620 | + this, SLOT(rowsInserted(QModelIndex,int,int)) ); | |
12621 | + connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), | |
12622 | + this, SLOT(rowsRemoved(QModelIndex,int,int)) ); | |
12623 | + connect(model, SIGNAL (rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), | |
12624 | + this, SLOT (rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)) ); | |
12625 | + connect(model, SIGNAL (rowsMoved(QModelIndex,int,int,QModelIndex,int)), | |
12626 | + this, SLOT (rowsMoved(QModelIndex,int,int,QModelIndex,int)) ); | |
12627 | + connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
12628 | + this, SLOT(dataChanged(QModelIndex,QModelIndex)) ); | |
12629 | + connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), | |
12630 | + this, SLOT(headerDataChanged(Qt::Orientation,int,int)) ); | |
12631 | ||
12632 | runAllTests(); | |
12633 | } | |
12634 | @@ -257,7 +249,7 @@ void ModelTest::index() | |
12635 | void ModelTest::parent() | |
12636 | { | |
12637 | // qDebug() << "p"; | |
12638 | - // Make sure the model wont crash and will return an invalid QModelIndex | |
12639 | + // Make sure the model won't crash and will return an invalid QModelIndex | |
12640 | // when asked for the parent of an invalid index. | |
12641 | QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() ); | |
12642 | ||
12643 | @@ -339,6 +331,8 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth ) | |
12644 | //qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows | |
12645 | // << "columns:" << columns << "parent column:" << parent.column(); | |
12646 | ||
12647 | + const QModelIndex topLeftChild = model->index( 0, 0, parent ); | |
12648 | + | |
12649 | QVERIFY( !model->hasIndex ( rows + 1, 0, parent ) ); | |
12650 | for ( int r = 0; r < rows; ++r ) { | |
12651 | if ( model->canFetchMore ( parent ) ) { | |
12652 | @@ -362,6 +356,15 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth ) | |
12653 | QModelIndex b = model->index ( r, c, parent ); | |
12654 | QVERIFY( a == b ); | |
12655 | ||
12656 | + { | |
12657 | + const QModelIndex sibling = model->sibling( r, c, topLeftChild ); | |
12658 | + QVERIFY( index == sibling ); | |
12659 | + } | |
12660 | + { | |
12661 | + const QModelIndex sibling = topLeftChild.sibling( r, c ); | |
12662 | + QVERIFY( index == sibling ); | |
12663 | + } | |
12664 | + | |
12665 | // Some basic checking on the index that is returned | |
12666 | QVERIFY( index.model() == model ); | |
12667 | QCOMPARE( index.row(), r ); | |
12668 | @@ -474,9 +477,9 @@ void ModelTest::data() | |
12669 | ||
12670 | \sa rowsInserted() | |
12671 | */ | |
12672 | -void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int end ) | |
12673 | +void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int /* end */) | |
12674 | { | |
12675 | - Q_UNUSED(end); | |
12676 | +// Q_UNUSED(end); | |
12677 | // qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).toString() | |
12678 | // << "current count of parent=" << model->rowCount ( parent ); // << "display of last=" << model->data( model->index(start-1, 0, parent) ); | |
12679 | // qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) ); | |
12680 | @@ -565,6 +568,30 @@ void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end ) | |
12681 | QVERIFY( c.next == model->data ( model->index ( start, 0, c.parent ) ) ); | |
12682 | } | |
12683 | ||
12684 | +void ModelTest::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) | |
12685 | +{ | |
12686 | + QVERIFY(topLeft.isValid()); | |
12687 | + QVERIFY(bottomRight.isValid()); | |
12688 | + QModelIndex commonParent = bottomRight.parent(); | |
12689 | + QVERIFY(topLeft.parent() == commonParent); | |
12690 | + QVERIFY(topLeft.row() <= bottomRight.row()); | |
12691 | + QVERIFY(topLeft.column() <= bottomRight.column()); | |
12692 | + int rowCount = model->rowCount(commonParent); | |
12693 | + int columnCount = model->columnCount(commonParent); | |
12694 | + QVERIFY(bottomRight.row() < rowCount); | |
12695 | + QVERIFY(bottomRight.column() < columnCount); | |
12696 | +} | |
12697 | + | |
12698 | +void ModelTest::headerDataChanged(Qt::Orientation orientation, int start, int end) | |
12699 | +{ | |
12700 | + QVERIFY(start >= 0); | |
12701 | + QVERIFY(end >= 0); | |
12702 | + QVERIFY(start <= end); | |
12703 | + int itemCount = orientation == Qt::Vertical ? model->rowCount() : model->columnCount(); | |
12704 | + QVERIFY(start < itemCount); | |
12705 | + QVERIFY(end < itemCount); | |
12706 | +} | |
12707 | + | |
12708 | void ModelTest::rowsAboutToBeMoved( const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow ) | |
12709 | { | |
12710 | Changing cs; | |
12711 | @@ -589,8 +616,8 @@ void ModelTest::rowsMoved( const QModelIndex &srcParent, int start, int end, con | |
12712 | QVERIFY ( cd.oldSize == model->rowCount ( destParent ) ); | |
12713 | ||
12714 | // TODO: Find out what I can assert here about last and next. | |
12715 | - // QVERIFY ( cd.last == model->data ( model->index ( destinationRow - 1, 0, cd.parent ) ) ); | |
12716 | - // QVERIFY ( cd.next == model->data ( model->index ( destinationRow + (end - start + 1), 0, cd.parent ) ) ); | |
12717 | + // Q_ASSERT ( cd.last == model->data ( model->index ( destinationRow - 1, 0, cd.parent ) ) ); | |
12718 | + // Q_ASSERT ( cd.next == model->data ( model->index ( destinationRow + (end - start + 1), 0, cd.parent ) ) ); | |
12719 | } | |
12720 | else { | |
12721 | QVERIFY ( cd.oldSize + ( end - start + 1 ) == model->rowCount ( destParent ) ); | |
12722 | @@ -602,12 +629,12 @@ void ModelTest::rowsMoved( const QModelIndex &srcParent, int start, int end, con | |
12723 | Changing cs = remove.pop(); | |
12724 | QVERIFY ( cs.parent == srcParent ); | |
12725 | if (srcParent == destParent) { | |
12726 | - QVERIFY ( cs.oldSize == model->rowCount ( srcParent ) ); | |
12727 | + QVERIFY ( cs.oldSize == model->rowCount ( srcParent ) ); | |
12728 | } | |
12729 | else { | |
12730 | - QVERIFY ( cs.oldSize - ( end - start + 1 ) == model->rowCount ( srcParent ) ); | |
12731 | + QVERIFY ( cs.oldSize - ( end - start + 1 ) == model->rowCount ( srcParent ) ); | |
12732 | ||
12733 | - QVERIFY ( cs.last == model->data ( model->index ( start - 1, 0, srcParent ) ) ); | |
12734 | - QVERIFY ( cs.next == model->data ( model->index ( start, 0, srcParent ) ) ); | |
12735 | + QVERIFY ( cs.last == model->data ( model->index ( start - 1, 0, srcParent ) ) ); | |
12736 | + QVERIFY ( cs.next == model->data ( model->index ( start, 0, srcParent ) ) ); | |
12737 | } | |
12738 | } | |
12739 | diff --git a/tests/modeltest.h b/tests/modeltest.h | |
12740 | index 9eb343d..3dcf18c 100644 | |
12741 | --- a/tests/modeltest.h | |
12742 | +++ b/tests/modeltest.h | |
12743 | @@ -1,40 +1,32 @@ | |
12744 | /**************************************************************************** | |
12745 | ** | |
12746 | -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | |
12747 | -** All rights reserved. | |
12748 | -** Contact: Nokia Corporation (qt-info@nokia.com) | |
12749 | +** Copyright (C) 2015 The Qt Company Ltd. | |
12750 | +** Contact: http://www.qt.io/licensing/ | |
12751 | ** | |
12752 | ** This file is part of the test suite of the Qt Toolkit. | |
12753 | ** | |
12754 | -** $QT_BEGIN_LICENSE:LGPL$ | |
12755 | +** $QT_BEGIN_LICENSE:LGPL21$ | |
12756 | +** Commercial License Usage | |
12757 | +** Licensees holding valid commercial Qt licenses may use this file in | |
12758 | +** accordance with the commercial license agreement provided with the | |
12759 | +** Software or, alternatively, in accordance with the terms contained in | |
12760 | +** a written agreement between you and The Qt Company. For licensing terms | |
12761 | +** and conditions see http://www.qt.io/terms-conditions. For further | |
12762 | +** information use the contact form at http://www.qt.io/contact-us. | |
12763 | +** | |
12764 | ** GNU Lesser General Public License Usage | |
12765 | -** This file may be used under the terms of the GNU Lesser General Public | |
12766 | -** License version 2.1 as published by the Free Software Foundation and | |
12767 | -** appearing in the file LICENSE.LGPL included in the packaging of this | |
12768 | -** file. Please review the following information to ensure the GNU Lesser | |
12769 | -** General Public License version 2.1 requirements will be met: | |
12770 | +** Alternatively, this file may be used under the terms of the GNU Lesser | |
12771 | +** General Public License version 2.1 or version 3 as published by the Free | |
12772 | +** Software Foundation and appearing in the file LICENSE.LGPLv21 and | |
12773 | +** LICENSE.LGPLv3 included in the packaging of this file. Please review the | |
12774 | +** following information to ensure the GNU Lesser General Public License | |
12775 | +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | |
12776 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
12777 | ** | |
12778 | -** In addition, as a special exception, Nokia gives you certain additional | |
12779 | -** rights. These rights are described in the Nokia Qt LGPL Exception | |
12780 | +** As a special exception, The Qt Company gives you certain additional | |
12781 | +** rights. These rights are described in The Qt Company LGPL Exception | |
12782 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
12783 | ** | |
12784 | -** GNU General Public License Usage | |
12785 | -** Alternatively, this file may be used under the terms of the GNU General | |
12786 | -** Public License version 3.0 as published by the Free Software Foundation | |
12787 | -** and appearing in the file LICENSE.GPL included in the packaging of this | |
12788 | -** file. Please review the following information to ensure the GNU General | |
12789 | -** Public License version 3.0 requirements will be met: | |
12790 | -** http://www.gnu.org/copyleft/gpl.html. | |
12791 | -** | |
12792 | -** Other Usage | |
12793 | -** Alternatively, this file may be used in accordance with the terms and | |
12794 | -** conditions contained in a signed written agreement between you and Nokia. | |
12795 | -** | |
12796 | -** | |
12797 | -** | |
12798 | -** | |
12799 | -** | |
12800 | ** $QT_END_LICENSE$ | |
12801 | ** | |
12802 | ****************************************************************************/ | |
12803 | @@ -43,8 +35,8 @@ | |
12804 | #ifndef MODELTEST_H | |
12805 | #define MODELTEST_H | |
12806 | ||
12807 | -#include <QAbstractItemModel> | |
12808 | #include <QObject> | |
12809 | +#include <QAbstractItemModel> | |
12810 | #include <QStack> | |
12811 | ||
12812 | class ModelTest : public QObject | |
12813 | @@ -73,7 +65,8 @@ protected Q_SLOTS: | |
12814 | void rowsRemoved( const QModelIndex & parent, int start, int end ); | |
12815 | void rowsAboutToBeMoved ( const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow ); | |
12816 | void rowsMoved ( const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow ); | |
12817 | - | |
12818 | + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); | |
12819 | + void headerDataChanged(Qt::Orientation orientation, int start, int end); | |
12820 | ||
12821 | private: | |
12822 | void checkChildren( const QModelIndex &parent, int currentDepth = 0 ); | |
12823 | diff --git a/tests/tests.h b/tests/tests.h | |
12824 | deleted file mode 100644 | |
12825 | index e719a0b..0000000 | |
12826 | --- a/tests/tests.h | |
12827 | +++ /dev/null | |
12828 | @@ -1,72 +0,0 @@ | |
12829 | -/* | |
12830 | - * Copyright (C) 2011 Felix Geyer <debfx@fobos.de> | |
12831 | - * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). | |
12832 | - * | |
12833 | - * This program is free software: you can redistribute it and/or modify | |
12834 | - * it under the terms of the GNU General Public License as published by | |
12835 | - * the Free Software Foundation, either version 2 or (at your option) | |
12836 | - * version 3 of the License. | |
12837 | - * | |
12838 | - * This program is distributed in the hope that it will be useful, | |
12839 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12840 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12841 | - * GNU General Public License for more details. | |
12842 | - * | |
12843 | - * You should have received a copy of the GNU General Public License | |
12844 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
12845 | - */ | |
12846 | - | |
12847 | -#ifndef KEEPASSX_TESTS_H | |
12848 | -#define KEEPASSX_TESTS_H | |
12849 | - | |
12850 | -#include <QTest> | |
12851 | - | |
12852 | -// backport QTEST_GUILESS_MAIN, QTRY_VERIFY and QTRY_COMPARE from Qt 5 | |
12853 | - | |
12854 | -#ifndef QTEST_GUILESS_MAIN | |
12855 | -#define QTEST_GUILESS_MAIN(TestObject) \ | |
12856 | -int main(int argc, char* argv[]) \ | |
12857 | -{ \ | |
12858 | - QCoreApplication app(argc, argv); \ | |
12859 | - TestObject tc; \ | |
12860 | - return QTest::qExec(&tc, argc, argv); \ | |
12861 | -} | |
12862 | -#endif // QTEST_GUILESS_MAIN | |
12863 | - | |
12864 | - | |
12865 | -#ifndef QTRY_VERIFY | |
12866 | -#define KEEPASSX_VERIFY_WITH_TIMEOUT(__expr, __timeout) \ | |
12867 | -do { \ | |
12868 | - const int __step = 50; \ | |
12869 | - const int __timeoutValue = __timeout; \ | |
12870 | - if (!(__expr)) { \ | |
12871 | - QTest::qWait(0); \ | |
12872 | - } \ | |
12873 | - for (int __i = 0; __i < __timeoutValue && !(__expr); __i+=__step) { \ | |
12874 | - QTest::qWait(__step); \ | |
12875 | - } \ | |
12876 | - QVERIFY(__expr); \ | |
12877 | -} while (0) | |
12878 | - | |
12879 | -#define QTRY_VERIFY(__expr) KEEPASSX_VERIFY_WITH_TIMEOUT(__expr, 5000) | |
12880 | -#endif // QTRY_VERIFY | |
12881 | - | |
12882 | - | |
12883 | -#ifndef QTRY_COMPARE | |
12884 | -#define KEEPASSX_COMPARE_WITH_TIMEOUT(__expr, __expected, __timeout) \ | |
12885 | -do { \ | |
12886 | - const int __step = 50; \ | |
12887 | - const int __timeoutValue = __timeout; \ | |
12888 | - if ((__expr) != (__expected)) { \ | |
12889 | - QTest::qWait(0); \ | |
12890 | - } \ | |
12891 | - for (int __i = 0; __i < __timeoutValue && ((__expr) != (__expected)); __i+=__step) { \ | |
12892 | - QTest::qWait(__step); \ | |
12893 | - } \ | |
12894 | - QCOMPARE(__expr, __expected); \ | |
12895 | -} while (0) | |
12896 | - | |
12897 | -#define QTRY_COMPARE(__expr, __expected) KEEPASSX_COMPARE_WITH_TIMEOUT(__expr, __expected, 5000) | |
12898 | -#endif // QTRY_COMPARE | |
12899 | - | |
12900 | -#endif // KEEPASSX_TESTS_H | |
12901 | diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt | |
12902 | index c4aa5fa..7988467 100644 | |
12903 | --- a/utils/CMakeLists.txt | |
12904 | +++ b/utils/CMakeLists.txt | |
12905 | @@ -18,7 +18,8 @@ include_directories(../src) | |
12906 | add_executable(kdbx-extract kdbx-extract.cpp) | |
12907 | target_link_libraries(kdbx-extract | |
12908 | keepassx_core | |
12909 | - ${QT_QTCORE_LIBRARY} | |
12910 | - ${QT_QTGUI_LIBRARY} | |
12911 | + Qt5::Core | |
12912 | + Qt5::Concurrent | |
12913 | + Qt5::Widgets | |
12914 | ${GCRYPT_LIBRARIES} | |
12915 | ${ZLIB_LIBRARIES}) |