dependencydlg.cpp

00001 
00002 // Name:        dependencydlg.cpp
00003 // Purpose:     wxPackageDependencyDlg
00004 // Author:      Francesco Montorsi
00005 // Modified by:
00006 // Created:     29/07/2006 09:48:04
00007 // RCS-ID:      $Id: dependencydlg.cpp,v 1.2 2007/01/01 20:06:21 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/statline.h>
00025 
00026 #include "guipm/dependencydlg.h"
00027 #include "guipm/smartmsgdlg.h"
00028 #include "guipm/taskpanel.h"
00029 
00030 #include "wxp/packagedep.h"
00031 #include "wxp/package.h"
00032 
00033 
00034 
00035 // ----------------------------------------------------------------------------
00036 // wxPackageDependencyDlg
00037 // ----------------------------------------------------------------------------
00038 
00039 IMPLEMENT_DYNAMIC_CLASS( wxPackageDependencyDlg, wxDialog )
00040 BEGIN_EVENT_TABLE( wxPackageDependencyDlg, wxDialog )
00041     EVT_BUTTON(wxID_ANY, wxPackageDependencyDlg::OnButton)
00042 END_EVENT_TABLE()
00043 
00044 wxPackageDependencyDlg::wxPackageDependencyDlg( )
00045 {
00046 }
00047 
00048 bool wxPackageDependencyDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption,
00049                                      const wxPoint& pos, const wxSize& size, long style )
00050 {
00052     m_pMainMsg = NULL;
00053     m_pRequiredCheckList = NULL;
00054     m_pSuggestedCheckList = NULL;
00055     m_pQuestionMsg = NULL;
00057 
00059     SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
00060     wxDialog::Create( parent, id, caption, pos, size, style );
00061 
00062     CreateControls();
00063     if (GetSizer())
00064     {
00065         GetSizer()->SetSizeHints(this);
00066     }
00067     CentreOnScreen();
00069     return true;
00070 }
00071 
00072 void wxPackageDependencyDlg::CreateControls()
00073 {
00074     wxASSERT_MSG(!IsEmpty(), wxT("Cannot build an empty dialog!"));
00075 
00077     wxPackageDependencyDlg* itemDialog1 = this;
00078 
00079     wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
00080     itemDialog1->SetSizer(itemBoxSizer2);
00081 
00082 
00083     if (m_required.GetCount() > 0)
00084     {
00085         wxString msg;
00086 
00087         if (m_bSelectedPackagesAreDownloaded)
00088             msg = _("In order to be able to successfully build the selected package(s),\nyou should download and install also the following REQUIRED packages:");
00089         else
00090             msg = _("In order to be able to successfully build the selected package(s), after the download,\nyou should download and install also the following REQUIRED packages:");
00091 
00092         m_pMainMsg = new wxStaticText( itemDialog1, wxID_STATIC,
00093             msg, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
00094         itemBoxSizer2->Add(m_pMainMsg, 0, wxGROW|wxALL|wxADJUST_MINSIZE, 5);
00095 
00096         wxString* m_pRequiredCheckListStrings = NULL;
00097         m_pRequiredCheckList = new wxCheckListBox( itemDialog1, ID_DEPENDENCY_REQUIRED_LIST, wxDefaultPosition, wxDefaultSize, 0, m_pRequiredCheckListStrings, wxLB_SINGLE );
00098         itemBoxSizer2->Add(m_pRequiredCheckList, 0, wxGROW|wxALL, 5);
00099     }
00100 
00101     if (m_suggested.GetCount() > 0)
00102     {
00103         wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC,
00104             _("The selected package(s) indicate, as SUGGESTED dependencies, the following package(s), too:"), wxDefaultPosition, wxDefaultSize, 0 );
00105         itemBoxSizer2->Add(itemStaticText5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxADJUST_MINSIZE, 5);
00106 
00107         wxString* m_pSuggestedCheckListStrings = NULL;
00108         m_pSuggestedCheckList = new wxCheckListBox( itemDialog1, ID_DEPENDENCY_SUGGESTED_LIST, wxDefaultPosition, wxDefaultSize, 0, m_pSuggestedCheckListStrings, wxLB_SINGLE );
00109         itemBoxSizer2->Add(m_pSuggestedCheckList, 0, wxGROW|wxALL, 5);
00110     }
00111 
00112     if (m_notfound.GetCount() > 0)
00113     {
00114         itemBoxSizer2->Add(new wxStaticLine(this, wxID_ANY), 0, wxGROW|wxALL, 5);
00115 
00116         wxStaticText* itemStaticText7 = new wxStaticText( itemDialog1, wxID_STATIC,
00117             _("WARNING: the selected package(s) indicate the following REQUIRED or SUGGESTED dependencies \nwhich could not be found in the repository:"), wxDefaultPosition, wxDefaultSize, 0 );
00118         itemBoxSizer2->Add(itemStaticText7, 0, wxGROW|wxALL|wxADJUST_MINSIZE, 5);
00119 
00120         wxString* itemListBox8Strings = NULL;
00121         m_pNotFoundList = new wxListBox( itemDialog1, ID_DEPENDENCY_NOTINREPO, wxDefaultPosition, wxDefaultSize, 0, itemListBox8Strings, wxLB_SINGLE );
00122         itemBoxSizer2->Add(m_pNotFoundList, 0, wxGROW|wxALL, 5);
00123     }
00124 
00125     m_pQuestionMsg = new wxStaticText( itemDialog1, wxID_STATIC, _("Proceed with the download of the checked package(s) ?"), wxDefaultPosition, wxDefaultSize, 0 );
00126     itemBoxSizer2->Add(m_pQuestionMsg, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
00127 
00128     itemBoxSizer2->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
00129 
00130     wxStdDialogButtonSizer* itemStdDialogButtonSizer11 = new wxStdDialogButtonSizer;
00131 
00132     itemBoxSizer2->Add(itemStdDialogButtonSizer11, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
00133     wxButton* itemButton12 = new wxButton( itemDialog1, wxID_YES, _("&Yes"), wxDefaultPosition, wxDefaultSize, 0 );
00134     itemStdDialogButtonSizer11->AddButton(itemButton12);
00135 
00136     wxButton* itemButton13 = new wxButton( itemDialog1, wxID_NO, _("&No"), wxDefaultPosition, wxDefaultSize, 0 );
00137     itemStdDialogButtonSizer11->AddButton(itemButton13);
00138 
00139     itemStdDialogButtonSizer11->Realize();
00140 
00142 
00143     // init listboxes
00144     FillListbox(m_pRequiredCheckList, m_required);
00145     FillListbox(m_pSuggestedCheckList, m_suggested);
00146     FillListbox(m_pNotFoundList, m_notfound, true);
00147 }
00148 
00149 void wxPackageDependencyDlg::FillListbox(wxListBox *box,
00150                                          const wxPackageDependencyArray &arr,
00151                                          bool useversionrange)
00152 {
00153     for (size_t i=0; i<arr.GetCount(); i++)
00154     {
00155         wxString ver;
00156 
00157         if (useversionrange)
00158             ver = arr[i].GetVersion().GetAsString();
00159         else
00160         {
00161             int n = arr[i].GetBestMatch(*m_pRemote);
00162             wxASSERT(n != wxNOT_FOUND);
00163             ver = m_pRemote->Item(n).GetVersion().GetAsString();
00164         }
00165 
00166         int last =
00167             box->Append(wxString::Format(wxT("%s %s (required by %s)"),
00168                                          arr[i].GetName().c_str(),
00169                                          ver.c_str(),
00170                                          arr[i].GetOwnersIdStr().c_str()));
00171 
00172         wxCheckListBox *cb = wxDynamicCast(box, wxCheckListBox);
00173         if (cb)
00174             cb->Check(last, true);
00175     }
00176 }
00177 
00178 bool wxPackageDependencyDlg::ShowToolTips()
00179 {
00180     return true;
00181 }
00182 
00183 bool wxPackageDependencyDlg::SetPackageArray(const wxPackageArray &arr,
00184                                              const wxPackageArray &installed,
00185                                              const wxPackageArray &remote)
00186 {
00187     // these info are required later by other
00188     // functions of wxPackageDependencyDlg:
00189     m_pRemote = &remote;
00190 
00191     m_bSelectedPackagesAreDownloaded = true;
00192     for (size_t i=0; i < arr.GetCount(); i++)
00193     {
00194         if (arr[i].GetStatus() == wxPS_REMOTE)
00195         {
00196             m_bSelectedPackagesAreDownloaded = false;
00197             break;
00198         }
00199     }
00200 
00201     m_required.Clear();
00202     m_suggested.Clear();
00203     m_notfound.Clear();
00204 
00205     // build the complete list of packages that we can use
00206     // for dependency resolution:
00207     wxPackageArray total(installed);
00208     WX_APPEND_ARRAY(total, remote);
00209 
00210     // FIXME: it would be better to use a AppendWithoutDuplicates()
00211     //        instead of WX_APPEND_ARRAY
00212     total.RemoveDuplicates();
00213 
00214     // get info about dependencies of selected packages
00215     wxPackageDependencyArray dep;
00216     arr.GetRecursiveDependencies(&dep, total, wxPDT_INVALID, &m_notfound);
00217     //dep.Dump();
00218 
00219     // are there conflicting dep ?
00220     wxPackageDependencyArray temp(dep.GetConflictingDependencies());
00221     if (temp.GetCount() > 0)
00222     {
00223         wxString list;
00224         for (size_t i=0; i<temp.GetCount(); i++)
00225             list += wxString::Format(wxT("%s requires version %s of %s\n"),
00226                         temp[i].GetOwnersIdStr().c_str(),
00227                         temp[i].GetVersion().GetAsString().c_str(),
00228                         temp[i].GetName().c_str());
00229 
00230         if (wxSmartLogYesNoQuestion(
00231                 wxT("depconflict"),
00232                 _("There are conflicting dependencies:\n\n%s\nShould I ignore them and proceed ?"),
00233                 list.c_str()) == wxID_NO)
00234             return false;
00235     }
00236 
00237     dep = dep.GetDependenciesNotAvailableIn(installed);
00238     m_required = dep.GetDependenciesOfType(wxPDT_REQUIRED);
00239     m_suggested = dep.GetDependenciesOfType(wxPDT_SUGGESTED);
00240 
00241     if (!m_notfound.IsEmpty() && m_required.IsEmpty() && m_suggested.IsEmpty())
00242     {
00243         // building a wxPackageDependencyDlg does not make much sense in this
00244         // case (since it contains yes/no buttons and in this case there are
00245         // no sensed questions!)
00246 
00247         wxString list;
00248         for (size_t i=0; i<m_notfound.GetCount(); i++)
00249             list += m_notfound[i].GetName() + wxT(",");
00250         list.RemoveLast();
00251 
00252         wxString msg;
00253         if (arr.GetCount() > 1)
00254             msg = _("The selected packages, or the packages they depend from, have dependencies from the\n\n     %s\n\npackages, which are not in the repository!\nShould I ignore them and proceed ?");
00255         else
00256             msg = _("The selected package, or the packages it depends from, has dependencies from the\n\n     %s\n\npackages, which are not in the repository!\nShould I ignore them and proceed ?");
00257 
00258         if (wxSmartLogYesNoQuestion(
00259                 wxT("ignoredep"),
00260                 msg,
00261                 list.c_str()) == wxID_NO)
00262             return false;
00263 
00264         // ignore missing packages (and make IsEmpty() return true
00265         // so that the Create() function of this dialog cannot be called)
00266         m_notfound.Clear();
00267     }
00268 
00269     return true;
00270 }
00271 
00272 bool wxPackageDependencyDlg::SetPackage(const wxPackage &pkg,
00273                                         const wxPackageArray &installed,
00274                                         const wxPackageArray &remote)
00275 {
00276     wxPackageArray temp;
00277     temp.Add(pkg);
00278     return SetPackageArray(temp, installed, remote);
00279 }
00280 
00281 void wxPackageDependencyDlg::QueueAdditionalPackages(wxPackageDependencyType type,
00282                                                      wxPackageDownloadQueuePanel *panel)
00283 {
00284     wxPackageArray arr = GetAdditionalPackages(type);
00285     panel->QueueDownloadOf(arr);
00286 }
00287 
00288 wxPackageArray wxPackageDependencyDlg::GetAdditionalPackages(wxPackageDependencyType t) const
00289 {
00290     wxPackageArray req, sugg;
00291 
00292     switch (t)
00293     {
00294     case wxPDT_REQUIRED:
00295         return GetPackagesFromCheckListbox(m_pRequiredCheckList, m_required);
00296 
00297     case wxPDT_SUGGESTED:
00298         return GetPackagesFromCheckListbox(m_pSuggestedCheckList, m_suggested);
00299 
00300     default:
00301         req = GetPackagesFromCheckListbox(m_pRequiredCheckList, m_required);
00302         sugg = GetPackagesFromCheckListbox(m_pSuggestedCheckList, m_suggested);
00303         WX_APPEND_ARRAY(req, sugg);
00304         return req;
00305     }
00306 }
00307 
00308 wxPackageArray wxPackageDependencyDlg::GetPackagesFromCheckListbox(wxCheckListBox *box,
00309                                            const wxPackageDependencyArray &arr) const
00310 {
00311     wxPackageArray ret;
00312 
00313     for (size_t i=0; i<arr.GetCount(); i++)
00314     {
00315         if (box->IsChecked(i))
00316         {
00317             int n = arr[i].GetBestMatch(*m_pRemote);
00318             wxASSERT(n != wxNOT_FOUND);
00319 
00320             ret.Add(m_pRemote->Item(n));
00321         }
00322     }
00323 
00324     return ret;
00325 }
00326 
00327 
00328 // ----------------------------------------------------------------------------
00329 // wxPackageDependencyDlg - event handlers
00330 // ----------------------------------------------------------------------------
00331 
00332 void wxPackageDependencyDlg::OnButton(wxCommandEvent &ev)
00333 {
00334     // ev.GetId() should be wxID_YES or wxID_NO
00335     switch (ev.GetId())
00336     {
00337     case wxID_YES:
00338         {
00339             wxPackageArray arr = GetAdditionalPackages();
00340             if (wxWidgetsBuildArray::s_arrWxBuilds.GetCount() > 0)
00341             {
00342                 // do wxWidgets dependency check without checking the compiler
00343                 // as we are not in build stage yet
00344 
00345                 for (size_t i=0; i < arr.GetCount(); i++)
00346                 {
00347                     if (arr[i].GetSupportedWxBuilds(false).IsEmpty())
00348                     {
00349                         wxLogWarning(wxT("The package '%s' does not support any of the installed wxWidgets ports/versions!\nCannot proceed."),
00350                                     arr[i].GetName().c_str());
00351                         return;
00352                     }
00353                 }
00354             }
00355             else
00356             {
00357                 // DO NOT USE wxLogMessage here - it could be shown
00358                 // *after* the download dialog!
00359                 wxSmartLogWarning(
00360                     wxT("nowxbuilds"),
00361                     _("You have not defined any wxWidgets build installed on this system.\nThe wxWidgets ports/versions compatibility check will be skipped!\n\nNote: you can modify the list of installed wxWidgets builds in the Settings -> wxWidgets panel."));
00362             }
00363         }
00364 
00365         EndModal(wxID_YES);
00366         break;
00367 
00368     default:
00369         EndModal(wxID_NO);
00370         break;
00371     }
00372 }
00373 
00374 

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