decompressdlg.cpp

00001 
00002 // Name:        decompressdlg.cpp
00003 // Purpose:     wxPackageDecompressDlg
00004 // Author:      Francesco Montorsi
00005 // Modified by: 
00006 // Created:     17/07/2006 23:38:05
00007 // RCS-ID:      $Id: decompressdlg.cpp,v 1.4 2007/01/27 23:32:08 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 
00025 #include "guipm/decompressdlg.h"
00026 #include <wx/filepicker.h>
00027 
00028 #include "wxp/package.h"
00029 
00030 
00031 // ----------------------------------------------------------------------------
00032 // wxPackageDecompressDlg
00033 // ----------------------------------------------------------------------------
00034 
00035 IMPLEMENT_DYNAMIC_CLASS( wxPackageDecompressDlg, wxDialog )
00036 BEGIN_EVENT_TABLE( wxPackageDecompressDlg, wxDialog )
00037     EVT_DIRPICKER_CHANGED(ID_DECOMPRESS_DESTINATION, 
00038                           wxPackageDecompressDlg::OnDestinationChange)
00039 
00040     EVT_BUTTON( wxID_OK, wxPackageDecompressDlg::OnOK )
00041 END_EVENT_TABLE()
00042 
00043 
00044 wxPackageDecompressDlg::wxPackageDecompressDlg( )
00045 {
00046 }
00047 
00048 wxPackageDecompressDlg::wxPackageDecompressDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00049 {
00050     Create(parent, id, caption, pos, size, style);
00051 }
00052 
00053 bool wxPackageDecompressDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00054 {
00056     m_pCompressedFileName = NULL;
00057     m_pRequiredSpace = NULL;
00058     m_pFreeSpace = NULL;
00059     m_pProgress = NULL;
00061 
00062     SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
00063     wxDialog::Create( parent, id, caption, pos, size, style );
00064 
00065     CreateControls();
00066     if (GetSizer())
00067     {
00068         wxSize sz = GetSizer()->GetMinSize();
00069         sz.Scale(2, 1);
00070         GetSizer()->SetMinSize(sz);
00071         GetSizer()->SetSizeHints(this);
00072     }
00073     CentreOnScreen();
00074 
00075     return true;
00076 }
00077 
00078 void wxPackageDecompressDlg::CreateControls()
00079 {
00080     m_pDestination = new wxDirPickerCtrl(this, ID_DECOMPRESS_DESTINATION);
00081     
00083     wxPackageDecompressDlg* itemDialog1 = this;
00084 
00085     wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
00086     itemDialog1->SetSizer(itemBoxSizer2);
00087 
00088     wxStaticText* itemStaticText3 = new wxStaticText( itemDialog1, wxID_STATIC, _("The files extracted from:"), wxDefaultPosition, wxDefaultSize, 0 );
00089     itemBoxSizer2->Add(itemStaticText3, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
00090 
00091     m_pCompressedFileName = new wxTextCtrl( itemDialog1, wxID_STATIC, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_CENTRE|wxNO_BORDER );
00092     m_pCompressedFileName->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, _T("")));
00093     itemBoxSizer2->Add(m_pCompressedFileName, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
00094 
00095     wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _("will be placed in:"), wxDefaultPosition, wxDefaultSize, 0 );
00096     itemBoxSizer2->Add(itemStaticText5, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
00097 
00098     wxDirPickerCtrl* itemWindow6 = (wxDirPickerCtrl*) FindWindow(ID_DECOMPRESS_DESTINATION);
00099     wxASSERT( itemWindow6 != NULL );
00100     itemBoxSizer2->Add(itemWindow6, 1, wxGROW|wxLEFT|wxRIGHT, 10);
00101 
00102     wxFlexGridSizer* itemFlexGridSizer7 = new wxFlexGridSizer(2, 2, 0, 0);
00103     itemFlexGridSizer7->AddGrowableCol(1);
00104     itemBoxSizer2->Add(itemFlexGridSizer7, 0, wxGROW|wxALL, 5);
00105 
00106     wxStaticText* itemStaticText8 = new wxStaticText( itemDialog1, wxID_STATIC, _("Approximate required space:"), wxDefaultPosition, wxDefaultSize, 0 );
00107     itemFlexGridSizer7->Add(itemStaticText8, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00108 
00109     m_pRequiredSpace = new wxStaticText( itemDialog1, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE|wxST_NO_AUTORESIZE );
00110     itemFlexGridSizer7->Add(m_pRequiredSpace, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00111 
00112     wxStaticText* itemStaticText10 = new wxStaticText( itemDialog1, wxID_STATIC, _("Free space in selected destination:"), wxDefaultPosition, wxDefaultSize, 0 );
00113     itemFlexGridSizer7->Add(itemStaticText10, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00114 
00115     m_pFreeSpace = new wxStaticText( itemDialog1, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE|wxST_NO_AUTORESIZE );
00116     itemFlexGridSizer7->Add(m_pFreeSpace, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00117 
00118     wxStaticLine* itemStaticLine12 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
00119     itemBoxSizer2->Add(itemStaticLine12, 0, wxGROW|wxALL, 10);
00120 
00121     wxStaticText* itemStaticText13 = new wxStaticText( itemDialog1, wxID_STATIC, _("Progress:"), wxDefaultPosition, wxDefaultSize, 0 );
00122     itemBoxSizer2->Add(itemStaticText13, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
00123 
00124     m_pProgress = new wxGauge( itemDialog1, ID_DECOMPRESS_PROGRESS, 100, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL );
00125     m_pProgress->SetValue(0);
00126     itemBoxSizer2->Add(m_pProgress, 0, wxGROW|wxALL, 5);
00127 
00128     itemBoxSizer2->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
00129 
00130     wxStdDialogButtonSizer* itemStdDialogButtonSizer16 = new wxStdDialogButtonSizer;
00131 
00132     itemBoxSizer2->Add(itemStdDialogButtonSizer16, 0, wxALIGN_RIGHT|wxALL, 5);
00133     wxButton* itemButton17 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
00134     itemStdDialogButtonSizer16->AddButton(itemButton17);
00135 
00136     wxButton* itemButton18 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
00137     itemStdDialogButtonSizer16->AddButton(itemButton18);
00138 
00139     itemStdDialogButtonSizer16->Realize();
00140 
00142 
00143     m_pCompressedFileName->SetBackgroundColour(
00144         wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
00145 
00146     // set gauge range
00147     m_pProgress->SetRange(1000);    // see wxProgressHandler description
00148 }
00149 
00150 bool wxPackageDecompressDlg::ShowToolTips()
00151 {
00152     return true;
00153 }
00154 
00155 void wxPackageDecompressDlg::SetPackage(const wxPackage &pkg)
00156 { 
00157     m_pkg = pkg;
00158     SetDestination(pkg.GetDecompressionPath());
00159 
00160     // update labels
00161     m_pRequiredSpace->SetLabel(
00162         wxFileName::GetHumanReadableSize(pkg.GetDecompressedSize()));
00163     m_pCompressedFileName->SetValue(pkg.GetDownloadPath());
00164     UpdateFreeSpace(); 
00165 }
00166 
00167 void wxPackageDecompressDlg::UpdateFreeSpace()
00168 {
00169     wxLongLong free;
00170     if (!wxGetDiskSpace(m_pDestination->GetPath(), NULL, &free))
00171     {
00172         m_pFreeSpace->SetLabel(wxT("Not available"));
00173         return;
00174     }
00175 
00176     wxULongLong sz(free.GetHi(), free.GetLo());
00177     m_pFreeSpace->SetLabel(wxFileName::GetHumanReadableSize(sz));
00178 }
00179 
00180 
00181 
00182 // ----------------------------------------------------------------------------
00183 // wxPackageDecompressDlg - event handlers
00184 // ----------------------------------------------------------------------------
00185 
00186 void wxPackageDecompressDlg::OnDestinationChange(wxFileDirPickerEvent &)
00187 {
00188     UpdateFreeSpace();
00189 }
00190 
00191 void wxPackageDecompressDlg::OnOK(wxCommandEvent &WXUNUSED(ev))
00192 {
00193     class myProgressHandler : public wxProgressHandler
00194     {
00195     public:
00196         myProgressHandler(wxGauge *p) { m_gauge=p; }
00197 
00198         bool OnUpdate(unsigned long progress, const wxString &WXUNUSED(text))
00199         { 
00200             m_gauge->SetValue(progress); 
00201             wxYieldIfNeeded();
00202             return true; 
00203         }
00204 
00205         wxGauge *m_gauge;
00206     };
00207 
00208     myProgressHandler handler(m_pProgress);
00209     if (!m_pkg.Decompress(m_pDestination->GetPath(), &handler))
00210         EndModal(wxID_CANCEL);
00211     EndModal(wxID_OK);
00212 }
00213 

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