OSDN Git Service

Version 5.91
[vbslib/main.git] / GPL_bin_fullset / NaturalDocs / Modules / NaturalDocs / StatusMessage.pm
1 ###############################################################################
2 #
3 #   Package: NaturalDocs::StatusMessage
4 #
5 ###############################################################################
6 #
7 #   A package to handle status message updates.  Automatically handles <NaturalDocs::Settings->IsQuiet()>.
8 #
9 ###############################################################################
10
11 # This file is part of Natural Docs, which is Copyright © 2003-2010 Greg Valure
12 # Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
13 # Refer to License.txt for the complete details
14
15 use strict;
16 use integer;
17
18 package NaturalDocs::StatusMessage;
19
20
21 #
22 #   var: message
23 #   The message to display.
24 #
25 my $message;
26
27 #
28 #   var: total
29 #   The number of items to work through.
30 #
31 my $total;
32
33 #
34 #   var: completed
35 #   The number of items completed.
36 #
37 my $completed;
38
39 #
40 #   var: lastMessageTime
41 #   The time the last message was posted.
42 #
43 my $lastMessageTime;
44
45
46 #
47 #   constant: TIME_BETWEEN_UPDATES
48 #   The number of seconds that should occur between updates.
49 #
50 use constant TIME_BETWEEN_UPDATES => 10;
51
52
53
54 #
55 #   Function: Start
56 #
57 #   Starts the status message.
58 #
59 #   Parameters:
60 #
61 #       message - The message to post.
62 #       total - The number of items that are going to be worked through.
63 #
64 sub Start #(message, total)
65     {
66     my $self = shift;
67
68     if (!NaturalDocs::Settings->IsQuiet())
69         {
70         ($message, $total) = @_;
71         $completed = 0;
72
73         print $message . "\n";
74
75         $lastMessageTime = time();
76         };
77     };
78
79
80 #
81 #   Function: CompletedItem
82 #
83 #   Should be called every time an item is completed.
84 #
85 sub CompletedItem
86     {
87     my $self = shift;
88
89     if (!NaturalDocs::Settings->IsQuiet())
90         {
91         # We scale completed by 100 since we need to anyway to get the percentage.
92
93         $completed += 100;
94
95         if (time() >= $lastMessageTime + TIME_BETWEEN_UPDATES && $completed != $total * 100)
96             {
97             print $message . ' (' . ($completed / $total) . '%)' . "\n";
98             $lastMessageTime = time();
99             };
100         };
101     };
102
103 1;