1 # -*- coding: utf-8 -*-
3 # (c) Copyright 2001-2011 Hewlett-Packard Development Company, L.P.
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.
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.
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
19 # Authors: Amarnath Chitumalla
28 from base import device, utils, pkit
29 from ui_utils import *
32 from PyQt4.QtCore import *
33 from PyQt4.QtGui import *
36 from upgradedialog_base import Ui_Dialog
38 MANUAL_INSTALL_LINK = "http://hplipopensource.com/hplip-web/install/manual/index.html"
41 class UpgradeDialog(QDialog, Ui_Dialog):
42 def __init__(self, parent, distro_tier, msg):
43 QDialog.__init__(self, parent)
44 self.distro_tier = distro_tier
47 self.setupUi(self, distro_tier, msg)
52 # connect signals/slots
53 self.connect(self.NextButton, SIGNAL("clicked()"), self.NextButton_clicked)
54 self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
55 # self.connect (self.comboBox, SIGNAL ("currentIndexChanged (const QString&)"), self.slotIndexChanged)
56 self.connect(self.installRadioBtton, SIGNAL("toggled(bool)"), self.installRadioBtton_toggled)
57 self.connect(self.remindRadioBtton, SIGNAL("toggled(bool)"), self.remindRadioBtton_toggled)
58 self.connect(self.dontRemindRadioBtton, SIGNAL("toggled(bool)"), self.dontRemindRadioBtton_toggled)
61 self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
64 def installRadioBtton_toggled(self, radio_enabled):
65 if radio_enabled is True:
66 self.installRadioBtton.setChecked(True)
68 self.installRadioBtton.setChecked(False)
71 def remindRadioBtton_toggled(self, radio_enabled):
72 if radio_enabled is True:
73 self.remindRadioBtton.setChecked(True)
74 self.daysSpinBox.setEnabled(True)
76 self.remindRadioBtton.setChecked(False)
77 self.daysSpinBox.setEnabled(False)
80 def dontRemindRadioBtton_toggled(self, radio_enabled):
81 if radio_enabled is True:
82 self.dontRemindRadioBtton.setChecked(True)
84 self.dontRemindRadioBtton.setChecked(False)
87 def NextButton_clicked (self):
88 if self.dontRemindRadioBtton.isChecked():
89 log.debug("HPLIP Upgrade, selected Don't remind again radiobutton")
90 user_conf.set('upgrade', 'notify_upgrade', 'false')
91 msg= "Check for HPLIP updates is disabled. To enable it again, change 'Settings' in 'HP systemtray' "
92 SuccessUI(self, self.__tr(msg))
94 elif self.remindRadioBtton.isChecked():
95 schedule_days = str(self.daysSpinBox.value())
96 log.debug("HPLIP Upgrade, selected remind later radiobutton days= %d" %(int(schedule_days)))
97 next_time = time.time() + (int(schedule_days) *24 * 60 *60)
98 user_conf.set('upgrade', 'pending_upgrade_time', str(int(next_time)))
100 log.debug("HPLIP Upgrade, selected Install radiobutton distro_type=%d" %self.distro_tier)
101 self.NextButton.setEnabled(False)
102 if self.distro_tier != 1: # not tier 1 distro
103 log.debug("OK pressed for tier 2 distro pressed")
104 utils.openURL(MANUAL_INSTALL_LINK)
108 terminal_cmd = utils.get_terminal()
109 if terminal_cmd is not None and utils.which("hp-upgrade"):
110 cmd = terminal_cmd + " 'hp-upgrade'"
111 log.debug("cmd = %s " %cmd)
115 log.error("Failed to run hp-upgrade command from terminal =%s "%terminal_cmd)
116 ErrorUI(self, self.__tr("Failed to run hp-upgrade"))
121 def CancelButton_clicked(self):
122 log.debug("User exit")
125 def __tr(self,s,c = None):
126 return qApp.translate("UpgradeDialog",s,c)