0001 ### BITPIM 0002 ### 0003 ### Copyright (C) 2005 Joe Pham <djpham@bitpim.org> 0004 ### 0005 ### This program is free software; you can redistribute it and/or modify 0006 ### it under the terms of the BitPim license as detailed in the LICENSE file. 0007 ### 0008 ### $Id: outlook_tasks.py 2703 2005-12-29 09:21:18Z djpham $ 0009 0010 "Deals with Outlook Tasks import stuff" 0011 0012 # System modules 0013 0014 # wxPython modules 0015 import wx 0016 0017 # BitPim modules 0018 import common_calendar 0019 import native.outlook as ol 0020 import outlook_calendar 0021 import outlook_notes 0022 import todo 0023 0024 #------------------------------------------------------------------------------- 0025 # convertor funcs 0026 _outlook_status={ 0027 ol.outlook_com.constants.olTaskNotStarted: todo.TodoEntry.ST_NotStarted, 0028 ol.outlook_com.constants.olTaskInProgress: todo.TodoEntry.ST_InProgress, 0029 ol.outlook_com.constants.olTaskComplete: todo.TodoEntry.ST_Completed, 0030 ol.outlook_com.constants.olTaskWaiting: todo.TodoEntry.ST_NeedActions, 0031 ol.outlook_com.constants.olTaskDeferred: todo.TodoEntry.ST_Cancelled } 0032 0033 _outlook_priority={ 0034 ol.outlook_com.constants.olImportanceLow: 10, 0035 ol.outlook_com.constants.olImportanceNormal: 5, 0036 ol.outlook_com.constants.olImportanceHigh: 1 } 0037 0038 def _convert_status(dict, v, obj): 0039 return _outlook_status.get(v, None) 0040 def _convert_priority(dict, v, obj): 0041 return _outlook_priority.get(v, 5) 0042 0043 def bp_date_str(dict, v): 0044 try: 0045 if v[0]>=common_calendar.no_end_date[0]: 0046 # no-end date, don't display it 0047 return '' 0048 return '%04d-%02d-%02d'% v[:3] 0049 except (ValueError, TypeError): 0050 return '' 0051 except: 0052 if __debug__: raise 0053 return '' 0054 0055 def status_str(dict, v): 0056 if v: 0057 return todo.TodoEntry.ST_Names[v] 0058 else: 0059 return '' 0060 0061 #------------------------------------------------------------------------------- 0062 class OutlookTasksImportData(outlook_notes.OutlookNotesImportData): 0063 0064 _data_keys=[ 0065 # (Outlook field, MemoEntry field, convertor function) 0066 ('Status', 'status', _convert_status), 0067 ('DateCompleted', 'completion_date', outlook_calendar.to_bp_date), 0068 ('Complete', 'complete', None), 0069 ('Importance', 'priority', _convert_priority), 0070 ('PercentComplete', 'percent_complete', None), 0071 ('DueDate', 'due_date', outlook_calendar.to_bp_date), 0072 ('Subject', 'summary', None), 0073 ('Body', 'note', None), 0074 ('Categories', 'categories', outlook_calendar.convert_categories), 0075 ] 0076 0077 _default_filter={ 0078 'start': None, 0079 'end': None, 0080 'categories': None, 0081 'non_completed': False, 0082 } 0083 0084 _data_item_class=todo.TodoEntry 0085 _default_folder_type='tasks' 0086 0087 def __init__(self, outlook): 0088 outlook_notes.OutlookNotesImportData.__init__(self, outlook) 0089 0090 def _accept(self, e): 0091 # check for Completed tasks 0092 if self._filter['non_completed'] and e['complete']: 0093 return False 0094 # check for the due date 0095 if e['due_date']!=common_calendar.no_end_date: 0096 _date=e['due_date'][:3] 0097 if self._filter['start'] is not None and \ 0098 _date<self._filter['start'][:3]: 0099 return False 0100 if self._filter['end'] is not None and \ 0101 _date>self._filter['end'][:3]: 0102 return False 0103 c=self._filter.get('categories', None) 0104 if not c: 0105 # no categories specified => all catefories allowed. 0106 return True 0107 if [x for x in e['categories'] if x in c]: 0108 return True 0109 return False 0110 0111 def _populate_entry(self, entry, new_entry): 0112 new_entry.status=entry.get('status', todo.TodoEntry.ST_NotStarted) 0113 if entry['completion_date']!=common_calendar.no_end_date: 0114 new_entry.completion_date='%04d%02d%02d'%entry['completion_date'][:3] 0115 new_entry.priority=entry.get('priority', 5) 0116 new_entry.percent_complete=entry.get('percent_complete', 0) 0117 if entry['due_date']!=common_calendar.no_end_date: 0118 new_entry.due_date='%04d%02d%02d'%entry['due_date'][:3] 0119 new_entry.summary=entry.get('summary', None) 0120 new_entry.note=entry.get('note', None) 0121 v=[] 0122 for k in entry.get('categories', []): 0123 v.append({ 'category': k }) 0124 new_entry.categories=v 0125 0126 #------------------------------------------------------------------------------- 0127 class FilterDialog(outlook_notes.FilterDialog): 0128 _has_complete_option=True 0129 0130 #------------------------------------------------------------------------------- 0131 class OutlookImportTasksDialog(outlook_calendar.OutlookImportCalDialog): 0132 _column_labels=[ 0133 ('due_date', 'Due Date', 200, bp_date_str), 0134 ('summary', 'Summary', 400, None), 0135 ('status', 'Status', 200, status_str), 0136 ('categories', 'Category', 200, common_calendar.category_str) 0137 ] 0138 0139 _config_name='import/tasks/outlookdialog' 0140 _browse_label='Outlook Tasks Folder:' 0141 _progress_dlg_title='Outlook Tasks Import' 0142 _error_dlg_title='Outlook Tasks Import Error' 0143 _error_dlg_text='Outlook Tasks Items that failed to import:' 0144 _data_class=OutlookTasksImportData 0145 _filter_dlg_class=FilterDialog 0146
Generated by PyXR 0.9.4