Tizen 2.1 base
[platform/upstream/hplip.git] / ui4 / plugindiagnose.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
23 # Local
24 from base.g import *
25 from base import device, utils, pkit
26 from prnt import cups
27 from base.codes import *
28 from ui_utils import *
29 from installer.core_install import CoreInstall
30 from installer.core_install import  PLUGIN_INSTALL_ERROR_NONE, \
31                                     PLUGIN_INSTALL_ERROR_PLUGIN_FILE_NOT_FOUND, \
32                                     PLUGIN_INSTALL_ERROR_DIGITAL_SIG_NOT_FOUND, \
33                                     PLUGIN_INSTALL_ERROR_DIGITAL_SIG_BAD, \
34                                     PLUGIN_INSTALL_ERROR_PLUGIN_FILE_CHECKSUM_ERROR, \
35                                     PLUGIN_INSTALL_ERROR_NO_NETWORK, \
36                                     PLUGIN_INSTALL_ERROR_DIRECTORY_ERROR, \
37                                     PLUGIN_INSTALL_ERROR_UNABLE_TO_RECV_KEYS
38
39 # Qt
40 from PyQt4.QtCore import *
41 from PyQt4.QtGui import *
42
43 # Ui
44 from plugindiagnose_base import Ui_Dialog
45
46
47
48 class PluginDiagnose(QDialog, Ui_Dialog):
49     def __init__(self, parent, install_mode=PLUGIN_NONE, plugin_reason=PLUGIN_REASON_NONE, upgrade=False):
50         QDialog.__init__(self, parent)
51         self.install_mode = install_mode
52         self.plugin_reason = plugin_reason
53         self.plugin_path = None
54         self.result = False
55         self.core = CoreInstall()
56         self.core.set_plugin_version()
57         self.setupUi(self, upgrade)
58
59         self.user_settings = UserSettings()
60         self.user_settings.load()
61         self.user_settings.debug()
62
63         self.initUi()
64
65
66
67
68     def initUi(self):
69         # connect signals/slots
70         self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
71         self.connect(self.NextButton, SIGNAL("clicked()"), self.NextButton_clicked)
72
73         # Application icon
74         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
75
76
77     def PathLineEdit_textChanged(self, t):
78         self.plugin_path = unicode(t)
79         self.setPathIndicators()
80
81
82     #
83     # Misc
84     #
85
86     def displayPage(self, page):
87         self.updateStepText(page)
88         self.StackedWidget.setCurrentIndex(page)
89
90     def CancelButton_clicked(self):
91         self.close()
92
93
94     def NextButton_clicked(self):
95         self.NextButton.setEnabled(False)
96         self.CancelButton.setEnabled(False)
97         try:
98             plugin = PLUGIN_REQUIRED 
99             plugin_reason = PLUGIN_REASON_NONE
100             ok, sudo_ok = pkit.run_plugin_command(plugin == PLUGIN_REQUIRED, plugin_reason)
101         
102             if not ok or self.core.check_for_plugin() != PLUGIN_INSTALLED:
103                 FailureUI(self, self.__tr("Failed to install Plug-in.\nEither you have chosen to skip the Plug-in installation  or entered incorrect Password."))
104
105         finally:
106             endWaitCursor()
107         self.result = True
108         self.close()
109
110
111     def __tr(self,s,c = None):
112         return qApp.translate("PluginDialog",s,c)
113