2 * Copyright 2009-2010, Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT License.
6 #include "ProgressReporter.h"
14 #undef B_TRANSLATION_CONTEXT
15 #define B_TRANSLATION_CONTEXT "InstallProgress"
18 ProgressReporter::ProgressReporter(const BMessenger
& messenger
,
29 fMessenger(messenger
),
35 ProgressReporter::~ProgressReporter()
42 ProgressReporter::Reset()
51 BMessage
message(*fMessage
);
52 message
.AddString("status",
53 B_TRANSLATE("Collecting copy information."));
54 fMessenger
.SendMessage(&message
);
60 ProgressReporter::AddItems(uint64 count
, off_t bytes
)
62 fBytesToWrite
+= bytes
;
63 fItemsToWrite
+= count
;
68 ProgressReporter::StartTimer()
70 fStartTime
= system_time();
72 printf("%" B_PRIdOFF
" bytes to write in %" B_PRId64
" files\n",
73 fBytesToWrite
, fItemsToWrite
);
76 BMessage
message(*fMessage
);
77 message
.AddString("status", B_TRANSLATE("Performing installation."));
78 fMessenger
.SendMessage(&message
);
84 ProgressReporter::ItemsWritten(uint64 items
, off_t bytes
,
85 const char* itemName
, const char* targetFolder
)
87 fItemsWritten
+= items
;
88 fBytesWritten
+= bytes
;
90 _UpdateProgress(itemName
, targetFolder
);
95 ProgressReporter::_UpdateProgress(const char* itemName
,
96 const char* targetFolder
)
101 // TODO: Could add time to finish calculation here...
103 BMessage
message(*fMessage
);
104 float progress
= 100.0 * fBytesWritten
/ fBytesToWrite
;
105 message
.AddFloat("progress", progress
);
106 message
.AddInt32("current", fItemsWritten
);
107 message
.AddInt32("maximum", fItemsToWrite
);
108 message
.AddString("item", itemName
);
109 message
.AddString("folder", targetFolder
);
110 fMessenger
.SendMessage(&message
);