Dev
This commit is contained in:
parent
c6937d5e0c
commit
31997aad40
@ -12,7 +12,10 @@ HEADERS += \
|
||||
Sources/DeadboltDevice.h \
|
||||
Sources/AbstractDevice.h \
|
||||
Sources/ProtocolDefs.h \
|
||||
Sources/AVReceiverDevice.h
|
||||
Sources/AVReceiverDevice.h \
|
||||
Sources/VoipSMS/VoipMsSMSClient.h \
|
||||
Sources/VoipSMS/CSMSMessage.h \
|
||||
Sources/Gui/SystemTrayManager.h
|
||||
|
||||
SOURCES += \
|
||||
Sources/main.cpp \
|
||||
@ -22,7 +25,10 @@ SOURCES += \
|
||||
Sources/EthernetNetworkCommIF.cpp \
|
||||
Sources/NetworkProtocol.cpp \
|
||||
Sources/DeadboltDevice.cpp \
|
||||
Sources/AVReceiverDevice.cpp
|
||||
Sources/AVReceiverDevice.cpp \
|
||||
Sources/VoipSMS/VoipMsSMSClient.cpp \
|
||||
Sources/VoipSMS/CSMSMessage.cpp \
|
||||
Sources/Gui/SystemTrayManager.cpp
|
||||
|
||||
|
||||
#win32:SOURCES += $$PWD/Source/qextserialport/win_qextserialport.cpp \
|
||||
@ -31,4 +37,6 @@ SOURCES += \
|
||||
|
||||
INCLUDEPATH += $$PWD/ \
|
||||
$$PWD/Sources/ \
|
||||
$$PWD/Sources/qextserialport/
|
||||
$$PWD/Sources/qextserialport/ \
|
||||
$$PWD/Sources/VoipSMS/ \
|
||||
$$PWD/Sources/Gui/
|
||||
|
||||
77
Sources/Gui/SystemTrayManager.cpp
Normal file
77
Sources/Gui/SystemTrayManager.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include "SystemTrayManager.h"
|
||||
#include "MasterCtrl.h"
|
||||
#include <QCursor>
|
||||
|
||||
CSystemTrayManager::CSystemTrayManager()
|
||||
{
|
||||
|
||||
mProgramHandle = 0;
|
||||
|
||||
mTrayMenu = new QMenu();
|
||||
|
||||
connect(&mSystemTrayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(TrayIconActivated(QSystemTrayIcon::ActivationReason)));
|
||||
connect(&mSystemTrayIcon,SIGNAL(messageClicked()),this,SLOT(TrayBaloonMessageClicked()));
|
||||
connect(mTrayMenu,SIGNAL(triggered(QAction*)),this,SLOT(TrayMenuClicked(QAction*)));
|
||||
|
||||
mQuitAction = mTrayMenu->addAction("Quit MasterController");
|
||||
mShowSettingsGUIAction = mTrayMenu->addAction("Settings");
|
||||
mSystemTrayIcon.setIcon(QIcon("./Ico/icon.png"));
|
||||
mSystemTrayIcon.setToolTip("MasterController :)");
|
||||
mSystemTrayIcon.show();
|
||||
mSystemTrayIcon.setContextMenu(mTrayMenu);
|
||||
|
||||
}
|
||||
CSystemTrayManager::~CSystemTrayManager()
|
||||
{
|
||||
mSystemTrayIcon.hide();
|
||||
delete mTrayMenu;
|
||||
}
|
||||
|
||||
void CSystemTrayManager::TrayBaloonMessageClicked()
|
||||
{
|
||||
qDebug("Baloon message clicked");
|
||||
}
|
||||
|
||||
void CSystemTrayManager::TrayIconActivated(QSystemTrayIcon::ActivationReason Reason)
|
||||
{
|
||||
qDebug("Tray icon activated %d",Reason);
|
||||
// mSystemTrayIcon.showMessage("Icon Clicked","The icon has\nbeen clicked.");
|
||||
switch(Reason)
|
||||
{
|
||||
case QSystemTrayIcon::Unknown:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case QSystemTrayIcon::Context:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case QSystemTrayIcon::DoubleClick:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case QSystemTrayIcon::Trigger:
|
||||
{
|
||||
mTrayMenu->popup(QCursor::pos());
|
||||
break;
|
||||
}
|
||||
case QSystemTrayIcon::MiddleClick:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSystemTrayManager::TrayMenuClicked(QAction *Menu)
|
||||
{
|
||||
if(Menu == mQuitAction)
|
||||
{
|
||||
qDebug("Quit");
|
||||
mProgramHandle->QuitApplicationRequest();
|
||||
}
|
||||
else if(Menu == mShowSettingsGUIAction)
|
||||
{
|
||||
qDebug("Settings");
|
||||
}
|
||||
|
||||
}
|
||||
30
Sources/Gui/SystemTrayManager.h
Normal file
30
Sources/Gui/SystemTrayManager.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef CSYSTEMTRAYMANAGER_H
|
||||
#define CSYSTEMTRAYMANAGER_H
|
||||
|
||||
#include "GlobalDefine.h"
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
class CMasterCtrl;
|
||||
|
||||
class CSystemTrayManager: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CSystemTrayManager();
|
||||
virtual ~CSystemTrayManager();
|
||||
CMasterCtrl *mProgramHandle;
|
||||
|
||||
private:
|
||||
QSystemTrayIcon mSystemTrayIcon;
|
||||
QMenu *mTrayMenu;
|
||||
QAction *mQuitAction, *mShowSettingsGUIAction;
|
||||
|
||||
public slots:
|
||||
void TrayIconActivated(QSystemTrayIcon::ActivationReason);
|
||||
void TrayBaloonMessageClicked();
|
||||
void TrayMenuClicked(QAction*);
|
||||
};
|
||||
|
||||
#endif // CSYSTEMTRAYMANAGER_H
|
||||
@ -1,10 +1,14 @@
|
||||
#include "MasterCtrl.h"
|
||||
#include <QApplication>
|
||||
|
||||
CMasterCtrl::CMasterCtrl()
|
||||
{
|
||||
qDebug("Creation...");
|
||||
mDeadBoltDevice = new CDeadboltDevice(1);
|
||||
mAVReceiverDevice = new CAVReceiverDevice;
|
||||
mVoipMsSMSClient = new CVoipMsSMSClient;
|
||||
mSystemTrayManager = new CSystemTrayManager;
|
||||
mSystemTrayManager->mProgramHandle = this;
|
||||
|
||||
|
||||
}
|
||||
@ -15,10 +19,20 @@ CMasterCtrl::~CMasterCtrl()
|
||||
|
||||
delete mDeadBoltDevice;
|
||||
delete mAVReceiverDevice;
|
||||
delete mVoipMsSMSClient;
|
||||
delete mSystemTrayManager;
|
||||
}
|
||||
|
||||
void CMasterCtrl::Start()
|
||||
{
|
||||
qDebug("Started!");
|
||||
|
||||
mAVReceiverDevice->ConnectToReceiver();
|
||||
mVoipMsSMSClient->DownloadSMSFromServer();
|
||||
}
|
||||
|
||||
unsigned int CMasterCtrl::QuitApplicationRequest()
|
||||
{
|
||||
QApplication::exit(69);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
#include "GlobalDefine.h"
|
||||
#include "DeadboltDevice.h"
|
||||
#include "AVReceiverDevice.h"
|
||||
#include "VoipMsSMSClient.h"
|
||||
#include "SystemTrayManager.h"
|
||||
|
||||
class CMasterCtrl
|
||||
{
|
||||
@ -14,6 +16,12 @@ public:
|
||||
void Start(void);
|
||||
CDeadboltDevice *mDeadBoltDevice;
|
||||
CAVReceiverDevice *mAVReceiverDevice;
|
||||
CVoipMsSMSClient *mVoipMsSMSClient;
|
||||
CSystemTrayManager *mSystemTrayManager;
|
||||
|
||||
|
||||
unsigned int QuitApplicationRequest();
|
||||
|
||||
};
|
||||
|
||||
#endif // MASTERCTRL_H
|
||||
|
||||
9
Sources/VoipSMS/CSMSMessage.cpp
Normal file
9
Sources/VoipSMS/CSMSMessage.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "CSMSMessage.h"
|
||||
|
||||
|
||||
|
||||
CSMSMessage::CSMSMessage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
36
Sources/VoipSMS/CSMSMessage.h
Normal file
36
Sources/VoipSMS/CSMSMessage.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef CSMSMESSAGE_H
|
||||
#define CSMSMESSAGE_H
|
||||
|
||||
#include "GlobalDefine.h"
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
|
||||
typedef enum eSMSType
|
||||
{
|
||||
SMS_SENT_TYPE,
|
||||
SMS_RECEIVED_TYPE
|
||||
}SmsType_t;
|
||||
|
||||
class CSMSMessage
|
||||
{
|
||||
|
||||
public:
|
||||
CSMSMessage();
|
||||
|
||||
qint64 mVOIPMSDatabaseID;
|
||||
QDateTime mDateTime;
|
||||
SmsType_t mType;
|
||||
QString mDID, mContact, mMessageText;
|
||||
|
||||
|
||||
|
||||
// [id] => 111120
|
||||
// [date] => 2014-03-30 10:24:16
|
||||
// [type] => 0
|
||||
// [did] => 8574884828
|
||||
// [contact] => 8577884821
|
||||
// [message] => hello+john
|
||||
|
||||
};
|
||||
|
||||
#endif // CSMSOBJECT_H
|
||||
92
Sources/VoipSMS/VoipMsSMSClient.cpp
Normal file
92
Sources/VoipSMS/VoipMsSMSClient.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
#include "VoipMsSMSClient.h"
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDateTime>
|
||||
|
||||
CVoipMsSMSClient::CVoipMsSMSClient()
|
||||
{
|
||||
mVOIPMSSocket = new QNetworkAccessManager();
|
||||
connect(mVOIPMSSocket,SIGNAL(finished(QNetworkReply*)),this,SLOT(VoipServerReplyFinished(QNetworkReply*)));
|
||||
}
|
||||
|
||||
CVoipMsSMSClient::~CVoipMsSMSClient()
|
||||
{
|
||||
delete mVOIPMSSocket;
|
||||
mSMSMessagesList.clear();
|
||||
}
|
||||
|
||||
int CVoipMsSMSClient::DownloadSMSFromServer()
|
||||
{
|
||||
|
||||
QString Username = "jean-francois.martel@polymtl.ca";
|
||||
QString Password = "Pentium2";
|
||||
QString Method = "getSMS";
|
||||
QString Url;
|
||||
Url.clear();
|
||||
QTextStream UrlStream(&Url);
|
||||
|
||||
UrlStream << VOIP_MS_API_URL
|
||||
<< "api_username=" << Username << "&"
|
||||
<< "api_password=" << Password << "&"
|
||||
<< "method=" << Method << "&"
|
||||
<< "from=" << "2015-10-01" << "&"
|
||||
<< "to=" << "2015-11-30" << "&"
|
||||
<< "did=" << "5143606463" << "&"
|
||||
<< "limit=" << "50";
|
||||
|
||||
mVOIPMSSocket->get(QNetworkRequest(Url));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
void CVoipMsSMSClient::VoipServerReplyFinished(QNetworkReply *NetworkReply)
|
||||
{
|
||||
QByteArray Reply = NetworkReply->readAll();
|
||||
|
||||
QJsonDocument JsonReply = QJsonDocument::fromJson(Reply);
|
||||
QJsonObject JsonObject = JsonReply.object();
|
||||
if(JsonObject["status"].toString() == "success")
|
||||
{
|
||||
QJsonArray SMSArray = JsonObject["sms"].toArray();
|
||||
|
||||
foreach (const QJsonValue & value, SMSArray)
|
||||
{
|
||||
CSMSMessage NewMessage;
|
||||
QJsonObject obj = value.toObject();
|
||||
NewMessage.mContact = obj["contact"].toString();
|
||||
NewMessage.mDateTime = QDateTime::fromString(obj["date"].toString(),"yyyy-MM-dd HH:mm:ss");
|
||||
NewMessage.mDID = obj["did"].toString();
|
||||
NewMessage.mMessageText = obj["message"].toString();
|
||||
NewMessage.mType = (SmsType_t)obj["type"].toString().toInt();
|
||||
NewMessage.mVOIPMSDatabaseID = (qint64)obj["type"].toString().toLongLong();
|
||||
mSMSMessagesList.append(NewMessage);
|
||||
qDebug() << obj["contact"].toString().toUtf8() << " : " << obj["message"].toString().toUtf8();
|
||||
}
|
||||
|
||||
qDebug("Added %d messages in the list",mSMSMessagesList.size());
|
||||
}
|
||||
|
||||
|
||||
// qDebug() << "Reply from server: " << Reply;
|
||||
|
||||
|
||||
// [id] => 111120
|
||||
// [date] => 2014-03-30 10:24:16
|
||||
// [type] => 0
|
||||
// [did] => 8574884828
|
||||
// [contact] => 8577884821
|
||||
// [message] => hello+john
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getBalance&advanced=True
|
||||
|
||||
|
||||
//https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getSMS&from=2014-01-01&to=2015-11-11&did=5143606463&limit=50
|
||||
|
||||
34
Sources/VoipSMS/VoipMsSMSClient.h
Normal file
34
Sources/VoipSMS/VoipMsSMSClient.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef CVOIPMSSMSCLIENT_H
|
||||
#define CVOIPMSSMSCLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include "GlobalDefine.h"
|
||||
#include <QList>
|
||||
#include "CSMSMessage.h"
|
||||
|
||||
#define VOIP_MS_API_URL "https://www.voip.ms/api/v1/rest.php?"
|
||||
|
||||
class CVoipMsSMSClient : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CVoipMsSMSClient();
|
||||
virtual ~CVoipMsSMSClient();
|
||||
|
||||
int DownloadSMSFromServer();
|
||||
|
||||
QList<CSMSMessage> mSMSMessagesList;
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *mVOIPMSSocket;
|
||||
|
||||
|
||||
|
||||
|
||||
public slots:
|
||||
void VoipServerReplyFinished(QNetworkReply*);
|
||||
};
|
||||
|
||||
#endif // CVOIPMSSMSCLIENT_H
|
||||
Loading…
x
Reference in New Issue
Block a user