Clone
ixen <ixen@copyhandler.com>
committed
on 23 Dec 15
Update to boost 1.60 (CH-201).
LoggerImprovements + 5 more
src/ch/StatusDlg.cpp (+17 -11)
9 9 *   This program is distributed in the hope that it will be useful,       *
10 10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 12 *   GNU General Public License for more details.                          *
13 13 *                                                                         *
14 14 *   You should have received a copy of the GNU Library General Public     *
15 15 *   License along with this program; if not, write to the                 *
16 16 *   Free Software Foundation, Inc.,                                       *
17 17 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18 18 ***************************************************************************/
19 19 #include "stdafx.h"
20 20 #include "ch.h"
21 21 #include "../libchcore/TTaskManager.h"
22 22 #include "../libchcore/TTask.h"
23 23 #include "resource.h"
24 24 #include "StatusDlg.h"
25 25 #include "BufferSizeDlg.h"
26 26 #include "StringHelpers.h"
27 27 #include "StaticEx.h"
28 28 #include "Structs.h"
  29 #include "../libchcore/TTaskStatsSnapshot.h"
  30 #include "../libchcore/TTaskManagerStatsSnapshot.h"
29 31
30 32 #ifdef _DEBUG
31 33 #define new DEBUG_NEW
32 34 #undef THIS_FILE
33 35 static char THIS_FILE[] = __FILE__;
34 36 #endif
35 37
36 38 bool CStatusDlg::m_bLock=false;
37 39
38 40 /////////////////////////////////////////////////////////////////////////////
39 41 // CStatusDlg dialog
40 42
41 43 CStatusDlg::CStatusDlg(chcore::TTaskManager* pTasks, CWnd* pParent /*=NULL*/)
42 44         : ictranslate::CLanguageDialog(CStatusDlg::IDD, pParent, &m_bLock)
43 45 {
44 46         //{{AFX_DATA_INIT(CStatusDlg)
45 47         //}}AFX_DATA_INIT
46 48         m_i64LastProcessed=0;
47 49         m_i64LastAllTasksProcessed=0;
48 50         m_pTasks=pTasks;
 
251 253         lvi.iSubItem=1;
252 254         if(td.m_strFileName.IsEmpty())
253 255                 strTemp = GetResManager().LoadString(IDS_NONEINPUTFILE_STRING);
254 256         else
255 257                 strTemp = td.m_strFileName;
256 258         lvi.pszText=strTemp.GetBuffer(0);
257 259         strTemp.ReleaseBuffer();
258 260         lvi.cchTextMax=lstrlen(lvi.pszText);
259 261         m_ctlStatusList.SetItem(&lvi);
260 262
261 263         // insert 'file' subitem
262 264         lvi.iSubItem=2;
263 265         strTemp = td.m_pathDstPath.ToString();
264 266         lvi.pszText=strTemp.GetBuffer(0);
265 267         strTemp.ReleaseBuffer();
266 268         lvi.cchTextMax=lstrlen(lvi.pszText);
267 269         m_ctlStatusList.SetItem(&lvi);
268 270
269 271         // insert dest subitem
270 272         lvi.iSubItem=3;
271           _itot( td.m_nPercent, m_szData, 10 );
  273         _itot(boost::numeric_cast<int>(td.m_dPercent), m_szData, 10);
272 274         _tcscat(m_szData, _T(" %"));
273 275         lvi.pszText=m_szData;
274 276         lvi.cchTextMax=lstrlen(lvi.pszText);
275 277         m_ctlStatusList.SetItem(&lvi);
276 278
277 279         // right side update
278 280         if(spTask == m_spSelectedItem && GetPropValue<PP_STATUSSHOWDETAILS>(GetConfig()))
279 281         {
280 282                 // data that can be changed by a thread
281 283                 GetDlgItem(IDC_OPERATION_STATIC)->SetWindowText(strStatusText); // operation
282 284
283 285                 if(td.m_strFullFilePath.IsEmpty())
284 286                         GetDlgItem(IDC_SOURCE_STATIC)->SetWindowText(GetResManager().LoadString(IDS_NONEINPUTFILE_STRING));
285 287                 else
286 288                         GetDlgItem(IDC_SOURCE_STATIC)->SetWindowText(td.m_strFullFilePath);     // src object
287 289                 
288 290                 // count of processed data/overall count of data
289 291                 _sntprintf(m_szData, _MAX_PATH, _T("%d/%d ("), td.m_stIndex, td.m_stSize);
290 292                 strTemp=CString(m_szData);
291 293                 strTemp+=GetSizeString(td.m_ullProcessedSize, m_szData, _MAX_PATH)+CString(_T("/"));
 
302 304                                 strTemp=GetSizeString( 0ULL, m_szData, _MAX_PATH);
303 305
304 306                 // avg transfer
305 307                 GetDlgItem(IDC_TRANSFER_STATIC)->SetWindowText(strTemp+_T("/s (")+CString(GetResManager().LoadString(IDS_AVERAGEWORD_STRING))
306 308                         +CString(GetSizeString(td.m_timeElapsed ? td.m_ullProcessedSize/td.m_timeElapsed : 0, m_szData, _MAX_PATH))+_T("/s )")
307 309                         );
308 310                 
309 311                 // elapsed time / estimated total time (estimated time left)
310 312                 FormatTime(td.m_timeElapsed, m_szTimeBuffer1, 40);
311 313                 time_t timeTotal = (td.m_ullProcessedSize == 0) ? 0 : (long)(td.m_ullSizeAll * td.m_timeElapsed / td.m_ullProcessedSize);
312 314                 FormatTime(timeTotal, m_szTimeBuffer2, 40);
313 315                 FormatTime(std::max((time_t)0l, timeTotal - td.m_timeElapsed), m_szTimeBuffer3, 40);
314 316
315 317                 _sntprintf(m_szData, _MAX_PATH, _T("%s / %s (%s)"), m_szTimeBuffer1, m_szTimeBuffer2, m_szTimeBuffer3);
316 318                 GetDlgItem(IDC_TIME_STATIC)->SetWindowText(m_szData);
317 319
318 320                 // remember current processed data (used for calculating transfer)
319 321                 m_i64LastProcessed=td.m_ullProcessedSize;
320 322
321 323                 // set progress
322                   m_ctlCurrentProgress.SetPos(td.m_nPercent);
  324                 m_ctlCurrentProgress.SetPos(boost::numeric_cast<int>(td.m_dPercent));
323 325
324 326                 SetBufferSizesString(td.m_iCurrentBufferSize, td.m_iCurrentBufferIndex);
325 327
326 328                 // data that can be changed only by user from outside the thread
327 329                 // refresh only when there are new selected item
328 330 //              if (spTask != m_spLastSelected)
329 331                 {
330 332                         GetDlgItem(IDC_DESTINATION_STATIC)->SetWindowText(td.m_pathDstPath.ToString());
331 333                         GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager().LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(td.m_nPriority)));
332 334                         GetDlgItem(IDC_ASSOCIATEDFILES__STATIC)->SetWindowText(td.m_strUniqueName);
333 335                 }
334 336
335 337                 // refresh m_spLastSelected
336 338                 m_spLastSelected = spTask;
337 339         }
338 340 }
339 341
340 342 void CStatusDlg::OnSetBuffersizeButton()
341 343 {
342 344         chcore::TTaskPtr spTask = GetSelectedItemPointer();
343 345         if(!spTask)
344 346                 return;
345 347
346 348         CBufferSizeDlg dlg;
  349         chcore::TTaskStatsSnapshot tTaskStats;
  350         spTask->GetTaskStats(tTaskStats);
  351
347 352         spTask->GetBufferSizes(dlg.m_bsSizes);
348           dlg.m_iActiveIndex = spTask->GetCurrentBufferIndex();
  353         dlg.m_iActiveIndex = tTaskStats.GetCurrentSubTaskStats().GetCurrentBufferIndex();
349 354         if(dlg.DoModal() == IDOK)
350 355                 spTask->SetBufferSizes(dlg.m_bsSizes);
351 356 }
352 357
353 358 chcore::TTaskPtr CStatusDlg::GetSelectedItemPointer()
354 359 {
355 360         // returns ptr to a TTask for a given element in listview
356 361         if(m_ctlStatusList.GetSelectedCount() == 1)
357 362         {
358 363                 POSITION pos = m_ctlStatusList.GetFirstSelectedItemPosition();
359 364                 int nPos = m_ctlStatusList.GetNextSelectedItem(pos);
360 365                 return m_pTasks->GetTaskBySessionUniqueID(m_ctlStatusList.GetItemData(nPos));
361 366         }
362 367
363 368         return chcore::TTaskPtr();
364 369 }
365 370
366 371 void CStatusDlg::OnRollUnrollButton()
367 372 {
368 373         // change settings in config dialog
 
697 702 }
698 703
699 704 void CStatusDlg::RefreshStatus()
700 705 {
701 706         // remember address of a current selection
702 707         m_spSelectedItem=GetSelectedItemPointer();
703 708
704 709         // current time
705 710         DWORD dwCurrentTime=GetTickCount();
706 711
707 712         // get rid of item after the current part
708 713         m_ctlStatusList.LimitItems(boost::numeric_cast<int>(m_pTasks->GetSize()));
709 714
710 715         // add task info
711 716         for(size_t stIndex = 0; stIndex < m_pTasks->GetSize(); ++stIndex)
712 717         {
713 718                 AddTaskInfo(boost::numeric_cast<int>(stIndex), m_pTasks->GetAt(stIndex), dwCurrentTime);
714 719         }
715 720
716 721         // percent
717           int nPercent=m_pTasks->GetPercent();
  722         chcore::TTaskManagerStatsSnapshot tTMStats;
  723         m_pTasks->GetStatsSnapshot(tTMStats);
718 724
719 725         // set title
720 726         if (m_pTasks->GetSize() != 0)
721                   _sntprintf(m_szData, _MAX_PATH, _T("%s [%d %%]"), GetResManager().LoadString(IDS_STATUSTITLE_STRING), m_pTasks->GetPercent());
  727                 _sntprintf(m_szData, _MAX_PATH, _T("%s [%.0f %%]"), GetResManager().LoadString(IDS_STATUSTITLE_STRING), tTMStats.GetGlobalProgressInPercent());
722 728         else
723 729                 _sntprintf(m_szData, _MAX_PATH, _T("%s"), GetResManager().LoadString(IDS_STATUSTITLE_STRING));
724 730         
725 731         // if changed
726 732         CString strTemp;
727 733         GetWindowText(strTemp);
728 734         if (strTemp != CString(m_szData))
729 735                 SetWindowText(m_szData);
730 736         
731 737         // refresh overall progress
732 738         if (GetPropValue<PP_STATUSSHOWDETAILS>(GetConfig()))
733 739         {
734                   m_ctlProgressAll.SetPos(nPercent);
  740                 m_ctlProgressAll.SetPos(boost::numeric_cast<int>(tTMStats.GetGlobalProgressInPercent()));
735 741                 
736 742                 // progress - count of processed data/count of data
737                   strTemp=GetSizeString(m_pTasks->GetPosition(), m_szData, _MAX_PATH)+CString(_T("/"));
738                   strTemp+=GetSizeString(m_pTasks->GetRange(), m_szData, _MAX_PATH);
  743                 strTemp=GetSizeString(tTMStats.GetProcessedSize(), m_szData, _MAX_PATH)+CString(_T("/"));
  744                 strTemp+=GetSizeString(tTMStats.GetTotalSize(), m_szData, _MAX_PATH);
739 745                 GetDlgItem(IDC_OVERALL_PROGRESS_STATIC)->SetWindowText(strTemp);
740 746                 
741 747                 // transfer
742 748                 if (m_i64LastAllTasksProcessed == 0)
743                           m_i64LastAllTasksProcessed=m_pTasks->GetPosition();
  749                         m_i64LastAllTasksProcessed=tTMStats.GetProcessedSize();
744 750                 
745 751                 if (dwCurrentTime-m_dwLastUpdate != 0)
746                           strTemp=GetSizeString( (static_cast<double>(m_pTasks->GetPosition()) - static_cast<double>(m_i64LastAllTasksProcessed))/static_cast<double>(static_cast<double>(dwCurrentTime-m_dwLastUpdate)/1000.0), m_szData, _MAX_PATH);
  752                         strTemp=GetSizeString( (static_cast<double>(tTMStats.GetProcessedSize()) - static_cast<double>(m_i64LastAllTasksProcessed))/static_cast<double>(static_cast<double>(dwCurrentTime-m_dwLastUpdate)/1000.0), m_szData, _MAX_PATH);
747 753                 else
748 754                         strTemp=GetSizeString( 0ULL, m_szData, _MAX_PATH);
749 755                 
750 756                 GetDlgItem(IDC_OVERALL_TRANSFER_STATIC)->SetWindowText(strTemp+_T("/s"));
751                   m_i64LastAllTasksProcessed=m_pTasks->GetPosition();
  757                 m_i64LastAllTasksProcessed=tTMStats.GetProcessedSize();
752 758                 m_dwLastUpdate=dwCurrentTime;
753 759         }
754 760
755 761         // if selection's missing - hide controls
756 762         if (m_ctlStatusList.GetSelectedCount() == 0)
757 763         {
758 764                 EnableControls(false);
759 765                 m_spLastSelected.reset();
760 766                 m_i64LastProcessed=0;
761 767         }
762 768         else
763 769                 EnableControls();               // enable controls
764 770         
765 771         // apply state of the resume, cancel, ... buttons
766 772         ApplyButtonsState();
767 773 }
768 774
769 775 void CStatusDlg::OnSelectionChanged(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
770 776 {
771 777         TRACE("Received LVN_CHANGEDSELECTION\n");