summaryrefslogtreecommitdiffstats
path: root/src/Gui/CCMainWindow.py
blob: 35e9b1a3bf026fad696a95c692722068c8d0bde2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import sys
import pygtk
pygtk.require("2.0")
import gobject
import gtk
import gtk.glade
import CCDBusBackend
import sys
from CC_gui_functions import *
from CCDumpList import getDumpList, DumpList
from CCReporterDialog import ReporterDialog
from CCReport import Report
from exception import installExceptionHandler, handleMyException
try:
    import rpm
except:
    rpm = None

installExceptionHandler("cc-gui", "0.0.1")

class MainWindow():
    def __init__(self):
        self.theme = theme = gtk.icon_theme_get_default()
        try:
            self.ccdaemon = CCDBusBackend.DBusManager()
        except Exception, e:
            # show error message if connection fails
            # FIXME add an option to start the daemon
            gui_error_message(e.message)
            sys.exit()
        #Set the Glade file
        # FIXME add to PATH
        # FIXME remove!
        
        self.gladefile = "%s%sccgui.glade" % (sys.path[0],"/")
        self.wTree = gtk.glade.XML(self.gladefile)
        
        #Get the Main Window, and connect the "destroy" event
        self.window = self.wTree.get_widget("main_window2")
        self.window.set_default_size(700, 480)
        if (self.window):
            self.window.connect("delete_event", self.delete_event_cb)
            self.window.connect("destroy", self.destroy)
        
        self.appBar = self.wTree.get_widget("appBar")
        # pregress bar window to show while bt is being extracted
        self.pBarWindow = self.wTree.get_widget("pBarWindow")
        self.pBarWindow.set_transient_for(self.window)
        self.pBar = self.wTree.get_widget("pBar")
        
        # set colours for descritpion heading
        self.wTree.get_widget("evDescription").modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("black"))
        
        #init the dumps treeview
        self.dlist = self.wTree.get_widget("tvDumps")
        self.dumpsListStore = gtk.ListStore(gtk.gdk.Pixbuf, str,str,str,str, object)
        # set filter
        self.modelfilter = self.dumpsListStore.filter_new()
        self.modelfilter.set_visible_func(self.filter_dumps, None)
        self.dlist.set_model(self.modelfilter)
        # add pixbuff separatelly
        icon_column = gtk.TreeViewColumn('Icon')
        icon_column.cell = gtk.CellRendererPixbuf()
        n = self.dlist.append_column(icon_column)
        icon_column.pack_start(icon_column.cell, False)
        icon_column.set_attributes(icon_column.cell, pixbuf=(n-1))
        # ===============================================
        columns = [None]*4
        columns[0] = gtk.TreeViewColumn('Package')
        columns[1] = gtk.TreeViewColumn('Application')
        columns[2] = gtk.TreeViewColumn('Date')
        columns[3] = gtk.TreeViewColumn('Crash Rate')
        # create list
        for column in columns:
            n = self.dlist.append_column(column)
            column.cell = gtk.CellRendererText()
            column.pack_start(column.cell, False)
            column.set_attributes(column.cell, text=(n-1))
            column.set_resizable(True)
        #connect signals
        self.dlist.connect("cursor-changed", self.on_tvDumps_cursor_changed)
        self.wTree.get_widget("bDelete").connect("clicked", self.on_bDelete_clicked, self.dlist)
        self.wTree.get_widget("bReport").connect("clicked", self.on_bReport_clicked)
        self.wTree.get_widget("bQuit").connect("clicked", self.on_bQuit_clicked)
        self.ccdaemon.connect("crash", self.on_data_changed_cb, None)
        self.ccdaemon.connect("analyze-complete", self.on_analyze_complete_cb, self.pBarWindow)
        
        # load data
        #self.load()
        
    # call to update the progressbar
    def progress_update_cb(self, *args):
        self.pBar.pulse()
        return True
        
    def hydrate(self):
        self.dumpsListStore.clear()
        self.rows = self.ccdaemon.getDumps()
        try:
            dumplist = getDumpList(self.ccdaemon, refresh=True)
        except Exception, e:
            gui_error_message("Error while loading the dumplist, please check if abrt daemon is running\n %s" % e.message)
        for entry in dumplist:
            try:
                icon = get_icon_for_package(self.theme,entry.getPackageName())
            except:
                icon = None
            self.dumpsListStore.append([icon, entry.getPackage(),entry.getExecutable(), entry.getTime("%Y.%m.%d %H:%M:%S"),entry.getCount(), entry])
            
    def filter_dumps(self, model, miter, data):
        # for later..
        return True

    def on_tvDumps_cursor_changed(self,treeview):
        dumpsListStore, path = self.dlist.get_selection().get_selected_rows()
        if not path:
            self.wTree.get_widget("lDescription").set_label("")
            return
        # this should work until we keep the row object in the last position
        dump = dumpsListStore.get_value(dumpsListStore.get_iter(path[0]), len(self.dlist.get_columns()))
        
        #move this to Dump class
        lPackage = self.wTree.get_widget("lPackage")
        self.wTree.get_widget("lDescription").set_label(dump.getDescription())
        #print self.rows[row]
    def on_bDelete_clicked(self, button, treeview):
        dumpsListStore, path = self.dlist.get_selection().get_selected_rows()
        if not path:
            return
        # this should work until we keep the row object in the last position
        dump = dumpsListStore.get_value(dumpsListStore.get_iter(path[0]), len(self.dlist.get_columns()))
        try:
            if self.ccdaemon.DeleteDebugDump(dump.UUID):
                self.hydrate()
                treeview.emit("cursor-changed")
            else:
                print "Couldn't delete"
        except Exception, e:
            print e
    
    def destroy(self, widget, data=None):
        print "destroy signal occurred"
        gtk.main_quit()
    
    def on_data_changed_cb(self, *args):
        ret = gui_question_dialog("Another crash detected, do you want to refresh the data?",self.window)
        if ret == gtk.RESPONSE_YES:
            self.hydrate()
        else:
            pass
        #print "got another crash, refresh gui?"
    
    def on_analyze_complete_cb(self, daemon, report, pBarWindow):
        gobject.source_remove(self.timer)
        self.pBarWindow.hide()
        try:
            dumplist = getDumpList(self.ccdaemon)
        except Exception, e:
            print e
        if not report:
            gui_error_message("Unable to get report!\nDebuginfo is missing?")
            return
        report_dialog = ReporterDialog(report)
        result = report_dialog.run()
        if result:
            self.ccdaemon.Report(result)
        #ret = gui_question_dialog("GUI: Analyze for package %s crash with UUID %s is complete" % (entry.Package, UUID),self.window)
        #if ret == gtk.RESPONSE_YES:
        #    self.hydrate()
        #else:
        #    pass
        #print "got another crash, refresh gui?"
    
    
    def on_bReport_clicked(self, button):
        # FIXME don't duplicate the code, move to function
        dumpsListStore, path = self.dlist.get_selection().get_selected_rows()
        if not path:
            return
        self.update_pBar = False
        self.pBar.show()
        self.pBarWindow.show()
        self.timer = gobject.timeout_add (100,self.progress_update_cb)
        
        dump = dumpsListStore.get_value(dumpsListStore.get_iter(path[0]), len(self.dlist.get_columns()))
        # show the report window with selected dump
        try:
            report = self.ccdaemon.getReport(dump.getUUID())
        except Exception, e:
            # FIXME #3	dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply
            # do this async and wait for yum to end with debuginfoinstal
            gui_error_message("Error getting the report: %s" % e.message)
        return

    def delete_event_cb(self, widget, event, data=None):
        # Change FALSE to TRUE and the main window will not be destroyed
        # with a "delete_event".
        return self.on_bQuit_clicked(widget)
        
    def on_bQuit_clicked(self, widget):
        ret = gui_question_dialog("Do you really want to quit?",self.window)
        if ret == gtk.RESPONSE_YES:
            gtk.main_quit()
        return True
            
    def show(self):
        self.window.show()
    

if __name__ == "__main__":
    cc = MainWindow()
    cc.hydrate()
    cc.show()
    gtk.main()