diff --git a/.gitmodules b/.gitmodules index 1cec96a..6108b72 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "3rdparty/nlohmann_json"] path = 3rdparty/nlohmann_json url = https://github.com/nlohmann/json.git +[submodule "3rdparty/singleapplication"] + path = 3rdparty/singleapplication + url = git@github.com:itay-grudev/SingleApplication.git diff --git a/3rdparty/singleapplication b/3rdparty/singleapplication new file mode 160000 index 0000000..7163d16 --- /dev/null +++ b/3rdparty/singleapplication @@ -0,0 +1 @@ +Subproject commit 7163d166a1fbce7917015293f8e139bd65604881 diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index b66b5c1..8992f6f 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -11,6 +11,11 @@ set(CMAKE_AUTORCC ON) find_package(Qt5Widgets CONFIG REQUIRED) find_package(Qt5PrintSupport CONFIG REQUIRED) +# For SingleApplication: +find_package(Qt5Network CONFIG REQUIRED) +set(QAPPLICATION_CLASS QApplication) +add_compile_definitions(QAPPLICATION_CLASS=${QAPPLICATION_CLASS}) + set(GUI_SOURCES kima2.cpp mainwindow.cpp @@ -28,11 +33,14 @@ set(GUI_SOURCES settingsdialog.cpp settingsdialog.ui ../../kima2.qrc + ${PROJECT_SOURCE_DIR}/3rdparty/singleapplication/singleapplication.cpp + ${PROJECT_SOURCE_DIR}/3rdparty/singleapplication/singleapplication_p.cpp ) add_executable(kima2 ${GUI_SOURCES} kima2.rc) target_include_directories(kima2 PRIVATE ${PROJECT_BINARY_DIR}) -target_link_libraries(kima2 core printer Qt5::Widgets Qt5::PrintSupport stdc++fs) +target_include_directories(kima2 PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/singleapplication) +target_link_libraries(kima2 core printer Qt5::Widgets Qt5::PrintSupport Qt5::Network stdc++fs) if(WIN32) set_target_properties(kima2 PROPERTIES LINK_FLAGS "-mwindows") endif(WIN32) diff --git a/src/gui/kima2.cpp b/src/gui/kima2.cpp index 3f4a259..1b6ad96 100644 --- a/src/gui/kima2.cpp +++ b/src/gui/kima2.cpp @@ -6,12 +6,14 @@ #include #include #include -#include #include +#include + +#include int main(int argc, char* argv[]) { - QApplication kimaApp{argc, argv}; + SingleApplication kimaApp(argc, argv); // QCoreApplication::setOrganizationName("RustySoft"); QCoreApplication::setOrganizationDomain("rustysoft.de"); @@ -19,10 +21,11 @@ int main(int argc, char* argv[]) // Make sure that only one instance of the application runs // Of course the uuid used here is unique to this application - QSharedMemory shared("26297455-946a-4607-bfb7-5025a5f1e136"); + // (commented out in favour of SingleApplication) + /*QSharedMemory shared("26297455-946a-4607-bfb7-5025a5f1e136"); if (!shared.create(512, QSharedMemory::ReadWrite)) { exit(0); - } + }*/ QTranslator qTranslator; QLocale german(QLocale::German);