diff --git a/3rdparty/qt-unix-signals/CMakeLists.txt b/3rdparty/qt-unix-signals/CMakeLists.txt new file mode 100644 index 0000000..0745620 --- /dev/null +++ b/3rdparty/qt-unix-signals/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.1.0) + +project(QtSignals LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + +find_package(Qt5 REQUIRED COMPONENTS Core) + +add_library(QtSignals sigwatch.cpp) +target_include_directories(QtSignals INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(QtSignals Qt5::Core) \ No newline at end of file diff --git a/3rdparty/qt-unix-signals/LICENCE b/3rdparty/qt-unix-signals/LICENCE new file mode 100644 index 0000000..7cee458 --- /dev/null +++ b/3rdparty/qt-unix-signals/LICENCE @@ -0,0 +1,21 @@ +Unix signal watcher for Qt. + +Copyright (C) 2014 Simon Knopp + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/GPService/sigwatch.cpp b/3rdparty/qt-unix-signals/sigwatch.cpp similarity index 100% rename from GPService/sigwatch.cpp rename to 3rdparty/qt-unix-signals/sigwatch.cpp diff --git a/GPService/sigwatch.h b/3rdparty/qt-unix-signals/sigwatch.h similarity index 100% rename from GPService/sigwatch.h rename to 3rdparty/qt-unix-signals/sigwatch.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b4f6095..fce7253 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,5 +22,7 @@ find_package(Qt5 REQUIRED COMPONENTS DBus ) +add_subdirectory(3rdparty/qt-unix-signals) add_subdirectory(GPService) add_subdirectory(GPClient) +add_dependencies(gpclient gpservice) diff --git a/GPClient/CMakeLists.txt b/GPClient/CMakeLists.txt index 775ed48..ab671ae 100644 --- a/GPClient/CMakeLists.txt +++ b/GPClient/CMakeLists.txt @@ -4,7 +4,11 @@ project(GPClient) set(gpclient_GENERATED_SOURCES) -qt5_add_dbus_interface(gpclient_GENERATED_SOURCES ${CMAKE_BINARY_DIR}/com.yuezk.qt.GPService.xml gpserviceinterface) +qt5_add_dbus_interface( + gpclient_GENERATED_SOURCES + ${CMAKE_BINARY_DIR}/com.yuezk.qt.GPService.xml + gpserviceinterface +) add_executable(gpclient cdpcommand.cpp @@ -75,6 +79,7 @@ target_link_libraries(gpclient Qt5::WebEngine Qt5::WebEngineWidgets Qt5::DBus + QtSignals ) target_compile_definitions(gpclient PUBLIC QAPPLICATION_CLASS=QApplication) diff --git a/GPClient/gpclient.h b/GPClient/gpclient.h index 690c026..ae2eaf7 100644 --- a/GPClient/gpclient.h +++ b/GPClient/gpclient.h @@ -23,6 +23,7 @@ public: ~GPClient(); void activate(); + void quit(); private slots: void onSettingsButtonClicked(); @@ -97,6 +98,5 @@ private: void setCurrentGateway(const GPGateway gateway); void clearSettings(); - void quit(); }; #endif // GPCLIENT_H diff --git a/GPClient/main.cpp b/GPClient/main.cpp index 2902a0e..b93a17c 100644 --- a/GPClient/main.cpp +++ b/GPClient/main.cpp @@ -8,6 +8,7 @@ #include "singleapplication.h" #include "gpclient.h" #include "enhancedwebview.h" +#include "sigwatch.h" #include "version.h" int main(int argc, char *argv[]) @@ -40,5 +41,12 @@ int main(int argc, char *argv[]) QObject::connect(&app, &SingleApplication::instanceStarted, &w, &GPClient::activate); + UnixSignalWatcher sigwatch; + sigwatch.watchForSignal(SIGINT); + sigwatch.watchForSignal(SIGTERM); + sigwatch.watchForSignal(SIGQUIT); + sigwatch.watchForSignal(SIGHUP); + QObject::connect(&sigwatch, &UnixSignalWatcher::unixSignal, &w, &GPClient::quit); + return app.exec(); } diff --git a/GPService/CMakeLists.txt b/GPService/CMakeLists.txt index 69045de..8786f8e 100644 --- a/GPService/CMakeLists.txt +++ b/GPService/CMakeLists.txt @@ -5,7 +5,10 @@ project(GPService) set(gpservice_GENERATED_SOURCES) # generate the dbus xml definition -qt5_generate_dbus_interface(gpservice.h ${CMAKE_BINARY_DIR}/com.yuezk.qt.GPService.xml) +qt5_generate_dbus_interface( + gpservice.h + ${CMAKE_BINARY_DIR}/com.yuezk.qt.GPService.xml +) # generate dbus adaptor qt5_add_dbus_adaptor( @@ -18,7 +21,6 @@ qt5_add_dbus_adaptor( add_executable(gpservice gpservice.cpp main.cpp - sigwatch.cpp ${gpservice_GENERATED_SOURCES} ) @@ -53,6 +55,7 @@ target_link_libraries(gpservice Qt5::Core Qt5::Network Qt5::DBus + QtSignals ) target_compile_definitions(gpservice PUBLIC QAPPLICATION_CLASS=QCoreApplication) diff --git a/GPService/gpservice.cpp b/GPService/gpservice.cpp index 644847f..97306f5 100644 --- a/GPService/gpservice.cpp +++ b/GPService/gpservice.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "gpservice.h" #include "gpserviceadaptor.h" @@ -123,8 +122,6 @@ void GPService::connect(QString server, QString username, QString passwd, QStrin log("Start process with arugments: " + args.join(" ")); - log("ENV for OC: " + openconnect->environment().join("\n")); - log("ENV for gpservice: " + QProcessEnvironment::systemEnvironment().toStringList().join("\n")); openconnect->start(bin, args); } diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index aa3549f..b09fe02 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -13,10 +13,12 @@ package-repositories: ppa: dwmw2/openconnect layout: - /usr/share/vpnc-scripts: - bind: $SNAP/usr/share/vpnc-scripts /usr/local/sbin: bind: $SNAP/usr/sbin + /usr/share/vpnc-scripts: + bind: $SNAP/usr/share/vpnc-scripts + /usr/share/locale: + bind: $SNAP/usr/share/locale slots: gpservice-slot: @@ -37,7 +39,8 @@ apps: command-chain: - snap/command-chain/desktop-launch environment: - LANG: en_US.utf8 + LC_ALL: en_US.UTF-8 + LANG: en_US.UTF-8 plugs: - network slots: