| 1 | # Copyright (C) 2005-2006 Insecure.Com LLC. |
|---|
| 2 | # Copyright (C) 2007 Adriano Monteiro Marques |
|---|
| 3 | # |
|---|
| 4 | # Authors: Adriano Monteiro Marques <py.adriano@gmail.com> |
|---|
| 5 | # Frederico Silva Ribeiro <ribeiro.fsilva@gmail.com> |
|---|
| 6 | # |
|---|
| 7 | # This program is free software; you can redistribute it and/or modify |
|---|
| 8 | # it under the terms of the GNU General Public License as published by |
|---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | # (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, |
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | # GNU General Public License for more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License |
|---|
| 18 | # along with this program; if not, write to the Free Software |
|---|
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | import gtk |
|---|
| 22 | import gobject |
|---|
| 23 | import webbrowser |
|---|
| 24 | |
|---|
| 25 | from higwidgets.higdialogs import HIGAlertDialog |
|---|
| 26 | from higwidgets.higlabels import HIGSectionLabel, HIGHintSectionLabel |
|---|
| 27 | from higwidgets.higtables import HIGTable |
|---|
| 28 | from higwidgets.higwindows import HIGWindow |
|---|
| 29 | from higwidgets.higboxes import HIGHBox, HIGVBox |
|---|
| 30 | |
|---|
| 31 | from umit.core.BugRegister import BugRegister |
|---|
| 32 | from umit.core.I18N import _ |
|---|
| 33 | |
|---|
| 34 | class CrashReport(HIGWindow): |
|---|
| 35 | def __init__(self, summary, description): |
|---|
| 36 | HIGWindow.__init__(self) |
|---|
| 37 | gtk.Window.__init__(self) |
|---|
| 38 | self.set_title(_('Crash Report')) |
|---|
| 39 | self.set_position(gtk.WIN_POS_CENTER_ALWAYS) |
|---|
| 40 | |
|---|
| 41 | self.response_id = False |
|---|
| 42 | |
|---|
| 43 | self._create_widgets() |
|---|
| 44 | self._pack_widgets() |
|---|
| 45 | self._connect_widgets() |
|---|
| 46 | |
|---|
| 47 | self.summary = summary |
|---|
| 48 | self.description = description |
|---|
| 49 | |
|---|
| 50 | def _create_widgets(self): |
|---|
| 51 | self.vbox = HIGVBox() |
|---|
| 52 | self.button_box = gtk.HButtonBox() |
|---|
| 53 | |
|---|
| 54 | self.private_check = gtk.CheckButton(_("Only Umit project members should read this \ |
|---|
| 55 | bug report")) |
|---|
| 56 | |
|---|
| 57 | self.email_label = HIGHintSectionLabel(_("Email"), |
|---|
| 58 | _("Please, inform a valid e-mail address, from \ |
|---|
| 59 | where you can be reached to be notified when the bug get fixed. Not used for other purposes.")) |
|---|
| 60 | self.email_entry = gtk.Entry() |
|---|
| 61 | |
|---|
| 62 | self.description_label = HIGHintSectionLabel(_("Description"), |
|---|
| 63 | _("This is where you should really write \ |
|---|
| 64 | about the bug, describing it as clear as possible, and giving as many informations as you can \ |
|---|
| 65 | along with your system informations, like: Which operating system you're using? \ |
|---|
| 66 | Which Nmap version you have insalled?")) |
|---|
| 67 | self.description_scrolled = gtk.ScrolledWindow() |
|---|
| 68 | self.description_text = gtk.TextView() |
|---|
| 69 | |
|---|
| 70 | self.bug_icon = gtk.Image() |
|---|
| 71 | self.bug_text = gtk.Label(_("This Bug Report dialog, allows you to easily tell us \ |
|---|
| 72 | about a problem that you may have found on Umit. Doing so, you help us to help you, by \ |
|---|
| 73 | fixing and improving Umit faster than usual.")) |
|---|
| 74 | |
|---|
| 75 | self.btn_ok = gtk.Button(stock=gtk.STOCK_OK) |
|---|
| 76 | self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL) |
|---|
| 77 | |
|---|
| 78 | self.hbox = HIGHBox() |
|---|
| 79 | self.table = HIGTable() |
|---|
| 80 | |
|---|
| 81 | def _pack_widgets(self): |
|---|
| 82 | self.description_scrolled.add(self.description_text) |
|---|
| 83 | self.description_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| 84 | self.description_scrolled.set_size_request(400, 150) |
|---|
| 85 | self.description_text.set_wrap_mode(gtk.WRAP_WORD) |
|---|
| 86 | |
|---|
| 87 | self.bug_icon.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG) |
|---|
| 88 | self.bug_icon.set_padding(10, 0) |
|---|
| 89 | self.bug_text.set_line_wrap(True) |
|---|
| 90 | |
|---|
| 91 | self.hbox.set_border_width(12) |
|---|
| 92 | self.vbox.set_border_width(6) |
|---|
| 93 | |
|---|
| 94 | self.table.attach_label(self.email_label, 0, 1, 0, 1) |
|---|
| 95 | self.table.attach_entry(self.email_entry, 1, 2, 0, 1) |
|---|
| 96 | |
|---|
| 97 | self.table.attach_label(self.description_label, 0, 1, 1, 2) |
|---|
| 98 | self.table.attach_entry(self.description_scrolled, 0, 2, 2, 3) |
|---|
| 99 | |
|---|
| 100 | self.hbox._pack_noexpand_nofill(self.bug_icon) |
|---|
| 101 | self.hbox._pack_expand_fill(self.bug_text) |
|---|
| 102 | |
|---|
| 103 | self.button_box.set_layout(gtk.BUTTONBOX_END) |
|---|
| 104 | self.button_box.pack_start(self.btn_ok) |
|---|
| 105 | self.button_box.pack_start(self.btn_cancel) |
|---|
| 106 | |
|---|
| 107 | self.vbox._pack_noexpand_nofill(self.hbox) |
|---|
| 108 | self.vbox._pack_expand_fill(self.table) |
|---|
| 109 | self.vbox._pack_noexpand_nofill(self.button_box) |
|---|
| 110 | self.add(self.vbox) |
|---|
| 111 | |
|---|
| 112 | def _connect_widgets(self): |
|---|
| 113 | self.btn_ok.connect("clicked", self.send_report) |
|---|
| 114 | self.btn_cancel.connect("clicked", self.close) |
|---|
| 115 | self.connect("delete-event", self.close) |
|---|
| 116 | |
|---|
| 117 | def send_report(self, widget): |
|---|
| 118 | if self.description == "" or self.email == "": |
|---|
| 119 | cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR, |
|---|
| 120 | message_format=_("Bug report is incomplete!"), |
|---|
| 121 | secondary_text=_("The bug report is incomplete. \ |
|---|
| 122 | You must inform a description that explains clearly what is happening and a valid e-mail, \ |
|---|
| 123 | so you can be contacted when the bug get fixed.")) |
|---|
| 124 | cancel_dialog.run() |
|---|
| 125 | cancel_dialog.destroy() |
|---|
| 126 | return None |
|---|
| 127 | |
|---|
| 128 | bug_register = BugRegister() |
|---|
| 129 | |
|---|
| 130 | bug_register.is_private = self.private |
|---|
| 131 | bug_register.category_id = "862568" |
|---|
| 132 | bug_register.summary = self.summary |
|---|
| 133 | bug_register.details = "%s\n\nEmail: %s" % (self.description, self.email) |
|---|
| 134 | |
|---|
| 135 | bug_page = None |
|---|
| 136 | try: |
|---|
| 137 | bug_page = bug_register.report() |
|---|
| 138 | except: |
|---|
| 139 | cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR, |
|---|
| 140 | message_format=_("Bug not reported!"), |
|---|
| 141 | secondary_text=_("The bug description could \ |
|---|
| 142 | not be reported. This problem may be caused by the lack of Internet Access or \ |
|---|
| 143 | indisponibility of the bug tracker server. Please, verify your internet access, and \ |
|---|
| 144 | then try to report the bug once again.")) |
|---|
| 145 | cancel_dialog.run() |
|---|
| 146 | cancel_dialog.destroy() |
|---|
| 147 | else: |
|---|
| 148 | ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO, |
|---|
| 149 | message_format=_("Bug sucessfully reported!"), |
|---|
| 150 | secondary_text=_("The bug description was \ |
|---|
| 151 | sucessfully reported. A web page with detailed description about this report is \ |
|---|
| 152 | going to be openned in your default web browser.")) |
|---|
| 153 | ok_dialog.run() |
|---|
| 154 | ok_dialog.destroy() |
|---|
| 155 | |
|---|
| 156 | self.close() |
|---|
| 157 | |
|---|
| 158 | if bug_page: |
|---|
| 159 | try: |
|---|
| 160 | webbrowser.open(bug_page) |
|---|
| 161 | except: |
|---|
| 162 | page_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR, |
|---|
| 163 | message_format=_("Could not open default Web Browser"), |
|---|
| 164 | secondary_text=_("Umit was unable to open your default \ |
|---|
| 165 | web browser to show the bug tracker page with the report status. Try to visit the Umit's \ |
|---|
| 166 | bug tracker page to see if your bug was reported (you won't see if you marked the check box \ |
|---|
| 167 | that makes the report private).")) |
|---|
| 168 | page_dialog.run() |
|---|
| 169 | page_dialog.destroy() |
|---|
| 170 | |
|---|
| 171 | self.close() |
|---|
| 172 | |
|---|
| 173 | def close(self, widget=None, event=None): |
|---|
| 174 | self.destroy() |
|---|
| 175 | gtk.main_quit() |
|---|
| 176 | |
|---|
| 177 | def get_description(self): |
|---|
| 178 | buff = self.description_text.get_buffer() |
|---|
| 179 | return buff.get_text(buff.get_start_iter(), buff.get_end_iter()) |
|---|
| 180 | |
|---|
| 181 | def set_description(self, description): |
|---|
| 182 | self.description_text.get_buffer().set_text(description) |
|---|
| 183 | |
|---|
| 184 | def get_private(self): |
|---|
| 185 | if self.private_check.get_active(): |
|---|
| 186 | return "1" |
|---|
| 187 | return "0" |
|---|
| 188 | |
|---|
| 189 | def set_private(self, private): |
|---|
| 190 | self.private_check.set_active(private) |
|---|
| 191 | |
|---|
| 192 | def get_email(self): |
|---|
| 193 | return self.email_entry.get_text() |
|---|
| 194 | |
|---|
| 195 | def set_email(self, email): |
|---|
| 196 | self.email_entry.set_text(email) |
|---|
| 197 | |
|---|
| 198 | def run_unblocked(self): |
|---|
| 199 | if not self.modal: |
|---|
| 200 | self.set_modal(True) |
|---|
| 201 | self.show_all() |
|---|
| 202 | |
|---|
| 203 | description = property(get_description, set_description) |
|---|
| 204 | private = property(get_private, set_private) |
|---|
| 205 | email = property(get_email, set_email) |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | if __name__ == "__main__": |
|---|
| 209 | c = CrashReport("Sumariu", "Descricao") |
|---|
| 210 | c.show_all() |
|---|
| 211 | c.connect("delete-event", lambda x, y: gtk.main_quit()) |
|---|
| 212 | |
|---|
| 213 | gtk.main() |
|---|