Ejemplo n.º 1
0
    def __init__(self):
        QObject.__init__(self)
        self.sysTray = KMySystemTray()
        self.sysTray.setPixmap(self.sysTray.loadIcon("ksmarttray"))
        self.sysTray.show()

        self.process = KProcIO()

        self.state = KSmartTray.State.Waiting
        self.lastKnownStatus = ""

        self.blinkFlag = False
        self.updateFailed = False

        self.checkTimer = QTimer()
        self.blinkTimer = QTimer()

        QObject.connect(self.checkTimer, SIGNAL("timeout()"),
                        self.checkUpgrades)
        QObject.connect(self.process, SIGNAL("processExited(KProcess *)"),
                        self.processDone)

        QObject.connect(self, PYSIGNAL("foundNewUpgrades()"),
                        self.startBlinking)
        QObject.connect(self, PYSIGNAL("foundNoUpgrades()"), self.stopBlinking)
        QObject.connect(self.sysTray, PYSIGNAL("mouseEntered()"),
                        self.stopBlinking)
        QObject.connect(self.blinkTimer, SIGNAL("timeout()"), self.toggleBlink)

        QObject.connect(self.sysTray.checkAction, SIGNAL("activated()"),
                        self.manualCheckUpgrades)
        QObject.connect(self.sysTray.startSmartAction, SIGNAL("activated()"),
                        self.startSmart)
        QObject.connect(self.sysTray.stopAction, SIGNAL("activated()"),
                        self.stopChecking)
        QObject.connect(self.sysTray, SIGNAL("quitSelected()"),
                        KApplication.kApplication(), SLOT("quit()"))

        QObject.connect(self.sysTray, PYSIGNAL("activated()"),
                        self.runUpgrades)

        self.checkTimer.start(5 * 60 * 1000)

        self.checkUpgrades()
Ejemplo n.º 2
0
    def __init__(self):
        QObject.__init__(self)
        self.sysTray = KMySystemTray()
        self.sysTray.setPixmap(self.sysTray.loadIcon("ksmarttray"))
        self.sysTray.show()
    
        self.process = KProcIO()
    
        self.state = KSmartTray.State.Waiting
        self.lastKnownStatus = ""
    
        self.blinkFlag = False
        self.updateFailed = False
    
        self.checkTimer = QTimer()
        self.blinkTimer = QTimer()

        QObject.connect(self.checkTimer, SIGNAL("timeout()"), self.checkUpgrades)
        QObject.connect(self.process, SIGNAL("processExited(KProcess *)"),
                self.processDone)
    
        QObject.connect(self, PYSIGNAL("foundNewUpgrades()"), self.startBlinking)
        QObject.connect(self, PYSIGNAL("foundNoUpgrades()"), self.stopBlinking)
        QObject.connect(self.sysTray, PYSIGNAL("mouseEntered()"), self.stopBlinking)
        QObject.connect(self.blinkTimer, SIGNAL("timeout()"), self.toggleBlink)
    
        QObject.connect(self.sysTray.checkAction, SIGNAL("activated()"),
                self.manualCheckUpgrades)
        QObject.connect(self.sysTray.startSmartAction, SIGNAL("activated()"),
                self.startSmart)
        QObject.connect(self.sysTray.stopAction, SIGNAL("activated()"),
                self.stopChecking)
        QObject.connect(self.sysTray, SIGNAL("quitSelected()"),
                KApplication.kApplication(), SLOT("quit()"))
    
        QObject.connect(self.sysTray, PYSIGNAL("activated()"), self.runUpgrades)
    
        self.checkTimer.start(5*60*1000)
    
        self.checkUpgrades()
