def check(self): # If we have found the correct user, then we need to ensure we are # in the valid time duration and have not exceeded the limit if not self.isEnabled: return True # Check for the case where we didn't get the user ID - this means we are # already shutting down if self.userId in [None, ""]: return False log("UserPinControl: Performing check for user %s" % self.userId) # First check that the current time is within the allowed boundaries localTime = time.localtime() currentTime = (localTime.tm_hour * 60) + localTime.tm_min if self.allowedStartTime > currentTime or self.allowedEndTime < currentTime: log("UserPinControl: User not allowed access until %d to %d currently %d" % (self.allowedStartTime, self.allowedEndTime, currentTime)) self.shutdown(32130) return False # Check if the screensaver is running, if so we need to make sure we do not # class that as time used by the user if xbmc.getCondVisibility("System.ScreenSaverActive"): if self.screensaverStart < 1: self.screensaverStart = currentTime else: # Not the screensaver, check to see if this is the first check # after the screensaver stopped if self.screensaverStart > 0: screensaverDuration = currentTime - self.screensaverStart self.screensaverStart = 0 log("UserPinControl: Updating duration for screensaver, %d minutes" % screensaverDuration) # Now we roll the time forward that we started viewing so that # we are not counting the screensaver self.startedViewing = self.startedViewing + screensaverDuration # Check to see if we need to update the record for how long the user has already been viewing viewingLimit = Settings.getUserViewingLimit(self.userId) self.usedViewingLimit = currentTime - self.startedViewing log("UserPinControl: Time used by user is %d" % self.usedViewingLimit) # Update the settings record for how much this user has viewed so far Settings.setUserViewingUsedTime(self.userId, self.usedViewingLimit) # Now check to see if the user has exceeded their limit if self.usedViewingLimit >= viewingLimit: self.shutdown(32133) return False # Check if we need to warn the user that the time is running out warningTime = Settings.getWarnExpiringTime() if (not self.warningDisplayed) and ((self.usedViewingLimit + warningTime) >= viewingLimit): self.warningDisplayed = True # Calculate the time left remainingTime = viewingLimit - self.usedViewingLimit msg = "%d %s" % (remainingTime, __addon__.getLocalizedString(32134)) xbmcgui.Dialog().notification(__addon__.getLocalizedString(32001).encode('utf-8'), msg, __icon__, 3000, False) return True
def displaySummary(self): # Load the settings for this user allowedStartTime, displayStartTime = Settings.getUserStartTime(self.userId) allowedEndTime, displayEndTime = Settings.getUserEndTime(self.userId) viewingLimit = Settings.getUserViewingLimit(self.userId) usersName = Settings.getUserName(self.userId) # Work out how much time is remaining displayRemainingTime = viewingLimit - self.usedViewingLimit if displayRemainingTime < 0: displayRemainingTime = 0 # Do a notification to let the user know how long they have left today summaryUserName = "******" % (__addon__.getLocalizedString(32035), usersName) summaryLimit = "%s: %d" % (__addon__.getLocalizedString(32033), viewingLimit) summaryLimitRemaining = "%s: %d" % (__addon__.getLocalizedString(32131), displayRemainingTime) summaryAccess = "%s: %s - %s" % (__addon__.getLocalizedString(32132), displayStartTime, displayEndTime) fullSummary = "%s\n%s\n%s\n%s" % (summaryUserName, summaryLimit, summaryLimitRemaining, summaryAccess) xbmcgui.Dialog().ok(__addon__.getLocalizedString(32001).encode('utf-8'), fullSummary)