#include "ftpro.h"
BEGIN_EVENT_TABLE(ConnectionDialog,wxDialog)
EVT_CHECKBOX( ID_ANONYMOUS_CHECKBOX, ConnectionDialog::OnAnonymous )
EVT_CHECKBOX( ID_CONNECT_QUICK_NAME, ConnectionDialog::OnAnonymous )
EVT_BUTTON( ID_CONNECT_OK, ConnectionDialog::OnOk )
EVT_BUTTON( ID_CONNECT_BUTTON, ConnectionDialog::OnCancel )
//QUICK CONNECTS
EVT_BUTTON( ID_QC_CANCEL, ConnectionDialog::OnCancel)
EVT_BUTTON( ID_QC_CONNECT, ConnectionDialog::OnQuickConnect )
EVT_BUTTON( ID_QC_EDIT, ConnectionDialog::OnQuickEdit )
EVT_BUTTON( ID_QC_REMOVE, ConnectionDialog::OnQuickRemove )
// SOI
EVT_BUTTON( ID_SOI_CONNECT, ConnectionDialog::OnSOIConnect)
EVT_BUTTON( ID_SOI_INFO, ConnectionDialog::OnSOIInfo )
EVT_BUTTON( ID_SOI_CANCEL, ConnectionDialog::OnCancel )
END_EVENT_TABLE()
ConnectionDialog::ConnectionDialog( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &position, const wxSize& size, long style ) :
wxDialog( parent, id, title, position, size, style )
{
// needed so i can add items below
vector<string> qc_filestoadd;
if (!wxFileExists("C:\\FTPro\\.qc"))
{
ofstream out("C:\\FTPro\\.qc");
out.close();
}
else
{
char line[256];
ifstream in("C:\\FTPro\\.qc");
string shortcut;
string l;
while (true)
{
vector<string> info(4);
in.getline(line, 256);
if (line[0] == '\n' || line[0] == '\0')
break;
l = line;
stringTok tok(&l, "~~");
shortcut = tok.NextToken();
qc_filestoadd.push_back(shortcut);
while(tok.HasMoreTokens())
{
info.push_back(tok.NextToken());
}
QCList[shortcut] = info;
}
}
wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
wxNotebook *item2 = new wxNotebook( this, ID_NOTEBOOK, wxDefaultPosition, wxSize(200,160), wxNB_FIXEDWIDTH );
wxNotebookSizer *item1 = new wxNotebookSizer( item2 );
wxPanel *p1 = new wxPanel( item2, -1 );
// connection_dialog( item3, FALSE );
{
wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
wxStaticBox *item2 = new wxStaticBox( p1, -1, "Connect" );
wxStaticBoxSizer *item1 = new wxStaticBoxSizer( item2, wxVERTICAL );
wxBoxSizer *item3 = new wxBoxSizer( wxHORIZONTAL );
wxCheckBox *item4 = new wxCheckBox( p1, ID_ENCRYPTED_CHECKBOX, "Encrypted (soon to come)", wxDefaultPosition, wxDefaultSize, 0 );
item4->SetToolTip( "An option to encrypt" );
item3->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
item3->Add( 90, 20, 0, wxALIGN_CENTRE|wxALL, 5 );
anonymous_cx = new wxCheckBox( p1, ID_ANONYMOUS_CHECKBOX, "Anonymous", wxDefaultPosition, wxDefaultSize, 0 );
anonymous_cx->SetToolTip( "Make anonymous connection" );
item3->Add( anonymous_cx, 0, wxALIGN_CENTRE|wxALL, 5 );
item1->Add( item3, 0, wxALIGN_CENTRE|wxALL, 5 );
wxBoxSizer *item6 = new wxBoxSizer( wxHORIZONTAL );
wxStaticText *item7 = new wxStaticText( p1, ID_TEXT, "Host", wxDefaultPosition, wxDefaultSize, 0 );
item6->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );
host_tc = new wxTextCtrl( p1, ID_HOST_TEXT, "", wxDefaultPosition, wxSize(160,-1), 0 );
host_tc->SetToolTip( "The host address" );
item6->Add( host_tc, 0, wxALIGN_CENTRE|wxALL, 5 );
wxStaticText *item9 = new wxStaticText( p1, ID_TEXT, " User", wxDefaultPosition, wxDefaultSize, 0 );
item6->Add( item9, 0, wxALIGN_CENTRE|wxALL, 5 );
user_tc = new wxTextCtrl( p1, ID_HOST_USER, "", wxDefaultPosition, wxSize(160,-1), 0 );
user_tc->SetToolTip( "Your username" );
item6->Add( user_tc, 0, wxALIGN_CENTRE|wxALL, 5 );
item1->Add( item6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
wxBoxSizer *item11 = new wxBoxSizer( wxHORIZONTAL );
wxStaticText *item12 = new wxStaticText( p1, ID_TEXT, "Port ", wxDefaultPosition, wxDefaultSize, 0 );
item11->Add( item12, 0, wxALIGN_CENTRE|wxALL, 5 );
wxString strs13[] =
{
"21",
"22",
"23"
};
port_cb= new wxComboBox( p1, ID_PORT_COMBO, "", wxDefaultPosition, wxSize(160,-1), 1, strs13, wxCB_DROPDOWN );
port_cb->SetToolTip( "The port to connect to, usually 21" );
item11->Add( port_cb, 0, wxALIGN_CENTRE|wxALL, 5 );
port_cb->SetSelection(0);
wxStaticText *item14 = new wxStaticText( p1, ID_TEXT, "Password", wxDefaultPosition, wxDefaultSize, 0 );
item11->Add( item14, 0, wxALIGN_CENTRE|wxALL, 5 );
password_tc = new wxTextCtrl( p1, ID_HOST_PASSWORD, "", wxDefaultPosition, wxSize(160,-1), 0 );
password_tc->SetToolTip( "Your password" );
item11->Add( password_tc, 0, wxALIGN_CENTRE|wxALL, 5 );
item1->Add( item11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
wxBoxSizer *item16 = new wxBoxSizer( wxHORIZONTAL );
qc_cx = new wxCheckBox( p1, ID_CONNECT_QUICK_NAME, "Add to Quick Connect", wxDefaultPosition, wxDefaultSize, 0);
qc_cx->SetToolTip( "Add to your quick connect collection ?" );
item16->Add( qc_cx, 0, wxALIGN_CENTRE|wxALL, 5 );
item16->Add( 70, 20, 0, wxALIGN_CENTRE|wxALL, 5 );
wxStaticText *item18 = new wxStaticText( p1, ID_TEXT, "(Name)", wxDefaultPosition, wxDefaultSize, 0 );
item16->Add( item18, 0, wxALIGN_CENTRE|wxALL, 5 );
qc_tc = new wxTextCtrl( p1, ID_QUICK_NAME, "", wxDefaultPosition, wxSize(160,-1), 0 );
qc_tc->SetToolTip( "The name to add to your quick connect collection" );
qc_tc->Enable( FALSE );
item16->Add( qc_tc, 0, wxALIGN_CENTRE|wxALL, 5 );
item1->Add( item16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
item0->Add( item1, 0, wxALIGN_CENTRE|wxALL, 5 );
wxBoxSizer *item20 = new wxBoxSizer( wxHORIZONTAL );
wxButton *item21 = new wxButton( p1, ID_CONNECT_OK, "OK", wxDefaultPosition, wxDefaultSize, 0 );
item21->SetToolTip( "Connect" );
item20->Add( item21, 0, wxALIGN_CENTRE|wxALL, 5 );
item20->Add( 80, 20, 0, wxALIGN_CENTRE|wxALL, 5 );
wxButton *item22 = new wxButton( p1, ID_CONNECT_BUTTON, "Cancel", wxDefaultPosition, wxDefaultSize, 0 );
item22->SetToolTip( "Cancel" );
item20->Add( item22, 0, wxALIGN_CENTRE|wxALL, 5 );
item0->Add( item20, 0, wxALIGN_CENTRE|wxALL, 5 );
p1->SetAutoLayout( TRUE );
p1->SetSizer( item0 );
item0->Fit( p1 );
item0->SetSizeHints( p1 );
}
item2->AddPage( p1, "Connect" );
wxPanel *p2 = new wxPanel( item2, -1 );
// quick_connect( item4, FALSE );
{
wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
wxStaticBox *item2 = new wxStaticBox( p2, -1, "Quick Connect" );
wxStaticBoxSizer *item1 = new wxStaticBoxSizer( item2, wxHORIZONTAL );
wxString *strs3 = (wxString*) NULL;
qc_listbox = new wxListBox( p2, ID_QC_LISTBOX, wxDefaultPosition, wxSize(140,160), 0, strs3, wxLB_SINGLE );
item1->Add( qc_listbox, 0, wxALIGN_CENTRE|wxALL, 5 );
for (int i = 0;i < qc_filestoadd.size();i++)
qc_listbox->Append(qc_filestoadd[i].c_str());
qc_listbox->Delete(0);
wxBoxSizer *item4 = new wxBoxSizer( wxVERTICAL );
wxButton *item5 = new wxButton( p2, ID_QC_CONNECT, "Connect", wxDefaultPosition, wxDefaultSize, 0 );
item4->Add( item5, 0, wxALIGN_CENTRE|wxALL, 5 );
wxButton *item6 = new wxButton( p2, ID_QC_EDIT, "Edit", wxDefaultPosition, wxDefaultSize, 0 );
item4->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
wxButton *item7 = new wxButton( p2, ID_QC_REMOVE, "Remove", wxDefaultPosition, wxDefaultSize, 0 );
item4->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );
item1->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
item0->Add( item1, 0, wxALIGN_CENTRE|wxALL, 15 );
wxButton *item8 = new wxButton( p2, ID_QC_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize, 0 );
item0->Add( item8, 0, wxALIGN_CENTRE|wxALL, 5 );
p2->SetAutoLayout( TRUE );
p2->SetSizer( item0 );
item0->Fit( p2 );
item0->SetSizeHints( p2 );
}
item2->AddPage( p2, "Quick Connect" );
wxPanel *p3 = new wxPanel( item2, -1 );
// sites_of_interest_dialog( item5, FALSE );
{
wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
wxStaticBox *item2 = new wxStaticBox( p3, -1, "Sites of Interest" );
wxStaticBoxSizer *item1 = new wxStaticBoxSizer( item2, wxHORIZONTAL );
wxString *strs3 = (wxString*) NULL;
site_listbox = new wxListBox( p3, ID_SOI_LISTBOX, wxDefaultPosition, wxSize(140,160), 0, strs3, wxLB_SINGLE );
item1->Add( site_listbox, 0, wxALIGN_CENTRE|wxALL, 5 );
wxString entries[] = {
"ftp.gnu.org",
"ftp.cuj.com",
"ftp.perl.org",
"www.remstar.org"
};
info[0] = "GNU headquarters";
info[1] = "C/C++ Users Journal Archives!! Yay!!";
info[2] = "Perl Monks!";
info[3] = "wxWindows Stronghold, lots of great stuff\nleft out of the distrubution get splashtext.exe!!";
for (int i =0;i < 4;i++)
site_listbox->Append(entries[i]);
wxBoxSizer *item4 = new wxBoxSizer( wxVERTICAL );
wxButton *item5 = new wxButton( p3, ID_SOI_CONNECT, "Connect", wxDefaultPosition, wxDefaultSize, 0 );
item4->Add( item5, 0, wxALIGN_CENTRE|wxALL, 5 );
wxButton *item6 = new wxButton( p3, ID_SOI_INFO, "Info", wxDefaultPosition, wxDefaultSize, 0 );
item4->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
item1->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
item0->Add( item1, 0, wxALIGN_CENTRE|wxALL, 15 );
wxButton *item7 = new wxButton( p3, ID_SOI_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize, 0 );
item0->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );
p3->SetAutoLayout( TRUE );
p3->SetSizer( item0 );
item0->Fit( p3 );
item0->SetSizeHints( p3 );
}
item2->AddPage( p3, "Sites of Interest" );
item0->Add( item1, 0, wxALIGN_CENTRE|wxALL, 5 );
this->SetAutoLayout( TRUE );
this->SetSizer( item0 );
item0->Fit( this );
item0->SetSizeHints( this );
}
// WDR: handler implementations for ConnectionDialog
void ConnectionDialog::OnSOIInfo()
{
wxMessageDialog dialog(this, info[site_listbox->GetSelection()],"Info",wxOK);
dialog.ShowModal();
}
void ConnectionDialog::OnSOIConnect()
{
wxString site;
if ((site = site_listbox->GetStringSelection()).IsEmpty())
return;
HarborDialog harbor(this, -1, site, wxPoint(100,100));
wxBeginBusyCursor();
FTP current;
current.SetUser("anonymous");
current.SetPassword("guest@foo.com");
try
{
current.Connect(site.c_str(),21);
}
catch (FTP::InvalidHost)
{
wxString message = "The host appears to be invalid or changed,";
wxMessageDialog dialog(this, message,site ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
catch (FTP::InvalidUser)
{
wxString message = "Invalid username or password";
wxMessageDialog dialog(this, message,"Error: Invalid Host" ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
catch (FTP::InvalidPassword)
{
wxString message = "Invalid username or password";
wxMessageDialog dialog(this, message,"Error: Invalid Host" ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
harbor.SetFTP(current);
harbor.GetRemoteFiles();
harbor.SetRemoteDir("");
harbor.SetPreviousRemoteDir("");
wxEndBusyCursor();
if (!(wxDirExists(harbor.GetHome())))
{
wxMessageDialog dialog(this, "Your home directory appears to be invalid\nPlease change it in Settings->SetHome",harbor.GetHome(),wxOK);
dialog.ShowModal();
harbor.SetHome(wxGetCwd());
harbor.GetLocalFiles(wxGetCwd());
harbor.ShowModal();
}
else
{
if (!(wxSetWorkingDirectory(harbor.GetHome())))
{
wxMessageDialog dialog(this, "Couldn't Change to Home Directory\nTo you have proper permissions ?",harbor.GetHome(),wxOK| wxICON_ERROR);
dialog.ShowModal();
}
harbor.GetLocalFiles(wxGetCwd());
harbor.ShowModal();
}
}
void ConnectionDialog::OnQuickConnect( )
{
if (qc_listbox->GetStringSelection().IsEmpty())
return;
vector<string> temp = QCList[qc_listbox->GetStringSelection().c_str()];
if (temp.size() <= 0)
return;
long port;
wxString ws_port = temp[5].c_str();
ws_port.ToLong(&port);
// i do this at the begging so i can add the text stuff to the main window
HarborDialog harbor(this, -1, temp[4].c_str(), wxPoint(100,100));
wxBeginBusyCursor();
FTP current;
current.SetUser(temp[6]);
current.SetPassword(temp[7]);
try
{
current.Connect(temp[4],port);
}
catch (FTP::InvalidHost)
{
wxString message = "The host appears to be invalid, please try again";
wxMessageDialog dialog(this, message,temp[4].c_str() ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
catch (FTP::InvalidUser)
{
wxString message = "Invalid username or password";
wxMessageDialog dialog(this, message,"Error: Invalid Host" ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
catch (FTP::InvalidPassword)
{
wxString message = "Invalid username or password";
wxMessageDialog dialog(this, message,"Error: Invalid Host" ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
harbor.SetFTP(current);
harbor.GetRemoteFiles();
harbor.SetRemoteDir("");
harbor.SetPreviousRemoteDir("");
wxEndBusyCursor();
if (!(wxDirExists(harbor.GetHome())))
{
wxMessageDialog dialog(this, "Your home directory appears to be invalid\nPlease change it in Settings->SetHome",harbor.GetHome(),wxOK);
dialog.ShowModal();
harbor.SetHome(wxGetCwd());
harbor.GetLocalFiles(wxGetCwd());
harbor.ShowModal();
}
else
{
if (!(wxSetWorkingDirectory(harbor.GetHome())))
{
wxMessageDialog dialog(this, "Couldn't Change to Home Directory\nTo you have proper permissions ?",harbor.GetHome(),wxOK| wxICON_ERROR);
dialog.ShowModal();
}
harbor.GetLocalFiles(wxGetCwd());
harbor.ShowModal();
}
}
void ConnectionDialog::OnQuickEdit()
{
wxString sel;
if ((sel = qc_listbox->GetStringSelection()).IsEmpty())
return;
QuickConnectEditDialog edit(this, -1, "Edit");
edit.SetInfo(QCList[sel.c_str()], sel.c_str());
edit.ShowModal();
EndModal(1);
ConnectionDialog CD(this, -1, "Connect");
CD.ShowModal();
}
void ConnectionDialog::OnQuickRemove()
{
wxString sel;
if ((sel = qc_listbox->GetStringSelection()).IsEmpty())
return;
wxMessageDialog dialog(this, "Are you sure you want to delete" + sel + " ?","Warning: Delete",wxYES_NO | wxICON_INFORMATION);
if (dialog.ShowModal() == wxID_YES)
{
ifstream in("C:\\Ftpro\\.qc");
vector<wxString> keep;
char line[256];
wxString l;
while (1)
{
in.getline(line, 256);
if (line[0] == '\n' || line[0] == '\0')
break;
l = line;
if (l.BeforeFirst('~').IsSameAs(sel))
continue;
keep.push_back(l);
}
in.close();
ofstream out("C:\\Ftpro\\.qc");
for (int i = 0;i < keep.size();i++)
{
out << keep[i].c_str() << "\n";
}
out.close();
qc_listbox->Delete(qc_listbox->GetSelection());
}
}
void ConnectionDialog::OnCancel( )
{
Hide();
}
void ConnectionDialog::OnOk( wxCommandEvent &event )
{
wxBeginBusyCursor();
wxString s_port = port_cb->GetValue();
long port;
s_port.ToLong(&port);
// i do this at the begging so i can add the text stuff to the main window
HarborDialog harbor(this, -1, host_tc->GetValue(), wxPoint(100,100));
FTP current;
if (anonymous_cx->GetValue())
{
current.SetUser("anonymous");
current.SetPassword("guest@foo.com");
try
{
current.Connect(host_tc->GetValue().c_str(),port);
}
catch (FTP::InvalidHost)
{
wxString message = host_tc->GetValue() + " appears to be invalid, please try again";
wxMessageDialog dialog(this, message,"Error: Invalid Host" ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
catch (FTP::InvalidUser)
{
wxString message = "Invalid username or password";
wxMessageDialog dialog(this, message,"Error: Invalid Host" ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
catch (FTP::InvalidPassword)
{
wxString message = "Invalid username or password";
wxMessageDialog dialog(this, message,"Error: Invalid Host" ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
}
else
{
if ((user_tc->GetValue().IsEmpty()) || (password_tc->GetValue().IsEmpty()) || (host_tc->GetValue().IsEmpty()))
{
wxMessageDialog dialog(this, "Required data is not filled out","Error missing data",wxOK);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
current.SetUser(user_tc->GetValue().c_str());
current.SetPassword(password_tc->GetValue().c_str());
try
{
current.Connect(host_tc->GetValue().c_str(), port);
}
catch (FTP::InvalidHost)
{
wxString message = host_tc->GetValue() + " appears to be invalid, please try again";
wxMessageDialog dialog(this, message,"Error: Invalid Host" ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
catch (FTP::InvalidUser)
{
wxString message = user_tc->GetValue() + " appears to be invalid, please try again";
wxMessageDialog dialog(this, message,"Error: Invalid User or Password" ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
catch (FTP::InvalidPassword)
{
wxMessageDialog dialog(this, "Invalid Password and/or Username", "Error: Invalid User or Password" ,wxOK | wxICON_ERROR);
dialog.ShowModal();
wxEndBusyCursor();
return;
}
}
// initialize harbor variables
harbor.SetFTP(current);
harbor.GetRemoteFiles();
harbor.SetRemoteDir("");
harbor.SetPreviousRemoteDir("");
wxEndBusyCursor();
// if add to QC, add to file
if (qc_cx->GetValue())
{
if (qc_tc->GetValue().IsEmpty())
{
wxMessageDialog dialog(this, "You must select a name for the quick connect","Error: No Name",wxOK);
dialog.ShowModal();
return;
}
// add to QC START
wxString qc_add;
if (anonymous_cx->GetValue())
qc_add = qc_tc->GetValue() + "~~" + host_tc->GetValue()+ "~~" + port_cb->GetValue() + "~~anonymous~~guest@foo.com~~\n";
else
qc_add = qc_tc->GetValue() + "~~" + host_tc->GetValue()+ "~~" + port_cb->GetValue() + "~~" + user_tc->GetValue() + "~~" + password_tc->GetValue() + "~~\n";
ofstream out("C:\\FTPro\\.qc", ios::app);
out.write(qc_add.c_str(), qc_add.Length());
out.close();
// add to QC END
}
if (!(wxDirExists(harbor.GetHome())))
{
wxMessageDialog dialog(this, "Your home directory appears to be invalid\nPlease change it in Settings->SetHome",harbor.GetHome(),wxOK);
dialog.ShowModal();
harbor.SetHome(wxGetCwd());
harbor.GetLocalFiles(wxGetCwd());
harbor.ShowModal();
}
else
{
if (!(wxSetWorkingDirectory(harbor.GetHome())))
{
wxMessageDialog dialog(this, "Couldn't Change to Home Directory\nTo you have proper permissions ?",harbor.GetHome(),wxOK| wxICON_ERROR);
dialog.ShowModal();
}
harbor.GetLocalFiles(wxGetCwd());
harbor.ShowModal();
}
}
void ConnectionDialog::OnAnonymous( wxCommandEvent &event )
{
if (anonymous_cx->GetValue())
{
user_tc->Enable(FALSE);
password_tc->Enable(FALSE);
}
else
{
user_tc->Enable(TRUE);
password_tc->Enable(TRUE);
}
if (qc_cx->GetValue())
qc_tc->Enable(TRUE);
else
qc_tc->Enable(FALSE);
}
BEGIN_EVENT_TABLE(QuickConnectEditDialog,wxDialog)
EVT_BUTTON(ID_QCEDIT_OK, QuickConnectEditDialog::OnOk)
EVT_BUTTON(ID_QCEDIT_CANCEL, QuickConnectEditDialog::OnCancel)
END_EVENT_TABLE()
QuickConnectEditDialog::QuickConnectEditDialog( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &position, const wxSize& size, long style ) :
wxDialog( parent, id, title, position, size, style )
{
wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
wxBoxSizer *item1 = new wxBoxSizer( wxVERTICAL );
wxStaticBox *item3 = new wxStaticBox( this, -1, "Edit Quick Connect" );
wxStaticBoxSizer *item2 = new wxStaticBoxSizer( item3, wxVERTICAL );
wxStaticText *item4 = new wxStaticText( this, ID_QCE_NAME, "Name", wxDefaultPosition, wxDefaultSize, 0 );
item4->SetFont( wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ) );
#if defined(__WXMSW__) && !(wxCHECK_VERSION(2,3,0))
item4->SetSize( item4->GetBestSize() );
#endif
item2->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
name_tc = new wxTextCtrl( this, ID_TEXTCTRL, "", wxDefaultPosition, wxSize(150,-1), wxTE_READONLY);
item2->Add( name_tc, 0, wxALIGN_CENTRE|wxALL, 5 );
wxBoxSizer *item6 = new wxBoxSizer( wxHORIZONTAL );
wxStaticText *item7 = new wxStaticText( this, ID_TEXT, "Host", wxDefaultPosition, wxDefaultSize, 0 );
item6->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );
host_tc = new wxTextCtrl( this, ID_QCEHOST_TEXT, "", wxDefaultPosition, wxSize(160,-1), 0 );
host_tc->SetToolTip( "The host address" );
item6->Add( host_tc, 0, wxALIGN_CENTRE|wxALL, 5 );
wxStaticText *item9 = new wxStaticText( this, ID_TEXT, " User", wxDefaultPosition, wxDefaultSize, 0 );
item6->Add( item9, 0, wxALIGN_CENTRE|wxALL, 5 );
user_tc = new wxTextCtrl( this, ID_QCEHOST_USER, "", wxDefaultPosition, wxSize(160,-1), 0 );
user_tc->SetToolTip( "Your username" );
item6->Add( user_tc, 0, wxALIGN_CENTRE|wxALL, 5 );
item2->Add( item6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
wxBoxSizer *item11 = new wxBoxSizer( wxHORIZONTAL );
wxStaticText *item12 = new wxStaticText( this, ID_TEXT, "Port ", wxDefaultPosition, wxDefaultSize, 0 );
item11->Add( item12, 0, wxALIGN_CENTRE|wxALL, 5 );
wxString strs13[] =
{
"21"
};
port_cb = new wxComboBox( this, ID_QCEPORT_COMBO, "", wxDefaultPosition, wxSize(160,-1), 1, strs13, wxCB_DROPDOWN );
port_cb->SetToolTip( "The port to connect to, usually 21" );
item11->Add( port_cb, 0, wxALIGN_CENTRE|wxALL, 5 );
wxStaticText *item14 = new wxStaticText( this, ID_TEXT, "Password", wxDefaultPosition, wxDefaultSize, 0 );
item11->Add( item14, 0, wxALIGN_CENTRE|wxALL, 5 );
password_tc = new wxTextCtrl( this, ID_QCEHOST_PASSWORD, "", wxDefaultPosition, wxSize(160,-1), 0 );
password_tc->SetToolTip( "Your password" );
item11->Add( password_tc, 0, wxALIGN_CENTRE|wxALL, 5 );
item2->Add( item11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
item1->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );
wxBoxSizer *item16 = new wxBoxSizer( wxHORIZONTAL );
wxButton *item17 = new wxButton( this, ID_QCEDIT_OK, "Save", wxDefaultPosition, wxDefaultSize, 0 );
item17->SetToolTip( "Save" );
item16->Add( item17, 0, wxALIGN_CENTRE|wxALL, 5 );
item16->Add( 80, 20, 0, wxALIGN_CENTRE|wxALL, 5 );
wxButton *item18 = new wxButton( this, ID_QCEDIT_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize, 0 );
item18->SetToolTip( "Cancel" );
item16->Add( item18, 0, wxALIGN_CENTRE|wxALL, 5 );
item1->Add( item16, 0, wxALIGN_CENTRE|wxALL, 5 );
item0->Add( item1, 0, wxALL, 5 );
this->SetAutoLayout( TRUE );
this->SetSizer( item0 );
item0->Fit( this );
item0->SetSizeHints( this );
}
void QuickConnectEditDialog::OnOk()
{
ifstream in("C:\\Ftpro\\.qc");
vector<wxString> keep;
char line[256];
wxString l;
while (1)
{
in.getline(line, 256);
if (line[0] == '\n' || line[0] == '\0')
break;
l = line;
if (l.BeforeFirst('~').IsSameAs(name_tc->GetValue()))
{
wxString temp = name_tc->GetValue() + "~~" + host_tc->GetValue() + "~~" + port_cb->GetValue() + "~~" + user_tc->GetValue() + "~~" + password_tc->GetValue() + "~~";
keep.push_back(temp);
continue;
}
keep.push_back(l);
}
in.close();
ofstream out("C:\\Ftpro\\.qc");
for (int i = 0;i < keep.size();i++)
{
out << keep[i].c_str() << "\n";
}
out.close();
EndModal(1);
}
void QuickConnectEditDialog::SetInfo(vector<string> info, string name)
{
name_tc->AppendText(name.c_str());
host_tc->AppendText(info[4].c_str());
port_cb->SetValue(info[5].c_str());
user_tc->AppendText(info[6].c_str());
password_tc->AppendText(info[7].c_str());
}