/*! load_initial_plugin will be called when this plug in being loaded.
 * Please notice that a global parament "map_instances" is introduced, for multi-instance situation
 * in windows OCX usage. A Brave new instance of "qtvplugin_geomarker" will be created for each different viewer_interface.
 *
 * @param strSLibPath the absolute path of this dll.
 * @param ptrviewer the pointer to main view.
 * @return	return the instance pointer to the instance belong to ptrviewer
*/
layer_interface * qtvplugin_geomarker::load_initial_plugin(QString strSLibPath,viewer_interface  * ptrviewer)
{
	//!In this instance, we will see how to create a new instance for each ptrviewer
	qtvplugin_geomarker * instance = 0;
	//!1.Check whether there is already a instance for ptrviewer( viewer_interface)
	mutex_instances.lock();
	//!1.1 situation 1: map_instances is empty, which means no instance exists. We just save this pointer to map_instances
	if (map_instances.empty()==true)
	{
		map_instances[ptrviewer] = this;
		instance = this;
	}
	/*! 1.2 situation 2: map_instances dose not contain ptrviewer, which is the normal situation when a second ocx ctrl is initializing.
	 * we just allocate a new  qtvplugin_geomarker, and save key-value in map_instances.
	*/
	else if (map_instances.contains(ptrviewer)==false)
	{
		instance = new qtvplugin_geomarker;
		map_instances[ptrviewer] = instance;
	}
	//! 1.3 situation 3: a ABNORMAL situation. load_initial_plugin is called again.
	else
		instance = map_instances[ptrviewer];
	mutex_instances.unlock();
	//2. if the instance is just this object, we do real init code.
	if (instance==this)
	{
		QFileInfo info(strSLibPath);
		m_SLLibPath = strSLibPath;
		m_SLLibName = info.completeBaseName();
		m_pVi = ptrviewer;

		mutex_instances.lock();
		m_nInstance = ++count_instances[m_SLLibName];
		mutex_instances.unlock();

		loadTranslations();
		ini_load();
		style_load();
		initialBindPluginFuntions();
	}
	//3. elseif, we call the instance's load_initial_plugin method instead
	else
	{
		 layer_interface * ret = instance->load_initial_plugin(strSLibPath,ptrviewer);
		 assert(ret==instance);
		 return ret;
	}
	qDebug()<<QFont::substitutions();
	return instance;
}
Beispiel #2
0
CApplication::CApplication(int& argc, char* argv[])
	: QApplication(argc, argv)
{
	//Icon
	QIcon icon("./bicorem.png");
	setWindowIcon(icon);	
	//Für Settings (Speichern und Laden) benötigt
	setOrganizationName("BiCoRem");
	setOrganizationDomain("DE");
	setApplicationName("BiCoRem");
	setApplicationVersion("BiCoRem v1.1");
	//Lokalisierung und Internationalisierung
	loadTranslations("./lang");
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    // Install the custom handler
    qInstallMessageHandler(messageOutput);

    QApplication app(argc, argv);
    QCoreApplication::setApplicationName(APPLICATION_NAME);
    QCoreApplication::setOrganizationName(APPLICATION_NAME);
    QCoreApplication::setApplicationVersion("0.0.1-alpha");

    // Load default Qt translations
    const QString locale = QLocale::system().name().section('_', 0, 0);
    QTranslator qtTranslator;
    qtTranslator.load(QStringLiteral("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&qtTranslator);

    // Load translations in the "translations" dir
    loadTranslations(QCoreApplication::applicationDirPath() + QStringLiteral("/translations"), locale, &app);

    // Check the parameters
    QCommandLineParser parser;
    parser.setApplicationDescription(QCoreApplication::tr("Simple application that allow the control of an Android VR app with the Bluetooth and a 3D depth sensor."));
    parser.addHelpOption();
    parser.addVersionOption();

    parser.addOption(QCommandLineOption({"a", "auto-start"}, QCoreApplication::translate("options", "Auto start the bluetooth listening (don't wait for the user click).")));
    parser.addOption(QCommandLineOption({"c", "controller"}, QCoreApplication::translate("options", "The controller <controller-name> will be used."), QCoreApplication::translate("options", "controller-name")));
    parser.addOption(QCommandLineOption({"p", "port"}, QCoreApplication::translate("options", "The Bluetooth engine will listen on the specified <port-number>. The <port-number> must be in range 1-30. Set to 0 if you want to select the first available."), QCoreApplication::translate("options", "port-number")));
    parser.addOption(QCommandLineOption({"f", "frequency"}, QCoreApplication::translate("options", "Frequency for emitting data to the bluetooth device (number of data per second)"), QCoreApplication::translate("options", "number-per-second")));
    parser.addOption(QCommandLineOption("nologwidget", QCoreApplication::translate("options", "Don't show the log console in the bottom of the window.")));

    parser.process(app);

    const bool useLogWidget = !parser.isSet("nologwidget");
    if(useLogWidget)
        globalLogBrowser = new LogBrowser();

    MainWindow window(globalLogBrowser, parser.isSet("auto-start"), parser.value("controller"), intFromParser(parser, "port"), intFromParser(parser, "frequency"));
    window.show();

    // Execute the main loop
    const int result = app.exec();

    // Delete the log browser if needed
    if(useLogWidget)
        delete globalLogBrowser;

    return result;
}
bool LanguageSelection::loadLanguage(const LanguageCode& languageCode)
{
  if(languageCode == mCurrentLanguage){
    return true;
  }

  const auto translations = mTranslations.getTranslationsForFileLanguageCode(languageCode);

  if(!loadTranslations(translations)){
    return false;
  }
  mCurrentLanguage = languageCode;

  return true;
}
Beispiel #5
0
UISettings::UISettings( QList <supportedRes_struct> *supportedResolutions, QList <translation_struct> *translations, QWidget* p )
	: QDialog( p )
{
	// setup dialog
	setupUi( this );

	QRect maxWinRect = QApplication::desktop()->availableGeometry();
	
	
	leWinWidth->setValidator(new QIntValidator(0, maxWinRect.width(), leWinWidth));
	leWinHeight->setValidator(new QIntValidator(0, maxWinRect.height(), leWinHeight));

	pmPort1->setPort( 1 );
	pmPort1->loadSettings();
	pmPort2->setPort( 2 );
	pmPort2->loadSettings();
	
	if ( p && !p->isFullScreen() )
	{
		setWindowFlags( Qt::Sheet );
	}

	setupCdDrives();

	// load cores informations
	loadCores();

	supportedRes = *supportedResolutions;
	loadSupportedResolutions();

#ifdef HAVE_LIBMINI18N
	trans = *translations;
	loadTranslations();
#else
   lTranslation->hide();
	cbTranslation->hide();
#endif

	loadShortcuts();

	// load settings
	loadSettings();
	
	// connections
	foreach ( QToolButton* tb, findChildren<QToolButton*>() )
	{
		connect( tb, SIGNAL( clicked() ), this, SLOT( tbBrowse_clicked() ) );
	}
PreferenceDialog::PreferenceDialog(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::PreferenceDialog) {
    ui->setupUi(this);
    QSettings settings;
    loadTranslations();
    readPreferences();

    //If we want a custom folder, show the browse button
    ui->browseButton->setVisible(ui->outputFileMethodComboBox->currentIndex() == 2);

    //Override the item delegate for styling QComboBox on OSX
    QStyledItemDelegate* itemDelegate = new QStyledItemDelegate();
    ui->languageComboBox->setItemDelegate(itemDelegate);
    ui->outputFileMethodComboBox->setItemDelegate(itemDelegate);
}
Beispiel #7
0
UISettings::UISettings( QList <supportedRes_struct> *supportedResolutions, QList <translation_struct> *translations, QWidget* p )
	: QDialog( p )
{
	// setup dialog
	setupUi( this );
	pmPort1->setPort( 1 );
	pmPort1->loadSettings();
	pmPort2->setPort( 2 );
	pmPort2->loadSettings();
	
	if ( p && !p->isFullScreen() )
	{
		setWindowFlags( Qt::Sheet );
	}

	setupCdDrives();

	// load cores informations
	loadCores();

	supportedRes = *supportedResolutions;
	loadSupportedResolutions();

#ifdef HAVE_LIBMINI18N
	trans = *translations;
	loadTranslations();
#else
   lTranslation->hide();
	cbTranslation->hide();
#endif

	loadShortcuts();

	// load settings
	loadSettings();
	
	// connections
	foreach ( QToolButton* tb, findChildren<QToolButton*>() )
	{
		connect( tb, SIGNAL( clicked() ), this, SLOT( tbBrowse_clicked() ) );
	}
Beispiel #8
0
bool Application::init()
try
{
    // initialize resources
#if !defined(DESKTOP)
    Q_INIT_RESOURCE(keyboard);
    Q_INIT_RESOURCE(rotation);
    Q_INIT_RESOURCE(eink);
#if defined(EINK)
    setCursorFlashTime(0);
#endif
#endif

    QString logFile( Platform::get()->getUserSettingsPath() + QDir::separator() + applicationName() + ".log.txt" );
    g_pLog = new Log( QFile::encodeName(logFile).constData(), 1, 1 );

    g_pConfig = new Config(applicationName());
    int logLevel = g_pConfig->readInt("log_level", -1);
    if ( -1 == logLevel )
    {
        logLevel = qgetenv("VLASOVSOFT_LOG").toInt();
    } 
    if ( logLevel < 0 ) logLevel = 0;
    if ( logLevel > 2 ) logLevel = 2;
    g_pLog->setLevel( logLevel );

    g_pLog->write(1, Log::MT_I, "Program started, version: %s.%s", VERSION, REVISION);

    // set default application font
    QFont fnt = font();
    fnt.setPointSize(Platform::get()->getDefaultFontSize());
    setFont(fnt);

#if defined(EINK)
    // set palette
    QPalette pal = palette();
    pal.setColor(QPalette::Window, Qt::white);
    pal.setColor(QPalette::Highlight, Qt::black);
    setPalette(pal);
#endif

#if defined(ANDROID) || defined(SIMPLE) || defined(IOS)
    QPalette pal = palette();
    pal.setColor(QPalette::Highlight, Qt::darkBlue);
    pal.setColor(QPalette::HighlightedText, Qt::white);
    setPalette(pal);
#endif

#if !defined(DESKTOP)
    StyleEbook* pStyle = new StyleEbook(style());
    int bSize = g_pConfig->readInt( "button_size", 40 ); // 40 = 1 cm
    QSize size( getSizePx( QSize(bSize, bSize), 5 ) );
    pStyle->setButtonIconSize(qMax( size.width(), size.height() ));
    setStyle(pStyle);
#endif

#if defined(Q_WS_QWS)
    QWSServer::setBackground(QBrush(Qt::black));
    setNavigationMode( Qt::NavigationModeKeypadDirectional );
#endif

#if defined(ANDROID)
    installEventFilter(&kf);
#endif

    loadTranslations();

    customInit();

    return true;
}
catch(const Exception& e)
{
    if ( g_pLog != NULL )
        g_pLog->write(1, Log::MT_F, "Fatal error: %s", e.what());
    ::messageBox(0, QMessageBox::Critical, qApp->translate("main", "Error:"), QString::fromLocal8Bit(e.what()) );
    return false;
}
catch(...)
{
    if ( g_pLog != NULL )
        g_pLog->write(1, Log::MT_F, "Fatal error!");
    ::messageBox(0, QMessageBox::Critical, qApp->translate("main", "Error:"), "Fatal error!" );
    return false;
}
Beispiel #9
0
void CApplication::loadTranslations(const QString& dir)
{
	loadTranslations(QDir(dir));
}
static void tioAgent(const char *translatePath, unsigned refreshDelay,
    unsigned short tioPort, const char *tioSocketPath, unsigned short sioPort,
    const char *sioSocketPath, const unsigned short mapSize)
{
    fd_set currFdSet;
    int connectedFd = -1;  /* not currently connected */
    time_t lastCheckTime = 0;
    time_t lastModTime = 0;
    int addressFamily = 0;

    TranslatorState *translatorState = GetTranslatorState();
    initTranslations(translatorState, mapSize);

    {
        /* install a signal handler to remove the socket file */
        struct sigaction a;
        memset(&a, 0, sizeof(a));
        a.sa_handler = tioInterruptHandler;
        if (sigaction(SIGINT, &a, 0) != 0) {
            LogMsg(LOG_ERR, "[TIO] sigaction(SIGINT) failed, errno = %d\n", errno);
            exit(1);
        }
        if (sigaction(SIGTERM, &a, 0) != 0) {
            LogMsg(LOG_ERR, "[TIO] sigaction(SIGTERM) failed, errno = %d\n", errno);
            exit(1);
        }
    }

    /* buffers for collection characters from each side */
    struct LineBuffer fromSio;
    fromSio.pos = 0;
    struct LineBuffer fromQv;
    fromQv.pos = 0;

    /* do initial load, may get reloaded in while loop, below */
    lastModTime = loadTranslations(translatorState, translatePath, 0);
    lastCheckTime = time(0);

    /* 
     * This is the select loop which waits for characters to be received on the
     * sio_agent descriptor and on either the listen socket (meaning an
     * incoming connection is queued) or on a connected socket descriptor.  If
     * not connected to the sio_agent, make select() time out to keep trying to
     * open a connection to it.
     */
    /* 100ms retry timeout for opening socket to sio_agent */
    struct  timeval timeout;
    int     sioFd       = -1;
    int     listenFd    = -1;
    int     nfds        = 0;
    keepGoing = 1;
    while (keepGoing) {
        /* try opening a connection to the sio_agent */
        if (sioFd < 0) {
            sioFd = tioSioSocketInit(sioPort, sioSocketPath);
            if (sioFd >= 0) {
                FD_ZERO(&currFdSet);
                FD_SET(sioFd, &currFdSet);
                nfds = max(sioFd,
                    (connectedFd >= 0) ? connectedFd : listenFd) + 1;

                /* open socket for qml viewer */
                listenFd = tioQvSocketInit(tioPort, &addressFamily,
                    tioSocketPath);
                if (listenFd < 0) {
                    /* open failed, can't continue */
                    LogMsg(LOG_ERR, "[TIO] could not open server socket\n");
                    return;
                }
                FD_SET(listenFd, &currFdSet);
                nfds = listenFd + 1;
            }
        }

        /* figure out timeout value address */
        struct timeval *pTimeout = 0;
        if (sioFd < 0) {
            /* Linux modifies the timeout value in select() so initialize it */
            timeout.tv_sec = 0;
            timeout.tv_usec = 100000;
            pTimeout = &timeout;
        }

        fd_set readFdSet = currFdSet;
        const int sel = select(nfds, &readFdSet, 0, 0, pTimeout);
        if (sel == -1) {
            if (errno != EINTR) {
                dieWithSystemMessage("select() returned -1");
            }
            /* else keepGoing was set to 0 in signal handler */
        } else if (sel > 0) {
            /* check for a new connection to accept */
            if (FD_ISSET(listenFd, &readFdSet)) {
                /* new connection is here, accept it */
                connectedFd = tioQvSocketAccept(listenFd, addressFamily);
                if (connectedFd >= 0) {
                    FD_CLR(listenFd, &currFdSet);
                    FD_SET(connectedFd, &currFdSet);
                    nfds = max(sioFd, connectedFd) + 1;
                }
            }

            /* see about auto reloading the translation file */
            if ((refreshDelay > 0) &&
                (time(0) > (lastCheckTime + refreshDelay))) {
                lastModTime = loadTranslations(translatorState, translatePath, lastModTime);
                lastCheckTime = time(0);
            }

            /* check for packet received from qml-viewer */
            if ((connectedFd >= 0) && FD_ISSET(connectedFd, &readFdSet)) {
                /* connected qml-viewer has something to say */
                char inMsg[READ_BUF_SIZE];
                const int readCount = readLine2(connectedFd, inMsg,
                    sizeof(inMsg), &fromSio, "qml-viewer");
                if (readCount < 0) {
                    /* socket closed, stop watching this file descriptor */
                    FD_CLR(connectedFd, &currFdSet);
                    FD_SET(listenFd, &currFdSet);
                    connectedFd = -1;
                    nfds = max(sioFd, listenFd) + 1;
                } else if (readCount > 0) {
                    if (sioFd >= 0) {
                        /* 
                         * this is a normal message from qml-viewer, translate
                         * it and send the result to sio_agent 
                         */ 
                        char outMsg[READ_BUF_SIZE];
                        translate_gui_msg(translatorState, inMsg, outMsg,
                            sizeof(outMsg));
                        tioSioSocketWrite(sioFd, outMsg);
                        tioSioSocketWrite(sioFd, "\r");
                    }
                }
            }

            /* check for anything from sio_agent connection */
            if ((sioFd >= 0) && FD_ISSET(sioFd, &readFdSet)) {
                /* 
                 * sio_agent socket port has something to send to the 
                 * tio_agent, if connected 
                 */
                char inMsg[READ_BUF_SIZE];
                int readCount = readLine2(sioFd, inMsg, sizeof(inMsg),
                    &fromQv, "sio-agent");
                if (readCount < 0) {
                    /* fall out of this loop to reopen connection to sio_agent */
                    FD_CLR(sioFd, &currFdSet);
                    sioFd = -1;
                    if(connectedFd >=0) {
                        close(connectedFd);
                    }
                    connectedFd = -1;
                    FD_CLR(connectedFd, &currFdSet);
                    if(listenFd >=0) {
                        close(listenFd);
                    }
                    listenFd = -1;
                    FD_CLR(listenFd, &currFdSet);
                    nfds = 0;
                } else if ((readCount > 0) && (connectedFd >= 0)) {
                    char outMsg[READ_BUF_SIZE];
                    translate_micro_msg(translatorState, inMsg, outMsg,
                        sizeof(outMsg));
                    tioQvSocketWrite(connectedFd, outMsg);
                    tioQvSocketWrite(connectedFd, "\n");
                }
            }
        } /* else timeout to retry opening sio_agent socket */
    }

    LogMsg(LOG_INFO, "[TIO] cleaning up\n");
    freeTranslations(translatorState);

    if (connectedFd >= 0) {
        close(connectedFd);
    }
    if (listenFd >= 0) {
        close(listenFd);
    }
    if (sioFd >= 0) {
        close(sioFd);
    }
    
    if (tioPort == 0) {
        /* best effort removal of socket */
        const int rv = unlink(tioSocketPath);
        if (rv == 0) {
            LogMsg(LOG_INFO, "[TIO] socket file %s unlinked\n", tioSocketPath);
        } else {
            LogMsg(LOG_INFO, "[TIO] socket file %s unlink failed\n", tioSocketPath);
        }
    }

}
Sysuid::Sysuid(QObject* parent) : QObject(parent)
{
    instance_ = this;

    // Load translations of System-UI
    loadTranslations();

    // D-Bus registration
    QDBusConnection bus = QDBusConnection::sessionBus();
    if (!bus.registerService(SYSTEMUI_DBUS_SERVICE)) {
        qCritical("Unable to register system-ui D-Bus service %s: %s", SYSTEMUI_DBUS_SERVICE, bus.lastError().message().toUtf8().constData());
        abort();
    }
    if (!bus.registerObject(SYSTEMUI_DBUS_PATH, instance())) {
        qCritical("Unable to register system-ui object at path %s: %s", SYSTEMUI_DBUS_PATH, bus.lastError().message().toUtf8().constData());
        abort();
    }

    // Initialize notification system
    notificationManager = new NotificationManager(NOTIFICATION_RELAY_INTERVAL);
    mCompositorNotificationSink = new MCompositorNotificationSink;
    ngfNotificationSink = new NGFNotificationSink;
    notificationStatusIndicatorSink_ = new NotificationStatusIndicatorSink;

    // Connect the notification signals for the compositor notification sink
    connect(notificationManager, SIGNAL(notificationUpdated(const Notification &)), mCompositorNotificationSink, SLOT(addNotification(const Notification &)));
    connect(notificationManager, SIGNAL(notificationRemoved(uint)), mCompositorNotificationSink, SLOT(removeNotification(uint)));
    connect(mCompositorNotificationSink, SIGNAL(notificationRemovalRequested(uint)), notificationManager, SLOT(removeNotification(uint)));

    // Connect the notification signals for the feedback notification sink
    connect(notificationManager, SIGNAL(notificationUpdated(const Notification &)), ngfNotificationSink, SLOT(addNotification(const Notification &)));
    connect(notificationManager, SIGNAL(notificationRemoved(uint)), ngfNotificationSink, SLOT(removeNotification(uint)));

    // Connect the notification signals for the notification status indicator sink
    connect(notificationManager, SIGNAL(notificationUpdated(const Notification &)), notificationStatusIndicatorSink_, SLOT(addNotification(const Notification &)));
    connect(notificationManager, SIGNAL(notificationRemoved(uint)), notificationStatusIndicatorSink_, SLOT(removeNotification(uint)));
    connect(notificationManager, SIGNAL(notificationRestored(const Notification &)), notificationStatusIndicatorSink_, SLOT(addNotification(const Notification &)));
    connect(notificationManager, SIGNAL(groupUpdated(uint, const NotificationParameters &)), notificationStatusIndicatorSink_, SLOT(addGroup(uint, const NotificationParameters &)));

    // Subscribe to a context property for getting information about the video recording status
    ContextFrameworkContext context;
    useMode = QSharedPointer<ContextItem>(context.createContextItem("/com/nokia/policy/camera"));
    useMode.data()->subscribe();
    connect(useMode.data(), SIGNAL(contentsChanged()), this, SLOT(applyUseMode()));
    applyUseMode();

    // Create shut down UI
    shutdownBusinessLogic = new ShutdownBusinessLogic(this);
    new ShutdownBusinessLogicAdaptor(this, shutdownBusinessLogic);

    // Create a status area renderer for rendering the shared status area pixmap
    statusAreaRenderer = new StatusAreaRenderer(this);
    new StatusAreaRendererAdaptor(statusAreaRenderer);
    bus.registerService("com.meego.core.MStatusBar");
    bus.registerObject("/statusbar", statusAreaRenderer);

    // Create a status indicator menu
    statusIndicatorMenuBusinessLogic = new StatusIndicatorMenuBusinessLogic(this);
    connect(statusIndicatorMenuBusinessLogic, SIGNAL(statusIndicatorMenuVisibilityChanged(bool)), this, SLOT(updateCompositorNotificationSinkEnabledStatus()));
    new StatusIndicatorMenuAdaptor(statusIndicatorMenuBusinessLogic);
    bus.registerService("com.meego.core.MStatusIndicatorMenu");
    bus.registerObject("/statusindicatormenu", statusIndicatorMenuBusinessLogic);

    // Create screen lock business logic
    screenLockBusinessLogic = new ScreenLockBusinessLogic(this);
    new ScreenLockBusinessLogicAdaptor(screenLockBusinessLogic);
    connect(screenLockBusinessLogic, SIGNAL(screenIsLocked(bool)), this, SLOT(updateCompositorNotificationSinkEnabledStatus()));
    connect(screenLockBusinessLogic, SIGNAL(screenIsLocked(bool)), mCompositorNotificationSink, SLOT(setTouchScreenLockActive(bool)));

    // MCE expects the service to be registered on the system bus
    QDBusConnection systemBus = QDBusConnection::systemBus();
    if (!systemBus.registerService(SCREENLOCK_DBUS_SERVICE)) {
        qWarning("Unable to register screen lock D-Bus service %s: %s", SCREENLOCK_DBUS_SERVICE, systemBus.lastError().message().toUtf8().constData());
    }
    if (!systemBus.registerObject(SCREENLOCK_DBUS_PATH, screenLockBusinessLogic)) {
        qWarning("Unable to register screen lock object at path %s: %s", SCREENLOCK_DBUS_PATH, systemBus.lastError().message().toUtf8().constData());
    }

    // Update the enabled status of compositor notification sink based on screen and device locks
#ifdef HAVE_QMSYSTEM
    connect(&qmLocks, SIGNAL(stateChanged(MeeGo::QmLocks::Lock, MeeGo::QmLocks::State)), this, SLOT(updateCompositorNotificationSinkEnabledStatus()));
#endif
    updateCompositorNotificationSinkEnabledStatus();

    // Create an extension area for the volume extension
    volumeExtensionArea = new MApplicationExtensionArea("com.meego.core.VolumeExtensionInterface/0.20");
    volumeExtensionArea->setInProcessFilter(QRegExp("/sysuid-volume.desktop$"));
    volumeExtensionArea->setOutOfProcessFilter(QRegExp("$^"));
    volumeExtensionArea->init();

    // Initialize notifications store after all the signal connections are made to the notification sinks but before any components that may send/remove notifications
    notificationManager->initializeStore();

    // Create components that may create or remove notifications
    batteryBusinessLogic = new BatteryBusinessLogic(this);
    connect(screenLockBusinessLogic, SIGNAL(screenIsLocked(bool)), batteryBusinessLogic, SLOT(setTouchScreenLockActive(bool)));

    usbUi = new UsbUi(this);

    new DiskSpaceNotifier(this);

    // Unlock the touch screen lock when displaying the USB dialog
    connect(usbUi, SIGNAL(dialogShown()), screenLockBusinessLogic, SLOT(unlockScreen()));
}
PHIApplication::PHIApplication( int &argc, char **argv, const char *name , const char *version, Type type )
    : QObject( 0 ), _app( 0 ), _settings( 0 ), _serverSettings( 0 ), _type( type )
{
    qDebug( "PHIApplication::PHIApplication()" );
    Q_ASSERT( argc>0 );
    _instance=this;
    setObjectName( QString::fromLatin1( name ) );
    const QString phis=L1( "phis" );
    _usrDocPath=QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation );
    QDir rootDir;

#ifdef PHIAPPSTORE
    // needed for Apple AppStore:
    const QString domain=QString::fromLatin1( "phisys.com" );
    const QString org=QString::fromLatin1( "Phisys AG" );
#else
    const QString domain=QString::fromLatin1( PHIDOM );
    const QString org=QString::fromLatin1( PHIORG );
#endif

#ifdef Q_OS_WIN
    _serverSettings=new QSettings( QSettings::NativeFormat, QSettings::SystemScope, org, phis, this );
    rootDir=QFileInfo( qAppFileName() ).dir();
    rootDir.cdUp();
    _rootPath=rootDir.canonicalPath();
    _binPath=_rootPath+L1( "/bin" );
    _libPath=_binPath;
    _pluginsPath=_binPath+L1( "/plugins" );
    _modulesPath=_pluginsPath+L1( "/modules" );
    _itemsPath=_pluginsPath+L1( "/items" );
    _tsPath=_rootPath+L1( "/ts" );
    _serverBin=_binPath+L1( "/Phis.exe" );
    _appBin=_binPath+L1( "/PhiApp.exe" );
#elif defined Q_OS_MAC
    _serverSettings=new QSettings( domain, phis, this );
    rootDir=QFileInfo( QString::fromLocal8Bit( argv[0] ) ).dir(); // bundleID/Contents/MacOS
    _binPath=rootDir.canonicalPath();
    rootDir.cdUp(); // bundleID/Contents
    _libPath=rootDir.canonicalPath()+L1( "/Frameworks" );
    rootDir.cdUp(); // bundleID
    _rootPath=rootDir.canonicalPath();
    _pluginsPath=_rootPath+L1( "/Contents/PlugIns" );
    _modulesPath=_pluginsPath+L1( "/modules" );
    _itemsPath=_pluginsPath+L1( "/items" );
    _tsPath=_rootPath+L1( "/Contents/Resources/ts" );
    _serverBin=_binPath+L1( "/Phis" );
    _appBin=_binPath+L1( "/PhiApp" );
    _dataPath=QStandardPaths::writableLocation( QStandardPaths::DataLocation )+L1( "/" )+objectName();
#elif defined Q_OS_LINUX
    Q_UNUSED( phis )
    QString conf;
    if ( PHISysInfo::effUserId()==0 ) conf=L1( "/etc/phi/phis.conf" );
    else conf=QStandardPaths::writableLocation( QStandardPaths::HomeLocation )+L1( "/.phi/phis.conf" );
    _serverSettings=new QSettings( conf, QSettings::IniFormat, this );
    if ( type!=ApacheModule ) { // normal application
        QFileInfo fi( QString::fromLatin1( "/proc/%1/exe" ).arg( PHISysInfo::processId() ) );
        if ( fi.exists() && fi.isSymLink() ) _binPath=fi.canonicalPath();
        else _binPath=QFileInfo( QString::fromLocal8Bit( argv[0] ) ).canonicalPath();
        rootDir.setPath( _binPath );
        rootDir.cdUp();
        _rootPath=rootDir.canonicalPath();
    } else { // Apache module
        conf=L1( "/opt/phi" ); // fallback
        _rootPath=_serverSettings->value( L1( "RootDir" ), conf ).toString();
        _binPath=_rootPath+L1( "/bin" );
        conf=_rootPath+L1( "/plugins" ); // fallback
        _usrDocPath=L1( "/root/Documents" );
    }
    _pluginsPath=_rootPath+L1( "/plugins" );
    _modulesPath=_pluginsPath+L1( "/modules" );
    _itemsPath=_pluginsPath+L1( "/items" );
    _libPath=_rootPath+L1( "/lib" );
    _tsPath=_rootPath+L1( "/ts" );
    _serverBin=_binPath+L1( "/phis" );
    _appBin=_binPath+L1( "/phiapp" );
    if ( PHISysInfo::effUserId()==0 )  _dataPath=L1( "/var/phis/" );
    else _dataPath=QStandardPaths::writableLocation( QStandardPaths::HomeLocation )+L1( "/.phi/phis" );
#else
#error Unsupported system
#endif

    Q_ASSERT( _serverSettings );
    // Fix for QPA (Qt5 needs to find platform plugins - better way could be qt.conf)
    _pluginsPath=_serverSettings->value( L1( "PluginsPath" ), _pluginsPath ).toString();
    qputenv( "QT_PLUGIN_PATH", _pluginsPath.toUtf8() );

    if ( type==ApacheModule || type==Service ) {
#ifdef Q_OS_MAC
        qputenv( "QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM", "1" );
#elif defined Q_OS_LINUX
        QByteArray fdir=_serverSettings->value( L1( "FontDir" ), _libPath+L1( "/fonts" ) ).toString().toUtf8();
        qputenv( "QT_QPA_FONTDIR", fdir );
#endif
        _app=new QGuiApplication( argc, argv );
        delete _settings;
        _settings=_serverSettings;
    } else {
        PHIPrivateApplication *pApp=new PHIPrivateApplication( argc, argv );
        connect( pApp, &PHIPrivateApplication::openFileRequest,
            this, &PHIApplication::openFileRequest, Qt::QueuedConnection );
        _app=pApp;
#ifdef Q_OS_MAC
        _settings=new QSettings( QSettings::UserScope, domain, objectName(), this );
#elif defined Q_OS_WIN
        _settings=new QSettings( QSettings::UserScope, org, objectName(), this );
#elif defined Q_OS_LINUX
        QString s=QStandardPaths::writableLocation( QStandardPaths::HomeLocation )
            +L1( "/.phi/" )+objectName()+L1( ".conf" );
        _settings=new QSettings( s, QSettings::IniFormat, this );
        qobject_cast<QApplication*>(_app)->setStyle( L1( "fusion" ) );
#else
#error Unsupported system
#endif
    }

    Q_ASSERT( _settings );
    _cachePath=QStandardPaths::writableLocation( QStandardPaths::CacheLocation );
#ifdef Q_OS_WIN
    _dataPath=_settings->value( L1( "BaseDir" ), _rootPath+L1( "/data" ) ).toString();
    _tmpPath=_dataPath+L1( "/temp" );
#elif defined Q_OS_MAC
    _tmpPath=QStandardPaths::writableLocation( QStandardPaths::TempLocation )+QLatin1Char( '/' )+objectName();
#else
    _tmpPath=L1( "/tmp/" )+objectName();
#endif
    _tmpPath=_settings->value( L1( "TempDir" ), _tmpPath ).toString();
    if ( type==Service || type==ApacheModule ) {
        _cachePath=_tmpPath+L1( "/cache" );
        _settings->beginGroup( PHI::defaultString() );
        _dataPath=_settings->value( L1( "BaseDir" ), _dataPath ).toString();
        _settings->endGroup();
    } else {
        if ( !QFileInfo( _cachePath ).exists() ) QDir( _cachePath ).mkpath( _cachePath );
        if ( !QFileInfo( _tmpPath ).exists() ) QDir( _tmpPath ).mkpath( _tmpPath );
    }
    qRegisterMetaTypeStreamOperators<PHIRectHash>("PHIRectHash");
    qRegisterMetaTypeStreamOperators<PHIByteArrayList>("PHIByteArrayList");
    qRegisterMetaTypeStreamOperators<PHIImageHash>("PHIImageHash");
    qRegisterMetaTypeStreamOperators<QGradientStops>("QGradientStops");
    qRegisterMetaTypeStreamOperators<PHIListChar>("PHIListChar");
    qRegisterMetaTypeStreamOperators<PHIListWord>("PHIListWord");
    qRegisterMetaType<QDateTime>("QDateTime");
    qRegisterMetaType<PHIRC>("PHIRC");
    qRegisterMetaType<PHIWID>("PHIWID");
    qRegisterMetaType<QSizePolicy>("QSizePolicy");

#ifdef PHIDEBUG
    _rootPath=L1( PHIDIR );
    _binPath=L1( PHIDIR )+L1( "/bin" );
    _pluginsPath=L1( PHIDIR )+L1( "/plugins" );
    _itemsPath=_pluginsPath+L1( "/items" );
    _serverBin=L1( PHIDIR )+L1( "/bin/Phisd" );
    _appBin=L1( PHIDIR )+L1( "/bin/PhiAppd" );
    _tsPath=L1( PHIDIR )+L1( "/src/ts" );
    _libPath=L1( PHIDIR )+L1( "/lib" );
    _modulesPath=_libPath+L1( "/modules" );
#ifdef Q_OS_WIN
    _libPath=L1( PHIDIR )+L1( "/bin" );
    _pluginsPath=_libPath+L1( "/plugins" );
    _itemsPath=_pluginsPath+L1( "/items" );
    _modulesPath=_pluginsPath+L1( "/modules" );
    _serverBin=L1( PHIDIR )+L1( "/bin/Phisd.exe" );
    _appBin=L1( PHIDIR )+L1( "/bin/PhiAppd.exe" );
#elif defined Q_OS_LINUX
    _serverBin=L1( PHIDIR )+L1( "/bin/phis_debug" );
    _appBin=L1( PHIDIR )+L1( "/bin/phiapp_debug" );
#endif

#endif
#ifdef PHIEMBEDEDSERVER
    _serverBin=QString();
#endif
#ifdef PHIEMBEDEDAPP
    _appBin=QString();
#endif
    _pluginsPath=QDir::toNativeSeparators( _pluginsPath );
    _itemsPath=QDir::toNativeSeparators( _itemsPath );
    _modulesPath=QDir::toNativeSeparators( _modulesPath );
    _binPath=QDir::toNativeSeparators( _binPath );
    _serverBin=QDir::toNativeSeparators( _serverBin );
    _appBin=QDir::toNativeSeparators( _appBin );
    _tsPath=QDir::toNativeSeparators( _tsPath );
    _rootPath=QDir::toNativeSeparators( _rootPath );
    _libPath=QDir::toNativeSeparators( _libPath );
    _tmpPath=QDir::toNativeSeparators( _tmpPath );
    _cachePath=QDir::toNativeSeparators( _cachePath );
    _dataPath=QDir::toNativeSeparators( _dataPath );
    _usrDocPath=QDir::toNativeSeparators( _usrDocPath );

#ifdef PHIPRINTDIRS
    qWarning( "App name:       %s", name );
    qWarning( "Version:        %s", version );
    qWarning( "Settings file:  %s", qPrintable( _settings->fileName() ) );
    qWarning( "Server setings: %s", qPrintable( _serverSettings->fileName() ) );
    qWarning( "Root dir:       %s", qPrintable( _rootPath ) );
    qWarning( "Plug-in dir:    %s", qPrintable( _pluginsPath ) );
    qWarning( "Items dir:      %s", qPrintable( _itemsPath ) );
    qWarning( "Modules dir:    %s", qPrintable( _modulesPath ) );
    qWarning( "Bin dir:        %s", qPrintable( _binPath ) );
    qWarning( "Server bin:     %s", qPrintable( _serverBin ) );
    qWarning( "PhiApp bin:     %s", qPrintable( _appBin ) );
    qWarning( "TS dir:         %s", qPrintable( _tsPath ) );
    qWarning( "Lib dir:        %s", qPrintable( _libPath ) );
    qWarning( "Tmp dir:        %s", qPrintable( _tmpPath ) );
    qWarning( "Cache dir:      %s", qPrintable( _cachePath ) );
    qWarning( "Data dir:       %s", qPrintable( _dataPath ) );
    qWarning( "User doc dir:   %s", qPrintable( _usrDocPath ) );
#endif

    Q_ASSERT( _app );
    _app->setApplicationName( objectName() );
    _app->setApplicationVersion( QString::fromLatin1( version ) );
    _app->setOrganizationDomain( domain );
    _app->setOrganizationName( org );
    _app->addLibraryPath( _pluginsPath );
    loadTranslations();
    PHINetManager::instance();
    new PHIItemFactory( _itemsPath, this );

#ifdef PHIWEBKIT
    QWebSettings *ws=QWebSettings::globalSettings();
    ws->setAttribute( QWebSettings::PluginsEnabled, true );
    ws->setAttribute( QWebSettings::JavascriptCanOpenWindows, true );
    ws->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
    ws->setAttribute( QWebSettings::JavascriptEnabled, true );
    ws->setIconDatabasePath( _cachePath );
#endif
}