From c6d09d489d67d869e090e3831ce0c9bb59a8b2aa Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 20:12:07 +0100 Subject: [PATCH 01/21] [Port to Qt6] CMakeLists upgrade for qt6 + remove warnings --- 3rdparty/qtiocompressor/CMakeLists.txt | 2 +- CMakeLists.txt | 87 +++++++++++++------------- replaygain/CMakeLists.txt | 2 +- support/CMakeLists.txt | 4 +- tags/CMakeLists.txt | 2 +- translations/CMakeLists.txt | 30 +++------ 6 files changed, 57 insertions(+), 70 deletions(-) diff --git a/3rdparty/qtiocompressor/CMakeLists.txt b/3rdparty/qtiocompressor/CMakeLists.txt index 567e8c17ef..129eb6547f 100644 --- a/3rdparty/qtiocompressor/CMakeLists.txt +++ b/3rdparty/qtiocompressor/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.5) include_directories(${QTINCLUDES} ${ZLIB_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) ADD_LIBRARY(qtiocompressor STATIC qtiocompressor.cpp) diff --git a/CMakeLists.txt b/CMakeLists.txt index 373bca6f66..5280d831d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.5) project(cantata) cmake_policy(SET CMP0020 NEW) @@ -23,7 +23,7 @@ endif () set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -set (QT_MIN_VERSION 5.11) +set (QT_MIN_VERSION 6.5) set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") set(CPACK_GENERATOR "DEB;RPM;TBZ2") @@ -187,31 +187,28 @@ if (TAGLIB_FOUND) endif () else (TAGLIB_FOUND) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable -Wno-unused-parameter") - set(ENABLE_DEVICES_SUPPORT OFF) + set(ENABLE_DEVICES_SUPPORT OFF) endif () if (NOT MTP_FOUND) - set(ENABLE_UNCACHED_MTP OFF) + set(ENABLE_UNCACHED_MTP OFF) endif () -find_package(Qt5 ${QT_MIN_VERSION} COMPONENTS Widgets Xml Network Concurrent Svg Sql REQUIRED) +find_package(Qt6 ${QT_MIN_VERSION} COMPONENTS Core Widgets Xml Network Concurrent Svg Sql REQUIRED) set(CMAKE_AUTOMOC TRUE) set(CMAKE_AUTOUIC TRUE) set(CMAKE_AUTORCC TRUE) -set(CMAKE_CXX_STANDARD 11) - -set(QTCORELIBS ${Qt5Core_LIBRARIES}) -set(QTNETWORKLIBS ${Qt5Network_LIBRARIES}) -set(QTGUILIBS ${Qt5Gui_LIBRARIES}) -set(QTLIBS ${QTCORELIBS} ${Qt5Widgets_LIBRARIES} ${QTNETWORKLIBS} ${QTGUILIBS} ${Qt5Xml_LIBRARIES} ${Qt5Concurrent_LIBRARIES} ${Qt5Svg_LIBRARIES} ${Qt5Sql_LIBRARIES}) -set(QTINCLUDES ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} ${Qt5Concurrent_INCLUDE_DIRS} - ${Qt5Svg_INCLUDE_DIRS} ${Qt5Sql_INCLUDE_DIRS}) -add_definitions(${Qt5Widgets_DEFINITIONS} ${Qt5Network_DEFINITIONS} ${Qt5Xml_DEFINITIONS} ${Qt5Concurrent_DEFINITIONS} ${Qt5Svg_DEFINITIONS} ${Qt5Sql_DEFINITIONS}) -if (Qt5_POSITION_INDEPENDENT_CODE) +set(CMAKE_CXX_STANDARD 17) + +set(QTLIBS Qt6::Core Qt6::Widgets Qt6::Network Qt6::Gui Qt6::Xml Qt6::Concurrent Qt6::Svg Qt6::Sql) +set(QTINCLUDES ${Qt6Widgets_INCLUDE_DIRS} ${Qt6Network_INCLUDE_DIRS} ${Qt6Xml_INCLUDE_DIRS} ${Qt6Core_INCLUDE_DIRS} ${Qt6Concurrent_INCLUDE_DIRS} + ${Qt6Svg_INCLUDE_DIRS} ${Qt6Sql_INCLUDE_DIRS}) +add_definitions(${Qt6Widgets_DEFINITIONS} ${Qt6Network_DEFINITIONS} ${Qt6Xml_DEFINITIONS} ${Qt6Concurrent_DEFINITIONS} ${Qt6Svg_DEFINITIONS} ${Qt6Sql_DEFINITIONS}) +if (Qt6_POSITION_INDEPENDENT_CODE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) else () - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt6Widgets_EXECUTABLE_COMPILE_FLAGS}") endif () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wpedantic -Wall -Wextra \ @@ -226,14 +223,14 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") endif() if (APPLE OR WIN32 OR HAIKU) - get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION) - exec_program(${QT_QMAKE_EXECUTABLE} ARGS -query QT_INSTALL_TRANSLATIONS OUTPUT_VARIABLE QT_TRANSLATIONS_DIR) + get_target_property(QT_QMAKE_EXECUTABLE Qt6::qmake IMPORTED_LOCATION) + execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_TRANSLATIONS OUTPUT_VARIABLE QT_TRANSLATIONS_DIR) else () - find_package(Qt5DBus REQUIRED) + find_package(Qt6DBus REQUIRED) set(QT_QTDBUS_FOUND 1) # required for config.h !!! - set(QTLIBS ${QTLIBS} ${Qt5DBus_LIBRARIES}) - set(QTINCLUDES ${QTINCLUDES} ${Qt5DBus_INCLUDE_DIRS}) - add_definitions(${Qt5DBus_DEFINITIONS}) + set(QTLIBS ${QTLIBS} Qt6::DBus) + set(QTINCLUDES ${QTINCLUDES} ${Qt6DBus_INCLUDE_DIRS}) + add_definitions(${Qt6DBus_DEFINITIONS}) endif () if (ENABLE_HTTP_STREAM_PLAYBACK) @@ -244,11 +241,11 @@ if (ENABLE_HTTP_STREAM_PLAYBACK) include_directories(${LIBVLC_INCLUDE_DIR}) set(CANTATA_LIBS ${CANTATA_LIBS} ${LIBVLC_LIBRARY}) else () - find_package(Qt5 ${QT_MIN_VERSION} COMPONENTS Multimedia REQUIRED) - macro_log_feature(Qt5Multimedia_FOUND "Qt5Multimedia" "MPD HTTP stream playback." "http://qtproject.org") - include_directories(${Qt5Multimedia_INCLUDE_DIRS}) - add_definitions(${Qt5Multimedia_DEFINITIONS}) - set(CANTATA_LIBS ${CANTATA_LIBS} ${Qt5Multimedia_LIBRARIES}) + find_package(Qt6 ${QT_MIN_VERSION} COMPONENTS Multimedia REQUIRED) + macro_log_feature(Qt6Multimedia_FOUND "Qt6Multimedia" "MPD HTTP stream playback." "http://qtproject.org") + include_directories(${Qt6Multimedia_INCLUDE_DIRS}) + add_definitions(${Qt6Multimedia_DEFINITIONS}) + set(CANTATA_LIBS ${CANTATA_LIBS} Qt6::Multimedia) endif () set(CANTATA_SRCS ${CANTATA_SRCS} mpd-interface/httpstream.cpp) endif () @@ -272,10 +269,10 @@ if (APPLE) add_definitions(-DMAC_MEDIAPLAYER_FOUND) endif () elseif (WIN32) - find_package(Qt5 COMPONENTS WinExtras REQUIRED) - set(QTINCLUDES ${QTINCLUDES} ${Qt5WinExtras_INCLUDE_DIRS}) - set(QTLIBS ${QTLIBS} ${Qt5WinExtras_LIBRARIES}) - add_definitions(${Qt5WinExtras_DEFINITIONS}) + find_package(Qt6 COMPONENTS WinExtras REQUIRED) + set(QTINCLUDES ${QTINCLUDES} ${Qt6WinExtras_INCLUDE_DIRS}) + set(QTLIBS ${QTLIBS} Qt6::WinExtras) + add_definitions(${Qt6WinExtras_DEFINITIONS}) set(CANTATA_SRCS ${CANTATA_SRCS} windows/thumbnailtoolbar.cpp) endif () @@ -365,16 +362,16 @@ if (QT_QTDBUS_FOUND) set(CANTATA_SRCS ${CANTATA_SRCS} dbus/mpris.cpp dbus/powermanagement.cpp) set(CANTATA_SRCS ${CANTATA_SRCS} dbus/notify.cpp) - qt5_add_dbus_adaptor(CANTATA_SRCS dbus/org.mpris.MediaPlayer2.Player.xml dbus/mpris.h Mpris) - qt5_add_dbus_adaptor(CANTATA_SRCS dbus/org.mpris.MediaPlayer2.root.xml dbus/mpris.h Mpris) - qt5_add_dbus_adaptor(CANTATA_SRCS dbus/${PROJECT_REV_URL}.xml gui/mainwindow.h MainWindow) - qt5_add_dbus_interfaces(CANTATA_SRCS dbus/org.freedesktop.Notifications.xml) - qt5_add_dbus_interfaces(CANTATA_SRCS dbus/org.freedesktop.UPower.xml) - qt5_add_dbus_interfaces(CANTATA_SRCS dbus/org.freedesktop.login1.xml) - qt5_add_dbus_interfaces(CANTATA_SRCS dbus/org.gnome.SettingsDaemon.xml) - qt5_add_dbus_interfaces(CANTATA_SRCS dbus/org.gnome.SettingsDaemon.MediaKeys.xml) - qt5_add_dbus_interfaces(CANTATA_SRCS dbus/org.kde.Solid.PowerManagement.PolicyAgent.xml) - qt5_add_dbus_interfaces(CANTATA_SRCS dbus/org.freedesktop.PowerManagement.Inhibit.xml) + qt6_add_dbus_adaptor(CANTATA_SRCS dbus/org.mpris.MediaPlayer2.Player.xml dbus/mpris.h Mpris) + qt6_add_dbus_adaptor(CANTATA_SRCS dbus/org.mpris.MediaPlayer2.root.xml dbus/mpris.h Mpris) + qt6_add_dbus_adaptor(CANTATA_SRCS dbus/${PROJECT_REV_URL}.xml gui/mainwindow.h MainWindow) + qt6_add_dbus_interfaces(CANTATA_SRCS dbus/org.freedesktop.Notifications.xml) + qt6_add_dbus_interfaces(CANTATA_SRCS dbus/org.freedesktop.UPower.xml) + qt6_add_dbus_interfaces(CANTATA_SRCS dbus/org.freedesktop.login1.xml) + qt6_add_dbus_interfaces(CANTATA_SRCS dbus/org.gnome.SettingsDaemon.xml) + qt6_add_dbus_interfaces(CANTATA_SRCS dbus/org.gnome.SettingsDaemon.MediaKeys.xml) + qt6_add_dbus_interfaces(CANTATA_SRCS dbus/org.kde.Solid.PowerManagement.PolicyAgent.xml) + qt6_add_dbus_interfaces(CANTATA_SRCS dbus/org.freedesktop.PowerManagement.Inhibit.xml) endif () if (NOT WIN32 AND NOT APPLE) @@ -506,14 +503,14 @@ elseif (APPLE) install(FILES ${BREW_OPENSSL_PATH}/libssl.1.0.0.dylib DESTINATION ${MACOSX_BUNDLE_APP_DIR} RENAME libssl.dylib) endif() add_subdirectory(mac) - include(DeployQt5) + include(DeployQt6) install(PROGRAMS ${CMAKE_BINARY_DIR}/cantata.app/Contents/MacOS/cantata DESTINATION ${MACOSX_BUNDLE_APP_DIR}) # Create our own plist file to enable HighDPI support configure_file(mac/Info.plist.cmake ${CMAKE_CURRENT_BINARY_DIR}/mac/Info.plist) configure_file(mac/dmg/create-dmg.sh.in ${CMAKE_CURRENT_BINARY_DIR}/mac/create-dmg.sh) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mac/Info.plist DESTINATION ${CANTATA_APP_CONTENTS_DIR}) if (TAGLIB_FOUND) - # *NEED* to install cantata-replagain/cantata-tags *before* install_qt5_executable fix'es the bundle + # *NEED* to install cantata-replagain/cantata-tags *before* install_qt6_executable fix'es the bundle # If we install from their own CMakeLists.txt then they are installed *after* the fix-up, and so link # to the build libs not the packaged ones! if (FFMPEG_FOUND OR MPG123_FOUND) @@ -522,9 +519,9 @@ elseif (APPLE) install(PROGRAMS ${CMAKE_BINARY_DIR}/tags/cantata-tags DESTINATION ${MACOSX_BUNDLE_APP_DIR}) endif (TAGLIB_FOUND) if (ENABLE_HTTP_STREAM_PLAYBACK AND NOT ENABLE_LIBVLC) - install_qt5_executable(Cantata.app "qjpeg;qsvg;qsvgicon;qcocoa;qmacstyle;qsqlite;qavfmediaplayer") + install_qt6_executable(Cantata.app "qjpeg;qsvg;qsvgicon;qcocoa;qmacstyle;qsqlite;qavfmediaplayer") else (ENABLE_HTTP_STREAM_PLAYBACK AND NOT ENABLE_LIBVLC) - install_qt5_executable(Cantata.app "qjpeg;qsvg;qsvgicon;qcocoa;qmacstyle;qsqlite") + install_qt6_executable(Cantata.app "qjpeg;qsvg;qsvgicon;qcocoa;qmacstyle;qsqlite") endif (ENABLE_HTTP_STREAM_PLAYBACK AND NOT ENABLE_LIBVLC) elseif (HAIKU) ADD_EXECUTABLE(cantata ${CANTATA_SRCS}) diff --git a/replaygain/CMakeLists.txt b/replaygain/CMakeLists.txt index ae456ea039..306f328262 100644 --- a/replaygain/CMakeLists.txt +++ b/replaygain/CMakeLists.txt @@ -43,7 +43,7 @@ if (FFMPEG_FOUND OR MPG123_FOUND) if (MPG123_FOUND) target_link_libraries(cantata-replaygain ${MPG123_LIBRARIES}) endif () - target_link_libraries(cantata-replaygain ${QTCORELIBS}) + target_link_libraries(cantata-replaygain Qt6::Core) if (UNIX AND NOT APPLE) target_link_libraries(cantata-replaygain -lpthread) endif () diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index 90ccf01397..977dbcc5d8 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -16,7 +16,7 @@ set(SUPPORT_SRCS ${SUPPORT_SRCS} pathrequester.cpp kmessagewidget.cpp dialog.cpp shortcutssettingswidget.cpp keysequencewidget.cpp acceleratormanager.cpp urllabel.cpp) set(SUPPORT_UIS shortcutssettingswidget.ui) -qt5_wrap_ui(SUPPORT_UI_HDRS ${SUPPORT_UIS}) -qt5_add_resources(SUPPORT_RC_SRCS support.qrc) +qt6_wrap_ui(SUPPORT_UI_HDRS ${SUPPORT_UIS}) +qt6_add_resources(SUPPORT_RC_SRCS support.qrc) add_library(support STATIC ${SUPPORT_SRCS} ${SUPPORT_UI_HDRS} ${SUPPORT_RC_SRCS}) diff --git a/tags/CMakeLists.txt b/tags/CMakeLists.txt index 1da10f9f4d..f0a4f3815f 100644 --- a/tags/CMakeLists.txt +++ b/tags/CMakeLists.txt @@ -15,7 +15,7 @@ else () endif () add_definitions(-DCANTATA_TAG_SERVER -DCANTATA_NO_UI_FUNCTIONS) -target_link_libraries(cantata-tags ${TAGLIB_LIBRARIES} ${QTGUILIBS} ${QTCORELIBS} ${QTNETWORKLIBS}) +target_link_libraries(cantata-tags ${TAGLIB_LIBRARIES} Qt6::Gui Qt6::Core Qt6::Network) if (TAGLIB-EXTRAS_FOUND) target_link_libraries(cantata-tags ${TAGLIB-EXTRAS_LIBRARIES}) include_directories(${TAGLIB-EXTRAS_INCLUDES}) diff --git a/translations/CMakeLists.txt b/translations/CMakeLists.txt index 61ab93cd3c..0346fa984b 100644 --- a/translations/CMakeLists.txt +++ b/translations/CMakeLists.txt @@ -1,28 +1,18 @@ file(GLOB TS_FILES cantata_*.ts) -foreach (TS_FILE ${TS_FILES}) - get_filename_component(TRANS ${TS_FILE} NAME_WE) - list(APPEND CANTATA_TRANS "${TRANS}") -endforeach () -find_package(Qt5LinguistTools ${QT_MIN_VERSION} QUIET) +find_package(Qt6LinguistTools ${QT_MIN_VERSION} QUIET) -if (Qt5LinguistTools_FOUND) +if (Qt6LinguistTools_FOUND) set(catalogname cantata) add_custom_target(translations ALL) - foreach(TRANS ${CANTATA_TRANS}) - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${TRANS}.ts) - set(CUR_TS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${TRANS}.ts) - set(CUR_QM_FILE ${CMAKE_CURRENT_BINARY_DIR}/${TRANS}.qm) - add_custom_command(TARGET translations - COMMAND ${Qt5_LRELEASE_EXECUTABLE} ARGS ${CUR_TS_FILE} -qm ${CUR_QM_FILE} - DEPENDS ${CUR_TS_FILE}) - if (WIN32) - install(FILES ${CUR_QM_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/translations/) - elseif (APPLE) - install(FILES ${CUR_QM_FILE} DESTINATION ${MACOSX_BUNDLE_RESOURCES}/translations/) - else () - install(FILES ${CUR_QM_FILE} DESTINATION ${SHARE_INSTALL_PREFIX}/cantata/translations/) - endif () + qt6_add_lrelease(translations TS_FILES ${TS_FILES} QM_FILES_OUTPUT_VARIABLE QM_FILES) + foreach(CUR_QM_FILE ${QM_FILES}) + if (WIN32) + install(FILES ${CUR_QM_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/translations/) + elseif (APPLE) + install(FILES ${CUR_QM_FILE} DESTINATION ${MACOSX_BUNDLE_RESOURCES}/translations/) + else () + install(FILES ${CUR_QM_FILE} DESTINATION ${SHARE_INSTALL_PREFIX}/cantata/translations/) endif () endforeach() else () From 84bedd7fb0cab6ebb6bcd0cdfeaea6f8c944e702 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 20:13:36 +0100 Subject: [PATCH 02/21] [Port to Qt6] Add -fPIC compilation flag --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5280d831d7..89d2903fa4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,6 +215,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wpedantic -Wall -Wextra \ -Wno-cast-qual -Wno-float-equal \ -Wmissing-format-attribute -Wpacked -Wredundant-decls") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") # flags unique to GCC set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wduplicated-branches -Wduplicated-cond -Wlogical-op") From 9f9fef492f153b50ad75a43dc601de87f22bcc44 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 20:17:55 +0100 Subject: [PATCH 03/21] [Port to Qt6] Remove cmake warnings --- cmake/FindCdioparanoia.cmake | 2 +- cmake/FindFFMPEG.cmake | 2 +- cmake/FindFoundation.cmake | 2 +- cmake/FindIOKit.cmake | 2 +- cmake/FindMPG123.cmake | 2 +- cmake/FindMtp.cmake | 4 ++-- cmake/FindMusicBrainz5.cmake | 2 +- cmake/FindQJSON.cmake | 2 +- cmake/FindSqlite.cmake | 2 +- cmake/FindTaglib.cmake | 7 ++++--- cmake/FindUDev.cmake | 4 ++-- 11 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cmake/FindCdioparanoia.cmake b/cmake/FindCdioparanoia.cmake index 5e1eb5eb93..edc68541ca 100644 --- a/cmake/FindCdioparanoia.cmake +++ b/cmake/FindCdioparanoia.cmake @@ -8,7 +8,7 @@ cmake_policy(SET CMP0075 NEW) cmake_policy(SET CMP0011 NEW) -include(FindPkgConfig) +find_package(PkgConfig) include(CheckIncludeFiles) if(PKG_CONFIG_FOUND) diff --git a/cmake/FindFFMPEG.cmake b/cmake/FindFFMPEG.cmake index 59d07f7dd6..62ef7cb533 100644 --- a/cmake/FindFFMPEG.cmake +++ b/cmake/FindFFMPEG.cmake @@ -17,6 +17,6 @@ find_library(LIBAVUTIL_LIBRARY NAMES avutil avutil-50 set(FFMPEG_LIBRARIES ${LIBAVCODEC_LIBRARY} ${LIBAVFORMAT_LIBRARY} ${LIBAVUTIL_LIBRARY}) set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR}) -include(FindPackageHandleStandardArgs) +find_package(PackageHandleStandardArgs) find_package_handle_standard_args(FFMPEG DEFAULT_MSG LIBAVCODEC_LIBRARY LIBAVFORMAT_LIBRARY LIBAVUTIL_LIBRARY FFMPEG_INCLUDE_DIR) mark_as_advanced(LIBAVCODEC_LIBRARY LIBAVFORMAT_LIBRARY LIBAVUTIL_LIBRARY FFMPEG_INCLUDE_DIR) diff --git a/cmake/FindFoundation.cmake b/cmake/FindFoundation.cmake index 4639f0c7a2..1e3ff00c82 100644 --- a/cmake/FindFoundation.cmake +++ b/cmake/FindFoundation.cmake @@ -17,6 +17,6 @@ if (Foundation_FRAMEWORKS) set(FOUNDATION_FOUND 1) endif (Foundation_FRAMEWORKS) -include(FindPackageHandleStandardArgs) +find_pacakge(PackageHandleStandardArgs) find_package_handle_standard_args(Foundation DEFAULT_MSG FOUNDATION_LIBRARY) diff --git a/cmake/FindIOKit.cmake b/cmake/FindIOKit.cmake index f3e3ecb2e0..6dc01db79a 100644 --- a/cmake/FindIOKit.cmake +++ b/cmake/FindIOKit.cmake @@ -18,6 +18,6 @@ if (IOKit_FRAMEWORKS) set(IOKIT_FOUND 1) endif (IOKit_FRAMEWORKS) -include(FindPackageHandleStandardArgs) +find_package(PackageHandleStandardArgs) find_package_handle_standard_args(IOKit DEFAULT_MSG IOKIT_LIBRARY) diff --git a/cmake/FindMPG123.cmake b/cmake/FindMPG123.cmake index 390717d940..a00c6e16f5 100644 --- a/cmake/FindMPG123.cmake +++ b/cmake/FindMPG123.cmake @@ -9,6 +9,6 @@ find_library(MPG123_LIBRARY NAMES mpg123 mpg123-0 set(MPG123_LIBRARIES ${MPG123_LIBRARY}) set(MPG123_INCLUDE_DIRS ${MPG123_INCLUDE_DIR}) -include(FindPackageHandleStandardArgs) +find_package(PackageHandleStandardArgs) find_package_handle_standard_args(MPG123 DEFAULT_MSG MPG123_LIBRARY MPG123_INCLUDE_DIR) mark_as_advanced(MPG123_INCLUDE_DIR MPG123_LIBRARY) diff --git a/cmake/FindMtp.cmake b/cmake/FindMtp.cmake index 3a7c78a655..dd87e26415 100644 --- a/cmake/FindMtp.cmake +++ b/cmake/FindMtp.cmake @@ -16,7 +16,7 @@ else (MTP_INCLUDE_DIR AND MTP_LIBRARIES AND MTP_VERSION_OKAY) if(NOT WIN32) # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls - INCLUDE(FindPkgConfig) + find_package(PkgConfig) pkg_check_modules(_MTP libmtp) @@ -31,7 +31,7 @@ else (MTP_INCLUDE_DIR AND MTP_LIBRARIES AND MTP_VERSION_OKAY) ${_MTP_LIBRARY_DIRS} ) - exec_program(${PKG_CONFIG_EXECUTABLE} ARGS --atleast-version=1.1.0 libmtp OUTPUT_VARIABLE _pkgconfigDevNull RETURN_VALUE MTP_VERSION_OKAY) + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --atleast-version=1.1.0 libmtp OUTPUT_VARIABLE _pkgconfigDevNull RESULT_VARIABLE MTP_VERSION_OKAY) if (MTP_INCLUDE_DIR AND MTP_LIBRARIES AND MTP_VERSION_OKAY STREQUAL "0") set(MTP_FOUND TRUE) diff --git a/cmake/FindMusicBrainz5.cmake b/cmake/FindMusicBrainz5.cmake index c86f9560f6..7836012830 100644 --- a/cmake/FindMusicBrainz5.cmake +++ b/cmake/FindMusicBrainz5.cmake @@ -32,7 +32,7 @@ ELSE (NOT WIN32) ENDIF (NOT WIN32) -include(FindPackageHandleStandardArgs) +find_package(PackageHandleStandardArgs) find_package_handle_standard_args( MUSICBRAINZ5 DEFAULT_MSG MUSICBRAINZ5_INCLUDE_DIRS MUSICBRAINZ5_LIBRARIES) diff --git a/cmake/FindQJSON.cmake b/cmake/FindQJSON.cmake index 28791ef85e..619c34a448 100644 --- a/cmake/FindQJSON.cmake +++ b/cmake/FindQJSON.cmake @@ -8,7 +8,7 @@ find_path(QJSON_INCLUDE_DIR qjson/parser.h) find_library(QJSON_LIBRARIES qjson) -include(FindPackageHandleStandardArgs) +find_package(PackageHandleStandardArgs) find_package_handle_standard_args(QJSON DEFAULT_MSG QJSON_INCLUDE_DIR QJSON_LIBRARIES) mark_as_advanced(QJSON_INCLUDE_DIR QJSON_LIBRARIES) diff --git a/cmake/FindSqlite.cmake b/cmake/FindSqlite.cmake index 47caa360cc..ea48d0a9ed 100644 --- a/cmake/FindSqlite.cmake +++ b/cmake/FindSqlite.cmake @@ -58,7 +58,7 @@ find_library(SQLITE_LIBRARIES NAMES sqlite3 ${PC_SQLITE_LIBRARY_DIRS} ) -include(FindPackageHandleStandardArgs) +find_package(PackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sqlite DEFAULT_MSG SQLITE_INCLUDE_DIR SQLITE_LIBRARIES) # show the SQLITE_INCLUDE_DIR and SQLITE_LIBRARIES variables only in the advanced view diff --git a/cmake/FindTaglib.cmake b/cmake/FindTaglib.cmake index 708c1c122e..1875d4d442 100644 --- a/cmake/FindTaglib.cmake +++ b/cmake/FindTaglib.cmake @@ -25,16 +25,17 @@ find_package(PkgConfig) # if pkg-config has been found if(PKG_CONFIG_EXECUTABLE) - exec_program(${PKG_CONFIG_EXECUTABLE} ARGS --modversion taglib RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_VERSION) + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --modversion taglib RESULT_VARIABLE _return_VALUE OUTPUT_VARIABLE TAGLIB_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) + message(${TAGLIB_VERSION}) if(TAGLIB_VERSION VERSION_LESS "${TAGLIB_MIN_VERSION}") message(STATUS "TagLib version too old: version searched :${TAGLIB_MIN_VERSION}, found ${TAGLIB_VERSION}") set(TAGLIB_FOUND FALSE) else(TAGLIB_VERSION VERSION_LESS "${TAGLIB_MIN_VERSION}") - exec_program(${PKG_CONFIG_EXECUTABLE} ARGS --libs taglib RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_LIBRARIES) + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --libs taglib RESULT_VARIABLE _return_VALUE OUTPUT_VARIABLE TAGLIB_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE) - exec_program(${PKG_CONFIG_EXECUTABLE} ARGS --cflags taglib RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_CFLAGS) + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --cflags taglib RESULT_VARIABLE _return_VALUE OUTPUT_VARIABLE TAGLIB_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE) if(TAGLIB_LIBRARIES AND TAGLIB_CFLAGS) set(TAGLIB_FOUND TRUE) diff --git a/cmake/FindUDev.cmake b/cmake/FindUDev.cmake index 44d6f122a5..8743599924 100644 --- a/cmake/FindUDev.cmake +++ b/cmake/FindUDev.cmake @@ -12,7 +12,7 @@ # use pkg-config to get the directories and then use these values # in the find_path() and find_library() calls -include(FindPkgConfig) +find_package(PkgConfig) pkg_check_modules(_UDEV libudev) find_path(UDEV_INCLUDE_DIR libudev.h @@ -24,7 +24,7 @@ find_library(UDEV_LIBS NAMES udev ${_UDEV_LIBRARY_DIRS} ) -include(FindPackageHandleStandardArgs) +find_package(PackageHandleStandardArgs) find_package_handle_standard_args(UDev DEFAULT_MSG UDEV_INCLUDE_DIR UDEV_LIBS) mark_as_advanced(UDEV_INCLUDE_DIR UDEV_LIBS) From 1887306bd0fc3038c0430638f3d117ad48dea246 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 20:32:28 +0100 Subject: [PATCH 04/21] [Port to Qt6] Update solid-lite parts to what currently exists in KDE. And remove Qt5 only code --- .../backends/udisks2/udisksdevicebackend.cpp | 22 +- .../backends/udisks2/udisksdevicebackend.h | 1 + .../backends/udisks2/udisksopticaldisc.cpp | 246 ++++++++++++++---- .../backends/udisks2/udisksopticaldisc.h | 19 +- 3rdparty/solid-lite/soliddefs_p.h | 95 +------ 5 files changed, 239 insertions(+), 144 deletions(-) diff --git a/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.cpp b/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.cpp index 7213a71819..a78f4cd589 100644 --- a/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.cpp +++ b/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.cpp @@ -144,7 +144,11 @@ QVariantMap DeviceBackend::allProperties() const QDBusPendingReply reply = QDBusConnection::systemBus().call(call); if (reply.isValid()) { - m_propertyCache.unite(reply.value()); + auto props = reply.value(); + // Can not use QMap<>::unite(), as it allows multiple values per key + for (auto it = props.cbegin(); it != props.cend(); ++it) { + cacheProperty(it.key(), it.value()); + } } else { qWarning() << "Error getting props:" << reply.error().name() << reply.error().message(); } @@ -242,3 +246,19 @@ void DeviceBackend::slotInterfacesRemoved(const QDBusObjectPath& object_path, co m_interfaces.removeAll(iface); } } + +// UDisks2 sends us null terminated strings, make sure to strip the extranous \0 in favor of the implicit \0. +// Otherwise comparision becomes unnecessarily complicated because 'foo\0' != 'foo'. QByteArrays are implicitly +// terminated already. +void DeviceBackend::cacheProperty(const QString &key, const QVariant &value) const +{ + if (value.metaType() == QMetaType::fromType()) { + auto blob = value.toByteArray(); + while (blob.endsWith('\0')) { + blob.chop(1); + } + m_propertyCache.insert(key, blob); + } else { + m_propertyCache.insert(key, value); + } +} diff --git a/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.h b/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.h index e3c1971098..089a99f547 100644 --- a/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.h +++ b/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.h @@ -67,6 +67,7 @@ class DeviceBackend: public QObject { void initInterfaces(); QString introspect() const; void checkCache(const QString &key) const; + void cacheProperty(const QString &key, const QVariant &value) const; QDBusInterface *m_device; diff --git a/3rdparty/solid-lite/backends/udisks2/udisksopticaldisc.cpp b/3rdparty/solid-lite/backends/udisks2/udisksopticaldisc.cpp index 1e89e55b3f..825749cfb9 100644 --- a/3rdparty/solid-lite/backends/udisks2/udisksopticaldisc.cpp +++ b/3rdparty/solid-lite/backends/udisks2/udisksopticaldisc.cpp @@ -24,10 +24,10 @@ #include #include -#include #include -#include -#include +#include +#include +#include #include "../shared/udevqt.h" @@ -35,10 +35,7 @@ #include "udisksdevice.h" #include "udisksopticaldisc.h" #include "soliddefs_p.h" - -typedef QMap ContentTypesCache; -SOLID_GLOBAL_STATIC(ContentTypesCache, cache) -SOLID_GLOBAL_STATIC(QMutex, cacheLock) +#include "udisks2.h" // inspired by http://cgit.freedesktop.org/hal/tree/hald/linux/probing/probe-volume.c static Solid::OpticalDisc::ContentType advancedDiscDetect(const QByteArray & device_file) @@ -173,17 +170,195 @@ static Solid::OpticalDisc::ContentType advancedDiscDetect(const QByteArray & dev using namespace Solid::Backends::UDisks2; +class ContentTypesCache +{ +public: + ContentTypesCache() + : m_n(0) + { + } + + void add(const OpticalDisc::Identity &key, Solid::OpticalDisc::ContentTypes content) + { + if (!find(key)) { + m_n = qMin(m_n + 1, sizeof(m_info) / sizeof(*m_info)); + moveToFront(m_n - 1); + front().first = key; + } + front().second = content; + } + + bool find(const OpticalDisc::Identity &key) + { + for (size_t i = 0; i < m_n; i++) { + if (m_info[i].first == key) { + moveToFront(i); + return true; + } + } + return false; + } + + QPair &front() + { + return *m_info; + } + +private: + void moveToFront(size_t i) + { + while (i) { + qSwap(m_info[i - 1], m_info[i]); + --i; + } + } + + size_t m_n; + QPair m_info[100]; +}; + +class SharedContentTypesCache +{ +private: + ContentTypesCache *m_pointer; + QSystemSemaphore m_semaphore; + QSharedMemory m_shmem; + + struct Unlocker { + public: + Unlocker(QSharedMemory *mem) + : m_mem(mem) + { + } + ~Unlocker() + { + m_mem->unlock(); + } + Unlocker(const Unlocker &) = delete; + Unlocker &operator=(const Unlocker &) = delete; + + private: + QSharedMemory *m_mem; + }; + + struct Releaser { + public: + Releaser(QSystemSemaphore *sem) + : m_sem(sem) + { + } + ~Releaser() + { + m_sem->release(); + } + Releaser(const Releaser &) = delete; + Releaser &operator=(const Releaser &) = delete; + + private: + QSystemSemaphore *m_sem; + }; + + static QString getKey() + { + static const QString keyTemplate("solid-disk-info-1-%1-%2"); + static const QString tableSize(QString::number(sizeof(ContentTypesCache))); + + return keyTemplate.arg(tableSize, QString::number(geteuid())); + } + +public: + SharedContentTypesCache() + : m_pointer(nullptr) + , m_semaphore(getKey() + "sem", 1) + , m_shmem(getKey() + "mem") + { + if (!m_semaphore.acquire()) { + return; + } + Releaser releaser(&m_semaphore); + + if (m_shmem.attach()) { + m_pointer = reinterpret_cast(m_shmem.data()); + return; + } + + if (!m_shmem.create(sizeof(ContentTypesCache))) { + return; + } + + if (!m_shmem.lock()) { + m_shmem.detach(); + return; + } + Unlocker unlocker(&m_shmem); + + m_pointer = new (m_shmem.data()) ContentTypesCache; + } + + Solid::OpticalDisc::ContentTypes getContent(const OpticalDisc::Identity &info, const QByteArray &file) + { + if (!m_pointer) { + return advancedDiscDetect(file); + } + + if (!m_semaphore.acquire()) { + return advancedDiscDetect(file); + } + Releaser releaser(&m_semaphore); + + if (!m_shmem.lock()) { + return advancedDiscDetect(file); + } + Unlocker unlocker(&m_shmem); + + if (!m_pointer->find(info)) { + m_pointer->add(info, advancedDiscDetect(file)); + } + + Solid::OpticalDisc::ContentTypes content = m_pointer->front().second; + return content; + } + + ~SharedContentTypesCache() + { + m_semaphore.acquire(); + Releaser releaser(&m_semaphore); + m_shmem.detach(); + } +}; + +Q_GLOBAL_STATIC(QThreadStorage, sharedContentTypesCache) + +OpticalDisc::Identity::Identity() + : m_detectTime(0) + , m_size(0) + , m_labelHash(0) +{ +} + +OpticalDisc::Identity::Identity(const Device &device, const Device &drive) + : m_detectTime(drive.prop("TimeMediaDetected").toLongLong()) + , m_size(device.prop("Size").toLongLong()) + , m_labelHash(qHash(device.prop("IdLabel").toString())) +{ +} + +bool OpticalDisc::Identity::operator==(const OpticalDisc::Identity &b) const +{ + return m_detectTime == b.m_detectTime + && m_size == b.m_size + && m_labelHash == b.m_labelHash; +} + OpticalDisc::OpticalDisc(Device *dev) - : StorageVolume(dev), m_needsReprobe(true), m_cachedContent(Solid::OpticalDisc::NoContent) + : StorageVolume(dev) { UdevQt::Client client(this); m_udevDevice = client.deviceByDeviceFile(device()); - //qDebug() << "udev device:" << m_udevDevice.name() << "valid:" << m_udevDevice.isValid(); + // qDebug() << "udev device:" << m_udevDevice.name() << "valid:" << m_udevDevice.isValid(); /*qDebug() << "\tProperties:" << */ m_udevDevice.deviceProperties(); // initialize the properties DB so that it doesn't crash further down, #298416 m_drive = new Device(m_device->drivePath()); - QDBusConnection::systemBus().connect(UD2_DBUS_SERVICE, m_drive->udi(), DBUS_INTERFACE_PROPS, "PropertiesChanged", this, - SLOT(slotDrivePropertiesChanged(QString,QVariantMap,QStringList))); } OpticalDisc::~OpticalDisc() @@ -247,49 +422,30 @@ Solid::OpticalDisc::DiscType OpticalDisc::discType() const Solid::OpticalDisc::ContentTypes OpticalDisc::availableContent() const { if (isBlank()) { - m_needsReprobe = false; return Solid::OpticalDisc::NoContent; } - if (m_needsReprobe) { - QMutexLocker lock(cacheLock); + Solid::OpticalDisc::ContentTypes content = Solid::OpticalDisc::NoContent; + const bool hasData = m_drive->prop("OpticalNumDataTracks").toUInt() > 0; + const bool hasAudio = m_drive->prop("OpticalNumAudioTracks").toUInt() > 0; - const QByteArray deviceFile = m_device->prop("Device").toByteArray(); + if (hasData) { + content |= Solid::OpticalDisc::Data; - if (cache->contains(deviceFile)) { - m_cachedContent = cache->value(deviceFile); - m_needsReprobe = false; - return m_cachedContent; + Identity newIdentity(*m_device, *m_drive); + if (!(m_identity == newIdentity)) { + QByteArray deviceFile(m_device->prop("Device").toByteArray()); + m_cachedContent = sharedContentTypesCache->localData().getContent(newIdentity, deviceFile); + m_identity = newIdentity; } - m_cachedContent = Solid::OpticalDisc::NoContent; - const bool hasData = m_drive->prop("OpticalNumDataTracks").toUInt() > 0; - const bool hasAudio = m_drive->prop("OpticalNumAudioTracks").toUInt() > 0; - - if ( hasData ) { - m_cachedContent |= Solid::OpticalDisc::Data; - m_cachedContent |= advancedDiscDetect(deviceFile); - } - if ( hasAudio ) - m_cachedContent |= Solid::OpticalDisc::Audio; - - m_needsReprobe = false; - cache->insert(deviceFile, m_cachedContent); + content |= m_cachedContent; } - - return m_cachedContent; -} - -void OpticalDisc::slotDrivePropertiesChanged(const QString &ifaceName, const QVariantMap &changedProps, const QStringList &invalidatedProps) -{ - Q_UNUSED(ifaceName); - - if (changedProps.keys().contains("Media") || invalidatedProps.contains("Media")) { - QMutexLocker lock(cacheLock); - m_needsReprobe = true; - m_cachedContent = Solid::OpticalDisc::NoContent; - cache->remove(m_device->prop("Device").toByteArray()); + if (hasAudio) { + content |= Solid::OpticalDisc::Audio; } + + return content; } QString OpticalDisc::media() const diff --git a/3rdparty/solid-lite/backends/udisks2/udisksopticaldisc.h b/3rdparty/solid-lite/backends/udisks2/udisksopticaldisc.h index 9656d0ec30..8edecfda48 100644 --- a/3rdparty/solid-lite/backends/udisks2/udisksopticaldisc.h +++ b/3rdparty/solid-lite/backends/udisks2/udisksopticaldisc.h @@ -52,14 +52,25 @@ class OpticalDisc: public StorageVolume, virtual public Solid::Ifaces::OpticalDi Solid::OpticalDisc::DiscType discType() const override; Solid::OpticalDisc::ContentTypes availableContent() const override; -private Q_SLOTS: - void slotDrivePropertiesChanged(const QString & ifaceName, const QVariantMap & changedProps, const QStringList & invalidatedProps); + + class Identity + { + public: + Identity(); + Identity(const Device &device, const Device &drive); + bool operator==(const Identity &) const; + + private: + long long m_detectTime; + long long m_size; + uint m_labelHash; + }; private: + mutable Identity m_identity; QString media() const; - mutable bool m_needsReprobe; mutable Solid::OpticalDisc::ContentTypes m_cachedContent; - Device * m_drive; + Device *m_drive; UdevQt::Device m_udevDevice; }; diff --git a/3rdparty/solid-lite/soliddefs_p.h b/3rdparty/solid-lite/soliddefs_p.h index 64c0fefbcd..12ceca061e 100644 --- a/3rdparty/solid-lite/soliddefs_p.h +++ b/3rdparty/solid-lite/soliddefs_p.h @@ -76,99 +76,8 @@ namespace Solid #define SOLID_GLOBAL_STATIC(TYPE, NAME) SOLID_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ()) -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) #define SOLID_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \ -static QBasicAtomicPointer _solid_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0);\ -static bool _solid_static_##NAME##_destroyed; \ -static struct SOLID_GLOBAL_STATIC_STRUCT_NAME(NAME) \ -{ \ - bool isDestroyed() \ - { \ - return _solid_static_##NAME##_destroyed; \ - } \ - inline operator TYPE*() \ - { \ - return operator->(); \ - } \ - inline TYPE *operator->() \ - { \ - if (!_solid_static_##NAME) { \ - if (isDestroyed()) { \ - qFatal("Fatal Error: Accessed global static '%s *%s()' after destruction. " \ - "Defined at %s:%d", #TYPE, #NAME, __FILE__, __LINE__); \ - } \ - TYPE *x = new TYPE ARGS; \ - if (!_solid_static_##NAME.testAndSetOrdered(0, x) \ - && _solid_static_##NAME != x ) { \ - delete x; \ - } else { \ - static Solid::CleanUpGlobalStatic cleanUpObject = { destroy }; \ - } \ - } \ - return _solid_static_##NAME; \ - } \ - inline TYPE &operator*() \ - { \ - return *operator->(); \ - } \ - static void destroy() \ - { \ - _solid_static_##NAME##_destroyed = true; \ - TYPE *x = _solid_static_##NAME; \ - _solid_static_##NAME = 0; \ - delete x; \ - } \ -} NAME; - -#elif QT_VERSION < QT_VERSION_CHECK(5, 15, 0) - -#define SOLID_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \ -static QBasicAtomicPointer _solid_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0);\ -static bool _solid_static_##NAME##_destroyed; \ -static struct SOLID_GLOBAL_STATIC_STRUCT_NAME(NAME) \ -{ \ - bool isDestroyed() \ - { \ - return _solid_static_##NAME##_destroyed; \ - } \ - inline operator TYPE*() \ - { \ - return operator->(); \ - } \ - inline TYPE *operator->() \ - { \ - if (!_solid_static_##NAME.load()) { \ - if (isDestroyed()) { \ - qFatal("Fatal Error: Accessed global static '%s *%s()' after destruction. " \ - "Defined at %s:%d", #TYPE, #NAME, __FILE__, __LINE__); \ - } \ - TYPE *x = new TYPE ARGS; \ - if (!_solid_static_##NAME.testAndSetOrdered(0, x) \ - && _solid_static_##NAME.load() != x ) { \ - delete x; \ - } else { \ - static Solid::CleanUpGlobalStatic cleanUpObject = { destroy }; \ - } \ - } \ - return _solid_static_##NAME.load(); \ - } \ - inline TYPE &operator*() \ - { \ - return *operator->(); \ - } \ - static void destroy() \ - { \ - _solid_static_##NAME##_destroyed = true; \ - TYPE *x = _solid_static_##NAME.load(); \ - _solid_static_##NAME.store(0); \ - delete x; \ - } \ -} NAME; - -#else - -#define SOLID_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \ -static QBasicAtomicPointer _solid_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0);\ +static QAtomicPointer _solid_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0);\ static bool _solid_static_##NAME##_destroyed; \ static struct SOLID_GLOBAL_STATIC_STRUCT_NAME(NAME) \ { \ @@ -211,5 +120,3 @@ static struct SOLID_GLOBAL_STATIC_STRUCT_NAME(NAME) \ } NAME; #endif - -#endif From c614adfb0c76e3a14c296622e752f60cd2a9886f Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 20:25:40 +0100 Subject: [PATCH 05/21] [Port to Qt6] QRegExp -> QRegularExpression --- .../backends/hal/halfstabhandling.cpp | 3 +- context/lastfmengine.cpp | 4 +-- context/ultimatelyricsprovider.cpp | 18 +++++----- context/wikipediaengine.cpp | 36 +++++++++---------- db/librarydb.cpp | 4 +-- devices/deviceoptions.cpp | 5 +-- devices/encoders.cpp | 4 +-- devices/musicbrainz.cpp | 9 ++--- devices/transcodingjob.cpp | 24 +++++++------ gui/interfacesettings.cpp | 9 ++--- http/httpsocket.cpp | 5 +-- models/streamsmodel.cpp | 4 +-- mpd-interface/cuefile.cpp | 18 +++++----- mpd-interface/mpdconnection.cpp | 13 ++++--- online/rssparser.cpp | 14 ++++---- streams/streamfetcher.cpp | 8 ++--- 16 files changed, 94 insertions(+), 84 deletions(-) diff --git a/3rdparty/solid-lite/backends/hal/halfstabhandling.cpp b/3rdparty/solid-lite/backends/hal/halfstabhandling.cpp index 535343ff3f..5ac31b29a5 100644 --- a/3rdparty/solid-lite/backends/hal/halfstabhandling.cpp +++ b/3rdparty/solid-lite/backends/hal/halfstabhandling.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -167,7 +168,7 @@ QProcess *Solid::Backends::Hal::FstabHandling::callSystemCommand(const QString & QObject *obj, const char *slot) { QStringList env = QProcess::systemEnvironment(); - env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=/sbin:/bin:/usr/sbin/:/usr/bin"); + env.replaceInStrings(QRegularExpression("^PATH=(.*)", QRegularExpression::CaseInsensitiveOption), "PATH=/sbin:/bin:/usr/sbin/:/usr/bin"); QProcess *process = new QProcess(obj); diff --git a/context/lastfmengine.cpp b/context/lastfmengine.cpp index 79eb562e3b..1851406631 100644 --- a/context/lastfmengine.cpp +++ b/context/lastfmengine.cpp @@ -28,7 +28,7 @@ #include "config.h" #include #include -#include +#include #include static bool debugEnabled=false; @@ -133,7 +133,7 @@ void LastFmEngine::parseResponse() } if (!text.isEmpty()) { - static const QRegExp constLicense("User-contributed text is available.*"); + static const QRegularExpression constLicense("User-contributed text is available.*"); text.remove(constLicense); text.replace("\n", "
"); text=text.simplified(); diff --git a/context/ultimatelyricsprovider.cpp b/context/ultimatelyricsprovider.cpp index 481239b95d..67f4ea6d29 100644 --- a/context/ultimatelyricsprovider.cpp +++ b/context/ultimatelyricsprovider.cpp @@ -23,11 +23,11 @@ #include "ultimatelyricsprovider.h" #include "network/networkaccessmanager.h" -#include #include #include #include #include +#include static bool debugEnabled=false; #define DBUG if (debugEnabled) qWarning() << "Lyrics" << __FUNCTION__ void UltimateLyricsProvider::enableDebug() @@ -124,14 +124,15 @@ static QString extract(const QString &source, const QString &begin, const QStrin static QString extractXmlTag(const QString &source, const QString &tag) { DBUG << "Looking for" << tag; - QRegExp re("<(\\w+).*>"); // ಠ_ಠ - if (-1==re.indexIn(tag)) { + QRegularExpression re("<(\\w+).*>"); // ಠ_ಠ + QRegularExpressionMatch reMatch = re.match(tag); + if (! reMatch.hasMatch()) { DBUG << "Failed to find tag"; return QString(); } DBUG << "Found match"; - return extract(source, tag, "", true); + return extract(source, tag, "", true); } static QString exclude(const QString &source, const QString &begin, const QString &end) @@ -151,12 +152,13 @@ static QString exclude(const QString &source, const QString &begin, const QStrin static QString excludeXmlTag(const QString &source, const QString &tag) { - QRegExp re("<(\\w+).*>"); // ಠ_ಠ - if (-1==re.indexIn(tag)) { + QRegularExpression re("<(\\w+).*>"); // ಠ_ಠ + QRegularExpressionMatch reMatch = re.match(tag); + if (! reMatch.hasMatch()) { return source; } - return exclude(source, tag, ""); + return exclude(source, tag, ""); } static void applyExtractRule(const UltimateLyricsProvider::Rule &rule, QString &content, const Song &song) @@ -447,7 +449,7 @@ void UltimateLyricsProvider::doUrlReplace(const QString &tag, const QString &val // Apply URL character replacement QString valueCopy(value); for (const UltimateLyricsProvider::UrlFormat& format: urlFormats) { - QRegExp re("[" + QRegExp::escape(format.first) + "]"); + QRegularExpression re("[" + QRegularExpression::escape(format.first) + "]"); valueCopy.replace(re, format.second); } u.replace(tag, urlEncode(valueCopy), Qt::CaseInsensitive); diff --git a/context/wikipediaengine.cpp b/context/wikipediaengine.cpp index e2f7ec51f5..8c1be00e8f 100644 --- a/context/wikipediaengine.cpp +++ b/context/wikipediaengine.cpp @@ -28,7 +28,7 @@ #include "config.h" #include #include -#include +#include #include static bool debugEnabled=false; @@ -184,27 +184,27 @@ static QString wikiToHtml(QString answer, bool introOnly, const QUrl &url) { QString u=fixWikiLink(url); int start = answer.indexOf('>', answer.indexOf(" start && e < end) { end = e; } - e = answer.lastIndexOf(QRegExp("\n==\\s*Sources\\s*==")); + e = answer.lastIndexOf(QRegularExpression("\n==\\s*Sources\\s*==")); if (e > start && e < end) { end = e; } - e = answer.lastIndexOf(QRegExp("\n==\\s*Notes\\s*==")); + e = answer.lastIndexOf(QRegularExpression("\n==\\s*Notes\\s*==")); if (e > start && e < end) { end = e; } - e = answer.lastIndexOf(QRegExp("\n==\\s*References\\s*==")); + e = answer.lastIndexOf(QRegularExpression("\n==\\s*References\\s*==")); if (e > start && e < end) { end = e; } - e = answer.lastIndexOf(QRegExp("\n==\\s*External links\\s*==")); + e = answer.lastIndexOf(QRegularExpression("\n==\\s*External links\\s*==")); if (e > start && e < end) { end = e; } @@ -217,35 +217,35 @@ static QString wikiToHtml(QString answer, bool introOnly, const QUrl &url) answer = strip(answer, "{{", "}}"); // strip wiki internal stuff answer.replace("<", "<").replace(">", ">"); answer = strip(answer, ""); // strip comments - answer.remove(QRegExp("]*/>")); // strip inline refereces + answer.remove(QRegularExpression("]*/>")); // strip inline refereces answer = strip(answer, "", "", ""); +// answer.replace(QRegularExpression("\\n\\{\\|[^\\n]*wikitable[^\\n]*\\n!"), "\n
"); answer.replace("\n\n", "
"); answer.replace("( ; ", "("); // answer.replace("\n\n", "

"); - answer.replace(QRegExp("\\n'''([^\\n]*)'''\\n"), "


\\1\n"); - answer.replace(QRegExp("\\n\\{\\|[^\\n]*\\n"), "\n"); - answer.replace(QRegExp("\\n\\|[^\\n]*\\n"), "\n"); + answer.replace(QRegularExpression("\\n'''([^\\n]*)'''\\n"), "
\\1\n"); + answer.replace(QRegularExpression("\\n\\{\\|[^\\n]*\\n"), "\n"); + answer.replace(QRegularExpression("\\n\\|[^\\n]*\\n"), "\n"); answer.replace("\n*", "
"); answer.replace("\n", ""); answer.replace("'''s ", "'s"); - answer.replace("'''", "¬").replace(QRegExp("¬([^¬]*)¬"), "\\1"); - answer.replace("''", "¬").replace(QRegExp("¬([^¬]*)¬"), "\\1"); + answer.replace("'''", "¬").replace(QRegularExpression("¬([^¬]*)¬"), "\\1"); + answer.replace("''", "¬").replace(QRegularExpression("¬([^¬]*)¬"), "\\1"); if (!introOnly) { - answer.replace("===", "¬").replace(QRegExp("¬([^¬]*)¬"), "

\\1

"); - answer.replace("==", "¬").replace(QRegExp("¬([^¬]*)¬"), "

\\1

"); + answer.replace("===", "¬").replace(QRegularExpression("¬([^¬]*)¬"), "

\\1

"); + answer.replace("==", "¬").replace(QRegularExpression("¬([^¬]*)¬"), "

\\1

"); } answer.replace("&nbsp;", " "); answer.replace("–", "-"); @@ -404,7 +404,7 @@ void WikipediaEngine::parseTitles() if (titles.isEmpty()) { DBUG << "No titles"; - QRegExp regex(QLatin1Char('^') + hostLang + QLatin1String(".*$")); + QRegularExpression regex(QLatin1Char('^') + hostLang + QLatin1String(".*$")); int index = preferredLangs.indexOf(regex); if (-1!=index && index < preferredLangs.count()-1) { // use next preferred language as base for fetching langlinks since diff --git a/db/librarydb.cpp b/db/librarydb.cpp index 46bdccfd56..5f268ec558 100644 --- a/db/librarydb.cpp +++ b/db/librarydb.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -1173,7 +1173,7 @@ bool LibraryDb::setFilter(const QString &f, const QString &genre) QString newFilter=f.trimmed().toLower(); QString year; if (!f.isEmpty()) { - QStringList strings(newFilter.split(QRegExp("\\s+"))); + QStringList strings(newFilter.split(QRegularExpression("\\s+"))); static QList replaceChars=QList() << QLatin1Char('(') << QLatin1Char(')') << QLatin1Char('"') << QLatin1Char(':') << QLatin1Char('-') << QLatin1Char('#'); QStringList tokens; diff --git a/devices/deviceoptions.cpp b/devices/deviceoptions.cpp index 93048446ff..30c6529853 100644 --- a/devices/deviceoptions.cpp +++ b/devices/deviceoptions.cpp @@ -26,6 +26,7 @@ #include "support/configuration.h" #include #include +#include #ifndef _MSC_VER #include #endif @@ -340,7 +341,7 @@ QString DeviceOptions::clean(const QString &str) const result=result.simplified(); if (replaceSpaces) { - result.replace(QRegExp("\\s"), "_"); + result.replace(QRegularExpression("\\s"), "_"); } if (vfatSafe) { result = vfatPath(result); @@ -386,7 +387,7 @@ QString DeviceOptions::createFilename(const Song &s) const path.replace(i, QLatin1String("")); } if (replaceSpaces) { - path.replace(QRegExp("\\s"), "_"); + path.replace(QRegularExpression("\\s"), "_"); } Song copy=clean(s); diff --git a/devices/encoders.cpp b/devices/encoders.cpp index 65c76bd022..e369b22c5b 100644 --- a/devices/encoders.cpp +++ b/devices/encoders.cpp @@ -25,7 +25,7 @@ #include "config.h" #include "encoders.h" #include "support/utils.h" -#include +#include #include #include @@ -352,7 +352,7 @@ static void init() QStringList lines=output.split('\n', CANTATA_SKIP_EMPTY); for (const QString &line: lines) { - int pos=line.indexOf(QRegExp(QLatin1String("[\\. D]EA"))); + int pos=line.indexOf(QRegularExpression(QLatin1String("[\\. D]EA"))); if (0==pos || 1==pos) { QList::Iterator it(initial.begin()); QList::Iterator end(initial.end()); diff --git a/devices/musicbrainz.cpp b/devices/musicbrainz.cpp index e11aab093d..4c85f203c9 100644 --- a/devices/musicbrainz.cpp +++ b/devices/musicbrainz.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include "config.h" #include "support/thread.h" #include @@ -303,9 +303,10 @@ void MusicBrainz::lookup(bool full) album.genre=Song::unknown(); QString date = QString::fromUtf8(fullRelease->Date().c_str()); - QRegExp yearRe("^(\\d{4,4})(-\\d{1,2}-\\d{1,2})?$"); - if (yearRe.indexIn(date) > -1) { - QString yearString = yearRe.cap(1); + QRegularExpression yearRe("^(\\d{4,4})(-\\d{1,2}-\\d{1,2})?$"); + QRegularExpressionMatch yearMatch = yearRe.match(date); + if (yearMatch.hasMatch()) { + QString yearString = yearMatch.captured(1); bool ok; album.year=yearString.toInt(&ok); if (!ok) { diff --git a/devices/transcodingjob.cpp b/devices/transcodingjob.cpp index 0a410fcc85..8b62bf568b 100644 --- a/devices/transcodingjob.cpp +++ b/devices/transcodingjob.cpp @@ -23,6 +23,7 @@ #include "transcodingjob.h" #include "device.h" #include +#include TranscodingJob::TranscodingJob(const Encoders::Encoder &enc, int val, const QString &src, const QString &dest, const DeviceOptions &d, int co, const Song &s) : CopyJob(src, dest, d, co, s) @@ -127,14 +128,14 @@ void TranscodingJob::processOutput() inline qint64 TranscodingJob::computeDuration(const QString &output) { //We match something like "Duration: 00:04:33.60" - QRegExp matchDuration("Duration: (\\d{2,}):(\\d{2}):(\\d{2})\\.(\\d{2})"); - - if(output.contains(matchDuration)) { + QRegularExpression durationRegexp("Duration: (\\d{2,}):(\\d{2}):(\\d{2})\\.(\\d{2})"); + QRegularExpressionMatch match; + if(output.contains(durationRegexp, &match)) { //duration is in csec - return matchDuration.cap(1).toLong() * 60 * 60 * 100 + - matchDuration.cap(2).toInt() * 60 * 100 + - matchDuration.cap(3).toInt() * 100 + - matchDuration.cap(4).toInt(); + return match.captured(1).toLong() * 60 * 60 * 100 + + match.captured(2).toInt() * 60 * 100 + + match.captured(3).toInt() * 100 + + match.captured(4).toInt(); } else { return -1; } @@ -144,11 +145,12 @@ inline qint64 TranscodingJob::computeProgress(const QString &output) { //Output is like size= 323kB time=18.10 bitrate= 146.0kbits/s //We're going to use the "time" column, which counts the elapsed time in seconds. - QRegExp matchTime("time=(\\d+)\\.(\\d{2})"); + QRegularExpression timeRegexp("time=(\\d+)\\.(\\d{2})"); + QRegularExpressionMatch match; - if(output.contains(matchTime)) { - return matchTime.cap(1).toLong() * 100 + - matchTime.cap(2).toInt(); + if(output.contains(timeRegexp, &match)) { + return match.captured(1).toLong() * 100 + + match.captured(2).toInt(); } else { return -1; } diff --git a/gui/interfacesettings.cpp b/gui/interfacesettings.cpp index 017e8eda10..2325b990be 100644 --- a/gui/interfacesettings.cpp +++ b/gui/interfacesettings.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #ifdef QT_QTDBUS_FOUND #include @@ -400,10 +400,11 @@ static QSet translationCodes(const QString &dir) QSet codes; QDir d(dir); QStringList installed(d.entryList(QStringList() << "*.qm")); - QRegExp langRegExp("^cantata_(.*).qm$"); + QRegularExpression langRegExp("^cantata_(.*).qm$"); for (const QString &filename: installed) { - if (langRegExp.exactMatch(filename)) { - codes.insert(langRegExp.cap(1)); + QRegularExpressionMatch matchResult = langRegExp.match(filename); + if (matchResult.hasMatch()) { + codes.insert(matchResult.captured(1)); } } return codes; diff --git a/http/httpsocket.cpp b/http/httpsocket.cpp index 13b91b8e61..fa675bb5bc 100644 --- a/http/httpsocket.cpp +++ b/http/httpsocket.cpp @@ -31,6 +31,7 @@ #endif #include #include +#include #include #include #include @@ -264,9 +265,9 @@ void HttpSocket::readClient() } if (socket->canReadLine()) { - QList tokens = split(socket->readLine()); // QRegExp("[ \r\n][ \r\n]*")); + QList tokens = split(socket->readLine()); // QRegularExpression("[ \r\n][ \r\n]*")); if (tokens.length()>=2 && "GET"==tokens[0]) { - QStringList params = QString(socket->readAll()).split(QRegExp("[\r\n][\r\n]*")); + QStringList params = QString(socket->readAll()).split(QRegularExpression("[\r\n][\r\n]*")); DBUG << "params" << params << "tokens" << tokens; QUrl url(QUrl::fromEncoded(tokens[1])); diff --git a/models/streamsmodel.cpp b/models/streamsmodel.cpp index 5523b8de5a..621ecf4482 100644 --- a/models/streamsmodel.cpp +++ b/models/streamsmodel.cpp @@ -1236,11 +1236,11 @@ static QStringList fixGenres(const QString &genre) for (const QString &genre: allGenres) { if (genre.length() < 2 || genre.contains("ÃÂ") || // Broken unicode. - genre.contains(QRegExp("^#x[0-9a-f][0-9a-f]"))) { // Broken XML entities. + genre.contains(QRegularExpression("^#x[0-9a-f][0-9a-f]"))) { // Broken XML entities. continue; } // Convert 80 -> 80s. - if (genre.contains(QRegExp("^[0-9]0$"))) { + if (genre.contains(QRegularExpression("^[0-9]0$"))) { fixed << genre + 's'; } else { fixed << genre; diff --git a/mpd-interface/cuefile.cpp b/mpd-interface/cuefile.cpp index 654c17a577..7f791efc7d 100644 --- a/mpd-interface/cuefile.cpp +++ b/mpd-interface/cuefile.cpp @@ -30,9 +30,8 @@ #include #include #include -#include #include -#include +#include #include #include #include @@ -127,12 +126,13 @@ static const double constMsecPerSec = 1000.0; // Seconds in a MSF index (MM:SS:FF) static double indexToMarker(const QString &index) { - QRegExp indexRegexp("(\\d{1,3}):(\\d{2}):(\\d{2})"); - if (!indexRegexp.exactMatch(index)) { + QRegularExpression indexRegexp("(\\d{1,3}):(\\d{2}):(\\d{2})"); + QRegularExpressionMatch indexMatch = indexRegexp.match(index); + if (!indexMatch.hasMatch()) { return -1.0; } - QStringList splitted = indexRegexp.capturedTexts().mid(1, -1); + QStringList splitted = indexMatch.capturedTexts().mid(1, -1); qlonglong frames = splitted.at(0).toLongLong() * 60 * 75 + splitted.at(1).toLongLong() * 75 + splitted.at(2).toLongLong(); return (frames * constMsecPerSec) / 75.0; } @@ -348,7 +348,7 @@ bool CueFile::parse(const QString &fileName, const QString &dir, QList &so // get the file type if (!cmdVal.isEmpty()) { cmdVal.remove('"').remove("'"); - QStringList cmdValSplitted = cmdVal.split(QRegExp("\\s+")); + QStringList cmdValSplitted = cmdVal.split(QRegularExpression("\\s+")); if (cmdValSplitted.size() == 2) { file = cmdValSplitted[0].remove("\""); // file audio: name fileType = cmdValSplitted[1]; // file audio: type @@ -374,7 +374,7 @@ bool CueFile::parse(const QString &fileName, const QString &dir, QList &so // continue parsing the FILE section (header of the CUE file)... } else if (cmdCmd == constGenre) { // if GENRE is a list (separated by one of: , ; | \t), then split - for (const auto &g: cmdVal.split(QRegExp("(,|;|\\t|\\|)"))) { + for (const auto &g: cmdVal.split(QRegularExpression("(,|;|\\t|\\|)"))) { genre.append(g.trimmed()); } } else if (cmdCmd == constTitle) { @@ -456,7 +456,7 @@ bool CueFile::parse(const QString &fileName, const QString &dir, QList &so // here is a new track... get the actual track number and the track type if (!cmdVal.isEmpty()) { cmdVal.remove('"').remove("'"); - QStringList cmdValSplitted = cmdVal.split(QRegExp("\\s+")); + QStringList cmdValSplitted = cmdVal.split(QRegularExpression("\\s+")); if (cmdValSplitted.size() == 2) { trackNo = cmdValSplitted[0]; trackType = cmdValSplitted[1].toLower(); @@ -469,7 +469,7 @@ bool CueFile::parse(const QString &fileName, const QString &dir, QList &so // note: PREGAP and POSTGAP are NOT handled... if (!cmdVal.isEmpty()) { cmdVal.remove('"').remove("'"); - QStringList cmdValSplitted = cmdVal.split(QRegExp("\\s+")); + QStringList cmdValSplitted = cmdVal.split(QRegularExpression("\\s+")); // if there's none "01" index, we'll just take the first one // also, we'll take the "01" index even if it's the last one if (cmdValSplitted.size() == 2 && (cmdValSplitted[0]==QLatin1String("01") || cmdValSplitted[0]==QLatin1String("1") || index.isEmpty())) { diff --git a/mpd-interface/mpdconnection.cpp b/mpd-interface/mpdconnection.cpp index 785919a465..a8030a062d 100644 --- a/mpd-interface/mpdconnection.cpp +++ b/mpd-interface/mpdconnection.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -2044,13 +2045,11 @@ void MPDConnection::search(const QString &field, const QString &value, int id) if (field==constModifiedSince) { time_t v=0; - if (QRegExp("\\d*").exactMatch(value)) { - #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - v=QDateTime::currentDateTime().date().startOfDay().toTime_t()-(value.toInt()*24*60*60); - #else - v=QDateTime(QDateTime::currentDateTime().date()).toTime_t()-(value.toInt()*24*60*60); - #endif - } else if (QRegExp("^((19|20)\\d\\d)[-/](0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])$").exactMatch(value)) { + if (QRegularExpression("\\d*").match(value).hasMatch()) { + QDateTime vDate = QDateTime(); + vDate.setDate(QDateTime::currentDateTime().date()); + v=vDate.toSecsSinceEpoch()-(value.toInt()*24*60*60); + } else if (QRegularExpression("^((19|20)\\d\\d)[-/](0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])$").match(value).hasMatch()) { QDateTime dt=QDateTime::fromString(QString(value).replace("/", "-"), Qt::ISODate); if (dt.isValid()) { v=dt.toTime_t(); diff --git a/online/rssparser.cpp b/online/rssparser.cpp index 572e369a79..cac8d918bf 100644 --- a/online/rssparser.cpp +++ b/online/rssparser.cpp @@ -25,6 +25,7 @@ #include #include #include +#include static const char * constITunesNameSpace = "http://www.itunes.com/dtds/podcast-1.0.dtd"; static const char * constMediaNameSpace = "http://search.yahoo.com/mrss/"; @@ -69,19 +70,20 @@ static QDateTime parseRfc822DateTime(const QString &text) // This sucks but we need it because some podcasts don't quite follow the // spec properly - they might have 1-digit hour numbers for example. - QRegExp re("([a-zA-Z]{3}),? (\\d{1,2}) ([a-zA-Z]{3}) (\\d{4}) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})"); - if (-1==re.indexIn(text)) { + QRegularExpression re("([a-zA-Z]{3}),? (\\d{1,2}) ([a-zA-Z]{3}) (\\d{4}) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})"); + QRegularExpressionMatch reMatch = re.match(text); + if (!reMatch.hasMatch()) { return QDateTime(); } - QDateTime dt(QDate::fromString(QString("%1 %2 %3 %4").arg(re.cap(1), re.cap(3), re.cap(2), re.cap(4)), Qt::TextDate), - QTime(re.cap(5).toInt(), re.cap(6).toInt(), re.cap(7).toInt())); + QDateTime dt(QDate::fromString(QString("%1 %2 %3 %4").arg(reMatch.captured(1), reMatch.captured(3), reMatch.captured(2), reMatch.captured(4)), Qt::TextDate), + QTime(reMatch.captured(5).toInt(), reMatch.captured(6).toInt(), reMatch.captured(7).toInt())); if (dt.isValid()) { return dt; } - return QDateTime(QDate::fromString(QString("%1 %2 %3 %4").arg(capitaliseWord(re.cap(1)), capitaliseWord(re.cap(3)), re.cap(2), re.cap(4)), Qt::TextDate), - QTime(re.cap(5).toInt(), re.cap(6).toInt(), re.cap(7).toInt())); + return QDateTime(QDate::fromString(QString("%1 %2 %3 %4").arg(capitaliseWord(reMatch.captured(1)), capitaliseWord(reMatch.captured(3)), reMatch.captured(2), reMatch.captured(4)), Qt::TextDate), + QTime(reMatch.captured(5).toInt(), reMatch.captured(6).toInt(), reMatch.captured(7).toInt())); } static QUrl parseImage(QXmlStreamReader &reader) diff --git a/streams/streamfetcher.cpp b/streams/streamfetcher.cpp index 02963bfbeb..4a005f88d5 100644 --- a/streams/streamfetcher.cpp +++ b/streams/streamfetcher.cpp @@ -26,7 +26,7 @@ #include "mpd-interface/mpdconnection.h" #include "mpd-interface/mpdparseutils.h" #include "models/streamsmodel.h" -#include +#include #include #include #include @@ -75,7 +75,7 @@ static QString parsePlaylist(const QByteArray &data, const QString &key, const Q static QString parseExt3Mu(const QByteArray &data, const QSet &handlers) { - QStringList lines=QString(data).split(QRegExp(QLatin1String("(\r\n|\n|\r)")), CANTATA_SKIP_EMPTY); + QStringList lines=QString(data).split(QRegularExpression(QLatin1String("(\r\n|\n|\r)")), CANTATA_SKIP_EMPTY); for (QString line: lines) { for (const QString &handler: handlers) { @@ -93,7 +93,7 @@ static QString parseExt3Mu(const QByteArray &data, const QSet &handlers static QString parseAsx(const QByteArray &data, const QSet &handlers) { - QStringList lines=QString(data).split(QRegExp(QLatin1String("(\r\n|\n|\r|/>)")), CANTATA_SKIP_EMPTY); + QStringList lines=QString(data).split(QRegularExpression(QLatin1String("(\r\n|\n|\r|/>)")), CANTATA_SKIP_EMPTY); for (QString line: lines) { int ref=line.indexOf(QLatin1String(" Date: Thu, 29 Feb 2024 20:35:02 +0100 Subject: [PATCH 06/21] [Port to Qt6] QVariant::type() => QVariant::typeId() --- 3rdparty/solid-lite/backends/iokit/cfhelper.cpp | 2 +- 3rdparty/solid-lite/predicate.cpp | 16 ++++++++-------- db/librarydb.cpp | 2 +- support/urllabel.cpp | 2 +- widgets/notelabel.cpp | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/3rdparty/solid-lite/backends/iokit/cfhelper.cpp b/3rdparty/solid-lite/backends/iokit/cfhelper.cpp index 62c5c37578..7b6557f404 100644 --- a/3rdparty/solid-lite/backends/iokit/cfhelper.cpp +++ b/3rdparty/solid-lite/backends/iokit/cfhelper.cpp @@ -109,7 +109,7 @@ static QVariant q_toVariant(const CFTypeRef &obj) bool metNonString = false; for (CFIndex i = 0; i < size; ++i) { QVariant value = q_toVariant(CFArrayGetValueAtIndex(cfarray, i)); - if (value.type() != QVariant::String) + if (value.typeId() != QMetaType::QString) metNonString = true; list << value; } diff --git a/3rdparty/solid-lite/predicate.cpp b/3rdparty/solid-lite/predicate.cpp index aeabcefb84..b3e8e8f970 100644 --- a/3rdparty/solid-lite/predicate.cpp +++ b/3rdparty/solid-lite/predicate.cpp @@ -209,7 +209,7 @@ bool Solid::Predicate::matches(const Device &device) const QVariant value = metaProp.isReadable() ? metaProp.read(iface) : QVariant(); QVariant expected = d->value; - if (metaProp.isEnumType() && expected.type()==QVariant::String) { + if (metaProp.isEnumType() && expected.typeId()==QMetaType::QString) { QMetaEnum metaEnum = metaProp.enumerator(); int value = metaEnum.keysToValue(d->value.toString().toLatin1()); if (value>=0) { // No value found for these keys, resetting expected to invalid @@ -287,9 +287,9 @@ QString Solid::Predicate::toString() const QString value; - switch (d->value.type()) + switch (d->value.typeId()) { - case QVariant::StringList: + case QMetaType::QStringList: { value = '{'; @@ -311,13 +311,13 @@ QString Solid::Predicate::toString() const value+= '}'; break; } - case QVariant::Bool: + case QMetaType::Bool: value = (d->value.toBool()?"true":"false"); break; - case QVariant::Int: - case QVariant::UInt: - case QVariant::LongLong: - case QVariant::ULongLong: + case QMetaType::Int: + case QMetaType::UInt: + case QMetaType::LongLong: + case QMetaType::ULongLong: value = d->value.toString(); break; default: diff --git a/db/librarydb.cpp b/db/librarydb.cpp index 5f268ec558..c94755bb1b 100644 --- a/db/librarydb.cpp +++ b/db/librarydb.cpp @@ -413,7 +413,7 @@ class SqlQuery } else { // Do integers inline - sqlite seems to get confused when you pass integers // to bound parameters - if (QVariant::Int==value.type()) { + if (QMetaType::Int==value.typeId()) { whereClauses << QString("%1 %2 %3").arg(column, op, value.toString()); } else if ("genre"==column) { QString clause("("); diff --git a/support/urllabel.cpp b/support/urllabel.cpp index 845452ab31..427c9f23c6 100644 --- a/support/urllabel.cpp +++ b/support/urllabel.cpp @@ -43,7 +43,7 @@ void UrlLabel::setText(const QString &t) void UrlLabel::setProperty(const char *name, const QVariant &value) { - if (name && !strcmp(name, "text") && QVariant::String==value.type()) { + if (name && !strcmp(name, "text") && QMetaType::QString==value.typeId()) { setText(value.toString()); } } diff --git a/widgets/notelabel.cpp b/widgets/notelabel.cpp index b8896091ec..86eba54704 100644 --- a/widgets/notelabel.cpp +++ b/widgets/notelabel.cpp @@ -76,7 +76,7 @@ NoteLabel::NoteLabel(QWidget *parent) void NoteLabel::setProperty(const char *name, const QVariant &value) { - if (name && !strcmp(name, "text") && QVariant::String==value.type()) { + if (name && !strcmp(name, "text") && QMetaType::QString==value.typeId()) { setText(value.toString()); } } @@ -90,7 +90,7 @@ UrlNoteLabel::UrlNoteLabel(QWidget *parent) void UrlNoteLabel::setProperty(const char *name, const QVariant &value) { - if (name && !strcmp(name, "text") && QVariant::String==value.type()) { + if (name && !strcmp(name, "text") && QMetaType::QString==value.typeId()) { setText(value.toString()); } } From 493784a4cfcd6cee8de472381f975cab7a92bd47 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:10:16 +0100 Subject: [PATCH 07/21] [Port to Qt6] Change in QVariant::setValue templating --- models/actionmodel.cpp | 7 +++++-- models/devicesmodel.cpp | 4 ++-- models/localbrowsemodel.cpp | 2 +- models/mpdlibrarymodel.cpp | 4 ++-- models/mpdsearchmodel.cpp | 2 +- models/playlistsmodel.cpp | 2 +- models/playqueuemodel.cpp | 4 ++-- models/searchmodel.cpp | 4 ++-- models/streamsearchmodel.cpp | 4 ++-- models/streamsmodel.cpp | 2 +- online/jamendoservice.cpp | 2 +- online/magnatuneservice.cpp | 2 +- online/podcastservice.cpp | 4 ++-- playlists/dynamicplaylists.cpp | 2 +- 14 files changed, 24 insertions(+), 21 deletions(-) diff --git a/models/actionmodel.cpp b/models/actionmodel.cpp index b8ec5d6d47..907f92a1b4 100644 --- a/models/actionmodel.cpp +++ b/models/actionmodel.cpp @@ -30,13 +30,16 @@ QVariant ActionModel::data(const QModelIndex &index, int role) const QVariant v; Q_UNUSED(index) switch(role) { - case Cantata::Role_Actions: - v.setValue >(QList() << StdActions::self()->replacePlayQueueAction << StdActions::self()->appendToPlayQueueAction); + case Cantata::Role_Actions: { + v.setValue(QList() << StdActions::self()->replacePlayQueueAction << StdActions::self()->appendToPlayQueueAction); + } break; case Cantata::Role_RatingCol: return -1; + break; case Cantata::Role_TitleText: return data(index, Qt::DisplayRole); + break; default: break; } diff --git a/models/devicesmodel.cpp b/models/devicesmodel.cpp index 4c15f1e9ef..42a5edc83f 100644 --- a/models/devicesmodel.cpp +++ b/models/devicesmodel.cpp @@ -378,9 +378,9 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const actions << editAction; } #endif - v.setValue >(actions); + v.setValue(actions); } else if (root(item)->canPlaySongs() && HttpServer::self()->isAlive()) { - v.setValue >(QList() << StdActions::self()->replacePlayQueueAction << StdActions::self()->appendToPlayQueueAction); + v.setValue(QList() << StdActions::self()->replacePlayQueueAction << StdActions::self()->appendToPlayQueueAction); } return v; } diff --git a/models/localbrowsemodel.cpp b/models/localbrowsemodel.cpp index 48ea6fb818..bc58320c64 100644 --- a/models/localbrowsemodel.cpp +++ b/models/localbrowsemodel.cpp @@ -104,7 +104,7 @@ QVariant LocalBrowseModel::data(const QModelIndex &index, int role) const } case Cantata::Role_Actions: { QVariant v; - v.setValue >(QList() << StdActions::self()->replacePlayQueueAction << StdActions::self()->appendToPlayQueueAction); + v.setValue(QList() << StdActions::self()->replacePlayQueueAction << StdActions::self()->appendToPlayQueueAction); return v; } default: diff --git a/models/mpdlibrarymodel.cpp b/models/mpdlibrarymodel.cpp index dc9e55c868..c46b5a73d7 100644 --- a/models/mpdlibrarymodel.cpp +++ b/models/mpdlibrarymodel.cpp @@ -78,7 +78,7 @@ QVariant MpdLibraryModel::data(const QModelIndex &index, int role) const song.addGenre(item->getParent()->getParent()->getId()); } } - v.setValue(item->getSong()); + v.setValue(item->getSong()); break; case T_Artist: if (!showArtistImages && Cantata::Role_CoverSong==role) { @@ -102,7 +102,7 @@ QVariant MpdLibraryModel::data(const QModelIndex &index, int role) const } item->setSong(song); } - v.setValue(item->getSong()); + v.setValue(item->getSong()); break; default: break; diff --git a/models/mpdsearchmodel.cpp b/models/mpdsearchmodel.cpp index c7f9a8997b..8f7dcb009e 100644 --- a/models/mpdsearchmodel.cpp +++ b/models/mpdsearchmodel.cpp @@ -60,7 +60,7 @@ QVariant MpdSearchModel::data(const QModelIndex &index, int role) const emit getRating(song->file); song->rating=Song::Rating_Requested; } - var.setValue(*song); + var.setValue(*song); return var; } default: diff --git a/models/playlistsmodel.cpp b/models/playlistsmodel.cpp index 8914188d3e..b65abbd23c 100644 --- a/models/playlistsmodel.cpp +++ b/models/playlistsmodel.cpp @@ -379,7 +379,7 @@ QVariant PlaylistsModel::data(const QModelIndex &index, int role) const case Cantata::Role_SongWithRating: case Cantata::Role_Song: { QVariant var; - var.setValue(*s); + var.setValue(*s); return var; } case Cantata::Role_AlbumDuration: { diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index 43542f0f44..364fb6e5dc 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -601,13 +601,13 @@ QVariant PlayQueueModel::data(const QModelIndex &index, int role) const return songs.at(index.row()).id; case Cantata::Role_SongWithRating: case Cantata::Role_Song: { - QVariant var; const Song &s=songs.at(index.row()); if (Cantata::Role_SongWithRating==role && Song::Standard==s.type && Song::Rating_Null==s.rating) { emit getRating(s.file); s.rating=Song::Rating_Requested; } - var.setValue(s); + QVariant var; + var.setValue(s); return var; } case Cantata::Role_AlbumDuration: { diff --git a/models/searchmodel.cpp b/models/searchmodel.cpp index 5f045883b8..002e14232a 100644 --- a/models/searchmodel.cpp +++ b/models/searchmodel.cpp @@ -235,12 +235,12 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const return true; case Cantata::Role_CoverSong: { QVariant v; - v.setValue(*song); + v.setValue(*song); return v; } case Cantata::Role_Song: { QVariant var; - var.setValue(*song); + var.setValue(*song); return var; } default: diff --git a/models/streamsearchmodel.cpp b/models/streamsearchmodel.cpp index a3b4d3a33b..2c54d7cdfb 100644 --- a/models/streamsearchmodel.cpp +++ b/models/streamsearchmodel.cpp @@ -147,12 +147,12 @@ QVariant StreamSearchModel::data(const QModelIndex &index, int role) const if (item->isCategory()){ if (static_cast(item)->canBookmark) { QVariant v; - v.setValue >(QList() << StreamsModel::self()->addBookmarkAct()); + v.setValue(QList() << StreamsModel::self()->addBookmarkAct()); return v; } } else { QVariant v; - v.setValue >(QList() << StdActions::self()->replacePlayQueueAction << StreamsModel::self()->addToFavouritesAct()); + v.setValue(QList() << StdActions::self()->replacePlayQueueAction << StreamsModel::self()->addToFavouritesAct()); return v; } break; diff --git a/models/streamsmodel.cpp b/models/streamsmodel.cpp index 621ecf4482..c51ffefa54 100644 --- a/models/streamsmodel.cpp +++ b/models/streamsmodel.cpp @@ -645,7 +645,7 @@ QVariant StreamsModel::data(const QModelIndex &index, int role) const } if (!actions.isEmpty()) { QVariant v; - v.setValue >(actions); + v.setValue(actions); return v; } break; diff --git a/online/jamendoservice.cpp b/online/jamendoservice.cpp index e502a8758e..116d1bf520 100644 --- a/online/jamendoservice.cpp +++ b/online/jamendoservice.cpp @@ -343,7 +343,7 @@ QVariant JamendoService::data(const QModelIndex &index, int role) const song.setExtraField(Song::OnlineImageUrl, QString("http://api.jamendo.com/get2/image/album/redirect/?id=%1&imagesize=300").arg(id)); item->setSong(song); } - v.setValue(item->getSong()); + v.setValue(item->getSong()); break; case T_Artist: break; diff --git a/online/magnatuneservice.cpp b/online/magnatuneservice.cpp index f9cce2f230..6a55c8704a 100644 --- a/online/magnatuneservice.cpp +++ b/online/magnatuneservice.cpp @@ -186,7 +186,7 @@ QVariant MagnatuneService::data(const QModelIndex &index, int role) const song.setExtraField(Song::OnlineImageUrl, url); item->setSong(song); } - v.setValue(item->getSong()); + v.setValue(item->getSong()); break; case T_Artist: break; diff --git a/online/podcastservice.cpp b/online/podcastservice.cpp index ae9840afe0..0fbef83d52 100644 --- a/online/podcastservice.cpp +++ b/online/podcastservice.cpp @@ -581,14 +581,14 @@ QVariant PodcastService::data(const QModelIndex &index, int role) const switch(role) { case Cantata::Role_Actions: { QVariant v; - v.setValue >(QList() << StdActions::self()->replacePlayQueueAction << StdActions::self()->appendToPlayQueueAction << refreshAction); + v.setValue(QList() << StdActions::self()->replacePlayQueueAction << StdActions::self()->appendToPlayQueueAction << refreshAction); return v; } case Cantata::Role_ListImage: return true; case Cantata::Role_CoverSong: { QVariant v; - v.setValue(podcast->coverSong()); + v.setValue(podcast->coverSong()); return v; } case Qt::DecorationRole: diff --git a/playlists/dynamicplaylists.cpp b/playlists/dynamicplaylists.cpp index 47c823795b..01dd485260 100644 --- a/playlists/dynamicplaylists.cpp +++ b/playlists/dynamicplaylists.cpp @@ -175,7 +175,7 @@ QVariant DynamicPlaylists::data(const QModelIndex &index, int role) const return IS_ACTIVE(entryList.at(index.row()).name) ? Icons::self()->replacePlayQueueIcon : icn; case Cantata::Role_Actions: { QVariant v; - v.setValue >(QList() << (IS_ACTIVE(entryList.at(index.row()).name) ? stopAction : startAction)); + v.setValue(QList() << (IS_ACTIVE(entryList.at(index.row()).name) ? stopAction : startAction)); return v; } default: From 90296ef18feebb1e69322cb7424a02413c6594f4 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 20:40:49 +0100 Subject: [PATCH 08/21] [Port to Qt6] QLayout::setMargin(int) -> QLayout::setContentsMargins(int,int,int,int) idem for getMargin --- context/contextwidget.cpp | 16 ++++++++-------- context/lyricsdialog.cpp | 4 ++-- context/view.cpp | 2 +- devices/devicepropertieswidget.cpp | 2 +- devices/remotedevicepropertieswidget.cpp | 2 +- gui/apikeyssettings.cpp | 2 +- gui/cachesettings.cpp | 2 +- gui/coverdialog.cpp | 2 +- gui/customactionssettings.cpp | 4 ++-- gui/mainwindow.cpp | 4 ++-- gui/shortcutssettingspage.cpp | 2 +- online/jamendosettingsdialog.cpp | 2 +- online/magnatunesettingsdialog.cpp | 2 +- online/podcastsearchdialog.cpp | 16 ++++++++-------- online/podcastsettingsdialog.cpp | 2 +- replaygain/rgdialog.cpp | 2 +- streams/streamdialog.cpp | 2 +- support/dialog.cpp | 4 ++-- support/fancytabwidget.cpp | 6 +++--- support/inputdialog.cpp | 2 +- support/keysequencewidget.cpp | 2 +- support/kmessagewidget.cpp | 4 ++-- support/messagebox.cpp | 2 +- support/pagewidget.cpp | 4 ++-- widgets/coverwidget.cpp | 2 +- widgets/multipagewidget.cpp | 19 +++++++++++++++---- widgets/notelabel.cpp | 2 +- widgets/nowplayingwidget.cpp | 4 ++-- widgets/singlepagewidget.cpp | 6 +++--- widgets/sizegrip.cpp | 2 +- widgets/titlewidget.cpp | 6 +++--- widgets/volumecontrol.cpp | 2 +- 32 files changed, 73 insertions(+), 62 deletions(-) diff --git a/context/contextwidget.cpp b/context/contextwidget.cpp index a5c2c6cfba..15b2b997c6 100644 --- a/context/contextwidget.cpp +++ b/context/contextwidget.cpp @@ -131,7 +131,7 @@ void ViewSelector::addItem(const QString &label, const QVariant &data) QHBoxLayout *l; if (buttons.isEmpty()) { l = new QHBoxLayout(this); - l->setMargin(0); + l->setContentsMargins(0, 0, 0, 0); l->setSpacing(0); } else { l=static_cast(layout()); @@ -260,7 +260,7 @@ ContextWidget::ContextWidget(QWidget *parent) mainStack=new QStackedWidget(this); standardContext=new QWidget(mainStack); mainStack->addWidget(standardContext); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(mainStack); animator.setPropertyName("fade"); animator.setTargetObject(this); @@ -295,8 +295,8 @@ void ContextWidget::setWide(bool w) } QHBoxLayout *l=new QHBoxLayout(standardContext); standardContext->setLayout(l); - int m=l->margin()/2; - l->setMargin(0); + int m=l->contentsMargins().top()/2; + l->setContentsMargins(0, 0, 0, 0); if (stack) { stack->setVisible(false); viewSelector->setVisible(false); @@ -336,8 +336,8 @@ void ContextWidget::setWide(bool w) } QGridLayout *l=new QGridLayout(standardContext); standardContext->setLayout(l); - int m=l->margin()/2; - l->setMargin(0); + int m=l->contentsMargins().top()/2; + l->setContentsMargins(0, 0, 0, 0); l->setSpacing(0); if (!stack) { stack=new QStackedWidget(standardContext); @@ -623,8 +623,8 @@ void ContextWidget::update(const Song &s) if (!onlineContext) { QWidget *onlinePage=new QWidget(mainStack); QHBoxLayout *onlineLayout=new QHBoxLayout(onlinePage); - int m=onlineLayout->margin()/2; - onlineLayout->setMargin(0); + int m=onlineLayout->contentsMargins().top()/2; + onlineLayout->setContentsMargins(0, 0, 0, 0); onlineLayout->addItem(new QSpacerItem(m, m, QSizePolicy::Fixed, QSizePolicy::Fixed)); onlineContext=new OnlineView(onlinePage); onlineLayout->addWidget(onlineContext); diff --git a/context/lyricsdialog.cpp b/context/lyricsdialog.cpp index 5f43051aa3..2960efd8af 100644 --- a/context/lyricsdialog.cpp +++ b/context/lyricsdialog.cpp @@ -48,8 +48,8 @@ LyricsDialog::LyricsDialog(const Song &s, QWidget *parent) int iconSize=Icon::dlgIconSize(); icn->setFixedSize(iconSize, iconSize); icn->setPixmap(style()->standardIcon(QStyle::SP_MessageBoxInformation).pixmap(iconSize, iconSize)); - mainLayout->setMargin(0); - layout->setMargin(0); + mainLayout->setContentsMargins(0, 0, 0, 0); + layout->setContentsMargins(0, 0, 0, 0); mainLayout->addWidget(icn, 0, 0, 1, 1); mainLayout->addWidget(lbl, 0, 1, 1, 1); mainLayout->addItem(new QSpacerItem(8, 4, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 0); diff --git a/context/view.cpp b/context/view.cpp index 7ed9b044d9..b48dd7f308 100644 --- a/context/view.cpp +++ b/context/view.cpp @@ -116,7 +116,7 @@ View::View(QWidget *parent, const QStringList &views) header->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); header->setTextInteractionFlags(Qt::TextSelectableByMouse|Qt::TextSelectableByKeyboard); - layout->setMargin(2); + layout->setContentsMargins(2, 2, 2, 2); layout->addWidget(header); if (views.isEmpty()) { layout->addWidget(texts.at(0)); diff --git a/devices/devicepropertieswidget.cpp b/devices/devicepropertieswidget.cpp index 3c93f1750c..4a74113ce2 100644 --- a/devices/devicepropertieswidget.cpp +++ b/devices/devicepropertieswidget.cpp @@ -103,7 +103,7 @@ DevicePropertiesWidget::DevicePropertiesWidget(QWidget *parent) "the contents of the device re-scanned.

")); if (qobject_cast(parent)) { - verticalLayout->setMargin(4); + verticalLayout->setContentsMargins(4, 4, 4, 4); } } diff --git a/devices/remotedevicepropertieswidget.cpp b/devices/remotedevicepropertieswidget.cpp index d470e78ba8..93a50c6477 100644 --- a/devices/remotedevicepropertieswidget.cpp +++ b/devices/remotedevicepropertieswidget.cpp @@ -42,7 +42,7 @@ RemoteDevicePropertiesWidget::RemoteDevicePropertiesWidget(QWidget *parent) { setupUi(this); if (qobject_cast(parent)) { - verticalLayout->setMargin(4); + verticalLayout->setContentsMargins(4, 4, 4, 4); } type->addItem(tr("Secure Shell (sshfs)"), (int)Type_SshFs); type->addItem(tr("Locally Mounted Folder"), (int)Type_File); diff --git a/gui/apikeyssettings.cpp b/gui/apikeyssettings.cpp index ff0254c467..0fcb699792 100644 --- a/gui/apikeyssettings.cpp +++ b/gui/apikeyssettings.cpp @@ -69,7 +69,7 @@ ApiKeysSettings::ApiKeysSettings(QWidget *p) { int spacing=Utils::layoutSpacing(this); QVBoxLayout *layout=new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); QLabel *label=new QLabel(tr("Cantata uses various internet services to provide covers, radio stream listings, etc. " "Most of these require an application's developer to register with the service, and obtain an API Key. " "Cantata contains the keys required to access these services. Unfortunately, some of these services have " diff --git a/gui/cachesettings.cpp b/gui/cachesettings.cpp index d1abe70e70..25383cfd4d 100644 --- a/gui/cachesettings.cpp +++ b/gui/cachesettings.cpp @@ -247,7 +247,7 @@ CacheSettings::CacheSettings(QWidget *parent) { int spacing=Utils::layoutSpacing(this); QGridLayout *layout=new QGridLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); int row=0; int col=0; QLabel *label=new QLabel(tr("Cantata caches various pieces of information (covers, lyrics, etc). Below is a summary of Cantata's " diff --git a/gui/coverdialog.cpp b/gui/coverdialog.cpp index 8873367fcf..8d18a5da5b 100644 --- a/gui/coverdialog.cpp +++ b/gui/coverdialog.cpp @@ -236,7 +236,7 @@ CoverPreview::CoverPreview(QWidget *p) layout->addWidget(loadingLabel); layout->addWidget(pbar); layout->addWidget(scrollArea); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); setMainWidget(mw); } diff --git a/gui/customactionssettings.cpp b/gui/customactionssettings.cpp index e69b2508dd..f6d087c5b0 100644 --- a/gui/customactionssettings.cpp +++ b/gui/customactionssettings.cpp @@ -49,7 +49,7 @@ CustomActionDialog::CustomActionDialog(QWidget *p) NoteLabel *note=new NoteLabel(widget); note->setText(tr("In the command line above, %f will be replaced with the file list and %d with the folder list. If neither are supplied, the the list of files will be appended to the command.")); layout->setWidget(2, QFormLayout::SpanningRole, note); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); setButtons(Dialog::Ok|Dialog::Cancel); setMainWidget(widget); setMinimumWidth(400); @@ -83,7 +83,7 @@ CustomActionsSettings::CustomActionsSettings(QWidget *parent) , dlg(nullptr) { QGridLayout *layout=new QGridLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); QLabel *label=new QLabel(tr("To have Cantata call external commands (e.g. to edit tags with another application), add an entry for the command below. When at least one command " "command is defined, a 'Custom Actions' entry will be added to the context menus in the Library, Folders, and Playlists views."), this); QFont f(Utils::smallFont(label->font())); diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index b5635e383b..1bf06ee12e 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -216,7 +216,7 @@ MainWindow::MainWindow(QWidget *parent) topToolBar->setContentsMargins(0, 0, 0, 0); QLayout *l=topToolBar->layout(); if (l) { - l->setMargin(0); + l->setContentsMargins(0, 0, 0, 0); l->setSpacing(0); } topToolBar->ensurePolished(); @@ -234,7 +234,7 @@ MainWindow::MainWindow(QWidget *parent) topToolBar->setContentsMargins(0, 0, 0, 0); QLayout *l=topToolBar->layout(); if (l) { - l->setMargin(0); + l->setContentsMargins(0, 0, 0, 0); l->setSpacing(0); } topToolBar->ensurePolished(); diff --git a/gui/shortcutssettingspage.cpp b/gui/shortcutssettingspage.cpp index 419a95d127..eccf3b1af6 100644 --- a/gui/shortcutssettingspage.cpp +++ b/gui/shortcutssettingspage.cpp @@ -42,7 +42,7 @@ ShortcutsSettingsPage::ShortcutsSettingsPage(QWidget *p) : QWidget(p) { QBoxLayout *lay=new QBoxLayout(QBoxLayout::TopToBottom, this); - lay->setMargin(0); + lay->setContentsMargins(0, 0, 0, 0); QHash map; map.insert("Cantata", ActionCollection::get()); diff --git a/online/jamendosettingsdialog.cpp b/online/jamendosettingsdialog.cpp index 3f3ffc2449..fa2c70ada5 100644 --- a/online/jamendosettingsdialog.cpp +++ b/online/jamendosettingsdialog.cpp @@ -37,7 +37,7 @@ JamendoSettingsDialog::JamendoSettingsDialog(QWidget *parent) fmt->insertItem(1, tr("Ogg")); layout->setWidget(0, QFormLayout::LabelRole, new BuddyLabel(tr("Streaming format:"), mw, fmt)); layout->setWidget(0, QFormLayout::FieldRole, fmt); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); setMainWidget(mw); } diff --git a/online/magnatunesettingsdialog.cpp b/online/magnatunesettingsdialog.cpp index f1d41b95bc..a0b45c54a7 100644 --- a/online/magnatunesettingsdialog.cpp +++ b/online/magnatunesettingsdialog.cpp @@ -57,7 +57,7 @@ MagnatuneSettingsDialog::MagnatuneSettingsDialog(QWidget *parent) BuddyLabel *dlLabel=new BuddyLabel(tr("Downloads:"), mw, dl); layout->setWidget(3, QFormLayout::LabelRole, dlLabel); layout->setWidget(3, QFormLayout::FieldRole, dl); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); dlLabel->setVisible(false); // TODO: Magnatune downloads! dl->setVisible(false); // TODO: Magnatune downloads! diff --git a/online/podcastsearchdialog.cpp b/online/podcastsearchdialog.cpp index cd65219f4a..e27167943d 100644 --- a/online/podcastsearchdialog.cpp +++ b/online/podcastsearchdialog.cpp @@ -353,9 +353,9 @@ PodcastSearchPage::PodcastSearchPage(QWidget *p, const QString &n, int i, const QBoxLayout *searchLayout=new QBoxLayout(QBoxLayout::LeftToRight); QBoxLayout *viewLayout=new QBoxLayout(QBoxLayout::LeftToRight); QBoxLayout *mainLayout=new QBoxLayout(QBoxLayout::TopToBottom, this); - searchLayout->setMargin(0); - viewLayout->setMargin(0); - mainLayout->setMargin(0); + searchLayout->setContentsMargins(0, 0, 0, 0); + viewLayout->setContentsMargins(0, 0, 0, 0); + mainLayout->setContentsMargins(0, 0, 0, 0); search=new LineEdit(p); search->setPlaceholderText(tr("Enter search term...")); searchButton=new QPushButton(tr("Search"), p); @@ -418,7 +418,7 @@ OpmlBrowsePage::OpmlBrowsePage(QWidget *p, const QString &n, const QIcon &i, con , url(u) { QBoxLayout *mainLayout=new QBoxLayout(QBoxLayout::LeftToRight, this); - mainLayout->setMargin(0); + mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->addWidget(tree, 1); mainLayout->addWidget(text, 0); Action *act=new Action(tr("Reload"), this); @@ -503,9 +503,9 @@ PodcastUrlPage::PodcastUrlPage(QWidget *p) QBoxLayout *searchLayout=new QBoxLayout(QBoxLayout::LeftToRight); QBoxLayout *viewLayout=new QBoxLayout(QBoxLayout::LeftToRight); QBoxLayout *mainLayout=new QBoxLayout(QBoxLayout::TopToBottom, this); - searchLayout->setMargin(0); - viewLayout->setMargin(0); - mainLayout->setMargin(0); + searchLayout->setContentsMargins(0, 0, 0, 0); + viewLayout->setContentsMargins(0, 0, 0, 0); + mainLayout->setContentsMargins(0, 0, 0, 0); urlEntry=new LineEdit(p); urlEntry->setPlaceholderText(tr("Enter podcast URL...")); QPushButton *loadButton=new QPushButton(tr("Load"), p); @@ -626,7 +626,7 @@ PodcastSearchDialog::PodcastSearchDialog(PodcastService *s, QWidget *parent) spacer = new QWidget(this); spacer->setFixedSize(Utils::layoutSpacing(this), 0); QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, mainWidget); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); pageWidget = new PageWidget(mainWidget); diff --git a/online/podcastsettingsdialog.cpp b/online/podcastsettingsdialog.cpp index 9a5f5f2f61..c730468308 100644 --- a/online/podcastsettingsdialog.cpp +++ b/online/podcastsettingsdialog.cpp @@ -68,7 +68,7 @@ PodcastSettingsDialog::PodcastSettingsDialog(QWidget *p) autoDownloadLabel->setBuddy(autoDownloadCombo); int row=0; - lay->setMargin(0); + lay->setContentsMargins(0, 0, 0, 0); lay->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); lay->setWidget(row, QFormLayout::LabelRole, updateLabel); lay->setWidget(row++, QFormLayout::FieldRole, updateCombo); diff --git a/replaygain/rgdialog.cpp b/replaygain/rgdialog.cpp index fdbb08c98b..2e03ebb6d5 100644 --- a/replaygain/rgdialog.cpp +++ b/replaygain/rgdialog.cpp @@ -119,7 +119,7 @@ RgDialog::RgDialog(QWidget *parent) setResizeMode(hv, COL_TRACKPEAK, QHeaderView::Fixed); hv->setStretchLastSection(false); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(combo); layout->addWidget(view); layout->addWidget(statusLabel); diff --git a/streams/streamdialog.cpp b/streams/streamdialog.cpp index 8718a778f9..a5c57862f4 100644 --- a/streams/streamdialog.cpp +++ b/streams/streamdialog.cpp @@ -42,7 +42,7 @@ StreamDialog::StreamDialog(QWidget *parent, bool addToPlayQueue) QWidget *wid = new QWidget(this); QFormLayout *layout = new QFormLayout(wid); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); urlEntry = new LineEdit(wid); nameEntry = new LineEdit(wid); if (addToPlayQueue) { diff --git a/support/dialog.cpp b/support/dialog.cpp index ada35dba0d..664d0f0fae 100644 --- a/support/dialog.cpp +++ b/support/dialog.cpp @@ -411,8 +411,8 @@ void Dialog::showEvent(QShowEvent *e) mwSize=mw->minimumSizeHint(); } if (mwSize.width()>15 && mwSize.height()>15) { - setMinimumHeight(qMax(minimumHeight(), buttonBox->height()+layout()->spacing()+mwSize.height()+(2*layout()->margin()))); - setMinimumWidth(qMax(minimumWidth(), mwSize.width()+(2*layout()->margin()))); + setMinimumHeight(qMax(minimumHeight(), buttonBox->height()+layout()->spacing()+mwSize.height()+(2*layout()->contentsMargins().top()))); + setMinimumWidth(qMax(minimumWidth(), mwSize.width()+(2*layout()->contentsMargins().left()))); } } } diff --git a/support/fancytabwidget.cpp b/support/fancytabwidget.cpp index 954855266a..935e431214 100644 --- a/support/fancytabwidget.cpp +++ b/support/fancytabwidget.cpp @@ -493,18 +493,18 @@ FancyTabWidget::FancyTabWidget(QWidget *parent) , proxyStyle(new FancyTabProxyStyle) { sideLayout->setSpacing(0); - sideLayout->setMargin(0); + sideLayout->setContentsMargins(0, 0, 0, 0); sideLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding)); sideWidget->setLayout(sideLayout); sideWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - topLayout->setMargin(0); + topLayout->setContentsMargins(0, 0, 0, 0); topLayout->setSpacing(0); topLayout->addWidget(stack_); QHBoxLayout *mainLayout = new QHBoxLayout; - mainLayout->setMargin(0); + mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setSpacing(0); mainLayout->addWidget(sideWidget); mainLayout->addLayout(topLayout); diff --git a/support/inputdialog.cpp b/support/inputdialog.cpp index 4cb873bdf9..1ab796fbf9 100644 --- a/support/inputdialog.cpp +++ b/support/inputdialog.cpp @@ -110,7 +110,7 @@ void InputDialog::init(int type, const QString &caption, const QString &labelTex break; } layout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); setCaption(caption); setMainWidget(wid); setButtons(Ok|Cancel); diff --git a/support/keysequencewidget.cpp b/support/keysequencewidget.cpp index e8beba95e5..e0d4587ad4 100644 --- a/support/keysequencewidget.cpp +++ b/support/keysequencewidget.cpp @@ -169,7 +169,7 @@ KeySequenceWidget::KeySequenceWidget(QWidget *parent) _modifierKeys(0) { QHBoxLayout *layout = new QHBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); _keyButton = new KeySequenceButton(this, this); _keyButton->setFocusPolicy(Qt::StrongFocus); diff --git a/support/kmessagewidget.cpp b/support/kmessagewidget.cpp index 02414bfcd3..dedd17aac2 100644 --- a/support/kmessagewidget.cpp +++ b/support/kmessagewidget.cpp @@ -95,7 +95,7 @@ void KMsgWidgetPrivate::createLayout() if (wordWrap) { QGridLayout* layout = new QGridLayout(content); layout->addWidget(textLabel, 0, 1); - layout->setMargin(4); + layout->setContentsMargins(4, 4, 4, 4); QHBoxLayout* buttonLayout = new QHBoxLayout; buttonLayout->addStretch(); @@ -117,7 +117,7 @@ void KMsgWidgetPrivate::createLayout() } layout->addWidget(closeButton); - layout->setMargin(4); + layout->setContentsMargins(4, 4, 4, 4); }; if (q->isVisible()) { diff --git a/support/messagebox.cpp b/support/messagebox.cpp index 00bf52e1f7..0e637c6abc 100644 --- a/support/messagebox.cpp +++ b/support/messagebox.cpp @@ -171,7 +171,7 @@ MessageBox::ButtonCode MessageBox::msgListEx(QWidget *parent, Type type, const Q lay->addWidget(msgLabel, 0, 1, 1, 1); QListWidget *list=new QListWidget(wid); lay->addWidget(list, 1, 0, 1, 2); - lay->setMargin(0); + lay->setContentsMargins(0, 0, 0, 0); list->insertItems(0, strlist); dlg->setMainWidget(wid); #ifdef Q_OS_MAC diff --git a/support/pagewidget.cpp b/support/pagewidget.cpp index 31e8d54d73..6d922e222f 100644 --- a/support/pagewidget.cpp +++ b/support/pagewidget.cpp @@ -299,7 +299,7 @@ PageWidgetItem::PageWidgetItem(QWidget *p, const QString &header, const QIcon &i layout->addItem(new QSpacerItem(8, 8, QSizePolicy::Fixed, QSizePolicy::Fixed)); } layout->addWidget(cfg); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); cfg->setParent(this); adjustSize(); } @@ -315,7 +315,7 @@ PageWidget::PageWidget(QWidget *p, bool listView, bool headers) connect(stack, SIGNAL(currentChanged(int)), this, SIGNAL(currentPageChanged())); layout->addWidget(list); layout->addWidget(stack); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); list->setViewMode(QListView::ListMode); list->setVerticalScrollMode(QListView::ScrollPerPixel); list->setMovement(QListView::Static); diff --git a/widgets/coverwidget.cpp b/widgets/coverwidget.cpp index f12931b239..eedcd97940 100644 --- a/widgets/coverwidget.cpp +++ b/widgets/coverwidget.cpp @@ -171,7 +171,7 @@ CoverWidget::CoverWidget(QWidget *parent) : QWidget(parent) { QBoxLayout *l=new QBoxLayout(QBoxLayout::LeftToRight, this); - l->setMargin(0); + l->setContentsMargins(0, 0, 0, 0); l->setSpacing(0); l->addItem(new QSpacerItem(qMax(Utils::scaleForDpi(8), Utils::layoutSpacing(this)), 4, QSizePolicy::Fixed, QSizePolicy::Fixed)); label=new CoverLabel(this); diff --git a/widgets/multipagewidget.cpp b/widgets/multipagewidget.cpp index 94e5b293a9..fe16392a8d 100644 --- a/widgets/multipagewidget.cpp +++ b/widgets/multipagewidget.cpp @@ -79,8 +79,14 @@ class SelectorButton : public ToolButton setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); mainText->setText(t); subText->setText(s); - layout->setMargin(qMin(layout->margin(), 8)); - setMinimumHeight(qMax(textSize, size)+(layout->margin()*2)); + int left; + int top; + int right; + int bottom; + layout->getContentsMargins(&left, &top, &right, &bottom); + layout->setContentsMargins(qMin(8, left), qMin(8, top), qMin(8, right), qMin(8, bottom)); + + setMinimumHeight(qMax(textSize, size)+(layout->contentsMargins().top()*2)); updateToolTip(); setFocusPolicy(Qt::TabFocus); } @@ -142,14 +148,19 @@ MultiPageWidget::MultiPageWidget(QWidget *p) scroll->setProperty(ProxyStyle::constModifyFrameProp, ProxyStyle::VF_Side|ProxyStyle::VF_Top); mainPage->setLayout(mainLayout); mainLayout->addWidget(scroll); - mainLayout->setMargin(0); + mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setSpacing(0); mainLayout->addWidget(infoLabel); infoLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); mainLayout->addWidget(sizer); layout->setSpacing(0); layout->setSizeConstraint(QLayout::SetMinimumSize); - layout->setMargin(qMin(layout->margin(), 4)); + int left; + int top; + int right; + int bottom; + layout->getContentsMargins(&left, &top, &right, &bottom); + layout->setContentsMargins(qMin(4, left), qMin(4, top), qMin(4, right), qMin(4, bottom)); #ifdef Q_OS_MAC // TODO: This feels a bt of a hack... mainPage->setContentsMargins(-3, 0, -3, 0); diff --git a/widgets/notelabel.cpp b/widgets/notelabel.cpp index 86eba54704..bdc0385b07 100644 --- a/widgets/notelabel.cpp +++ b/widgets/notelabel.cpp @@ -47,7 +47,7 @@ static QLabel * init(QWidget *p, bool url) } QVBoxLayout *l=new QVBoxLayout(p); - l->setMargin(0); + l->setContentsMargins(0, 0, 0, 0); l->setSpacing(0); QLabel *label; if (url) { diff --git a/widgets/nowplayingwidget.cpp b/widgets/nowplayingwidget.cpp index c59db7f3bb..fff4888acc 100644 --- a/widgets/nowplayingwidget.cpp +++ b/widgets/nowplayingwidget.cpp @@ -294,8 +294,8 @@ NowPlayingWidget::NowPlayingWidget(QWidget *p) layout->setContentsMargins(pad, space, pad, space); #endif layout->setSpacing(space/2); - topLayout->setMargin(0); - botLayout->setMargin(0); + topLayout->setContentsMargins(0, 0, 0, 0); + botLayout->setContentsMargins(0, 0, 0, 0); topLayout->setSpacing(space/2); botLayout->setSpacing(space/2); topLayout->addWidget(track); diff --git a/widgets/singlepagewidget.cpp b/widgets/singlepagewidget.cpp index 7cab2febea..41ecfe1884 100644 --- a/widgets/singlepagewidget.cpp +++ b/widgets/singlepagewidget.cpp @@ -59,7 +59,7 @@ SinglePageWidget::SinglePageWidget(QWidget *p) Application::fixSize(sizer); layout->addWidget(view, 1, 0, 1, 5); layout->addWidget(sizer, 2, 2, 1, 1); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); connect(view, SIGNAL(searchItems()), this, SIGNAL(searchItems())); connect(view, SIGNAL(itemsSelected(bool)), this, SLOT(controlActions())); @@ -115,7 +115,7 @@ void SinglePageWidget::init(int flags, const QList &leftXtra, const Q if (!left.isEmpty()) { QHBoxLayout *ll=new QHBoxLayout(); - ll->setMargin(0); + ll->setContentsMargins(0, 0, 0, 0); ll->setSpacing(1); for (QWidget *b: left) { Application::fixSize(b); @@ -125,7 +125,7 @@ void SinglePageWidget::init(int flags, const QList &leftXtra, const Q } if (!right.isEmpty()) { QHBoxLayout *rl=new QHBoxLayout(); - rl->setMargin(0); + rl->setContentsMargins(0, 0, 0, 0); rl->setSpacing(1); for (QWidget *b: right) { Application::fixSize(b); diff --git a/widgets/sizegrip.cpp b/widgets/sizegrip.cpp index e85fe4cbbe..7e59d98f96 100644 --- a/widgets/sizegrip.cpp +++ b/widgets/sizegrip.cpp @@ -32,7 +32,7 @@ SizeGrip::SizeGrip(QWidget *parent) l->addItem(new QSpacerItem(0, 0, QSizePolicy::Maximum, QSizePolicy::Preferred)); QSizeGrip *grip=new QSizeGrip(this); l->addWidget(grip); - l->setMargin(0); + l->setContentsMargins(0, 0, 0, 0); l->setSpacing(0); l->setAlignment(Qt::AlignBottom|Qt::AlignRight); } diff --git a/widgets/titlewidget.cpp b/widgets/titlewidget.cpp index 8409d56d74..d048413c95 100644 --- a/widgets/titlewidget.cpp +++ b/widgets/titlewidget.cpp @@ -96,9 +96,9 @@ TitleWidget::TitleWidget(QWidget *p) connect(Covers::self(), SIGNAL(cover(Song,QImage,QString)), this, SLOT(coverRetrieved(Song,QImage,QString))); connect(Covers::self(), SIGNAL(coverUpdated(Song,QImage,QString)), this, SLOT(coverRetrieved(Song,QImage,QString))); connect(Covers::self(), SIGNAL(artistImage(Song,QImage,QString)), this, SLOT(coverRetrieved(Song,QImage,QString))); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(2); - textLayout->setMargin(0); + textLayout->setContentsMargins(0, 0, 0, 0); textLayout->setSpacing(2); mainText->setAlignment(Qt::AlignBottom); subText->setAlignment(Qt::AlignTop); @@ -124,7 +124,7 @@ void TitleWidget::update(const Song &sng, const QIcon &icon, const QString &text if (!controls) { controls=new QWidget(this); QVBoxLayout *l=new QVBoxLayout(controls); - l->setMargin(0); + l->setContentsMargins(0, 0, 0, 0); l->setSpacing(0); ToolButton *add=new ToolButton(this); ToolButton *replace=new ToolButton(this); diff --git a/widgets/volumecontrol.cpp b/widgets/volumecontrol.cpp index de76f2d1d9..9e9ec793b4 100644 --- a/widgets/volumecontrol.cpp +++ b/widgets/volumecontrol.cpp @@ -50,7 +50,7 @@ VolumeControl::VolumeControl(QWidget *p) label->addItem("HTTP", "http"); QVBoxLayout *layout = new QVBoxLayout(this); layout->setSpacing(0); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->addItem(new QSpacerItem(0, size, QSizePolicy::Fixed, QSizePolicy::Fixed)); layout->addWidget(stack); layout->addWidget(label); From 1c01e2283e605f86bf7eeabfaabc603d83d5a786 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 20:47:08 +0100 Subject: [PATCH 09/21] [Port to Qt6] QApplication::fontMetrics() -> QFontMetricsF(QApplication::font()) --- online/onlinesettings.cpp | 2 +- support/icon.cpp | 4 ++-- support/pagewidget.cpp | 4 ++-- widgets/actionitemdelegate.cpp | 2 +- widgets/groupedview.cpp | 4 ++-- widgets/itemview.cpp | 10 +++++----- widgets/ratingwidget.cpp | 2 +- widgets/treeview.cpp | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/online/onlinesettings.cpp b/online/onlinesettings.cpp index 8dbe49f1e6..472446e0e4 100644 --- a/online/onlinesettings.cpp +++ b/online/onlinesettings.cpp @@ -39,7 +39,7 @@ OnlineSettings::OnlineSettings(QWidget *p) setupUi(this); providers->setItemDelegate(new BasicItemDelegate(providers)); providers->setSortingEnabled(true); - int iSize=Icon::stdSize(QApplication::fontMetrics().height()*1.25); + int iSize=Icon::stdSize(QFontMetricsF(QApplication::font()).height()*1.25); providers->setIconSize(QSize(iSize, iSize)); connect(providers, SIGNAL(currentRowChanged(int)), SLOT(currentProviderChanged(int))); connect(configureButton, SIGNAL(clicked()), this, SLOT(configure())); diff --git a/support/icon.cpp b/support/icon.cpp index 04f9e05ddb..a318fca325 100644 --- a/support/icon.cpp +++ b/support/icon.cpp @@ -62,7 +62,7 @@ int Icon::dlgIconSize() box->ensurePolished(); QPixmap pix=box->iconPixmap(); if (pix.isNull() || pix.width()<16) { - size=stdSize(QApplication::fontMetrics().height()*3.5); + size=stdSize(QFontMetricsF(QApplication::font()).height()*3.5); } else { size=pix.width(); } @@ -76,7 +76,7 @@ void Icon::init(QToolButton *btn, bool setFlat) static int size=-1; if (-1==size) { - size=QApplication::fontMetrics().height(); + size=QFontMetricsF(QApplication::font()).height(); if (size>22) { size=stdSize(size*1.1); } else { diff --git a/support/pagewidget.cpp b/support/pagewidget.cpp index 6d922e222f..cfc4575a19 100644 --- a/support/pagewidget.cpp +++ b/support/pagewidget.cpp @@ -65,7 +65,7 @@ class PageWidgetItemDelegate : public QStyledItemDelegate , underMouse(false) { if (!standard) { - int height=QApplication::fontMetrics().height(); + int height=QFontMetricsF(QApplication::font()).height(); iconSize=height>22 ? Icon::stdSize(height*2.5) : 32; } } @@ -284,7 +284,7 @@ PageWidgetItem::PageWidgetItem(QWidget *p, const QString &header, const QIcon &i static int iconSize=-1; if (-1==iconSize) { - iconSize=QApplication::fontMetrics().height(); + iconSize=QFontMetricsF(QApplication::font()).height(); if (iconSize>20) { iconSize=Icon::stdSize(iconSize*1.25); } else { diff --git a/widgets/actionitemdelegate.cpp b/widgets/actionitemdelegate.cpp index 192a055216..c4c9afbc80 100644 --- a/widgets/actionitemdelegate.cpp +++ b/widgets/actionitemdelegate.cpp @@ -43,7 +43,7 @@ int ActionItemDelegate::constLargeActionIconSize = 22; void ActionItemDelegate::setup() { - int height=QApplication::fontMetrics().height(); + int height=QFontMetricsF(QApplication::font()).height(); if (height>17) { constActionIconSize=Icon::stdSize(((int)(height/4))*4); diff --git a/widgets/groupedview.cpp b/widgets/groupedview.cpp index 7526672458..75ffa3183f 100644 --- a/widgets/groupedview.cpp +++ b/widgets/groupedview.cpp @@ -52,7 +52,7 @@ static double sizeAdjust=1.25; void GroupedView::setup() { - int height=QApplication::fontMetrics().height(); + int height=QFontMetricsF(QApplication::font()).height(); sizeAdjust=1.25; if (height>17) { @@ -199,7 +199,7 @@ GroupedViewDelegate::~GroupedViewDelegate() QSize GroupedViewDelegate::sizeHint(int type, bool isCollection) const { - int textHeight = QApplication::fontMetrics().height()*sizeAdjust; + int textHeight = QFontMetricsF(QApplication::font()).height()*sizeAdjust; if (isCollection || AlbumHeader==type) { return QSize(64, qMax(constCoverSize, (qMax(constIconSize, textHeight)*2)+constBorder)+(2*constBorder)); diff --git a/widgets/itemview.cpp b/widgets/itemview.cpp index b99bc217d2..7f01f5b49f 100644 --- a/widgets/itemview.cpp +++ b/widgets/itemview.cpp @@ -75,7 +75,7 @@ static inline int adjust(int v) void ItemView::setup() { - int height=QApplication::fontMetrics().height(); + int height=QFontMetricsF(QApplication::font()).height(); if (height>22) { detailedViewDecorationSize=Icon::stdSize(height*1.4); @@ -228,17 +228,17 @@ class ListDelegate : public ActionItemDelegate double textSpace = !isCategorizedView || view->model()->data(QModelIndex(), Cantata::Role_CatergizedHasSubText).toBool() ? 2.5 : 1.75; #ifdef RESPONSIVE_LAYOUT if (!isCategorizedView) { - return QSize(calcItemWidth(), zoomedSize(view, gridCoverSize)+(QApplication::fontMetrics().height()*textSpace)); + return QSize(calcItemWidth(), zoomedSize(view, gridCoverSize)+(QFontMetricsF(QApplication::font()).height()*textSpace)); } #endif - return QSize(zoomedSize(view, gridCoverSize)+8, zoomedSize(view, gridCoverSize)+(QApplication::fontMetrics().height()*textSpace)); + return QSize(zoomedSize(view, gridCoverSize)+8, zoomedSize(view, gridCoverSize)+(QFontMetricsF(QApplication::font()).height()*textSpace)); } else { int imageSize = index.data(Cantata::Role_ListImage).toBool() ? listCoverSize : 0; // TODO: Any point to checking one-line here? All models return sub-text... // Things will be quicker if we dont call SubText here... bool oneLine = false ; // index.data(Cantata::Role_SubText).toString().isEmpty(); bool showCapacity = !index.data(Cantata::Role_CapacityText).toString().isEmpty(); - int textHeight = QApplication::fontMetrics().height()*(oneLine ? 1 : 2); + int textHeight = QFontMetricsF(QApplication::font()).height()*(oneLine ? 1 : 2); if (showCapacity) { imageSize=constDevImageSize; @@ -515,7 +515,7 @@ class TreeDelegate : public ListDelegate if (index.data(Cantata::Role_ListImage).toBool()) { sz.setHeight(qMax(sz.height(), listCoverSize)); } - int textHeight = QApplication::fontMetrics().height()*1.25; + int textHeight = QFontMetricsF(QApplication::font()).height()*1.25; sz.setHeight(qMax(sz.height(), textHeight)+(constBorder*2)); return sz; } diff --git a/widgets/ratingwidget.cpp b/widgets/ratingwidget.cpp index e072403850..ec55b12f36 100644 --- a/widgets/ratingwidget.cpp +++ b/widgets/ratingwidget.cpp @@ -111,7 +111,7 @@ void RatingPainter::setColor(const QColor &c) RatingWidget::RatingWidget(QWidget *parent) : QWidget(parent) - , rp(Icon::stdSize(QApplication::fontMetrics().height()*0.9)) + , rp(Icon::stdSize(QFontMetricsF(QApplication::font()).height()*0.9)) , val(0) , hoverVal(-1) , showZeroForNull(false) diff --git a/widgets/treeview.cpp b/widgets/treeview.cpp index 572a218ed0..8a160d4858 100644 --- a/widgets/treeview.cpp +++ b/widgets/treeview.cpp @@ -61,7 +61,7 @@ QPixmap TreeView::createBgndPixmap(const QIcon &icon) } static int bgndSize=0; if (0==bgndSize) { - bgndSize=QApplication::fontMetrics().height()*16; + bgndSize=QFontMetricsF(QApplication::font()).height()*16; } QImage img=icon.pixmap(bgndSize, bgndSize).toImage(); From ca77dfa46c56777888667799a8351ae4bbec082c Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 20:56:10 +0100 Subject: [PATCH 10/21] [Port to Qt6] QMatrix -> QTransform --- widgets/actionlabel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/widgets/actionlabel.cpp b/widgets/actionlabel.cpp index b56e799382..da7babc156 100644 --- a/widgets/actionlabel.cpp +++ b/widgets/actionlabel.cpp @@ -26,10 +26,10 @@ #include #include #include -#include +#include // Borrowed from kolourpaint... -static QTransform transformWithZeroOrigin(const QMatrix &matrix, int width, int height) +static QTransform transformWithZeroOrigin(const QTransform &matrix, int width, int height) { QRect newRect(matrix.mapRect(QRect(0, 0, width, height))); @@ -39,7 +39,7 @@ static QTransform transformWithZeroOrigin(const QMatrix &matrix, int width, int static QTransform rotateMatrix(int width, int height, double angle) { - QMatrix matrix; + QTransform matrix; matrix.translate(width/2, height/2); matrix.rotate(angle); From 2cd4bd054420f4edadfdc4037dca680f535da97f Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 20:56:50 +0100 Subject: [PATCH 11/21] [Port to Qt6] QKeySequence are now added with | instead of + --- gui/mainwindow.cpp | 43 +++++++++++++++++++++------------------ gui/stdactions.cpp | 12 +++++------ models/playqueuemodel.cpp | 4 ++-- widgets/genrecombo.cpp | 2 +- widgets/itemview.cpp | 2 +- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 1bf06ee12e..3a84cab435 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -118,8 +118,11 @@ #ifdef Q_OS_WIN #include "windows/thumbnailtoolbar.h" #endif +#include +#include #include #include +#include #include #include #include @@ -128,9 +131,9 @@ #include #include -static int nextKey(int &key) +static Qt::Key nextKey(int &key) { - int k=key; + Qt::Key k = static_cast(key); if (Qt::Key_0==key) { key=Qt::Key_A; } else if (Qt::Key_Colon==++key) { @@ -299,8 +302,8 @@ MainWindow::MainWindow(QWidget *parent) addAction(fwdAction); addAction(revAction); if (isetShortcut((Qt::RightToLeft==layoutDirection() ? Qt::Key_Left : Qt::Key_Right)+seekShortcuts.at(i)); - revAction->setShortcut((Qt::RightToLeft==layoutDirection() ? Qt::Key_Right : Qt::Key_Left)+seekShortcuts.at(i)); + fwdAction->setShortcut((Qt::RightToLeft==layoutDirection() ? Qt::Key_Left : Qt::Key_Right)|seekShortcuts.at(i)); + revAction->setShortcut((Qt::RightToLeft==layoutDirection() ? Qt::Key_Right : Qt::Key_Left)|seekShortcuts.at(i)); } } @@ -314,7 +317,7 @@ MainWindow::MainWindow(QWidget *parent) addLocalFilesToPlayQueueAction = ActionCollection::get()->createAction("addlocalfiles", tr("Add Local Files")); QIcon clearIcon = MonoIcon::icon(FontAwesome::times, MonoIcon::constRed, MonoIcon::constRed); clearPlayQueueAction = ActionCollection::get()->createAction("clearplaylist", tr("Clear"), clearIcon); - clearPlayQueueAction->setShortcut(Qt::ControlModifier+Qt::Key_K); + clearPlayQueueAction->setShortcut(Qt::ControlModifier|Qt::Key_K); centerPlayQueueAction = ActionCollection::get()->createAction("centerplaylist", tr("Center On Current Track"), Icons::self()->centrePlayQueueOnTrackIcon); expandInterfaceAction = ActionCollection::get()->createAction("expandinterface", tr("Expanded Interface"), MonoIcon::icon(FontAwesome::expand, iconCol)); expandInterfaceAction->setCheckable(true); @@ -331,7 +334,7 @@ MainWindow::MainWindow(QWidget *parent) consumePlayQueueAction = ActionCollection::get()->createAction("consumeplaylist", tr("Consume"), Icons::self()->consumeIcon, tr("When consume is activated, a song is removed from the play queue after it has been played.")); searchPlayQueueAction = ActionCollection::get()->createAction("searchplaylist", tr("Find in Play Queue"), Icons::self()->searchIcon); addAction(searchPlayQueueAction); - searchPlayQueueAction->setShortcut(Qt::ControlModifier+Qt::ShiftModifier+Qt::Key_F); + searchPlayQueueAction->setShortcut(Qt::ControlModifier|Qt::ShiftModifier|Qt::Key_F); #ifdef ENABLE_HTTP_STREAM_PLAYBACK streamPlayAction = ActionCollection::get()->createAction("streamplay", tr("Play HTTP Output Stream"), Icons::self()->httpStreamIcon); streamPlayAction->setCheckable(true); @@ -362,11 +365,11 @@ MainWindow::MainWindow(QWidget *parent) editPlayQueueTagsAction->setSettingsText(tr("Edit Track Information (Play Queue)")); #endif addAction(expandAllAction = ActionCollection::get()->createAction("expandall", tr("Expand All"))); - expandAllAction->setShortcut(Qt::ControlModifier+Qt::Key_Down); + expandAllAction->setShortcut(Qt::ControlModifier | Qt::Key_Down); addAction(collapseAllAction = ActionCollection::get()->createAction("collapseall", tr("Collapse All"))); - collapseAllAction->setShortcut(Qt::ControlModifier+Qt::Key_Up); + collapseAllAction->setShortcut(Qt::ControlModifier | Qt::Key_Up); cancelAction = ActionCollection::get()->createAction("cancel", tr("Cancel"), Icons::self()->cancelIcon); - cancelAction->setShortcut(Qt::AltModifier+Qt::Key_Escape); + cancelAction->setShortcut(Qt::AltModifier | Qt::Key_Escape); connect(cancelAction, SIGNAL(triggered()), messageWidget, SLOT(animatedHide())); StdActions::self()->playPauseTrackAction->setEnabled(false); @@ -422,23 +425,23 @@ MainWindow::MainWindow(QWidget *parent) #define TAB_ACTION(A) A->icon(), A->text(), A->text() int sidebarPageShortcutKey=Qt::Key_1; addAction(showPlayQueueAction = ActionCollection::get()->createAction("showplayqueue", tr("Play Queue"), Icons::self()->playqueueIcon)); - showPlayQueueAction->setShortcut(Qt::ControlModifier+Qt::ShiftModifier+Qt::Key_Q); + showPlayQueueAction->setShortcut(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Q); tabWidget->addTab(playQueuePage, TAB_ACTION(showPlayQueueAction), playQueueInSidebar); connect(showPlayQueueAction, SIGNAL(triggered()), this, SLOT(showPlayQueue())); libraryPage = new LibraryPage(this); addAction(libraryTabAction = ActionCollection::get()->createAction("showlibrarytab", tr("Library"), Icons::self()->libraryIcon)); - libraryTabAction->setShortcut(Qt::ControlModifier+Qt::ShiftModifier+nextKey(sidebarPageShortcutKey)); + libraryTabAction->setShortcut(Qt::ControlModifier | Qt::ShiftModifier | nextKey(sidebarPageShortcutKey)); tabWidget->addTab(libraryPage, TAB_ACTION(libraryTabAction), !hiddenPages.contains(libraryPage->metaObject()->className())); connect(libraryTabAction, SIGNAL(triggered()), this, SLOT(showLibraryTab())); folderPage = new FolderPage(this); addAction(foldersTabAction = ActionCollection::get()->createAction("showfolderstab", tr("Folders"), Icons::self()->foldersIcon)); - foldersTabAction->setShortcut(Qt::ControlModifier+Qt::ShiftModifier+nextKey(sidebarPageShortcutKey)); + foldersTabAction->setShortcut(Qt::ControlModifier | Qt::ShiftModifier | nextKey(sidebarPageShortcutKey)); tabWidget->addTab(folderPage, TAB_ACTION(foldersTabAction), !hiddenPages.contains(folderPage->metaObject()->className())); connect(foldersTabAction, SIGNAL(triggered()), this, SLOT(showFoldersTab())); folderPage->setEnabled(!hiddenPages.contains(folderPage->metaObject()->className())); playlistsPage = new PlaylistsPage(this); addAction(playlistsTabAction = ActionCollection::get()->createAction("showplayliststab", tr("Playlists"), Icons::self()->playlistsIcon)); - playlistsTabAction->setShortcut(Qt::ControlModifier+Qt::ShiftModifier+nextKey(sidebarPageShortcutKey)); + playlistsTabAction->setShortcut(Qt::ControlModifier | Qt::ShiftModifier | nextKey(sidebarPageShortcutKey)); tabWidget->addTab(playlistsPage, TAB_ACTION(playlistsTabAction), !hiddenPages.contains(playlistsPage->metaObject()->className())); connect(playlistsTabAction, SIGNAL(triggered()), this, SLOT(showPlaylistsTab())); connect(playlistsPage, SIGNAL(error(const QString &)), SLOT(showError(const QString &))); @@ -448,7 +451,7 @@ MainWindow::MainWindow(QWidget *parent) stopDynamicButton->setDefaultAction(DynamicPlaylists::self()->stopAct()); onlinePage = new OnlineServicesPage(this); addAction(onlineTabAction = ActionCollection::get()->createAction("showonlinetab", tr("Internet"), Icons::self()->onlineIcon)); - onlineTabAction->setShortcut(Qt::ControlModifier+Qt::ShiftModifier+nextKey(sidebarPageShortcutKey)); + onlineTabAction->setShortcut(Qt::ControlModifier | Qt::ShiftModifier | nextKey(sidebarPageShortcutKey)); tabWidget->addTab(onlinePage, TAB_ACTION(onlineTabAction), !hiddenPages.contains(onlinePage->metaObject()->className())); onlinePage->setEnabled(!hiddenPages.contains(onlinePage->metaObject()->className())); connect(onlineTabAction, SIGNAL(triggered()), this, SLOT(showOnlineTab())); @@ -457,14 +460,14 @@ MainWindow::MainWindow(QWidget *parent) #ifdef ENABLE_DEVICES_SUPPORT devicesPage = new DevicesPage(this); addAction(devicesTabAction = ActionCollection::get()->createAction("showdevicestab", tr("Devices"), Icons::self()->devicesIcon)); - devicesTabAction->setShortcut(Qt::ControlModifier+Qt::ShiftModifier+nextKey(sidebarPageShortcutKey)); + devicesTabAction->setShortcut(Qt::ControlModifier | Qt::ShiftModifier | nextKey(sidebarPageShortcutKey)); tabWidget->addTab(devicesPage, TAB_ACTION(devicesTabAction), !hiddenPages.contains(devicesPage->metaObject()->className())); DevicesModel::self()->setEnabled(!hiddenPages.contains(devicesPage->metaObject()->className())); connect(devicesTabAction, SIGNAL(triggered()), this, SLOT(showDevicesTab())); #endif searchPage = new SearchPage(this); addAction(searchTabAction = ActionCollection::get()->createAction("showsearchtab", tr("Search"), Icons::self()->searchTabIcon)); - searchTabAction->setShortcut(Qt::ControlModifier+Qt::ShiftModifier+nextKey(sidebarPageShortcutKey)); + searchTabAction->setShortcut(Qt::ControlModifier | Qt::ShiftModifier | nextKey(sidebarPageShortcutKey)); connect(searchTabAction, SIGNAL(triggered()), this, SLOT(showSearchTab())); connect(searchPage, SIGNAL(locate(QList)), this, SLOT(locateTracks(QList))); tabWidget->addTab(searchPage, TAB_ACTION(searchTabAction), !hiddenPages.contains(searchPage->metaObject()->className())); @@ -611,7 +614,7 @@ MainWindow::MainWindow(QWidget *parent) menuButton->setVisible(false); #else showMenubarAction = ActionCollection::get()->createAction("showmenubar", tr("Show Menubar")); - showMenubarAction->setShortcut(Qt::ControlModifier+Qt::Key_M); + showMenubarAction->setShortcut(Qt::ControlModifier | Qt::Key_M); showMenubarAction->setCheckable(true); connect(showMenubarAction, SIGNAL(toggled(bool)), this, SLOT(toggleMenubar())); #endif @@ -737,7 +740,7 @@ MainWindow::MainWindow(QWidget *parent) } Action *action=ActionCollection::get()->createAction(QLatin1String("rating")+QString::number(i), text); action->setProperty(constRatingKey, i*Song::Rating_Step); - action->setShortcut(Qt::AltModifier+Qt::Key_0+i); + action->setShortcut(Qt::AltModifier | static_cast(static_cast(Qt::Key_0)+i)); action->setSettingsText(ratingAction); ratingAction->menu()->addAction(action); connect(action, SIGNAL(triggered()), SLOT(setRating())); @@ -1456,7 +1459,7 @@ void MainWindow::outputsUpdated(const QList &outputs) act->setData(o.id); act->setCheckable(true); act->setChecked(o.enabled); - act->setShortcut(Qt::ControlModifier+Qt::AltModifier+nextKey(i)); + act->setShortcut(Qt::ControlModifier | Qt::AltModifier | nextKey(i)); } menu->addSeparator(); QMenu* moveMenu = menu->addMenu(tr("Move output to this partition")); @@ -1540,7 +1543,7 @@ void MainWindow::updateConnectionsMenu() act->setCheckable(true); act->setChecked(d.name==currentConn); act->setActionGroup(connectionsGroup); - act->setShortcut(Qt::ControlModifier+nextKey(i)); + act->setShortcut(Qt::ControlModifier | nextKey(i)); } } } diff --git a/gui/stdactions.cpp b/gui/stdactions.cpp index 9a6c93f0a7..8894334622 100644 --- a/gui/stdactions.cpp +++ b/gui/stdactions.cpp @@ -99,9 +99,9 @@ StdActions::StdActions() insertAfterCurrentAction = ActionCollection::get()->createAction("insertintoplayqueue", QObject::tr("Insert After Current")); addRandomAlbumToPlayQueueAction = ActionCollection::get()->createAction("addrandomalbumtoplayqueue", QObject::tr("Append Random Album")); replacePlayQueueAction = ActionCollection::get()->createAction("replaceplayqueue", QObject::tr("Play Now (And Replace Play Queue)"), Icons::self()->replacePlayQueueIcon); - savePlayQueueAction->setShortcut(Qt::ControlModifier+Qt::Key_S); - appendToPlayQueueAction->setShortcut(Qt::ControlModifier+Qt::Key_P); - replacePlayQueueAction->setShortcut(Qt::ControlModifier+Qt::Key_R); + savePlayQueueAction->setShortcut(Qt::ControlModifier | Qt::Key_S); + appendToPlayQueueAction->setShortcut(Qt::ControlModifier | Qt::Key_P); + replacePlayQueueAction->setShortcut(Qt::ControlModifier | Qt::Key_R); addWithPriorityAction = new Action(QObject::tr("Add With Priority"), nullptr); setPriorityAction = new Action(QObject::tr("Set Priority"), nullptr); @@ -124,7 +124,7 @@ StdActions::StdActions() setCoverAction = ActionCollection::get()->createAction("setimage", QObject::tr("Set Image")); removeAction = ActionCollection::get()->createAction("remove", QObject::tr("Remove"), Icons::self()->removeIcon); searchAction = ActionCollection::get()->createAction("search", QObject::tr("Find"), Icons::self()->searchIcon); - searchAction->setShortcut(Qt::ControlModifier+Qt::Key_F); + searchAction->setShortcut(Qt::ControlModifier | Qt::Key_F); addToStoredPlaylistAction->setMenu(PlaylistsModel::self()->menu()); @@ -140,9 +140,9 @@ StdActions::StdActions() addRandomAlbumToPlayQueueAction->setVisible(false); zoomInAction = ActionCollection::get()->createAction("zoomIn", QObject::tr("Zoom In")); - zoomInAction->setShortcut(Qt::ControlModifier+Qt::Key_Plus); + zoomInAction->setShortcut(Qt::ControlModifier | Qt::Key_Plus); zoomOutAction = ActionCollection::get()->createAction("zoomOut", QObject::tr("Zoom Out")); - zoomOutAction->setShortcut(Qt::ControlModifier+Qt::Key_Minus); + zoomOutAction->setShortcut(Qt::ControlModifier | Qt::Key_Minus); } void StdActions::enableAddToPlayQueue(bool en) diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index 364fb6e5dc..e386b8c060 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -439,9 +439,9 @@ PlayQueueModel::PlayQueueModel(QObject *parent) removeDuplicatesAction->setEnabled(false); QColor col=Utils::monoIconColor(); undoAction=ActionCollection::get()->createAction("playqueue-undo", tr("Undo"), MonoIcon::icon(FontAwesome::undo, col)); - undoAction->setShortcut(Qt::ControlModifier+Qt::Key_Z); + undoAction->setShortcut(Qt::ControlModifier|Qt::Key_Z); redoAction=ActionCollection::get()->createAction("playqueue-redo", tr("Redo"), MonoIcon::icon(FontAwesome::repeat, col)); - redoAction->setShortcut(Qt::ControlModifier+Qt::ShiftModifier+Qt::Key_Z); + redoAction->setShortcut(Qt::ControlModifier|Qt::ShiftModifier|Qt::Key_Z); connect(undoAction, SIGNAL(triggered()), this, SLOT(undo())); connect(redoAction, SIGNAL(triggered()), this, SLOT(redo())); connect(removeDuplicatesAction, SIGNAL(triggered()), this, SLOT(removeDuplicates())); diff --git a/widgets/genrecombo.cpp b/widgets/genrecombo.cpp index f0414a38d0..7e5049a70e 100644 --- a/widgets/genrecombo.cpp +++ b/widgets/genrecombo.cpp @@ -39,7 +39,7 @@ GenreCombo::GenreCombo(QWidget *p) setFocusPolicy(Qt::NoFocus); if (!action) { action=ActionCollection::get()->createAction("genrefilter", tr("Filter On Genre"), nullptr); - action->setShortcut(Qt::ControlModifier+Qt::Key_G); + action->setShortcut(Qt::ControlModifier|Qt::Key_G); } addAction(action); connect(action, SIGNAL(triggered()), SLOT(showEntries())); diff --git a/widgets/itemview.cpp b/widgets/itemview.cpp index 7f01f5b49f..9aa8a8b964 100644 --- a/widgets/itemview.cpp +++ b/widgets/itemview.cpp @@ -714,7 +714,7 @@ ItemView::ItemView(QWidget *p) setupUi(this); if (!backAction) { backAction=ActionCollection::get()->createAction("itemview-goback", tr("Go Back")); - backAction->setShortcut(Qt::AltModifier+(Qt::LeftToRight==layoutDirection() ? Qt::Key_Left : Qt::Key_Right)); + backAction->setShortcut(Qt::AltModifier|(Qt::LeftToRight==layoutDirection() ? Qt::Key_Left : Qt::Key_Right)); } title->addAction(backAction); title->setVisible(false); From 4c29c9672cc5ade4258631ea19389210a00ac6d4 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:01:52 +0100 Subject: [PATCH 12/21] [Port to Qt6] QDesktopWidget -> QScreen --- gui/coverdialog.cpp | 3 +-- gui/covers.cpp | 7 +++---- gui/customactions.cpp | 2 +- gui/preferencesdialog.cpp | 3 ++- support/combobox.cpp | 6 +++--- support/configdialog.cpp | 6 +++--- support/utils.cpp | 11 ++++++----- widgets/menubutton.cpp | 6 +++--- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/gui/coverdialog.cpp b/gui/coverdialog.cpp index 8d18a5da5b..cb70571d28 100644 --- a/gui/coverdialog.cpp +++ b/gui/coverdialog.cpp @@ -44,7 +44,6 @@ #include #include #include -#include #include #include #include @@ -259,7 +258,7 @@ void CoverPreview::showImage(const QImage &img, const QString &u) fw=2; } fw*=2; - QRect desktop = qApp->desktop()->screenGeometry(this); + QRect desktop = qApp->primaryScreen()->availableGeometry(); int maxWidth=desktop.width()*0.75; int maxHeight=desktop.height()*0.75; int lrPad=width()-mainWidget()->width(); diff --git a/gui/covers.cpp b/gui/covers.cpp index 6f30995746..25db5ec80c 100644 --- a/gui/covers.cpp +++ b/gui/covers.cpp @@ -54,10 +54,10 @@ #include #include #include +#include #include #include #include -#include GLOBAL_STATIC(Covers, instance) @@ -1251,10 +1251,9 @@ Covers::Covers() // Use screen size to calculate max cost - Issue #1498 int maxCost = 0; - QDesktopWidget *dw=QApplication::desktop(); + QScreen *dw=QApplication::primaryScreen(); if (dw) { - QWidget w; - QSize sz = dw->availableGeometry(&w).size(); + QSize sz = dw->availableGeometry().size(); maxCost = sz.width() * sz.height() * 5; // *5 as 32-bit pixmap (so 4 bytes), + some wiggle rooom :-) } cache.setMaxCost(qMax(static_cast(15*1024*1024*devicePixelRatio), maxCost)); // Ensure at least 15M diff --git a/gui/customactions.cpp b/gui/customactions.cpp index 20f78916bb..d69e0374a1 100644 --- a/gui/customactions.cpp +++ b/gui/customactions.cpp @@ -107,7 +107,7 @@ void CustomActions::set(QList cmds) cfg.removeGroup(metaObject()->className()); if (!commands.isEmpty()) { cfg.beginGroup(metaObject()->className()); - cfg.set("count", commands.count()); + cfg.set("count", static_cast(commands.count())); for (int i=0; i +#include +#include #include static int iCount=0; diff --git a/support/combobox.cpp b/support/combobox.cpp index 3e89572ab4..238ea20464 100644 --- a/support/combobox.cpp +++ b/support/combobox.cpp @@ -25,7 +25,7 @@ #include "lineedit.h" #include "utils.h" #include -#include +#include #include #include @@ -38,8 +38,8 @@ ComboBox::ComboBox(QWidget *p) { #if !defined Q_OS_WIN && !defined Q_OS_MAC if (-1==maxPopupItemCount) { - if (QApplication::desktop()) { - maxPopupItemCount=((QApplication::desktop()->height()/(QApplication::fontMetrics().height()*1.5))*0.75)+0.5; + if (QApplication::primaryScreen()) { + maxPopupItemCount=((QApplication::primaryScreen()->availableGeometry().height()/(QFontMetricsF(QApplication::font()).height()*1.5))*0.75)+0.5; } else { maxPopupItemCount=32; } diff --git a/support/configdialog.cpp b/support/configdialog.cpp index a9019e6e65..ef2e3954ca 100644 --- a/support/configdialog.cpp +++ b/support/configdialog.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include "icon.h" #include "osxstyle.h" #include "windowmanager.h" @@ -415,9 +415,9 @@ void ConfigDialog::showEvent(QShowEvent *e) shown=true; ensurePolished(); - QDesktopWidget *dw=QApplication::desktop(); + QScreen *dw=QApplication::primaryScreen(); if (dw) { - move(QPoint((dw->availableGeometry(this).size().width()-width())/2, 86)); + move(QPoint((dw->availableGeometry().size().width()-width())/2, 86)); } } OSXStyle::self()->addWindow(this); diff --git a/support/utils.cpp b/support/utils.cpp index 023147961b..64a1791c49 100644 --- a/support/utils.cpp +++ b/support/utils.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -907,25 +907,26 @@ double Utils::screenDpiScale() { static double scaleFactor=-1.0; if (scaleFactor<0) { - QWidget *dw=QApplication::desktop(); + QScreen *dw=QApplication::primaryScreen(); if (!dw) { return 1.0; } - scaleFactor=dw->logicalDpiX()>120 ? qMin(qMax(dw->logicalDpiX()/96.0, 1.0), 4.0) : 1.0; + scaleFactor=dw->logicalDotsPerInchX()>120 ? qMin(qMax(dw->logicalDotsPerInchX()/96.0, 1.0), 4.0) : 1.0; } return scaleFactor; } bool Utils::limitedHeight(QWidget *w) { + Q_UNUSED(w) static bool init=false; static bool limited=false; if (!init) { limited=!qgetenv("CANTATA_NETBOOK").isEmpty(); if (!limited) { - QDesktopWidget *dw=QApplication::desktop(); + QScreen *dw=QApplication::primaryScreen(); if (dw) { - limited=dw->availableGeometry(w).size().height()<=800; + limited=dw->availableGeometry().size().height()<=800; } } } diff --git a/widgets/menubutton.cpp b/widgets/menubutton.cpp index f3c3df28e0..f2c04d96e9 100644 --- a/widgets/menubutton.cpp +++ b/widgets/menubutton.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #ifdef Q_OS_WIN @@ -106,9 +106,9 @@ bool MenuButton::eventFilter(QObject *o, QEvent *e) if (newPos<0) { newPos=0; } else { - QDesktopWidget *dw=QApplication::desktop(); + QScreen *dw=QApplication::primaryScreen(); if (dw) { - QRect geo=dw->availableGeometry(this); + QRect geo=dw->availableGeometry(); int maxWidth=geo.x()+geo.width(); if (maxWidth>0 && (newPos+mnu->width())>maxWidth) { newPos=maxWidth-mnu->width(); From a510473cd4a1acecc1ff59fa576beae8638b1c7e Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:05:22 +0100 Subject: [PATCH 13/21] [Port to Qt6] DateTime::toTime_t() -> DateTime.toSecsSinceEpoch() --- dbus/gnomemediakeys.cpp | 2 +- gui/mainwindow.cpp | 2 +- mpd-interface/mpdconnection.cpp | 2 +- mpd-interface/mpdparseutils.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dbus/gnomemediakeys.cpp b/dbus/gnomemediakeys.cpp index c3798ec5f3..a3a0130957 100644 --- a/dbus/gnomemediakeys.cpp +++ b/dbus/gnomemediakeys.cpp @@ -104,7 +104,7 @@ void GnomeMediaKeys::grabKeys() mk = new OrgGnomeSettingsDaemonMediaKeysInterface(service, constMediaKeysPath, QDBusConnection::sessionBus(), this); } - QDBusPendingReply<> reply = mk->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentDateTime().toTime_t()); + QDBusPendingReply<> reply = mk->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentDateTime().toSecsSinceEpoch()); QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(reply, this); connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher *)), this, SLOT(registerFinished(QDBusPendingCallWatcher*))); diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 3a84cab435..f8b32d79eb 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1761,7 +1761,7 @@ void MainWindow::showServerInfo() std::sort(tags.begin(), tags.end()); long version=MPDConnection::self()->version(); QDateTime dbUpdate; - dbUpdate.setTime_t(MPDStats::self()->dbUpdate()); + dbUpdate.setSecsSinceEpoch(MPDStats::self()->dbUpdate()); MessageBox::information(this, #ifdef Q_OS_MAC tr("Server Information")+QLatin1String("

")+ diff --git a/mpd-interface/mpdconnection.cpp b/mpd-interface/mpdconnection.cpp index a8030a062d..74f994628d 100644 --- a/mpd-interface/mpdconnection.cpp +++ b/mpd-interface/mpdconnection.cpp @@ -2052,7 +2052,7 @@ void MPDConnection::search(const QString &field, const QString &value, int id) } else if (QRegularExpression("^((19|20)\\d\\d)[-/](0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])$").match(value).hasMatch()) { QDateTime dt=QDateTime::fromString(QString(value).replace("/", "-"), Qt::ISODate); if (dt.isValid()) { - v=dt.toTime_t(); + v=dt.toSecsSinceEpoch(); } } if (v>0) { diff --git a/mpd-interface/mpdparseutils.cpp b/mpd-interface/mpdparseutils.cpp index 6327274d71..7599c87111 100644 --- a/mpd-interface/mpdparseutils.cpp +++ b/mpd-interface/mpdparseutils.cpp @@ -350,7 +350,7 @@ Song MPDParseUtils::parseSong(const QList &lines, Location location) } else if (line.startsWith(constAlbumId)) { song.setMbAlbumId(line.mid(constAlbumId.length())); } else if ((Loc_Search==location || Loc_Library==location) && line.startsWith(constLastModifiedKey)) { - song.lastModified=QDateTime::fromString(QString::fromUtf8(line.mid(constLastModifiedKey.length())), Qt::ISODate).toTime_t(); + song.lastModified=QDateTime::fromString(QString::fromUtf8(line.mid(constLastModifiedKey.length())), Qt::ISODate).toSecsSinceEpoch(); } else if ((Loc_Search==location || Loc_Playlists==location || Loc_PlayQueue==location) && line.startsWith(constPerformerKey)) { if (song.hasPerformer()) { song.setPerformer(song.performer()+QLatin1String(", ")+QString::fromUtf8(line.mid(constPerformerKey.length()))); From a8b3f0b1f14523102bad680f831f46578d093612 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:07:39 +0100 Subject: [PATCH 14/21] [Port to Qt6] QStringRef -> QStringView and other string manipulations --- models/musiclibrarymodel.cpp | 2 +- models/streamsmodel.cpp | 2 +- online/jamendoservice.cpp | 6 +++--- online/magnatuneservice.cpp | 2 +- online/opmlparser.cpp | 2 +- online/rssparser.cpp | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/models/musiclibrarymodel.cpp b/models/musiclibrarymodel.cpp index 9c73e94e55..ca50af21d2 100644 --- a/models/musiclibrarymodel.cpp +++ b/models/musiclibrarymodel.cpp @@ -35,7 +35,7 @@ #include "gui/settings.h" #include #include -#include +#include #include #include #include diff --git a/models/streamsmodel.cpp b/models/streamsmodel.cpp index c51ffefa54..e705c5a220 100644 --- a/models/streamsmodel.cpp +++ b/models/streamsmodel.cpp @@ -1297,7 +1297,7 @@ QList StreamsModel::parseIceCastResponse(QIODevice *dev, C doc.readNext(); if (QXmlStreamReader::StartElement==doc.tokenType()) { - QStringRef elem = doc.name(); + QStringView elem = doc.name(); if (QLatin1String("server_name")==elem) { name=doc.readElementText().trimmed(); diff --git a/online/jamendoservice.cpp b/online/jamendoservice.cpp index 116d1bf520..d0a57239c6 100644 --- a/online/jamendoservice.cpp +++ b/online/jamendoservice.cpp @@ -222,7 +222,7 @@ void JamendoXmlParser::parseArtist(QList *songList, QXmlStreamReader &xml) xml.readNext(); if (QXmlStreamReader::StartElement==xml.tokenType()) { - QStringRef name = xml.name(); + QStringView name = xml.name(); if (QLatin1String("name")==name) { song.artist=xml.readElementText().trimmed(); @@ -248,7 +248,7 @@ void JamendoXmlParser::parseAlbum(Song &song, QList *songList, QXmlStreamR xml.readNext(); if (QXmlStreamReader::StartElement==xml.tokenType()) { - QStringRef name = xml.name(); + QStringView name = xml.name(); if (QLatin1String("name")==name) { song.album=xml.readElementText().trimmed(); @@ -284,7 +284,7 @@ void JamendoXmlParser::parseSong(Song &song, const QString &albumGenre, QXmlStre xml.readNext(); if (QXmlStreamReader::StartElement==xml.tokenType()) { - QStringRef name = xml.name(); + QStringView name = xml.name(); if (QLatin1String("name")==name) { song.title=xml.readElementText().trimmed(); diff --git a/online/magnatuneservice.cpp b/online/magnatuneservice.cpp index 6a55c8704a..b45e38b3f8 100644 --- a/online/magnatuneservice.cpp +++ b/online/magnatuneservice.cpp @@ -62,7 +62,7 @@ Song MagnatuneXmlParser::parseSong(QXmlStreamReader &xml) xml.readNext(); if (QXmlStreamReader::StartElement==xml.tokenType()) { - QStringRef name = xml.name(); + QStringView name = xml.name(); QString value = xml.readElementText(QXmlStreamReader::SkipChildElements); if (QLatin1String("artist")==name) { diff --git a/online/opmlparser.cpp b/online/opmlparser.cpp index 0218b683a7..fc1bab44d5 100644 --- a/online/opmlparser.cpp +++ b/online/opmlparser.cpp @@ -56,7 +56,7 @@ static void parseOutline(QXmlStreamReader &reader, Category &cat) QXmlStreamReader::TokenType type = reader.readNext(); switch (type) { case QXmlStreamReader::StartElement: { - const QStringRef name = reader.name(); + const QStringView name = reader.name(); if (name != QLatin1String("outline")) { consumeCurrentElement(reader); continue; diff --git a/online/rssparser.cpp b/online/rssparser.cpp index cac8d918bf..15db0e9832 100644 --- a/online/rssparser.cpp +++ b/online/rssparser.cpp @@ -27,8 +27,8 @@ #include #include -static const char * constITunesNameSpace = "http://www.itunes.com/dtds/podcast-1.0.dtd"; -static const char * constMediaNameSpace = "http://search.yahoo.com/mrss/"; +static const QString constITunesNameSpace = QStringLiteral("http://www.itunes.com/dtds/podcast-1.0.dtd"); +static const QString constMediaNameSpace = QStringLiteral("http://search.yahoo.com/mrss/"); using namespace RssParser; @@ -112,7 +112,7 @@ static Episode parseEpisode(QXmlStreamReader &reader) while (!reader.atEnd()) { reader.readNext(); - const QStringRef name = reader.name(); + const QStringView name = reader.name(); if (reader.isStartElement()) { if (QLatin1String("title")==name) { ep.name=reader.readElementText().simplified(); @@ -182,7 +182,7 @@ Channel RssParser::parse(QIODevice *dev, bool getEpisodes, bool getDescription) reader.readNext(); if (reader.isStartElement()) { - const QStringRef name = reader.name(); + const QStringView name = reader.name(); if (ch.name.isEmpty() && QLatin1String("title")==name) { ch.name=reader.readElementText().simplified(); } else if (QLatin1String("image")==name && ch.image.isEmpty()) { From c2d88cd815c52a7b16acdb83f46bc284ffaaf7ef Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:13:25 +0100 Subject: [PATCH 15/21] [Port to Qt6] std::random_shuffle -> std::shuffle --- playlists/smartplaylistspage.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/playlists/smartplaylistspage.cpp b/playlists/smartplaylistspage.cpp index 3fe7449f86..4f139c0509 100644 --- a/playlists/smartplaylistspage.cpp +++ b/playlists/smartplaylistspage.cpp @@ -33,6 +33,7 @@ #include "gui/stdactions.h" #include "models/mpdlibrarymodel.h" #include +#include SmartPlaylistsPage::SmartPlaylistsPage(QWidget *p) : SinglePageWidget(p) @@ -353,7 +354,7 @@ void SmartPlaylistsPage::addSongsToPlayQueue() break; default: case RulesPlaylists::Order_Random: - std::random_shuffle(songs.begin(), songs.end()); + std::shuffle(songs.begin(), songs.end(), *QRandomGenerator::global()); } QStringList files; From aefaaa22e5335ac54f423bc922058ebaf6eb790b Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:14:12 +0100 Subject: [PATCH 16/21] [Port to Qt6] QStandardPath changes --- support/utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support/utils.cpp b/support/utils.cpp index 64a1791c49..20ead770ae 100644 --- a/support/utils.cpp +++ b/support/utils.cpp @@ -743,13 +743,13 @@ QString Utils::dataDir(const QString &sub, bool create) { #if defined Q_OS_WIN || defined Q_OS_MAC - return userDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)+constDirSep, sub, create); + return userDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)+constDirSep, sub, create); #else static QString location; if (location.isEmpty()) { - location=QStandardPaths::writableLocation(QStandardPaths::DataLocation); + location=QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); if (QCoreApplication::organizationName()==QCoreApplication::applicationName()) { location=location.replace(QCoreApplication::organizationName()+Utils::constDirSep+QCoreApplication::applicationName(), QCoreApplication::applicationName()); From 0058df44478c0c258dc12275981a3ace72da67d4 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:15:43 +0100 Subject: [PATCH 17/21] [Port to Qt6] event->pos() -> event->position().toPoint() --- widgets/groupedview.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/widgets/groupedview.cpp b/widgets/groupedview.cpp index 75ffa3183f..a2dd5c7f21 100644 --- a/widgets/groupedview.cpp +++ b/widgets/groupedview.cpp @@ -696,15 +696,15 @@ void GroupedView::dropEvent(QDropEvent *event) { QModelIndex parent; quint32 dropRowAdjust=0; - if (model() && viewport()->rect().contains(event->pos())) { + if (model() && viewport()->rect().contains(event->position().toPoint())) { // Dont allow to drop on an already selected row - as this seems to cuase a crash!!! - QModelIndex idx=TreeView::indexAt(event->pos()); + QModelIndex idx=TreeView::indexAt(event->position().toPoint()); if (idx.isValid() && selectionModel() && selectionModel()->isSelected(idx)) { return; } if (idx.isValid() && isAlbumHeader(idx)) { QRect rect(visualRect(idx)); - if (event->pos().y()>(rect.y()+(rect.height()/2))) { + if (event->position().toPoint().y()>(rect.y()+(rect.height()/2))) { quint16 key=idx.data(Cantata::Role_Key).toUInt(); quint32 collection=idx.data(Cantata::Role_CollectionId).toUInt(); if (!isExpanded(key, collection)) { From d026f21451e45b15827fbe67d9d92bb8fe2758c3 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:16:07 +0100 Subject: [PATCH 18/21] [Port to Qt6] QMenu::addAction signature change --- widgets/mirrormenu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/mirrormenu.cpp b/widgets/mirrormenu.cpp index 64b7f56319..c754f623aa 100644 --- a/widgets/mirrormenu.cpp +++ b/widgets/mirrormenu.cpp @@ -51,14 +51,14 @@ QAction * MirrorMenu::addAction(const QIcon &icon, const QString &text) QAction * MirrorMenu::addAction(const QString &text, const QObject *receiver, const char *member, const QKeySequence &shortcut) { - QAction *act=QMenu::addAction(text, receiver, member, shortcut); + QAction *act=QMenu::addAction(text, shortcut, receiver, member); updateMenus(); return act; } QAction * MirrorMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char *member, const QKeySequence &shortcut) { - QAction *act=QMenu::addAction(icon, text, receiver, member, shortcut); + QAction *act=QMenu::addAction(icon, text, shortcut, receiver, member); updateMenus(); return act; } From 7b0e0b744421a02da7843a040ce40aecb31d74a4 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:17:43 +0100 Subject: [PATCH 19/21] [Port to Qt6] Port away from QTextCodec --- context/ultimatelyricsprovider.cpp | 12 ++---------- gui/main.cpp | 1 - mpd-interface/cuefile.cpp | 30 ++++++++++++------------------ online/jamendoservice.cpp | 4 +--- playlists/rulesplaylists.cpp | 4 ++-- tags/tags.cpp | 6 ++---- 6 files changed, 19 insertions(+), 38 deletions(-) diff --git a/context/ultimatelyricsprovider.cpp b/context/ultimatelyricsprovider.cpp index 67f4ea6d29..fb4832e715 100644 --- a/context/ultimatelyricsprovider.cpp +++ b/context/ultimatelyricsprovider.cpp @@ -216,12 +216,6 @@ QString UltimateLyricsProvider::displayName() const void UltimateLyricsProvider::fetchInfo(int id, Song metadata, bool removeThe) { - const QTextCodec *codec = QTextCodec::codecForName(charset.toLatin1().constData()); - if (!codec) { - emit lyricsReady(id, QString()); - return; - } - QString artistFixed=metadata.basicArtist(); QString titleFixed=metadata.basicTitle(); QString urlText(url); @@ -362,8 +356,7 @@ void UltimateLyricsProvider::wikiMediaLyricsFetched() return; } - const QTextCodec *codec = QTextCodec::codecForName(charset.toLatin1().constData()); - QString contents = codec->toUnicode(reply->readAll()).replace("
", "
"); + QString contents = QString::fromLatin1(reply->readAll()).replace("
", "
"); DBUG << name << "response" << contents; emit lyricsReady(id, extract(contents, QLatin1String("<lyrics>"), QLatin1String("</lyrics>"))); } @@ -389,8 +382,7 @@ void UltimateLyricsProvider::lyricsFetched() return; } - const QTextCodec *codec = QTextCodec::codecForName(charset.toLatin1().constData()); - const QString originalContent = codec->toUnicode(reply->readAll()).replace("
", "
"); + const QString originalContent = QString::fromLatin1(reply->readAll()).replace("
", "
"); DBUG << name << "response" << originalContent; // Check for invalid indicators diff --git a/gui/main.cpp b/gui/main.cpp index 52c7793e3c..ab37c42d06 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -23,7 +23,6 @@ #include "application.h" #include -#include #include #include #include diff --git a/mpd-interface/cuefile.cpp b/mpd-interface/cuefile.cpp index 7f791efc7d..6461d67d18 100644 --- a/mpd-interface/cuefile.cpp +++ b/mpd-interface/cuefile.cpp @@ -85,21 +85,14 @@ QByteArray CueFile::getLoadLine(const QString &str) return MPDConnection::encodeName(str); } -static const QList & codecList() +static const QList & encodingList() { - static QList codecs; - if (codecs.isEmpty()) { - codecs.append(QTextCodec::codecForName("UTF-8")); - QTextCodec *codec=QTextCodec::codecForLocale(); - if (codec && !codecs.contains(codec)) { - codecs.append(codec); - } - codec=QTextCodec::codecForName("System"); - if (codec && !codecs.contains(codec)) { - codecs.append(codec); - } + static QList encodings; + if (encodings.isEmpty()) { + encodings.append(QStringConverter::Utf8); + encodings.append(QStringConverter::System); } - return codecs; + return encodings; } // Split a raw .cue line into logical parts, returning a list where: @@ -254,10 +247,10 @@ bool CueFile::parse(const QString &fileName, const QString &dir, QList &so if (f.open(QIODevice::ReadOnly)) { // First attempt to use QTextDecoder to decode cue file contents into a QString QByteArray contents=f.readAll(); - for (QTextCodec *codec: codecList()) { - QTextDecoder decoder(codec); - decoded=decoder.toUnicode(contents); - if (!decoder.hasFailure()) { + for (QStringConverter::Encoding encoding: encodingList()) { + QStringDecoder decoder(encoding); + decoded = decoder.decode(contents); + if (!decoder.hasError()) { textStream.reset(new QTextStream(&decoded, QIODevice::ReadOnly)); break; } @@ -269,7 +262,8 @@ bool CueFile::parse(const QString &fileName, const QString &dir, QList &so // Failed to use text decoders, fall back to old method... f.open(QIODevice::ReadOnly|QIODevice::Text); textStream.reset(new QTextStream(&f)); - textStream->setCodec(QTextCodec::codecForUtfText(f.peek(1024), QTextCodec::codecForName("UTF-8"))); + std::optional encoding = QStringDecoder::encodingForData(f.peek(1024)); + textStream->setEncoding(encoding.value_or(QStringConverter::Utf8)); } } diff --git a/online/jamendoservice.cpp b/online/jamendoservice.cpp index d0a57239c6..0b6e27ab7b 100644 --- a/online/jamendoservice.cpp +++ b/online/jamendoservice.cpp @@ -36,12 +36,10 @@ #include #include -#include static QString id3Genre(int id) { - static QTextCodec *codec = QTextCodec::codecForName("UTF-8"); // Clementine: In theory, genre 0 is "blues"; in practice it's invalid. - return 0==id ? QString() : codec->toUnicode(TagLib::ID3v1::genre(id).toCString(true)).trimmed(); + return 0==id ? QString() : QString::fromUtf8(TagLib::ID3v1::genre(id).toCString(true)).trimmed(); } #else // TAGLIB_FOUND diff --git a/playlists/rulesplaylists.cpp b/playlists/rulesplaylists.cpp index d01755656c..3808516f89 100644 --- a/playlists/rulesplaylists.cpp +++ b/playlists/rulesplaylists.cpp @@ -246,7 +246,7 @@ bool RulesPlaylists::save(const Entry &e) QFile f(Utils::dataDir(rulesDir, true)+e.name+constExtension); if (f.open(QIODevice::WriteOnly|QIODevice::Text)) { QTextStream out(&f); - out.setCodec("UTF-8"); + out.setEncoding(QStringConverter::Utf8); out << string; updateEntry(e); return true; @@ -323,7 +323,7 @@ void RulesPlaylists::loadLocal() e.numTracks=defaultNumTracks(); Rule r; QTextStream in(&f); - in.setCodec("UTF-8"); + in.setEncoding(QStringConverter::Utf8); QStringList lines = in.readAll().split('\n', CANTATA_SKIP_EMPTY); for (const QString &line: lines) { QString str=line.trimmed(); diff --git a/tags/tags.cpp b/tags/tags.cpp index 5817dc1bbf..97c62c8866 100644 --- a/tags/tags.cpp +++ b/tags/tags.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #define TAGLIB_VERSION CANTATA_MAKE_VERSION(TAGLIB_MAJOR_VERSION, TAGLIB_MINOR_VERSION, TAGLIB_PATCH_VERSION) @@ -100,8 +99,7 @@ void enableDebug() static QString tString2QString(const TagLib::String &str) { - static QTextCodec *codec = QTextCodec::codecForName("UTF-8"); - return codec->toUnicode(str.toCString(true)).trimmed(); + return QString::fromUtf8(str.toCString(true)).trimmed(); } TagLib::String qString2TString(const QString &str) @@ -1149,7 +1147,7 @@ static void readASFTags(TagLib::ASF::Tag *tag, Song *song, int *rating) song->setComposer(tString2QString(map["WM/Composer"].front().toString())); } if (map.contains("WM/PartOfSet") && !map["WM/PartOfSet"].isEmpty()) { - song->albumartist=map["WM/PartOfSet"].front().toUInt(); + song->albumartist=tString2QString(map["WM/PartOfSet"].front().toString()); } if (map.contains("WM/Genre") && !map["WM/Genre"].isEmpty()) { const TagLib::ASF::AttributeList &genres=map["WM/Genre"]; From f28e459ce0e0c880c1989ede6ee659ad42104fe6 Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:04:26 +0100 Subject: [PATCH 20/21] [Port to Qt6] AudioOutput is split from MediaPlayer --- mpd-interface/httpstream.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/mpd-interface/httpstream.cpp b/mpd-interface/httpstream.cpp index c75fde7fae..41b619c425 100644 --- a/mpd-interface/httpstream.cpp +++ b/mpd-interface/httpstream.cpp @@ -28,7 +28,8 @@ #include "support/globalstatic.h" #include "support/configuration.h" #ifndef LIBVLC_FOUND -#include +#include +#include #endif #include @@ -98,7 +99,8 @@ void HttpStream::setVolume(int vol) #ifdef LIBVLC_FOUND libvlc_audio_set_volume(player, vol); #else - player->setVolume(vol); + // QAudioOutput::volume is between 0 and 100 + player->audioOutput()->setVolume(static_cast(vol)/100); #endif emit update(); } @@ -115,7 +117,8 @@ int HttpStream::volume() #ifdef LIBVLC_FOUND vol = libvlc_audio_get_volume(player); #else - vol = player->volume(); + // QAudioOutput::volume is between 0 and 100 + vol = int(player->audioOutput()->volume() * 100); #endif if (vol < 0) { vol = currentVolume; @@ -135,7 +138,7 @@ void HttpStream::toggleMute() #ifdef LIBVLC_FOUND libvlc_audio_set_mute(player, muted); #else - player->setMuted(!muted); + player->audioOutput()->setMuted(!muted); #endif emit update(); } @@ -153,9 +156,9 @@ void HttpStream::streamUrl(const QString &url) } #else if (player) { - QMediaContent media = player->media(); - if (media != nullptr && media.request().url() != url) { + if (player->source().url() != url) { player->stop(); + player->audioOutput()->deleteLater(); player->deleteLater(); player = nullptr; } @@ -171,8 +174,10 @@ void HttpStream::streamUrl(const QString &url) libvlc_media_release(media); #else player = new QMediaPlayer(this); - player->setMedia(qUrl); - connect(player, &QMediaPlayer::bufferStatusChanged, this, &HttpStream::bufferingProgress); + QAudioOutput* audioOutput = new QAudioOutput(this); + player->setAudioOutput(audioOutput); + player->setSource(qUrl); + connect(player, &QMediaPlayer::bufferProgressChanged, this, &HttpStream::bufferingProgress); #endif muted = false; setVolume(Configuration(metaObject()->className()).get("volume", currentVolume)); @@ -214,7 +219,7 @@ void HttpStream::updateStatus() #ifdef LIBVLC_FOUND playerNeedsToStart = playerNeedsToStart && libvlc_media_player_get_state(player) != libvlc_Playing; #else - playerNeedsToStart = playerNeedsToStart && player->state() == QMediaPlayer::StoppedState; + playerNeedsToStart = playerNeedsToStart && player->playbackState() == QMediaPlayer::StoppedState; #endif if (status->state() == state && !playerNeedsToStart) { @@ -230,8 +235,9 @@ void HttpStream::updateStatus() libvlc_media_player_play(player); startTimer(); #else - QUrl url = player->media().request().url(); - player->setMedia(url); + QUrl url = player->source().url(); + player->setSource(url); + player->play(); #endif } break; From 3c6668773b131780162ce371efdea765c4726d7e Mon Sep 17 00:00:00 2001 From: Olivier CHURLAUD Date: Thu, 29 Feb 2024 21:18:55 +0100 Subject: [PATCH 21/21] [Port to Qt6] Various corrections --- 3rdparty/solid-lite/backends/hal/haldevice.cpp | 1 + .../solid-lite/backends/udev/udevportablemediaplayer.cpp | 2 +- 3rdparty/solid-lite/backends/udisks/udisksopticaldisc.cpp | 6 +++--- .../solid-lite/backends/udisks2/udisksdevicebackend.h | 2 +- 3rdparty/solid-lite/xdgbasedirs_p.h | 2 +- context/ultimatelyrics.cpp | 2 +- devices/fsdevice.h | 1 + gui/coverdialog.cpp | 2 +- gui/interfacesettings.h | 1 - gui/main.cpp | 8 +------- gui/preferencesdialog.h | 1 - streams/streamfetcher.cpp | 2 +- support/acceleratormanager.cpp | 2 +- support/actioncollection.cpp | 1 + support/fancytabwidget.h | 2 +- widgets/autohidingsplitter.h | 2 +- widgets/singlepagewidget.cpp | 1 + widgets/stretchheaderview.cpp | 1 + 18 files changed, 18 insertions(+), 21 deletions(-) diff --git a/3rdparty/solid-lite/backends/hal/haldevice.cpp b/3rdparty/solid-lite/backends/hal/haldevice.cpp index 88a02ff83c..2dd3fb7056 100644 --- a/3rdparty/solid-lite/backends/hal/haldevice.cpp +++ b/3rdparty/solid-lite/backends/hal/haldevice.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include diff --git a/3rdparty/solid-lite/backends/udev/udevportablemediaplayer.cpp b/3rdparty/solid-lite/backends/udev/udevportablemediaplayer.cpp index b5ea113c74..922043efde 100644 --- a/3rdparty/solid-lite/backends/udev/udevportablemediaplayer.cpp +++ b/3rdparty/solid-lite/backends/udev/udevportablemediaplayer.cpp @@ -53,7 +53,7 @@ static QString readMpiValue(QIODevice &file, const QString &group, const QString else if (line.startsWith(QChar('[')) && line.endsWith(QChar(']'))) { currGroup = line.mid(1, line.length() - 2); // strip [ and ] } - else if (line.indexOf(QChar('=') != -1)) { + else if (line.indexOf(QChar('=')) != -1) { int index = line.indexOf(QChar('=')); if (currGroup == group && line.left(index) == key) { line = line.right(line.length() - index - 1); diff --git a/3rdparty/solid-lite/backends/udisks/udisksopticaldisc.cpp b/3rdparty/solid-lite/backends/udisks/udisksopticaldisc.cpp index 8eb3588c46..93078b2594 100644 --- a/3rdparty/solid-lite/backends/udisks/udisksopticaldisc.cpp +++ b/3rdparty/solid-lite/backends/udisks/udisksopticaldisc.cpp @@ -24,9 +24,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "udisksopticaldisc.h" #include "soliddefs_p.h" diff --git a/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.h b/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.h index 089a99f547..7f9382620e 100644 --- a/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.h +++ b/3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.h @@ -71,7 +71,7 @@ class DeviceBackend: public QObject { QDBusInterface *m_device; - mutable QMultiMap m_propertyCache; + mutable QVariantMap m_propertyCache; QStringList m_interfaces; QString m_udi; diff --git a/3rdparty/solid-lite/xdgbasedirs_p.h b/3rdparty/solid-lite/xdgbasedirs_p.h index 369d12f671..7d60b63711 100644 --- a/3rdparty/solid-lite/xdgbasedirs_p.h +++ b/3rdparty/solid-lite/xdgbasedirs_p.h @@ -26,8 +26,8 @@ #ifndef SOLID_XDGBASEDIRS_H #define SOLID_XDGBASEDIRS_H +#include class QString; -class QStringList; namespace Solid { diff --git a/context/ultimatelyrics.cpp b/context/ultimatelyrics.cpp index ee437c09ef..1bb9af7b71 100644 --- a/context/ultimatelyrics.cpp +++ b/context/ultimatelyrics.cpp @@ -157,7 +157,7 @@ void UltimateLyrics::load() if (!userDir.isEmpty()) { QFileInfoList files=QDir(userDir).entryInfoList(QStringList() << QLatin1String("lyrics_*.xml"), QDir::NoDotAndDotDot|QDir::Files); for (const QFileInfo &f: files) { - files.append(f.absoluteFilePath()); + files.append(QFileInfo(f.absoluteFilePath())); } } diff --git a/devices/fsdevice.h b/devices/fsdevice.h index fec9febf9d..ac065a881d 100644 --- a/devices/fsdevice.h +++ b/devices/fsdevice.h @@ -37,6 +37,7 @@ class Thread; struct FileOnlySong : public Song { + FileOnlySong() { } FileOnlySong(const Song &o) : Song(o) { } bool operator==(const FileOnlySong &o) const { return file==o.file; } bool operator<(const FileOnlySong &o) const { return file.compare(o.file)<0; } diff --git a/gui/coverdialog.cpp b/gui/coverdialog.cpp index cb70571d28..06e8798cf9 100644 --- a/gui/coverdialog.cpp +++ b/gui/coverdialog.cpp @@ -252,7 +252,7 @@ void CoverPreview::showImage(const QImage &img, const QString &u) QApplication::processEvents(); adjustSize(); QStyleOptionFrame opt; - opt.init(scrollArea); + opt.initFrom(scrollArea); int fw=style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, scrollArea); if (fw<0) { fw=2; diff --git a/gui/interfacesettings.h b/gui/interfacesettings.h index 0c94432689..8d93f941b4 100644 --- a/gui/interfacesettings.h +++ b/gui/interfacesettings.h @@ -26,7 +26,6 @@ #include "ui_interfacesettings.h" -class QStringList; class InterfaceSettings : public QWidget, private Ui::InterfaceSettings { diff --git a/gui/main.cpp b/gui/main.cpp index ab37c42d06..102fa7cb13 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -352,12 +352,6 @@ int main(int argc, char *argv[]) QCoreApplication::setApplicationName(PACKAGE_NAME); QCoreApplication::setOrganizationName(ORGANIZATION_NAME); - QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); - // Dont enable AA_EnableHighDpiScaling - messes up fractional scaling? Issue #1257 - //#if QT_VERSION >= 0x050600 && defined Q_OS_WIN - //QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - //#endif - Application app(argc, argv); app.setApplicationVersion(PACKAGE_VERSION_STRING); @@ -413,7 +407,7 @@ int main(int argc, char *argv[]) #if defined Q_OS_WIN || defined Q_OS_MAC loadTranslation("qt", CANTATA_SYS_TRANS_DIR, lang); #else - loadTranslation("qt", QLibraryInfo::location(QLibraryInfo::TranslationsPath), lang); + loadTranslation("qt", QLibraryInfo::path(QLibraryInfo::TranslationsPath), lang); #endif QString local = Utils::fixPath(QCoreApplication::applicationDirPath())+"translations"; loadTranslation("cantata", QDir(local).exists() ? local : CANTATA_SYS_TRANS_DIR, lang); diff --git a/gui/preferencesdialog.h b/gui/preferencesdialog.h index b5bf98f8b9..0608bb9d79 100644 --- a/gui/preferencesdialog.h +++ b/gui/preferencesdialog.h @@ -38,7 +38,6 @@ class CacheSettings; #if defined CDDB_FOUND || defined MUSICBRAINZ5_FOUND class AudioCdSettings; #endif -class QStringList; #ifdef ENABLE_PROXY_CONFIG class ProxySettings; #endif diff --git a/streams/streamfetcher.cpp b/streams/streamfetcher.cpp index 4a005f88d5..c65f7eda78 100644 --- a/streams/streamfetcher.cpp +++ b/streams/streamfetcher.cpp @@ -291,7 +291,7 @@ void StreamFetcher::dataReady() data+=job->readAll(); - if (data.count()>constMaxData) { + if (data.length()>constMaxData) { NetworkJob *thisJob=job; jobFinished(thisJob); // If jobFinished did not redirect, then we need to ensure job is cancelled. diff --git a/support/acceleratormanager.cpp b/support/acceleratormanager.cpp index 9f051bb25e..ecc221eb6f 100644 --- a/support/acceleratormanager.cpp +++ b/support/acceleratormanager.cpp @@ -273,7 +273,7 @@ void AcceleratorManagerPrivate::traverseChildren(QWidget *widget, Item *item) // Ignore unless we have the direct parent if(qobject_cast(w->parent()) != widget) continue; - if ( !w->isVisibleTo( widget ) || (w->isTopLevel() && qobject_cast(w) == nullptr) ) + if ( !w->isVisibleTo( widget ) || (w->isWindow() && qobject_cast(w) == nullptr) ) continue; if ( AcceleratorManagerPrivate::ignored_widgets.contains( w ) ) diff --git a/support/actioncollection.cpp b/support/actioncollection.cpp index 4ec41e6abc..fcde6fc77b 100644 --- a/support/actioncollection.cpp +++ b/support/actioncollection.cpp @@ -26,6 +26,7 @@ #include #include #include +#include static const char *constProp="Category"; static ActionCollection *coll=nullptr; diff --git a/support/fancytabwidget.h b/support/fancytabwidget.h index f8fcde7102..e33857cde2 100644 --- a/support/fancytabwidget.h +++ b/support/fancytabwidget.h @@ -77,7 +77,7 @@ class FancyTab : public QWidget bool underMouse; protected: - void enterEvent(QEvent *) override; + void enterEvent(QEvent *); void leaveEvent(QEvent *) override; private: diff --git a/widgets/autohidingsplitter.h b/widgets/autohidingsplitter.h index e9749d4343..8151fc3f92 100644 --- a/widgets/autohidingsplitter.h +++ b/widgets/autohidingsplitter.h @@ -52,7 +52,7 @@ class AutohidingSplitterHandle : public ThinSplitterHandle void hoverFinished(); protected: - void enterEvent(QEvent *) override { emit hoverStarted(); } + void enterEvent(QEvent *) { emit hoverStarted(); } void leaveEvent(QEvent *) override { emit hoverFinished(); } }; diff --git a/widgets/singlepagewidget.cpp b/widgets/singlepagewidget.cpp index 41ecfe1884..9693a5212d 100644 --- a/widgets/singlepagewidget.cpp +++ b/widgets/singlepagewidget.cpp @@ -30,6 +30,7 @@ #include "mpd-interface/mpdconnection.h" #include #include +#include static QString viewTypeString(ItemView::Mode mode) { diff --git a/widgets/stretchheaderview.cpp b/widgets/stretchheaderview.cpp index 5aeceee9ca..f51a40fe69 100644 --- a/widgets/stretchheaderview.cpp +++ b/widgets/stretchheaderview.cpp @@ -19,6 +19,7 @@ //#include "core/logging.h" #include +#include #include #include