Ejemplo n.º 1
0
    def __init__(self):
        GObject.GObject.__init__(self)
        
        ## object to manage processes to activate for.
        self.ProcMan = caffeine.get_ProcManager()
        
        ## Status string.
        self.status_string = ""

        ## Makes sure that only one instance of Caffeine is run for
        ## each user on the system.
        self.pid_name = '/tmp/caffeine' + str(os.getuid()) + '.pid'
        self.appInstance = applicationinstance.ApplicationInstance( self.pid_name )

        ## In the next three list strings represent desktop enviroments in order:
        ## "KDE, GNOME and Unity", "Xfce and LXDE", "MATE".
        self.dbus_service = [
            'org.freedesktop.ScreenSaver',
            'org.freedesktop.PowerManagement',
            'org.mate.ScreenSaver'
        ]

        self.dbus_path = [
            '/ScreenSaver',
            '/org/freedesktop/PowerManagement/Inhibit',
            '/',
        ]

        self.dbus_interface = [
            'org.freedesktop.ScreenSaver',
            'org.freedesktop.PowerManagement.Inhibit',
            'org.mate.ScreenSaver',
        ]

        ## Number indicating what dbus service/path/interface to use.
        self.dbusType = None

	## This variable is set to a string describing only the type of screensaver
        ## used on this computer. Needed because users sometimes install additional
	## screensaver not from default instalation. It is detected when the user
        ## first attempts to inhibit the screensaver and powersaving. At the moment
	## only detects xscreensaver. Can be set to value: "XSS".
        self.screensaverType = None

        # Set to True when the detection routine is in progress
        self.attemptingToDetect = False

        self.dbusDetectionTimer = None
        self.dbusDetectionFailures = 0

        # Set to True when sleep seems to be prevented from the perspective of the user.
        # This does not necessarily mean that sleep really is prevented, because the
        # detection routine could be in progress.
        self.sleepAppearsPrevented = False

        # Set to True when sleep mode has been successfully inhibited somehow. This should
        # match up with "self.sleepAppearsPrevented" most of the time.
        self.sleepIsPrevented = False

        self.preventedForProcess = False
        self.dbusCookie = None
        self.xss_id = None

        ## check for processes to activate for.
        GObject.timeout_add(10000, self._check_for_process)
        
        print self.status_string
Ejemplo n.º 2
0
    def __init__(self):
        
        GObject.GObject.__init__(self)

        
        ## object to manage processes to activate for.
        self.ProcMan = caffeine.get_ProcManager()
        
        ## Status string.
        self.status_string = ""

        ## Makes sure that only one instance of Caffeine is run for
        ## each user on the system.
        self.pid_name = '/tmp/caffeine' + str(os.getuid()) + '.pid'
        self.appInstance = applicationinstance.ApplicationInstance( self.pid_name )

        ## This variable is set to a string describing the type of screensaver and
        ## powersaving systems used on this computer. It is detected when the user
        ## first attempts to inhibit the screensaver and powersaving, and can be set
        ## to one of the following values: "Gnome", "KDE", "XSS+DPMS" or "DPMS".
        self.screensaverAndPowersavingType = None

        # Set to True when the detection routine is in progress
        self.attemptingToDetect = False

        self.dbusDetectionTimer = None
        self.dbusDetectionFailures = 0

        # Set to True when sleep seems to be prevented from the perspective of the user.
        # This does not necessarily mean that sleep really is prevented, because the
        # detection routine could be in progress.
        self.sleepAppearsPrevented = False

        # Set to True when sleep mode has been successfully inhibited somehow. This should
        # match up with "self.sleepAppearsPrevented" most of the time.
        self.sleepIsPrevented = False

        self.preventedForProcess = False
        self.preventedForQL = False
        self.preventedForFlash = False

        self.screenSaverCookie = None
        self.powerManagementCookie = None
        self.timer = None
        self.inhibit_id = None


        self.note = None
        
        ## check for processes to activate for.
        id = GObject.timeout_add(10000, self._check_for_process)

        
        settings = Gio.Settings.new(caffeine.BASE_KEY)
        ## check for Quake Live.
        self.ql_id = None
        if settings.get_boolean("act-for-quake"):
            self.setActivateForQL(True)

        ## check for Flash video.
        self.flash_durations = {}
        self.flash_id = None
        if settings.get_boolean("act-for-flash"):
            self.setActivateForFlash(True)
        print self.status_string