Dev..
This commit is contained in:
parent
a34cb0c7f4
commit
6b7ff8e86a
BIN
Configuration/Settings.mcs
Normal file
BIN
Configuration/Settings.mcs
Normal file
Binary file not shown.
@ -15,7 +15,9 @@ HEADERS += \
|
|||||||
Sources/AVReceiverDevice.h \
|
Sources/AVReceiverDevice.h \
|
||||||
Sources/VoipSMS/VoipMsSMSClient.h \
|
Sources/VoipSMS/VoipMsSMSClient.h \
|
||||||
Sources/VoipSMS/CSMSMessage.h \
|
Sources/VoipSMS/CSMSMessage.h \
|
||||||
Sources/Gui/SystemTrayManager.h
|
Sources/Gui/SystemTrayManager.h \
|
||||||
|
Sources/Gui/SettingsWindow.h \
|
||||||
|
Sources/ProgramSettings.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
Sources/main.cpp \
|
Sources/main.cpp \
|
||||||
@ -28,7 +30,9 @@ SOURCES += \
|
|||||||
Sources/AVReceiverDevice.cpp \
|
Sources/AVReceiverDevice.cpp \
|
||||||
Sources/VoipSMS/VoipMsSMSClient.cpp \
|
Sources/VoipSMS/VoipMsSMSClient.cpp \
|
||||||
Sources/VoipSMS/CSMSMessage.cpp \
|
Sources/VoipSMS/CSMSMessage.cpp \
|
||||||
Sources/Gui/SystemTrayManager.cpp
|
Sources/Gui/SystemTrayManager.cpp \
|
||||||
|
Sources/Gui/SettingsWindow.cpp \
|
||||||
|
Sources/ProgramSettings.cpp
|
||||||
|
|
||||||
|
|
||||||
#win32:SOURCES += $$PWD/Source/qextserialport/win_qextserialport.cpp \
|
#win32:SOURCES += $$PWD/Source/qextserialport/win_qextserialport.cpp \
|
||||||
|
|||||||
147
Sources/Gui/SettingsWindow.cpp
Normal file
147
Sources/Gui/SettingsWindow.cpp
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
#include "SettingsWindow.h"
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include "MasterCtrl.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mProgramHandle->FetchDIDsRequest(mVoipMSUsername->text(),mVoipMSPassword->text());
|
||||||
|
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();
|
||||||
|
}
|
||||||
44
Sources/Gui/SettingsWindow.h
Normal file
44
Sources/Gui/SettingsWindow.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef CSETTINGSWINDOW_H
|
||||||
|
#define CSETTINGSWINDOW_H
|
||||||
|
|
||||||
|
#include "GlobalDefine.h"
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QTabBar>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QCalendarWidget>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include "ProgramSettings.h"
|
||||||
|
|
||||||
|
class CMasterCtrl;
|
||||||
|
|
||||||
|
|
||||||
|
class CSettingsWindow : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CSettingsWindow();
|
||||||
|
virtual ~CSettingsWindow();
|
||||||
|
|
||||||
|
CMasterCtrl *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
|
||||||
@ -13,8 +13,8 @@ CSystemTrayManager::CSystemTrayManager()
|
|||||||
connect(&mSystemTrayIcon,SIGNAL(messageClicked()),this,SLOT(TrayBaloonMessageClicked()));
|
connect(&mSystemTrayIcon,SIGNAL(messageClicked()),this,SLOT(TrayBaloonMessageClicked()));
|
||||||
connect(mTrayMenu,SIGNAL(triggered(QAction*)),this,SLOT(TrayMenuClicked(QAction*)));
|
connect(mTrayMenu,SIGNAL(triggered(QAction*)),this,SLOT(TrayMenuClicked(QAction*)));
|
||||||
|
|
||||||
mQuitAction = mTrayMenu->addAction("Quit MasterController");
|
|
||||||
mShowSettingsGUIAction = mTrayMenu->addAction("Settings");
|
mShowSettingsGUIAction = mTrayMenu->addAction("Settings");
|
||||||
|
mQuitAction = mTrayMenu->addAction("Quit MasterController");
|
||||||
mSystemTrayIcon.setIcon(QIcon("./Ico/icon.png"));
|
mSystemTrayIcon.setIcon(QIcon("./Ico/icon.png"));
|
||||||
mSystemTrayIcon.setToolTip("MasterController :)");
|
mSystemTrayIcon.setToolTip("MasterController :)");
|
||||||
mSystemTrayIcon.show();
|
mSystemTrayIcon.show();
|
||||||
@ -72,6 +72,7 @@ void CSystemTrayManager::TrayMenuClicked(QAction *Menu)
|
|||||||
else if(Menu == mShowSettingsGUIAction)
|
else if(Menu == mShowSettingsGUIAction)
|
||||||
{
|
{
|
||||||
qDebug("Settings");
|
qDebug("Settings");
|
||||||
|
mProgramHandle->ShowSettingsWindowRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,8 +9,9 @@ CMasterCtrl::CMasterCtrl()
|
|||||||
mVoipMsSMSClient = new CVoipMsSMSClient;
|
mVoipMsSMSClient = new CVoipMsSMSClient;
|
||||||
mSystemTrayManager = new CSystemTrayManager;
|
mSystemTrayManager = new CSystemTrayManager;
|
||||||
mSystemTrayManager->mProgramHandle = this;
|
mSystemTrayManager->mProgramHandle = this;
|
||||||
|
mSettingsWindow = new CSettingsWindow();
|
||||||
|
mSettingsWindow->mProgramHandle = this;
|
||||||
|
// mMasterCtrlSettings = new CSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMasterCtrl::~CMasterCtrl()
|
CMasterCtrl::~CMasterCtrl()
|
||||||
@ -21,14 +22,22 @@ CMasterCtrl::~CMasterCtrl()
|
|||||||
delete mAVReceiverDevice;
|
delete mAVReceiverDevice;
|
||||||
delete mVoipMsSMSClient;
|
delete mVoipMsSMSClient;
|
||||||
delete mSystemTrayManager;
|
delete mSystemTrayManager;
|
||||||
|
delete mSettingsWindow;
|
||||||
|
// delete mMasterCtrlSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMasterCtrl::Start()
|
void CMasterCtrl::Start()
|
||||||
{
|
{
|
||||||
qDebug("Started!");
|
qDebug("Started!");
|
||||||
|
|
||||||
|
|
||||||
|
connect(mVoipMsSMSClient,SIGNAL(DIDSFetched(QStringList)),mSettingsWindow,SLOT(DIDsListFetched(QStringList)));
|
||||||
|
|
||||||
mAVReceiverDevice->ConnectToReceiver();
|
mAVReceiverDevice->ConnectToReceiver();
|
||||||
mVoipMsSMSClient->DownloadSMSFromServer();
|
|
||||||
|
mSettingsManager.LoadSettings(&mMasterCtrlSettings);
|
||||||
|
mSettingsWindow->SetSettingsData(&mMasterCtrlSettings);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CMasterCtrl::QuitApplicationRequest()
|
unsigned int CMasterCtrl::QuitApplicationRequest()
|
||||||
@ -36,3 +45,32 @@ unsigned int CMasterCtrl::QuitApplicationRequest()
|
|||||||
QApplication::exit(69);
|
QApplication::exit(69);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int CMasterCtrl::ShowSettingsWindowRequest()
|
||||||
|
{
|
||||||
|
mSettingsWindow->show();
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CMasterCtrl::FetchDIDsRequest(QString Username, QString Password)
|
||||||
|
{
|
||||||
|
mVoipMsSMSClient->GetDidFromUserAccount(Username,Password);
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CMasterCtrl::SaveSettings(CSettings *Settings)
|
||||||
|
{
|
||||||
|
CSettings toto;
|
||||||
|
toto = *Settings;
|
||||||
|
mMasterCtrlSettings = toto;
|
||||||
|
mSettingsManager.SaveSettings(&mMasterCtrlSettings);
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CMasterCtrl::SettingsWindowClosed()
|
||||||
|
{
|
||||||
|
mVoipMsSMSClient->SetVOIPMsSettings(&mMasterCtrlSettings.mVoipMSSettings);
|
||||||
|
mVoipMsSMSClient->DownloadSMSFromServer();
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|||||||
@ -6,9 +6,12 @@
|
|||||||
#include "AVReceiverDevice.h"
|
#include "AVReceiverDevice.h"
|
||||||
#include "VoipMsSMSClient.h"
|
#include "VoipMsSMSClient.h"
|
||||||
#include "SystemTrayManager.h"
|
#include "SystemTrayManager.h"
|
||||||
|
#include "SettingsWindow.h"
|
||||||
|
#include "ProgramSettings.h"
|
||||||
|
|
||||||
class CMasterCtrl
|
class CMasterCtrl : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CMasterCtrl();
|
CMasterCtrl();
|
||||||
~CMasterCtrl();
|
~CMasterCtrl();
|
||||||
@ -18,10 +21,23 @@ public:
|
|||||||
CAVReceiverDevice *mAVReceiverDevice;
|
CAVReceiverDevice *mAVReceiverDevice;
|
||||||
CVoipMsSMSClient *mVoipMsSMSClient;
|
CVoipMsSMSClient *mVoipMsSMSClient;
|
||||||
CSystemTrayManager *mSystemTrayManager;
|
CSystemTrayManager *mSystemTrayManager;
|
||||||
|
CSettingsWindow *mSettingsWindow;
|
||||||
|
CProgramSettings mSettingsManager;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int QuitApplicationRequest();
|
unsigned int QuitApplicationRequest();
|
||||||
|
unsigned int ShowSettingsWindowRequest();
|
||||||
|
unsigned int FetchDIDsRequest(QString Username, QString Password);
|
||||||
|
unsigned int SaveSettings(CSettings *Settings);
|
||||||
|
|
||||||
|
unsigned int SettingsWindowClosed();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
CSettings mMasterCtrlSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MASTERCTRL_H
|
#endif // MASTERCTRL_H
|
||||||
|
|||||||
146
Sources/ProgramSettings.cpp
Normal file
146
Sources/ProgramSettings.cpp
Normal file
@ -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;
|
||||||
|
}
|
||||||
54
Sources/ProgramSettings.h
Normal file
54
Sources/ProgramSettings.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#ifndef CPROGRAMSETTINGS_H
|
||||||
|
#define CPROGRAMSETTINGS_H
|
||||||
|
|
||||||
|
#include "GlobalDefine.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDate>
|
||||||
|
#include <QDataStream>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
@ -17,7 +17,7 @@ class CSMSMessage
|
|||||||
public:
|
public:
|
||||||
CSMSMessage();
|
CSMSMessage();
|
||||||
|
|
||||||
qint64 mVOIPMSDatabaseID;
|
/*qint64*/QString mVOIPMSDatabaseID;
|
||||||
QDateTime mDateTime;
|
QDateTime mDateTime;
|
||||||
SmsType_t mType;
|
SmsType_t mType;
|
||||||
QString mDID, mContact, mMessageText;
|
QString mDID, mContact, mMessageText;
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
CVoipMsSMSClient::CVoipMsSMSClient()
|
CVoipMsSMSClient::CVoipMsSMSClient()
|
||||||
@ -18,42 +17,132 @@ CVoipMsSMSClient::~CVoipMsSMSClient()
|
|||||||
mSMSMessagesList.clear();
|
mSMSMessagesList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int CVoipMsSMSClient::SetVOIPMsSettings(CVoipMSSMSSettings *SettingsData)
|
||||||
|
{
|
||||||
|
mVOIPMsSettings = SettingsData;
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
int CVoipMsSMSClient::DownloadSMSFromServer()
|
int CVoipMsSMSClient::DownloadSMSFromServer()
|
||||||
{
|
{
|
||||||
|
|
||||||
QString Username = "jean-francois.martel@polymtl.ca";
|
QDate EndDate;
|
||||||
QString Password = "Pentium2";
|
mCurStartDate = mVOIPMsSettings.mStartDate;
|
||||||
QString Method = "getSMS";
|
if(mCurStartDate.daysTo(QDate::currentDate()) > VOIP_MS_SMS_DATESPAN)
|
||||||
|
{
|
||||||
|
EndDate = mCurStartDate.addDays(VOIP_MS_SMS_DATESPAN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EndDate = mCurStartDate.addDays(mCurStartDate.daysTo(QDate::currentDate()));
|
||||||
|
}
|
||||||
|
|
||||||
|
SendSMSDownloadRequest(mCurStartDate,EndDate);
|
||||||
|
|
||||||
|
// QString Url;
|
||||||
|
// Url.clear();
|
||||||
|
// QTextStream UrlStream(&Url);
|
||||||
|
|
||||||
|
// // Url = "https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getSMS&from=2015-11-01&to=2015-11-11&did=5143606463&limit=50";
|
||||||
|
|
||||||
|
// UrlStream << VOIP_MS_API_URL
|
||||||
|
// << "api_username=" << mVOIPMsSettings.mUsername << "&"
|
||||||
|
// << "api_password=" << mVOIPMsSettings.mPassword << "&"
|
||||||
|
// << "method=" << "getSMS" << "&"
|
||||||
|
// << "from=" << mCurStartDate.toString("yyyy-MM-dd") << "&"
|
||||||
|
// << "to=" << EndDate.toString("yyyy-MM-dd") << "&"
|
||||||
|
// << "did=" << mVOIPMsSettings.mDefaultDID << "&"
|
||||||
|
// << "limit=" << "50";
|
||||||
|
|
||||||
|
// qDebug() << "Cmd: " << Url;
|
||||||
|
// mVOIPMSSocket->get(QNetworkRequest(Url));
|
||||||
|
// mCurStartDate = EndDate;
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CVoipMsSMSClient::SendSMSDownloadRequest(QDate StartDate, QDate EndDate)
|
||||||
|
{
|
||||||
|
QString Url;
|
||||||
|
Url.clear();
|
||||||
|
QTextStream UrlStream(&Url);
|
||||||
|
|
||||||
|
qDebug() << "Sending request for dates from: " << StartDate.toString("yyyy-MM-dd") << " to: " << EndDate.toString("yyyy-MM-dd");
|
||||||
|
|
||||||
|
// Url = "https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getSMS&from=2015-11-01&to=2015-11-11&did=5143606463&limit=50";
|
||||||
|
|
||||||
|
UrlStream << VOIP_MS_API_URL
|
||||||
|
<< "api_username=" << mVOIPMsSettings.mUsername << "&"
|
||||||
|
<< "api_password=" << mVOIPMsSettings.mPassword << "&"
|
||||||
|
<< "method=" << "getSMS" << "&"
|
||||||
|
<< "from=" << StartDate.toString("yyyy-MM-dd") << "&"
|
||||||
|
<< "to=" << EndDate.toString("yyyy-MM-dd") << "&"
|
||||||
|
<< "did=" << mVOIPMsSettings.mDefaultDID << "&"
|
||||||
|
<< "limit=" << "50";
|
||||||
|
|
||||||
|
qDebug() << "Cmd: " << Url;
|
||||||
|
mVOIPMSSocket->get(QNetworkRequest(Url));
|
||||||
|
mCurStartDate = EndDate;
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CVoipMsSMSClient::GetDidFromUserAccount(const QString username, const QString Password)
|
||||||
|
{
|
||||||
|
QString Method = "getDIDsInfo";
|
||||||
QString Url;
|
QString Url;
|
||||||
Url.clear();
|
Url.clear();
|
||||||
QTextStream UrlStream(&Url);
|
QTextStream UrlStream(&Url);
|
||||||
|
|
||||||
UrlStream << VOIP_MS_API_URL
|
UrlStream << VOIP_MS_API_URL
|
||||||
<< "api_username=" << Username << "&"
|
<< "api_username=" << username << "&"
|
||||||
<< "api_password=" << Password << "&"
|
<< "api_password=" << Password << "&"
|
||||||
<< "method=" << Method << "&"
|
<< "method=" << Method << "&";
|
||||||
<< "from=" << "2015-10-01" << "&"
|
|
||||||
<< "to=" << "2015-11-30" << "&"
|
|
||||||
<< "did=" << "5143606463" << "&"
|
|
||||||
<< "limit=" << "50";
|
|
||||||
|
|
||||||
mVOIPMSSocket->get(QNetworkRequest(Url));
|
mVOIPMSSocket->get(QNetworkRequest(Url));
|
||||||
|
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CVoipMsSMSClient::VoipServerReplyFinished(QNetworkReply *NetworkReply)
|
void CVoipMsSMSClient::VoipServerReplyFinished(QNetworkReply *NetworkReply)
|
||||||
{
|
{
|
||||||
QByteArray Reply = NetworkReply->readAll();
|
QByteArray Reply = NetworkReply->readAll();
|
||||||
|
|
||||||
QJsonDocument JsonReply = QJsonDocument::fromJson(Reply);
|
QJsonDocument JsonReply = QJsonDocument::fromJson(Reply);
|
||||||
QJsonObject JsonObject = JsonReply.object();
|
QJsonObject JsonObject = JsonReply.object();
|
||||||
|
QStringList Keys = JsonObject.keys();
|
||||||
if(JsonObject["status"].toString() == "success")
|
if(JsonObject["status"].toString() == "success")
|
||||||
{
|
{
|
||||||
QJsonArray SMSArray = JsonObject["sms"].toArray();
|
if(Keys.contains("sms"))
|
||||||
|
{
|
||||||
|
QJsonArray SMSArray = JsonObject["sms"].toArray();
|
||||||
|
SMSReceived(&SMSArray);
|
||||||
|
}
|
||||||
|
else if(Keys.contains("dids"))
|
||||||
|
{
|
||||||
|
QJsonArray DIDsInfoArray = JsonObject["dids"].toArray();
|
||||||
|
DIDsInfoReceived(&DIDsInfoArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(JsonObject["status"].toString() == "no_sms")
|
||||||
|
{
|
||||||
|
SMSReceived(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << "Failed VOIP.MS reply: " << JsonObject["status"].toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (const QJsonValue & value, SMSArray)
|
unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray)
|
||||||
|
{
|
||||||
|
if(SMSArray != 0)
|
||||||
|
{
|
||||||
|
foreach (const QJsonValue & value, *SMSArray)
|
||||||
{
|
{
|
||||||
CSMSMessage NewMessage;
|
CSMSMessage NewMessage;
|
||||||
QJsonObject obj = value.toObject();
|
QJsonObject obj = value.toObject();
|
||||||
@ -62,28 +151,57 @@ void CVoipMsSMSClient::VoipServerReplyFinished(QNetworkReply *NetworkReply)
|
|||||||
NewMessage.mDID = obj["did"].toString();
|
NewMessage.mDID = obj["did"].toString();
|
||||||
NewMessage.mMessageText = obj["message"].toString();
|
NewMessage.mMessageText = obj["message"].toString();
|
||||||
NewMessage.mType = (SmsType_t)obj["type"].toString().toInt();
|
NewMessage.mType = (SmsType_t)obj["type"].toString().toInt();
|
||||||
NewMessage.mVOIPMSDatabaseID = (qint64)obj["type"].toString().toLongLong();
|
NewMessage.mVOIPMSDatabaseID = obj["id"].toString();//.toLongLong();
|
||||||
mSMSMessagesList.append(NewMessage);
|
mSMSMessagesList.append(NewMessage);
|
||||||
qDebug() << obj["contact"].toString().toUtf8() << " : " << obj["message"].toString().toUtf8();
|
qDebug() << obj["contact"].toString().toUtf8() << " : " << obj["message"].toString().toUtf8();
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug("Added %d messages in the list",mSMSMessagesList.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mCurStartDate != QDate::currentDate())
|
||||||
|
{
|
||||||
|
if(mSMSMessagesList.size() != 0)
|
||||||
|
{
|
||||||
|
mCurStartDate = QDate::fromString(mSMSMessagesList.last().mDateTime.toString("yyyy-MM-dd"));
|
||||||
|
}
|
||||||
|
|
||||||
// qDebug() << "Reply from server: " << Reply;
|
QDate EndDate;
|
||||||
|
if(mCurStartDate.daysTo(QDate::currentDate()) > VOIP_MS_SMS_DATESPAN)
|
||||||
|
{
|
||||||
// [id] => 111120
|
EndDate = mCurStartDate.addDays(VOIP_MS_SMS_DATESPAN);
|
||||||
// [date] => 2014-03-30 10:24:16
|
}
|
||||||
// [type] => 0
|
else
|
||||||
// [did] => 8574884828
|
{
|
||||||
// [contact] => 8577884821
|
EndDate = mCurStartDate.addDays(mCurStartDate.daysTo(QDate::currentDate()));
|
||||||
// [message] => hello+john
|
}
|
||||||
|
|
||||||
|
SendSMSDownloadRequest(mCurStartDate,EndDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug("Added %d messages in the list",mSMSMessagesList.size());
|
||||||
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int CVoipMsSMSClient::DIDsInfoReceived(QJsonArray *DIDsInfoPtr)
|
||||||
|
{
|
||||||
|
QStringList DIDs;
|
||||||
|
QJsonArray DIDsInfo = *DIDsInfoPtr;
|
||||||
|
|
||||||
|
foreach (const QJsonValue & value, DIDsInfo)
|
||||||
|
{
|
||||||
|
QJsonObject DIDInfo = value.toObject();
|
||||||
|
QString CurDID = DIDInfo["did"].toString();
|
||||||
|
int SMSEnabled = DIDInfo["sms_enabled"].toString().toInt();
|
||||||
|
if(SMSEnabled == 1)
|
||||||
|
{
|
||||||
|
DIDs.append(CurDID);
|
||||||
|
}
|
||||||
|
qDebug("DID: %s - SMSEnabled %d",CurDID.toUtf8().data(),SMSEnabled);
|
||||||
|
|
||||||
|
emit DIDSFetched(DIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getBalance&advanced=True
|
//https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getBalance&advanced=True
|
||||||
|
|
||||||
|
|||||||
@ -7,10 +7,21 @@
|
|||||||
#include "GlobalDefine.h"
|
#include "GlobalDefine.h"
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include "CSMSMessage.h"
|
#include "CSMSMessage.h"
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include "ProgramSettings.h"
|
||||||
|
|
||||||
#define VOIP_MS_API_URL "https://www.voip.ms/api/v1/rest.php?"
|
#define VOIP_MS_API_URL "https://www.voip.ms/api/v1/rest.php?"
|
||||||
|
#define VOIP_MS_SMS_DATESPAN 90
|
||||||
|
|
||||||
class CVoipMsSMSClient : QObject
|
enum VoipMSRetValues
|
||||||
|
{
|
||||||
|
VOIPMS_RET_SUCCESS,
|
||||||
|
VOIPMS_RET_FAILED,
|
||||||
|
VOIPMS_RET_NO_DID_FOUND
|
||||||
|
};
|
||||||
|
|
||||||
|
class CVoipMsSMSClient : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@ -18,14 +29,26 @@ public:
|
|||||||
virtual ~CVoipMsSMSClient();
|
virtual ~CVoipMsSMSClient();
|
||||||
|
|
||||||
int DownloadSMSFromServer();
|
int DownloadSMSFromServer();
|
||||||
|
int SendSMSDownloadRequest(QDate StartDate, QDate EndDate);
|
||||||
|
|
||||||
QList<CSMSMessage> mSMSMessagesList;
|
QList<CSMSMessage> mSMSMessagesList;
|
||||||
|
|
||||||
|
unsigned int GetDidFromUserAccount(const QString username, const QString Password);
|
||||||
|
unsigned int SetVOIPMsSettings(CVoipMSSMSSettings *SettingsData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *mVOIPMSSocket;
|
QNetworkAccessManager *mVOIPMSSocket;
|
||||||
|
|
||||||
|
unsigned int SMSReceived(QJsonArray *sms);
|
||||||
|
unsigned int DIDsInfoReceived(QJsonArray *DIDsInfo);
|
||||||
|
|
||||||
|
CVoipMSSMSSettings mVOIPMsSettings;
|
||||||
|
|
||||||
|
QDate mCurStartDate;
|
||||||
|
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void DIDSFetched(QStringList);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void VoipServerReplyFinished(QNetworkReply*);
|
void VoipServerReplyFinished(QNetworkReply*);
|
||||||
|
|||||||
@ -38,6 +38,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
QFont serifFont("Times", 10, QFont::Bold);
|
QFont serifFont("Times", 10, QFont::Bold);
|
||||||
QApplication::setFont(serifFont);
|
QApplication::setFont(serifFont);
|
||||||
|
QApplication::setQuitOnLastWindowClosed(false);
|
||||||
|
|
||||||
|
|
||||||
//Create program instance
|
//Create program instance
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user