void CSafeCombinationEntry::OnNewDbClick( wxCommandEvent& /* evt */ ) { // 1. Get a filename from a file dialog box // 2. Get a password // 3. Set m_filespec && m_passkey to returned value! wxString newfile; wxString cs_msg, cs_title, cs_temp; wxString cf(wxT("pwsafe")); // reasonable default for first time user stringT v3FileName = PWSUtil::GetNewFileName(tostdstring(cf), wxT("psafe3")); stringT dir = PWSdirs::GetSafeDir(); while (1) { wxFileDialog fd(this, _("Please choose a name for the new database"), dir.c_str(), v3FileName.c_str(), _("Password Safe Databases (*.psafe3; *.dat)|*.psafe3;*.dat| All files (*.*; *)|*.*;*"), (wxFD_SAVE | wxFD_OVERWRITE_PROMPT| wxFD_CHANGE_DIR)); int rc = fd.ShowModal(); if (rc == wxID_OK) { wxFileName wxfn(fd.GetPath()); if (wxfn.GetExt().empty()) { wxfn.SetExt(DEFAULT_SUFFIX); } newfile = wxfn.GetFullPath(); break; } else return; } // 2. Get a password CSafeCombinationSetup pksetup(this); int rc = pksetup.ShowModal(); if (rc != wxID_OK) return; //User cancelled password entry // 3. Set m_filespec && m_passkey to returned value! m_core.SetCurFile(tostringx(newfile)); // Now lock the new file std::wstring locker(L""); // null init is important here m_core.LockFile(tostdstring(newfile), locker); m_core.SetReadOnly(false); // new file can't be read-only... m_core.NewFile(tostringx(pksetup.GetPassword())); if ((rc = m_core.WriteCurFile()) == PWSfile::SUCCESS) { wxGetApp().recentDatabases().AddFileToHistory(newfile); EndModal(wxID_OK); } else { wxMessageBox(wxString()<< newfile << wxT("\n\n") << _("Could not open file for writing!"), _("Write Error"), wxOK | wxICON_ERROR, this); } }
void CSafeCombinationPrompt::OnOkClick( wxCommandEvent& /* evt */ ) { if (Validate() && TransferDataFromWindow()) { if (m_password.empty()) { wxMessageDialog err(this, _("The combination cannot be blank."), _("Error"), wxOK | wxICON_EXCLAMATION); err.ShowModal(); return; } if (!pws_os::FileExists(tostdstring(m_filename))) { wxMessageDialog err(this, _("File or path not found."), _("Error"), wxOK | wxICON_EXCLAMATION); err.ShowModal(); return; } ProcessPhrase(); } }
void CSafeCombinationPrompt::OnYubibtnClick( wxCommandEvent& /* event */ ) { m_scctrl->AllowEmptyCombinationOnce(); // Allow blank password when Yubi's used if (Validate() && TransferDataFromWindow()) { if (!pws_os::FileExists(tostdstring(m_filename))) { wxMessageDialog err(this, _("File or path not found."), _("Error"), wxOK | wxICON_EXCLAMATION); err.ShowModal(); return; } StringX response; bool oldYubiChallenge = ::wxGetKeyState(WXK_SHIFT); // for pre-0.94 databases if (PerformChallengeResponse(this, m_password, response, oldYubiChallenge)) { m_password = response; ProcessPhrase(); UpdateStatus(); } } }
void CSafeCombinationEntry::OnOk( wxCommandEvent& ) { if (Validate() && TransferDataFromWindow()) { if (m_password.empty()) { wxMessageDialog err(this, _("The combination cannot be blank."), _("Error"), wxOK | wxICON_EXCLAMATION); err.ShowModal(); FindWindow(ID_COMBINATION)->SetFocus(); return; } if (!pws_os::FileExists(tostdstring(m_filename))) { wxMessageDialog err(this, _("File or path not found."), _("Error"), wxOK | wxICON_EXCLAMATION); err.ShowModal(); m_filenameCB->SetFocus(); return; } ProcessPhrase(); } // Validate && TransferDataFromWindow }
bool COpenFilePickerValidator::Validate(wxWindow * parent) { if (GetWindow() && GetWindow()->IsKindOf(&wxFilePickerCtrl::ms_classInfo)) { wxFilePickerCtrl* ctrl = dynamic_cast<wxFilePickerCtrl *>(GetWindow()); wxASSERT(ctrl); if (!ctrl) return false; wxString path = ctrl->GetPath(); if (path.IsEmpty()) { wxMessageBox(wxString() << _("You must select a valid file to continue.") << wxT("\n\n") << path, _("You haven't selected any files"), wxOK | wxICON_EXCLAMATION, parent); } else if (pws_os::FileExists(tostdstring(path))) { return true; } else { //path is blank on Linux/gtk. May be its not so on other platforms wxMessageBox(wxString() << _("Selected file doesn't exist.") << wxT("\n\n") << path, _("Please select a valid file"), wxOK | wxICON_EXCLAMATION, parent); return false; } } return false; }
void CompareDlg::DoCompare(wxCommandEvent& /*evt*/) { bool treatWhitespacesAsEmpty = false; m_currentCore->Compare(m_otherCore, m_selCriteria->GetSelectedFields(), m_selCriteria->HasSubgroupRestriction(), treatWhitespacesAsEmpty, tostdstring(m_selCriteria->SubgroupSearchText()), m_selCriteria->SubgroupObject(), m_selCriteria->SubgroupFunction(), m_current->data, m_comparison->data, m_conflicts->data, m_identical->data); struct { ComparisonData* cd; bool expand; bool multiSource; bool useComparisonSafe; ////unused if multisource is true } sections[] = { {m_conflicts, true, true, false}, {m_current, true, false, false}, {m_comparison, true, false, true}, {m_identical, false, false, false} }; wxSizerItem* prevSizer = 0; for(size_t idx =0; idx < WXSIZEOF(sections); ++idx) { ComparisonGridTable* table; if (sections[idx].multiSource) { table = new MultiSafeCompareGridTable(m_selCriteria, §ions[idx].cd->data, m_currentCore, m_otherCore); } else { table = new UniSafeCompareGridTable(m_selCriteria, §ions[idx].cd->data, sections[idx].useComparisonSafe? m_otherCore: m_currentCore, sections[idx].useComparisonSafe? &st_CompareData::uuid1: &st_CompareData::uuid0, sections[idx].useComparisonSafe? ComparisonBackgroundColor: CurrentBackgroundColor); } sections[idx].cd->grid->SetTable(table, true, wxGrid::wxGridSelectRows); wxCollapsiblePane* pane = sections[idx].cd->pane; //expand the columns to show these fields fully, as these are usually small(er) strings table->AutoSizeField(CItemData::GROUP); table->AutoSizeField(CItemData::TITLE); table->AutoSizeField(CItemData::USER); table->AutoSizeField(CItemData::PASSWORD); /* // wxCollapsiblePane::GetLabel() doesn't work wxString newLabel(pane->GetLabel()); newLabel << wxT(" (") << sections[idx].cd->data.size() << wxT(")"); pane->SetLabel(newLabel); */ if (!sections[idx].cd->data.empty()) { pane->Show(); //if the next pane is displayed, show the sizer below this pane if (prevSizer) prevSizer->Show(true); prevSizer = sections[idx].cd->sizerBelow; } else { pane->Collapse(); pane->Hide(); } } wxCommandEvent cmdEvent(EVT_EXPAND_DATA_PANELS, GetId()); GetEventHandler()->AddPendingEvent(cmdEvent); }