51
52
self.PreferencesDialog = PreferencesQreatorDialog
53
54
# Code for other initialization actions should be added here.
56
# Initialize the clipboard
54
57
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
59
# Initialize the style for the main toolbar
55
60
context = self.ui.toolbar1.get_style_context()
56
61
context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
63
# Initialize the Cairo surface that will contain the QR code
57
64
self.surface = None
66
# Initialize the icon view widget
58
67
self.ui.iconview1.set_text_column(COL_TEXT)
59
68
self.ui.iconview1.set_pixbuf_column(COL_PIXBUF)
70
# Hide the notebook tabs
61
71
self.ui.notebook1.set_show_tabs(False)
63
73
self.qr_code_placeholder = 'aa'
71
81
def on_toolbuttonHome_clicked(self, widget, data=None):
82
'''Shows the home page'''
72
83
self.ui.notebook1.set_current_page(PAGE_HOME)
74
85
def on_toolbuttonHistory_clicked(self, widget, data=None):
86
'''Shows the history page'''
75
87
self.ui.notebook1.set_current_page(PAGE_HISTORY)
77
89
def on_toolbuttonSettings_clicked(self, widget, data=None):
90
'''Shows the settings page'''
78
91
self.ui.notebook1.set_current_page(PAGE_SETTINGS)
80
93
def on_toolbuttonAbout_clicked(self, widget, data=None):
94
'''Shows the about page'''
81
95
self.ui.notebook1.set_current_page(PAGE_ABOUT)
83
97
def on_iconview1_item_activated(self, widget, item):
98
'''Loads the UI for the appropriate QR type'''
85
100
model = widget.get_model()
86
101
qr_type = model[item][COL_ID]
103
# We're loading each UI type inside this grid
88
104
grid = self.ui.grid1
106
# FIXME: the way of choosing the page is a bit of a hack for now
90
107
if qr_type + PAGE_URL == PAGE_URL:
108
# We're now loading the UI for the URL QR type
91
109
entry1 = Gtk.Entry()
92
110
entry1.connect('changed', self.on_entry1_changed)
93
111
entry1.set_hexpand(True)
113
# Remove the current widgets from the top half of the UI,
114
# replace them with the current QR type's UI
94
115
children = grid.get_children()
95
116
grid.remove(children[0])
96
117
grid.attach(entry1, 0, 0, 1, 1)
98
119
elif qr_type + PAGE_URL == PAGE_GEO:
120
# We're now loading the UI for the map QR type
100
121
map_widget = GtkChamplain.Embed()
101
122
map_widget.set_hexpand(True)
102
123
map_widget.set_vexpand(True)
104
125
map_grid = Gtk.Grid()
105
126
map_grid.attach(map_widget, 0, 0, 2, 1)
107
#map_location_grid = Gtk.Grid()
108
128
lat_entry = Gtk.Entry()
109
129
lat_entry.set_hexpand(True)
110
130
lat_label = Gtk.Label(_('Latitude:'))
111
131
lat_label.set_alignment(xalign=0, yalign=0.5)
112
#lat_label.set_hexpand(True)
113
132
lon_entry = Gtk.Entry()
114
133
lon_label = Gtk.Label(_('Longitude:'))
115
134
lon_label.set_alignment(xalign=0, yalign=0.5)
123
142
Gtk.PositionType.RIGHT, 1, 1)
124
143
map_grid.attach_next_to(lon_entry, lon_label,
125
144
Gtk.PositionType.RIGHT, 1, 1)
146
# Remove the current widgets from the top half of the UI,
147
# replace them with the current QR type's UI
128
148
children = grid.get_children()
129
149
grid.remove(children[0])
130
150
self.ui.grid1.attach(map_grid, 0, 0, 1, 1)
134
154
map_widget.connect('button-release-event',
135
155
self.on_map_widget_button_press_event,
158
# Get the current location, center the map on it, and initialize
137
160
latitude, longitude = get_current_location()
138
161
self.map_view.center_on(latitude, longitude)
139
162
self.map_view.set_zoom_level(15)
234
257
def get_current_location():
258
'''Gets the current location from geolocation via IP (only method)
259
currently supported'''
235
261
location = Geoclue.DiscoverLocation()
237
263
location.set_position_provider(POS_PROVIDER)
238
264
position = location.get_location_info()
239
266
return position['latitude'], position['longitude']