[ADD]: Images: caldav, crm_caldav, document_webdav, project_caldav
[odoo/odoo.git] / addons / caldav / wizard / caldav_browse.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from osv import osv, fields
23 from tools import config
24 import base64
25 import addons
26 from tools.translate import _
27
28 class caldav_browse(osv.osv_memory):
29     
30     __doc = {
31     
32     'other' : _("""
33   * Webdav server that provides remote access to calendar
34   * Synchronisation of calendar using WebDAV
35   * Customize calendar event and todo attribute with any of OpenERP model
36   * Provides iCal Import/Export functionality
37
38     To access Calendars using CalDAV clients, point them to:
39         http://HOSTNAME:PORT/webdav/DATABASE_NAME/calendars/users/USERNAME/c
40
41     To access OpenERP Calendar using WebCal to remote site use the URL like:
42         http://HOSTNAME:PORT/webdav/DATABASE_NAME/Calendars/CALENDAR_NAME.ics
43
44       Where,
45         HOSTNAME: Host on which OpenERP server(With webdav) is running
46         PORT : Port on which OpenERP server is running (By Default : 8069)
47         DATABASE_NAME: Name of database on which OpenERP Calendar is created
48         CALENDAR_NAME: Name of calendar to access
49      """),
50      
51      
52      
53      'iphone' : _("""
54     For SSL specific configuration see the documentation below
55
56 Now, to setup the calendars, you need to:
57
58 1. Click on the "Settings" and go to the "Mail, Contacts, Calendars" page.
59 2. Go to "Add account..."
60 3. Click on "Other"
61 4. From the "Calendars" group, select "Add CalDAV Account"
62
63 5. Enter the host's name 
64    (ie : if the url is http://openerp.com:8069/webdav/db_1/calendars/ , openerp.com is the host)
65
66 6. Fill Username and password with your openerp login and password
67
68 7. As a description, you can either leave the server's name or
69    something like "OpenERP calendars".
70
71 9. If you are not using a SSL server, you'll get an error, do not worry and push "Continue"
72
73 10. Then click to "Advanced Settings" to specify the right
74     ports and paths. 
75     
76 11. Specify the port for the OpenERP server: 8071 for SSL, 8069 without.
77
78 12. Set the "Account URL" to the right path of the OpenERP webdav:
79     the url given by the wizard (ie : http://my.server.ip:8069/webdav/dbname/calendars/ )
80
81 11. Click on Done. The phone will hopefully connect to the OpenERP server
82     and verify it can use the account.
83
84 12. Go to the main menu of the iPhone and enter the Calendar application.
85     Your OpenERP calendars will be visible inside the selection of the
86     "Calendars" button.
87     Note that when creating a new calendar entry, you will have to specify
88     which calendar it should be saved at.
89
90
91
92 IF you need SSL (and your certificate is not a verified one, as usual),
93 then you first will need to let the iPhone trust that. Follow these
94 steps:
95
96     s1. Open Safari and enter the https location of the OpenERP server:
97       https://my.server.ip:8071/
98       (assuming you have the server at "my.server.ip" and the HTTPS port
99       is the default 8071)
100     s2. Safari will try to connect and issue a warning about the certificate
101       used. Inspect the certificate and click "Accept" so that iPhone
102       now trusts it.   
103     """),
104     'android' : _("""
105 Prerequire
106 ----------
107 There is no buit-in way to synchronize calendar with caldav.
108 So you need to install a third part software : Calendar (CalDav) 
109 for now it's the only one
110
111 configuration
112 -------------
113
114 1. Open Calendar Sync
115    I'll get an interface with 2 tabs
116    Stay on the first one
117    
118 2. CaDAV Calendar URL : put the URL given above (ie : http://host.com:8069/webdav/db/calendars/users/demo/c/Meetings)
119
120 3. Put your openerp username and password
121
122 4. If your server don't use SSL, you'll get a warnign, say "Yes"
123
124 5. Then you can synchronize manually or custom the settings to synchronize every x minutes.
125     
126     """),
127     
128      'evolution' : _("""
129     1. Go to Calendar View
130
131     2. File -> New -> Calendar
132
133     3. Fill the form 
134         - type : CalDav
135         - name : Whaterver you want (ie : Meeting)
136         - url : http://HOST:PORT/webdav/DB_NAME/calendars/users/USER/c/Meetings (ie : http://localhost:8069/webdav/db_1/calendars/users/demo/c/Meetings) the one given on the top of this window
137         - uncheck "User SSL"
138         - Username : Your username (ie : Demo)
139         - Refresh : everytime you want that evolution synchronize the data with the server
140
141     4. Click ok and give your openerp password
142
143     5. A new calendar named with the name you gave should appear on the left side.     
144      """),
145      
146      
147      'thunderbird' : _("""
148 Prerequire
149 ----------
150 If you are using thunderbird, first you need to install the lightning module
151 http://www.mozilla.org/projects/calendar/lightning/
152
153 configuration
154 -------------
155
156 1. Go to Calendar View
157
158 2. File -> New Calendar
159
160 3. Chosse "On the Network"
161
162 4. for format choose CalDav
163    and as location the url given above (ie : http://host.com:8069/webdav/db/calendars/users/demo/c/Meetings)
164    
165 5. Choose a name and a color for the Calendar, and we advice you to uncheck "alarm"
166
167 6. Then put your openerp login and password (to give the password only check the box "Use password Manager to remember this password"
168
169 7. Then Finish, your meetings should appear now in your calendar view
170 """),
171     }
172     
173     
174     _name = 'caldav.browse'
175     _description = 'Caldav Browse'
176
177     _columns = {
178         'url' : fields.char('Caldav Server', size=264, required=True, help="Url of the caldav server, use for synchronization"),
179         #'doc_link':fields.char('Caldav Documentation', size="264", help="The link to Caldav Online Documentation.", readonly=True),
180         'description':fields.text('Description', readonly=True)
181     }
182
183     def default_get(self, cr, uid, fields, context=None):
184         res = {}
185         host = ''
186         port = ''
187         prefix = 'http://'  
188         if not config.get('xmlrpc'):
189             if not config.get('netrpc'):
190                 prefix = 'https://' 
191                 host = config.get('xmlrpcs_interface', None)
192                 port = config.get('xmlrpcs_port', 8071)
193             else:
194                 host = config.get('netrpc_interface', None)
195                 port = config.get('netrpc_port',8070) 
196         else: 
197             host = config.get('xmlrpc_interface', None)
198             port = config.get('xmlrpc_port',8069)
199         if host ==  '' or None:
200                 host = 'localhost'
201                 port = 8069
202         if not config.get_misc('webdav','enable',True):
203             raise Exception("WebDAV is disabled, cannot continue")
204         user_pool = self.pool.get('res.users')
205         current_user = user_pool.browse(cr, uid, uid, context=context)
206         pref_obj = self.pool.get('user.preference')
207         pref_ids = pref_obj.browse(cr, uid ,context.get('rec_id',False), context=context)
208         #TODO write documentation
209         res['description'] = self.__doc['other']
210         if pref_ids:
211             pref_ids = pref_ids[0] 
212             if pref_ids.device == 'iphone':
213                 url = host + ':' + str(port) + '/'+ pref_ids.service + '/' + cr.dbname + '/'+'calendars/'
214             else :
215                 url = host + ':' + str(port) + '/'+ pref_ids.service + '/' + cr.dbname + '/'+'calendars/'+ 'users/'+ current_user.login + '/'+ pref_ids.collection.name+ '/'+ pref_ids.calendar.name
216             
217             res['description'] = self.__doc.get(pref_ids.device , self.__doc['other'])
218         file = open(addons.get_module_resource('caldav','doc', 'caldav_doc.pdf'),'rb')
219         res['caldav_doc_file'] = base64.encodestring(file.read())
220         
221         #res['doc_link'] = 'http://doc.openerp.com/'
222         res['url'] = prefix+url
223         return res
224
225     def browse_caldav(self, cr, uid, ids, context):
226
227         return {}
228
229 caldav_browse()
230
231 class user_preference(osv.osv_memory):
232     
233     _name = 'user.preference'
234     _description = 'User preference Form'
235
236     _columns = {
237                'collection' :fields.many2one('document.directory', "Calendar Collection", required=True, domain = [('calendar_collection', '=', True)]),
238                'calendar' :fields.many2one('basic.calendar', 'Calendar', required=True),
239                'service': fields.selection([('webdav','CalDAV')], "Services"),
240                'device' : fields.selection([('other', 'Other'), ('iphone', 'iPhone'), ('android', 'Android based device'),('thunderbird', 'Sunbird/Thunderbird'), ('evolution','Evolution')], "Software/Devices"),
241     }
242     
243     def _get_default_calendar(self, cr, uid, context):
244         if context == None:
245             context = {}
246         name = context.get('cal_name')
247         
248         collection_obj = self.pool.get('basic.calendar')
249         ids = collection_obj.search(cr, uid, [('name', '=', name)])
250         return ids[0]
251        
252         
253     def _get_default_collection(self, cr, uid, context):
254         collection_obj = self.pool.get('document.directory')
255         ids = collection_obj.search(cr, uid, [('name', '=', 'c')])
256         return ids[0]
257     
258         
259     _defaults={
260               'service': 'webdav',
261               'collection' : _get_default_collection,
262               'calendar' : _get_default_calendar,
263               'device' : 'other',
264               
265     }    
266    
267     def open_window(self, cr, uid, ids, context=None):
268         obj_model = self.pool.get('ir.model.data')
269         model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','caldav_Browse')])
270         resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])
271         context.update({'rec_id': ids})
272         return {
273             'view_type': 'form',
274             'view_mode': 'form',
275             'res_model': 'caldav.browse',
276             'views': [(resource_id,'form')],
277             'type': 'ir.actions.act_window',
278             'target': 'new',
279             'context': context,
280         }
281     
282     
283 user_preference()