void GamessQFrame::OnJoblistctrlEndLabelEdit( wxListEvent& event ) { Job *job = mJobList.Item(event.GetIndex())->GetData(); if (mQueueManager.SetName(job->GetId(), event.GetLabel())) { job->SetName(event.GetLabel()); } RefreshButtons(); }
void GamessQFrame::OnRemoveClick( wxCommandEvent& event ) { GreyButtons(); int index = jobListCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); while (index != -1) { Job *job = mJobList.Item(index)->GetData(); mQueueManager.Remove(job->GetId()); index = jobListCtrl->GetNextItem(index, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); } RefreshList(); RefreshButtons(); }
/*! * This function is called when someone clicks "View Logs". It creates and * shows a new LogViewer with the log files of all the jobs that have valid * logs. */ void GamessQFrame::OnViewlogsClick( wxCommandEvent& event ) { wxArrayString filenames; int index = jobListCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (index == -1) { return; } while (index != -1) { Job *job = mJobList.Item(index)->GetData(); if (CanViewLogs(job)) { wxFileName name = (mQueueManager.GetFileName(job->GetId())); name.SetExt(wxT("log")); filenames.Add(name.GetFullPath()); } index = jobListCtrl->GetNextItem(index, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); } LogViewer *viewer = new LogViewer(this, filenames); viewer->Show(); }
/*! * This function refreshes the job list. It queries the server for the required * information and then updates the list control. * * \par Notes on the implementation of RefreshList() * For efficiency reasons, after the initial refresh, all refreshes are * incremental. Because IPC is the slowest part of the whole program the client * only gathers the only the information that is subject to have changed from * the server. The list control is also left alone during the process so that * it is greyed out for as short a period as possible. * * \par * The list control is also updated incrementally, yet for a completely * different reason. Whenever the list control is cleared entirely, it not only * takes time to reload the entire list, but it resets the current position of * the list in the scroller, so every time the client refreshes the user is * looking at the top (and most likely irrelevant) portion of the queue again. * * \par * Due to the incremental nature of this code, it is rather complicated and * should be left alone, unless there is a good reason to change it. */ void GamessQFrame::RefreshList() { int *ids = mQueueManager.GetJobIds(); int num = ids[0]; wxString name; int procs; Job::Status status; Job *job; // update any jobs that are out of date, and remove any jobs that no longer // exist on the server JobList::compatibility_iterator node = mJobList.GetFirst(); int i = 1; while (node) { job = node->GetData(); if (i <= num && job->GetId() == ids[i]) { // update the status status = job->GetStatus(); if (status != Job::STATUS_DONE && status != Job::STATUS_ERROR && status != Job::STATUS_CANCELED) { job->SetStatus(mQueueManager.GetStatus(ids[i])); } node = node->GetNext(); i++; } else { JobList::compatibility_iterator nextNode = node->GetNext(); mJobList.DeleteNode(node); node = nextNode; } } // add any new jobs for which we do not yet have local copies for (; i <= num; i++) { name = mQueueManager.GetName(ids[i]); procs = mQueueManager.GetNumProcessors(ids[i]); status = mQueueManager.GetStatus(ids[i]); job = new Job(ids[i], name, wxT(""), status, procs); mJobList.Append(job); } // update the interface jobListCtrl->Hide(); // update the jobs that are in the control and delete any jobs that no // longer exist node = mJobList.GetFirst(); i = 0; while (i < jobListCtrl->GetItemCount()) { if (node && jobListCtrl->GetItemData(i) == node->GetData()->GetId()) { jobListCtrl->SetItem(i, 0, node->GetData()->GetName()); jobListCtrl->SetItem(i, 2, node->GetData()->GetStatusString()); node = node->GetNext(); i++; } else { jobListCtrl->DeleteItem(i); } } // add new entries to the control for the new jobs for (;node; i ++, node = node->GetNext()) { Job *job = node->GetData(); int index = jobListCtrl->InsertItem(i, job->GetName()); jobListCtrl->SetItemData(index, job->GetId()); wxString procs; procs << job->GetNumProcessors(); jobListCtrl->SetItem(index, 1, procs); jobListCtrl->SetItem(index, 2, job->GetStatusString()); } jobListCtrl->Show(); delete ids; mRefreshTimer->Start(mRefreshFrequency, wxTIMER_ONE_SHOT); }