Logo Search packages:      
Sourcecode: wammu version File versions

TalkbackDialog.py

# -*- coding: UTF-8 -*-
# generated by wxGlade 0.4.1 on Thu Feb  8 13:07:50 2007
# vim: expandtab sw=4 ts=4 sts=4:
'''
Wammu - Phone manager
Gammu Phone Database Talkback window
'''
__author__ = 'Michal Čihař'
__email__ = 'michal@cihar.com'
__license__ = '''
Copyright (c) 2003 - 2007 Michal Čihař

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
'''


import httplib
import urllib
import Wammu.Webbrowser
import re
import wx
import Wammu.TalkbackFeaturesDialog
import Wammu.Utils
import Wammu.Data
if Wammu.gammu_error == None:
    import gammu

# begin wxGlade: dependencies
# end wxGlade

class TalkbackDialog(wx.Dialog):
    def __init__(self, parent, config, phoneid = 0, *args, **kwds):
        # begin wxGlade: TalkbackDialog.__init__
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.THICK_FRAME
        wx.Dialog.__init__(self, parent, *args, **kwds)
        self.main_panel = wx.Panel(self, -1)
        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."))
        self.top_static_line = wx.StaticLine(self, -1)
        self.manufacturer_label = wx.StaticText(self.main_panel, -1, _("Manufacturer:"), style=wx.ALIGN_CENTRE)
        self.manufacturer_choice = wx.Choice(self.main_panel, -1, choices=[])
        self.model_label = wx.StaticText(self.main_panel, -1, _("Phone model:"))
        self.model_text_ctrl = wx.TextCtrl(self.main_panel, -1, "")
        self.connection_label = wx.StaticText(self.main_panel, -1, _("Connection type:"))
        self.connection_combo_box = wx.ComboBox(self.main_panel, -1, choices=[], style=wx.CB_DROPDOWN)
        self.gammu_model_label = wx.StaticText(self.main_panel, -1, _("Model in gammu configuration:"))
        self.model_combo_box = wx.ComboBox(self.main_panel, -1, choices=[], style=wx.CB_DROPDOWN)
        self.features_label = wx.StaticText(self.main_panel, -1, _("Working features:"))
        self.features_button = wx.Button(self.main_panel, -1, _("Please select features..."))
        self.gammu_version_text_label = wx.StaticText(self.main_panel, -1, _("Gammu version:"))
        self.gammu_version_label = wx.StaticText(self.main_panel, -1, "")
        self.note_label = wx.StaticText(self.main_panel, -1, _("Note:"))
        self.note_text_ctrl = wx.TextCtrl(self.main_panel, -1, "", style=wx.TE_MULTILINE)
        self.name_label = wx.StaticText(self.main_panel, -1, _("Your name:"))
        self.name_text_ctrl = wx.TextCtrl(self.main_panel, -1, "")
        self.email_label = wx.StaticText(self.main_panel, -1, _("Your email:"))
        self.email_text_ctrl = wx.TextCtrl(self.main_panel, -1, "")
        self.mangle_label = wx.StaticText(self.main_panel, -1, _("Email displaying:"), style=wx.ALIGN_CENTRE)
        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")])
        self.bottom_static_line = wx.StaticLine(self, -1)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.OnFeatures, self.features_button)
        # end wxGlade
        for x in Wammu.Data.Connections:
            self.connection_combo_box.Append(x)
        for x in Wammu.Data.Models:
            self.model_combo_box.Append(x)
        for x in Wammu.Data.ManufacturerMap.keys():
            self.manufacturer_choice.Append(x)
        self.wammu_cfg = config
        self.phoneid = phoneid
        self.features = []
        self.gammu_version_label.SetLabel(gammu.Version()[0])
        self.note_text_ctrl.SetValue('Report has been created using Wammu %s.\n' % Wammu.__version__)
        # Read phone name and manufacturer
        manufacturer = self.wammu_cfg.Read('/Phone-%d/Manufacturer' % phoneid)
        self.manufacturer_choice.SetStringSelection(manufacturer)
        model = self.wammu_cfg.Read('/Phone-%d/Model' % phoneid)
        self.model_text_ctrl.SetValue(model)
        # Set connection type which is being used
        section = self.wammu_cfg.ReadInt('/Gammu/Section')
        config = self.wammu_cfg.gammu.GetConfig(section)
        self.connection_combo_box.SetValue(config['Connection'])
        self.model_combo_box.SetValue(config['Model'])
        self.name_text_ctrl.SetValue(self.wammu_cfg.Read('/User/Name'))
        self.email_text_ctrl.SetValue(self.wammu_cfg.Read('/User/Email'))


    def __set_properties(self):
        # begin wxGlade: TalkbackDialog.__set_properties
        self.SetTitle(_("Gammu Phone Database Talkback"))
        self.features_label.SetToolTipString(_("Select which features work correctly with your phone"))
        self.gammu_version_label.SetToolTipString(_("This information is automatically included in report."))
        self.note_text_ctrl.SetToolTipString(_("Describe some glitches of this phone or other experiences with Gammu."))
        self.email_text_ctrl.SetToolTipString(_("Please enter valid mail here, choose display options bellow. Your email won't be given or sold to anybody."))
        self.mangle_choice.SetToolTipString(_("If you don't want to display email clear text, please select one mangling option."))
        self.mangle_choice.SetSelection(0)
        # end wxGlade

    def __do_layout(self):
        self.button_sizer = wx.StdDialogButtonSizer()
        self.button_sizer.AddButton(wx.Button(self, wx.ID_OK))
        self.button_sizer.AddButton(wx.Button(self, wx.ID_CANCEL))
        self.info_label.Wrap(400)
        # begin wxGlade: TalkbackDialog.__do_layout
        window_grid_sizer = wx.FlexGridSizer(3, 1, 0, 0)
        main_grid_sizer = wx.FlexGridSizer(8, 2, 5, 5)
        window_grid_sizer.Add(self.info_label, 2, wx.ALL|wx.EXPAND, 5)
        window_grid_sizer.Add(self.top_static_line, 0, wx.ALL|wx.EXPAND, 5)
        main_grid_sizer.Add(self.manufacturer_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.manufacturer_choice, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.model_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.model_text_ctrl, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.connection_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.connection_combo_box, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.gammu_model_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.model_combo_box, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.features_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.features_button, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.gammu_version_text_label, 0, wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.gammu_version_label, 0, wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.note_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.note_text_ctrl, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.name_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.name_text_ctrl, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.email_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.email_text_ctrl, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.mangle_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        main_grid_sizer.Add(self.mangle_choice, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        self.main_panel.SetAutoLayout(True)
        self.main_panel.SetSizer(main_grid_sizer)
        main_grid_sizer.Fit(self.main_panel)
        main_grid_sizer.SetSizeHints(self.main_panel)
        main_grid_sizer.AddGrowableRow(5)
        main_grid_sizer.AddGrowableCol(1)
        window_grid_sizer.Add(self.main_panel, 0, wx.EXPAND, 0)
        window_grid_sizer.Add(self.bottom_static_line, 0, wx.ALL|wx.EXPAND, 3)
        self.SetAutoLayout(True)
        self.SetSizer(window_grid_sizer)
        window_grid_sizer.Fit(self)
        window_grid_sizer.SetSizeHints(self)
        window_grid_sizer.AddGrowableRow(1)
        window_grid_sizer.AddGrowableCol(0)
        self.Layout()
        # end wxGlade
        self.button_sizer.Realize()
        window_grid_sizer.Add(self.button_sizer, 0, wx.ALIGN_RIGHT, 0)
        window_grid_sizer.Fit(self)
        self.Layout()

    def OnFeatures(self, event): # wxGlade: TalkbackDialog.<event_handler>
        dlg = Wammu.TalkbackFeaturesDialog.TalkbackFeaturesDialog(self)
        dlg.SetFeatures(self.features)
        if dlg.ShowModal() == wx.ID_OK:
            self.features = dlg.GetFeatures()
            self.features_button.SetLabel(', '.join(self.features))

# end of class TalkbackDialog

def DoTalkback(parent, config, phoneid = 0):
    dlg = TalkbackDialog(parent, config, phoneid)
    ok_matcher = re.compile('Entry created, id=(\d*), url=(.*)')
    fail_matcher = re.compile('Invalid values: (.*)')

    while dlg.ShowModal() == wx.ID_OK:
        if len(dlg.features) == 0:
            wx.MessageDialog(parent,
                _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Supported features'),
                _('Entry not created!'),
                wx.OK | wx.ICON_ERROR).ShowModal()
            continue
        man_str = dlg.manufacturer_choice.GetStringSelection()
        try:
            man_id = Wammu.Data.ManufacturerMap[man_str]
        except:
            wx.MessageDialog(parent,
                _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Manufacturer'),
                _('Entry not created!'),
                wx.OK | wx.ICON_ERROR).ShowModal()
            continue
        garble_id = dlg.mangle_choice.GetSelection()
        try:
            garble_text = Wammu.Data.GarbleMap[garble_id]
        except:
            wx.MessageDialog(parent,
                _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Email displaying'),
                _('Entry not created!'),
                wx.OK | wx.ICON_ERROR).ShowModal()
            continue

        config.Write('/User/Name', dlg.name_text_ctrl.GetValue())
        config.Write('/User/Email', dlg.email_text_ctrl.GetValue())

        params_dict = {
            'irobot': 'wammu',
            'manufacturer': man_id,
            'name': dlg.model_text_ctrl.GetValue(),
            'model': dlg.model_combo_box.GetValue(),
            'connection': dlg.connection_combo_box.GetValue(),
            'note': dlg.note_text_ctrl.GetValue(),
            'author_name': dlg.name_text_ctrl.GetValue(),
            'author_email': dlg.email_text_ctrl.GetValue(),
            'email_garble': garble_text,
            'gammu_version': gammu.Version()[0],
        }
        for x in dlg.features:
            params_dict['fts[%s]' % x] = 1
        params = urllib.urlencode(params_dict)
        headers = {'Content-type': 'application/x-www-form-urlencoded',
                    'Accept': 'text/plain'}
        conn = httplib.HTTPConnection('cihar.com')
        conn.request('POST', '/gammu/phonedb/new.php', params, headers)
        response = conn.getresponse()
        if response.status != 200:
            wx.MessageDialog(parent,
                _('HTTP request failed with status %(code)d (%(text)s), please retry later or create entry manually.') % {
                    'code': response.status,
                    'text': response.reason,
                    },
                _('Entry not created!'),
                wx.OK | wx.ICON_ERROR).ShowModal()
        data = response.read()
        conn.close()
        ok_test = ok_matcher.match(data)
        if ok_test is not None:
            url = 'http://%scihar.com%s' % (Wammu.Utils.GetWebsiteLang(), ok_test.groups()[1])
            if wx.MessageDialog(parent,
                _('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,
                _('Entry created!'),
                wx.YES_NO | wx.ICON_INFORMATION).ShowModal() == wx.ID_YES:
                Wammu.Webbrowser.Open(url)
            config.Write('/Wammu/TalkbackDone', 'yes')
            break
        fail_test = fail_matcher.match(data)
        if fail_test is not None:
            wrong_fields = fail_test.groups()[0]
            wx.MessageDialog(parent,
                _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % wrong_fields,
                _('Entry not created!'),
                wx.OK | wx.ICON_ERROR).ShowModal()
            continue

Generated by  Doxygen 1.6.0   Back to index