commit 9f5b83c77674c0ca9eb534986c504944f8227ef1 Author: J-F Martel Date: Wed Apr 12 13:37:09 2017 -0400 Creation diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f1bd8f --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/SystemGui.pro.user +/Makefile +/Makefile.Debug +/Makefile.Release +/object_script.MasterInterface.Debug +/object_script.MasterInterface.Release +/object_script.SystemGui.Debug +/object_script.SystemGui.Release +/debug +/release diff --git a/Configuration/Settings.mcs b/Configuration/Settings.mcs new file mode 100644 index 0000000..1445910 Binary files /dev/null and b/Configuration/Settings.mcs differ diff --git a/Ico/back.png b/Ico/back.png new file mode 100644 index 0000000..48998cc Binary files /dev/null and b/Ico/back.png differ diff --git a/Ico/close.png b/Ico/close.png new file mode 100644 index 0000000..0a54af8 Binary files /dev/null and b/Ico/close.png differ diff --git a/Ico/contact.png b/Ico/contact.png new file mode 100644 index 0000000..7a49860 Binary files /dev/null and b/Ico/contact.png differ diff --git a/Ico/icon.png b/Ico/icon.png new file mode 100644 index 0000000..f0fd832 Binary files /dev/null and b/Ico/icon.png differ diff --git a/Ico/sms.png b/Ico/sms.png new file mode 100644 index 0000000..e35e35a Binary files /dev/null and b/Ico/sms.png differ diff --git a/Ico/sms_new.png b/Ico/sms_new.png new file mode 100644 index 0000000..fe26353 Binary files /dev/null and b/Ico/sms_new.png differ diff --git a/SMSGui.ui b/SMSGui.ui new file mode 100644 index 0000000..5531808 --- /dev/null +++ b/SMSGui.ui @@ -0,0 +1,136 @@ + + + CSMSGui + + + + 0 + 0 + 803 + 785 + + + + + 0 + 0 + + + + Form + + + + + 0 + 160 + 481 + 451 + + + + + + + 0 + 620 + 521 + 121 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Send + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 200 + 75 + + + + TextLabel + + + + + + + + + 520 + 160 + 256 + 471 + + + + 2 + + + false + + + + 1 + + + + + + + 10 + 10 + 141 + 121 + + + + TextLabel + + + + + + 180 + 20 + 591 + 101 + + + + TextLabel + + + + + + diff --git a/Sources/AbstractNetworkInterface.h b/Sources/AbstractNetworkInterface.h new file mode 100644 index 0000000..75ee027 --- /dev/null +++ b/Sources/AbstractNetworkInterface.h @@ -0,0 +1,10 @@ +#ifndef ABSTRACTNETWORKINTERFACE_H +#define ABSTRACTNETWORKINTERFACE_H +#include + +class CAbstractNetworkCommIF +{ +public: + virtual int NewFrameReceived(QByteArray Frame) = 0; +}; +#endif // ABSTRACTNETWORKINTERFACE_H diff --git a/Sources/GlobalDefine.h b/Sources/GlobalDefine.h new file mode 100644 index 0000000..670535f --- /dev/null +++ b/Sources/GlobalDefine.h @@ -0,0 +1,9 @@ +#ifndef GLOBALDEFINE_H +#define GLOBALDEFINE_H + +#include "QDebug" + +#define RET_OK 1 +#define RET_ERROR 0 + +#endif // GLOBALDEFINE_H diff --git a/Sources/GuiMain.cpp b/Sources/GuiMain.cpp new file mode 100644 index 0000000..448162d --- /dev/null +++ b/Sources/GuiMain.cpp @@ -0,0 +1,45 @@ +#include "GuiMain.h" +#include + +CGuiMain::CGuiMain(QWidget *parent) + : QMainWindow(parent) +{ + mSMSGui = new CSMSGui(this); + mSprinklerGui = new CSprinklerGui(this); + mMainTabWidget = new QTabWidget(this); + setCentralWidget(mMainTabWidget); + mMainTabWidget->addTab(mSMSGui,"SMS"); + mMainTabWidget->addTab(mSprinklerGui,"Sprinkler"); + resize(1024,768); +} + +CGuiMain::~CGuiMain() +{ + // delete mSMSGui; +} + +int CGuiMain::RespawnMainWindow() +{ + // qDebug("Respawn"); + activateWindow(); + showNormal(); + raise(); + return RET_OK; +} + +void CGuiMain::changeEvent(QEvent *event) +{ + // qDebug("State Changed"); + if (event->type() == QEvent::WindowStateChange) + { + // qDebug("Window state"); + QWindowStateChangeEvent* WinEvent = (QWindowStateChangeEvent*)event; + if(window()->isMinimized() && ((WinEvent->oldState() != Qt::WindowMinimized))) + { + qDebug("Minimized"); + + hide(); + } + + } +} diff --git a/Sources/GuiMain.h b/Sources/GuiMain.h new file mode 100644 index 0000000..090df0d --- /dev/null +++ b/Sources/GuiMain.h @@ -0,0 +1,28 @@ +#ifndef GUIMAIN_H +#define GUIMAIN_H + +#include +#include +#include "SMSGui.h" +#include +#include "SprinklerGui.h" + +class CGuiMain : public QMainWindow +{ + Q_OBJECT + +public: + CGuiMain(QWidget *parent = 0); + ~CGuiMain(); + + CSMSGui *mSMSGui; + CSprinklerGui *mSprinklerGui; + QTabWidget *mMainTabWidget; + int RespawnMainWindow(); + int HideMainWindow(); + + virtual void changeEvent(QEvent* event); + +}; + +#endif // GUIMAIN_H diff --git a/Sources/MasterCtrlInterface.cpp b/Sources/MasterCtrlInterface.cpp new file mode 100644 index 0000000..baadc00 --- /dev/null +++ b/Sources/MasterCtrlInterface.cpp @@ -0,0 +1,96 @@ +#include "MasterCtrlInterface.h" + +CMasterCtrlInterface::CMasterCtrlInterface() +{ + +} + +int CMasterCtrlInterface::ConnectToMasterCtrl() +{ + if(mNetworkCommSocket == 0) + { + mNetworkCommSocket = new QTcpSocket(); + } + connect(mNetworkCommSocket,SIGNAL(connected()),this,SLOT(NetworkSocketConnected())); + connect(mNetworkCommSocket,SIGNAL(disconnected()),this,SLOT(NetworkSocketDisconnected())); + connect(mNetworkCommSocket,SIGNAL(readyRead()),this,SLOT(NetworkSocketDataAvailable())); + + mNetworkCommSocket->connectToHost(mMasterCtrlAddress,mNetworkPort); + + return RET_OK; +} + +int CMasterCtrlInterface::DisconnectMasterCtrl() +{ + if(mNetworkCommSocket != 0) + { + mNetworkCommSocket->close(); + // mNetworkCommSocket->deleteLater(); + } + + return RET_OK; +} + +int CMasterCtrlInterface::NewFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data) +{ + + if(TargetDeviceID == ID_ETHERNET_VIRTUAL) + { + switch(MessageID) + { + case ETH_NETWK_DEVICE_INFO_REQUEST: + { + QByteArray Frame,ResponseData; + ResponseData.append((char)mMyDeviceID); + ResponseData.append((char)mDeviceAddress); + Frame = GetTxPacket(ETH_NETWK_DEVICE_INFO_RESPONSE,0,ResponseData.data(),ResponseData.size(),1,ID_MASTER,ID_ETHERNET_VIRTUAL,mDeviceAddress); + mNetworkCommSocket->write(Frame); + break; + } + case ETH_NETWK_CONNECTION_REFUSED: + { + qDebug("MasterCtrl connection refused"); + mNetworkCommSocket->close(); + delete mNetworkCommSocket; + mNetworkCommSocket = 0; + break; + } + case ETH_NETWK_SET_DEVICE_INFO_ACK: + { +// mNetworkCommSocket->write(GetTxPacket(SMS_CLIENT_DEVICE_DID_INFO_REQUEST,0,0,0,1,ID_MASTER,ID_SMS_CLIENT,mDeviceAddress)); + DeviceConnectedToMaster(); + qDebug("MasterCtrl accepted connection"); + break; + } + case ETH_NETWK_DEVICE_INFO_RESPONSE: + default: + { + break; + } + + } + } + else + { + DeviceFrameReceived(TargetDeviceID, TargetDeviceAddress, SenderID, SenderAddress, MessageID, DataSize, Data); + } + + return RET_OK; +} + +void CMasterCtrlInterface::NetworkSocketConnected() +{ + qDebug("Connected to MasterCtrl"); + +} + +void CMasterCtrlInterface::NetworkSocketDataAvailable() +{ + AnalyzeRxBuffer(mNetworkCommSocket->readAll()); +} + +void CMasterCtrlInterface::NetworkSocketDisconnected() +{ + qDebug("Disconnected from MasterCtrl"); + +} diff --git a/Sources/MasterCtrlInterface.h b/Sources/MasterCtrlInterface.h new file mode 100644 index 0000000..3796a26 --- /dev/null +++ b/Sources/MasterCtrlInterface.h @@ -0,0 +1,39 @@ +#ifndef MASTERCTRLINTERFACE_H +#define MASTERCTRLINTERFACE_H +#include +#include "NetworkProtocol.h" +#include "GlobalDefine.h" +#include "ProtocolDefs.h" +#include +#include "SMSMessage.h" + +class CMasterCtrlInterface : public QObject, public CNetworkProtocol +{ + Q_OBJECT + +public: + CMasterCtrlInterface(); + + + QTcpSocket *mNetworkCommSocket; + int mDeviceAddress; + int mNetworkPort; + QString mMasterCtrlAddress; + int mMyDeviceID; + + int ConnectToMasterCtrl(); + int DisconnectMasterCtrl(); + virtual int NewFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data); + + virtual int DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data) = 0; + virtual int DeviceConnectedToMaster(bool Connected = true) = 0; + + +public slots: + void NetworkSocketConnected(); + void NetworkSocketDataAvailable(); + void NetworkSocketDisconnected(); + +}; + +#endif // MASTERCTRLINTERFACE_H diff --git a/Sources/NetworkProtocol.cpp b/Sources/NetworkProtocol.cpp new file mode 100644 index 0000000..30d40a7 --- /dev/null +++ b/Sources/NetworkProtocol.cpp @@ -0,0 +1,379 @@ + + +#include "NetworkProtocol.h" + + +CNetworkProtocol::CNetworkProtocol() +{ + mIsResetManual = false; + ResetRxStateMachine(); + +} + +CNetworkProtocol::~CNetworkProtocol() +{ + +} + +//void CNetworkProtocol::BindUpperLayer(CMasterCtrl *UpperLayerPtr) +//{ +// mMasterCtrlHandle = UpperLayerPtr; +//} + + +unsigned char CNetworkProtocol::CalcCRC(char *Buffer, int Size) +{ + unsigned char CRC = 0x00; + + for( int i = 0; i < Size; i++) + { + CRC ^= Buffer[i]; + } + return CRC; +} + +QByteArray CNetworkProtocol::GetTxPacket(unsigned char MessageID, unsigned char Flags, const char *Data, int Size, unsigned char Address, unsigned char ID, unsigned char SenderDevice, unsigned char SenderAddress) +{ +#ifdef USE_BYTEARRAY_IN_SEND + + QByteArray Frame; + Frame.clear(); + int FrameSize = Size + 11; //Add header data... + + Frame.append(FRAME_HEADER); //header + Frame.append(SenderAddress); //Device address (default = MasterCtrl) + Frame.append(SenderDevice); //Device ID (default = MasterCtrl + Frame.append(ID); //destination ID + Frame.append(Address); //Destination Address + Frame.append(Flags); + Frame.append(MessageID); //Cmd + Frame.append((Size & 0xFF000000) >> 24); + Frame.append((Size & 0x00FF0000) >> 16); + Frame.append((Size & 0x0000FF00) >> 8); + Frame.append(Size & 0x000000FF); + Frame.append(Data,Size); + char CRC = CalcCRC(Frame.data(),FrameSize); + Frame.append(CRC); + + return Frame; + + +#else + int toto; + char temp; + char OutBuffer[MAX_MESSAGE_SIZE+10]; + + int FrameSize = Size + 9; //Add header data... + + OutBuffer[0] = (char)FRAME_HEADER; //header + OutBuffer[1] = SenderAddress; //Device address (default = MasterCtrl) + OutBuffer[2] = SenderDevice; //Device ID (default = MasterCtrl + OutBuffer[3] = (char)ID; //destination ID + OutBuffer[4] = (char)Address; //Destination Address + OutBuffer[5] = (char)Flags; + OutBuffer[6] = (char)MessageID; //Cmd + // toto = FrameSize & 0xFF00; + temp = FrameSize >> 8; + OutBuffer[7] = ((FrameSize - 9) & 0xFF00) >> 8; + OutBuffer[8] = (FrameSize - 9) & 0x00FF; + + for(int i = 0; i < Size; i++) + { + temp = Data[i]; + OutBuffer[i+9] = temp; + } + + OutBuffer[FrameSize] = CalcCRC(OutBuffer,FrameSize); + + +// CSerialComm::instance()->WriteData(&OutBuffer[0],FrameSize+1); + + return QByteArray(OutBuffer,FrameSize); +#endif +} + +//int CNetworkProtocol::TxData(unsigned char MessageID,unsigned char Flags,unsigned char *Data,int Size, unsigned char Address,unsigned char ID) +//{ + +// int toto; +// char temp; +// char OutBuffer[MAX_MESSAGE_SIZE+10]; + +// int FrameSize = Size + 9; //Add header data... + +// OutBuffer[0] = (char)FRAME_HEADER; //header +// OutBuffer[1] = 1; //MasterCtrl address +// OutBuffer[2] = ID_MASTER; //MasterCtrl ID +// OutBuffer[3] = (char)ID; //destination ID +// OutBuffer[4] = (char)Address; //Destination Address +// OutBuffer[5] = (char)Flags; +// OutBuffer[6] = (char)MessageID; //Cmd +// toto = FrameSize & 0xFF00; +// temp = FrameSize >> 8; +// OutBuffer[7] = ((FrameSize - 9) & 0xFF00) >> 8; +// OutBuffer[8] = (FrameSize - 9) & 0x00FF; + +// for(int i = 0; i < Size; i++) +// { +// temp = Data[i]; +// OutBuffer[i+9] = temp; +// } + +// OutBuffer[FrameSize] = CalcCRC(OutBuffer,FrameSize); + + +//// CSerialComm::instance()->WriteData(&OutBuffer[0],FrameSize+1); + +// return 0; +//} + +//void CNetworkProtocol::ReadPort(void) +//{ +// int Size = 0; +// RxBuff = CSerialComm::instance()->ReceiveData(Size); +// if(Size) +// { +// if(Size > 50) +// { +// int toto = 5; +// } +//// TRACE("Received %d bytes\n",Size); +// AnalyseNewData(RxBuff,Size); + +// } +//} + +//void CNetworkProtocol::AnalyseNewData(char *Data, int size) +//{ +// if(size != 0) +// { +// for(int i(0); i < size; i++) +// { +// StateMachine((unsigned char)Data[i]); +// } +// } +//} + +int CNetworkProtocol::RxStateMachine(unsigned char Data) +{ + int ret = PROTOCOL_RET_OK_PACKET_INCOMPLETE; + + switch(RxState) + { + case RxHeader: //Wait for data header... + { + if((unsigned char)Data == FRAME_HEADER) + { + mRxData[BufPtr++] = Data; + RxState = RxAdd; + CRC ^= Data; + } + else + { + ResetRxStateMachine(); + ret = PROTOCOL_RET_OK_BAD_HEADER; + } + + break; + } + case RxAdd: //Sender Address. + { + SenderAddress = Data; + mRxData[BufPtr++] = Data; + RxState = RxID; + CRC ^= Data; + break; + } + case RxID: //Sender ID + { + mRxData[BufPtr++] = Data; + RxState = RxMyID; + SenderID = Data; + CRC ^= Data; + break; + } + case RxMyID: + { + +// if(Data != ID_MASTER && Data != 0xFF) //Message is not for Master and it's not a broadcast +// { +// ResetRxStateMachine(); +// ret = PROTOCOL_RET_ERROR_INVALID_TARGET_DEVICE; + +// break; +// } + TargetDeviceID = Data; + mRxData[BufPtr++] = Data; + RxState = RxMyAddress; + CRC ^= Data; + break; + } + case RxMyAddress: + { +// if(Data != 1 && Data != 0xFF) //Message is not for us and it's not a broadcast +// { +// ResetRxStateMachine(); +// ret = PROTOCOL_RET_ERROR_INVALID_TARGET_ADDRESS; + +// break; +// } + TargetAddress = Data; + mRxData[BufPtr++] = Data; + RxState = RxFlags; + CRC ^= Data; + break; + } + case RxFlags: + { + Flags = Data; + mRxData[BufPtr++] = Data; + RxState = RxCMD; + CRC ^= Data; + break; + } + case RxCMD: + { + RxCmd = Data; + mRxData[BufPtr++] = Data; + RxState = RxSize1; + CRC ^= Data; + break; + } + case RxSize1: //Data size MSB + { + RxSize = 0; + RxSize = (unsigned int)Data; + RxSize <<= 8; + mRxData[BufPtr++] = Data; + + + RxState = RxSize2; + CRC ^= Data; + break; + } + case RxSize2: //Data size MSB + { + RxSize |= (unsigned int)Data; + RxSize <<= 8; + mRxData[BufPtr++] = Data; + + + RxState = RxSize3; + CRC ^= Data; + break; + } + case RxSize3: //Data size MSB + { + RxSize |= (unsigned int)Data; + RxSize <<= 8; + mRxData[BufPtr++] = Data; + + + RxState = RxSize4; + CRC ^= Data; + break; + } + case RxSize4: //Data size LSB + { + RxSize |= (unsigned int)Data; + mRxData[BufPtr++] = Data; + + if(RxSize == 0) + RxState = RxCRC; + else + RxState = RxData; + + CRC ^= Data; + break; + } + + case RxData: + { + //mRxData[BufPtr++] = Data; + mDataBuffer.append(Data); + CRC ^= Data; + DataCnt++; + + if(DataCnt == RxSize) + RxState = RxCRC; + + break; + } + case RxCRC: + { + if(Data != CRC) //Data corruption + { + ResetRxStateMachine(); + ret = PROTOCOL_RET_ERROR_BAD_CRC; + + break; + } + + // mDataBuffer = QByteArray(&mRxData[DATA_START],RxSize); + NewFrameReceived(TargetDeviceID,TargetAddress,SenderID,SenderAddress,RxCmd,RxSize,mDataBuffer); + ret = PROTOCOL_RET_OK_PACKET_COMPLETE; + if(mIsResetManual == false) + { + ResetRxStateMachine(); + } + break; + } + default: + { + ret = PROTOCOL_RET_ERROR_SM_LOGIC; + ResetRxStateMachine(); + break; + } + } + + return ret; +} + +void CNetworkProtocol::ResetRxStateMachine(void) +{ + RxState = RxHeader; + RxSize = 0; + SenderID = 0; + SenderAddress = 0; + TargetAddress = 0; + TargetDeviceID = 0; + RxCmd = 0; + memset(mRxData,0,sizeof(mRxData)); + DataCnt = 0; + BufPtr = 0; + CRC = 0; + Flags = 0; + mDataBuffer.clear(); +} + +void CNetworkProtocol::PrepareForNewPacket() +{ + ResetRxStateMachine(); +} + +int CNetworkProtocol::AnalyzeRxBuffer(QByteArray Buffer) +{ + int ret = PROTOCOL_RET_ERROR_EMPTY_BUFFER; + for(int i = 0; i < Buffer.size(); i++) + { + ret = RxStateMachine(Buffer.at(i)); + if(ret != PROTOCOL_RET_OK_PACKET_INCOMPLETE) + { + if(ret == PROTOCOL_RET_OK_BAD_HEADER) + { + qDebug("Protocol Bad header"); + } + else + { + return ret; + } + + } + } + return ret; +} + +void CNetworkProtocol::SetManualPacketReset(bool Manual) +{ + mIsResetManual = Manual; +} diff --git a/Sources/NetworkProtocol.h b/Sources/NetworkProtocol.h new file mode 100644 index 0000000..dbeb0c2 --- /dev/null +++ b/Sources/NetworkProtocol.h @@ -0,0 +1,92 @@ +#ifndef NETWORKPROTOCOL_H +#define NETWORKPROTOCOL_H + +#define USE_BYTEARRAY_IN_SEND + +#include "GlobalDefine.h" +#include "ProtocolDefs.h" +#include "AbstractNetworkInterface.h" +#include + +class CNetworkProtocol +{ +public: + CNetworkProtocol(); + ~CNetworkProtocol(); + QByteArray GetTxPacket(unsigned char MessageID, unsigned char Flags, const char *Data, int Size, unsigned char Address, unsigned char ID, unsigned char SenderDevice = ID_SMS_CLIENT, unsigned char SenderAddress = 1); + int AnalyzeRxBuffer(QByteArray Buffer); + void PrepareForNewPacket(); + void SetManualPacketReset(bool Manual); + + virtual int NewFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data) = 0; + + enum ProtocolRetValues + { + PROTOCOL_RET_OK_PACKET_COMPLETE, + PROTOCOL_RET_OK_PACKET_INCOMPLETE, + PROTOCOL_RET_OK_BAD_HEADER, + PROTOCOL_RET_ERROR_INVALID_TARGET_DEVICE, + PROTOCOL_RET_ERROR_INVALID_TARGET_ADDRESS, + PROTOCOL_RET_ERROR_BAD_CRC, + PROTOCOL_RET_ERROR_SM_LOGIC, + PROTOCOL_RET_ERROR_EMPTY_BUFFER + }; + + char ProtocolGetSenderID(){return SenderID;} + char ProtocolGetSenderAddress(){return SenderAddress;} + int ProtocolGetCmd(){return RxCmd;} + int ProtocolGetDataSize(){return RxSize;} + QByteArray ProtocolGetData(){return mDataBuffer;} + + +private: + void ResetRxStateMachine(); + unsigned char CalcCRC(char *Buffer, int Size); + // int TxData(unsigned char MessageID,unsigned char Flags,unsigned char *Data,int Size, unsigned char Address,unsigned char ID); + + int RxStateMachine(unsigned char Data); + + //State Machine states + enum States + { + Initialization, + RxHeader, + RxID, + RxAdd, + RxMyID, + RxMyAddress, + RxFlags, + RxCMD, + RxSize1, + RxSize2, + RxSize3, + RxSize4, + RxData, + RxCRC + }; + + bool mIsResetManual; + + + char *RxBuff; + char mRxData[MAX_MESSAGE_SIZE+10]; + + int RxState; + int RxSize; + char SenderID; + char SenderAddress; + int RxCmd; + int TargetDeviceID; + int TargetAddress; + int DataCnt; + int BufPtr; + unsigned char CRC; + unsigned char Flags; + + unsigned char State; + + QByteArray mDataBuffer; + +}; + +#endif // NETWORKPROTOCOL_H diff --git a/Sources/ProgramSettings.cpp b/Sources/ProgramSettings.cpp new file mode 100644 index 0000000..806bdad --- /dev/null +++ b/Sources/ProgramSettings.cpp @@ -0,0 +1,146 @@ +#include "ProgramSettings.h" + +CProgramSettings::CProgramSettings() +{ + +} + + +unsigned int CProgramSettings::LoadSettings(CSettings* Settings) +{ + QFile* SettingsFile = new QFile("./Configuration/Settings.mcs"); + if(SettingsFile) + { + if(SettingsFile->open(QIODevice::ReadOnly | QIODevice::Unbuffered) == false) + { + LoadDefaultSettings(Settings); + SaveSettings(Settings); + return RET_ERROR; + } + } + else + { + LoadDefaultSettings(Settings); + return RET_ERROR; + } + + QDataStream * InputStream = new QDataStream(SettingsFile); + + quint32 MagicNbr;// = 0xBAADCAFE; + + *InputStream >> MagicNbr; + + if(MagicNbr != 0xBAADCAFE) + { + LoadDefaultSettings(Settings); + return RET_ERROR; + } + + *InputStream >> *Settings; + + SettingsFile->close(); + delete SettingsFile; + delete InputStream; + + return RET_OK; +} + +void CProgramSettings::LoadDefaultSettings(CSettings *Settings) +{ + Settings->mVoipMSSettings.mDefaultDID = "555555555"; + Settings->mVoipMSSettings.mPassword = "Voip.ms Password"; + Settings->mVoipMSSettings.mUsername = "Voip.ms Username"; + Settings->mVoipMSSettings.mStartDate = QDate::currentDate(); +} + +unsigned int CProgramSettings::SaveSettings(CSettings *SettingsData) +{ + QFile* SettingsFile = new QFile("./Configuration/Settings.mcs"); + if(SettingsFile) + { + if(SettingsFile->open(QIODevice::WriteOnly | QIODevice::Unbuffered) == false) + { + return RET_ERROR; + } + } + else + { + return RET_ERROR; + } + + QDataStream * OutputStream = new QDataStream(SettingsFile); + + quint32 MagicNbr = 0xBAADCAFE; + + *OutputStream << MagicNbr; + + *OutputStream << *SettingsData; + + SettingsFile->flush(); + SettingsFile->close(); + + delete SettingsFile; + delete OutputStream; + + return RET_OK; +} + + +QDataStream &operator<<(QDataStream &out, const CSettings &source) +{ + out << source.mVoipMSSettings; + + return out; +} + +QDataStream &operator>>(QDataStream &in, CSettings &dest) +{ + in >> dest.mVoipMSSettings; + + return in; +} + +QDataStream &operator<<(QDataStream &out, const CVoipMSSMSSettings &source) +{ + out << source.mDefaultDID + << source.mPassword + << source.mStartDate + << source.mUsername; + + return out; +} + +QDataStream &operator>>(QDataStream &in, CVoipMSSMSSettings &dest) +{ + in >> dest.mDefaultDID + >> dest.mPassword + >> dest.mStartDate + >> dest.mUsername; + + return in; +} + +CVoipMSSMSSettings& CVoipMSSMSSettings::operator=(const CVoipMSSMSSettings *source) +{ + if(source == this) + { + return *this; + } + + this->mDefaultDID = source->mDefaultDID; + this->mPassword = source->mPassword; + this->mStartDate = source->mStartDate; + this->mUsername = source->mUsername; + + return *this; +} + +CSettings& CSettings::operator =(const CSettings &source) +{ + if(this == &source) + { + return *this; + } + this->mVoipMSSettings = source.mVoipMSSettings; + return *this; +} diff --git a/Sources/ProgramSettings.h b/Sources/ProgramSettings.h new file mode 100644 index 0000000..d1625a3 --- /dev/null +++ b/Sources/ProgramSettings.h @@ -0,0 +1,54 @@ +#ifndef CPROGRAMSETTINGS_H +#define CPROGRAMSETTINGS_H + +#include "GlobalDefine.h" +#include +#include +#include +#include + + +class CVoipMSSMSSettings +{ +public: + QString mUsername; + QString mPassword; + QDate mStartDate; + QString mDefaultDID; + + CVoipMSSMSSettings &operator=(const CVoipMSSMSSettings *source); + +}; +QDataStream &operator<<(QDataStream &out, const CVoipMSSMSSettings &source); +QDataStream &operator>>(QDataStream &in, CVoipMSSMSSettings &dest); + + +class CSettings +{ +public: + CVoipMSSMSSettings mVoipMSSettings; + + CSettings &operator=(const CSettings &source); +}; + +QDataStream &operator<<(QDataStream &out, const CSettings &source); +QDataStream &operator>>(QDataStream &in, CSettings &dest); + +class CProgramSettings +{ +public: + CProgramSettings(); + unsigned int LoadSettings(CSettings*); + unsigned int SaveSettings(CSettings *SettingsData); + +private: + + void LoadDefaultSettings(CSettings* Settings); + + + +}; + + + +#endif // CPROGRAMSETTINGS_H diff --git a/Sources/ProtocolDefs.h b/Sources/ProtocolDefs.h new file mode 100644 index 0000000..d72478a --- /dev/null +++ b/Sources/ProtocolDefs.h @@ -0,0 +1,186 @@ +/********************************************************************** +Project: Automatic cat feeder +Date: march 19 2006 +Author: Jean-François Martel +Target: PIC 18F252 +Compiler: Microchip mcc18 +Filename: Protocol.h + +File description: Communication protocol implementation. + + +jean-francois.martel@polymtl.ca +**********************************************************************/ + +#ifndef PROTOCOLDEFS_H +#define PROTOCOLDEFS_H + +//Protocol buffer specific definitionsazsdf + +#define MAX_MESSAGE_SIZE 0xFFFF + +#define FRAME_HEADER 0x8A +#define DATA_START 11 +#define ACK 0xA3 +#define NAK 0x90 +#define BROADCAST_VALUE 0xFF + +enum eFrameIndex +{ + FRAME_HEADER_INDEX, + FRAME_SENDER_ID_INDEX, + FRAME_SENDER_ADDRESS_INDEX, + FRAME_DEST_ID_INDEX, + FRAME_DEST_ADDRESS_INDEX, + FRAME_FLAGS_INDEX, + FRAME_COMMAND_INDEX, + FRAME_SIZE1_INDEX, + FRAME_SIZE2_INDEX, + FRAME_DATA_INDEX +}; + +enum DEVICES_IDS +{ + ID_MASTER, //Master Controller + ID_CONSOLE, //LCD Console + ID_PC, //PC + ID_AV_MUX, //Audio Video Multiplexer + ID_IR_REMOTE, //Infra red transmitter + ID_DEADBOLT, + ID_RECEIVER_AMP, + ID_SMS_CLIENT, + ID_ETHERNET_VIRTUAL, + ID_SPRINKLER_DEVICE, + ID_SPRINKLER_INTERFACE, + ID_DEADBOLT_INTERFACE, + ID_NB_DEVICE_ID + +}; + +// Commands definitions + +enum MASTER_CMD +{ + RX_MASTER_GET_STATUS, + TX_MASTER_STATUS, + TX_MASTER_ACK, + RX_MASTER_SET_NET_INFO, + RX_MASTER_GET_NET_INFO, + TX_MASTER_NET_INFO, + RX_MASTER_SEND_DEVICE_CMD, + TX_MASTER_SEND_DEVICE_CMD_ACK, + RX_MASTER_SET_WEATHER_INFO, + TX_MASTER_SET_WEATHER_INFO_ACK, + RX_MASTER_SET_MAIL_MSG, + TX_MASTER_SET_MAIL_MSG_ACK, + RX_MASTER_NEW_OUTLOOK_EMAILS, + TX_MASTER_NEW_OUTLOOK_EMAILS_ACK, + RX_MASTER_TODAYS_EVENTS, + TX_MASTER_TODAYS_EVENTS_ACK +}; + + +//CONSOLE +enum CONSOLE_CMD +{ + RX_CONSOLE_GET_STATUS, + TX_CONSOLE_STATUS, + TX_CONSOLE_ACK, + RX_START_CALIBRATION, + RX_GET_CONSOLE_EVENT_MSG, + TX_CONSOLE_EVENT_MSG, + RX_CONSOLE_SHOW_CALLER_ID, + RX_SET_TIME, + RX_SET_WEATHER, + RX_SEND_NEW_MAIL_MSG, + RX_SEND_NEW_MAIL_MSG_ACK, + RX_NEW_OUTLOOK_EMAILS, + TX_NEW_OUTLOOK_EMAILS_ACK, + RX_TODAYS_EVENTS, + TX_TODAYS_EVENTS_ACK, + LAST_CONSOLE_CMD +}; + + + +enum IR_REMOTE_CMDS +{ + TX_IR_REMOTE_ACK = 1, + RX_GET_STATUS, + TX_REMOTE_STATUS, + RX_TRANSMIT_CMD, + RX_LEARN_IR_CMD, + TX_LEARN_IR_CMD_FINISHED, + RX_GET_IR_DATA, + TX_SEND_IR_DATA, + RX_SET_IR_CMD, + RX_SET_IR_DATA, + RX_GET_IR_CMD, + TX_SEND_IR_CMD, + MAX_IR_REMOTE_CMD +}; + +//The SMS remote interface commands +enum SMS_CLIENT_CMDS +{ + SMS_CLIENT_DEVICE_ACK = 1, + SMS_CLIENT_DEVICE_STATUS_REQUEST, + SMS_CLIENT_DEVICE_STATUS_RESPONSE, + SMS_CLIENT_DEVICE_DID_INFO_REQUEST, + SMS_CLIENT_DEVICE_DID_INFO_RESPONSE, + SMS_CLIENT_DEVICE_GET_ALL_MSG_REQUEST, + SMS_CLIENT_DEVICE_GET_ALL_MSG_RESPONSE, + SMS_CLIENT_DEVICE_NEW_MSG_NOTIFICATION, + SMS_CLIENT_DEVICE_SEND_SMS_REQUEST, + SMS_CLIENT_DEVICE_SEND_SMS_ACK, + SMS_CLIENT_DEVICE_GET_CONTACTS_REQUEST, + SMS_CLIENT_DEVICE_GET_CONTACTS_RESPONSE,//12 + SMS_CLIENT_DEVICE_CONTACTS_CHANGED_NOTIFICATION, + + SMS_CLIENT_DEVICE_MAX_MSG + +}; + +//The actual deadbolt device commands +enum DEADBOLT_CMDS +{ + DEADBOLT_DEVICE_ACK = 1, + DEADBOLT_DEVICE_STATUS_REQUEST, + DEADBOLT_DEVICE_STATUS_RESPONSE, + + MAX_DEADBOLT_DEVICE_CMD +}; + +//The actual sprinkler module device commands +enum SPRINKLER_DEVICE_CMDS +{ + SPRINKLER_DEVICE_ACK = 1, + SPRINKLER_DEVICE_STATUS_REQUEST, + SPRINKLER_DEVICE_STATUS_RESPONSE, + + MAX_SPRINKLER_DEVICE_CMD +}; + +//The sprinkler interface commands +enum SPRINKLER_INTERFACE_CMDS +{ + SPRINKLER_INTERFACE_ACK = 1, + SPRINKLER_INTERFACE_STATUS_REQUEST, + SPRINKLER_INTERFACE_STATUS_RESPONSE, + + MAX_SPRINKLER_INTERFACE_CMD +}; + + +enum ETHERNET_NETWORK_VIRTUAL_CMDS +{ + ETH_NETWK_DEVICE_INFO_REQUEST = 0xD0, + ETH_NETWK_DEVICE_INFO_RESPONSE, + ETH_NETWK_SET_DEVICE_INFO_ACK, + ETH_NETWK_CONNECTION_REFUSED, + + MAX_ETHERNET_NETWORK_VIRTUAL_CMDS + +}; + +#endif diff --git a/Sources/SMSClient/Contact.cpp b/Sources/SMSClient/Contact.cpp new file mode 100644 index 0000000..a006132 --- /dev/null +++ b/Sources/SMSClient/Contact.cpp @@ -0,0 +1,107 @@ +#include "Contact.h" + +CContact::CContact(QString ContactNbr, QString ContactName, QPixmap *Picture) +{ + + mRAWContactNbr = ContactNbr; + mContactNumber = ContactNbr; + mContactNumber.insert(0,'('); + mContactNumber.insert(4,") "); + mContactNumber.insert(9,'-'); + + mContactName = ContactName; + if(mContactName == "") + { + mContactName = mContactNumber; + } + + + if(Picture == 0) + { + mContactPicture = QPixmap("./Ico/contact.png"); + } + else + { + if(Picture->isNull()) + { + mContactPicture = QPixmap("./Ico/contact.png"); + } + else + { + mContactPicture = QPixmap(*Picture); + } + } + + + +} + +CContact::CContact() +{ + mContactNumber="INVALID"; + mContactPicture = QPixmap("./Ico/contact.png"); +} + +CContact::~CContact() +{ + +} + +int CContact::SetContactImage(QString FilePath) +{ + mContactPicture = QPixmap(FilePath); + + return RET_OK; +} + +bool operator ==(const CContact& left, const CContact& right) +{ + if(left.mRAWContactNbr == right.mRAWContactNbr) + { + return true; + } + + return false; +} +bool operator !=(const CContact& left, const CContact& right) +{ + return !(left==right); +} + +CContact & CContact::operator=(const CContact source) +{ + if(&source == this) + { + return *this; + } + + this->mRAWContactNbr = source.mRAWContactNbr; + this->mContactName = source.mContactName; + this->mContactNumber = source.mContactNumber; + this->mContactPicture = source.mContactPicture; + + return *this; +} + +QDataStream &operator<<(QDataStream &out, const CContact &source) +{ + out << source.mContactName + << source.mContactNumber + << source.mContactPicture + << source.mRAWContactNbr; + + + return out; +} + +QDataStream &operator>>(QDataStream &in, CContact &dest) +{ + in >> dest.mContactName + >> dest.mContactNumber + >> dest.mContactPicture + >> dest.mRAWContactNbr; + + + + return in; +} diff --git a/Sources/SMSClient/Contact.h b/Sources/SMSClient/Contact.h new file mode 100644 index 0000000..21b4be3 --- /dev/null +++ b/Sources/SMSClient/Contact.h @@ -0,0 +1,29 @@ +#ifndef CCONTACT_H +#define CCONTACT_H + +#include "GlobalDefine.h" +#include +#include + +class CContact +{ +public: + CContact(QString ContactNbr, QString ContactName = "", QPixmap *Picture = 0); + CContact(); + virtual ~CContact(); + + int SetContactImage(QString FilePath); + + QString mContactName; + QPixmap mContactPicture; + QString mContactNumber, mRAWContactNbr; + + CContact &operator=(const CContact source); +}; + + bool operator==(const CContact& left, const CContact& right); + bool operator!=(const CContact& left, const CContact& right); + +QDataStream &operator<<(QDataStream &out, const CContact &source); +QDataStream &operator>>(QDataStream &in, CContact &dest); +#endif // CCONTACT_H diff --git a/Sources/SMSClient/ContactRepository.cpp b/Sources/SMSClient/ContactRepository.cpp new file mode 100644 index 0000000..2db39db --- /dev/null +++ b/Sources/SMSClient/ContactRepository.cpp @@ -0,0 +1,168 @@ +#include "ContactRepository.h" +#include + +CContactRepository::CContactRepository() +{ + +} + +//int CContactRepository::LoadContacts() +//{ +// QFile* ContactsFile = new QFile("./Configuration/Contacts.mcc"); +// if(ContactsFile) +// { +// if(ContactsFile->open(QIODevice::ReadOnly | QIODevice::Unbuffered) == false) +// { +// if(ContactsFile->open(QIODevice::WriteOnly | QIODevice::Unbuffered) == true) +// { +// mContactsList.clear(); +// SaveContacts(); //create an empty file... +// } +// return 0; +// } +// } +// else +// { +// return 0; +// } + +// mContactsList.clear(); + +// QDataStream * InputStream = new QDataStream(ContactsFile); + +// quint32 MagicNbr;// = 0xBAADCAFE; +// quint32 NbEntries; + +// *InputStream >> MagicNbr; + +// if(MagicNbr != 0xDEADBEEF) +// { +// return RET_ERROR; +// } + +// *InputStream >> NbEntries; + +// for(unsigned int i = 0; i < NbEntries; i++) +// { +// CContact NewContact; +// *InputStream >> NewContact; +// mContactsList.append(NewContact); +// } + +// qDebug("Loaded %d contacts",mContactsList.size()); +// ContactsFile->close(); +// delete ContactsFile; +// delete InputStream; + +// return mContactsList.size(); +//} + +int CContactRepository::SetContacts(QList *ContactsList) +{ + mContactsList.clear(); + mContactsList = *ContactsList; + + return mContactsList.size(); +} + +CContact * CContactRepository::FindContact(QString ContactRawNumber) +{ + for(int i = 0; i < mContactsList.size(); i++) + { + if(mContactsList.at(i).mRAWContactNbr == ContactRawNumber) + { + return &mContactsList[i]; + } + } + return 0; +} + +int CContactRepository::AddContact(CContact Contact) +{ + + for(int i = 0; i < mContactsList.size(); i++) + { + if(mContactsList.at(i) == Contact) + { + mContactsList[i] = Contact; + //SaveContacts(); + return RET_OK; + } + } + + mContactsList.append(Contact); + // SaveContacts(); + return RET_OK; +} + +int CContactRepository::DeleteContact(int index) +{ + if(index < 0 || index >= mContactsList.size()) + { + return RET_ERROR; + } + + mContactsList.takeAt(index); +// SaveContacts(); + return RET_OK; +} + +int CContactRepository::GetContact(int index,CContact& Contact) +{ + if(index < 0 || index >= mContactsList.size()) + { + return RET_ERROR; + } + + Contact = mContactsList.at(index); + + return RET_OK; +} + +CContact *CContactRepository::GetContactPtr(int index) +{ + if(index < 0 || index >= mContactsList.size()) + { + return 0; + } + + return &mContactsList[index]; +} + +//int CContactRepository::SaveContacts() +//{ +// QFile* ContactsFile = new QFile("./Configuration/Contacts.mcc"); +// if(ContactsFile) +// { +// if(ContactsFile->open(QIODevice::WriteOnly | QIODevice::Unbuffered | QIODevice::Truncate) == false) +// { + +// return 0; +// } +// } +// else +// { +// return 0; +// } + + +// QDataStream * InputStream = new QDataStream(ContactsFile); + +// quint32 MagicNbr = 0xDEADBEEF; + +// *InputStream << MagicNbr; +// *InputStream << mContactsList.size(); + +// for(int i = 0; i < mContactsList.size(); i++) +// { +// *InputStream << mContactsList.at(i); +// } + +// ContactsFile->close(); +// delete ContactsFile; +// delete InputStream; + +// qDebug("SAved %d contacts",mContactsList.size()); + +// return mContactsList.size(); +//} diff --git a/Sources/SMSClient/ContactRepository.h b/Sources/SMSClient/ContactRepository.h new file mode 100644 index 0000000..515c05a --- /dev/null +++ b/Sources/SMSClient/ContactRepository.h @@ -0,0 +1,27 @@ +#ifndef CCONTACTREPOSITORY_H +#define CCONTACTREPOSITORY_H + +#include "Contact.h" +#include + + +class CContactRepository +{ +public: + CContactRepository(); + +// int LoadContacts(); +// int SaveContacts(); + int SetContacts(QList *ContactsList); + int AddContact(CContact Contact); + QList *GetContacts(){return &mContactsList;} + int GetContact(int index, CContact &Contact); + CContact *GetContactPtr(int index); + CContact *FindContact(QString ContactRawNumber); + int DeleteContact(int index); + +private: + QList mContactsList; +}; + +#endif // CCONTACTREPOSITORY_H diff --git a/Sources/SMSClient/SMSClient.cpp b/Sources/SMSClient/SMSClient.cpp new file mode 100644 index 0000000..5c1d96f --- /dev/null +++ b/Sources/SMSClient/SMSClient.cpp @@ -0,0 +1,198 @@ +#include "SMSClient.h" +#include + + + +CSMSClient::CSMSClient(CSMSGui *GuiHandle, CVoipMSSMSSettings *ProgramSettings) +{ + qDebug("Creation..."); + mSMSDatabase.mProgramHandle = this; + mGuiHandle = GuiHandle; + mGuiHandle->mProgramHandle = this; + mGuiHandle->mSMSDatabase = &mSMSDatabase; + mSettings = ProgramSettings; + +// mSystemTrayManager = new CSystemTrayManager; +// mSystemTrayManager->mProgramHandle = this; +// mSettingsWindow = new CSettingsWindow(); +// mSettingsWindow->mProgramHandle = this; + //mMainPanel = new Panel; + // mMasterCtrlIF = new CMasterCtrlInterface(); + + +} + +CSMSClient::~CSMSClient() +{ +// delete mSystemTrayManager; +// delete mSettingsWindow; + // delete mMainPanel; + // delete mMasterCtrlIF; + +} + +void CSMSClient::Start() +{ + qDebug("Started!"); + mMasterCtrlIF = new CSMSMasterCtrlInterface(this); + mSMSDatabase.mContactRepository = &mContactRepository; + + mMasterCtrlIF->ConnectToMasterCtrl(); +} + +int CSMSClient::SetAllMsgsDatabase(QString DID, QList *MessagesList) +{ + if(mSMSDatabase.SetAllMessages(DID,MessagesList) == RET_OK) + { + mGuiHandle->FullConversationsUpdate(); +// mMainPanel->mConversationsWindow->FullConversationsUpdate(); +// mMainPanel->mConversationWindow->hide(); + } + return RET_OK; +} + +int CSMSClient::SetDIDDatabase(QString DID) +{ + mSMSDatabase.SetDID(DID); + return RET_OK; +} + +int CSMSClient::NewMessagesEvent(QList *MessagesList) +{ + mSMSDatabase.SetNewMessages("",MessagesList); + return RET_OK; +} + +int CSMSClient::SetContacts(QList *ContactsList) +{ + mContactRepository.SetContacts(ContactsList); + mSMSDatabase.ContactsRepositoryChanged(); + return RET_OK; +} + +//unsigned int CSMSClient::QuitApplicationRequest() +//{ + +// QApplication::exit(69); +// return RET_OK; +//} + +//unsigned int CSMSClient::ShowSettingsWindowRequest() +//{ +// mSettingsWindow->show(); +// return RET_OK; +//} + +//unsigned int CSMSClient::SaveSettings(CSettings *Settings) +//{ +// CSettings toto; +// toto = *Settings; +// mSMSClientSettings = toto; +// mSettingsManager.SaveSettings(&mSMSClientSettings); + +// return RET_OK; +//} + +//unsigned int CSMSClient::SettingsWindowClosed() +//{ + +// return RET_OK; +//} + +//int CSMSClient::AppToggle() +//{ +//// if(mMainPanel->mConversationWindow->isVisible()) +//// { +//// mMainPanel->mConversationWindow->hide(); + +//// } +//// else if(mMainPanel->mConversationsWindow->isVisible()) +//// { +//// mMainPanel->mConversationsWindow->hide(); +//// } +//// else +//// { +//// mMainPanel->mConversationsWindow->show(); +//// } + +// return RET_OK; +//} +//int CSMSClient::AppPosChanged(int NewPosX, int NewPosY) +//{ +//// mMainPanel->mConversationsWindow->setPos(50,50); +//// mMainPanel->mConversationWindow->setPos(50,50); +// return RET_OK; +//} + +int CSMSClient::ShowConversation(QString Contact) +{ + CSMSConversation* Conversation; + Conversation = mSMSDatabase.GetConversation(Contact); + + if(Conversation == 0) + { + return RET_ERROR; + } + +// mMainPanel->mConversationWindow->SetConversation(Conversation); + +// mMainPanel->mConversationsWindow->hide(); +// mMainPanel->mConversationWindow->show(); + + return RET_OK; +} + +//int CSMSClient::CloseConversationsWindow() +//{ +//// mMainPanel->mConversationsWindow->hide(); +// return RET_OK; +//} + +//int CSMSClient::CloseConversationWindow(CConversationWindow *Window) +//{ +// Q_UNUSED(Window) + +//// mMainPanel->mConversationsWindow->FullConversationsUpdate(); +//// mMainPanel->mConversationWindow->hide(); +//// mMainPanel->mConversationsWindow->show(); + +// return RET_OK; +//} + +int CSMSClient::SendSMSMessage(CSMSMessage Message) +{ + mMasterCtrlIF->SendSMS(Message); + return RET_OK; +} + +int CSMSClient::NewMessageNotification(CSMSConversation *Conversation, int MessageIndex) +{ +// if(mMainPanel->mConversationWindow->NewMessageNotification(Conversation,MessageIndex) == true) +// { +// mSMSDatabase.SetConversationAsRead(Conversation); +// } + // mMainPanel->mConversationsWindow->UpdateConversation(Conversation); + mGuiHandle->NewMessageNotification(Conversation,MessageIndex); + + MessageCountChangeNotification(mSMSDatabase.GetNbUnreadMsgs()); + + return RET_OK; +} + +int CSMSClient::SyncConversations() +{ + // mMainPanel->mConversationsWindow->FullConversationsUpdate(); + return RET_OK; +} + +int CSMSClient::MessageCountChangeNotification(int MsgCount) +{ + // mMainPanel->mAppIconWidget->SetNewMsgCount(MsgCount); + mTrayIconMgr->NewSMSMessagesPendingCount(MsgCount); + return RET_OK; +} + +//int CSMSClient::NewConversationAddedToDatabase(CSMSConversation *Conversation) +//{ + +//} diff --git a/Sources/SMSClient/SMSClient.h b/Sources/SMSClient/SMSClient.h new file mode 100644 index 0000000..7949d6f --- /dev/null +++ b/Sources/SMSClient/SMSClient.h @@ -0,0 +1,77 @@ +#ifndef MASTERCTRL_H +#define MASTERCTRL_H + +#include "GlobalDefine.h" +#include "SystemTrayManager.h" +#include "SettingsWindow.h" +#include "ProgramSettings.h" +//#include "AppIconWidget.h" +//#include "MainPanel.h" +#include "SMSMasterCtrlInterface.h" +#include "SMSDatabase.h" +#include "ContactRepository.h" +#include "SMSGui.h" + + + +class CSMSClient : public QObject +{ + Q_OBJECT +public: + CSMSClient(CSMSGui *GuiHandle, CVoipMSSMSSettings *ProgramSettings); + ~CSMSClient(); + + void Start(void); + // CSystemTrayManager *mSystemTrayManager; + // CSettingsWindow *mSettingsWindow; + // CProgramSettings mSettingsManager; + //Panel *mMainPanel; + CSMSMasterCtrlInterface *mMasterCtrlIF; + CSMSDatabase mSMSDatabase; + CContactRepository mContactRepository; + CSMSGui *mGuiHandle; + CVoipMSSMSSettings *mSettings; + CSystemTrayManager *mTrayIconMgr; + + + + +// unsigned int QuitApplicationRequest(); +// unsigned int ShowSettingsWindowRequest(); +// unsigned int SaveSettings(CSettings *Settings); + +// unsigned int SettingsWindowClosed(); + + //AppIconWidget requests +// int AppToggle(); +// int AppPosChanged(int NewPosX, int NewPosY); + + //MasterCtrlIngerface Requests + int SetAllMsgsDatabase(QString DID, QList *MessagesList); + int SetDIDDatabase(QString DID); + int NewMessagesEvent(QList *MessagesList); + int SetContacts(QList *ContactsList); + + + //ConversationsWindow requests + int ShowConversation(QString Contact); +// int CloseConversationsWindow(); + + + //ConversationWindow requests + //int CloseConversationWindow(CConversationWindow* Window); + int SendSMSMessage(CSMSMessage Message); + + //SMSDatabase requests + int NewMessageNotification(CSMSConversation* Conversation, int MessageIndex); + // void NewConversationAddedToDatabase(CSMSConversation *Conversation); + int SyncConversations(); + int MessageCountChangeNotification(int MsgCount); + + +private: + + CSettings mSMSClientSettings; +}; + +#endif // MASTERCTRL_H diff --git a/Sources/SMSClient/SMSConversation.cpp b/Sources/SMSClient/SMSConversation.cpp new file mode 100644 index 0000000..f6f80ef --- /dev/null +++ b/Sources/SMSClient/SMSConversation.cpp @@ -0,0 +1,61 @@ +#include "SMSConversation.h" + +CSMSConversation::CSMSConversation(CContact ConversationContact) +{ + mConversationContact = ConversationContact; +} + +CSMSConversation::CSMSConversation() +{ + +} + +CSMSConversation::~CSMSConversation() +{ + for(int i = 0; i < mMessages.size(); i++) + { + delete mMessages.at(i); + } + + mMessages.clear(); +} + +int CSMSConversation::InsertNewMessage(CSMSMessage *Message) +{ + mMessages.prepend(Message); + + return RET_OK; +} + +int CSMSConversation::InsertMessage(CSMSMessage *Message) +{ + mMessages.append(Message); + + return RET_OK; +} + +CContact* CSMSConversation::GetConversationContact() +{ + return &mConversationContact; +} + +int CSMSConversation::SetConversationContact(CContact *Contact) +{ + mConversationContact = *Contact; + return RET_OK; +} + +CSMSMessage* CSMSConversation::GetMostRecentMessage() +{ + if(mMessages.isEmpty()) + { + return 0; + } + + return mMessages.at(0); +} + +QList *CSMSConversation::GetMessages() +{ + return &mMessages; +} diff --git a/Sources/SMSClient/SMSConversation.h b/Sources/SMSClient/SMSConversation.h new file mode 100644 index 0000000..bba12e3 --- /dev/null +++ b/Sources/SMSClient/SMSConversation.h @@ -0,0 +1,27 @@ +#ifndef CSMSCONVERSATION_H +#define CSMSCONVERSATION_H + +#include "SMSMessage.h" +#include +#include "Contact.h" + +class CSMSConversation +{ +public: + CSMSConversation(CContact ConversationContact); + CSMSConversation(); + ~CSMSConversation(); + + CContact mConversationContact; + QList mMessages; + + int InsertNewMessage(CSMSMessage *Message); + int InsertMessage(CSMSMessage *Message); + CContact *GetConversationContact(); + int SetConversationContact(CContact *Contact); + CSMSMessage *GetMostRecentMessage(); + QList *GetMessages(); + +}; + +#endif // CSMSCONVERSATION_H diff --git a/Sources/SMSClient/SMSDatabase.cpp b/Sources/SMSClient/SMSDatabase.cpp new file mode 100644 index 0000000..f148141 --- /dev/null +++ b/Sources/SMSClient/SMSDatabase.cpp @@ -0,0 +1,204 @@ +#include "SMSDatabase.h" +#include "SMSClient.h" + +CSMSDatabase::CSMSDatabase() +{ + mProgramHandle = 0; + mNbUnreadMessages = 0; + mConversations.clear(); +} + + +CSMSDatabase::~CSMSDatabase() +{ + for(int i = 0; i < mConversations.size(); i++) + { + delete mConversations.at(i); + } + mConversations.clear(); +} + +int CSMSDatabase::SetAllMessages(QString DID, QList *MessagesList) +{ + Q_UNUSED(DID) + mConversations.clear(); + mNbUnreadMessages = 0; + // SetDID(DID); + mContactsHash.clear(); + + for(int i = 0; i < MessagesList->size(); i++) + { + CSMSMessage *CurMsg = new CSMSMessage(MessagesList->at(i)); + QString ContactNbr = CurMsg->mContact; + + if(mContactsHash.contains(ContactNbr) == true) + { + int Index = mContactsHash.value(ContactNbr); + mConversations.at(Index)->InsertMessage(CurMsg); + } + else + { + CSMSConversation *NewConversation = new CSMSConversation(CContact(CurMsg->mContact)); + CContact *Contact = mContactRepository->FindContact(CurMsg->mContact); + if(Contact != 0) + { + NewConversation->SetConversationContact(Contact); + } + mConversations.append(NewConversation); + int Index = mConversations.size()-1; + mContactsHash.insert(CurMsg->mContact,Index); + mConversations.at(Index)->InsertMessage(CurMsg); + } + } + + qDebug("Rx %d Messages",MessagesList->size()); + + return RET_OK; +} + +int CSMSDatabase::SetNewMessages(QString DID, QList *MessagesList) +{ + Q_UNUSED(DID) + + bool SyncConversations = false; + + for(int i = 0; i < MessagesList->size(); i++) + { + CSMSMessage *CurMsg = new CSMSMessage(MessagesList->at(i)); + QString ContactNbr = CurMsg->mContact; + // if(CurMsg->mType == SMS_RECEIVED_TYPE) + { + mNbUnreadMessages++; + CurMsg->mIsRead = false; + } + + if(mContactsHash.contains(ContactNbr) == true) + { + int Index = mContactsHash.value(ContactNbr); + mConversations.at(Index)->InsertNewMessage(CurMsg); + + + mProgramHandle->NewMessageNotification(mConversations.at(Index),0); + +// if(Index != 0) +// { +// CSMSConversation *Conversation = mConversations.takeAt(Index); +// mConversations.prepend(Conversation); +// mContactsHash.clear(); + +// for(int i = 0; i < mConversations.size(); i++) +// { +// mContactsHash.insert(mConversations.at(i)->mConversationContact.mRAWContactNbr,i); +// } + +// SyncConversations = true; +// } + } + else + { + CSMSConversation *NewConversation = new CSMSConversation(CContact(CurMsg->mContact)); + mConversations.append(NewConversation); + int Index = mConversations.size()-1; + mContactsHash.insert(CurMsg->mContact,Index); + mConversations.at(Index)->InsertNewMessage(CurMsg); + + SyncConversations = true; + mProgramHandle->MessageCountChangeNotification(mNbUnreadMessages); + } + } + + if(SyncConversations) + { + mProgramHandle->SyncConversations(); + } + + qDebug("Rx %d New Messages",MessagesList->size()); + + return RET_OK; +} + +QList* CSMSDatabase::GetConversations(QString DID) +{ + Q_UNUSED(DID); + + return &mConversations; +} + +CSMSConversation * CSMSDatabase::GetConversation(QString Contact) +{ + if(mContactsHash.contains(Contact)) + { + return mConversations.at(mContactsHash.value(Contact)); + } + + return 0; +} + +int CSMSDatabase::SetDID(QString DID) +{ + mClientDID = DID; + + mFormattedDID = DID; + mFormattedDID.insert(0,'('); + mFormattedDID.insert(4,") "); + mFormattedDID.insert(9,'-'); + + return RET_OK; + +} + +int CSMSDatabase::SetConversationAsRead(CSMSConversation *Conversation, bool ForceAll) +{ + if(Conversation == 0) + { + return RET_ERROR; + } + + QList *Messages = Conversation->GetMessages(); + + for(int i = 0; i < Messages->size(); i++) + { + if(Messages->at(i)->mIsRead == true) + { + if(ForceAll == false) + { + break; + } + } + else + { + Messages->at(i)->mIsRead = true; + // if(Messages->at(i)->mType == SMS_RECEIVED_TYPE) + { + mNbUnreadMessages--; + } + } + } + + mProgramHandle->MessageCountChangeNotification(mNbUnreadMessages); + + return RET_OK; +} + + +int CSMSDatabase::ContactsRepositoryChanged() +{ + CContact *Contact; + for(int i = 0; i < mConversations.size(); i++) + { + Contact = mContactRepository->FindContact(mConversations.at(i)->GetConversationContact()->mRAWContactNbr); + if(Contact != 0) + { + mConversations.at(i)->SetConversationContact(Contact); + } + } + return RET_OK; +} + + + + + + + + diff --git a/Sources/SMSClient/SMSDatabase.h b/Sources/SMSClient/SMSDatabase.h new file mode 100644 index 0000000..c7761b2 --- /dev/null +++ b/Sources/SMSClient/SMSDatabase.h @@ -0,0 +1,52 @@ +#ifndef CSMSDATABASE_H +#define CSMSDATABASE_H + + +#include "SMSConversation.h" +#include "SMSMessage.h" +#include "ContactRepository.h" +#include +#include + +class CSMSClient; + + +class CSMSDatabase +{ +public: + enum eNewMessageReadStatus + { + DB_NEW_MSG_READ, + DB_NEW_MSG_UNREAD + }; + + CSMSDatabase(); + ~CSMSDatabase(); + + CSMSClient *mProgramHandle; + CContactRepository *mContactRepository; + + QList mConversations; + QString mClientDID, mFormattedDID; + + QHash mContactsHash; + int mNbUnreadMessages; + + int SetAllMessages(QString DID, QList *MessagesList); + int SetNewMessages(QString DID, QList *MessagesList); + int SetDID(QString DID); + int SetConversationAsRead(CSMSConversation* Conversation, bool ForceAll = false); + int ContactsRepositoryChanged(); + + QList *GetConversations(QString DID = ""); + CSMSConversation* GetConversation(QString Contact); + QString GetDID(){return mClientDID;} + QString GetFormattedDID(){return mFormattedDID;} + int GetNbUnreadMsgs(){return mNbUnreadMessages;} + +// bool SortConversations(); + + +}; + +#endif // CSMSDATABASE_H diff --git a/Sources/SMSClient/SMSGui.cpp b/Sources/SMSClient/SMSGui.cpp new file mode 100644 index 0000000..60a715c --- /dev/null +++ b/Sources/SMSClient/SMSGui.cpp @@ -0,0 +1,276 @@ +#include "SMSGui.h" +#include "ui_SMSGui.h" +#include +#include "SMSClient.h" +#include + +CSMSGui::CSMSGui(QWidget *parent) : + QWidget(parent) + +{ + setupUi(this); + mSMSDatabase = 0; + mSelectedConversation = 0; + mProgramHandle = 0; + mCharCounter = 160; + mMsgCounter = 0; + + mSMSMessageStatsLabel->setText(QString().sprintf("Nombre de caractères du message %d/160\nNombre de messages à envoyer: %d msg",mCharCounter,mMsgCounter+1)); + +// connect(mContactsTreeWidget,SIGNAL(itemActivated(QTreeWidgetItem*,int)),this,SLOT(ConversationSelected(QTreeWidgetItem*,int))); + connect(mContactsTreeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(ConversationClicked(QTreeWidgetItem*,int))); + connect(mSMSSendBtn,SIGNAL(clicked(bool)),this,SLOT(SendMsgBtnClicked(bool))); + connect(mSMSEdit,SIGNAL(textChanged()),this,SLOT(SMSEditZoneContentsChanged())); + + mSMSEdit->installEventFilter(this); +} + +CSMSGui::~CSMSGui() +{ + +} + + +int CSMSGui::FullConversationsUpdate() +{ + QList *ConversationsList = mSMSDatabase->GetConversations(); + + mContactsTreeWidget->clear(); + mContactsTreeWidget->setColumnCount(3); + mContactsTreeWidget->setIconSize(QSize(25,25)); + + + + for(int i = 0; i < ConversationsList->size(); i++) + { + QFont NewMsgFont; + NewMsgFont.setBold(true); + + QTreeWidgetItem *NewContact = new QTreeWidgetItem(mContactsTreeWidget); + CSMSConversation *Conversation = ConversationsList->at(i); + CSMSMessage *LastMsg = Conversation->GetMostRecentMessage(); + NewContact->setIcon(0,QIcon(Conversation->GetConversationContact()->mContactPicture)); + if(LastMsg->mIsRead == false) + { + NewContact->setFont(1,NewMsgFont); + NewContact->setFont(2,NewMsgFont); + } + NewContact->setText(1,Conversation->GetConversationContact()->mContactName); + NewContact->setText(2,Conversation->GetConversationContact()->mContactNumber); +// QVariant data = QVariant::fromValue((void*)Conversation); + NewContact->setData(0,Qt::UserRole,QVariant::fromValue((void*)Conversation)); + mContactsTreeWidget->insertTopLevelItem(0,NewContact); + } + + mContactsTreeWidget->resizeColumnToContents(0); + mContactsTreeWidget->resizeColumnToContents(1); + mContactsTreeWidget->resizeColumnToContents(2); + mContactsTreeWidget->topLevelItem(0)->setSelected(true); + ConversationClicked(mContactsTreeWidget->topLevelItem(0),0); + + +// mContactsTreeWidget->addTopLevelItem(QTreeWidget()); + return RET_OK; +} + +void CSMSGui::ConversationClicked(QTreeWidgetItem *item, int column) +{ + //qDebug("Clicked %d",column); + mSelectedConversation = (CSMSConversation*) item->data(0,Qt::UserRole).value(); + QString MessageText; + MessageText.clear(); + + mConversationText->clear(); + +// for(int i = 0; i < Conversation->GetMessages()->size(); i++) + for(int i = mSelectedConversation->GetMessages()->size()-1; i >=0; i--) + { + MessageText.append(mSelectedConversation->GetMessages()->at(i)->mDateTime.toString("yyyy/MM/dd hh:mm - ")); + + if(mSelectedConversation->GetMessages()->at(i)->mType == SMS_SENT_TYPE) + { + MessageText.append("YOU: "); + } + else + { + MessageText.append(mSelectedConversation->GetConversationContact()->mContactName); + MessageText.append(": "); + } + MessageText.append(mSelectedConversation->GetMessages()->at(i)->mMessageText); + MessageText.append("\n\r"); + } + + mConversationText->setText(MessageText); + + QFont font; + font.setBold(false); + item->setFont(0,font); + item->setFont(1,font); + item->setFont(2,font); + + QTextCursor cursor( mConversationText->textCursor() ); + cursor.movePosition( QTextCursor::End ); + + QScrollBar *bar = mConversationText->verticalScrollBar(); + if( bar ) + { + if( !bar->isSliderDown() ) + bar->setValue( bar->maximum() ); + } + else + mConversationText->ensureCursorVisible(); + + mContactPic->setPixmap(mSelectedConversation->GetConversationContact()->mContactPicture.scaled(mContactPic->size())); + font.setPointSize(26); + mContactName->setFont(font); + mContactName->setText(mSelectedConversation->GetConversationContact()->mContactName); + + mSMSDatabase->SetConversationAsRead(mSelectedConversation); + + +} + +int CSMSGui::UpdateDisplayedConversation(int MessageIndex) +{ + if(MessageIndex != -1) + { + QString MessageText; + MessageText = mConversationText->toPlainText(); + + MessageText.append(mSelectedConversation->GetMessages()->at(MessageIndex)->mDateTime.toString("yyyy/MM/dd hh:mm - ")); + + if(mSelectedConversation->GetMessages()->at(MessageIndex)->mType == SMS_SENT_TYPE) + { + MessageText.append("YOU: "); + } + else + { + MessageText.append(mSelectedConversation->GetMessages()->at(MessageIndex)->mContact); + MessageText.append(": "); + } + MessageText.append(mSelectedConversation->GetMessages()->at(MessageIndex)->mMessageText); + MessageText.append("\n\r"); + + mConversationText->setText(MessageText); + } + + + + QTextCursor cursor( mConversationText->textCursor() ); + cursor.movePosition( QTextCursor::End ); + + QScrollBar *bar = mConversationText->verticalScrollBar(); + if( bar ) + { + if( !bar->isSliderDown() ) + bar->setValue( bar->maximum() ); + } + else + mConversationText->ensureCursorVisible(); + + return RET_OK; + +} + +//void CSMSGui::ConversationSelected(QTreeWidgetItem *item, int column) +//{ +// // qDebug("Selected, %d",column); +//} + +int CSMSGui::NewMessageNotification(CSMSConversation *Conversation, int MessageIndex) +{ + if(Conversation == 0) + { + return NEW_MSG_ERROR_STATUS; + } + if(mSelectedConversation == Conversation) //the new msg comes from the currently displayed contact conversation + { + UpdateDisplayedConversation(MessageIndex); + mSMSDatabase->SetConversationAsRead(mSelectedConversation); + return NEW_MSG_READ_STATUS; + } + + //Find conversation... + for(int i = 0; i < mContactsTreeWidget->topLevelItemCount(); i++) + { + void *data = mContactsTreeWidget->topLevelItem(i)->data(0,Qt::UserRole).value(); + if((CSMSConversation*)data == Conversation) + { + //found it! + QFont font; + font.setBold(true); + mContactsTreeWidget->topLevelItem(i)->setFont(0,font); + mContactsTreeWidget->topLevelItem(i)->setFont(1,font); + mContactsTreeWidget->topLevelItem(i)->setFont(2,font); + return NEW_MSG_UNREAD_STATUS; + } + } + return NEW_MSG_ERROR_STATUS; +} + +int CSMSGui::SendEditMessage() +{ + if(mSelectedConversation == 0) + { + return RET_ERROR; + } + + QString MsgTxt = mSMSEdit->toPlainText(); + + if(MsgTxt.isEmpty()) + { + return RET_ERROR; + } + + CSMSMessage Message; + Message.mContact = mSelectedConversation->mConversationContact.mRAWContactNbr; + Message.mDID = mSMSDatabase->GetDID(); + Message.mMessageText = MsgTxt; + + mProgramHandle->SendSMSMessage(Message); + mSMSEdit->clear(); + + return RET_OK; +} + +void CSMSGui::SendMsgBtnClicked(bool checked) +{ + Q_UNUSED(checked) + SendEditMessage(); +} + +bool CSMSGui::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) + { + QKeyEvent *keyEvent = static_cast(event); + if(keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) + { + // qDebug("Ate key press %d", keyEvent->key()); + SendEditMessage(); + return true; + } + // qDebug("Key press %d", keyEvent->key()); + + } + + // standard event processing + return QObject::eventFilter(obj, event); +} + +void CSMSGui::SMSEditZoneContentsChanged() +{ + int CurStringCharCount = mSMSEdit->toPlainText().size(); + if(CurStringCharCount <= 160) + { + mCharCounter = 160-CurStringCharCount; + mMsgCounter = 0; + } + else + { + mMsgCounter = (int)(CurStringCharCount / 160); + mCharCounter = 160 - (CurStringCharCount - (mMsgCounter*160)); + } + mSMSMessageStatsLabel->setText(QString().sprintf("Nombre de caractères du message %d/160\nNombre de messages à envoyer: %d msg",mCharCounter,mMsgCounter+1)); + +} diff --git a/Sources/SMSClient/SMSGui.h b/Sources/SMSClient/SMSGui.h new file mode 100644 index 0000000..f44f85b --- /dev/null +++ b/Sources/SMSClient/SMSGui.h @@ -0,0 +1,49 @@ +#ifndef SMSGUI_H +#define SMSGUI_H + +#include +#include "ui_SMSGui.h" +#include "SMSDatabase.h" + +//namespace Ui { +//class CSMSGui; +//} +class CSMSClient; + +enum eNewMessageStatus +{ + NEW_MSG_READ_STATUS, + NEW_MSG_UNREAD_STATUS, + NEW_MSG_ERROR_STATUS +}; + +class CSMSGui : public QWidget, private Ui::CSMSGui +{ + Q_OBJECT + +public: + explicit CSMSGui(QWidget *parent = 0); + ~CSMSGui(); + + int FullConversationsUpdate(); + int NewMessageNotification(CSMSConversation* Conversation, int MessageIndex); + int SendEditMessage(); + + int UpdateDisplayedConversation(int MessageIndex = -1); + virtual bool eventFilter(QObject *obj, QEvent *event); + + CSMSDatabase *mSMSDatabase; + CSMSConversation *mSelectedConversation; + CSMSClient *mProgramHandle; + +private: + int mCharCounter, mMsgCounter; + +public slots: + // void ConversationSelected(QTreeWidgetItem * item, int column); + void ConversationClicked(QTreeWidgetItem * item, int column); + void SendMsgBtnClicked(bool); + void SMSEditZoneContentsChanged(); +}; + +#endif // SMSGUI_H diff --git a/Sources/SMSClient/SMSMasterCtrlInterface.cpp b/Sources/SMSClient/SMSMasterCtrlInterface.cpp new file mode 100644 index 0000000..746e278 --- /dev/null +++ b/Sources/SMSClient/SMSMasterCtrlInterface.cpp @@ -0,0 +1,291 @@ +#include "SMSMasterCtrlInterface.h" +#include +#include +#include +#include "SystemGui.h" +#include "Contact.h" +#include "SMSClient.h" + + +CSMSMasterCtrlInterface::CSMSMasterCtrlInterface(CSMSClient *ProgramHandle) +{ + mDeviceAddress = 1; + mNetworkPort = 2182; + mMasterCtrlAddress = "127.0.0.1"; +// mNetworkPort = 6463; +// mMasterCtrlAddress = "192.168.0.112"; + mNetworkCommSocket = 0; + mMyDeviceID = ID_SMS_CLIENT; + + mProgramHandle = ProgramHandle; +} + +CSMSMasterCtrlInterface::~CSMSMasterCtrlInterface() +{ + if(mNetworkCommSocket !=0) + { +// mNetworkCommSocket->disconnectFromHost(); + // delete mNetworkCommSocket; + } +} + +//int CSMSMasterCtrlInterface::ConnectToMasterCtrl() +//{ +//// if(mNetworkCommSocket == 0) +//// { +//// mNetworkCommSocket = new QTcpSocket(); +//// } +//// connect(mNetworkCommSocket,SIGNAL(connected()),this,SLOT(NetworkSocketConnected())); +//// connect(mNetworkCommSocket,SIGNAL(disconnected()),this,SLOT(NetworkSocketDisconnected())); +//// connect(mNetworkCommSocket,SIGNAL(readyRead()),this,SLOT(NetworkSocketDataAvailable())); + +//// mNetworkCommSocket->connectToHost(mMasterCtrlAddress,mNetworkPort); + +// return RET_OK; +//} + +int CSMSMasterCtrlInterface::DeviceConnectedToMaster(bool Connected) +{ + if(Connected) + { + mNetworkCommSocket->write(GetTxPacket(SMS_CLIENT_DEVICE_DID_INFO_REQUEST,0,0,0,1,ID_MASTER,ID_SMS_CLIENT,mDeviceAddress)); + } + else + { + //??? + } + return RET_OK; +} + +int CSMSMasterCtrlInterface::DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderDeviceID, int SenderAddress, int MessageID, int DataSize, QByteArray Data) +{ + Q_UNUSED(DataSize) + + +// if(TargetDeviceID == ID_ETHERNET_VIRTUAL) +// { +// switch(MessageID) +// { +// case ETH_NETWK_DEVICE_INFO_REQUEST: +// { +// QByteArray Frame,ResponseData; +// ResponseData.append((char)ID_SMS_CLIENT); +// ResponseData.append((char)mDeviceAddress); +// Frame = GetTxPacket(ETH_NETWK_DEVICE_INFO_RESPONSE,0,ResponseData.data(),ResponseData.size(),1,ID_MASTER,ID_ETHERNET_VIRTUAL,mDeviceAddress); +// mNetworkCommSocket->write(Frame); +// break; +// } +// case ETH_NETWK_CONNECTION_REFUSED: +// { +// qDebug("MasterCtrl connection refused"); +// mNetworkCommSocket->close(); +// delete mNetworkCommSocket; +// mNetworkCommSocket = 0; +// break; +// } +// case ETH_NETWK_SET_DEVICE_INFO_ACK: +// { +// mNetworkCommSocket->write(GetTxPacket(SMS_CLIENT_DEVICE_DID_INFO_REQUEST,0,0,0,1,ID_MASTER,ID_SMS_CLIENT,mDeviceAddress)); +// qDebug("MasterCtrl accepted connection"); +// break; +// } +// case ETH_NETWK_DEVICE_INFO_RESPONSE: +// default: +// { +// break; +// } + +// } +// } + /* else*/ if(TargetDeviceID == ID_SMS_CLIENT && (TargetDeviceAddress == BROADCAST_VALUE || TargetDeviceAddress == mDeviceAddress)) + { + switch(MessageID) + { + case SMS_CLIENT_DEVICE_ACK: + { + break; + } + case SMS_CLIENT_DEVICE_STATUS_REQUEST: + { + QByteArray Frame,ResponseData; + ResponseData.append(ACK); + ResponseData.append((char)SMS_CLIENT_DEVICE_STATUS_REQUEST); + Frame = GetTxPacket(SMS_CLIENT_DEVICE_STATUS_RESPONSE,0,ResponseData.data(),ResponseData.size(),1,ID_MASTER,ID_SMS_CLIENT,mDeviceAddress); + mNetworkCommSocket->write(Frame); + // qDebug("Rx Status Request"); + break; + } + case SMS_CLIENT_DEVICE_DID_INFO_RESPONSE: + { + QString DidInfo; + QDataStream *Strm = new QDataStream(Data); + *Strm >> DidInfo; + delete Strm; + qDebug("Rx DID info: %s",DidInfo.toUtf8().data()); + mProgramHandle->SetDIDDatabase(DidInfo); + +// mNetworkCommSocket->write(GetTxPacket(SMS_CLIENT_DEVICE_GET_ALL_MSG_REQUEST,0,0,0,1,ID_MASTER,ID_SMS_CLIENT,mDeviceAddress)); + mNetworkCommSocket->write(GetTxPacket(SMS_CLIENT_DEVICE_GET_CONTACTS_REQUEST,0,0,0,1,ID_MASTER,ID_SMS_CLIENT,mDeviceAddress)); + break; + } + case SMS_CLIENT_DEVICE_GET_ALL_MSG_RESPONSE: + { + QList RAWSMSList; + QDataStream *Stream = new QDataStream(Data); + CSMSMessage NewMsg; + + int NbMsg; + *Stream >> NbMsg; + + for(int i = 0; i < NbMsg; i++) + { + *Stream >> NewMsg; + RAWSMSList.append(NewMsg); + } + + mProgramHandle->SetAllMsgsDatabase("",&RAWSMSList); + + RAWSMSList.clear(); + + + delete Stream; + break; + } + case SMS_CLIENT_DEVICE_NEW_MSG_NOTIFICATION: + { + QList RAWSMSList; + QDataStream *Stream = new QDataStream(Data); + CSMSMessage NewMsg; + + int NbMsg; + *Stream >> NbMsg; + + for(int i = 0; i < NbMsg; i++) + { + *Stream >> NewMsg; + RAWSMSList.append(NewMsg); + } + + mProgramHandle->NewMessagesEvent(&RAWSMSList); + + RAWSMSList.clear(); + + + delete Stream; + + + break; + } + case SMS_CLIENT_DEVICE_SEND_SMS_ACK: + { + + QDataStream *Stream = new QDataStream(Data); + qint32 Success; + *Stream >> Success; + if(Success == 1) + { + qDebug("SMS Sent!!!"); + } + else + { + qDebug("Send SMS Failed"); + } + + delete Stream; + + break; + } + case SMS_CLIENT_DEVICE_GET_CONTACTS_RESPONSE: + { + QList ContactsList; + QDataStream *Stream = new QDataStream(Data); + CContact NewContact; + + int NbContact; + *Stream >> NbContact; + + for(int i = 0; i < NbContact; i++) + { + *Stream >> NewContact; + ContactsList.append(NewContact); + } + + mProgramHandle->SetContacts(&ContactsList); + + ContactsList.clear(); + qDebug("Contacts downloaded!"); + + + delete Stream; + + mNetworkCommSocket->write(GetTxPacket(SMS_CLIENT_DEVICE_GET_ALL_MSG_REQUEST,0,0,0,1,ID_MASTER,ID_SMS_CLIENT,mDeviceAddress)); + break; + } + case SMS_CLIENT_DEVICE_CONTACTS_CHANGED_NOTIFICATION: + { + mNetworkCommSocket->write(GetTxPacket(SMS_CLIENT_DEVICE_GET_CONTACTS_REQUEST,0,0,0,1,ID_MASTER,ID_SMS_CLIENT,mDeviceAddress)); + break; + } + + case SMS_CLIENT_DEVICE_SEND_SMS_REQUEST: + case SMS_CLIENT_DEVICE_STATUS_RESPONSE: + case SMS_CLIENT_DEVICE_DID_INFO_REQUEST: + case SMS_CLIENT_DEVICE_GET_ALL_MSG_REQUEST: + default: + { + qDebug("SMSDevice: Invalid Ethernet MSg received: %d",MessageID); + break; + } + + } + } + + return RET_OK; +} + +//int CSMSMasterCtrlInterface::DisconnectMasterCtrl() +//{ +// if(mNetworkCommSocket != 0) +// { +// mNetworkCommSocket->close(); +// // mNetworkCommSocket->deleteLater(); +// } + +// return RET_OK; +//} + +//void CSMSMasterCtrlInterface::NetworkSocketConnected() +//{ +// qDebug("Connected to MasterCtrl"); +//} + +//void CSMSMasterCtrlInterface::NetworkSocketDataAvailable() +//{ +// AnalyzeRxBuffer(mNetworkCommSocket->readAll()); +//} + +void CSMSMasterCtrlInterface::SendSMS(CSMSMessage Message) +{ + QByteArray FrameData; + QBuffer FrameBuffer(&FrameData); + FrameBuffer.open(QIODevice::ReadWrite); + QDataStream *FrameDataStrm = new QDataStream(&FrameBuffer); + + qint32 NbMsg = 1; + + *FrameDataStrm << NbMsg << Message; + + FrameBuffer.seek(0); + + mNetworkCommSocket->write(GetTxPacket(SMS_CLIENT_DEVICE_SEND_SMS_REQUEST,0,FrameData,FrameData.size(),1,ID_MASTER)); + + FrameBuffer.close(); + delete FrameDataStrm; +} + +//void CSMSMasterCtrlInterface::NetworkSocketDisconnected() +//{ +// qDebug("Disconnected from MasterCtrl"); +//// delete mNetworkCommSocket; +//// mNetworkCommSocket = 0; +//} diff --git a/Sources/SMSClient/SMSMasterCtrlInterface.h b/Sources/SMSClient/SMSMasterCtrlInterface.h new file mode 100644 index 0000000..5e05160 --- /dev/null +++ b/Sources/SMSClient/SMSMasterCtrlInterface.h @@ -0,0 +1,47 @@ +#ifndef CSMSMASTERCTRLINTERFACE_H +#define CSMSMASTERCTRLINTERFACE_H + +//#include "NetworkProtocol.h" +//#include "GlobalDefine.h" +//#include "ProtocolDefs.h" +//#include +//#include "SMSMessage.h" +#include "MasterCtrlInterface.h" + + +class CSystemGui; +class CSMSClient +; +class CSMSMasterCtrlInterface: public CMasterCtrlInterface//CNetworkProtocol +{ + Q_OBJECT +public: + CSMSMasterCtrlInterface(CSMSClient *ProgramHandle); + ~CSMSMasterCtrlInterface(); + + CSMSClient *mProgramHandle; + + // virtual int DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data); + +// QTcpSocket *mNetworkCommSocket; +// int mDeviceAddress; +// int mNetworkPort; +// QString mMasterCtrlAddress; + + +// int ConnectToMasterCtrl(); +// int DisconnectMasterCtrl(); +// virtual int NewFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data); + + virtual int DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data); + virtual int DeviceConnectedToMaster(bool Connected); + + void SendSMS(CSMSMessage Message); + +//public slots: +// void NetworkSocketConnected(); +// void NetworkSocketDataAvailable(); +// void NetworkSocketDisconnected(); +}; + +#endif // CSMSMasterCtrlInterface_H diff --git a/Sources/SMSClient/SMSMessage.cpp b/Sources/SMSClient/SMSMessage.cpp new file mode 100644 index 0000000..40df6c1 --- /dev/null +++ b/Sources/SMSClient/SMSMessage.cpp @@ -0,0 +1,63 @@ +#include "SMSMessage.h" +#include + + + +CSMSMessage::CSMSMessage() +{ + this->mContact = "INVALID"; + this->mDateTime = QDateTime::currentDateTime(); + this->mDID = "INVALID"; + this->mMessageText = "INVALID"; + this->mType = SMS_INVALID_TYPE; + this->mVOIPMSDatabaseID = "INVALID"; + + mIsRead = true; +} + +CSMSMessage::CSMSMessage(const CSMSMessage &Message) +{ + this->mContact = Message.mContact; + this->mDateTime = Message.mDateTime; + this->mDID = Message.mDID; + this->mMessageText = Message.mMessageText; + this->mType = Message.mType; + this->mVOIPMSDatabaseID = Message.mVOIPMSDatabaseID; + + mIsRead = true; +} + + +CSMSMessage::~CSMSMessage() +{ + +} + +QDataStream &operator<<(QDataStream &out, const CSMSMessage &source) +{ + + out << source.mDID + << source.mDateTime + << source.mMessageText + << source.mContact + << (qint32)source.mType + << source.mVOIPMSDatabaseID; + + + return out; +} + +QDataStream &operator>>(QDataStream &in, CSMSMessage &dest) +{ + qint32 temp; + in >> dest.mDID + >> dest.mDateTime + >> dest.mMessageText + >> dest.mContact + >> temp + >> dest.mVOIPMSDatabaseID; + + dest.mType = (eSMSType)temp; + + return in; +} diff --git a/Sources/SMSClient/SMSMessage.h b/Sources/SMSClient/SMSMessage.h new file mode 100644 index 0000000..6705cce --- /dev/null +++ b/Sources/SMSClient/SMSMessage.h @@ -0,0 +1,44 @@ +#ifndef CSMSMESSAGE_H +#define CSMSMESSAGE_H + +#include "GlobalDefine.h" +#include +#include + +typedef enum eSMSType +{ + SMS_SENT_TYPE, + SMS_RECEIVED_TYPE, + SMS_INVALID_TYPE +}SmsType_t; + +class CSMSMessage +{ + +public: + CSMSMessage(); + CSMSMessage(const CSMSMessage &Message); + ~CSMSMessage(); + + /*qint64*/QString mVOIPMSDatabaseID; + QDateTime mDateTime; + SmsType_t mType; + QString mDID, mContact, mMessageText; + + bool mIsRead; + + + +// [id] => 111120 +// [date] => 2014-03-30 10:24:16 +// [type] => 0 +// [did] => 8574884828 +// [contact] => 8577884821 +// [message] => hello+john + +}; + +QDataStream &operator<<(QDataStream &out, const CSMSMessage &source); +QDataStream &operator>>(QDataStream &in, CSMSMessage &dest); + +#endif // CSMSOBJECT_H diff --git a/Sources/SettingsWindow.cpp b/Sources/SettingsWindow.cpp new file mode 100644 index 0000000..a9db25f --- /dev/null +++ b/Sources/SettingsWindow.cpp @@ -0,0 +1,147 @@ +#include "SettingsWindow.h" +#include +#include +#include +#include "SMSClient.h" + + +CSettingsWindow::CSettingsWindow() +{ + resize(600,600); + + QVBoxLayout *MainLayout = new QVBoxLayout; + QWidget *mPagesContainer = new QWidget(this); + + mOptionsTabBar = new QTabBar(); + mOptionsTabBar->addTab("SMS"); + mOptionsTabBar->addTab("Network"); + mOptionsTabBar->resize(this->geometry().width(),mOptionsTabBar->height()); + MainLayout->addWidget(mOptionsTabBar); + + mSMSPage = new QWidget(mPagesContainer); + // mVoipPage->resize(this->size()); + + QGridLayout *mSMSPageLayout = new QGridLayout; + + + QLabel *Label; + mVoipMSUsername = new QLineEdit; + Label = new QLabel("Voip.ms Username: "); + mSMSPageLayout->addWidget(Label,0,1,1,1); + mSMSPageLayout->addWidget(mVoipMSUsername,0,2,1,2/*,Qt::AlignLeft*/); + + Label = new QLabel("Voip.ms Password: "); + mVoipMSPassword = new QLineEdit; + mVoipMSPassword->setEchoMode(QLineEdit::Password); + mSMSPageLayout->addWidget(Label,1,1,1,1); + mSMSPageLayout->addWidget(mVoipMSPassword,1,2,1,1/*,Qt::AlignLeft*/); + + mRetreiveDIDSButton = new QPushButton("Get DIDs"); + connect(mRetreiveDIDSButton,SIGNAL(clicked(bool)),this,SLOT(RetreiveDIDButtonClicked(bool))); + mSMSPageLayout->addWidget(mRetreiveDIDSButton,1,3,1,1); + + + Label = new QLabel("DID:"); + mDIDSelectionDropList = new QComboBox(); + mSMSPageLayout->addWidget(Label,2,1,1,1); + mSMSPageLayout->addWidget(mDIDSelectionDropList,2,2,1,1); + + + mVoipMSCalendar = new QCalendarWidget; + Label = new QLabel("SMS retreival stard date:"); + mSMSPageLayout->addWidget(Label,3,1,1,1); + mSMSPageLayout->addWidget(mVoipMSCalendar,4,1,1,4); + + mDoneButton = new QPushButton("Done"); + MainLayout->addWidget(mDoneButton); + connect(mDoneButton,SIGNAL(clicked(bool)),this,SLOT(DoneButtonClicked(bool))); + + + + + mSMSPage->setLayout(mSMSPageLayout); + mSMSPage->show(); + + MainLayout->addWidget(mPagesContainer); + setLayout(MainLayout); + + connect(mOptionsTabBar,SIGNAL(currentChanged(int)),this,SLOT(TabBarClicked(int))); + +} + +CSettingsWindow::~CSettingsWindow() +{ + +} + +void CSettingsWindow::TabBarClicked(int TabIndex) +{ + if(TabIndex == 0)//SMS + { + mSMSPage->show(); + + + } + else if(TabIndex == 1)//Network + { + mSMSPage->hide(); + + } +} + +void CSettingsWindow::RetreiveDIDButtonClicked(bool checked) +{ + Q_UNUSED(checked) + + if(mVoipMSUsername->text().isEmpty() || mVoipMSPassword->text().isEmpty()) + { + return; + } + + + + qDebug("CLick!"); +} + +void CSettingsWindow::DIDsListFetched(QStringList DIDs) +{ + if(DIDs.size() == 0) + { + + } + else + { + mDIDSelectionDropList->clear(); + for(int i = 0; i < DIDs.size(); i++) + { + mDIDSelectionDropList->addItem(DIDs.at(i)); + } + } +} + +unsigned int CSettingsWindow::SetSettingsData(CSettings *SettingsData) +{ + mVoipMSPassword->setText(SettingsData->mVoipMSSettings.mPassword); + mVoipMSUsername->setText(SettingsData->mVoipMSSettings.mUsername); + mDIDSelectionDropList->clear(); + mDIDSelectionDropList->addItem(SettingsData->mVoipMSSettings.mDefaultDID); + mVoipMSCalendar->setSelectedDate(SettingsData->mVoipMSSettings.mStartDate); + return RET_OK; +} + +void CSettingsWindow::DoneButtonClicked(bool checked) +{ + Q_UNUSED(checked) + + CSettings *Settings = new CSettings; + Settings->mVoipMSSettings.mDefaultDID = mDIDSelectionDropList->currentText(); + Settings->mVoipMSSettings.mPassword = mVoipMSPassword->text(); + Settings->mVoipMSSettings.mStartDate = mVoipMSCalendar->selectedDate(); + Settings->mVoipMSSettings.mUsername = mVoipMSUsername->text(); + + mProgramHandle->SaveSettings(Settings); + mProgramHandle->SettingsWindowClosed(); + delete Settings; + + this->hide(); +} diff --git a/Sources/SettingsWindow.h b/Sources/SettingsWindow.h new file mode 100644 index 0000000..852fc8d --- /dev/null +++ b/Sources/SettingsWindow.h @@ -0,0 +1,44 @@ +#ifndef CSETTINGSWINDOW_H +#define CSETTINGSWINDOW_H + +#include "GlobalDefine.h" +#include +#include +#include +#include +#include +#include +#include "ProgramSettings.h" + +class CSMSClient; + + +class CSettingsWindow : public QDialog +{ + Q_OBJECT +public: + CSettingsWindow(); + virtual ~CSettingsWindow(); + + CSMSClient *mProgramHandle; + + QWidget *mSMSPage; + QTabBar *mOptionsTabBar; + QLineEdit *mVoipMSUsername; + QLineEdit *mVoipMSPassword; + QCalendarWidget *mVoipMSCalendar; + QComboBox *mDIDSelectionDropList; + QPushButton *mRetreiveDIDSButton; + + QPushButton *mDoneButton; + + unsigned int SetSettingsData(CSettings *SettingsData); + +public slots: + void TabBarClicked(int); + void RetreiveDIDButtonClicked(bool); + void DIDsListFetched(QStringList); + void DoneButtonClicked(bool); +}; + +#endif // CSETTINGSWINDOW_H diff --git a/Sources/Sprinkler/SprinklerGui.cpp b/Sources/Sprinkler/SprinklerGui.cpp new file mode 100644 index 0000000..f2ec187 --- /dev/null +++ b/Sources/Sprinkler/SprinklerGui.cpp @@ -0,0 +1,13 @@ +#include "SprinklerGui.h" +#include "ui_SprinklerGui.h" + +CSprinklerGui::CSprinklerGui(QWidget *parent) : + QWidget(parent) +{ + setupUi(this); +} + +CSprinklerGui::~CSprinklerGui() +{ + +} diff --git a/Sources/Sprinkler/SprinklerGui.h b/Sources/Sprinkler/SprinklerGui.h new file mode 100644 index 0000000..1db22ee --- /dev/null +++ b/Sources/Sprinkler/SprinklerGui.h @@ -0,0 +1,23 @@ +#ifndef SPRINKLERGUI_H +#define SPRINKLERGUI_H + +#include +#include "ui_SprinklerGui.h" + +namespace Ui { +class CSprinklerGui; +} + +class CSprinklerGui : public QWidget, public Ui::CSprinklerGui +{ + Q_OBJECT + +public: + explicit CSprinklerGui(QWidget *parent = 0); + ~CSprinklerGui(); + +private: + +}; + +#endif // SPRINKLERGUI_H diff --git a/Sources/Sprinkler/SprinklerGui.ui b/Sources/Sprinkler/SprinklerGui.ui new file mode 100644 index 0000000..4cfbdd8 --- /dev/null +++ b/Sources/Sprinkler/SprinklerGui.ui @@ -0,0 +1,32 @@ + + + CSprinklerGui + + + + 0 + 0 + 1047 + 560 + + + + Form + + + + + 0 + -10 + 201 + 51 + + + + Sprinklers + + + + + + diff --git a/Sources/SystemGui.cpp b/Sources/SystemGui.cpp new file mode 100644 index 0000000..93adb69 --- /dev/null +++ b/Sources/SystemGui.cpp @@ -0,0 +1,62 @@ +#include "SystemGui.h" + + +CSystemGui::CSystemGui(QObject *parent) : QObject(parent) +{ + mGui = new CGuiMain(); + mProgramSettings = new CProgramSettings(); + mSMSClient = new CSMSClient(mGui->mSMSGui,&mSettings.mVoipMSSettings); + + mSysTrayMgr = new CSystemTrayManager(); + mSysTrayMgr->mProgramHandle=this; + mSMSClient->mTrayIconMgr = mSysTrayMgr; + +} + +CSystemGui::~CSystemGui() +{ + delete mGui; + delete mSMSClient; + delete mProgramSettings; + delete mSysTrayMgr; + +} + +void CSystemGui::Start() +{ + mProgramSettings->LoadSettings(&mSettings); + mGui->show(); + mSMSClient->Start(); + +} + +void CSystemGui::ShowSettingsWindowRequest() +{ + +} + +void CSystemGui::QuitApplicationRequest() +{ + QApplication::exit(69); +} + +int CSystemGui::RespawnMainWindowRequest() +{ + //qDebug("Respawn request"); + mGui->RespawnMainWindow(); + return RET_OK; +} + +int CSystemGui::TrayIconLeftClick() +{ + if(mGui->isVisible()) + { + mGui->hide(); + } + else + { + mGui->RespawnMainWindow(); + } + + return RET_OK; +} diff --git a/Sources/SystemGui.h b/Sources/SystemGui.h new file mode 100644 index 0000000..83c4bf7 --- /dev/null +++ b/Sources/SystemGui.h @@ -0,0 +1,37 @@ +#ifndef SYSTEMGUI_H +#define SYSTEMGUI_H + +#include +#include "GuiMain.h" +#include "SMSClient.h" +#include "ProgramSettings.h" +#include "SystemTrayManager.h" + +class CSystemGui : public QObject +{ + Q_OBJECT +public: + explicit CSystemGui(QObject *parent = 0); + ~CSystemGui(); + + void Start(); + + void ShowSettingsWindowRequest(); + void QuitApplicationRequest(); + int RespawnMainWindowRequest(); + int TrayIconLeftClick(); + +private: + CGuiMain *mGui; + CSMSClient *mSMSClient; + CProgramSettings *mProgramSettings; + CSettings mSettings; + CSystemTrayManager *mSysTrayMgr; + + +signals: + +public slots: +}; + +#endif // SYSTEMGUI_H diff --git a/Sources/SystemTrayManager.cpp b/Sources/SystemTrayManager.cpp new file mode 100644 index 0000000..eeacdb1 --- /dev/null +++ b/Sources/SystemTrayManager.cpp @@ -0,0 +1,96 @@ +#include "SystemTrayManager.h" +#include "SystemGui.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*))); + + mShowSettingsGUIAction = mTrayMenu->addAction("Settings"); + mQuitAction = mTrayMenu->addAction("Quit SMS Client"); + mSystemTrayIcon.setIcon(QIcon("./Ico/sms.png")); + mSystemTrayIcon.setToolTip("SMS Client :)"); + 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: + { + //qDebug("Context"); + break; + } + case QSystemTrayIcon::DoubleClick: + { + break; + } + case QSystemTrayIcon::Trigger: + { + //qDebug("Trigger"); + //mTrayMenu->popup(QCursor::pos()); + //mProgramHandle->RespawnMainWindowRequest(); + mProgramHandle->TrayIconLeftClick(); + break; + } + case QSystemTrayIcon::MiddleClick: + { + break; + } + } +} + +void CSystemTrayManager::TrayMenuClicked(QAction *Menu) +{ + if(Menu == mQuitAction) + { + qDebug("Quit"); + mProgramHandle->QuitApplicationRequest(); + } + else if(Menu == mShowSettingsGUIAction) + { + qDebug("Settings"); + mProgramHandle->ShowSettingsWindowRequest(); + } + +} + +int CSystemTrayManager::NewSMSMessagesPendingCount(int count) +{ + if(count == 0) + { + mSystemTrayIcon.setIcon(QIcon("./Ico/sms.png")); + } + else + { + mSystemTrayIcon.setIcon(QIcon("./Ico/sms_new.png")); + } + + return RET_OK; +} diff --git a/Sources/SystemTrayManager.h b/Sources/SystemTrayManager.h new file mode 100644 index 0000000..940621c --- /dev/null +++ b/Sources/SystemTrayManager.h @@ -0,0 +1,32 @@ +#ifndef CSYSTEMTRAYMANAGER_H +#define CSYSTEMTRAYMANAGER_H + +#include "GlobalDefine.h" +#include +#include +#include + +class CSystemGui; + +class CSystemTrayManager: public QObject +{ + Q_OBJECT +public: + CSystemTrayManager(); + virtual ~CSystemTrayManager(); + CSystemGui *mProgramHandle; + int NewSMSMessagesPendingCount(int count); + + +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/main.cpp b/Sources/main.cpp new file mode 100644 index 0000000..9b4f908 --- /dev/null +++ b/Sources/main.cpp @@ -0,0 +1,15 @@ +//#include "GuiMain.h" +#include "SystemGui.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + CSystemGui Program; + Program.Start(); +// CGuiMain w; +// w.show(); + + return a.exec(); +} diff --git a/SystemGui.pro b/SystemGui.pro new file mode 100644 index 0000000..79b7e52 --- /dev/null +++ b/SystemGui.pro @@ -0,0 +1,67 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-03-20T13:09:51 +# +#------------------------------------------------- + +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = SystemGui +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +INCLUDEPATH += Sources\ + Sources/SMSClient\ + Sources/Sprinkler\ + +SOURCES += \ + Sources/GuiMain.cpp \ + Sources/main.cpp \ + Sources/NetworkProtocol.cpp \ + Sources/ProgramSettings.cpp \ + Sources/SystemGui.cpp \ + Sources/SMSClient/SMSConversation.cpp \ + Sources/SMSClient/SMSDatabase.cpp \ + Sources/SMSClient/SMSGui.cpp \ + Sources/SMSClient/SMSMessage.cpp \ + Sources/SMSClient/SMSClient.cpp \ + Sources/SMSClient/SMSMasterCtrlInterface.cpp \ + Sources/MasterCtrlInterface.cpp \ + Sources/SMSClient/Contact.cpp \ + Sources/SMSClient/ContactRepository.cpp \ + Sources/SystemTrayManager.cpp \ + Sources/Sprinkler/SprinklerGui.cpp + +HEADERS += Sources/AbstractNetworkInterface.h \ + Sources/GuiMain.h \ + Sources/NetworkProtocol.h \ + Sources/ProgramSettings.h \ + Sources/ProtocolDefs.h \ + Sources/SystemGui.h \ + Sources/SMSClient/SMSConversation.h \ + Sources/SMSClient/SMSDatabase.h \ + Sources/SMSClient/SMSGui.h \ + Sources/SMSClient/SMSMessage.h \ + Sources/SMSClient/SMSClient.h \ + Sources/SMSClient/SMSMasterCtrlInterface.h \ + Sources/MasterCtrlInterface.h \ + Sources/SMSClient/Contact.h \ + Sources/SMSClient/ContactRepository.h \ + Sources/SystemTrayManager.h \ + Sources/Sprinkler/SprinklerGui.h + +FORMS += \ + SMSGui.ui \ + Sources/Sprinkler/SprinklerGui.ui diff --git a/ui_SMSGui.h b/ui_SMSGui.h new file mode 100644 index 0000000..7426bc7 --- /dev/null +++ b/ui_SMSGui.h @@ -0,0 +1,120 @@ +/******************************************************************************** +** Form generated from reading UI file 'SMSGui.ui' +** +** Created by: Qt User Interface Compiler version 5.5.0 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_SMSGUI_H +#define UI_SMSGUI_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Ui_CSMSGui +{ +public: + QTextBrowser *mConversationText; + QFrame *mSMSEditFrame; + QGridLayout *gridLayout; + QPushButton *mSMSSendBtn; + QTextEdit *mSMSEdit; + QSpacerItem *horizontalSpacer; + QLabel *mSMSMessageStatsLabel; + QTreeWidget *mContactsTreeWidget; + QLabel *mContactPic; + QLabel *mContactName; + + void setupUi(QWidget *CSMSGui) + { + if (CSMSGui->objectName().isEmpty()) + CSMSGui->setObjectName(QStringLiteral("CSMSGui")); + CSMSGui->resize(803, 785); + QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + sizePolicy.setHeightForWidth(CSMSGui->sizePolicy().hasHeightForWidth()); + CSMSGui->setSizePolicy(sizePolicy); + mConversationText = new QTextBrowser(CSMSGui); + mConversationText->setObjectName(QStringLiteral("mConversationText")); + mConversationText->setGeometry(QRect(0, 160, 481, 451)); + mSMSEditFrame = new QFrame(CSMSGui); + mSMSEditFrame->setObjectName(QStringLiteral("mSMSEditFrame")); + mSMSEditFrame->setGeometry(QRect(0, 620, 521, 121)); + mSMSEditFrame->setFrameShape(QFrame::StyledPanel); + mSMSEditFrame->setFrameShadow(QFrame::Raised); + gridLayout = new QGridLayout(mSMSEditFrame); + gridLayout->setObjectName(QStringLiteral("gridLayout")); + mSMSSendBtn = new QPushButton(mSMSEditFrame); + mSMSSendBtn->setObjectName(QStringLiteral("mSMSSendBtn")); + + gridLayout->addWidget(mSMSSendBtn, 3, 2, 1, 1); + + mSMSEdit = new QTextEdit(mSMSEditFrame); + mSMSEdit->setObjectName(QStringLiteral("mSMSEdit")); + + gridLayout->addWidget(mSMSEdit, 2, 0, 2, 1); + + horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + + gridLayout->addItem(horizontalSpacer, 3, 3, 1, 1); + + mSMSMessageStatsLabel = new QLabel(mSMSEditFrame); + mSMSMessageStatsLabel->setObjectName(QStringLiteral("mSMSMessageStatsLabel")); + mSMSMessageStatsLabel->setMinimumSize(QSize(200, 75)); + + gridLayout->addWidget(mSMSMessageStatsLabel, 2, 2, 1, 2); + + mContactsTreeWidget = new QTreeWidget(CSMSGui); + QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem(); + __qtreewidgetitem->setText(0, QStringLiteral("1")); + mContactsTreeWidget->setHeaderItem(__qtreewidgetitem); + mContactsTreeWidget->setObjectName(QStringLiteral("mContactsTreeWidget")); + mContactsTreeWidget->setGeometry(QRect(520, 160, 256, 471)); + mContactsTreeWidget->setIndentation(2); + mContactsTreeWidget->header()->setVisible(false); + mContactPic = new QLabel(CSMSGui); + mContactPic->setObjectName(QStringLiteral("mContactPic")); + mContactPic->setGeometry(QRect(10, 10, 141, 121)); + mContactName = new QLabel(CSMSGui); + mContactName->setObjectName(QStringLiteral("mContactName")); + mContactName->setGeometry(QRect(180, 20, 591, 101)); + + retranslateUi(CSMSGui); + + QMetaObject::connectSlotsByName(CSMSGui); + } // setupUi + + void retranslateUi(QWidget *CSMSGui) + { + CSMSGui->setWindowTitle(QApplication::translate("CSMSGui", "Form", 0)); + mSMSSendBtn->setText(QApplication::translate("CSMSGui", "Send", 0)); + mSMSMessageStatsLabel->setText(QApplication::translate("CSMSGui", "TextLabel", 0)); + mContactPic->setText(QApplication::translate("CSMSGui", "TextLabel", 0)); + mContactName->setText(QApplication::translate("CSMSGui", "TextLabel", 0)); + } // retranslateUi + +}; + +namespace Ui { + class CSMSGui: public Ui_CSMSGui {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_SMSGUI_H diff --git a/ui_SprinklerGui.h b/ui_SprinklerGui.h new file mode 100644 index 0000000..d79a24c --- /dev/null +++ b/ui_SprinklerGui.h @@ -0,0 +1,55 @@ +/******************************************************************************** +** Form generated from reading UI file 'SprinklerGui.ui' +** +** Created by: Qt User Interface Compiler version 5.5.0 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_SPRINKLERGUI_H +#define UI_SPRINKLERGUI_H + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Ui_CSprinklerGui +{ +public: + QLabel *label; + + void setupUi(QWidget *CSprinklerGui) + { + if (CSprinklerGui->objectName().isEmpty()) + CSprinklerGui->setObjectName(QStringLiteral("CSprinklerGui")); + CSprinklerGui->resize(1047, 560); + label = new QLabel(CSprinklerGui); + label->setObjectName(QStringLiteral("label")); + label->setGeometry(QRect(0, -10, 201, 51)); + + retranslateUi(CSprinklerGui); + + QMetaObject::connectSlotsByName(CSprinklerGui); + } // setupUi + + void retranslateUi(QWidget *CSprinklerGui) + { + CSprinklerGui->setWindowTitle(QApplication::translate("CSprinklerGui", "Form", 0)); + label->setText(QApplication::translate("CSprinklerGui", "Sprinklers", 0)); + } // retranslateUi + +}; + +namespace Ui { + class CSprinklerGui: public Ui_CSprinklerGui {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_SPRINKLERGUI_H