Changeset 16566


Ignore:
Timestamp:
Aug 24, 2016, 7:57:29 PM (3 years ago)
Author:
dcorreia
Message:

Finished customize login configurations feature.
Fixed interface naming and bugs.

Location:
internals/2016/linuxloginsmartcardwizard/trunk/proto1
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • internals/2016/linuxloginsmartcardwizard/trunk/proto1/mainwin.py

    r16564 r16566  
    33from PyQt5.QtWidgets import QMessageBox
    44import os
    5 import fileHelper
    65import config
    76import subprocess
     7import settingswin
    88
    99
     
    1515        self.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
    1616        self.setEnabled(True)
    17         self.setFixedSize(550, 480)
     17        self.setFixedSize(500, 450)
    1818        self.setAutoFillBackground(True)
    1919        self.centerOnScreen()
     
    2323       
    2424        self.title = QtWidgets.QLabel(self.centralwidget)
    25         self.title.setGeometry(QtCore.QRect(0, 0, 550, 70))
     25        self.title.setGeometry(QtCore.QRect(0, 0, 500, 70))
    2626        self.title.setStyleSheet("border-bottom: 1px solid grey;\n"
    2727                                 "background-color: white;\n"
     
    3232
    3333        self.layoutWidget = QtWidgets.QWidget(self.centralwidget)
    34         self.layoutWidget.setGeometry(QtCore.QRect(75, 110, 360, 300))
     34        self.layoutWidget.setGeometry(QtCore.QRect(70, 110, 360, 250))
    3535        self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
    36         self.verticalLayout.setSpacing(40)
     36        self.verticalLayout.setSpacing(35)
    3737        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
    3838        self.addUserButton = QtWidgets.QPushButton(self.layoutWidget)
    39         self.addUserButton.setMinimumHeight(70)
     39        self.addUserButton.setMinimumHeight(85)
    4040        self.addUserButton.setFont(font)
    4141        self.addUserButton.setIcon(QtGui.QIcon("img/add-business-card-symbol.png"))
    42         self.addUserButton.setIconSize(QtCore.QSize(50, 50))
     42        self.addUserButton.setIconSize(QtCore.QSize(55, 55))
    4343        self.addUserButton.setStyleSheet("text-align: left;"
    4444                                         "padding-left: 20px;")
    4545        self.verticalLayout.addWidget(self.addUserButton)
    46        
    47         self.listConfigButton = QtWidgets.QPushButton(self.layoutWidget)
    48         self.listConfigButton.setMinimumHeight(70)
    49         self.listConfigButton.setFont(font)
    50         self.listConfigButton.setIcon(QtGui.QIcon("img/business-cards-database.png"))
    51         self.listConfigButton.setIconSize(QtCore.QSize(50, 50))
    52         self.listConfigButton.setStyleSheet("text-align: left;"
    53                                             "padding-left: 20px;")
    54         self.verticalLayout.addWidget(self.listConfigButton)
    55        
     46
    5647        self.resetConfigButton = QtWidgets.QPushButton(self.layoutWidget)
    57         self.resetConfigButton.setMinimumHeight(70)
     48        self.resetConfigButton.setMinimumHeight(85)
    5849        self.resetConfigButton.setFont(font)
    59         self.resetConfigButton.setIcon(QtGui.QIcon("img/minus-sign-on-business-card.png"))
    60         self.resetConfigButton.setIconSize(QtCore.QSize(50, 50))
     50        self.resetConfigButton.setIcon(QtGui.QIcon("img/business-cards-database.png"))
     51        self.resetConfigButton.setIconSize(QtCore.QSize(55, 55))
    6152        self.resetConfigButton.setStyleSheet("text-align: left;"
    6253                                             "padding-left: 20px;")
     
    6859        self.statusbarLabel = QtWidgets.QLabel(self.statusbar)
    6960
    70         self.statusbarLabel.setStyleSheet("margin-left: 335px")
     61        self.statusbarLabel.setStyleSheet("margin-left: 290px")
    7162        self.statusbar.addWidget(self.statusbarLabel, 10)
    7263
     
    8576        self.title.setText("SmartCard Login Configuration")
    8677        self.addUserButton.setText("    Assign Card to User Login")
    87         self.listConfigButton.setText("    List Login Configurations")
    88         self.resetConfigButton.setText("    Remove Login Configurations")
    89         if config.isPkcs11LoginActive():
     78        self.resetConfigButton.setText("    Customize Login Configurations")
     79        if config.isPkcs11LoginEnabled():
    9080            self.statusbarLabel.setText("Smartcard Login Enabled")
    9181        else:
     
    9383
    9484        self.addUserButton.clicked.connect(self.openAddUserWizard)
    95         self.listConfigButton.clicked.connect(self.listCurrentConfigs)
    9685        self.resetConfigButton.clicked.connect(self.resetLoginConfigs)
    9786        self.statusbarSlider.valueChanged.connect(self.changeLoginStatus)
    9887
    9988        self.wizardProcess = None
    100         self.popup = None
     89        self.customizeWindow = None
    10190
    10291    def centerOnScreen(self):
     
    113102            self.wizardProcess = subprocess.Popen(["sudo", "python3", "w4pages.py"])
    114103
    115     def listCurrentConfigs(self):
    116         print("List current login configurations")
    117         message = "\nBI Number".ljust(25) + " Full Name".ljust(25) + "  Username".ljust(25) + "\n"
    118         localCombos = config.listLocalCombos()
    119         if localCombos is None or localCombos == []:
    120             message = "\nYou have no local configurations.\n\n"\
    121                       "Please use the 'Add User Login' option to add \n"\
    122                       "a new local configuration to your computer.\n"
    123         else:
    124             for combo in config.listLocalCombos():
    125                 message += combo[0].ljust(25) + combo[1].ljust(25) + combo[2].ljust(25) + "\n"
    126         self.messageBox.information(self, "Title", message)
    127 
    128104    def resetLoginConfigs(self):
    129105        if self.isWizardProcessActive():
     
    136112            self.messageBox.information(self, "Title", message)
    137113        else:
    138             self.popup = resetPopup()
    139             self.popup.show()
    140 
    141     def checkResetPopup(self):
    142         message = "\nYou're about to reset your smartcard login \n" \
    143                   "configurations in this computer.\n\n" \
    144                   "You will lose all current login configurations \n" \
    145                   "and disable smartcard login in your computer.\n\n" \
    146                   "Do you still want to reset your current \n" \
    147                   "smartcard login configurations?\n"
    148         reply = self.messageBox.warning(self, "Reset Login Configurations", message,
    149                                         QMessageBox.No, QMessageBox.Yes)
    150         return reply == QMessageBox.Yes
     114            self.customizeWindow = settingswin.customizeConfigsWindow()
     115            self.customizeWindow.show()
    151116
    152117    def isWizardProcessActive(self):
     
    161126        if config.isPkcs11Installed() and config.hasAdminPermissions(os.getlogin()):
    162127            self.statusbarSlider.show()
    163             if config.isPkcs11LoginActive():
     128            if config.isPkcs11LoginEnabled():
    164129                self.statusbarLabel.setText("Smartcard Login Enabled")
    165130                self.statusbarSlider.setValue(self.statusbarSlider.maximum())
     
    171136
    172137    def changeLoginStatus(self):
    173         if config.isPkcs11LoginActive():
     138        if config.isPkcs11LoginEnabled():
    174139            config.disablePkcs11Login()
    175140        else:
     
    178143
    179144    def closeEvent(self, QCloseEvent):
    180         if self.popup is not None:
    181             self.popup.close()
     145        if self.customizeWindow is not None:
     146            self.customizeWindow.close()
    182147        if self.isWizardProcessActive():
    183148            reply = self.messageBox.warning(self, "Title",  "\nYou have an add user login wizard open.\n\n"
     
    199164
    200165
    201 class resetPopup(QtWidgets.QWidget):
    202     def __init__(self):
    203         super(resetPopup, self).__init__()
    204         self.resize(550, 400)
    205         self.centerOnScreen()
    206 
    207         self.messageBox = QtWidgets.QMessageBox(self)
    208 
    209         self.tabwidget = QtWidgets.QTabWidget(self)
    210         self.tabwidget.setGeometry(QtCore.QRect(40, 30, 400, 290))
    211 
    212         #self.firstRow = QtWidgets.QLabel(self)
    213         #self.firstRow.setStyleSheet("font: bold;")
    214         #self.firstRow.setGeometry(QtCore.QRect(40, 30, 400, 30))
    215         # self.firstRow.setText("\n      BI Number".ljust(25)+"     Full Name".ljust(25)+"  Username".ljust(25) + "\n")
    216 
    217         self.enabledCombosList = QtWidgets.QListWidget(self)
    218         self.buildLocalCombos()
    219         self.tabwidget.insertTab(0, self.enabledCombosList, "Enabled Logins")
    220 
    221         self.disabledCombosList = QtWidgets.QListWidget(self)
    222         self.buildDisabledCombos()
    223         self.tabwidget.insertTab(1, self.disabledCombosList, "Disabled Logins")
    224 
    225         self.selectAllButton = QtWidgets.QPushButton(self)
    226         self.selectAllButton.setGeometry(QtCore.QRect(40, 330, 100, 30))
    227 
    228         self.disableSelectionButton = QtWidgets.QPushButton(self)
    229         self.disableSelectionButton.setGeometry(QtCore.QRect(250, 330, 90, 30))
    230 
    231         self.removeSelectionButton = QtWidgets.QPushButton(self)
    232         self.removeSelectionButton.setGeometry(QtCore.QRect(350, 330, 90, 30))
    233 
    234         self.setWindowTitle("Remove Login Configurations")
    235         self.selectAllButton.setText("Select All")
    236         self.disableSelectionButton.setText("Disable")
    237         self.removeSelectionButton.setText("Delete")
    238 
    239         self.selectAllButton.clicked.connect(self.selectAllEvent)
    240         self.removeSelectionButton.clicked.connect(self.removeSelectionEvent)
    241         self.tabwidget.currentChanged.connect(self.updateTabList)
    242         self.enabledCombosList.itemChanged.connect(self.updateTabList)
    243         self.disabledCombosList.itemChanged.connect(self.updateTabList)
    244 
    245     def centerOnScreen(self):
    246         resolution = QtWidgets.QDesktopWidget().screenGeometry()
    247         self.move((resolution.width() / 2) - (self.frameSize().width() / 2),
    248                   (resolution.height() / 2) - (self.frameSize().height() / 2))
    249 
    250     def buildLocalCombos(self):
    251         self.enabledCombosList.clear()
    252         localCombos = config.listLocalCombos()
    253         for combo in localCombos:
    254             number, name, user = combo[0], combo[1], combo[2]
    255             item = QtWidgets.QListWidgetItem("\n" + number.ljust(25) + name.ljust(25) + user.ljust(25) + "\n")
    256             item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
    257             item.setData(QtCore.Qt.CheckStateRole, QtCore.QVariant(QtCore.Qt.Unchecked))
    258             self.enabledCombosList.addItem(item)
    259 
    260     def buildDisabledCombos(self):
    261         self.disabledCombosList.clear()
    262         disabledCombos = config.listDisabledCombos()
    263         for combo in disabledCombos:
    264             number, name, user = combo[0], combo[1], combo[2]
    265             item = QtWidgets.QListWidgetItem("\n" + number.ljust(25) + name.ljust(25) + user.ljust(25) + "\n")
    266             item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
    267             item.setData(QtCore.Qt.CheckStateRole, QtCore.QVariant(QtCore.Qt.Unchecked))
    268             self.disabledCombosList.addItem(item)
    269 
    270     def updateTabList(self):
    271         if self.hasAllItemsChecked():
    272             self.selectAllButton.setText("Unselect All")
    273         else:
    274             self.selectAllButton.setText("Select All")
    275 
    276     def hasAllItemsChecked(self):
    277         if self.tabwidget.currentIndex() == 0:
    278             for i in range(self.enabledCombosList.count()):
    279                 item = self.enabledCombosList.item(i)
    280                 if item.checkState() == QtCore.Qt.Unchecked:
    281                     return False
    282             return True
    283         else:
    284             for i in range(self.disabledCombosList.count()):
    285                 item = self.disabledCombosList.item(i)
    286                 if item.checkState() == QtCore.Qt.Unchecked:
    287                     return False
    288             return True
    289 
    290     def selectAllEvent(self):
    291         if self.hasAllItemsChecked():
    292             self.unselectAllCombos()
    293             self.selectAllButton.setText("Select All")
    294         else:
    295             self.selectAllCombos()
    296             self.selectAllButton.setText("Unselect All")
    297 
    298     def selectAllCombos(self):
    299         if self.tabwidget.currentIndex() == 0:
    300             for i in range(self.enabledCombosList.count()):
    301                 item = self.enabledCombosList.item(i)
    302                 item.setCheckState(QtCore.Qt.Checked)
    303         else:
    304             for i in range(self.disabledCombosList.count()):
    305                 item = self.disabledCombosList.item(i)
    306                 item.setCheckState(QtCore.Qt.Checked)
    307 
    308     def unselectAllCombos(self):
    309         if self.tabwidget.currentIndex() == 0:
    310             for i in range(self.enabledCombosList.count()):
    311                 item = self.enabledCombosList.item(i)
    312                 item.setCheckState(QtCore.Qt.Unchecked)
    313         else:
    314             for i in range(self.disabledCombosList.count()):
    315                 item = self.disabledCombosList.item(i)
    316                 item.setCheckState(QtCore.Qt.Unchecked)
    317 
    318     def removeSelectionEvent(self):
    319         ret = []
    320         message = "\n     BI Number".ljust(25) + "      Full Name".ljust(25) + "       Username".ljust(25) + "\n"
    321         for i in range(self.enabledCombosList.count()):
    322             item = self.enabledCombosList.item(i)
    323             if item.checkState() == QtCore.Qt.Checked:
    324                 message += "     " + item.text().strip() + "\n"
    325                 ret.append(i)
    326         if len(ret) == 0:
    327             self.messageBox.information(self, "Title", "\nNo login configurations selected.\n\n"
    328                                         "Please select the login configurations \n"
    329                                         "you would like to remove.\n\n")
    330         else:
    331             reply = self.messageBox.warning(self, "Title",
    332                                             "\nYou are about to remove the following login configurations:\n" +
    333                                             message + "\nAre you sure you want to remove them?\n",
    334                                             QMessageBox.No, QMessageBox.Yes)
    335             if reply == QMessageBox.Yes:
    336                 config.deleteSelectedCombos(ret)
    337                 self.buildLocalCombos()
    338 
    339 
    340166if __name__ == "__main__":
    341167    import sys
Note: See TracChangeset for help on using the changeset viewer.