def notify(self, message, actions=[]):
        '''Display a notification.

        @message, string
        @actions, a list of actions
        '''
        varRPlaceId = QtCore.QVariant(0)
        varRPlaceId.convert(QtCore.QVariant.UInt)
        varActions = QtCore.QVariant(actions)
        varActions.convert(QtCore.QVariant.StringList)

        msg = self.call(
            'Notify',  # `Notify` method
            _(constants.APP_NAME),  # app name
            varRPlaceId,  # replaces_id
            constants.ICON_NAME,  # app icon
            _(constants.APP_NAME),  # summary
            message,  # message body
            varActions,  # actions
            {},  # hints
            -1  # expire timeout, default is -1
        )
        reply = QtDBus.QDBusReply(msg)
        if reply.isValid():
            return reply.value()
        else:
            return None
Beispiel #2
0
 def call_dbus(method, *args):
     result = self.iface.call(method, *args)
     reply = QtDBus.QDBusReply(result)
     assert reply.isValid(), 'Dbus reply was not valid: {}'.format(
         bus_connection.lastError().message())
     LOGGER.debug("Called dbus %s: returned %s (%s)", method,
                  reply.value(), type(reply.value()))
     # return the whole value
     return reply.value()
Beispiel #3
0
 def set_conn_result(self, connection_id, save_option, verdict,
                     apply_to_all):
     msg = self.app.dbus_handler.interface.call(
         'connection_set_result', connection_id,
         RuleSaveOption(save_option).value,
         RuleVerdict(verdict).value, apply_to_all)
     reply = QtDBus.QDBusReply(msg)
     if not reply.isValid():
         logging.info('Could not apply result to connection "%s"',
                      connection_id)
         logging.error(msg.arguments()[0])
Beispiel #4
0
    def handle_connection(self):
        # This method will get called again after the user took action
        # on the currently handled connection
        if self.connection is not None:
            return

        try:
            connection = self.connection_queue.get_nowait()
        except queue.Empty:
            return

        # Check if process is still alive, if not we dont need to handle
        if connection.app_pid:
            try:
                os.kill(connection.app_pid, 0)
            except ProcessLookupError:
                return

        # Re-check in case permanent rule was added since connection was queued
        verd = False
        with self.rule_lock:
            msg = self.app.dbus_handler.interface.call(
                'connection_recheck_verdict', connection.id)
            reply = QtDBus.QDBusReply(msg)
            if reply.isValid() and reply.value():
                verd = True
            elif not reply.isValid():
                logging.error(msg.arguments()[0])

        # Lock needs to be released before callback can be triggered
        if verd:
            return self.add_connection_signal.emit()

        self.connection = connection
        if connection.app_path is not None:
            app_name, app_icon = self.desktop_parser.get_info_by_path(
                connection.app_path)
        else:
            app_name = 'Unknown'
            app_icon = None

        self.setup_labels(app_name)
        self.setup_icon(app_icon)
        self.setup_extra()
        self.result = Dialog.DEFAULT_RESULT
        self.action_combo_box.setCurrentIndex(0)
        self.show()