Initial
This commit is contained in:
126
guitar/LicenseDialog.cpp
Normal file
126
guitar/LicenseDialog.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#include <guitar/LicenseDialog.hpp>
|
||||
#include <guitar/License.hpp>
|
||||
#include <guitar/Registration.hpp>
|
||||
#include <guitar/BrowserHelper.hpp>
|
||||
#include <guitar/MessageBox.hpp>
|
||||
#include <guitar/guitar.hpp>
|
||||
|
||||
LicenseDialog::LicenseDialog(void)
|
||||
{
|
||||
mInitHandler.setCallback(this,&LicenseDialog::initHandler);
|
||||
mCreateHandler.setCallback(this,&LicenseDialog::createHandler);
|
||||
mCloseHandler.setCallback(this,&LicenseDialog::closeHandler);
|
||||
mDestroyHandler.setCallback(this,&LicenseDialog::destroyHandler);
|
||||
mCommandHandler.setCallback(this,&LicenseDialog::commandHandler);
|
||||
insertHandler(VectorHandler::InitDialogHandler,&mInitHandler);
|
||||
insertHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
||||
insertHandler(VectorHandler::CloseHandler,&mCloseHandler);
|
||||
insertHandler(VectorHandler::CommandHandler,&mCommandHandler);
|
||||
insertHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
||||
}
|
||||
|
||||
LicenseDialog::LicenseDialog(const LicenseDialog &someLicenseDialog)
|
||||
{ // private implementation
|
||||
*this=someLicenseDialog;
|
||||
}
|
||||
|
||||
LicenseDialog::~LicenseDialog()
|
||||
{
|
||||
removeHandler(VectorHandler::InitDialogHandler,&mInitHandler);
|
||||
removeHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
||||
removeHandler(VectorHandler::CloseHandler,&mCloseHandler);
|
||||
removeHandler(VectorHandler::CommandHandler,&mCommandHandler);
|
||||
removeHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
||||
}
|
||||
|
||||
LicenseDialog &LicenseDialog::operator=(const LicenseDialog &someLicenseDialog)
|
||||
{ // private implementation
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool LicenseDialog::perform(GUIWindow &parentWindow,bool cancelTerminates)
|
||||
{
|
||||
bool returnCode;
|
||||
mCancelTerminates=cancelTerminates;
|
||||
returnCode=::DialogBoxParam(processInstance(),(LPSTR)"LICENSEDIALOG",(HWND)parentWindow,DWindow::DlgProc,(LPARAM)(DWindow*)this);
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType LicenseDialog::initHandler(CallbackData &someCallbackData)
|
||||
{
|
||||
return (CallbackData::ReturnType)false;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType LicenseDialog::createHandler(CallbackData &someCallbackData)
|
||||
{
|
||||
return (CallbackData::ReturnType)FALSE;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType LicenseDialog::closeHandler(CallbackData &someCallbackData)
|
||||
{
|
||||
return (CallbackData::ReturnType)FALSE;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType LicenseDialog::destroyHandler(CallbackData &someCallbackData)
|
||||
{
|
||||
return (CallbackData::ReturnType)FALSE;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType LicenseDialog::commandHandler(CallbackData &someCallbackData)
|
||||
{
|
||||
LRESULT result;
|
||||
switch(someCallbackData.wmCommandID())
|
||||
{
|
||||
case IDOK :
|
||||
if(!validateLicense())
|
||||
{
|
||||
MessageBox::messageBox("Error","The license you entered was invalid, please try again");
|
||||
setText(LICENSE_DIALOG_LICENSE,String());
|
||||
setFocus(LICENSE_DIALOG_LICENSE);
|
||||
}
|
||||
else endDialog(true);
|
||||
break;
|
||||
case IDCANCEL :
|
||||
if(mCancelTerminates)
|
||||
{
|
||||
result=MessageBox::messageBox(*this,"Warning","Cancelling now will terminate the application.",MB_OKCANCEL);
|
||||
if(IDOK==result)endDialog(false);
|
||||
}
|
||||
else endDialog(false);
|
||||
break;
|
||||
case LICENSE_DIALOG_REQUEST_LICENSE :
|
||||
handleLicenseRequest();
|
||||
break;
|
||||
}
|
||||
return (CallbackData::ReturnType)FALSE;
|
||||
}
|
||||
|
||||
bool LicenseDialog::validateLicense(void)const
|
||||
{
|
||||
License license;
|
||||
String strLicense;
|
||||
Block<String> strLicenseLines;
|
||||
|
||||
strLicense=getText(LICENSE_DIALOG_LICENSE);
|
||||
if(strLicense.isNull())return false;
|
||||
makeLicenseLines(strLicense,strLicenseLines);
|
||||
license.fromLines(strLicenseLines);
|
||||
if(!license.isValid()||license.isExpiring())return false;
|
||||
if(!Registration::getInstance().applyLicense(strLicenseLines))return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LicenseDialog::handleLicenseRequest(void)const
|
||||
{
|
||||
BrowserHelper::launchBrowser(String(STRING_HOST));
|
||||
}
|
||||
|
||||
void LicenseDialog::makeLicenseLines(String strLicense,Block<String> &strLicenseLines)const
|
||||
{
|
||||
strLicenseLines.remove();
|
||||
if(strLicense.isNull())return;
|
||||
strLicense.removeTokens("\r");
|
||||
strLicenseLines.insert(&String(strLicense.betweenString(0,'\n')));
|
||||
strLicenseLines.insert(&String(strLicense.betweenString('\n','\n')));
|
||||
strLicenseLines.insert(&String(strLicense.betweenString('\n','\0').betweenString('\n','\n\0')));
|
||||
}
|
||||
Reference in New Issue
Block a user