diff options
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs/hig/simplesettingsdialog.py')
-rw-r--r-- | bitbake/lib/bb/ui/crumbs/hig/simplesettingsdialog.py | 722 |
1 files changed, 722 insertions, 0 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/hig/simplesettingsdialog.py b/bitbake/lib/bb/ui/crumbs/hig/simplesettingsdialog.py new file mode 100644 index 0000000000..3642e9bc5c --- /dev/null +++ b/bitbake/lib/bb/ui/crumbs/hig/simplesettingsdialog.py | |||
@@ -0,0 +1,722 @@ | |||
1 | # | ||
2 | # BitBake Graphical GTK User Interface | ||
3 | # | ||
4 | # Copyright (C) 2011-2012 Intel Corporation | ||
5 | # | ||
6 | # Authored by Joshua Lock <josh@linux.intel.com> | ||
7 | # Authored by Dongxiao Xu <dongxiao.xu@intel.com> | ||
8 | # Authored by Shane Wang <shane.wang@intel.com> | ||
9 | # | ||
10 | # This program is free software; you can redistribute it and/or modify | ||
11 | # it under the terms of the GNU General Public License version 2 as | ||
12 | # published by the Free Software Foundation. | ||
13 | # | ||
14 | # This program is distributed in the hope that it will be useful, | ||
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | # GNU General Public License for more details. | ||
18 | # | ||
19 | # You should have received a copy of the GNU General Public License along | ||
20 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
21 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
22 | |||
23 | import gtk | ||
24 | import gobject | ||
25 | import hashlib | ||
26 | from bb.ui.crumbs.hobwidget import hic, HobInfoButton, HobButton, HobAltButton | ||
27 | from bb.ui.crumbs.progressbar import HobProgressBar | ||
28 | from bb.ui.crumbs.hig.settingsuihelper import SettingsUIHelper | ||
29 | from bb.ui.crumbs.hig.crumbsdialog import CrumbsDialog | ||
30 | from bb.ui.crumbs.hig.crumbsmessagedialog import CrumbsMessageDialog | ||
31 | from bb.ui.crumbs.hig.proxydetailsdialog import ProxyDetailsDialog | ||
32 | |||
33 | """ | ||
34 | The following are convenience classes for implementing GNOME HIG compliant | ||
35 | BitBake GUI's | ||
36 | In summary: spacing = 12px, border-width = 6px | ||
37 | """ | ||
38 | |||
39 | class SimpleSettingsDialog (CrumbsDialog, SettingsUIHelper): | ||
40 | |||
41 | (BUILD_ENV_PAGE_ID, | ||
42 | SHARED_STATE_PAGE_ID, | ||
43 | PROXIES_PAGE_ID, | ||
44 | OTHERS_PAGE_ID) = range(4) | ||
45 | |||
46 | (TEST_NETWORK_NONE, | ||
47 | TEST_NETWORK_INITIAL, | ||
48 | TEST_NETWORK_RUNNING, | ||
49 | TEST_NETWORK_PASSED, | ||
50 | TEST_NETWORK_FAILED, | ||
51 | TEST_NETWORK_CANCELED) = range(6) | ||
52 | |||
53 | def __init__(self, title, configuration, all_image_types, | ||
54 | all_package_formats, all_distros, all_sdk_machines, | ||
55 | max_threads, parent, flags, handler, buttons=None): | ||
56 | super(SimpleSettingsDialog, self).__init__(title, parent, flags, buttons) | ||
57 | |||
58 | # class members from other objects | ||
59 | # bitbake settings from Builder.Configuration | ||
60 | self.configuration = configuration | ||
61 | self.image_types = all_image_types | ||
62 | self.all_package_formats = all_package_formats | ||
63 | self.all_distros = all_distros | ||
64 | self.all_sdk_machines = all_sdk_machines | ||
65 | self.max_threads = max_threads | ||
66 | |||
67 | # class members for internal use | ||
68 | self.dldir_text = None | ||
69 | self.sstatedir_text = None | ||
70 | self.sstatemirrors_list = [] | ||
71 | self.sstatemirrors_changed = 0 | ||
72 | self.bb_spinner = None | ||
73 | self.pmake_spinner = None | ||
74 | self.rootfs_size_spinner = None | ||
75 | self.extra_size_spinner = None | ||
76 | self.gplv3_checkbox = None | ||
77 | self.toolchain_checkbox = None | ||
78 | self.setting_store = None | ||
79 | self.image_types_checkbuttons = {} | ||
80 | |||
81 | self.md5 = self.config_md5() | ||
82 | self.proxy_md5 = self.config_proxy_md5() | ||
83 | self.settings_changed = False | ||
84 | self.proxy_settings_changed = False | ||
85 | self.handler = handler | ||
86 | self.proxy_test_ran = False | ||
87 | |||
88 | # create visual elements on the dialog | ||
89 | self.create_visual_elements() | ||
90 | self.connect("response", self.response_cb) | ||
91 | |||
92 | def _get_sorted_value(self, var): | ||
93 | return " ".join(sorted(str(var).split())) + "\n" | ||
94 | |||
95 | def config_proxy_md5(self): | ||
96 | data = ("ENABLE_PROXY: " + self._get_sorted_value(self.configuration.enable_proxy)) | ||
97 | if self.configuration.enable_proxy: | ||
98 | for protocol in self.configuration.proxies.keys(): | ||
99 | data += (protocol + ": " + self._get_sorted_value(self.configuration.combine_proxy(protocol))) | ||
100 | return hashlib.md5(data).hexdigest() | ||
101 | |||
102 | def config_md5(self): | ||
103 | data = "" | ||
104 | for key in self.configuration.extra_setting.keys(): | ||
105 | data += (key + ": " + self._get_sorted_value(self.configuration.extra_setting[key])) | ||
106 | return hashlib.md5(data).hexdigest() | ||
107 | |||
108 | def gen_proxy_entry_widget(self, protocol, parent, need_button=True, line=0): | ||
109 | label = gtk.Label(protocol.upper() + " proxy") | ||
110 | self.proxy_table.attach(label, 0, 1, line, line+1, xpadding=24) | ||
111 | |||
112 | proxy_entry = gtk.Entry() | ||
113 | proxy_entry.set_size_request(300, -1) | ||
114 | self.proxy_table.attach(proxy_entry, 1, 2, line, line+1, ypadding=4) | ||
115 | |||
116 | self.proxy_table.attach(gtk.Label(":"), 2, 3, line, line+1, xpadding=12, ypadding=4) | ||
117 | |||
118 | port_entry = gtk.Entry() | ||
119 | port_entry.set_size_request(60, -1) | ||
120 | self.proxy_table.attach(port_entry, 3, 4, line, line+1, ypadding=4) | ||
121 | |||
122 | details_button = HobAltButton("Details") | ||
123 | details_button.connect("clicked", self.details_cb, parent, protocol) | ||
124 | self.proxy_table.attach(details_button, 4, 5, line, line+1, xpadding=4, yoptions=gtk.EXPAND) | ||
125 | |||
126 | return proxy_entry, port_entry, details_button | ||
127 | |||
128 | def refresh_proxy_components(self): | ||
129 | self.same_checkbox.set_sensitive(self.configuration.enable_proxy) | ||
130 | |||
131 | self.http_proxy.set_text(self.configuration.combine_host_only("http")) | ||
132 | self.http_proxy.set_editable(self.configuration.enable_proxy) | ||
133 | self.http_proxy.set_sensitive(self.configuration.enable_proxy) | ||
134 | self.http_proxy_port.set_text(self.configuration.combine_port_only("http")) | ||
135 | self.http_proxy_port.set_editable(self.configuration.enable_proxy) | ||
136 | self.http_proxy_port.set_sensitive(self.configuration.enable_proxy) | ||
137 | self.http_proxy_details.set_sensitive(self.configuration.enable_proxy) | ||
138 | |||
139 | self.https_proxy.set_text(self.configuration.combine_host_only("https")) | ||
140 | self.https_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
141 | self.https_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
142 | self.https_proxy_port.set_text(self.configuration.combine_port_only("https")) | ||
143 | self.https_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
144 | self.https_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
145 | self.https_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
146 | |||
147 | self.ftp_proxy.set_text(self.configuration.combine_host_only("ftp")) | ||
148 | self.ftp_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
149 | self.ftp_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
150 | self.ftp_proxy_port.set_text(self.configuration.combine_port_only("ftp")) | ||
151 | self.ftp_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
152 | self.ftp_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
153 | self.ftp_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
154 | |||
155 | self.git_proxy.set_text(self.configuration.combine_host_only("git")) | ||
156 | self.git_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
157 | self.git_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
158 | self.git_proxy_port.set_text(self.configuration.combine_port_only("git")) | ||
159 | self.git_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
160 | self.git_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
161 | self.git_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
162 | |||
163 | self.cvs_proxy.set_text(self.configuration.combine_host_only("cvs")) | ||
164 | self.cvs_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
165 | self.cvs_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
166 | self.cvs_proxy_port.set_text(self.configuration.combine_port_only("cvs")) | ||
167 | self.cvs_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
168 | self.cvs_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
169 | self.cvs_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy)) | ||
170 | |||
171 | if self.configuration.same_proxy: | ||
172 | if self.http_proxy.get_text(): | ||
173 | [w.set_text(self.http_proxy.get_text()) for w in self.same_proxy_addresses] | ||
174 | if self.http_proxy_port.get_text(): | ||
175 | [w.set_text(self.http_proxy_port.get_text()) for w in self.same_proxy_ports] | ||
176 | |||
177 | def proxy_checkbox_toggled_cb(self, button): | ||
178 | self.configuration.enable_proxy = self.proxy_checkbox.get_active() | ||
179 | if not self.configuration.enable_proxy: | ||
180 | self.configuration.same_proxy = False | ||
181 | self.same_checkbox.set_active(self.configuration.same_proxy) | ||
182 | self.save_proxy_data() | ||
183 | self.refresh_proxy_components() | ||
184 | |||
185 | def same_checkbox_toggled_cb(self, button): | ||
186 | self.configuration.same_proxy = self.same_checkbox.get_active() | ||
187 | self.save_proxy_data() | ||
188 | self.refresh_proxy_components() | ||
189 | |||
190 | def save_proxy_data(self): | ||
191 | self.configuration.split_proxy("http", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text()) | ||
192 | if self.configuration.same_proxy: | ||
193 | self.configuration.split_proxy("https", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text()) | ||
194 | self.configuration.split_proxy("ftp", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text()) | ||
195 | self.configuration.split_proxy("git", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text()) | ||
196 | self.configuration.split_proxy("cvs", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text()) | ||
197 | else: | ||
198 | self.configuration.split_proxy("https", self.https_proxy.get_text() + ":" + self.https_proxy_port.get_text()) | ||
199 | self.configuration.split_proxy("ftp", self.ftp_proxy.get_text() + ":" + self.ftp_proxy_port.get_text()) | ||
200 | self.configuration.split_proxy("git", self.git_proxy.get_text() + ":" + self.git_proxy_port.get_text()) | ||
201 | self.configuration.split_proxy("cvs", self.cvs_proxy.get_text() + ":" + self.cvs_proxy_port.get_text()) | ||
202 | |||
203 | def response_cb(self, dialog, response_id): | ||
204 | if response_id == gtk.RESPONSE_YES: | ||
205 | # Check that all proxy entries have a corresponding port | ||
206 | for proxy, port in zip(self.all_proxy_addresses, self.all_proxy_ports): | ||
207 | if proxy.get_text() and not port.get_text(): | ||
208 | lbl = "<b>Enter all port numbers</b>\n\n" | ||
209 | msg = "Proxy servers require a port number. Please make sure you have entered a port number for each proxy server." | ||
210 | dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_WARNING, msg) | ||
211 | button = dialog.add_button("Close", gtk.RESPONSE_OK) | ||
212 | HobButton.style_button(button) | ||
213 | response = dialog.run() | ||
214 | dialog.destroy() | ||
215 | self.emit_stop_by_name("response") | ||
216 | return | ||
217 | |||
218 | self.configuration.dldir = self.dldir_text.get_text() | ||
219 | self.configuration.sstatedir = self.sstatedir_text.get_text() | ||
220 | self.configuration.sstatemirror = "" | ||
221 | for mirror in self.sstatemirrors_list: | ||
222 | if mirror[1] != "": | ||
223 | if mirror[1].endswith("\\1"): | ||
224 | smirror = mirror[2] + " " + mirror[1] + " \\n " | ||
225 | else: | ||
226 | smirror = mirror[2] + " " + mirror[1] + "\\1 \\n " | ||
227 | self.configuration.sstatemirror += smirror | ||
228 | self.configuration.bbthread = self.bb_spinner.get_value_as_int() | ||
229 | self.configuration.pmake = self.pmake_spinner.get_value_as_int() | ||
230 | self.save_proxy_data() | ||
231 | self.configuration.extra_setting = {} | ||
232 | it = self.setting_store.get_iter_first() | ||
233 | while it: | ||
234 | key = self.setting_store.get_value(it, 0) | ||
235 | value = self.setting_store.get_value(it, 1) | ||
236 | self.configuration.extra_setting[key] = value | ||
237 | it = self.setting_store.iter_next(it) | ||
238 | |||
239 | md5 = self.config_md5() | ||
240 | self.settings_changed = (self.md5 != md5) | ||
241 | self.proxy_settings_changed = (self.proxy_md5 != self.config_proxy_md5()) | ||
242 | |||
243 | def create_build_environment_page(self): | ||
244 | advanced_vbox = gtk.VBox(False, 6) | ||
245 | advanced_vbox.set_border_width(6) | ||
246 | |||
247 | advanced_vbox.pack_start(self.gen_label_widget('<span weight="bold">Parallel threads</span>'), expand=False, fill=False) | ||
248 | sub_vbox = gtk.VBox(False, 6) | ||
249 | advanced_vbox.pack_start(sub_vbox, expand=False, fill=False) | ||
250 | label = self.gen_label_widget("BitBake parallel threads") | ||
251 | tooltip = "Sets the number of threads that BitBake tasks can simultaneously run. See the <a href=\"" | ||
252 | tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/" | ||
253 | tooltip += "poky-ref-manual.html#var-BB_NUMBER_THREADS\">Poky reference manual</a> for information" | ||
254 | bbthread_widget, self.bb_spinner = self.gen_spinner_widget(self.configuration.bbthread, 1, self.max_threads, tooltip) | ||
255 | sub_vbox.pack_start(label, expand=False, fill=False) | ||
256 | sub_vbox.pack_start(bbthread_widget, expand=False, fill=False) | ||
257 | |||
258 | sub_vbox = gtk.VBox(False, 6) | ||
259 | advanced_vbox.pack_start(sub_vbox, expand=False, fill=False) | ||
260 | label = self.gen_label_widget("Make parallel threads") | ||
261 | tooltip = "Sets the maximum number of threads the host can use during the build. See the <a href=\"" | ||
262 | tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/" | ||
263 | tooltip += "poky-ref-manual.html#var-PARALLEL_MAKE\">Poky reference manual</a> for information" | ||
264 | pmake_widget, self.pmake_spinner = self.gen_spinner_widget(self.configuration.pmake, 1, self.max_threads, tooltip) | ||
265 | sub_vbox.pack_start(label, expand=False, fill=False) | ||
266 | sub_vbox.pack_start(pmake_widget, expand=False, fill=False) | ||
267 | |||
268 | advanced_vbox.pack_start(self.gen_label_widget('<span weight="bold">Downloaded source code</span>'), expand=False, fill=False) | ||
269 | sub_vbox = gtk.VBox(False, 6) | ||
270 | advanced_vbox.pack_start(sub_vbox, expand=False, fill=False) | ||
271 | label = self.gen_label_widget("Downloads directory") | ||
272 | tooltip = "Select a folder that caches the upstream project source code" | ||
273 | dldir_widget, self.dldir_text = self.gen_entry_widget(self.configuration.dldir, self, tooltip) | ||
274 | sub_vbox.pack_start(label, expand=False, fill=False) | ||
275 | sub_vbox.pack_start(dldir_widget, expand=False, fill=False) | ||
276 | |||
277 | return advanced_vbox | ||
278 | |||
279 | def create_shared_state_page(self): | ||
280 | advanced_vbox = gtk.VBox(False) | ||
281 | advanced_vbox.set_border_width(12) | ||
282 | |||
283 | sub_vbox = gtk.VBox(False) | ||
284 | advanced_vbox.pack_start(sub_vbox, expand=False, fill=False, padding=24) | ||
285 | content = "<span>Shared state directory</span>" | ||
286 | tooltip = "Select a folder that caches your prebuilt results" | ||
287 | label = self.gen_label_info_widget(content, tooltip) | ||
288 | sstatedir_widget, self.sstatedir_text = self.gen_entry_widget(self.configuration.sstatedir, self) | ||
289 | sub_vbox.pack_start(label, expand=False, fill=False) | ||
290 | sub_vbox.pack_start(sstatedir_widget, expand=False, fill=False, padding=12) | ||
291 | |||
292 | content = "<span weight=\"bold\">Shared state mirrors</span>" | ||
293 | tooltip = "URLs pointing to pre-built mirrors that will speed your build. " | ||
294 | tooltip += "Select the \'Standard\' configuration if the structure of your " | ||
295 | tooltip += "mirror replicates the structure of your local shared state directory. " | ||
296 | tooltip += "For more information on shared state mirrors, check the <a href=\"" | ||
297 | tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/" | ||
298 | tooltip += "poky-ref-manual.html#shared-state\">Yocto Project Reference Manual</a>." | ||
299 | table = self.gen_label_info_widget(content, tooltip) | ||
300 | advanced_vbox.pack_start(table, expand=False, fill=False) | ||
301 | |||
302 | sub_vbox = gtk.VBox(False) | ||
303 | scroll = gtk.ScrolledWindow() | ||
304 | scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) | ||
305 | scroll.add_with_viewport(sub_vbox) | ||
306 | scroll.connect('size-allocate', self.scroll_changed) | ||
307 | advanced_vbox.pack_start(scroll, gtk.TRUE, gtk.TRUE, 0) | ||
308 | searched_string = "file://" | ||
309 | |||
310 | if self.sstatemirrors_changed == 0: | ||
311 | self.sstatemirrors_changed = 1 | ||
312 | sstatemirrors = self.configuration.sstatemirror | ||
313 | if sstatemirrors == "": | ||
314 | sm_list = [ 0, "", "file://(.*)"] | ||
315 | self.sstatemirrors_list.append(sm_list) | ||
316 | else: | ||
317 | while sstatemirrors.find(searched_string) != -1: | ||
318 | if sstatemirrors.find(searched_string,1) != -1: | ||
319 | sstatemirror = sstatemirrors[:sstatemirrors.find(searched_string,1)] | ||
320 | sstatemirrors = sstatemirrors[sstatemirrors.find(searched_string,1):] | ||
321 | else: | ||
322 | sstatemirror = sstatemirrors | ||
323 | sstatemirrors = sstatemirrors[1:] | ||
324 | |||
325 | sstatemirror_fields = [x for x in sstatemirror.split(' ') if x.strip()] | ||
326 | if sstatemirror_fields[0] == "file://(.*)": | ||
327 | sm_list = [ 0, sstatemirror_fields[1], "file://(.*)"] | ||
328 | else: | ||
329 | sm_list = [ 1, sstatemirror_fields[1], sstatemirror_fields[0]] | ||
330 | self.sstatemirrors_list.append(sm_list) | ||
331 | |||
332 | index = 0 | ||
333 | for mirror in self.sstatemirrors_list: | ||
334 | if mirror[0] == 0: | ||
335 | sstatemirror_widget = self.gen_mirror_entry_widget(mirror[1], index) | ||
336 | else: | ||
337 | sstatemirror_widget = self.gen_mirror_entry_widget(mirror[1], index, mirror[2]) | ||
338 | sub_vbox.pack_start(sstatemirror_widget, expand=False, fill=False, padding=9) | ||
339 | index += 1 | ||
340 | |||
341 | table = gtk.Table(1, 1, False) | ||
342 | table.set_col_spacings(6) | ||
343 | add_mirror_button = HobAltButton("Add another mirror") | ||
344 | add_mirror_button.connect("clicked", self.add_mirror) | ||
345 | add_mirror_button.set_size_request(150,30) | ||
346 | table.attach(add_mirror_button, 1, 2, 0, 1, xoptions=gtk.SHRINK) | ||
347 | advanced_vbox.pack_start(table, expand=False, fill=False, padding=9) | ||
348 | |||
349 | return advanced_vbox | ||
350 | |||
351 | def refresh_shared_state_page(self): | ||
352 | page_num = self.nb.get_current_page() | ||
353 | self.nb.remove_page(page_num); | ||
354 | self.nb.insert_page(self.create_shared_state_page(), gtk.Label("Shared state"),page_num) | ||
355 | self.show_all() | ||
356 | self.nb.set_current_page(page_num) | ||
357 | |||
358 | def test_proxy_ended(self, passed): | ||
359 | self.proxy_test_running = False | ||
360 | self.set_test_proxy_state(self.TEST_NETWORK_PASSED if passed else self.TEST_NETWORK_FAILED) | ||
361 | self.set_sensitive(True) | ||
362 | self.refresh_proxy_components() | ||
363 | |||
364 | def timer_func(self): | ||
365 | self.test_proxy_progress.pulse() | ||
366 | return self.proxy_test_running | ||
367 | |||
368 | def test_network_button_cb(self, b): | ||
369 | self.set_test_proxy_state(self.TEST_NETWORK_RUNNING) | ||
370 | self.set_sensitive(False) | ||
371 | self.save_proxy_data() | ||
372 | if self.configuration.enable_proxy == True: | ||
373 | self.handler.set_http_proxy(self.configuration.combine_proxy("http")) | ||
374 | self.handler.set_https_proxy(self.configuration.combine_proxy("https")) | ||
375 | self.handler.set_ftp_proxy(self.configuration.combine_proxy("ftp")) | ||
376 | self.handler.set_git_proxy(self.configuration.combine_host_only("git"), self.configuration.combine_port_only("git")) | ||
377 | self.handler.set_cvs_proxy(self.configuration.combine_host_only("cvs"), self.configuration.combine_port_only("cvs")) | ||
378 | elif self.configuration.enable_proxy == False: | ||
379 | self.handler.set_http_proxy("") | ||
380 | self.handler.set_https_proxy("") | ||
381 | self.handler.set_ftp_proxy("") | ||
382 | self.handler.set_git_proxy("", "") | ||
383 | self.handler.set_cvs_proxy("", "") | ||
384 | self.proxy_test_ran = True | ||
385 | self.proxy_test_running = True | ||
386 | gobject.timeout_add(100, self.timer_func) | ||
387 | self.handler.trigger_network_test() | ||
388 | |||
389 | def test_proxy_focus_event(self, w, direction): | ||
390 | if self.test_proxy_state in [self.TEST_NETWORK_PASSED, self.TEST_NETWORK_FAILED]: | ||
391 | self.set_test_proxy_state(self.TEST_NETWORK_INITIAL) | ||
392 | return False | ||
393 | |||
394 | def http_proxy_changed(self, e): | ||
395 | if not self.configuration.same_proxy: | ||
396 | return | ||
397 | if e == self.http_proxy: | ||
398 | [w.set_text(self.http_proxy.get_text()) for w in self.same_proxy_addresses] | ||
399 | else: | ||
400 | [w.set_text(self.http_proxy_port.get_text()) for w in self.same_proxy_ports] | ||
401 | |||
402 | def proxy_address_focus_out_event(self, w, direction): | ||
403 | text = w.get_text() | ||
404 | if not text: | ||
405 | return False | ||
406 | if text.find("//") == -1: | ||
407 | w.set_text("http://" + text) | ||
408 | return False | ||
409 | |||
410 | def set_test_proxy_state(self, state): | ||
411 | if self.test_proxy_state == state: | ||
412 | return | ||
413 | [self.proxy_table.remove(w) for w in self.test_gui_elements] | ||
414 | if state == self.TEST_NETWORK_INITIAL: | ||
415 | self.proxy_table.attach(self.test_network_button, 1, 2, 5, 6) | ||
416 | self.test_network_button.show() | ||
417 | elif state == self.TEST_NETWORK_RUNNING: | ||
418 | self.test_proxy_progress.set_rcstyle("running") | ||
419 | self.test_proxy_progress.set_text("Testing network configuration") | ||
420 | self.proxy_table.attach(self.test_proxy_progress, 0, 5, 5, 6, xpadding=4) | ||
421 | self.test_proxy_progress.show() | ||
422 | else: # passed or failed | ||
423 | self.dummy_progress.update(1.0) | ||
424 | if state == self.TEST_NETWORK_PASSED: | ||
425 | self.dummy_progress.set_text("Your network is properly configured") | ||
426 | self.dummy_progress.set_rcstyle("running") | ||
427 | else: | ||
428 | self.dummy_progress.set_text("Network test failed") | ||
429 | self.dummy_progress.set_rcstyle("fail") | ||
430 | self.proxy_table.attach(self.dummy_progress, 0, 4, 5, 6) | ||
431 | self.proxy_table.attach(self.retest_network_button, 4, 5, 5, 6, xpadding=4) | ||
432 | self.dummy_progress.show() | ||
433 | self.retest_network_button.show() | ||
434 | self.test_proxy_state = state | ||
435 | |||
436 | def create_network_page(self): | ||
437 | advanced_vbox = gtk.VBox(False, 6) | ||
438 | advanced_vbox.set_border_width(6) | ||
439 | self.same_proxy_addresses = [] | ||
440 | self.same_proxy_ports = [] | ||
441 | self.all_proxy_ports = [] | ||
442 | self.all_proxy_addresses = [] | ||
443 | |||
444 | sub_vbox = gtk.VBox(False, 6) | ||
445 | advanced_vbox.pack_start(sub_vbox, expand=False, fill=False) | ||
446 | label = self.gen_label_widget("<span weight=\"bold\">Set the proxies used when fetching source code</span>") | ||
447 | tooltip = "Set the proxies used when fetching source code. A blank field uses a direct internet connection." | ||
448 | info = HobInfoButton(tooltip, self) | ||
449 | hbox = gtk.HBox(False, 12) | ||
450 | hbox.pack_start(label, expand=True, fill=True) | ||
451 | hbox.pack_start(info, expand=False, fill=False) | ||
452 | sub_vbox.pack_start(hbox, expand=False, fill=False) | ||
453 | |||
454 | proxy_test_focus = [] | ||
455 | self.direct_checkbox = gtk.RadioButton(None, "Direct network connection") | ||
456 | proxy_test_focus.append(self.direct_checkbox) | ||
457 | self.direct_checkbox.set_tooltip_text("Check this box to use a direct internet connection with no proxy") | ||
458 | self.direct_checkbox.set_active(not self.configuration.enable_proxy) | ||
459 | sub_vbox.pack_start(self.direct_checkbox, expand=False, fill=False) | ||
460 | |||
461 | self.proxy_checkbox = gtk.RadioButton(self.direct_checkbox, "Manual proxy configuration") | ||
462 | proxy_test_focus.append(self.proxy_checkbox) | ||
463 | self.proxy_checkbox.set_tooltip_text("Check this box to manually set up a specific proxy") | ||
464 | self.proxy_checkbox.set_active(self.configuration.enable_proxy) | ||
465 | sub_vbox.pack_start(self.proxy_checkbox, expand=False, fill=False) | ||
466 | |||
467 | self.same_checkbox = gtk.CheckButton("Use the HTTP proxy for all protocols") | ||
468 | proxy_test_focus.append(self.same_checkbox) | ||
469 | self.same_checkbox.set_tooltip_text("Check this box to use the HTTP proxy for all five proxies") | ||
470 | self.same_checkbox.set_active(self.configuration.same_proxy) | ||
471 | hbox = gtk.HBox(False, 12) | ||
472 | hbox.pack_start(self.same_checkbox, expand=False, fill=False, padding=24) | ||
473 | sub_vbox.pack_start(hbox, expand=False, fill=False) | ||
474 | |||
475 | self.proxy_table = gtk.Table(6, 5, False) | ||
476 | self.http_proxy, self.http_proxy_port, self.http_proxy_details = self.gen_proxy_entry_widget( | ||
477 | "http", self, True, 0) | ||
478 | proxy_test_focus +=[self.http_proxy, self.http_proxy_port] | ||
479 | self.http_proxy.connect("changed", self.http_proxy_changed) | ||
480 | self.http_proxy_port.connect("changed", self.http_proxy_changed) | ||
481 | |||
482 | self.https_proxy, self.https_proxy_port, self.https_proxy_details = self.gen_proxy_entry_widget( | ||
483 | "https", self, True, 1) | ||
484 | proxy_test_focus += [self.https_proxy, self.https_proxy_port] | ||
485 | self.same_proxy_addresses.append(self.https_proxy) | ||
486 | self.same_proxy_ports.append(self.https_proxy_port) | ||
487 | |||
488 | self.ftp_proxy, self.ftp_proxy_port, self.ftp_proxy_details = self.gen_proxy_entry_widget( | ||
489 | "ftp", self, True, 2) | ||
490 | proxy_test_focus += [self.ftp_proxy, self.ftp_proxy_port] | ||
491 | self.same_proxy_addresses.append(self.ftp_proxy) | ||
492 | self.same_proxy_ports.append(self.ftp_proxy_port) | ||
493 | |||
494 | self.git_proxy, self.git_proxy_port, self.git_proxy_details = self.gen_proxy_entry_widget( | ||
495 | "git", self, True, 3) | ||
496 | proxy_test_focus += [self.git_proxy, self.git_proxy_port] | ||
497 | self.same_proxy_addresses.append(self.git_proxy) | ||
498 | self.same_proxy_ports.append(self.git_proxy_port) | ||
499 | |||
500 | self.cvs_proxy, self.cvs_proxy_port, self.cvs_proxy_details = self.gen_proxy_entry_widget( | ||
501 | "cvs", self, True, 4) | ||
502 | proxy_test_focus += [self.cvs_proxy, self.cvs_proxy_port] | ||
503 | self.same_proxy_addresses.append(self.cvs_proxy) | ||
504 | self.same_proxy_ports.append(self.cvs_proxy_port) | ||
505 | self.all_proxy_ports = self.same_proxy_ports + [self.http_proxy_port] | ||
506 | self.all_proxy_addresses = self.same_proxy_addresses + [self.http_proxy] | ||
507 | sub_vbox.pack_start(self.proxy_table, expand=False, fill=False) | ||
508 | self.proxy_table.show_all() | ||
509 | |||
510 | # Create the graphical elements for the network test feature, but don't display them yet | ||
511 | self.test_network_button = HobAltButton("Test network configuration") | ||
512 | self.test_network_button.connect("clicked", self.test_network_button_cb) | ||
513 | self.test_proxy_progress = HobProgressBar() | ||
514 | self.dummy_progress = HobProgressBar() | ||
515 | self.retest_network_button = HobAltButton("Retest") | ||
516 | self.retest_network_button.connect("clicked", self.test_network_button_cb) | ||
517 | self.test_gui_elements = [self.test_network_button, self.test_proxy_progress, self.dummy_progress, self.retest_network_button] | ||
518 | # Initialize the network tester | ||
519 | self.test_proxy_state = self.TEST_NETWORK_NONE | ||
520 | self.set_test_proxy_state(self.TEST_NETWORK_INITIAL) | ||
521 | self.proxy_test_passed_id = self.handler.connect("network-passed", lambda h:self.test_proxy_ended(True)) | ||
522 | self.proxy_test_failed_id = self.handler.connect("network-failed", lambda h:self.test_proxy_ended(False)) | ||
523 | [w.connect("focus-in-event", self.test_proxy_focus_event) for w in proxy_test_focus] | ||
524 | [w.connect("focus-out-event", self.proxy_address_focus_out_event) for w in self.all_proxy_addresses] | ||
525 | |||
526 | self.direct_checkbox.connect("toggled", self.proxy_checkbox_toggled_cb) | ||
527 | self.proxy_checkbox.connect("toggled", self.proxy_checkbox_toggled_cb) | ||
528 | self.same_checkbox.connect("toggled", self.same_checkbox_toggled_cb) | ||
529 | |||
530 | self.refresh_proxy_components() | ||
531 | return advanced_vbox | ||
532 | |||
533 | def switch_to_page(self, page_id): | ||
534 | self.nb.set_current_page(page_id) | ||
535 | |||
536 | def details_cb(self, button, parent, protocol): | ||
537 | self.save_proxy_data() | ||
538 | dialog = ProxyDetailsDialog(title = protocol.upper() + " Proxy Details", | ||
539 | user = self.configuration.proxies[protocol][1], | ||
540 | passwd = self.configuration.proxies[protocol][2], | ||
541 | parent = parent, | ||
542 | flags = gtk.DIALOG_MODAL | ||
543 | | gtk.DIALOG_DESTROY_WITH_PARENT | ||
544 | | gtk.DIALOG_NO_SEPARATOR) | ||
545 | dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_OK) | ||
546 | response = dialog.run() | ||
547 | if response == gtk.RESPONSE_OK: | ||
548 | self.configuration.proxies[protocol][1] = dialog.user | ||
549 | self.configuration.proxies[protocol][2] = dialog.passwd | ||
550 | self.refresh_proxy_components() | ||
551 | dialog.destroy() | ||
552 | |||
553 | def rootfs_combo_changed_cb(self, rootfs_combo, all_package_format, check_hbox): | ||
554 | combo_item = self.rootfs_combo.get_active_text() | ||
555 | for child in check_hbox.get_children(): | ||
556 | if isinstance(child, gtk.CheckButton): | ||
557 | check_hbox.remove(child) | ||
558 | for format in all_package_format: | ||
559 | if format != combo_item: | ||
560 | check_button = gtk.CheckButton(format) | ||
561 | check_hbox.pack_start(check_button, expand=False, fill=False) | ||
562 | check_hbox.show_all() | ||
563 | |||
564 | def gen_pkgfmt_widget(self, curr_package_format, all_package_format, tooltip_combo="", tooltip_extra=""): | ||
565 | pkgfmt_hbox = gtk.HBox(False, 24) | ||
566 | |||
567 | rootfs_vbox = gtk.VBox(False, 6) | ||
568 | pkgfmt_hbox.pack_start(rootfs_vbox, expand=False, fill=False) | ||
569 | |||
570 | label = self.gen_label_widget("Root file system package format") | ||
571 | rootfs_vbox.pack_start(label, expand=False, fill=False) | ||
572 | |||
573 | rootfs_format = "" | ||
574 | if curr_package_format: | ||
575 | rootfs_format = curr_package_format.split()[0] | ||
576 | |||
577 | rootfs_format_widget, rootfs_combo = self.gen_combo_widget(rootfs_format, all_package_format, tooltip_combo) | ||
578 | rootfs_vbox.pack_start(rootfs_format_widget, expand=False, fill=False) | ||
579 | |||
580 | extra_vbox = gtk.VBox(False, 6) | ||
581 | pkgfmt_hbox.pack_start(extra_vbox, expand=False, fill=False) | ||
582 | |||
583 | label = self.gen_label_widget("Additional package formats") | ||
584 | extra_vbox.pack_start(label, expand=False, fill=False) | ||
585 | |||
586 | check_hbox = gtk.HBox(False, 12) | ||
587 | extra_vbox.pack_start(check_hbox, expand=False, fill=False) | ||
588 | for format in all_package_format: | ||
589 | if format != rootfs_format: | ||
590 | check_button = gtk.CheckButton(format) | ||
591 | is_active = (format in curr_package_format.split()) | ||
592 | check_button.set_active(is_active) | ||
593 | check_hbox.pack_start(check_button, expand=False, fill=False) | ||
594 | |||
595 | info = HobInfoButton(tooltip_extra, self) | ||
596 | check_hbox.pack_end(info, expand=False, fill=False) | ||
597 | |||
598 | rootfs_combo.connect("changed", self.rootfs_combo_changed_cb, all_package_format, check_hbox) | ||
599 | |||
600 | pkgfmt_hbox.show_all() | ||
601 | |||
602 | return pkgfmt_hbox, rootfs_combo, check_hbox | ||
603 | |||
604 | def editable_settings_cell_edited(self, cell, path_string, new_text, model): | ||
605 | it = model.get_iter_from_string(path_string) | ||
606 | column = cell.get_data("column") | ||
607 | model.set(it, column, new_text) | ||
608 | |||
609 | def editable_settings_add_item_clicked(self, button, model): | ||
610 | new_item = ["##KEY##", "##VALUE##"] | ||
611 | |||
612 | iter = model.append() | ||
613 | model.set (iter, | ||
614 | 0, new_item[0], | ||
615 | 1, new_item[1], | ||
616 | ) | ||
617 | |||
618 | def editable_settings_remove_item_clicked(self, button, treeview): | ||
619 | selection = treeview.get_selection() | ||
620 | model, iter = selection.get_selected() | ||
621 | |||
622 | if iter: | ||
623 | path = model.get_path(iter)[0] | ||
624 | model.remove(iter) | ||
625 | |||
626 | def gen_editable_settings(self, setting, tooltip=""): | ||
627 | setting_hbox = gtk.HBox(False, 12) | ||
628 | |||
629 | vbox = gtk.VBox(False, 12) | ||
630 | setting_hbox.pack_start(vbox, expand=True, fill=True) | ||
631 | |||
632 | setting_store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) | ||
633 | for key in setting.keys(): | ||
634 | setting_store.set(setting_store.append(), 0, key, 1, setting[key]) | ||
635 | |||
636 | setting_tree = gtk.TreeView(setting_store) | ||
637 | setting_tree.set_headers_visible(True) | ||
638 | setting_tree.set_size_request(300, 100) | ||
639 | |||
640 | col = gtk.TreeViewColumn('Key') | ||
641 | col.set_min_width(100) | ||
642 | col.set_max_width(150) | ||
643 | col.set_resizable(True) | ||
644 | col1 = gtk.TreeViewColumn('Value') | ||
645 | col1.set_min_width(100) | ||
646 | col1.set_max_width(150) | ||
647 | col1.set_resizable(True) | ||
648 | setting_tree.append_column(col) | ||
649 | setting_tree.append_column(col1) | ||
650 | cell = gtk.CellRendererText() | ||
651 | cell.set_property('width-chars', 10) | ||
652 | cell.set_property('editable', True) | ||
653 | cell.set_data("column", 0) | ||
654 | cell.connect("edited", self.editable_settings_cell_edited, setting_store) | ||
655 | cell1 = gtk.CellRendererText() | ||
656 | cell1.set_property('width-chars', 10) | ||
657 | cell1.set_property('editable', True) | ||
658 | cell1.set_data("column", 1) | ||
659 | cell1.connect("edited", self.editable_settings_cell_edited, setting_store) | ||
660 | col.pack_start(cell, True) | ||
661 | col1.pack_end(cell1, True) | ||
662 | col.set_attributes(cell, text=0) | ||
663 | col1.set_attributes(cell1, text=1) | ||
664 | |||
665 | scroll = gtk.ScrolledWindow() | ||
666 | scroll.set_shadow_type(gtk.SHADOW_IN) | ||
667 | scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) | ||
668 | scroll.add(setting_tree) | ||
669 | vbox.pack_start(scroll, expand=True, fill=True) | ||
670 | |||
671 | # some buttons | ||
672 | hbox = gtk.HBox(True, 6) | ||
673 | vbox.pack_start(hbox, False, False) | ||
674 | |||
675 | button = gtk.Button(stock=gtk.STOCK_ADD) | ||
676 | button.connect("clicked", self.editable_settings_add_item_clicked, setting_store) | ||
677 | hbox.pack_start(button) | ||
678 | |||
679 | button = gtk.Button(stock=gtk.STOCK_REMOVE) | ||
680 | button.connect("clicked", self.editable_settings_remove_item_clicked, setting_tree) | ||
681 | hbox.pack_start(button) | ||
682 | |||
683 | info = HobInfoButton(tooltip, self) | ||
684 | setting_hbox.pack_start(info, expand=False, fill=False) | ||
685 | |||
686 | return setting_hbox, setting_store | ||
687 | |||
688 | def create_others_page(self): | ||
689 | advanced_vbox = gtk.VBox(False, 6) | ||
690 | advanced_vbox.set_border_width(6) | ||
691 | |||
692 | sub_vbox = gtk.VBox(False, 6) | ||
693 | advanced_vbox.pack_start(sub_vbox, expand=True, fill=True) | ||
694 | label = self.gen_label_widget("<span weight=\"bold\">Add your own variables:</span>") | ||
695 | tooltip = "These are key/value pairs for your extra settings. Click \'Add\' and then directly edit the key and the value" | ||
696 | setting_widget, self.setting_store = self.gen_editable_settings(self.configuration.extra_setting, tooltip) | ||
697 | sub_vbox.pack_start(label, expand=False, fill=False) | ||
698 | sub_vbox.pack_start(setting_widget, expand=True, fill=True) | ||
699 | |||
700 | return advanced_vbox | ||
701 | |||
702 | def create_visual_elements(self): | ||
703 | self.nb = gtk.Notebook() | ||
704 | self.nb.set_show_tabs(True) | ||
705 | self.nb.append_page(self.create_build_environment_page(), gtk.Label("Build environment")) | ||
706 | self.nb.append_page(self.create_shared_state_page(), gtk.Label("Shared state")) | ||
707 | self.nb.append_page(self.create_network_page(), gtk.Label("Network")) | ||
708 | self.nb.append_page(self.create_others_page(), gtk.Label("Others")) | ||
709 | self.nb.set_current_page(0) | ||
710 | self.vbox.pack_start(self.nb, expand=True, fill=True) | ||
711 | self.vbox.pack_end(gtk.HSeparator(), expand=True, fill=True) | ||
712 | |||
713 | self.show_all() | ||
714 | |||
715 | def destroy(self): | ||
716 | self.handler.disconnect(self.proxy_test_passed_id) | ||
717 | self.handler.disconnect(self.proxy_test_failed_id) | ||
718 | super(SimpleSettingsDialog, self).destroy() | ||
719 | |||
720 | def scroll_changed(self, widget, event, data=None): | ||
721 | adj = widget.get_vadjustment() | ||
722 | adj.set_value(adj.upper - adj.page_size) | ||