Ejemplo n.º 3
0
class KSmartTray(QObject):
    class State:
        Waiting = 'StateWaiting'
        Updating = 'StateUpdating'
        Checking = 'StateChecking'
        Upgrading = 'StateUpgrading'
        RunningSmart = 'StateRunningSmart'

    def __init__(self):
        QObject.__init__(self)
        self.sysTray = KMySystemTray()
        self.sysTray.setPixmap(self.sysTray.loadIcon("ksmarttray"))
        self.sysTray.show()

        self.process = KProcIO()

        self.state = KSmartTray.State.Waiting
        self.lastKnownStatus = ""

        self.blinkFlag = False
        self.updateFailed = False

        self.checkTimer = QTimer()
        self.blinkTimer = QTimer()

        QObject.connect(self.checkTimer, SIGNAL("timeout()"),
                        self.checkUpgrades)
        QObject.connect(self.process, SIGNAL("processExited(KProcess *)"),
                        self.processDone)

        QObject.connect(self, PYSIGNAL("foundNewUpgrades()"),
                        self.startBlinking)
        QObject.connect(self, PYSIGNAL("foundNoUpgrades()"), self.stopBlinking)
        QObject.connect(self.sysTray, PYSIGNAL("mouseEntered()"),
                        self.stopBlinking)
        QObject.connect(self.blinkTimer, SIGNAL("timeout()"), self.toggleBlink)

        QObject.connect(self.sysTray.checkAction, SIGNAL("activated()"),
                        self.manualCheckUpgrades)
        QObject.connect(self.sysTray.startSmartAction, SIGNAL("activated()"),
                        self.startSmart)
        QObject.connect(self.sysTray.stopAction, SIGNAL("activated()"),
                        self.stopChecking)
        QObject.connect(self.sysTray, SIGNAL("quitSelected()"),
                        KApplication.kApplication(), SLOT("quit()"))

        QObject.connect(self.sysTray, PYSIGNAL("activated()"),
                        self.runUpgrades)

        self.checkTimer.start(5 * 60 * 1000)

        self.checkUpgrades()

    def internalCheckUpgrades(self, manual):
        if not manual and self.blinkTimer.isActive():
            return
        if self.state == KSmartTray.State.Waiting:
            self.sysTray.checkAction.setEnabled(False)
            self.sysTray.startSmartAction.setEnabled(False)
            self.sysTray.stopAction.setEnabled(True)
            self.process.resetAll()
            if manual:
                self.process.setArguments(["smart-update"])
            else:
                self.process.setArguments(["smart-update", "--after", "60"])
            if not self.process.start():
                KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                    "Couldn't run 'smart-update'.")
            else:
                QToolTip.add(self.sysTray, "Updating channels...")
                self.state = KSmartTray.State.Updating

    def checkUpgrades(self):
        self.internalCheckUpgrades(False)

    def manualCheckUpgrades(self):
        self.internalCheckUpgrades(True)

    def runUpgrades(self):
        if self.state != KSmartTray.State.Waiting:
            KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                "There is a running process.")
        else:
            self.sysTray.checkAction.setEnabled(False)
            self.sysTray.startSmartAction.setEnabled(False)
            self.sysTray.stopAction.setEnabled(False)
            self.process.resetAll()
            self.process.setArguments(
                ["kdesu", "-d", "-c", "smart --gui upgrade"])
            if not self.process.start():
                KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                    "Couldn't run 'smart upgrade'.")
            else:
                self.state = KSmartTray.State.Upgrading
                QToolTip.remove(self.sysTray)
                QToolTip.add(self.sysTray, "Running Smart Package Manager...")

    def startSmart(self):
        if self.state != KSmartTray.State.Waiting:
            KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                "There is a running process.")
        else:
            self.sysTray.checkAction.setEnabled(False)
            self.sysTray.startSmartAction.setEnabled(False)
            self.sysTray.stopAction.setEnabled(False)
            self.process.resetAll()
            self.process.setArguments(["kdesu", "-d", "-c", "smart --gui"])
            if not self.process.start():
                KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                    "Couldn't run 'smart'.")
            else:
                self.state = KSmartTray.State.RunningSmart
                QToolTip.remove(self.sysTray)
                QToolTip.add(self.sysTray, "Running Smart Package Manager...")

    def stopChecking(self):
        self.process.kill()

    def processDone(self, process):
        if self.state == KSmartTray.State.Updating:
            if not process.normalExit() or process.exitStatus() != 0:
                self.updateFailed = True
            if self.updateFailed and not self.lastKnownStatus == "":
                self.state = KSmartTray.State.Waiting
            else:
                process.resetAll()
                process.setArguments(["smart", "upgrade", "--check-update"])
                if not process.start():
                    KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                        "Couldn't run 'smart upgrade'.")
                    self.state = KSmartTray.State.Waiting
                    self.lastKnownStatus = ""
                else:
                    QToolTip.remove(self.sysTray)
                    QToolTip.add(self.sysTray,
                                 "Verifying upgradable packages...")
                    self.state = KSmartTray.State.Checking
        elif self.state == KSmartTray.State.Checking:
            self.state = KSmartTray.State.Waiting
            if process.normalExit():
                if process.exitStatus() == 0:
                    self.lastKnownStatus = "There are new upgrades available!"
                    KNotifyClient.event(self.sysTray.winId(),
                                        "found-new-upgrades",
                                        self.lastKnownStatus)
                    self.emit(PYSIGNAL("foundNewUpgrades()"), ())
                elif process.exitStatus() == 1:
                    self.lastKnownStatus = "There are pending upgrades!"
                    if not self.updateFailed:
                        KNotifyClient.event(self.sysTray.winId(),
                                            "found-old-upgrades",
                                            self.lastKnownStatus)
                    self.emit(PYSIGNAL("foundOldUpgrades()"), ())
                elif process.exitStatus() == 2:
                    self.lastKnownStatus = "No interesting upgrades available."
                    if not self.updateFailed:
                        KNotifyClient.event(self.sysTray.winId(),
                                            "found-no-upgrades",
                                            self.lastKnownStatus)
                    self.emit(PYSIGNAL("foundNoUpgrades()"), ())
                else:
                    self.lastKnownStatus = ""
        elif self.state == KSmartTray.State.Upgrading:
            self.state = KSmartTray.State.Waiting
            self.lastKnownStatus = ""
        elif self.state == KSmartTray.State.RunningSmart:
            self.state = KSmartTray.State.Waiting
            self.lastKnownStatus = ""
        else:
            # Error!
            pass

        if self.state == KSmartTray.State.Waiting:
            self.updateFailed = False
            self.sysTray.checkAction.setEnabled(True)
            self.sysTray.startSmartAction.setEnabled(True)
            self.sysTray.stopAction.setEnabled(False)
            if not self.lastKnownStatus == "":
                QToolTip.remove(self.sysTray)
                QToolTip.add(self.sysTray, self.lastKnownStatus)
            else:
                QToolTip.remove(self.sysTray)

    def startBlinking(self):
        if not self.blinkTimer.isActive():
            self.blinkTimer.start(500)

    def stopBlinking(self):
        if self.blinkTimer.isActive():
            self.blinkTimer.stop()
        self.sysTray.setPixmap(self.sysTray.loadIcon("ksmarttray"))

    def toggleBlink(self):
        if self.blinkFlag:
            self.sysTray.setPixmap(QPixmap())
        else:
            self.sysTray.setPixmap(self.sysTray.loadIcon("ksmarttray"))
        self.blinkFlag = not self.blinkFlag
