btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / installer / ProgressReporter.cpp
blob9c95fa92ccb592da8c4913afbe8569eb00f5c48f
1 /*
2 * Copyright 2009-2010, Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "ProgressReporter.h"
8 #include <stdio.h>
10 #include <Catalog.h>
11 #include <Locale.h>
14 #undef B_TRANSLATION_CONTEXT
15 #define B_TRANSLATION_CONTEXT "InstallProgress"
18 ProgressReporter::ProgressReporter(const BMessenger& messenger,
19 BMessage* message)
21 fStartTime(0),
23 fBytesToWrite(0),
24 fBytesWritten(0),
26 fItemsToWrite(0),
27 fItemsWritten(0),
29 fMessenger(messenger),
30 fMessage(message)
35 ProgressReporter::~ProgressReporter()
37 delete fMessage;
41 void
42 ProgressReporter::Reset()
44 fBytesToWrite = 0;
45 fBytesWritten = 0;
47 fItemsToWrite = 0;
48 fItemsWritten = 0;
50 if (fMessage) {
51 BMessage message(*fMessage);
52 message.AddString("status",
53 B_TRANSLATE("Collecting copy information."));
54 fMessenger.SendMessage(&message);
59 void
60 ProgressReporter::AddItems(uint64 count, off_t bytes)
62 fBytesToWrite += bytes;
63 fItemsToWrite += count;
67 void
68 ProgressReporter::StartTimer()
70 fStartTime = system_time();
72 printf("%" B_PRIdOFF " bytes to write in %" B_PRId64 " files\n",
73 fBytesToWrite, fItemsToWrite);
75 if (fMessage) {
76 BMessage message(*fMessage);
77 message.AddString("status", B_TRANSLATE("Performing installation."));
78 fMessenger.SendMessage(&message);
83 void
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);
94 void
95 ProgressReporter::_UpdateProgress(const char* itemName,
96 const char* targetFolder)
98 if (fMessage == NULL)
99 return;
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);