You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1607 lines
53 KiB

  1. # a graphical (GTK+) user interface
  2. # Written by Luca Bruno <lethalman88@gmail.com>
  3. # Based on gnome-reportbug work done by Philipp Kern <pkern@debian.org>
  4. # Copyright (C) 2006 Philipp Kern
  5. # Copyright (C) 2008-2009 Luca Bruno
  6. #
  7. # This program is freely distributable per the following license:
  8. #
  9. # Permission to use, copy, modify, and distribute this software and its
  10. # documentation for any purpose and without fee is hereby granted,
  11. # provided that the above copyright notice appears in all copies and that
  12. # both that copyright notice and this permission notice appear in
  13. # supporting documentation.
  14. #
  15. # I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  16. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I
  17. # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  18. # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. # SOFTWARE.
  22. from reportbug.exceptions import UINotImportable
  23. try:
  24. # use a PyGTK compatibility layer
  25. # https://wiki.gnome.org/Projects/PyGObject/IntrospectionPorting
  26. from gi import pygtkcompat
  27. pygtkcompat.enable()
  28. pygtkcompat.enable_gtk(version='3.0')
  29. import gtk
  30. import gobject
  31. import pango
  32. except ImportError:
  33. raise UINotImportable('Please install the python-gtk2 package to use this interface.')
  34. global vte
  35. try:
  36. import gtkspellcheck
  37. has_spell = True
  38. except:
  39. has_spell = False
  40. #gtk.set_interactive(0)
  41. gtk.gdk.threads_init()
  42. import sys
  43. import re
  44. import os
  45. import traceback
  46. from queue import Queue
  47. import threading
  48. import textwrap
  49. from reportbug.exceptions import NoPackage, NoBugs, NoNetwork, NoReport
  50. from reportbug import debbugs
  51. from reportbug.urlutils import launch_browser
  52. ISATTY = True
  53. DEBIAN_LOGO = "/usr/share/pixmaps/debian-logo.png"
  54. global application, assistant, report_message
  55. # Utilities
  56. def highlight(s):
  57. return '<b>%s</b>' % s
  58. re_markup_free = re.compile("<.*?>")
  59. def markup_free(s):
  60. return re_markup_free.sub("", s)
  61. def ask_free(s):
  62. s = s.strip()
  63. if s[-1] in('?', ':'):
  64. return s[:-1]
  65. return s
  66. def create_scrollable(widget, with_viewport=False):
  67. scrolled = gtk.ScrolledWindow()
  68. scrolled.set_shadow_type(gtk.SHADOW_ETCHED_IN)
  69. scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
  70. if with_viewport:
  71. scrolled.add_with_viewport(widget)
  72. else:
  73. scrolled.add(widget)
  74. return scrolled
  75. def info_dialog(message):
  76. dialog = gtk.MessageDialog(assistant, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
  77. gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, message)
  78. dialog.connect('response', lambda d, *args: d.destroy())
  79. dialog.set_title('Reportbug')
  80. dialog.show_all()
  81. def error_dialog(message):
  82. dialog = gtk.MessageDialog(assistant, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
  83. gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, message)
  84. dialog.connect('response', lambda d, *args: d.destroy())
  85. dialog.set_title('Reportbug')
  86. dialog.show_all()
  87. class CustomDialog(gtk.Dialog):
  88. def __init__(self, stock_image, message, buttons, *args, **kwargs):
  89. gtk.Dialog.__init__(self, "Reportbug", assistant,
  90. gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
  91. buttons)
  92. # Try following the HIG
  93. self.set_default_response(buttons[-1]) # this is the response of the last button
  94. self.set_border_width(5)
  95. vbox = gtk.VBox(spacing=10)
  96. vbox.set_border_width(6)
  97. self.vbox.pack_start(vbox)
  98. # The header image + label
  99. hbox = gtk.HBox(spacing=10)
  100. vbox.pack_start(hbox, expand=False)
  101. align = gtk.Alignment(0.5, 0.5, 1.0, 1.0)
  102. hbox.pack_start(align, expand=False)
  103. image = gtk.image_new_from_stock(stock_image, gtk.ICON_SIZE_DIALOG)
  104. hbox.pack_start(image)
  105. label = gtk.Label(message)
  106. label.set_line_wrap(True)
  107. label.set_justify(gtk.JUSTIFY_FILL)
  108. label.set_selectable(True)
  109. label.set_property("can-focus", False)
  110. hbox.pack_start(label, expand=False)
  111. self.setup_dialog(vbox, *args, **kwargs)
  112. class InputStringDialog(CustomDialog):
  113. def __init__(self, message):
  114. CustomDialog.__init__(self, gtk.STOCK_DIALOG_INFO, message,
  115. (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
  116. gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
  117. def setup_dialog(self, vbox):
  118. self.entry = gtk.Entry()
  119. vbox.pack_start(self.entry, expand=False)
  120. def get_value(self):
  121. return self.entry.get_text()
  122. class ExceptionDialog(CustomDialog):
  123. # Register an exception hook to display an error when the GUI breaks
  124. @classmethod
  125. def create_excepthook(cls, oldhook):
  126. def excepthook(exctype, value, tb):
  127. if oldhook:
  128. oldhook(exctype, value, tb)
  129. application.run_once_in_main_thread(cls.start_dialog,
  130. ''.join(traceback.format_exception(exctype, value, tb)))
  131. return excepthook
  132. @classmethod
  133. def start_dialog(cls, tb):
  134. try:
  135. dialog = cls(tb)
  136. dialog.show_all()
  137. except:
  138. sys.exit(1)
  139. def __init__(self, tb):
  140. CustomDialog.__init__(self, gtk.STOCK_DIALOG_ERROR, "An error has occurred while doing an operation in Reportbug.\nPlease report the bug.", (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE), tb)
  141. def setup_dialog(self, vbox, tb):
  142. # The traceback
  143. expander = gtk.Expander("More details")
  144. vbox.pack_start(expander, True)
  145. view = gtk.TextView()
  146. view.set_editable(False)
  147. view.get_buffer().set_text(tb)
  148. scrolled = create_scrollable(view)
  149. expander.add(scrolled)
  150. self.connect('response', self.on_response)
  151. def on_response(self, dialog, res):
  152. sys.exit(1)
  153. class ReportViewerDialog(gtk.Dialog):
  154. def __init__(self, message):
  155. gtk.Dialog.__init__(self, "Reportbug", assistant,
  156. gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
  157. (gtk.STOCK_COPY, gtk.RESPONSE_APPLY,
  158. gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
  159. self.message = message
  160. self.set_default_size(400, 400)
  161. self.set_default_response(gtk.RESPONSE_CLOSE)
  162. self.set_border_width(6)
  163. self.connect('response', self.on_response)
  164. view = gtk.TextView()
  165. view.get_buffer().set_text(self.message)
  166. self.vbox.pack_start(create_scrollable(view))
  167. self.show_all()
  168. def on_response(self, dialog, res):
  169. # ok gtk.RESPONSE_APPLY is ugly for gtk.STOCK_COPY, but who cares?
  170. # maybe adding it as a secondary button or such is better
  171. if res == gtk.RESPONSE_APPLY:
  172. clipboard = gtk.clipboard_get()
  173. clipboard.set_text(self.message)
  174. else:
  175. self.destroy()
  176. # BTS
  177. class Bug(object):
  178. """Encapsulate a bug report for the GTK+ UI"""
  179. def __init__(self, bug):
  180. self.id = bug.bug_num
  181. self.tag = ', '.join(bug.tags)
  182. self.package = bug.package
  183. self.status = bug.pending
  184. self.reporter = bug.originator
  185. self.date = bug.date
  186. self.severity = bug.severity
  187. self.version = ', '.join(bug.found_versions)
  188. self.filed_date = bug.date
  189. self.modified_date = bug.log_modified
  190. self.info = bug.subject
  191. def __iter__(self):
  192. yield self.id
  193. yield self.tag
  194. yield self.package
  195. yield self.info
  196. yield self.status
  197. yield self.reporter
  198. yield self.date
  199. yield self.severity
  200. yield self.version
  201. yield self.filed_date
  202. yield self.modified_date
  203. class BugReport(object):
  204. def __init__(self, message):
  205. lines = message.split('\n')
  206. i = 0
  207. self.headers = []
  208. while i < len(lines):
  209. line = lines[i]
  210. i += 1
  211. if not line.strip():
  212. break
  213. self.headers.append(line)
  214. store = 0
  215. info = []
  216. while i < len(lines):
  217. line = lines[i]
  218. info.append(line)
  219. i += 1
  220. if store < 2 and not line.strip():
  221. store += 1
  222. continue
  223. if store == 2 and(line.startswith('-- ') or line.startswith('** ')):
  224. break
  225. store = 0
  226. self.original_info = '\n'.join(info[:-3])
  227. self.others = '\n'.join(lines[i - 1:])
  228. def get_others(self):
  229. return self.others
  230. def get_original_info(self):
  231. return self.original_info
  232. def get_subject(self):
  233. for header in self.headers:
  234. if 'Subject' in header:
  235. return header[len('Subject: '):]
  236. def set_subject(self, subject):
  237. for i in range(len(self.headers)):
  238. if 'Subject' in self.headers[i]:
  239. self.headers[i] = 'Subject: ' + subject
  240. break
  241. def wrap_bug_body(self, msg, width=79, break_long_words=False):
  242. """Wrap every line in the message"""
  243. # resulting body text
  244. body = ''
  245. for line in msg.splitlines():
  246. # wrap long lines, it returns a list of "sub-lines"
  247. tmp = textwrap.wrap(line, width=width,
  248. break_long_words=break_long_words)
  249. # need to special-case this else a join() on the list generator
  250. # would remove all the '[]' so no empty lines in the report
  251. if tmp == []:
  252. body += '\n'
  253. else:
  254. # join the "sub-lines" and add a \n at the end(if there is
  255. # only one item in the list, else there wouldn't be a \n)
  256. body += '\n'.join(tmp) + '\n'
  257. return body
  258. def create_message(self, info):
  259. message = """%s
  260. %s
  261. %s""" % ('\n'.join(self.headers), self.wrap_bug_body(info), self.others)
  262. return message
  263. # BTS GUI
  264. class BugPage(gtk.EventBox, threading.Thread):
  265. def __init__(self, assistant, dialog, number, queryonly, bts, mirrors, http_proxy, timeout, archived):
  266. threading.Thread.__init__(self)
  267. gtk.EventBox.__init__(self)
  268. self.setDaemon(True)
  269. self.dialog = dialog
  270. self.assistant = assistant
  271. self.application = self.assistant.application
  272. self.number = number
  273. self.queryonly = queryonly
  274. self.bts = bts
  275. self.mirrors = mirrors
  276. self.http_proxy = http_proxy
  277. self.timeout = timeout
  278. self.archived = archived
  279. self.bug_status = None
  280. vbox = gtk.VBox(spacing=12)
  281. vbox.pack_start(gtk.Label("Retrieving bug information."), expand=False)
  282. self.progress = gtk.ProgressBar()
  283. self.progress.set_pulse_step(0.01)
  284. vbox.pack_start(self.progress, expand=False)
  285. self.add(vbox)
  286. def run(self):
  287. # Start the progress bar
  288. gobject.timeout_add(10, self.pulse)
  289. info = debbugs.get_report(int(self.number), self.timeout,
  290. self.bts, mirrors=self.mirrors,
  291. http_proxy=self.http_proxy, archived=self.archived)
  292. if not info:
  293. self.application.run_once_in_main_thread(self.not_found)
  294. else:
  295. self.bug_status = info[0]
  296. self.application.run_once_in_main_thread(self.found, info)
  297. def drop_progressbar(self):
  298. child = self.get_child()
  299. if child:
  300. self.remove(child)
  301. child.unparent()
  302. def pulse(self):
  303. self.progress.pulse()
  304. return self.isAlive()
  305. def not_found(self):
  306. self.drop_progressbar()
  307. self.add(gtk.Label("The bug can't be fetched or it doesn't exist."))
  308. self.show_all()
  309. def found(self, info):
  310. self.drop_progressbar()
  311. desc = info[0].subject
  312. bodies = info[1]
  313. vbox = gtk.VBox(spacing=12)
  314. vbox.set_border_width(12)
  315. label = gtk.Label('Description: ' + desc)
  316. label.set_line_wrap(True)
  317. label.set_justify(gtk.JUSTIFY_FILL)
  318. vbox.pack_start(label, expand=False)
  319. views = gtk.VBox()
  320. odd = False
  321. for body in bodies:
  322. view = gtk.TextView()
  323. view.set_editable(False)
  324. view.get_buffer().set_text(body)
  325. if odd:
  326. view.set_state(gtk.STATE_PRELIGHT)
  327. views.pack_start(view, False)
  328. odd = not odd
  329. scrolled = create_scrollable(views, True)
  330. vbox.pack_start(scrolled)
  331. bbox = gtk.HButtonBox()
  332. button = gtk.Button("Open in browser")
  333. button.connect('clicked', self.on_open_browser)
  334. bbox.pack_start(button)
  335. if not self.queryonly:
  336. button = gtk.Button("Reply")
  337. button.set_image(gtk.image_new_from_stock(gtk.STOCK_EDIT, gtk.ICON_SIZE_BUTTON))
  338. button.connect('clicked', self.on_reply)
  339. bbox.pack_start(button)
  340. vbox.pack_start(bbox, expand=False)
  341. self.add(vbox)
  342. self.show_all()
  343. def on_open_browser(self, button):
  344. launch_browser(debbugs.get_report_url(self.bts, int(self.number), self.archived))
  345. def on_reply(self, button):
  346. # Return the bug number to reportbug
  347. self.application.set_next_value(self.bug_status)
  348. # Forward the assistant to the progress bar
  349. self.assistant.forward_page()
  350. # Though we're only a page, we are authorized to destroy our parent :)
  351. # This would be better handled connecting externally to self.reply_button
  352. self.dialog.destroy()
  353. class BugsDialog(gtk.Dialog):
  354. def __init__(self, assistant, queryonly):
  355. gtk.Dialog.__init__(self, "Reportbug: bug information", assistant,
  356. gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
  357. (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
  358. self.assistant = assistant
  359. self.queryonly = queryonly
  360. self.application = assistant.application
  361. self.notebook = gtk.Notebook()
  362. self.vbox.pack_start(self.notebook)
  363. self.connect('response', self.on_response)
  364. self.set_default_size(600, 600)
  365. def on_response(self, *args):
  366. self.destroy()
  367. def show_bug(self, number, *args):
  368. page = BugPage(self.assistant, self, number, self.queryonly, *args)
  369. self.notebook.append_page(page, gtk.Label(number))
  370. page.start()
  371. # Application
  372. class ReportbugApplication(threading.Thread):
  373. def __init__(self):
  374. threading.Thread.__init__(self)
  375. self.setDaemon(True)
  376. self.queue = Queue()
  377. self.next_value = None
  378. def run(self):
  379. gtk.gdk.threads_enter()
  380. gtk.main()
  381. gtk.gdk.threads_leave()
  382. def get_last_value(self):
  383. return self.queue.get()
  384. def put_next_value(self):
  385. self.queue.put(self.next_value)
  386. self.next_value = None
  387. def set_next_value(self, value):
  388. self.next_value = value
  389. @staticmethod
  390. def create_idle_callback(func, *args, **kwargs):
  391. def callback():
  392. func(*args, **kwargs)
  393. return False
  394. return callback
  395. def run_once_in_main_thread(self, func, *args, **kwargs):
  396. gobject.idle_add(self.create_idle_callback(func, *args, **kwargs))
  397. # Connection with reportbug
  398. # Syncronize "pipe" with reportbug
  399. class SyncReturn(RuntimeError):
  400. def __init__(self, result):
  401. RuntimeError.__init__(self, result)
  402. self.result = result
  403. class ReportbugConnector(object):
  404. # Executed in the glib thread
  405. def execute_operation(self, *args, **kwargs):
  406. pass
  407. # Executed in sync with reportbug. raise SyncResult(value) to directly return to reportbug
  408. # Returns args and kwargs to pass to execute_operation
  409. def sync_pre_operation(cls, *args, **kwargs):
  410. return args, kwargs
  411. # Assistant
  412. class Page(ReportbugConnector):
  413. next_page_num = 0
  414. page_type = gtk.ASSISTANT_PAGE_CONTENT
  415. default_complete = False
  416. side_image = DEBIAN_LOGO
  417. WARNING_COLOR = gtk.gdk.color_parse("#fff8ae")
  418. def __init__(self, assistant):
  419. self.assistant = assistant
  420. self.application = assistant.application
  421. self.widget = self.create_widget()
  422. self.widget.page = self
  423. self.widget.set_border_width(6)
  424. self.widget.show_all()
  425. self.page_num = Page.next_page_num
  426. def execute_operation(self, *args, **kwargs):
  427. self.switch_in()
  428. self.connect_signals()
  429. self.empty_ok = kwargs.pop('empty_ok', False)
  430. self.presubj = kwargs.pop('presubj', False)
  431. self.execute(*args, **kwargs)
  432. self.assistant.show()
  433. self.setup_focus()
  434. def connect_signals(self):
  435. pass
  436. def set_page_complete(self, complete):
  437. self.assistant.set_page_complete(self.widget, complete)
  438. def set_page_type(self, type):
  439. self.assistant.set_page_type(self.widget, type)
  440. def set_page_title(self, title):
  441. if title:
  442. self.assistant.set_page_title(self.widget, title)
  443. # The user will see this as next page
  444. def switch_in(self):
  445. Page.next_page_num += 1
  446. self.assistant.insert_page(self.widget, self.page_num)
  447. self.set_page_complete(self.default_complete)
  448. self.set_page_type(self.page_type)
  449. self.assistant.set_page_side_image(self.widget, gtk.gdk.pixbuf_new_from_file(self.side_image))
  450. self.assistant.set_next_page(self)
  451. self.set_page_title("Reportbug")
  452. # Setup keyboard focus in the page
  453. def setup_focus(self):
  454. self.widget.grab_focus()
  455. # Forward page when a widget is activated(e.g. GtkEntry) only if page is complete
  456. def activate_forward(self, *args):
  457. if self.assistant.get_page_complete(self.widget):
  458. self.assistant.forward_page()
  459. # The user forwarded the assistant to see the next page
  460. def switch_out(self):
  461. pass
  462. def is_valid(self, value):
  463. if self.empty_ok:
  464. return True
  465. else:
  466. return bool(value)
  467. def validate(self, *args, **kwargs):
  468. value = self.get_value()
  469. if self.is_valid(value):
  470. self.application.set_next_value(value)
  471. self.set_page_complete(True)
  472. else:
  473. self.set_page_complete(False)
  474. class IntroPage(Page):
  475. page_type = gtk.ASSISTANT_PAGE_INTRO
  476. default_complete = True
  477. def create_widget(self):
  478. vbox = gtk.VBox(spacing=24)
  479. label = gtk.Label("""
  480. <b>Reportbug</b> is a tool designed to make the reporting of bugs in Debian and derived distributions relatively painless.
  481. This wizard will guide you through the bug reporting process step by step.
  482. <b>Note:</b> bug reports are publicly archived(including the email address of the submitter).""")
  483. label.set_use_markup(True)
  484. label.set_line_wrap(True)
  485. label.set_justify(gtk.JUSTIFY_FILL)
  486. vbox.pack_start(label, expand=False)
  487. link = gtk.LinkButton("http://alioth.debian.org/projects/reportbug",
  488. "Homepage of reportbug project")
  489. vbox.pack_start(link, expand=False)
  490. return vbox
  491. class GetStringPage(Page):
  492. def setup_focus(self):
  493. self.entry.grab_focus()
  494. def create_widget(self):
  495. vbox = gtk.VBox(spacing=12)
  496. self.label = gtk.Label()
  497. self.label.set_line_wrap(True)
  498. self.label.set_justify(gtk.JUSTIFY_FILL)
  499. self.label.set_selectable(True)
  500. self.label.set_property("can-focus", False)
  501. self.entry = gtk.Entry()
  502. vbox.pack_start(self.label, expand=False)
  503. vbox.pack_start(self.entry, expand=False)
  504. return vbox
  505. def connect_signals(self):
  506. self.entry.connect('changed', self.validate)
  507. self.entry.connect('activate', self.activate_forward)
  508. def get_value(self):
  509. return self.entry.get_text()
  510. def execute(self, prompt, options=None, force_prompt=False, default=''):
  511. # Hackish: remove the text needed for textual UIs...
  512. gobject.idle_add(self.label.set_text, prompt.replace('(enter Ctrl+c to exit reportbug without reporting a bug)', ''))
  513. self.entry.set_text(default)
  514. if options:
  515. options.sort()
  516. completion = gtk.EntryCompletion()
  517. model = gtk.ListStore(str)
  518. for option in options:
  519. model.append([option])
  520. completion.set_model(model)
  521. completion.set_inline_selection(True)
  522. completion.set_text_column(0)
  523. self.entry.set_completion(completion)
  524. else:
  525. self.completion = None
  526. self.validate()
  527. class GetPasswordPage(GetStringPage):
  528. def create_widget(self):
  529. widget = GetStringPage.create_widget(self)
  530. self.entry.set_visibility(False)
  531. return widget
  532. class GetMultilinePage(Page):
  533. def setup_focus(self):
  534. self.view.grab_focus()
  535. def create_widget(self):
  536. vbox = gtk.VBox(spacing=12)
  537. self.label = gtk.Label()
  538. self.label.set_line_wrap(True)
  539. self.label.set_justify(gtk.JUSTIFY_FILL)
  540. self.label.set_selectable(True)
  541. self.label.set_property("can-focus", False)
  542. vbox.pack_start(self.label, expand=False)
  543. self.view = gtk.TextView()
  544. self.buffer = view.get_buffer()
  545. scrolled = create_scrollable(self.view)
  546. vbox.pack_start(scrolled)
  547. return vbox
  548. def connect_signals(self):
  549. self.buffer.connect('changed', self.validate)
  550. def get_value(self):
  551. text = self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter())
  552. lines = text.split('\n')
  553. # Remove the trailing empty line at the end
  554. if len(lines) > 0 and not lines[-1].strip():
  555. del lines[-1]
  556. return text.split('\n')
  557. def execute(self, prompt):
  558. self.empty_ok = True
  559. # The result must be iterable for reportbug even if it's empty and not modified
  560. gobject.idle_add(self.label.set_text, prompt)
  561. self.buffer.set_text("")
  562. self.buffer.emit('changed')
  563. class TreePage(Page):
  564. value_column = None
  565. def __init__(self, *args, **kwargs):
  566. Page.__init__(self, *args, **kwargs)
  567. self.selection = self.view.get_selection()
  568. def setup_focus(self):
  569. self.view.grab_focus()
  570. def connect_signals(self):
  571. self.selection.connect('changed', self.validate)
  572. def get_value(self):
  573. model, paths = self.selection.get_selected_rows()
  574. multiple = self.selection.get_mode() == gtk.SELECTION_MULTIPLE
  575. result = []
  576. for path in paths:
  577. value = model.get_value(model.get_iter(path), self.value_column)
  578. if value is not None:
  579. result.append(markup_free(value))
  580. if result and not multiple:
  581. return result[0]
  582. return result
  583. class GetListPage(TreePage):
  584. value_column = 0
  585. def create_widget(self):
  586. vbox = gtk.VBox(spacing=12)
  587. self.label = gtk.Label()
  588. self.label.set_line_wrap(True)
  589. self.label.set_justify(gtk.JUSTIFY_FILL)
  590. vbox.pack_start(self.label, expand=False)
  591. hbox = gtk.HBox(spacing=6)
  592. self.view = gtk.TreeView()
  593. self.view.set_rules_hint(True)
  594. self.view.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
  595. scrolled = create_scrollable(self.view)
  596. hbox.pack_start(scrolled)
  597. bbox = gtk.VButtonBox()
  598. bbox.set_spacing(6)
  599. bbox.set_layout(gtk.BUTTONBOX_START)
  600. button = gtk.Button(stock=gtk.STOCK_ADD)
  601. button.connect('clicked', self.on_add)
  602. bbox.pack_start(button, expand=False)
  603. button = gtk.Button(stock=gtk.STOCK_REMOVE)
  604. button.connect('clicked', self.on_remove)
  605. bbox.pack_start(button, expand=False)
  606. hbox.pack_start(bbox, expand=False)
  607. vbox.pack_start(hbox)
  608. return vbox
  609. def get_value(self):
  610. values = []
  611. for row in self.model:
  612. values.append(row[self.value_column])
  613. return values
  614. def on_add(self, button):
  615. dialog = InputStringDialog("Add a new item to the list")
  616. dialog.show_all()
  617. dialog.connect('response', self.on_add_dialog_response)
  618. def on_add_dialog_response(self, dialog, res):
  619. if res == gtk.RESPONSE_ACCEPT:
  620. self.model.append([dialog.get_value()])
  621. dialog.destroy()
  622. def on_remove(self, button):
  623. model, paths = self.selection.get_selected_rows()
  624. # We need to transform them to iters, since paths change when removing rows
  625. iters = []
  626. for path in paths:
  627. iters.append(self.model.get_iter(path))
  628. for iter in iters:
  629. self.model.remove(iter)
  630. def execute(self, prompt):
  631. self.empty_ok = True
  632. gobject.idle_add(self.label.set_text, prompt)
  633. self.model = gtk.ListStore(str)
  634. self.model.connect('row-changed', self.validate)
  635. self.view.set_model(self.model)
  636. self.selection.set_mode(gtk.SELECTION_MULTIPLE)
  637. self.view.append_column(gtk.TreeViewColumn('Item', gtk.CellRendererText(), text=0))
  638. class WrapRendererText(gtk.CellRendererText):
  639. def do_render(self, window, widget, background_area, cell_area, expose_area, flags):
  640. self.set_property('wrap-width', cell_area.width)
  641. gtk.CellRendererText.do_render(self, window, widget, background_area, cell_area, expose_area, flags)
  642. gobject.type_register(WrapRendererText)
  643. class MenuPage(TreePage):
  644. value_column = 0
  645. def create_widget(self):
  646. vbox = gtk.VBox(spacing=12)
  647. self.label = gtk.Label()
  648. self.label.set_line_wrap(True)
  649. self.label.set_justify(gtk.JUSTIFY_FILL)
  650. vbox.pack_start(self.label, expand=False)
  651. self.view = gtk.TreeView()
  652. self.view.set_rules_hint(True)
  653. scrolled = create_scrollable(self.view)
  654. scrolled.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
  655. vbox.pack_start(scrolled)
  656. vbox.show_all()
  657. return vbox
  658. def connect_signals(self):
  659. TreePage.connect_signals(self)
  660. self.view.connect('row-activated', self.activate_forward)
  661. def execute(self, par, options, prompt, default=None, any_ok=False,
  662. order=None, extras=None, multiple=False):
  663. gobject.idle_add(self.label.set_text, par)
  664. self.model = gtk.ListStore(str, str)
  665. self.view.set_model(self.model)
  666. if multiple:
  667. self.selection.set_mode(gtk.SELECTION_MULTIPLE)
  668. self.view.append_column(gtk.TreeViewColumn('Option', gtk.CellRendererText(), markup=0))
  669. rend = WrapRendererText()
  670. rend.set_property('wrap-mode', pango.WRAP_WORD)
  671. rend.set_property('wrap-width', 300)
  672. self.view.append_column(gtk.TreeViewColumn('Description', rend, text=1))
  673. default_iter = None
  674. # here below, 'text' is the value of the description of the item, but
  675. # writen all on a single-line, it will be wrapped by the list settings
  676. if isinstance(options, dict):
  677. if order:
  678. for option in order:
  679. if option in options:
  680. text = ' '.join(options[option].split())
  681. iter = self.model.append((highlight(option), text))
  682. if option == default:
  683. default_iter = iter
  684. for option, desc in options.items():
  685. if not order or option not in order:
  686. text = ' '.join(desc.split())
  687. iter = self.model.append((highlight(option), text))
  688. if option == default:
  689. default_iter = iter
  690. else:
  691. for row in options:
  692. text = ' '.join(row[1].split())
  693. iter = self.model.append((highlight(row[0]), text))
  694. if row[0] == default:
  695. default_iter = iter
  696. if default_iter:
  697. self.selection.select_iter(default_iter)
  698. class HandleBTSQueryPage(TreePage):
  699. default_complete = True
  700. value_column = 0
  701. def sync_pre_operation(self, package, bts, timeout, mirrors=None, http_proxy="", queryonly=False, screen=None,
  702. archived='no', source=False, title=None,
  703. version=None, buglist=None, mbox_reader_cmd=None, latest_first=False):
  704. self.bts = bts
  705. self.mirrors = mirrors
  706. self.http_proxy = http_proxy
  707. self.timeout = timeout
  708. self.archived = archived
  709. self.queryonly = queryonly
  710. if queryonly:
  711. self.page_type = gtk.ASSISTANT_PAGE_CONFIRM
  712. sysinfo = debbugs.SYSTEMS[bts]
  713. root = sysinfo.get('btsroot')
  714. if not root:
  715. # do we need to make a dialog for this?
  716. return
  717. if isinstance(package, str):
  718. pkgname = package
  719. if source:
  720. pkgname += '(source)'
  721. progress_label = 'Querying %s bug tracking system for reports on %s' % (debbugs.SYSTEMS[bts]['name'], pkgname)
  722. else:
  723. progress_label = 'Querying %s bug tracking system for reports %s' % (debbugs.SYSTEMS[bts]['name'], ' '.join([str(x) for x in package]))
  724. self.application.run_once_in_main_thread(self.assistant.set_progress_label, progress_label)
  725. try:
  726. (count, sectitle, hierarchy) = debbugs.get_reports(
  727. package, timeout, bts, mirrors=mirrors, version=version,
  728. http_proxy=http_proxy, archived=archived, source=source)
  729. except:
  730. error_dialog("Unable to connect to %s BTS." % sysinfo['name'])
  731. raise NoBugs
  732. try:
  733. if not count:
  734. if hierarchy is None:
  735. raise NoPackage
  736. else:
  737. raise NoBugs
  738. else:
  739. if count > 1:
  740. sectitle = '%d bug reports found' % (count,)
  741. else:
  742. sectitle = 'One bug report found'
  743. report = []
  744. for category, bugs in hierarchy:
  745. buglist = []
  746. for bug in bugs:
  747. buglist.append(bug)
  748. # XXX: this needs to be fixed in debianbts; Bugreport are
  749. # not sortable(on bug_num) - see #639458
  750. sorted(buglist, reverse=latest_first)
  751. report.append((category, list(map(Bug, buglist))))
  752. return(report, sectitle), {}
  753. except NoPackage:
  754. error_dialog('No record of this package found.')
  755. raise NoPackage
  756. raise SyncReturn(None)
  757. def setup_focus(self):
  758. self.entry.grab_focus()
  759. def create_widget(self):
  760. vbox = gtk.VBox(spacing=6)
  761. self.label = gtk.Label("List of bugs. Select a bug to retrieve and submit more information.")
  762. vbox.pack_start(self.label, expand=False, padding=6)
  763. hbox = gtk.HBox(spacing=6)
  764. label = gtk.Label("Filter:")
  765. hbox.pack_start(label, expand=False)
  766. self.entry = gtk.Entry()
  767. hbox.pack_start(self.entry)
  768. button = gtk.Button()
  769. button.set_image(gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU))
  770. button.set_relief(gtk.RELIEF_NONE)
  771. button.connect('clicked', self.on_filter_clear)
  772. hbox.pack_start(button, expand=False)
  773. vbox.pack_start(hbox, expand=False)
  774. self.view = gtk.TreeView()
  775. self.view.set_rules_hint(True)
  776. scrolled = create_scrollable(self.view)
  777. self.columns = ['ID', 'Tag', 'Package', 'Description', 'Status', 'Submitter', 'Date', 'Severity', 'Version',
  778. 'Filed date', 'Modified date']
  779. for col in zip(self.columns, list(range(len(self.columns)))):
  780. column = gtk.TreeViewColumn(col[0], gtk.CellRendererText(), text=col[1])
  781. column.set_reorderable(True)
  782. self.view.append_column(column)
  783. vbox.pack_start(scrolled)
  784. button = gtk.Button("Retrieve and submit bug information")
  785. button.set_image(gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON))
  786. button.connect('clicked', self.on_retrieve_info)
  787. vbox.pack_start(button, expand=False)
  788. return vbox
  789. def connect_signals(self):
  790. TreePage.connect_signals(self)
  791. self.view.connect('row-activated', self.on_retrieve_info)
  792. self.entry.connect('changed', self.on_filter_changed)
  793. def on_filter_clear(self, button):
  794. self.entry.set_text("")
  795. def on_filter_changed(self, entry):
  796. self.model.filter_text = entry.get_text().lower()
  797. self.filter.refilter()
  798. def on_retrieve_info(self, *args):
  799. bug_ids = TreePage.get_value(self)
  800. if not bug_ids:
  801. info_dialog("Please select one ore more bugs")
  802. return
  803. dialog = BugsDialog(self.assistant, self.queryonly)
  804. for id in bug_ids:
  805. dialog.show_bug(id, self.bts, self.mirrors, self.http_proxy, self.timeout, self.archived)
  806. dialog.show_all()
  807. def is_valid(self, value):
  808. return True
  809. def get_value(self):
  810. # The value returned to reportbug doesn't depend by a selection, but by the dialog of a bug
  811. return None
  812. def match_filter(self, iter):
  813. # Flatten the columns into a single string
  814. text = ""
  815. for col in range(len(self.columns)):
  816. value = self.model.get_value(iter, col)
  817. if value:
  818. text += self.model.get_value(iter, col) + " "
  819. text = text.lower()
  820. # Tokens shouldn't be adjacent by default
  821. for token in self.model.filter_text.split(' '):
  822. if token in text:
  823. return True
  824. return False
  825. def filter_visible_func(self, model, iter):
  826. matches = self.match_filter(iter)
  827. if not self.model.iter_parent(iter) and not matches:
  828. # If no children are visible, hide it
  829. it = model.iter_children(iter)
  830. while it:
  831. if self.match_filter(it):
  832. return True
  833. it = model.iter_next(it)
  834. return False
  835. return matches
  836. def execute(self, buglist, sectitle):
  837. gobject.idle_add(self.label.set_text, "%s. Double-click a bug to retrieve and submit more information." % sectitle)
  838. self.model = gtk.TreeStore(*([str] * len(self.columns)))
  839. for category in buglist:
  840. row = [None] * len(self.columns)
  841. row[3] = category[0]
  842. iter = self.model.append(None, row)
  843. for bug in category[1]:
  844. self.model.append(iter, list(bug))
  845. self.selection.set_mode(gtk.SELECTION_MULTIPLE)
  846. self.model.filter_text = ""
  847. self.filter = self.model.filter_new()
  848. self.filter.set_visible_func(self.filter_visible_func)
  849. self.view.set_model(self.filter)
  850. class ShowReportPage(Page):
  851. default_complete = True
  852. def create_widget(self):
  853. self.page = BugPage(self.assistant, None, None, None, None, None, None, None, None)
  854. return self.page
  855. def get_value(self):
  856. return None
  857. def is_valid(self, value):
  858. return True
  859. def sync_pre_operation(self, *args, **kwargs):
  860. if kwargs.get('queryonly'):
  861. self.page_type = gtk.ASSISTANT_PAGE_CONFIRM
  862. return args, kwargs
  863. def execute(self, number, system, mirrors, http_proxy, timeout, queryonly=False, title='', archived='no', mbox_reader_cmd=None):
  864. self.page.number = number
  865. self.page.bts = system
  866. self.page.mirrors = mirrors
  867. self.page.http_proxy = http_proxy
  868. self.page.timeout = timeout
  869. self.page.queryonly = queryonly
  870. self.page.archived = archived
  871. self.page.start()
  872. self.validate()
  873. class DisplayReportPage(Page):
  874. default_complete = True
  875. def create_widget(self):
  876. self.view = gtk.TextView()
  877. self.view.set_editable(False)
  878. scrolled = create_scrollable(self.view)
  879. return scrolled
  880. def execute(self, message, *args):
  881. # 'use' args only if it's passed
  882. if args:
  883. message = message % args
  884. self.view.get_buffer().set_text(message)
  885. class LongMessagePage(Page):
  886. default_complete = True
  887. def create_widget(self):
  888. self.label = gtk.Label()
  889. self.label.set_line_wrap(True)
  890. self.label.set_justify(gtk.JUSTIFY_FILL)
  891. self.label.set_selectable(True)
  892. self.label.set_property("can-focus", False)
  893. eb = gtk.EventBox()
  894. eb.add(self.label)
  895. return eb
  896. def execute(self, message, *args):
  897. message = message % args
  898. # make it all on one line, it will be wrapped at display-time
  899. message = ' '.join(message.split())
  900. gobject.idle_add(self.label.set_text, message)
  901. # Reportbug should use final_message, so emulate it
  902. if('999999' in message):
  903. self.set_page_type(gtk.ASSISTANT_PAGE_CONFIRM)
  904. self.set_page_title("Thanks for your report")
  905. class FinalMessagePage(LongMessagePage):
  906. page_type = gtk.ASSISTANT_PAGE_CONFIRM
  907. default_complete = True
  908. def execute(self, *args, **kwargs):
  909. LongMessagePage.execute(self, *args, **kwargs)
  910. self.set_page_title("Thanks for your report")
  911. class EditorPage(Page):
  912. def create_widget(self):
  913. vbox = gtk.VBox(spacing=6)
  914. hbox = gtk.HBox(spacing=12)
  915. hbox.pack_start(gtk.Label("Subject: "), expand=False)
  916. self.subject = gtk.Entry()
  917. hbox.pack_start(self.subject)
  918. vbox.pack_start(hbox, expand=False)
  919. self.view = gtk.TextView()
  920. self.view.modify_font(pango.FontDescription("Monospace"))
  921. self.view.set_wrap_mode(gtk.WRAP_WORD)
  922. if has_spell:
  923. gtkspellcheck.SpellChecker(self.view)
  924. self.info_buffer = self.view.get_buffer()
  925. scrolled = create_scrollable(self.view)
  926. vbox.pack_start(scrolled)
  927. expander = gtk.Expander("Other system information")
  928. view = gtk.TextView()
  929. view.set_editable(False)
  930. self.others_buffer = view.get_buffer()
  931. scrolled = create_scrollable(view)
  932. expander.add(scrolled)
  933. vbox.pack_start(expander, False)
  934. if not has_spell:
  935. box = gtk.EventBox()
  936. label = gtk.Label("Please install <b>python-gtkspellcheck</b> to enable spell checking")
  937. label.set_use_markup(True)
  938. label.set_line_wrap(True)
  939. label.set_selectable(True)
  940. label.set_property("can-focus", False)
  941. box.add(label)
  942. box.modify_bg(gtk.STATE_NORMAL, self.WARNING_COLOR)
  943. box.connect('button-press-event', lambda *args: box.destroy())
  944. vbox.pack_start(box, False)
  945. return vbox
  946. def switch_out(self):
  947. global report_message
  948. report_message = self.get_value()[0]
  949. f = file(self.filename, "w")
  950. f.write(report_message)
  951. f.close()
  952. def connect_signals(self):
  953. self.info_buffer.connect('changed', self.validate)
  954. self.subject.connect('changed', self.validate)
  955. def get_value(self):
  956. info = self.info_buffer.get_text(self.info_buffer.get_start_iter(),
  957. self.info_buffer.get_end_iter())
  958. if not info.strip():
  959. return None
  960. subject = self.subject.get_text().strip()
  961. if not subject.strip():
  962. return None
  963. self.report.set_subject(subject)
  964. message = self.report.create_message(info)
  965. message = message.decode(self.charset, 'replace')
  966. return(message, message != self.message)
  967. def handle_first_info(self):
  968. self.focus_in_id = self.view.connect('focus-in-event', self.on_view_focus_in_event)
  969. def on_view_focus_in_event(self, view, *args):
  970. # Empty the buffer only the first time
  971. self.info_buffer.set_text("")
  972. view.disconnect(self.focus_in_id)
  973. def execute(self, message, filename, editor, charset='utf-8'):
  974. self.message = message
  975. self.report = BugReport(message)
  976. self.filename = filename
  977. self.charset = charset
  978. self.subject.set_text(self.report.get_subject())
  979. self.others_buffer.set_text(self.report.get_others())
  980. info = self.report.get_original_info()
  981. if info.strip() == "*** Please type your report below this line ***":
  982. info = "Please type your report here.\nThe text will be wrapped to be max 79 chars long per line."
  983. self.handle_first_info()
  984. self.info_buffer.set_text(info)
  985. class SelectOptionsPage(Page):
  986. default_complete = False
  987. def create_widget(self):
  988. self.label = gtk.Label()
  989. self.label.set_line_wrap(True)
  990. self.label.set_justify(gtk.JUSTIFY_FILL)
  991. self.vbox = gtk.VBox(spacing=6)
  992. self.vbox.pack_start(self.label, expand=False, padding=6)
  993. self.default = None
  994. return self.vbox
  995. def on_clicked(self, button, menuopt):
  996. self.application.set_next_value(menuopt)
  997. self.assistant.forward_page()
  998. def on_display_clicked(self, button):
  999. global report_message
  1000. ReportViewerDialog(report_message)
  1001. def setup_focus(self):
  1002. if self.default:
  1003. self.default.set_flags(gtk.CAN_DEFAULT | gtk.HAS_DEFAULT)
  1004. self.default.grab_default()
  1005. self.default.grab_focus()
  1006. def execute(self, prompt, menuopts, options):
  1007. # remove text UI indication
  1008. prompt = prompt.replace('(e to edit)', '')
  1009. gobject.idle_add(self.label.set_text, prompt)
  1010. buttons = []
  1011. for menuopt in menuopts:
  1012. desc = options[menuopt.lower()]
  1013. # do we really need to launch an external editor?
  1014. if 'Change editor' in desc:
  1015. continue
  1016. # this will be handled using the text view below
  1017. if 'Pipe the message through the pager' in desc:
  1018. continue
  1019. # stdout is a textview for us
  1020. if 'Print message to stdout' in desc:
  1021. button = gtk.Button("Display message in a text view")
  1022. button.connect('clicked', self.on_display_clicked)
  1023. buttons.append(button)
  1024. else:
  1025. button = gtk.Button()
  1026. label = gtk.Label(options[menuopt.lower()])
  1027. button.add(label)
  1028. button.connect('clicked', self.on_clicked, menuopt.lower())
  1029. if menuopt.isupper():
  1030. label.set_markup("<b>%s</b>" % label.get_text())
  1031. self.default = button
  1032. buttons.insert(0, gtk.HSeparator())
  1033. buttons.insert(0, button)
  1034. else:
  1035. buttons.append(button)
  1036. for button in buttons:
  1037. self.vbox.pack_start(button, expand=False)
  1038. self.vbox.show_all()
  1039. class SystemPage(Page):
  1040. default_complete = False
  1041. def create_widget(self):
  1042. hbox = gtk.HBox()
  1043. self.terminal = vte.Terminal()
  1044. self.terminal.set_cursor_blinks(True)
  1045. self.terminal.set_emulation("xterm")
  1046. self.terminal.connect('child-exited', self.on_child_exited)
  1047. hbox.pack_start(self.terminal)
  1048. scrollbar = gtk.VScrollbar()
  1049. scrollbar.set_adjustment(self.terminal.get_adjustment())
  1050. hbox.pack_start(scrollbar)
  1051. return hbox
  1052. def on_child_exited(self, terminal):
  1053. self.application.set_next_value(None)
  1054. self.assistant.forward_page()
  1055. def execute(self, cmdline):
  1056. self.terminal.fork_command('/bin/bash', ['/bin/bash', '-c', cmdline])
  1057. class ProgressPage(Page):
  1058. page_type = gtk.ASSISTANT_PAGE_PROGRESS
  1059. def pulse(self):
  1060. self.progress.pulse()
  1061. return True
  1062. def create_widget(self):
  1063. vbox = gtk.VBox(spacing=6)
  1064. self.label = gtk.Label()
  1065. self.label.set_line_wrap(True)
  1066. self.label.set_justify(gtk.JUSTIFY_FILL)
  1067. self.progress = gtk.ProgressBar()
  1068. self.progress.set_pulse_step(0.01)
  1069. vbox.pack_start(self.label, expand=False)
  1070. vbox.pack_start(self.progress, expand=False)
  1071. gobject.timeout_add(10, self.pulse)
  1072. return vbox
  1073. def set_label(self, text):
  1074. gobject.idle_add(self.label.set_text, text)
  1075. def reset_label(self):
  1076. self.set_label("This operation may take a while")
  1077. class ReportbugAssistant(gtk.Assistant):
  1078. def __init__(self, application):
  1079. gtk.Assistant.__init__(self)
  1080. self.application = application
  1081. self.set_title('Reportbug')
  1082. self.hack_buttons()
  1083. self.showing_page = None
  1084. self.requested_page = None
  1085. self.progress_page = None
  1086. self.set_default_size(600, 400)
  1087. self.set_forward_page_func(self.forward)
  1088. self.connect_signals()
  1089. self.setup_pages()
  1090. def _hack_buttons(self, widget):
  1091. # This is a real hack for two reasons:
  1092. # 1. There's no other way to access action area but inspecting the assistant and searching for the back button
  1093. # 2. Hide back button on show, because it can be shown-hidden by the assistant depending on the page
  1094. if isinstance(widget, gtk.Button):
  1095. if widget.get_label() == 'gtk-go-back':
  1096. widget.connect('show', self.on_back_show)
  1097. return
  1098. if widget.get_label() == 'gtk-apply':
  1099. widget.connect('show', self.on_back_show)
  1100. return
  1101. if widget.get_label() == 'gtk-cancel':
  1102. image = gtk.image_new_from_stock(gtk.STOCK_QUIT,
  1103. gtk.ICON_SIZE_BUTTON)
  1104. widget.set_label("_Quit")
  1105. widget.set_image(image)
  1106. return
  1107. if widget.get_label() == 'gtk-go-forward':
  1108. image = gtk.image_new_from_stock(gtk.STOCK_GO_FORWARD, gtk.ICON_SIZE_BUTTON)
  1109. widget.set_label("_Continue")
  1110. widget.set_image(image)
  1111. return
  1112. if isinstance(widget, gtk.Container):
  1113. widget.forall(self._hack_buttons)
  1114. def hack_buttons(self):
  1115. self._hack_buttons(self)
  1116. def connect_signals(self):
  1117. self.connect('cancel', self.confirm_exit)
  1118. self.connect('prepare', self.on_prepare)
  1119. self.connect('delete-event', self.close)
  1120. self.connect('apply', self.close)
  1121. def on_back_show(self, widget):
  1122. widget.hide()
  1123. def on_prepare(self, assistant, widget):
  1124. # If the user goes back then forward, we must ensure the feedback value to reportbug must be sent
  1125. # when the user clicks on "Forward" to the requested page by reportbug
  1126. if self.showing_page and self.showing_page == self.requested_page and self.get_current_page() > self.showing_page.page_num:
  1127. self.application.put_next_value()
  1128. # Reportbug doesn't support going back, so make widgets insensitive
  1129. self.showing_page.widget.set_sensitive(False)
  1130. self.showing_page.switch_out()
  1131. self.showing_page = widget.page
  1132. # Some pages might have changed the label in the while
  1133. if self.showing_page == self.progress_page:
  1134. self.progress_page.reset_label()
  1135. gobject.idle_add(self.showing_page.setup_focus)
  1136. def close(self, *args):
  1137. sys.exit(0)
  1138. def confirm_exit(self, *args):
  1139. dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
  1140. gtk.MESSAGE_WARNING, gtk.BUTTONS_YES_NO,
  1141. "Are you sure you want to quit Reportbug?")
  1142. response = dialog.run()
  1143. dialog.destroy()
  1144. if response == gtk.RESPONSE_YES:
  1145. sys.exit(0)
  1146. def forward(self, page_num):
  1147. return page_num + 1
  1148. def forward_page(self):
  1149. self.set_current_page(self.forward(self.showing_page.page_num))
  1150. def set_next_page(self, page):
  1151. self.requested_page = page
  1152. # If we're in progress immediately show this guy
  1153. if self.showing_page == self.progress_page:
  1154. self.set_current_page(page.page_num)
  1155. def set_progress_label(self, text, *args, **kwargs):
  1156. self.progress_page.set_label(text % args)
  1157. def setup_pages(self):
  1158. # We insert pages between the intro and the progress, so that we give the user the feedback
  1159. # that the applications is still running when he presses the "Forward" button
  1160. self.showing_page = IntroPage(self)
  1161. self.showing_page.switch_in()
  1162. self.progress_page = ProgressPage(self)
  1163. self.progress_page.switch_in()
  1164. Page.next_page_num = 1
  1165. # Dialogs
  1166. class YesNoDialog(ReportbugConnector, gtk.MessageDialog):
  1167. def __init__(self, application):
  1168. gtk.MessageDialog.__init__(self, assistant, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
  1169. gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO)
  1170. self.application = application
  1171. self.connect('response', self.on_response)
  1172. def on_response(self, dialog, res):
  1173. self.application.set_next_value(res == gtk.RESPONSE_YES)
  1174. self.application.put_next_value()
  1175. self.destroy()
  1176. def execute_operation(self, msg, yeshelp=None, nohelp=None, default=True, nowrap=False):
  1177. self.set_markup(msg)
  1178. if default:
  1179. self.set_default_response(gtk.RESPONSE_YES)
  1180. else:
  1181. self.set_default_response(gtk.RESPONSE_NO)
  1182. self.show_all()
  1183. class DisplayFailureDialog(ReportbugConnector, gtk.MessageDialog):
  1184. def __init__(self, application):
  1185. gtk.MessageDialog.__init__(self, assistant, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
  1186. gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE)
  1187. self.application = application
  1188. self.connect('response', self.on_response)
  1189. def on_response(self, dialog, res):
  1190. self.application.put_next_value()
  1191. self.destroy()
  1192. def execute_operation(self, msg, *args):
  1193. self.set_markup(msg % args)
  1194. self.show_all()
  1195. class GetFilenameDialog(ReportbugConnector, gtk.FileChooserDialog):
  1196. def __init__(self, application):
  1197. gtk.FileChooserDialog.__init__(self, '', assistant, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
  1198. gtk.STOCK_OPEN, gtk.RESPONSE_OK))
  1199. self.application = application
  1200. self.connect('response', self.on_response)
  1201. def on_response(self, dialog, res):
  1202. value = None
  1203. if res == gtk.RESPONSE_OK:
  1204. value = self.get_filename()
  1205. self.application.set_next_value(value)
  1206. self.application.put_next_value()
  1207. self.destroy()
  1208. def execute_operation(self, title, force_prompt=False):
  1209. self.set_title(ask_free(title))
  1210. self.show_all()
  1211. def log_message(*args, **kwargs):
  1212. return assistant.set_progress_label(*args, **kwargs)
  1213. def select_multiple(*args, **kwargs):
  1214. kwargs['multiple'] = True
  1215. kwargs['empty_ok'] = True
  1216. return menu(*args, **kwargs)
  1217. def get_multiline(prompt, *args, **kwargs):
  1218. if 'ENTER' in prompt:
  1219. # This is a list, let's handle it the best way
  1220. return get_list(prompt, *args, **kwargs)
  1221. else:
  1222. return get_multiline(prompt, *args, **kwargs)
  1223. pages = {'get_string': GetStringPage,
  1224. 'get_password': GetPasswordPage,
  1225. 'menu': MenuPage,
  1226. 'handle_bts_query': HandleBTSQueryPage,
  1227. 'show_report': ShowReportPage,
  1228. 'long_message': LongMessagePage,
  1229. 'display_report': DisplayReportPage,
  1230. 'final_message': FinalMessagePage,
  1231. 'spawn_editor': EditorPage,
  1232. 'select_options': SelectOptionsPage,
  1233. 'get_list': GetListPage,
  1234. 'system': SystemPage,
  1235. }
  1236. dialogs = {'yes_no': YesNoDialog,
  1237. 'get_filename': GetFilenameDialog,
  1238. 'display_failure': DisplayFailureDialog,
  1239. }
  1240. def create_forwarder(parent, klass):
  1241. def func(*args, **kwargs):
  1242. op = klass(parent)
  1243. try:
  1244. args, kwargs = op.sync_pre_operation(*args, **kwargs)
  1245. except SyncReturn as e:
  1246. return e.result
  1247. application.run_once_in_main_thread(op.execute_operation, *args, **kwargs)
  1248. return application.get_last_value()
  1249. return func
  1250. def forward_operations(parent, operations):
  1251. for operation, klass in operations.items():
  1252. globals()[operation] = create_forwarder(parent, klass)
  1253. def initialize():
  1254. global application, assistant, vte
  1255. try:
  1256. vte = __import__("vte")
  1257. except ImportError:
  1258. message = """Please install the %s package to use the GTK+(known as 'gtk2' in reportbug) interface.
  1259. Falling back to 'text' interface."""
  1260. dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
  1261. gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, None)
  1262. dialog.set_markup(message % "<b>python-vte</b>")
  1263. dialog.run()
  1264. dialog.destroy()
  1265. while gtk.events_pending():
  1266. gtk.main_iteration()
  1267. if not sys.stdout.isatty():
  1268. os.execlp('x-terminal-emulator', 'x-terminal-emulator', '-e', 'reportbug -u text')
  1269. return False
  1270. # Exception hook
  1271. oldhook = sys.excepthook
  1272. sys.excepthook = ExceptionDialog.create_excepthook(oldhook)
  1273. # GTK settings
  1274. gtk.window_set_default_icon_from_file(DEBIAN_LOGO)
  1275. gtk.link_button_set_uri_hook(lambda button, uri: launch_browser(uri))
  1276. application = ReportbugApplication()
  1277. assistant = ReportbugAssistant(application)
  1278. # Forwarders
  1279. forward_operations(assistant, pages)
  1280. forward_operations(application, dialogs)
  1281. application.start()
  1282. return True
  1283. def can_input():
  1284. return True