1 // frmActivityMgr-addtask.cpp - Activity Manager add task subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmActivityMgr.h"
21 int frmActivityMgr::AddTask(int TaskType, wxString TaskDetail, wxString TaskAccount,
22 wxString TaskURL, wxString TaskFilename, wxString TaskFullFilename,
30 coldata.SetId(ActivityTaskID);
31 coldata.SetData(ActivityTaskID);
33 if (ApplicationSleepMode == FALSE){
35 AnimationTimer.StartAnimation();
39 // Get the preferences file.
41 wxString PrefFilename = GetUserPrefDir();
43 XABPreferences PrefData(PrefFilename);
47 wxString AccountAddress;
49 wxString AccountUsername;
50 wxString AccountPassword;
51 bool AccountSSL = FALSE;
52 wxString AccountPrefix;
54 // Look for the account and get the friendly name for the account.
56 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
58 AccountDir = PrefData.accounts.GetAccountDirectory(i);
61 AccountDir.Append(wxT(".carddav"));
63 if (AccountDir == TaskAccount){
65 AccountName = PrefData.accounts.GetAccountName(i);
66 AccountAddress = PrefData.accounts.GetAccountAddress(i);
67 AccountPort = PrefData.accounts.GetAccountPort(i);
68 AccountUsername = PrefData.accounts.GetAccountUsername(i);
69 AccountPassword = PrefData.accounts.GetAccountPassword(i);
70 AccountPrefix = PrefData.accounts.GetAccountDirPrefix(i);
71 AccountSSL = PrefData.accounts.GetAccountSSL(i);
74 AccountAddress.Trim();
76 AccountUsername.Trim();
77 AccountPassword.Trim();
85 ActivityMgrAccountSettings AccountSettings;
86 AccountSettings.Address = AccountAddress;
87 AccountSettings.Port = AccountPort;
88 AccountSettings.Username = AccountUsername;
89 AccountSettings.Password = AccountPassword;
90 AccountSettings.SSL = AccountSSL;
91 AccountSettings.Prefix = AccountPrefix;
92 AccountSettings.Dir = AccountDir;
96 // 1 - Update a contact.
97 // 2 - Delete a contact.
98 // 3 - Account syncronisation.
102 coldata.SetText(_("Adding Contact '") + TaskDetail + _("'"));
103 itemindex = lstActivity->InsertItem(coldata);
105 lstActivity->SetItem(itemindex, 1, AccountName);
106 lstActivity->SetItem(itemindex, 2, _("Queued"));
108 // Setup all of the task details.
110 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
112 CardDAV2 *ConnObject = new CardDAV2(AccountAddress.ToStdString(), AccountPort, AccountUsername.ToStdString(), AccountPassword.ToStdString(), AccountSSL, AccountPrefix.ToStdString(), AccountDir.ToStdString());
113 ConnObject->SetupConnectionObject();
115 ActivityListType.insert(std::make_pair(ActivityTaskID, 0));
116 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
117 ActivityListURL.insert(std::make_pair(ActivityTaskID, TaskURL));
118 ActivityListEditMode.insert(std::make_pair(ActivityTaskID, false));
119 ActivityListConnObject.insert(std::make_pair(ActivityTaskID, ConnObject));
120 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
121 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail));
122 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
123 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
124 ActivityListFullFilename.insert(std::make_pair(ActivityTaskID, TaskFullFilename));
125 ActivityListAccSettings.insert(std::make_pair(ActivityTaskID, AccountSettings));
127 ActivityListETag.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETag(TaskFilename)));
128 ActivityListETagOriginal.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETagOriginal(TaskFilename)));
129 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
131 } else if (TaskType == 1){
133 coldata.SetText(_("Updating Contact '") + TaskDetail + _("'"));
134 itemindex = lstActivity->InsertItem(coldata);
136 lstActivity->SetItem(itemindex, 1, AccountName);
137 lstActivity->SetItem(itemindex, 2, _("Queued"));
139 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
141 CardDAV2 *ConnObject = new CardDAV2(AccountAddress.ToStdString(), AccountPort, AccountUsername.ToStdString(), AccountPassword.ToStdString(), AccountSSL, AccountPrefix.ToStdString(), AccountDir.ToStdString());
142 ConnObject->SetupConnectionObject();
144 ActivityListType.insert(std::make_pair(ActivityTaskID, 1));
145 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
146 ActivityListURL.insert(std::make_pair(ActivityTaskID, TaskURL));
147 ActivityListEditMode.insert(std::make_pair(ActivityTaskID, true));
148 ActivityListConnObject.insert(std::make_pair(ActivityTaskID, ConnObject));
149 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
150 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail));
151 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
152 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
153 ActivityListFullFilename.insert(std::make_pair(ActivityTaskID, TaskFullFilename));
154 ActivityListAccSettings.insert(std::make_pair(ActivityTaskID, AccountSettings));
156 ActivityListETag.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETag(TaskFilename)));
157 ActivityListETagOriginal.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETagOriginal(TaskFilename)));
158 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
160 } else if (TaskType == 2){
162 coldata.SetText(_("Deleting Contact '") + TaskDetail + _("'"));
163 itemindex = lstActivity->InsertItem(coldata);
165 lstActivity->SetItem(itemindex, 1, AccountName);
166 lstActivity->SetItem(itemindex, 2, _("Queued"));
168 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
170 CardDAV2 *ConnObject = new CardDAV2(AccountAddress.ToStdString(), AccountPort, AccountUsername.ToStdString(), AccountPassword.ToStdString(), AccountSSL, AccountPrefix.ToStdString(), AccountDir.ToStdString());
171 ConnObject->SetupConnectionObject();
173 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
174 ActivityListType.insert(std::make_pair(ActivityTaskID, 2));
175 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
176 ActivityListURL.insert(std::make_pair(ActivityTaskID, TaskURL));
177 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
178 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
179 ActivityListConnObject.insert(std::make_pair(ActivityTaskID, ConnObject));
180 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
181 ActivityListAccSettings.insert(std::make_pair(ActivityTaskID, AccountSettings));
183 } else if (TaskType == 3){
185 coldata.SetText(_("Syncronising All Contacts"));
186 itemindex = lstActivity->InsertItem(coldata);
188 lstActivity->SetItem(itemindex, 1, AccountName);
189 lstActivity->SetItem(itemindex, 2, _("Queued"));
191 CardDAV2 *ConnObject = new CardDAV2(AccountAddress.ToStdString(), AccountPort, AccountUsername.ToStdString(), AccountPassword.ToStdString(), AccountSSL, AccountPrefix.ToStdString(), AccountDir.ToStdString());
192 ConnObject->SetupConnectionObject();
194 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
195 ActivityListType.insert(std::make_pair(ActivityTaskID, 3));
196 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
197 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, AccountPrefix));
198 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
199 ActivityListConnObject.insert(std::make_pair(ActivityTaskID, ConnObject));
200 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
201 ActivityListAccSettings.insert(std::make_pair(ActivityTaskID, AccountSettings));
205 ProcessTasksData = TRUE;
207 if (!ActProcessTimer.IsRunning() && ApplicationSleepMode == FALSE) {
209 wxCommandEvent event(ACTMGR_STARTTIMER);
210 wxPostEvent(this, event);
212 wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
213 wxPostEvent(this, eventp);
215 //ActProcessTimer.Start(1000, FALSE);
216 //ActListProcTimer.Start(1000, FALSE);
220 // Update the recovery database.
222 return ActivityTaskID;
226 void frmActivityMgr::RemoveTask(){
228 // Remove task from the recovery database.
232 void frmActivityMgr::StopTask( wxCommandEvent& event ){
234 // Check if activity has been completed already before stopping.
236 long longSelected = -1;
237 int intSelectedData = 0;
239 longSelected = lstActivity->GetNextItem(longSelected,
241 wxLIST_STATE_SELECTED);
243 intSelectedData = (int)lstActivity->GetItemData(longSelected);
245 if (longSelected == -1){
249 lstActivity->SetItem(longSelected, 2, _("Stopped"));
253 void frmActivityMgr::StopAllTasks( wxCommandEvent& event ){
255 // Check if activity has been completed already before stopping.
257 // TODO: Look through for '1' and stop the running task(s).
259 long longSelected = -1;
260 int intSelectedData = 0;
262 longSelected = lstActivity->GetNextItem(longSelected,
264 wxLIST_STATE_SELECTED);
266 intSelectedData = (int)lstActivity->GetItemData(longSelected);
268 if (longSelected == -1){
272 lstActivity->SetItem(longSelected, 2, _("Stopped"));
273 AnimationTimer.StopAnimation();
274 bmpActivity->SetBitmap(SleepBitmap);
275 lblDetails->SetLabel(_("No activity."));
279 void frmActivityMgr::RetryTask( wxCommandEvent& event ){
281 // Check if activity has been completed already before retrying.
283 long longSelected = -1;
284 int intSelectedData = 0;
286 longSelected = lstActivity->GetNextItem(longSelected,
288 wxLIST_STATE_SELECTED);
290 intSelectedData = (int)lstActivity->GetItemData(longSelected);
292 if (longSelected == -1){
298 //CDAVter->second.Abort();
300 std::map<int,int>::iterator Iter;
301 Iter = ActivityList.find(intSelectedData);
305 AnimationTimer.StartAnimation();
307 if (!ActProcessTimer.IsRunning()) {
309 ActProcessTimer.Start(150, FALSE);
310 ActListProcTimer.Start(150, FALSE);
314 //lstActivity->SetItem(longSelected, 2, _("Processing..."));
318 int frmActivityMgr::GetTaskStatus(int intTaskID){
322 if (ActivityList.find(intTaskID) == ActivityList.end()){
328 std::map<int,int>::iterator taskiter = ActivityList.find(intTaskID);
329 intResult = taskiter->second;