1 # -*- coding: UTF-8 -*-
2 # generated by wxGlade 0.4.1 on Thu Feb 8 13:07:50 2007
3 # vim: expandtab sw=4 ts=4 sts=4:
6 Gammu Phone Database Talkback window
8 __author__
= 'Michal Čihař'
9 __email__
= 'michal@cihar.com'
11 Copyright © 2003 - 2008 Michal Čihař
13 This program is free software; you can redistribute it and/or modify it
14 under the terms of the GNU General Public License version 2 as published by
15 the Free Software Foundation.
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 import Wammu
.Webbrowser
33 import Wammu
.TalkbackFeaturesDialog
36 if Wammu
.gammu_error
== None:
39 # begin wxGlade: dependencies
42 class TalkbackDialog(wx
.Dialog
):
43 def __init__(self
, parent
, config
, phoneid
= 0, *args
, **kwds
):
44 # begin wxGlade: TalkbackDialog.__init__
45 kwds
["style"] = wx
.DEFAULT_DIALOG_STYLE|wx
.RESIZE_BORDER|wx
.THICK_FRAME
46 wx
.Dialog
.__init
__(self
, parent
, *args
, **kwds
)
47 self
.main_panel
= wx
.Panel(self
, -1)
48 self
.info_label
= wx
.StaticText(self
, -1, _("Please share your experiences with Wammu and Gammu which is backend library. When you fill in following form, other users can benefit from your experiences in Gammu Phone Database. Only information you see here will be submited."))
49 self
.top_static_line
= wx
.StaticLine(self
, -1)
50 self
.manufacturer_label
= wx
.StaticText(self
.main_panel
, -1, _("Manufacturer:"), style
=wx
.ALIGN_CENTRE
)
51 self
.manufacturer_choice
= wx
.Choice(self
.main_panel
, -1, choices
=[])
52 self
.model_label
= wx
.StaticText(self
.main_panel
, -1, _("Phone model:"))
53 self
.model_text_ctrl
= wx
.TextCtrl(self
.main_panel
, -1, "")
54 self
.connection_label
= wx
.StaticText(self
.main_panel
, -1, _("Connection type:"))
55 self
.connection_combo_box
= wx
.ComboBox(self
.main_panel
, -1, choices
=[], style
=wx
.CB_DROPDOWN
)
56 self
.gammu_model_label
= wx
.StaticText(self
.main_panel
, -1, _("Model in gammu configuration:"))
57 self
.model_combo_box
= wx
.ComboBox(self
.main_panel
, -1, choices
=[], style
=wx
.CB_DROPDOWN
)
58 self
.features_label
= wx
.StaticText(self
.main_panel
, -1, _("Working features:"))
59 self
.features_button
= wx
.Button(self
.main_panel
, -1, _("Please select features..."))
60 self
.gammu_version_text_label
= wx
.StaticText(self
.main_panel
, -1, _("Gammu version:"))
61 self
.gammu_version_label
= wx
.StaticText(self
.main_panel
, -1, "")
62 self
.note_label
= wx
.StaticText(self
.main_panel
, -1, _("Note:"))
63 self
.note_text_ctrl
= wx
.TextCtrl(self
.main_panel
, -1, "", style
=wx
.TE_MULTILINE
)
64 self
.name_label
= wx
.StaticText(self
.main_panel
, -1, _("Your name:"))
65 self
.name_text_ctrl
= wx
.TextCtrl(self
.main_panel
, -1, "")
66 self
.email_label
= wx
.StaticText(self
.main_panel
, -1, _("Your email:"))
67 self
.email_text_ctrl
= wx
.TextCtrl(self
.main_panel
, -1, "")
68 self
.mangle_label
= wx
.StaticText(self
.main_panel
, -1, _("Email displaying:"), style
=wx
.ALIGN_CENTRE
)
69 self
.mangle_choice
= wx
.Choice(self
.main_panel
, -1, choices
=[_("Use [at] and [dot]"), _("Insert NOSPAM text at random position"), _("Display it normally"), _("Don't show email at all")])
70 self
.bottom_static_line
= wx
.StaticLine(self
, -1)
72 self
.__set
_properties
()
75 self
.Bind(wx
.EVT_BUTTON
, self
.OnFeatures
, self
.features_button
)
77 self
.ns_string
= '<%s>' % _('Not supported')
78 self
.connection_combo_box
.Append(self
.ns_string
)
79 for x
in Wammu
.Data
.Connections
:
80 self
.connection_combo_box
.Append(x
)
81 for x
in Wammu
.Data
.Models
:
82 self
.model_combo_box
.Append(x
)
83 for x
in Wammu
.Data
.ManufacturerMap
.keys():
84 self
.manufacturer_choice
.Append(x
)
85 self
.wammu_cfg
= config
86 self
.phoneid
= phoneid
88 self
.gammu_version_label
.SetLabel(gammu
.Version()[0])
89 self
.note_text_ctrl
.SetValue('Report has been created using Wammu %s.\n' % Wammu
.__version
__)
90 # Read phone name and manufacturer
91 manufacturer
= self
.wammu_cfg
.Read('/Phone-%d/Manufacturer' % phoneid
)
92 self
.manufacturer_choice
.SetStringSelection(manufacturer
)
93 model
= self
.wammu_cfg
.Read('/Phone-%d/Model' % phoneid
)
94 self
.model_text_ctrl
.SetValue(model
)
95 # Set connection type which is being used
96 section
= self
.wammu_cfg
.ReadInt('/Gammu/Section')
97 config
= self
.wammu_cfg
.gammu
.GetConfig(section
)
98 self
.connection_combo_box
.SetValue(config
['Connection'])
99 self
.model_combo_box
.SetValue(config
['Model'])
100 self
.name_text_ctrl
.SetValue(self
.wammu_cfg
.Read('/User/Name'))
101 self
.email_text_ctrl
.SetValue(self
.wammu_cfg
.Read('/User/Email'))
104 def __set_properties(self
):
105 # begin wxGlade: TalkbackDialog.__set_properties
106 self
.SetTitle(_("Gammu Phone Database Talkback"))
107 self
.features_label
.SetToolTipString(_("Select which features work correctly with your phone"))
108 self
.gammu_version_label
.SetToolTipString(_("This information is automatically included in report."))
109 self
.note_text_ctrl
.SetToolTipString(_("Describe some glitches of this phone or other experiences with Gammu."))
110 self
.email_text_ctrl
.SetToolTipString(_("Please enter valid mail here, choose display options bellow. Your email won't be given or sold to anybody."))
111 self
.mangle_choice
.SetToolTipString(_("If you don't want to display email clear text, please select one mangling option."))
112 self
.mangle_choice
.SetSelection(0)
115 def __do_layout(self
):
116 self
.button_sizer
= wx
.StdDialogButtonSizer()
117 self
.button_sizer
.AddButton(wx
.Button(self
, wx
.ID_OK
))
118 self
.button_sizer
.AddButton(wx
.Button(self
, wx
.ID_CANCEL
))
119 self
.info_label
.Wrap(400)
120 # begin wxGlade: TalkbackDialog.__do_layout
121 window_grid_sizer
= wx
.FlexGridSizer(3, 1, 0, 0)
122 main_grid_sizer
= wx
.FlexGridSizer(8, 2, 5, 5)
123 window_grid_sizer
.Add(self
.info_label
, 2, wx
.ALL|wx
.EXPAND
, 5)
124 window_grid_sizer
.Add(self
.top_static_line
, 0, wx
.ALL|wx
.EXPAND
, 5)
125 main_grid_sizer
.Add(self
.manufacturer_label
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 0)
126 main_grid_sizer
.Add(self
.manufacturer_choice
, 0, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
127 main_grid_sizer
.Add(self
.model_label
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 0)
128 main_grid_sizer
.Add(self
.model_text_ctrl
, 0, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
129 main_grid_sizer
.Add(self
.connection_label
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 0)
130 main_grid_sizer
.Add(self
.connection_combo_box
, 0, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
131 main_grid_sizer
.Add(self
.gammu_model_label
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 0)
132 main_grid_sizer
.Add(self
.model_combo_box
, 0, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
133 main_grid_sizer
.Add(self
.features_label
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 0)
134 main_grid_sizer
.Add(self
.features_button
, 0, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
135 main_grid_sizer
.Add(self
.gammu_version_text_label
, 0, wx
.ADJUST_MINSIZE
, 0)
136 main_grid_sizer
.Add(self
.gammu_version_label
, 0, wx
.ADJUST_MINSIZE
, 0)
137 main_grid_sizer
.Add(self
.note_label
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 0)
138 main_grid_sizer
.Add(self
.note_text_ctrl
, 0, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
139 main_grid_sizer
.Add(self
.name_label
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 0)
140 main_grid_sizer
.Add(self
.name_text_ctrl
, 0, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
141 main_grid_sizer
.Add(self
.email_label
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 0)
142 main_grid_sizer
.Add(self
.email_text_ctrl
, 0, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
143 main_grid_sizer
.Add(self
.mangle_label
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 0)
144 main_grid_sizer
.Add(self
.mangle_choice
, 0, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
145 self
.main_panel
.SetAutoLayout(True)
146 self
.main_panel
.SetSizer(main_grid_sizer
)
147 main_grid_sizer
.Fit(self
.main_panel
)
148 main_grid_sizer
.SetSizeHints(self
.main_panel
)
149 main_grid_sizer
.AddGrowableRow(5)
150 main_grid_sizer
.AddGrowableCol(1)
151 window_grid_sizer
.Add(self
.main_panel
, 0, wx
.EXPAND
, 0)
152 window_grid_sizer
.Add(self
.bottom_static_line
, 0, wx
.ALL|wx
.EXPAND
, 3)
153 self
.SetAutoLayout(True)
154 self
.SetSizer(window_grid_sizer
)
155 window_grid_sizer
.Fit(self
)
156 window_grid_sizer
.SetSizeHints(self
)
157 window_grid_sizer
.AddGrowableRow(1)
158 window_grid_sizer
.AddGrowableCol(0)
161 self
.button_sizer
.Realize()
162 window_grid_sizer
.Add(self
.button_sizer
, 0, wx
.ALIGN_RIGHT
, 0)
163 window_grid_sizer
.Fit(self
)
166 def OnFeatures(self
, event
): # wxGlade: TalkbackDialog.<event_handler>
167 dlg
= Wammu
.TalkbackFeaturesDialog
.TalkbackFeaturesDialog(self
)
168 dlg
.SetFeatures(self
.features
)
169 if dlg
.ShowModal() == wx
.ID_OK
:
170 self
.features
= dlg
.GetFeatures()
171 self
.features_button
.SetLabel(', '.join(self
.features
))
173 # end of class TalkbackDialog
175 def DoTalkback(parent
, config
, phoneid
= 0):
176 dlg
= TalkbackDialog(parent
, config
, phoneid
)
177 ok_matcher
= re
.compile('Entry created, id=(\d*), url=(.*)')
178 fail_matcher
= re
.compile('Invalid values: (.*)')
180 while dlg
.ShowModal() == wx
.ID_OK
:
181 connection
= dlg
.connection_combo_box
.GetValue()
182 if connection
== dlg
.ns_string
:
184 if len(dlg
.features
) == 0 and connection
!= 'NULL':
185 wx
.MessageDialog(parent
,
186 _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Supported features'),
187 _('Entry not created!'),
188 wx
.OK | wx
.ICON_ERROR
).ShowModal()
190 elif len(dlg
.features
) != 0 and connection
== 'NULL':
191 wx
.MessageDialog(parent
,
192 _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Supported features'),
193 _('Entry not created!'),
194 wx
.OK | wx
.ICON_ERROR
).ShowModal()
196 man_str
= dlg
.manufacturer_choice
.GetStringSelection()
198 man_id
= Wammu
.Data
.ManufacturerMap
[man_str
]
200 wx
.MessageDialog(parent
,
201 _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Manufacturer'),
202 _('Entry not created!'),
203 wx
.OK | wx
.ICON_ERROR
).ShowModal()
205 garble_id
= dlg
.mangle_choice
.GetSelection()
207 garble_text
= Wammu
.Data
.GarbleMap
[garble_id
]
209 wx
.MessageDialog(parent
,
210 _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Email displaying'),
211 _('Entry not created!'),
212 wx
.OK | wx
.ICON_ERROR
).ShowModal()
215 # Remember user information for next run
216 config
.Write('/User/Name', dlg
.name_text_ctrl
.GetValue())
217 config
.Write('/User/Email', dlg
.email_text_ctrl
.GetValue())
219 # Prepare data to post
222 'manufacturer': man_id
,
223 'name': dlg
.model_text_ctrl
.GetValue(),
224 'model': dlg
.model_combo_box
.GetValue(),
225 'connection': connection
,
226 'note': dlg
.note_text_ctrl
.GetValue(),
227 'author_name': dlg
.name_text_ctrl
.GetValue(),
228 'author_email': dlg
.email_text_ctrl
.GetValue(),
229 'email_garble': garble_text
,
230 'gammu_version': gammu
.Version()[0],
232 for x
in dlg
.features
:
233 params_dict
['fts[%s]' % x
] = 1
235 # Convert unicode to raw utf-8 strigns so that they can be properly
236 # handled by urllib and later by website
237 for x
in params_dict
.keys():
238 if type(params_dict
[x
]) == unicode:
239 params_dict
[x
] = params_dict
[x
].encode('utf-8')
241 # Encode request and prepare headers
242 params
= urllib
.urlencode(params_dict
)
243 headers
= {'Content-type': 'application/x-www-form-urlencoded',
244 'Accept': 'text/plain'}
247 conn
= httplib
.HTTPConnection('cihar.com')
248 conn
.request('POST', '/gammu/phonedb/new.php', params
, headers
)
250 # Check request response
251 response
= conn
.getresponse()
252 if response
.status
!= 200:
253 wx
.MessageDialog(parent
,
254 _('HTTP request failed with status %(code)d (%(text)s), please retry later or create entry manually.') % {
255 'code': response
.status
,
256 'text': response
.reason
,
258 _('Entry not created!'),
259 wx
.OK | wx
.ICON_ERROR
).ShowModal()
262 # Verify acquired data
263 data
= response
.read()
265 ok_test
= ok_matcher
.match(data
)
266 if ok_test
is not None:
267 url
= 'http://%scihar.com%s' % (Wammu
.Utils
.GetWebsiteLang(), ok_test
.groups()[1])
268 if wx
.MessageDialog(parent
,
269 _('Entry in Gammu Phone Database has been created, you can see it on <%s> URL.\nDo you want to open it in browser now?') % url
,
271 wx
.YES_NO | wx
.ICON_INFORMATION
).ShowModal() == wx
.ID_YES
:
272 Wammu
.Webbrowser
.Open(url
)
273 config
.Write('/Wammu/TalkbackDone', 'yes')
275 fail_test
= fail_matcher
.match(data
)
276 if fail_test
is not None:
277 wrong_fields
= fail_test
.groups()[0]
278 wx
.MessageDialog(parent
,
279 _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % wrong_fields
,
280 _('Entry not created!'),
281 wx
.OK | wx
.ICON_ERROR
).ShowModal()