Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Replaced code for PREF in GEO with ProcessIntegerValue.
[xestiaab/.git] / source / actmgr / frmActivityMgr-tasks.cpp
1 // frmActivityMgr-addtask.cpp - Activity Manager add task subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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, 
23         wxString TaskData){
25         ActivityTaskID++;
27         wxListItem coldata;
28         long itemindex = -1;
29         CardDAV* CardDAVConn = new CardDAV;
31         coldata.SetId(ActivityTaskID);
32         coldata.SetData(ActivityTaskID);
34         AnimationTimer.StartAnimation();
36         // Get the preferences file.
37         
38         wxString PrefFilename = GetUserPrefDir();
39         
40         XABPreferences PrefData(PrefFilename);
42         wxString AccountName;
43         wxString AccountDir;
44         wxString AccountAddress;
45         int AccountPort = 0;
46         wxString AccountUsername;
47         wxString AccountPassword;
48         bool AccountSSL = FALSE;
49         wxString AccountPrefix;
51         // Look for the account and get the friendly name for the account.
52         
53         for (int i = 0; i < PrefData.accounts.GetCount(); i++){
54         
55                 AccountDir = PrefData.accounts.GetAccountDirectory(i);
56                 
57                 AccountDir.Trim();
58                 AccountDir.Append(wxT(".carddav"));
59         
60                 if (AccountDir == TaskAccount){
61                 
62                         AccountName = PrefData.accounts.GetAccountName(i);
63                         AccountAddress = PrefData.accounts.GetAccountAddress(i);
64                         AccountPort = PrefData.accounts.GetAccountPort(i);
65                         AccountUsername = PrefData.accounts.GetAccountUsername(i);
66                         AccountPassword = PrefData.accounts.GetAccountPassword(i);
67                         AccountPrefix = PrefData.accounts.GetAccountDirPrefix(i);
68                         AccountSSL = PrefData.accounts.GetAccountSSL(i);
69                         
70                         AccountName.Trim();
71                         AccountAddress.Trim();
72                         //AccountPort.Trim();
73                         AccountUsername.Trim();
74                         AccountPassword.Trim();
75                         AccountPrefix.Trim();
76                         break;
77                 
78                 }
79         
80         }
81         
82         CardDAVConn->SetupConnection(AccountAddress, AccountPort, AccountUsername, AccountPassword, AccountSSL, AccountPrefix, AccountDir);
83         CardDAVConn->SetupVariables(&ActivityList, ActivityTaskID);
84         CardDAVConn->SetupResultBools(&BlankBool, &BlankBool);          
86         // TaskType:
87         // 0 - Add a contact.
88         // 1 - Update a contact.
89         // 2 - Delete a contact.
90         // 3 - Account syncronisation.
92         if (TaskType == 0){             
94                 coldata.SetText(_("Adding Contact '") + TaskDetail + _("'"));
95                 itemindex = lstActivity->InsertItem(coldata);
96                 
97                 lstActivity->SetItem(itemindex, 1, AccountName);
98                 lstActivity->SetItem(itemindex, 2, _("Queued"));
99                 
100                 CardDAVConn->SetUploadMode(TRUE);
101                 CardDAVConn->SetupData(wxT("PUT"), TaskURL, TaskData);
102                 
103                 // Setup all of the task details.
105                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
106                 
107                 ActivityListType.insert(std::make_pair(ActivityTaskID, 0));
108                 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
109                 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
110                 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
111                 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail));
112                 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
113                 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
114                 ActivityListFullFilename.insert(std::make_pair(ActivityTaskID, TaskFullFilename));
115                 
116                 ActivityListETag.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETag(TaskFilename)));
117                 ActivityListETagOriginal.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETagOriginal(TaskFilename)));
118                 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
119         
120         } else if (TaskType == 1){
121         
122                 coldata.SetText(_("Updating Contact '") + TaskDetail + _("'"));
123                 itemindex = lstActivity->InsertItem(coldata);           
124                 
125                 lstActivity->SetItem(itemindex, 1, AccountName);
126                 lstActivity->SetItem(itemindex, 2, _("Queued"));
127                 
128                 CardDAVConn->SetUploadMode(TRUE);
129                 CardDAVConn->SetupData(wxT("PUT"), TaskURL, TaskData);
130                 CardDAVConn->SetEditMode(TRUE);
131                 
132                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
133                 
134                 ActivityListType.insert(std::make_pair(ActivityTaskID, 1));
135                 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
136                 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
137                 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
138                 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail));
139                 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
140                 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
141                 ActivityListFullFilename.insert(std::make_pair(ActivityTaskID, TaskFullFilename));
142                 
143                 ActivityListETag.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETag(TaskFilename)));
144                 ActivityListETagOriginal.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETagOriginal(TaskFilename)));
145                 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
146         
147         } else if (TaskType == 2){
149                 coldata.SetText(_("Deleting Contact '") + TaskDetail + _("'"));
150                 itemindex = lstActivity->InsertItem(coldata);
151                 
152                 lstActivity->SetItem(itemindex, 1, AccountName);
153                 lstActivity->SetItem(itemindex, 2, _("Queued"));
154                 
155                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
156                 
157                 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
158                 ActivityListType.insert(std::make_pair(ActivityTaskID, 2));
159                 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
160                 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
161                 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
162                 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
163                 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
164         
165         } else if (TaskType == 3){
167                 coldata.SetText(_("Syncronising All Contacts"));
168                 itemindex = lstActivity->InsertItem(coldata);
169                 
170                 lstActivity->SetItem(itemindex, 1, AccountName);
171                 lstActivity->SetItem(itemindex, 2, _("Queued"));
172                 
173                 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
174                 ActivityListType.insert(std::make_pair(ActivityTaskID, 3));
175                 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
176                 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
177                 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, AccountPrefix));
178                 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
179                 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
180         
181         }
182         
183         ProcessTasksData = TRUE;
184         
185         if (!ActProcessTimer.IsRunning()) {
186         
187                 wxCommandEvent event(ACTMGR_STARTTIMER);
188                 wxPostEvent(this, event);
190                 wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
191                 wxPostEvent(this, eventp);
193                 //ActProcessTimer.Start(1000, FALSE);
194                 //ActListProcTimer.Start(1000, FALSE);
195         
196         }
197         
198         // Update the recovery database.
199         
200         return ActivityTaskID;
204 void frmActivityMgr::RemoveTask(){
206         // Remove task from the recovery database.
210 void frmActivityMgr::StopTask( wxCommandEvent& event ){
212         // Check if activity has been completed already before stopping.
214         long longSelected = -1;
215         int intSelectedData = 0;
216                 
217         longSelected = lstActivity->GetNextItem(longSelected, 
218                 wxLIST_NEXT_ALL,
219                 wxLIST_STATE_SELECTED);
221         intSelectedData = (int)lstActivity->GetItemData(longSelected);
222         
223         if (longSelected == -1){
224                 return;
225         }
226         
227         std::map<int,CardDAV*>::iterator CDAVter;
228         
229         CDAVter = ActivityListConn.find(intSelectedData);
230         
231         CDAVter->second->Abort();
232         
233         lstActivity->SetItem(longSelected, 2, _("Stopped"));
237 void frmActivityMgr::StopAllTasks( wxCommandEvent& event ){
239         // Check if activity has been completed already before stopping.
240         
241         // TODO: Look through for '1' and stop the running task(s).
242         
243         long longSelected = -1;
244         int intSelectedData = 0;
245                 
246         longSelected = lstActivity->GetNextItem(longSelected, 
247                 wxLIST_NEXT_ALL,
248                 wxLIST_STATE_SELECTED);
250         intSelectedData = (int)lstActivity->GetItemData(longSelected);
251         
252         if (longSelected == -1){
253                 return;
254         }
255         
256         std::map<int,CardDAV*>::iterator CDAVter;
257         
258         CDAVter = ActivityListConn.find(intSelectedData);
259         
260         CDAVter->second->Abort();
261         
262         lstActivity->SetItem(longSelected, 2, _("Stopped"));
263         AnimationTimer.StopAnimation();
264         bmpActivity->SetBitmap(SleepBitmap);
265         lblDetails->SetLabel(_("No activity."));
269 void frmActivityMgr::RetryTask( wxCommandEvent& event ){
271         // Check if activity has been completed already before retrying.
272         
273         long longSelected = -1;
274         int intSelectedData = 0;
275                 
276         longSelected = lstActivity->GetNextItem(longSelected, 
277                 wxLIST_NEXT_ALL,
278                 wxLIST_STATE_SELECTED);
280         intSelectedData = (int)lstActivity->GetItemData(longSelected);
281         
282         if (longSelected == -1){
283                 return;
284         }
285         
286         std::map<int,CardDAV*>::iterator CDAVter;
287         
288         CDAVter = ActivityListConn.find(intSelectedData);
289         
290         // Restart the task.
291         
292         //CDAVter->second.Abort();
293         
294         std::map<int,int>::iterator Iter;
295         Iter = ActivityList.find(intSelectedData);
296         
297         Iter->second = 0;
298         
299         AnimationTimer.StartAnimation();
300         
301         if (!ActProcessTimer.IsRunning()) {
302         
303                 ActProcessTimer.Start(150, FALSE);
304                 ActListProcTimer.Start(150, FALSE);
305         
306         }
307         
308         //lstActivity->SetItem(longSelected, 2, _("Processing..."));
312 int frmActivityMgr::GetTaskStatus(int intTaskID){
314         int intResult = 2;
315         
316         if (ActivityList.find(intTaskID) == ActivityList.end()){
317         
318                 return intResult;
319         
320         }
321         
322         std::map<int,int>::iterator taskiter = ActivityList.find(intTaskID);
323         intResult = taskiter->second;
324         
325         return intResult;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy