From: Till Kamppeter <till.kamppeter@gmail.com>
Date: Wed, 3 Oct 2018 15:13:00 +0200
Subject: Call QMessageBox constructors of PyQT5 with the correct parameters

The whole Python source code of HPLIP contains 40 incorrect calls of
the QMessageBox constructurs, mostly the list of buttons was given as
separate arguments instead of a bitwise OR of each button's
representation value.  If the flow of the code hits one of these
calls (usually when some error or warnings message should be
displayed or an "Are you sure?" question asked) the GUI app crashes.
See https://pythonspot.com/pyqt5-messagebox/ for QMessageBox
documentation.
This patch corrects all these calls.

Bug-Debian: https://bugs.debian.org/912768
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1745383
---
 ui/devmgr4.py          | 16 ++++++++--------
 ui/faxaddrbookform.py  |  6 +++---
 ui/faxsendjobform.py   |  6 +++---
 ui/firmwaredialog.py   |  2 +-
 ui/makecopiesform.py   |  4 ++--
 ui/nodevicesform.py    |  2 +-
 ui/pluginform2.py      |  4 ++--
 ui/printerform.py      |  2 +-
 ui/settingsdialog.py   |  4 ++--
 ui/setupform.py        | 10 +++++-----
 ui/unloadform.py       |  2 +-
 ui/upgradeform.py      |  4 ++--
 ui5/devmgr5.py         |  6 ++----
 ui5/fabwindow.py       |  2 +-
 ui5/nodevicesdialog.py |  3 +--
 ui5/plugindialog.py    |  2 +-
 ui5/queuesconf.py      |  2 +-
 ui5/setupdialog.py     |  6 +++---
 18 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/ui/devmgr4.py b/ui/devmgr4.py
index cc2552f..a868cca 100644
--- a/ui/devmgr4.py
+++ b/ui/devmgr4.py
@@ -1422,7 +1422,7 @@ class DevMgr4(DevMgr4_base):
             QMessageBox.critical(self,
                 self.caption(),
                 self.__tr("<b>Unable to find an appropriate su/sudo utility to run hp-plugin.</b><p>Install kdesu, gnomesu, or gksu.</p>"),
-                QMessageBox.Ok,
+                QMessageBox.Ok |\
                 QMessageBox.NoButton,
                 QMessageBox.NoButton)
         else:
@@ -2854,7 +2854,7 @@ class DevMgr4(DevMgr4_base):
             x = QMessageBox.critical(self,
            self.caption(),
            self.__tr("<b>Annoying Confirmation: Are you sure you want to remove this device?</b>"),
-            QMessageBox.Yes,
+            QMessageBox.Yes |\
             QMessageBox.No | QMessageBox.Default,
             QMessageBox.NoButton)
             if x == QMessageBox.Yes:
@@ -2949,7 +2949,7 @@ class DevMgr4(DevMgr4_base):
         QMessageBox.critical(self,
             self.caption(),
             error_text,
-            QMessageBox.Ok,
+            QMessageBox.Ok |\
             QMessageBox.NoButton,
             QMessageBox.NoButton)
 
@@ -2958,7 +2958,7 @@ class DevMgr4(DevMgr4_base):
         QMessageBox.warning(self,
             self.caption(),
             msg,
-            QMessageBox.Ok,
+            QMessageBox.Ok |\
             QMessageBox.NoButton,
             QMessageBox.NoButton)
 
@@ -3115,7 +3115,7 @@ class ScrollTestpageView(ScrollView):
             QMessageBox.information(self,
                 self.caption(),
                 self.__tr("<p><b>A test page should be printing on your printer.</b><p>If the page fails to print, please visit http://hplip.sourceforge.net for troubleshooting and support."),
-                QMessageBox.Ok,
+                QMessageBox.Ok |\
                 QMessageBox.NoButton,
                 QMessageBox.NoButton)
 
