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/artprov.h>
00025 #include <wx/image.h>
00026
00027 #include "guicmn/guiutils.h"
00028 #include "guipm/taskpanel.h"
00029 #include "guipm/extcmdprogresspanel.h"
00030 #include "guipm/downloadprogresspanel.h"
00031 #include "guipm/logdlg.h"
00032
00033
00034 #include "bitmaps/play.xpm"
00035 #include "bitmaps/stop.xpm"
00036
00037
00038
00039
00040
00041 BEGIN_EVENT_TABLE( wxPackageTaskQueuePanel, wxPanel )
00042 EVT_IDLE(wxPackageTaskQueuePanel::OnIdle)
00043
00044
00045 EVT_BUTTON(ID_BUILDPANEL_START, wxPackageTaskQueuePanel::OnStart)
00046 EVT_BUTTON(ID_BUILDPANEL_STOP, wxPackageTaskQueuePanel::OnStop)
00047 EVT_BUTTON(ID_BUILDPANEL_DELETEQUEUED, wxPackageTaskQueuePanel::OnDeleteQueuedBuild)
00048
00049
00050 EVT_BUTTON(ID_BUILDPANEL_SHOWLOG, wxPackageTaskQueuePanel::OnShowLog)
00051 EVT_BUTTON(ID_BUILDPANEL_DELETECOMPLETED, wxPackageTaskQueuePanel::OnDeleteCompletedBuild)
00052
00053 EVT_UPDATE_UI( wxID_ANY, wxPackageTaskQueuePanel::OnUpdateUI )
00054
00055
00056 EVT_PROGRESS_FAILED(wxID_ANY, wxPackageTaskQueuePanel::OnProgressPanelFailed)
00057 EVT_PROGRESS_END(wxID_ANY, wxPackageTaskQueuePanel::OnProgressPanelEnd)
00058
00059 END_EVENT_TABLE()
00060
00061 wxPackageTaskQueuePanel::wxPackageTaskQueuePanel( )
00062 {
00063 }
00064
00065 wxPackageTaskQueuePanel::wxPackageTaskQueuePanel( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00066 {
00067 Create(parent, id, caption, pos, size, style);
00068 }
00069
00070 bool wxPackageTaskQueuePanel::Create( wxWindow* parent, wxWindowID id, const wxString&, const wxPoint& pos, const wxSize& size, long style )
00071 {
00073 m_pQueuedList = NULL;
00074 m_pStartBtn = NULL;
00075 m_pStopBtn = NULL;
00076 m_pDeleteQueuedBtn = NULL;
00077 m_pCompletedList = NULL;
00078 m_pShowLogBtn = NULL;
00079 m_pDeleteCompletedBtn = NULL;
00081
00083 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
00084 wxPanel::Create( parent, id, pos, size, style );
00085
00086 CreateControls();
00087 if (GetSizer())
00088 {
00089 GetSizer()->SetSizeHints(this);
00090 }
00091 Centre();
00093 return true;
00094 }
00095
00096 void wxPackageTaskQueuePanel::CreateControls()
00097 {
00098 m_pProgressEndHandler = NULL;
00099 CreateProgressPanel();
00100
00102 wxPackageTaskQueuePanel* itemPanel1 = this;
00103
00104 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
00105 itemPanel1->SetSizer(itemBoxSizer2);
00106
00107 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
00108 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW, 5);
00109
00110 wxStaticBox* itemStaticBoxSizer4Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Queued operations"));
00111 wxStaticBoxSizer* itemStaticBoxSizer4 = new wxStaticBoxSizer(itemStaticBoxSizer4Static, wxHORIZONTAL);
00112 itemBoxSizer3->Add(itemStaticBoxSizer4, 1, wxGROW|wxALL, 5);
00113
00114 m_pQueuedList = new wxTaskListBox( itemPanel1, ID_BUILDPANEL_QUEUED, wxDefaultPosition, wxDefaultSize, 0 );
00115 itemStaticBoxSizer4->Add(m_pQueuedList, 1, wxGROW|wxLEFT|wxTOP|wxBOTTOM, 5);
00116
00117 wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxVERTICAL);
00118 itemStaticBoxSizer4->Add(itemBoxSizer6, 0, wxGROW, 5);
00119
00120 wxBitmap m_pStartBtnBitmap(itemPanel1->GetBitmapResource(wxT("play")));
00121 m_pStartBtn = new wxBitmapButton( itemPanel1, ID_BUILDPANEL_START, m_pStartBtnBitmap, wxDefaultPosition, wxSize(26, 20), wxBU_AUTODRAW );
00122 if (ShowToolTips())
00123 m_pStartBtn->SetToolTip(_("Start building queued packages"));
00124 itemBoxSizer6->Add(m_pStartBtn, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
00125
00126 wxBitmap m_pStopBtnBitmap(itemPanel1->GetBitmapResource(wxT("stop")));
00127 m_pStopBtn = new wxBitmapButton( itemPanel1, ID_BUILDPANEL_STOP, m_pStopBtnBitmap, wxDefaultPosition, wxSize(26, 20), wxBU_AUTODRAW );
00128 if (ShowToolTips())
00129 m_pStopBtn->SetToolTip(_("Stop building queued packages"));
00130 itemBoxSizer6->Add(m_pStopBtn, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxBOTTOM, 5);
00131
00132 wxBitmap m_pDeleteQueuedBtnBitmap(itemPanel1->GetBitmapResource(wxT("delete")));
00133 m_pDeleteQueuedBtn = new wxBitmapButton( itemPanel1, ID_BUILDPANEL_DELETEQUEUED, m_pDeleteQueuedBtnBitmap, wxDefaultPosition, wxSize(26, 20), wxBU_AUTODRAW );
00134 if (ShowToolTips())
00135 m_pDeleteQueuedBtn->SetToolTip(_("Delete selected build from queue"));
00136 itemBoxSizer6->Add(m_pDeleteQueuedBtn, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxBOTTOM, 5);
00137
00138 wxStaticBox* itemStaticBoxSizer10Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Completed operations"));
00139 wxStaticBoxSizer* itemStaticBoxSizer10 = new wxStaticBoxSizer(itemStaticBoxSizer10Static, wxHORIZONTAL);
00140 itemBoxSizer3->Add(itemStaticBoxSizer10, 1, wxGROW|wxALL, 5);
00141
00142 m_pCompletedList = new wxTaskListBox( itemPanel1, ID_BUILDPANEL_COMPLETED, wxDefaultPosition, wxDefaultSize, 0 );
00143 itemStaticBoxSizer10->Add(m_pCompletedList, 1, wxGROW|wxLEFT|wxTOP|wxBOTTOM, 5);
00144
00145 wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxVERTICAL);
00146 itemStaticBoxSizer10->Add(itemBoxSizer12, 0, wxGROW, 5);
00147
00148 wxBitmap m_pShowLogBtnBitmap(itemPanel1->GetBitmapResource(wxT("showlog")));
00149 m_pShowLogBtn = new wxBitmapButton( itemPanel1, ID_BUILDPANEL_SHOWLOG, m_pShowLogBtnBitmap, wxDefaultPosition, wxSize(26, 20), wxBU_AUTODRAW );
00150 if (ShowToolTips())
00151 m_pShowLogBtn->SetToolTip(_("Show log of selected build"));
00152 itemBoxSizer12->Add(m_pShowLogBtn, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
00153
00154 wxBitmap m_pDeleteCompletedBtnBitmap(itemPanel1->GetBitmapResource(wxT("delete")));
00155 m_pDeleteCompletedBtn = new wxBitmapButton( itemPanel1, ID_BUILDPANEL_DELETECOMPLETED, m_pDeleteCompletedBtnBitmap, wxDefaultPosition, wxSize(26, 20), wxBU_AUTODRAW );
00156 if (ShowToolTips())
00157 m_pDeleteCompletedBtn->SetToolTip(_("Delete selected build from list"));
00158 itemBoxSizer12->Add(m_pDeleteCompletedBtn, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxBOTTOM, 5);
00159
00160 wxStaticBox* itemStaticBoxSizer15Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Current operation"));
00161 wxStaticBoxSizer* itemStaticBoxSizer15 = new wxStaticBoxSizer(itemStaticBoxSizer15Static, wxVERTICAL);
00162
00163
00164 itemBoxSizer2->Add(itemStaticBoxSizer15, GetCurrentOperationProportion(), wxGROW|wxALL, 5);
00165
00166 wxWindow* itemWindow16 = (wxWindow*) FindWindow(ID_BUILDPANEL_CURRENT);
00167 wxASSERT( itemWindow16 != NULL );
00168 itemStaticBoxSizer15->Add(itemWindow16, 1, wxGROW, 5);
00169
00171
00172 m_bUserStopped = false;
00173 }
00174
00175 void wxPackageTaskQueuePanel::RemoveFirstQueuedPackage()
00176 {
00177 m_arrQueue.RemoveAt(0);
00178
00179 m_pQueuedList->Delete(0);
00180 m_pQueuedList->RefreshAll();
00181 }
00182
00183 void wxPackageTaskQueuePanel::Stop()
00184 {
00185 m_pProgressPanel->Stop();
00186
00187
00188 m_pCompletedList->Prepend(m_currentBuild,
00189 m_pProgressPanel->GetLogData(),
00190 m_pProgressPanel->GetLogLabel(),
00191 m_pProgressPanel->IsSuccessful());
00192 m_pCompletedList->RefreshAll();
00193
00194 m_pProgressPanel->ClearControls();
00195 }
00196
00197 void wxPackageTaskQueuePanel::Start()
00198 {
00199 if (m_arrQueue.GetCount() == 0 ||
00200 m_pProgressPanel->IsProcessing())
00201 return;
00202
00203
00204 m_pProgressPanel->SetPackage(m_arrQueue[0]);
00205
00206
00207 m_currentBuild = m_pQueuedList->GetString(0);
00208 m_pQueuedList->SetTaskInProgress(0);
00209
00210
00211 m_pProgressPanel->Start();
00212 }
00213
00214 bool wxPackageTaskQueuePanel::ShowToolTips()
00215 {
00216 return true;
00217 }
00218
00219 wxBitmap wxPackageTaskQueuePanel::GetBitmapResource( const wxString& name )
00220 {
00221 wxImage bitmap;
00222
00223 if (name == _T("play"))
00224 bitmap = wxGetImageFromXPM_or_GTK2Stock(play_xpm, "gtk-media-play");
00225 else if (name == _T("stop"))
00226 bitmap = wxGetImageFromXPM_or_GTK2Stock(stop_xpm, "gtk-media-stop");
00227 else if (name == _T("delete"))
00228 bitmap = wxGetImageFromArtProvider_or_GTK2Stock(wxART_CROSS_MARK, "gtk-stop");
00229 else if (name == _T("showlog"))
00230 bitmap = wxGetImageFromArtProvider_or_GTK2Stock(wxART_INFORMATION, "gtk-dialog-info");
00231
00232 if (bitmap.IsOk())
00233 {
00234 float ratio = (float)bitmap.GetWidth() / (float)ID_BUILDPANEL_BITMAP_WIDTH;
00235 int height = (int)(bitmap.GetHeight()*ratio);
00236
00237 bitmap.Rescale(ID_BUILDPANEL_BITMAP_WIDTH, height,
00238 wxIMAGE_QUALITY_HIGH);
00239 }
00240
00241 return wxBitmap(bitmap);
00242 }
00243
00244 void wxPackageTaskQueuePanel::OnQueueTask()
00245 {
00246
00247
00248 m_bUserStopped = false;
00249 }
00250
00251
00252
00253
00254
00255
00256
00257 void wxPackageTaskQueuePanel::OnProgressPanelEnd(wxCommandEvent &ev)
00258 {
00259 RemoveFirstQueuedPackage();
00260 Stop();
00261
00262 if (m_pProgressEndHandler)
00263 m_pProgressEndHandler->AddPendingEvent(ev);
00264 }
00265
00266 void wxPackageTaskQueuePanel::OnProgressPanelFailed(wxCommandEvent &ev)
00267 {
00268 OnProgressPanelEnd(ev);
00269
00270
00271
00272
00273 m_bUserStopped = true;
00274 }
00275
00276 void wxPackageTaskQueuePanel::OnIdle(wxIdleEvent &WXUNUSED(ev))
00277 {
00278
00279 if (!m_bUserStopped) Start();
00280 }
00281
00282 void wxPackageTaskQueuePanel::OnUpdateUI(wxUpdateUIEvent & WXUNUSED(ev))
00283 {
00284 m_pStartBtn->Enable(m_arrQueue.GetCount() > 0 &&
00285 !m_pProgressPanel->IsProcessing());
00286 m_pStopBtn->Enable(m_arrQueue.GetCount() > 0 &&
00287 !m_pStartBtn->IsEnabled());
00288
00289 m_pDeleteQueuedBtn->Enable(m_pQueuedList->GetSelection() != wxNOT_FOUND);
00290 m_pShowLogBtn->Enable(m_pCompletedList->GetSelection() != wxNOT_FOUND);
00291 m_pDeleteCompletedBtn->Enable(m_pCompletedList->GetSelection() != wxNOT_FOUND);
00292 }
00293
00294 void wxPackageTaskQueuePanel::OnStart(wxCommandEvent &WXUNUSED(ev))
00295 {
00296 Start();
00297 m_bUserStopped = false;
00298 }
00299
00300 void wxPackageTaskQueuePanel::OnStop(wxCommandEvent &)
00301 {
00302 Stop();
00303 m_bUserStopped = true;
00304 }
00305
00306 void wxPackageTaskQueuePanel::OnDeleteQueuedBuild(wxCommandEvent &)
00307 {
00308 int n = m_pQueuedList->GetSelection();
00309 wxASSERT(n != wxNOT_FOUND);
00310 m_pQueuedList->Delete(n);
00311 m_pQueuedList->RefreshAll();
00312 }
00313
00314 void wxPackageTaskQueuePanel::OnShowLog(wxCommandEvent &)
00315 {
00316 int n = m_pCompletedList->GetSelection();
00317 wxASSERT(n != wxNOT_FOUND);
00318
00319 wxPackageLogDlg dlg(this, wxID_ANY,
00320 wxT("Log for ") + m_pCompletedList->GetString(n));
00321 dlg.SetLog(m_pCompletedList->GetLog(n));
00322 dlg.SetLabel(m_pCompletedList->GetLogLabel(n));
00323 dlg.ShowModal();
00324 }
00325
00326 void wxPackageTaskQueuePanel::OnDeleteCompletedBuild(wxCommandEvent &)
00327 {
00328 int n = m_pCompletedList->GetSelection();
00329 wxASSERT(n != wxNOT_FOUND);
00330 m_pCompletedList->Delete(n);
00331 m_pCompletedList->RefreshAll();
00332 }
00333
00334
00335
00336
00337
00338
00339
00340 wxPackageDownloadQueuePanel::wxPackageDownloadQueuePanel(
00341 wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos,
00342 const wxSize& size, long style )
00343 {
00344 Create(parent, id, caption, pos, size, style);
00345 }
00346
00347 bool wxPackageDownloadQueuePanel::CreateProgressPanel()
00348 {
00349 m_pProgressPanel = new wxDownloadProgressPanel(this, ID_BUILDPANEL_CURRENT);
00350 return true;
00351 }
00352
00353 void wxPackageDownloadQueuePanel::QueueDownloadOf(const wxPackage &pkg)
00354 {
00355 OnQueueTask();
00356
00357 m_arrQueue.Add(pkg);
00358 m_pQueuedList->Append(wxT("Download of ") + pkg.GetName());
00359 m_pQueuedList->RefreshAll();
00360 }
00361
00362 void wxPackageDownloadQueuePanel::QueueDownloadOf(const wxPackageArray &arr)
00363 {
00364 OnQueueTask();
00365
00366 for (size_t i=0; i<arr.GetCount(); i++)
00367 {
00368 m_arrQueue.Add(arr[i]);
00369 m_pQueuedList->Append(wxT("Download of ") + arr[i].GetName());
00370 }
00371
00372
00373
00374 m_pQueuedList->RefreshAll();
00375 }
00376
00377
00378
00379
00380
00381
00382
00383 wxPackageCommandQueuePanel::wxPackageCommandQueuePanel(
00384 wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos,
00385 const wxSize& size, long style )
00386 {
00387 Create(parent, id, caption, pos, size, style);
00388 }
00389
00390 bool wxPackageCommandQueuePanel::CreateProgressPanel()
00391 {
00392 m_pProgressPanel = new wxExtCmdProgressPanel(this, ID_BUILDPANEL_CURRENT);
00393 wxStaticCast(m_pProgressPanel, wxExtCmdProgressPanel)->SetStage(wxPBSS_BUILD);
00394 return true;
00395 }
00396
00397 void wxPackageCommandQueuePanel::QueueBuildOf(const wxPackage &pkg)
00398 {
00399 OnQueueTask();
00400
00401 m_arrQueue.Add(pkg);
00402 m_pQueuedList->Append(
00403 wxString::Format(wxT("Build of %s <small>[%s]</small>"),
00404 pkg.GetName().c_str(), wxDateTime::Now().FormatTime().c_str()));
00405 m_pQueuedList->RefreshAll();
00406 }
00407
00408
00409
00410
00411
00412
00413 wxTaskListBox::wxTaskListBox(wxWindow* parent, wxWindowID id, const wxPoint& pos,
00414 const wxSize& size, long style, const wxString& name)
00415 {
00416
00417 wxHtmlListBox::Create(parent, id, pos, size, style|wxSUNKEN_BORDER, name);
00418
00419 SetMargins(1, 1);
00420
00421 m_nInProgress = -1;
00422 }
00423
00424
00425
00426
00427
00428
00429
00430 wxString wxTaskListBox::OnGetItem(size_t n) const
00431 {
00432 if (m_success[n] == -1)
00433 {
00434 if ((size_t)m_nInProgress == n)
00435 return wxT("<b>=> ") + m_items[n] + wxT(" <=</b>");
00436 return wxString::Format(wxT("#%d: "), n+1) + m_items[n];
00437 }
00438
00439
00440 wxString img = m_success[n] == 1 ? wxT("memory:tickmark") : wxT("memory:crossmark");
00441 return wxString::Format(wxT("<img src='%s'/> %s"),
00442 img.c_str(), m_items[n].c_str());
00443 }
00444
00445 wxString wxTaskListBox::OnGetItemMarkup(size_t n) const
00446 {
00447 wxString str(OnGetItem(n));
00448 if (m_success[n] == -1)
00449 return str;
00450
00451
00452
00453
00454
00455 return wxString::Format(wxT("<font color='%s'><b>%s</b></font>"),
00456 m_success[n] == 1 ? wxT("#00AA00") : wxT("red"),
00457 str.c_str());
00458 }
00459
00460
00461
00462
00463
00464
00465 void wxTaskListBox::Delete(unsigned int n)
00466 {
00467 m_items.RemoveAt(n);
00468 m_logs.RemoveAt(n);
00469 m_success.RemoveAt(n);
00470
00471 if (n == (unsigned)m_nInProgress)
00472 m_nInProgress = -1;
00473
00474 SetItemCount(m_items.GetCount());
00475 }
00476