Module outlook_tasks
[hide private]
[frames] | no frames]

Source Code for Module outlook_tasks

  1  ### BITPIM 
  2  ### 
  3  ### Copyright (C) 2005 Joe Pham <djpham@bitpim.org> 
  4  ### 
  5  ### This program is free software; you can redistribute it and/or modify 
  6  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
  7  ### 
  8  ### $Id: outlook_tasks.py 2703 2005-12-29 09:21:18Z djpham $ 
  9   
 10  "Deals with Outlook Tasks import stuff" 
 11   
 12  # System modules 
 13   
 14  # wxPython modules 
 15  import wx 
 16   
 17  # BitPim modules 
 18  import common_calendar 
 19  import native.outlook as ol 
 20  import outlook_calendar 
 21  import outlook_notes 
 22  import todo 
 23   
 24  #------------------------------------------------------------------------------- 
 25  # convertor funcs 
 26  _outlook_status={ 
 27      ol.outlook_com.constants.olTaskNotStarted: todo.TodoEntry.ST_NotStarted, 
 28      ol.outlook_com.constants.olTaskInProgress: todo.TodoEntry.ST_InProgress, 
 29      ol.outlook_com.constants.olTaskComplete: todo.TodoEntry.ST_Completed, 
 30      ol.outlook_com.constants.olTaskWaiting: todo.TodoEntry.ST_NeedActions, 
 31      ol.outlook_com.constants.olTaskDeferred: todo.TodoEntry.ST_Cancelled } 
 32   
 33  _outlook_priority={ 
 34      ol.outlook_com.constants.olImportanceLow: 10, 
 35      ol.outlook_com.constants.olImportanceNormal: 5, 
 36      ol.outlook_com.constants.olImportanceHigh: 1 } 
 37   
38 -def _convert_status(dict, v, obj):
39 return _outlook_status.get(v, None)
40 -def _convert_priority(dict, v, obj):
41 return _outlook_priority.get(v, 5)
42
43 -def bp_date_str(dict, v):
44 try: 45 if v[0]>=common_calendar.no_end_date[0]: 46 # no-end date, don't display it 47 return '' 48 return '%04d-%02d-%02d'% v[:3] 49 except (ValueError, TypeError): 50 return '' 51 except: 52 if __debug__: raise 53 return ''
54
55 -def status_str(dict, v):
56 if v: 57 return todo.TodoEntry.ST_Names[v] 58 else: 59 return ''
60 61 #-------------------------------------------------------------------------------
62 -class OutlookTasksImportData(outlook_notes.OutlookNotesImportData):
63 64 _data_keys=[ 65 # (Outlook field, MemoEntry field, convertor function) 66 ('Status', 'status', _convert_status), 67 ('DateCompleted', 'completion_date', outlook_calendar.to_bp_date), 68 ('Complete', 'complete', None), 69 ('Importance', 'priority', _convert_priority), 70 ('PercentComplete', 'percent_complete', None), 71 ('DueDate', 'due_date', outlook_calendar.to_bp_date), 72 ('Subject', 'summary', None), 73 ('Body', 'note', None), 74 ('Categories', 'categories', outlook_calendar.convert_categories), 75 ] 76 77 _default_filter={ 78 'start': None, 79 'end': None, 80 'categories': None, 81 'non_completed': False, 82 } 83 84 _data_item_class=todo.TodoEntry 85 _default_folder_type='tasks' 86
87 - def __init__(self, outlook):
89
90 - def _accept(self, e):
91 # check for Completed tasks 92 if self._filter['non_completed'] and e['complete']: 93 return False 94 # check for the due date 95 if e['due_date']!=common_calendar.no_end_date: 96 _date=e['due_date'][:3] 97 if self._filter['start'] is not None and \ 98 _date<self._filter['start'][:3]: 99 return False 100 if self._filter['end'] is not None and \ 101 _date>self._filter['end'][:3]: 102 return False 103 c=self._filter.get('categories', None) 104 if not c: 105 # no categories specified => all catefories allowed. 106 return True 107 if [x for x in e['categories'] if x in c]: 108 return True 109 return False
110
111 - def _populate_entry(self, entry, new_entry):
112 new_entry.status=entry.get('status', todo.TodoEntry.ST_NotStarted) 113 if entry['completion_date']!=common_calendar.no_end_date: 114 new_entry.completion_date='%04d%02d%02d'%entry['completion_date'][:3] 115 new_entry.priority=entry.get('priority', 5) 116 new_entry.percent_complete=entry.get('percent_complete', 0) 117 if entry['due_date']!=common_calendar.no_end_date: 118 new_entry.due_date='%04d%02d%02d'%entry['due_date'][:3] 119 new_entry.summary=entry.get('summary', None) 120 new_entry.note=entry.get('note', None) 121 v=[] 122 for k in entry.get('categories', []): 123 v.append({ 'category': k }) 124 new_entry.categories=v
125 126 #-------------------------------------------------------------------------------
127 -class FilterDialog(outlook_notes.FilterDialog):
128 _has_complete_option=True
129 130 #-------------------------------------------------------------------------------
131 -class OutlookImportTasksDialog(outlook_calendar.OutlookImportCalDialog):
132 _column_labels=[ 133 ('due_date', 'Due Date', 200, bp_date_str), 134 ('summary', 'Summary', 400, None), 135 ('status', 'Status', 200, status_str), 136 ('categories', 'Category', 200, common_calendar.category_str) 137 ] 138 139 _config_name='import/tasks/outlookdialog' 140 _browse_label='Outlook Tasks Folder:' 141 _progress_dlg_title='Outlook Tasks Import' 142 _error_dlg_title='Outlook Tasks Import Error' 143 _error_dlg_text='Outlook Tasks Items that failed to import:' 144 _data_class=OutlookTasksImportData 145 _filter_dlg_class=FilterDialog
146