Skip to content

Commit 4092f0c

Browse files
committed
Removed QtSingleApplication and switched over to my fork of SingleApplication.
1 parent 560d66a commit 4092f0c

19 files changed

+33
-1637
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "tools/UGlobalHotkey"]
22
path = tools/UGlobalHotkey
33
url = https://github.com/ckaiser/UGlobalHotkey.git
4+
[submodule "tools/SingleApplication"]
5+
path = tools/SingleApplication
6+
url = https://github.com/ckaiser/SingleApplication.git

lightscreen.pro

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ HEADERS += dialogs/areadialog.h \
1313
tools/windowpicker.h \
1414
updater/updater.h \
1515
widgets/hotkeywidget.h \
16-
tools/qtsingleapplication/qtlockedfile.h \
17-
tools/qtsingleapplication/qtsinglecoreapplication.h \
1816
tools/uploader/imageuploader.h \
1917
tools/uploader/imguruploader.h \
2018
tools/uploader/uploader.h
@@ -32,10 +30,6 @@ SOURCES += dialogs/areadialog.cpp \
3230
tools/windowpicker.cpp \
3331
updater/updater.cpp \
3432
widgets/hotkeywidget.cpp \
35-
tools/qtsingleapplication/qtlockedfile.cpp \
36-
tools/qtsingleapplication/qtlockedfile_unix.cpp \
37-
tools/qtsingleapplication/qtlockedfile_win.cpp \
38-
tools/qtsingleapplication/qtsinglecoreapplication.cpp \
3933
tools/uploader/imageuploader.cpp \
4034
tools/uploader/imguruploader.cpp \
4135
tools/uploader/uploader.cpp
@@ -47,9 +41,9 @@ RESOURCES += lightscreen.qrc
4741

4842
RC_FILE += lightscreen.rc
4943
CODECFORSRC = UTF-8
50-
QT += core gui network sql multimedia
44+
QT += core gui widgets network sql multimedia
5145

52-
include($$PWD/tools/qtsingleapplication/qtsingleapplication.pri)
46+
include($$PWD/tools/SingleApplication/singleapplication.pri)
5347
include($$PWD/tools/UGlobalHotkey/uglobalhotkey.pri)
5448

5549
windows {

lightscreenwindow.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
#include <QtWinExtras>
4040
#endif
4141

42-
/*
43-
* Lightscreen includes
44-
*/
42+
//
43+
//Lightscreen includes
44+
//
4545
#include "lightscreenwindow.h"
4646
#include "dialogs/optionsdialog.h"
4747
#include "dialogs/previewdialog.h"
@@ -344,21 +344,19 @@ void LightscreenWindow::messageClicked()
344344
}
345345
}
346346

347-
void LightscreenWindow::messageReceived(const QString &message)
347+
void LightscreenWindow::executeArgument(const QString &message)
348348
{
349349
if (message.contains(' ')) {
350350
foreach (QString argument, message.split(' ')) {
351-
messageReceived(argument);
351+
executeArgument(argument);
352352
}
353353
}
354354

355355
if (message == "--wake") {
356356
show();
357-
qApp->alert(this, 500);
358-
return;
359-
}
360-
361-
if (message == "--screen") {
357+
os::setForegroundWindow(this);
358+
qApp->alert(this, 2000);
359+
} else if (message == "--screen") {
362360
screenshotAction();
363361
} else if (message == "--area") {
364362
screenshotAction(2);
@@ -379,6 +377,19 @@ void LightscreenWindow::messageReceived(const QString &message)
379377
}
380378
}
381379

380+
void LightscreenWindow::executeArguments(const QStringList arguments)
381+
{
382+
// If we just have the default argument, call "--wake"
383+
if (arguments.count() == 1 && (arguments.at(0) == qApp->arguments().at(0) || arguments.at(0) == QFileInfo(qApp->applicationFilePath()).fileName())) {
384+
executeArgument("--wake");
385+
return;
386+
}
387+
388+
foreach (const QString argument, arguments) {
389+
executeArgument(argument);
390+
}
391+
}
392+
382393
void LightscreenWindow::notify(const Screenshot::Result &result)
383394
{
384395
switch (result) {

lightscreenwindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public slots:
5353
void createUploadMenu();
5454
void goToFolder();
5555
void messageClicked();
56-
void messageReceived(const QString &message);
56+
void executeArgument(const QString &message);
57+
void executeArguments(const QStringList arguments);
5758
void notify(const Screenshot::Result &result);
5859
void preview(Screenshot *screenshot);
5960
void quit();

main.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
#endif
2626

2727
#include "tools/os.h"
28-
#include <QtSingleApplication>
28+
#include "tools/SingleApplication/singleapplication.h"
29+
2930
#include "lightscreenwindow.h"
3031

3132
int main(int argc, char *argv[])
@@ -34,24 +35,12 @@ int main(int argc, char *argv[])
3435
qSetMessagePattern("%{message} @%{line}[%{function}()]");
3536
#endif
3637

37-
QtSingleApplication application(argc, argv);
38+
SingleApplication application(argc, argv);
3839
application.setOrganizationName("K");
3940
application.setApplicationName("Lightscreen");
4041
application.setApplicationVersion("2.2");
4142
application.setQuitOnLastWindowClosed(false);
4243

43-
if (application.isRunning()) {
44-
if (application.arguments().size() > 1) {
45-
QStringList arguments = application.arguments();
46-
arguments.removeFirst();
47-
application.sendMessage(arguments.join(" "));
48-
} else {
49-
application.sendMessage("--wake");
50-
}
51-
52-
return 0;
53-
}
54-
5544
LightscreenWindow lightscreen;
5645

5746
#ifdef Q_OS_WIN
@@ -89,14 +78,12 @@ int main(int argc, char *argv[])
8978
#endif
9079

9180
if (application.arguments().size() > 1) {
92-
foreach (QString argument, application.arguments()) {
93-
lightscreen.messageReceived(argument);
94-
}
81+
lightscreen.executeArguments(application.arguments());
9582
} else {
9683
lightscreen.show();
9784
}
9885

99-
QObject::connect(&application, SIGNAL(messageReceived(const QString &)), &lightscreen, SLOT(messageReceived(const QString &)));
86+
QObject::connect(&application, SIGNAL(instanceArguments(const QStringList)), &lightscreen, SLOT(executeArguments(const QStringList)));
10087
QObject::connect(&lightscreen, SIGNAL(finished()), &application, SLOT(quit()));
10188

10289
int result = application.exec();

tools/qtsingleapplication/QtLockedFile

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/qtsingleapplication/QtSingleApplication

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/qtsingleapplication/qtlocalpeer.cpp

Lines changed: 0 additions & 204 deletions
This file was deleted.

0 commit comments

Comments
 (0)