Commit 3f7cfbe7 by Carwyn

1. 每次启动删除配置; 2. 添加单例; 3. Home 解决显示到屏幕外问题

parent 9cd3f530
include ("qtservice/src/qtservice.pri")
QT += core widgets
QT += core widgets network
CONFIG += c++11
TARGET = FreemudPOS
TEMPLATE = app
INCLUDEPATH += $$PWD/../include/interface
SOURCES += \
fm_pos_app.cpp
INCLUDEPATH += $$PWD/../include/interface \
CONFIG(debug, debug|release) {
DESTDIR = $$PWD/../debug/bins
......@@ -21,3 +18,9 @@ else {
win32 {
RC_FILE += res/FreemudPOS.rc
}
HEADERS += \
../include/application/fm_singleton.h
SOURCES += \
fm_pos_app.cpp
#include <QApplication>
#include <fmp_manager_i.h>
#include <fmp_manager_i.h>
#include <QDebug>
#include <QPluginLoader>
#include <QSettings>
......@@ -14,16 +13,17 @@
#undef StartService
#endif
#include "../application/fm_singleton.h"
#include "../fmp_settings/fmp_settings_def.h"
class FMPService : public QtService<QApplication>
class FMPService : public QtService<FMSingleApplication>
{
public:
FMPService(int argc, char**argv, const QString &svcname) :
_starttype(0),
_name(svcname),
_setting(0),
QtService<QApplication>(argc, argv, svcname)
QtService<FMSingleApplication>(argc, argv, svcname)
{
createApplication(argc, argv);
_setting = new QSettings(qApp->applicationDirPath() + "/" + qApp->applicationName() + ".ini", QSettings::IniFormat);
......@@ -36,7 +36,12 @@ public:
setServiceDescription(_description);
}
void start()
bool isRunning()
{
return application()->IsRunning();
}
void start()
{
QString manager_plugin_path = getPluginPath("fmp.manager");
QPluginLoader fmp_manager_plugin(manager_plugin_path);
......@@ -64,7 +69,7 @@ public:
}
}
QString getPluginPath(const QString &plugin_name)
QString getPluginPath(const QString &plugin_name)
{
QString plugin_file_name(plugin_name);
plugin_file_name.replace(".", "_");
......@@ -127,11 +132,15 @@ int main(int argc, char** argv)
FMPService svc(argc, argv, svc_name);
if (!svc.isRunning()) {
#if SERVICE
return svc->exec();
return svc->exec();
#else
svc.start();
return qApp->exec();
svc.start();
return qApp->exec();
#endif
}
else {
return 0;
}
}
fmp_home @ ad717311
Subproject commit 06108fca4c9277b4ce5b1263bdc45db8e21db044
Subproject commit ad71731169534f554792db9e9c286f8407a5b10c
......@@ -29,6 +29,9 @@ void FMPluginManager::InitService()
{
if (_fw_factory) return;
//! 每次启动前删除配置文件夹
QDir(qApp->applicationDirPath() + "/configuration").removeRecursively();
_fw_factory = new ctkPluginFrameworkFactory(_fw_props);
_fw = _fw_factory->getFramework();
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 58
#define VER_BUILD 60
//! Convert version numbers to string
#define _STR(S) #S
......
#ifndef DSINGLEAPPLICATION_H
#define DSINGLEAPPLICATION_H
#include <QWidget>
#include <QFileInfo>
#include <QLocalSocket>
#include <QLocalServer>
#include <QApplication>
class FMSingleApplication : public QApplication
{
Q_OBJECT
public:
explicit FMSingleApplication(int &argc, char **argv)
:QApplication(argc, argv),
widget(NULL),
isRunning(false),
localServer(NULL)
{
//! 取应用程序名作为LocalServer的名字
serverName = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
InitLocalConnection();
}
/** 功能:判断是否有实例在运行
* 返回:true有 false无
**/
bool IsRunning() { return isRunning; }
/** 功能:设置主窗口句柄
* 参数:主窗口句柄
* 返回:NULL
**/
void SetWidget(QWidget* w) { widget = w; }
private slots:
//! 有新连接时触发
void OnNewLocalConnection() { ActivateWindow(); }
private:
//! 初始化本地连接
void InitLocalConnection()
{
isRunning = false;
QLocalSocket socket;
socket.connectToServer(serverName);
if(socket.waitForConnected(500)) {
isRunning = true;
return;
}
//! 连接不上服务器,就创建一个
NewLocalServer();
}
//! 创建服务端
void NewLocalServer()
{
localServer = new QLocalServer(this);
connect(localServer, SIGNAL(newConnection()), this, SLOT(OnNewLocalConnection()));
if(!localServer->listen(serverName)) {
//! 此时监听失败,可能是程序崩溃时,残留进程服务导致的,移除之
if(localServer->serverError() == QAbstractSocket::AddressInUseError) {
QLocalServer::removeServer(serverName);
localServer->listen(serverName); //! 再次监听
}
}
}
//! 激活窗口
void ActivateWindow()
{
if(NULL != widget) {
widget->show();
widget->raise();
widget->activateWindow();
}
return;
}
QWidget * widget; //! 主窗口句柄
bool isRunning; //! 是否已经有实例在运行
QLocalServer * localServer; //! 本地socket Server
QString serverName; //! 服务名称
};
#endif // DSINGLEAPPLICATION_H
/*=============================================================================
Library: CTK
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=============================================================================*/
#ifndef CTKPLUGINGENERATORABSTRACTEXTENSION_H
#define CTKPLUGINGENERATORABSTRACTEXTENSION_H
#include <QObject>
#include <QHash>
#include <org_commontk_plugingenerator_core_Export.h>
class ctkPluginGeneratorAbstractExtensionPrivate;
class ctkPluginGeneratorCodeModel;
class org_commontk_plugingenerator_core_EXPORT ctkPluginGeneratorAbstractExtension : public QObject
{
Q_OBJECT
public:
ctkPluginGeneratorAbstractExtension();
virtual ~ctkPluginGeneratorAbstractExtension();
//virtual void getCommandLineArgs() const = 0;
void setParameter(const QHash<QString, QVariant>& params);
void setParameter(const QString& name, const QVariant& value);
QHash<QString, QVariant> getParameter() const;
bool isValid() const;
void validate();
void updateCodeModel();
QString getErrorMessage() const;
ctkPluginGeneratorCodeModel* getCodeModel() const;
Q_SIGNALS:
void errorMessageChanged(const QString&);
protected:
void setErrorMessage(const QString& errMsg);
virtual bool verifyParameters(const QHash<QString, QVariant>& params) = 0;
virtual void updateCodeModel(const QHash<QString, QVariant>& params) = 0;
private:
Q_DECLARE_PRIVATE(ctkPluginGeneratorAbstractExtension)
const QScopedPointer<ctkPluginGeneratorAbstractExtensionPrivate> d_ptr;
};
#endif // CTKPLUGINGENERATORABSTRACTEXTENSION_H
/*=============================================================================
Library: CTK
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=============================================================================*/
#ifndef CTKPLUGINGENERATORABSTRACTUIEXTENSION_H
#define CTKPLUGINGENERATORABSTRACTUIEXTENSION_H
#include <QObject>
#include <QIcon>
#include <ctkPluginGeneratorAbstractExtension.h>
#include <org_commontk_plugingenerator_ui_Export.h>
class QWidget;
class ctkPluginGeneratorAbstractUiExtensionPrivate;
class org_commontk_plugingenerator_ui_EXPORT ctkPluginGeneratorAbstractUiExtension : public ctkPluginGeneratorAbstractExtension
{
Q_OBJECT
public:
ctkPluginGeneratorAbstractUiExtension();
virtual ~ctkPluginGeneratorAbstractUiExtension();
QWidget* getWidget();
QString getDescription() const;
QString getTitle() const;
QString getMessage() const;
QIcon getIcon() const;
Q_SIGNALS:
void descriptionChanged(const QString&);
void titleChanged(const QString&);
void messageChanged(const QString&);
void iconChanged(const QIcon&);
protected:
virtual QWidget* createWidget() = 0;
void setDescription(const QString& description);
void setTitle(const QString& title);
void setMessage(const QString& msg);
void setIcon(const QIcon& icon);
private:
Q_DECLARE_PRIVATE(ctkPluginGeneratorAbstractUiExtension)
const QScopedPointer<ctkPluginGeneratorAbstractUiExtensionPrivate> d_ptr;
};
#endif // CTKPLUGINGENERATORABSTRACTUIEXTENSION_H
// .NAME __org_commontk_plugingenerator_core_Export - manage Windows system differences
// .SECTION Description
// The __org_commontk_plugingenerator_core_Export captures some system differences between Unix
// and Windows operating systems.
#ifndef __org_commontk_plugingenerator_core_Export_h
#define __org_commontk_plugingenerator_core_Export_h
#include <QtGlobal>
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
# if defined(org_commontk_plugingenerator_core_EXPORTS)
# define org_commontk_plugingenerator_core_EXPORT Q_DECL_EXPORT
# else
# define org_commontk_plugingenerator_core_EXPORT Q_DECL_IMPORT
# endif
#endif
#if !defined(org_commontk_plugingenerator_core_EXPORT)
//# if defined(CTK_SHARED)
# define org_commontk_plugingenerator_core_EXPORT Q_DECL_EXPORT
//# else
//# define org_commontk_plugingenerator_core_EXPORT
//# endif
#endif
#endif
// .NAME __org_commontk_plugingenerator_ui_Export - manage Windows system differences
// .SECTION Description
// The __org_commontk_plugingenerator_ui_Export captures some system differences between Unix
// and Windows operating systems.
#ifndef __org_commontk_plugingenerator_ui_Export_h
#define __org_commontk_plugingenerator_ui_Export_h
#include <QtGlobal>
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
# if defined(org_commontk_plugingenerator_ui_EXPORTS)
# define org_commontk_plugingenerator_ui_EXPORT Q_DECL_EXPORT
# else
# define org_commontk_plugingenerator_ui_EXPORT Q_DECL_IMPORT
# endif
#endif
#if !defined(org_commontk_plugingenerator_ui_EXPORT)
//# if defined(CTK_SHARED)
# define org_commontk_plugingenerator_ui_EXPORT Q_DECL_EXPORT
//# else
//# define org_commontk_plugingenerator_ui_EXPORT
//# endif
#endif
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment