From 35933327813cbe16add31d5bd0494df1dbb0ee96 Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Mon, 22 May 2017 23:24:18 +0200 Subject: [PATCH] Move code to ./src --- flameshot.pro | 54 +-- singleapplication | 1 - .../Qt-Color-Widgets}/COPYING | 0 .../Qt-Color-Widgets}/LICENSE-EXCEPTION | 0 .../Qt-Color-Widgets}/README.md | 0 .../Qt-Color-Widgets}/color_widgets.pri | 0 .../Qt-Color-Widgets}/color_widgets.pro | 0 .../Qt-Color-Widgets}/include/ColorWheel | 0 .../Qt-Color-Widgets}/include/color_wheel.hpp | 0 .../include/colorwidgets_global.hpp | 0 .../Qt-Color-Widgets}/src/alphaback.png | Bin .../Qt-Color-Widgets}/src/color_utils.cpp | 0 .../Qt-Color-Widgets}/src/color_utils.hpp | 0 .../Qt-Color-Widgets}/src/color_wheel.cpp | 0 .../Qt-Color-Widgets}/src/color_widgets.qrc | 0 {capture => src/capture}/button.cpp | 2 +- {capture => src/capture}/button.h | 1 - {capture => src/capture}/buttonhandler.cpp | 0 {capture => src/capture}/buttonhandler.h | 0 .../capture}/capturemodification.cpp | 0 .../capture}/capturemodification.h | 0 {capture => src/capture}/capturewidget.cpp | 2 +- {capture => src/capture}/capturewidget.h | 0 {capture => src/capture}/colorpicker.cpp | 0 {capture => src/capture}/colorpicker.h | 0 {capture => src/capture}/screenshot.cpp | 0 {capture => src/capture}/screenshot.h | 0 {config => src/config}/buttonlistview.cpp | 2 +- {config => src/config}/buttonlistview.h | 0 {config => src/config}/configwindow.cpp | 6 +- {config => src/config}/configwindow.h | 0 {config => src/config}/uicoloreditor.cpp | 2 +- {config => src/config}/uicoloreditor.h | 0 controller.cpp => src/controller.cpp | 0 controller.h => src/controller.h | 0 infowindow.cpp => src/infowindow.cpp | 0 infowindow.h => src/infowindow.h | 0 main.cpp => src/main.cpp | 0 .../nativeeventfilter.cpp | 0 .../nativeeventfilter.h | 0 src/singleapplication/CHANGELOG.md | 134 ++++++ src/singleapplication/LICENSE | 24 + src/singleapplication/README.md | 274 +++++++++++ .../examples/basic/basic.pro | 5 + src/singleapplication/examples/basic/main.cpp | 9 + .../examples/calculator/button.cpp | 73 +++ .../examples/calculator/button.h | 68 +++ .../examples/calculator/calculator.cpp | 406 ++++++++++++++++ .../examples/calculator/calculator.h | 117 +++++ .../examples/calculator/calculator.pro | 11 + .../examples/calculator/main.cpp | 71 +++ .../examples/sending_arguments/main.cpp | 25 + .../sending_arguments/messagereceiver.cpp | 12 + .../sending_arguments/messagereceiver.h | 15 + .../sending_arguments/sending_arguments.pro | 9 + src/singleapplication/singleapplication.cpp | 450 ++++++++++++++++++ src/singleapplication/singleapplication.h | 129 +++++ src/singleapplication/singleapplication.pri | 13 + src/singleapplication/singleapplication_p.h | 77 +++ 59 files changed, 1956 insertions(+), 36 deletions(-) delete mode 160000 singleapplication rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/COPYING (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/LICENSE-EXCEPTION (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/README.md (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/color_widgets.pri (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/color_widgets.pro (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/include/ColorWheel (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/include/color_wheel.hpp (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/include/colorwidgets_global.hpp (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/src/alphaback.png (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/src/color_utils.cpp (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/src/color_utils.hpp (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/src/color_wheel.cpp (100%) rename {Qt-Color-Widgets => src/Qt-Color-Widgets}/src/color_widgets.qrc (100%) rename {capture => src/capture}/button.cpp (99%) rename {capture => src/capture}/button.h (99%) rename {capture => src/capture}/buttonhandler.cpp (100%) rename {capture => src/capture}/buttonhandler.h (100%) rename {capture => src/capture}/capturemodification.cpp (100%) rename {capture => src/capture}/capturemodification.h (100%) rename {capture => src/capture}/capturewidget.cpp (99%) rename {capture => src/capture}/capturewidget.h (100%) rename {capture => src/capture}/colorpicker.cpp (100%) rename {capture => src/capture}/colorpicker.h (100%) rename {capture => src/capture}/screenshot.cpp (100%) rename {capture => src/capture}/screenshot.h (100%) rename {config => src/config}/buttonlistview.cpp (98%) rename {config => src/config}/buttonlistview.h (100%) rename {config => src/config}/configwindow.cpp (93%) rename {config => src/config}/configwindow.h (100%) rename {config => src/config}/uicoloreditor.cpp (98%) rename {config => src/config}/uicoloreditor.h (100%) rename controller.cpp => src/controller.cpp (100%) rename controller.h => src/controller.h (100%) rename infowindow.cpp => src/infowindow.cpp (100%) rename infowindow.h => src/infowindow.h (100%) rename main.cpp => src/main.cpp (100%) rename nativeeventfilter.cpp => src/nativeeventfilter.cpp (100%) rename nativeeventfilter.h => src/nativeeventfilter.h (100%) create mode 100644 src/singleapplication/CHANGELOG.md create mode 100644 src/singleapplication/LICENSE create mode 100644 src/singleapplication/README.md create mode 100755 src/singleapplication/examples/basic/basic.pro create mode 100755 src/singleapplication/examples/basic/main.cpp create mode 100644 src/singleapplication/examples/calculator/button.cpp create mode 100644 src/singleapplication/examples/calculator/button.h create mode 100644 src/singleapplication/examples/calculator/calculator.cpp create mode 100644 src/singleapplication/examples/calculator/calculator.h create mode 100644 src/singleapplication/examples/calculator/calculator.pro create mode 100644 src/singleapplication/examples/calculator/main.cpp create mode 100755 src/singleapplication/examples/sending_arguments/main.cpp create mode 100644 src/singleapplication/examples/sending_arguments/messagereceiver.cpp create mode 100644 src/singleapplication/examples/sending_arguments/messagereceiver.h create mode 100755 src/singleapplication/examples/sending_arguments/sending_arguments.pro create mode 100644 src/singleapplication/singleapplication.cpp create mode 100644 src/singleapplication/singleapplication.h create mode 100644 src/singleapplication/singleapplication.pri create mode 100644 src/singleapplication/singleapplication_p.h diff --git a/flameshot.pro b/flameshot.pro index b0c1f366..76e53fa0 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -27,38 +27,38 @@ DEFINES += QT_DEPRECATED_WARNINGS # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -include(singleapplication/singleapplication.pri) -include(Qt-Color-Widgets//color_widgets.pri) +include(src/singleapplication/singleapplication.pri) +include(src/Qt-Color-Widgets//color_widgets.pri) DEFINES += QAPPLICATION_CLASS=QApplication -SOURCES += main.cpp\ - nativeeventfilter.cpp \ - controller.cpp \ - capture/button.cpp \ - capture/buttonhandler.cpp \ - infowindow.cpp \ - config/configwindow.cpp \ - capture/screenshot.cpp \ - capture/capturewidget.cpp \ - capture/capturemodification.cpp \ - capture/colorpicker.cpp \ - config/buttonlistview.cpp \ - config/uicoloreditor.cpp +SOURCES += src/main.cpp\ + src/nativeeventfilter.cpp \ + src/controller.cpp \ + src/capture/button.cpp \ + src/capture/buttonhandler.cpp \ + src/infowindow.cpp \ + src/config/configwindow.cpp \ + src/capture/screenshot.cpp \ + src/capture/capturewidget.cpp \ + src/capture/capturemodification.cpp \ + src/capture/colorpicker.cpp \ + src/config/buttonlistview.cpp \ + src/config/uicoloreditor.cpp HEADERS += \ - nativeeventfilter.h \ - controller.h \ - capture/button.h \ - capture/buttonhandler.h \ - infowindow.h \ - config/configwindow.h \ - capture/screenshot.h \ - capture/capturewidget.h \ - capture/capturemodification.h \ - capture/colorpicker.h \ - config/buttonlistview.h \ - config/uicoloreditor.h + src/nativeeventfilter.h \ + src/controller.h \ + src/capture/button.h \ + src/capture/buttonhandler.h \ + src/infowindow.h \ + src/config/configwindow.h \ + src/capture/screenshot.h \ + src/capture/capturewidget.h \ + src/capture/capturemodification.h \ + src/capture/colorpicker.h \ + src/config/buttonlistview.h \ + src/config/uicoloreditor.h RESOURCES += \ graphics.qrc diff --git a/singleapplication b/singleapplication deleted file mode 160000 index 00a0da8b..00000000 --- a/singleapplication +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 00a0da8b00c97cc38951f0f21ce08fa69998cc72 diff --git a/Qt-Color-Widgets/COPYING b/src/Qt-Color-Widgets/COPYING similarity index 100% rename from Qt-Color-Widgets/COPYING rename to src/Qt-Color-Widgets/COPYING diff --git a/Qt-Color-Widgets/LICENSE-EXCEPTION b/src/Qt-Color-Widgets/LICENSE-EXCEPTION similarity index 100% rename from Qt-Color-Widgets/LICENSE-EXCEPTION rename to src/Qt-Color-Widgets/LICENSE-EXCEPTION diff --git a/Qt-Color-Widgets/README.md b/src/Qt-Color-Widgets/README.md similarity index 100% rename from Qt-Color-Widgets/README.md rename to src/Qt-Color-Widgets/README.md diff --git a/Qt-Color-Widgets/color_widgets.pri b/src/Qt-Color-Widgets/color_widgets.pri similarity index 100% rename from Qt-Color-Widgets/color_widgets.pri rename to src/Qt-Color-Widgets/color_widgets.pri diff --git a/Qt-Color-Widgets/color_widgets.pro b/src/Qt-Color-Widgets/color_widgets.pro similarity index 100% rename from Qt-Color-Widgets/color_widgets.pro rename to src/Qt-Color-Widgets/color_widgets.pro diff --git a/Qt-Color-Widgets/include/ColorWheel b/src/Qt-Color-Widgets/include/ColorWheel similarity index 100% rename from Qt-Color-Widgets/include/ColorWheel rename to src/Qt-Color-Widgets/include/ColorWheel diff --git a/Qt-Color-Widgets/include/color_wheel.hpp b/src/Qt-Color-Widgets/include/color_wheel.hpp similarity index 100% rename from Qt-Color-Widgets/include/color_wheel.hpp rename to src/Qt-Color-Widgets/include/color_wheel.hpp diff --git a/Qt-Color-Widgets/include/colorwidgets_global.hpp b/src/Qt-Color-Widgets/include/colorwidgets_global.hpp similarity index 100% rename from Qt-Color-Widgets/include/colorwidgets_global.hpp rename to src/Qt-Color-Widgets/include/colorwidgets_global.hpp diff --git a/Qt-Color-Widgets/src/alphaback.png b/src/Qt-Color-Widgets/src/alphaback.png similarity index 100% rename from Qt-Color-Widgets/src/alphaback.png rename to src/Qt-Color-Widgets/src/alphaback.png diff --git a/Qt-Color-Widgets/src/color_utils.cpp b/src/Qt-Color-Widgets/src/color_utils.cpp similarity index 100% rename from Qt-Color-Widgets/src/color_utils.cpp rename to src/Qt-Color-Widgets/src/color_utils.cpp diff --git a/Qt-Color-Widgets/src/color_utils.hpp b/src/Qt-Color-Widgets/src/color_utils.hpp similarity index 100% rename from Qt-Color-Widgets/src/color_utils.hpp rename to src/Qt-Color-Widgets/src/color_utils.hpp diff --git a/Qt-Color-Widgets/src/color_wheel.cpp b/src/Qt-Color-Widgets/src/color_wheel.cpp similarity index 100% rename from Qt-Color-Widgets/src/color_wheel.cpp rename to src/Qt-Color-Widgets/src/color_wheel.cpp diff --git a/Qt-Color-Widgets/src/color_widgets.qrc b/src/Qt-Color-Widgets/src/color_widgets.qrc similarity index 100% rename from Qt-Color-Widgets/src/color_widgets.qrc rename to src/Qt-Color-Widgets/src/color_widgets.qrc diff --git a/capture/button.cpp b/src/capture/button.cpp similarity index 99% rename from capture/button.cpp rename to src/capture/button.cpp index 47a69d5b..2c048695 100644 --- a/capture/button.cpp +++ b/src/capture/button.cpp @@ -16,7 +16,7 @@ // along with Flameshot. If not, see . #include "button.h" -#include "capture/capturewidget.h" +#include "src/capture/capturewidget.h" #include #include #include diff --git a/capture/button.h b/src/capture/button.h similarity index 99% rename from capture/button.h rename to src/capture/button.h index 850490a5..fd83ce75 100644 --- a/capture/button.h +++ b/src/capture/button.h @@ -20,7 +20,6 @@ #include #include -#include "button.h" class QWidget; class QPropertyAnimation; diff --git a/capture/buttonhandler.cpp b/src/capture/buttonhandler.cpp similarity index 100% rename from capture/buttonhandler.cpp rename to src/capture/buttonhandler.cpp diff --git a/capture/buttonhandler.h b/src/capture/buttonhandler.h similarity index 100% rename from capture/buttonhandler.h rename to src/capture/buttonhandler.h diff --git a/capture/capturemodification.cpp b/src/capture/capturemodification.cpp similarity index 100% rename from capture/capturemodification.cpp rename to src/capture/capturemodification.cpp diff --git a/capture/capturemodification.h b/src/capture/capturemodification.h similarity index 100% rename from capture/capturemodification.h rename to src/capture/capturemodification.h diff --git a/capture/capturewidget.cpp b/src/capture/capturewidget.cpp similarity index 99% rename from capture/capturewidget.cpp rename to src/capture/capturewidget.cpp index 96ce0b5f..12f5d387 100644 --- a/capture/capturewidget.cpp +++ b/src/capture/capturewidget.cpp @@ -25,7 +25,7 @@ #include "capturemodification.h" #include "capturewidget.h" #include "button.h" -#include "capture/colorpicker.h" +#include "src/capture/colorpicker.h" #include #include #include diff --git a/capture/capturewidget.h b/src/capture/capturewidget.h similarity index 100% rename from capture/capturewidget.h rename to src/capture/capturewidget.h diff --git a/capture/colorpicker.cpp b/src/capture/colorpicker.cpp similarity index 100% rename from capture/colorpicker.cpp rename to src/capture/colorpicker.cpp diff --git a/capture/colorpicker.h b/src/capture/colorpicker.h similarity index 100% rename from capture/colorpicker.h rename to src/capture/colorpicker.h diff --git a/capture/screenshot.cpp b/src/capture/screenshot.cpp similarity index 100% rename from capture/screenshot.cpp rename to src/capture/screenshot.cpp diff --git a/capture/screenshot.h b/src/capture/screenshot.h similarity index 100% rename from capture/screenshot.h rename to src/capture/screenshot.h diff --git a/config/buttonlistview.cpp b/src/config/buttonlistview.cpp similarity index 98% rename from config/buttonlistview.cpp rename to src/config/buttonlistview.cpp index 2714f707..373e5a72 100644 --- a/config/buttonlistview.cpp +++ b/src/config/buttonlistview.cpp @@ -16,7 +16,7 @@ // along with Flameshot. If not, see . #include "buttonlistview.h" -#include "capture/button.h" +#include "src/capture/button.h" #include #include #include diff --git a/config/buttonlistview.h b/src/config/buttonlistview.h similarity index 100% rename from config/buttonlistview.h rename to src/config/buttonlistview.h diff --git a/config/configwindow.cpp b/src/config/configwindow.cpp similarity index 93% rename from config/configwindow.cpp rename to src/config/configwindow.cpp index 31b678e1..d864efc9 100644 --- a/config/configwindow.cpp +++ b/src/config/configwindow.cpp @@ -16,9 +16,9 @@ // along with Flameshot. If not, see . #include "configwindow.h" -#include "capture/button.h" -#include "config/buttonlistview.h" -#include "config/uicoloreditor.h" +#include "src/capture/button.h" +#include "src/config/buttonlistview.h" +#include "src/config/uicoloreditor.h" #include #include #include diff --git a/config/configwindow.h b/src/config/configwindow.h similarity index 100% rename from config/configwindow.h rename to src/config/configwindow.h diff --git a/config/uicoloreditor.cpp b/src/config/uicoloreditor.cpp similarity index 98% rename from config/uicoloreditor.cpp rename to src/config/uicoloreditor.cpp index 826afbba..9e5a56a2 100644 --- a/config/uicoloreditor.cpp +++ b/src/config/uicoloreditor.cpp @@ -17,7 +17,7 @@ #include "uicoloreditor.h" #include "color_wheel.hpp" -#include "capture/button.h" +#include "src/capture/button.h" #include #include #include diff --git a/config/uicoloreditor.h b/src/config/uicoloreditor.h similarity index 100% rename from config/uicoloreditor.h rename to src/config/uicoloreditor.h diff --git a/controller.cpp b/src/controller.cpp similarity index 100% rename from controller.cpp rename to src/controller.cpp diff --git a/controller.h b/src/controller.h similarity index 100% rename from controller.h rename to src/controller.h diff --git a/infowindow.cpp b/src/infowindow.cpp similarity index 100% rename from infowindow.cpp rename to src/infowindow.cpp diff --git a/infowindow.h b/src/infowindow.h similarity index 100% rename from infowindow.h rename to src/infowindow.h diff --git a/main.cpp b/src/main.cpp similarity index 100% rename from main.cpp rename to src/main.cpp diff --git a/nativeeventfilter.cpp b/src/nativeeventfilter.cpp similarity index 100% rename from nativeeventfilter.cpp rename to src/nativeeventfilter.cpp diff --git a/nativeeventfilter.h b/src/nativeeventfilter.h similarity index 100% rename from nativeeventfilter.h rename to src/nativeeventfilter.h diff --git a/src/singleapplication/CHANGELOG.md b/src/singleapplication/CHANGELOG.md new file mode 100644 index 00000000..52a7c8bd --- /dev/null +++ b/src/singleapplication/CHANGELOG.md @@ -0,0 +1,134 @@ +Changelog +========= + +__3.0.7a__ +---------- + +* Fixed compilation error with Mingw32 in MXE thanks to Vitaly Tonkacheyev. +* Removed QMutex used for thread safe behaviour. The implementation now uses + QCoreApplication::instance() to get an instance to SingleApplication for + memory deallocation. + +__3.0.6a__ +---------- + +* Reverted GetUserName API usage on Windows. Fixed bug with missing library. +* Fixed bug in the Calculator example, preventing it's window to be raised + on Windows. + + Special thanks to Charles Gunawan. + +__3.0.5a__ +---------- + +* Fixed a memory leak in the SingleApplicationPrivate destructor. + + _Sergei Moiseev_ + +__3.0.4a__ +---------- + +* Fixed shadow and uninitialised variable warnings. + + _Paul Walmsley_ + +__3.0.3a__ +---------- + +* Removed Microsoft Windows specific code for getting username due to + multiple problems and compiler differences on Windows platforms. On + Windows the shared memory block in User mode now includes the user's + home path (which contains the user's username). + +* Explicitly getting absolute path of the user's home directory as on Unix + a relative path (`~`) may be returned. + +__3.0.2a__ +---------- + +* Fixed bug on Windows when username containing wide characters causes the + library to crash. + + _Le Liu_ + +__3.0.1a__ +---------- + +* Allows the application path and version to be excluded from the server name + hash. The following flags were added for this purpose: + * `SingleApplication::Mode::ExcludeAppVersion` + * `SingleApplication::Mode::ExcludeAppPath` +* Allow a non elevated process to connect to a local server created by an + elevated process run by the same user on Windows +* Fixes a problem with upper case letters in paths on Windows + + _Le Liu_ + +__v3.0a__ +--------- + +* Depricated secondary instances count. +* Added a sendMessage() method to send a message to the primary instance. +* Added a receivedMessage() signal, emitted when a message is received from a + secondary instance. +* The SingleApplication constructor's third parameter is now a bool + specifying if the current instance should be allowed to run as a secondary + instance if there is already a primary instance. +* The SingleApplication constructor accept a fourth parameter specifying if + the SingleApplication block should be User-wide or System-wide. +* SingleApplication no longer relies on `applicationName` and + `organizationName` to be set. It instead concatenates all of the following + data and computes a `SHA256` hash which is used as the key of the + `QSharedMemory` block and the `QLocalServer`. Since at least + `applicationFilePath` is always present there is no need to explicitly set + any of the following prior to initialising `SingleApplication`. + * `QCoreApplication::applicationName` + * `QCoreApplication::applicationVersion` + * `QCoreApplication::applicationFilePath` + * `QCoreApplication::organizationName` + * `QCoreApplication::organizationDomain` + * User name or home directory path if in User mode +* The primary instance is no longer notified when a secondary instance had + been started by default. A `Mode` flag for this feature exists. +* Added `instanceNumber()` which represents a unique identifier for each + secondary instance started. When called from the primary instance will + return `0`. + +__v2.4__ +-------- + +* Stability improvements +* Support for secondary instances. +* The library now recovers safely after the primary process has crashed +and the shared memory had not been deleted. + +__v2.3__ +-------- + +* Improved pimpl design and inheritance safety. + + _Vladislav Pyatnichenko_ + +__v2.2__ +-------- + +* The `QAPPLICATION_CLASS` macro can now be defined in the file including the +Single Application header or with a `DEFINES+=` statement in the project file. + +__v2.1__ +-------- + +* A race condition can no longer occur when starting two processes nearly + simultaneously. + + Fix issue [#3](https://github.com/itay-grudev/SingleApplication/issues/3) + +__v2.0__ +-------- + +* SingleApplication is now being passed a reference to `argc` instead of a + copy. + + Fix issue [#1](https://github.com/itay-grudev/SingleApplication/issues/1) + +* Improved documentation. diff --git a/src/singleapplication/LICENSE b/src/singleapplication/LICENSE new file mode 100644 index 00000000..85b2a149 --- /dev/null +++ b/src/singleapplication/LICENSE @@ -0,0 +1,24 @@ +The MIT License (MIT) + +Copyright (c) Itay Grudev 2015 - 2016 + +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. + +Note: Some of the examples include code not distributed under the terms of the +MIT License. diff --git a/src/singleapplication/README.md b/src/singleapplication/README.md new file mode 100644 index 00000000..e003ab45 --- /dev/null +++ b/src/singleapplication/README.md @@ -0,0 +1,274 @@ +SingleApplication +================= + +This is a replacement of the QtSingleApplication for `Qt5`. + +Keeps the Primary Instance of your Application and kills each subsequent +instances. It can (if enabled) spawn secondary (non-related to the primary) +instances and can send data to the primary instance from secondary instances. + +Usage +----- + +The `SingleApplication` class inherits from whatever `Q[Core|Gui]Application` +class you specify via the `QAPPLICATION_CLASS` macro (`QCoreApplication` is the +default). Further usage is similar to the use of the `Q[Core|Gui]Application` +classes. + +The library sets up a `QLocalServer` and a `QSharedMemory` block. The first +instance of your Application is your Primary Instance. It would check if the +shared memory block exists and if not it will start a `QLocalServer` and listen +for connections. Each subsequent instance of your application would check if the +shared memory block exists and if it does, it will connect to the QLocalServer +to notify the primary instance that a new instance had been started, after which +it would terminate with status code `0`. In the Primary Instance +`SingleApplication` would emit the `instanceStarted()` signal upon detecting +that a new instance had been started. + +The library uses `stdlib` to terminate the program with the `exit()` function. + +You can use the library as if you use any other `QCoreApplication` derived +class: + +```cpp +#include +#include + +int main( int argc, char* argv[] ) +{ + SingleApplication app( argc, argv ); + + return app.exec(); +} +``` + +To include the library files I would recommend that you add it as a git +submodule to your project and include it's contents with a `.pri` file. Here is +how: + +```bash +git submodule add git@github.com:itay-grudev/SingleApplication.git singleapplication +``` + +Then include the `singleapplication.pri` file in your `.pro` project file. Also +don't forget to specify which `QCoreApplication` class your app is using if it +is not `QCoreApplication`. + +```qmake +include(singleapplication/singleapplication.pri) +DEFINES += QAPPLICATION_CLASS=QApplication +``` + +The `Instance Started` signal +------------------------ + +The SingleApplication class implements a `instanceStarted()` signal. You can +bind to that signal to raise your application's window when a new instance had +been started, for example. + +```cpp +// window is a QWindow instance +QObject::connect( + &app, + &SingleApplication::instanceStarted, + &window, + &QWindow::raise +); +``` + +Using `SingleApplication::instance()` is a neat way to get the +`SingleApplication` instance for binding to it's signals anywhere in your +program. + +Secondary Instances +------------------- + +If you want to be able to launch additional Secondary Instances (not related to +your Primary Instance) you have to enable that with the third parameter of the +`SingleApplication` constructor. The default is `false` meaning no Secondary +Instances. Here is an example of how you would start a Secondary Instance send +a message with the command line arguments to the primary instance and then shut +down. + +```cpp +int main(int argc, char *argv[]) +{ + SingleApplication app( argc, argv, true ); + + if( app.isSecondary() ) { + app.sendMessage( app.arguments().join(' ')).toUtf8() ); + app.exit( 0 ); + } + + return app.exec(); +} +``` + +*__Note:__ A secondary instance won't cause the emission of the +`instanceStarted()` signal by default. See `SingleApplication::Mode` for more +details.* + +You can check whether your instance is a primary or secondary with the following +methods: + +```cpp +app.isPrimary(); +// or +app.isSecondary(); +``` + +*__Note:__ If your Primary Instance is terminated a newly launched instance +will replace the Primary one even if the Secondary flag has been set.* + +API +--- + +### Members + +```cpp +SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 100 ) +``` + +Depending on whether `allowSecondary` is set, this constructor may terminate +your app if there is already a primary instance running. Additional `Options` +can be specified to set whether the SingleApplication block should work +user-wide or system-wide. Additionally the `Mode::SecondaryNotification` may be +used to notify the primary instance whenever a secondary instance had been +started (disabled by default). `timeout` specifies the maximum time in +milliseconds to wait for blocking operations. + +*__Note:__ `argc` and `argv` may be changed as Qt removes arguments that it +recognizes.* + +*__Note:__ `Mode::SecondaryNotification` only works if set on both the primary +and the secondary instance.* + +*__Note:__ Operating system can restrict the shared memory blocks to the same +user, in which case the User/System modes will have no effect and the block will +be user wide.* + +--- + +```cpp +bool SingleApplication::sendMessage( QByteArray message, int timeout = 100 ) +``` + +Sends `message` to the Primary Instance. Uses `timeout` as a the maximum timeout +in milliseconds for blocking functions + +--- + +```cpp +bool SingleApplication::isPrimary() +``` + +Returns if the instance is the primary instance. + +--- + +```cpp +bool SingleApplication::isSecondary() +``` +Returns if the instance is a secondary instance. + +--- + +```cpp +quint32 SingleApplication::instanceId() +``` + +Returns a unique identifier for the current instance + +### Signals + +```cpp +void SingleApplication::instanceStarted() +``` + +Triggered whenever a new instance had been started, except for secondary +instances if the `Mode::SecondaryNotification` flag is not specified. + +--- + +```cpp +void SingleApplication::receivedMessage( quint32 instanceId, QByteArray message ) +``` + +Triggered whenever there is a message received from a secondary instance. + +--- + +### Flags + +```cpp +enum SingleApplication::Mode +``` + +* `Mode::User` - The SingleApplication block should apply user wide. This adds + user specific data to the key used for the shared memory and server name. + This is the default functionality. +* `Mode::System` – The SingleApplication block applies system-wide. +* `Mode::SecondaryNotification` – Whether to trigger `instanceStarted()` even + whenever secondary instances are started. +* `Mode::ExcludeAppPath` – Excludes the application path from the server name + (and memory block) hash. +* `Mode::ExcludeAppVersion` – Excludes the application version from the server + name (and memory block) hash. + +*__Note:__ `Mode::SecondaryNotification` only works if set on both the primary +and the secondary instance.* + +*__Note:__ Operating system can restrict the shared memory blocks to the same +user, in which case the User/System modes will have no effect and the block will +be user wide.* + +--- + +Versioning +---------- + +Each major version introduces either very significant changes or is not +backwards compatible with the previous version. Minor versions only add +additional features, bug fixes or performance improvements and are backwards +compatible with the previous release. See [`CHANGELOG.md`](CHANGELOG.md) for +more details. + +Implementation +-------------- + +The library is implemented with a QSharedMemory block which is thread safe and +guarantees a race condition will not occur. It also uses a QLocalSocket to +notify the main process that a new instance had been spawned and thus invoke the +`instanceStarted()` signal. + +To handle an issue on `*nix` systems, where the operating system owns the shared +memory block and if the program crashes the memory remains untouched, the +library binds to the following signals and closes the program with +`error code = 128 + signum` where signum is the number representation of the +signal listed below. Handling the signal is required in order to safely delete +the `QSharedMemory` block. Each of these signals are potentially lethal and will +results in process termination. + +* `SIGHUP` - `1`, Hangup. +* `SIGINT` - `2`, Terminal interrupt signal +* `SIGQUIT` - `3`, Terminal quit signal. +* `SIGILL` - `4`, Illegal instruction. +* `SIGABRT` - `6`, Process abort signal. +* `SIGBUS` - `7`, Access to an undefined portion of a memory object. +* `SIGFPE` - `8`, Erroneous arithmetic operation (such as division by zero). +* `SIGSEGV` - `11`, Invalid memory reference. +* `SIGSYS` - `12`, Bad system call. +* `SIGPIPE` - `13`, Write on a pipe with no one to read it. +* `SIGALRM` - `14`, Alarm clock. +* `SIGTERM` - `15`, Termination signal. +* `SIGXCPU` - `24`, CPU time limit exceeded. +* `SIGXFSZ` - `25`, File size limit exceeded. + +Additionally the library can recover from being killed with uncatchable signals +and will reset the memory block given that there are no other instances running. + +License +------- +This library and it's supporting documentation are released under +`The MIT License (MIT)` with the exception of some of the examples distributed +under the BSD license. diff --git a/src/singleapplication/examples/basic/basic.pro b/src/singleapplication/examples/basic/basic.pro new file mode 100755 index 00000000..b7af16cf --- /dev/null +++ b/src/singleapplication/examples/basic/basic.pro @@ -0,0 +1,5 @@ +# Single Application implementation +include(../../singleapplication.pri) +DEFINES += QAPPLICATION_CLASS=QCoreApplication + +SOURCES += main.cpp diff --git a/src/singleapplication/examples/basic/main.cpp b/src/singleapplication/examples/basic/main.cpp new file mode 100755 index 00000000..4787d1c5 --- /dev/null +++ b/src/singleapplication/examples/basic/main.cpp @@ -0,0 +1,9 @@ +#include + +int main(int argc, char *argv[]) +{ + // Allow secondary instances + SingleApplication app( argc, argv ); + + return app.exec(); +} diff --git a/src/singleapplication/examples/calculator/button.cpp b/src/singleapplication/examples/calculator/button.cpp new file mode 100644 index 00000000..d6cca0a0 --- /dev/null +++ b/src/singleapplication/examples/calculator/button.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "button.h" + +//! [0] +Button::Button(const QString &text, QWidget *parent) + : QToolButton(parent) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + setText(text); +} +//! [0] + +//! [1] +QSize Button::sizeHint() const +//! [1] //! [2] +{ + QSize size = QToolButton::sizeHint(); + size.rheight() += 20; + size.rwidth() = qMax(size.width(), size.height()); + return size; +} +//! [2] diff --git a/src/singleapplication/examples/calculator/button.h b/src/singleapplication/examples/calculator/button.h new file mode 100644 index 00000000..2c014c7b --- /dev/null +++ b/src/singleapplication/examples/calculator/button.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BUTTON_H +#define BUTTON_H + +#include + +//! [0] +class Button : public QToolButton +{ + Q_OBJECT + +public: + explicit Button(const QString &text, QWidget *parent = 0); + + QSize sizeHint() const Q_DECL_OVERRIDE; +}; +//! [0] + +#endif diff --git a/src/singleapplication/examples/calculator/calculator.cpp b/src/singleapplication/examples/calculator/calculator.cpp new file mode 100644 index 00000000..c02b5604 --- /dev/null +++ b/src/singleapplication/examples/calculator/calculator.cpp @@ -0,0 +1,406 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include + +#include "button.h" +#include "calculator.h" + +//! [0] +Calculator::Calculator(QWidget *parent) + : QWidget(parent) +{ + sumInMemory = 0.0; + sumSoFar = 0.0; + factorSoFar = 0.0; + waitingForOperand = true; +//! [0] + +//! [1] + display = new QLineEdit("0"); +//! [1] //! [2] + display->setReadOnly(true); + display->setAlignment(Qt::AlignRight); + display->setMaxLength(15); + + QFont font = display->font(); + font.setPointSize(font.pointSize() + 8); + display->setFont(font); +//! [2] + +//! [4] + for (int i = 0; i < NumDigitButtons; ++i) { + digitButtons[i] = createButton(QString::number(i), SLOT(digitClicked())); + } + + Button *pointButton = createButton(tr("."), SLOT(pointClicked())); + Button *changeSignButton = createButton(tr("\302\261"), SLOT(changeSignClicked())); + + Button *backspaceButton = createButton(tr("Backspace"), SLOT(backspaceClicked())); + Button *clearButton = createButton(tr("Clear"), SLOT(clear())); + Button *clearAllButton = createButton(tr("Clear All"), SLOT(clearAll())); + + Button *clearMemoryButton = createButton(tr("MC"), SLOT(clearMemory())); + Button *readMemoryButton = createButton(tr("MR"), SLOT(readMemory())); + Button *setMemoryButton = createButton(tr("MS"), SLOT(setMemory())); + Button *addToMemoryButton = createButton(tr("M+"), SLOT(addToMemory())); + + Button *divisionButton = createButton(tr("\303\267"), SLOT(multiplicativeOperatorClicked())); + Button *timesButton = createButton(tr("\303\227"), SLOT(multiplicativeOperatorClicked())); + Button *minusButton = createButton(tr("-"), SLOT(additiveOperatorClicked())); + Button *plusButton = createButton(tr("+"), SLOT(additiveOperatorClicked())); + + Button *squareRootButton = createButton(tr("Sqrt"), SLOT(unaryOperatorClicked())); + Button *powerButton = createButton(tr("x\302\262"), SLOT(unaryOperatorClicked())); + Button *reciprocalButton = createButton(tr("1/x"), SLOT(unaryOperatorClicked())); + Button *equalButton = createButton(tr("="), SLOT(equalClicked())); +//! [4] + +//! [5] + QGridLayout *mainLayout = new QGridLayout; +//! [5] //! [6] + mainLayout->setSizeConstraint(QLayout::SetFixedSize); + mainLayout->addWidget(display, 0, 0, 1, 6); + mainLayout->addWidget(backspaceButton, 1, 0, 1, 2); + mainLayout->addWidget(clearButton, 1, 2, 1, 2); + mainLayout->addWidget(clearAllButton, 1, 4, 1, 2); + + mainLayout->addWidget(clearMemoryButton, 2, 0); + mainLayout->addWidget(readMemoryButton, 3, 0); + mainLayout->addWidget(setMemoryButton, 4, 0); + mainLayout->addWidget(addToMemoryButton, 5, 0); + + for (int i = 1; i < NumDigitButtons; ++i) { + int row = ((9 - i) / 3) + 2; + int column = ((i - 1) % 3) + 1; + mainLayout->addWidget(digitButtons[i], row, column); + } + + mainLayout->addWidget(digitButtons[0], 5, 1); + mainLayout->addWidget(pointButton, 5, 2); + mainLayout->addWidget(changeSignButton, 5, 3); + + mainLayout->addWidget(divisionButton, 2, 4); + mainLayout->addWidget(timesButton, 3, 4); + mainLayout->addWidget(minusButton, 4, 4); + mainLayout->addWidget(plusButton, 5, 4); + + mainLayout->addWidget(squareRootButton, 2, 5); + mainLayout->addWidget(powerButton, 3, 5); + mainLayout->addWidget(reciprocalButton, 4, 5); + mainLayout->addWidget(equalButton, 5, 5); + setLayout(mainLayout); + + setWindowTitle(tr("Calculator")); +} +//! [6] + +//! [7] +void Calculator::digitClicked() +{ + Button *clickedButton = qobject_cast