1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
5 Module for writing SMS to XML.
7 __author__
= 'Florent Kaisser'
8 __email__
= 'florent.kaisser@free.fr'
10 Copyright © 2008 Florent Kaisser
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 from Wammu
.Utils
import SearchNumber
27 from Wammu
.MessageDisplay
import SmsTextFormat
32 if Wammu
.gammu_error
== None:
35 XMLheader
= '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"sms.xsl\"?>\n'
40 def SMSToXML(cfg
, sms
, lookuplist
= None):
46 text
= SmsTextFormat(cfg
, sms
['Text'], doxml
= True)
48 smsxml
= " <message>\n"
50 if sms
['DateTime'] is not None:
53 smsxml
+= sms
['DateTime'].strftime("%d.%m.%Y %H:%M:%S")
56 smsxml
+= " <dateenc>"
57 smsxml
+= sms
['DateTime'].strftime("%Y%m%d%H%M%S")
58 smsxml
+= "</dateenc>\n"
61 smsxml
+= text
.encode('utf-8')
64 smsxml
+= " <telephone>"
65 smsxml
+= sms
['Number'].encode('utf-8')
66 smsxml
+= "</telephone>\n"
69 smsxml
+= str(sms
['Folder'])
70 smsxml
+= "</folder>\n"
73 smsxml
+= sms
['State']
76 smsxml
+= " </message>\n"
80 def SMSExportXML(parent
, messages
, contacts
):
82 wildcard
= _('XML File') + ' (*.xml)|*.xml|' + _('All files') + ' (*.*)|*.*;*'
85 dlg
= wx
.FileDialog(parent
, _('Select XML file...'), os
.getcwd(), "", wildcard
, wx
.SAVE | wx
.OVERWRITE_PROMPT | wx
.CHANGE_DIR
)
87 if dlg
.ShowModal() != wx
.ID_OK
:
91 ext
= exts
[dlg
.GetFilterIndex()]
92 # Add automatic extension if we know one and file does not
94 if (os
.path
.splitext(path
)[1] == '' and
98 parent
.ShowProgress(_('Saving messages to XML'))
102 f
.write("<messages>\n")
103 for i
in range(count
):
104 if not parent
.progress
.Update(i
* 100 / count
):
106 parent
.SetStatusText(_('Export terminated'))
110 data
= Wammu
.SMSXML
.SMSToXML(parent
.cfg
, sms
, contacts
)
114 f
.write("</messages>\n")
118 wx
.MessageDialog(parent
,
119 _('Creating of file %s failed, bailing out.') % path
,
120 _('Can not create file!'),
121 wx
.OK | wx
.ICON_ERROR
).ShowModal()
123 parent
.SetStatusText(_('Export terminated'))
126 parent
.progress
.Update(100)
128 parent
.SetStatusText(_('%(count)d messages exported to "%(path)s" (%(type)s)') % {'count':count
, 'path':path
, 'type': _('mailbox')})