// frmActivityMgr.cpp - Activity Manager form.
//
// (c) 2012-2015 Xestia Software Development.
//
// This file is part of Xestia Address Book.
//
// Xestia Address Book is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
// Xestia Address Book is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with Xestia Address Book. If not, see
#include "frmActivityMgr.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "bitmaps.h"
#include "enums.h"
#include "common/preferences.h"
#include "frmConflictResolution.h"
#include "frmInvalidSSLCertificate.h"
#include "frmMain.h"
#include "common/events.h"
#include "common/filename.h"
#include "common/dirs.h"
#include "vcard/vcard34conv.h"
#include "vcard/vcard.h"
#ifndef FRMACTIVITYMGR_H
#define FRMACTIVITYMGR_H
DEFINE_EVENT_TYPE(ACTMGR_RESUMEPROC);
DEFINE_EVENT_TYPE(ACTMGR_TOGGLECONN);
DEFINE_EVENT_TYPE(ACTMGR_STARTTIMER);
DEFINE_EVENT_TYPE(ACTMGR_STOPTIMER);
DEFINE_EVENT_TYPE(ACTMGR_STARTPROCESSTIMER);
DEFINE_EVENT_TYPE(ACTMGR_STOPPROCESSTIMER);
DEFINE_EVENT_TYPE(ACTMGR_UPDATESTATUSLABEL);
BEGIN_EVENT_TABLE(frmActivityMgr, wxWindow)
EVT_COMMAND(wxID_ANY, ACTMGR_RESUMEPROC, frmActivityMgr::ResumeProcessing)
EVT_COMMAND(wxID_ANY, ACTMGR_TOGGLECONN, frmActivityMgr::ToggleConnectionStatus)
EVT_COMMAND(wxID_ANY, ACTMGR_STARTTIMER, frmActivityMgr::StartTimer)
EVT_COMMAND(wxID_ANY, ACTMGR_STOPTIMER, frmActivityMgr::StopTimer)
EVT_COMMAND(wxID_ANY, ACTMGR_STARTPROCESSTIMER, frmActivityMgr::StartProcessTimer)
EVT_COMMAND(wxID_ANY, ACTMGR_STOPPROCESSTIMER, frmActivityMgr::StopProcessTimer)
EVT_COMMAND(wxID_ANY, ACTMGR_UPDATESTATUSLABEL, frmActivityMgr::UpdateStatusLabel)
END_EVENT_TABLE()
frmActivityMgr::frmActivityMgr( wxWindow* parent )
:
frmActivityMgrADT( parent )
{
wxMemoryInputStream istream(icons_activitywindow_png, sizeof(icons_activitywindow_png));
wxImage icons_activitywindow_pngi(istream, wxBITMAP_TYPE_PNG);
wxBitmap activityiconbmp(icons_activitywindow_pngi, -1);
wxIcon activityicon;
activityicon.CopyFromBitmap(activityiconbmp);
this->SetIcon(activityicon);
wxMemoryInputStream istream2(misc_activitysleep_png, sizeof(misc_activitysleep_png));
wxImage misc_activitysleep_pngi(istream2, wxBITMAP_TYPE_PNG);
wxBitmap sleepiconbmp(misc_activitysleep_pngi, -1);
SleepBitmap = sleepiconbmp;
bmpActivity->SetBitmap(SleepBitmap);
ActProcessTimer.SetupPointers(this);
lblDetails->SetLabel(_("No activity."));
ActListProcTimer.SetupPointers(&ActivityList, &ActivityListIndex, &ActivityListTaskDetail,
&TasksActive, lstActivity, lblDetails, GauProgress, this, &AnimationTimer,
&ActProcessTimer, &ActivityListFinDate);
AnimationTimer.SetBitmap(bmpActivity);
AnimationTimer.SetSleepBitmap(&SleepBitmap);
AnimationTimer.SetupPointer(this->GetParent());
wxListItem ColumnData;
ColumnData.SetId(0);
ColumnData.SetText(_("Activity"));
ColumnData.SetWidth(175);
lstActivity->InsertColumn(0, ColumnData);
wxListItem ColumnData2;
ColumnData2.SetId(1);
ColumnData2.SetText(_("Account"));
ColumnData2.SetWidth(100);
lstActivity->InsertColumn(1, ColumnData2);
wxListItem ColumnData3;
ColumnData3.SetId(2);
ColumnData3.SetText(_("Status"));
ColumnData3.SetWidth(100);
lstActivity->InsertColumn(2, ColumnData3);
//AnimationTimer.StartAnimation();
// Create recovery database if it doesn't exist.
wxString RecoveryFilename = GetRecoveryDB();
wxFile RecoveryDB;
if (wxFile::Exists(RecoveryFilename) == FALSE){
// Create the recovery database.
RecoveryDB.Open(RecoveryFilename.c_str(), wxFile::write);
RecoveryDB.Write(wxT("BEGIN:XAB-RECOVERYDB\r\n"), wxConvUTF8);
RecoveryDB.Write(wxT("VERSION:1.0\r\n"), wxConvUTF8);
RecoveryDB.Write(wxT("COMMENT:Please do not alter or delete this file. DATA LOSS IS POSSIBLE!\r\n"), wxConvUTF8);
RecoveryDB.Write(wxT("END:XAB-RECOVERYDB\r\n"), wxConvUTF8);
RecoveryDB.Close();
}
wxFFile RecoveryDBF;
#if wxABI_VERSION < 20900
RecoveryDBF.Open(RecoveryFilename.c_str(), wxT("r"));
#else
RecoveryDBF.Open(RecoveryFilename, wxT("r"));
#endif
// Load the recovery database for tasks not done.
if (RecoveryDBF.IsOpened() == TRUE){
wxString wxSRecoveryDB;
wxString RecoveryLine;
// Check if we are using wxWidgets version 2.8 or less and
// execute the required command accordingly.
RecoveryDBF.ReadAll(&wxSRecoveryDB, wxConvAuto());
// Split the lines.
std::map RecoveryFileLines;
std::map::iterator striter;
wxStringTokenizer wSTRecoveryDBLines(wxSRecoveryDB, wxT("\r\n"));
int RecoveryLineSeek = 0;
while (wSTRecoveryDBLines.HasMoreTokens() == TRUE){
RecoveryLine = wSTRecoveryDBLines.GetNextToken();
RecoveryFileLines.insert(std::make_pair(RecoveryLineSeek, RecoveryLine));
RecoveryLineSeek++;
}
}
//TestTimer.Start(50, FALSE);
}
int frmActivityMgr::AddTask(int TaskType, wxString TaskDetail, wxString TaskAccount,
wxString TaskURL, wxString TaskFilename, wxString TaskFullFilename,
wxString TaskData){
ActivityTaskID++;
wxListItem coldata;
long itemindex = -1;
CardDAV CardDAVConn;
coldata.SetId(ActivityTaskID);
coldata.SetData(ActivityTaskID);
AnimationTimer.StartAnimation();
// Get the preferences file.
wxString PrefFilename = GetUserPrefDir();
XABPreferences PrefData(PrefFilename);
wxString AccountName;
wxString AccountDir;
wxString AccountAddress;
int AccountPort = 0;
wxString AccountUsername;
wxString AccountPassword;
bool AccountSSL = FALSE;
wxString AccountPrefix;
// Look for the account and get the friendly name for the account.
for (int i = 0; i < PrefData.accounts.GetCount(); i++){
AccountDir = PrefData.accounts.GetAccountDirectory(i);
AccountDir.Trim();
AccountDir.Append(wxT(".carddav"));
if (AccountDir == TaskAccount){
AccountName = PrefData.accounts.GetAccountName(i);
AccountAddress = PrefData.accounts.GetAccountAddress(i);
AccountPort = PrefData.accounts.GetAccountPort(i);
AccountUsername = PrefData.accounts.GetAccountUsername(i);
AccountPassword = PrefData.accounts.GetAccountPassword(i);
AccountPrefix = PrefData.accounts.GetAccountDirPrefix(i);
AccountSSL = PrefData.accounts.GetAccountSSL(i);
AccountName.Trim();
AccountAddress.Trim();
//AccountPort.Trim();
AccountUsername.Trim();
AccountPassword.Trim();
AccountPrefix.Trim();
break;
}
}
CardDAVConn.SetupConnection(AccountAddress, AccountPort, AccountUsername, AccountPassword, AccountSSL, AccountPrefix, AccountDir);
CardDAVConn.SetupVariables(&ActivityList, ActivityTaskID);
CardDAVConn.SetupResultBools(&BlankBool, &BlankBool);
// TaskType:
// 0 - Add a contact.
// 1 - Update a contact.
// 2 - Delete a contact.
// 3 - Account syncronisation.
if (TaskType == 0){
coldata.SetText(_("Adding Contact '") + TaskDetail + _("'"));
itemindex = lstActivity->InsertItem(coldata);
lstActivity->SetItem(itemindex, 1, AccountName);
lstActivity->SetItem(itemindex, 2, _("Queued"));
CardDAVConn.SetUploadMode(TRUE);
CardDAVConn.SetupData(wxT("PUT"), TaskURL, TaskData);
// Setup all of the task details.
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
ActivityListType.insert(std::make_pair(ActivityTaskID, 0));
ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail));
ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
ActivityListFullFilename.insert(std::make_pair(ActivityTaskID, TaskFullFilename));
ActivityListETag.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETag(TaskFilename)));
ActivityListETagOriginal.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETagOriginal(TaskFilename)));
ActivityList.insert(std::make_pair(ActivityTaskID, 0));
} else if (TaskType == 1){
coldata.SetText(_("Updating Contact '") + TaskDetail + _("'"));
itemindex = lstActivity->InsertItem(coldata);
lstActivity->SetItem(itemindex, 1, AccountName);
lstActivity->SetItem(itemindex, 2, _("Queued"));
CardDAVConn.SetUploadMode(TRUE);
CardDAVConn.SetupData(wxT("PUT"), TaskURL, TaskData);
CardDAVConn.SetEditMode(TRUE);
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
ActivityListType.insert(std::make_pair(ActivityTaskID, 1));
ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail));
ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
ActivityListFullFilename.insert(std::make_pair(ActivityTaskID, TaskFullFilename));
ActivityListETag.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETag(TaskFilename)));
ActivityListETagOriginal.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETagOriginal(TaskFilename)));
ActivityList.insert(std::make_pair(ActivityTaskID, 0));
} else if (TaskType == 2){
coldata.SetText(_("Deleting Contact '") + TaskDetail + _("'"));
itemindex = lstActivity->InsertItem(coldata);
lstActivity->SetItem(itemindex, 1, AccountName);
lstActivity->SetItem(itemindex, 2, _("Queued"));
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
ActivityList.insert(std::make_pair(ActivityTaskID, 0));
ActivityListType.insert(std::make_pair(ActivityTaskID, 2));
ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
} else if (TaskType == 3){
coldata.SetText(_("Syncronising All Contacts"));
itemindex = lstActivity->InsertItem(coldata);
lstActivity->SetItem(itemindex, 1, AccountName);
lstActivity->SetItem(itemindex, 2, _("Queued"));
ActivityList.insert(std::make_pair(ActivityTaskID, 0));
ActivityListType.insert(std::make_pair(ActivityTaskID, 3));
ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, AccountPrefix));
ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
}
ProcessTasksData = TRUE;
if (!ActProcessTimer.IsRunning()) {
wxCommandEvent event(ACTMGR_STARTTIMER);
wxPostEvent(this, event);
wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
wxPostEvent(this, eventp);
//ActProcessTimer.Start(1000, FALSE);
//ActListProcTimer.Start(1000, FALSE);
}
// Update the recovery database.
return ActivityTaskID;
}
void frmActivityMgr::RemoveTask(){
// Remove task from the recovery database.
}
void frmActivityMgr::StopTask( wxCommandEvent& event ){
// Check if activity has been completed already before stopping.
long longSelected = -1;
int intSelectedData = 0;
longSelected = lstActivity->GetNextItem(longSelected,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
intSelectedData = (int)lstActivity->GetItemData(longSelected);
if (longSelected == -1){
return;
}
std::map::iterator CDAVter;
CDAVter = ActivityListConn.find(intSelectedData);
CDAVter->second.Abort();
lstActivity->SetItem(longSelected, 2, _("Stopped"));
}
void frmActivityMgr::StopAllTasks( wxCommandEvent& event ){
// Check if activity has been completed already before stopping.
// TODO: Look through for '1' and stop the running task(s).
long longSelected = -1;
int intSelectedData = 0;
longSelected = lstActivity->GetNextItem(longSelected,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
intSelectedData = (int)lstActivity->GetItemData(longSelected);
if (longSelected == -1){
return;
}
std::map::iterator CDAVter;
CDAVter = ActivityListConn.find(intSelectedData);
CDAVter->second.Abort();
lstActivity->SetItem(longSelected, 2, _("Stopped"));
AnimationTimer.StopAnimation();
bmpActivity->SetBitmap(SleepBitmap);
lblDetails->SetLabel(_("No activity."));
}
void frmActivityMgr::RetryTask( wxCommandEvent& event ){
// Check if activity has been completed already before retrying.
long longSelected = -1;
int intSelectedData = 0;
longSelected = lstActivity->GetNextItem(longSelected,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
intSelectedData = (int)lstActivity->GetItemData(longSelected);
if (longSelected == -1){
return;
}
std::map::iterator CDAVter;
CDAVter = ActivityListConn.find(intSelectedData);
// Restart the task.
//CDAVter->second.Abort();
std::map::iterator Iter;
Iter = ActivityList.find(intSelectedData);
Iter->second = 0;
AnimationTimer.StartAnimation();
if (!ActProcessTimer.IsRunning()) {
ActProcessTimer.Start(150, FALSE);
ActListProcTimer.Start(150, FALSE);
}
//lstActivity->SetItem(longSelected, 2, _("Processing..."));
}
void frmActivityMgr::OpenWindow()
{
WindowOpen = TRUE;
}
void frmActivityMgr::CloseWindow( wxCommandEvent& event )
{
WindowOpen = FALSE;
this->Hide();
}
void frmActivityMgr::CloseWindow( wxCloseEvent& event )
{
WindowOpen = FALSE;
this->Hide();
}
void frmActivityMgr::ProcessTasksThread()
{
if (ProcessTasksData == FALSE){
return;
}
std::map::iterator TypeIter;
std::map::iterator StringIter;
std::map::iterator StringDetailIter;
std::map::iterator StringAccountIter;
std::map::iterator StringFilenameIter;
std::map::iterator StringFullFilenameIter;
std::map::iterator StringTaskDetailIter;
std::map::iterator StringETagIter;
std::map::iterator StringETagOrigIter;
std::map::iterator CardDAVIter;
std::map::iterator LongIter;
bool TasksFoundProc = FALSE;
wxString TaskDetail;
for (std::map::iterator iter = ActivityList.begin();
iter != ActivityList.end(); ++iter){
// Check for any queued tasks and start one.
if (iter->second > 4){
continue;
}
CardDAVIter = ActivityListConn.find(iter->first);
TypeIter = ActivityListType.find(iter->first);
StringETagIter = ActivityListETag.find(iter->first);
StringETagOrigIter = ActivityListETagOriginal.find(iter->first);
StringAccountIter = ActivityListAccount.find(iter->first);
StringFilenameIter = ActivityListFilename.find(iter->first);
StringFullFilenameIter = ActivityListFullFilename.find(iter->first);
// 0 = Queued.
// 1 = Processing.
// 2 = Failed.
// 3 = Stopped.
// 4 = Completed.
// 5 = Failed (UI Updated).
// 6 = Stopped (UI Updated).
// 7 = (Reserved) (UI Updated).
// 8 = Completed. (UI Updated).
if (iter->second == 0){
//CardDAVIter->second.
// Wait for process to finish.
TasksActive = TRUE;
TasksFoundProc = TRUE;
wxString ETag;
wxString ETagOriginal;
wxString ETagServer;
wxString AccountDir;
wxString ContactFilename;
wxString FullFilename;
wxString ETagResult;
iter->second = 1;
if (TypeIter->second == 1){
CardDAVIter->second.GetServerETagValueThread();
ETagServer = CardDAVIter->second.ETagValueResult();
}
// Compare the ETags and work out if a conflict has occured.
if (TypeIter->second == 1){
ETag = StringETagIter->second;
ETagOriginal = StringETagOrigIter->second;
AccountDir = StringAccountIter->second;
ContactFilename = StringFilenameIter->second;
FullFilename = StringFullFilenameIter->second;
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
if (ETag == ETagOriginal){
// Compare the ETag with the Server ETag.
if (ETagOriginal != ETagServer){
// Server ETag is different from original ETag.
// This is a conflict which the user will now
// need to resolve.
vCard Moo1;
vCard Moo2;
frmMain *frmMainPtrGet = static_cast(frmMainPtr);
vCard34Conv vCard34Obj;
wxString ServerContactData;
vCard ClientData;
vCard ConvertedV4Data;
// Load the client data from the filename given.
CardDAVIter->second.GetServerContactData();
ServerContactData = CardDAVIter->second.GetPageData();
// Process v3 version into v4 version.
vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
vCardConflictObj vCardProcData;
vCardProcData.vCardLocalData = &ClientData;
vCardProcData.vCardServerData = &ConvertedV4Data;
ClientData.LoadFile(FullFilename);
//ContactConflictEvent event(ContactConflictCmdEnv);
//event.SetData(ContactFilename, Moo1, Moo2);
//wxPostEvent(frmMainPtrGet, event);
// Setup Conflict Resolution Dialog.
// Fetch Data from Server and convert.
bool *PauseMode = new bool;
int ConflictResult;
QRNotif qrn;
*PauseMode = TRUE;
qrn.QResponse = &ConflictResult;
qrn.PausePtr = PauseMode;
vCardProcData.QRNotifData = &qrn;
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
event.SetClientData(&vCardProcData);
wxPostEvent(frmMainPtrGet, event);
/*timespec n1, n2;
n1.tv_sec = 0;
n1.tv_nsec = 250000000L;*/
while (*PauseMode == TRUE){
//nanosleep(&n1, &n2);
SleepFor(250000000);
}
delete PauseMode;
PauseMode = NULL;
//intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
if (ConflictResult == 0){
// Decide Later.
iter->second = 4;
continue;
} else if (ConflictResult == 1){
// Decided to use client version.
CardDAVIter->second.ProcessData();
iter->second = 4;
} else if (ConflictResult == 2){
// Decided to use server version.
// Download server version.
ConvertedV4Data.WriteFile(FullFilename);
iter->second = 4;
}
} else {
// Update the data to the server.
CardDAVIter->second.ProcessData();
}
} else {
if (ETagOriginal != ETagServer){
// Server ETag is different from original ETag.
// This is a conflict which the user will now
// need to resolve.
frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
//ContactConflictEvent event(ContactConflictCmdEnv);
//event.SetData(ContactFilename, Moo1, Moo2);
vCard34Conv vCard34Obj;
wxString ServerContactData;
vCard ClientData;
vCard ConvertedV4Data;
// Load the client data from the filename given.
CardDAVIter->second.GetServerContactData();
ServerContactData = CardDAVIter->second.GetPageData();
ClientData.LoadFile(FullFilename);
// Process v3 version into v4 version.
vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
vCardConflictObj vCardProcData;
vCardProcData.vCardLocalData = &ClientData;
vCardProcData.vCardServerData = &ConvertedV4Data;
bool *PauseMode = new bool;
int ConflictResult;
QRNotif qrn;
*PauseMode = TRUE;
qrn.QResponse = &ConflictResult;
qrn.PausePtr = PauseMode;
vCardProcData.QRNotifData = &qrn;
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
event.SetClientData(&vCardProcData);
wxPostEvent(frmMainPtrGet, event);
/*timespec n1, n2;
n1.tv_sec = 0;
n1.tv_nsec = 250000000L;*/
while (*PauseMode == TRUE){
//nanosleep(&n1, &n2);
SleepFor(250000000);
}
delete PauseMode;
PauseMode = NULL;
//intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
if (ConflictResult == 0){
// Decide Later.
iter->second = 4;
continue;
} else if (ConflictResult == 1){
// Decided to use client version.
CardDAVIter->second.ProcessData();
//ETagServer = CardDAVIter->second.GetServerETagValueThread();
//ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
iter->second = 4;
} else if (ConflictResult == 2){
// Decided to use server version.
// Write server version to file.
ConvertedV4Data.WriteFile(FullFilename);
iter->second = 4;
}
} else {
// Update the data to the server.
CardDAVIter->second.ProcessData();
}
}
// Update the ETag DB.
CardDAVIter->second.GetServerETagValueThread();
ETagServer = CardDAVIter->second.ETagValueResult();
ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
iter->second = 4;
} else if (TypeIter->second == 2) {
// Delete the contact from the server and update the ETag DB.
AccountDir = StringAccountIter->second;
ContactFilename = StringFilenameIter->second;
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
CardDAVIter->second.SetUploadMode(FALSE);
CardDAVIter->second.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
//CardDAVIter->second.SetServerFilename();
CardDAVIter->second.ProcessData();
ETagDBPtr->RemoveETag(ContactFilename);
iter->second = 4;
} else if (TypeIter->second == 3) {
frmMain *frmMainPtrGet = static_cast(frmMainPtr);
wxString AccountNameFriendly;
wxString PrefFilename = GetUserPrefDir();
XABPreferences PrefData(PrefFilename);
int AccountID = 0;
for (int i = 0; i < PrefData.accounts.GetCount(); i++){
wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
AccountDirCheck.Trim();
AccountDirCheck.Append(wxT(".carddav"));
if (AccountDirCheck == StringAccountIter->second){
AccountNameFriendly = PrefData.accounts.GetAccountName(i);
AccountID = i;
}
}
bool KeepUpdating = TRUE;
while (KeepUpdating == TRUE){
StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
AccountDir = StringAccountIter->second;
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
wxArrayString vCardAdd;
wxArrayString vCardDelete;
wxArrayString vCardList;
wxArrayString vCardUpdateLocal;
wxArrayString vCardUpdateRemote;
wxArrayString vCardUpdateLog;
std::map vCardETag;
ContactListData ServerContactList;
std::map vCardDownloadData;
//wxArrayString vCardDownload;
//std::map vCardDownloadData;
// Get the list of vCard files locally.
wxString AccountDirFinal;
wxString AccountSyncTokenFilename;
wxString SyncTokenLoad;
#if defined(__HAIKU__)
//preffilename = wxT("noo");
#elif defined(__WIN32__)
AccountDirFinal = GetAccountDir(AccountDir, FALSE);
AccountSyncTokenFilename = AccountDirFinal;
AccountSyncTokenFilename.Append(wxT("synctoken"));
#else
AccountDirFinal = GetAccountDir(AccountDir, FALSE);
AccountSyncTokenFilename = AccountDirFinal;
AccountSyncTokenFilename.Append(wxT("synctoken"));
#endif
// Suppress Error Messages.
wxLogNull PleaseDoNotDisturb;
wxFFile SyncLoad;
SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
if (SyncLoad.IsOpened()){
SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
SyncLoad.Close();
}
// Get a list of vCard files from the server.
// Get the list of vCard files from the ETagDB.
std::map ETagDBData = ETagDBPtr->GetETagData();
CardDAV CardDAVInstance = CardDAVIter->second;
bool ExitLoop = FALSE;
std::map *SCListData = NULL;
while (ExitLoop == FALSE){
//ServerContactList = CardDAVInstance.GetContactList(SyncTokenLoad.ToUTF8());
ServerContactList = CardDAVIter->second.GetContactList(SyncTokenLoad.ToUTF8());
SSLCertCollection certcol = CardDAVIter->second.GetCertificateData();
// Create a pointer for the std::map.
SCListData = &ServerContactList.ListData;
// Check if any errors have occured whilst getting the data.
int ErrorCode = CardDAVIter->second.GetResultCode();
if (ErrorCode != 0){
if (ErrorCode == 60 || ErrorCode == 51){
// Invalid SSL certificate so bring up a dialog to the user
// explaining what has happened and the options available.
// Stop all the timers.
frmMainPtrGet->PauseAllTimers();
// Setup the data to be sent in the wxPostEvent command.
SSLInvalidCertNotifObj SSLICNProcData;
bool *PauseMode = new bool;
int SSLResult;
QRNotif qrn;
*PauseMode = TRUE;
qrn.QResponse = &SSLResult;
qrn.PausePtr = PauseMode;
SSLICNProcData.CertCollection = certcol;
SSLICNProcData.QRNotifData = &qrn;
SSLICNProcData.AccountName = AccountNameFriendly;
wxCommandEvent event(INVALIDSSLCERT);
event.SetClientData(&SSLICNProcData);
wxPostEvent(frmMainPtrGet, event);
/*timespec n1, n2;
// Fall asleep until we get an response.
n1.tv_sec = 0;
n1.tv_nsec = 250000000L;*/
while (*PauseMode == TRUE){
//nanosleep(&n1, &n2);
SleepFor(250000000);
}
// Process the response from the user.
if (SSLResult == 1){
// Accept the certificate. Write the certificate into the account
// directory (as server.crt) - will overwrite old certificate.
frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second.GetCertificateData());
WriteServerCertificate(AccountDir, CardDAVIter->second.GetCertificateData());
} else if (SSLResult == 2){
// Reject the certificate, abort the task and mark as failed.
frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, CardDAVIter->second.GetCertificateData());
iter->second = 2;
break;
}
// Resume all the timers.
frmMainPtrGet->ResumeAllTimers();
} else {
iter->second = 4;
break;
}
} else {
ExitLoop = TRUE;
}
}
if (iter->second == 2 || iter->second == 3 || iter->second == 4){
break;
}
frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second.GetCertificateData());
// Look in directory and see which vCards to add and delete
// In short:
// vCard exists but not in ETagDB - Add (and upload).
// vCard missing but in ETagDB - Delete (from server).
// Start by looking for vCards that are not in the ETagDB.
wxDir AccDir(AccountDirFinal);
wxString AccDirFilename;
bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
// Process the server data.
if (SCListData != NULL){
for (std::map::iterator fsiter = SCListData->begin();
fsiter != SCListData->end(); fsiter++){
// Check the mode of the file before adding.
// Get the HTTP status of the file from the list.
FileSyncData fsd = fsiter->second;
if (fsd.DataFlag == 1){
// Added or modified contact.
//vCardAdd.Add(fsiter->first, 1);
vCardDownloadDataFileClass vCardNewData;
vCardNewData.DataType = 0;
vCardDownloadData.insert(std::make_pair(fsiter->first, vCardNewData));
//} else if (fsd.DataFlag == 1){
// Contact has been modified on the server.
// vCardUpdateLocal.Add(fsiter->first, 1);
}
else if (fsd.DataFlag == 2){
// Contact has been deleted.
vCardDelete.Add(fsiter->first, 1);
}
}
}
// Look for vCards that are missing but in the ETagDB.
for (std::map::iterator etagiter = ETagDBData.begin();
etagiter != ETagDBData.end(); etagiter++){
// Check if the vCard exists.
if (!wxFileExists(AccountDirFinal + etagiter->first)){
// vCard doesn't exist so mark for deleting.
vCardDelete.Add(etagiter->first, 1);
}
}
// Compare Server with the ETag DB. Work out which
// needs to updated remotely and which needs to be
// updated locally.
for (std::map::iterator srviter = SCListData->begin();
srviter != SCListData->end(); srviter++){
if (ETagDBData.find(srviter->first) == ETagDBData.end()){
continue;
}
std::map::iterator lociter = ETagDBData.find(srviter->first);
ETagData etd = lociter->second;
FileSyncData fsd = srviter->second;
wxString ETagSrv = fsd.ETagData;
// Compare local ETag with original local ETag.
// If different, update to server is required.
if (etd.ETagValue != etd.ETagOrigValue){
// Check if local original ETag is different from server ETag.
// If it is then throw up a conflict resolution dialog.
if (etd.ETagOrigValue != ETagSrv){
vCard34Conv vCard34Obj;
wxString ServerContactData;
wxString FullFilename;
vCard ClientData;
vCard ConvertedV4Data;
// Conflict. Bring up conflict resolution dialog.
// Get the server contact data for comparison.
CardDAVIter->second.SetServerFilename(srviter->first);
CardDAVIter->second.GetServerContactData();
ServerContactData = CardDAVIter->second.GetPageData();
FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first);
// Convert it to v4.
vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
vCardConflictObj vCardProcData;
vCardProcData.vCardLocalData = &ClientData;
vCardProcData.vCardServerData = &ConvertedV4Data;
// Load the client data from the filename given.
ClientData.LoadFile(FullFilename);
// Show dialog.
bool *PauseMode = new bool;
int ConflictResult;
QRNotif qrn;
frmMain *frmMainPtrGet = static_cast(frmMainPtr);
*PauseMode = TRUE;
qrn.QResponse = &ConflictResult;
qrn.PausePtr = PauseMode;
vCardProcData.QRNotifData = &qrn;
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
event.SetClientData(&vCardProcData);
wxPostEvent(frmMainPtrGet, event);
/*timespec n1, n2;
n1.tv_sec = 0;
n1.tv_nsec = 250000000L;*/
while (*PauseMode == TRUE){
//nanosleep(&n1, &n2);
SleepFor(250000000);
}
delete PauseMode;
PauseMode = NULL;
// If replacing local version, store copy for now.
// Otherwise upload to server.
if (ConflictResult == 0){
// Decide Later.
continue;
} else if (ConflictResult == 1){
// Decided to use client version.
vCardUpdateLocal.Remove(srviter->first);
vCardUpdateRemote.Add(srviter->first, 1);
} else if (ConflictResult == 2){
// Decided to use server version.
// Store the converted downloaded copy for
// processing later.
//vCardUpdateLocal.Add(srviter->first, 1);
vCardDownloadDataFileClass vCardNewData;
vCardNewData.DataType = 1;
vCardNewData.FileData = ConvertedV4Data.WriteString();
ConvertedV4Data.WriteFile(FullFilename);
vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData));
}
} else {
// Send vCard to the server.
vCardUpdateRemote.Add(srviter->first, 1);
}
} else {
// Check if local ETag is different from server ETag.
// If different, obtain the vCard from the server.
if (etd.ETagOrigValue != ETagSrv){
vCardUpdateLocal.Add(srviter->first, 1);
}
}
}
// Process the vCards that need to be downloaded and added/overwritten.
wxString vCardFilenameFinal;
wxString vCardOutputData;
wxString vCardInputData;
wxString ETagFileData;
wxFFile vCardFile;
for (std::map::iterator additer = vCardDownloadData.begin();
additer != vCardDownloadData.end(); additer++){
vCardFilenameFinal.Clear();
vCardInputData.Clear();
vCardOutputData.Clear();
ETagFileData.Clear();
vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
if (additer->second.DataType == 0){
vCard ConvertedV4Data;
// Grab the file from the server and write the contact out.
vCard34Conv vCard34Obj;
CardDAVIter->second.SetServerFilename(additer->first);
CardDAVIter->second.GetServerContactData();
vCardInputData = CardDAVIter->second.GetPageData();
vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
ConvertedV4Data.WriteFile(vCardFilenameFinal);
// Update the ETagDB.
//vCardFile.Open(vCardFilenameFinal, wxT("w"));
//if (vCardFile.IsOpened()){
// vCardFile.Write(vCardOutputData, wxConvAuto());
// vCardFile.Close();
//}
// Get the server ETag.
wxString ServerETag;
CardDAVIter->second.GetServerETagValueThread();
ServerETag = CardDAVIter->second.ETagValueResult();
// Add to the ETag Database.
ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
} else if (additer->second.DataType == 1){
// Write out the contact to the account directory.
vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
vCardOutputData = additer->second.FileData;
vCardFile.Open(vCardFilenameFinal, wxT("w"));
if (vCardFile.IsOpened()){
vCardFile.Write(vCardOutputData, wxConvAuto());
vCardFile.Close();
}
// Update the ETagDB.
wxString ServerETag;
CardDAVIter->second.GetServerETagValueThread();
ServerETag = CardDAVIter->second.ETagValueResult();
// Add to the ETag Database.
ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
}
}
// Look for vCard files which aren't in the ETagDB.
while(ContinueProcess){
// Check and make sure that the filename ends in .vcf/.vcard
// Skip any file that beings with a dot.
if (AccDirFilename.Left(1) == wxT(".")){
ContinueProcess = AccDir.GetNext(&AccDirFilename);
continue;
}
if (AccDirFilename.Right(4) != wxT(".vcf") &&
AccDirFilename.Right(6) != wxT(".vcard")){
ContinueProcess = AccDir.GetNext(&AccDirFilename);
continue;
}
// Look in the ETagDB for the file.
bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
if (ETagExists == FALSE){
// Add the vCard to the list to be added.
vCardAdd.Add(AccDirFilename, 1);
}
ContinueProcess = AccDir.GetNext(&AccDirFilename);
}
// Process the vCards to add/update to the server.
for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
ContactFilename = vCardAdd[vi];
FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
ContactFilename.Trim();
if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
// Compare the ETag with the Server ETag.
CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
CardDAVIter->second.GetServerETagValueThread();
ETagServer = CardDAVIter->second.ETagValueResult();
if (ETagOriginal != ETagServer){
// Server ETag is different from original ETag.
// This is a conflict which the user will now
// need to resolve.
frmMain *frmMainPtrGet = static_cast(frmMainPtr);
vCard34Conv vCard34Obj;
wxString ServerContactData;
vCard ClientData;
vCard ConvertedV4Data;
// Load the client data from the filename given.
CardDAVIter->second.GetServerContactData();
ServerContactData = CardDAVIter->second.GetPageData();
// Process v3 version into v4 version.
vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
vCardConflictObj vCardProcData;
vCardProcData.vCardLocalData = &ClientData;
vCardProcData.vCardServerData = &ConvertedV4Data;
ClientData.LoadFile(FullFilename);
//ContactConflictEvent event(ContactConflictCmdEnv);
//event.SetData(ContactFilename, Moo1, Moo2);
//wxPostEvent(frmMainPtrGet, event);
// Setup Conflict Resolution Dialog.
// Fetch Data from Server and convert.
bool *PauseMode = new bool;
int ConflictResult;
QRNotif qrn;
*PauseMode = TRUE;
qrn.QResponse = &ConflictResult;
qrn.PausePtr = PauseMode;
vCardProcData.QRNotifData = &qrn;
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
event.SetClientData(&vCardProcData);
wxPostEvent(frmMainPtrGet, event);
/*timespec n1, n2;
n1.tv_sec = 0;
n1.tv_nsec = 250000000L;*/
while (*PauseMode == TRUE){
//nanosleep(&n1, &n2);
SleepFor(250000000);
}
delete PauseMode;
PauseMode = NULL;
//intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
if (ConflictResult == 0){
// Decide Later.
iter->second = 4;
continue;
} else if (ConflictResult == 1){
// Decided to use client version.
CardDAVIter->second.ProcessData();
iter->second = 4;
} else if (ConflictResult == 2){
// Decided to use server version.
// Download server version.
ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
iter->second = 4;
}
} else {
// Setup the filename for the contact being added.
wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
wxString wxSCardData;
wxString TaskData;
//wxString TaskURL;
// Load the data from the file.
wxFFile wxFCard;
wxFCard.Open(wxSFilename, wxT("r"));
if (wxFCard.IsOpened()){
wxFCard.ReadAll(&wxSCardData, wxConvAuto());
wxFCard.Close();
}
// Convert the data to v3.
vCard34Conv vCard34Obj;
vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
// Setup the URL address.
//TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
// Upload the data to the server.
CardDAVIter->second.SetUploadMode(TRUE);
CardDAVIter->second.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
CardDAVIter->second.ProcessData();
// Get the Server ETag and put it in the ETag database.
CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
CardDAVIter->second.GetServerETagValueThread();
ETagServer = CardDAVIter->second.ETagValueResult();
ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
}
} else {
if (ETagOriginal != ETagServer){
// Server ETag is different from original ETag.
// This is a conflict which the user will now
// need to resolve.
frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
//ContactConflictEvent event(ContactConflictCmdEnv);
//event.SetData(ContactFilename, Moo1, Moo2);
vCard34Conv vCard34Obj;
wxString ServerContactData;
vCard ClientData;
vCard ConvertedV4Data;
// Load the client data from the filename given.
CardDAVIter->second.GetServerContactData();
ServerContactData = CardDAVIter->second.GetPageData();
ClientData.LoadFile(FullFilename);
// Process v3 version into v4 version.
vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
vCardConflictObj vCardProcData;
vCardProcData.vCardLocalData = &ClientData;
vCardProcData.vCardServerData = &ConvertedV4Data;
bool *PauseMode = new bool;
int ConflictResult;
QRNotif qrn;
*PauseMode = TRUE;
qrn.QResponse = &ConflictResult;
qrn.PausePtr = PauseMode;
vCardProcData.QRNotifData = &qrn;
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
event.SetClientData(&vCardProcData);
wxPostEvent(frmMainPtrGet, event);
/*timespec n1, n2;
n1.tv_sec = 0;
n1.tv_nsec = 250000000L;*/
while (*PauseMode == TRUE){
//nanosleep(&n1, &n2);
SleepFor(250000000);
}
delete PauseMode;
PauseMode = NULL;
//intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
if (ConflictResult == 0){
// Decide Later.
iter->second = 4;
continue;
} else if (ConflictResult == 1){
// Decided to use client version.
CardDAVIter->second.ProcessData();
//ETagServer = CardDAVIter->second.GetServerETagValueThread();
//ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
iter->second = 4;
} else if (ConflictResult == 2){
// Decided to use server version.
// Write server version to file.
ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
iter->second = 4;
}
} else {
// Setup the filename for the contact being added.
wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
wxString wxSCardData;
wxString TaskData;
//wxString TaskURL;
// Load the data from the file.
wxFFile wxFCard;
wxFCard.Open(wxSFilename, wxT("r"));
if (wxFCard.IsOpened()){
wxFCard.ReadAll(&wxSCardData, wxConvAuto());
wxFCard.Close();
}
// Convert the data to v3.
vCard34Conv vCard34Obj;
vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
// Setup the URL address.
//TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
// Upload the data to the server.
CardDAVIter->second.SetUploadMode(TRUE);
CardDAVIter->second.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
CardDAVIter->second.ProcessData();
// Get the Server ETag and put it in the ETag database.
CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
CardDAVIter->second.GetServerETagValueThread();
ETagServer = CardDAVIter->second.ETagValueResult();
ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
}
}
}
// Process the vCards to delete locally.
for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
} else {
ETagDBPtr->RemoveETag(vCardDelete[vi]);
}
}
// Process the vCards to delete from the server.
std::map *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
for (std::map::iterator deliter = ETagFilenameMap->begin();
deliter != ETagFilenameMap->end(); deliter++){
// Look through the ETagDB and find contacts which are marked as DELETED.
if (deliter->second == wxT("DELETED")){
CardDAVIter->second.SetUploadMode(FALSE);
CardDAVIter->second.SetupData(wxT("DELETE"), deliter->first, wxT(""));
CardDAVIter->second.ProcessData();
// Delete the ETag as the file has now been deleted.
ETagDBPtr->RemoveETag(deliter->first);
}
}
// Write out the update server sync token.
wxString ServerSyncToken = ServerContactList.SyncToken;
ServerSyncToken.Trim();
if (!ServerSyncToken.IsEmpty()){
wxFFile SyncWrite;
SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
if (SyncWrite.IsOpened()){
SyncWrite.Write(ServerSyncToken, wxConvAuto());
SyncWrite.Close();
}
}
// Check for another sync token. If there is another
// sync token then repeat this. If token matches then stop processing.
if (SyncTokenLoad == ServerSyncToken){
KeepUpdating = FALSE;
}
}
// Mark as completed.
wxString AccountNameFinal;
AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
AccountNameFinal.Append(wxT(".carddav"));
wxCommandEvent reloadevent(RELOADCONTACTLIST);
reloadevent.SetString(AccountNameFinal);
wxPostEvent(this->GetParent(), reloadevent);
iter->second = 4;
continue;
} else {
// Update the data to the server.
CardDAVIter->second.ProcessData();
iter->second = 4;
continue;
}
/*timespec n1, n2;
n1.tv_sec = 0;
n1.tv_nsec = 250000000L;*/
while (iter->second == 1){
SleepFor(250000000);
//nanosleep(&n1, &n2);
}
if ((iter->second == 4 && TypeIter->second == 0) ||
(iter->second == 8 && TypeIter->second == 0)){
AccountDir = StringAccountIter->second;
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
CardDAVIter->second.GetServerETagValueThread();
ETagServer = CardDAVIter->second.ETagValueResult();
ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
}
if ((iter->second == 4 && TypeIter->second == 1) ||
(iter->second == 8 && TypeIter->second == 1)){
AccountDir = StringAccountIter->second;
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
CardDAVIter->second.GetServerETagValueThread();
ETagServer = CardDAVIter->second.ETagValueResult();
ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
}
break;
}
}
if (TasksFoundProc == FALSE){
TasksActive = FALSE;
ProcessTasksData = FALSE;
} else {
wxCommandEvent eventp(ACTMGR_STARTTIMER);
wxPostEvent(this, eventp);
//AnimationTimer.StartAnimation();
//ActListProcTimer.Start();
}
wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
wxPostEvent(this, event);
//ActProcessTimer.Start();
}
void frmActivityMgr::ProcessTasks()
{
std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
ProcessThread.detach();
}
void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
{
ETagTmrPtr = ETagTmrPtrInc;
frmMainPtr = frmMainPtrInc;
}
void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
QRNotif *qrn = (QRNotif *)event.GetClientData();
int *QRes = qrn->QResponse;
*qrn->PausePtr = FALSE;
*QRes = event.GetInt();
}
int frmActivityMgr::GetTaskStatus(int intTaskID){
int intResult = 2;
if (ActivityList.find(intTaskID) == ActivityList.end()){
return intResult;
}
std::map::iterator taskiter = ActivityList.find(intTaskID);
intResult = taskiter->second;
return intResult;
}
void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
wxCommandEvent connevent(CONNSTAT_UPDATE);
if (SleepMode == FALSE){
connevent.SetInt(1);
SleepMode = TRUE;
} else {
connevent.SetInt(0);
SleepMode = FALSE;
}
wxPostEvent(GetParent(), connevent);
}
void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
wxString ServerCertFinal;
// Get the Cert section of the certificate and write it to the file.
ServerCertFinal = GetAccountDir(AccountName, TRUE);
wxFile CertFile;
std::map::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
std::multimap::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
CertFile.Open(ServerCertFinal, wxFile::write);
CertFile.Write(SSLDataIter->second, wxConvUTF8);
CertFile.Close();
}
void frmActivityMgr::StartTimer(wxCommandEvent& event){
ActListProcTimer.Start(1000, FALSE);
}
void frmActivityMgr::StopTimer(wxCommandEvent& event){
ActListProcTimer.Stop();
}
void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
ActProcessTimer.Start(1000, FALSE);
}
void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
ActProcessTimer.Stop();
}
void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
if (actmgrudata != NULL){
lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
/*if (!actmgrudata->ItemDes.IsEmpty()){
lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes);
}*/
delete actmgrudata;
actmgrudata = NULL;
}
}
#endif