17
17
from gi.repository import Gtk
18
from qreator_lib.i18n import _
18
19
from qreator_lib.helpers import get_data_file
22
MESSAGE_TYPES = [(_("SMS"), "SMS"),
21
27
class QRCodeSMSGtk(object):
22
28
def __init__(self, qr_code_update_func):
23
29
self.qr_code_update_func = qr_code_update_func
24
builder = Gtk.Builder()
30
self.builder = Gtk.Builder()
26
builder.add_from_file(
32
self.builder.add_from_file(
27
33
get_data_file('ui', '%s.ui' % ('QrCodeSMS',)))
28
self.grid = builder.get_object('qr_code_sms')
30
textbuffer = builder.get_object('entryText').get_buffer()
31
textbuffer.connect("changed", self.on_entryText_changed, None)
34
self.grid = self.builder.get_object('qr_code_sms')
36
self.messagecombo = self.builder.get_object('comboboxType')
37
for t in MESSAGE_TYPES:
38
self.messagecombo.append_text(t[0])
39
self.messagecombo.set_active(0)
40
self.messagecombo.connect("changed", self.on_comboboxType_changed, None)
42
self.text = self.builder.get_object('entryText')
43
self.text.connect("changed", self.on_entryText_changed, None)
45
self.builder.get_object('eventboxmessage').connect("button-press-event", self.on_eventboxmessage_press_event, None)
33
47
def on_activated(self):
50
def on_comboboxType_changed(self, widget, data=None):
51
self.on_entryText_changed(self.text)
36
53
def on_entryText_changed(self, widget, data=None):
37
self.qr_code_update_func(widget.get_text(widget.get_start_iter(),
38
widget.get_end_iter(),
54
ty = MESSAGE_TYPES[self.builder.get_object('comboboxType').get_active()][1]
55
n = self.builder.get_object('entryNumber').get_text()
56
te = widget.get_text()
58
self.qr_code_update_func("{0}:{1}".format(ty, n))
60
self.qr_code_update_func("{0}:{1}?body={2}".format(ty, n, te))
62
def on_eventboxmessage_press_event(self, widget, event, data=None):
63
print widget, event, data
64
dialog = Gtk.MessageDialog(message_type=Gtk.MessageType.INFO,
65
buttons=Gtk.ButtonsType.OK, message_format="Not all QR Code readers can handle SMS codes with message!")
66
dialog.format_secondary_text("""Different QR Code scanning applications expect different formats.
68
Some accept SMS with predefined message, while others might either ignore the text or get the whole data wrong.
70
The format Qreator uses is:
72
SMSTO:<phone number>:<message>
76
SMSTO:<phone number>.""")