#include <thread>
#include <curl/curl.h>
-#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"
-
+#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 "../vcard/vcard34conv.h"
+#include "../vcard/vcard.h"
#ifndef FRMACTIVITYMGR_H
#define FRMACTIVITYMGR_H
//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 = new CardDAV;
-
- 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<int,CardDAV*>::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<int,CardDAV*>::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<int,CardDAV*>::iterator CDAVter;
-
- CDAVter = ActivityListConn.find(intSelectedData);
-
- // Restart the task.
-
- //CDAVter->second.Abort();
-
- std::map<int,int>::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;
}
-int frmActivityMgr::GetTaskStatus(int intTaskID){
-
- int intResult = 2;
-
- if (ActivityList.find(intTaskID) == ActivityList.end()){
-
- return intResult;
-
- }
-
- std::map<int,int>::iterator taskiter = ActivityList.find(intTaskID);
- intResult = taskiter->second;
-
- return intResult;
-
-}
-
void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
wxCommandEvent connevent(CONNSTAT_UPDATE);