1# -*- coding: utf-8 -*- 2# 3# (c) Copyright 2001-2015 HP Development Company, L.P. 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, write to the Free Software 17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18# 19# Authors: Amarnath Chitumalla 20# 21 22#Global 23import os 24import time 25import signal 26 27# Local 28from base.g import * 29from base import device, utils, pkit, os_utils 30from .ui_utils import * 31 32# Qt 33from PyQt4.QtCore import * 34from PyQt4.QtGui import * 35 36# Ui 37from .upgradedialog_base import Ui_Dialog 38 39MANUAL_INSTALL_LINK = "http://hplipopensource.com/hplip-web/install/manual/index.html" 40 41 42class UpgradeDialog(QDialog, Ui_Dialog): 43 def __init__(self, parent, distro_tier, msg): 44 QDialog.__init__(self, parent) 45 self.distro_tier = distro_tier 46 self.msg = msg 47 self.result = False 48 self.setupUi(self, distro_tier, msg) 49 self.initUi() 50 51 52 def initUi(self): 53 # connect signals/slots 54 self.connect(self.NextButton, SIGNAL("clicked()"), self.NextButton_clicked) 55 self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked) 56# self.connect (self.comboBox, SIGNAL ("currentIndexChanged (const QString&)"), self.slotIndexChanged) 57 self.connect(self.installRadioBtton, SIGNAL("toggled(bool)"), self.installRadioBtton_toggled) 58 self.connect(self.remindRadioBtton, SIGNAL("toggled(bool)"), self.remindRadioBtton_toggled) 59 self.connect(self.dontRemindRadioBtton, SIGNAL("toggled(bool)"), self.dontRemindRadioBtton_toggled) 60 signal.signal(signal.SIGINT, signal.SIG_DFL) 61 62 # Application icon 63 self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128'))) 64 65 66 def installRadioBtton_toggled(self, radio_enabled): 67 if radio_enabled is True: 68 self.installRadioBtton.setChecked(True) 69 else: 70 self.installRadioBtton.setChecked(False) 71 72 73 def remindRadioBtton_toggled(self, radio_enabled): 74 if radio_enabled is True: 75 self.remindRadioBtton.setChecked(True) 76 self.daysSpinBox.setEnabled(True) 77 else: 78 self.remindRadioBtton.setChecked(False) 79 self.daysSpinBox.setEnabled(False) 80 81 82 def dontRemindRadioBtton_toggled(self, radio_enabled): 83 if radio_enabled is True: 84 self.dontRemindRadioBtton.setChecked(True) 85 else: 86 self.dontRemindRadioBtton.setChecked(False) 87 88 89 def NextButton_clicked (self): 90 if self.dontRemindRadioBtton.isChecked(): 91 log.debug("HPLIP Upgrade, selected Don't remind again radiobutton") 92 user_conf.set('upgrade', 'notify_upgrade', 'false') 93 msg= "Check for HPLIP updates is disabled. To enable it again, change 'Settings' in 'HP systemtray' " 94 SuccessUI(self, self.__tr(msg)) 95 96 elif self.remindRadioBtton.isChecked(): 97 schedule_days = str(self.daysSpinBox.value()) 98 log.debug("HPLIP Upgrade, selected remind later radiobutton days= %d" %(int(schedule_days))) 99 next_time = time.time() + (int(schedule_days) *24 * 60 *60) 100 user_conf.set('upgrade', 'pending_upgrade_time', str(int(next_time))) 101 else: 102 log.debug("HPLIP Upgrade, selected Install radiobutton distro_type=%d" %self.distro_tier) 103 self.NextButton.setEnabled(False) 104 if self.distro_tier != 1: # not tier 1 distro 105 log.debug("OK pressed for tier 2 distro pressed") 106 utils.openURL(MANUAL_INSTALL_LINK) 107 108 ## TBD::open browser 109 else: 110 terminal_cmd = utils.get_terminal() 111 if terminal_cmd is not None and utils.which("hp-upgrade"): 112 cmd = terminal_cmd + " 'hp-upgrade -w'" 113 os_utils.execute(cmd) 114 self.result = True 115 else: 116 log.error("Failed to run hp-upgrade command from terminal =%s "%terminal_cmd) 117 FailureUI(self, self.__tr("Failed to run hp-upgrade")) 118 119 self.close() 120 121 122 def CancelButton_clicked(self): 123 log.debug("User exit") 124 self.close() 125 126 def __tr(self,s,c = None): 127 return qApp.translate("UpgradeDialog",s,c) 128 129