Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
configure: cURL 7.52.0 required
[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;
30         coldata.SetId(ActivityTaskID);
31         coldata.SetData(ActivityTaskID);
33         if (ApplicationSleepMode == FALSE){
34                 
35                 AnimationTimer.StartAnimation();
36                 
37         }
39         // Get the preferences file.
40         
41         wxString PrefFilename = GetUserPrefDir();
42         
43         XABPreferences PrefData(PrefFilename);
45         wxString AccountName;
46         wxString AccountDir;
47         wxString AccountAddress;
48         int AccountPort = 0;
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.
55         
56         for (int i = 0; i < PrefData.accounts.GetCount(); i++){
57         
58                 AccountDir = PrefData.accounts.GetAccountDirectory(i);
59                 
60                 AccountDir.Trim();
61                 AccountDir.Append(wxT(".carddav"));
62         
63                 if (AccountDir == TaskAccount){
64                 
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);
72                         
73                         AccountName.Trim();
74                         AccountAddress.Trim();
75                         //AccountPort.Trim();
76                         AccountUsername.Trim();
77                         AccountPassword.Trim();
78                         AccountPrefix.Trim();
79                         break;
80                 
81                 }
82         
83         }
84         
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;       
94         // TaskType:
95         // 0 - Add a contact.
96         // 1 - Update a contact.
97         // 2 - Delete a contact.
98         // 3 - Account syncronisation.
100         if (TaskType == 0){             
102                 coldata.SetText(_("Adding Contact '") + TaskDetail + _("'"));
103                 itemindex = lstActivity->InsertItem(coldata);
104                 
105                 lstActivity->SetItem(itemindex, 1, AccountName);
106                 lstActivity->SetItem(itemindex, 2, _("Queued"));
107                 
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();
114                 
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));
126                 
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));
130         
131         } else if (TaskType == 1){
132         
133                 coldata.SetText(_("Updating Contact '") + TaskDetail + _("'"));
134                 itemindex = lstActivity->InsertItem(coldata);           
135                 
136                 lstActivity->SetItem(itemindex, 1, AccountName);
137                 lstActivity->SetItem(itemindex, 2, _("Queued"));
138                 
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();
143                 
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));
155                 
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));
159         
160         } else if (TaskType == 2){
162                 coldata.SetText(_("Deleting Contact '") + TaskDetail + _("'"));
163                 itemindex = lstActivity->InsertItem(coldata);
164                 
165                 lstActivity->SetItem(itemindex, 1, AccountName);
166                 lstActivity->SetItem(itemindex, 2, _("Queued"));
167                 
168                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
169                 
170                 CardDAV2 *ConnObject = new CardDAV2(AccountAddress.ToStdString(), AccountPort, AccountUsername.ToStdString(), AccountPassword.ToStdString(), AccountSSL, AccountPrefix.ToStdString(), AccountDir.ToStdString());
171                 ConnObject->SetupConnectionObject();
172                 
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));
182         
183         } else if (TaskType == 3){
185                 coldata.SetText(_("Syncronising All Contacts"));
186                 itemindex = lstActivity->InsertItem(coldata);
187                 
188                 lstActivity->SetItem(itemindex, 1, AccountName);
189                 lstActivity->SetItem(itemindex, 2, _("Queued"));
190                 
191                 CardDAV2 *ConnObject = new CardDAV2(AccountAddress.ToStdString(), AccountPort, AccountUsername.ToStdString(), AccountPassword.ToStdString(), AccountSSL, AccountPrefix.ToStdString(), AccountDir.ToStdString());
192                 ConnObject->SetupConnectionObject();
193                 
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));
202         
203         }
204         
205         ProcessTasksData = TRUE;
206         
207         if (!ActProcessTimer.IsRunning() && ApplicationSleepMode == FALSE) {
208         
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);
217         
218         }
219         
220         // Update the recovery database.
221         
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;
238                 
239         longSelected = lstActivity->GetNextItem(longSelected, 
240                 wxLIST_NEXT_ALL,
241                 wxLIST_STATE_SELECTED);
243         intSelectedData = (int)lstActivity->GetItemData(longSelected);
244         
245         if (longSelected == -1){
246                 return;
247         }
248         
249         lstActivity->SetItem(longSelected, 2, _("Stopped"));
253 void frmActivityMgr::StopAllTasks( wxCommandEvent& event ){
255         // Check if activity has been completed already before stopping.
256         
257         // TODO: Look through for '1' and stop the running task(s).
258         
259         long longSelected = -1;
260         int intSelectedData = 0;
261                 
262         longSelected = lstActivity->GetNextItem(longSelected, 
263                 wxLIST_NEXT_ALL,
264                 wxLIST_STATE_SELECTED);
266         intSelectedData = (int)lstActivity->GetItemData(longSelected);
267         
268         if (longSelected == -1){
269                 return;
270         }
271         
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.
282         
283         long longSelected = -1;
284         int intSelectedData = 0;
285                 
286         longSelected = lstActivity->GetNextItem(longSelected, 
287                 wxLIST_NEXT_ALL,
288                 wxLIST_STATE_SELECTED);
290         intSelectedData = (int)lstActivity->GetItemData(longSelected);
291         
292         if (longSelected == -1){
293                 return;
294         }
295         
296         // Restart the task.
297         
298         //CDAVter->second.Abort();
299         
300         std::map<int,int>::iterator Iter;
301         Iter = ActivityList.find(intSelectedData);
302         
303         Iter->second = 0;
304         
305         AnimationTimer.StartAnimation();
306         
307         if (!ActProcessTimer.IsRunning()) {
308         
309                 ActProcessTimer.Start(150, FALSE);
310                 ActListProcTimer.Start(150, FALSE);
311         
312         }
313         
314         //lstActivity->SetItem(longSelected, 2, _("Processing..."));
318 int frmActivityMgr::GetTaskStatus(int intTaskID){
320         int intResult = 2;
321         
322         if (ActivityList.find(intTaskID) == ActivityList.end()){
323         
324                 return intResult;
325         
326         }
327         
328         std::map<int,int>::iterator taskiter = ActivityList.find(intTaskID);
329         intResult = taskiter->second;
330         
331         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