'Handles the events from gui/customevents. The second
argument is the \'receiver\', but as this was made for QT3 it is now
deprecated and we must manually set the receiver until the
events module is updated.
DO NOT, AND I REPEAT, DO NOT REDRAW *ANYTHING* FROM THE GUI
FROM HERE. If you must do it, you should to it sing GObject.idle_add,
a misterious function with outdated documentation. Good luck.'

def postEvent(self, _, event):

    def new_log_event():
        GObject.idle_add(self.console_log.customEvent, event.text)
    def new_conflict_event():
        GObject.idle_add(self.statusbar.update_conflict_button_label, event.nconflicts)
    def new_notification_event():
        self.notificationsModel.prepend([str(event)])
        GObject.idle_add(self.statusbar.inc_notif_button_label)
        (host_count, service_count, vuln_count) = self.update_counts()
        GObject.idle_add(self.statusbar.update_ws_info, host_count, service_count, vuln_count)
    def workspace_changed_event():
        self.serverIO.active_workspace = event.workspace.name
        (host_count, service_count, vuln_count) = self.update_counts()
        total_host_amount = self.serverIO.get_hosts_number()
        first_host_page = self.serverIO.get_hosts(page='0', page_size='20', sort='vulns', sort_dir='desc')
        total_host_amount = self.serverIO.get_workspace_numbers()[0]
        GObject.idle_add(self.statusbar.set_workspace_label, event.workspace.name)
        GObject.idle_add(self.hosts_sidebar.reset_model_after_workspace_changed, first_host_page, total_host_amount)
        GObject.idle_add(self.statusbar.update_ws_info, host_count, service_count, vuln_count)
        GObject.idle_add(self.statusbar.set_default_conflict_label)
        GObject.idle_add(self.statusbar.set_default_conflict_label)
        GObject.idle_add(self.select_active_workspace)
    def normal_error_event():
        GObject.idle_add(self.show_normal_error, event.text)
    def important_error_event():
        GObject.idle_add(self.show_important_error, event)
    def lost_connection_to_server_event():
        GObject.idle_add(self.lost_db_connection, event.problem, self.handle_connection_lost, self.force_change_couch_url)
        GObject.idle_add(self.reload_workspaces_no_connection)
    def workspace_not_accessible_event():
        GObject.idle_add(self.handle_no_active_workspace)
    def add_object():
        if event.new_obj:
            GObject.idle_add(self.hosts_sidebar.add_object, event.new_obj)
            (host_count, service_count, vuln_count) = self.update_counts()
            GObject.idle_add(self.statusbar.update_ws_info, host_count, service_count, vuln_count)
    def delete_object():
        if event.obj_id:
            GObject.idle_add(self.hosts_sidebar.remove_object, event.obj_id)
            (host_count, service_count, vuln_count) = self.update_counts()
            GObject.idle_add(self.statusbar.update_ws_info, host_count, service_count, vuln_count)
    def update_object():
        if event.obj:
            GObject.idle_add(self.hosts_sidebar.update_object, event.obj)
            (host_count, service_count, vuln_count) = self.update_counts()
            GObject.idle_add(self.statusbar.update_ws_info, host_count, service_count, vuln_count)
    dispatch = {3131: new_log_event, 3141: new_conflict_event, 5100: new_notification_event, 3140: workspace_changed_event, 3132: normal_error_event, 3134: important_error_event, 42424: lost_connection_to_server_event, 24242: workspace_not_accessible_event, 7777: add_object, 8888: delete_object, 9999: update_object}
    function = dispatch.get(event.type())
    if (function is not None):
        function()
