uploaddlg.cpp

00001 
00002 // Name:        uploaddlg.cpp
00003 // Purpose:     wxPackageUploadDialog
00004 // Author:      Francesco Montorsi
00005 // Modified by:
00006 // Created:     01/01/2007 16:58:55
00007 // RCS-ID:      $Id: uploaddlg.cpp,v 1.2 2007/01/01 21:36:45 frm Exp $
00008 // Copyright:   (c) 2006 Francesco Montorsi
00009 // Licence:     wxWidgets license
00011 
00012 
00013 // For compilers that support precompilation, includes "wx/wx.h".
00014 #include "wx/wxprec.h"
00015 
00016 #ifdef __BORLANDC__
00017 #pragma hdrstop
00018 #endif
00019 
00020 #ifndef WX_PRECOMP
00021 #include "wx/wx.h"
00022 #endif
00023 
00024 #include <wx/filename.h>
00025 #include <wx/uri.h>
00026 
00027 #include "guipkg/uploaddlg.h"
00028 
00029 
00030 
00031 // ----------------------------------------------------------------------------
00032 // wxPackageUploadDlg
00033 // ----------------------------------------------------------------------------
00034 
00035 IMPLEMENT_DYNAMIC_CLASS( wxPackageUploadDlg, wxDialog )
00036 BEGIN_EVENT_TABLE( wxPackageUploadDlg, wxDialog )
00037     EVT_CHECKBOX(wxID_ANY, wxPackageUploadDlg::OnAnonymous)
00038 END_EVENT_TABLE()
00039 
00040 wxPackageUploadDlg::wxPackageUploadDlg( )
00041 {
00042 }
00043 
00044 wxPackageUploadDlg::wxPackageUploadDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00045 {
00046     Create(parent, id, caption, pos, size, style);
00047 }
00048 
00049 bool wxPackageUploadDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00050 {
00052     m_pFileSizeLabel = NULL;
00053     m_pFile = NULL;
00054     m_pUser = NULL;
00055     m_pPassword = NULL;
00056     m_pAnonymous = NULL;
00057     m_pDir = NULL;
00059 
00060     SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
00061     wxDialog::Create( parent, id, caption, pos, size, style );
00062 
00063     CreateControls();
00064     if (GetSizer())
00065     {
00066         GetSizer()->SetSizeHints(this);
00067 
00068         SetMinSize(GetMinSize().Scale(2.0, 1));
00069     }
00070     CentreOnScreen();
00071 
00072     return true;
00073 }
00074 
00075 void wxPackageUploadDlg::CreateControls()
00076 {    
00078     wxPackageUploadDlg* itemDialog1 = this;
00079 
00080     wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
00081     itemDialog1->SetSizer(itemBoxSizer2);
00082 
00083     m_pFileSizeLabel = new wxStaticText( itemDialog1, wxID_STATIC, _("File to upload (SIZE SIZE):"), wxDefaultPosition, wxDefaultSize, 0 );
00084     itemBoxSizer2->Add(m_pFileSizeLabel, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
00085 
00086     m_pFile = new wxTextCtrl( itemDialog1, ID_UPLOAD_FILENAME, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_READONLY|wxTE_CENTRE|wxSTATIC_BORDER );
00087     m_pFile->SetBackgroundColour(wxColour(211, 211, 211));
00088     itemBoxSizer2->Add(m_pFile, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM|wxADJUST_MINSIZE, 5);
00089 
00090     wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _("Please enter the following info for a correct upload:"), wxDefaultPosition, wxDefaultSize, 0 );
00091     itemBoxSizer2->Add(itemStaticText5, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
00092 
00093     wxStaticBox* itemStaticBoxSizer6Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Authentication"));
00094     wxStaticBoxSizer* itemStaticBoxSizer6 = new wxStaticBoxSizer(itemStaticBoxSizer6Static, wxVERTICAL);
00095     itemBoxSizer2->Add(itemStaticBoxSizer6, 0, wxGROW|wxALL, 5);
00096 
00097     wxFlexGridSizer* itemFlexGridSizer7 = new wxFlexGridSizer(2, 2, 0, 0);
00098     itemFlexGridSizer7->AddGrowableCol(1);
00099     itemStaticBoxSizer6->Add(itemFlexGridSizer7, 1, wxGROW|wxLEFT|wxRIGHT, 5);
00100 
00101     wxStaticText* itemStaticText8 = new wxStaticText( itemDialog1, wxID_STATIC, _("User:"), wxDefaultPosition, wxDefaultSize, 0 );
00102     itemFlexGridSizer7->Add(itemStaticText8, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00103 
00104     m_pUser = new wxTextCtrl( itemDialog1, ID_UPLOAD_USER, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
00105     itemFlexGridSizer7->Add(m_pUser, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00106 
00107     wxStaticText* itemStaticText10 = new wxStaticText( itemDialog1, wxID_STATIC, _("Password:"), wxDefaultPosition, wxDefaultSize, 0 );
00108     itemFlexGridSizer7->Add(itemStaticText10, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00109 
00110     m_pPassword = new wxTextCtrl( itemDialog1, ID_UPLOAD_PASSWORD, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
00111     itemFlexGridSizer7->Add(m_pPassword, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00112 
00113     m_pAnonymous = new wxCheckBox( itemDialog1, ID_UPLOAD_ANONYMOUS, _("Anonymous"), wxDefaultPosition, wxDefaultSize, 0 );
00114     m_pAnonymous->SetValue(false);
00115     itemStaticBoxSizer6->Add(m_pAnonymous, 0, wxALIGN_RIGHT|wxLEFT|wxRIGHT|wxBOTTOM, 5);
00116 
00117     wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
00118     itemBoxSizer2->Add(itemBoxSizer13, 0, wxGROW|wxALL, 5);
00119 
00120     wxStaticText* itemStaticText14 = new wxStaticText( itemDialog1, wxID_STATIC, _("Server and \ndirectory:"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
00121     itemBoxSizer13->Add(itemStaticText14, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00122 
00123     m_pDir = new wxTextCtrl( itemDialog1, ID_UPLOAD_DIRECTORY, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
00124     m_pDir->SetHelpText(_("This is an URL like ftp://upload.sourceforge.net/incoming"));
00125     if (ShowToolTips())
00126         m_pDir->SetToolTip(_("This is an URL like ftp://upload.sourceforge.net/incoming"));
00127     itemBoxSizer13->Add(m_pDir, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00128 
00129     wxStdDialogButtonSizer* itemStdDialogButtonSizer16 = new wxStdDialogButtonSizer;
00130 
00131     itemBoxSizer2->Add(itemStdDialogButtonSizer16, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
00132     wxButton* itemButton17 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
00133     itemStdDialogButtonSizer16->AddButton(itemButton17);
00134 
00135     wxButton* itemButton18 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
00136     itemStdDialogButtonSizer16->AddButton(itemButton18);
00137 
00138     itemStdDialogButtonSizer16->Realize();
00139 
00141 }
00142 
00143 bool wxPackageUploadDlg::ShowToolTips()
00144 {
00145     return true;
00146 }
00147 
00148 void wxPackageUploadDlg::SetFileToUpload(const wxString &packagefile)
00149 {
00150     wxULongLong sz = wxFileName::GetSize(packagefile);
00151     m_pFileSizeLabel->SetLabel(
00152         wxT("The file to upload (") + wxFileName::GetHumanReadableSize(sz) + wxT(") is:"));
00153     m_pFile->SetLabel(packagefile);
00154 }
00155 
00156 wxString wxPackageUploadDlg::GetPath() const
00157 {
00158     wxURI uri(m_pDir->GetValue());
00159     return uri.GetPath();
00160 }
00161 
00162 wxString wxPackageUploadDlg::GetServer() const
00163 {
00164     wxURI uri(m_pDir->GetValue());
00165     return uri.GetServer();
00166 }
00167 
00168 void wxPackageUploadDlg::SetDefaults(const wxString &defaults)
00169 {
00170     wxURI uri(defaults);
00171 
00172     if (uri.GetScheme() != wxT("ftp"))
00173         return;
00174 
00175     m_pUser->SetValue(uri.GetUser());
00176     m_pPassword->SetValue(uri.GetPassword());
00177     m_pDir->SetValue(uri.GetScheme() + wxT("://") + uri.GetServer() + uri.GetPath());
00178 
00179     bool isAnonymous = uri.GetUser().IsEmpty();
00180     m_pAnonymous->SetValue(isAnonymous);
00181 
00182     wxCommandEvent fake;
00183     fake.SetInt(isAnonymous);
00184     OnAnonymous(fake);
00185 }
00186 
00187 
00188 // ----------------------------------------------------------------------------
00189 // wxPackageUploadDlg - event handlers
00190 // ----------------------------------------------------------------------------
00191 
00192 void wxPackageUploadDlg::OnAnonymous(wxCommandEvent &event)
00193 {
00194     m_pUser->Enable(!event.IsChecked());
00195     m_pPassword->Enable(!event.IsChecked());
00196 }
00197 
00198 
00199 

Generated on Thu Feb 1 22:14:31 2007 for wxWidgets Package Manager by  doxygen 1.5.1-p1