From 8eb1643c92176a1caf5763a6a4a6ebe02b863cb1 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 10 Oct 2017 12:58:41 -0400 Subject: [PATCH 1/7] Fix templates and recent files on KDE. Workaround for https://bugs.kde.org/show_bug.cgi?id=337491 --- src/gui/MainWindow.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index b91fe3ef2fa..ee522901928 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -836,8 +836,14 @@ void MainWindow::createNewProjectFromTemplate( QAction * _idx ) ConfigManager::inst()->factoryTemplatesDir() : ConfigManager::inst()->userTemplateDir(); + QString templateFile = dirBase + _idx->text() + ".mpt"; + //KDE adds accelerators to everythng in the menu. + if( !QFileInfo::exists(templateFile) ) { + templateFile = templateFile.replace('&', "" ); + } + Engine::getSong()->createNewProjectFromTemplate( - dirBase + _idx->text() + ".mpt" ); + templateFile ); } } @@ -909,8 +915,12 @@ void MainWindow::openRecentlyOpenedProject( QAction * _action ) { if ( mayChangeProject(true) ) { - const QString & f = _action->text(); + QString f = _action->text(); setCursor( Qt::WaitCursor ); + //KDE adds accelerators to everythng in the menu. + if( !QFileInfo::exists(f) ) { + f = f.replace('&', "" ); + } Engine::getSong()->loadProject( f ); setCursor( Qt::ArrowCursor ); } From d72ac095f6a066c2653e0260d71cde75d58f3264 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 10 Oct 2017 13:08:03 -0400 Subject: [PATCH 2/7] Fix the ability to build with qt4. --- src/gui/MainWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index ee522901928..6d01ee4b0df 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -838,7 +838,7 @@ void MainWindow::createNewProjectFromTemplate( QAction * _idx ) QString templateFile = dirBase + _idx->text() + ".mpt"; //KDE adds accelerators to everythng in the menu. - if( !QFileInfo::exists(templateFile) ) { + if( !QFileInfo(templateFile).exists() ) { templateFile = templateFile.replace('&', "" ); } @@ -918,7 +918,7 @@ void MainWindow::openRecentlyOpenedProject( QAction * _action ) QString f = _action->text(); setCursor( Qt::WaitCursor ); //KDE adds accelerators to everythng in the menu. - if( !QFileInfo::exists(f) ) { + if( !QFileInfo(f).exists() ) { f = f.replace('&', "" ); } Engine::getSong()->loadProject( f ); From 413ecd7e88b5bb700723e1ae45bec55d7354749a Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 10 Oct 2017 13:52:06 -0400 Subject: [PATCH 3/7] Fix & in recent files. Call into KDE stuff to stop it adding accelerators. Escape & as && when building the recent file lists, and reverse that when getting the file name. --- src/CMakeLists.txt | 5 +++++ src/gui/MainWindow.cpp | 42 ++++++++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd29619b295..c0fce8fe778 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -130,6 +130,11 @@ if(LMMS_HAVE_OSS AND LMMS_BUILD_OPENBSD) SET(EXTRA_LIBRARIES "-lossaudio") endif() +if(LMMS_BUILD_LINUX) + #libdl is needed for a KDE bug workaround. + SET(EXTRA_LIBRARIES "-ldl") +endif() + IF(LMMS_BUILD_HAIKU) SET(EXTRA_LIBRARIES "-lnetwork") ENDIF() diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 6d01ee4b0df..de61cf8e3db 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -64,6 +64,24 @@ #include "lmmsversion.h" +#ifdef LMMS_BUILD_LINUX +#include +//This function is slightly modified from a solution to a KDE bug +//Found at https://bugs.kde.org/show_bug.cgi?id=337491#c21 +void DisableSystemAccel(QWidget *what) +{ + void *d = dlopen("libKF5WidgetsAddons.so", RTLD_LAZY); + if (!d) + return; + using DisablerFunc = void(*)(QWidget*); + DisablerFunc setNoAccel; + setNoAccel = reinterpret_cast(dlsym(d, "_ZN19KAcceleratorManager10setNoAccelEP7QWidget")); + if (setNoAccel) { + setNoAccel(what); + } + dlclose(d); +} +#endif MainWindow::MainWindow() : @@ -76,6 +94,9 @@ MainWindow::MainWindow() : m_metronomeToggle( 0 ), m_session( Normal ) { +#ifdef LMMS_BUILD_LINUX + DisableSystemAccel(this); +#endif setAttribute( Qt::WA_DeleteOnClose ); QWidget * main_widget = new QWidget( this ); @@ -836,14 +857,8 @@ void MainWindow::createNewProjectFromTemplate( QAction * _idx ) ConfigManager::inst()->factoryTemplatesDir() : ConfigManager::inst()->userTemplateDir(); - QString templateFile = dirBase + _idx->text() + ".mpt"; - //KDE adds accelerators to everythng in the menu. - if( !QFileInfo(templateFile).exists() ) { - templateFile = templateFile.replace('&', "" ); - } - - Engine::getSong()->createNewProjectFromTemplate( - templateFile ); + const QString f = dirBase + _idx->text().replace("&&", "&") + ".mpt"; + Engine::getSong()->createNewProjectFromTemplate(f); } } @@ -894,7 +909,7 @@ void MainWindow::updateRecentlyOpenedProjectsMenu() } m_recentlyOpenedProjectsMenu->addAction( - embed::getIconPixmap( "project_file" ), *it ); + embed::getIconPixmap( "project_file" ), it->replace("&", "&&") ); #ifdef LMMS_BUILD_APPLE m_recentlyOpenedProjectsMenu->actions().last()->setIconVisibleInMenu(false); // QTBUG-44565 workaround m_recentlyOpenedProjectsMenu->actions().last()->setIconVisibleInMenu(true); @@ -910,17 +925,12 @@ void MainWindow::updateRecentlyOpenedProjectsMenu() - void MainWindow::openRecentlyOpenedProject( QAction * _action ) { if ( mayChangeProject(true) ) { - QString f = _action->text(); + const QString f = _action->text().replace("&&", "&"); setCursor( Qt::WaitCursor ); - //KDE adds accelerators to everythng in the menu. - if( !QFileInfo(f).exists() ) { - f = f.replace('&', "" ); - } Engine::getSong()->loadProject( f ); setCursor( Qt::ArrowCursor ); } @@ -1510,7 +1520,7 @@ void MainWindow::fillTemplatesMenu() { m_templatesMenu->addAction( embed::getIconPixmap( "project_file" ), - ( *it ).left( ( *it ).length() - 4 ) ); + ( *it ).left( ( *it ).length() - 4 ).replace("&", "&&") ); #ifdef LMMS_BUILD_APPLE m_templatesMenu->actions().last()->setIconVisibleInMenu(false); // QTBUG-44565 workaround m_templatesMenu->actions().last()->setIconVisibleInMenu(true); From 13214e059f44d97c831b3c07b71a56f1efc5763f Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 10 Oct 2017 16:59:29 -0400 Subject: [PATCH 4/7] Make the fix (probably) work on bsd. --- src/CMakeLists.txt | 11 ++++++----- src/gui/MainWindow.cpp | 28 +++++++++++++++------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c0fce8fe778..dfe9ab0bc2e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -130,15 +130,15 @@ if(LMMS_HAVE_OSS AND LMMS_BUILD_OPENBSD) SET(EXTRA_LIBRARIES "-lossaudio") endif() -if(LMMS_BUILD_LINUX) - #libdl is needed for a KDE bug workaround. - SET(EXTRA_LIBRARIES "-ldl") -endif() - IF(LMMS_BUILD_HAIKU) SET(EXTRA_LIBRARIES "-lnetwork") ENDIF() +if(NOT LMMS_BUILD_WIN32 AND NOT LMMS_BUILD_APPLE AND NOT LMMS_BUILD_HAIKU) + #see https://bugs.kde.org/show_bug.cgi?id=337491#c21 + SET(KDE_FIX_LIBRARIES "-ldl") +endif() + SET(LMMS_REQUIRED_LIBS ${CMAKE_THREAD_LIBS_INIT} ${QT_LIBRARIES} @@ -154,6 +154,7 @@ SET(LMMS_REQUIRED_LIBS ${SAMPLERATE_LIBRARIES} ${SNDFILE_LIBRARIES} ${EXTRA_LIBRARIES} + ${KDE_FIX_LIBRARIES} rpmalloc ) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index de61cf8e3db..0b54bfd5682 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -64,22 +64,24 @@ #include "lmmsversion.h" -#ifdef LMMS_BUILD_LINUX +#if !defined(LMMS_BUILD_WIN32) && !defined(LMMS_BULID_APPLE) && !defined(LMMS_BUILD_HAIKU) #include -//This function is slightly modified from a solution to a KDE bug -//Found at https://bugs.kde.org/show_bug.cgi?id=337491#c21 -void DisableSystemAccel(QWidget *what) +//Work around an issue on KDE5 as per https://bugs.kde.org/show_bug.cgi?id=337491#c21 +void disableAutoKeyAccelerators(QWidget* mainWindow) { - void *d = dlopen("libKF5WidgetsAddons.so", RTLD_LAZY); - if (!d) + void *libraryHandle = dlopen("libKF5WidgetsAddons.so", RTLD_LAZY); + if (!libraryHandle) { + //KDE not installed, nothing to do. return; + } using DisablerFunc = void(*)(QWidget*); - DisablerFunc setNoAccel; - setNoAccel = reinterpret_cast(dlsym(d, "_ZN19KAcceleratorManager10setNoAccelEP7QWidget")); - if (setNoAccel) { - setNoAccel(what); + DisablerFunc setNoAccelerators = + reinterpret_cast(dlsym(libraryHandle, + "_ZN19KAcceleratorManager10setNoAccelEP7QWidget")); + if (setNoAccelerators) { + setNoAccelerators(mainWindow); } - dlclose(d); + dlclose(libraryHandle); } #endif @@ -94,8 +96,8 @@ MainWindow::MainWindow() : m_metronomeToggle( 0 ), m_session( Normal ) { -#ifdef LMMS_BUILD_LINUX - DisableSystemAccel(this); +#if !defined(LMMS_BUILD_WIN32) && !defined(LMMS_BULID_APPLE) && !defined(LMMS_BUILD_HAIKU) + disableAutoKeyAccelerators(this); #endif setAttribute( Qt::WA_DeleteOnClose ); From b39a908ce00a2738d8bf00a122d77bc1a2216b92 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 2 Nov 2017 22:36:27 -0400 Subject: [PATCH 5/7] Use QLibrary instead of calling dlopen QLibrary is significantly simpler of code. We don't extra stuff in the cmake files for QLibrary --- src/CMakeLists.txt | 6 ------ src/gui/MainWindow.cpp | 18 +++++++----------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dfe9ab0bc2e..bd29619b295 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -134,11 +134,6 @@ IF(LMMS_BUILD_HAIKU) SET(EXTRA_LIBRARIES "-lnetwork") ENDIF() -if(NOT LMMS_BUILD_WIN32 AND NOT LMMS_BUILD_APPLE AND NOT LMMS_BUILD_HAIKU) - #see https://bugs.kde.org/show_bug.cgi?id=337491#c21 - SET(KDE_FIX_LIBRARIES "-ldl") -endif() - SET(LMMS_REQUIRED_LIBS ${CMAKE_THREAD_LIBS_INIT} ${QT_LIBRARIES} @@ -154,7 +149,6 @@ SET(LMMS_REQUIRED_LIBS ${SAMPLERATE_LIBRARIES} ${SNDFILE_LIBRARIES} ${EXTRA_LIBRARIES} - ${KDE_FIX_LIBRARIES} rpmalloc ) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 0b54bfd5682..2ef8371feec 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -65,23 +66,18 @@ #include "lmmsversion.h" #if !defined(LMMS_BUILD_WIN32) && !defined(LMMS_BULID_APPLE) && !defined(LMMS_BUILD_HAIKU) -#include //Work around an issue on KDE5 as per https://bugs.kde.org/show_bug.cgi?id=337491#c21 void disableAutoKeyAccelerators(QWidget* mainWindow) { - void *libraryHandle = dlopen("libKF5WidgetsAddons.so", RTLD_LAZY); - if (!libraryHandle) { - //KDE not installed, nothing to do. - return; - } using DisablerFunc = void(*)(QWidget*); - DisablerFunc setNoAccelerators = - reinterpret_cast(dlsym(libraryHandle, - "_ZN19KAcceleratorManager10setNoAccelEP7QWidget")); - if (setNoAccelerators) { + QLibrary kf5WidgetsAddon("libKF5WidgetsAddons.so"); + DisablerFunc setNoAccelerators = + reinterpret_cast(kf5WidgetsAddon.resolve("_ZN19KAcceleratorManager10setNoAccelEP7QWidget")); + if(setNoAccelerators) + { setNoAccelerators(mainWindow); } - dlclose(libraryHandle); + kf5WidgetsAddon.unload(); } #endif From b855413539adc0c09228c36f540a768797c6cbf2 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 2 Nov 2017 22:42:24 -0400 Subject: [PATCH 6/7] Simplify name of loaded library. QLibrary means you don't need to put "lib" on the front or ".so" on the end. --- src/gui/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 2ef8371feec..8869e242631 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -70,7 +70,7 @@ void disableAutoKeyAccelerators(QWidget* mainWindow) { using DisablerFunc = void(*)(QWidget*); - QLibrary kf5WidgetsAddon("libKF5WidgetsAddons.so"); + QLibrary kf5WidgetsAddon("KF5WidgetsAddons"); DisablerFunc setNoAccelerators = reinterpret_cast(kf5WidgetsAddon.resolve("_ZN19KAcceleratorManager10setNoAccelEP7QWidget")); if(setNoAccelerators) From aed19202e68b72dae030c71f9341eaa52f9f9d35 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 3 Nov 2017 18:09:12 -0400 Subject: [PATCH 7/7] Specify the version to make it work on ubuntu. Ubuntu doesn't ship libKF5WidgetAddons.so, but does ship libKF5WidgetAddons.so.5 --- src/gui/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 8869e242631..32d16546b1b 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -70,7 +70,7 @@ void disableAutoKeyAccelerators(QWidget* mainWindow) { using DisablerFunc = void(*)(QWidget*); - QLibrary kf5WidgetsAddon("KF5WidgetsAddons"); + QLibrary kf5WidgetsAddon("KF5WidgetsAddons", 5); DisablerFunc setNoAccelerators = reinterpret_cast(kf5WidgetsAddon.resolve("_ZN19KAcceleratorManager10setNoAccelEP7QWidget")); if(setNoAccelerators)