@@ -3130,7 +3130,7 @@ class ScrollTestpageView(ScrollView):
         QMessageBox.critical(self,
             self.caption(),
             error_text,
-            QMessageBox.Ok,
+            QMessageBox.Ok |\
             QMessageBox.NoButton,
             QMessageBox.NoButton)
 
@@ -3272,7 +3272,7 @@ class ScrollColorCalView(ScrollView):
             QMessageBox.information(self,
                 self.caption(),
                 self.__tr("<p><b>A test page should be printing on your printer.</b><p>If the page fails to print, please visit http://hplip.sourceforge.net for troubleshooting and support."),
-                QMessageBox.Ok,
+                QMessageBox.Ok |\
                 QMessageBox.NoButton,
                 QMessageBox.NoButton)
 
@@ -3287,7 +3287,7 @@ class ScrollColorCalView(ScrollView):
         QMessageBox.critical(self,
             self.caption(),
             error_text,
-            QMessageBox.Ok,
+            QMessageBox.Ok |\
             QMessageBox.NoButton,
             QMessageBox.NoButton)
 
diff --git a/ui/faxaddrbookform.py b/ui/faxaddrbookform.py
index 1094622..b233644 100644
--- a/ui/faxaddrbookform.py
+++ b/ui/faxaddrbookform.py
@@ -228,7 +228,7 @@ class FaxAddrBookGroupsForm(FaxAddrBookGroupsForm_base):
         x = QMessageBox.critical(self,
                                  self.caption(),
                                  self.__tr("<b>Annoying Confirmation: Are you sure you want to delete this group?</b>"),
-                                  QMessageBox.Yes,
+                                  QMessageBox.Yes |\
                                   QMessageBox.No | QMessageBox.Default,
                                   QMessageBox.NoButton)
         if x == QMessageBox.Yes:
@@ -421,7 +421,7 @@ class FaxAddrBookForm(FaxAddrBookForm_base):
         if QMessageBox.critical(self,
              self.caption(),
              self.__tr("<b>Annoying Confirmation: Are you sure you want to delete this address book entry?</b>"),
-              QMessageBox.Yes,
+              QMessageBox.Yes |\
               QMessageBox.No | QMessageBox.Default,
               QMessageBox.NoButton) == QMessageBox.Yes:
             db.delete(self.current.entry['name'])
