示例#1
0
void MainWindow::on_action_EditPassword_triggered()
{
    int row = ui->listWidget->currentRow();
    QListWidgetItem *widgetItem = ui->listWidget->currentItem();

    if(row >= 0 && widgetItem && widgetItem->isSelected())
    {
        QList<PasswordItem> list = this->accountFile->getPasswordList();
        PasswordDialog dialog;

        dialog.setWindowTitle("编辑密码项");
        dialog.setPasswordItem(list.at(row));
        if(dialog.exec() == QDialog::Accepted)
        {
            PasswordItem item = dialog.getPasswordItem();
            bool ok;

            list[row].name = item.name;
            list[row].password = item.password;
            this->accountFile->setPasswordList(list);
            ok = this->accountFile->save(this->accountFileName);
            if(ok)
                ui->listWidget->item(row)->setText(item.name);
        }
    }
}
示例#2
0
void MainWindow::on_action_NewPassword_triggered()
{
    PasswordDialog dialog;

    dialog.setWindowTitle("新增密码项");
    if(dialog.exec() == QDialog::Accepted)
    {
        PasswordItem item = dialog.getPasswordItem();
        QList<PasswordItem> list = this->accountFile->getPasswordList();
        bool ok;

        list.append(item);
        this->accountFile->setPasswordList(list);
        ok = this->accountFile->save(this->accountFileName);
        if(ok)
            ui->listWidget->addItem(item.name);
    }
}