deskflow/src/gui/src/main.cpp

166 lines
3.6 KiB
C++
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012 Synergy Si Ltd.
2012-06-10 16:50:54 +00:00
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
2012-06-10 16:50:54 +00:00
*
* This package 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#define TRAY_RETRY_COUNT 10
#define TRAY_RETRY_WAIT 2000
#include "QSynergyApplication.h"
#include "MainWindow.h"
#include "AppConfig.h"
#include "SetupWizard.h"
#include <QtCore>
#include <QtGui>
#include <QSettings>
2014-02-14 16:21:02 +00:00
#include <QMessageBox>
2012-06-10 16:50:54 +00:00
2014-01-24 17:53:03 +00:00
#if defined(Q_OS_MAC)
#include <Carbon/Carbon.h>
#endif
2012-06-10 16:50:54 +00:00
class QThreadImpl : public QThread
{
public:
static void msleep(unsigned long msecs)
{
QThread::msleep(msecs);
}
};
int waitForTray();
2014-01-24 17:53:03 +00:00
#if defined(Q_OS_MAC)
bool checkMacAssistiveDevices();
#endif
2012-06-10 16:50:54 +00:00
int main(int argc, char* argv[])
{
QCoreApplication::setOrganizationName("Synergy");
2016-09-06 15:13:50 +00:00
QCoreApplication::setOrganizationDomain("http://symless.com/");
2012-06-10 16:50:54 +00:00
QCoreApplication::setApplicationName("Synergy");
QSynergyApplication app(argc, argv);
2014-01-24 17:53:03 +00:00
#if defined(Q_OS_MAC)
if (app.applicationDirPath().startsWith("/Volumes/")) {
QMessageBox::information(
NULL, "Synergy",
"Please drag Synergy to the Applications folder, and open it from there.");
return 1;
}
2014-01-24 17:53:03 +00:00
if (!checkMacAssistiveDevices())
{
return 1;
}
#endif
2012-06-10 16:50:54 +00:00
if (!waitForTray())
2014-01-24 17:53:03 +00:00
{
2012-06-10 16:50:54 +00:00
return -1;
2014-01-24 17:53:03 +00:00
}
2012-06-10 16:50:54 +00:00
#ifndef Q_OS_WIN
2012-06-10 16:50:54 +00:00
QApplication::setQuitOnLastWindowClosed(false);
#endif
2012-06-10 16:50:54 +00:00
QSettings settings;
AppConfig appConfig(&settings);
app.switchTranslator(appConfig.language());
2012-06-10 16:50:54 +00:00
MainWindow mainWindow(settings, appConfig);
SetupWizard setupWizard(mainWindow, true);
if (appConfig.wizardShouldRun())
{
setupWizard.show();
}
else
{
mainWindow.open();
}
2012-06-10 16:50:54 +00:00
return app.exec();
}
int waitForTray()
{
// on linux, the system tray may not be available immediately after logging in,
// so keep retrying but give up after a short time.
int trayAttempts = 0;
while (true)
{
if (QSystemTrayIcon::isSystemTrayAvailable())
{
break;
}
if (++trayAttempts > TRAY_RETRY_COUNT)
{
QMessageBox::critical(NULL, "Synergy",
QObject::tr("System tray is unavailable, quitting."));
return false;
}
QThreadImpl::msleep(TRAY_RETRY_WAIT);
}
return true;
}
2014-01-24 17:53:03 +00:00
#if defined(Q_OS_MAC)
bool checkMacAssistiveDevices()
{
2014-02-14 16:21:02 +00:00
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 // mavericks
2014-01-24 17:53:03 +00:00
// new in mavericks, applications are trusted individually
// with use of the accessibility api. this call will show a
// prompt which can show the security/privacy/accessibility
// tab, with a list of allowed applications. synergy should
// show up there automatically, but will be unchecked.
if (AXIsProcessTrusted()) {
return true;
}
const void* keys[] = { kAXTrustedCheckOptionPrompt };
const void* trueValue[] = { kCFBooleanTrue };
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, trueValue, 1, NULL, NULL);
2014-01-24 17:53:03 +00:00
bool result = AXIsProcessTrustedWithOptions(options);
CFRelease(options);
2014-01-24 17:53:03 +00:00
return result;
#else
// now deprecated in mavericks.
bool result = AXAPIEnabled();
if (!result) {
QMessageBox::information(
NULL, "Synergy",
"Please enable access to assistive devices "
"(System Preferences), then re-open Synergy.");
}
2014-01-24 17:53:03 +00:00
return result;
#endif
}
#endif