libyui  3.3.2
YDownloadProgress.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YDownloadProgress.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YDownloadProgress_h
26 #define YDownloadProgress_h
27 
28 #include "YWidget.h"
29 
30 
32 
33 /**
34  * DownloadProgress: A progress bar that monitors downloading a file by
35  * repeatedly polling its size up to its expected size.
36  **/
37 class YDownloadProgress : public YWidget
38 {
39 protected:
40  /**
41  * Constructor.
42  *
43  * 'label' is the label above the progress bar.
44  *
45  * 'filename' is the name (with path) of the file being monitored.
46  *
47  * 'expectedSize' is the expected size of the file in bytes.
48  **/
50  const std::string & label,
51  const std::string & filename,
52  YFileSize_t expectedSize );
53 public:
54  /**
55  * Destructor.
56  **/
57  virtual ~YDownloadProgress();
58 
59  /**
60  * Returns a descriptive name of this widget class for logging,
61  * debugging etc.
62  **/
63  virtual const char * widgetClass() const { return "YDownloadProgress"; }
64 
65  /**
66  * Get the label (the text above the progress bar).
67  **/
68  std::string label() const;
69 
70  /**
71  * Set the label (the text above the progress bar).
72  *
73  * Derived classes are free to reimplement this, but they should call this
74  * base class method at the end of the overloaded function.
75  **/
76  virtual void setLabel( const std::string & label );
77 
78  /**
79  * Return the name of the file that is being monitored.
80  **/
81  std::string filename() const;
82 
83  /**
84  * Set the name of a new file to monitor.
85  *
86  * Derived classes are free to reimplement this, but they should call this
87  * base class method at the end of the overloaded function.
88  **/
89  virtual void setFilename( const std::string & filename );
90 
91  /**
92  * Return the expected file size.
93  **/
94  YFileSize_t expectedSize() const;
95 
96  /**
97  * Set the expected file size.
98  *
99  * Derived classes are free to reimplement this, but they should call this
100  * base class method at the end of the overloaded function.
101  **/
102  virtual void setExpectedSize( YFileSize_t newSize );
103 
104  /**
105  * Return the current size of the file that is being downloaded
106  * or 0 if this file doesn't exist (yet).
107  *
108  * This default implementation returns the 'st_size' field of a stat()
109  * system call on the file. This should be useful for most implementations.
110  **/
111  virtual YFileSize_t currentFileSize() const;
112 
113  /**
114  * Return the percentage (0..100) of the file being downloaded so far.
115  **/
116  int currentPercent() const;
117 
118  /**
119  * Alias for currentPercent().
120  **/
121  int value() const { return currentPercent(); }
122 
123  /**
124  * Set a property.
125  * Reimplemented from YWidget.
126  *
127  * This function may throw YUIPropertyExceptions.
128  *
129  * This function returns 'true' if the value was successfully set and
130  * 'false' if that value requires special handling (not in error cases:
131  * those are covered by exceptions).
132  **/
133  virtual bool setProperty( const std::string & propertyName,
134  const YPropertyValue & val );
135 
136  /**
137  * Get a property.
138  * Reimplemented from YWidget.
139  *
140  * This method may throw YUIPropertyExceptions.
141  **/
142  virtual YPropertyValue getProperty( const std::string & propertyName );
143 
144  /**
145  * Return this class's property set.
146  * This also initializes the property upon the first call.
147  *
148  * Reimplemented from YWidget.
149  **/
150  virtual const YPropertySet & propertySet();
151 
152 
153 private:
154 
156 };
157 
158 
159 #endif // YDownloadProgress_h
std::string label() const
Get the label (the text above the progress bar).
DownloadProgress: A progress bar that monitors downloading a file by repeatedly polling its size up t...
virtual YFileSize_t currentFileSize() const
Return the current size of the file that is being downloaded or 0 if this file doesn&#39;t exist (yet)...
Transport class for the value of simple properties.
Definition: YProperty.h:104
A set of properties to check names and types against.
Definition: YProperty.h:197
virtual const char * widgetClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
virtual void setExpectedSize(YFileSize_t newSize)
Set the expected file size.
std::string filename() const
Return the name of the file that is being monitored.
virtual void setLabel(const std::string &label)
Set the label (the text above the progress bar).
virtual void setFilename(const std::string &filename)
Set the name of a new file to monitor.
virtual ~YDownloadProgress()
Destructor.
YDownloadProgress(YWidget *parent, const std::string &label, const std::string &filename, YFileSize_t expectedSize)
Constructor.
YFileSize_t expectedSize() const
Return the expected file size.
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
int value() const
Alias for currentPercent().
Abstract base class of all UI widgets.
Definition: YWidget.h:54
int currentPercent() const
Return the percentage (0..100) of the file being downloaded so far.