00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
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
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
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
00188
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
00206
00207 wxPackageArray total(installed);
00208 WX_APPEND_ARRAY(total, remote);
00209
00210
00211
00212 total.RemoveDuplicates();
00213
00214
00215 wxPackageDependencyArray dep;
00216 arr.GetRecursiveDependencies(&dep, total, wxPDT_INVALID, &m_notfound);
00217
00218
00219
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
00244
00245
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
00265
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
00330
00331
00332 void wxPackageDependencyDlg::OnButton(wxCommandEvent &ev)
00333 {
00334
00335 switch (ev.GetId())
00336 {
00337 case wxID_YES:
00338 {
00339 wxPackageArray arr = GetAdditionalPackages();
00340 if (wxWidgetsBuildArray::s_arrWxBuilds.GetCount() > 0)
00341 {
00342
00343
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
00358
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