diff --git a/Configuration/Contacts.mcc b/Configuration/Contacts.mcc new file mode 100644 index 0000000..123db1f Binary files /dev/null and b/Configuration/Contacts.mcc 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/MasterCtrl.pro b/MasterCtrl.pro index 530a399..847c5c6 100644 --- a/MasterCtrl.pro +++ b/MasterCtrl.pro @@ -21,7 +21,10 @@ HEADERS += \ Sources/SMSDevice.h \ Sources/NetworkDevice.h \ Sources/AbstractNetworkInterface.h \ - Sources/VoipSMS/SMSMessage.h + Sources/VoipSMS/SMSMessage.h \ + Sources/Gui/CContactsWindow.h \ + Sources/Contact.h \ + Sources/ContactRepository.h SOURCES += \ Sources/main.cpp \ @@ -41,7 +44,10 @@ SOURCES += \ Sources/NetworkDevicesMgr.cpp \ Sources/SMSDevice.cpp \ Sources/NetworkDevice.cpp \ - Sources/VoipSMS/SMSMessage.cpp + Sources/VoipSMS/SMSMessage.cpp \ + Sources/Gui/CContactsWindow.cpp \ + Sources/Contact.cpp \ + Sources/ContactRepository.cpp #win32:SOURCES += $$PWD/Source/qextserialport/win_qextserialport.cpp \ diff --git a/Sources/Contact.cpp b/Sources/Contact.cpp new file mode 100644 index 0000000..a006132 --- /dev/null +++ b/Sources/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/Contact.h b/Sources/Contact.h new file mode 100644 index 0000000..21b4be3 --- /dev/null +++ b/Sources/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/ContactRepository.cpp b/Sources/ContactRepository.cpp new file mode 100644 index 0000000..6fd8c37 --- /dev/null +++ b/Sources/ContactRepository.cpp @@ -0,0 +1,161 @@ +#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::ChangeContact(int index, CContact Contact) +{ + if(index < 0 || index >= mContactsList.size()) + { + return RET_ERROR; + } + + mContactsList[index] = Contact; + SaveContacts(); + return RET_OK; +} + + +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/ContactRepository.h b/Sources/ContactRepository.h new file mode 100644 index 0000000..fe4be84 --- /dev/null +++ b/Sources/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 AddContact(CContact Contact); + int ChangeContact(int index, CContact Contact); + QList *GetContacts(){return &mContactsList;} + int GetContact(int index, CContact &Contact); + CContact *GetContactPtr(int index); + int DeleteContact(int index); + int GetContactCount(){return mContactsList.size();} + +private: + QList mContactsList; +}; + +#endif // CCONTACTREPOSITORY_H diff --git a/Sources/Gui/CContactsWindow.cpp b/Sources/Gui/CContactsWindow.cpp new file mode 100644 index 0000000..53bc937 --- /dev/null +++ b/Sources/Gui/CContactsWindow.cpp @@ -0,0 +1,7 @@ +#include "CContactsWindow.h" + +CContactsWindow::CContactsWindow() +{ + +} + diff --git a/Sources/Gui/CContactsWindow.h b/Sources/Gui/CContactsWindow.h new file mode 100644 index 0000000..cadde1f --- /dev/null +++ b/Sources/Gui/CContactsWindow.h @@ -0,0 +1,11 @@ +#ifndef CCONTACTSWINDOW_H +#define CCONTACTSWINDOW_H + + +class CContactsWindow +{ +public: + CContactsWindow(); +}; + +#endif // CCONTACTSWINDOW_H diff --git a/Sources/Gui/SettingsWindow.cpp b/Sources/Gui/SettingsWindow.cpp index 13ec302..c85e564 100644 --- a/Sources/Gui/SettingsWindow.cpp +++ b/Sources/Gui/SettingsWindow.cpp @@ -3,6 +3,8 @@ #include #include #include "MasterCtrl.h" +#include + CSettingsWindow::CSettingsWindow() @@ -15,9 +17,13 @@ CSettingsWindow::CSettingsWindow() mOptionsTabBar = new QTabBar(); mOptionsTabBar->addTab("SMS"); mOptionsTabBar->addTab("Network"); + mOptionsTabBar->addTab("Contacts"); mOptionsTabBar->resize(this->geometry().width(),mOptionsTabBar->height()); MainLayout->addWidget(mOptionsTabBar); + + //////////////////VOIP.MS config page///////////////////// + mSMSPage = new QWidget(mPagesContainer); // mVoipPage->resize(this->size()); @@ -62,6 +68,73 @@ CSettingsWindow::CSettingsWindow() mSMSPage->setLayout(mSMSPageLayout); mSMSPage->show(); + + + //////////////////VOIP.MS config page///////////////////// + + mContactsPage = new QWidget(mPagesContainer); + mContactsPage->resize(400,400); + + mDefaultContactPixmap = new QPixmap(QPixmap("./Ico/contact.png").scaled(75,75)); + + QGridLayout *mContactsPageLayout = new QGridLayout; + + mContactsList = new QTableWidget(0,2); + mContactsList->setSelectionBehavior(QAbstractItemView::SelectRows); + mContactsList->setSelectionMode(QAbstractItemView::SingleSelection); + mContactsList->clearContents(); + mContactsList->setRowCount(0); + mContactsList->setHorizontalHeaderLabels(QStringList() << "Contact" << "Name"); + mContactsPageLayout->addWidget(mContactsList,0,0,1,3); + connect(mContactsList,SIGNAL(cellDoubleClicked(int,int)),SLOT(TableDoubleClicked(int,int))); + //connect(mLogsTable,SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)),this,SLOT(TableCurItemChanged(QTableWidgetItem*,QTableWidgetItem*))); + connect(mContactsList,SIGNAL(itemSelectionChanged()),this,SLOT(TableCellSelected(/*int,int*/))); + + + + Label = new QLabel("Contact Name: "); + mContactsPageLayout->addWidget(Label,1,1,1,1); + mContactNameEdit = new QLineEdit(); + mContactsPageLayout->addWidget(mContactNameEdit,1,2,1,1); + + Label = new QLabel("Contact Raw Number: "); + mContactsPageLayout->addWidget(Label,2,1,1,1); + mContactRawNbrEdit = new QLineEdit(); + // mContactRawNbrEdit->setInputMask("9"); + mContactsPageLayout->addWidget(mContactRawNbrEdit,2,2,1,1); + + Label = new QLabel("Contact Number: "); + mContactsPageLayout->addWidget(Label,3,1,1,1); + mContactNbrEdit = new QLineEdit(); + mContactNbrEdit->setDisabled(true); + mContactsPageLayout->addWidget(mContactNbrEdit,3,2,1,1); + + mContactPixmapLabel = new QLabel(); + mContactPixmapLabel->setPixmap(*mDefaultContactPixmap); + mContactsPageLayout->addWidget(mContactPixmapLabel,1,0,2,1); + + + mSelectContactPicBtn = new QPushButton("Choose"); + mContactsPageLayout->addWidget(mSelectContactPicBtn,3,0,1,1); + connect(mSelectContactPicBtn,SIGNAL(clicked(bool)),this,SLOT(SelectContactPicClicked(bool))); + + + mNewContactBtn = new QPushButton("New"); + mContactsPageLayout->addWidget(mNewContactBtn,4,1,1,1); + connect(mNewContactBtn,SIGNAL(clicked(bool)),this,SLOT(NewContactClicked(bool))); + + mSaveContactBtn = new QPushButton("Save"); + mContactsPageLayout->addWidget(mSaveContactBtn,4,2,1,1); + connect(mSaveContactBtn,SIGNAL(clicked(bool)),this,SLOT(SaveContactClicked(bool))); + + mDeleteContactBtn = new QPushButton("Delete Contact"); + mContactsPageLayout->addWidget(mDeleteContactBtn,4,0,1,1); + connect(mDeleteContactBtn,SIGNAL(clicked(bool)),this,SLOT(DeleteContactClicked(bool))); + + mContactsPage->setLayout(mContactsPageLayout); + mContactsPage->hide(); + + MainLayout->addWidget(mPagesContainer); setLayout(MainLayout); @@ -79,12 +152,20 @@ void CSettingsWindow::TabBarClicked(int TabIndex) if(TabIndex == 0)//SMS { mSMSPage->show(); + mContactsPage->hide(); } else if(TabIndex == 1)//Network { mSMSPage->hide(); + mContactsPage->hide(); + + } + else if(TabIndex == 2)//Contacts + { + mSMSPage->hide(); + mContactsPage->show(); } } @@ -145,3 +226,150 @@ void CSettingsWindow::DoneButtonClicked(bool checked) this->hide(); } + +void CSettingsWindow::SelectContactPicClicked(bool checked) +{ + Q_UNUSED(checked) + + QString fileName = QFileDialog::getOpenFileName(this,tr("Select Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); + if(fileName.isNull()) + { + return; + } + +// int Index =GetCurSelectedItemIndexInTable(); + +// if(Index >= 0) +// { +// mProgramHandle->GetContactRepository()->GetContactPtr(Index)->SetContactImage(fileName); +// } + + // mContactPixmap = mProgramHandle->GetContactRepository()->GetContactPtr(Index)->mContactPicture; + + mContactPixmap = QPixmap(fileName); + mContactPixmapLabel->setPixmap(mContactPixmap.scaled(75,75)); + +} + +void CSettingsWindow::SaveContactClicked(bool checked) +{ + Q_UNUSED(checked) + CContact NewContact(mContactRawNbrEdit->text(),mContactNameEdit->text(),&mContactPixmap); + int index = GetCurSelectedItemIndexInTable(); + + mProgramHandle->GetContactRepository()->ChangeContact(index,NewContact); + + UpdateContacts(); + + // delete NewContact; + +} + +void CSettingsWindow::DeleteContactClicked(bool checked) +{ + Q_UNUSED(checked) + int Index =GetCurSelectedItemIndexInTable(); + + if(Index >= 0) + { + mProgramHandle->GetContactRepository()->DeleteContact(Index); + } + + UpdateContacts(); + mContactsList->setCurrentCell(0,0); +} + +void CSettingsWindow::NewContactClicked(bool checked) +{ + Q_UNUSED(checked) + CContact NewContact("---"); + mProgramHandle->GetContactRepository()->AddContact(NewContact); + + UpdateContacts(); + mContactsList->setCurrentCell(mContactsList->rowCount()-1,0); + +} + +int CSettingsWindow::UpdateContacts() +{ + QList *ContactsList; + ClearTable(); + ContactsList = mProgramHandle->GetContactRepository()->GetContacts(); + + mContactsList->setRowCount(ContactsList->size()); + + for(int i = 0; i < ContactsList->size(); i++) + { + QTableWidgetItem * NewItem = new QTableWidgetItem(ContactsList->at(i).mContactNumber); + NewItem->setData(Qt::UserRole,QVariant(i)); + NewItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + mContactsList->setItem(i,0,NewItem); + + NewItem = new QTableWidgetItem(ContactsList->at(i).mContactName); + NewItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + mContactsList->setItem(i,1,NewItem); + } + + + mContactsList->resizeColumnsToContents(); + + return RET_OK; +} + +void CSettingsWindow::ClearTable() +{ + for(int Col = 0; Col < mContactsList->columnCount(); Col++) + { + for(int Row = 0; Row < mContactsList->rowCount(); Row++) + { + delete mContactsList->item(Row,Col); + //mLogsTable->item(Row,Col) = 0; + } + } + mContactsList->setRowCount(0); + mContactsList->clearContents(); +} + +void CSettingsWindow::TableCellSelected(/*int row, int col*/) +{ + int Selection = GetCurSelectedItemIndexInTable(); + + if(Selection == -1) + return; + + CContact SelectedContact; + mProgramHandle->GetContactRepository()->GetContact(Selection,SelectedContact); + + mContactRawNbrEdit->setText(SelectedContact.mRAWContactNbr); + mContactNameEdit->setText(SelectedContact.mContactName); + mContactNbrEdit->setText(SelectedContact.mContactNumber); + + mContactPixmap = SelectedContact.mContactPicture; + mContactPixmapLabel->setPixmap(mContactPixmap.scaled(75,75)); + +} + +int CSettingsWindow::GetCurSelectedItemIndexInTable() +{ + QList list = mContactsList->selectedItems(); + + if(list.size() == 0) + return - 1; + + int Selection = -1; + for(int i = 0; i < list.size(); i++) + { + if(list.at(i)->column() == 0) + { + Selection = list.at(i)->data(Qt::UserRole).toInt(); + break; + } + } + + return Selection; +} + +void CSettingsWindow::TableDoubleClicked(int row, int col) +{ + +} diff --git a/Sources/Gui/SettingsWindow.h b/Sources/Gui/SettingsWindow.h index 2c09ce9..fe8c630 100644 --- a/Sources/Gui/SettingsWindow.h +++ b/Sources/Gui/SettingsWindow.h @@ -9,6 +9,9 @@ #include #include #include "ProgramSettings.h" +#include "QTableWidget" +#include + class CMasterCtrl; @@ -23,22 +26,49 @@ public: CMasterCtrl *mProgramHandle; QWidget *mSMSPage; + QWidget *mContactsPage; QTabBar *mOptionsTabBar; + + //SMS Page QLineEdit *mVoipMSUsername; QLineEdit *mVoipMSPassword; QCalendarWidget *mVoipMSCalendar; QComboBox *mDIDSelectionDropList; QPushButton *mRetreiveDIDSButton; + //Contacts Page + QTableWidget *mContactsList; + QPixmap *mDefaultContactPixmap; + QPixmap mContactPixmap; + QLineEdit *mContactRawNbrEdit; + QLineEdit *mContactNameEdit; + QLineEdit *mContactNbrEdit; + QLabel *mContactPixmapLabel; + QPushButton *mSelectContactPicBtn; + QPushButton *mNewContactBtn; + QPushButton *mSaveContactBtn; + QPushButton *mDeleteContactBtn; + + QPushButton *mDoneButton; unsigned int SetSettingsData(CSettings *SettingsData); + int UpdateContacts(); + void ClearTable(); + int GetCurSelectedItemIndexInTable(); public slots: void TabBarClicked(int); void RetreiveDIDButtonClicked(bool); void DIDsListFetched(QStringList); void DoneButtonClicked(bool); + + void SelectContactPicClicked(bool checked); + void SaveContactClicked(bool checked); + void NewContactClicked(bool checked); + void DeleteContactClicked(bool checked); + void TableDoubleClicked(int,int); + void TableCellSelected(/*int,int*/); }; #endif // CSETTINGSWINDOW_H diff --git a/Sources/MasterCtrl.cpp b/Sources/MasterCtrl.cpp index f0932c5..d86d137 100644 --- a/Sources/MasterCtrl.cpp +++ b/Sources/MasterCtrl.cpp @@ -18,6 +18,7 @@ CMasterCtrl::CMasterCtrl() mEthernetNetworkServer = new CEthernetNetworkServer; mNetworkDevicesManager = new CNetworkDevicesMgr; + mContactsRepository = new CContactRepository; // mMasterCtrlSettings = new CSettings; } @@ -33,6 +34,7 @@ CMasterCtrl::~CMasterCtrl() delete mSettingsWindow; delete mNetworkDevicesManager; delete mEthernetNetworkServer; + delete mContactsRepository; // delete mMasterCtrlSettings; } @@ -51,7 +53,10 @@ void CMasterCtrl::Start() // FrameBuffer.seek(0); + mContactsRepository->LoadContacts(); + mNetworkDevicesManager->mVoipMSInterfaceHandle = mVoipMsSMSClient; + mNetworkDevicesManager->mContactRepositoryHandle = mContactsRepository; mNetworkDevicesManager->mProgramHandle = this; mEthernetNetworkServer->mDevicesMgrHandle = mNetworkDevicesManager; mEthernetNetworkServer->mProgramHandle = this; @@ -69,6 +74,8 @@ void CMasterCtrl::Start() mNetworkDevicesManager->InitNetworkDevices(); mEthernetNetworkServer->StartServer(2182); + + // mAppWidget.show(); @@ -82,6 +89,7 @@ unsigned int CMasterCtrl::QuitApplicationRequest() unsigned int CMasterCtrl::ShowSettingsWindowRequest() { + mSettingsWindow->UpdateContacts(); mSettingsWindow->show(); return RET_OK; } diff --git a/Sources/MasterCtrl.h b/Sources/MasterCtrl.h index 075807f..780829e 100644 --- a/Sources/MasterCtrl.h +++ b/Sources/MasterCtrl.h @@ -10,6 +10,7 @@ #include "ProgramSettings.h" #include "NetworkDevicesMgr.h" #include "EthernetNetworkServer.h" +#include "ContactRepository.h" //#include "AppIconWidget.h" class CMasterCtrl : public QObject @@ -28,6 +29,7 @@ public: CProgramSettings mSettingsManager; CNetworkDevicesMgr *mNetworkDevicesManager; CEthernetNetworkServer *mEthernetNetworkServer; + CContactRepository *mContactsRepository; // CAppIconWidget mAppWidget; @@ -42,6 +44,8 @@ public: int NewSMSMessagesArrived(QList NewMessages); + CContactRepository *GetContactRepository(){return mContactsRepository;} + //Modules requests... diff --git a/Sources/NetworkDevicesMgr.cpp b/Sources/NetworkDevicesMgr.cpp index 3c56cdc..88b7cba 100644 --- a/Sources/NetworkDevicesMgr.cpp +++ b/Sources/NetworkDevicesMgr.cpp @@ -40,6 +40,7 @@ int CNetworkDevicesMgr::CreateNewSMSDevice(int Address, CAbstractNetworkCommIF * CSMSDevice *SMSDevice = new CSMSDevice(Address,NetworkIF,mVoipMSInterfaceHandle); + SMSDevice->mContactRepositoryHandle = mContactRepositoryHandle; mNetworkDevicesList.append((CNetworkDevice*)SMSDevice); diff --git a/Sources/NetworkDevicesMgr.h b/Sources/NetworkDevicesMgr.h index 3299e2e..8bdb078 100644 --- a/Sources/NetworkDevicesMgr.h +++ b/Sources/NetworkDevicesMgr.h @@ -10,6 +10,7 @@ class CVoipMsSMSClient; class CMasterCtrl; +class CContactRepository; class CNetworkDevicesMgr: public QObject { Q_OBJECT @@ -26,6 +27,7 @@ public: CNetworkDevice *GetDevice(int DeviceID, int Address); CVoipMsSMSClient *mVoipMSInterfaceHandle; + CContactRepository *mContactRepositoryHandle; CMasterCtrl *mProgramHandle; int NewSMSMessagesReceived(QList NewMessages); diff --git a/Sources/ProtocolDefs.h b/Sources/ProtocolDefs.h index 417f186..b67d3b8 100644 --- a/Sources/ProtocolDefs.h +++ b/Sources/ProtocolDefs.h @@ -131,6 +131,9 @@ enum SMS_CLIENT_CMDS SMS_CLIENT_DEVICE_NEW_MSG_NOTIFICATION, //8 SMS_CLIENT_DEVICE_SEND_SMS_REQUEST, SMS_CLIENT_DEVICE_SEND_SMS_ACK, //10 + SMS_CLIENT_DEVICE_GET_CONTACTS_REQUEST, + SMS_CLIENT_DEVICE_GET_CONTACTS_RESPONSE,//12 + SMS_CLIENT_DEVICE_CONTACTS_CHANGED_NOTIFICATION, SMS_CLIENT_DEVICE_MAX_MSG diff --git a/Sources/SMSDevice.cpp b/Sources/SMSDevice.cpp index c62fc96..dec978a 100644 --- a/Sources/SMSDevice.cpp +++ b/Sources/SMSDevice.cpp @@ -1,7 +1,7 @@ #include "SMSDevice.h" #include "ProtocolDefs.h" #include - +#include "Contact.h" CSMSDevice::CSMSDevice(int Address, CAbstractNetworkCommIF *NetworkInterface, CVoipMsSMSClient *VoipMsIFPtr): CNetworkDevice(ID_SMS_CLIENT,Address,NetworkInterface) @@ -113,11 +113,35 @@ int CSMSDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int Mess break; + } + case SMS_CLIENT_DEVICE_GET_CONTACTS_REQUEST: + { + QByteArray FrameData; + QBuffer FrameBuffer(&FrameData); + FrameBuffer.open(QIODevice::ReadWrite); + QDataStream *FrameDataStrm = new QDataStream(&FrameBuffer); + + QList *ContactsList = mContactRepositoryHandle->GetContacts(); + *FrameDataStrm << ContactsList->size(); + for(int i = 0; i < ContactsList->size(); i++) + { + *FrameDataStrm << ContactsList->at(i); + } + + FrameBuffer.seek(0); + mNetworkInterfacePtr->SendNetworkMessage(mDeviceID,mDeviceAddress,SMS_CLIENT_DEVICE_GET_CONTACTS_RESPONSE,FrameData.size(),FrameData); + + FrameBuffer.close(); + delete FrameDataStrm; + + break; + } case SMS_CLIENT_DEVICE_STATUS_REQUEST: case SMS_CLIENT_DEVICE_DID_INFO_RESPONSE: case SMS_CLIENT_DEVICE_NEW_MSG_NOTIFICATION: case SMS_CLIENT_DEVICE_GET_ALL_MSG_RESPONSE: + case SMS_CLIENT_DEVICE_GET_CONTACTS_RESPONSE: default: { qDebug("SMSDevice Rx invalid MSG %d",MessageID); diff --git a/Sources/SMSDevice.h b/Sources/SMSDevice.h index 01de9d8..d7273f4 100644 --- a/Sources/SMSDevice.h +++ b/Sources/SMSDevice.h @@ -4,6 +4,7 @@ #include "GlobalDefine.h" #include "NetworkDevice.h" #include "VoipMsSMSClient.h" +#include "ContactRepository.h" #include @@ -18,6 +19,7 @@ public: virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data); CVoipMsSMSClient *mVoipMsInterfaceHandle; + CContactRepository *mContactRepositoryHandle; QTimer *mStatusRequestTimer; int mStatusRequestsCount; diff --git a/Sources/VoipSMS/VoipMsSMSClient.cpp b/Sources/VoipSMS/VoipMsSMSClient.cpp index dd54b03..a6ed2e6 100644 --- a/Sources/VoipSMS/VoipMsSMSClient.cpp +++ b/Sources/VoipSMS/VoipMsSMSClient.cpp @@ -136,6 +136,7 @@ int CVoipMsSMSClient::DownloadNewSMS() int CVoipMsSMSClient::CheckForNewSMS() { + // qDebug("Check new SMS"); if(mSMSMessagesList.isEmpty() == true) { return RET_ERROR; @@ -310,6 +311,7 @@ unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray) NewMessages.append(mSMSMessagesList); mSMSMessagesList = NewMessages; + StartSMSCheckTimer(); } else @@ -335,6 +337,7 @@ unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray) } } mSMSMessagesList.append(NewMessages); + StartSMSCheckTimer(); if(mFirstDownloadDone == true && NewMessages.size() > 0) { mProgramHandle->NewSMSMessagesArrived(NewMessages); @@ -504,12 +507,14 @@ void CVoipMsSMSClient::StartSMSCheckTimer() { if(mFirstDownloadDone == true) { + //qDebug("Timer started"); mCheckNewSMSTimer->start(VOIP_MS_SMS_CHECK_TIMEOUT); } } void CVoipMsSMSClient::StopSMSCheckTimer() { + //qDebug("Timer Stopped"); mCheckNewSMSTimer->stop(); }