예제 #1
0
 def logIn(self):
     """
         Read input lines and login user if possible.
     """
     logging.debug("logging user ...")
     
     try:
         path = AppSettings.readDbFilePath()
         self.__db_ctrl.connectDB(path)
         
         login_ctrl = LoginController(self.__db_ctrl)
         
         username = AppSettings.USER_NAME
         master = str(self._passwd.text().toUtf8())
         
         logged_user = login_ctrl.logInUser(username, master)
         
         if (logged_user):
             self.signalSuccessfullyLogged.emit(QtCore.QString.fromUtf8(username), QtCore.QString.fromUtf8(master))
             
             self.close()
         else:
             # sleep for a while
             time.sleep(AppSettings.WRONG_PASWD_SLEEP)
             
             # show message
             QtGui.QMessageBox(QtGui.QMessageBox.Critical, tr("Wrong credentials!"), tr("Username or password are wrong.")).exec_()
     except Exception as e:
         InfoMsgBoxes.showErrorMsg(e)
예제 #2
0
def main():
    app = QtGui.QApplication(sys.argv)
    
    logging.info("Absolute app root: '%s'", AppSettings.APP_ABS_ROOT)
    
    # set application icon
    app.setWindowIcon(QtGui.QIcon(AppSettings.APP_ICON_PATH))
    
    # create neccessary paths if missing
    ifNotExCreate(AppSettings.TMP_PATH)
    ifNotExCreate(AppSettings.BACKUP_PATH)
    ifNotExCreate(AppSettings.DATA_PATH)
    ifNotExCreate(AppSettings.DB_PATH)
    ifNotExCreate(AppSettings.ICONS_PATH)
    
    # preapare languages
    AppSettings.writeLanguage("sk")
    
    AppSettings.LANG = AppSettings.readLanguage()
    
    TransController.loadTranslation("sk")
    TransController.loadTranslation("en")
    
    # DB controller instance
    db_con = DbController()

    # login dialog instance
    login_dialog = LoginDialog(db_con)

    db_path = AppSettings.readDbFilePath()
    logging.info("DB path: '%s'", db_path)
    
    if (not os.path.exists(AppSettings.decodePath(db_path))):
        # if default DB file doesnt exists, run create DB dialog
        login_dialog.enLogIn(False)
    else:
        # leave only last 10 backups
        backups = sorted(os.listdir(AppSettings.BACKUP_PATH), reverse=True)

        if len(backups) >= 10:
            for i in range(9, len(backups)):
                os.remove(AppSettings.BACKUP_PATH + backups[i])
        # first backup database
        backup_file = AppSettings.BACKUP_PATH + time.strftime("%Y-%m-%dT%H:%M:%S_", time.localtime()) + os.path.basename(db_path)
        logging.info("backup file: '%s'", backup_file)
        
        shutil.copyfile(AppSettings.decodePath(db_path), AppSettings.decodePath(backup_file))

    login_dialog.show()
    w = MainWindow(db_con)
 
    # when succesfully logged load main window
    login_dialog.signalSuccessfullyLogged.connect(w.setUserReloadShow)
    
    sys.exit(app.exec_())
예제 #3
0
    def initUI(self):
        """
            Initialize UI components.
        """
        self.setWindowTitle(tr("Log in: ") + QtCore.QString.fromUtf8(os.path.basename(AppSettings.readDbFilePath())))
        self.setFixedSize(500, 100)
        
        # create main grid layout
        layout_gl = QtGui.QGridLayout()
        self.setLayout(layout_gl)
        
        # labels
#         username_label = QtGui.QLabel("<b>" + tr("Username:"******"</b>")
        passwd_label = QtGui.QLabel("<b>" + tr("Password:"******"</b>")
        
        # add to layout
#         layout_gl.addWidget(username_label, 0, 0)
        layout_gl.addWidget(passwd_label, 0, 0)
        
#         self._username = QtGui.QLineEdit()
#         layout_gl.addWidget(self._username, 0, 1)
        
        self._passwd = QtGui.QLineEdit()
        
        # hide password
        self._passwd.setEchoMode(QtGui.QLineEdit.Password)
        
        # password layout
        passwd_hl = QtGui.QHBoxLayout()
        
        # add password edit line to layout
        passwd_hl.addWidget(self._passwd)
        
        # password visibility check box
        self._show_passwd_check = QtGui.QCheckBox(tr("Show"))
        self._show_passwd_check.setChecked(False)
        passwd_hl.addWidget(self._show_passwd_check)
        
        layout_gl.addLayout(passwd_hl, 0, 1)
        
        # create buttons
        self._button_box = QtGui.QDialogButtonBox()
        
        self.__login_button = QtGui.QPushButton(tr("&Log In"))
        self.__login_button.setEnabled(False)
        
        self.__close_button = QtGui.QPushButton(tr("&Close"))
        
        self._button_box.addButton(self.__login_button, QtGui.QDialogButtonBox.AcceptRole)
        self._button_box.addButton(self.__close_button, QtGui.QDialogButtonBox.RejectRole)
        
#         layout_gl.addWidget(self._button_box, 1, 1)
        
        # db button layout
        db_buttons_hl = QtGui.QHBoxLayout()
    
        self.__open_db = QtGui.QPushButton(tr("Open Database"))
        self.__create_db = QtGui.QPushButton(tr("Create Database"))
        
        db_buttons_hl.addWidget(self.__open_db)
        db_buttons_hl.addWidget(self.__create_db)
        db_buttons_hl.addWidget(self._button_box)
        
        layout_gl.addLayout(db_buttons_hl, 1, 0, 1, 2)
예제 #4
0
 def enLogIn(self, b = True):
     """
         Enable or disable password input, show checkbox and login button.
     """
     logging.debug("enabling login: %s", b)
     
     self._passwd.setEnabled(b)
     self._show_passwd_check.setEnabled(b)
     self.__login_button.setEnabled(b)
     
     if (not b):
         self.setWindowTitle(tr("Database not selected."))
     else:
         self.setWindowTitle(tr("Log in: ") + QtCore.QString.fromUtf8(os.path.basename(AppSettings.readDbFilePath())))