diff --git a/MasterCtrl.pro b/MasterCtrl.pro index bd7f974..2e58a91 100644 --- a/MasterCtrl.pro +++ b/MasterCtrl.pro @@ -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/ diff --git a/Sources/Gui/SystemTrayManager.cpp b/Sources/Gui/SystemTrayManager.cpp new file mode 100644 index 0000000..f9ed27a --- /dev/null +++ b/Sources/Gui/SystemTrayManager.cpp @@ -0,0 +1,77 @@ +#include "SystemTrayManager.h" +#include "MasterCtrl.h" +#include + +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"); + } + +} diff --git a/Sources/Gui/SystemTrayManager.h b/Sources/Gui/SystemTrayManager.h new file mode 100644 index 0000000..8d12d6d --- /dev/null +++ b/Sources/Gui/SystemTrayManager.h @@ -0,0 +1,30 @@ +#ifndef CSYSTEMTRAYMANAGER_H +#define CSYSTEMTRAYMANAGER_H + +#include "GlobalDefine.h" +#include +#include +#include + +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 diff --git a/Sources/MasterCtrl.cpp b/Sources/MasterCtrl.cpp index f3cd8ed..53eb3e0 100644 --- a/Sources/MasterCtrl.cpp +++ b/Sources/MasterCtrl.cpp @@ -1,10 +1,14 @@ #include "MasterCtrl.h" +#include 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; } diff --git a/Sources/MasterCtrl.h b/Sources/MasterCtrl.h index ab1bf26..8d15eed 100644 --- a/Sources/MasterCtrl.h +++ b/Sources/MasterCtrl.h @@ -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 diff --git a/Sources/VoipSMS/CSMSMessage.cpp b/Sources/VoipSMS/CSMSMessage.cpp new file mode 100644 index 0000000..9d045ca --- /dev/null +++ b/Sources/VoipSMS/CSMSMessage.cpp @@ -0,0 +1,9 @@ +#include "CSMSMessage.h" + + + +CSMSMessage::CSMSMessage() +{ + +} + diff --git a/Sources/VoipSMS/CSMSMessage.h b/Sources/VoipSMS/CSMSMessage.h new file mode 100644 index 0000000..c074389 --- /dev/null +++ b/Sources/VoipSMS/CSMSMessage.h @@ -0,0 +1,36 @@ +#ifndef CSMSMESSAGE_H +#define CSMSMESSAGE_H + +#include "GlobalDefine.h" +#include +#include + +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 diff --git a/Sources/VoipSMS/VoipMsSMSClient.cpp b/Sources/VoipSMS/VoipMsSMSClient.cpp new file mode 100644 index 0000000..ec456f1 --- /dev/null +++ b/Sources/VoipSMS/VoipMsSMSClient.cpp @@ -0,0 +1,92 @@ +#include "VoipMsSMSClient.h" +#include +#include +#include +#include +#include +#include + +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 + diff --git a/Sources/VoipSMS/VoipMsSMSClient.h b/Sources/VoipSMS/VoipMsSMSClient.h new file mode 100644 index 0000000..b53f611 --- /dev/null +++ b/Sources/VoipSMS/VoipMsSMSClient.h @@ -0,0 +1,34 @@ +#ifndef CVOIPMSSMSCLIENT_H +#define CVOIPMSSMSCLIENT_H + +#include +#include +#include +#include "GlobalDefine.h" +#include +#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 mSMSMessagesList; + +private: + QNetworkAccessManager *mVOIPMSSocket; + + + + +public slots: + void VoipServerReplyFinished(QNetworkReply*); +}; + +#endif // CVOIPMSSMSCLIENT_H