1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2012 David Planella <david.planella@ubuntu.com>
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
from gi.repository import Gtk
18
from qreator_lib.helpers import get_data_file
19
from qreator_lib.i18n import _
23
def add_fullname(card, fullname):
26
card.fn.value = fullname()
28
def add_email(card, emailaddress, addresstype):
31
card.email.value = emailaddress()
32
card.email.type_param = addresstype()
34
def add_phone(card, phone, phonetype):
37
card.tel.value = phone()
38
card.tel.type_param = phonetype()
40
def add_address(card, street, city, region, code, country, box):
41
if street() or city() or region() or code() or country() or box():
43
card.adr.value = vobject.vcard.Address(street(), city(), region(), code(), country(), box())
45
def add_title(card, title):
48
card.title.value = title()
50
def add_url(card, url):
53
card.url.value = url()
56
class QRCodeVCardGtk(object):
57
def __init__(self, qr_code_update_func):
58
self.qr_code_update_func = qr_code_update_func
59
self.builder = Gtk.Builder()
61
self.builder.add_from_file(
62
get_data_file('ui', '%s.ui' % ('QrCodeVCard',)))
63
self.grid = self.builder.get_object('qr_code_vcard')
64
self.builder.connect_signals(self)
65
self.fullname_edited = False
66
# other entries are added later to this list
67
# first tuple element is a function to call with parameters, in most cases the parameters
68
# will be the functions needed to access the entry texts
69
self.entries = [(add_fullname, [self.builder.get_object('entry3').get_text,] ),]
72
def create_vcard(self):
73
self.j = vobject.vCard()
75
f = self.builder.get_object('entry2').get_text()
76
g = self.builder.get_object('entry1').get_text()
77
self.j.n.value = vobject.vcard.Name(family = f, given = g)
78
for e in self.entries:
82
self.builder.get_object('label4').set_text(_("VCard is not yet valid. All names are required."))
84
self.builder.get_object('label4').set_text("")
85
print self.j.prettyPrint()
87
def on_activated(self):
90
def on_changed(self, widget):
91
firstname = self.builder.get_object('entry1').get_text()
92
lastname = self.builder.get_object('entry2').get_text()
93
if not self.fullname_edited:
94
# TRANSLATORS: if there is a language dependent preference for the order of the familyname {0} and
95
# the givenname {1}, this should be indicated here.
96
self.builder.get_object('entry3').set_text(_("{0} {1}").format(firstname, lastname))
97
fullname = self.builder.get_object('entry3').get_text()
100
self.qr_code_update_func(self.j.serialize())
103
def on_entry3_button_press_event(self, widget, something):
104
self.fullname_edited = True
107
def on_button1_activate(self, widget):
108
def add_items(label_texts):
110
for n, l in enumerate(label_texts):
112
self.builder.get_object('grid1').attach(label, 2*n, self.rows+1, 1, 1)
114
entry.connect("changed", self.on_changed)
115
self.builder.get_object('grid1').attach(entry, 2*n+1, self.rows+1, 1, 1)
116
entries.append(entry)
123
sep = Gtk.Separator()
125
self.builder.get_object('grid1').attach(sep, 0, self.rows+1, 4, 1)
128
entry_type = self.builder.get_object('comboboxtext1').get_active_text()
129
if entry_type == "Email":
131
entry1, entry2 = add_items([_("Email"), _("Type")])
132
entry2.set_text(_("Private"))
133
self.entries.append((add_email, [entry1.get_text, entry2.get_text]))
134
elif entry_type == _("Phone"):
136
entry1, entry2 = add_items([_("Phone"),_("Type")])
137
entry2.set_text(_("Private"))
138
self.entries.append((add_phone, [entry1.get_text,entry2.get_text]))
139
elif entry_type == _("Address"):
141
street, city = add_items([_("Street"), _("City")],)
142
region, code = add_items([_("Region"), _("Zipcode"),])
143
country, box = add_items([_("Country"), _("Postbox")])
144
self.entries.append((add_address, [street.get_text, city.get_text,
145
region.get_text, code.get_text,
146
country.get_text, box.get_text]))
147
elif entry_type == _("Title"):
149
title = add_items([_("Title")])[0]
150
self.entries.append((add_title, [title.get_text,]))
152
elif entry_type == _("Url"):
154
url = add_items([_("Website")])[0]
155
self.entries.append((add_url, [url.get_text,]))
156
url.set_text("http://")