@@ -451,7 +451,7 @@ class FaxAddrBookForm(FaxAddrBookForm_base):
         QMessageBox.critical(self,
                              self.caption(),
                              QString(error_text),
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
diff --git a/ui/faxsendjobform.py b/ui/faxsendjobform.py
index 106215c..69f424c 100644
--- a/ui/faxsendjobform.py
+++ b/ui/faxsendjobform.py
@@ -210,7 +210,7 @@ class FaxSendJobForm(QMainWindow):
         QMessageBox.information(self,
                              self.caption(),
                              self.__tr("<p><b>Fax send completed successfully.</b>"),
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
@@ -219,7 +219,7 @@ class FaxSendJobForm(QMainWindow):
         QMessageBox.critical(self,
                              self.caption(),
                              error_text,
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
@@ -228,7 +228,7 @@ class FaxSendJobForm(QMainWindow):
         QMessageBox.warning(self,
                              self.caption(),
                              error_text,
-                             QMessageBox.Ok,
+                             QMessageBox.Ok |\
                              QMessageBox.NoButton,
                              QMessageBox.NoButton)
 
diff --git a/ui/firmwaredialog.py b/ui/firmwaredialog.py
index 16b3133..0bcee11 100644
--- a/ui/firmwaredialog.py
+++ b/ui/firmwaredialog.py
@@ -109,7 +109,7 @@ class FirmwareDialog(QDialog, FirmwareDialog_Base):
         QMessageBox.critical(self,
                 self.caption(),
                 error_text,
-                QMessageBox.Ok,
+                QMessageBox.Ok |\
                 QMessageBox.NoButton,
                 QMessageBox.NoButton)
 
diff --git a/ui/makecopiesform.py b/ui/makecopiesform.py
index 27f144b..0fbb573 100644
--- a/ui/makecopiesform.py
+++ b/ui/makecopiesform.py
@@ -156,7 +156,7 @@ class MakeCopiesForm(QMainWindow):
         QMessageBox.critical(self,
                              self.caption(),
                              error_text,
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
@@ -164,7 +164,7 @@ class MakeCopiesForm(QMainWindow):
         QMessageBox.warning(self,
                              self.caption(),
                              msg,
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
diff --git a/ui/nodevicesform.py b/ui/nodevicesform.py
index 01f6ae5..57a6963 100644
--- a/ui/nodevicesform.py
+++ b/ui/nodevicesform.py
@@ -67,7 +67,7 @@ class NoDevicesForm(NoDevicesForm_base):
             QMessageBox.critical(self,
                                     self.caption(),
                                     self.__tr("<b>An error occurred.</b><p>Please re-start the Device Manager and try again."),
-                                    QMessageBox.Ok,
+                                    QMessageBox.Ok |\
                                     QMessageBox.NoButton,
                                     QMessageBox.NoButton)
 
diff --git a/ui/pluginform2.py b/ui/pluginform2.py
index 64e64aa..76cb023 100644
--- a/ui/pluginform2.py
+++ b/ui/pluginform2.py
@@ -173,7 +173,7 @@ class PluginForm2(PluginForm2_base):
         QMessageBox.critical(self,
             self.caption(),
             error_text,
-            QMessageBox.Ok,
+            QMessageBox.Ok |\
             QMessageBox.NoButton,
             QMessageBox.NoButton)
 
@@ -181,7 +181,7 @@ class PluginForm2(PluginForm2_base):
         QMessageBox.information(self,
                              self.caption(),
                              text,
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
diff --git a/ui/printerform.py b/ui/printerform.py
index 0c6c4f3..7c10ab0 100644
--- a/ui/printerform.py
+++ b/ui/printerform.py
@@ -154,7 +154,7 @@ class PrinterForm(QMainWindow):
         QMessageBox.critical(self,
                              self.caption(),
                              error_text,
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
diff --git a/ui/settingsdialog.py b/ui/settingsdialog.py
index 92da225..24f02fd 100644
--- a/ui/settingsdialog.py
+++ b/ui/settingsdialog.py
@@ -146,7 +146,7 @@ class SettingsDialog(SettingsDialog_base):
 ##            QMessageBox.warning(self,
 ##                                 self.caption(),
 ##                                 self.__tr("<b>One or more email addresses are missing.</b><p>Please enter this information and try again."),
-##                                  QMessageBox.Ok,
+##                                  QMessageBox.Ok |\
 ##                                  QMessageBox.NoButton,
 ##                                  QMessageBox.NoButton)
 ##            return
@@ -163,7 +163,7 @@ class SettingsDialog(SettingsDialog_base):
 ##        QMessageBox.information(self,
 ##                     self.caption(),
 ##                     self.__tr("<p><b>Please check your email for a test message.</b><p>If the message doesn't arrive, please check your settings and try again."),
-##                      QMessageBox.Ok,
+##                      QMessageBox.Ok |\
 ##                      QMessageBox.NoButton,
 ##                      QMessageBox.NoButton)
 
diff --git a/ui/setupform.py b/ui/setupform.py
index 307917b..78863fd 100644
--- a/ui/setupform.py
+++ b/ui/setupform.py
@@ -602,7 +602,7 @@ class SetupForm(SetupForm_base):
             if ( QMessageBox.warning(self,
                                 self.caption(),
                                 warn_text,
-                                QMessageBox.Yes,
+                                QMessageBox.Yes |\
                                 QMessageBox.No,
                                 QMessageBox.NoButton) == QMessageBox.Yes ):
 
@@ -804,7 +804,7 @@ class SetupForm(SetupForm_base):
                     if QMessageBox.critical(self,
                                            self.caption(),
                                            error_text,
-                                           QMessageBox.Retry | QMessageBox.Default,
+                                           QMessageBox.Retry | QMessageBox.Default |\
                                            QMessageBox.Cancel | QMessageBox.Escape,
                                            QMessageBox.NoButton) == QMessageBox.Cancel:
                         break
@@ -832,7 +832,7 @@ class SetupForm(SetupForm_base):
                                 if QMessageBox.critical(self,
                                                        self.caption(),
                                                        error_text,
-                                                       QMessageBox.Retry | QMessageBox.Default,
+                                                       QMessageBox.Retry | QMessageBox.Default |\
                                                        QMessageBox.Cancel | QMessageBox.Escape,
                                                        QMessageBox.NoButton) == QMessageBox.Cancel:
                                     break
@@ -1003,7 +1003,7 @@ class SetupForm(SetupForm_base):
         QMessageBox.critical(self,
                              self.caption(),
                              error_text,
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
@@ -1011,7 +1011,7 @@ class SetupForm(SetupForm_base):
         QMessageBox.warning(self,
                              self.caption(),
                              error_text,
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
diff --git a/ui/unloadform.py b/ui/unloadform.py
index 8397a68..ae363e0 100644
--- a/ui/unloadform.py
+++ b/ui/unloadform.py
@@ -135,7 +135,7 @@ class UnloadForm(QMainWindow):
         QMessageBox.critical(self,
                              self.caption(),
                              error_text,
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
diff --git a/ui/upgradeform.py b/ui/upgradeform.py
index 6b9acf5..d0b4184 100644
--- a/ui/upgradeform.py
+++ b/ui/upgradeform.py
@@ -118,7 +118,7 @@ class UpgradeForm(UpgradeForm_base):
         QMessageBox.critical(self,
             self.caption(),
             error_text,
-            QMessageBox.Ok,
+            QMessageBox.Ok |\
             QMessageBox.NoButton,
             QMessageBox.NoButton)
 
@@ -126,7 +126,7 @@ class UpgradeForm(UpgradeForm_base):
         QMessageBox.information(self,
                              self.caption(),
                              text,
-                              QMessageBox.Ok,
+                              QMessageBox.Ok |\
                               QMessageBox.NoButton,
                               QMessageBox.NoButton)
 
diff --git a/ui5/devmgr5.py b/ui5/devmgr5.py
index 7957446..491f168 100644
--- a/ui5/devmgr5.py
+++ b/ui5/devmgr5.py
@@ -144,8 +144,7 @@ class PluginInstall(QObject):
             install_plugin = QMessageBox.warning(self.parent,
                                 self.parent.windowTitle(),
                                 self.__tr("<b>The HPLIP plugin is already installed.</b><p>Do you want to continue and re-install it?"),
-                                QMessageBox.Yes,
-                                QMessageBox.No,
+                                QMessageBox.Yes | QMessageBox.No,
                                 QMessageBox.NoButton) == QMessageBox.Yes
 
         if install_plugin:
@@ -154,8 +153,7 @@ class PluginInstall(QObject):
                 QMessageBox.critical(self.parent,
                     self.parent.windowTitle(),
                     self.__tr("<b>Unable to find an appropriate su/sudo utility to run hp-plugin.</b><p>Install kdesu, gnomesu, or gksu.</p>"),
-                    QMessageBox.Ok,
-                    QMessageBox.NoButton,
+                    QMessageBox.Ok | QMessageBox.NoButton,
                     QMessageBox.NoButton)
 
 
diff --git a/ui5/fabwindow.py b/ui5/fabwindow.py
index 19f76f7..2b29c2d 100644
--- a/ui5/fabwindow.py
+++ b/ui5/fabwindow.py
@@ -344,7 +344,7 @@ class FABWindow(QMainWindow,  Ui_MainWindow):
             new_name = to_unicode(self.NameLineEdit.text())
             if new_name != self.name:
                 if QMessageBox.question(self, self.__tr("Rename?"), "Rename '%s' to '%s'?"%(self.name,new_name), \
-                                        QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes:
+                                        QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes:
 
                     self.db.rename(self.name, new_name)
                     log.debug("Rename %s to %s" % (self.name, new_name))
diff --git a/ui5/nodevicesdialog.py b/ui5/nodevicesdialog.py
index 6083f6d..ca86bfc 100644
--- a/ui5/nodevicesdialog.py
+++ b/ui5/nodevicesdialog.py
@@ -64,8 +64,7 @@ class NoDevicesDialog(QDialog, Ui_NoDevicesDialog_base):
             QMessageBox.critical(self,
                                     self.windowTitle(),
                                     self.__tr("<b>An error occurred.</b><p>Please re-start the Device Manager and try again."),
-                                    QMessageBox.Ok,
-                                    QMessageBox.NoButton,
+                                    QMessageBox.Ok | QMessageBox.NoButton,
                                     QMessageBox.NoButton)
 
 
diff --git a/ui5/plugindialog.py b/ui5/plugindialog.py
index e3007f9..1c6b338 100644
--- a/ui5/plugindialog.py
+++ b/ui5/plugindialog.py
@@ -252,7 +252,7 @@ class PluginDialog(QDialog, Ui_Dialog):
 
                 if QMessageBox.question(self, " ",
                         self.__tr("<b>%s</b><p>Without this, it is not possible to authenticate and validate the plug-in prior to installation.</p>Do you still want to install the plug-in?" %error_str),
-                        QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
+                                        QMessageBox.Yes | QMessageBox.No, QMessageBox.No) != QMessageBox.Yes:
 
                     self.pluginObj.deleteInstallationFiles(download_plugin_file)
                     self.close()
diff --git a/ui5/queuesconf.py b/ui5/queuesconf.py
index cf22064..e3c2a02 100644
--- a/ui5/queuesconf.py
+++ b/ui5/queuesconf.py
@@ -245,7 +245,7 @@ class QueuesDiagnose(QDialog, Ui_Dialog):
                 
                     if QMessageBox.question(self, " ",
                         self.__tr("<b>%s</b><p>Without this, it is not possible to authenticate and validate this tool prior to installation.</p>Do you still want to run Smart Install disabler?" %error_str),
-                        QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes:
+                                            QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes:
                         # Disabling without verification.
                         sts, out = utils.run("sh %s"%smart_install_run)
 
diff --git a/ui5/setupdialog.py b/ui5/setupdialog.py
index 7b58d80..64e3370 100644
--- a/ui5/setupdialog.py
+++ b/ui5/setupdialog.py
@@ -1171,7 +1171,7 @@ class SetupDialog(QDialog, Ui_Dialog):
                     if QMessageBox.critical(self,
                                             self.windowTitle(),
                                             error_text,
-                                            QMessageBox.Retry | QMessageBox.Default,
+                                            QMessageBox.Retry | QMessageBox.Default |\
                                             QMessageBox.Cancel | QMessageBox.Escape,
                                             QMessageBox.NoButton) == QMessageBox.Cancel:
                         break
@@ -1223,7 +1223,7 @@ class SetupDialog(QDialog, Ui_Dialog):
                                 if QMessageBox.critical(self,
                                                         self.windowTitle(),
                                                         error_text,
-                                                        QMessageBox.Retry | QMessageBox.Default,
+                                                        QMessageBox.Retry | QMessageBox.Default |\
                                                         QMessageBox.Cancel | QMessageBox.Escape,
                                                         QMessageBox.NoButton) == QMessageBox.Cancel:
                                     break
