void CCreateShortcutDlg::OnOK() 
{
  if (UpdateData(TRUE) == FALSE)
    return;

  CGeneralMsgBox gmb;
  m_group.EmptyIfOnlyWhiteSpace();
  m_title.EmptyIfOnlyWhiteSpace();
  m_username.EmptyIfOnlyWhiteSpace();

  //Check that data is valid
  if (m_title.IsEmpty()) {
    gmb.AfxMessageBox(IDS_MUSTHAVETITLE);
    ((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus();
    return;
  }

  if (!m_group.IsEmpty() && m_group[0] == '.') {
    gmb.AfxMessageBox(IDS_DOTINVALID);
    ((CEdit*)GetDlgItem(IDC_GROUP))->SetFocus();
    return;
  }

  // If there is a matching entry in our list, tell the user to try again.
  if (GetMainDlg()->Find(m_group, m_title, m_username) != app.GetMainDlg()->End()) {
    CSecString temp;
    if (m_group.IsEmpty())
      temp.Format(IDS_ENTRYEXISTS2, m_title, m_username);
    else
      temp.Format(IDS_ENTRYEXISTS, m_group, m_title, m_username);
    gmb.AfxMessageBox(temp);
    ((CEdit*)GetDlgItem(IDC_TITLE))->SetSel(MAKEWORD(-1, 0));
    ((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus();
    return;
  }
  //End check

  CPWDialog::OnOK();
}
예제 #2
0
BOOL CAddEdit_Basic::OnApply()
{
    if (M_uicaller() == IDS_VIEWENTRY || M_protected() != 0)
        return FALSE; //CAddEdit_PropertyPage::OnApply();

    CWnd *pFocus(NULL);
    CGeneralMsgBox gmb;
    ItemListIter listindex;
    bool brc, b_msg_issued;

    UpdateData(TRUE);

    M_group().EmptyIfOnlyWhiteSpace();
    M_title().EmptyIfOnlyWhiteSpace();
    M_username().EmptyIfOnlyWhiteSpace();
    M_URL().EmptyIfOnlyWhiteSpace();
    M_email().EmptyIfOnlyWhiteSpace();
    M_symbols().EmptyIfOnlyWhiteSpace();

    m_notes.EmptyIfOnlyWhiteSpace();

    if (m_password.IsOnlyWhiteSpace()) {
        m_password.Empty();
        if (m_isPWHidden)
            m_password2.Empty();
    }

    if (!m_isPWHidden || m_password != HIDDEN_PASSWORD)
        M_realpassword() = m_password;

    if (!m_isNotesHidden)
        M_realnotes() = m_notes;

    UpdateData(FALSE);

    //Check that data is valid
    if (M_title().IsEmpty()) {
        gmb.AfxMessageBox(IDS_MUSTHAVETITLE);
        pFocus = &m_ex_title;
        goto error;
    }

    if (M_realpassword().IsEmpty()) {
        gmb.AfxMessageBox(IDS_MUSTHAVEPASSWORD);
        pFocus = &m_ex_password;
        goto error;
    }

    if (!M_group().IsEmpty() && M_group()[0] == '.') {
        gmb.AfxMessageBox(IDS_DOTINVALID);
        pFocus = &m_ex_group;
        goto error;
    }

    if (m_isPWHidden && (m_password.Compare(m_password2) != 0)) {
        gmb.AfxMessageBox(IDS_PASSWORDSNOTMATCH);
        UpdateData(FALSE);
        pFocus = &m_ex_password;
        goto error;
    }

    // If there is a matching entry in our list, tell the user to try again.
    listindex = GetMainDlg()->Find(M_group(), M_title(), M_username());
    if (M_uicaller() == IDS_ADDENTRY) {
        // Add entry
        if (listindex != GetMainDlg()->End()) {
            CSecString temp;
            if (M_group().IsEmpty())
                if (M_username().IsEmpty())
                    temp.Format(IDS_ENTRYEXISTS3, M_title());
                else
                    temp.Format(IDS_ENTRYEXISTS2, M_title(), M_username());
            else if (M_username().IsEmpty())
                temp.Format(IDS_ENTRYEXISTS1, M_group(), M_title());
            else
                temp.Format(IDS_ENTRYEXISTS, M_group(), M_title(), M_username());

            gmb.AfxMessageBox(temp);
            pFocus = &m_ex_title;
            goto error;
        }
    } else {
        // Edit entry
        if (listindex != GetMainDlg()->End()) {
            const CItemData &listItem = GetMainDlg()->GetEntryAt(listindex);
            if (listItem.GetUUID() != M_pci()->GetUUID()) {
                CSecString temp;
                temp.Format(IDS_ENTRYEXISTS, M_group(), M_title(), M_username());
                gmb.AfxMessageBox(temp);
                pFocus = &m_ex_title;
                goto error;
            }
        }
    }

    brc = CheckNewPassword(M_group(), M_title(), M_username(), M_realpassword(),
                           M_uicaller() != IDS_ADDENTRY, CItemData::ET_ALIAS,
                           M_base_uuid(), M_ibasedata(), b_msg_issued);

    if (!brc && M_ibasedata() != 0) {
        if (!b_msg_issued)
            gmb.AfxMessageBox(IDS_MUSTHAVETARGET, MB_OK);

        UpdateData(FALSE);
        pFocus = &m_ex_password;
        goto error;
    }
    //End check

    return CAddEdit_PropertyPage::OnApply();

error:
    // Are we the current page, if not activate this page
    if (m_ae_psh->GetActivePage() != (CAddEdit_PropertyPage *)this)
        m_ae_psh->SetActivePage(this);

    if (pFocus != NULL)
        pFocus->SetFocus();

    if (pFocus == &m_ex_title)
        m_ex_title.SetSel(MAKEWORD(-1, 0));

    return FALSE;
}
예제 #3
0
void CEditShortcutDlg::OnOK() 
{
  ItemListIter listindex;

  if (m_Edit_IsReadOnly) {
    CPWDialog::OnOK();
    return;
  }

  UpdateData(TRUE);
  m_group.EmptyIfOnlyWhiteSpace();
  m_title.EmptyIfOnlyWhiteSpace();
  m_username.EmptyIfOnlyWhiteSpace();

  m_bIsModified |= (m_group != m_pci->GetGroup() ||
                    m_title != m_pci->GetTitle() ||
                    m_username != m_pci->GetUser());

  //Check that data is valid
  if (m_title.IsEmpty()) {
    CGeneralMsgBox gmb;
    gmb.AfxMessageBox(IDS_MUSTHAVETITLE);
    ((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus();
    goto dont_close;
  }

  if (!m_group.IsEmpty() && m_group[0] == '.') {
    CGeneralMsgBox gmb;
    gmb.AfxMessageBox(IDS_DOTINVALID);
    ((CEdit*)GetDlgItem(IDC_GROUP))->SetFocus();
    goto dont_close;
  }

  listindex = GetMainDlg()->Find(m_group, m_title, m_username);
  /*
  *  If there is a matching entry in our list, and that
  *  entry is not the same one we started editing, tell the
  *  user to try again.
  */
  if (listindex != GetMainDlg()->End()) {
    const CItemData &listItem = GetMainDlg()->GetEntryAt(listindex);
    bool notSame = listItem.GetUUID() != m_pci->GetUUID();
    if (notSame) {
      CGeneralMsgBox gmb;
      CSecString temp;
      temp.Format(IDS_ENTRYEXISTS, m_group, m_title, m_username);
      gmb.AfxMessageBox(temp);
      ((CEdit*)GetDlgItem(IDC_TITLE))->SetSel(MAKEWORD(-1, 0));
      ((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus();
      goto dont_close;
    }
  }
  //End check

  // Everything OK, update fields
  m_pci->SetGroup(m_group);
  m_pci->SetTitle(m_title);
  m_pci->SetUser(m_username.IsEmpty() ? m_defusername : m_username);

  time_t t;
  time(&t);

  if (m_bIsModified)
    m_pci->SetRMTime(t);

  CPWDialog::OnOK();
  return;

  // If we don't close, then update controls, as some of the fields
  // may have been modified (e.g., spaces removed).
dont_close:
  UpdateData(FALSE);
}