Fixed build error by changing buildrequires from pkgconfig(turbo-jpeg) to libjpeg...
[platform/upstream/hplip.git] / ui4 / upgradedialog.py
1 # -*- coding: utf-8 -*-
2 #
3 # (c) Copyright 2001-2011 Hewlett-Packard 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
23 import os
24 import time
25
26 # Local
27 from base.g import *
28 from base import device, utils, pkit
29 from ui_utils import *
30
31 # Qt
32 from PyQt4.QtCore import *
33 from PyQt4.QtGui import *
34
35 # Ui
36 from upgradedialog_base import Ui_Dialog
37
38 MANUAL_INSTALL_LINK = "http://hplipopensource.com/hplip-web/install/manual/index.html"
39
40
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
45         self.msg = msg
46         self.result = False
47         self.setupUi(self, distro_tier, msg)
48         self.initUi()
49
50
51     def initUi(self):
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)
59         
60         # Application icon
61         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
62
63
64     def installRadioBtton_toggled(self, radio_enabled):
65         if radio_enabled is True:
66             self.installRadioBtton.setChecked(True)
67         else:
68             self.installRadioBtton.setChecked(False)
69
70
71     def remindRadioBtton_toggled(self, radio_enabled):
72         if radio_enabled is True:
73             self.remindRadioBtton.setChecked(True)
74             self.daysSpinBox.setEnabled(True)
75         else:
76             self.remindRadioBtton.setChecked(False)
77             self.daysSpinBox.setEnabled(False)
78
79
80     def dontRemindRadioBtton_toggled(self, radio_enabled):
81         if radio_enabled is True:
82             self.dontRemindRadioBtton.setChecked(True)
83         else:
84             self.dontRemindRadioBtton.setChecked(False)
85
86
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))
93
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)))
99         else:
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)
105                 
106                 ## TBD::open browser
107             else:
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)
112                     os.system(cmd)
113                     self.result = True
114                 else:
115                     log.error("Failed to run hp-upgrade command from terminal =%s "%terminal_cmd)
116                     ErrorUI(self, self.__tr("Failed to run hp-upgrade"))
117
118         self.close()
119
120
121     def CancelButton_clicked(self):
122         log.debug("User exit")
123         self.close()
124
125     def __tr(self,s,c = None):
126         return qApp.translate("UpgradeDialog",s,c)
127