Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
104 KB
Referenced Files
None
Subscribers
None
diff --git a/.gitmodules b/.gitmodules
index 6bcd7e2..416f48b 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
[submodule "tools/UGlobalHotkey"]
path = tools/UGlobalHotkey
url = https://github.com/ckaiser/UGlobalHotkey.git
+[submodule "tools/SingleApplication"]
+ path = tools/SingleApplication
+ url = https://github.com/ckaiser/SingleApplication.git
diff --git a/lightscreen.pro b/lightscreen.pro
index 137bd9e..df17c3f 100644
--- a/lightscreen.pro
+++ b/lightscreen.pro
@@ -1,88 +1,82 @@
TEMPLATE = app
TARGET = lightscreen
HEADERS += dialogs/areadialog.h \
dialogs/historydialog.h \
dialogs/namingdialog.h \
dialogs/optionsdialog.h \
dialogs/previewdialog.h \
dialogs/updaterdialog.h \
lightscreenwindow.h \
tools/os.h \
tools/screenshot.h \
tools/screenshotmanager.h \
tools/windowpicker.h \
updater/updater.h \
widgets/hotkeywidget.h \
- tools/qtsingleapplication/qtlockedfile.h \
- tools/qtsingleapplication/qtsinglecoreapplication.h \
tools/uploader/imageuploader.h \
tools/uploader/imguruploader.h \
tools/uploader/uploader.h
SOURCES += dialogs/areadialog.cpp \
dialogs/historydialog.cpp \
dialogs/namingdialog.cpp \
dialogs/optionsdialog.cpp \
dialogs/previewdialog.cpp \
dialogs/updaterdialog.cpp \
lightscreenwindow.cpp \
main.cpp \
tools/os.cpp \
tools/screenshot.cpp \
tools/screenshotmanager.cpp \
tools/windowpicker.cpp \
updater/updater.cpp \
widgets/hotkeywidget.cpp \
- tools/qtsingleapplication/qtlockedfile.cpp \
- tools/qtsingleapplication/qtlockedfile_unix.cpp \
- tools/qtsingleapplication/qtlockedfile_win.cpp \
- tools/qtsingleapplication/qtsinglecoreapplication.cpp \
tools/uploader/imageuploader.cpp \
tools/uploader/imguruploader.cpp \
tools/uploader/uploader.cpp
FORMS += dialogs/historydialog.ui \
dialogs/namingdialog.ui \
dialogs/optionsdialog.ui \
lightscreenwindow.ui
RESOURCES += lightscreen.qrc
RC_FILE += lightscreen.rc
CODECFORSRC = UTF-8
-QT += core gui network sql multimedia
+QT += core gui widgets network sql multimedia
-include($$PWD/tools/qtsingleapplication/qtsingleapplication.pri)
+include($$PWD/tools/SingleApplication/singleapplication.pri)
include($$PWD/tools/UGlobalHotkey/uglobalhotkey.pri)
windows {
QT += winextras
contains(QMAKE_CC, gcc){
LIBS += libgdi32 libgcc libuser32 libole32 libshell32 libshlwapi libcomctl32
QMAKE_CXXFLAGS = -Wextra -Wall -Wpointer-arith
}
contains(QMAKE_CC, cl){
LIBS += gdi32.lib user32.lib ole32.lib shell32.lib shlwapi.lib comctl32.lib
}
CONFIG += embed_manifest_exe
QMAKE_LFLAGS_WINDOWS += /SUBSYSTEM:WINDOWS,5.01
QMAKE_LFLAGS_WINDOWS += /MANIFESTUAC:level=\'asInvoker\'
QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.01
DEFINES += _ATL_XP_TARGETING
QMAKE_CFLAGS += /D _USING_V110_SDK71
QMAKE_CXXFLAGS += /D _USING_V110_SDK71
}
unix:LIBS += -lX11
unix:QT += x11extras
OTHER_FILES += TODO.txt
diff --git a/lightscreenwindow.cpp b/lightscreenwindow.cpp
index 3040ed6..b45d8b7 100644
--- a/lightscreenwindow.cpp
+++ b/lightscreenwindow.cpp
@@ -1,1033 +1,1044 @@
/*
* Copyright (C) 2016 Christian Kaiser
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <QDate>
#include <QDesktopServices>
#include <QDesktopWidget>
#include <QFileInfo>
#include <QKeyEvent>
#include <QMainWindow>
#include <QMenu>
#include <QMessageBox>
#include <QPointer>
#include <QProcess>
#include <QSettings>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QToolTip>
#include <QUrl>
#include <QSound>
#include <QKeyEvent>
#ifdef Q_OS_WIN
#include <windows.h>
#include <QtWinExtras>
#endif
-/*
- * Lightscreen includes
- */
+//
+//Lightscreen includes
+//
#include "lightscreenwindow.h"
#include "dialogs/optionsdialog.h"
#include "dialogs/previewdialog.h"
#include "dialogs/historydialog.h"
#include "tools/os.h"
#include "tools/screenshot.h"
#include "tools/screenshotmanager.h"
#include "tools/UGlobalHotkey/uglobalhotkeys.h"
#include "tools/uploader/uploader.h"
#include "updater/updater.h"
LightscreenWindow::LightscreenWindow(QWidget *parent) :
QMainWindow(parent),
mDoCache(false),
mHideTrigger(false),
mReviveMain(false),
mWasVisible(true),
mLastMessage(0),
mLastMode(-1),
mLastScreenshot(),
mHasTaskbarButton(false)
{
ui.setupUi(this);
ui.screenPushButton->setIcon(os::icon("screen.big"));
ui.areaPushButton->setIcon(os::icon("area.big"));
ui.windowPushButton->setIcon(os::icon("pickWindow.big"));
ui.optionsPushButton->setIcon(os::icon("configure"));
ui.folderPushButton->setIcon(os::icon("folder"));
ui.imgurPushButton->setIcon(os::icon("imgur"));
createUploadMenu();
#ifdef Q_OS_WIN
if (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS7) {
mTaskbarButton = new QWinTaskbarButton(this);
mHasTaskbarButton = true;
if (QtWin::isCompositionEnabled()) {
setAttribute(Qt::WA_NoSystemBackground);
QtWin::enableBlurBehindWindow(this);
QtWin::extendFrameIntoClientArea(this, QMargins(-1, -1, -1, -1));
}
}
if (QSysInfo::WindowsVersion < QSysInfo::WV_WINDOWS7) {
ui.centralWidget->setStyleSheet("QPushButton { padding: 2px; border: 1px solid #acacac; background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 #eaeaea, stop:1 #e5e5e5);} QPushButton:hover { border: 1px solid #7eb4ea; background-color: #e4f0fc; }");
}
#endif
setMaximumSize(size());
setMinimumSize(size());
setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint);
// Actions
connect(ui.screenPushButton, SIGNAL(clicked()), this, SLOT(screenshotAction()));
connect(ui.areaPushButton , SIGNAL(clicked()), this, SLOT(areaHotkey()));
connect(ui.windowPushButton, SIGNAL(clicked()), this, SLOT(windowPickerHotkey()));
connect(ui.optionsPushButton, SIGNAL(clicked()), this, SLOT(showOptions()));
connect(ui.folderPushButton , SIGNAL(clicked()), this, SLOT(goToFolder()));
// Shortcuts
mGlobalHotkeys = new UGlobalHotkeys(this);
connect(mGlobalHotkeys, &UGlobalHotkeys::activated, [&](size_t id) {
if (id <= 3) {
screenshotAction(id);
} else if (id == 4) {
show();
} else if (id == 5) {
goToFolder();
} else {
qWarning() << "Uknown hotkey ID: " << id;
}
});
// Uploader
connect(Uploader::instance(), SIGNAL(progress(int)), this, SLOT(uploadProgress(int)));
connect(Uploader::instance(), SIGNAL(done(QString, QString, QString)), this, SLOT(showUploaderMessage(QString, QString)));
connect(Uploader::instance(), SIGNAL(error(QString)), this, SLOT(showUploaderError(QString)));
// Manager
connect(ScreenshotManager::instance(), SIGNAL(confirm(Screenshot *)), this, SLOT(preview(Screenshot *)));
connect(ScreenshotManager::instance(), SIGNAL(windowCleanup(Screenshot::Options &)), this, SLOT(cleanup(Screenshot::Options &)));
connect(ScreenshotManager::instance(), SIGNAL(activeCountChange()), this, SLOT(updateStatus()));
if (!settings()->contains("file/format")) {
showOptions(); // There are no options (or the options config is invalid or incomplete)
} else {
QTimer::singleShot(0 , this, SLOT(applySettings()));
QTimer::singleShot(5000, this, SLOT(checkForUpdates()));
}
}
LightscreenWindow::~LightscreenWindow()
{
settings()->setValue("lastScreenshot", mLastScreenshot);
settings()->sync();
mGlobalHotkeys->unregisterAllHotkeys();
}
void LightscreenWindow::action(int mode)
{
if (mode == 4) {
goToFolder();
} else {
show();
}
}
void LightscreenWindow::areaHotkey()
{
screenshotAction(2);
}
void LightscreenWindow::checkForUpdates()
{
if (settings()->value("options/disableUpdater", false).toBool()) {
return;
}
if (settings()->value("lastUpdateCheck").toInt() + 7
> QDate::currentDate().dayOfYear()) {
return; // If 7 days have not passed since the last update check.
}
mUpdater = new Updater(this);
connect(mUpdater, SIGNAL(done(bool)), this, SLOT(updaterDone(bool)));
mUpdater->check();
}
void LightscreenWindow::cleanup(Screenshot::Options &options)
{
// Reversing settings
if (settings()->value("options/hide").toBool()) {
#ifndef Q_OS_LINUX // X is not quick enough and the notification ends up everywhere but in the icon
if (settings()->value("options/tray").toBool() && mTrayIcon) {
mTrayIcon->show();
}
#endif
if (mPreviewDialog) {
if (mPreviewDialog->count() <= 1 && mWasVisible) {
show();
}
mPreviewDialog->show();
} else if (mWasVisible) {
show();
}
mHideTrigger = false;
}
if (settings()->value("options/tray").toBool() && mTrayIcon) {
notify(options.result);
if (settings()->value("options/message").toBool() && options.file && !options.upload) {
// This message wll get shown only when messages are enabled and the file won't get another upload pop-up soon.
showScreenshotMessage(options.result, options.fileName);
}
}
if (settings()->value("options/playSound", false).toBool()) {
if (options.result == Screenshot::Success) {
QSound::play("sounds/ls.screenshot.wav");
} else {
#ifdef Q_OS_WIN
QSound::play("afakepathtomakewindowsplaythedefaultsoundtheresprobablyabetterwaybuticantbebothered");
#else
QSound::play("sound/ls.error.wav");
#endif
}
}
updateStatus();
if (options.result != Screenshot::Success) {
return;
}
mLastScreenshot = options.fileName;
}
void LightscreenWindow::closeToTrayWarning()
{
if (!settings()->value("options/closeToTrayWarning", true).toBool()) {
return;
}
mLastMessage = 3;
mTrayIcon->showMessage(tr("Closed to tray"), tr("Lightscreen will keep running, you can disable this in the options menu."));
settings()->setValue("options/closeToTrayWarning", false);
}
bool LightscreenWindow::closingWithoutTray()
{
if (settings()->value("options/disableHideAlert", false).toBool()) {
return false;
}
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Lightscreen"));
msgBox.setText(tr("You have chosen to hide Lightscreen when there's no system tray icon, so you will not be able to access the program <b>unless you have selected a hotkey to do so</b>.<br>What do you want to do?"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStyleSheet("QPushButton { padding: 4px 8px; }");
QPushButton *enableButton = msgBox.addButton(tr("Hide but enable tray"),
QMessageBox::ActionRole);
QPushButton *enableAndDenotifyButton = msgBox.addButton(tr("Hide and don't warn"),
QMessageBox::ActionRole);
QPushButton *hideButton = msgBox.addButton(tr("Just hide"),
QMessageBox::ActionRole);
QPushButton *abortButton = msgBox.addButton(QMessageBox::Cancel);
Q_UNUSED(abortButton);
msgBox.exec();
if (msgBox.clickedButton() == hideButton) {
return true;
} else if (msgBox.clickedButton() == enableAndDenotifyButton) {
settings()->setValue("options/disableHideAlert", true);
applySettings();
return true;
} else if (msgBox.clickedButton() == enableButton) {
settings()->setValue("options/tray", true);
applySettings();
return true;
}
return false; // Cancel.
}
void LightscreenWindow::createUploadMenu()
{
QMenu *imgurMenu = new QMenu(tr("Upload"));
QAction *uploadAction = new QAction(os::icon("imgur"), tr("&Upload last"), imgurMenu);
uploadAction->setToolTip(tr("Upload the last screenshot you took to imgur.com"));
connect(uploadAction, SIGNAL(triggered()), this, SLOT(uploadLast()));
QAction *cancelAction = new QAction(os::icon("no"), tr("&Cancel upload"), imgurMenu);
cancelAction->setToolTip(tr("Cancel the currently uploading screenshots"));
cancelAction->setEnabled(false);
connect(this, SIGNAL(uploading(bool)), cancelAction, SLOT(setEnabled(bool)));
connect(cancelAction, SIGNAL(triggered()), this, SLOT(uploadCancel()));
QAction *historyAction = new QAction(os::icon("view-history"), tr("View &History"), imgurMenu);
connect(historyAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog()));
imgurMenu->addAction(uploadAction);
imgurMenu->addAction(cancelAction);
imgurMenu->addAction(historyAction);
imgurMenu->addSeparator();
connect(imgurMenu, SIGNAL(aboutToShow()), this, SLOT(uploadMenuShown()));
ui.imgurPushButton->setMenu(imgurMenu);
}
void LightscreenWindow::goToFolder()
{
#ifdef Q_OS_WIN
if (!mLastScreenshot.isEmpty() && QFile::exists(mLastScreenshot)) {
QProcess::startDetached("explorer /select, \"" + mLastScreenshot + "\"");
} else {
#endif
QDir path(settings()->value("file/target").toString());
// We might want to go to the folder without it having been created by taking a screenshot yet.
if (!path.exists()) {
path.mkpath(path.absolutePath());
}
QDesktopServices::openUrl(QUrl::fromLocalFile(path.absolutePath() + QDir::separator()));
#ifdef Q_OS_WIN
}
#endif
}
void LightscreenWindow::messageClicked()
{
if (mLastMessage == 1) {
goToFolder();
} else if (mLastMessage == 3) {
QTimer::singleShot(0, this, SLOT(showOptions()));
} else {
QDesktopServices::openUrl(QUrl(Uploader::instance()->lastUrl()));
}
}
-void LightscreenWindow::messageReceived(const QString &message)
+void LightscreenWindow::executeArgument(const QString &message)
{
if (message.contains(' ')) {
foreach (QString argument, message.split(' ')) {
- messageReceived(argument);
+ executeArgument(argument);
}
}
if (message == "--wake") {
show();
- qApp->alert(this, 500);
- return;
- }
-
- if (message == "--screen") {
+ os::setForegroundWindow(this);
+ qApp->alert(this, 2000);
+ } else if (message == "--screen") {
screenshotAction();
} else if (message == "--area") {
screenshotAction(2);
} else if (message == "--activewindow") {
screenshotAction(1);
} else if (message == "--pickwindow") {
screenshotAction(3);
} else if (message == "--folder") {
action(4);
} else if (message == "--uploadlast") {
uploadLast();
} else if (message == "--viewhistory") {
showHistoryDialog();
} else if (message == "--options") {
showOptions();
} else if (message == "--quit") {
qApp->quit();
}
}
+void LightscreenWindow::executeArguments(const QStringList arguments)
+{
+ // If we just have the default argument, call "--wake"
+ if (arguments.count() == 1 && (arguments.at(0) == qApp->arguments().at(0) || arguments.at(0) == QFileInfo(qApp->applicationFilePath()).fileName())) {
+ executeArgument("--wake");
+ return;
+ }
+
+ foreach (const QString argument, arguments) {
+ executeArgument(argument);
+ }
+}
+
void LightscreenWindow::notify(const Screenshot::Result &result)
{
switch (result) {
case Screenshot::Success:
mTrayIcon->setIcon(QIcon(":/icons/lightscreen.yes"));
if (mHasTaskbarButton) {
mTaskbarButton->setOverlayIcon(os::icon("yes"));
}
setWindowTitle(tr("Success!"));
break;
case Screenshot::Fail:
mTrayIcon->setIcon(QIcon(":/icons/lightscreen.no"));
setWindowTitle(tr("Failed!"));
if (mHasTaskbarButton) {
mTaskbarButton->setOverlayIcon(os::icon("no"));
}
break;
case Screenshot::Cancel:
setWindowTitle(tr("Cancelled!"));
break;
}
QTimer::singleShot(2000, this, SLOT(restoreNotification()));
}
void LightscreenWindow::preview(Screenshot *screenshot)
{
if (screenshot->options().preview) {
if (!mPreviewDialog) {
mPreviewDialog = new PreviewDialog(this);
}
mPreviewDialog->add(screenshot);
} else {
screenshot->confirm(true);
}
}
void LightscreenWindow::quit()
{
settings()->setValue("position", pos());
int answer = 0;
QString doing;
if (ScreenshotManager::instance()->activeCount() > 0) {
doing = tr("processing");
}
if (Uploader::instance()->uploading() > 0) {
if (doing.isEmpty()) {
doing = tr("uploading");
} else {
doing = tr("processing and uploading");
}
}
if (!doing.isEmpty()) {
answer = QMessageBox::question(this,
tr("Are you sure you want to quit?"),
tr("Lightscreen is currently %1 screenshots. Are you sure you want to quit?").arg(doing),
tr("Quit"),
tr("Don't Quit"));
}
if (answer == 0) {
emit finished();
}
}
void LightscreenWindow::restoreNotification()
{
if (mTrayIcon) {
mTrayIcon->setIcon(QIcon(":/icons/lightscreen.small"));
}
if (mHasTaskbarButton) {
mTaskbarButton->clearOverlayIcon();
mTaskbarButton->progress()->setVisible(false);
mTaskbarButton->progress()->stop();
mTaskbarButton->progress()->reset();
}
updateStatus();
}
void LightscreenWindow::screenshotAction(int mode)
{
int delayms = -1;
bool optionsHide = settings()->value("options/hide").toBool(); // Option cache, used a couple of times.
if (!mHideTrigger) {
mWasVisible = isVisible();
mHideTrigger = true;
}
// Applying pre-screenshot settings
if (optionsHide) {
hide();
#ifndef Q_OS_LINUX // X is not quick enough and the notification ends up everywhere but in the icon
if (mTrayIcon) {
mTrayIcon->hide();
}
#endif
}
// Screenshot delay
delayms = settings()->value("options/delay", 0).toInt();
delayms = delayms * 1000; // Converting the delay to milliseconds.
delayms += 400;
if (optionsHide && mPreviewDialog) {
if (mPreviewDialog->count() >= 1) {
mPreviewDialog->hide();
}
}
// The delayed functions works using the static variable lastMode
// which keeps the argument so a QTimer can call this function again.
if (delayms > 0) {
if (mLastMode < 0) {
mLastMode = mode;
QTimer::singleShot(delayms, this, SLOT(screenshotAction()));
return;
} else {
mode = mLastMode;
mLastMode = -1;
}
}
static Screenshot::Options options;
if (!mDoCache) {
// Populating the option object that will then be passed to the screenshot engine (sounds fancy huh?)
options.file = settings()->value("file/enabled").toBool();
options.format = (Screenshot::Format) settings()->value("file/format").toInt();
options.prefix = settings()->value("file/prefix").toString();
QDir dir(settings()->value("file/target").toString());
dir.makeAbsolute();
options.directory = dir;
options.quality = settings()->value("options/quality", 100).toInt();
options.currentMonitor = settings()->value("options/currentMonitor", false).toBool();
options.clipboard = settings()->value("options/clipboard", true).toBool();
options.imgurClipboard = settings()->value("options/imgurClipboard", false).toBool();
options.preview = settings()->value("options/preview", false).toBool();
options.magnify = settings()->value("options/magnify", false).toBool();
options.cursor = settings()->value("options/cursor", true).toBool();
options.saveAs = settings()->value("options/saveAs", false).toBool();
options.animations = settings()->value("options/animations", true).toBool();
options.replace = settings()->value("options/replace", false).toBool();
options.upload = settings()->value("options/uploadAuto", false).toBool();
options.optimize = settings()->value("options/optipng", false).toBool();
Screenshot::NamingOptions namingOptions;
namingOptions.naming = (Screenshot::Naming) settings()->value("file/naming").toInt();
namingOptions.leadingZeros = settings()->value("options/naming/leadingZeros", 0).toInt();
namingOptions.flip = settings()->value("options/flip", false).toBool();
namingOptions.dateFormat = settings()->value("options/naming/dateFormat", "yyyy-MM-dd").toString();
options.namingOptions = namingOptions;
mDoCache = true;
}
options.mode = mode;
ScreenshotManager::instance()->take(options);
}
void LightscreenWindow::screenshotActionTriggered(QAction *action)
{
screenshotAction(action->data().toInt());
}
void LightscreenWindow::screenHotkey()
{
screenshotAction(0);
}
void LightscreenWindow::showHotkeyError(const QStringList &hotkeys)
{
static bool dontShow = false;
if (dontShow) {
return;
}
QString messageText;
messageText = tr("Some hotkeys could not be registered, they might already be in use");
if (hotkeys.count() > 1) {
messageText += tr("<br>The failed hotkeys are the following:") + "<ul>";
foreach (const QString &hotkey, hotkeys) {
messageText += QString("%1%2%3").arg("<li><b>").arg(hotkey).arg("</b></li>");
}
messageText += "</ul>";
} else {
messageText += tr("<br>The failed hotkey is <b>%1</b>").arg(hotkeys[0]);
}
messageText += tr("<br><i>What do you want to do?</i>");
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Lightscreen"));
msgBox.setText(messageText);
QPushButton *changeButton = msgBox.addButton(tr("Change") , QMessageBox::ActionRole);
QPushButton *disableButton = msgBox.addButton(tr("Disable"), QMessageBox::ActionRole);
QPushButton *exitButton = msgBox.addButton(tr("Quit") , QMessageBox::ActionRole);
msgBox.exec();
if (msgBox.clickedButton() == exitButton) {
dontShow = true;
QTimer::singleShot(10, this, SLOT(quit()));
} else if (msgBox.clickedButton() == changeButton) {
showOptions();
} else if (msgBox.clickedButton() == disableButton) {
foreach (const QString &hotkey, hotkeys) {
settings()->setValue(QString("actions/%1/enabled").arg(hotkey), false);
}
}
}
void LightscreenWindow::showHistoryDialog()
{
HistoryDialog historyDialog(this);
historyDialog.exec();
updateStatus();
}
void LightscreenWindow::showOptions()
{
mGlobalHotkeys->unregisterAllHotkeys();
QPointer<OptionsDialog> optionsDialog = new OptionsDialog(this);
optionsDialog->exec();
optionsDialog->deleteLater();
applySettings();
}
void LightscreenWindow::showScreenshotMessage(const Screenshot::Result &result, const QString &fileName)
{
if (result == Screenshot::Cancel) {
return;
}
// Showing message.
QString title;
QString message;
if (result == Screenshot::Success) {
title = QFileInfo(fileName).fileName();
if (settings()->value("file/target").toString().isEmpty()) {
message = QDir::toNativeSeparators(QCoreApplication::applicationDirPath());
} else {
message = tr("Saved to \"%1\"").arg(settings()->value("file/target").toString());
}
} else {
title = tr("The screenshot was not taken");
message = tr("An error occurred.");
}
mLastMessage = 1;
mTrayIcon->showMessage(title, message);
}
void LightscreenWindow::showUploaderError(const QString &error)
{
mLastMessage = -1;
updateStatus();
if (mTrayIcon && !error.isEmpty() && settings()->value("options/message").toBool()) {
mTrayIcon->showMessage(tr("Upload error"), error);
}
notify(Screenshot::Fail);
}
void LightscreenWindow::showUploaderMessage(const QString &fileName, const QString &url)
{
if (mTrayIcon && settings()->value("options/message").toBool() && !url.isEmpty()) {
QString screenshot = QFileInfo(fileName).fileName();
if (screenshot.startsWith(".lstemp.")) {
screenshot = tr("Screenshot");
}
mLastMessage = 2;
mTrayIcon->showMessage(tr("%1 uploaded").arg(screenshot), tr("Click here to go to %1").arg(url));
}
updateStatus();
}
void LightscreenWindow::toggleVisibility(QSystemTrayIcon::ActivationReason reason)
{
if (reason != QSystemTrayIcon::DoubleClick) {
return;
}
if (isVisible()) {
hide();
} else {
show();
os::setForegroundWindow(this);
}
}
void LightscreenWindow::updateStatus()
{
int uploadCount = Uploader::instance()->uploading();
int activeCount = ScreenshotManager::instance()->activeCount();
if (mHasTaskbarButton) {
mTaskbarButton->progress()->setPaused(true);
mTaskbarButton->progress()->setVisible(true);
}
if (uploadCount > 0) {
setStatus(tr("%1 uploading").arg(uploadCount));
if (mHasTaskbarButton) {
mTaskbarButton->progress()->setRange(0, 100);
mTaskbarButton->progress()->resume();
}
emit uploading(true);
} else {
if (activeCount > 1) {
setStatus(tr("%1 processing").arg(activeCount));
} else if (activeCount == 1) {
setStatus(tr("processing"));
} else {
setStatus();
if (mHasTaskbarButton) {
mTaskbarButton->progress()->setVisible(false);
}
}
emit uploading(false);
}
}
void LightscreenWindow::updaterDone(bool result)
{
settings()->setValue("lastUpdateCheck", QDate::currentDate().dayOfYear());
if (!result) {
return;
}
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Lightscreen"));
msgBox.setText(tr("There's a new version of Lightscreen available.<br>Would you like to see more information?<br>(<em>You can turn this notification off</em>)"));
msgBox.setIcon(QMessageBox::Information);
QPushButton *yesButton = msgBox.addButton(QMessageBox::Yes);
QPushButton *turnOffButton = msgBox.addButton(tr("Turn Off"), QMessageBox::ActionRole);
QPushButton *remindButton = msgBox.addButton(tr("Remind Me Later"), QMessageBox::RejectRole);
Q_UNUSED(remindButton);
msgBox.exec();
if (msgBox.clickedButton() == yesButton) {
QDesktopServices::openUrl(QUrl("https://lightscreen.com.ar/whatsnew?from=" + qApp->applicationVersion()));
} else if (msgBox.clickedButton() == turnOffButton) {
settings()->setValue("options/disableUpdater", true);
}
mUpdater->deleteLater();
}
void LightscreenWindow::upload(const QString &fileName)
{
Uploader::instance()->upload(fileName);
}
void LightscreenWindow::uploadCancel()
{
if (Uploader::instance()->uploading() <= 0) {
return;
}
int confirm = QMessageBox::question(this, tr("Upload cancel"), tr("Do you want to cancel all screenshot uploads?"), tr("Cancel"), tr("Don't Cancel"));
if (confirm == 0) {
Uploader::instance()->cancel();
updateStatus();
}
}
void LightscreenWindow::uploadLast()
{
upload(mLastScreenshot);
updateStatus();
}
void LightscreenWindow::uploadProgress(int progress)
{
if (mHasTaskbarButton) {
mTaskbarButton->progress()->setVisible(true);
mTaskbarButton->progress()->setValue(progress);
}
if (isVisible() && progress > 0) {
int uploadCount = Uploader::instance()->uploading();
if (uploadCount > 1) {
setWindowTitle(tr("%1% of %2 uploads - Lightscreen").arg(progress).arg(uploadCount));
} else {
setWindowTitle(tr("%1% - Lightscreen").arg(progress));
}
}
}
void LightscreenWindow::uploadMenuShown()
{
QMenu *imgurMenu = qobject_cast<QMenu *>(sender());
imgurMenu->actions().at(0)->setEnabled(!mLastScreenshot.isEmpty());
}
void LightscreenWindow::windowHotkey()
{
screenshotAction(1);
}
void LightscreenWindow::windowPickerHotkey()
{
screenshotAction(3);
}
void LightscreenWindow::applySettings()
{
bool tray = settings()->value("options/tray", true).toBool();
if (tray && !mTrayIcon) {
createTrayIcon();
mTrayIcon->setVisible(true);
} else if (!tray && mTrayIcon) {
mTrayIcon->setVisible(false);
}
connectHotkeys();
mDoCache = false;
if (settings()->value("lastScreenshot").isValid() && mLastScreenshot.isEmpty()) {
mLastScreenshot = settings()->value("lastScreenshot").toString();
}
os::setStartup(settings()->value("options/startup").toBool(), settings()->value("options/startupHide").toBool());
}
void LightscreenWindow::connectHotkeys()
{
QStringList failed;
QStringList actions = {"screen", "window", "area", "windowPicker", "open", "directory"};
size_t i = 0;
foreach (const QString &action, actions) {
if (settings()->value("actions/" + action + "/enabled").toBool()) {
if (!mGlobalHotkeys->registerHotkey(settings()->value("actions/" + action + "/hotkey").toString(), i)) {
failed << action;
}
}
i++;
}
if (!failed.isEmpty()) {
showHotkeyError(failed);
}
}
void LightscreenWindow::createTrayIcon()
{
mTrayIcon = new QSystemTrayIcon(QIcon(":/icons/lightscreen.small"), this);
updateStatus();
connect(mTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason)));
connect(mTrayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
QAction *hideAction = new QAction(QIcon(":/icons/lightscreen.small"), tr("Show&/Hide"), mTrayIcon);
connect(hideAction, SIGNAL(triggered()), this, SLOT(toggleVisibility()));
QAction *screenAction = new QAction(os::icon("screen"), tr("&Screen"), mTrayIcon);
screenAction->setData(QVariant(0));
QAction *windowAction = new QAction(os::icon("window"), tr("Active &Window"), this);
windowAction->setData(QVariant(1));
QAction *windowPickerAction = new QAction(os::icon("pickWindow"), tr("&Pick Window"), this);
windowPickerAction->setData(QVariant(3));
QAction *areaAction = new QAction(os::icon("area"), tr("&Area"), mTrayIcon);
areaAction->setData(QVariant(2));
QActionGroup *screenshotGroup = new QActionGroup(mTrayIcon);
screenshotGroup->addAction(screenAction);
screenshotGroup->addAction(areaAction);
screenshotGroup->addAction(windowAction);
screenshotGroup->addAction(windowPickerAction);
connect(screenshotGroup, SIGNAL(triggered(QAction *)), this, SLOT(screenshotActionTriggered(QAction *)));
// Duplicated for the screenshot button :(
QAction *uploadAction = new QAction(os::icon("imgur"), tr("&Upload last"), mTrayIcon);
uploadAction->setToolTip(tr("Upload the last screenshot you took to imgur.com"));
connect(uploadAction, SIGNAL(triggered()), this, SLOT(uploadLast()));
QAction *cancelAction = new QAction(os::icon("no"), tr("&Cancel upload"), mTrayIcon);
cancelAction->setToolTip(tr("Cancel the currently uploading screenshots"));
cancelAction->setEnabled(false);
connect(this, SIGNAL(uploading(bool)), cancelAction, SLOT(setEnabled(bool)));
connect(cancelAction, SIGNAL(triggered()), this, SLOT(uploadCancel()));
QAction *historyAction = new QAction(os::icon("view-history"), tr("View History"), mTrayIcon);
connect(historyAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog()));
//
QAction *optionsAction = new QAction(os::icon("configure"), tr("View &Options"), mTrayIcon);
connect(optionsAction, SIGNAL(triggered()), this, SLOT(showOptions()));
QAction *goAction = new QAction(os::icon("folder"), tr("&Go to Folder"), mTrayIcon);
connect(goAction, SIGNAL(triggered()), this, SLOT(goToFolder()));
QAction *quitAction = new QAction(tr("&Quit"), mTrayIcon);
connect(quitAction, SIGNAL(triggered()), this, SLOT(quit()));
QMenu *screenshotMenu = new QMenu(tr("Screenshot"));
screenshotMenu->addAction(screenAction);
screenshotMenu->addAction(areaAction);
screenshotMenu->addAction(windowAction);
screenshotMenu->addAction(windowPickerAction);
// Duplicated for the screenshot button :(
QMenu *imgurMenu = new QMenu(tr("Upload"));
imgurMenu->addAction(uploadAction);
imgurMenu->addAction(cancelAction);
imgurMenu->addAction(historyAction);
imgurMenu->addSeparator();
QMenu *trayIconMenu = new QMenu;
trayIconMenu->addAction(hideAction);
trayIconMenu->addSeparator();
trayIconMenu->addMenu(imgurMenu);
trayIconMenu->addSeparator();
trayIconMenu->addMenu(screenshotMenu);
trayIconMenu->addAction(optionsAction);
trayIconMenu->addAction(goAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
mTrayIcon->setContextMenu(trayIconMenu);
}
void LightscreenWindow::setStatus(QString status)
{
if (status.isEmpty()) {
status = tr("Lightscreen");
} else {
status += tr(" - Lightscreen");
}
if (mTrayIcon) {
mTrayIcon->setToolTip(status);
}
setWindowTitle(status);
}
QSettings *LightscreenWindow::settings() const
{
return ScreenshotManager::instance()->settings();
}
// Event handling
bool LightscreenWindow::event(QEvent *event)
{
if (event->type() == QEvent::Show) {
QPoint savedPosition = settings()->value("position").toPoint();
if (!savedPosition.isNull() && qApp->desktop()->availableGeometry().contains(QRect(savedPosition, size()))) {
move(savedPosition);
}
if (mHasTaskbarButton) {
mTaskbarButton->setWindow(windowHandle());
}
} else if (event->type() == QEvent::Hide) {
settings()->setValue("position", pos());
} else if (event->type() == QEvent::Close) {
if (settings()->value("options/tray").toBool() && settings()->value("options/closeHide").toBool()) {
closeToTrayWarning();
hide();
} else if (settings()->value("options/closeHide").toBool()) {
if (closingWithoutTray()) {
hide();
}
} else {
quit();
}
} else if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
#ifdef Q_WS_MAC
if (keyEvent->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period) {
keyEvent->ignore();
if (isVisible()) {
toggleVisibility();
}
return false;
} else
#endif
if (!keyEvent->modifiers() && keyEvent->key() == Qt::Key_Escape) {
keyEvent->ignore();
if (isVisible()) {
toggleVisibility();
}
return false;
}
} else if (event->type() == QEvent::LanguageChange) {
ui.retranslateUi(this);
resize(minimumSizeHint());
}
return QMainWindow::event(event);
}
diff --git a/lightscreenwindow.h b/lightscreenwindow.h
index 75bbb75..5e576d7 100644
--- a/lightscreenwindow.h
+++ b/lightscreenwindow.h
@@ -1,149 +1,150 @@
/*
* Copyright (C) 2016 Christian Kaiser
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef LIGHTSCREENWINDOW_H
#define LIGHTSCREENWINDOW_H
#include <QMainWindow>
#include <QPointer>
#include <QSystemTrayIcon>
#include "updater/updater.h"
#include "tools/screenshot.h"
#include "dialogs/previewdialog.h"
#include "ui_lightscreenwindow.h"
class Updater;
class QSettings;
class QProgressBar;
class QWinTaskbarButton;
class UGlobalHotkeys;
class LightscreenWindow : public QMainWindow
{
Q_OBJECT
public:
LightscreenWindow(QWidget *parent = 0);
~LightscreenWindow();
public slots:
void action(int mode = 3);
void areaHotkey();
void checkForUpdates();
void cleanup(Screenshot::Options &options);
void closeToTrayWarning();
bool closingWithoutTray();
void createUploadMenu();
void goToFolder();
void messageClicked();
- void messageReceived(const QString &message);
+ void executeArgument(const QString &message);
+ void executeArguments(const QStringList arguments);
void notify(const Screenshot::Result &result);
void preview(Screenshot *screenshot);
void quit();
void restoreNotification();
void setStatus(QString status = "");
void screenshotAction(int mode = 0);
void screenshotActionTriggered(QAction *action);
void screenHotkey();
void showHotkeyError(const QStringList &hotkeys);
void showHistoryDialog();
void showOptions();
void showScreenshotMessage(const Screenshot::Result &result, const QString &fileName);
void showUploaderError(const QString &error);
void showUploaderMessage(const QString &fileName, const QString &url);
void toggleVisibility(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::DoubleClick);
void updateStatus();
void updaterDone(bool result);
void upload(const QString &fileName);
void uploadCancel();
void uploadLast();
void uploadProgress(int progress);
void uploadMenuShown();
void windowHotkey();
void windowPickerHotkey();
private slots:
void applySettings();
signals:
void uploading(bool uploading);
void finished();
private:
void connectHotkeys();
void createTrayIcon();
#ifdef Q_OS_WIN
bool winEvent(MSG *message, long *result);
#endif
// Convenience function
QSettings *settings() const;
protected:
bool event(QEvent *event);
private:
bool mDoCache;
bool mHideTrigger;
bool mReviveMain;
bool mWasVisible;
int mLastMessage;
int mLastMode;
QString mLastScreenshot;
QPointer<QSystemTrayIcon> mTrayIcon;
QPointer<PreviewDialog> mPreviewDialog;
QPointer<Updater> mUpdater;
Ui::LightscreenWindowClass ui;
QPointer<UGlobalHotkeys> mGlobalHotkeys;
bool mHasTaskbarButton;
#ifdef Q_OS_WIN
QPointer<QWinTaskbarButton> mTaskbarButton;
#else
class QWinTaskbarProgressDummy
{
public:
void setVisible(bool v) { Q_UNUSED(v) }
void setPaused(bool p) { Q_UNUSED(p) }
void resume() {}
void stop() {}
void reset() {}
void setRange(int m, int m2) { Q_UNUSED(m) Q_UNUSED(m2) }
void setValue(int v) { Q_UNUSED(v) }
};
class QWinTaskbarDummy : public QObject
{
public:
void setOverlayIcon(QIcon i) { Q_UNUSED(i) }
void clearOverlayIcon() {}
QWinTaskbarProgressDummy *progress() { return 0; }
void setWindow(QWindow *w) { Q_UNUSED(w) }
};
QWinTaskbarDummy *mTaskbarButton;
#endif
};
#endif // LIGHTSCREENWINDOW_H
diff --git a/main.cpp b/main.cpp
index 5dd8afb..4cfbffd 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,104 +1,91 @@
/*
* Copyright (C) 2016 Christian Kaiser
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <QApplication>
#include <QDesktopWidget>
#include <QLocale>
#ifdef Q_OS_WIN
#include <QtWinExtras>
#endif
#include "tools/os.h"
-#include <QtSingleApplication>
+#include "tools/SingleApplication/singleapplication.h"
+
#include "lightscreenwindow.h"
int main(int argc, char *argv[])
{
#ifdef QT_DEBUG
qSetMessagePattern("%{message} @%{line}[%{function}()]");
#endif
- QtSingleApplication application(argc, argv);
+ SingleApplication application(argc, argv);
application.setOrganizationName("K");
application.setApplicationName("Lightscreen");
application.setApplicationVersion("2.2");
application.setQuitOnLastWindowClosed(false);
- if (application.isRunning()) {
- if (application.arguments().size() > 1) {
- QStringList arguments = application.arguments();
- arguments.removeFirst();
- application.sendMessage(arguments.join(" "));
- } else {
- application.sendMessage("--wake");
- }
-
- return 0;
- }
-
LightscreenWindow lightscreen;
#ifdef Q_OS_WIN
if (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS7) {
QWinJumpList *jumplist = new QWinJumpList(&lightscreen);
QColor backgroundColor = qApp->palette("QToolTip").color(QPalette::Background);
if (QSysInfo::WindowsVersion == QSysInfo::WV_WINDOWS10) {
// contrast r hard
backgroundColor = Qt::black;
}
QWinJumpListCategory *screenshotCategory = new QWinJumpListCategory("Screenshot");
screenshotCategory->setVisible(true);
screenshotCategory->addLink(os::icon("screen", backgroundColor), QObject::tr("Screen") , application.applicationFilePath(), QStringList("--screen"));
screenshotCategory->addLink(os::icon("area", backgroundColor), QObject::tr("Area") , application.applicationFilePath(), QStringList("--area"));
screenshotCategory->addLink(os::icon("pickWindow", backgroundColor), QObject::tr("Pick Window") , application.applicationFilePath(), QStringList("--pickwindow"));
QWinJumpListCategory *uploadCategory = new QWinJumpListCategory("Upload");
uploadCategory->setVisible(true);
uploadCategory->addLink(os::icon("imgur", backgroundColor), QObject::tr("Upload Last") , application.applicationFilePath(), QStringList("--uploadlast"));
uploadCategory->addLink(os::icon("view-history", backgroundColor), QObject::tr("View History") , application.applicationFilePath(), QStringList("--viewhistory"));
QWinJumpListCategory *actionsCategory = new QWinJumpListCategory("Actions");
actionsCategory->setVisible(true);
actionsCategory->addLink(os::icon("configure", backgroundColor), QObject::tr("Options") , application.applicationFilePath(), QStringList("--options"));
actionsCategory->addLink(os::icon("folder", backgroundColor), QObject::tr("Go to Folder") , application.applicationFilePath(), QStringList("--folder"));
actionsCategory->addLink(os::icon("no.big", backgroundColor), QObject::tr("Quit Lightscreen") , application.applicationFilePath(), QStringList("--quit"));
jumplist->addCategory(screenshotCategory);
jumplist->addCategory(uploadCategory);
jumplist->addCategory(actionsCategory);
}
#endif
if (application.arguments().size() > 1) {
- foreach (QString argument, application.arguments()) {
- lightscreen.messageReceived(argument);
- }
+ lightscreen.executeArguments(application.arguments());
} else {
lightscreen.show();
}
- QObject::connect(&application, SIGNAL(messageReceived(const QString &)), &lightscreen, SLOT(messageReceived(const QString &)));
+ QObject::connect(&application, SIGNAL(instanceArguments(const QStringList)), &lightscreen, SLOT(executeArguments(const QStringList)));
QObject::connect(&lightscreen, SIGNAL(finished()), &application, SLOT(quit()));
int result = application.exec();
return result;
}
diff --git a/tools/qtsingleapplication/QtLockedFile b/tools/qtsingleapplication/QtLockedFile
deleted file mode 100644
index 16b48ba..0000000
--- a/tools/qtsingleapplication/QtLockedFile
+++ /dev/null
@@ -1 +0,0 @@
-#include "qtlockedfile.h"
diff --git a/tools/qtsingleapplication/QtSingleApplication b/tools/qtsingleapplication/QtSingleApplication
deleted file mode 100644
index d111bf7..0000000
--- a/tools/qtsingleapplication/QtSingleApplication
+++ /dev/null
@@ -1 +0,0 @@
-#include "qtsingleapplication.h"
diff --git a/tools/qtsingleapplication/qtlocalpeer.cpp b/tools/qtsingleapplication/qtlocalpeer.cpp
deleted file mode 100644
index 19914f4..0000000
--- a/tools/qtsingleapplication/qtlocalpeer.cpp
+++ /dev/null
@@ -1,204 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Solutions component.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 Digia Plc and its Subsidiary(-ies) 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 "qtlocalpeer.h"
-#include <QCoreApplication>
-#include <QTime>
-#include <QDataStream>
-
-#if defined(Q_OS_WIN)
-#include <QLibrary>
-#include <qt_windows.h>
-typedef BOOL(WINAPI*PProcessIdToSessionId)(DWORD,DWORD*);
-static PProcessIdToSessionId pProcessIdToSessionId = 0;
-#endif
-#if defined(Q_OS_UNIX)
-#include <sys/types.h>
-#include <time.h>
-#include <unistd.h>
-#endif
-
-namespace QtLP_Private {
-#include "qtlockedfile.cpp"
-#if defined(Q_OS_WIN)
-#include "qtlockedfile_win.cpp"
-#else
-#include "qtlockedfile_unix.cpp"
-#endif
-}
-
-const char* QtLocalPeer::ack = "ack";
-
-QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId)
- : QObject(parent), id(appId)
-{
- QString prefix = id;
- if (id.isEmpty()) {
- id = QCoreApplication::applicationFilePath();
-#if defined(Q_OS_WIN)
- id = id.toLower();
-#endif
- prefix = id.section(QLatin1Char('/'), -1);
- }
- prefix.remove(QRegExp("[^a-zA-Z]"));
- prefix.truncate(6);
-
- QByteArray idc = id.toUtf8();
- quint16 idNum = qChecksum(idc.constData(), idc.size());
- socketName = QLatin1String("qtsingleapp-") + prefix
- + QLatin1Char('-') + QString::number(idNum, 16);
-
-#if defined(Q_OS_WIN)
- if (!pProcessIdToSessionId) {
- QLibrary lib("kernel32");
- pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId");
- }
- if (pProcessIdToSessionId) {
- DWORD sessionId = 0;
- pProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
- socketName += QLatin1Char('-') + QString::number(sessionId, 16);
- }
-#else
- socketName += QLatin1Char('-') + QString::number(::getuid(), 16);
-#endif
-
- server = new QLocalServer(this);
- QString lockName = QDir(QDir::tempPath()).absolutePath()
- + QLatin1Char('/') + socketName
- + QLatin1String("-lockfile");
- lockFile.setFileName(lockName);
- lockFile.open(QIODevice::ReadWrite);
-}
-
-
-
-bool QtLocalPeer::isClient()
-{
- if (lockFile.isLocked())
- return false;
-
- if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false))
- return true;
-
- bool res = server->listen(socketName);
-#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0))
- // ### Workaround
- if (!res && server->serverError() == QAbstractSocket::AddressInUseError) {
- QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName);
- res = server->listen(socketName);
- }
-#endif
- if (!res)
- qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString()));
- QObject::connect(server, SIGNAL(newConnection()), SLOT(receiveConnection()));
- return false;
-}
-
-
-bool QtLocalPeer::sendMessage(const QString &message, int timeout)
-{
- if (!isClient())
- return false;
-
- QLocalSocket socket;
- bool connOk = false;
- for(int i = 0; i < 2; i++) {
- // Try twice, in case the other instance is just starting up
- socket.connectToServer(socketName);
- connOk = socket.waitForConnected(timeout/2);
- if (connOk || i)
- break;
- int ms = 250;
-#if defined(Q_OS_WIN)
- Sleep(DWORD(ms));
-#else
- struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
- nanosleep(&ts, NULL);
-#endif
- }
- if (!connOk)
- return false;
-
- QByteArray uMsg(message.toUtf8());
- QDataStream ds(&socket);
- ds.writeBytes(uMsg.constData(), uMsg.size());
- bool res = socket.waitForBytesWritten(timeout);
- if (res) {
- res &= socket.waitForReadyRead(timeout); // wait for ack
- if (res)
- res &= (socket.read(qstrlen(ack)) == ack);
- }
- return res;
-}
-
-
-void QtLocalPeer::receiveConnection()
-{
- QLocalSocket* socket = server->nextPendingConnection();
- if (!socket)
- return;
-
- while (socket->bytesAvailable() < (int)sizeof(quint32))
- socket->waitForReadyRead();
- QDataStream ds(socket);
- QByteArray uMsg;
- quint32 remaining;
- ds >> remaining;
- uMsg.resize(remaining);
- int got = 0;
- char* uMsgBuf = uMsg.data();
- do {
- got = ds.readRawData(uMsgBuf, remaining);
- remaining -= got;
- uMsgBuf += got;
- } while (remaining && got >= 0 && socket->waitForReadyRead(2000));
- if (got < 0) {
- qWarning("QtLocalPeer: Message reception failed %s", socket->errorString().toLatin1().constData());
- delete socket;
- return;
- }
- QString message(QString::fromUtf8(uMsg));
- socket->write(ack, qstrlen(ack));
- socket->waitForBytesWritten(1000);
- socket->waitForDisconnected(1000); // make sure client reads ack
- delete socket;
- emit messageReceived(message); //### (might take a long time to return)
-}
diff --git a/tools/qtsingleapplication/qtlocalpeer.h b/tools/qtsingleapplication/qtlocalpeer.h
deleted file mode 100644
index 1b533b1..0000000
--- a/tools/qtsingleapplication/qtlocalpeer.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Solutions component.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 Digia Plc and its Subsidiary(-ies) 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 QTLOCALPEER_H
-#define QTLOCALPEER_H
-
-#include <QLocalServer>
-#include <QLocalSocket>
-#include <QDir>
-
-#include "qtlockedfile.h"
-
-class QtLocalPeer : public QObject
-{
- Q_OBJECT
-
-public:
- QtLocalPeer(QObject *parent = 0, const QString &appId = QString());
- bool isClient();
- bool sendMessage(const QString &message, int timeout);
- QString applicationId() const
- { return id; }
-
-Q_SIGNALS:
- void messageReceived(const QString &message);
-
-protected Q_SLOTS:
- void receiveConnection();
-
-protected:
- QString id;
- QString socketName;
- QLocalServer* server;
- QtLP_Private::QtLockedFile lockFile;
-
-private:
- static const char* ack;
-};
-
-#endif // QTLOCALPEER_H
diff --git a/tools/qtsingleapplication/qtlockedfile.cpp b/tools/qtsingleapplication/qtlockedfile.cpp
deleted file mode 100644
index c142a86..0000000
--- a/tools/qtsingleapplication/qtlockedfile.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Solutions component.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 Digia Plc and its Subsidiary(-ies) 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 "qtlockedfile.h"
-
-/*!
- \class QtLockedFile
-
- \brief The QtLockedFile class extends QFile with advisory locking
- functions.
-
- A file may be locked in read or write mode. Multiple instances of
- \e QtLockedFile, created in multiple processes running on the same
- machine, may have a file locked in read mode. Exactly one instance
- may have it locked in write mode. A read and a write lock cannot
- exist simultaneously on the same file.
-
- The file locks are advisory. This means that nothing prevents
- another process from manipulating a locked file using QFile or
- file system functions offered by the OS. Serialization is only
- guaranteed if all processes that access the file use
- QLockedFile. Also, while holding a lock on a file, a process
- must not open the same file again (through any API), or locks
- can be unexpectedly lost.
-
- The lock provided by an instance of \e QtLockedFile is released
- whenever the program terminates. This is true even when the
- program crashes and no destructors are called.
-*/
-
-/*! \enum QtLockedFile::LockMode
-
- This enum describes the available lock modes.
-
- \value ReadLock A read lock.
- \value WriteLock A write lock.
- \value NoLock Neither a read lock nor a write lock.
-*/
-
-/*!
- Constructs an unlocked \e QtLockedFile object. This constructor
- behaves in the same way as \e QFile::QFile().
-
- \sa QFile::QFile()
-*/
-QtLockedFile::QtLockedFile()
- : QFile()
-{
-#ifdef Q_OS_WIN
- wmutex = 0;
- rmutex = 0;
-#endif
- m_lock_mode = NoLock;
-}
-
-/*!
- Constructs an unlocked QtLockedFile object with file \a name. This
- constructor behaves in the same way as \e QFile::QFile(const
- QString&).
-
- \sa QFile::QFile()
-*/
-QtLockedFile::QtLockedFile(const QString &name)
- : QFile(name)
-{
-#ifdef Q_OS_WIN
- wmutex = 0;
- rmutex = 0;
-#endif
- m_lock_mode = NoLock;
-}
-
-/*!
- Opens the file in OpenMode \a mode.
-
- This is identical to QFile::open(), with the one exception that the
- Truncate mode flag is disallowed. Truncation would conflict with the
- advisory file locking, since the file would be modified before the
- write lock is obtained. If truncation is required, use resize(0)
- after obtaining the write lock.
-
- Returns true if successful; otherwise false.
-
- \sa QFile::open(), QFile::resize()
-*/
-bool QtLockedFile::open(OpenMode mode)
-{
- if (mode & QIODevice::Truncate) {
- qWarning("QtLockedFile::open(): Truncate mode not allowed.");
- return false;
- }
- return QFile::open(mode);
-}
-
-/*!
- Returns \e true if this object has a in read or write lock;
- otherwise returns \e false.
-
- \sa lockMode()
-*/
-bool QtLockedFile::isLocked() const
-{
- return m_lock_mode != NoLock;
-}
-
-/*!
- Returns the type of lock currently held by this object, or \e
- QtLockedFile::NoLock.
-
- \sa isLocked()
-*/
-QtLockedFile::LockMode QtLockedFile::lockMode() const
-{
- return m_lock_mode;
-}
-
-/*!
- \fn bool QtLockedFile::lock(LockMode mode, bool block = true)
-
- Obtains a lock of type \a mode. The file must be opened before it
- can be locked.
-
- If \a block is true, this function will block until the lock is
- aquired. If \a block is false, this function returns \e false
- immediately if the lock cannot be aquired.
-
- If this object already has a lock of type \a mode, this function
- returns \e true immediately. If this object has a lock of a
- different type than \a mode, the lock is first released and then a
- new lock is obtained.
-
- This function returns \e true if, after it executes, the file is
- locked by this object, and \e false otherwise.
-
- \sa unlock(), isLocked(), lockMode()
-*/
-
-/*!
- \fn bool QtLockedFile::unlock()
-
- Releases a lock.
-
- If the object has no lock, this function returns immediately.
-
- This function returns \e true if, after it executes, the file is
- not locked by this object, and \e false otherwise.
-
- \sa lock(), isLocked(), lockMode()
-*/
-
-/*!
- \fn QtLockedFile::~QtLockedFile()
-
- Destroys the \e QtLockedFile object. If any locks were held, they
- are released.
-*/
diff --git a/tools/qtsingleapplication/qtlockedfile.h b/tools/qtsingleapplication/qtlockedfile.h
deleted file mode 100644
index 84c18e5..0000000
--- a/tools/qtsingleapplication/qtlockedfile.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Solutions component.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 Digia Plc and its Subsidiary(-ies) 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 QTLOCKEDFILE_H
-#define QTLOCKEDFILE_H
-
-#include <QFile>
-#ifdef Q_OS_WIN
-#include <QVector>
-#endif
-
-#if defined(Q_OS_WIN)
-# if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT)
-# define QT_QTLOCKEDFILE_EXPORT
-# elif defined(QT_QTLOCKEDFILE_IMPORT)
-# if defined(QT_QTLOCKEDFILE_EXPORT)
-# undef QT_QTLOCKEDFILE_EXPORT
-# endif
-# define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport)
-# elif defined(QT_QTLOCKEDFILE_EXPORT)
-# undef QT_QTLOCKEDFILE_EXPORT
-# define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport)
-# endif
-#else
-# define QT_QTLOCKEDFILE_EXPORT
-#endif
-
-namespace QtLP_Private {
-
-class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile
-{
-public:
- enum LockMode { NoLock = 0, ReadLock, WriteLock };
-
- QtLockedFile();
- QtLockedFile(const QString &name);
- ~QtLockedFile();
-
- bool open(OpenMode mode);
-
- bool lock(LockMode mode, bool block = true);
- bool unlock();
- bool isLocked() const;
- LockMode lockMode() const;
-
-private:
-#ifdef Q_OS_WIN
- Qt::HANDLE wmutex;
- Qt::HANDLE rmutex;
- QVector<Qt::HANDLE> rmutexes;
- QString mutexname;
-
- Qt::HANDLE getMutexHandle(int idx, bool doCreate);
- bool waitMutex(Qt::HANDLE mutex, bool doBlock);
-
-#endif
- LockMode m_lock_mode;
-};
-}
-#endif
diff --git a/tools/qtsingleapplication/qtlockedfile_unix.cpp b/tools/qtsingleapplication/qtlockedfile_unix.cpp
deleted file mode 100644
index 976c1b9..0000000
--- a/tools/qtsingleapplication/qtlockedfile_unix.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Solutions component.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 Digia Plc and its Subsidiary(-ies) 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 <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include "qtlockedfile.h"
-
-bool QtLockedFile::lock(LockMode mode, bool block)
-{
- if (!isOpen()) {
- qWarning("QtLockedFile::lock(): file is not opened");
- return false;
- }
-
- if (mode == NoLock)
- return unlock();
-
- if (mode == m_lock_mode)
- return true;
-
- if (m_lock_mode != NoLock)
- unlock();
-
- struct flock fl;
- fl.l_whence = SEEK_SET;
- fl.l_start = 0;
- fl.l_len = 0;
- fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK;
- int cmd = block ? F_SETLKW : F_SETLK;
- int ret = fcntl(handle(), cmd, &fl);
-
- if (ret == -1) {
- if (errno != EINTR && errno != EAGAIN)
- qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
- return false;
- }
-
-
- m_lock_mode = mode;
- return true;
-}
-
-
-bool QtLockedFile::unlock()
-{
- if (!isOpen()) {
- qWarning("QtLockedFile::unlock(): file is not opened");
- return false;
- }
-
- if (!isLocked())
- return true;
-
- struct flock fl;
- fl.l_whence = SEEK_SET;
- fl.l_start = 0;
- fl.l_len = 0;
- fl.l_type = F_UNLCK;
- int ret = fcntl(handle(), F_SETLKW, &fl);
-
- if (ret == -1) {
- qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
- return false;
- }
-
- m_lock_mode = NoLock;
- return true;
-}
-
-QtLockedFile::~QtLockedFile()
-{
- if (isOpen())
- unlock();
-}
-
diff --git a/tools/qtsingleapplication/qtlockedfile_win.cpp b/tools/qtsingleapplication/qtlockedfile_win.cpp
deleted file mode 100644
index 5e21262..0000000
--- a/tools/qtsingleapplication/qtlockedfile_win.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Solutions component.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 Digia Plc and its Subsidiary(-ies) 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 "qtlockedfile.h"
-#include <qt_windows.h>
-#include <QFileInfo>
-
-#define MUTEX_PREFIX "QtLockedFile mutex "
-// Maximum number of concurrent read locks. Must not be greater than MAXIMUM_WAIT_OBJECTS
-#define MAX_READERS MAXIMUM_WAIT_OBJECTS
-
-#if QT_VERSION >= 0x050000
-#define QT_WA(unicode, ansi) unicode
-#endif
-
-Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate)
-{
- if (mutexname.isEmpty()) {
- QFileInfo fi(*this);
- mutexname = QString::fromLatin1(MUTEX_PREFIX)
- + fi.absoluteFilePath().toLower();
- }
- QString mname(mutexname);
- if (idx >= 0)
- mname += QString::number(idx);
-
- Qt::HANDLE mutex;
- if (doCreate) {
- QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); },
- { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } );
- if (!mutex) {
- qErrnoWarning("QtLockedFile::lock(): CreateMutex failed");
- return 0;
- }
- }
- else {
- QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); },
- { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } );
- if (!mutex) {
- if (GetLastError() != ERROR_FILE_NOT_FOUND)
- qErrnoWarning("QtLockedFile::lock(): OpenMutex failed");
- return 0;
- }
- }
- return mutex;
-}
-
-bool QtLockedFile::waitMutex(Qt::HANDLE mutex, bool doBlock)
-{
- Q_ASSERT(mutex);
- DWORD res = WaitForSingleObject(mutex, doBlock ? INFINITE : 0);
- switch (res) {
- case WAIT_OBJECT_0:
- case WAIT_ABANDONED:
- return true;
- break;
- case WAIT_TIMEOUT:
- break;
- default:
- qErrnoWarning("QtLockedFile::lock(): WaitForSingleObject failed");
- }
- return false;
-}
-
-
-
-bool QtLockedFile::lock(LockMode mode, bool block)
-{
- if (!isOpen()) {
- qWarning("QtLockedFile::lock(): file is not opened");
- return false;
- }
-
- if (mode == NoLock)
- return unlock();
-
- if (mode == m_lock_mode)
- return true;
-
- if (m_lock_mode != NoLock)
- unlock();
-
- if (!wmutex && !(wmutex = getMutexHandle(-1, true)))
- return false;
-
- if (!waitMutex(wmutex, block))
- return false;
-
- if (mode == ReadLock) {
- int idx = 0;
- for (; idx < MAX_READERS; idx++) {
- rmutex = getMutexHandle(idx, false);
- if (!rmutex || waitMutex(rmutex, false))
- break;
- CloseHandle(rmutex);
- }
- bool ok = true;
- if (idx >= MAX_READERS) {
- qWarning("QtLockedFile::lock(): too many readers");
- rmutex = 0;
- ok = false;
- }
- else if (!rmutex) {
- rmutex = getMutexHandle(idx, true);
- if (!rmutex || !waitMutex(rmutex, false))
- ok = false;
- }
- if (!ok && rmutex) {
- CloseHandle(rmutex);
- rmutex = 0;
- }
- ReleaseMutex(wmutex);
- if (!ok)
- return false;
- }
- else {
- Q_ASSERT(rmutexes.isEmpty());
- for (int i = 0; i < MAX_READERS; i++) {
- Qt::HANDLE mutex = getMutexHandle(i, false);
- if (mutex)
- rmutexes.append(mutex);
- }
- if (rmutexes.size()) {
- DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(),
- TRUE, block ? INFINITE : 0);
- if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED) {
- if (res != WAIT_TIMEOUT)
- qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed");
- m_lock_mode = WriteLock; // trick unlock() to clean up - semiyucky
- unlock();
- return false;
- }
- }
- }
-
- m_lock_mode = mode;
- return true;
-}
-
-bool QtLockedFile::unlock()
-{
- if (!isOpen()) {
- qWarning("QtLockedFile::unlock(): file is not opened");
- return false;
- }
-
- if (!isLocked())
- return true;
-
- if (m_lock_mode == ReadLock) {
- ReleaseMutex(rmutex);
- CloseHandle(rmutex);
- rmutex = 0;
- }
- else {
- foreach(Qt::HANDLE mutex, rmutexes) {
- ReleaseMutex(mutex);
- CloseHandle(mutex);
- }
- rmutexes.clear();
- ReleaseMutex(wmutex);
- }
-
- m_lock_mode = QtLockedFile::NoLock;
- return true;
-}
-
-QtLockedFile::~QtLockedFile()
-{
- if (isOpen())
- unlock();
- if (wmutex)
- CloseHandle(wmutex);
-}
diff --git a/tools/qtsingleapplication/qtsingleapplication.cpp b/tools/qtsingleapplication/qtsingleapplication.cpp
deleted file mode 100644
index 13d7f6d..0000000
--- a/tools/qtsingleapplication/qtsingleapplication.cpp
+++ /dev/null
@@ -1,347 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Solutions component.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 Digia Plc and its Subsidiary(-ies) 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 "qtsingleapplication.h"
-#include "qtlocalpeer.h"
-#include <QWidget>
-
-
-/*!
- \class QtSingleApplication qtsingleapplication.h
- \brief The QtSingleApplication class provides an API to detect and
- communicate with running instances of an application.
-
- This class allows you to create applications where only one
- instance should be running at a time. I.e., if the user tries to
- launch another instance, the already running instance will be
- activated instead. Another usecase is a client-server system,
- where the first started instance will assume the role of server,
- and the later instances will act as clients of that server.
-
- By default, the full path of the executable file is used to
- determine whether two processes are instances of the same
- application. You can also provide an explicit identifier string
- that will be compared instead.
-
- The application should create the QtSingleApplication object early
- in the startup phase, and call isRunning() to find out if another
- instance of this application is already running. If isRunning()
- returns false, it means that no other instance is running, and
- this instance has assumed the role as the running instance. In
- this case, the application should continue with the initialization
- of the application user interface before entering the event loop
- with exec(), as normal.
-
- The messageReceived() signal will be emitted when the running
- application receives messages from another instance of the same
- application. When a message is received it might be helpful to the
- user to raise the application so that it becomes visible. To
- facilitate this, QtSingleApplication provides the
- setActivationWindow() function and the activateWindow() slot.
-
- If isRunning() returns true, another instance is already
- running. It may be alerted to the fact that another instance has
- started by using the sendMessage() function. Also data such as
- startup parameters (e.g. the name of the file the user wanted this
- new instance to open) can be passed to the running instance with
- this function. Then, the application should terminate (or enter
- client mode).
-
- If isRunning() returns true, but sendMessage() fails, that is an
- indication that the running instance is frozen.
-
- Here's an example that shows how to convert an existing
- application to use QtSingleApplication. It is very simple and does
- not make use of all QtSingleApplication's functionality (see the
- examples for that).
-
- \code
- // Original
- int main(int argc, char **argv)
- {
- QApplication app(argc, argv);
-
- MyMainWidget mmw;
- mmw.show();
- return app.exec();
- }
-
- // Single instance
- int main(int argc, char **argv)
- {
- QtSingleApplication app(argc, argv);
-
- if (app.isRunning())
- return !app.sendMessage(someDataString);
-
- MyMainWidget mmw;
- app.setActivationWindow(&mmw);
- mmw.show();
- return app.exec();
- }
- \endcode
-
- Once this QtSingleApplication instance is destroyed (normally when
- the process exits or crashes), when the user next attempts to run the
- application this instance will not, of course, be encountered. The
- next instance to call isRunning() or sendMessage() will assume the
- role as the new running instance.
-
- For console (non-GUI) applications, QtSingleCoreApplication may be
- used instead of this class, to avoid the dependency on the QtGui
- library.
-
- \sa QtSingleCoreApplication
-*/
-
-
-void QtSingleApplication::sysInit(const QString &appId)
-{
- actWin = 0;
- peer = new QtLocalPeer(this, appId);
- connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
-}
-
-
-/*!
- Creates a QtSingleApplication object. The application identifier
- will be QCoreApplication::applicationFilePath(). \a argc, \a
- argv, and \a GUIenabled are passed on to the QAppliation constructor.
-
- If you are creating a console application (i.e. setting \a
- GUIenabled to false), you may consider using
- QtSingleCoreApplication instead.
-*/
-
-QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled)
- : QApplication(argc, argv, GUIenabled)
-{
- sysInit();
-}
-
-
-/*!
- Creates a QtSingleApplication object with the application
- identifier \a appId. \a argc and \a argv are passed on to the
- QAppliation constructor.
-*/
-
-QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv)
- : QApplication(argc, argv)
-{
- sysInit(appId);
-}
-
-#if QT_VERSION < 0x050000
-
-/*!
- Creates a QtSingleApplication object. The application identifier
- will be QCoreApplication::applicationFilePath(). \a argc, \a
- argv, and \a type are passed on to the QAppliation constructor.
-*/
-QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type)
- : QApplication(argc, argv, type)
-{
- sysInit();
-}
-
-
-# if defined(Q_OS_LINUX)
-/*!
- Special constructor for X11, ref. the documentation of
- QApplication's corresponding constructor. The application identifier
- will be QCoreApplication::applicationFilePath(). \a dpy, \a visual,
- and \a cmap are passed on to the QApplication constructor.
-*/
-QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap)
- : QApplication(dpy, visual, cmap)
-{
- sysInit();
-}
-
-/*!
- Special constructor for X11, ref. the documentation of
- QApplication's corresponding constructor. The application identifier
- will be QCoreApplication::applicationFilePath(). \a dpy, \a argc, \a
- argv, \a visual, and \a cmap are passed on to the QApplication
- constructor.
-*/
-QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap)
- : QApplication(dpy, argc, argv, visual, cmap)
-{
- sysInit();
-}
-
-/*!
- Special constructor for X11, ref. the documentation of
- QApplication's corresponding constructor. The application identifier
- will be \a appId. \a dpy, \a argc, \a
- argv, \a visual, and \a cmap are passed on to the QApplication
- constructor.
-*/
-QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap)
- : QApplication(dpy, argc, argv, visual, cmap)
-{
- sysInit(appId);
-}
-# endif // Q_OS_LINUX
-#endif // QT_VERSION < 0x050000
-
-
-/*!
- Returns true if another instance of this application is running;
- otherwise false.
-
- This function does not find instances of this application that are
- being run by a different user (on Windows: that are running in
- another session).
-
- \sa sendMessage()
-*/
-
-bool QtSingleApplication::isRunning()
-{
- return peer->isClient();
-}
-
-
-/*!
- Tries to send the text \a message to the currently running
- instance. The QtSingleApplication object in the running instance
- will emit the messageReceived() signal when it receives the
- message.
-
- This function returns true if the message has been sent to, and
- processed by, the current instance. If there is no instance
- currently running, or if the running instance fails to process the
- message within \a timeout milliseconds, this function return false.
-
- \sa isRunning(), messageReceived()
-*/
-bool QtSingleApplication::sendMessage(const QString &message, int timeout)
-{
- return peer->sendMessage(message, timeout);
-}
-
-
-/*!
- Returns the application identifier. Two processes with the same
- identifier will be regarded as instances of the same application.
-*/
-QString QtSingleApplication::id() const
-{
- return peer->applicationId();
-}
-
-
-/*!
- Sets the activation window of this application to \a aw. The
- activation window is the widget that will be activated by
- activateWindow(). This is typically the application's main window.
-
- If \a activateOnMessage is true (the default), the window will be
- activated automatically every time a message is received, just prior
- to the messageReceived() signal being emitted.
-
- \sa activateWindow(), messageReceived()
-*/
-
-void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage)
-{
- actWin = aw;
- if (activateOnMessage)
- connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
- else
- disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
-}
-
-
-/*!
- Returns the applications activation window if one has been set by
- calling setActivationWindow(), otherwise returns 0.
-
- \sa setActivationWindow()
-*/
-QWidget* QtSingleApplication::activationWindow() const
-{
- return actWin;
-}
-
-
-/*!
- De-minimizes, raises, and activates this application's activation window.
- This function does nothing if no activation window has been set.
-
- This is a convenience function to show the user that this
- application instance has been activated when he has tried to start
- another instance.
-
- This function should typically be called in response to the
- messageReceived() signal. By default, that will happen
- automatically, if an activation window has been set.
-
- \sa setActivationWindow(), messageReceived(), initialize()
-*/
-void QtSingleApplication::activateWindow()
-{
- if (actWin) {
- actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
- actWin->raise();
- actWin->activateWindow();
- }
-}
-
-
-/*!
- \fn void QtSingleApplication::messageReceived(const QString& message)
-
- This signal is emitted when the current instance receives a \a
- message from another instance of this application.
-
- \sa sendMessage(), setActivationWindow(), activateWindow()
-*/
-
-
-/*!
- \fn void QtSingleApplication::initialize(bool dummy = true)
-
- \obsolete
-*/
diff --git a/tools/qtsingleapplication/qtsingleapplication.h b/tools/qtsingleapplication/qtsingleapplication.h
deleted file mode 100644
index 646f360..0000000
--- a/tools/qtsingleapplication/qtsingleapplication.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Solutions component.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 Digia Plc and its Subsidiary(-ies) 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 QTSINGLEAPPLICATION_H
-#define QTSINGLEAPPLICATION_H
-
-#include <QApplication>
-
-class QtLocalPeer;
-
-#if defined(Q_OS_WIN)
-# if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT)
-# define QT_QTSINGLEAPPLICATION_EXPORT
-# elif defined(QT_QTSINGLEAPPLICATION_IMPORT)
-# if defined(QT_QTSINGLEAPPLICATION_EXPORT)
-# undef QT_QTSINGLEAPPLICATION_EXPORT
-# endif
-# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport)
-# elif defined(QT_QTSINGLEAPPLICATION_EXPORT)
-# undef QT_QTSINGLEAPPLICATION_EXPORT
-# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport)
-# endif
-#else
-# define QT_QTSINGLEAPPLICATION_EXPORT
-#endif
-
-class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication
-{
- Q_OBJECT
-
-public:
- QtSingleApplication(int &argc, char **argv, bool GUIenabled = true);
- QtSingleApplication(const QString &id, int &argc, char **argv);
-#if QT_VERSION < 0x050000
- QtSingleApplication(int &argc, char **argv, Type type);
-# if defined(Q_OS_LINUX)
- QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0);
- QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0);
- QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0);
-# endif // Q_OS_LINUX
-#endif // QT_VERSION < 0x050000
-
- bool isRunning();
- QString id() const;
-
- void setActivationWindow(QWidget* aw, bool activateOnMessage = true);
- QWidget* activationWindow() const;
-
- // Obsolete:
- void initialize(bool dummy = true)
- { isRunning(); Q_UNUSED(dummy) }
-
-public Q_SLOTS:
- bool sendMessage(const QString &message, int timeout = 5000);
- void activateWindow();
-
-
-Q_SIGNALS:
- void messageReceived(const QString &message);
-
-
-private:
- void sysInit(const QString &appId = QString());
- QtLocalPeer *peer;
- QWidget *actWin;
-};
-
-#endif // QTSINGLEAPPLICATION_H
diff --git a/tools/qtsingleapplication/qtsingleapplication.pri b/tools/qtsingleapplication/qtsingleapplication.pri
deleted file mode 100644
index 2a71d43..0000000
--- a/tools/qtsingleapplication/qtsingleapplication.pri
+++ /dev/null
@@ -1,19 +0,0 @@
-INCLUDEPATH += $$PWD
-DEPENDPATH += $$PWD
-QT *= network
-
-contains(QT_VERSION, ^5.*) {
- QT *= widgets
-}
-
-qtsingleapplication-uselib:!qtsingleapplication-buildlib {
- LIBS += -L$$QTSINGLEAPPLICATION_LIBDIR -l$$QTSINGLEAPPLICATION_LIBNAME
-} else {
- SOURCES += $$PWD/qtsingleapplication.cpp $$PWD/qtlocalpeer.cpp
- HEADERS += $$PWD/qtsingleapplication.h $$PWD/qtlocalpeer.h
-}
-
-win32 {
- contains(TEMPLATE, lib):contains(CONFIG, shared):DEFINES += QT_QTSINGLEAPPLICATION_EXPORT
- else:qtsingleapplication-uselib:DEFINES += QT_QTSINGLEAPPLICATION_IMPORT
-}
diff --git a/tools/qtsingleapplication/qtsinglecoreapplication.cpp b/tools/qtsingleapplication/qtsinglecoreapplication.cpp
deleted file mode 100644
index 5634537..0000000
--- a/tools/qtsingleapplication/qtsinglecoreapplication.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Solutions component.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 Digia Plc and its Subsidiary(-ies) 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 "qtsinglecoreapplication.h"
-#include "qtlocalpeer.h"
-
-/*!
- \class QtSingleCoreApplication qtsinglecoreapplication.h
- \brief A variant of the QtSingleApplication class for non-GUI applications.
-
- This class is a variant of QtSingleApplication suited for use in
- console (non-GUI) applications. It is an extension of
- QCoreApplication (instead of QApplication). It does not require
- the QtGui library.
-
- The API and usage is identical to QtSingleApplication, except that
- functions relating to the "activation window" are not present, for
- obvious reasons. Please refer to the QtSingleApplication
- documentation for explanation of the usage.
-
- A QtSingleCoreApplication instance can communicate to a
- QtSingleApplication instance if they share the same application
- id. Hence, this class can be used to create a light-weight
- command-line tool that sends commands to a GUI application.
-
- \sa QtSingleApplication
-*/
-
-/*!
- Creates a QtSingleCoreApplication object. The application identifier
- will be QCoreApplication::applicationFilePath(). \a argc and \a
- argv are passed on to the QCoreAppliation constructor.
-*/
-
-QtSingleCoreApplication::QtSingleCoreApplication(int &argc, char **argv)
- : QCoreApplication(argc, argv)
-{
- peer = new QtLocalPeer(this);
- connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
-}
-
-
-/*!
- Creates a QtSingleCoreApplication object with the application
- identifier \a appId. \a argc and \a argv are passed on to the
- QCoreAppliation constructor.
-*/
-QtSingleCoreApplication::QtSingleCoreApplication(const QString &appId, int &argc, char **argv)
- : QCoreApplication(argc, argv)
-{
- peer = new QtLocalPeer(this, appId);
- connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
-}
-
-
-/*!
- Returns true if another instance of this application is running;
- otherwise false.
-
- This function does not find instances of this application that are
- being run by a different user (on Windows: that are running in
- another session).
-
- \sa sendMessage()
-*/
-
-bool QtSingleCoreApplication::isRunning()
-{
- return peer->isClient();
-}
-
-
-/*!
- Tries to send the text \a message to the currently running
- instance. The QtSingleCoreApplication object in the running instance
- will emit the messageReceived() signal when it receives the
- message.
-
- This function returns true if the message has been sent to, and
- processed by, the current instance. If there is no instance
- currently running, or if the running instance fails to process the
- message within \a timeout milliseconds, this function return false.
-
- \sa isRunning(), messageReceived()
-*/
-
-bool QtSingleCoreApplication::sendMessage(const QString &message, int timeout)
-{
- return peer->sendMessage(message, timeout);
-}
-
-
-/*!
- Returns the application identifier. Two processes with the same
- identifier will be regarded as instances of the same application.
-*/
-
-QString QtSingleCoreApplication::id() const
-{
- return peer->applicationId();
-}
-
-
-/*!
- \fn void QtSingleCoreApplication::messageReceived(const QString& message)
-
- This signal is emitted when the current instance receives a \a
- message from another instance of this application.
-
- \sa sendMessage()
-*/
diff --git a/tools/qtsingleapplication/qtsinglecoreapplication.h b/tools/qtsingleapplication/qtsinglecoreapplication.h
deleted file mode 100644
index b87fffe..0000000
--- a/tools/qtsingleapplication/qtsinglecoreapplication.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Solutions component.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 Digia Plc and its Subsidiary(-ies) 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 QTSINGLECOREAPPLICATION_H
-#define QTSINGLECOREAPPLICATION_H
-
-#include <QCoreApplication>
-
-class QtLocalPeer;
-
-class QtSingleCoreApplication : public QCoreApplication
-{
- Q_OBJECT
-
-public:
- QtSingleCoreApplication(int &argc, char **argv);
- QtSingleCoreApplication(const QString &id, int &argc, char **argv);
-
- bool isRunning();
- QString id() const;
-
-public Q_SLOTS:
- bool sendMessage(const QString &message, int timeout = 5000);
-
-
-Q_SIGNALS:
- void messageReceived(const QString &message);
-
-
-private:
- QtLocalPeer* peer;
-};
-
-#endif // QTSINGLECOREAPPLICATION_H
diff --git a/tools/qtsingleapplication/qtsinglecoreapplication.pri b/tools/qtsingleapplication/qtsinglecoreapplication.pri
deleted file mode 100644
index d2d6cc3..0000000
--- a/tools/qtsingleapplication/qtsinglecoreapplication.pri
+++ /dev/null
@@ -1,10 +0,0 @@
-INCLUDEPATH += $$PWD
-DEPENDPATH += $$PWD
-HEADERS += $$PWD/qtsinglecoreapplication.h $$PWD/qtlocalpeer.h
-SOURCES += $$PWD/qtsinglecoreapplication.cpp $$PWD/qtlocalpeer.cpp
-
-QT *= network
-
-win32:contains(TEMPLATE, lib):contains(CONFIG, shared) {
- DEFINES += QT_QTSINGLECOREAPPLICATION_EXPORT=__declspec(dllexport)
-}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 16, 12:20 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70753
Default Alt Text
(104 KB)

Event Timeline