Ejemplo n.º 4
0
class KSmartTray(QObject):

    class State:
         Waiting = 'StateWaiting'
         Updating = 'StateUpdating'
         Checking = 'StateChecking'
         Upgrading = 'StateUpgrading'
         RunningSmart = 'StateRunningSmart'

    def __init__(self):
        QObject.__init__(self)
        self.sysTray = KMySystemTray()
        self.sysTray.setPixmap(self.sysTray.loadIcon("ksmarttray"))
        self.sysTray.show()
    
        self.process = KProcIO()
    
        self.state = KSmartTray.State.Waiting
        self.lastKnownStatus = ""
    
        self.blinkFlag = False
        self.updateFailed = False
    
        self.checkTimer = QTimer()
        self.blinkTimer = QTimer()

        QObject.connect(self.checkTimer, SIGNAL("timeout()"), self.checkUpgrades)
        QObject.connect(self.process, SIGNAL("processExited(KProcess *)"),
                self.processDone)
    
        QObject.connect(self, PYSIGNAL("foundNewUpgrades()"), self.startBlinking)
        QObject.connect(self, PYSIGNAL("foundNoUpgrades()"), self.stopBlinking)
        QObject.connect(self.sysTray, PYSIGNAL("mouseEntered()"), self.stopBlinking)
        QObject.connect(self.blinkTimer, SIGNAL("timeout()"), self.toggleBlink)
    
        QObject.connect(self.sysTray.checkAction, SIGNAL("activated()"),
                self.manualCheckUpgrades)
        QObject.connect(self.sysTray.startSmartAction, SIGNAL("activated()"),
                self.startSmart)
        QObject.connect(self.sysTray.stopAction, SIGNAL("activated()"),
                self.stopChecking)
        QObject.connect(self.sysTray, SIGNAL("quitSelected()"),
                KApplication.kApplication(), SLOT("quit()"))
    
        QObject.connect(self.sysTray, PYSIGNAL("activated()"), self.runUpgrades)
    
        self.checkTimer.start(5*60*1000)
    
        self.checkUpgrades()
    
    def internalCheckUpgrades(self, manual):
        if not manual and self.blinkTimer.isActive():
            return
        if self.state == KSmartTray.State.Waiting:
            self.sysTray.checkAction.setEnabled(False)
            self.sysTray.startSmartAction.setEnabled(False)
            self.sysTray.stopAction.setEnabled(True)
            self.process.resetAll()
            if manual:
                self.process.setArguments(["smart-update"])
            else:
                self.process.setArguments(["smart-update", "--after", "60"])
            if not self.process.start():
                KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                     "Couldn't run 'smart-update'.")
            else:
                QToolTip.add(self.sysTray, "Updating channels...")
                self.state = KSmartTray.State.Updating
    
    def checkUpgrades(self):
        self.internalCheckUpgrades(False)
    
    def manualCheckUpgrades(self):
        self.internalCheckUpgrades(True)
    
    def runUpgrades(self):
        if self.state != KSmartTray.State.Waiting:
            KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                 "There is a running process.")
        else:
            self.sysTray.checkAction.setEnabled(False)
            self.sysTray.startSmartAction.setEnabled(False)
            self.sysTray.stopAction.setEnabled(False)
            self.process.resetAll()
            self.process.setArguments(["kdesu", "-d", "-c", "smart --gui upgrade"])
            if not self.process.start():
                KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                     "Couldn't run 'smart upgrade'.")
            else:
                self.state = KSmartTray.State.Upgrading
                QToolTip.remove(self.sysTray)
                QToolTip.add(self.sysTray, "Running Smart Package Manager...")
    
    def startSmart(self):
        if self.state != KSmartTray.State.Waiting:
            KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                 "There is a running process.")
        else:
            self.sysTray.checkAction.setEnabled(False)
            self.sysTray.startSmartAction.setEnabled(False)
            self.sysTray.stopAction.setEnabled(False)
            self.process.resetAll()
            self.process.setArguments(["kdesu", "-d", "-c", "smart --gui"])
            if not self.process.start():
                KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                     "Couldn't run 'smart'.")
            else:
                self.state = KSmartTray.State.RunningSmart
                QToolTip.remove(self.sysTray)
                QToolTip.add(self.sysTray, "Running Smart Package Manager...")
    
    def stopChecking(self):
        self.process.kill()
    
    def processDone(self, process):
        if self.state == KSmartTray.State.Updating:
            if not process.normalExit() or process.exitStatus() != 0:
                self.updateFailed = True
            if self.updateFailed and not self.lastKnownStatus == "":
                self.state = KSmartTray.State.Waiting
            else:
                process.resetAll()
                process.setArguments(["smart", "upgrade", "--check-update"])
                if not process.start():
                    KNotifyClient.event(self.sysTray.winId(), "fatalerror",
                                         "Couldn't run 'smart upgrade'.")
                    self.state = KSmartTray.State.Waiting
                    self.lastKnownStatus = ""
                else:
                    QToolTip.remove(self.sysTray)
                    QToolTip.add(self.sysTray,
                                  "Verifying upgradable packages...")
                    self.state = KSmartTray.State.Checking
        elif self.state == KSmartTray.State.Checking:
            self.state = KSmartTray.State.Waiting
            if process.normalExit():
                if process.exitStatus() == 0:
                    self.lastKnownStatus = "There are new upgrades available!"
                    KNotifyClient.event(self.sysTray.winId(), "found-new-upgrades",
                                         self.lastKnownStatus)
                    self.emit(PYSIGNAL("foundNewUpgrades()"), ())
                elif process.exitStatus() == 1:
                    self.lastKnownStatus = "There are pending upgrades!"
                    if not self.updateFailed:
                        KNotifyClient.event(self.sysTray.winId(),
                                             "found-old-upgrades",
                                             self.lastKnownStatus)
                    self.emit(PYSIGNAL("foundOldUpgrades()"), ())
                elif process.exitStatus() == 2:
                    self.lastKnownStatus = "No interesting upgrades available."
                    if not self.updateFailed:
                        KNotifyClient.event(self.sysTray.winId(),
                                             "found-no-upgrades",
                                             self.lastKnownStatus)
                    self.emit(PYSIGNAL("foundNoUpgrades()"), ())
                else:
                    self.lastKnownStatus = ""
        elif self.state == KSmartTray.State.Upgrading:
            self.state = KSmartTray.State.Waiting
            self.lastKnownStatus = ""
        elif self.state ==  KSmartTray.State.RunningSmart:
            self.state = KSmartTray.State.Waiting
            self.lastKnownStatus = ""
        else:
            # Error!
            pass

        if self.state == KSmartTray.State.Waiting:
            self.updateFailed = False
            self.sysTray.checkAction.setEnabled(True)
            self.sysTray.startSmartAction.setEnabled(True)
            self.sysTray.stopAction.setEnabled(False)
            if not self.lastKnownStatus == "":
                QToolTip.remove(self.sysTray)
                QToolTip.add(self.sysTray, self.lastKnownStatus)
            else:
                QToolTip.remove(self.sysTray)
    
    def startBlinking(self):
        if not self.blinkTimer.isActive():
            self.blinkTimer.start(500)
    
    def stopBlinking(self):
        if self.blinkTimer.isActive():
            self.blinkTimer.stop()
        self.sysTray.setPixmap(self.sysTray.loadIcon("ksmarttray"))
    
    def toggleBlink(self):
        if self.blinkFlag:
            self.sysTray.setPixmap(QPixmap())
        else:
            self.sysTray.setPixmap(self.sysTray.loadIcon("ksmarttray"))
        self.blinkFlag = not self.blinkFlag