Commit 181e0c38 by NitefullWind

1. 加入事件发送和响应代码. 2. Home使用fmp_setting读取配置信息。

parent 36a3b281
......@@ -17,3 +17,10 @@ Level=1
[Syncer]
Server=http://www.baidu.com
Timer=10
[Home]
Server=http://115.159.226.87:20001/api/user/login
StoreId=fm99999
PartnerId=1371
;动画开关,0:关闭 1:开启
Animation=1
\ No newline at end of file
#include "fmp_epay_p.h"
#include "fmp_pe_handlers.h"
class ctkPluginContext;
FMPePay::FMPePay(ctkPluginContext *context)
: FMPePayInterface(context),
_inited(false),
d_ptr(new FMPePayPrivate)
{
FMPStartEventHandler *ste_handler = new FMPStartEventHandler(_ctx, this);
}
int FMPePay::StopService()
......
......@@ -9,13 +9,15 @@ TEMPLATE = lib
SOURCES += \
fmp_epay.cpp \
fmp_epay_p.cpp \
fmp_epay_plugin.cpp
fmp_epay_plugin.cpp \
fmp_pe_handlers.cpp
HEADERS +=\
fmp_epay.h \
fmp_epay_i.h \
fmp_epay_p.h \
fmp_epay_plugin_p.h
fmp_epay_plugin_p.h \
fmp_pe_handlers.h
unix {
target.path = /usr/lib
......
......@@ -5,12 +5,12 @@
#include <ctkPluginContext.h>
#include <ctkServiceReference.h>
#include <QDebug>
#include "fmp_pe_handlers.h"
int FMPePayPrivate::StartService()
{
qDebug() << "======== ePay init ===========";
Q_Q(FMPePay);
q->_inited = true;
return FMP_SUCCESS;
}
......
#include <fmp_logger_i.h>
#include "fmp_pe_handlers.h"
#include "fmp_epay.h"
FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPePay *epay)
: FMPePayEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_START "/"
+ QString::number(ctx->getPlugin()->getPluginId()), epay),
_ctx(ctx)
{
FMPProps props;
props[ctkEventConstants::EVENT_TOPIC] = _topic;
_ctx->registerService<ctkEventHandler>(this, props);
}
void FMPStartEventHandler::handleEvent(const ctkEvent &event)
{
qDebug() << "=======-------";
if (_epay) {
if (event.getProperty(FMP_PROPKEY_AGREED).toBool()) {
// _epay->UpgradeOldPlugins(event.getProperty(FMP_PROPKEY_PID_LIST).toList());
_epay->Pay();
}
else {
FMP_WARN_CTX(_ctx) << "Refused start request" << event.getTopic();
}
}
else {
FMP_DEBUG_CTX(_ctx) << "No handler instance for event" << event.getTopic();
}
}
#ifndef FMP_MANAGER_EVENT_HANDLERS_H
#define FMP_MANAGER_EVENT_HANDLERS_H
#include <QObject>
#include <service/event/ctkEventConstants.h>
#include <service/event/ctkEventHandler.h>
class FMPePay;
class FMPePayEventHandler : public ctkEventHandler
{
public:
explicit FMPePayEventHandler(const QString &topic, FMPePay *epay) : _epay(epay), _topic(topic) {}
protected:
FMPePay* _epay;
const QString _topic;
};
/**
* 升级事件处理类
* @brief The FMPUpgradeEventHandler class
*/
class FMPStartEventHandler : public QObject, public FMPePayEventHandler
{
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPStartEventHandler(ctkPluginContext *ctx, FMPePay *epay);
void handleEvent(const ctkEvent &event);
private:
ctkPluginContext* _ctx;
};
#endif // FMP_MANAGER_EVENT_HANDLERS_H
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 7
#define VER_BUILD 10
//! Convert version numbers to string
#define _STR(S) #S
......
#include <fmp_logger_i.h>
#include "fmp_he_handlers.h"
#include "fmp_home.h"
FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home)
: FMPHomeEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_REQ_START "/*" , home),
_ctx(ctx)
{
FMPProps props;
props[ctkEventConstants::EVENT_TOPIC] = _topic;
_ctx->registerService<ctkEventHandler>(this, props);
}
void FMPStartEventHandler::handleEvent(const ctkEvent &event)
{
qDebug() << "===========";
if (_home) {
QString ack_topic = event.getTopic();
//! com/fmp/services/REQ_START/id
ack_topic.replace(FMPE_SERVICE_REQ_START, FMPE_SERVICE_ACK_START);
FMPProps props;
props[FMP_PROPKEY_AGREED] = _home->isLogined();
_home->PostEvent(ack_topic, props);
}
else {
FMP_DEBUG_CTX(_ctx) << "No handler instance for event" << event.getTopic();
}
}
#ifndef FMP_MANAGER_EVENT_HANDLERS_H
#define FMP_MANAGER_EVENT_HANDLERS_H
#include <QObject>
#include <service/event/ctkEventConstants.h>
#include <service/event/ctkEventHandler.h>
class FMPHome;
class FMPHomeEventHandler : public ctkEventHandler
{
public:
explicit FMPHomeEventHandler(const QString &topic, FMPHome *home) : _home(home), _topic(topic) {}
protected:
FMPHome* _home;
const QString _topic;
};
class FMPStartEventHandler : public QObject, public FMPHomeEventHandler
{
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home);
void handleEvent(const ctkEvent &event);
private:
ctkPluginContext* _ctx;
};
#endif // FMP_MANAGER_EVENT_HANDLERS_H
......@@ -28,6 +28,12 @@ int FMPHome::StopService()
return d->Uninit();
}
void FMPHome::StartPlugins(const QVariantList &pids)
{
Q_D(FMPHome);
d->StartPlugins(pids);
}
int FMPHome::login()
{
Q_D(FMPHome);
......
......@@ -7,6 +7,7 @@
class ctkPluginContext;
class FMPHomePrivate;
class FMPStartEventHandler;
class FMPHome : public QObject, public FMPHomeInterface
{
......@@ -21,9 +22,17 @@ public:
int StartService();
int StopService();
void StartPlugins(const QVariantList &pids);
int login();
bool isLogined();
QString userName();
private:
FMPHomePrivate *d_ptr;
bool _inited;
friend class FMPStartEventHandler;
};
#endif // FMP_HOME_H
......@@ -20,7 +20,8 @@ SOURCES +=\
fmp_wnd.cpp \
fmp_login.cpp \
fmp_num_pad.cpp \
fmnetwork.cpp
fmnetwork.cpp \
fmp_he_handlers.cpp
HEADERS += fmp_home.h \
fmp_home_plugin_p.h \
......@@ -31,7 +32,8 @@ HEADERS += fmp_home.h \
fmp_login.h \
menubutton.h \
fmp_num_pad.h \
fmnetwork.h
fmnetwork.h \
fmp_he_handlers.h
FORMS += \
fmp_home_navwindow.ui \
......
......@@ -5,13 +5,15 @@
#include <QDesktopWidget>
#include <QParallelAnimationGroup>
#include <QPropertyAnimation>
#include <fmp_settings_i.h>
NavWindow::NavWindow(QWidget *parent) :
NavWindow::NavWindow(FMPSettingsInterface *&settings, QWidget *parent) :
QDialog(parent),
ui(new Ui::NavWindow),
_btn_group(new QButtonGroup(this)),
_animationShow(new QParallelAnimationGroup(this)),
PI(3.1415926)
PI(3.1415926),
_settings(settings)
{
ui->setupUi(this);
ui->navMainBtn->setMovedItem(this);
......@@ -21,7 +23,7 @@ NavWindow::NavWindow(QWidget *parent) :
MenuUiProp.distance = 100;
MenuUiProp.beginAngle = -(PI*0.45);
MenuUiProp.endAngle = (PI*0.45);
isUseAnimation = true;
isUseAnimation = _settings->GetBool(FMP_INIKEY_HOMEANIMATION);
setNavStatus(Default);
......
......@@ -12,6 +12,7 @@ class NavWindow;
class QButtonGroup;
class QAbstractButton;
class QParallelAnimationGroup;
class FMPSettingsInterface;
class NavWindow : public QDialog
{
......@@ -30,7 +31,7 @@ public:
Message
};
explicit NavWindow(QWidget *parent = 0);
explicit NavWindow(FMPSettingsInterface* &settings, QWidget *parent = 0);
~NavWindow();
public slots:
......@@ -77,6 +78,8 @@ private:
};
MenuUiProps MenuUiProp;
bool isUseAnimation;
FMPSettingsInterface *_settings;
};
#endif // NAVWINDOW_H
......@@ -4,11 +4,13 @@
#include <ctkPluginContext.h>
#include <ctkServiceReference.h>
#include <QDebug>
#include <fmp_epay_i.h>
#include <fmp_settings_i.h>
#include "fmp_login.h"
#include "fmp_he_handlers.h"
FMPHomePrivate::FMPHomePrivate(FMPHome *q)
: q_ptr(q),
_navWindow(new NavWindow),
_isLogined(false),
_userName(""),
_errorMsg("")
......@@ -22,13 +24,18 @@ FMPHomePrivate::~FMPHomePrivate()
int FMPHomePrivate::Init()
{
Q_Q(FMPHome);
_settings = q->GetService<FMPSettingsInterface>(q->_ctx);
_navWindow = new NavWindow(_settings);
FMPStartEventHandler* handler = new FMPStartEventHandler(q->_ctx, q);
if(login() != FMP_SUCCESS) {
return FMP_FAILURE;
}
_navWindow->show();
connect(_navWindow, SIGNAL(menuBtnClicked(QString)), this, SLOT(onMenuBtnClicked(QString)));
Q_Q(FMPHome);
q->_inited = true;
return FMP_SUCCESS;
}
......@@ -48,9 +55,16 @@ int FMPHomePrivate::Uninit()
return FMP_SUCCESS;
}
void FMPHomePrivate::StartPlugins(const QVariantList &pids)
{
qDebug() << pids;
}
int FMPHomePrivate::login()
{
FMPLogin loginWnd;
FMPLogin loginWnd(_settings->GetString(FMP_INIKEY_LOGINSERVER),
_settings->GetString(FMP_INIKEY_LOGINSTOREID),
_settings->GetString(FMP_INIKEY_LOGINPARTNERID));
loginWnd.exec();
if(loginWnd.isLogined()) {
_isLogined = true;
......@@ -64,11 +78,13 @@ int FMPHomePrivate::login()
void FMPHomePrivate::onMenuBtnClicked(QString btnName)
{
qDebug() << "====" << __FUNCTION__ << btnName;
Q_Q(FMPHome);
FMP_DEBUG_CTX(q->_ctx) << "Menu clicked: " << btnName;
if(btnName == "huiyuanshezhi")
{
FMP_DEBUG_CTX(q->_ctx) << "Menu clicked";
if(btnName == "payment") {
FMPePayInterface *e = q->GetService<FMPePayInterface>(q->_ctx);
e->StartService();
} else if(btnName == "tool") {
qDebug() << "tool menu";
}
}
......@@ -5,6 +5,7 @@
class NavWindow;
class FMPLogin;
class FMPSettingsInterface;
class FMPHomePrivate : public QObject
{
......@@ -16,6 +17,7 @@ public:
int Init();
int Uninit();
void StartPlugins(const QVariantList &pids);
int login();
public slots:
......@@ -30,6 +32,7 @@ public:
private:
NavWindow *_navWindow;
FMPSettingsInterface *_settings;
};
#endif // FMP_HOME_P_H
......@@ -9,12 +9,15 @@
#include "fmnetwork.h"
#include <QDebug>
FMPLogin::FMPLogin(QDialog *parent) :
FMPLogin::FMPLogin(QString url, QString storeId, QString partnerId, QDialog *parent) :
FMPWnd(parent),
ui(new Ui::FMPLogin),
_numPad(new FMNumPad),
_userName(""),
_errorMsg("")
_errorMsg(""),
_url(url),
_storeId(storeId),
_partnerId(partnerId)
{
ui->setupUi(this);
connect(_numPad, SIGNAL(digit_confirm()), this, SLOT(on_login_btn_clicked()));
......@@ -48,15 +51,14 @@ void FMPLogin::on_login_btn_clicked()
bool FMPLogin::login(QString userName, QString password)
{
_userName = "";
QString url = "http://115.159.226.87:20001/api/user/login";
QByteArray reqData = tr("{\"StoreId\": \"%1\",\"PartnerId\": \"%2\",\"UserId\": \"%3\",\"Pwd\": \"%4\"}")
.arg("fm99999")
.arg("1371")
.arg(_storeId)
.arg(_partnerId)
.arg(userName)
.arg(password).toLatin1();
QByteArray rspData;
FMNetwork net;
if(net.post(url, &reqData, &rspData)) {
if(net.post(_url, &reqData, &rspData)) {
// 解析返回的数据
QJsonParseError error;
QJsonDocument json = QJsonDocument::fromJson(rspData, &error);
......
......@@ -14,7 +14,7 @@ class FMPLogin : public FMPWnd
Q_OBJECT
public:
explicit FMPLogin(QDialog *parent = 0);
explicit FMPLogin(QString url, QString storeId, QString partnerId, QDialog *parent = 0);
~FMPLogin();
/**
......@@ -41,6 +41,10 @@ private:
FMNumPad* _numPad;
QString _userName;
QString _errorMsg;
const QString _url;
const QString _storeId;
const QString _partnerId;
};
#endif // FMP_LOGIN_H
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 7
#define VER_BUILD 10
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 7
#define VER_BUILD 10
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -11,7 +11,6 @@
#include <fmp_logger_i.h>
#include <fmp_settings_i.h>
#include <fmp_syncer_i.h>
#include <fmp_home_i.h>
FMPluginManager::FMPluginManager() :
_ctx(nullptr),
......@@ -201,7 +200,7 @@ void FMPluginManager::OnPluginsChanged(const QString &path)
if (!expired_plugins.isEmpty()) {
FMPProps props;
props[FMP_PROPKEY_PID_LIST] = expired_plugins;
PostEvent(QString(FMP_TOPICS_SERVICES) + "/" + FMPE_SERVICE_REQ_UPDATE, props);
PostEvent(QString(FMP_TOPICS_SERVICES) + FMPE_SERVICE_REQ_UPDATE, props);
}
}
......
......@@ -3,7 +3,7 @@
#include "fmp_manager.h"
FMPUpgradeEventHandler::FMPUpgradeEventHandler(ctkPluginContext *ctx, FMPluginManager *pm)
: FMPManagerEventHandler(FMP_TOPICS_SERVICES "/" FMPE_SERVICE_REQ_UPDATE, pm),
: FMPManagerEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_REQ_UPDATE, pm),
_ctx(ctx)
{
FMPProps props;
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 7
#define VER_BUILD 10
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -20,5 +20,9 @@
#define FMP_INIKEY_LOGSIZE "Log/Size"
#define FMP_INIKEY_LOGLEVEL "Log/Level"
#define FMP_INIKEY_LOGINSERVER "Home/Server"
#define FMP_INIKEY_LOGINSTOREID "Home/StoreId"
#define FMP_INIKEY_LOGINPARTNERID "Home/PartnerId"
#define FMP_INIKEY_HOMEANIMATION "Home/Animation"
#endif // FMP_SETTINGS_DEF_H
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 7
#define VER_BUILD 10
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -8,13 +8,11 @@ QT -= gui
TEMPLATE = lib
SOURCES += \
fmupdater.cpp \
fmp_syncer.cpp \
fmp_syncer_p.cpp \
fmp_syncer_plugin.cpp
HEADERS += \
fmupdater.h \
fmp_syncer.h \
fmp_syncer_i.h \
fmp_syncer_p.h \
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 7
#define VER_BUILD 10
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -21,7 +21,8 @@ public:
int StartService()
{
QString topic = FMP_TOPICS_SERVICES;
topic += QString::number(_ctx->getPlugin()->getPluginId()) + "/" + FMPE_SERVICE_REQ_START;
topic += FMPE_SERVICE_REQ_START;
topic += "/" + QString::number(_ctx->getPlugin()->getPluginId());
return PostEvent(topic);
}
......
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