~ubuntu-branches/ubuntu/raring/hplip/raring-proposed

« back to all changes in this revision

Viewing changes to ui/upgradeform.py

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-05-26 11:20:39 UTC
  • mfrom: (1.5.6) (31.1.3 precise)
  • Revision ID: package-import@ubuntu.com-20120526112039-bevxczegxnbyr5m7
Tags: 3.12.4-1
* New upstream release
* Switch to source/format 3.0 (quilt) - drop dpatch
* Refreshed debian/patches
* dh_autoreconf debian/autogen.sh & set local-options single-debian-patch
* Update to debian/compat -> 9
* Fix "hardened build flags" patch from Moritz - thanks (Closes: #667828)
* Fix "duplex descriptor uninitialized" patch from Matej (Closes: #583273)
* Fix "please migrate to kde-runtime" patch from Pino (Closes: #666544)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# (c) Copyright 2001-2012 Hewlett-Packard Development Company, L.P.
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program; if not, write to the Free Software
 
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
19
#
 
20
# Author: Don Welch, Goutam Korra, Naga Samrat Chowdary Narla,
 
21
 
 
22
# Std Lib
 
23
import sys
 
24
import re
 
25
import os.path, os
 
26
import time
 
27
 
 
28
# Local
 
29
from base.g import *
 
30
from base import device, utils, models
 
31
from ui_utils import load_pixmap
 
32
 
 
33
# Qt
 
34
from qt import *
 
35
from upgradeform_base import UpgradeForm_base
 
36
 
 
37
MANUAL_INSTALL_LINK = "http://hplipopensource.com/hplip-web/install/manual/index.html"
 
38
 
 
39
class UpgradeForm(UpgradeForm_base):
 
40
    def __init__(self, parent=None, name="",modal=0, fl=0,distro_type= 1,msg=""):
 
41
        UpgradeForm_base.__init__(self, parent,  name, modal, fl,distro_type, msg)
 
42
 
 
43
        self.msg = msg
 
44
        self.distro_type = distro_type
 
45
        self.setIcon(load_pixmap('hp_logo', '128x128'))
 
46
        self.initUi()
 
47
 
 
48
    def initUi(self):
 
49
        self.connect(self.NextButton,SIGNAL('clicked()'),self.NextButton_clicked)
 
50
        self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
 
51
 
 
52
#        self.connect(self.installRadioBtton, SIGNAL("toggled(bool)"), self.installRadioBtton_toggled)
 
53
#        self.connect(self.remindRadioBtton, SIGNAL("toggled(bool)"), self.remindRadioBtton_toggled)
 
54
#        self.connect(self.dontRemindRadioBtton, SIGNAL("toggled(bool)"), self.dontRemindRadioBtton_toggled)
 
55
 
 
56
 
 
57
    def installRadioBtton_toggled(self, radio_enabled):
 
58
        log.info("+++++++ installRadioBtton_toggled  = %d" %radio_enabled)
 
59
        if radio_enabled is True:
 
60
            self.installRadioBtton.setChecked(True)
 
61
        else:
 
62
            self.installRadioBtton.setChecked(False)
 
63
 
 
64
 
 
65
    def remindRadioBtton_toggled(self, radio_enabled):
 
66
        log.info("+++++++ remindRadioBtton_toggled  = %d" %radio_enabled)
 
67
        if radio_enabled is True:
 
68
            self.remindRadioBtton.setChecked(True)
 
69
            self.daysSpinBox.setEnabled(True)
 
70
        else:
 
71
            self.remindRadioBtton.setChecked(False)
 
72
            self.daysSpinBox.setEnabled(False)
 
73
 
 
74
 
 
75
    def dontRemindRadioBtton_toggled(self, radio_enabled):
 
76
        log.info("+++++++ dontRemindRadioBtton_toggled  = %d" %radio_enabled)
 
77
        if radio_enabled is True:
 
78
            self.dontRemindRadioBtton.setChecked(True)
 
79
        else:
 
80
            self.dontRemindRadioBtton.setChecked(False)
 
81
 
 
82
 
 
83
    def NextButton_clicked (self):
 
84
        if self.dontRemindRadioBtton.isChecked():
 
85
            log.debug("HPLIP Upgrade, selected Don't remind again radiobutton")
 
86
            user_conf.set('upgrade', 'notify_upgrade', 'false')
 
87
            msg= "Check for HPLIP updates is disabled. To Upgrade again, check it in 'HP-toolbox' "
 
88
            self.SuccessUI( self.__tr(msg))
 
89
        elif self.remindRadioBtton.isChecked():
 
90
            schedule_days = str(self.daysSpinBox.value())
 
91
            log.debug("HPLIP Upgrade, selected remind later radiobutton  days= %d" %(int(schedule_days)))
 
92
            next_time = time.time() + (int(schedule_days) *24 * 60 *60) 
 
93
            user_conf.set('upgrade', 'pending_upgrade_time', str(int(next_time)))
 
94
        else:
 
95
            log.debug("HPLIP Upgrade, selected Install radiobutton  distro_type=%d" %self.distro_type)
 
96
            self.NextButton.setEnabled(False)
 
97
            if self.distro_type != 1:           # not tier 1 distro
 
98
                utils.openURL(MANUAL_INSTALL_LINK)
 
99
            else:
 
100
                terminal_cmd = utils.get_terminal()
 
101
                if terminal_cmd is not None and utils.which("hp-upgrade"):
 
102
                    cmd = terminal_cmd + " 'hp-upgrade '"
 
103
                    log.debug("cmd = %s " %cmd)
 
104
                    os.system(cmd)
 
105
                    self.result = True
 
106
                else:
 
107
                    log.error("Failed to run hp-upgrade command from terminal =%s "%terminal_cmd)
 
108
                    self.FailureUI( self.__tr("Failed to run hp-upgrade"))
 
109
 
 
110
        self.close()
 
111
 
 
112
 
 
113
    def CancelButton_clicked(self):
 
114
        log.debug("User exit")
 
115
        self.close()
 
116
 
 
117
 
 
118
    def FailureUI(self, error_text):
 
119
        QMessageBox.critical(self,
 
120
            self.caption(),
 
121
            error_text,
 
122
            QMessageBox.Ok,
 
123
            QMessageBox.NoButton,
 
124
            QMessageBox.NoButton)
 
125
 
 
126
    def SuccessUI(self, text):
 
127
        QMessageBox.information(self,
 
128
                             self.caption(),
 
129
                             text,
 
130
                              QMessageBox.Ok,
 
131
                              QMessageBox.NoButton,
 
132
                              QMessageBox.NoButton)
 
133
 
 
134
 
 
135
    def __tr(self,s,c = None):
 
136
        return qApp.translate("UpgradeDialog",s,c)